doxum 0.1.23 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +198 -102
  2. package/dist/advanced.cjs +237 -2
  3. package/dist/advanced.cjs.map +1 -0
  4. package/dist/advanced.d.cts +98 -2
  5. package/dist/advanced.d.ts +98 -2
  6. package/dist/advanced.js +236 -1
  7. package/dist/advanced.js.map +1 -0
  8. package/dist/{contract-ULPQmiEs.d.ts → contract-DB8XvNt0.d.cts} +89 -30
  9. package/dist/{contract-SYJFP0lM.d.cts → contract-Dawq6LKS.d.ts} +89 -30
  10. package/dist/definition-CHVS-RDY.d.cts +110 -0
  11. package/dist/definition-DT1NpMul.d.ts +110 -0
  12. package/dist/{driver-yFfvDMX5.js → driver-B5vdPohL.js} +59 -3
  13. package/dist/driver-B5vdPohL.js.map +1 -0
  14. package/dist/{driver-BD3DQOW6.cjs → driver-BL91gn7_.cjs} +107 -9
  15. package/dist/driver-BL91gn7_.cjs.map +1 -0
  16. package/dist/index.cjs +1637 -703
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +66 -33
  19. package/dist/index.d.ts +66 -33
  20. package/dist/index.js +1432 -497
  21. package/dist/index.js.map +1 -1
  22. package/dist/local-sync.cjs +69 -103
  23. package/dist/local-sync.cjs.map +1 -1
  24. package/dist/local-sync.d.cts +14 -26
  25. package/dist/local-sync.d.ts +14 -26
  26. package/dist/local-sync.js +68 -96
  27. package/dist/local-sync.js.map +1 -1
  28. package/dist/react.cjs +4 -5
  29. package/dist/react.cjs.map +1 -1
  30. package/dist/react.d.cts +6 -8
  31. package/dist/react.d.ts +6 -8
  32. package/dist/react.js +4 -5
  33. package/dist/react.js.map +1 -1
  34. package/dist/record-B2yRhYsc.js +28 -0
  35. package/dist/record-B2yRhYsc.js.map +1 -0
  36. package/dist/record-ChYUi8PP.cjs +45 -0
  37. package/dist/record-ChYUi8PP.cjs.map +1 -0
  38. package/dist/scheduler--137L3j-.js +500 -0
  39. package/dist/scheduler--137L3j-.js.map +1 -0
  40. package/dist/scheduler-D4VthaaK.cjs +589 -0
  41. package/dist/scheduler-D4VthaaK.cjs.map +1 -0
  42. package/package.json +5 -3
  43. package/skills/doxum-runtime/SKILL.md +26 -7
  44. package/skills/doxum-runtime/agents/openai.yaml +1 -1
  45. package/skills/doxum-runtime/references/api.en.md +243 -0
  46. package/skills/doxum-runtime/references/api.zh-CN.md +236 -0
  47. package/skills/doxum-runtime/references/guide.en.md +18 -8
  48. package/skills/doxum-runtime/references/guide.zh-CN.md +14 -6
  49. package/skills/doxum-runtime/references/invariants.en.md +29 -5
  50. package/skills/doxum-runtime/references/invariants.zh-CN.md +24 -6
  51. package/skills/doxum-runtime/references/patterns.en.md +78 -18
  52. package/skills/doxum-runtime/references/patterns.zh-CN.md +76 -18
  53. package/skills/doxum-runtime/references/projections.en.md +206 -119
  54. package/skills/doxum-runtime/references/projections.zh-CN.md +197 -101
  55. package/dist/advanced-CLJCWkHa.d.cts +0 -176
  56. package/dist/advanced-CRNHfJBu.js +0 -1224
  57. package/dist/advanced-CRNHfJBu.js.map +0 -1
  58. package/dist/advanced-Cle5g3B4.cjs +0 -1517
  59. package/dist/advanced-Cle5g3B4.cjs.map +0 -1
  60. package/dist/advanced-d6J61er9.d.ts +0 -176
  61. package/dist/context-BcLKGfq8.cjs +0 -149
  62. package/dist/context-BcLKGfq8.cjs.map +0 -1
  63. package/dist/context-DFEaDUv5.js +0 -84
  64. package/dist/context-DFEaDUv5.js.map +0 -1
  65. package/dist/driver-BD3DQOW6.cjs.map +0 -1
  66. package/dist/driver-yFfvDMX5.js.map +0 -1
@@ -1,7 +1,7 @@
1
- //#region core/src/schema.d.ts
1
+ //#region core/src/schema/model.d.ts
2
2
  type DocumentAddress = readonly string[];
3
3
  /** Pure synchronous validation. Successful output is ignored; input is never transformed. */
