doxum 0.1.23 → 0.1.26

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 +208 -102
  2. package/dist/advanced.cjs +237 -2
  3. package/dist/advanced.cjs.map +1 -0
  4. package/dist/advanced.d.cts +90 -2
  5. package/dist/advanced.d.ts +90 -2
  6. package/dist/advanced.js +236 -1
  7. package/dist/advanced.js.map +1 -0
  8. package/dist/{contract-ULPQmiEs.d.ts → contract-CNR6BS75.d.cts} +216 -30
  9. package/dist/{contract-SYJFP0lM.d.cts → contract-COgxO5sv.d.ts} +216 -30
  10. package/dist/definition-CDOuvb5C.d.cts +111 -0
  11. package/dist/definition-xgk3YNBp.d.ts +111 -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 +65 -33
  19. package/dist/index.d.ts +65 -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 +6 -3
  43. package/skills/doxum-runtime/SKILL.md +32 -7
  44. package/skills/doxum-runtime/agents/openai.yaml +1 -1
  45. package/skills/doxum-runtime/references/api.en.md +249 -0
  46. package/skills/doxum-runtime/references/api.zh-CN.md +242 -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 +209 -119
  54. package/skills/doxum-runtime/references/projections.zh-CN.md +200 -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,66 @@ 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 objectSchema: unique symbol;
89
+ /** Portable public schema handle. The definition parameter carries compile-time shape only. */
90
+ type Schema<T = unknown, Definition = unknown> = {
91
+ readonly [schemaType]: {
92
+ readonly value: T;
93
+ readonly definition: Definition;
94
+ };
95
+ };
96
+ type PublicSchemaShape = {
97
+ readonly [key: string]: Schema<unknown, unknown>;
98
+ };
99
+ type ObjectSchema<T extends object = object, Shape extends PublicSchemaShape = PublicSchemaShape> = Schema<T, {
100
+ readonly kind: 'object';
101
+ readonly shape: Shape;
102
+ }> & {
103
+ readonly [objectSchema]: true;
104
+ };
105
+ type SchemaDefinitionOf<S extends Schema<unknown, unknown>> = S extends Schema<unknown, infer Definition> ? Definition : unknown;
106
+ type Optionalized<N extends DocumentNode, Optional extends boolean> = Optional extends true ? OptionalNode<N> : N;
107
+ type FieldNodeFor<TValue, Optional extends boolean> = Optional extends true ? FieldNode<TValue, true> : FieldNode<TValue, false>;
108
+ type TreeNodeFor<TValue, ValueOptional extends boolean> = ValueOptional extends true ? TreeNode<TValue, true> : TreeNode<TValue, false>;
109
+ type SchemaNodeFromDefinition<Definition> = Definition extends {
110
+ readonly kind: 'field';
111
+ readonly value: infer TValue;
112
+ readonly optional: infer Optional extends boolean;
113
+ } ? FieldNodeFor<TValue, Optional> : Definition extends {
114
+ readonly kind: 'object';
115
+ readonly shape: infer Shape extends PublicSchemaShape;
116
+ } ? ObjectNode<NodeShapeOf<Shape>> : Definition extends {
117
+ readonly kind: 'variant';
118
+ readonly tag: infer Tag extends string;
119
+ readonly variants: infer Variants extends PublicVariantShape;
120
+ readonly optional: infer Optional extends boolean;
121
+ } ? Optionalized<VariantNode<Tag, VariantNodeShapeOf<Variants>>, Optional> : Definition extends {
122
+ readonly kind: 'table';
123
+ readonly value: infer Value extends Schema<unknown, unknown>;
124
+ readonly key: infer Key extends string;
125
+ } ? TableNode<Extract<SchemaNodeOf<Value>, EntitySchemaNode>, Key> : Definition extends {
126
+ readonly kind: 'map';
127
+ readonly value: infer Value extends Schema<unknown, unknown>;
128
+ readonly key: infer Key extends string;
129
+ readonly optional: infer Optional extends boolean;
130
+ } ? Optionalized<MapNode<Extract<SchemaNodeOf<Value>, ValueSchemaNode>, Key>, Optional> : Definition extends {
131
+ readonly kind: 'list';
132
+ readonly value: infer TValue;
133
+ readonly optional: infer Optional extends boolean;
134
+ } ? Optionalized<ListNode<TValue>, Optional> : Definition extends {
135
+ readonly kind: 'tree';
136
+ readonly value: infer TValue;
137
+ readonly valueOptional: infer ValueOptional extends boolean;
138
+ readonly optional: infer Optional extends boolean;
139
+ } ? Optionalized<TreeNodeFor<TValue, ValueOptional>, Optional> : DocumentNode;
140
+ type SchemaNodeOf<S extends Schema<unknown, unknown>> = SchemaNodeFromDefinition<SchemaDefinitionOf<S>>;
87
141
  type SchemaObject<T> = { [K in keyof T]: T[K] } & {};
