doxum 0.1.7 → 0.1.9

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 (70) hide show
  1. package/README.md +217 -296
  2. package/dist/contract-BNStLbSE.d.ts +441 -0
  3. package/dist/contract-CIU5FCC1.d.cts +441 -0
  4. package/dist/driver-BlR81Dqg.js +200 -0
  5. package/dist/driver-BlR81Dqg.js.map +1 -0
  6. package/dist/driver-xOIkwrB8.cjs +241 -0
  7. package/dist/driver-xOIkwrB8.cjs.map +1 -0
  8. package/dist/index.cjs +666 -2222
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +10 -20
  11. package/dist/index.d.ts +10 -18
  12. package/dist/index.js +634 -2189
  13. package/dist/index.js.map +1 -1
  14. package/dist/{integration-CZwCwFBS.cjs → integration-C87tjRop.cjs} +4 -9
  15. package/dist/integration-C87tjRop.cjs.map +1 -0
  16. package/dist/{integration-B56u1l9V.js → integration-D5XCBLJ8.js} +2 -7
  17. package/dist/integration-D5XCBLJ8.js.map +1 -0
  18. package/dist/integration.cjs +11 -11
  19. package/dist/integration.d.cts +10 -4
  20. package/dist/integration.d.ts +10 -4
  21. package/dist/integration.js +4 -3
  22. package/dist/issue-DVaGQGeP.js +576 -0
  23. package/dist/issue-DVaGQGeP.js.map +1 -0
  24. package/dist/issue-DhrNdQNg.cjs +797 -0
  25. package/dist/issue-DhrNdQNg.cjs.map +1 -0
  26. package/dist/local-sync.cjs +67 -39
  27. package/dist/local-sync.cjs.map +1 -1
  28. package/dist/local-sync.d.cts +10 -10
  29. package/dist/local-sync.d.ts +10 -10
  30. package/dist/local-sync.js +66 -38
  31. package/dist/local-sync.js.map +1 -1
  32. package/dist/react.cjs +23 -4
  33. package/dist/react.cjs.map +1 -1
  34. package/dist/react.d.cts +8 -3
  35. package/dist/react.d.ts +8 -3
  36. package/dist/react.js +21 -6
  37. package/dist/react.js.map +1 -1
  38. package/dist/store-1Uob0Ghk.cjs +2750 -0
  39. package/dist/store-1Uob0Ghk.cjs.map +1 -0
  40. package/dist/store-CD0KdGsq.d.cts +262 -0
  41. package/dist/store-D7QH6Rzw.js +2511 -0
  42. package/dist/store-D7QH6Rzw.js.map +1 -0
  43. package/dist/store-cp5CpfCy.d.ts +262 -0
  44. package/package.json +1 -1
  45. package/skills/doxum-runtime/SKILL.md +26 -44
  46. package/skills/doxum-runtime/references/guide.en.md +95 -359
  47. package/skills/doxum-runtime/references/guide.zh-CN.md +80 -285
  48. package/skills/doxum-runtime/references/invariants.en.md +42 -165
  49. package/skills/doxum-runtime/references/invariants.zh-CN.md +34 -97
  50. package/skills/doxum-runtime/references/patterns.en.md +73 -225
  51. package/skills/doxum-runtime/references/patterns.zh-CN.md +73 -179
  52. package/dist/chunk-pbuEa-1d.js +0 -13
  53. package/dist/contract-DNZ4D53r.d.ts +0 -563
  54. package/dist/contract-j3SLGAwh.d.cts +0 -563
  55. package/dist/driver-CNxqMVFH.cjs +0 -69
  56. package/dist/driver-CNxqMVFH.cjs.map +0 -1
  57. package/dist/driver-CbzfW5MR.js +0 -46
  58. package/dist/driver-CbzfW5MR.js.map +0 -1
  59. package/dist/integration-B56u1l9V.js.map +0 -1
  60. package/dist/integration-CZwCwFBS.cjs.map +0 -1
  61. package/dist/ownership-CY0nPXGF.cjs +0 -304
  62. package/dist/ownership-CY0nPXGF.cjs.map +0 -1
  63. package/dist/ownership-CduRygE7.js +0 -245
  64. package/dist/ownership-CduRygE7.js.map +0 -1
  65. package/dist/runtime-0mOFbe_H.cjs +0 -2439
  66. package/dist/runtime-0mOFbe_H.cjs.map +0 -1
  67. package/dist/runtime-B22tuj9A.d.cts +0 -150
  68. package/dist/runtime-BFmhzPpZ.d.ts +0 -150
  69. package/dist/runtime-DF1q9Gje.js +0 -2129
  70. package/dist/runtime-DF1q9Gje.js.map +0 -1