4
- type Validator<T> = ((value: unknown) => T) | {
4
+ type Validator<T> = ((value: unknown) => value is T) | ((value: unknown) => asserts value is T) | {
5
5
  readonly '~standard': {
6
6
  readonly version: 1;
7
7
  readonly vendor: string;
@@ -84,11 +84,24 @@ type TreeNode<TValue, ValueOptional extends boolean = false> = BaseNode<'tree'>
84
84
  readonly value: FieldNode<TValue, ValueOptional>;
85
85
  };
86
86
  type DocumentNode = FieldNode<unknown, false> | FieldNode<unknown, true> | ObjectNode<ObjectShape> | VariantNode<string, VariantShape> | TableNode<ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> | MapNode<ValueSchemaNode> | ListNode<unknown> | TreeNode<unknown, false> | TreeNode<unknown, true>;
87
+ declare const schemaType: unique symbol;
88
+ declare const schemaNode: unique symbol;
89
+ declare const objectSchema: unique symbol;
90
+ type Schema<T = unknown> = {
91
+ readonly [schemaType]: T;
92
+ };
93
+ type ObjectSchema<T extends object = object> = Schema<T> & {
94
+ readonly [objectSchema]: true;
95
+ };
96
+ type SchemaNodeOf<S extends Schema<unknown>> = S extends {
97
+ readonly [schemaNode]: infer N extends DocumentNode;
98
+ } ? N : S extends ObjectSchema<object> ? ObjectNode : DocumentNode;
87
99
  type SchemaObject<T> = { [K in keyof T]: T[K] } & {};
88
100
  /** Infer a document or node value, including optional node presence. */
89
- type Infer<T extends DocumentNode> = T extends {
101
+ type InferNode<T extends DocumentNode> = T extends {
90
102
  readonly optional: true;
91
103
  } ? NodeValue<T> | undefined : NodeValue<T>;
104
+ type Infer<T extends Schema<unknown> | DocumentNode> = T extends Schema<infer TValue> ? TValue : T extends DocumentNode ? InferNode<T> : never;
92
105
  type NodeValue<N> = N extends FieldNode<infer T, infer O> ? O extends true ? ReadonlyValue<T> | undefined : ReadonlyValue<T> : N extends ObjectNode<infer S> ? ShapeValue<S> : N extends VariantNode<infer T, infer V> ? { [K in keyof V & string]: SchemaObject<{ readonly [P in T]: K } & NodeValue<V[K]>> }[keyof V & string] : N extends TableNode<infer V, infer K> ? {
93
106
  readonly ids: readonly K[];
94
107
  readonly byId: Readonly<Record<K, NodeValue<V>>>;
@@ -98,6 +111,7 @@ type OptionalKeys<S extends ObjectShape> = { [K in keyof S]: S[K] extends {
98
111
  } ? K : never }[keyof S];
99
112
  type RequiredKeys<S extends ObjectShape> = Exclude<keyof S, OptionalKeys<S>>;
100
113
  type ShapeValue<S extends ObjectShape> = SchemaObject<{ readonly [K in RequiredKeys<S>]: NodeValue<S[K]> } & { readonly [K in OptionalKeys<S>]?: NodeValue<S[K]> }>;
114
+ type RootNodeOf<S extends ObjectSchema<object>> = Extract<SchemaNodeOf<S>, ObjectNode>;
101
115
  type EntitySchemaNode = ObjectNode<ObjectShape> | VariantNode<string, VariantShape>;
102
116
  type ValueSchemaNode = EntitySchemaNode | FieldNode<unknown, boolean>;
103
117
  type DocumentAnchor<K extends string = string> = {
@@ -107,6 +121,58 @@ type DocumentAnchor<K extends string = string> = {
107
121
  } | {
108
122
  readonly after: K;
109
123
  };
124
+ type SchemaHandle<N extends DocumentNode> = Schema<InferNode<N>> & {
125
+ readonly [schemaNode]: N;
126
+ };
127
+ type PublicSchemaShape = {
128
+ readonly [key: string]: Schema<unknown>;
129
+ };
130
+ type NodeShapeOf<S extends PublicSchemaShape> = { readonly [K in keyof S]: SchemaNodeOf<S[K]> };
131
+ type PublicOptionalKeys<S extends PublicSchemaShape> = { [K in keyof S]: SchemaNodeOf<S[K]> extends {
132
+ readonly optional: true;
133
+ } ? K : never }[keyof S];
134
+ type PublicRequiredKeys<S extends PublicSchemaShape> = Exclude<keyof S, PublicOptionalKeys<S>>;
135
+ type PublicShapeValue<S extends PublicSchemaShape> = SchemaObject<{ readonly [K in PublicRequiredKeys<S>]: Infer<S[K]> } & { readonly [K in PublicOptionalKeys<S>]?: Infer<S[K]> }>;
136
+ type ObjectSchemaHandle<S extends PublicSchemaShape> = ObjectSchema<PublicShapeValue<S>> & {
137
+ readonly [schemaNode]: ObjectNode<NodeShapeOf<S>>;
138
+ };
139
+ type FieldSchemaHandle<T> = SchemaHandle<FieldNode<T, false>>;
140
+ type OptionalFieldSchemaHandle<T> = SchemaHandle<FieldNode<T, true>>;
141
+ type OptionalSchemaHandle = Schema<unknown> & {
142
+ readonly [schemaNode]: OptionalLeaf;
143
+ };
144
+ type EntitySchemaHandle = Schema<unknown> & {
145
+ readonly [schemaNode]: EntitySchemaNode;
146
+ };
147
+ type ValueSchemaHandle = Schema<unknown> & {
148
+ readonly [schemaNode]: ValueSchemaNode;
149
+ };
150
+ type PublicVariantShape = {
151
+ readonly [key: string]: ObjectSchema<object>;
152
+ };
153
+ type VariantNodeShapeOf<V extends PublicVariantShape> = { readonly [K in keyof V]: Extract<SchemaNodeOf<V[K]>, ObjectNode> };
154
+ type VariantSchemaHandle<T extends string, V extends PublicVariantShape> = Schema<{ [K in keyof V & string]: SchemaObject<{ readonly [P in T]: K } & Infer<V[K]>> }[keyof V & string]> & {
155
+ readonly [schemaNode]: VariantNode<T, VariantNodeShapeOf<V>>;
156
+ };
157
+ type OptionalLeaf = FieldNode<unknown, boolean> | VariantNode<string, VariantShape> | MapNode<ValueSchemaNode> | ListNode<unknown> | TreeNode<unknown, false> | TreeNode<unknown, true>;
158
+ type OptionalResult<T extends OptionalSchemaHandle> = SchemaHandle<OptionalNode<Extract<SchemaNodeOf<T>, OptionalLeaf>>>;
159
+ type EntityNodeOf<V extends EntitySchemaHandle> = Extract<SchemaNodeOf<V>, EntitySchemaNode>;
160
+ type ValueNodeOf<V extends ValueSchemaHandle> = Extract<SchemaNodeOf<V>, ValueSchemaNode>;
161
+ declare const field: <T>(validator?: Validator<T>) => FieldSchemaHandle<T>;
162
+ declare const optional: <T extends OptionalSchemaHandle>(value: T) => OptionalResult<T>;
163
+ declare const object: <S extends PublicSchemaShape>(shape: S) => ObjectSchemaHandle<S>;
164
+ declare const variant: <T extends string, V extends PublicVariantShape>(tag: T, variants: V) => VariantSchemaHandle<T, V>;
165
+ declare const table: <V extends EntitySchemaHandle, K extends string = string>(value: V, options?: {
166
+ readonly key: Validator<K>;
167
+ }) => SchemaHandle<TableNode<EntityNodeOf<V>, K>>;
168
+ declare const map: <V extends ValueSchemaHandle, K extends string = string>(value: V, options?: {
169
+ readonly key: Validator<K>;
170
+ }) => SchemaHandle<MapNode<ValueNodeOf<V>, K>>;
171
+ declare const list: <TItem>(value: FieldSchemaHandle<TItem>, config: DocumentListConfig<TItem>) => SchemaHandle<ListNode<TItem>>;
172
+ declare function tree<TValue>(value: FieldSchemaHandle<TValue>): SchemaHandle<TreeNode<TValue, false>>;
173
+ declare function tree<TValue>(value: OptionalFieldSchemaHandle<TValue>): SchemaHandle<TreeNode<TValue, true>>;
174
+ //#endregion
175
+ //#region core/src/schema/path.d.ts
110
176
  declare const pathValue: unique symbol;
111
177
  declare const collectionEntry: unique symbol;
112
178
  declare const collectionKey: unique symbol;
@@ -122,8 +188,8 @@ type NodeAbsent<N extends DocumentNode, ParentAbsent extends boolean> = Or<Paren
122
188
  } ? true : false>;
123
189
  type PathResult<N extends DocumentNode, ParentAbsent extends boolean> = Infer<N> | (ParentAbsent extends true ? undefined : never);
124
190
  type SchemaPathFor<S extends ObjectShape = ObjectShape, TValue = unknown, Absent extends boolean = false> = { readonly [K in keyof S]: PathValue<S[K], Absent> } & PathMarker<TValue | (Absent extends true ? undefined : never)>;
125
- type SchemaPath<S extends ObjectShape = ObjectShape> = SchemaPathFor<S, ShapeValue<S>>;
126
- type PathPick<S extends ObjectNode = ObjectNode> = (path: SchemaPath<S['shape']>) => PathMarker<unknown>;
191
+ type SchemaPath<S extends ObjectSchema<object> = ObjectSchema<object>> = RootNodeOf<S> extends ObjectNode<infer Shape> ? SchemaPathFor<Shape, Infer<S>> : never;
192
+ type PathPick<S extends ObjectSchema<object> = ObjectSchema<object>> = (path: SchemaPath<S>) => PathMarker<unknown>;
127
193
  type VariantKeys<V extends VariantShape> = { [K in keyof V & string]: keyof (V[K] extends ObjectNode<infer S> ? S : {}) }[keyof V & string] & string;
128
194
  type VariantFieldMissing<V extends VariantShape, K extends string> = { [P in keyof V & string]: V[P] extends ObjectNode<infer S> ? (K extends keyof S ? never : P) : P }[keyof V & string] extends never ? false : true;
129
195
  type VariantFieldPath<V extends VariantShape, K extends string, Absent extends boolean> = { [P in keyof V & string]: V[P] extends ObjectNode<infer S> ? K extends keyof S ? PathValue<S[K], Or<Absent, VariantFieldMissing<V, K>>> : never : never }[keyof V & string];
@@ -152,19 +218,6 @@ type CollectionId<T> = CollectionInfo<T> extends {
152
218
  type CollectionEntry<T> = CollectionInfo<T> extends {
153
219
  readonly entry: infer TEntry;
154
220
  } ? TEntry : unknown;
155
- declare const field: <T>(validator?: Validator<T>) => FieldNode<T>;
156
- type OptionalLeaf = FieldNode<unknown, boolean> | VariantNode<string, VariantShape> | MapNode<ValueSchemaNode> | ListNode<unknown> | TreeNode<unknown, false> | TreeNode<unknown, true>;
157
- declare const optional: <T extends OptionalLeaf>(value: T) => OptionalNode<T>;
158
- declare const object: <S extends ObjectShape>(shape: S) => ObjectNode<S>;
159
- declare const variant: <T extends string, V extends VariantShape>(tag: T, variants: V) => VariantNode<T, V>;
160
- declare const table: <V extends EntitySchemaNode, K extends string = string>(value: V, options?: {
161
- readonly key: Validator<K>;
162
- }) => TableNode<V, K>;
163
- declare const map: <V extends ValueSchemaNode, K extends string = string>(value: V, options?: {
164
- readonly key: Validator<K>;
165
- }) => MapNode<V, K>;
166
- declare const list: <TItem>(value: FieldNode<TItem, false>, config: DocumentListConfig<TItem>) => ListNode<TItem>;
167
- declare const tree: <TValue, ValueOptional extends boolean>(value: FieldNode<TValue, ValueOptional>) => TreeNode<TValue, ValueOptional>;
168
221
  //#endregion
169
222
  //#region core/src/schema/value.d.ts
170
223
  type ParseIssue = {
@@ -176,7 +229,7 @@ declare class ParseError extends TypeError {
176
229
  readonly issues: readonly ParseIssue[];
177
230
  constructor(issue: ParseIssue);
178
231
  }
179
- declare const parse: <N extends DocumentNode>(node: N, input: unknown) => Infer<N>;
232
+ declare const parse: <S extends Schema<unknown>>(schema: S, input: unknown) => Infer<S>;
180
233
  //#endregion
181
234
  //#region core/src/changes.d.ts
182
235
  type ValueTransition<T = unknown> = {
@@ -288,8 +341,9 @@ type NodeAccess<N extends DocumentNode, W extends boolean> = N extends FieldNode
288
341
  type Access<N extends DocumentNode, W extends boolean> = N extends {
289
342
  readonly optional: true;
290
343
  } ? NodeAccess<N, W> | undefined : NodeAccess<N, W>;
291
- type Read<N extends DocumentNode> = Access<N, false>;
292
- type Draft<N extends DocumentNode> = Access<N, true>;
344
+ type AccessNode<S extends Schema<unknown> | DocumentNode> = S extends Schema<unknown> ? SchemaNodeOf<S> : Extract<S, DocumentNode>;
345
+ type Read<S extends Schema<unknown> | DocumentNode> = Access<AccessNode<S>, false>;
346
+ type Draft<S extends Schema<unknown> | DocumentNode> = Access<AccessNode<S>, true>;
293
347
  type Snapshot<T> = T extends {
294
348
  readonly [scopeValue]?: readonly [DocumentNode, boolean, infer V];
295
349
  } ? V : ReadonlyValue<T>;
@@ -312,10 +366,10 @@ type CollectionImpact<K> = {
312
366
  readonly updated: ReadonlySet<K>;
313
367
  readonly orderChanged: boolean;
314
368
  };
315
- type DocumentImpact<S extends ObjectNode> = {
369
+ type DocumentImpact<S extends ObjectSchema<object>> = {
316
370
  readonly kind: 'incremental' | 'reset';
317
371
  affects(pick: PathPick<S>): boolean;
318
- collection<P extends CollectionPath>(pick: (path: SchemaPath<S['shape']>) => P): CollectionImpact<CollectionId<P>>;
372
+ collection<P extends CollectionPath>(pick: (path: SchemaPath<S>) => P): CollectionImpact<CollectionId<P>>;
319
373
  };
320
374
  //#endregion
321
375
  //#region core/src/mutation/issue.d.ts
@@ -357,7 +411,7 @@ declare class TransactionRejected extends Error {
357
411
  readonly issues: readonly DocumentDiagnostic[];
358
412
  constructor(input: DiagnosticInput | readonly DiagnosticInput[]);
359
413
  }
360
- type DocumentCommit<S extends ObjectNode> = {
414
+ type DocumentCommit<S extends ObjectSchema<object>> = {
361
415
  readonly revision: number;
362
416
  readonly source: CommitSource;
363
417
  readonly changes: ChangeSet;
@@ -406,22 +460,27 @@ type LocalHistory<C> = Readable<HistoryState> & {
406
460
  cancel(): OperationResult<C>;
407
461
  };
408
462
  };
409
- type CommitListener<S extends ObjectNode> = (commit: DocumentCommit<S>) => void;
410
- type DocumentReadable<S extends ObjectNode> = {
463
+ type CommitListener<S extends ObjectSchema<object>> = (commit: DocumentCommit<S>) => void;
464
+ type ReadonlyDocument<S extends ObjectSchema<object>> = {
411
465
  revision(): number;
412
466
  subscribe(listener: CommitListener<S>): Unsubscribe;
413
467
  subscribe(pick: PathPick<S> | readonly [PathPick<S>, ...PathPick<S>[]], listener: CommitListener<S>): Unsubscribe;
414
468
  };
415
- type DocumentRuntime<S extends ObjectNode> = DocumentReadable<S> & {
469
+ type DocumentRuntime<S extends ObjectSchema<object>> = ReadonlyDocument<S> & {
416
470
  readonly schema: S;
471
+ readonly(): ReadonlyDocument<S>;
417
472
  update<V>(run: (draft: Draft<S>) => Synchronous<V>, options?: {
418
473
  readonly source?: Extract<CommitSource, 'local' | 'system'>;
419
474
  readonly history?: boolean;
420
475
  }): TransactionResult<V, DocumentCommit<S>>;
421
476
  apply(changes: unknown, options: {
422
477
  readonly expectedRevision: number;
423
- readonly source?: Exclude<CommitSource, 'history'>;
478
+ readonly source?: Extract<CommitSource, 'local' | 'system'>;
424
479
  readonly history?: boolean;
480
+ } | {
481
+ readonly expectedRevision: number;
482
+ readonly source: 'remote';
483
+ readonly history?: never;
425
484
  }): OperationResult<DocumentCommit<S>>;
426
485
  replace(value: Infer<S>, options?: {
427
486
  readonly source?: Extract<CommitSource, 'system' | 'remote'>;
@@ -431,5 +490,5 @@ type DocumentRuntime<S extends ObjectNode> = DocumentReadable<S> & {
431
490
  dispose(): void;
432
491
  };
433
492
  //#endregion
434
- export { TreeNode as $, ParseError as A, DocumentTreeNode as B, Read as C, ChangeSet as D, Change as E, CollectionPath as F, MapNode as G, FieldNode as H, DocumentAddress as I, OptionalNode as J, ObjectNode as K, DocumentAnchor as L, parse as M, CollectionEntry as N, MemberChange as O, CollectionId as P, TableNode as Q, DocumentListConfig as R, Draft as S, snapshot as T, Infer as U, DocumentTreeValue as V, ListNode as W, ReadonlyValue as X, PathValueOf as Y, SchemaPath as Z, Unsubscribe as _, DocumentProblem as a, map as at, CollectionImpact as b, DocumentRuntime as c, table as ct, ObserverError as d, Validator as et, OperationResult as f, Readable as g, TransactionResult as h, DocumentDisposedError as i, list as it, ParseIssue as j, ValueTransition as k, HistoryState as l, tree as lt, TransactionRejected as m, DocumentCommit as n, VariantShape as nt, DocumentReadable as o, object as ot, Synchronous as p, ObjectShape as q, DocumentDiagnostic as r, field as rt, DocumentReentrancyError as s, optional as st, CommitSource as t, VariantNode as tt, LocalHistory as u, variant as ut, MutationIssue as v, replace as w, DocumentImpact as x, MutationIssueCode as y, DocumentNode as z };
435
- //# sourceMappingURL=contract-ULPQmiEs.d.ts.map
493
+ export { table as $, ParseError as A, DocumentListConfig as B, Read as C, ChangeSet as D, Change as E, CollectionPath as F, ReadonlyValue as G, DocumentTreeValue as H, PathValueOf as I, field as J, Schema as K, SchemaPath as L, parse as M, CollectionEntry as N, MemberChange as O, CollectionId as P, optional as Q, DocumentAddress as R, Draft as S, snapshot as T, Infer as U, DocumentTreeNode as V, ObjectSchema as W, map as X, list as Y, object as Z, Unsubscribe as _, DocumentProblem as a, CollectionImpact as b, HistoryState as c, OperationResult as d, tree as et, ReadonlyDocument as f, Readable as g, TransactionResult as h, DocumentDisposedError as i, ParseIssue as j, ValueTransition as k, LocalHistory as l, TransactionRejected as m, DocumentCommit as n, DocumentReentrancyError as o, Synchronous as p, Validator as q, DocumentDiagnostic as r, DocumentRuntime as s, CommitSource as t, variant as tt, ObserverError as u, MutationIssue as v, replace as w, DocumentImpact as x, MutationIssueCode as y, DocumentAnchor as z };
494
+ //# sourceMappingURL=contract-DB8XvNt0.d.cts.map
@@ -1,7 +1,7 @@
1
- //#region core/src/schema.d.ts
1
+ //#region core/src/schema/model.d.ts
2
2
  type DocumentAddress = readonly string[];
3
3
  /** Pure synchronous validation. Successful output is ignored; input is never transformed. */
4
- type Validator<T> = ((value: unknown) => T) | {
4
+ type Validator<T> = ((value: unknown) => value is T) | ((value: unknown) => asserts value is T) | {
5
5
  readonly '~standard': {
6
6
  readonly version: 1;
7
7
  readonly vendor: string;
@@ -84,11 +84,24 @@ type TreeNode<TValue, ValueOptional extends boolean = false> = BaseNode<'tree'>
84
84
  readonly value: FieldNode<TValue, ValueOptional>;
85
85
  };
86
86
  type DocumentNode = FieldNode<unknown, false> | FieldNode<unknown, true> | ObjectNode<ObjectShape> | VariantNode<string, VariantShape> | TableNode<ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> | MapNode<ValueSchemaNode> | ListNode<unknown> | TreeNode<unknown, false> | TreeNode<unknown, true>;
87
+ declare const schemaType: unique symbol;
88
+ declare const schemaNode: unique symbol;
89
+ declare const objectSchema: unique symbol;
90
+ type Schema<T = unknown> = {
91
+ readonly [schemaType]: T;
92
+ };
93
+ type ObjectSchema<T extends object = object> = Schema<T> & {
94
+ readonly [objectSchema]: true;
95
+ };
96
+ type SchemaNodeOf<S extends Schema<unknown>> = S extends {
97
+ readonly [schemaNode]: infer N extends DocumentNode;
98
+ } ? N : S extends ObjectSchema<object> ? ObjectNode : DocumentNode;
87
99
  type SchemaObject<T> = { [K in keyof T]: T[K] } & {};
88
100
  /** Infer a document or node value, including optional node presence. */
89
- type Infer<T extends DocumentNode> = T extends {
101
+ type InferNode<T extends DocumentNode> = T extends {
90
102
  readonly optional: true;
91
103
  } ? NodeValue<T> | undefined : NodeValue<T>;
104
+ type Infer<T extends Schema<unknown> | DocumentNode> = T extends Schema<infer TValue> ? TValue : T extends DocumentNode ? InferNode<T> : never;
92
105
  type NodeValue<N> = N extends FieldNode<infer T, infer O> ? O extends true ? ReadonlyValue<T> | undefined : ReadonlyValue<T> : N extends ObjectNode<infer S> ? ShapeValue<S> : N extends VariantNode<infer T, infer V> ? { [K in keyof V & string]: SchemaObject<{ readonly [P in T]: K } & NodeValue<V[K]>> }[keyof V & string] : N extends TableNode<infer V, infer K> ? {
93
106
  readonly ids: readonly K[];
94
107
  readonly byId: Readonly<Record<K, NodeValue<V>>>;
@@ -98,6 +111,7 @@ type OptionalKeys<S extends ObjectShape> = { [K in keyof S]: S[K] extends {
98
111
  } ? K : never }[keyof S];
99
112
  type RequiredKeys<S extends ObjectShape> = Exclude<keyof S, OptionalKeys<S>>;
100
113
  type ShapeValue<S extends ObjectShape> = SchemaObject<{ readonly [K in RequiredKeys<S>]: NodeValue<S[K]> } & { readonly [K in OptionalKeys<S>]?: NodeValue<S[K]> }>;
114
+ type RootNodeOf<S extends ObjectSchema<object>> = Extract<SchemaNodeOf<S>, ObjectNode>;
101
115
  type EntitySchemaNode = ObjectNode<ObjectShape> | VariantNode<string, VariantShape>;
102
116
  type ValueSchemaNode = EntitySchemaNode | FieldNode<unknown, boolean>;
103
117
  type DocumentAnchor<K extends string = string> = {
@@ -107,6 +121,58 @@ type DocumentAnchor<K extends string = string> = {
107
121
  } | {
108
122
  readonly after: K;
109
123
  };
124
+ type SchemaHandle<N extends DocumentNode> = Schema<InferNode<N>> & {
125
+ readonly [schemaNode]: N;
126
+ };
127
+ type PublicSchemaShape = {
128
+ readonly [key: string]: Schema<unknown>;
129
+ };
130
+ type NodeShapeOf<S extends PublicSchemaShape> = { readonly [K in keyof S]: SchemaNodeOf<S[K]> };
131
+ type PublicOptionalKeys<S extends PublicSchemaShape> = { [K in keyof S]: SchemaNodeOf<S[K]> extends {
132
+ readonly optional: true;
133
+ } ? K : never }[keyof S];
134
+ type PublicRequiredKeys<S extends PublicSchemaShape> = Exclude<keyof S, PublicOptionalKeys<S>>;
135
+ type PublicShapeValue<S extends PublicSchemaShape> = SchemaObject<{ readonly [K in PublicRequiredKeys<S>]: Infer<S[K]> } & { readonly [K in PublicOptionalKeys<S>]?: Infer<S[K]> }>;
136
+ type ObjectSchemaHandle<S extends PublicSchemaShape> = ObjectSchema<PublicShapeValue<S>> & {
137
+ readonly [schemaNode]: ObjectNode<NodeShapeOf<S>>;
138
+ };
139
+ type FieldSchemaHandle<T> = SchemaHandle<FieldNode<T, false>>;
140
+ type OptionalFieldSchemaHandle<T> = SchemaHandle<FieldNode<T, true>>;
141
+ type OptionalSchemaHandle = Schema<unknown> & {
142
+ readonly [schemaNode]: OptionalLeaf;
143
+ };
144
+ type EntitySchemaHandle = Schema<unknown> & {
145
+ readonly [schemaNode]: EntitySchemaNode;
146
+ };
147
+ type ValueSchemaHandle = Schema<unknown> & {
148
+ readonly [schemaNode]: ValueSchemaNode;
149
+ };
150
+ type PublicVariantShape = {
151
+ readonly [key: string]: ObjectSchema<object>;
152
+ };
153
+ type VariantNodeShapeOf<V extends PublicVariantShape> = { readonly [K in keyof V]: Extract<SchemaNodeOf<V[K]>, ObjectNode> };
154
+ type VariantSchemaHandle<T extends string, V extends PublicVariantShape> = Schema<{ [K in keyof V & string]: SchemaObject<{ readonly [P in T]: K } & Infer<V[K]>> }[keyof V & string]> & {
155
+ readonly [schemaNode]: VariantNode<T, VariantNodeShapeOf<V>>;
156
+ };
157
+ type OptionalLeaf = FieldNode<unknown, boolean> | VariantNode<string, VariantShape> | MapNode<ValueSchemaNode> | ListNode<unknown> | TreeNode<unknown, false> | TreeNode<unknown, true>;
158
+ type OptionalResult<T extends OptionalSchemaHandle> = SchemaHandle<OptionalNode<Extract<SchemaNodeOf<T>, OptionalLeaf>>>;
159
+ type EntityNodeOf<V extends EntitySchemaHandle> = Extract<SchemaNodeOf<V>, EntitySchemaNode>;
160
+ type ValueNodeOf<V extends ValueSchemaHandle> = Extract<SchemaNodeOf<V>, ValueSchemaNode>;
161
+ declare const field: <T>(validator?: Validator<T>) => FieldSchemaHandle<T>;
162
+ declare const optional: <T extends OptionalSchemaHandle>(value: T) => OptionalResult<T>;
163
+ declare const object: <S extends PublicSchemaShape>(shape: S) => ObjectSchemaHandle<S>;
164
+ declare const variant: <T extends string, V extends PublicVariantShape>(tag: T, variants: V) => VariantSchemaHandle<T, V>;
165
+ declare const table: <V extends EntitySchemaHandle, K extends string = string>(value: V, options?: {
166
+ readonly key: Validator<K>;
167
+ }) => SchemaHandle<TableNode<EntityNodeOf<V>, K>>;
168
+ declare const map: <V extends ValueSchemaHandle, K extends string = string>(value: V, options?: {
169
+ readonly key: Validator<K>;
170
+ }) => SchemaHandle<MapNode<ValueNodeOf<V>, K>>;
171
+ declare const list: <TItem>(value: FieldSchemaHandle<TItem>, config: DocumentListConfig<TItem>) => SchemaHandle<ListNode<TItem>>;
172
+ declare function tree<TValue>(value: FieldSchemaHandle<TValue>): SchemaHandle<TreeNode<TValue, false>>;
173
+ declare function tree<TValue>(value: OptionalFieldSchemaHandle<TValue>): SchemaHandle<TreeNode<TValue, true>>;
174
+ //#endregion
175
+ //#region core/src/schema/path.d.ts
110
176
  declare const pathValue: unique symbol;
111
177
  declare const collectionEntry: unique symbol;
112
178
  declare const collectionKey: unique symbol;
@@ -122,8 +188,8 @@ type NodeAbsent<N extends DocumentNode, ParentAbsent extends boolean> = Or<Paren
122
188
  } ? true : false>;
123
189
  type PathResult<N extends DocumentNode, ParentAbsent extends boolean> = Infer<N> | (ParentAbsent extends true ? undefined : never);
124
190
  type SchemaPathFor<S extends ObjectShape = ObjectShape, TValue = unknown, Absent extends boolean = false> = { readonly [K in keyof S]: PathValue<S[K], Absent> } & PathMarker<TValue | (Absent extends true ? undefined : never)>;
125
- type SchemaPath<S extends ObjectShape = ObjectShape> = SchemaPathFor<S, ShapeValue<S>>;
126
- type PathPick<S extends ObjectNode = ObjectNode> = (path: SchemaPath<S['shape']>) => PathMarker<unknown>;
191
+ type SchemaPath<S extends ObjectSchema<object> = ObjectSchema<object>> = RootNodeOf<S> extends ObjectNode<infer Shape> ? SchemaPathFor<Shape, Infer<S>> : never;
192
+ type PathPick<S extends ObjectSchema<object> = ObjectSchema<object>> = (path: SchemaPath<S>) => PathMarker<unknown>;
127
193
  type VariantKeys<V extends VariantShape> = { [K in keyof V & string]: keyof (V[K] extends ObjectNode<infer S> ? S : {}) }[keyof V & string] & string;
128
194
  type VariantFieldMissing<V extends VariantShape, K extends string> = { [P in keyof V & string]: V[P] extends ObjectNode<infer S> ? (K extends keyof S ? never : P) : P }[keyof V & string] extends never ? false : true;
129
195
  type VariantFieldPath<V extends VariantShape, K extends string, Absent extends boolean> = { [P in keyof V & string]: V[P] extends ObjectNode<infer S> ? K extends keyof S ? PathValue<S[K], Or<Absent, VariantFieldMissing<V, K>>> : never : never }[keyof V & string];
@@ -152,19 +218,6 @@ type CollectionId<T> = CollectionInfo<T> extends {
152
218
  type CollectionEntry<T> = CollectionInfo<T> extends {
153
219
  readonly entry: infer TEntry;
154
220
  } ? TEntry : unknown;
155
- declare const field: <T>(validator?: Validator<T>) => FieldNode<T>;
156
- type OptionalLeaf = FieldNode<unknown, boolean> | VariantNode<string, VariantShape> | MapNode<ValueSchemaNode> | ListNode<unknown> | TreeNode<unknown, false> | TreeNode<unknown, true>;
157
- declare const optional: <T extends OptionalLeaf>(value: T) => OptionalNode<T>;
158
- declare const object: <S extends ObjectShape>(shape: S) => ObjectNode<S>;
159
- declare const variant: <T extends string, V extends VariantShape>(tag: T, variants: V) => VariantNode<T, V>;
160
- declare const table: <V extends EntitySchemaNode, K extends string = string>(value: V, options?: {
161
- readonly key: Validator<K>;
162
- }) => TableNode<V, K>;
163
- declare const map: <V extends ValueSchemaNode, K extends string = string>(value: V, options?: {
164
- readonly key: Validator<K>;
165
- }) => MapNode<V, K>;
166
- declare const list: <TItem>(value: FieldNode<TItem, false>, config: DocumentListConfig<TItem>) => ListNode<TItem>;
167
- declare const tree: <TValue, ValueOptional extends boolean>(value: FieldNode<TValue, ValueOptional>) => TreeNode<TValue, ValueOptional>;
168
221
  //#endregion
169
222
  //#region core/src/schema/value.d.ts
170
223
  type ParseIssue = {
@@ -176,7 +229,7 @@ declare class ParseError extends TypeError {
176
229
  readonly issues: readonly ParseIssue[];
177
230
  constructor(issue: ParseIssue);
178
231
  }
179
- declare const parse: <N extends DocumentNode>(node: N, input: unknown) => Infer<N>;
232
+ declare const parse: <S extends Schema<unknown>>(schema: S, input: unknown) => Infer<S>;
180
233
  //#endregion
181
234
  //#region core/src/changes.d.ts
182
235
  type ValueTransition<T = unknown> = {
@@ -288,8 +341,9 @@ type NodeAccess<N extends DocumentNode, W extends boolean> = N extends FieldNode
288
341
  type Access<N extends DocumentNode, W extends boolean> = N extends {
289
342
  readonly optional: true;
290
343
  } ? NodeAccess<N, W> | undefined : NodeAccess<N, W>;
291
- type Read<N extends DocumentNode> = Access<N, false>;
292
- type Draft<N extends DocumentNode> = Access<N, true>;
344
+ type AccessNode<S extends Schema<unknown> | DocumentNode> = S extends Schema<unknown> ? SchemaNodeOf<S> : Extract<S, DocumentNode>;
345
+ type Read<S extends Schema<unknown> | DocumentNode> = Access<AccessNode<S>, false>;
346
+ type Draft<S extends Schema<unknown> | DocumentNode> = Access<AccessNode<S>, true>;
293
347
  type Snapshot<T> = T extends {
294
348
  readonly [scopeValue]?: readonly [DocumentNode, boolean, infer V];
295
349
  } ? V : ReadonlyValue<T>;
@@ -312,10 +366,10 @@ type CollectionImpact<K> = {
312
366
  readonly updated: ReadonlySet<K>;
313
367
  readonly orderChanged: boolean;
314
368
  };
315
- type DocumentImpact<S extends ObjectNode> = {
369
+ type DocumentImpact<S extends ObjectSchema<object>> = {
316
370
  readonly kind: 'incremental' | 'reset';
317
371
  affects(pick: PathPick<S>): boolean;
318
- collection<P extends CollectionPath>(pick: (path: SchemaPath<S['shape']>) => P): CollectionImpact<CollectionId<P>>;
372
+ collection<P extends CollectionPath>(pick: (path: SchemaPath<S>) => P): CollectionImpact<CollectionId<P>>;
319
373
  };
320
374
  //#endregion
321
375
  //#region core/src/mutation/issue.d.ts
@@ -357,7 +411,7 @@ declare class TransactionRejected extends Error {
357
411
  readonly issues: readonly DocumentDiagnostic[];
358
412
  constructor(input: DiagnosticInput | readonly DiagnosticInput[]);
359
413
  }
360
- type DocumentCommit<S extends ObjectNode> = {
414
+ type DocumentCommit<S extends ObjectSchema<object>> = {
361
415
  readonly revision: number;
362
416
  readonly source: CommitSource;
363
417
  readonly changes: ChangeSet;
@@ -406,22 +460,27 @@ type LocalHistory<C> = Readable<HistoryState> & {
406
460
  cancel(): OperationResult<C>;
407
461
  };
408
462
  };
409
- type CommitListener<S extends ObjectNode> = (commit: DocumentCommit<S>) => void;
410
- type DocumentReadable<S extends ObjectNode> = {
463
+ type CommitListener<S extends ObjectSchema<object>> = (commit: DocumentCommit<S>) => void;
464
+ type ReadonlyDocument<S extends ObjectSchema<object>> = {
411
465
  revision(): number;
412
466
  subscribe(listener: CommitListener<S>): Unsubscribe;
413
467
  subscribe(pick: PathPick<S> | readonly [PathPick<S>, ...PathPick<S>[]], listener: CommitListener<S>): Unsubscribe;
414
468
  };
415
- type DocumentRuntime<S extends ObjectNode> = DocumentReadable<S> & {
469
+ type DocumentRuntime<S extends ObjectSchema<object>> = ReadonlyDocument<S> & {
416
470
  readonly schema: S;
471
+ readonly(): ReadonlyDocument<S>;
417
472
  update<V>(run: (draft: Draft<S>) => Synchronous<V>, options?: {
418
473
  readonly source?: Extract<CommitSource, 'local' | 'system'>;
419
474
  readonly history?: boolean;
420
475
  }): TransactionResult<V, DocumentCommit<S>>;
421
476
  apply(changes: unknown, options: {
422
477
  readonly expectedRevision: number;
423
- readonly source?: Exclude<CommitSource, 'history'>;
478
+ readonly source?: Extract<CommitSource, 'local' | 'system'>;
424
479
  readonly history?: boolean;
480
+ } | {
481
+ readonly expectedRevision: number;
482
+ readonly source: 'remote';
483
+ readonly history?: never;
425
484
  }): OperationResult<DocumentCommit<S>>;
426
485
  replace(value: Infer<S>, options?: {
427
486
  readonly source?: Extract<CommitSource, 'system' | 'remote'>;
@@ -431,5 +490,5 @@ type DocumentRuntime<S extends ObjectNode> = DocumentReadable<S> & {
431
490
  dispose(): void;
432
491
  };
433
492
  //#endregion
434
- export { TreeNode as $, ParseError as A, DocumentTreeNode as B, Read as C, ChangeSet as D, Change as E, CollectionPath as F, MapNode as G, FieldNode as H, DocumentAddress as I, OptionalNode as J, ObjectNode as K, DocumentAnchor as L, parse as M, CollectionEntry as N, MemberChange as O, CollectionId as P, TableNode as Q, DocumentListConfig as R, Draft as S, snapshot as T, Infer as U, DocumentTreeValue as V, ListNode as W, ReadonlyValue as X, PathValueOf as Y, SchemaPath as Z, Unsubscribe as _, DocumentProblem as a, map as at, CollectionImpact as b, DocumentRuntime as c, table as ct, ObserverError as d, Validator as et, OperationResult as f, Readable as g, TransactionResult as h, DocumentDisposedError as i, list as it, ParseIssue as j, ValueTransition as k, HistoryState as l, tree as lt, TransactionRejected as m, DocumentCommit as n, VariantShape as nt, DocumentReadable as o, object as ot, Synchronous as p, ObjectShape as q, DocumentDiagnostic as r, field as rt, DocumentReentrancyError as s, optional as st, CommitSource as t, VariantNode as tt, LocalHistory as u, variant as ut, MutationIssue as v, replace as w, DocumentImpact as x, MutationIssueCode as y, DocumentNode as z };
435
- //# sourceMappingURL=contract-SYJFP0lM.d.cts.map
493
+ export { table as $, ParseError as A, DocumentListConfig as B, Read as C, ChangeSet as D, Change as E, CollectionPath as F, ReadonlyValue as G, DocumentTreeValue as H, PathValueOf as I, field as J, Schema as K, SchemaPath as L, parse as M, CollectionEntry as N, MemberChange as O, CollectionId as P, optional as Q, DocumentAddress as R, Draft as S, snapshot as T, Infer as U, DocumentTreeNode as V, ObjectSchema as W, map as X, list as Y, object as Z, Unsubscribe as _, DocumentProblem as a, CollectionImpact as b, HistoryState as c, OperationResult as d, tree as et, ReadonlyDocument as f, Readable as g, TransactionResult as h, DocumentDisposedError as i, ParseIssue as j, ValueTransition as k, LocalHistory as l, TransactionRejected as m, DocumentCommit as n, DocumentReentrancyError as o, Synchronous as p, Validator as q, DocumentDiagnostic as r, DocumentRuntime as s, CommitSource as t, variant as tt, ObserverError as u, MutationIssue as v, replace as w, DocumentImpact as x, MutationIssueCode as y, DocumentAnchor as z };
494
+ //# sourceMappingURL=contract-Dawq6LKS.d.ts.map
@@ -0,0 +1,110 @@
1
+ import { _ as Unsubscribe, b as CollectionImpact } from "./contract-DB8XvNt0.cjs";
2
+
3
+ //#region core/src/projection/contract.d.ts
4
+ /** The one processor-facing collection transition protocol. */
5
+ type CollectionChange<K extends string, V> = {
6
+ readonly kind: 'reset';
7
+ } | {
8
+ readonly kind: 'incremental';
9
+ readonly added: readonly {
10
+ readonly key: K;
11
+ readonly after: V;
12
+ }[];
13
+ readonly updated: readonly {
14
+ readonly key: K;
15
+ readonly before: V;
16
+ readonly after: V;
17
+ }[];
18
+ readonly removed: readonly {
19
+ readonly key: K;
20
+ readonly before: V;
21
+ }[];
22
+ readonly order?: {
23
+ readonly before: readonly K[];
24
+ readonly after: readonly K[];
25
+ };
26
+ };
27
+ type CollectionRead<K extends string, V> = {
28
+ get(key: K): V | undefined;
29
+ has(key: K): boolean;
30
+ ids(): readonly K[];
31
+ };
32
+ type ExternalCollectionRead<K extends string, V> = {
33
+ readonly get: (key: K) => V | undefined;
34
+ readonly has: (key: K) => boolean;
35
+ readonly ids: () => readonly K[];
36
+ };
37
+ type ExternalValueSource<T> = {
38
+ readonly kind: 'value';
39
+ current(): T;
40
+ revision(): number;
41
+ subscribe(listener: (event: ExternalValueEvent<T>) => void): Unsubscribe;
42
+ };
43
+ type ExternalCollectionSource<K extends string, V> = {
44
+ readonly kind: 'collection';
45
+ current(): ExternalCollectionRead<K, V>;
46
+ revision(): number;
47
+ subscribe(listener: (event: ExternalCollectionEvent<K, V>) => void): Unsubscribe;
48
+ };
49
+ type ExternalValueEvent<T> = {
50
+ readonly value: T;
51
+ readonly revision: number;
52
+ readonly reset?: boolean;
53
+ readonly cause?: unknown;
54
+ };
55
+ type ExternalCollectionEvent<K extends string, V> = {
56
+ /** Stable read from the source before this event or external batch. */readonly previous: ExternalCollectionRead<K, V>;
57
+ readonly revision: number; /** Optional document-style hint; the adapter resolves the canonical change. */
58
+ readonly impact?: CollectionImpact<K>;
59
+ readonly cause?: unknown;
60
+ };
61
+ type CollectionDraft<K extends string, V> = {
62
+ set(key: K, value: V): void;
63
+ remove(key: K): void;
64
+ order(ids: readonly K[]): void;
65
+ };
66
+ declare class ProjectionError extends Error {
67
+ readonly phase: 'processor' | 'listener' | 'source' | 'blocked';
68
+ readonly cause: unknown;
69
+ constructor(phase: 'processor' | 'listener' | 'source' | 'blocked', cause: unknown);
70
+ }
71
+ declare class ProjectionDisposedError extends Error {
72
+ constructor();
73
+ }
74
+ //#endregion
75
+ //#region core/src/projection/definition.d.ts
76
+ declare const projectionDefinition: unique symbol;
77
+ declare const projectionChanges: unique symbol;
78
+ declare const writableInput: unique symbol;
79
+ declare const writableCollectionInput: unique symbol;
80
+ /** A lazy output reference with no materialized Runtime state. */
81
+ type Projection<T> = {
82
+ readonly [projectionDefinition]: T;
83
+ };
84
+ /** A writable source projection. */
85
+ type Input<T> = Projection<T> & {
86
+ readonly [writableInput]: true;
87
+ };
88
+ /** A writable keyed collection source projection. */
89
+ type CollectionInput<K extends string, V> = Projection<ReadonlyMap<K, V>> & {
90
+ readonly [writableCollectionInput]: {
91
+ readonly key: K;
92
+ readonly value: V;
93
+ };
94
+ readonly [projectionChanges]: CollectionChange<K, V>;
95
+ };
96
+ type CollectionInputDraft<K extends string, V> = {
97
+ get(key: K): V | undefined;
98
+ has(key: K): boolean;
99
+ set(key: K, value: V): void;
100
+ remove(key: K): void;
101
+ };
102
+ type ProjectionWithChange<T, C> = Projection<T> & {
103
+ readonly [projectionChanges]: C;
104
+ };
105
+ type ProjectionChange<P> = P extends {
106
+ readonly [projectionChanges]: infer C;
107
+ } ? C : undefined;
108
+ //#endregion
109
+ export { ProjectionChange as a, CollectionDraft as c, ExternalCollectionRead as d, ExternalCollectionSource as f, ProjectionError as g, ProjectionDisposedError as h, Projection as i, CollectionRead as l, ExternalValueSource as m, CollectionInputDraft as n, ProjectionWithChange as o, ExternalValueEvent as p, Input as r, CollectionChange as s, CollectionInput as t, ExternalCollectionEvent as u };
110
+ //# sourceMappingURL=definition-CHVS-RDY.d.cts.map