88
142
  /** Infer a document or node value, including optional node presence. */
89
- type Infer<T extends DocumentNode> = T extends {
143
+ type InferNode<T extends DocumentNode> = T extends {
90
144
  readonly optional: true;
91
145
  } ? NodeValue<T> | undefined : NodeValue<T>;
146
+ type Infer<T extends Schema<unknown, unknown> | DocumentNode> = T extends Schema<infer TValue, unknown> ? TValue : T extends DocumentNode ? InferNode<T> : never;
92
147
  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
148
  readonly ids: readonly K[];
94
149
  readonly byId: Readonly<Record<K, NodeValue<V>>>;
@@ -98,6 +153,7 @@ type OptionalKeys<S extends ObjectShape> = { [K in keyof S]: S[K] extends {
98
153
  } ? K : never }[keyof S];
99
154
  type RequiredKeys<S extends ObjectShape> = Exclude<keyof S, OptionalKeys<S>>;
100
155
  type ShapeValue<S extends ObjectShape> = SchemaObject<{ readonly [K in RequiredKeys<S>]: NodeValue<S[K]> } & { readonly [K in OptionalKeys<S>]?: NodeValue<S[K]> }>;
156
+ type RootNodeOf<S extends ObjectSchema<object>> = Extract<SchemaNodeOf<S>, ObjectNode>;
101
157
  type EntitySchemaNode = ObjectNode<ObjectShape> | VariantNode<string, VariantShape>;
102
158
  type ValueSchemaNode = EntitySchemaNode | FieldNode<unknown, boolean>;
103
159
  type DocumentAnchor<K extends string = string> = {
@@ -107,6 +163,143 @@ type DocumentAnchor<K extends string = string> = {
107
163
  } | {
108
164
  readonly after: K;
109
165
  };
166
+ type NodeShapeOf<S extends PublicSchemaShape> = { readonly [K in keyof S]: SchemaNodeOf<S[K]> };
167
+ type PublicOptionalKeys<S extends PublicSchemaShape> = { [K in keyof S]: SchemaNodeOf<S[K]> extends {
168
+ readonly optional: true;
169
+ } ? K : never }[keyof S];
170
+ type PublicRequiredKeys<S extends PublicSchemaShape> = Exclude<keyof S, PublicOptionalKeys<S>>;
171
+ type PublicShapeValue<S extends PublicSchemaShape> = SchemaObject<{ readonly [K in PublicRequiredKeys<S>]: Infer<S[K]> } & { readonly [K in PublicOptionalKeys<S>]?: Infer<S[K]> }>;
172
+ type PublicVariantShape = {
173
+ readonly [key: string]: ObjectSchema<object>;
174
+ };
175
+ type VariantNodeShapeOf<V extends PublicVariantShape> = { readonly [K in keyof V]: Extract<SchemaNodeOf<V[K]>, ObjectNode> };
176
+ type FieldSchema<T, Optional extends boolean = boolean> = Schema<ReadonlyValue<T> | (Optional extends true ? undefined : never), {
177
+ readonly kind: 'field';
178
+ readonly value: T;
179
+ readonly optional: Optional;
180
+ }>;
181
+ type VariantSchema = Schema<unknown, {
182
+ readonly kind: 'variant';
183
+ readonly tag: string;
184
+ readonly variants: PublicVariantShape;
185
+ readonly optional: boolean;
186
+ }>;
187
+ type EntitySchema = ObjectSchema<object> | VariantSchema;
188
+ type ValueSchema = EntitySchema | FieldSchema<unknown>;
189
+ declare const field: <T>(validator?: Validator<T>) => Schema<ReadonlyValue<T>, {
190
+ readonly kind: "field";
191
+ readonly value: T;
192
+ readonly optional: false;
193
+ }>;
194
+ declare function optional<T, Optional extends boolean>(value: Schema<ReadonlyValue<T> | (Optional extends true ? undefined : never), {
195
+ readonly kind: 'field';
196
+ readonly value: T;
197
+ readonly optional: Optional;
198
+ }>): Schema<ReadonlyValue<T> | undefined, {
199
+ readonly kind: 'field';
200
+ readonly value: T;
201
+ readonly optional: true;
202
+ }>;
203
+ declare function optional<TValue, Tag extends string, Variants extends PublicVariantShape, Optional extends boolean>(value: Schema<TValue, {
204
+ readonly kind: 'variant';
205
+ readonly tag: Tag;
206
+ readonly variants: Variants;
207
+ readonly optional: Optional;
208
+ }>): Schema<TValue | undefined, {
209
+ readonly kind: 'variant';
210
+ readonly tag: Tag;
211
+ readonly variants: Variants;
212
+ readonly optional: true;
213
+ }>;
214
+ declare function optional<TValue, Value extends Schema<unknown, unknown>, Key extends string, Optional extends boolean>(value: Schema<TValue, {
215
+ readonly kind: 'map';
216
+ readonly value: Value;
217
+ readonly key: Key;
218
+ readonly optional: Optional;
219
+ }>): Schema<TValue | undefined, {
220
+ readonly kind: 'map';
221
+ readonly value: Value;
222
+ readonly key: Key;
223
+ readonly optional: true;
224
+ }>;
225
+ declare function optional<TValue, TItem, Optional extends boolean>(value: Schema<TValue, {
226
+ readonly kind: 'list';
227
+ readonly value: TItem;
228
+ readonly optional: Optional;
229
+ }>): Schema<TValue | undefined, {
230
+ readonly kind: 'list';
231
+ readonly value: TItem;
232
+ readonly optional: true;
233
+ }>;
234
+ declare function optional<TValue, TNodeValue, ValueOptional extends boolean, Optional extends boolean>(value: Schema<TValue, {
235
+ readonly kind: 'tree';
236
+ readonly value: TNodeValue;
237
+ readonly valueOptional: ValueOptional;
238
+ readonly optional: Optional;
239
+ }>): Schema<TValue | undefined, {
240
+ readonly kind: 'tree';
241
+ readonly value: TNodeValue;
242
+ readonly valueOptional: ValueOptional;
243
+ readonly optional: true;
244
+ }>;
245
+ declare const object: <S extends PublicSchemaShape>(shape: S) => ObjectSchema<PublicShapeValue<S>, S>;
246
+ declare const variant: <T extends string, V extends PublicVariantShape>(tag: T, variants: V) => Schema<{ [K in keyof V & string]: SchemaObject<{ readonly [P in T]: K } & Infer<V[K]>> }[keyof V & string], {
247
+ readonly kind: "variant";
248
+ readonly tag: T;
249
+ readonly variants: V;
250
+ readonly optional: false;
251
+ }>;
252
+ declare const table: <V extends EntitySchema, K extends string = string>(value: V, options?: {
253
+ readonly key: Validator<K>;
254
+ }) => Schema<{
255
+ readonly ids: readonly K[];
256
+ readonly byId: Readonly<Record<K, Exclude<Infer<V>, undefined>>>;
257
+ }, {
258
+ readonly kind: "table";
259
+ readonly value: V;
260
+ readonly key: K;
261
+ }>;
262
+ declare const map: <V extends ValueSchema, K extends string = string>(value: V, options?: {
263
+ readonly key: Validator<K>;
264
+ }) => Schema<Readonly<Record<K, V extends Schema<infer TValue, infer Definition> ? Definition extends {
265
+ readonly kind: "field";
266
+ } ? TValue : Exclude<TValue, undefined> : never>>, {
267
+ readonly kind: "map";
268
+ readonly value: V;
269
+ readonly key: K;
270
+ readonly optional: false;
271
+ }>;
272
+ declare const list: <TItem>(value: Schema<ReadonlyValue<TItem>, {
273
+ readonly kind: "field";
274
+ readonly value: TItem;
275
+ readonly optional: false;
276
+ }>, config: DocumentListConfig<TItem>) => Schema<readonly ReadonlyValue<TItem>[], {
277
+ readonly kind: "list";
278
+ readonly value: TItem;
279
+ readonly optional: false;
280
+ }>;
281
+ declare function tree<TValue>(value: Schema<ReadonlyValue<TValue>, {
282
+ readonly kind: 'field';
283
+ readonly value: TValue;
284
+ readonly optional: false;
285
+ }>): Schema<DocumentTreeValue<TValue, false>, {
286
+ readonly kind: 'tree';
287
+ readonly value: TValue;
288
+ readonly valueOptional: false;
289
+ readonly optional: false;
290
+ }>;
291
+ declare function tree<TValue>(value: Schema<ReadonlyValue<TValue> | undefined, {
292
+ readonly kind: 'field';
293
+ readonly value: TValue;
294
+ readonly optional: true;
295
+ }>): Schema<DocumentTreeValue<TValue, true>, {
296
+ readonly kind: 'tree';
297
+ readonly value: TValue;
298
+ readonly valueOptional: true;
299
+ readonly optional: false;
300
+ }>;
301
+ //#endregion
302
+ //#region core/src/schema/path.d.ts
110
303
  declare const pathValue: unique symbol;
111
304
  declare const collectionEntry: unique symbol;
112
305
  declare const collectionKey: unique symbol;
@@ -122,8 +315,8 @@ type NodeAbsent<N extends DocumentNode, ParentAbsent extends boolean> = Or<Paren
122
315
  } ? true : false>;
123
316
  type PathResult<N extends DocumentNode, ParentAbsent extends boolean> = Infer<N> | (ParentAbsent extends true ? undefined : never);
124
317
  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>;
318
+ type SchemaPath<S extends ObjectSchema<object> = ObjectSchema<object>> = RootNodeOf<S> extends ObjectNode<infer Shape> ? SchemaPathFor<Shape, Infer<S>> : never;
319
+ type PathPick<S extends ObjectSchema<object> = ObjectSchema<object>> = (path: SchemaPath<S>) => PathMarker<unknown>;
127
320
  type VariantKeys<V extends VariantShape> = { [K in keyof V & string]: keyof (V[K] extends ObjectNode<infer S> ? S : {}) }[keyof V & string] & string;
128
321
  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
322
  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 +345,6 @@ type CollectionId<T> = CollectionInfo<T> extends {
152
345
  type CollectionEntry<T> = CollectionInfo<T> extends {
153
346
  readonly entry: infer TEntry;
154
347
  } ? 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
348
  //#endregion
169
349
  //#region core/src/schema/value.d.ts
170
350
  type ParseIssue = {
@@ -176,7 +356,7 @@ declare class ParseError extends TypeError {
176
356
  readonly issues: readonly ParseIssue[];
177
357
  constructor(issue: ParseIssue);
178
358
  }
179
- declare const parse: <N extends DocumentNode>(node: N, input: unknown) => Infer<N>;
359
+ declare const parse: <S extends Schema<unknown>>(schema: S, input: unknown) => Infer<S>;
180
360
  //#endregion
181
361
  //#region core/src/changes.d.ts
182
362
  type ValueTransition<T = unknown> = {
@@ -288,8 +468,9 @@ type NodeAccess<N extends DocumentNode, W extends boolean> = N extends FieldNode
288
468
  type Access<N extends DocumentNode, W extends boolean> = N extends {
289
469
  readonly optional: true;
290
470
  } ? 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>;
471
+ type AccessNode<S extends Schema<unknown> | DocumentNode> = S extends Schema<unknown> ? SchemaNodeOf<S> : Extract<S, DocumentNode>;
472
+ type Read<S extends Schema<unknown> | DocumentNode> = Access<AccessNode<S>, false>;
473
+ type Draft<S extends Schema<unknown> | DocumentNode> = Access<AccessNode<S>, true>;
293
474
  type Snapshot<T> = T extends {
294
475
  readonly [scopeValue]?: readonly [DocumentNode, boolean, infer V];
295
476
  } ? V : ReadonlyValue<T>;
@@ -312,10 +493,10 @@ type CollectionImpact<K> = {
312
493
  readonly updated: ReadonlySet<K>;
313
494
  readonly orderChanged: boolean;
314
495
  };
315
- type DocumentImpact<S extends ObjectNode> = {
496
+ type DocumentImpact<S extends ObjectSchema<object>> = {
316
497
  readonly kind: 'incremental' | 'reset';
317
498
  affects(pick: PathPick<S>): boolean;
318
- collection<P extends CollectionPath>(pick: (path: SchemaPath<S['shape']>) => P): CollectionImpact<CollectionId<P>>;
499
+ collection<P extends CollectionPath>(pick: (path: SchemaPath<S>) => P): CollectionImpact<CollectionId<P>>;
319
500
  };
320
501
  //#endregion
321
502
  //#region core/src/mutation/issue.d.ts
@@ -357,7 +538,7 @@ declare class TransactionRejected extends Error {
357
538
  readonly issues: readonly DocumentDiagnostic[];
358
539
  constructor(input: DiagnosticInput | readonly DiagnosticInput[]);
359
540
  }
360
- type DocumentCommit<S extends ObjectNode> = {
541
+ type DocumentCommit<S extends ObjectSchema<object>> = {
361
542
  readonly revision: number;
362
543
  readonly source: CommitSource;
363
544
  readonly changes: ChangeSet;
@@ -406,22 +587,27 @@ type LocalHistory<C> = Readable<HistoryState> & {
406
587
  cancel(): OperationResult<C>;
407
588
  };
408
589
  };
409
- type CommitListener<S extends ObjectNode> = (commit: DocumentCommit<S>) => void;
410
- type DocumentReadable<S extends ObjectNode> = {
590
+ type CommitListener<S extends ObjectSchema<object>> = (commit: DocumentCommit<S>) => void;
591
+ type ReadonlyDocument<S extends ObjectSchema<object>> = {
411
592
  revision(): number;
412
593
  subscribe(listener: CommitListener<S>): Unsubscribe;
413
594
  subscribe(pick: PathPick<S> | readonly [PathPick<S>, ...PathPick<S>[]], listener: CommitListener<S>): Unsubscribe;
414
595
  };
415
- type DocumentRuntime<S extends ObjectNode> = DocumentReadable<S> & {
596
+ type DocumentRuntime<S extends ObjectSchema<object>> = ReadonlyDocument<S> & {
416
597
  readonly schema: S;
598
+ readonly(): ReadonlyDocument<S>;
417
599
  update<V>(run: (draft: Draft<S>) => Synchronous<V>, options?: {
418
600
  readonly source?: Extract<CommitSource, 'local' | 'system'>;
419
601
  readonly history?: boolean;
420
602
  }): TransactionResult<V, DocumentCommit<S>>;
421
603
  apply(changes: unknown, options: {
422
604
  readonly expectedRevision: number;
423
- readonly source?: Exclude<CommitSource, 'history'>;
605
+ readonly source?: Extract<CommitSource, 'local' | 'system'>;
424
606
  readonly history?: boolean;
607
+ } | {
608
+ readonly expectedRevision: number;
609
+ readonly source: 'remote';
610
+ readonly history?: never;
425
611
  }): OperationResult<DocumentCommit<S>>;
426
612
  replace(value: Infer<S>, options?: {
427
613
  readonly source?: Extract<CommitSource, 'system' | 'remote'>;
@@ -431,5 +617,5 @@ type DocumentRuntime<S extends ObjectNode> = DocumentReadable<S> & {
431
617
  dispose(): void;
432
618
  };
433
619
  //#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
620
+ 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 };
621
+ //# sourceMappingURL=contract-COgxO5sv.d.ts.map
@@ -0,0 +1,111 @@
1
+ import { _ as Unsubscribe, b as CollectionImpact } from "./contract-CNR6BS75.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 keyedProjection: 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 projection whose output is a keyed collection with per-key change semantics. */
85
+ type KeyedProjection<K extends string, V> = Projection<ReadonlyMap<K, V>> & {
86
+ readonly [keyedProjection]: {
87
+ readonly key: K;
88
+ readonly value: V;
89
+ };
90
+ };
91
+ /** A writable source projection. */
92
+ type Input<T> = Projection<T> & {
93
+ readonly [writableInput]: true;
94
+ };
95
+ /** A writable keyed collection source projection. */
96
+ type CollectionInput<K extends string, V> = KeyedProjection<K, V> & {
97
+ readonly [writableCollectionInput]: {
98
+ readonly key: K;
99
+ readonly value: V;
100
+ };
101
+ };
102
+ type CollectionInputDraft<K extends string, V> = {
103
+ get(key: K): V | undefined;
104
+ has(key: K): boolean;
105
+ set(key: K, value: V): void;
106
+ remove(key: K): void;
107
+ };
108
+ type ProjectionChange<P> = P extends KeyedProjection<infer K, infer V> ? CollectionChange<K, V> : undefined;
109
+ //#endregion
110
+ export { Projection as a, CollectionDraft as c, ExternalCollectionRead as d, ExternalCollectionSource as f, ProjectionError as g, ProjectionDisposedError as h, KeyedProjection as i, CollectionRead as l, ExternalValueSource as m, CollectionInputDraft as n, ProjectionChange as o, ExternalValueEvent as p, Input as r, CollectionChange as s, CollectionInput as t, ExternalCollectionEvent as u };
111
+ //# sourceMappingURL=definition-CDOuvb5C.d.cts.map
@@ -0,0 +1,111 @@
1
+ import { _ as Unsubscribe, b as CollectionImpact } from "./contract-COgxO5sv.js";
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 keyedProjection: 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 projection whose output is a keyed collection with per-key change semantics. */
85
+ type KeyedProjection<K extends string, V> = Projection<ReadonlyMap<K, V>> & {
86
+ readonly [keyedProjection]: {
87
+ readonly key: K;
88
+ readonly value: V;
89
+ };
90
+ };
91
+ /** A writable source projection. */
92
+ type Input<T> = Projection<T> & {
93
+ readonly [writableInput]: true;
94
+ };
95
+ /** A writable keyed collection source projection. */
96
+ type CollectionInput<K extends string, V> = KeyedProjection<K, V> & {
97
+ readonly [writableCollectionInput]: {
98
+ readonly key: K;
99
+ readonly value: V;
100
+ };
101
+ };
102
+ type CollectionInputDraft<K extends string, V> = {
103
+ get(key: K): V | undefined;
104
+ has(key: K): boolean;
105
+ set(key: K, value: V): void;
106
+ remove(key: K): void;
107
+ };
108
+ type ProjectionChange<P> = P extends KeyedProjection<infer K, infer V> ? CollectionChange<K, V> : undefined;
109
+ //#endregion
110
+ export { Projection as a, CollectionDraft as c, ExternalCollectionRead as d, ExternalCollectionSource as f, ProjectionError as g, ProjectionDisposedError as h, KeyedProjection as i, CollectionRead as l, ExternalValueSource as m, CollectionInputDraft as n, ProjectionChange as o, ExternalValueEvent as p, Input as r, CollectionChange as s, CollectionInput as t, ExternalCollectionEvent as u };
111
+ //# sourceMappingURL=definition-xgk3YNBp.d.ts.map
@@ -1,4 +1,49 @@
1
- import { n as contextOf, s as validNode, u as isPlainObject } from "./context-DFEaDUv5.js";
1
+ import { n as isPlainObject, r as isRecord } from "./record-B2yRhYsc.js";
2
+ //#region core/src/tree/topology.ts
3
+ const node = (tree, id) => Object.hasOwn(tree.nodes, id) ? tree.nodes[id] : void 0;
4
+ const is = (value) => isRecord(value) && isRecord(value.nodes);
5
+ const validNode = (value) => {
6
+ if (!isRecord(value) || !Array.isArray(value.children)) return false;
7
+ if (value.parentId !== void 0 && typeof value.parentId !== "string") return false;
8
+ const children = /* @__PURE__ */ new Set();
9
+ for (const id of value.children) {
10
+ if (typeof id !== "string" || children.has(id)) return false;
11
+ children.add(id);
12
+ }
13
+ return true;
14
+ };
15
+ const contains = (tree, id) => Object.hasOwn(tree.nodes, id);
16
+ const parent = (tree, id) => node(tree, id)?.parentId;
17
+ const children = (tree, id) => node(tree, id)?.children;
18
+ const validate = (value) => {
19
+ if (!is(value)) return false;
20
+ const ids = Object.keys(value.nodes);
21
+ if (ids.length === 0) return value.rootId === void 0;
22
+ if (typeof value.rootId !== "string" || !Object.hasOwn(value.nodes, value.rootId)) return false;
23
+ for (const id of ids) {
24
+ const entry = value.nodes[id];
25
+ if (!validNode(entry)) return false;
26
+ if (id === value.rootId) {
27
+ if (entry.parentId !== void 0) return false;
28
+ } else if (entry.parentId === void 0 || !Object.hasOwn(value.nodes, entry.parentId)) return false;
29
+ for (const child of entry.children) {
30
+ const childNode = value.nodes[child];
31
+ if (!childNode || childNode.parentId !== id) return false;
32
+ }
33
+ }
34
+ const seen = /* @__PURE__ */ new Set();
35
+ const stack = [value.rootId];
36
+ while (stack.length) {
37
+ const id = stack.pop();
38
+ if (seen.has(id)) return false;
39
+ seen.add(id);
40
+ const entry = value.nodes[id];
41
+ if (!entry) return false;
42
+ for (const child of entry.children) stack.push(child);
43
+ }
44
+ return seen.size === ids.length;
45
+ };
46
+ //#endregion
2
47
  //#region core/src/mutation/issue.ts
3
48
  const at = (address, code, message) => Object.freeze({
4
49
  source: "mutation",
@@ -296,6 +341,17 @@ const changeCount = (changes) => {
296
341
  return count;
297
342
  };
298
343
  //#endregion
344
+ //#region core/src/runtime/context.ts
345
+ const contexts = /* @__PURE__ */ new WeakMap();
346
+ const bindContext = (subject, context) => {
347
+ contexts.set(subject, context);
348
+ };
349
+ function contextOf(subject, required = true) {
350
+ const context = contexts.get(subject);
351
+ if (!context && required) throw new Error("Unknown Doxum runtime.");
352
+ return context;
353
+ }
354
+ //#endregion
299
355
  //#region core/src/runtime/driver.ts
300
356
  const assertRuntimeWritable = (runtime, intent) => {
301
357
  const context = contextOf(runtime);
@@ -324,6 +380,6 @@ const installRuntimeWriteDriver = (runtime, driver) => {
324
380
  });
325
381
  };
326
382
  //#endregion
327
- export { sealChanges as a, fail as c, decodeChanges as i, invalidValue as l, installRuntimeWriteDriver as n, AddressIndex as o, changeCount as r, MutationRejected as s, assertRuntimeWritable as t };
383
+ export { changeCount as a, AddressIndex as c, invalidValue as d, children as f, validate as g, parent as h, contextOf as i, MutationRejected as l, is as m, installRuntimeWriteDriver as n, decodeChanges as o, contains as p, bindContext as r, sealChanges as s, assertRuntimeWritable as t, fail as u };
328
384
 
329
- //# sourceMappingURL=driver-yFfvDMX5.js.map
385
+ //# sourceMappingURL=driver-B5vdPohL.js.map