typeHistoryActor
export type HistoryActor = z.infer<typeof HistoryActorSchema>;@vireocodedev/history · 0.2.2
@vireocodedev/history35 public exports generated from the shipped declaration graph.
Showing all 35 exports
export type HistoryActor = z.infer<typeof HistoryActorSchema>;export declare const HistoryActorSchema: z.ZodObject<{
id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
label: z.ZodString;
}, z.core.$strip>;export type HistoryArrayFieldConfig<TValue, TParent> = NonNullable<TValue> extends readonly (infer TItem)[] ? {
kind: "array";
label: string;
/** @default "set" */
mode?: HistoryArrayMode;
format?: (value: NonNullable<TValue>, context: HistoryFormatContext<TParent>) => string;
item: HistoryArrayItemConfig<TItem>;
} : never;export type HistoryArrayItemConfig<TItem> = HistoryAtomicFieldConfig<TItem, TItem> | HistoryArrayFieldConfig<TItem, TItem> | HistoryObjectFieldConfig<TItem>;export type HistoryArrayMode = "set" | "ordered";export type HistoryAtomicFieldConfig<TValue, TParent> = {
kind: "field";
label: string;
format?: (value: NonNullable<TValue>, context: HistoryFormatContext<TParent>) => string;
resolveChange?: (previous: TValue, current: TValue) => HistoryChangeType | null;
};export type HistoryChangeType = "added" | "removed" | "updated";export type HistoryDefinition<TEntity extends object, TSchema extends z.ZodTypeAny = z.ZodTypeAny> = {
schema: TSchema;
options: HistoryDefinitionOptions<TEntity>;
fields: HistoryDefinitionFields<TEntity>;
};export type HistoryDefinitionFields<TEntity extends object> = {
[TKey in keyof TEntity]-?: HistoryFieldConfig<TEntity[TKey], TEntity>;
};export type HistoryDefinitionOptions<TEntity extends object> = {
label: string;
key: (value: TEntity) => HistoryEntityKey;
format?: (value: TEntity, context: HistoryFormatContext<TEntity>) => string;
};export type HistoryEngineOptions = {
positionLabel?: string;
showUnchanged?: boolean;
};export type HistoryEntityForDefinition<TDefinition> = TDefinition extends HistoryDefinition<infer TEntity, z.ZodTypeAny> ? TEntity : never;export type HistoryEntityKey = string | number;export type HistoryEntityKind = string;export type HistoryFieldConfig<TValue, TParent> = false | HistoryAtomicFieldConfig<TValue, TParent> | HistoryArrayFieldConfig<TValue, TParent> | HistoryObjectFieldConfig<TValue>;export type HistoryFieldRow = {
type: "removed";
path: HistoryPath;
label: string;
previous: HistoryValue;
} | {
type: "updated";
path: HistoryPath;
label: string;
previous: HistoryValue;
current: HistoryValue;
} | {
type: "added";
path: HistoryPath;
label: string;
current: HistoryValue;
} | {
type: "moved";
path: HistoryPath;
label: string;
previous: HistoryValue;
current: HistoryValue;
} | {
type: "unchanged";
path: HistoryPath;
label: string;
current: HistoryValue;
};export type HistoryFormatContext<TParent> = {
parent: NonNullable<TParent>;
side: HistoryValueSide;
path: HistoryPath;
};export type HistoryGroupChangeType = "added" | "updated" | "removed" | "unchanged";export type HistoryGroupNode = {
type: "group";
path: HistoryPath;
label: string;
value?: HistoryValue;
changeType: HistoryGroupChangeType;
children: HistoryNode[];
};export type HistoryNode = HistoryFieldRow | HistoryGroupNode;export type HistoryObjectFieldConfig<TValue> = NonNullable<TValue> extends object ? NonNullable<TValue> extends readonly unknown[] ? never : {
kind: "object";
definition: HistoryDefinition<NonNullable<TValue>>;
} : never;export type HistoryPath = readonly HistoryPathSegment[];export type HistoryPathSegment = string | number;export interface HistoryRecord<TSnapshot extends HistorySnapshot = HistorySnapshot, TEntityKind extends HistoryEntityKind = HistoryEntityKind, TTimestamp extends HistoryTimestamp = HistoryTimestamp> {
id: string;
timestamp: TTimestamp;
actor: HistoryActor | null;
entity: TEntityKind;
entityId: string;
snapshotPrevious: TSnapshot | null;
snapshotCurrent: TSnapshot | null;
}export declare const HistoryRecordSchema: z.ZodType<HistoryRecord<Record<string, unknown>, string, HistoryTimestamp>, unknown, z.core.$ZodTypeInternals<HistoryRecord<Record<string, unknown>, string, HistoryTimestamp>, unknown>>;export type HistoryRecordSchemaOptions<TEntityKind extends HistoryEntityKind = HistoryEntityKind, TSnapshot extends HistorySnapshot = HistorySnapshot, TTimestamp extends HistoryTimestamp = HistoryTimestamp> = {
entityKind?: z.ZodType<TEntityKind>;
snapshot?: z.ZodType<TSnapshot>;
timestamp?: z.ZodType<TTimestamp>;
};export type HistorySnapshot = z.infer<typeof HistorySnapshotSchema>;export declare const HistorySnapshotSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;export type HistoryTimestamp = number | string;export declare const HistoryTimestampSchema: z.ZodUnion<readonly [
z.ZodNumber,
z.ZodString
]>;export type HistoryValue = {
raw: unknown;
formatted: string;
};export type HistoryValueSide = "previous" | "current";export declare function createHistoryDefinition<TSchema extends z.ZodTypeAny>(schema: TSchema, options: HistoryDefinitionOptions<HistoryObjectForSchema<TSchema>>, fields: HistoryDefinitionFields<HistoryObjectForSchema<TSchema>>): HistoryDefinition<HistoryObjectForSchema<TSchema>, TSchema>;export declare function createHistoryNodes<TEntity extends object, TSchema extends z.ZodTypeAny>(definition: HistoryDefinition<TEntity, TSchema>, previous: NoInfer<TEntity> | null | undefined, current: NoInfer<TEntity> | null | undefined, options?: HistoryEngineOptions): HistoryNode[];export declare function createHistoryRecordSchema<TEntityKind extends HistoryEntityKind = HistoryEntityKind, TSnapshot extends HistorySnapshot = HistorySnapshot, TTimestamp extends HistoryTimestamp = HistoryTimestamp>(options?: HistoryRecordSchemaOptions<TEntityKind, TSnapshot, TTimestamp>): z.ZodType<HistoryRecord<TSnapshot, TEntityKind, TTimestamp>>;