@@ -1,563 +0,0 @@
1
- //#region core/src/schema.d.ts
2
- type DocumentAddress = readonly string[];
3
- type DocumentListConfig<TItem> = {
4
- readonly keyOf: (item: TItem) => string;
5
- };
6
- type DocumentTreeNode<TValue> = {
7
- readonly parentId?: string;
8
- readonly children: readonly string[];
9
- readonly value?: TValue;
10
- };
11
- type DocumentTreeValue<TValue> = {
12
- readonly rootId?: string;
13
- readonly nodes: Readonly<Record<string, DocumentTreeNode<TValue>>>;
14
- };
15
- type BaseNode<K extends string> = {
16
- readonly kind: K;
17
- readonly optional?: boolean;
18
- };
19
- type FieldNode<T, Optional extends boolean = false> = BaseNode<'field'> & {
20
- readonly __value?: T;
21
- } & (Optional extends true ? {
22
- readonly optional: true;
23
- } : {
24
- readonly optional?: false;
25
- });
26
- /** A node with optional presence. The marker replaces, rather than intersects, a field marker. */
27
- type OptionalNode<TNode extends DocumentNode> = TNode extends FieldNode<infer TValue, boolean> ? FieldNode<TValue, true> : TNode & {
28
- readonly optional: true;
29
- };
30
- interface ObjectShape {
31
- readonly [key: string]: DocumentNode;
32
- }
33
- type ObjectNode<TShape extends ObjectShape> = BaseNode<'object'> & {
34
- readonly shape: TShape;
35
- };
36
- interface VariantShape {
37
- readonly [key: string]: ObjectNode<ObjectShape>;
38
- }
39
- type VariantNode<TTag extends string, TVariants extends VariantShape> = BaseNode<'variant'> & {
40
- readonly tag: TTag;
41
- readonly variants: TVariants;
42
- };
43
- type TableNode<TValue extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> = BaseNode<'table'> & {
44
- readonly value: TValue;
45
- };
46
- type MapNode<TValue extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> = BaseNode<'map'> & {
47
- readonly value: TValue;
48
- };
49
- type DictNode<TKey extends string, TValue> = BaseNode<'dict'> & {
50
- readonly __key?: TKey;
51
- readonly __value?: TValue;
52
- };
53
- type ListNode<TItem> = BaseNode<'list'> & {
54
- readonly __item?: TItem;
55
- keyOf(item: TItem): string;
56
- };
57
- type TreeNode<TValue> = BaseNode<'tree'> & {
58
- readonly __value?: TValue;
59
- };
60
- type DocumentNode = FieldNode<unknown, false> | FieldNode<unknown, true> | ObjectNode<ObjectShape> | VariantNode<string, VariantShape> | TableNode<ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> | MapNode<ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> | DictNode<string, unknown> | ListNode<unknown> | TreeNode<unknown>;
61
- type EntityValue<N extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> = N extends ObjectNode<infer S> ? DocumentValueOfShape<S> : N extends VariantNode<infer T, infer V> ? { [K in keyof V & string]: { [P in T]: K } & DocumentValueOfShape<V[K] extends ObjectNode<infer S> ? S : never> }[keyof V & string] : never;
62
- type DocumentValueOfNode<N> = N extends FieldNode<infer T, infer O> ? O extends true ? T | undefined : T : N extends ObjectNode<infer S> ? DocumentValueOfShape<S> : N extends VariantNode<infer T, infer V> ? EntityValue<VariantNode<T, V>> : N extends TableNode<infer V> ? {
63
- readonly ids: readonly string[];
64
- readonly byId: Readonly<Record<string, EntityValue<V>>>;
65
- } : N extends MapNode<infer V> ? Readonly<Record<string, EntityValue<V>>> : N extends DictNode<infer K, infer T> ? Readonly<Partial<Record<K, T>>> : N extends ListNode<infer I> ? readonly I[] : N extends TreeNode<infer T> ? DocumentTreeValue<T> : never;
66
- type OptionalKeys<S extends ObjectShape> = { [K in keyof S]: S[K] extends {
67
- readonly optional: true;
68
- } ? K : never }[keyof S];
69
- type RequiredKeys<S extends ObjectShape> = Exclude<keyof S, OptionalKeys<S>>;
70
- type DocumentValueOfShape<S extends ObjectShape> = { readonly [K in RequiredKeys<S>]: DocumentValueOfNode<S[K]> } & { readonly [K in OptionalKeys<S>]?: DocumentValueOfNode<S[K]> };
71
- type ReadonlyDocument<S extends DocumentSchema> = DocumentValueOfShape<S['shape']>;
72
- type EntitySchemaNode = ObjectNode<ObjectShape> | VariantNode<string, VariantShape>;
73
- type CollectionSelector<TId extends string = string, TNode extends EntitySchemaNode = EntitySchemaNode> = {
74
- readonly kind: 'collection';
75
- readonly schema: DocumentSchema;
76
- readonly address: DocumentAddress;
77
- readonly __id?: TId; /** Compile-time entry schema carried by schema selectors. */
78
- readonly __node?: TNode;
79
- };
80
- type ValueSelector<TResult = unknown> = {
81
- readonly kind: 'value';
82
- readonly schema: DocumentSchema;
83
- readonly address: DocumentAddress;
84
- readonly __value?: TResult;
85
- };
86
- type ImpactTarget<T = unknown> = {
87
- readonly kind: 'value';
88
- readonly at: DocumentAddress;
89
- } | ValueSelector<T> | {
90
- readonly kind: 'collection';
91
- readonly at: DocumentAddress;
92
- readonly id?: string;
93
- } | CollectionSelector<string>;
94
- declare const pathValue: unique symbol;
95
- declare const collectionNode: unique symbol;
96
- type PathMarker<TValue> = {
97
- readonly [pathValue]: TValue;
98
- };
99
- type SchemaPathFor<S extends ObjectShape = ObjectShape, TValue = unknown> = { readonly [K in keyof S]: PathValue<S[K]> } & PathMarker<TValue>;
100
- type DocumentSchema<TShape extends ObjectShape = {}> = {
101
- readonly kind: 'schema';
102
- readonly shape: TShape;
103
- collection<TPath extends CollectionPath>(pick: (path: SchemaPath<TShape>) => TPath): CollectionSelector<CollectionId<TPath>, CollectionNode<TPath>>;
104
- value<TPath extends PathMarker<unknown>>(pick: (path: SchemaPath<TShape>) => TPath): ValueSelector<PathValueResult<TPath>>;
105
- };
106
- type SchemaPath<S extends ObjectShape = {}> = SchemaPathFor<S, DocumentValueOfShape<S>>;
107
- type VariantKeys<V extends VariantShape> = { [K in keyof V & string]: keyof (V[K] extends ObjectNode<infer S> ? S : {}) }[keyof V & string] & string;
108
- type VariantFieldPath<V extends VariantShape, K extends string> = { [P in keyof V & string]: V[P] extends ObjectNode<infer S> ? K extends keyof S ? PathValue<S[K]> : never : never }[keyof V & string];
109
- type VariantPath<T extends string, V extends VariantShape> = { readonly [K in VariantKeys<V>]: VariantFieldPath<V, K> } & { readonly [K in T]: PathMarker<keyof V & string> } & PathMarker<EntityValue<VariantNode<T, V>>>;
110
- type PathNodeValue<N extends DocumentNode> = N extends {
111
- readonly optional: true;
112
- } ? DocumentValueOfNode<N> | undefined : DocumentValueOfNode<N>;
113
- type EntityPath<N extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> = N extends ObjectNode<infer S> ? SchemaPathFor<S, PathNodeValue<N>> : N extends VariantNode<infer T, infer V> ? VariantPath<T, V> : never;
114
- type CollectionPath<N extends EntitySchemaNode = EntitySchemaNode, TValue = unknown> = PathMarker<TValue> & {
115
- readonly item: (id: string) => EntityPath<N>;
116
- readonly [collectionNode]: N;
117
- };
118
- type PathValue<N extends DocumentNode> = N extends ObjectNode<infer S> ? SchemaPathFor<S, PathNodeValue<N>> : N extends VariantNode<infer TTag, infer V> ? VariantPath<TTag, V> : N extends TableNode<infer V> | MapNode<infer V> ? CollectionPath<V, PathNodeValue<N>> : PathMarker<PathNodeValue<N>>;
119
- type CollectionInfo<T> = T extends {
120
- readonly [collectionNode]: infer TNode extends EntitySchemaNode;
121
- } ? {
122
- readonly id: string;
123
- readonly node: TNode;
124
- } : never;
125
- type CollectionId<T> = CollectionInfo<T> extends {
126
- readonly id: infer TId extends string;
127
- } ? TId : string;
128
- type CollectionNode<T> = CollectionInfo<T> extends {
129
- readonly node: infer TNode extends EntitySchemaNode;
130
- } ? TNode : EntitySchemaNode;
131
- type PathValueResult<T> = T extends PathMarker<infer TValue> ? TValue : unknown;
132
- declare const field: <T>() => FieldNode<T>;
133
- type OptionalLeaf = FieldNode<unknown, boolean> | VariantNode<string, VariantShape> | DictNode<string, unknown> | ListNode<unknown> | TreeNode<unknown>;
134
- declare const optional: <T extends OptionalLeaf>(value: T) => OptionalNode<T>;
135
- declare const object: <S extends ObjectShape>(shape: S) => ObjectNode<S>;
136
- declare const variant: <T extends string, V extends VariantShape>(tag: T, variants: V) => VariantNode<T, V>;
137
- declare const table: <V extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>(value: V) => TableNode<V>;
138
- declare const map: <V extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>(value: V) => MapNode<V>;
139
- declare const dict: <TKey extends string = string, TValue = unknown>() => DictNode<TKey, TValue>;
140
- declare const list: <TItem>(config: DocumentListConfig<TItem>) => ListNode<TItem>;
141
- declare const tree: <TValue = unknown>() => TreeNode<TValue>;
142
- declare const schema: <S extends ObjectShape>(shape: S) => DocumentSchema<S>;
143
- //#endregion
144
- //#region core/src/operations.d.ts
145
- type DocumentAnchor = {
146
- readonly before: string;
147
- } | {
148
- readonly after: string;
149
- } | {
150
- readonly at: 'start' | 'end';
151
- };
152
- type OperationBase = {
153
- readonly at: DocumentAddress;
154
- };
155
- type FieldSetOperation = OperationBase & {
156
- readonly type: 'field.set';
157
- readonly value: unknown;
158
- };
159
- type FieldClearOperation = OperationBase & {
160
- readonly type: 'field.clear';
161
- };
162
- type ValueClearOperation = OperationBase & {
163
- readonly type: 'value.clear';
164
- };
165
- type VariantReplaceOperation = OperationBase & {
166
- readonly type: 'variant.replace';
167
- readonly value: unknown;
168
- };
169
- type DictSetOperation = OperationBase & {
170
- readonly type: 'dict.set';
171
- readonly key: string;
172
- readonly value: unknown;
173
- };
174
- type DictDeleteOperation = OperationBase & {
175
- readonly type: 'dict.delete';
176
- readonly key: string;
177
- };
178
- type DictReplaceOperation = OperationBase & {
179
- readonly type: 'dict.replace';
180
- readonly value: Readonly<Record<string, unknown>>;
181
- };
182
- type EntityCreateOperation = OperationBase & {
183
- readonly type: 'entity.create';
184
- readonly entries: readonly EntityEntry[];
185
- readonly anchor?: DocumentAnchor; /** Generated inverse metadata with strictly increasing final indices. Normal creates omit it. */
186
- readonly positions?: readonly number[];
187
- };
188
- type EntityEntry = {
189
- readonly id: string;
190
- readonly value: unknown;
191
- };
192
- type EntityRemoveOperation = OperationBase & {
193
- readonly type: 'entity.remove';
194
- readonly ids: readonly string[];
195
- };
196
- type EntityMoveOperation = OperationBase & {
197
- readonly type: 'entity.move';
198
- readonly id: string;
199
- readonly anchor?: DocumentAnchor;
200
- };
201
- type ListInsertOperation = OperationBase & {
202
- readonly type: 'list.insert';
203
- readonly key: string;
204
- readonly value: unknown;
205
- readonly anchor?: DocumentAnchor;
206
- };
207
- type ListMoveOperation = OperationBase & {
208
- readonly type: 'list.move';
209
- readonly key: string;
210
- readonly anchor?: DocumentAnchor;
211
- };
212
- type ListRemoveOperation = OperationBase & {
213
- readonly type: 'list.remove';
214
- readonly key: string;
215
- };
216
- type ListReplaceOperation = OperationBase & {
217
- readonly type: 'list.replace';
218
- readonly value: readonly unknown[];
219
- readonly keys: readonly string[];
220
- };
221
- type TreeInsertOperation = OperationBase & {
222
- readonly type: 'tree.insert';
223
- readonly treeNodeId: string;
224
- readonly parentId?: string;
225
- readonly index?: number;
226
- readonly value?: unknown;
227
- };
228
- type TreeMoveOperation = OperationBase & {
229
- readonly type: 'tree.move';
230
- readonly treeNodeId: string;
231
- readonly parentId?: string;
232
- readonly index?: number;
233
- };
234
- type TreeRemoveOperation = OperationBase & {
235
- readonly type: 'tree.remove';
236
- readonly treeNodeId: string;
237
- };
238
- type TreeSetOperation = OperationBase & {
239
- readonly type: 'tree.set';
240
- readonly treeNodeId: string;
241
- readonly value: unknown;
242
- };
243
- type TreeReplaceOperation = OperationBase & {
244
- readonly type: 'tree.replace';
245
- readonly value: unknown;
246
- };
247
- type DocumentOperation = FieldSetOperation | FieldClearOperation | ValueClearOperation | VariantReplaceOperation | DictSetOperation | DictDeleteOperation | DictReplaceOperation | EntityCreateOperation | EntityRemoveOperation | EntityMoveOperation | ListInsertOperation | ListMoveOperation | ListRemoveOperation | ListReplaceOperation | TreeInsertOperation | TreeMoveOperation | TreeRemoveOperation | TreeSetOperation | TreeReplaceOperation;
248
- //#endregion
249
- //#region core/src/access/reader.d.ts
250
- type FieldReader<T> = {
251
- readonly get: () => T;
252
- };
253
- type DictionaryReader<K extends string, V> = {
254
- get(key: K): V | undefined;
255
- has(key: K): boolean;
256
- keys(): readonly K[];
257
- values(): Readonly<Partial<Record<K, V>>>;
258
- };
259
- type CollectionReader<TId, TNode extends EntitySchemaNode> = {
260
- readonly ids: () => readonly TId[];
261
- readonly has: (id: TId) => boolean;
262
- readonly get: (id: TId) => ReaderOfNode<TNode> | undefined;
263
- };
264
- type ListReader<T> = {
265
- readonly get: (key: string) => T | undefined;
266
- readonly has: (key: string) => boolean;
267
- readonly values: () => readonly T[];
268
- readonly length: () => number;
269
- readonly at: (index: number) => T | undefined;
270
- };
271
- type TreeReader<T> = {
272
- readonly rootId: () => string | undefined;
273
- readonly has: (id: string) => boolean;
274
- readonly value: (id: string) => T | undefined;
275
- readonly parent: (id: string) => string | undefined;
276
- readonly children: (id: string) => readonly string[];
277
- };
278
- type ReaderOfNode<TNode extends DocumentNode> = TNode extends {
279
- kind: 'field';
280
- } ? FieldReader<DocumentValueOfNode<TNode>> : TNode extends ObjectNode<infer TShape> ? { readonly [K in keyof TShape]: ReaderOfNode<TShape[K]> } : TNode extends VariantNode<string, infer _TVariants> ? FieldReader<DocumentValueOfNode<TNode> | (TNode extends {
281
- readonly optional: true;
282
- } ? undefined : never)> : TNode extends TableNode<infer TValue> ? CollectionReader<string, TValue> : TNode extends MapNode<infer TValue> ? CollectionReader<string, TValue> : TNode extends DictNode<infer TKey, infer TValue> ? DictionaryReader<TKey, TValue> : TNode extends ListNode<infer TItem> ? ListReader<TItem> : TNode extends TreeNode<infer TValue> ? TreeReader<TValue> : FieldReader<DocumentValueOfNode<TNode>>;
283
- type DocumentReader<TSchema extends DocumentSchema> = ReaderOfNode<ObjectNode<TSchema['shape']>>;
284
- //#endregion
285
- //#region core/src/access/writer.d.ts
286
- type FieldWriter<T, Optional extends boolean = false> = {
287
- readonly set: (value: T) => void;
288
- } & (Optional extends true ? {
289
- readonly clear: () => void;
290
- } : {});
291
- type DictionaryWriter<TKey extends string, TValue> = {
292
- readonly set: (key: TKey, value: TValue) => void;
293
- readonly delete: (key: TKey) => void;
294
- readonly replace: (value: Readonly<Partial<Record<TKey, TValue>>>) => void;
295
- };
296
- type CollectionWriter<TId, TNode extends EntitySchemaNode> = {
297
- readonly create: (entry: {
298
- readonly id: TId;
299
- readonly value: DocumentValueOfNode<TNode>;
300
- } | readonly {
301
- readonly id: TId;
302
- readonly value: DocumentValueOfNode<TNode>;
303
- }[], anchor?: DocumentAnchor) => void;
304
- readonly item: (id: TId) => WriterOfNode<TNode>;
305
- readonly remove: (id: TId | readonly TId[]) => void;
306
- readonly move: (id: TId, anchor?: DocumentAnchor) => void;
307
- };
308
- type MapWriter<TId, TNode extends EntitySchemaNode> = {
309
- readonly create: (entry: {
310
- readonly id: TId;
311
- readonly value: DocumentValueOfNode<TNode>;
312
- } | readonly {
313
- readonly id: TId;
314
- readonly value: DocumentValueOfNode<TNode>;
315
- }[]) => void;
316
- readonly item: (id: TId) => WriterOfNode<TNode>;
317
- readonly remove: (id: TId | readonly TId[]) => void;
318
- };
319
- type ListWriter<T> = {
320
- readonly insert: (value: T, anchor?: DocumentAnchor) => void;
321
- readonly move: (key: string, anchor?: DocumentAnchor) => void;
322
- readonly remove: (key: string) => void;
323
- readonly replace: (value: readonly T[]) => void;
324
- };
325
- type TreeWriter<T> = {
326
- readonly insert: (id: string, value: T, position?: {
327
- readonly parentId?: string;
328
- readonly index?: number;
329
- }) => void;
330
- readonly move: (id: string, position?: {
331
- readonly parentId?: string;
332
- readonly index?: number;
333
- }) => void;
334
- readonly remove: (id: string) => void;
335
- readonly set: (id: string, value: T) => void;
336
- readonly replace: (value: DocumentTreeValue<T>) => void;
337
- };
338
- type OptionalClear<TNode extends DocumentNode, TWriter> = TNode extends {
339
- readonly optional: true;
340
- } ? TWriter & {
341
- readonly clear: () => void;
342
- } : TWriter;
343
- type WriterOfNode<TNode extends DocumentNode> = TNode extends {
344
- kind: 'field';
345
- } ? TNode extends {
346
- readonly optional: true;
347
- } ? FieldWriter<DocumentValueOfNode<TNode>, true> : FieldWriter<DocumentValueOfNode<TNode>> : TNode extends ObjectNode<infer TShape> ? { readonly [K in keyof TShape]: WriterOfNode<TShape[K]> } : TNode extends VariantNode<string, infer _TVariants> ? OptionalClear<TNode, {
348
- readonly replace: (value: DocumentValueOfNode<TNode>) => void;
349
- }> : TNode extends TableNode<infer TValue> ? CollectionWriter<string, TValue> : TNode extends MapNode<infer TValue> ? MapWriter<string, TValue> : TNode extends DictNode<infer TKey, infer TValue> ? OptionalClear<TNode, DictionaryWriter<TKey, TValue>> : TNode extends ListNode<infer TItem> ? OptionalClear<TNode, ListWriter<TItem>> : TNode extends TreeNode<infer TValue> ? OptionalClear<TNode, TreeWriter<TValue>> : FieldWriter<DocumentValueOfNode<TNode>>;
350
- type DocumentWriter<TSchema extends DocumentSchema> = WriterOfNode<ObjectNode<TSchema['shape']>>;
351
- //#endregion
352
- //#region core/src/mutation/issue.d.ts
353
- type MutationIssueCode = 'invalid-address' | 'invalid-operation' | 'unknown-operation' | 'required-field' | 'invalid-anchor' | 'duplicate-entity' | 'missing-entity' | 'invalid-collection' | 'invalid-list-keys' | 'invalid-list-key' | 'duplicate-list-item' | 'missing-list-item' | 'invalid-tree' | 'duplicate-tree-node' | 'missing-tree-parent' | 'invalid-tree-index' | 'missing-tree-node' | 'tree-cycle';
354
- type MutationIssue = {
355
- readonly source: 'mutation';
356
- readonly code: MutationIssueCode;
357
- readonly address: DocumentAddress;
358
- readonly message: string;
359
- readonly operation?: DocumentOperation['type'];
360
- };
361
- //#endregion
362
- //#region core/src/impact.d.ts
363
- type CollectionImpact<TId> = {
364
- readonly kind: 'reset';
365
- } | {
366
- readonly kind: 'incremental';
367
- readonly added: ReadonlySet<TId>;
368
- readonly removed: ReadonlySet<TId>;
369
- readonly updated: ReadonlySet<TId>;
370
- readonly orderChanged: boolean;
371
- };
372
- type DocumentImpact<TSchema extends DocumentSchema> = {
373
- readonly kind: 'incremental' | 'reset';
374
- readonly affects: (target: ImpactTarget<unknown>) => boolean;
375
- readonly collection: <TId extends string>(selector: CollectionSelector<TId>) => CollectionImpact<TId>;
376
- readonly operations: readonly DocumentOperation[];
377
- };
378
- //#endregion
379
- //#region core/src/address.d.ts
380
- /** The only resolved address representation used inside the runtime. */
381
- type AddressRef = {
382
- readonly path: number;
383
- readonly address: DocumentAddress;
384
- };
385
- declare const resolveAddress: (schema: DocumentSchema, address: DocumentAddress, document?: unknown) => AddressRef | undefined;
386
- declare const read: (root: unknown, address: DocumentAddress) => unknown;
387
- declare const contains: (parent: DocumentAddress, child: DocumentAddress) => boolean;
388
- declare const overlaps: (a: DocumentAddress, b: DocumentAddress) => boolean;
389
- declare const debugKey: (address: DocumentAddress) => string;
390
- //#endregion
391
- //#region core/src/mutation/footprint.d.ts
392
- type CommandFootprintTarget = {
393
- readonly kind: 'value';
394
- readonly at: DocumentAddress;
395
- } | {
396
- readonly kind: 'dictionary';
397
- readonly at: DocumentAddress;
398
- } | {
399
- readonly kind: 'dictionary-key';
400
- readonly at: DocumentAddress;
401
- readonly key: string;
402
- } | {
403
- readonly kind: 'collection';
404
- readonly at: DocumentAddress;
405
- } | {
406
- readonly kind: 'entity';
407
- readonly at: DocumentAddress;
408
- readonly id: string;
409
- } | {
410
- readonly kind: 'list';
411
- readonly at: DocumentAddress;
412
- } | {
413
- readonly kind: 'list-item';
414
- readonly at: DocumentAddress;
415
- readonly key: string;
416
- } | {
417
- readonly kind: 'tree';
418
- readonly at: DocumentAddress;
419
- } | {
420
- readonly kind: 'tree-node';
421
- readonly at: DocumentAddress;
422
- readonly id: string;
423
- };
424
- type CommandFootprint = readonly CommandFootprintTarget[];
425
- declare const commandFootprint: (operations: readonly DocumentOperation[]) => CommandFootprint;
426
- declare const footprintsOverlap: (left: CommandFootprint, right: CommandFootprint) => boolean;
427
- declare const decodeCommandFootprint: (value: unknown) => CommandFootprint | undefined;
428
- //#endregion
429
- //#region core/src/projection/readable.d.ts
430
- type Readable<TValue> = {
431
- current(): TValue;
432
- revision(): number;
433
- subscribe(listener: () => void): Unsubscribe;
434
- };
435
- //#endregion
436
- //#region core/src/runtime/contract.d.ts
437
- type Unsubscribe = () => void;
438
- type Synchronous<T> = T extends PromiseLike<unknown> ? never : T;
439
- type CommitSource = 'local' | 'system' | 'history' | 'remote';
440
- declare class DocumentReentrancyError extends Error {
441
- constructor();
442
- }
443
- declare class DocumentDisposedError extends Error {
444
- constructor();
445
- }
446
- type DocumentCommit<TSchema extends DocumentSchema> = {
447
- readonly revision: number;
448
- readonly kind: 'operations' | 'replace';
449
- readonly source: CommitSource;
450
- readonly operations: readonly DocumentOperation[];
451
- readonly inverse: readonly DocumentOperation[];
452
- readonly impact: DocumentImpact<TSchema>;
453
- };
454
- type DiagnosticInput = {
455
- readonly code: string;
456
- readonly message: string;
457
- readonly address?: DocumentAddress;
458
- };
459
- type DocumentDiagnostic = DiagnosticInput & {
460
- readonly source: 'application';
461
- };
462
- type DocumentProblem = DocumentDiagnostic | MutationIssue;
463
- type ObserverError = {
464
- readonly phase: 'processor' | 'flush' | 'listener';
465
- readonly error: unknown;
466
- };
467
- type TransactionResult<TValue, TCommit> = {
468
- readonly status: 'committed';
469
- readonly value: TValue;
470
- readonly commit: TCommit;
471
- readonly reports: readonly DocumentDiagnostic[];
472
- readonly observerErrors: readonly ObserverError[];
473
- } | {
474
- readonly status: 'unchanged';
475
- readonly value: TValue;
476
- readonly revision: number;
477
- readonly reports: readonly DocumentDiagnostic[];
478
- } | {
479
- readonly status: 'rejected';
480
- readonly issues: readonly DocumentProblem[];
481
- readonly revision: number;
482
- };
483
- type PreparedUpdateResult<TValue, TSchema extends DocumentSchema> = {
484
- readonly status: 'prepared';
485
- readonly value: TValue;
486
- readonly operations: readonly DocumentOperation[];
487
- readonly inverse: readonly DocumentOperation[];
488
- readonly impact: DocumentImpact<TSchema>;
489
- readonly footprint: CommandFootprint;
490
- readonly reports: readonly DocumentDiagnostic[];
491
- } | {
492
- readonly status: 'unchanged';
493
- readonly value: TValue;
494
- readonly reports: readonly DocumentDiagnostic[];
495
- } | {
496
- readonly status: 'rejected';
497
- readonly issues: readonly DocumentProblem[];
498
- };
499
- type OperationResult<TCommit> = {
500
- readonly status: 'committed';
501
- readonly commit: TCommit;
502
- readonly observerErrors: readonly ObserverError[];
503
- } | {
504
- readonly status: 'unchanged';
505
- readonly revision: number;
506
- } | {
507
- readonly status: 'rejected';
508
- readonly issues: readonly MutationIssue[];
509
- readonly revision: number;
510
- };
511
- type HistoryState = {
512
- readonly undoDepth: number;
513
- readonly redoDepth: number;
514
- };
515
- type LocalHistory<TCommit> = Readable<HistoryState> & {
516
- undo(): OperationResult<TCommit>;
517
- redo(): OperationResult<TCommit>;
518
- clear(): void;
519
- group(): {
520
- end(): void;
521
- cancel(): OperationResult<TCommit>;
522
- };
523
- };
524
- type DocumentTransaction<TSchema extends DocumentSchema> = {
525
- readonly read: DocumentReader<TSchema>;
526
- readonly write: DocumentWriter<TSchema>;
527
- readonly reject: (issue: DiagnosticInput | readonly DiagnosticInput[]) => never;
528
- readonly report: (issue: DiagnosticInput) => void;
529
- };
530
- type CommitListener<TSchema extends DocumentSchema> = (commit: DocumentCommit<TSchema>) => void;
531
- type DocumentReadable<TSchema extends DocumentSchema> = {
532
- readonly address: {
533
- readonly resolve: (address: DocumentAddress) => AddressRef | undefined;
534
- readonly read: (address: DocumentAddress) => unknown;
535
- readonly contains: (parent: DocumentAddress, child: DocumentAddress) => boolean;
536
- readonly overlaps: (left: DocumentAddress, right: DocumentAddress) => boolean;
537
- readonly debugKey: (address: DocumentAddress) => string;
538
- };
539
- revision(): number;
540
- subscribe(listener: CommitListener<TSchema>): Unsubscribe;
541
- subscribe(target: ImpactTarget<unknown> | readonly [ImpactTarget<unknown>, ...ImpactTarget<unknown>[]], listener: CommitListener<TSchema>): Unsubscribe;
542
- };
543
- type DocumentRuntime<TSchema extends DocumentSchema> = DocumentReadable<TSchema> & {
544
- /** Schema configuration captured when this runtime was created. */readonly schema: TSchema;
545
- update<TResult>(run: (transaction: DocumentTransaction<TSchema>) => Synchronous<TResult>, options?: {
546
- readonly source?: Extract<CommitSource, 'local' | 'system'>;
547
- readonly history?: boolean;
548
- }): TransactionResult<TResult, DocumentCommit<TSchema>>;
549
- prepare<TResult>(run: (transaction: DocumentTransaction<TSchema>) => Synchronous<TResult>): PreparedUpdateResult<TResult, TSchema>;
550
- apply(operations: unknown, options?: {
551
- readonly source?: Exclude<CommitSource, 'history'>;
552
- readonly history?: boolean;
553
- }): OperationResult<DocumentCommit<TSchema>>;
554
- replace(document: ReadonlyDocument<TSchema>, options?: {
555
- readonly source?: Extract<CommitSource, 'system' | 'remote'>;
556
- }): OperationResult<DocumentCommit<TSchema>>;
557
- snapshot(): ReadonlyDocument<TSchema>;
558
- readonly history: LocalHistory<DocumentCommit<TSchema>>;
559
- dispose(): void;
560
- };
561
- //#endregion
562
- export { DocumentOperation as $, variant as $t, CollectionImpact as A, FieldNode as At, TreeWriter as B, TreeNode as Bt, footprintsOverlap as C, DocumentNode as Ct, overlaps as D, DocumentValueOfNode as Dt, debugKey as E, DocumentTreeValue as Et, DictionaryWriter as F, ObjectShape as Ft, FieldReader as G, field as Gt, CollectionReader as H, VariantNode as Ht, DocumentWriter as I, OptionalNode as It, TreeReader as J, object as Jt, ListReader as K, list as Kt, FieldWriter as L, ReadonlyDocument as Lt, MutationIssue as M, ListNode as Mt, MutationIssueCode as N, MapNode as Nt, read as O, DocumentValueOfShape as Ot, CollectionWriter as P, ObjectNode as Pt, DocumentAnchor as Q, tree as Qt, ListWriter as R, SchemaPath as Rt, decodeCommandFootprint as S, DocumentListConfig as St, contains as T, DocumentTreeNode as Tt, DictionaryReader as U, VariantShape as Ut, WriterOfNode as V, ValueSelector as Vt, DocumentReader as W, dict as Wt, DictReplaceOperation as X, schema as Xt, DictDeleteOperation as Y, optional as Yt, DictSetOperation as Z, table as Zt, Unsubscribe as _, CollectionNode as _t, DocumentProblem as a, FieldSetOperation as at, CommandFootprintTarget as b, DictNode as bt, DocumentRuntime as c, ListRemoveOperation as ct, LocalHistory as d, TreeMoveOperation as dt, EntityCreateOperation as et, ObserverError as f, TreeRemoveOperation as ft, TransactionResult as g, VariantReplaceOperation as gt, Synchronous as h, ValueClearOperation as ht, DocumentDisposedError as i, FieldClearOperation as it, DocumentImpact as j, ImpactTarget as jt, resolveAddress as k, EntitySchemaNode as kt, DocumentTransaction as l, ListReplaceOperation as lt, PreparedUpdateResult as m, TreeSetOperation as mt, DocumentCommit as n, EntityMoveOperation as nt, DocumentReadable as o, ListInsertOperation as ot, OperationResult as p, TreeReplaceOperation as pt, ReaderOfNode as q, map as qt, DocumentDiagnostic as r, EntityRemoveOperation as rt, DocumentReentrancyError as s, ListMoveOperation as st, CommitSource as t, EntityEntry as tt, HistoryState as u, TreeInsertOperation as ut, Readable as v, CollectionPath as vt, AddressRef as w, DocumentSchema as wt, commandFootprint as x, DocumentAddress as xt, CommandFootprint as y, CollectionSelector as yt, MapWriter as z, TableNode as zt };
563
- //# sourceMappingURL=contract-j3SLGAwh.d.cts.map
@@ -1,69 +0,0 @@
1
- //#region core/src/runtime/driver.ts
2
- const states = /* @__PURE__ */ new WeakMap();
3
- const stateOf = (runtime) => {
4
- const state = states.get(runtime);
5
- if (!state) throw new Error("Unknown Doxum runtime.");
6
- return state;
7
- };
8
- const bindRuntimeDriver = (runtime) => {
9
- states.set(runtime, {
10
- driver: void 0,
11
- bypassDepth: 0
12
- });
13
- };
14
- const assertRuntimeWritable = (runtime, intent) => {
15
- const state = stateOf(runtime);
16
- if (state.bypassDepth === 0) state.driver?.assertWritable(intent);
17
- };
18
- const installRuntimeWriteDriver = (runtime, driver) => {
19
- const state = stateOf(runtime);
20
- if (state.driver) throw new Error("Doxum runtime already has a write driver.");
21
- state.driver = driver;
22
- let active = true;
23
- return Object.freeze({
24
- run: (run) => {
25
- if (!active) throw new Error("Doxum runtime write driver is no longer active.");
26
- state.bypassDepth += 1;
27
- try {
28
- return run();
29
- } finally {
30
- state.bypassDepth -= 1;
31
- }
32
- },
33
- dispose: () => {
34
- if (!active) return;
35
- active = false;
36
- if (state.driver === driver) state.driver = void 0;
37
- }
38
- });
39
- };
40
- const disposeRuntimeDriver = (runtime) => {
41
- states.delete(runtime);
42
- };
43
- //#endregion
44
- Object.defineProperty(exports, "assertRuntimeWritable", {
45
- enumerable: true,
46
- get: function() {
47
- return assertRuntimeWritable;
48
- }
49
- });
50
- Object.defineProperty(exports, "bindRuntimeDriver", {
51
- enumerable: true,
52
- get: function() {
53
- return bindRuntimeDriver;
54
- }
55
- });
56
- Object.defineProperty(exports, "disposeRuntimeDriver", {
57
- enumerable: true,
58
- get: function() {
59
- return disposeRuntimeDriver;
60
- }
61
- });
62
- Object.defineProperty(exports, "installRuntimeWriteDriver", {
63
- enumerable: true,
64
- get: function() {
65
- return installRuntimeWriteDriver;
66
- }
67
- });
68
-
69
- //# sourceMappingURL=driver-CNxqMVFH.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"driver-CNxqMVFH.cjs","names":[],"sources":["../core/src/runtime/driver.ts"],"sourcesContent":["import type { CommitSource, DocumentRuntime } from './contract';\nimport type { DocumentSchema } from '../schema';\n\nexport type RuntimeWriteIntent =\n | { readonly kind: 'update'; readonly source: Extract<CommitSource, 'local' | 'system'> }\n | { readonly kind: 'prepare' }\n | { readonly kind: 'apply'; readonly source: CommitSource }\n | { readonly kind: 'replace'; readonly source: Extract<CommitSource, 'system' | 'remote'> };\n\nexport type RuntimeWriteDriver = {\n readonly assertWritable: (intent: RuntimeWriteIntent) => void;\n};\n\nexport type RuntimeWriteDriverLease = {\n readonly run: <TResult>(run: () => TResult) => TResult;\n readonly dispose: () => void;\n};\n\ntype RuntimeDriverState = {\n driver: RuntimeWriteDriver | undefined;\n bypassDepth: number;\n};\n\nconst states = new WeakMap<object, RuntimeDriverState>();\n\nconst stateOf = (runtime: object): RuntimeDriverState => {\n const state = states.get(runtime);\n if (!state) throw new Error('Unknown Doxum runtime.');\n return state;\n};\n\nexport const bindRuntimeDriver = (runtime: object): void => {\n states.set(runtime, { driver: undefined, bypassDepth: 0 });\n};\n\nexport const assertRuntimeWritable = (runtime: object, intent: RuntimeWriteIntent): void => {\n const state = stateOf(runtime);\n if (state.bypassDepth === 0) state.driver?.assertWritable(intent);\n};\n\nexport const installRuntimeWriteDriver = <TSchema extends DocumentSchema>(\n runtime: DocumentRuntime<TSchema>,\n driver: RuntimeWriteDriver\n): RuntimeWriteDriverLease => {\n const state = stateOf(runtime);\n if (state.driver) throw new Error('Doxum runtime already has a write driver.');\n state.driver = driver;\n let active = true;\n return Object.freeze({\n run: <TResult>(run: () => TResult): TResult => {\n if (!active) throw new Error('Doxum runtime write driver is no longer active.');\n state.bypassDepth += 1;\n try {\n return run();\n } finally {\n state.bypassDepth -= 1;\n }\n },\n dispose: (): void => {\n if (!active) return;\n active = false;\n if (state.driver === driver) state.driver = undefined;\n },\n });\n};\n\nexport const disposeRuntimeDriver = (runtime: object): void => {\n states.delete(runtime);\n};\n"],"mappings":";AAuBA,MAAM,yBAAS,IAAI,SAAqC;AAExD,MAAM,WAAW,YAAwC;CACvD,MAAM,QAAQ,OAAO,IAAI,QAAQ;AACjC,KAAI,CAAC,MAAO,OAAM,IAAI,MAAM,yBAAyB;AACrD,QAAO;;AAGT,MAAa,qBAAqB,YAA0B;AAC1D,QAAO,IAAI,SAAS;EAAE,QAAQ,KAAA;EAAW,aAAa;EAAG,CAAC;;AAG5D,MAAa,yBAAyB,SAAiB,WAAqC;CAC1F,MAAM,QAAQ,QAAQ,QAAQ;AAC9B,KAAI,MAAM,gBAAgB,EAAG,OAAM,QAAQ,eAAe,OAAO;;AAGnE,MAAa,6BACX,SACA,WAC4B;CAC5B,MAAM,QAAQ,QAAQ,QAAQ;AAC9B,KAAI,MAAM,OAAQ,OAAM,IAAI,MAAM,4CAA4C;AAC9E,OAAM,SAAS;CACf,IAAI,SAAS;AACb,QAAO,OAAO,OAAO;EACnB,MAAe,QAAgC;AAC7C,OAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,kDAAkD;AAC/E,SAAM,eAAe;AACrB,OAAI;AACF,WAAO,KAAK;aACJ;AACR,UAAM,eAAe;;;EAGzB,eAAqB;AACnB,OAAI,CAAC,OAAQ;AACb,YAAS;AACT,OAAI,MAAM,WAAW,OAAQ,OAAM,SAAS,KAAA;;EAE/C,CAAC;;AAGJ,MAAa,wBAAwB,YAA0B;AAC7D,QAAO,OAAO,QAAQ"}