doxum 0.1.3 → 0.1.5
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.
- package/dist/{contract-BsY1XLiG.d.ts → contract-4E3moCbY.d.ts} +53 -40
- package/dist/{contract-D8kjdfqT.d.cts → contract-uYJTmT8o.d.cts} +53 -40
- package/dist/dependency-C5_R1tvQ.js.map +1 -1
- package/dist/dependency-Dfzs3khk.cjs.map +1 -1
- package/dist/index.cjs +171 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +171 -22
- package/dist/index.js.map +1 -1
- package/dist/integration.d.cts +1 -1
- package/dist/integration.d.ts +1 -1
- package/dist/local-sync.d.cts +1 -1
- package/dist/local-sync.d.ts +1 -1
- package/package.json +1 -1
- package/skills/doxum-runtime/references/guide.en.md +5 -0
- package/skills/doxum-runtime/references/guide.zh-CN.md +4 -0
- package/skills/doxum-runtime/references/patterns.en.md +7 -0
- package/skills/doxum-runtime/references/patterns.zh-CN.md +6 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as EntityEntry, $t as tree, A as MutationIssue, At as MapNode, B as CollectionReader, Bt as ValueSelector, C as contains, Ct as DocumentTreeValue, D as resolveAddress, Dt as FieldNode, E as read, Et as EntitySchemaNode, F as FieldWriter, Ft as RecordNode, G as TreeReader, Gt as list, H as FieldReader, Ht as VariantShape, I as ListWriter, It as SchemaPath, J as DictSetOperation, Jt as optional, K as DictDeleteOperation, Kt as map, L as MapWriter, Lt as SingleNode, M as CollectionWriter, Mt as ObjectShape, N as DictionaryWriter, Nt as OptionalNode, O as CollectionImpact, Ot as ImpactTarget, P as DocumentWriter, Pt as ReadonlyDocument, Q as EntityCreateOperation, Qt as table, R as TreeWriter, Rt as TableNode, S as AddressRef, St as DocumentTreeNode, T as overlaps, Tt as DocumentValueOfShape, U as ListReader, Ut as dict, V as DocumentReader, Vt as VariantNode, W as ReaderOfNode, Wt as field, X as DocumentOperation, Xt as schema, Y as DocumentAnchor, Yt as record, Z as DocumentOperationUnion, Zt as single, _ as CommandFootprint, _t as DictNode, a as DocumentProblem, at as ListMoveOperation, b as decodeCommandFootprint, bt as DocumentNode, c as DocumentRuntime, ct as TreeInsertOperation, d as LocalHistory, dt as TreeReplaceOperation, en as variant, et as EntityMoveOperation, f as ObserverError, ft as TreeSetOperation, g as Unsubscribe, gt as CollectionSelector, h as TransactionResult, ht as CollectionNode, i as DocumentDisposedError, it as ListInsertOperation, j as MutationIssueCode, jt as ObjectNode, k as DocumentImpact, kt as ListNode, l as DocumentTransaction, lt as TreeMoveOperation, m as PreparedUpdateResult, mt as VariantReplaceOperation, n as DocumentCommit, nt as FieldClearOperation, o as DocumentReadable, ot as ListRemoveOperation, p as OperationResult, pt as ValueClearOperation, q as DictReplaceOperation, qt as object, r as DocumentDiagnostic, rt as FieldSetOperation, s as DocumentReentrancyError, st as ListReplaceOperation, t as CommitSource, tt as EntityRemoveOperation, u as HistoryState, ut as TreeRemoveOperation, v as CommandFootprintTarget, vt as DocumentAddress, w as debugKey, wt as DocumentValueOfNode, x as footprintsOverlap, xt as DocumentSchema, y as commandFootprint, yt as DocumentListConfig, z as WriterOfNode, zt as TreeNode } from "./contract-uYJTmT8o.cjs";
|
|
2
2
|
|
|
3
3
|
//#region \0rolldown/runtime.js
|
|
4
4
|
//#endregion
|
|
@@ -41,10 +41,10 @@ type CollectionView<TId extends string, TValue> = {
|
|
|
41
41
|
revision(): number;
|
|
42
42
|
dispose(): void;
|
|
43
43
|
};
|
|
44
|
-
declare const createCollectionView: <TSchema extends DocumentSchema, TId extends string,
|
|
44
|
+
declare const createCollectionView: <TSchema extends DocumentSchema, TId extends string, TNode extends EntitySchemaNode, TValue>(input: {
|
|
45
45
|
readonly runtime: DocumentReadable<TSchema>;
|
|
46
|
-
readonly source: CollectionSelector<TId,
|
|
47
|
-
readonly map: (id: TId, entry:
|
|
46
|
+
readonly source: CollectionSelector<TId, TNode>;
|
|
47
|
+
readonly map: (id: TId, entry: ReaderOfNode<TNode>) => TValue;
|
|
48
48
|
readonly isEqual?: (previous: TValue, next: TValue) => boolean;
|
|
49
49
|
}) => CollectionView<TId, TValue>;
|
|
50
50
|
//#endregion
|
|
@@ -88,5 +88,5 @@ type MaterializedView<TValue, TChange = void> = Readable<TValue> & {
|
|
|
88
88
|
};
|
|
89
89
|
declare const createMaterializedView: <TSchema extends DocumentSchema, TValue, TChange = void, TSources extends MaterializedSources = {}>(runtime: DocumentReadable<TSchema>, spec: MaterializedViewSpec<TSchema, TValue, TChange, TSources>) => MaterializedView<TValue, TChange>;
|
|
90
90
|
//#endregion
|
|
91
|
-
export { type AddressRef, type CollectionImpact, type CollectionReader, type CollectionSelector, type CollectionView, type CollectionWriter, type CommandFootprint, type CommandFootprintTarget, type CommitSource, type DictDeleteOperation, type DictNode, type DictReplaceOperation, type DictSetOperation, type DictionaryWriter, type DocumentAddress, type DocumentAnchor, type DocumentCommit, type DocumentDiagnostic, DocumentDisposedError, type DocumentImpact, type DocumentListConfig, type DocumentNode, type DocumentOperation, type DocumentOperationUnion, type DocumentProblem, type DocumentReadable, type DocumentReader, DocumentReentrancyError, type DocumentRuntime, type DocumentSchema, type DocumentSelector, type DocumentTransaction, type DocumentTreeNode, type DocumentTreeValue, type DocumentValueOfNode, type DocumentValueOfShape, type DocumentWriter, type EntityCreateOperation, type EntityEntry, type EntityMoveOperation, type
|
|
91
|
+
export { type AddressRef, type CollectionImpact, type CollectionNode, type CollectionReader, type CollectionSelector, type CollectionView, type CollectionWriter, type CommandFootprint, type CommandFootprintTarget, type CommitSource, type DictDeleteOperation, type DictNode, type DictReplaceOperation, type DictSetOperation, type DictionaryWriter, type DocumentAddress, type DocumentAnchor, type DocumentCommit, type DocumentDiagnostic, DocumentDisposedError, type DocumentImpact, type DocumentListConfig, type DocumentNode, type DocumentOperation, type DocumentOperationUnion, type DocumentProblem, type DocumentReadable, type DocumentReader, DocumentReentrancyError, type DocumentRuntime, type DocumentSchema, type DocumentSelector, type DocumentTransaction, type DocumentTreeNode, type DocumentTreeValue, type DocumentValueOfNode, type DocumentValueOfShape, type DocumentWriter, type EntityCreateOperation, type EntityEntry, type EntityMoveOperation, type EntityRemoveOperation, type EntitySchemaNode, type FieldClearOperation, type FieldNode, type FieldReader, type FieldSetOperation, type FieldWriter, type HistoryState, type ImpactTarget, type ListInsertOperation, type ListMoveOperation, type ListNode, type ListReader, type ListRemoveOperation, type ListReplaceOperation, type ListWriter, type LocalHistory, type MapNode, type MapWriter, type MaterializedSource, type MaterializedSourceValues, type MaterializedSources, type MaterializedUpdateResult, type MaterializedView, type MaterializedViewSpec, type MaterializedViewUpdate, type MutationIssue, type MutationIssueCode, type ObjectNode, type ObjectShape, type ObserverError, type OperationResult, type OptionalNode, type PreparedUpdateResult, type Readable, type ReaderOfNode, type ReadonlyDocument, type RecordNode, type SchemaPath, type SingleNode, type TableNode, type TransactionResult, type TreeInsertOperation, type TreeMoveOperation, type TreeNode, type TreeReader, type TreeRemoveOperation, type TreeReplaceOperation, type TreeSetOperation, type TreeWriter, type Unsubscribe, type ValueClearOperation, type ValueSelector, type VariantNode, type VariantReplaceOperation, type VariantShape, type WriterOfNode, asReadable, commandFootprint, contains, createCollectionView, createDocument, createMaterializedView, debugKey, decodeCommandFootprint, dict, field, footprintsOverlap, list, map, object, optional, overlaps, read as readAddress, record, resolveAddress, schema, select, single, table, impact_target_d_exports as target, tree, variant };
|
|
92
92
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as EntityEntry, $t as tree, A as MutationIssue, At as MapNode, B as CollectionReader, Bt as ValueSelector, C as contains, Ct as DocumentTreeValue, D as resolveAddress, Dt as FieldNode, E as read, Et as EntitySchemaNode, F as FieldWriter, Ft as RecordNode, G as TreeReader, Gt as list, H as FieldReader, Ht as VariantShape, I as ListWriter, It as SchemaPath, J as DictSetOperation, Jt as optional, K as DictDeleteOperation, Kt as map, L as MapWriter, Lt as SingleNode, M as CollectionWriter, Mt as ObjectShape, N as DictionaryWriter, Nt as OptionalNode, O as CollectionImpact, Ot as ImpactTarget, P as DocumentWriter, Pt as ReadonlyDocument, Q as EntityCreateOperation, Qt as table, R as TreeWriter, Rt as TableNode, S as AddressRef, St as DocumentTreeNode, T as overlaps, Tt as DocumentValueOfShape, U as ListReader, Ut as dict, V as DocumentReader, Vt as VariantNode, W as ReaderOfNode, Wt as field, X as DocumentOperation, Xt as schema, Y as DocumentAnchor, Yt as record, Z as DocumentOperationUnion, Zt as single, _ as CommandFootprint, _t as DictNode, a as DocumentProblem, at as ListMoveOperation, b as decodeCommandFootprint, bt as DocumentNode, c as DocumentRuntime, ct as TreeInsertOperation, d as LocalHistory, dt as TreeReplaceOperation, en as variant, et as EntityMoveOperation, f as ObserverError, ft as TreeSetOperation, g as Unsubscribe, gt as CollectionSelector, h as TransactionResult, ht as CollectionNode, i as DocumentDisposedError, it as ListInsertOperation, j as MutationIssueCode, jt as ObjectNode, k as DocumentImpact, kt as ListNode, l as DocumentTransaction, lt as TreeMoveOperation, m as PreparedUpdateResult, mt as VariantReplaceOperation, n as DocumentCommit, nt as FieldClearOperation, o as DocumentReadable, ot as ListRemoveOperation, p as OperationResult, pt as ValueClearOperation, q as DictReplaceOperation, qt as object, r as DocumentDiagnostic, rt as FieldSetOperation, s as DocumentReentrancyError, st as ListReplaceOperation, t as CommitSource, tt as EntityRemoveOperation, u as HistoryState, ut as TreeRemoveOperation, v as CommandFootprintTarget, vt as DocumentAddress, w as debugKey, wt as DocumentValueOfNode, x as footprintsOverlap, xt as DocumentSchema, y as commandFootprint, yt as DocumentListConfig, z as WriterOfNode, zt as TreeNode } from "./contract-4E3moCbY.js";
|
|
2
2
|
|
|
3
3
|
//#region core/src/runtime.d.ts
|
|
4
4
|
declare const createDocument: <TSchema extends DocumentSchema>(input: {
|
|
@@ -39,10 +39,10 @@ type CollectionView<TId extends string, TValue> = {
|
|
|
39
39
|
revision(): number;
|
|
40
40
|
dispose(): void;
|
|
41
41
|
};
|
|
42
|
-
declare const createCollectionView: <TSchema extends DocumentSchema, TId extends string,
|
|
42
|
+
declare const createCollectionView: <TSchema extends DocumentSchema, TId extends string, TNode extends EntitySchemaNode, TValue>(input: {
|
|
43
43
|
readonly runtime: DocumentReadable<TSchema>;
|
|
44
|
-
readonly source: CollectionSelector<TId,
|
|
45
|
-
readonly map: (id: TId, entry:
|
|
44
|
+
readonly source: CollectionSelector<TId, TNode>;
|
|
45
|
+
readonly map: (id: TId, entry: ReaderOfNode<TNode>) => TValue;
|
|
46
46
|
readonly isEqual?: (previous: TValue, next: TValue) => boolean;
|
|
47
47
|
}) => CollectionView<TId, TValue>;
|
|
48
48
|
//#endregion
|
|
@@ -86,5 +86,5 @@ type MaterializedView<TValue, TChange = void> = Readable<TValue> & {
|
|
|
86
86
|
};
|
|
87
87
|
declare const createMaterializedView: <TSchema extends DocumentSchema, TValue, TChange = void, TSources extends MaterializedSources = {}>(runtime: DocumentReadable<TSchema>, spec: MaterializedViewSpec<TSchema, TValue, TChange, TSources>) => MaterializedView<TValue, TChange>;
|
|
88
88
|
//#endregion
|
|
89
|
-
export { type AddressRef, type CollectionImpact, type CollectionReader, type CollectionSelector, type CollectionView, type CollectionWriter, type CommandFootprint, type CommandFootprintTarget, type CommitSource, type DictDeleteOperation, type DictNode, type DictReplaceOperation, type DictSetOperation, type DictionaryWriter, type DocumentAddress, type DocumentAnchor, type DocumentCommit, type DocumentDiagnostic, DocumentDisposedError, type DocumentImpact, type DocumentListConfig, type DocumentNode, type DocumentOperation, type DocumentOperationUnion, type DocumentProblem, type DocumentReadable, type DocumentReader, DocumentReentrancyError, type DocumentRuntime, type DocumentSchema, type DocumentSelector, type DocumentTransaction, type DocumentTreeNode, type DocumentTreeValue, type DocumentValueOfNode, type DocumentValueOfShape, type DocumentWriter, type EntityCreateOperation, type EntityEntry, type EntityMoveOperation, type
|
|
89
|
+
export { type AddressRef, type CollectionImpact, type CollectionNode, type CollectionReader, type CollectionSelector, type CollectionView, type CollectionWriter, type CommandFootprint, type CommandFootprintTarget, type CommitSource, type DictDeleteOperation, type DictNode, type DictReplaceOperation, type DictSetOperation, type DictionaryWriter, type DocumentAddress, type DocumentAnchor, type DocumentCommit, type DocumentDiagnostic, DocumentDisposedError, type DocumentImpact, type DocumentListConfig, type DocumentNode, type DocumentOperation, type DocumentOperationUnion, type DocumentProblem, type DocumentReadable, type DocumentReader, DocumentReentrancyError, type DocumentRuntime, type DocumentSchema, type DocumentSelector, type DocumentTransaction, type DocumentTreeNode, type DocumentTreeValue, type DocumentValueOfNode, type DocumentValueOfShape, type DocumentWriter, type EntityCreateOperation, type EntityEntry, type EntityMoveOperation, type EntityRemoveOperation, type EntitySchemaNode, type FieldClearOperation, type FieldNode, type FieldReader, type FieldSetOperation, type FieldWriter, type HistoryState, type ImpactTarget, type ListInsertOperation, type ListMoveOperation, type ListNode, type ListReader, type ListRemoveOperation, type ListReplaceOperation, type ListWriter, type LocalHistory, type MapNode, type MapWriter, type MaterializedSource, type MaterializedSourceValues, type MaterializedSources, type MaterializedUpdateResult, type MaterializedView, type MaterializedViewSpec, type MaterializedViewUpdate, type MutationIssue, type MutationIssueCode, type ObjectNode, type ObjectShape, type ObserverError, type OperationResult, type OptionalNode, type PreparedUpdateResult, type Readable, type ReaderOfNode, type ReadonlyDocument, type RecordNode, type SchemaPath, type SingleNode, type TableNode, type TransactionResult, type TreeInsertOperation, type TreeMoveOperation, type TreeNode, type TreeReader, type TreeRemoveOperation, type TreeReplaceOperation, type TreeSetOperation, type TreeWriter, type Unsubscribe, type ValueClearOperation, type ValueSelector, type VariantNode, type VariantReplaceOperation, type VariantShape, type WriterOfNode, asReadable, commandFootprint, contains, createCollectionView, createDocument, createMaterializedView, debugKey, decodeCommandFootprint, dict, field, footprintsOverlap, list, map, object, optional, overlaps, read as readAddress, record, resolveAddress, schema, select, single, table, impact_target_d_exports as target, tree, variant };
|
|
90
90
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -195,7 +195,11 @@ const writerFor = (node, inputAddress, sink) => {
|
|
|
195
195
|
type: "dict.replace",
|
|
196
196
|
at: address,
|
|
197
197
|
value
|
|
198
|
-
})
|
|
198
|
+
}),
|
|
199
|
+
...node.optional ? { clear: () => emit(sink, {
|
|
200
|
+
type: "value.clear",
|
|
201
|
+
at: address
|
|
202
|
+
}) } : {}
|
|
199
203
|
};
|
|
200
204
|
if (node.kind === "list") return {
|
|
201
205
|
insert: (value, anchor) => emit(sink, {
|
|
@@ -221,7 +225,11 @@ const writerFor = (node, inputAddress, sink) => {
|
|
|
221
225
|
at: address,
|
|
222
226
|
value,
|
|
223
227
|
keys: value.map(node.keyOf)
|
|
224
|
-
})
|
|
228
|
+
}),
|
|
229
|
+
...node.optional ? { clear: () => emit(sink, {
|
|
230
|
+
type: "value.clear",
|
|
231
|
+
at: address
|
|
232
|
+
}) } : {}
|
|
225
233
|
};
|
|
226
234
|
if (node.kind === "tree") return {
|
|
227
235
|
insert: (treeNodeId, value, parentId, index) => emit(sink, {
|
|
@@ -254,7 +262,11 @@ const writerFor = (node, inputAddress, sink) => {
|
|
|
254
262
|
type: "tree.replace",
|
|
255
263
|
at: address,
|
|
256
264
|
value
|
|
257
|
-
})
|
|
265
|
+
}),
|
|
266
|
+
...node.optional ? { clear: () => emit(sink, {
|
|
267
|
+
type: "value.clear",
|
|
268
|
+
at: address
|
|
269
|
+
}) } : {}
|
|
258
270
|
};
|
|
259
271
|
if (node.kind === "table") {
|
|
260
272
|
let items;
|
|
@@ -318,11 +330,17 @@ const writerFor = (node, inputAddress, sink) => {
|
|
|
318
330
|
};
|
|
319
331
|
}
|
|
320
332
|
if (node.kind === "single") return writerFor(node.value, address, sink);
|
|
321
|
-
if (node.kind === "variant") return {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
333
|
+
if (node.kind === "variant") return {
|
|
334
|
+
replace: (value) => emit(sink, {
|
|
335
|
+
type: "variant.replace",
|
|
336
|
+
at: address,
|
|
337
|
+
value
|
|
338
|
+
}),
|
|
339
|
+
...node.optional ? { clear: () => emit(sink, {
|
|
340
|
+
type: "value.clear",
|
|
341
|
+
at: address
|
|
342
|
+
}) } : {}
|
|
343
|
+
};
|
|
326
344
|
let children;
|
|
327
345
|
return new Proxy({}, { get: (_target, property) => {
|
|
328
346
|
if (typeof property !== "string" || !node.shape[property]) return void 0;
|
|
@@ -540,8 +558,11 @@ const rejected$3 = (operation, code, message) => ({
|
|
|
540
558
|
issue: from(operation, code, message)
|
|
541
559
|
});
|
|
542
560
|
const executeList = (target, operation, copyPayload) => {
|
|
543
|
-
if (
|
|
544
|
-
const
|
|
561
|
+
if (target.node.kind !== "list") return rejected$3(operation, "invalid-address", "List target is invalid.");
|
|
562
|
+
const absent = target.value === void 0 && "optional" in target.node && target.node.optional === true;
|
|
563
|
+
if (!Array.isArray(target.value) && !absent) return rejected$3(operation, "invalid-address", "List target is invalid.");
|
|
564
|
+
if (absent && operation.type !== "list.replace") return rejected$3(operation, "invalid-address", "Only list replacement can initialize an optional list.");
|
|
565
|
+
const list = Array.isArray(target.value) ? target.value : [];
|
|
545
566
|
const orderedKeys = keys(list, target.node.keyOf);
|
|
546
567
|
const own = (value) => copyPayload ? ownPayload(value) : value;
|
|
547
568
|
if (operation.type === "list.replace") {
|
|
@@ -552,18 +573,23 @@ const executeList = (target, operation, copyPayload) => {
|
|
|
552
573
|
if (seen.has(key) || target.node.keyOf(operation.value[index]) !== key) return rejected$3(operation, "invalid-list-keys", "List replacement keys are invalid.");
|
|
553
574
|
seen.add(key);
|
|
554
575
|
}
|
|
555
|
-
if (sameStructuralValue(list, operation.value)) return { status: "unchanged" };
|
|
556
|
-
const keys =
|
|
557
|
-
|
|
558
|
-
|
|
576
|
+
if (!absent && sameStructuralValue(list, operation.value)) return { status: "unchanged" };
|
|
577
|
+
const keys = list.map(target.node.keyOf);
|
|
578
|
+
const inverse = absent ? {
|
|
579
|
+
type: "value.clear",
|
|
580
|
+
at: operation.at
|
|
581
|
+
} : {
|
|
559
582
|
type: "list.replace",
|
|
560
583
|
at: operation.at,
|
|
561
584
|
value: cloneValue(list, "inverse"),
|
|
562
585
|
keys
|
|
563
586
|
};
|
|
564
587
|
const owned = own(operation.value);
|
|
565
|
-
|
|
566
|
-
|
|
588
|
+
if (absent) target.parent[target.key] = owned;
|
|
589
|
+
else {
|
|
590
|
+
list.length = owned.length;
|
|
591
|
+
for (let index = 0; index < owned.length; index += 1) list[index] = owned[index];
|
|
592
|
+
}
|
|
567
593
|
return {
|
|
568
594
|
status: "changed",
|
|
569
595
|
inverse: [inverse]
|
|
@@ -1023,16 +1049,39 @@ const outcome = (operation, value) => value.status === "rejected" ? {
|
|
|
1023
1049
|
issue: from(operation, value.code, value.message)
|
|
1024
1050
|
} : value;
|
|
1025
1051
|
const executeTree = (root, target, operation, copyPayload) => {
|
|
1026
|
-
if (
|
|
1052
|
+
if (target.node.kind !== "tree") return {
|
|
1027
1053
|
status: "rejected",
|
|
1028
1054
|
issue: from(operation, "invalid-address", "Tree target is invalid.")
|
|
1029
1055
|
};
|
|
1030
1056
|
const own = (value) => copyPayload ? ownPayload(value) : value;
|
|
1057
|
+
const absent = target.value === void 0 && "optional" in target.node && target.node.optional === true;
|
|
1031
1058
|
if (operation.type === "tree.replace") {
|
|
1059
|
+
if (absent) {
|
|
1060
|
+
if (!validate(operation.value)) return {
|
|
1061
|
+
status: "rejected",
|
|
1062
|
+
issue: from(operation, "invalid-tree", "Tree replacement is malformed.")
|
|
1063
|
+
};
|
|
1064
|
+
target.parent[target.key] = own(operation.value);
|
|
1065
|
+
return {
|
|
1066
|
+
status: "changed",
|
|
1067
|
+
inverse: [{
|
|
1068
|
+
type: "value.clear",
|
|
1069
|
+
at: operation.at
|
|
1070
|
+
}]
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
if (!is(target.value)) return {
|
|
1074
|
+
status: "rejected",
|
|
1075
|
+
issue: from(operation, "invalid-address", "Tree target is invalid.")
|
|
1076
|
+
};
|
|
1032
1077
|
const result = replace(target.value, operation);
|
|
1033
1078
|
if (result.status === "changed") set$1(root, operation.at, ownPayload(operation.value));
|
|
1034
1079
|
return outcome(operation, result);
|
|
1035
1080
|
}
|
|
1081
|
+
if (!is(target.value)) return {
|
|
1082
|
+
status: "rejected",
|
|
1083
|
+
issue: from(operation, "invalid-address", "Tree target is invalid.")
|
|
1084
|
+
};
|
|
1036
1085
|
if (operation.type === "tree.insert") return outcome(operation, insert(target.value, operation, own(operation.value)));
|
|
1037
1086
|
if (operation.type === "tree.set") return outcome(operation, set(target.value, operation, own(operation.value)));
|
|
1038
1087
|
if (operation.type === "tree.remove") return outcome(operation, remove(target.value, operation));
|
|
@@ -1090,6 +1139,18 @@ const executeValue = (target, operation, copyPayload) => {
|
|
|
1090
1139
|
inverse: [inverse]
|
|
1091
1140
|
};
|
|
1092
1141
|
}
|
|
1142
|
+
if (operation.type === "dict.replace" && target.value === void 0) {
|
|
1143
|
+
if (!("optional" in target.node) || !target.node.optional) return rejected$1(operation, "invalid-address", "Dictionary target is invalid.");
|
|
1144
|
+
const inverse = {
|
|
1145
|
+
type: "value.clear",
|
|
1146
|
+
at: operation.at
|
|
1147
|
+
};
|
|
1148
|
+
target.parent[target.key] = own(operation.value);
|
|
1149
|
+
return {
|
|
1150
|
+
status: "changed",
|
|
1151
|
+
inverse: [inverse]
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1093
1154
|
if (!isRecord(target.value)) return rejected$1(operation, "invalid-address", "Dictionary target is invalid.");
|
|
1094
1155
|
if (operation.type === "dict.replace") {
|
|
1095
1156
|
if (sameStructuralValue(target.value, operation.value)) return { status: "unchanged" };
|
|
@@ -1138,11 +1199,67 @@ const executeValue = (target, operation, copyPayload) => {
|
|
|
1138
1199
|
};
|
|
1139
1200
|
//#endregion
|
|
1140
1201
|
//#region core/src/mutation/execute.ts
|
|
1202
|
+
const hasOwn$1 = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
1203
|
+
const executeClear = (target, operation) => {
|
|
1204
|
+
if (!("optional" in target.node) || !target.node.optional) return {
|
|
1205
|
+
status: "rejected",
|
|
1206
|
+
issue: from(operation, "required-field", "Only optional values can be cleared.")
|
|
1207
|
+
};
|
|
1208
|
+
if (!hasOwn$1(target.parent, target.key)) return { status: "unchanged" };
|
|
1209
|
+
if (target.node.kind !== "field" && target.node.kind !== "variant" && target.node.kind !== "dict" && target.node.kind !== "record" && target.node.kind !== "list" && target.node.kind !== "tree") return {
|
|
1210
|
+
status: "rejected",
|
|
1211
|
+
issue: from(operation, "invalid-operation", "This optional value has no clear operation.")
|
|
1212
|
+
};
|
|
1213
|
+
const inverse = (() => {
|
|
1214
|
+
switch (target.node.kind) {
|
|
1215
|
+
case "field": return {
|
|
1216
|
+
type: "field.set",
|
|
1217
|
+
at: operation.at,
|
|
1218
|
+
value: target.value
|
|
1219
|
+
};
|
|
1220
|
+
case "variant": return {
|
|
1221
|
+
type: "variant.replace",
|
|
1222
|
+
at: operation.at,
|
|
1223
|
+
value: cloneValue(target.value, "inverse")
|
|
1224
|
+
};
|
|
1225
|
+
case "dict":
|
|
1226
|
+
case "record": return {
|
|
1227
|
+
type: "dict.replace",
|
|
1228
|
+
at: operation.at,
|
|
1229
|
+
value: cloneValue(target.value, "inverse")
|
|
1230
|
+
};
|
|
1231
|
+
case "list":
|
|
1232
|
+
if (!Array.isArray(target.value)) return {
|
|
1233
|
+
type: "list.replace",
|
|
1234
|
+
at: operation.at,
|
|
1235
|
+
value: [],
|
|
1236
|
+
keys: []
|
|
1237
|
+
};
|
|
1238
|
+
return {
|
|
1239
|
+
type: "list.replace",
|
|
1240
|
+
at: operation.at,
|
|
1241
|
+
value: cloneValue(target.value, "inverse"),
|
|
1242
|
+
keys: target.value.map(target.node.keyOf)
|
|
1243
|
+
};
|
|
1244
|
+
case "tree": return {
|
|
1245
|
+
type: "tree.replace",
|
|
1246
|
+
at: operation.at,
|
|
1247
|
+
value: cloneValue(target.value, "inverse")
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
})();
|
|
1251
|
+
delete target.parent[target.key];
|
|
1252
|
+
return {
|
|
1253
|
+
status: "changed",
|
|
1254
|
+
inverse: [inverse]
|
|
1255
|
+
};
|
|
1256
|
+
};
|
|
1141
1257
|
const invalidTarget = (operation) => ({
|
|
1142
1258
|
status: "rejected",
|
|
1143
1259
|
issue: from(operation, "invalid-address", `Operation '${operation.type}' does not match the schema address.`)
|
|
1144
1260
|
});
|
|
1145
1261
|
const execute = (root, operation, target, copyPayload) => {
|
|
1262
|
+
if (operation.type === "value.clear") return !target ? invalidTarget(operation) : executeClear(target, operation);
|
|
1146
1263
|
if (operation.type === "field.set" || operation.type === "field.clear") return !target || target.node.kind !== "field" ? invalidTarget(operation) : executeValue(target, operation, copyPayload);
|
|
1147
1264
|
if (operation.type === "variant.replace") return !target || target.node.kind !== "variant" ? invalidTarget(operation) : executeValue(target, operation, copyPayload);
|
|
1148
1265
|
if (operation.type === "dict.set" || operation.type === "dict.delete" || operation.type === "dict.replace") return !target || target.node.kind !== "dict" && target.node.kind !== "record" ? invalidTarget(operation) : executeValue(target, operation, copyPayload);
|
|
@@ -1532,11 +1649,12 @@ const createChangeJournal = (root) => {
|
|
|
1532
1649
|
const recordValue = (resolved, operation, inverse) => {
|
|
1533
1650
|
if (find("value", operation.at, resolved.addressHash)) return;
|
|
1534
1651
|
const first = inverse[0];
|
|
1535
|
-
if (first?.type !== "field.set" && first?.type !== "field.clear") return inverseMismatch(operation);
|
|
1652
|
+
if (first?.type !== "field.set" && first?.type !== "field.clear" && first?.type !== "value.clear" && !("value" in (first ?? {}))) return inverseMismatch(operation);
|
|
1653
|
+
const before = first.type === "field.clear" || first.type === "value.clear" ? absent : "value" in first ? present(first.value) : inverseMismatch(operation);
|
|
1536
1654
|
add({
|
|
1537
1655
|
...base(resolved, operation),
|
|
1538
1656
|
kind: "value",
|
|
1539
|
-
before
|
|
1657
|
+
before
|
|
1540
1658
|
});
|
|
1541
1659
|
};
|
|
1542
1660
|
const recordVariant = (resolved, operation, inverse) => {
|
|
@@ -1579,6 +1697,18 @@ const createChangeJournal = (root) => {
|
|
|
1579
1697
|
if (!first) return inverseMismatch(operation);
|
|
1580
1698
|
let subject = find("list", operation.at, resolved.addressHash);
|
|
1581
1699
|
if (!subject) {
|
|
1700
|
+
if (first.type === "value.clear") {
|
|
1701
|
+
add({
|
|
1702
|
+
...base(resolved, operation),
|
|
1703
|
+
kind: "list",
|
|
1704
|
+
node: resolved.node,
|
|
1705
|
+
state: {
|
|
1706
|
+
mode: "whole",
|
|
1707
|
+
value: void 0
|
|
1708
|
+
}
|
|
1709
|
+
});
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1582
1712
|
if (first.type === "list.replace") {
|
|
1583
1713
|
add({
|
|
1584
1714
|
...base(resolved, operation),
|
|
@@ -1666,6 +1796,22 @@ const createChangeJournal = (root) => {
|
|
|
1666
1796
|
};
|
|
1667
1797
|
const recordTree = (resolved, operation, inverse) => {
|
|
1668
1798
|
const current = read(root, operation.at);
|
|
1799
|
+
if (inverse.length === 1 && inverse[0].type === "value.clear" && operation.type === "tree.replace") {
|
|
1800
|
+
const subject = find("tree", operation.at, resolved.addressHash);
|
|
1801
|
+
if (subject) subject.state = {
|
|
1802
|
+
mode: "whole",
|
|
1803
|
+
value: void 0
|
|
1804
|
+
};
|
|
1805
|
+
else add({
|
|
1806
|
+
...base(resolved, operation),
|
|
1807
|
+
kind: "tree",
|
|
1808
|
+
state: {
|
|
1809
|
+
mode: "whole",
|
|
1810
|
+
value: void 0
|
|
1811
|
+
}
|
|
1812
|
+
});
|
|
1813
|
+
return;
|
|
1814
|
+
}
|
|
1669
1815
|
if (!is(current)) return inverseMismatch(operation);
|
|
1670
1816
|
const inverses = inverse.filter(treeOperation);
|
|
1671
1817
|
if (inverses.length === 0 || inverses.length !== inverse.length) return inverseMismatch(operation);
|
|
@@ -1682,7 +1828,7 @@ const createChangeJournal = (root) => {
|
|
|
1682
1828
|
record: (resolved, operation, inverse) => {
|
|
1683
1829
|
profile.batch.journalRecord();
|
|
1684
1830
|
if (ownerOf(operation.at)) return;
|
|
1685
|
-
if (operation.type === "field.set" || operation.type === "field.clear") {
|
|
1831
|
+
if (operation.type === "field.set" || operation.type === "field.clear" || operation.type === "value.clear") {
|
|
1686
1832
|
recordValue(resolved, operation, inverse);
|
|
1687
1833
|
return;
|
|
1688
1834
|
}
|
|
@@ -1691,7 +1837,8 @@ const createChangeJournal = (root) => {
|
|
|
1691
1837
|
return;
|
|
1692
1838
|
}
|
|
1693
1839
|
if (operation.type === "dict.set" || operation.type === "dict.delete" || operation.type === "dict.replace") {
|
|
1694
|
-
|
|
1840
|
+
if (operation.type === "dict.replace" && inverse[0]?.type === "value.clear") recordValue(resolved, operation, inverse);
|
|
1841
|
+
else recordDict(resolved, operation, inverse);
|
|
1695
1842
|
return;
|
|
1696
1843
|
}
|
|
1697
1844
|
if (operation.type === "entity.create" || operation.type === "entity.remove" || operation.type === "entity.move") {
|
|
@@ -1792,7 +1939,8 @@ const decode = (input) => {
|
|
|
1792
1939
|
switch (input.type) {
|
|
1793
1940
|
case "field.set":
|
|
1794
1941
|
case "variant.replace": return has(input, "value") ? decoded(input) : rejected("invalid-operation", "Operation value is required.");
|
|
1795
|
-
case "field.clear":
|
|
1942
|
+
case "field.clear":
|
|
1943
|
+
case "value.clear": return decoded(input);
|
|
1796
1944
|
case "dict.set": return typeof input.key === "string" && has(input, "value") ? decoded(input) : rejected("invalid-operation", "Dictionary set requires a string key and value.");
|
|
1797
1945
|
case "dict.delete": return typeof input.key === "string" ? decoded(input) : rejected("invalid-operation", "Dictionary delete requires a string key.");
|
|
1798
1946
|
case "dict.replace": return isRecord(input.value) ? decoded(input) : rejected("invalid-operation", "Dictionary replacement must be an object.");
|
|
@@ -1985,6 +2133,7 @@ const commandFootprint = (operations) => {
|
|
|
1985
2133
|
for (const operation of operations) switch (operation.type) {
|
|
1986
2134
|
case "field.set":
|
|
1987
2135
|
case "field.clear":
|
|
2136
|
+
case "value.clear":
|
|
1988
2137
|
case "variant.replace":
|
|
1989
2138
|
add(targets, {
|
|
1990
2139
|
kind: "value",
|