@kition/kit-editor 0.2.0 → 0.3.0
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.
|
@@ -93,53 +93,53 @@ function EQ(g) {
|
|
|
93
93
|
Yg.clear();
|
|
94
94
|
const A = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map();
|
|
95
95
|
let Q = 0;
|
|
96
|
-
const C = (
|
|
96
|
+
const C = (w) => {
|
|
97
97
|
if (!g) throw "this host lends no files";
|
|
98
|
-
const G = NE(g.folder,
|
|
99
|
-
if (G.split("/").some((
|
|
98
|
+
const G = NE(g.folder, w);
|
|
99
|
+
if (G.split("/").some((h) => h.startsWith("."))) throw `${w} is not available to the kit`;
|
|
100
100
|
return new URL(G.split("/").map(encodeURIComponent).join("/"), g.root).href;
|
|
101
|
-
}, B = (
|
|
102
|
-
if (
|
|
103
|
-
const G = C(
|
|
101
|
+
}, B = (w) => {
|
|
102
|
+
if (w.startsWith(hg)) return xg(w) != null;
|
|
103
|
+
const G = C(w);
|
|
104
104
|
if (A.has(G)) return !0;
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
if (
|
|
105
|
+
const h = jg("HEAD", G);
|
|
106
|
+
if (h.status === 404) return !1;
|
|
107
|
+
if (h.status >= 400) throw `${w}: HTTP ${h.status}`;
|
|
108
108
|
return !0;
|
|
109
|
-
}, D = (
|
|
110
|
-
if (
|
|
111
|
-
const G = C(
|
|
112
|
-
if (
|
|
109
|
+
}, D = (w) => {
|
|
110
|
+
if (w.startsWith(hg)) return xg(w).byteLength;
|
|
111
|
+
const G = C(w), h = A.get(G);
|
|
112
|
+
if (h != null) return h;
|
|
113
113
|
const M = jg("HEAD", G);
|
|
114
|
-
if (M.status === 404) throw `${
|
|
115
|
-
if (M.status >= 400) throw `${
|
|
116
|
-
const
|
|
117
|
-
if (!Number.isFinite(
|
|
118
|
-
return A.set(G,
|
|
119
|
-
}, i = (
|
|
120
|
-
const
|
|
114
|
+
if (M.status === 404) throw `${w} is not in the workspace`;
|
|
115
|
+
if (M.status >= 400) throw `${w}: HTTP ${M.status}`;
|
|
116
|
+
const F = Number(M.getResponseHeader("Content-Length"));
|
|
117
|
+
if (!Number.isFinite(F) || F < 0) throw `${w}: the host reported no size`;
|
|
118
|
+
return A.set(G, F), F;
|
|
119
|
+
}, i = (w, G, h, M) => {
|
|
120
|
+
const F = `${h}:${w}`, K = I.get(F);
|
|
121
121
|
if (K)
|
|
122
|
-
return I.delete(
|
|
123
|
-
const S =
|
|
122
|
+
return I.delete(F), I.set(F, K), K;
|
|
123
|
+
const S = h * Dg, J = Math.min(M, S + Dg) - 1, Y = jg("GET", w, [S, J]);
|
|
124
124
|
if (Y.status !== 206 && Y.status !== 200) throw `${G}: HTTP ${Y.status}`;
|
|
125
125
|
let a = new Uint8Array(Y.response);
|
|
126
|
-
Y.status === 200 && (a = a.slice(S,
|
|
126
|
+
Y.status === 200 && (a = a.slice(S, J + 1)), I.set(F, a), Q += a.byteLength;
|
|
127
127
|
for (const [s, H] of I) {
|
|
128
128
|
if (Q <= oE) break;
|
|
129
129
|
I.delete(s), Q -= H.byteLength;
|
|
130
130
|
}
|
|
131
131
|
return a;
|
|
132
|
-
},
|
|
133
|
-
if (
|
|
134
|
-
const M = C(
|
|
135
|
-
for (let
|
|
136
|
-
const Y = Math.floor(
|
|
137
|
-
if (H <= 0) throw `${
|
|
138
|
-
S.set(a.subarray(s, s + H),
|
|
132
|
+
}, N = (w, G, h) => {
|
|
133
|
+
if (w.startsWith(hg)) return xg(w).slice(G, G + h);
|
|
134
|
+
const M = C(w), F = D(w), K = Math.min(F, G + h), S = new Uint8Array(Math.max(0, K - G));
|
|
135
|
+
for (let J = G; J < K; ) {
|
|
136
|
+
const Y = Math.floor(J / Dg), a = i(M, w, Y, F), s = J - Y * Dg, H = Math.min(a.byteLength - s, K - J);
|
|
137
|
+
if (H <= 0) throw `${w} is shorter than the host said`;
|
|
138
|
+
S.set(a.subarray(s, s + H), J - G), J += H;
|
|
139
139
|
}
|
|
140
140
|
return S;
|
|
141
141
|
};
|
|
142
|
-
globalThis.kitionHost = { size: D, readRange:
|
|
142
|
+
globalThis.kitionHost = { size: D, readRange: N, exists: B };
|
|
143
143
|
}
|
|
144
144
|
function kC(g) {
|
|
145
145
|
return typeof g.modelBatch == "function" && typeof g.modelDescribe == "function" ? "engine" : typeof g.exportChanges == "function" && typeof g.importChanges == "function" && typeof g.version == "function" ? "replica" : null;
|
|
@@ -302,9 +302,9 @@ function hC() {
|
|
|
302
302
|
}
|
|
303
303
|
async function cE(g, A, I) {
|
|
304
304
|
if (g.action === "begin" || g.action === "advance") {
|
|
305
|
-
const M = g.steps,
|
|
306
|
-
if (!Array.isArray(M) ||
|
|
307
|
-
const S = g.action === "advance" ? String(g.token) : String(++sE),
|
|
305
|
+
const M = g.steps, F = g.ops, K = JSON.stringify(g).length;
|
|
306
|
+
if (!Array.isArray(M) || F !== void 0 && !Array.isArray(F) || M.length + (Array.isArray(F) ? F.length : 0) > 256 || K > 1048576 || g.action === "begin" && AI.size >= 16) throw new Error("premise plan limit");
|
|
307
|
+
const S = g.action === "advance" ? String(g.token) : String(++sE), J = g.action === "advance" ? AI.get(S) : await (async () => {
|
|
308
308
|
const Y = b();
|
|
309
309
|
if (!Y.forkForPremises) throw new Error("the kit cannot fork for premise planning");
|
|
310
310
|
const a = Y.forkForPremises();
|
|
@@ -315,16 +315,16 @@ async function cE(g, A, I) {
|
|
|
315
315
|
throw a.free(), s;
|
|
316
316
|
}
|
|
317
317
|
})();
|
|
318
|
-
if (!
|
|
318
|
+
if (!J) throw new Error("premise plan unavailable");
|
|
319
319
|
AI.delete(S);
|
|
320
320
|
try {
|
|
321
|
-
if (
|
|
322
|
-
if (Array.isArray(
|
|
323
|
-
if (
|
|
324
|
-
const a = (H) => typeof H == "string" && Object.hasOwn(
|
|
325
|
-
Object.assign(
|
|
321
|
+
if (J.operations += M.length + (Array.isArray(F) ? F.length : 0), J.bytes += K, J.operations > 256 || J.bytes > 1048576) throw new Error("premise plan limit");
|
|
322
|
+
if (Array.isArray(F)) {
|
|
323
|
+
if (F.some((H) => typeof H?.ref == "string" && Object.hasOwn(J.refs, H.ref))) throw new Error("premise batch reference is already bound");
|
|
324
|
+
const a = (H) => typeof H == "string" && Object.hasOwn(J.refs, H) ? J.refs[H] : Array.isArray(H) ? H.map(a) : H && typeof H == "object" ? Object.fromEntries(Object.entries(H).map(([R, t]) => [R, a(t)])) : H, s = (await J.model.batch({ ops: a(F) }, null, !1)).refs;
|
|
325
|
+
Object.assign(J.refs, s);
|
|
326
326
|
}
|
|
327
|
-
const Y =
|
|
327
|
+
const Y = J.doc;
|
|
328
328
|
for (const a of M) {
|
|
329
329
|
if (a.context && Object.keys(a.context).length) {
|
|
330
330
|
if (!Y.setContext) throw new Error("the kit cannot set premise context");
|
|
@@ -335,9 +335,9 @@ async function cE(g, A, I) {
|
|
|
335
335
|
if (eI(s))
|
|
336
336
|
return Y.free(), { closed: !0 };
|
|
337
337
|
}
|
|
338
|
-
return
|
|
338
|
+
return J.changes = J.model.changesForPremises(J.before), J.step = Number(g.step ?? J.operations), AI.set(S, J), { token: S, beforeState: J.beforeState, state: JSON.parse(Y.editorState?.() ?? "null"), changes: J.changes, refs: J.refs };
|
|
339
339
|
} catch (Y) {
|
|
340
|
-
throw
|
|
340
|
+
throw J.doc.free(), Y;
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
const Q = String(g.token), C = AI.get(Q);
|
|
@@ -354,8 +354,8 @@ async function cE(g, A, I) {
|
|
|
354
354
|
if (!["under", "covered", "content", "state", "identity", "derived", "blob", "blob-support"].includes(D)) throw new Error("unsupported premise plan read");
|
|
355
355
|
if (D === "state") return { state: JSON.parse(C.doc.editorState?.() ?? "null"), beforeState: C.beforeState };
|
|
356
356
|
if (!C.doc.premiseRead) throw new Error("premise reads unavailable");
|
|
357
|
-
const i = () => JSON.parse(C.doc.premiseRead(D, JSON.stringify({ ...B, step: C.step, changes: C.changes, state: JSON.parse(C.doc.editorState?.() ?? "null") }))), { on:
|
|
358
|
-
return fI ? sg(C.doc, { state: null, set:
|
|
357
|
+
const i = () => JSON.parse(C.doc.premiseRead(D, JSON.stringify({ ...B, step: C.step, changes: C.changes, state: JSON.parse(C.doc.editorState?.() ?? "null") }))), { on: N, part: w, time: G } = B, h = { ...N ? { on: N } : {}, ...w ? { part: w } : {}, ...G !== void 0 ? { time: G } : {} };
|
|
358
|
+
return fI ? sg(C.doc, { state: null, set: h }, i).value : i();
|
|
359
359
|
}
|
|
360
360
|
function xC() {
|
|
361
361
|
return oQ ??= Promise.resolve().then(function() {
|
|
@@ -539,14 +539,14 @@ async function wB(g, A, I, Q = "undo") {
|
|
|
539
539
|
return wN;
|
|
540
540
|
})), D = ZA(g, "exportChanges");
|
|
541
541
|
DI ? DI.follow(D(DI.version().encode())) : DI = C.load(D(new Uint8Array(0)));
|
|
542
|
-
const i = nI(g),
|
|
543
|
-
if (nI(g) === i) return { value:
|
|
544
|
-
let
|
|
542
|
+
const i = nI(g), N = I();
|
|
543
|
+
if (nI(g) === i) return { value: N, changed: !1 };
|
|
544
|
+
let w = !1;
|
|
545
545
|
try {
|
|
546
|
-
|
|
546
|
+
w = B(DI.touched(D(DI.version().encode())));
|
|
547
547
|
} catch {
|
|
548
548
|
}
|
|
549
|
-
if (
|
|
549
|
+
if (w) return { value: N, changed: !0 };
|
|
550
550
|
throw oB(g, Q), new OA(`\`${A}\``, `\`${A}\` is not allowed: it changed more than comments, and the document is read-only`);
|
|
551
551
|
}
|
|
552
552
|
async function nE(g, A, I, Q) {
|
|
@@ -603,24 +603,24 @@ function b() {
|
|
|
603
603
|
async function xE(g) {
|
|
604
604
|
const A = b();
|
|
605
605
|
if (cA && fE(A, g.command)) {
|
|
606
|
-
const
|
|
607
|
-
if (
|
|
606
|
+
const h = hE(g.command, MC);
|
|
607
|
+
if (h) return { value: { result: await nE(A, g.command, g.params, h), info: dA(UA(A)) } };
|
|
608
608
|
if (!MC.has(g.command)) throw new OA(`\`${g.command}\``);
|
|
609
609
|
return { value: { result: await eE(A, g.command, g.params), info: dA(UA(A)) } };
|
|
610
610
|
}
|
|
611
611
|
const I = gB.has(g.command), Q = CB.has(g.command), C = (g.params.scope ?? (g.origin?.kind === "agent" ? "agent" : "person")) === "agent";
|
|
612
612
|
if (NA && (I || Q) && !C) {
|
|
613
|
-
const
|
|
614
|
-
if (M || !
|
|
613
|
+
const h = QB(A, I ? "undo" : "redo"), M = I ? NA.undo(h) : NA.redo(h);
|
|
614
|
+
if (M || !h) return { value: { result: JSON.stringify({ done: M }), info: dA(UA(A)) } };
|
|
615
615
|
}
|
|
616
616
|
const B = g.origin, D = B && typeof A.executeAs == "function", i = B?.kind === "system";
|
|
617
617
|
if (i && !D) throw new NI(cI, `\`${g.command}\` was not run: this kit cannot keep a host's change out of the undo history`);
|
|
618
|
-
const
|
|
618
|
+
const N = D ? () => A.executeAs(g.command, JSON.stringify(g.params), BB(B)) : () => A.execute(g.command, JSON.stringify(g.params)), w = () => vI(A, `\`${g.command}\``, I || Q || i ? N : () => Ug(A, N));
|
|
619
619
|
if (g.agent) {
|
|
620
|
-
const { value:
|
|
621
|
-
return eI(
|
|
620
|
+
const { value: h, state: M } = sg(A, g.agent, w);
|
|
621
|
+
return eI(h) ? JQ(A, h) : ((I || Q) && NA?.engineMoved(), { value: { result: h, info: NQ(A, !0), state: M } });
|
|
622
622
|
}
|
|
623
|
-
const G =
|
|
623
|
+
const G = w();
|
|
624
624
|
return eI(G) ? JQ(A, G) : ((I || Q) && NA?.engineMoved(), { value: { result: G, info: NQ(A, !0) } });
|
|
625
625
|
}
|
|
626
626
|
function eI(g) {
|
|
@@ -920,8 +920,8 @@ function XE(g) {
|
|
|
920
920
|
else if (C > 0 && C <= 16) D = `${Q.slice(0, C)}.${Q.slice(C)}`;
|
|
921
921
|
else if (C > -5 && C <= 0) D = `0.${"0".repeat(-C)}${Q}`;
|
|
922
922
|
else {
|
|
923
|
-
const i = C - 1,
|
|
924
|
-
D = `${Q[0]}${
|
|
923
|
+
const i = C - 1, N = Q.length > 1 ? `.${Q.slice(1)}` : "";
|
|
924
|
+
D = `${Q[0]}${N}e${i < 0 ? "-" : "+"}${Math.abs(i)}`;
|
|
925
925
|
}
|
|
926
926
|
return B + D;
|
|
927
927
|
}
|
|
@@ -979,15 +979,15 @@ function KC(g, A) {
|
|
|
979
979
|
try {
|
|
980
980
|
if (Array.isArray(C)) {
|
|
981
981
|
Object.getPrototypeOf(C) !== Array.prototype && D("an array subclass");
|
|
982
|
-
const
|
|
983
|
-
for (let
|
|
984
|
-
|
|
985
|
-
return
|
|
982
|
+
const N = [];
|
|
983
|
+
for (let w = 0; w < C.length; w += 1)
|
|
984
|
+
w in C || D("a hole"), N.push(Q(C[w], `${B}[${w}]`));
|
|
985
|
+
return N;
|
|
986
986
|
}
|
|
987
987
|
OE(C) || D(`a ${C.constructor?.name ?? "non-plain object"}`), Object.getOwnPropertySymbols(C).length > 0 && D("a symbol key");
|
|
988
988
|
const i = {};
|
|
989
|
-
for (const
|
|
990
|
-
|
|
989
|
+
for (const N of Object.keys(C))
|
|
990
|
+
N === "__proto__" && D("a `__proto__` key"), kA(i, YI(N), Q(C[N], `${B}.${N}`));
|
|
991
991
|
return i;
|
|
992
992
|
} finally {
|
|
993
993
|
I.delete(C);
|
|
@@ -1004,9 +1004,9 @@ function hB(g, A) {
|
|
|
1004
1004
|
if (i !== null)
|
|
1005
1005
|
C.push([i, B]);
|
|
1006
1006
|
else if (I(D))
|
|
1007
|
-
for (const
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1007
|
+
for (const N of Object.keys(D).sort(j)) {
|
|
1008
|
+
const w = Q(D[N]);
|
|
1009
|
+
w !== null && C.push([w, `${B}.${N}`]);
|
|
1010
1010
|
}
|
|
1011
1011
|
}
|
|
1012
1012
|
return C;
|
|
@@ -1048,15 +1048,15 @@ function JB(g, A) {
|
|
|
1048
1048
|
if (!X(A.members) || !["json", "map"].includes(I.kind) && Object.keys(A.members).length > 0) throw y.schema(`${g}: members requires json or map and an object`);
|
|
1049
1049
|
I.members = {};
|
|
1050
1050
|
for (const [Q, C] of Object.entries(A.members)) {
|
|
1051
|
-
if (Q.split(".").some((
|
|
1051
|
+
if (Q.split(".").some((w) => !/^[^.[\]]+(?:\[\])*$/.test(w))) throw y.schema(`${g}: invalid member path ${Q}`);
|
|
1052
1052
|
if (!X(C)) throw y.schema(`${g}: member limits must be an object`);
|
|
1053
1053
|
KA(g, C, ["minimum", "maximum", "multipleOf", "nullable"]);
|
|
1054
1054
|
const { nullable: B, ...D } = C;
|
|
1055
1055
|
if (B !== void 0 && typeof B != "boolean") throw y.schema(`${g}: nullable is a boolean`);
|
|
1056
|
-
const i = JB(`${g}.${Q}`, { kind: "number", ...D }),
|
|
1057
|
-
B === !0 && (
|
|
1058
|
-
for (const
|
|
1059
|
-
kA(I.members, Q,
|
|
1056
|
+
const i = JB(`${g}.${Q}`, { kind: "number", ...D }), N = {};
|
|
1057
|
+
B === !0 && (N.nullable = !0);
|
|
1058
|
+
for (const w of ["minimum", "maximum", "multipleOf"]) i[w] !== void 0 && (N[w] = i[w]);
|
|
1059
|
+
kA(I.members, Q, N);
|
|
1060
1060
|
}
|
|
1061
1061
|
}
|
|
1062
1062
|
if (A.of !== void 0 && A.of !== null) {
|
|
@@ -1147,49 +1147,49 @@ function $E(g) {
|
|
|
1147
1147
|
if (C.projectedOps !== void 0) {
|
|
1148
1148
|
if (!D.projected || !X(C.projectedOps)) throw y.schema(`type \`${Q}\`: projectedOps requires projected:true`);
|
|
1149
1149
|
const i = {};
|
|
1150
|
-
for (const [
|
|
1151
|
-
if (!
|
|
1150
|
+
for (const [N, w] of Object.entries(C.projectedOps)) {
|
|
1151
|
+
if (!N || !X(w) || typeof w.command != "string" || !w.command || Object.keys(w).some((G) => !["command", "params"].includes(G)) || w.params !== void 0 && (!X(w.params) || Object.entries(w.params).some(([G, h]) => !G || typeof h != "string" || h.split(".").some((M) => !M))))
|
|
1152
1152
|
throw y.schema(`type \`${Q}\`: projectedOps needs an operation, command and parameter paths`);
|
|
1153
|
-
kA(i,
|
|
1153
|
+
kA(i, N, { command: w.command, ...X(w.params) ? { params: { ...w.params } } : {} });
|
|
1154
1154
|
}
|
|
1155
1155
|
Object.keys(i).length && (D.projectedOps = i);
|
|
1156
1156
|
}
|
|
1157
1157
|
if (C.structuralConsequences !== void 0) {
|
|
1158
1158
|
const i = C.structuralConsequences;
|
|
1159
1159
|
if (!Array.isArray(i) || i.some(
|
|
1160
|
-
(
|
|
1160
|
+
(N) => !X(N) || Object.keys(N).some((w) => !["container", "on", "fields"].includes(w)) || typeof N.container != "string" || !Object.hasOwn(A, N.container) || !Array.isArray(N.on) || !N.on.length || N.on.some((w) => !["create", "delete", "move", "rename"].includes(w) && !(w === "set" && Object.values(A).some((G) => X(G) && G.projected === !0))) || !Array.isArray(N.fields) || !N.fields.length || N.fields.some((w) => typeof w != "string" || w.split(".").some((G) => !G) || !B[w.split(".")[0]] || w.includes(".") && !["json", "map"].includes(B[w.split(".")[0]].kind))
|
|
1161
1161
|
)) throw y.schema(`type \`${Q}\`: structuralConsequences needs a declared container, structural actions and stored field paths`);
|
|
1162
|
-
i.length && (D.structuralConsequences = i.map((
|
|
1162
|
+
i.length && (D.structuralConsequences = i.map((N) => ({ container: N.container, on: [...N.on], fields: [...N.fields] })));
|
|
1163
1163
|
}
|
|
1164
1164
|
if (C.moveConsequences !== void 0) {
|
|
1165
1165
|
if (!Array.isArray(C.moveConsequences) || C.moveConsequences.some((i) => {
|
|
1166
|
-
if (typeof i != "string" || i.split(".").some((
|
|
1167
|
-
const
|
|
1168
|
-
return !
|
|
1166
|
+
if (typeof i != "string" || i.split(".").some((w) => !w)) return !0;
|
|
1167
|
+
const N = B[i.split(".")[0]];
|
|
1168
|
+
return !N?.position || i.includes(".") && N.kind !== "json";
|
|
1169
1169
|
})) throw y.schema(`type \`${Q}\`: moveConsequences must name position fields or their JSON members`);
|
|
1170
1170
|
C.moveConsequences.length && (D.moveConsequences = [...C.moveConsequences]);
|
|
1171
1171
|
}
|
|
1172
1172
|
if (C.creation !== void 0) {
|
|
1173
1173
|
if (!X(C.creation)) throw y.schema("creation is an object");
|
|
1174
1174
|
KA("creation", C.creation, ["fields", "command", "fixtures"]);
|
|
1175
|
-
for (const
|
|
1175
|
+
for (const N of ["fields", "fixtures"]) if (C.creation[N] !== void 0 && !X(C.creation[N])) throw y.schema(`creation.${N} is an object`);
|
|
1176
1176
|
const i = C.creation.command;
|
|
1177
1177
|
if (i !== void 0) {
|
|
1178
1178
|
if (!X(i) || typeof i.command != "string" || !i.command) throw y.schema("creation command required");
|
|
1179
|
-
if (KA("creation command", i, ["command", "params"]), i.params !== void 0 && (!X(i.params) || Object.entries(i.params).some(([
|
|
1179
|
+
if (KA("creation command", i, ["command", "params"]), i.params !== void 0 && (!X(i.params) || Object.entries(i.params).some(([N, w]) => !N || typeof w != "string" || w.split(".").some((G) => !G)))) throw y.schema("invalid creation command paths");
|
|
1180
1180
|
}
|
|
1181
1181
|
D.creation = structuredClone(C.creation);
|
|
1182
1182
|
}
|
|
1183
1183
|
if (C.batchOps !== void 0) {
|
|
1184
1184
|
if (!X(C.batchOps)) throw y.schema(`type \`${Q}\`: batchOps is a mapping`);
|
|
1185
1185
|
const i = {};
|
|
1186
|
-
for (const [
|
|
1187
|
-
if (!
|
|
1188
|
-
if (
|
|
1189
|
-
KA("direct batchOps",
|
|
1186
|
+
for (const [N, w] of Object.entries(C.batchOps)) {
|
|
1187
|
+
if (!N || !X(w)) throw y.schema("invalid batchOps operation");
|
|
1188
|
+
if (w.direct === !0)
|
|
1189
|
+
KA("direct batchOps", w, ["direct"]), i[N] = { direct: !0 };
|
|
1190
1190
|
else {
|
|
1191
|
-
if (KA("command batchOps",
|
|
1192
|
-
i[
|
|
1191
|
+
if (KA("command batchOps", w, ["command", "params"]), typeof w.command != "string" || !w.command || w.params !== void 0 && (!X(w.params) || Object.entries(w.params).some(([G, h]) => !G || typeof h != "string" || h.split(".").some((M) => !M)))) throw y.schema("invalid batchOps command");
|
|
1192
|
+
i[N] = { command: w.command, params: w.params };
|
|
1193
1193
|
}
|
|
1194
1194
|
}
|
|
1195
1195
|
D.batchOps = i;
|
|
@@ -1206,7 +1206,7 @@ function $E(g) {
|
|
|
1206
1206
|
const i = C.readOnlyWhen;
|
|
1207
1207
|
if (!X(i)) throw y.schema(`type \`${Q}\`: \`readOnlyWhen\` is { field, values }`);
|
|
1208
1208
|
if (KA(`type \`${Q}\` readOnlyWhen`, i, ["field", "values"]), typeof i.field != "string") throw y.schema(`type \`${Q}\`: \`readOnlyWhen.field\` is a field name`);
|
|
1209
|
-
if (!Array.isArray(i.values) || !i.values.every((
|
|
1209
|
+
if (!Array.isArray(i.values) || !i.values.every((N) => typeof N == "string")) throw y.schema(`type \`${Q}\`: \`readOnlyWhen.values\` is a list of strings`);
|
|
1210
1210
|
D.readOnlyWhen = { field: i.field, values: [...i.values] };
|
|
1211
1211
|
}
|
|
1212
1212
|
if (C.toolId !== void 0 && C.toolId !== null) {
|
|
@@ -1218,27 +1218,27 @@ function $E(g) {
|
|
|
1218
1218
|
D.toolId = { field: i.field, prefix: typeof i.prefix == "string" ? i.prefix : "", ...typeof i.parent == "string" ? { parent: i.parent } : {} };
|
|
1219
1219
|
}
|
|
1220
1220
|
if (C.pathName !== void 0 && C.pathName !== null) {
|
|
1221
|
-
const i = C.pathName,
|
|
1222
|
-
if (typeof i != "string" || !
|
|
1221
|
+
const i = C.pathName, N = typeof i == "string" ? B[i.split(".")[0]]?.kind : void 0, w = N === "json" || (N === "string" || N === "enum") && typeof i == "string" && !i.includes(".");
|
|
1222
|
+
if (typeof i != "string" || !w) throw y.schema(`type \`${Q}\`: \`pathName\` \`${String(i)}\` names no string or enum field, nor a member of a json field`);
|
|
1223
1223
|
D.pathName = i;
|
|
1224
1224
|
}
|
|
1225
1225
|
for (const i of ["label", "text"]) if (C[i] !== void 0 && C[i] !== null) {
|
|
1226
|
-
const
|
|
1227
|
-
if (typeof
|
|
1228
|
-
D[i] =
|
|
1226
|
+
const N = C[i], w = typeof N == "string" ? B[N.split(".")[0]]?.kind : void 0, G = w === "json" || (w === "string" || w === "text" || w === "enum") && typeof N == "string" && !N.includes(".");
|
|
1227
|
+
if (typeof N != "string" || !G) throw y.schema(`type \`${Q}\`: \`${i}\` \`${String(N)}\` names no string, text or enum field, nor a member of a json field`);
|
|
1228
|
+
D[i] = N;
|
|
1229
1229
|
}
|
|
1230
1230
|
if (C.derived !== void 0 && C.derived !== null) {
|
|
1231
1231
|
if (!X(C.derived)) throw y.schema(`type \`${Q}\`: \`derived\` is an object of names`);
|
|
1232
1232
|
const i = {};
|
|
1233
|
-
for (const
|
|
1234
|
-
if (!/^[A-Za-z0-9_]+$/.test(
|
|
1235
|
-
const
|
|
1236
|
-
if (!X(
|
|
1237
|
-
if (KA(`type \`${Q}\` derived \`${
|
|
1238
|
-
if (
|
|
1239
|
-
if (
|
|
1240
|
-
if (
|
|
1241
|
-
kA(i,
|
|
1233
|
+
for (const N of Z(C.derived)) {
|
|
1234
|
+
if (!/^[A-Za-z0-9_]+$/.test(N)) throw y.schema(`type \`${Q}\`: derived \`${N}\` is no name (ASCII letters, digits and \`_\`)`);
|
|
1235
|
+
const w = C.derived[N];
|
|
1236
|
+
if (!X(w)) throw y.schema(`type \`${Q}\`: derived \`${N}\` is { description? }`);
|
|
1237
|
+
if (KA(`type \`${Q}\` derived \`${N}\``, w, ["description", "premiseOnly", "onDemand"]), w.description !== void 0 && typeof w.description != "string") throw y.schema(`type \`${Q}\`: derived \`${N}\`.description is a string`);
|
|
1238
|
+
if (w.premiseOnly !== void 0 && typeof w.premiseOnly != "boolean") throw y.schema(`type \`${Q}\`: derived \`${N}\`.premiseOnly is a boolean`);
|
|
1239
|
+
if (w.onDemand !== void 0 && typeof w.onDemand != "boolean") throw y.schema(`type \`${Q}\`: derived \`${N}\`.onDemand is a boolean`);
|
|
1240
|
+
if (w.onDemand && !w.premiseOnly) throw y.schema(`type \`${Q}\`: onDemand derived facts require premiseOnly`);
|
|
1241
|
+
kA(i, N, { ...typeof w.description == "string" ? { description: w.description } : {}, ...w.premiseOnly ? { premiseOnly: !0 } : {}, ...w.onDemand ? { onDemand: !0 } : {} });
|
|
1242
1242
|
}
|
|
1243
1243
|
Object.keys(i).length > 0 && (D.derived = i);
|
|
1244
1244
|
}
|
|
@@ -1267,32 +1267,32 @@ function AD(g) {
|
|
|
1267
1267
|
for (const B of Z(Q.fields)) {
|
|
1268
1268
|
const D = Q.fields[B];
|
|
1269
1269
|
if (B.startsWith("$") || B.startsWith("~")) throw y.schema(`\`${I}.${B}\`: names starting with \`$\` or \`~\` are reserved`);
|
|
1270
|
-
const i = uE.includes(D.kind),
|
|
1271
|
-
if (D.of !== void 0 && !i && !
|
|
1270
|
+
const i = uE.includes(D.kind), N = D.kind === "map" && D.owns === !0;
|
|
1271
|
+
if (D.of !== void 0 && !i && !N) throw y.schema(`\`${I}.${B}\`: only ref, list, and tree fields take \`of\``);
|
|
1272
1272
|
if (D.owns && (D.kind === "list" || D.kind === "tree"))
|
|
1273
1273
|
throw y.schema(`\`${I}.${B}\`: only ref fields take \`owns\` (list and tree fields always own their items)`);
|
|
1274
1274
|
if (D.owns && D.kind !== "ref" && D.kind !== "map") throw y.schema(`\`${I}.${B}\`: only ref and map fields take \`owns\``);
|
|
1275
1275
|
if (D.values?.length && D.kind !== "enum") throw y.schema(`\`${I}.${B}\`: only enum fields take \`values\``);
|
|
1276
1276
|
if (D.kind === "enum" && !D.values?.length) throw y.schema(`\`${I}.${B}\`: an enum needs \`values\``);
|
|
1277
|
-
if (i ||
|
|
1277
|
+
if (i || N && D.of !== void 0) {
|
|
1278
1278
|
if (D.of === void 0) throw y.schema(`\`${I}.${B}\` needs \`of\``);
|
|
1279
1279
|
if (!Object.hasOwn(g.types, D.of)) throw y.schema(`\`${I}.${B}\` refers to undeclared type \`${D.of}\``);
|
|
1280
1280
|
}
|
|
1281
|
-
const
|
|
1281
|
+
const w = D.marks ?? {}, G = Z(w);
|
|
1282
1282
|
if (G.length > 0 && D.kind !== "text") throw y.schema(`\`${I}.${B}\`: only text fields take \`marks\``);
|
|
1283
|
-
for (const
|
|
1284
|
-
const M = vE(
|
|
1285
|
-
if (M !== null) throw y.schema(`\`${I}.${B}\` mark \`${
|
|
1286
|
-
const
|
|
1287
|
-
if (K !== void 0 && K !==
|
|
1288
|
-
throw y.schema(`\`${I}.${B}\` mark \`${
|
|
1289
|
-
A.set(
|
|
1283
|
+
for (const h of G) {
|
|
1284
|
+
const M = vE(h);
|
|
1285
|
+
if (M !== null) throw y.schema(`\`${I}.${B}\` mark \`${h}\`: ${M}`);
|
|
1286
|
+
const F = w[h].expand, K = A.get(h);
|
|
1287
|
+
if (K !== void 0 && K !== F)
|
|
1288
|
+
throw y.schema(`\`${I}.${B}\` mark \`${h}\` expands \`${F}\`, but it is declared elsewhere expanding \`${K}\`; a mark key has one expand in a schema`);
|
|
1289
|
+
A.set(h, F);
|
|
1290
1290
|
}
|
|
1291
1291
|
}
|
|
1292
1292
|
}
|
|
1293
1293
|
}
|
|
1294
1294
|
function ID(g, A, I) {
|
|
1295
|
-
const Q = (
|
|
1295
|
+
const Q = (h) => y.schema(`type \`${A}\`: \`toolId\` ${h}`), C = g.types[A].fields;
|
|
1296
1296
|
if (!Object.hasOwn(C, I.field)) throw Q(`names undeclared field \`${I.field}\``);
|
|
1297
1297
|
const B = C[I.field];
|
|
1298
1298
|
if (B.kind !== "integer" && B.kind !== "string") throw Q(`names \`${I.field}\`, which is not an integer or a string`);
|
|
@@ -1302,16 +1302,16 @@ function ID(g, A, I) {
|
|
|
1302
1302
|
const i = I.parent;
|
|
1303
1303
|
if (i === void 0) return;
|
|
1304
1304
|
if (!Object.hasOwn(g.types, i)) throw Q(`names undeclared parent type \`${i}\``);
|
|
1305
|
-
const
|
|
1306
|
-
if (
|
|
1307
|
-
if (!Object.values(
|
|
1305
|
+
const N = g.types[i];
|
|
1306
|
+
if (N.toolId === void 0) throw Q(`names parent \`${i}\`, which declares no \`toolId\``);
|
|
1307
|
+
if (!Object.values(N.fields).some((h) => (h.kind === "list" || h.kind === "tree" || h.kind === "ref" || h.kind === "map" && h.owns) && h.of === A))
|
|
1308
1308
|
throw Q(`names parent \`${i}\`, which has no list, tree, or ref field of \`${A}\``);
|
|
1309
|
-
const
|
|
1309
|
+
const w = [];
|
|
1310
1310
|
let G = i;
|
|
1311
1311
|
for (; G !== void 0; ) {
|
|
1312
1312
|
if (G === A) throw Q(`parent \`${i}\` leads back to \`${A}\`: parents form no cycle`);
|
|
1313
|
-
if (
|
|
1314
|
-
|
|
1313
|
+
if (w.includes(G)) break;
|
|
1314
|
+
w.push(G), G = Object.hasOwn(g.types, G) ? g.types[G].toolId?.parent : void 0;
|
|
1315
1315
|
}
|
|
1316
1316
|
}
|
|
1317
1317
|
function FB(g) {
|
|
@@ -1346,10 +1346,10 @@ function yC(g, A, I, Q) {
|
|
|
1346
1346
|
}
|
|
1347
1347
|
const B = KC(Q, (i) => y.invalidValue(A, I, i));
|
|
1348
1348
|
if (SC(A, I, B, C), C.members !== void 0 && Object.keys(C.members).length > 0) {
|
|
1349
|
-
for (const [i,
|
|
1350
|
-
if (!(Array.isArray(
|
|
1351
|
-
if (typeof
|
|
1352
|
-
SC(A, I,
|
|
1349
|
+
for (const [i, N] of Object.entries(C.members)) for (const w of aI(B, i))
|
|
1350
|
+
if (!(Array.isArray(w) || X(w) || w === null && N.nullable)) {
|
|
1351
|
+
if (typeof w != "number") throw y.invalidValue(A, I, "bounded members require a number or an explicitly nullable null");
|
|
1352
|
+
SC(A, I, w, N);
|
|
1353
1353
|
}
|
|
1354
1354
|
}
|
|
1355
1355
|
let D;
|
|
@@ -1394,10 +1394,10 @@ function gD(g, A, I, Q, C) {
|
|
|
1394
1394
|
const B = zA(g, A, I);
|
|
1395
1395
|
if (B.of !== void 0 && (typeof C != "string" || C === "")) throw y.invalidValue(A, I, `map entry \`${Q}\` expects the id of a \`${B.of}\``);
|
|
1396
1396
|
for (const [D, i] of Object.entries(B.members ?? {}))
|
|
1397
|
-
for (const
|
|
1398
|
-
if (!(Array.isArray(
|
|
1399
|
-
if (typeof
|
|
1400
|
-
SC(A, I,
|
|
1397
|
+
for (const N of aI({ [Q]: C }, D))
|
|
1398
|
+
if (!(Array.isArray(N) || X(N) || N === null && i.nullable)) {
|
|
1399
|
+
if (typeof N != "number") throw y.invalidValue(A, I, `map entry \`${Q}\` requires a number`);
|
|
1400
|
+
SC(A, I, N, i);
|
|
1401
1401
|
}
|
|
1402
1402
|
}
|
|
1403
1403
|
const SQ = 20;
|
|
@@ -1450,8 +1450,8 @@ function ED(g) {
|
|
|
1450
1450
|
objectsOfType: (C) => Object.keys(A).filter((B) => gI(A[B]) && A[B].$type === C).sort(j),
|
|
1451
1451
|
register: I,
|
|
1452
1452
|
held: (C, B, D) => {
|
|
1453
|
-
const i = I(C, B),
|
|
1454
|
-
return D === "list" && Array.isArray(i) ?
|
|
1453
|
+
const i = I(C, B), N = [];
|
|
1454
|
+
return D === "list" && Array.isArray(i) ? N.push(...i.filter((w) => typeof w == "string")) : D === "tree" ? Q(i, N) : D === "ref" && typeof i == "string" && N.push(i), N.filter((w) => Object.hasOwn(A, w));
|
|
1455
1455
|
},
|
|
1456
1456
|
map: (C, B) => I(C, B),
|
|
1457
1457
|
exists: (C) => Object.hasOwn(A, C)
|
|
@@ -1461,17 +1461,17 @@ function DD(g, A, I) {
|
|
|
1461
1461
|
const Q = I.map(([C, B]) => {
|
|
1462
1462
|
const D = B === void 0 ? void 0 : g.types[B]?.pathName;
|
|
1463
1463
|
if (D === void 0) return null;
|
|
1464
|
-
const [i, ...
|
|
1465
|
-
let
|
|
1466
|
-
for (const G of
|
|
1467
|
-
return { text: typeof
|
|
1464
|
+
const [i, ...N] = D.split(".");
|
|
1465
|
+
let w = A.register(C, i);
|
|
1466
|
+
for (const G of N) w = gI(w) ? w[G] ?? null : null;
|
|
1467
|
+
return { text: typeof w == "string" ? w : null };
|
|
1468
1468
|
});
|
|
1469
1469
|
return Q.map((C, B) => {
|
|
1470
1470
|
if (C === null) return null;
|
|
1471
1471
|
const D = C.text, i = D !== null && D !== "" && !/[/.#@]/.test(D) && !/^\d+$/.test(D) ? D : null;
|
|
1472
1472
|
if (i === null) return `#${B + 1}`;
|
|
1473
|
-
const
|
|
1474
|
-
return
|
|
1473
|
+
const N = Q.slice(0, B).filter((w) => w !== null && w.text === i).length;
|
|
1474
|
+
return N === 0 ? i : `${i}#${N + 1}`;
|
|
1475
1475
|
});
|
|
1476
1476
|
}
|
|
1477
1477
|
function iD(g) {
|
|
@@ -1543,38 +1543,38 @@ class $ {
|
|
|
1543
1543
|
return D.set(Y, R), R;
|
|
1544
1544
|
};
|
|
1545
1545
|
for (const Y of [...C.keys()].sort(j)) i(Y, 0);
|
|
1546
|
-
const
|
|
1546
|
+
const N = /* @__PURE__ */ new Map();
|
|
1547
1547
|
for (const [Y, a] of D) {
|
|
1548
1548
|
const s = C.get(Y);
|
|
1549
1549
|
if (a === null || s === void 0) continue;
|
|
1550
|
-
const H =
|
|
1551
|
-
H.push({ id: Y, type: s.type, value: s.value }),
|
|
1550
|
+
const H = N.get(a) ?? [];
|
|
1551
|
+
H.push({ id: Y, type: s.type, value: s.value }), N.set(a, H);
|
|
1552
1552
|
}
|
|
1553
|
-
const
|
|
1554
|
-
for (const Y of [...
|
|
1555
|
-
const a =
|
|
1556
|
-
G.set(Y, a), a.length === 1 &&
|
|
1553
|
+
const w = /* @__PURE__ */ new Map(), G = /* @__PURE__ */ new Map();
|
|
1554
|
+
for (const Y of [...N.keys()].sort(j)) {
|
|
1555
|
+
const a = N.get(Y).sort((s, H) => j(s.type, H.type) || j(s.id, H.id));
|
|
1556
|
+
G.set(Y, a), a.length === 1 && w.set(a[0].id, Y);
|
|
1557
1557
|
}
|
|
1558
|
-
const
|
|
1559
|
-
if (M) for (const Y of Z(A.types)) for (const a of I.objectsOfType(Y))
|
|
1558
|
+
const h = /* @__PURE__ */ new Map(), M = Object.values(A.types).some((Y) => Y.pathName !== void 0), F = /* @__PURE__ */ new Map();
|
|
1559
|
+
if (M) for (const Y of Z(A.types)) for (const a of I.objectsOfType(Y)) F.set(a, Y);
|
|
1560
1560
|
for (const Y of Z(A.types)) {
|
|
1561
1561
|
const a = A.types[Y].fields;
|
|
1562
1562
|
for (const s of Z(a)) {
|
|
1563
1563
|
const H = a[s];
|
|
1564
1564
|
if (MB(H))
|
|
1565
1565
|
for (const R of I.objectsOfType(Y)) {
|
|
1566
|
-
const t = H.kind === "map" ? hB(I.map(R, s), (r) => I.exists(r)) : I.held(R, s, H.kind).map((r, x) => [r, H.kind === "ref" ? null : String(x)]), d = M && H.kind === "list" ? DD(A, I, t.map(([r]) => [r,
|
|
1566
|
+
const t = H.kind === "map" ? hB(I.map(R, s), (r) => I.exists(r)) : I.held(R, s, H.kind).map((r, x) => [r, H.kind === "ref" ? null : String(x)]), d = M && H.kind === "list" ? DD(A, I, t.map(([r]) => [r, F.get(r)])) : [];
|
|
1567
1567
|
t.forEach(([r, x], IA) => {
|
|
1568
|
-
const c =
|
|
1569
|
-
c.some((L) => L.owner === R && L.field === s) || c.push({ owner: R, field: s, at: x, name: d[IA] ?? null }),
|
|
1568
|
+
const c = h.get(r) ?? [];
|
|
1569
|
+
c.some((L) => L.owner === R && L.field === s) || c.push({ owner: R, field: s, at: x, name: d[IA] ?? null }), h.set(r, c);
|
|
1570
1570
|
});
|
|
1571
1571
|
}
|
|
1572
1572
|
}
|
|
1573
1573
|
}
|
|
1574
1574
|
const K = (Y) => {
|
|
1575
|
-
const a =
|
|
1575
|
+
const a = w.get(Y);
|
|
1576
1576
|
if (a !== void 0) return a;
|
|
1577
|
-
const s =
|
|
1577
|
+
const s = h.get(Y);
|
|
1578
1578
|
return s !== void 0 && s.length === 1 && s[0].at !== null && /^\d+$/.test(s[0].at) ? s[0].at : null;
|
|
1579
1579
|
}, S = (Y) => {
|
|
1580
1580
|
const a = Y.indexOf("."), s = a < 0 ? Y : Y.slice(0, a), H = a < 0 ? null : Y.slice(a + 1);
|
|
@@ -1585,14 +1585,14 @@ class $ {
|
|
|
1585
1585
|
R = t.join(":");
|
|
1586
1586
|
}
|
|
1587
1587
|
return H === null ? R : `${R}.${H}`;
|
|
1588
|
-
},
|
|
1589
|
-
for (const Y of
|
|
1588
|
+
}, J = [];
|
|
1589
|
+
for (const Y of h.values())
|
|
1590
1590
|
for (const a of Y) {
|
|
1591
1591
|
const s = a.at === null ? null : S(a.at);
|
|
1592
|
-
s !== null &&
|
|
1592
|
+
s !== null && J.push([a, s]);
|
|
1593
1593
|
}
|
|
1594
|
-
for (const [Y, a] of
|
|
1595
|
-
return new $(!0,
|
|
1594
|
+
for (const [Y, a] of J) Y.at = a;
|
|
1595
|
+
return new $(!0, w, G, h);
|
|
1596
1596
|
}
|
|
1597
1597
|
/**
|
|
1598
1598
|
* As the Rust `ToolIds::attributed`: for an object without a tool id of its own, the nearest
|
|
@@ -1629,8 +1629,8 @@ class $ {
|
|
|
1629
1629
|
const [i] = D;
|
|
1630
1630
|
if (i.name !== null ? I.push(i.name) : I.length === 0 && (i.at !== null && Q.push(i.at), Q.push(i.field)), this.own.has(i.owner)) {
|
|
1631
1631
|
if (I.length === 0) return null;
|
|
1632
|
-
const
|
|
1633
|
-
return Q.length === 0 ?
|
|
1632
|
+
const N = I.reverse().join("/");
|
|
1633
|
+
return Q.length === 0 ? N : `${N}.${Q.reverse().join(".")}`;
|
|
1634
1634
|
}
|
|
1635
1635
|
C = i.owner;
|
|
1636
1636
|
}
|
|
@@ -1706,90 +1706,90 @@ class SB {
|
|
|
1706
1706
|
for (const i of I) {
|
|
1707
1707
|
if (!i.id || i.id === "root" || i.id.startsWith("$") || Object.hasOwn(Q, i.id) || this.objects.has(i.id))
|
|
1708
1708
|
throw z(`projected id \`${i.id}\` is reserved, duplicated or shadows a stored object`);
|
|
1709
|
-
const
|
|
1710
|
-
if (!
|
|
1711
|
-
for (const [
|
|
1712
|
-
const
|
|
1713
|
-
if (!
|
|
1709
|
+
const N = Object.hasOwn(C.types, i.type) ? C.types[i.type] : void 0;
|
|
1710
|
+
if (!N?.projected) throw z(`\`${i.type}\` is not a projected type`);
|
|
1711
|
+
for (const [w, G] of Object.entries(i.fields)) {
|
|
1712
|
+
const h = Object.hasOwn(N.fields, w) ? N.fields[w] : void 0;
|
|
1713
|
+
if (!h) throw z(`unknown projected field \`${i.type}.${w}\``);
|
|
1714
1714
|
let M;
|
|
1715
|
-
if (
|
|
1716
|
-
else if (
|
|
1717
|
-
else if (
|
|
1715
|
+
if (h.kind === "text") M = typeof G == "string" || !!h.marks && Object.keys(h.marks).length > 0 && Array.isArray(G);
|
|
1716
|
+
else if (h.kind === "list" || h.kind === "tree") M = Array.isArray(G);
|
|
1717
|
+
else if (h.kind === "map") M = typeof G == "object" && G !== null && !Array.isArray(G);
|
|
1718
1718
|
else
|
|
1719
1719
|
try {
|
|
1720
|
-
lC(C, i.type,
|
|
1720
|
+
lC(C, i.type, w, G), M = !0;
|
|
1721
1721
|
} catch {
|
|
1722
1722
|
M = !1;
|
|
1723
1723
|
}
|
|
1724
|
-
if (!M) throw z(`invalid projected value \`${i.type}.${
|
|
1724
|
+
if (!M) throw z(`invalid projected value \`${i.type}.${w}\``);
|
|
1725
1725
|
}
|
|
1726
|
-
for (const [
|
|
1727
|
-
const
|
|
1728
|
-
if (!G.optional && !
|
|
1726
|
+
for (const [w, G] of Object.entries(N.fields)) {
|
|
1727
|
+
const h = aC(C, G);
|
|
1728
|
+
if (!G.optional && !h && !Object.hasOwn(i.fields, w)) throw z(`missing projected field \`${i.type}.${w}\``);
|
|
1729
1729
|
}
|
|
1730
1730
|
YC(Q, i.id, { ...structuredClone(i.fields), $type: i.type }), this.objects.set(i.id, structuredClone(i));
|
|
1731
1731
|
}
|
|
1732
|
-
const B = /* @__PURE__ */ new Map(), D = (i,
|
|
1733
|
-
for (const [i,
|
|
1734
|
-
for (const [
|
|
1732
|
+
const B = /* @__PURE__ */ new Map(), D = (i, N) => JSON.stringify([i, N]);
|
|
1733
|
+
for (const [i, N] of Object.entries(Q))
|
|
1734
|
+
for (const [w, G] of Object.entries(C.types[N.$type].fields))
|
|
1735
1735
|
if (aC(C, G)) {
|
|
1736
|
-
if (w
|
|
1737
|
-
B.set(D(i,
|
|
1736
|
+
if (N[w] !== null && N[w] !== void 0 && (!Array.isArray(N[w]) || N[w].length)) throw z(`\`${i}.${w}\`: projected membership must come from object placements`);
|
|
1737
|
+
B.set(D(i, w), { parent: i, field: w, kind: G.kind, groups: /* @__PURE__ */ new Map() });
|
|
1738
1738
|
}
|
|
1739
1739
|
for (const i of this.objects.values()) {
|
|
1740
1740
|
if (!i.at) continue;
|
|
1741
|
-
const
|
|
1742
|
-
if (!
|
|
1743
|
-
if (
|
|
1744
|
-
const
|
|
1745
|
-
if (
|
|
1741
|
+
const N = i.at, w = B.get(D(N.parent, N.field));
|
|
1742
|
+
if (!w) throw z(`\`${i.id}\` has no projected container \`${N.parent}.${N.field}\``);
|
|
1743
|
+
if (N.node !== void 0) {
|
|
1744
|
+
const F = this.objects.get(N.node)?.at;
|
|
1745
|
+
if (w.kind !== "tree" || F?.parent !== N.parent || F.field !== N.field) throw z("projected tree parent belongs to another container");
|
|
1746
1746
|
}
|
|
1747
|
-
const G = Q[
|
|
1748
|
-
if (C.types[G.$type].fields[
|
|
1749
|
-
const
|
|
1750
|
-
if (!Number.isSafeInteger(
|
|
1751
|
-
const M =
|
|
1752
|
-
M.push([
|
|
1753
|
-
}
|
|
1754
|
-
for (const { parent: i, field:
|
|
1755
|
-
for (const
|
|
1756
|
-
if (
|
|
1757
|
-
const
|
|
1747
|
+
const G = Q[N.parent];
|
|
1748
|
+
if (C.types[G.$type].fields[N.field].of !== i.type) throw z(`projected placement has the wrong type for \`${i.id}\``);
|
|
1749
|
+
const h = N.index ?? 0;
|
|
1750
|
+
if (!Number.isSafeInteger(h) || h < 0) throw z("projected index is a nonnegative integer");
|
|
1751
|
+
const M = w.groups.get(N.node) ?? [];
|
|
1752
|
+
M.push([h, i.id]), w.groups.set(N.node, M);
|
|
1753
|
+
}
|
|
1754
|
+
for (const { parent: i, field: N, kind: w, groups: G } of B.values()) {
|
|
1755
|
+
for (const F of G.values())
|
|
1756
|
+
if (F.sort(([K, S], [J, Y]) => K - J || S.localeCompare(Y)), F.some(([K], S) => K !== S)) throw z(`\`${i}.${N}\`: projected indexes must be contiguous and unique`);
|
|
1757
|
+
const h = G.get(void 0) ?? [];
|
|
1758
1758
|
let M;
|
|
1759
|
-
if (
|
|
1760
|
-
if (
|
|
1761
|
-
M =
|
|
1762
|
-
} else if (
|
|
1763
|
-
const
|
|
1764
|
-
if (
|
|
1759
|
+
if (w === "ref") {
|
|
1760
|
+
if (h.length > 1) throw z("a projected owning ref holds at most one object");
|
|
1761
|
+
M = h[0]?.[1] ?? null;
|
|
1762
|
+
} else if (w === "tree") {
|
|
1763
|
+
const F = /* @__PURE__ */ new Set(), K = (S, J) => {
|
|
1764
|
+
if (J > 64) throw z("projected tree exceeds depth limit");
|
|
1765
1765
|
return (G.get(S) ?? []).map(([, Y]) => {
|
|
1766
|
-
if (
|
|
1767
|
-
return
|
|
1766
|
+
if (F.has(Y)) throw z("projected placements contain a cycle");
|
|
1767
|
+
return F.add(Y), { object: Y, children: K(Y, J + 1) };
|
|
1768
1768
|
});
|
|
1769
1769
|
};
|
|
1770
|
-
if (M = K(void 0, 0),
|
|
1771
|
-
} else M =
|
|
1772
|
-
YC(Q[i],
|
|
1770
|
+
if (M = K(void 0, 0), F.size !== [...G.values()].reduce((S, J) => S + J.length, 0)) throw z("projected placements contain an unreachable tree cycle");
|
|
1771
|
+
} else M = h.map(([, F]) => F);
|
|
1772
|
+
YC(Q[i], N, M);
|
|
1773
1773
|
}
|
|
1774
1774
|
for (const i of this.objects.values()) {
|
|
1775
|
-
const
|
|
1776
|
-
let
|
|
1777
|
-
for (;
|
|
1778
|
-
if (
|
|
1779
|
-
|
|
1775
|
+
const N = /* @__PURE__ */ new Set([i.id]);
|
|
1776
|
+
let w = i;
|
|
1777
|
+
for (; w.at && (w = this.objects.get(w.at.parent)); ) {
|
|
1778
|
+
if (N.has(w.id)) throw z("projected placements contain a cycle");
|
|
1779
|
+
N.add(w.id);
|
|
1780
1780
|
}
|
|
1781
1781
|
}
|
|
1782
1782
|
}
|
|
1783
1783
|
load(A, I, Q) {
|
|
1784
1784
|
const C = I === "root" ? A ?? "" : I;
|
|
1785
1785
|
if (!Object.hasOwn(this.state.objects, C)) throw new n("not-found", null, `no object \`${I}\``);
|
|
1786
|
-
const B = this.state.objects[C], D = Q ?? Object.keys(B).filter((
|
|
1787
|
-
if (!Array.isArray(D) || D.some((
|
|
1788
|
-
const i = Object.fromEntries(D.map((
|
|
1789
|
-
if (!Object.hasOwn(B,
|
|
1790
|
-
return [
|
|
1791
|
-
})),
|
|
1792
|
-
return { id: C, type: B.$type, fields: i, ...
|
|
1786
|
+
const B = this.state.objects[C], D = Q ?? Object.keys(B).filter((w) => w !== "$type");
|
|
1787
|
+
if (!Array.isArray(D) || D.some((w) => typeof w != "string")) throw z("fields lists names");
|
|
1788
|
+
const i = Object.fromEntries(D.map((w) => {
|
|
1789
|
+
if (!Object.hasOwn(B, w)) throw z(`unknown field \`${w}\``);
|
|
1790
|
+
return [w, structuredClone(B[w])];
|
|
1791
|
+
})), N = this.objects.get(C);
|
|
1792
|
+
return { id: C, type: B.$type, fields: i, ...N ? { projected: !0, ...N.at ? { at: { ...N.at } } : {} } : {} };
|
|
1793
1793
|
}
|
|
1794
1794
|
}
|
|
1795
1795
|
function wD(g, A, I, Q) {
|
|
@@ -1799,42 +1799,42 @@ function wD(g, A, I, Q) {
|
|
|
1799
1799
|
let i = A.objects.get(D)?.type;
|
|
1800
1800
|
if (B === "create") i = typeof C.type == "string" && g.types[C.type]?.projected ? C.type : void 0;
|
|
1801
1801
|
else if ((!i || B === "set" || B.startsWith("list.") || B.startsWith("tree.")) && Object.hasOwn(A.state.objects, D) && typeof C.field == "string") {
|
|
1802
|
-
const
|
|
1802
|
+
const F = A.state.objects[D], K = g.types[F.$type].fields[C.field];
|
|
1803
1803
|
if (K?.of && g.types[K.of]?.projected) {
|
|
1804
|
-
const S = g.types[
|
|
1805
|
-
if (K.readOnly || S.readOnly || S.readOnlyWhen && S.readOnlyWhen.values.includes(
|
|
1804
|
+
const S = g.types[F.$type];
|
|
1805
|
+
if (K.readOnly || S.readOnly || S.readOnlyWhen && S.readOnlyWhen.values.includes(F[S.readOnlyWhen.field])) throw new n("read-only", null, "the projected container is read-only");
|
|
1806
1806
|
i = K.of;
|
|
1807
|
-
const
|
|
1807
|
+
const J = B === "list.move" ? C.from : C.index, Y = F[C.field], a = C.item ?? C.node ?? (K.kind === "ref" ? C.value : void 0) ?? (Array.isArray(Y) && typeof J == "number" ? Y[J] : void 0);
|
|
1808
1808
|
a !== void 0 && (C.in = `${D}.${C.field}`, C.target = a, K.kind === "ref" && B === "set" && (B = "ref.set", C.op = B, delete C.field));
|
|
1809
1809
|
}
|
|
1810
1810
|
}
|
|
1811
1811
|
if (!i) return;
|
|
1812
1812
|
if (typeof C.in == "string") {
|
|
1813
|
-
const
|
|
1814
|
-
if (
|
|
1815
|
-
const K = C.in.slice(0,
|
|
1813
|
+
const F = C.in.lastIndexOf(".");
|
|
1814
|
+
if (F < 1) throw z("a projected destination names parent.field");
|
|
1815
|
+
const K = C.in.slice(0, F), S = A.state.objects[K === "root" ? I : K], J = S && g.types[S.$type], Y = J?.fields[C.in.slice(F + 1)];
|
|
1816
1816
|
if (!Y || !aC(g, Y) || Y.of !== i) throw z("projected destination must own the object's type");
|
|
1817
|
-
if (Y.readOnly ||
|
|
1817
|
+
if (Y.readOnly || J.readOnly || J.readOnlyWhen && J.readOnlyWhen.values.includes(S[J.readOnlyWhen.field])) throw new n("read-only", null, "the projected container is read-only");
|
|
1818
1818
|
}
|
|
1819
|
-
const
|
|
1820
|
-
if (
|
|
1819
|
+
const N = g.types[i], w = typeof C.field == "string" ? C.field : void 0, G = A.state.objects[typeof C.target == "string" ? C.target : D];
|
|
1820
|
+
if (N.readOnly || N.readOnlyWhen && N.readOnlyWhen.values.includes(G?.[N.readOnlyWhen.field]) || w && N.fields[w]?.readOnly) throw new n("read-only", null, `projected \`${i}\` is read-only`);
|
|
1821
1821
|
if (B === "set") {
|
|
1822
|
-
if (!
|
|
1822
|
+
if (!w) throw z("a projected set needs a field");
|
|
1823
1823
|
try {
|
|
1824
|
-
lC(g, i,
|
|
1825
|
-
} catch (
|
|
1826
|
-
throw z(String(
|
|
1824
|
+
lC(g, i, w, C.value);
|
|
1825
|
+
} catch (F) {
|
|
1826
|
+
throw z(String(F));
|
|
1827
1827
|
}
|
|
1828
1828
|
}
|
|
1829
|
-
const
|
|
1830
|
-
if (!
|
|
1829
|
+
const h = (w ? N.projectedOps?.[`${B}.${w}`] : void 0) ?? N.projectedOps?.[B];
|
|
1830
|
+
if (!h) throw new n("read-only", null, `no projected command mapping for \`${i}.${B}\``);
|
|
1831
1831
|
const M = {};
|
|
1832
|
-
for (const [
|
|
1832
|
+
for (const [F, K] of Object.entries(h.params ?? {})) {
|
|
1833
1833
|
let S = C;
|
|
1834
|
-
for (const
|
|
1835
|
-
S !== void 0 && YC(M,
|
|
1834
|
+
for (const J of K.split(".")) S = S !== null && typeof S == "object" && Object.hasOwn(S, J) ? S[J] : void 0;
|
|
1835
|
+
S !== void 0 && YC(M, F, S);
|
|
1836
1836
|
}
|
|
1837
|
-
return { command:
|
|
1837
|
+
return { command: h.command, params: M, ...B === "create" ? { creates: i } : {} };
|
|
1838
1838
|
}
|
|
1839
1839
|
const YB = "KitObjectModel 1.0";
|
|
1840
1840
|
class n extends Error {
|
|
@@ -1905,10 +1905,10 @@ function lg(g, A, I, Q, C, B, D) {
|
|
|
1905
1905
|
if (typeof D != "string" || !I.isActive() || D === "") return D;
|
|
1906
1906
|
const i = A.types[C]?.fields[B];
|
|
1907
1907
|
if (!i || !(i.kind === "ref" || i.kind === "map" && i.of !== void 0)) return D;
|
|
1908
|
-
const
|
|
1909
|
-
if (!KB(
|
|
1910
|
-
if (
|
|
1911
|
-
throw cB(Q,
|
|
1908
|
+
const N = I.resolve(D, (w) => g.exists(w));
|
|
1909
|
+
if (!KB(N)) return N;
|
|
1910
|
+
if (N.reason === "not-found") return D;
|
|
1911
|
+
throw cB(Q, N);
|
|
1912
1912
|
}
|
|
1913
1913
|
function kD(g, A, I) {
|
|
1914
1914
|
if (!g.isActive()) return I;
|
|
@@ -1955,16 +1955,16 @@ async function LB(g, A) {
|
|
|
1955
1955
|
if (C.forEach((R, t) => {
|
|
1956
1956
|
D = aB.has(RB(t, R)) || D;
|
|
1957
1957
|
}), D && g.readOnly?.()) throw new n("read-only", null, "the document is read-only");
|
|
1958
|
-
const i = (await g.replica()).schema,
|
|
1958
|
+
const i = (await g.replica()).schema, N = jC(i), w = async () => N ? $.ofReplica(await g.replica()) : $.none();
|
|
1959
1959
|
let G = /* @__PURE__ */ new Map();
|
|
1960
|
-
const
|
|
1960
|
+
const h = C.map(() => null), M = yB(i), F = async () => {
|
|
1961
1961
|
if (!g.projectedObjects) throw new n("invalid-value", null, "this adapter cannot read declared projected objects");
|
|
1962
1962
|
const R = await g.projectedObjects();
|
|
1963
1963
|
return new SB(await g.replica(), R);
|
|
1964
1964
|
}, K = async (R) => {
|
|
1965
1965
|
if (!M || R.op === "command") return;
|
|
1966
|
-
const t = await
|
|
1967
|
-
return wD(i, t, r ? (await
|
|
1966
|
+
const t = await F(), d = await g.replica(), r = LI(d);
|
|
1967
|
+
return wD(i, t, r ? (await w()).show(r) : "", jA(R, G));
|
|
1968
1968
|
};
|
|
1969
1969
|
let S = 0;
|
|
1970
1970
|
for (; S < C.length; ) {
|
|
@@ -1980,30 +1980,30 @@ async function LB(g, A) {
|
|
|
1980
1980
|
if (t.creates) {
|
|
1981
1981
|
const p = typeof L == "string" ? L : QI(L) ? L.id : void 0;
|
|
1982
1982
|
if (typeof p != "string") throw new n("invalid-op", S, "a projected create command must return its id");
|
|
1983
|
-
if ((await
|
|
1983
|
+
if ((await F()).objects.get(p)?.type !== t.creates) throw new n("invalid-op", S, "a projected create command returned no live object of its type");
|
|
1984
1984
|
typeof R.ref == "string" && G.set(R.ref, p);
|
|
1985
1985
|
}
|
|
1986
|
-
|
|
1986
|
+
h[S++] = L ?? null;
|
|
1987
1987
|
continue;
|
|
1988
1988
|
}
|
|
1989
1989
|
if (R.op === "command") {
|
|
1990
1990
|
if (typeof R.id != "string") throw new n("invalid-op", S, "a command needs an `id`");
|
|
1991
1991
|
let L = {};
|
|
1992
|
-
if (R.params !== void 0 &&
|
|
1993
|
-
const p = await
|
|
1992
|
+
if (R.params !== void 0 && N && G.size > 0) {
|
|
1993
|
+
const p = await w();
|
|
1994
1994
|
L = jA(R.params, new Map([...G].map(([f, T]) => [f, p.show(T)])));
|
|
1995
1995
|
} else R.params !== void 0 && (L = jA(R.params, G));
|
|
1996
1996
|
try {
|
|
1997
1997
|
const p = R.at;
|
|
1998
1998
|
let f = G;
|
|
1999
|
-
if (
|
|
2000
|
-
const m = await
|
|
1999
|
+
if (N && G.size > 0) {
|
|
2000
|
+
const m = await w();
|
|
2001
2001
|
f = new Map([...G].map(([v, YA]) => [v, m.show(YA)]));
|
|
2002
2002
|
}
|
|
2003
2003
|
const T = Object.fromEntries(Object.entries({ on: R.on, part: p?.part, time: p?.time }).filter(([, m]) => m !== void 0).map(([m, v]) => [m, jA(v, f)]));
|
|
2004
2004
|
if (Object.keys(T).length > 0 && !g.commandAt) throw new Error("this batch adapter cannot apply explicit command context");
|
|
2005
|
-
if (
|
|
2006
|
-
const m =
|
|
2005
|
+
if (h[S] = await (g.commandAt ? g.commandAt(R.id, L, T, I) : g.command(R.id, L, I)) ?? null, typeof R.ref == "string") {
|
|
2006
|
+
const m = h[S], v = typeof m == "string" ? m : QI(m) && typeof m.id == "string" ? m.id : void 0;
|
|
2007
2007
|
if (!v) throw new Error("a bound command must return its object id");
|
|
2008
2008
|
const YA = await g.replica(), Eg = $.ofReplica(YA).resolve(v, (EE) => YA.exists(EE));
|
|
2009
2009
|
if (typeof Eg != "string") throw new Error("a bound command returned no live object");
|
|
@@ -2017,7 +2017,7 @@ async function LB(g, A) {
|
|
|
2017
2017
|
}
|
|
2018
2018
|
const d = S;
|
|
2019
2019
|
for (; S < C.length && C[S].op !== "command" && !await K(C[S]); ) S += 1;
|
|
2020
|
-
const r = S, x = await
|
|
2020
|
+
const r = S, x = await w();
|
|
2021
2021
|
let IA = G, c = [];
|
|
2022
2022
|
await g.transact(I, (L) => {
|
|
2023
2023
|
IA = new Map(G), c = [];
|
|
@@ -2025,42 +2025,42 @@ async function LB(g, A) {
|
|
|
2025
2025
|
const f = () => p === void 0 ? p = L.objectsOfType(i.root)[0] ?? null : p;
|
|
2026
2026
|
for (let T = d; T < r; T += 1) c.push(hD(L, i, x, T, C[T], IA, f));
|
|
2027
2027
|
}), G = IA, c.forEach((L, p) => {
|
|
2028
|
-
|
|
2028
|
+
h[d + p] = L;
|
|
2029
2029
|
});
|
|
2030
2030
|
}
|
|
2031
|
-
const
|
|
2031
|
+
const J = await w(), Y = await g.replica(), a = M ? await F() : void 0, s = B.map((R, t) => {
|
|
2032
2032
|
try {
|
|
2033
2033
|
if (a) {
|
|
2034
2034
|
if (!QI(R) || typeof R.target != "string") throw new n("invalid-op", null, "`target` is a string");
|
|
2035
|
-
return a.load(LI(Y) ?
|
|
2035
|
+
return a.load(LI(Y) ? J.show(LI(Y)) : null, G.get(R.target) ?? R.target, R.fields);
|
|
2036
2036
|
}
|
|
2037
|
-
return JD(Y,
|
|
2037
|
+
return JD(Y, J, R, G);
|
|
2038
2038
|
} catch (d) {
|
|
2039
2039
|
const r = sB(null, d);
|
|
2040
2040
|
throw new n(r.code, null, `load ${t}: ${r.message}`);
|
|
2041
2041
|
}
|
|
2042
2042
|
});
|
|
2043
|
-
|
|
2044
|
-
|
|
2043
|
+
J.isActive() && h.forEach((R, t) => {
|
|
2044
|
+
h[t] = J.showJson(R);
|
|
2045
2045
|
});
|
|
2046
|
-
const H = { refs: Object.fromEntries([...G].map(([R, t]) => [R,
|
|
2047
|
-
return A.objects && (H.objects = [...Object.keys(i.types).flatMap((R) => Y.objectsOfType(R).map((t) => ({ id:
|
|
2046
|
+
const H = { refs: Object.fromEntries([...G].map(([R, t]) => [R, J.show(t)])), results: h, loaded: s };
|
|
2047
|
+
return A.objects && (H.objects = [...Object.keys(i.types).flatMap((R) => Y.objectsOfType(R).map((t) => ({ id: J.show(t), type: R }))), ...[...a?.objects.values() ?? []].map((R) => ({ id: R.id, type: R.type, projected: !0, at: R.at }))].sort((R, t) => R.id < t.id ? -1 : R.id > t.id ? 1 : 0)), H;
|
|
2048
2048
|
}
|
|
2049
2049
|
function Tg(g, A, I, Q, C, B) {
|
|
2050
2050
|
const D = (M) => new n("invalid-op", Q, `\`field\` \`${B}\`: ${M}`);
|
|
2051
|
-
let i = C,
|
|
2052
|
-
const
|
|
2053
|
-
if (
|
|
2051
|
+
let i = C, N = B;
|
|
2052
|
+
const w = B.split(".")[0];
|
|
2053
|
+
if (w.includes("/") || w.includes("#")) {
|
|
2054
2054
|
let M = null;
|
|
2055
|
-
const
|
|
2056
|
-
for (;
|
|
2057
|
-
const S =
|
|
2055
|
+
const F = [C], K = /* @__PURE__ */ new Set();
|
|
2056
|
+
for (; F.length > 0; ) {
|
|
2057
|
+
const S = F.pop();
|
|
2058
2058
|
if (K.has(S) || K.size > 1e5) continue;
|
|
2059
2059
|
K.add(S);
|
|
2060
|
-
const
|
|
2061
|
-
if (
|
|
2062
|
-
const a = B.slice(
|
|
2063
|
-
(a === "" || a.startsWith(".")) && (M === null ||
|
|
2060
|
+
const J = I.namedPath(S);
|
|
2061
|
+
if (J !== null && B.startsWith(J)) {
|
|
2062
|
+
const a = B.slice(J.length);
|
|
2063
|
+
(a === "" || a.startsWith(".")) && (M === null || J.length > M[1]) && (M = [S, J.length]);
|
|
2064
2064
|
}
|
|
2065
2065
|
let Y;
|
|
2066
2066
|
try {
|
|
@@ -2071,48 +2071,48 @@ function Tg(g, A, I, Q, C, B) {
|
|
|
2071
2071
|
if (Object.hasOwn(A.types, Y))
|
|
2072
2072
|
for (const a of Z(A.types[Y].fields)) {
|
|
2073
2073
|
const s = A.types[Y].fields[a];
|
|
2074
|
-
if (s.kind === "list")
|
|
2074
|
+
if (s.kind === "list") F.push(...g.listItems(S, a));
|
|
2075
2075
|
else if (s.kind === "ref" && s.owns === !0) {
|
|
2076
2076
|
const H = g.get(S, a);
|
|
2077
|
-
typeof H == "string" && H !== "" &&
|
|
2077
|
+
typeof H == "string" && H !== "" && F.push(H);
|
|
2078
2078
|
}
|
|
2079
2079
|
}
|
|
2080
2080
|
}
|
|
2081
2081
|
if (M === null) throw D("no object the target holds has that name in the kit's words");
|
|
2082
|
-
i = M[0],
|
|
2083
|
-
}
|
|
2084
|
-
const G =
|
|
2085
|
-
let
|
|
2086
|
-
for (;
|
|
2087
|
-
const M = G[
|
|
2088
|
-
if (!Object.hasOwn(A.types,
|
|
2089
|
-
const K = A.types[
|
|
2090
|
-
if (
|
|
2091
|
-
const
|
|
2092
|
-
if (
|
|
2093
|
-
return [i, M,
|
|
2082
|
+
i = M[0], N = B.slice(M[1]).replace(/^\.+/, "");
|
|
2083
|
+
}
|
|
2084
|
+
const G = N.split(".");
|
|
2085
|
+
let h = 0;
|
|
2086
|
+
for (; h < G.length; ) {
|
|
2087
|
+
const M = G[h], F = g.objectType(i);
|
|
2088
|
+
if (!Object.hasOwn(A.types, F) || !Object.hasOwn(A.types[F].fields, M)) throw D(`\`${F}\` has no field \`${M}\``);
|
|
2089
|
+
const K = A.types[F].fields[M];
|
|
2090
|
+
if (h + 1 === G.length || !["ref", "list", "map", "tree"].includes(K.kind)) {
|
|
2091
|
+
const J = G.slice(h + 1);
|
|
2092
|
+
if (J.length > 0 && K.kind !== "json") throw D(`\`${F}.${M}\` is no json value to go into`);
|
|
2093
|
+
return [i, M, J];
|
|
2094
2094
|
}
|
|
2095
2095
|
let S = null;
|
|
2096
2096
|
if (K.kind === "ref" && K.owns === !0) {
|
|
2097
|
-
const
|
|
2098
|
-
S = typeof
|
|
2097
|
+
const J = g.get(i, M);
|
|
2098
|
+
S = typeof J == "string" && J !== "" ? J : null;
|
|
2099
2099
|
} else if (K.kind === "list") {
|
|
2100
|
-
|
|
2101
|
-
const
|
|
2102
|
-
if (
|
|
2103
|
-
const Y = Number(
|
|
2100
|
+
h += 1;
|
|
2101
|
+
const J = G[h];
|
|
2102
|
+
if (J === void 0 || !/^\d+$/.test(J)) throw D(`\`${M}\` is a list: give an index after it`);
|
|
2103
|
+
const Y = Number(J), a = g.listItems(i, M);
|
|
2104
2104
|
if (Y >= a.length) throw D(`\`${M}\` has ${a.length} items, not ${Y + 1}`);
|
|
2105
2105
|
S = a[Y];
|
|
2106
2106
|
} else if (K.kind === "map" && K.owns === !0) {
|
|
2107
|
-
|
|
2108
|
-
const
|
|
2109
|
-
if (
|
|
2110
|
-
const Y = g.mapGet(i, M,
|
|
2107
|
+
h += 1;
|
|
2108
|
+
const J = G[h];
|
|
2109
|
+
if (J === void 0) throw D(`\`${M}\` is a map: give a key after it`);
|
|
2110
|
+
const Y = g.mapGet(i, M, J);
|
|
2111
2111
|
S = typeof Y == "string" && Y !== "" ? Y : null;
|
|
2112
|
-
} else throw K.kind === "ref" || K.kind === "map" ? D(`\`${
|
|
2113
|
-
if (S === null) throw D(`\`${
|
|
2112
|
+
} else throw K.kind === "ref" || K.kind === "map" ? D(`\`${F}.${M}\` does not own what it names: a path goes through owning fields only`) : D(`\`${F}.${M}\` is a tree: a path does not go through trees`);
|
|
2113
|
+
if (S === null) throw D(`\`${F}.${M}\` holds nothing there`);
|
|
2114
2114
|
if (I.toolId(S) !== null) throw D(`it reaches \`${I.show(S)}\`, which has a tool id of its own: target it by that id`);
|
|
2115
|
-
i = S,
|
|
2115
|
+
i = S, h += 1;
|
|
2116
2116
|
}
|
|
2117
2117
|
throw D("it names no field");
|
|
2118
2118
|
}
|
|
@@ -2121,15 +2121,15 @@ function GD(g, A, I) {
|
|
|
2121
2121
|
const C = g === void 0 ? null : JSON.parse(JSON.stringify(g));
|
|
2122
2122
|
let B = C;
|
|
2123
2123
|
for (const [D, i] of A.entries()) {
|
|
2124
|
-
const
|
|
2124
|
+
const N = D === A.length - 1;
|
|
2125
2125
|
if (Array.isArray(B) && /^\d+$/.test(i)) {
|
|
2126
|
-
const
|
|
2127
|
-
if (
|
|
2128
|
-
|
|
2126
|
+
const w = Number(i);
|
|
2127
|
+
if (w >= B.length) throw new Error(N ? `no item ${w}` : `no item ${w} at \`${i}\``);
|
|
2128
|
+
N ? B[w] = I : B = B[w];
|
|
2129
2129
|
} else {
|
|
2130
2130
|
if (B === null || typeof B != "object" || Array.isArray(B)) throw new Error(`\`${i}\` is in no object`);
|
|
2131
|
-
const
|
|
2132
|
-
|
|
2131
|
+
const w = B;
|
|
2132
|
+
N ? w[i] = I : (Object.hasOwn(w, i) || (w[i] = null), B = w[i]);
|
|
2133
2133
|
}
|
|
2134
2134
|
}
|
|
2135
2135
|
return C;
|
|
@@ -2143,9 +2143,9 @@ function JA(g, A, I, Q, C, B) {
|
|
|
2143
2143
|
}
|
|
2144
2144
|
if (!Object.hasOwn(A.types, D)) return;
|
|
2145
2145
|
const i = A.types[D];
|
|
2146
|
-
if (pg(i, (
|
|
2146
|
+
if (pg(i, (w) => {
|
|
2147
2147
|
try {
|
|
2148
|
-
return g.get(C,
|
|
2148
|
+
return g.get(C, w);
|
|
2149
2149
|
} catch {
|
|
2150
2150
|
return;
|
|
2151
2151
|
}
|
|
@@ -2164,25 +2164,25 @@ function Zg(g, A, I, Q, C) {
|
|
|
2164
2164
|
const B = A.types[Q];
|
|
2165
2165
|
for (const [D, i] of C) {
|
|
2166
2166
|
if (!Object.hasOwn(B.fields, D) || typeof i != "string") continue;
|
|
2167
|
-
const
|
|
2168
|
-
if (!(
|
|
2169
|
-
const
|
|
2167
|
+
const N = B.fields[D];
|
|
2168
|
+
if (!(N.kind === "ref" || N.kind === "map" && N.of !== void 0) || g.exists(i)) continue;
|
|
2169
|
+
const w = N.of ?? "object";
|
|
2170
2170
|
throw new n(
|
|
2171
2171
|
"not-found",
|
|
2172
2172
|
I,
|
|
2173
|
-
`\`${Q}.${D}\` holds the id of a \`${
|
|
2173
|
+
`\`${Q}.${D}\` holds the id of a \`${w}\`, and no object has the id \`${i}\`: give the id of an existing \`${w}\` (a load or query answers them), or create one earlier in the batch and use its \`$name\``
|
|
2174
2174
|
);
|
|
2175
2175
|
}
|
|
2176
2176
|
}
|
|
2177
2177
|
function hD(g, A, I, Q, C, B, D) {
|
|
2178
|
-
const i = RB(Q, C),
|
|
2179
|
-
const [K, S,
|
|
2180
|
-
if (
|
|
2178
|
+
const i = RB(Q, C), N = (M) => g.exists(M) || i === "delete" && g.wasDeleted(M), w = (M) => cg(C[M], B, I, N, D, Q), G = (M, F) => {
|
|
2179
|
+
const [K, S, J] = Tg(g, A, I, Q, M, F);
|
|
2180
|
+
if (J.length) throw new n("invalid-op", Q, "a container operation requires a container field, not a JSON member");
|
|
2181
2181
|
return [K, S];
|
|
2182
|
-
},
|
|
2183
|
-
if (!
|
|
2184
|
-
const [K, S,
|
|
2185
|
-
if (
|
|
2182
|
+
}, h = (M, F) => {
|
|
2183
|
+
if (!F.includes(".") && !F.includes("/")) return [M, F];
|
|
2184
|
+
const [K, S, J] = Tg(g, A, I, Q, M, F);
|
|
2185
|
+
if (J.length) throw new n("invalid-op", Q, `\`field\` \`${F}\`: \`${i}\` ${i === "text.set" ? "replaces" : "edits"} a text field, not a path inside a value`);
|
|
2186
2186
|
return [K, S];
|
|
2187
2187
|
};
|
|
2188
2188
|
try {
|
|
@@ -2190,22 +2190,22 @@ function hD(g, A, I, Q, C, B, D) {
|
|
|
2190
2190
|
case "create": {
|
|
2191
2191
|
const M = gA(Q, C, "type");
|
|
2192
2192
|
if (C.fields !== void 0 && C.fields !== null && !QI(C.fields)) throw new n("invalid-op", Q, "`fields` is an object");
|
|
2193
|
-
const
|
|
2194
|
-
for (const a of Z(
|
|
2193
|
+
const F = jA(C.fields ?? {}, B) ?? {}, K = {};
|
|
2194
|
+
for (const a of Z(F)) K[a] = lg(g, A, I, Q, M, a, F[a]);
|
|
2195
2195
|
const S = C.ref;
|
|
2196
2196
|
if (S != null && !(typeof S == "string" && S.length > 1 && S.startsWith("$")))
|
|
2197
2197
|
throw new n("invalid-op", Q, "`ref` is a name starting with `$`");
|
|
2198
|
-
let
|
|
2198
|
+
let J = null;
|
|
2199
2199
|
if (C.in !== void 0 && C.in !== null) {
|
|
2200
2200
|
const a = C.in, s = typeof a == "string" ? a.indexOf(".") : -1;
|
|
2201
2201
|
if (typeof a != "string" || s < 0) throw new n("invalid-op", Q, '`in` is "<target>.<field>"');
|
|
2202
|
-
|
|
2202
|
+
J = G(cg(a.slice(0, s), B, I, N, D, Q), a.slice(s + 1));
|
|
2203
2203
|
}
|
|
2204
2204
|
if (C.id !== void 0 && C.id !== null && typeof C.id != "string") throw new n("invalid-op", Q, "`id` is a string");
|
|
2205
2205
|
MD(A, Q, M, K), Zg(g, A, Q, M, Z(K).map((a) => [a, K[a]]));
|
|
2206
2206
|
const Y = g.create(M, K, typeof C.id == "string" ? { id: C.id } : void 0);
|
|
2207
|
-
if (
|
|
2208
|
-
const [a, s] =
|
|
2207
|
+
if (J) {
|
|
2208
|
+
const [a, s] = J, H = g.objectType(a), R = zA(A, H, s).kind;
|
|
2209
2209
|
if (JA(g, A, I, Q, a, s), R === "list") g.listInsert(a, s, UQ(Q, C.at, g.listItems(a, s).length), Y);
|
|
2210
2210
|
else if (R === "tree") {
|
|
2211
2211
|
if (C.at !== void 0 && C.at !== null && C.at !== "end") throw new n("invalid-op", Q, "`at` places items in lists; a tree adds a node last among its siblings");
|
|
@@ -2215,9 +2215,9 @@ function hD(g, A, I, Q, C, B, D) {
|
|
|
2215
2215
|
return typeof S == "string" && B.set(S, Y), Y;
|
|
2216
2216
|
}
|
|
2217
2217
|
case "set": {
|
|
2218
|
-
let M =
|
|
2219
|
-
if (
|
|
2220
|
-
const Y =
|
|
2218
|
+
let M = w("target"), F = gA(Q, C, "field"), K = C.value === void 0 ? null : jA(C.value, B);
|
|
2219
|
+
if (F.includes(".") || F.includes("/")) {
|
|
2220
|
+
const Y = F, [a, s, H] = Tg(g, A, I, Q, M, Y);
|
|
2221
2221
|
if (H.length > 0) {
|
|
2222
2222
|
let R = null;
|
|
2223
2223
|
try {
|
|
@@ -2231,81 +2231,81 @@ function hD(g, A, I, Q, C, B, D) {
|
|
|
2231
2231
|
throw new n("invalid-op", Q, `\`field\` \`${Y}\`: ${t.message}`);
|
|
2232
2232
|
}
|
|
2233
2233
|
}
|
|
2234
|
-
M = a,
|
|
2234
|
+
M = a, F = s;
|
|
2235
2235
|
}
|
|
2236
2236
|
let S = K;
|
|
2237
2237
|
try {
|
|
2238
|
-
S = lg(g, A, I, Q, g.objectType(M),
|
|
2238
|
+
S = lg(g, A, I, Q, g.objectType(M), F, K);
|
|
2239
2239
|
} catch (Y) {
|
|
2240
2240
|
if (Y instanceof n) throw Y;
|
|
2241
2241
|
}
|
|
2242
|
-
JA(g, A, I, Q, M,
|
|
2243
|
-
let
|
|
2242
|
+
JA(g, A, I, Q, M, F);
|
|
2243
|
+
let J = null;
|
|
2244
2244
|
try {
|
|
2245
|
-
|
|
2245
|
+
J = g.objectType(M);
|
|
2246
2246
|
} catch {
|
|
2247
|
-
|
|
2247
|
+
J = null;
|
|
2248
2248
|
}
|
|
2249
|
-
if (
|
|
2250
|
-
const Y = A.types[
|
|
2251
|
-
if (s ===
|
|
2249
|
+
if (J !== null && Object.hasOwn(A.types, J)) {
|
|
2250
|
+
const Y = A.types[J], a = (s) => {
|
|
2251
|
+
if (s === F) return S;
|
|
2252
2252
|
try {
|
|
2253
2253
|
return g.get(M, s);
|
|
2254
2254
|
} catch {
|
|
2255
2255
|
return;
|
|
2256
2256
|
}
|
|
2257
2257
|
};
|
|
2258
|
-
if (Y.readOnlyWhen?.field ===
|
|
2259
|
-
throw new n("read-only", Q, `\`${
|
|
2258
|
+
if (Y.readOnlyWhen?.field === F && pg(Y, a))
|
|
2259
|
+
throw new n("read-only", Q, `\`${J}.${F}\` would make \`${I.show(M)}\` read-only: only the kit does`);
|
|
2260
2260
|
}
|
|
2261
|
-
return
|
|
2261
|
+
return J !== null && Zg(g, A, Q, J, [[F, S]]), g.set(M, F, S), null;
|
|
2262
2262
|
}
|
|
2263
2263
|
case "delete": {
|
|
2264
|
-
const M =
|
|
2264
|
+
const M = w("target");
|
|
2265
2265
|
if (!g.exists(M) && !g.wasDeleted(M)) throw new n("not-found", Q, `object \`${M}\` not found`);
|
|
2266
|
-
const
|
|
2267
|
-
for (;
|
|
2268
|
-
const [
|
|
2266
|
+
const F = [[M, !1]], K = /* @__PURE__ */ new Set(), S = [];
|
|
2267
|
+
for (; F.length; ) {
|
|
2268
|
+
const [J, Y] = F.pop();
|
|
2269
2269
|
if (Y) {
|
|
2270
|
-
S.push(
|
|
2270
|
+
S.push(J);
|
|
2271
2271
|
continue;
|
|
2272
2272
|
}
|
|
2273
|
-
if (!g.exists(
|
|
2274
|
-
K.add(
|
|
2273
|
+
if (!g.exists(J) || K.has(J)) continue;
|
|
2274
|
+
K.add(J), F.push([J, !0]);
|
|
2275
2275
|
for (const s of Z(A.types))
|
|
2276
2276
|
for (const [H, R] of Object.entries(oI(A, s).fields))
|
|
2277
2277
|
if (R.cascade)
|
|
2278
2278
|
for (const t of g.objectsOfType(s)) {
|
|
2279
|
-
const d = g.tree(t, H), r = d.filter((x) => x.object ===
|
|
2280
|
-
|
|
2279
|
+
const d = g.tree(t, H), r = d.filter((x) => x.object === J).map((x) => x.node);
|
|
2280
|
+
F.push(...d.filter((x) => x.parent !== null && r.some((IA) => IA.equals(x.parent))).map((x) => [x.object, !1]));
|
|
2281
2281
|
}
|
|
2282
|
-
const a = oI(A, g.objectType(
|
|
2282
|
+
const a = oI(A, g.objectType(J));
|
|
2283
2283
|
for (const s of Z(a.fields)) {
|
|
2284
2284
|
const H = a.fields[s];
|
|
2285
2285
|
if (!MB(H)) continue;
|
|
2286
2286
|
let R = [];
|
|
2287
2287
|
switch (H.kind) {
|
|
2288
2288
|
case "list":
|
|
2289
|
-
R = g.listItems(
|
|
2289
|
+
R = g.listItems(J, s);
|
|
2290
2290
|
break;
|
|
2291
2291
|
case "tree":
|
|
2292
|
-
R = g.tree(
|
|
2292
|
+
R = g.tree(J, s).map((t) => t.object);
|
|
2293
2293
|
break;
|
|
2294
2294
|
case "ref": {
|
|
2295
|
-
const t = g.get(
|
|
2295
|
+
const t = g.get(J, s);
|
|
2296
2296
|
typeof t == "string" && (R = [t]);
|
|
2297
2297
|
break;
|
|
2298
2298
|
}
|
|
2299
2299
|
case "map":
|
|
2300
|
-
R = hB(Object.fromEntries(g.mapEntries(
|
|
2300
|
+
R = hB(Object.fromEntries(g.mapEntries(J, s)), (t) => g.exists(t)).map(([t]) => t);
|
|
2301
2301
|
break;
|
|
2302
2302
|
}
|
|
2303
|
-
|
|
2303
|
+
F.push(...R.map((t) => [t, !1]));
|
|
2304
2304
|
}
|
|
2305
2305
|
}
|
|
2306
|
-
for (const
|
|
2307
|
-
const Y = g.objectType(
|
|
2308
|
-
JA(g, A, I, Q,
|
|
2306
|
+
for (const J of S) {
|
|
2307
|
+
const Y = g.objectType(J);
|
|
2308
|
+
JA(g, A, I, Q, J, null);
|
|
2309
2309
|
for (const a of Z(A.types)) {
|
|
2310
2310
|
const s = oI(A, a);
|
|
2311
2311
|
for (const H of Z(s.fields)) {
|
|
@@ -2313,8 +2313,8 @@ function hD(g, A, I, Q, C, B, D) {
|
|
|
2313
2313
|
if (!(R.kind !== "list" || R.of !== Y))
|
|
2314
2314
|
for (const t of g.objectsOfType(a)) {
|
|
2315
2315
|
const d = g.listItems(t, H);
|
|
2316
|
-
d.includes(
|
|
2317
|
-
for (let r = d.length - 1; r >= 0; r -= 1) d[r] ===
|
|
2316
|
+
d.includes(J) && JA(g, A, I, Q, t, H);
|
|
2317
|
+
for (let r = d.length - 1; r >= 0; r -= 1) d[r] === J && g.listRemove(t, H, r);
|
|
2318
2318
|
}
|
|
2319
2319
|
}
|
|
2320
2320
|
}
|
|
@@ -2324,70 +2324,70 @@ function hD(g, A, I, Q, C, B, D) {
|
|
|
2324
2324
|
const R = s.fields[H];
|
|
2325
2325
|
if (!(R.kind !== "tree" || R.of !== void 0 && R.of !== Y))
|
|
2326
2326
|
for (const t of g.objectsOfType(a)) {
|
|
2327
|
-
const d = g.tree(t, H), r = d.filter((x) => x.object ===
|
|
2327
|
+
const d = g.tree(t, H), r = d.filter((x) => x.object === J).map((x) => x.node);
|
|
2328
2328
|
if (r.length && JA(g, A, I, Q, t, H), d.some((x) => x.parent !== null && r.some((IA) => IA.equals(x.parent)) && g.exists(x.object)))
|
|
2329
|
-
throw new n("invalid-value", Q, `\`${I.show(
|
|
2329
|
+
throw new n("invalid-value", Q, `\`${I.show(J)}\` has children in \`${I.show(t)}.${H}\`: delete them child-first or move them, before deleting this node in the same batch`);
|
|
2330
2330
|
}
|
|
2331
2331
|
}
|
|
2332
2332
|
}
|
|
2333
|
-
g.delete(
|
|
2333
|
+
g.delete(J);
|
|
2334
2334
|
}
|
|
2335
2335
|
return null;
|
|
2336
2336
|
}
|
|
2337
2337
|
case "tree.insert": {
|
|
2338
|
-
const [M,
|
|
2339
|
-
JA(g, A, I, Q, M,
|
|
2340
|
-
const K =
|
|
2341
|
-
if (UC(g, M,
|
|
2342
|
-
return g.treeCreate(M,
|
|
2338
|
+
const [M, F] = G(w("target"), gA(Q, C, "field"));
|
|
2339
|
+
JA(g, A, I, Q, M, F);
|
|
2340
|
+
const K = w("item");
|
|
2341
|
+
if (UC(g, M, F, K)) throw new n("invalid-value", Q, `\`${I.show(K)}\` is already in \`${I.show(M)}.${F}\`: move it with tree.move`);
|
|
2342
|
+
return g.treeCreate(M, F, Xg(g, B, I, D, Q, C, M, F), K), null;
|
|
2343
2343
|
}
|
|
2344
2344
|
case "tree.move": {
|
|
2345
|
-
const [M,
|
|
2346
|
-
JA(g, A, I, Q, M,
|
|
2347
|
-
const K =
|
|
2348
|
-
if (!S) throw new n("not-found", Q, `\`${I.show(K)}\` is not in \`${I.show(M)}.${
|
|
2349
|
-
return g.treeMove(M,
|
|
2345
|
+
const [M, F] = G(w("target"), gA(Q, C, "field"));
|
|
2346
|
+
JA(g, A, I, Q, M, F);
|
|
2347
|
+
const K = w("item"), S = UC(g, M, F, K);
|
|
2348
|
+
if (!S) throw new n("not-found", Q, `\`${I.show(K)}\` is not in \`${I.show(M)}.${F}\``);
|
|
2349
|
+
return g.treeMove(M, F, S, Xg(g, B, I, D, Q, C, M, F)), null;
|
|
2350
2350
|
}
|
|
2351
2351
|
case "text.insert": {
|
|
2352
|
-
const [M,
|
|
2353
|
-
return JA(g, A, I, Q, M,
|
|
2352
|
+
const [M, F] = h(w("target"), gA(Q, C, "field"));
|
|
2353
|
+
return JA(g, A, I, Q, M, F), g.textInsert(M, F, TI(g.text(M, F), _A(Q, C, "index")), gA(Q, C, "text")), null;
|
|
2354
2354
|
}
|
|
2355
2355
|
case "text.delete": {
|
|
2356
|
-
const [M,
|
|
2357
|
-
JA(g, A, I, Q, M,
|
|
2358
|
-
const K = g.text(M,
|
|
2359
|
-
return g.textDelete(M,
|
|
2356
|
+
const [M, F] = h(w("target"), gA(Q, C, "field"));
|
|
2357
|
+
JA(g, A, I, Q, M, F);
|
|
2358
|
+
const K = g.text(M, F), S = _A(Q, C, "index"), J = TI(K, S);
|
|
2359
|
+
return g.textDelete(M, F, J, TI(K, S + _A(Q, C, "count")) - J), null;
|
|
2360
2360
|
}
|
|
2361
2361
|
case "text.set": {
|
|
2362
|
-
const [M,
|
|
2363
|
-
JA(g, A, I, Q, M,
|
|
2364
|
-
const K = gA(Q, C, "text"), S = g.textLength(M,
|
|
2365
|
-
return S > 0 && g.textDelete(M,
|
|
2362
|
+
const [M, F] = h(w("target"), gA(Q, C, "field"));
|
|
2363
|
+
JA(g, A, I, Q, M, F);
|
|
2364
|
+
const K = gA(Q, C, "text"), S = g.textLength(M, F);
|
|
2365
|
+
return S > 0 && g.textDelete(M, F, 0, S), K !== "" && g.textInsert(M, F, 0, K), null;
|
|
2366
2366
|
}
|
|
2367
2367
|
case "text.mark":
|
|
2368
2368
|
case "text.unmark": {
|
|
2369
|
-
const M =
|
|
2370
|
-
JA(g, A, I, Q, M,
|
|
2371
|
-
const K = g.text(M,
|
|
2372
|
-
return i === "text.mark" ? g.textMark(M,
|
|
2369
|
+
const M = w("target"), F = gA(Q, C, "field");
|
|
2370
|
+
JA(g, A, I, Q, M, F);
|
|
2371
|
+
const K = g.text(M, F), S = TI(K, _A(Q, C, "start")), J = TI(K, _A(Q, C, "end"));
|
|
2372
|
+
return i === "text.mark" ? g.textMark(M, F, S, J, gA(Q, C, "key"), C.value ?? null) : g.textUnmark(M, F, S, J, gA(Q, C, "key")), null;
|
|
2373
2373
|
}
|
|
2374
2374
|
case "list.insert": {
|
|
2375
|
-
const [M,
|
|
2376
|
-
return JA(g, A, I, Q, M,
|
|
2375
|
+
const [M, F] = G(w("target"), gA(Q, C, "field"));
|
|
2376
|
+
return JA(g, A, I, Q, M, F), g.listInsert(M, F, UQ(Q, C.index, g.listItems(M, F).length), w("item")), null;
|
|
2377
2377
|
}
|
|
2378
2378
|
case "list.move":
|
|
2379
2379
|
case "list.remove":
|
|
2380
2380
|
case "map.set":
|
|
2381
2381
|
case "map.delete": {
|
|
2382
|
-
const [M,
|
|
2383
|
-
if (JA(g, A, I, Q, M,
|
|
2382
|
+
const [M, F] = i.startsWith("list.") ? G(w("target"), gA(Q, C, "field")) : [w("target"), gA(Q, C, "field")];
|
|
2383
|
+
if (JA(g, A, I, Q, M, F), i === "list.move") {
|
|
2384
2384
|
const K = _A(Q, C, "from"), S = _A(Q, C, "to");
|
|
2385
|
-
g.listMove(M,
|
|
2386
|
-
} else if (i === "list.remove") g.listRemove(M,
|
|
2385
|
+
g.listMove(M, F, K, S > K ? S - 1 : S);
|
|
2386
|
+
} else if (i === "list.remove") g.listRemove(M, F, _A(Q, C, "index"));
|
|
2387
2387
|
else if (i === "map.set") {
|
|
2388
|
-
const K = g.objectType(M), S = lg(g, A, I, Q, K,
|
|
2389
|
-
Zg(g, A, Q, K, [[
|
|
2390
|
-
} else g.mapDelete(M,
|
|
2388
|
+
const K = g.objectType(M), S = lg(g, A, I, Q, K, F, C.value === void 0 ? null : jA(C.value, B));
|
|
2389
|
+
Zg(g, A, Q, K, [[F, S]]), g.mapSet(M, F, gA(Q, C, "key"), S);
|
|
2390
|
+
} else g.mapDelete(M, F, gA(Q, C, "key"));
|
|
2391
2391
|
return null;
|
|
2392
2392
|
}
|
|
2393
2393
|
default:
|
|
@@ -2403,23 +2403,23 @@ function UC(g, A, I, Q) {
|
|
|
2403
2403
|
function Xg(g, A, I, Q, C, B, D, i) {
|
|
2404
2404
|
if (B.parent === void 0 || B.parent === null) return null;
|
|
2405
2405
|
if (typeof B.parent != "string") throw new n("invalid-op", C, "`parent` is an object or null");
|
|
2406
|
-
const
|
|
2407
|
-
if (!
|
|
2408
|
-
return
|
|
2406
|
+
const N = cg(B.parent, A, I, (G) => g.exists(G), Q, C), w = UC(g, D, i, N);
|
|
2407
|
+
if (!w) throw new n("not-found", C, `the parent \`${I.show(N)}\` is not in \`${I.show(D)}.${i}\``);
|
|
2408
|
+
return w;
|
|
2409
2409
|
}
|
|
2410
2410
|
function JD(g, A, I, Q) {
|
|
2411
2411
|
if (!QI(I) || typeof I.target != "string") throw new n("invalid-op", null, "`target` is a string");
|
|
2412
|
-
const C = cg(I.target, Q, A, (
|
|
2412
|
+
const C = cg(I.target, Q, A, (w) => g.exists(w), () => LI(g), null), B = g.objectType(C), D = oI(g.schema, B);
|
|
2413
2413
|
let i;
|
|
2414
2414
|
if (I.fields === void 0 || I.fields === null) i = Z(D.fields);
|
|
2415
|
-
else if (Array.isArray(I.fields) && I.fields.every((
|
|
2415
|
+
else if (Array.isArray(I.fields) && I.fields.every((w) => typeof w == "string")) i = I.fields;
|
|
2416
2416
|
else throw new n("invalid-op", null, "`fields` lists names");
|
|
2417
|
-
const
|
|
2418
|
-
for (const
|
|
2419
|
-
const G = Object.hasOwn(D.fields,
|
|
2420
|
-
w
|
|
2417
|
+
const N = {};
|
|
2418
|
+
for (const w of i) {
|
|
2419
|
+
const G = Object.hasOwn(D.fields, w) ? D.fields[w].kind : "json";
|
|
2420
|
+
N[w] = kD(A, G, qB(g, C, B, w));
|
|
2421
2421
|
}
|
|
2422
|
-
return { id: A.show(C), type: B, fields:
|
|
2422
|
+
return { id: A.show(C), type: B, fields: N };
|
|
2423
2423
|
}
|
|
2424
2424
|
function qB(g, A, I, Q) {
|
|
2425
2425
|
const C = zA(g.schema, I, Q);
|
|
@@ -2433,7 +2433,7 @@ function qB(g, A, I, Q) {
|
|
|
2433
2433
|
case "tree": {
|
|
2434
2434
|
const B = [];
|
|
2435
2435
|
for (const D of g.tree(A, Q))
|
|
2436
|
-
(D.parent === null || B.some((
|
|
2436
|
+
(D.parent === null || B.some((N) => N.node.equals(D.parent))) && g.exists(D.object) && B.push(D);
|
|
2437
2437
|
return B.map((D) => ({ object: D.object, parent: B.find((i) => D.parent !== null && i.node.equals(D.parent))?.object ?? null }));
|
|
2438
2438
|
}
|
|
2439
2439
|
default:
|
|
@@ -2444,14 +2444,14 @@ function HB(g) {
|
|
|
2444
2444
|
const A = g.schema, I = {};
|
|
2445
2445
|
for (const B of Z(A.types)) {
|
|
2446
2446
|
const D = {};
|
|
2447
|
-
for (const [
|
|
2448
|
-
const
|
|
2449
|
-
G.label !== void 0 && (
|
|
2450
|
-
for (const M of ["minimum", "maximum", "multipleOf"]) G[M] !== void 0 && (
|
|
2451
|
-
G.members !== void 0 && Object.keys(G.members).length > 0 && (
|
|
2447
|
+
for (const [w, G] of Object.entries(A.types[B].fields)) {
|
|
2448
|
+
const h = { kind: G.kind };
|
|
2449
|
+
G.label !== void 0 && (h.label = G.label);
|
|
2450
|
+
for (const M of ["minimum", "maximum", "multipleOf"]) G[M] !== void 0 && (h[M] = G[M]);
|
|
2451
|
+
G.members !== void 0 && Object.keys(G.members).length > 0 && (h.members = G.members), G.of !== void 0 && (h.of = G.of), G.values?.length && (h.values = G.values), G.optional && (h.optional = !0), G.marks && Object.keys(G.marks).length > 0 && (h.marks = Z(G.marks)), G.readOnly && (h.readOnly = !0), G.owns && (h.owns = !0), G.cascade && (h.cascade = !0), G.position && (h.position = !0), G.display !== void 0 && (h.display = { ...G.display }), G.sample !== void 0 && (h.sample = G.sample), D[w] = h;
|
|
2452
2452
|
}
|
|
2453
|
-
const i = A.types[B],
|
|
2454
|
-
i.projected && (
|
|
2453
|
+
const i = A.types[B], N = { fields: D };
|
|
2454
|
+
i.projected && (N.projected = !0), i.projectedOps && Object.keys(i.projectedOps).length && (N.projectedOps = structuredClone(i.projectedOps)), i.readOnly && (N.readOnly = !0), i.readOnlyWhen && (N.readOnlyWhen = { field: i.readOnlyWhen.field, values: [...i.readOnlyWhen.values] }), i.toolId && (N.toolId = { field: i.toolId.field, prefix: i.toolId.prefix, ...i.toolId.parent === void 0 ? {} : { parent: i.toolId.parent } }), i.pathName !== void 0 && (N.pathName = i.pathName), i.label !== void 0 && (N.label = i.label), i.derived && (N.derived = Object.fromEntries(Z(i.derived).map((w) => [w, { ...i.derived[w] }]))), i.text && (N.text = i.text), i.batchOps && Object.assign(N, { batchOps: structuredClone(i.batchOps) }), i.creation && Object.assign(N, { creation: structuredClone(i.creation) }), i.batchIndependent && (N.batchIndependent = !0), i.moveConsequences?.length && (N.moveConsequences = [...i.moveConsequences]), i.structuralConsequences?.length && (N.structuralConsequences = i.structuralConsequences.map((w) => ({ container: w.container, on: [...w.on], fields: [...w.fields] }))), I[B] = N;
|
|
2455
2455
|
}
|
|
2456
2456
|
const Q = LI(g), C = Q !== null && jC(A) ? $.ofReplica(g).show(Q) : Q;
|
|
2457
2457
|
return { capability: YB, kit: A.kit, schemaVersion: A.schemaVersion, root: A.root, rootId: C, types: I };
|
|
@@ -2593,8 +2593,8 @@ const jD = typeof yg.encodeInto == "function" ? function(g, A) {
|
|
|
2593
2593
|
};
|
|
2594
2594
|
function l(g, A, I) {
|
|
2595
2595
|
if (I === void 0) {
|
|
2596
|
-
const i = yg.encode(g),
|
|
2597
|
-
return qI().subarray(
|
|
2596
|
+
const i = yg.encode(g), N = A(i.length, 1) >>> 0;
|
|
2597
|
+
return qI().subarray(N, N + i.length).set(i), e = i.length, N;
|
|
2598
2598
|
}
|
|
2599
2599
|
let Q = g.length, C = A(Q, 1) >>> 0;
|
|
2600
2600
|
const B = qI();
|
|
@@ -2606,8 +2606,8 @@ function l(g, A, I) {
|
|
|
2606
2606
|
}
|
|
2607
2607
|
if (D !== Q) {
|
|
2608
2608
|
D !== 0 && (g = g.slice(D)), C = I(C, Q, Q = D + g.length * 3, 1) >>> 0;
|
|
2609
|
-
const i = qI().subarray(C + D, C + Q),
|
|
2610
|
-
D +=
|
|
2609
|
+
const i = qI().subarray(C + D, C + Q), N = jD(g, i);
|
|
2610
|
+
D += N.written, C = I(C, Q, D, 1) >>> 0;
|
|
2611
2611
|
}
|
|
2612
2612
|
return e = D, C;
|
|
2613
2613
|
}
|
|
@@ -2759,8 +2759,8 @@ function FA(g, A) {
|
|
|
2759
2759
|
}
|
|
2760
2760
|
function WD(g) {
|
|
2761
2761
|
try {
|
|
2762
|
-
const D = E.__wbindgen_add_to_stack_pointer(-16), i = FA(g, E.__wbindgen_malloc),
|
|
2763
|
-
E.encodeFrontiers(D, i,
|
|
2762
|
+
const D = E.__wbindgen_add_to_stack_pointer(-16), i = FA(g, E.__wbindgen_malloc), N = e;
|
|
2763
|
+
E.encodeFrontiers(D, i, N);
|
|
2764
2764
|
var A = o().getInt32(D + 0, !0), I = o().getInt32(D + 4, !0), Q = o().getInt32(D + 8, !0), C = o().getInt32(D + 12, !0);
|
|
2765
2765
|
if (C)
|
|
2766
2766
|
throw k(Q);
|
|
@@ -3789,8 +3789,8 @@ class RA {
|
|
|
3789
3789
|
*/
|
|
3790
3790
|
cmpFrontiers(A, I) {
|
|
3791
3791
|
try {
|
|
3792
|
-
const D = E.__wbindgen_add_to_stack_pointer(-16), i = FA(A, E.__wbindgen_malloc),
|
|
3793
|
-
E.lorodoc_cmpFrontiers(D, this.__wbg_ptr, i,
|
|
3792
|
+
const D = E.__wbindgen_add_to_stack_pointer(-16), i = FA(A, E.__wbindgen_malloc), N = e, w = FA(I, E.__wbindgen_malloc), G = e;
|
|
3793
|
+
E.lorodoc_cmpFrontiers(D, this.__wbg_ptr, i, N, w, G);
|
|
3794
3794
|
var Q = o().getInt32(D + 0, !0), C = o().getInt32(D + 4, !0), B = o().getInt32(D + 8, !0);
|
|
3795
3795
|
if (B)
|
|
3796
3796
|
throw k(C);
|
|
@@ -4208,8 +4208,8 @@ class RA {
|
|
|
4208
4208
|
*/
|
|
4209
4209
|
subscribeJsonpath(A, I) {
|
|
4210
4210
|
try {
|
|
4211
|
-
const D = E.__wbindgen_add_to_stack_pointer(-16), i = l(A, E.__wbindgen_malloc, E.__wbindgen_realloc),
|
|
4212
|
-
E.lorodoc_subscribeJsonpath(D, this.__wbg_ptr, i,
|
|
4211
|
+
const D = E.__wbindgen_add_to_stack_pointer(-16), i = l(A, E.__wbindgen_malloc, E.__wbindgen_realloc), N = e;
|
|
4212
|
+
E.lorodoc_subscribeJsonpath(D, this.__wbg_ptr, i, N, U(I));
|
|
4213
4213
|
var Q = o().getInt32(D + 0, !0), C = o().getInt32(D + 4, !0), B = o().getInt32(D + 8, !0);
|
|
4214
4214
|
if (B)
|
|
4215
4215
|
throw k(C);
|
|
@@ -4448,8 +4448,8 @@ class RA {
|
|
|
4448
4448
|
*/
|
|
4449
4449
|
findIdSpansBetween(A, I) {
|
|
4450
4450
|
try {
|
|
4451
|
-
const D = E.__wbindgen_add_to_stack_pointer(-16), i = FA(A, E.__wbindgen_malloc),
|
|
4452
|
-
E.lorodoc_findIdSpansBetween(D, this.__wbg_ptr, i,
|
|
4451
|
+
const D = E.__wbindgen_add_to_stack_pointer(-16), i = FA(A, E.__wbindgen_malloc), N = e, w = FA(I, E.__wbindgen_malloc), G = e;
|
|
4452
|
+
E.lorodoc_findIdSpansBetween(D, this.__wbg_ptr, i, N, w, G);
|
|
4453
4453
|
var Q = o().getInt32(D + 0, !0), C = o().getInt32(D + 4, !0), B = o().getInt32(D + 8, !0);
|
|
4454
4454
|
if (B)
|
|
4455
4455
|
throw k(C);
|
|
@@ -4466,8 +4466,8 @@ class RA {
|
|
|
4466
4466
|
*/
|
|
4467
4467
|
getChangeAtLamport(A, I) {
|
|
4468
4468
|
try {
|
|
4469
|
-
const D = E.__wbindgen_add_to_stack_pointer(-16), i = l(A, E.__wbindgen_malloc, E.__wbindgen_realloc),
|
|
4470
|
-
E.lorodoc_getChangeAtLamport(D, this.__wbg_ptr, i,
|
|
4469
|
+
const D = E.__wbindgen_add_to_stack_pointer(-16), i = l(A, E.__wbindgen_malloc, E.__wbindgen_realloc), N = e;
|
|
4470
|
+
E.lorodoc_getChangeAtLamport(D, this.__wbg_ptr, i, N, I);
|
|
4471
4471
|
var Q = o().getInt32(D + 0, !0), C = o().getInt32(D + 4, !0), B = o().getInt32(D + 8, !0);
|
|
4472
4472
|
if (B)
|
|
4473
4473
|
throw k(C);
|
|
@@ -4511,9 +4511,9 @@ class RA {
|
|
|
4511
4511
|
*/
|
|
4512
4512
|
getChangedContainersIn(A, I) {
|
|
4513
4513
|
try {
|
|
4514
|
-
const
|
|
4515
|
-
E.lorodoc_getChangedContainersIn(
|
|
4516
|
-
var Q = o().getInt32(
|
|
4514
|
+
const N = E.__wbindgen_add_to_stack_pointer(-16);
|
|
4515
|
+
E.lorodoc_getChangedContainersIn(N, this.__wbg_ptr, U(A), I);
|
|
4516
|
+
var Q = o().getInt32(N + 0, !0), C = o().getInt32(N + 4, !0), B = o().getInt32(N + 8, !0), D = o().getInt32(N + 12, !0);
|
|
4517
4517
|
if (D)
|
|
4518
4518
|
throw k(B);
|
|
4519
4519
|
var i = LA(Q, C).slice();
|
|
@@ -4753,8 +4753,8 @@ class RA {
|
|
|
4753
4753
|
*/
|
|
4754
4754
|
diff(A, I, Q) {
|
|
4755
4755
|
try {
|
|
4756
|
-
const i = E.__wbindgen_add_to_stack_pointer(-16),
|
|
4757
|
-
E.lorodoc_diff(i, this.__wbg_ptr,
|
|
4756
|
+
const i = E.__wbindgen_add_to_stack_pointer(-16), N = FA(A, E.__wbindgen_malloc), w = e, G = FA(I, E.__wbindgen_malloc), h = e;
|
|
4757
|
+
E.lorodoc_diff(i, this.__wbg_ptr, N, w, G, h, W(Q) ? 16777215 : Q ? 1 : 0);
|
|
4758
4758
|
var C = o().getInt32(i + 0, !0), B = o().getInt32(i + 4, !0), D = o().getInt32(i + 8, !0);
|
|
4759
4759
|
if (D)
|
|
4760
4760
|
throw k(B);
|
|
@@ -5974,8 +5974,8 @@ class DA {
|
|
|
5974
5974
|
*/
|
|
5975
5975
|
setContainer(A, I) {
|
|
5976
5976
|
try {
|
|
5977
|
-
const D = E.__wbindgen_add_to_stack_pointer(-16), i = l(A, E.__wbindgen_malloc, E.__wbindgen_realloc),
|
|
5978
|
-
E.loromap_setContainer(D, this.__wbg_ptr, i,
|
|
5977
|
+
const D = E.__wbindgen_add_to_stack_pointer(-16), i = l(A, E.__wbindgen_malloc, E.__wbindgen_realloc), N = e;
|
|
5978
|
+
E.loromap_setContainer(D, this.__wbg_ptr, i, N, U(I));
|
|
5979
5979
|
var Q = o().getInt32(D + 0, !0), C = o().getInt32(D + 4, !0), B = o().getInt32(D + 8, !0);
|
|
5980
5980
|
if (B)
|
|
5981
5981
|
throw k(C);
|
|
@@ -6163,8 +6163,8 @@ class DA {
|
|
|
6163
6163
|
*/
|
|
6164
6164
|
getOrCreateContainer(A, I) {
|
|
6165
6165
|
try {
|
|
6166
|
-
const D = E.__wbindgen_add_to_stack_pointer(-16), i = l(A, E.__wbindgen_malloc, E.__wbindgen_realloc),
|
|
6167
|
-
E.loromap_getOrCreateContainer(D, this.__wbg_ptr, i,
|
|
6166
|
+
const D = E.__wbindgen_add_to_stack_pointer(-16), i = l(A, E.__wbindgen_malloc, E.__wbindgen_realloc), N = e;
|
|
6167
|
+
E.loromap_getOrCreateContainer(D, this.__wbg_ptr, i, N, U(I));
|
|
6168
6168
|
var Q = o().getInt32(D + 0, !0), C = o().getInt32(D + 4, !0), B = o().getInt32(D + 8, !0);
|
|
6169
6169
|
if (B)
|
|
6170
6170
|
throw k(C);
|
|
@@ -7287,8 +7287,8 @@ class uA {
|
|
|
7287
7287
|
* @returns {any}
|
|
7288
7288
|
*/
|
|
7289
7289
|
convertPos(A, I, Q) {
|
|
7290
|
-
const C = l(I, E.__wbindgen_malloc, E.__wbindgen_realloc), B = e, D = l(Q, E.__wbindgen_malloc, E.__wbindgen_realloc), i = e,
|
|
7291
|
-
return k(
|
|
7290
|
+
const C = l(I, E.__wbindgen_malloc, E.__wbindgen_realloc), B = e, D = l(Q, E.__wbindgen_malloc, E.__wbindgen_realloc), i = e, N = E.lorotext_convertPos(this.__wbg_ptr, A, C, B, D, i);
|
|
7291
|
+
return k(N);
|
|
7292
7292
|
}
|
|
7293
7293
|
/**
|
|
7294
7294
|
* Delete elements from index to utf-8 index + len
|
|
@@ -7561,8 +7561,8 @@ class uA {
|
|
|
7561
7561
|
*/
|
|
7562
7562
|
mark(A, I, Q) {
|
|
7563
7563
|
try {
|
|
7564
|
-
const D = E.__wbindgen_add_to_stack_pointer(-16), i = l(I, E.__wbindgen_malloc, E.__wbindgen_realloc),
|
|
7565
|
-
E.lorotext_mark(D, this.__wbg_ptr, U(A), i,
|
|
7564
|
+
const D = E.__wbindgen_add_to_stack_pointer(-16), i = l(I, E.__wbindgen_malloc, E.__wbindgen_realloc), N = e;
|
|
7565
|
+
E.lorotext_mark(D, this.__wbg_ptr, U(A), i, N, U(Q));
|
|
7566
7566
|
var C = o().getInt32(D + 0, !0), B = o().getInt32(D + 4, !0);
|
|
7567
7567
|
if (B)
|
|
7568
7568
|
throw k(C);
|
|
@@ -7604,12 +7604,12 @@ class uA {
|
|
|
7604
7604
|
slice(A, I) {
|
|
7605
7605
|
let Q, C;
|
|
7606
7606
|
try {
|
|
7607
|
-
const
|
|
7608
|
-
E.lorotext_slice(
|
|
7609
|
-
var B = o().getInt32(
|
|
7610
|
-
if (
|
|
7611
|
-
throw
|
|
7612
|
-
return Q =
|
|
7607
|
+
const h = E.__wbindgen_add_to_stack_pointer(-16);
|
|
7608
|
+
E.lorotext_slice(h, this.__wbg_ptr, A, I);
|
|
7609
|
+
var B = o().getInt32(h + 0, !0), D = o().getInt32(h + 4, !0), i = o().getInt32(h + 8, !0), N = o().getInt32(h + 12, !0), w = B, G = D;
|
|
7610
|
+
if (N)
|
|
7611
|
+
throw w = 0, G = 0, k(i);
|
|
7612
|
+
return Q = w, C = G, P(w, G);
|
|
7613
7613
|
} finally {
|
|
7614
7614
|
E.__wbindgen_add_to_stack_pointer(16), E.__wbindgen_free(Q, C, 1);
|
|
7615
7615
|
}
|
|
@@ -7714,12 +7714,12 @@ class uA {
|
|
|
7714
7714
|
splice(A, I, Q) {
|
|
7715
7715
|
let C, B;
|
|
7716
7716
|
try {
|
|
7717
|
-
const M = E.__wbindgen_add_to_stack_pointer(-16),
|
|
7718
|
-
E.lorotext_splice(M, this.__wbg_ptr, A, I,
|
|
7719
|
-
var D = o().getInt32(M + 0, !0), i = o().getInt32(M + 4, !0),
|
|
7720
|
-
if (
|
|
7721
|
-
throw G = 0,
|
|
7722
|
-
return C = G, B =
|
|
7717
|
+
const M = E.__wbindgen_add_to_stack_pointer(-16), F = l(Q, E.__wbindgen_malloc, E.__wbindgen_realloc), K = e;
|
|
7718
|
+
E.lorotext_splice(M, this.__wbg_ptr, A, I, F, K);
|
|
7719
|
+
var D = o().getInt32(M + 0, !0), i = o().getInt32(M + 4, !0), N = o().getInt32(M + 8, !0), w = o().getInt32(M + 12, !0), G = D, h = i;
|
|
7720
|
+
if (w)
|
|
7721
|
+
throw G = 0, h = 0, k(N);
|
|
7722
|
+
return C = G, B = h, P(G, h);
|
|
7723
7723
|
} finally {
|
|
7724
7724
|
E.__wbindgen_add_to_stack_pointer(16), E.__wbindgen_free(C, B, 1);
|
|
7725
7725
|
}
|
|
@@ -9304,11 +9304,11 @@ function Li(g) {
|
|
|
9304
9304
|
return q(g).length;
|
|
9305
9305
|
}
|
|
9306
9306
|
function qi(g, A, I, Q, C, B, D, i) {
|
|
9307
|
-
let
|
|
9307
|
+
let N, w;
|
|
9308
9308
|
try {
|
|
9309
|
-
|
|
9309
|
+
N = g, w = A, console.log(P(g, A), P(I, Q), P(C, B), P(D, i));
|
|
9310
9310
|
} finally {
|
|
9311
|
-
E.__wbindgen_free(
|
|
9311
|
+
E.__wbindgen_free(N, w, 1);
|
|
9312
9312
|
}
|
|
9313
9313
|
}
|
|
9314
9314
|
function Hi(g, A) {
|
|
@@ -9904,13 +9904,13 @@ RA.prototype.toJsonWithReplacer = function(g) {
|
|
|
9904
9904
|
const A = /* @__PURE__ */ new Set(), I = this, Q = (D, i) => {
|
|
9905
9905
|
if (typeof i == "string" && Kw(i) && !A.has(i)) {
|
|
9906
9906
|
A.add(i);
|
|
9907
|
-
const
|
|
9908
|
-
if (
|
|
9907
|
+
const w = I.getContainerById(i);
|
|
9908
|
+
if (w == null)
|
|
9909
9909
|
throw new Error(`ContainerID not found: ${i}`);
|
|
9910
|
-
const G = g(D,
|
|
9911
|
-
if (G ===
|
|
9912
|
-
const
|
|
9913
|
-
return typeof
|
|
9910
|
+
const G = g(D, w);
|
|
9911
|
+
if (G === w) {
|
|
9912
|
+
const h = w.getShallowValue();
|
|
9913
|
+
return typeof h == "object" ? C(h) : h;
|
|
9914
9914
|
}
|
|
9915
9915
|
if (nA(G))
|
|
9916
9916
|
throw new Error("Using new container is not allowed in toJsonWithReplacer");
|
|
@@ -9918,17 +9918,17 @@ RA.prototype.toJsonWithReplacer = function(g) {
|
|
|
9918
9918
|
}
|
|
9919
9919
|
if (typeof i == "object" && i != null)
|
|
9920
9920
|
return C(i);
|
|
9921
|
-
const
|
|
9922
|
-
if (nA(
|
|
9921
|
+
const N = g(D, i);
|
|
9922
|
+
if (nA(N))
|
|
9923
9923
|
throw new Error("Using new container is not allowed in toJsonWithReplacer");
|
|
9924
|
-
return
|
|
9924
|
+
return N;
|
|
9925
9925
|
}, C = (D) => {
|
|
9926
9926
|
if (Array.isArray(D))
|
|
9927
|
-
return D.map((
|
|
9927
|
+
return D.map((N, w) => Q(w, N)).filter((N) => N !== void 0);
|
|
9928
9928
|
const i = {};
|
|
9929
|
-
for (const [
|
|
9930
|
-
const G = Q(
|
|
9931
|
-
G !== void 0 && (i[
|
|
9929
|
+
for (const [N, w] of Object.entries(D)) {
|
|
9930
|
+
const G = Q(N, w);
|
|
9931
|
+
G !== void 0 && (i[N] = G);
|
|
9932
9932
|
}
|
|
9933
9933
|
return i;
|
|
9934
9934
|
}, B = I.getShallowValue();
|
|
@@ -10070,10 +10070,10 @@ function OC(g, A) {
|
|
|
10070
10070
|
if (typeof B != "string" || B === "") continue;
|
|
10071
10071
|
const D = C.attributes ?? {};
|
|
10072
10072
|
let i;
|
|
10073
|
-
for (const
|
|
10074
|
-
if (!Object.hasOwn(I,
|
|
10075
|
-
const
|
|
10076
|
-
|
|
10073
|
+
for (const N of Object.keys(D).sort(j)) {
|
|
10074
|
+
if (!Object.hasOwn(I, N)) continue;
|
|
10075
|
+
const w = D[N];
|
|
10076
|
+
w != null && (i ??= {}, kA(i, N, yA(w)));
|
|
10077
10077
|
}
|
|
10078
10078
|
xB(Q, B, i);
|
|
10079
10079
|
}
|
|
@@ -10137,8 +10137,8 @@ function AC(g, A) {
|
|
|
10137
10137
|
if (C.projected) throw y.invalidValue(Q, "$type", "projected objects are computed by the kit, never stored");
|
|
10138
10138
|
for (const [B, D] of Object.entries(C.fields)) {
|
|
10139
10139
|
if (!D.of || !A.types[D.of]?.projected) continue;
|
|
10140
|
-
const i = SA(g, I).get(B),
|
|
10141
|
-
if (
|
|
10140
|
+
const i = SA(g, I).get(B), N = nA(i) ? i.toJSON() : i;
|
|
10141
|
+
if (N != null && !(Array.isArray(N) && !N.length) && !(typeof N == "object" && !Object.keys(N).length))
|
|
10142
10142
|
throw y.invalidValue(Q, B, "projected membership is computed by the kit, never stored");
|
|
10143
10143
|
}
|
|
10144
10144
|
}
|
|
@@ -10190,19 +10190,19 @@ function VB(g, A, I) {
|
|
|
10190
10190
|
if (!Object.hasOwn(A.types, C)) return B;
|
|
10191
10191
|
const D = A.types[C].fields;
|
|
10192
10192
|
for (const i of Z(D)) {
|
|
10193
|
-
const
|
|
10194
|
-
let
|
|
10195
|
-
if (
|
|
10193
|
+
const N = D[i].kind;
|
|
10194
|
+
let w;
|
|
10195
|
+
if (N === "text" && Qg(D[i])) {
|
|
10196
10196
|
const G = wA(g, A, I, i, "text");
|
|
10197
|
-
|
|
10198
|
-
} else if (
|
|
10199
|
-
else if (
|
|
10200
|
-
else if (
|
|
10201
|
-
else if (
|
|
10197
|
+
w = G ? OC(G, D[i]) : [];
|
|
10198
|
+
} else if (N === "text") w = wA(g, A, I, i, "text")?.toString() ?? "";
|
|
10199
|
+
else if (N === "list") w = eg(wA(g, A, I, i, "list")?.toArray() ?? []);
|
|
10200
|
+
else if (N === "tree") w = WB(wA(g, A, I, i, "tree")?.roots());
|
|
10201
|
+
else if (N === "map") {
|
|
10202
10202
|
const G = wA(g, A, I, i, "map");
|
|
10203
|
-
|
|
10204
|
-
} else
|
|
10205
|
-
kA(B, i,
|
|
10203
|
+
w = G ? cw(G) : {};
|
|
10204
|
+
} else w = WC(g, A, I, i);
|
|
10205
|
+
kA(B, i, w);
|
|
10206
10206
|
}
|
|
10207
10207
|
return B;
|
|
10208
10208
|
}
|
|
@@ -10218,55 +10218,55 @@ function eQ(g, A) {
|
|
|
10218
10218
|
const I = g.toJSON(), Q = KI(I[hA]) ? I[hA] : {}, C = g.getMap(hA), B = Object.keys(Q);
|
|
10219
10219
|
C.get(yI) !== void 0 && B.push(yI), B.sort(j);
|
|
10220
10220
|
const D = {};
|
|
10221
|
-
for (const
|
|
10222
|
-
const G = Q[
|
|
10223
|
-
if (
|
|
10224
|
-
kA(D,
|
|
10221
|
+
for (const w of B) {
|
|
10222
|
+
const G = Q[w], h = KI(G) ? G[bA] : void 0, M = typeof h == "string" && Object.hasOwn(A.types, h);
|
|
10223
|
+
if (w === yI || M && Object.hasOwn(A.types[h].fields, yI)) {
|
|
10224
|
+
kA(D, w, yA(VB(g, A, w)));
|
|
10225
10225
|
continue;
|
|
10226
10226
|
}
|
|
10227
|
-
if (!KI(G) || typeof
|
|
10227
|
+
if (!KI(G) || typeof h != "string") throw y.notFound(w);
|
|
10228
10228
|
if (!M) {
|
|
10229
|
-
D[
|
|
10229
|
+
D[w] = { [bA]: h };
|
|
10230
10230
|
continue;
|
|
10231
10231
|
}
|
|
10232
|
-
const
|
|
10233
|
-
D[
|
|
10234
|
-
const K = A.types[
|
|
10235
|
-
for (const S of Rw(A,
|
|
10232
|
+
const F = {};
|
|
10233
|
+
D[w] = F;
|
|
10234
|
+
const K = A.types[h].fields;
|
|
10235
|
+
for (const S of Rw(A, h)) {
|
|
10236
10236
|
if (S === bA) {
|
|
10237
|
-
|
|
10237
|
+
F[S] = h;
|
|
10238
10238
|
continue;
|
|
10239
10239
|
}
|
|
10240
|
-
const
|
|
10240
|
+
const J = G[S], Y = () => lB(w, S);
|
|
10241
10241
|
switch (K[S].kind) {
|
|
10242
10242
|
case "text":
|
|
10243
|
-
if (
|
|
10243
|
+
if (J !== void 0 && typeof J != "string") throw Y();
|
|
10244
10244
|
if (Qg(K[S])) {
|
|
10245
|
-
const a =
|
|
10246
|
-
|
|
10247
|
-
} else
|
|
10245
|
+
const a = J === void 0 ? null : tA(SA(g, w).get(S), "text", w, S);
|
|
10246
|
+
F[S] = a ? OC(a, K[S]) : [];
|
|
10247
|
+
} else F[S] = J ?? "";
|
|
10248
10248
|
break;
|
|
10249
10249
|
case "list":
|
|
10250
|
-
if (
|
|
10251
|
-
|
|
10250
|
+
if (J !== void 0 && !Array.isArray(J)) throw Y();
|
|
10251
|
+
F[S] = Array.isArray(J) ? eg(J) : [];
|
|
10252
10252
|
break;
|
|
10253
10253
|
case "tree":
|
|
10254
|
-
if (
|
|
10255
|
-
|
|
10254
|
+
if (J !== void 0 && !Array.isArray(J)) throw Y();
|
|
10255
|
+
F[S] = bB(J);
|
|
10256
10256
|
break;
|
|
10257
10257
|
case "map": {
|
|
10258
|
-
if (
|
|
10259
|
-
const a = KI(
|
|
10260
|
-
H !== void 0 && kA(a, yI, OB(H)),
|
|
10258
|
+
if (J !== void 0 && !KI(J)) throw Y();
|
|
10259
|
+
const a = KI(J) ? { ...J } : {}, s = SA(g, w).get(S), H = s instanceof DA ? s.get(yI) : void 0;
|
|
10260
|
+
H !== void 0 && kA(a, yI, OB(H)), F[S] = yA(a);
|
|
10261
10261
|
break;
|
|
10262
10262
|
}
|
|
10263
10263
|
default:
|
|
10264
|
-
|
|
10264
|
+
F[S] = J === void 0 ? null : Lw(J);
|
|
10265
10265
|
}
|
|
10266
10266
|
}
|
|
10267
10267
|
}
|
|
10268
|
-
const i = KI(I[xI]) ? { ...I[xI] } : {},
|
|
10269
|
-
return
|
|
10268
|
+
const i = KI(I[xI]) ? { ...I[xI] } : {}, N = wI(g);
|
|
10269
|
+
return N !== null && (i[$I] = N), { meta: yA(i), objects: D };
|
|
10270
10270
|
}
|
|
10271
10271
|
function qw(g) {
|
|
10272
10272
|
if (g.outside) return !1;
|
|
@@ -10309,32 +10309,32 @@ class VC {
|
|
|
10309
10309
|
touched(A) {
|
|
10310
10310
|
const I = BI(A).engine, Q = this.doc.oplogFrontiers(), C = /* @__PURE__ */ new Set();
|
|
10311
10311
|
let B = !1;
|
|
10312
|
-
const D = this.doc.subscribe((
|
|
10313
|
-
for (const G of
|
|
10312
|
+
const D = this.doc.subscribe((w) => {
|
|
10313
|
+
for (const G of w.events)
|
|
10314
10314
|
if (G.path[0] !== hA) B = !0;
|
|
10315
10315
|
else if (G.path.length >= 2) C.add(String(G.path[1]));
|
|
10316
|
-
else if (G.diff.type === "map") for (const
|
|
10316
|
+
else if (G.diff.type === "map") for (const h of Object.keys(G.diff.updated)) C.add(h);
|
|
10317
10317
|
else B = !0;
|
|
10318
10318
|
});
|
|
10319
10319
|
try {
|
|
10320
10320
|
this.doc.import(I);
|
|
10321
|
-
} catch (
|
|
10322
|
-
throw y.encoding(IC(
|
|
10321
|
+
} catch (w) {
|
|
10322
|
+
throw y.encoding(IC(w));
|
|
10323
10323
|
} finally {
|
|
10324
10324
|
D();
|
|
10325
10325
|
}
|
|
10326
10326
|
const i = /* @__PURE__ */ new Map();
|
|
10327
10327
|
if (!C.size) return { objects: i, outside: B };
|
|
10328
|
-
const
|
|
10328
|
+
const N = new Map([...C].map((w) => [w, dQ(this.doc, w)]));
|
|
10329
10329
|
this.doc.checkout(Q);
|
|
10330
10330
|
try {
|
|
10331
|
-
for (const
|
|
10331
|
+
for (const w of C) i.set(w, dQ(this.doc, w) ?? N.get(w) ?? null);
|
|
10332
10332
|
} finally {
|
|
10333
10333
|
this.doc.checkoutToLatest();
|
|
10334
10334
|
}
|
|
10335
|
-
for (const
|
|
10336
|
-
const G = this.doc.getMap(hA).get(
|
|
10337
|
-
G !== void 0 && !nA(G) && i.set(
|
|
10335
|
+
for (const w of C) {
|
|
10336
|
+
const G = this.doc.getMap(hA).get(w);
|
|
10337
|
+
G !== void 0 && !nA(G) && i.set(w, null);
|
|
10338
10338
|
}
|
|
10339
10339
|
return { objects: i, outside: B };
|
|
10340
10340
|
}
|
|
@@ -10360,11 +10360,11 @@ function PB(g, A) {
|
|
|
10360
10360
|
}
|
|
10361
10361
|
function PC(g, A, I) {
|
|
10362
10362
|
let Q = 0;
|
|
10363
|
-
const C = (i,
|
|
10364
|
-
const
|
|
10365
|
-
if (!
|
|
10366
|
-
const K = new TextEncoder().encode(JSON.stringify(
|
|
10367
|
-
return Q + K > 65536 ? { ...
|
|
10363
|
+
const C = (i, N, w) => w.split(".").reduce((G, h) => BA(G) ? G[h] : Array.isArray(G) ? G[Number(h)] : void 0, Ig(i)[N]), B = { ...g, changed: g.changed.map((i) => ({ ...i, edits: i.edits?.map((N) => {
|
|
10364
|
+
const w = C(A, i.id, N.field), G = C(I, i.id, N.field), h = w == null ? "" : MI(w), M = G == null ? "" : MI(G), F = h === null || M === null ? void 0 : PB(h, M);
|
|
10365
|
+
if (!F) return N;
|
|
10366
|
+
const K = new TextEncoder().encode(JSON.stringify(F)).length;
|
|
10367
|
+
return Q + K > 65536 ? { ...N, spansTruncated: !0 } : (Q += K, { ...N, span: F });
|
|
10368
10368
|
}) })) }, D = PA.get(g);
|
|
10369
10369
|
return D && PA.set(B, D), B;
|
|
10370
10370
|
}
|
|
@@ -10422,8 +10422,8 @@ class lQ {
|
|
|
10422
10422
|
add(A, I, Q, C) {
|
|
10423
10423
|
if (C === "list") {
|
|
10424
10424
|
const B = [A, I, A];
|
|
10425
|
-
Q.filter((i) => typeof i == "string").forEach((i,
|
|
10426
|
-
this.at.has(i) || this.at.set(i, { group: B, index:
|
|
10425
|
+
Q.filter((i) => typeof i == "string").forEach((i, N) => {
|
|
10426
|
+
this.at.has(i) || this.at.set(i, { group: B, index: N });
|
|
10427
10427
|
});
|
|
10428
10428
|
} else C === "tree" && this.addNodes(A, I, A, Q);
|
|
10429
10429
|
}
|
|
@@ -10441,7 +10441,7 @@ class lQ {
|
|
|
10441
10441
|
const PA = /* @__PURE__ */ new WeakMap();
|
|
10442
10442
|
function ew(g, A) {
|
|
10443
10443
|
const I = PA.get(g), Q = { ...g, deleted: g.deleted.map((C) => {
|
|
10444
|
-
const B = I?.get(C.id), D = A.types[C.type]?.fields, i = Object.fromEntries(Object.entries(B ?? {}).filter(([
|
|
10444
|
+
const B = I?.get(C.id), D = A.types[C.type]?.fields, i = Object.fromEntries(Object.entries(B ?? {}).filter(([N]) => N.startsWith("~") || D && Object.hasOwn(D, N)));
|
|
10445
10445
|
return Object.keys(i).length ? { ...C, $was: i } : { ...C };
|
|
10446
10446
|
}) };
|
|
10447
10447
|
return I && PA.set(Q, I), Q;
|
|
@@ -10449,10 +10449,10 @@ function ew(g, A) {
|
|
|
10449
10449
|
function dw(g) {
|
|
10450
10450
|
const A = [], I = g.map(() => null);
|
|
10451
10451
|
g.forEach((B, D) => {
|
|
10452
|
-
let i = 0,
|
|
10453
|
-
for (; i <
|
|
10454
|
-
const
|
|
10455
|
-
g[A[
|
|
10452
|
+
let i = 0, N = A.length;
|
|
10453
|
+
for (; i < N; ) {
|
|
10454
|
+
const w = i + N >> 1;
|
|
10455
|
+
g[A[w]] < B ? i = w + 1 : N = w;
|
|
10456
10456
|
}
|
|
10457
10457
|
i > 0 && (I[D] = A[i - 1]), i === A.length ? A.push(D) : A[i] = D;
|
|
10458
10458
|
});
|
|
@@ -10497,8 +10497,8 @@ function rw(g, A, I) {
|
|
|
10497
10497
|
if (!BA(Q) || !BA(C)) return [{ field: g, before: A, after: I }];
|
|
10498
10498
|
const B = [];
|
|
10499
10499
|
for (const D of [.../* @__PURE__ */ new Set([...Object.keys(Q), ...Object.keys(C)])].sort(j)) {
|
|
10500
|
-
const [i,
|
|
10501
|
-
qC(i,
|
|
10500
|
+
const [i, N] = [Q[D] ?? null, C[D] ?? null];
|
|
10501
|
+
qC(i, N) || B.push(...uB(`${g}.${D}`, i, N));
|
|
10502
10502
|
}
|
|
10503
10503
|
return B;
|
|
10504
10504
|
}
|
|
@@ -10513,8 +10513,8 @@ function mC(g, A) {
|
|
|
10513
10513
|
} catch {
|
|
10514
10514
|
continue;
|
|
10515
10515
|
}
|
|
10516
|
-
const
|
|
10517
|
-
|
|
10516
|
+
const N = i.kind === "map" && !i.owns ? rw(D.field, D.before, D.after) : i.kind === "json" ? uB(D.field, D.before, D.after) : null;
|
|
10517
|
+
N && (N.length !== 1 || N[0].field !== D.field) && Q.set(D.field, N);
|
|
10518
10518
|
}
|
|
10519
10519
|
if (Q.size === 0) continue;
|
|
10520
10520
|
const C = [];
|
|
@@ -10525,35 +10525,35 @@ function mC(g, A) {
|
|
|
10525
10525
|
C.push(D);
|
|
10526
10526
|
continue;
|
|
10527
10527
|
}
|
|
10528
|
-
B = B.filter((
|
|
10528
|
+
B = B.filter((N) => N !== D.field), B.push(...i.map((N) => N.field)), C.push(...i);
|
|
10529
10529
|
}
|
|
10530
10530
|
I.edits = C.sort((D, i) => j(D.field, i.field)), I.fields = [...new Set(B)].sort(j);
|
|
10531
10531
|
}
|
|
10532
10532
|
return g;
|
|
10533
10533
|
}
|
|
10534
10534
|
function tC(g, A, I, Q, C) {
|
|
10535
|
-
const B = (
|
|
10535
|
+
const B = (J) => Q(J) !== null, D = { created: [], changed: [], moved: [], deleted: [] }, i = [], [N, w] = [new lQ(), new lQ()], G = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Set(), M = /* @__PURE__ */ new Map();
|
|
10536
10536
|
PA.set(D, M);
|
|
10537
|
-
for (const
|
|
10538
|
-
const Y = Object.hasOwn(A,
|
|
10537
|
+
for (const J of g) {
|
|
10538
|
+
const Y = Object.hasOwn(A, J) ? A[J] : void 0, a = Object.hasOwn(I, J) ? I[J] : void 0;
|
|
10539
10539
|
if (Y === void 0 && a !== void 0) {
|
|
10540
|
-
G.add(
|
|
10540
|
+
G.add(J);
|
|
10541
10541
|
const s = UI(a), H = tI(s).filter((t) => xQ(s[t])), R = {};
|
|
10542
10542
|
for (const t of H) {
|
|
10543
10543
|
const d = t.startsWith("~") ? "value" : gC(null, s[t], B);
|
|
10544
|
-
d === "value" ? R[t] = gg(s[t], 0) :
|
|
10544
|
+
d === "value" ? R[t] = gg(s[t], 0) : w.add(J, t, s[t], d);
|
|
10545
10545
|
const r = MI(s[t]);
|
|
10546
|
-
C && r && i.push({ id:
|
|
10546
|
+
C && r && i.push({ id: J, field: t, before: "", after: r });
|
|
10547
10547
|
}
|
|
10548
|
-
D.created.push({ id:
|
|
10548
|
+
D.created.push({ id: J, type: eA(a), fields: H, values: R });
|
|
10549
10549
|
} else if (Y !== void 0 && a === void 0) {
|
|
10550
|
-
|
|
10550
|
+
h.add(J);
|
|
10551
10551
|
const s = UI(Y), H = {};
|
|
10552
10552
|
for (const R of tI(s)) {
|
|
10553
10553
|
const t = R.startsWith("~") ? "value" : gC(s[R], null, B);
|
|
10554
|
-
t === "value" && xQ(s[R]) && (H[R] = qg(s[R], 0)),
|
|
10554
|
+
t === "value" && xQ(s[R]) && (H[R] = qg(s[R], 0)), N.add(J, R, s[R], t);
|
|
10555
10555
|
}
|
|
10556
|
-
M.set(
|
|
10556
|
+
M.set(J, H), D.deleted.push({ id: J, type: eA(Y), fields: [] });
|
|
10557
10557
|
} else if (Y !== void 0 && a !== void 0 && !LC(Y, a)) {
|
|
10558
10558
|
const [s, H] = [UI(Y), UI(a)], R = [], t = [];
|
|
10559
10559
|
eA(Y) !== eA(a) && (R.push("$type"), t.push({ field: "$type", before: eA(Y), after: eA(a) }));
|
|
@@ -10562,40 +10562,40 @@ function tC(g, A, I, Q, C) {
|
|
|
10562
10562
|
if (LC(r, x)) continue;
|
|
10563
10563
|
const IA = d.startsWith("~") ? "value" : gC(r, x, B);
|
|
10564
10564
|
if (IA !== "tree" && R.push(d), IA !== "value") {
|
|
10565
|
-
|
|
10565
|
+
N.add(J, d, r, IA), w.add(J, d, x, IA);
|
|
10566
10566
|
continue;
|
|
10567
10567
|
}
|
|
10568
10568
|
const c = (T) => T === null ? "" : MI(T), [L, p] = [c(r), c(x)];
|
|
10569
10569
|
let f = 0;
|
|
10570
|
-
L !== null && p !== null && (f = nw(L, p), C && L !== p && i.push({ id:
|
|
10570
|
+
L !== null && p !== null && (f = nw(L, p), C && L !== p && i.push({ id: J, field: d, before: L, after: p })), t.push({ field: d, before: qg(r, f), after: gg(x, f) });
|
|
10571
10571
|
}
|
|
10572
|
-
R.length && D.changed.push({ id:
|
|
10572
|
+
R.length && D.changed.push({ id: J, type: eA(a) || eA(Y), fields: R, edits: t });
|
|
10573
10573
|
}
|
|
10574
10574
|
}
|
|
10575
|
-
for (const
|
|
10576
|
-
const Y =
|
|
10577
|
-
Y && (
|
|
10575
|
+
for (const J of D.created) {
|
|
10576
|
+
const Y = w.position(J.id);
|
|
10577
|
+
Y && (J.at = Y);
|
|
10578
10578
|
}
|
|
10579
|
-
for (const
|
|
10580
|
-
const Y =
|
|
10581
|
-
Y && (
|
|
10579
|
+
for (const J of D.deleted) {
|
|
10580
|
+
const Y = N.position(J.id);
|
|
10581
|
+
Y && (J.at = Y);
|
|
10582
10582
|
}
|
|
10583
|
-
const
|
|
10584
|
-
for (const [
|
|
10585
|
-
const s =
|
|
10583
|
+
const F = /* @__PURE__ */ new Map();
|
|
10584
|
+
for (const [J, { group: Y, index: a }] of w.at) {
|
|
10585
|
+
const s = N.at.get(J);
|
|
10586
10586
|
if (s && CC(s.group) === CC(Y)) {
|
|
10587
10587
|
const H = CC(Y);
|
|
10588
|
-
|
|
10588
|
+
F.has(H) || F.set(H, []), F.get(H).push({ id: J, was: s.index, now: a });
|
|
10589
10589
|
}
|
|
10590
10590
|
}
|
|
10591
10591
|
const K = /* @__PURE__ */ new Set();
|
|
10592
|
-
for (const
|
|
10593
|
-
|
|
10594
|
-
for (const Y of dw(
|
|
10592
|
+
for (const J of F.values()) {
|
|
10593
|
+
J.sort((Y, a) => Y.now - a.now);
|
|
10594
|
+
for (const Y of dw(J.map((a) => a.was))) K.add(J[Y].id);
|
|
10595
10595
|
}
|
|
10596
|
-
const S = [.../* @__PURE__ */ new Set([...
|
|
10597
|
-
for (const
|
|
10598
|
-
G.has(
|
|
10596
|
+
const S = [.../* @__PURE__ */ new Set([...N.at.keys(), ...w.at.keys()])].sort(j);
|
|
10597
|
+
for (const J of S)
|
|
10598
|
+
G.has(J) || h.has(J) || K.has(J) || D.moved.push({ id: J, type: Q(J) ?? "", from: N.position(J), to: w.position(J) });
|
|
10599
10599
|
return C && (D.texts = i), D;
|
|
10600
10600
|
}
|
|
10601
10601
|
function WI(g, A) {
|
|
@@ -10604,22 +10604,22 @@ function WI(g, A) {
|
|
|
10604
10604
|
}
|
|
10605
10605
|
function xw(g, A, I, Q) {
|
|
10606
10606
|
g = PC(g, I, Q);
|
|
10607
|
-
const C = Ig(I), B = Ig(Q), D = $.ofState(A, Q), i = $.ofState(A, I),
|
|
10608
|
-
let
|
|
10607
|
+
const C = Ig(I), B = Ig(Q), D = $.ofState(A, Q), i = $.ofState(A, I), N = {};
|
|
10608
|
+
let w = 0;
|
|
10609
10609
|
for (const M of tI(C, B)) {
|
|
10610
10610
|
if (!Object.hasOwn(C, M) || !Object.hasOwn(B, M)) continue;
|
|
10611
|
-
const
|
|
10612
|
-
for (const S of tI(
|
|
10613
|
-
if (LC(
|
|
10614
|
-
const
|
|
10615
|
-
if (
|
|
10611
|
+
const F = UI(C[M]), K = UI(B[M]);
|
|
10612
|
+
for (const S of tI(F, K)) {
|
|
10613
|
+
if (LC(F[S], K[S]) || MI(F[S]) === null || MI(K[S]) === null) continue;
|
|
10614
|
+
const J = new TextEncoder().encode(JSON.stringify(F[S])).length;
|
|
10615
|
+
if (J > 1048576 || w + J > 4194304) continue;
|
|
10616
10616
|
const Y = D.attributed(M), a = Y?.holder ?? D.show(M), s = Y ? `${Y.path}.${S}` : S;
|
|
10617
|
-
(
|
|
10617
|
+
(N[a] ??= {})[s] = i.showText(F[S]), w += J;
|
|
10618
10618
|
}
|
|
10619
10619
|
}
|
|
10620
|
-
if (!Object.keys(
|
|
10621
|
-
const G = { ...g, $text:
|
|
10622
|
-
return
|
|
10620
|
+
if (!Object.keys(N).length) return g;
|
|
10621
|
+
const G = { ...g, $text: N }, h = PA.get(g);
|
|
10622
|
+
return h && PA.set(G, h), G;
|
|
10623
10623
|
}
|
|
10624
10624
|
const jw = (g) => !g.created.length && !g.changed.length && !g.moved.length && !g.deleted.length;
|
|
10625
10625
|
function uC(g, A, I, Q) {
|
|
@@ -10627,12 +10627,12 @@ function uC(g, A, I, Q) {
|
|
|
10627
10627
|
const C = PA.get(g) ?? /* @__PURE__ */ new Map(), B = (c, L) => {
|
|
10628
10628
|
const p = c.toolId(L) === null ? c.attributed(L) : null;
|
|
10629
10629
|
return p !== null ? `${p.holder}.${p.path}` : c.show(L);
|
|
10630
|
-
}, D = (c, L, p) => typeof L != "string" || L === "" ? L : c.toolId(L) === null && c.attributed(L) === null ? { unnamed: p ?? "object" } : B(c, L), i = (c, L) => Object.hasOwn(A.types, c) && Object.hasOwn(A.types[c].fields, L) ? A.types[c].fields[L].of ?? void 0 : void 0,
|
|
10630
|
+
}, D = (c, L, p) => typeof L != "string" || L === "" ? L : c.toolId(L) === null && c.attributed(L) === null ? { unnamed: p ?? "object" } : B(c, L), i = (c, L) => Object.hasOwn(A.types, c) && Object.hasOwn(A.types[c].fields, L) ? A.types[c].fields[L].of ?? void 0 : void 0, N = (c, L) => {
|
|
10631
10631
|
const p = c.toolId(L.parent) === null ? c.attributed(L.parent) : null;
|
|
10632
10632
|
return p !== null ? { parent: p.holder, field: `${p.path}.${L.field}`, index: L.index } : { ...L, parent: c.show(L.parent) };
|
|
10633
|
-
},
|
|
10633
|
+
}, w = new Map([...g.created, ...g.changed].map((c) => [c.id, c.type])), G = (c, L) => c !== void 0 && Object.hasOwn(A.types, c) && Object.hasOwn(A.types[c].fields, L) && A.types[c].fields[L].kind === "ref", h = (c, L) => G(w.get(c), L), M = (c, L) => ["json", "map"].includes(A.types[c]?.fields[L.split(".")[0]]?.kind ?? ""), F = (c) => c.sort((L, p) => j(L.id, p.id)), K = g.created.map((c) => {
|
|
10634
10634
|
const L = { ...c };
|
|
10635
|
-
return c.values && (L.values = Object.fromEntries(Object.entries(c.values).map(([p, f]) => [p, G(c.type, p) ? D(Q, f, i(c.type, p)) : M(c.type, p) ? Q.showJson(f) : f]))), c.at && (L.at =
|
|
10635
|
+
return c.values && (L.values = Object.fromEntries(Object.entries(c.values).map(([p, f]) => [p, G(c.type, p) ? D(Q, f, i(c.type, p)) : M(c.type, p) ? Q.showJson(f) : f]))), c.at && (L.at = N(Q, c.at)), L;
|
|
10636
10636
|
}), S = g.changed.map((c) => {
|
|
10637
10637
|
const L = { ...c };
|
|
10638
10638
|
if (c.edits) {
|
|
@@ -10643,9 +10643,9 @@ function uC(g, A, I, Q) {
|
|
|
10643
10643
|
p.size > 0 && (L.edits = L.edits.filter((f) => !p.has(f.field)), L.fields = L.fields.filter((f) => !p.has(f)));
|
|
10644
10644
|
}
|
|
10645
10645
|
return L;
|
|
10646
|
-
}).filter((c) => c.fields.length > 0),
|
|
10647
|
-
const p =
|
|
10648
|
-
return p.type = L.typeOf(c) ?? "",
|
|
10646
|
+
}).filter((c) => c.fields.length > 0), J = /* @__PURE__ */ new Map(), Y = (c, L) => {
|
|
10647
|
+
const p = J.get(c) ?? { type: "", fields: [], edits: [], values: {} };
|
|
10648
|
+
return p.type = L.typeOf(c) ?? "", J.set(c, p), p;
|
|
10649
10649
|
}, a = new Set(g.created.map((c) => Q.show(c.id))), s = new Set(g.deleted.map((c) => I.show(c.id))), H = [];
|
|
10650
10650
|
for (const c of S) {
|
|
10651
10651
|
const L = Q.attributed(c.id);
|
|
@@ -10717,18 +10717,18 @@ function uC(g, A, I, Q) {
|
|
|
10717
10717
|
f.fields.push(d(p.path)), f.edits.push({ field: d(p.path), before: null, after: p.path });
|
|
10718
10718
|
}
|
|
10719
10719
|
}
|
|
10720
|
-
for (const c of
|
|
10720
|
+
for (const c of J.values()) lw(c);
|
|
10721
10721
|
const x = {
|
|
10722
10722
|
created: R.map((c) => ({ ...c, id: Q.show(c.id) })),
|
|
10723
10723
|
changed: H.map((c) => ({ ...c, id: Q.show(c.id) })),
|
|
10724
|
-
moved: r.map((c) => ({ ...c, id: Q.show(c.id), from: c.from ?
|
|
10724
|
+
moved: r.map((c) => ({ ...c, id: Q.show(c.id), from: c.from ? N(I, c.from) : null, to: c.to ? N(Q, c.to) : null })),
|
|
10725
10725
|
deleted: t.map((c) => {
|
|
10726
10726
|
const L = { ...c, id: I.show(c.id) };
|
|
10727
|
-
return c.at && (L.at =
|
|
10727
|
+
return c.at && (L.at = N(I, c.at)), L;
|
|
10728
10728
|
})
|
|
10729
10729
|
}, IA = (c) => [...new Set(c)].sort(j);
|
|
10730
|
-
for (const c of [...
|
|
10731
|
-
const L =
|
|
10730
|
+
for (const c of [...J.keys()].sort(j)) {
|
|
10731
|
+
const L = J.get(c), p = x.created.find((T) => T.id === c);
|
|
10732
10732
|
if (p !== void 0) {
|
|
10733
10733
|
p.fields = IA([...p.fields, ...L.fields]), p.values = { ...p.values ?? {}, ...L.values };
|
|
10734
10734
|
continue;
|
|
@@ -10737,8 +10737,8 @@ function uC(g, A, I, Q) {
|
|
|
10737
10737
|
let f = x.changed.find((T) => T.id === c);
|
|
10738
10738
|
f === void 0 && (f = { id: c, type: L.type, fields: [], edits: [] }, x.changed.push(f)), f.fields = IA([...f.fields, ...L.fields]), f.edits = [...f.edits ?? [], ...L.edits].sort((T, m) => j(T.field, m.field));
|
|
10739
10739
|
}
|
|
10740
|
-
return
|
|
10741
|
-
const L =
|
|
10740
|
+
return F(x.created), F(x.changed), F(x.deleted), F(x.moved), g.texts && (x.texts = g.texts.map((c) => {
|
|
10741
|
+
const L = h(c.id, c.field), p = (v, YA) => L && YA !== "" ? B(v, YA) : YA, f = Q.attributed(c.id), [T, m] = f !== null ? [f.holder, `${f.path}.${c.field}`] : [B(Q, c.id), c.field];
|
|
10742
10742
|
return { ...c, id: T, field: m, before: p(I, c.before), after: p(Q, c.after) };
|
|
10743
10743
|
}).sort((c, L) => j(c.id, L.id) || j(c.field, L.field))), g.footprint !== void 0 && (x.footprint = g.footprint), PA.set(x, new Map([...C].map(([c, L]) => {
|
|
10744
10744
|
const p = I.typeOf(c) ?? "";
|
|
@@ -10758,12 +10758,12 @@ function lw(g) {
|
|
|
10758
10758
|
g.edits = g.edits.filter((B) => !Q.has(B.field)), g.fields = g.fields.filter((B) => !Q.has(B));
|
|
10759
10759
|
for (const B of [...Q].sort(j)) {
|
|
10760
10760
|
const D = I.get(B), i = A.get(B);
|
|
10761
|
-
for (const
|
|
10762
|
-
const
|
|
10763
|
-
if (!zB(
|
|
10764
|
-
g.fields.push(`${B}.${
|
|
10765
|
-
const
|
|
10766
|
-
g.edits.push({ field: `${B}.${
|
|
10761
|
+
for (const N of [.../* @__PURE__ */ new Set([...Object.keys(D), ...Object.keys(i)])].sort(j)) {
|
|
10762
|
+
const w = Object.hasOwn(D, N) ? D[N] : null, G = Object.hasOwn(i, N) ? i[N] : null;
|
|
10763
|
+
if (!zB(w, G)) {
|
|
10764
|
+
g.fields.push(`${B}.${N}`);
|
|
10765
|
+
const h = C.get(B);
|
|
10766
|
+
g.edits.push({ field: `${B}.${N}`, before: w, after: G, ...h === void 0 ? {} : { named: `${h}.${N}` } });
|
|
10767
10767
|
}
|
|
10768
10768
|
}
|
|
10769
10769
|
}
|
|
@@ -10794,52 +10794,52 @@ function Tw(g, A) {
|
|
|
10794
10794
|
for (const K of pA(g, "changed")) {
|
|
10795
10795
|
const S = Array.isArray(K.edits) ? K.edits : [];
|
|
10796
10796
|
if (typeof K.id != "string" || Q.has(K.id) || S.length === 0) continue;
|
|
10797
|
-
const
|
|
10797
|
+
const J = [];
|
|
10798
10798
|
for (const a of S) {
|
|
10799
10799
|
if (!lA(a) || typeof a.field != "string") break;
|
|
10800
10800
|
const s = vC(a.before, a.after);
|
|
10801
10801
|
if (s === null) break;
|
|
10802
|
-
|
|
10802
|
+
J.push([a.field, s]);
|
|
10803
10803
|
}
|
|
10804
10804
|
const Y = Array.isArray(K.fields) ? K.fields : [];
|
|
10805
|
-
|
|
10805
|
+
J.length !== S.length || Y.length !== J.length || !J.every(([a]) => Y.includes(a)) || (J.sort((a, s) => a[0] < s[0] ? -1 : a[0] > s[0] ? 1 : 0), J.length === 1 && (C.set(K.id, JSON.stringify(J[0])), B.set(K.id, J[0])), D.push([K.id, J]));
|
|
10806
10806
|
}
|
|
10807
|
-
const i = [],
|
|
10807
|
+
const i = [], N = /* @__PURE__ */ new Set(), w = vB(g);
|
|
10808
10808
|
if (C.size >= sI)
|
|
10809
|
-
for (const [K, S] of
|
|
10810
|
-
const
|
|
10811
|
-
if (!
|
|
10809
|
+
for (const [K, S] of w) {
|
|
10810
|
+
const J = A(K, S);
|
|
10811
|
+
if (!J) continue;
|
|
10812
10812
|
let Y = 0;
|
|
10813
|
-
for (; Y <
|
|
10814
|
-
const a = C.get(
|
|
10813
|
+
for (; Y < J.length; ) {
|
|
10814
|
+
const a = C.get(J[Y]);
|
|
10815
10815
|
if (a === void 0) {
|
|
10816
10816
|
Y += 1;
|
|
10817
10817
|
continue;
|
|
10818
10818
|
}
|
|
10819
10819
|
let s = Y + 1;
|
|
10820
|
-
for (; s <
|
|
10820
|
+
for (; s < J.length && C.get(J[s]) === a; ) s += 1;
|
|
10821
10821
|
if (s - Y >= sI) {
|
|
10822
|
-
const [H, R] = B.get(
|
|
10822
|
+
const [H, R] = B.get(J[Y]);
|
|
10823
10823
|
i.push({ parent: K, field: S, from: Y, count: s - Y, shift: { field: H, by: R } });
|
|
10824
|
-
for (const t of
|
|
10824
|
+
for (const t of J.slice(Y, s)) N.add(t);
|
|
10825
10825
|
}
|
|
10826
10826
|
Y = s;
|
|
10827
10827
|
}
|
|
10828
10828
|
}
|
|
10829
10829
|
const G = [];
|
|
10830
10830
|
for (const [K, S] of D) {
|
|
10831
|
-
if (
|
|
10832
|
-
const
|
|
10833
|
-
Y ? Y[2].push(K) : G.push([
|
|
10831
|
+
if (N.has(K)) continue;
|
|
10832
|
+
const J = JSON.stringify(S), Y = G.find(([a]) => a === J);
|
|
10833
|
+
Y ? Y[2].push(K) : G.push([J, S, [K]]);
|
|
10834
10834
|
}
|
|
10835
10835
|
for (const [, K, S] of G)
|
|
10836
10836
|
if (!(S.length < sI)) {
|
|
10837
|
-
i.push({ ids: S, edits: K.map(([
|
|
10838
|
-
for (const
|
|
10837
|
+
i.push({ ids: S, edits: K.map(([J, Y]) => ({ field: J, by: Y })) });
|
|
10838
|
+
for (const J of S) N.add(J);
|
|
10839
10839
|
}
|
|
10840
|
-
const
|
|
10840
|
+
const h = /* @__PURE__ */ new Map();
|
|
10841
10841
|
for (const K of pA(g, "changed")) {
|
|
10842
|
-
if (typeof K.id != "string" ||
|
|
10842
|
+
if (typeof K.id != "string" || N.has(K.id) || Q.has(K.id) || !Array.isArray(K.edits) || K.edits.length === 0 || !Array.isArray(K.fields)) continue;
|
|
10843
10843
|
const S = [];
|
|
10844
10844
|
for (const a of K.edits) {
|
|
10845
10845
|
if (!lA(a) || typeof a.field != "string" || !Object.hasOwn(a, "after")) break;
|
|
@@ -10849,28 +10849,28 @@ function Tw(g, A) {
|
|
|
10849
10849
|
}
|
|
10850
10850
|
if (S.length !== K.edits.length || K.fields.length !== S.length || !S.every((a) => K.fields.includes(a.field))) continue;
|
|
10851
10851
|
S.sort((a, s) => j(a.field, s.field));
|
|
10852
|
-
const
|
|
10853
|
-
Y ? Y.ids.push(K.id) :
|
|
10852
|
+
const J = AA(S), Y = h.get(J);
|
|
10853
|
+
Y ? Y.ids.push(K.id) : h.set(J, { edits: S, ids: [K.id] });
|
|
10854
10854
|
}
|
|
10855
|
-
for (const { edits: K, ids: S } of
|
|
10855
|
+
for (const { edits: K, ids: S } of h.values())
|
|
10856
10856
|
if (!(S.length < sI)) {
|
|
10857
10857
|
i.push({ ids: S, edits: K });
|
|
10858
|
-
for (const
|
|
10858
|
+
for (const J of S) N.add(J);
|
|
10859
10859
|
}
|
|
10860
10860
|
const M = new Set(
|
|
10861
10861
|
i.filter((K) => typeof K.parent == "string").map((K) => Sg(K.parent, K.field))
|
|
10862
|
-
),
|
|
10862
|
+
), F = (K) => {
|
|
10863
10863
|
K && M.add(Sg(...K));
|
|
10864
10864
|
};
|
|
10865
|
-
for (const K of [...pA(g, "created"), ...pA(g, "deleted")])
|
|
10865
|
+
for (const K of [...pA(g, "created"), ...pA(g, "deleted")]) F(pI(K.at));
|
|
10866
10866
|
for (const K of pA(g, "moved"))
|
|
10867
|
-
|
|
10867
|
+
F(pI(K.from)), F(pI(K.to));
|
|
10868
10868
|
return Array.isArray(I.changed) && (I.changed = I.changed.filter((K) => {
|
|
10869
10869
|
if (!lA(K) || typeof K.id != "string") return !0;
|
|
10870
|
-
if (
|
|
10870
|
+
if (N.has(K.id)) return !1;
|
|
10871
10871
|
if (!Array.isArray(K.edits) || K.edits.length > 0 || !Array.isArray(K.fields)) return !0;
|
|
10872
10872
|
const S = K.id;
|
|
10873
|
-
return K.fields = K.fields.filter((
|
|
10873
|
+
return K.fields = K.fields.filter((J) => typeof J != "string" || !M.has(Sg(S, J))), K.fields.length > 0;
|
|
10874
10874
|
})), i.length > 0 && (I.footprint = i), Zw(I);
|
|
10875
10875
|
}
|
|
10876
10876
|
function pC(g, A, I, Q, C) {
|
|
@@ -10884,27 +10884,27 @@ function pC(g, A, I, Q, C) {
|
|
|
10884
10884
|
function Zw(g) {
|
|
10885
10885
|
for (const A of pA(g, "changed")) {
|
|
10886
10886
|
const I = Array.isArray(A.edits) ? A.edits.filter(lA) : [], Q = [], C = /* @__PURE__ */ new Set();
|
|
10887
|
-
for (const
|
|
10888
|
-
const
|
|
10889
|
-
typeof
|
|
10887
|
+
for (const N of I) {
|
|
10888
|
+
const w = [];
|
|
10889
|
+
typeof N.field == "string" && (lA(N.before) || Array.isArray(N.before)) && pC(N.field, N.before, N.after, w, C) ? Q.push(...w) : Q.push(N);
|
|
10890
10890
|
}
|
|
10891
10891
|
const B = /* @__PURE__ */ new Map();
|
|
10892
|
-
Q.forEach((
|
|
10893
|
-
const G = vC(
|
|
10894
|
-
if (G === null || typeof
|
|
10895
|
-
const
|
|
10896
|
-
for (let M = 1; M <
|
|
10897
|
-
if (/^\d+$/.test(
|
|
10898
|
-
const
|
|
10899
|
-
S.members.push([
|
|
10892
|
+
Q.forEach((N, w) => {
|
|
10893
|
+
const G = vC(N.before, N.after);
|
|
10894
|
+
if (G === null || typeof N.field != "string") return;
|
|
10895
|
+
const h = N.field.split(".");
|
|
10896
|
+
for (let M = 1; M < h.length - 1; M++) {
|
|
10897
|
+
if (/^\d+$/.test(h[M]) && !C.has(h.slice(0, M).join("."))) continue;
|
|
10898
|
+
const F = h.map((J, Y) => Y === M ? "*" : J).join("."), K = JSON.stringify([F, G]), S = B.get(K) ?? { field: F, by: G, members: [] };
|
|
10899
|
+
S.members.push([w, h[M]]), B.set(K, S);
|
|
10900
10900
|
}
|
|
10901
10901
|
});
|
|
10902
10902
|
const D = /* @__PURE__ */ new Set(), i = [];
|
|
10903
|
-
for (const
|
|
10904
|
-
const
|
|
10905
|
-
G.length < sI || G.length !==
|
|
10903
|
+
for (const N of [...B.values()].sort((w, G) => w.field < G.field ? -1 : w.field > G.field ? 1 : JSON.stringify(w.by) < JSON.stringify(G.by) ? -1 : 1)) {
|
|
10904
|
+
const w = N.members.filter(([h]) => !D.has(h)), G = [...new Set(w.map(([, h]) => h))].sort(j);
|
|
10905
|
+
G.length < sI || G.length !== w.length || (i.push({ field: N.field, count: G.length, keys: G, shift: { by: N.by } }), w.forEach(([h]) => D.add(h)));
|
|
10906
10906
|
}
|
|
10907
|
-
i.length && (A.edits = [...Q.filter((
|
|
10907
|
+
i.length && (A.edits = [...Q.filter((N, w) => !D.has(w)), ...i], A.fields = [...new Set(A.edits.map((N) => N.field))].sort());
|
|
10908
10908
|
}
|
|
10909
10909
|
return g;
|
|
10910
10910
|
}
|
|
@@ -11139,8 +11139,8 @@ function _w(g, A, I, Q, C) {
|
|
|
11139
11139
|
}
|
|
11140
11140
|
}
|
|
11141
11141
|
Q.forEach((D, i) => {
|
|
11142
|
-
const
|
|
11143
|
-
|
|
11142
|
+
const N = B[i];
|
|
11143
|
+
N !== void 0 && Ww(D, N);
|
|
11144
11144
|
});
|
|
11145
11145
|
}
|
|
11146
11146
|
const bQ = 1024;
|
|
@@ -11269,28 +11269,31 @@ class Cg {
|
|
|
11269
11269
|
}
|
|
11270
11270
|
if (typeof B?.then == "function")
|
|
11271
11271
|
throw y.engine("a transaction runs synchronously; its function returned a promise");
|
|
11272
|
-
const { ops: D, nodes: i } = C;
|
|
11272
|
+
const { ops: D, nodes: i } = C, N = new Set(D.flatMap((w) => w.op === "create" ? [w.id] : []));
|
|
11273
11273
|
return {
|
|
11274
11274
|
result: B,
|
|
11275
11275
|
staged: {
|
|
11276
11276
|
empty: D.length === 0,
|
|
11277
11277
|
raisesSchema: D.some((w) => w.op === "raiseSchema"),
|
|
11278
|
-
undoTouches: D.flatMap((w,
|
|
11278
|
+
undoTouches: D.flatMap((w, G) => {
|
|
11279
11279
|
if (w.op === "raiseSchema") return [];
|
|
11280
|
-
const
|
|
11281
|
-
let
|
|
11282
|
-
if (w.op === "listInsert")
|
|
11283
|
-
else if (w.op === "treeCreate")
|
|
11280
|
+
const h = [{ id: w.id, fields: "field" in w ? [w.field] : null }];
|
|
11281
|
+
let M;
|
|
11282
|
+
if (w.op === "listInsert") M = w.item;
|
|
11283
|
+
else if (w.op === "treeCreate") M = w.object;
|
|
11284
11284
|
else if (w.op === "listMove" || w.op === "listRemove")
|
|
11285
|
-
|
|
11285
|
+
M = C.undoListItem(w.id, w.field, w.op === "listMove" ? w.from : w.index, G);
|
|
11286
11286
|
else if ((w.op === "treeMove" || w.op === "treeDelete") && Hg(w.node) === null) {
|
|
11287
|
-
const
|
|
11288
|
-
|
|
11287
|
+
const K = wA(A, I, w.id, w.field, "tree")?.getNodeByID(tg(w.node));
|
|
11288
|
+
M = K ? Rg(K) ?? void 0 : void 0;
|
|
11289
11289
|
}
|
|
11290
|
-
return
|
|
11290
|
+
return M && h.push({ id: M, fields: [] }), h;
|
|
11291
11291
|
}),
|
|
11292
|
-
apply: (w,
|
|
11293
|
-
|
|
11292
|
+
apply: (w, G, h) => _w(w, G, D, i, h),
|
|
11293
|
+
// Writes to an object the same operations create are left out, as its creation's own
|
|
11294
|
+
// fields are: no undo reaches such a register before a later write replaces it (undoing
|
|
11295
|
+
// the creation removes the whole object), so the replica keeps no note of them.
|
|
11296
|
+
registerWrites: D.flatMap((w) => (w.op === "set" || w.op === "mapSet" || w.op === "mapDelete") && N.has(w.id) ? [] : w.op === "set" ? [{ id: w.id, field: null, key: w.field, value: w.value }] : w.op === "mapSet" ? [{ id: w.id, field: w.field, key: w.key, value: w.value }] : w.op === "mapDelete" ? [{ id: w.id, field: w.field, key: w.key, value: void 0 }] : [])
|
|
11294
11297
|
}
|
|
11295
11298
|
};
|
|
11296
11299
|
}
|
|
@@ -11341,7 +11344,7 @@ class Cg {
|
|
|
11341
11344
|
let C;
|
|
11342
11345
|
if (Q !== void 0) {
|
|
11343
11346
|
OQ("the options", Q);
|
|
11344
|
-
const G = Object.keys(Q).find((
|
|
11347
|
+
const G = Object.keys(Q).find((h) => h !== "id");
|
|
11345
11348
|
if (G !== void 0) throw new O("invalid-value", `the options take only \`id\`, not \`${G}\``);
|
|
11346
11349
|
C = Q.id, C !== void 0 && u("an object id", C);
|
|
11347
11350
|
}
|
|
@@ -11350,17 +11353,17 @@ class Cg {
|
|
|
11350
11353
|
if (B.projected) throw y.invalidValue(A, "$type", "projected objects are computed by the kit, never stored");
|
|
11351
11354
|
const D = Z(I), i = {};
|
|
11352
11355
|
for (const G of D) {
|
|
11353
|
-
const
|
|
11354
|
-
typeof
|
|
11356
|
+
const h = yC(this.schema, A, G, I[G]);
|
|
11357
|
+
typeof h == "string" && this.checkOf(A, G, B.fields[G], h), kA(i, G, h);
|
|
11355
11358
|
}
|
|
11356
11359
|
for (const G of Z(B.fields)) {
|
|
11357
|
-
const
|
|
11358
|
-
if (!_I(
|
|
11360
|
+
const h = B.fields[G];
|
|
11361
|
+
if (!_I(h.kind) && !h.optional && !Object.hasOwn(I, G)) throw y.invalidValue(A, G, "is required");
|
|
11359
11362
|
}
|
|
11360
|
-
const
|
|
11361
|
-
this.created.set(
|
|
11362
|
-
const
|
|
11363
|
-
return
|
|
11363
|
+
const N = C === void 0 ? $B() : this.freeId(A, C);
|
|
11364
|
+
this.created.set(N, { ty: A, op: this.ops.length });
|
|
11365
|
+
const w = this.createdByType.get(A);
|
|
11366
|
+
return w ? w.push(N) : this.createdByType.set(A, [N]), this.ops.push({ op: "create", id: N, ty: A, fields: i }), N;
|
|
11364
11367
|
}
|
|
11365
11368
|
/** Sets one register field. Concurrent sets of one field resolve to one winner; sets of different fields both survive. */
|
|
11366
11369
|
set(A, I, Q) {
|
|
@@ -11427,8 +11430,8 @@ class Cg {
|
|
|
11427
11430
|
this.live(), _(A, I), qA("index", Q), qA("index", C), u("a mark key", B);
|
|
11428
11431
|
const i = this.markKey(A, I, B);
|
|
11429
11432
|
if (D == null) throw y.invalidValue(i, I, `mark \`${B}\` takes a value; remove a mark with textUnmark`);
|
|
11430
|
-
const
|
|
11431
|
-
this.markRange(A, I, Q, C) && this.ops.push({ op: "textMark", id: A, field: I, start: Q, end: C, key: B, value:
|
|
11433
|
+
const N = KC(D, (w) => y.invalidValue(i, I, `mark \`${B}\` ${w}`));
|
|
11434
|
+
this.markRange(A, I, Q, C) && this.ops.push({ op: "textMark", id: A, field: I, start: Q, end: C, key: B, value: N });
|
|
11432
11435
|
}
|
|
11433
11436
|
/** Removes mark `key` from the code units `start..end` of a text field. Characters without the mark are left as they are; an empty range changes nothing. */
|
|
11434
11437
|
textUnmark(A, I, Q, C, B) {
|
|
@@ -11468,7 +11471,7 @@ class Cg {
|
|
|
11468
11471
|
/** Sets `key` of a map field. Concurrent sets of one key resolve to one winner. */
|
|
11469
11472
|
mapSet(A, I, Q, C) {
|
|
11470
11473
|
this.live(), _(A, I), u("a map key", Q);
|
|
11471
|
-
const B = this.writableMap(A, I), D = KC(C, (
|
|
11474
|
+
const B = this.writableMap(A, I), D = KC(C, (N) => y.invalidValue(B, I, N));
|
|
11472
11475
|
gD(this.schema, B, I, Q, D), typeof D == "string" && this.checkOf(B, I, this.schema.types[B].fields[I], D);
|
|
11473
11476
|
const i = YI(Q);
|
|
11474
11477
|
this.mapWrites(A, I).set(i, this.ops.length), this.ops.push({ op: "mapSet", id: A, field: I, key: i, value: D });
|
|
@@ -11500,9 +11503,9 @@ class Cg {
|
|
|
11500
11503
|
const Q = tA(this.stored(A, I, !1), "map", A, I), C = Q ? ZB(Q) : [], B = this.maps.get(HA(A, I));
|
|
11501
11504
|
if (!B) return C;
|
|
11502
11505
|
const D = new Map(C);
|
|
11503
|
-
for (const [i,
|
|
11504
|
-
|
|
11505
|
-
return [...D].sort((i,
|
|
11506
|
+
for (const [i, N] of B)
|
|
11507
|
+
N === null ? D.delete(i) : D.set(i, this.pendingMapValue(N));
|
|
11508
|
+
return [...D].sort((i, N) => j(i[0], N[0]));
|
|
11506
11509
|
}
|
|
11507
11510
|
/**
|
|
11508
11511
|
* Ids of the live objects of type `ty`, including those this transaction created and without
|
|
@@ -11523,11 +11526,11 @@ class Cg {
|
|
|
11523
11526
|
this.live(), _(A, I), u("a tree node object", C);
|
|
11524
11527
|
const { ty: B, def: D } = this.containerField(A, I, "tree");
|
|
11525
11528
|
this.checkOf(B, I, D, C);
|
|
11526
|
-
const i = Q == null ? null : this.nodeKey(Q),
|
|
11527
|
-
if (i !== null && !
|
|
11528
|
-
|
|
11529
|
-
const G = Ow(this.serial,
|
|
11530
|
-
return this.nodes.push(G), this.ops.push({ op: "treeCreate", id: A, field: I, parent: i, object: C, node:
|
|
11529
|
+
const i = Q == null ? null : this.nodeKey(Q), N = this.nodes.length, w = this.treeState(A, I);
|
|
11530
|
+
if (i !== null && !w.contains(i)) throw y.notFound(`parent node in ${A}.${I}`);
|
|
11531
|
+
w.parents.set(BC(N), i);
|
|
11532
|
+
const G = Ow(this.serial, N);
|
|
11533
|
+
return this.nodes.push(G), this.ops.push({ op: "treeCreate", id: A, field: I, parent: i, object: C, node: N }), G;
|
|
11531
11534
|
}
|
|
11532
11535
|
/**
|
|
11533
11536
|
* Moves `node` under `parent` (`null`: a root), last among its siblings. A move that would make a
|
|
@@ -11557,10 +11560,10 @@ class Cg {
|
|
|
11557
11560
|
let Q = 0;
|
|
11558
11561
|
for (let C = this.treeDuplicate(A, I); C; C = this.treeDuplicate(A, I)) {
|
|
11559
11562
|
const [B, D] = C;
|
|
11560
|
-
for (const
|
|
11561
|
-
|
|
11562
|
-
const i = this.nodeKey(D),
|
|
11563
|
-
|
|
11563
|
+
for (const w of this.tree(A, I))
|
|
11564
|
+
w.parent?.id === D.id && this.treeMove(A, I, w.node, B);
|
|
11565
|
+
const i = this.nodeKey(D), N = this.treeState(A, I);
|
|
11566
|
+
N.parents.delete(i), N.deleted.add(i), this.ops.push({ op: "treeDelete", id: A, field: I, node: i }), Q += 1;
|
|
11564
11567
|
}
|
|
11565
11568
|
return Q;
|
|
11566
11569
|
}
|
|
@@ -11570,17 +11573,17 @@ class Cg {
|
|
|
11570
11573
|
let D = null;
|
|
11571
11574
|
for (const M of Q) {
|
|
11572
11575
|
C.set(M.node.id, M.parent?.id ?? null);
|
|
11573
|
-
const
|
|
11574
|
-
|
|
11576
|
+
const F = B.get(M.object) ?? [];
|
|
11577
|
+
F.push(M.node), B.set(M.object, F), F.length === 2 && D === null && (D = M.object);
|
|
11575
11578
|
}
|
|
11576
11579
|
const i = D === null ? void 0 : B.get(D);
|
|
11577
11580
|
if (!i) return null;
|
|
11578
|
-
const
|
|
11579
|
-
for (let
|
|
11580
|
-
if (
|
|
11581
|
+
const N = new Set(i.map((M) => M.id)), w = (M) => {
|
|
11582
|
+
for (let F = C.get(M.id) ?? null; F !== null; F = C.get(F) ?? null)
|
|
11583
|
+
if (N.has(F)) return !1;
|
|
11581
11584
|
return !0;
|
|
11582
|
-
}, G = i.filter(
|
|
11583
|
-
return G &&
|
|
11585
|
+
}, G = i.filter(w).sort((M, F) => gN(M.id, F.id))[0], h = G && i.find((M) => M.id !== G.id);
|
|
11586
|
+
return G && h ? [G, h] : null;
|
|
11584
11587
|
}
|
|
11585
11588
|
/**
|
|
11586
11589
|
* The tree's nodes in pre-order as this transaction sees it: the document's nodes plus the nodes
|
|
@@ -11590,42 +11593,42 @@ class Cg {
|
|
|
11590
11593
|
*/
|
|
11591
11594
|
tree(A, I) {
|
|
11592
11595
|
this.live(), _(A, I), this.containerField(A, I, "tree");
|
|
11593
|
-
const Q = tA(this.stored(A, I, !1), "tree", A, I), C = /* @__PURE__ */ new Map(), B = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map(), i = (M,
|
|
11596
|
+
const Q = tA(this.stored(A, I, !1), "tree", A, I), C = /* @__PURE__ */ new Map(), B = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map(), i = (M, F) => {
|
|
11594
11597
|
const K = C.get(M);
|
|
11595
|
-
K ? K.push(
|
|
11596
|
-
},
|
|
11598
|
+
K ? K.push(F) : C.set(M, [F]), B.set(F, M);
|
|
11599
|
+
}, N = (M, F) => {
|
|
11597
11600
|
for (const K of M ?? []) {
|
|
11598
11601
|
const S = eC(K.id);
|
|
11599
|
-
i(
|
|
11602
|
+
i(F, S), D.set(S, Rg(K)), N(K.children(), S);
|
|
11600
11603
|
}
|
|
11601
11604
|
};
|
|
11602
|
-
Q &&
|
|
11605
|
+
Q && N(Q.roots(), null);
|
|
11603
11606
|
for (const M of this.ops)
|
|
11604
11607
|
if (M.op === "treeCreate" && M.id === A && M.field === I) {
|
|
11605
|
-
const
|
|
11606
|
-
i(M.parent,
|
|
11608
|
+
const F = BC(M.node);
|
|
11609
|
+
i(M.parent, F), D.set(F, M.object);
|
|
11607
11610
|
} else if (M.op === "treeMove" && M.id === A && M.field === I) {
|
|
11608
|
-
const
|
|
11609
|
-
|
|
11611
|
+
const F = B.get(M.node);
|
|
11612
|
+
F !== void 0 && C.set(F, (C.get(F) ?? []).filter((K) => K !== M.node)), i(M.parent, M.node);
|
|
11610
11613
|
} else if (M.op === "treeDelete" && M.id === A && M.field === I) {
|
|
11611
|
-
const
|
|
11612
|
-
|
|
11614
|
+
const F = B.get(M.node);
|
|
11615
|
+
F !== void 0 && C.set(F, (C.get(F) ?? []).filter((K) => K !== M.node)), B.delete(M.node);
|
|
11613
11616
|
}
|
|
11614
|
-
const
|
|
11615
|
-
const
|
|
11616
|
-
if (
|
|
11617
|
-
const K = this.nodes[
|
|
11618
|
-
if (!K) throw y.engine(`tree node ${
|
|
11617
|
+
const w = (M) => {
|
|
11618
|
+
const F = Hg(M);
|
|
11619
|
+
if (F === null) return IE(tg(M));
|
|
11620
|
+
const K = this.nodes[F];
|
|
11621
|
+
if (!K) throw y.engine(`tree node ${F} was not staged`);
|
|
11619
11622
|
return K;
|
|
11620
|
-
}, G = [],
|
|
11623
|
+
}, G = [], h = (M, F) => {
|
|
11621
11624
|
for (const K of C.get(M) ?? []) {
|
|
11622
11625
|
const S = D.get(K);
|
|
11623
11626
|
if (S == null) continue;
|
|
11624
|
-
const
|
|
11625
|
-
G.push({ node:
|
|
11627
|
+
const J = w(K);
|
|
11628
|
+
G.push({ node: J, object: S, parent: F }), h(K, J);
|
|
11626
11629
|
}
|
|
11627
11630
|
};
|
|
11628
|
-
return
|
|
11631
|
+
return h(null, null), G;
|
|
11629
11632
|
}
|
|
11630
11633
|
/** Checks an id the host chose for a new object of type `ty`. */
|
|
11631
11634
|
freeId(A, I) {
|
|
@@ -11755,8 +11758,8 @@ class Cg {
|
|
|
11755
11758
|
}
|
|
11756
11759
|
function gN(g, A) {
|
|
11757
11760
|
const I = (i) => {
|
|
11758
|
-
const
|
|
11759
|
-
return [BigInt(i.slice(
|
|
11761
|
+
const N = i.indexOf("@");
|
|
11762
|
+
return [BigInt(i.slice(N + 1)), Number(i.slice(0, N))];
|
|
11760
11763
|
}, [Q, C] = I(g), [B, D] = I(A);
|
|
11761
11764
|
return Q !== B ? Q < B ? -1 : 1 : C - D;
|
|
11762
11765
|
}
|
|
@@ -11767,7 +11770,7 @@ function EC(g, A) {
|
|
|
11767
11770
|
if (D.path[0] === hA) {
|
|
11768
11771
|
if (D.path.length >= 2) {
|
|
11769
11772
|
if (I.add(String(D.path[1])), D.diff.type === "map")
|
|
11770
|
-
for (const [i,
|
|
11773
|
+
for (const [i, N] of Object.entries(D.diff.updated)) nA(N) || Q.push(rC(D.target, i));
|
|
11771
11774
|
} else if (D.diff.type === "map") for (const i of Object.keys(D.diff.updated)) I.add(i);
|
|
11772
11775
|
}
|
|
11773
11776
|
});
|
|
@@ -11850,16 +11853,16 @@ class fA {
|
|
|
11850
11853
|
QC(Q);
|
|
11851
11854
|
const i = new RA();
|
|
11852
11855
|
i.setPeerId(Q), ZI(i, A);
|
|
11853
|
-
const
|
|
11854
|
-
|
|
11855
|
-
const { result:
|
|
11856
|
+
const N = i.getMap(xI);
|
|
11857
|
+
N.set("docId", II(D)), N.set("kit", A.kit), N.set($I, A.schemaVersion), N.set("kdm", RI);
|
|
11858
|
+
const { result: w, staged: G } = Cg.stage(i, A, B);
|
|
11856
11859
|
try {
|
|
11857
11860
|
G.apply(i, A, () => {
|
|
11858
11861
|
});
|
|
11859
|
-
} catch (
|
|
11860
|
-
throw WQ(
|
|
11862
|
+
} catch (h) {
|
|
11863
|
+
throw WQ(h);
|
|
11861
11864
|
}
|
|
11862
|
-
return i.commit({ origin: mQ(C.kind), message: iI(C, A.schemaVersion) }), { replica: new fA(i, D, A, Q), result:
|
|
11865
|
+
return i.commit({ origin: mQ(C.kind), message: iI(C, A.schemaVersion) }), { replica: new fA(i, D, A, Q), result: w };
|
|
11863
11866
|
}
|
|
11864
11867
|
/**
|
|
11865
11868
|
* Opens a snapshot (or a full change export) as a new writable replica of `actor`. Refuses
|
|
@@ -11878,25 +11881,25 @@ class fA {
|
|
|
11878
11881
|
let i;
|
|
11879
11882
|
try {
|
|
11880
11883
|
i = D.import(B);
|
|
11881
|
-
} catch (
|
|
11882
|
-
throw y.encoding(iA(
|
|
11884
|
+
} catch (J) {
|
|
11885
|
+
throw y.encoding(iA(J));
|
|
11883
11886
|
}
|
|
11884
|
-
const
|
|
11885
|
-
const Y =
|
|
11887
|
+
const N = D.getMap(xI), w = (J) => {
|
|
11888
|
+
const Y = N.get(J);
|
|
11886
11889
|
return Y === void 0 || nA(Y) ? null : Y;
|
|
11887
|
-
}, G =
|
|
11890
|
+
}, G = w("kit");
|
|
11888
11891
|
if (G === null) throw y.encoding("not a snapshot: meta.kit is missing (load a snapshot or a full export, not changes only)");
|
|
11889
11892
|
if (G !== A.kit) throw y.schema(`the document belongs to ${AA(G)}, not \`${A.kit}\``);
|
|
11890
|
-
const
|
|
11891
|
-
if (
|
|
11893
|
+
const h = w("kdm");
|
|
11894
|
+
if (h !== RI) throw y.schema(`the document uses kdm ${AA(h)}; this build reads ${RI}`);
|
|
11892
11895
|
const M = wI(D);
|
|
11893
11896
|
if (M === null)
|
|
11894
|
-
throw y.schema(`the document has schema version ${AA(
|
|
11897
|
+
throw y.schema(`the document has schema version ${AA(w($I))}; this kit reads schema versions up to ${A.schemaVersion}`);
|
|
11895
11898
|
if (M > A.schemaVersion) throw y.newerSchema(M, A.schemaVersion);
|
|
11896
|
-
const
|
|
11899
|
+
const F = w("docId");
|
|
11897
11900
|
let K = null;
|
|
11898
11901
|
try {
|
|
11899
|
-
K = typeof
|
|
11902
|
+
K = typeof F == "string" ? fC(F) : null;
|
|
11900
11903
|
} catch {
|
|
11901
11904
|
K = null;
|
|
11902
11905
|
}
|
|
@@ -11955,8 +11958,8 @@ class fA {
|
|
|
11955
11958
|
throw y.invalidValue("$meta", "schemaVersion", `is raised only in a \`system\` transaction, not \`${A.kind}\``);
|
|
11956
11959
|
const D = this.doc.frontiers(), i = /* @__PURE__ */ new Set();
|
|
11957
11960
|
try {
|
|
11958
|
-
B.apply(this.doc, this.schema, (
|
|
11959
|
-
} catch (
|
|
11961
|
+
B.apply(this.doc, this.schema, (w) => i.add(w));
|
|
11962
|
+
} catch (w) {
|
|
11960
11963
|
if (this.doc.commit({ origin: VI }), !DC(this.doc.frontiers(), D)) {
|
|
11961
11964
|
try {
|
|
11962
11965
|
this.doc.revertTo(D);
|
|
@@ -11965,16 +11968,16 @@ class fA {
|
|
|
11965
11968
|
}
|
|
11966
11969
|
this.doc.commit({ origin: VI, message: iI(OI("rollback"), this.schema.schemaVersion) });
|
|
11967
11970
|
}
|
|
11968
|
-
throw WQ(
|
|
11971
|
+
throw WQ(w);
|
|
11969
11972
|
}
|
|
11970
11973
|
this.runs.pending = B.undoTouches;
|
|
11971
|
-
const
|
|
11972
|
-
if (this.runs.current !== null &&
|
|
11973
|
-
const
|
|
11974
|
-
this.runs.groups.set(
|
|
11974
|
+
const N = PI(A.kind);
|
|
11975
|
+
if (this.runs.current !== null && N !== null) {
|
|
11976
|
+
const w = `${N}:${this.runs.current}`;
|
|
11977
|
+
this.runs.groups.set(w, CE(this.runs.groups.get(w) ?? [], B.undoTouches));
|
|
11975
11978
|
}
|
|
11976
11979
|
this.doc.commit({ origin: mQ(A.kind), message: iI(A, this.schema.schemaVersion) });
|
|
11977
|
-
for (const
|
|
11980
|
+
for (const w of i) this.changed.add(w);
|
|
11978
11981
|
return this.noteOwnWrites(B.registerWrites, PI(A.kind)), C;
|
|
11979
11982
|
}
|
|
11980
11983
|
exists(A) {
|
|
@@ -12034,11 +12037,11 @@ class fA {
|
|
|
12034
12037
|
tree(A, I) {
|
|
12035
12038
|
TA(A, I);
|
|
12036
12039
|
const Q = [], C = wA(this.doc, this.schema, A, I, "tree"), B = (D, i) => {
|
|
12037
|
-
for (const
|
|
12038
|
-
const
|
|
12039
|
-
if (
|
|
12040
|
-
const G = IE(
|
|
12041
|
-
Q.push({ node: G, object:
|
|
12040
|
+
for (const N of D ?? []) {
|
|
12041
|
+
const w = Rg(N);
|
|
12042
|
+
if (w === null) continue;
|
|
12043
|
+
const G = IE(N.id);
|
|
12044
|
+
Q.push({ node: G, object: w, parent: i }), B(N.children(), G);
|
|
12042
12045
|
}
|
|
12043
12046
|
};
|
|
12044
12047
|
return C && B(C.roots(), null), Q;
|
|
@@ -12084,27 +12087,27 @@ class fA {
|
|
|
12084
12087
|
if (!wg(I, this.docIdBytes)) throw y.wrongDocument(this.docId, II(I));
|
|
12085
12088
|
const C = this.doc.oplogFrontiers();
|
|
12086
12089
|
let B = null;
|
|
12087
|
-
const { value: D, changed: i, registers:
|
|
12090
|
+
const { value: D, changed: i, registers: N } = EC(this.doc, () => {
|
|
12088
12091
|
try {
|
|
12089
12092
|
return this.doc.import(Q);
|
|
12090
|
-
} catch (
|
|
12091
|
-
return B =
|
|
12093
|
+
} catch (h) {
|
|
12094
|
+
return B = h, null;
|
|
12092
12095
|
}
|
|
12093
12096
|
});
|
|
12094
12097
|
try {
|
|
12095
12098
|
AC(this.doc, this.schema);
|
|
12096
|
-
} catch (
|
|
12097
|
-
throw this.doc.isShallow() ? this.closedBy =
|
|
12099
|
+
} catch (h) {
|
|
12100
|
+
throw this.doc.isShallow() ? this.closedBy = h : this.restore(C), h;
|
|
12098
12101
|
}
|
|
12099
|
-
const
|
|
12100
|
-
if (
|
|
12101
|
-
const
|
|
12102
|
-
throw this.doc.isShallow() ? (this.closedBy =
|
|
12102
|
+
const w = wI(this.doc);
|
|
12103
|
+
if (w !== null && w > this.schema.schemaVersion) {
|
|
12104
|
+
const h = y.newerSchema(w, this.schema.schemaVersion);
|
|
12105
|
+
throw this.doc.isShallow() ? (this.closedBy = h, h) : (this.restore(C), h);
|
|
12103
12106
|
}
|
|
12104
12107
|
if (D === null) throw VQ(B);
|
|
12105
|
-
for (const
|
|
12108
|
+
if (["person", "agent"].some((h) => this.undoManagers[h].canUndo() || this.undoManagers[h].canRedo())) for (const h of N) this.importedRegisters.add(h);
|
|
12106
12109
|
this.notePending(D);
|
|
12107
|
-
for (const
|
|
12110
|
+
for (const h of i) this.changed.add(h);
|
|
12108
12111
|
return this.reopenUndoGroup(), kg(i);
|
|
12109
12112
|
}
|
|
12110
12113
|
/**
|
|
@@ -12194,13 +12197,13 @@ class fA {
|
|
|
12194
12197
|
const Q = fA.load(this.schema, A, this.actor);
|
|
12195
12198
|
if (!Q.version().includes(this.version()) && (Q.importChanges(this.exportChanges(Q.version())), !Q.version().includes(this.version())))
|
|
12196
12199
|
throw y.historyMissing(DN);
|
|
12197
|
-
const C = (
|
|
12198
|
-
for (const
|
|
12199
|
-
(AA(B[
|
|
12200
|
+
const C = (N) => N.objects ?? {}, B = C(this.stateJson()), D = C(Q.stateJson()), i = /* @__PURE__ */ new Set();
|
|
12201
|
+
for (const N of /* @__PURE__ */ new Set([...Object.keys(B), ...Object.keys(D)]))
|
|
12202
|
+
(AA(B[N] ?? null) !== AA(D[N] ?? null) || N in B != N in D) && i.add(N);
|
|
12200
12203
|
$Q(this.undoManagers), this.doc = Q.doc, this.undoManagers = Q.undoManagers, this.importedRegisters.clear(), this.keptRegisters.clear(), this.ownRegisters.clear(), this.localWrites.clear();
|
|
12201
|
-
for (const [
|
|
12204
|
+
for (const [N, w] of Q.pending) this.pending.set(N, Math.max(w, this.pending.get(N) ?? 0));
|
|
12202
12205
|
this.prunePending(), this.reopenUndoGroup();
|
|
12203
|
-
for (const
|
|
12206
|
+
for (const N of i) this.changed.add(N);
|
|
12204
12207
|
return kg(i);
|
|
12205
12208
|
}
|
|
12206
12209
|
/**
|
|
@@ -12358,27 +12361,27 @@ class fA {
|
|
|
12358
12361
|
let i;
|
|
12359
12362
|
try {
|
|
12360
12363
|
i = C.diff(B, D);
|
|
12361
|
-
} catch (
|
|
12362
|
-
throw y.engine(iA(
|
|
12364
|
+
} catch (h) {
|
|
12365
|
+
throw y.engine(iA(h));
|
|
12363
12366
|
}
|
|
12364
|
-
let
|
|
12365
|
-
const { changed:
|
|
12367
|
+
let N = null;
|
|
12368
|
+
const { changed: w, registers: G } = EC(this.doc, () => {
|
|
12366
12369
|
try {
|
|
12367
12370
|
this.doc.applyDiff(i);
|
|
12368
|
-
} catch (
|
|
12369
|
-
|
|
12371
|
+
} catch (h) {
|
|
12372
|
+
N = h;
|
|
12370
12373
|
return;
|
|
12371
12374
|
}
|
|
12372
12375
|
this.doc.commit({ origin: Q === null ? I.kind : "person", message: iI(I, this.schema.schemaVersion) });
|
|
12373
12376
|
});
|
|
12374
|
-
if (
|
|
12375
|
-
throw this.doc.commit({ origin: VI }), DC(this.doc.oplogFrontiers(), B) || (this.doc.revertTo(B), this.doc.commit({ origin: VI, message: iI(OI("rollback"), this.schema.schemaVersion) })), y.engine(iA(
|
|
12376
|
-
for (const
|
|
12377
|
-
const M = this.registerValue(
|
|
12378
|
-
M.container || (this.ownRegisters.set(
|
|
12377
|
+
if (N !== null)
|
|
12378
|
+
throw this.doc.commit({ origin: VI }), DC(this.doc.oplogFrontiers(), B) || (this.doc.revertTo(B), this.doc.commit({ origin: VI, message: iI(OI("rollback"), this.schema.schemaVersion) })), y.engine(iA(N));
|
|
12379
|
+
for (const h of G) {
|
|
12380
|
+
const M = this.registerValue(h);
|
|
12381
|
+
M.container || (this.ownRegisters.set(h, M.value), this.localWrites.set(h, { by: Q === null ? null : "person", value: M.value }));
|
|
12379
12382
|
}
|
|
12380
|
-
for (const
|
|
12381
|
-
return kg(
|
|
12383
|
+
for (const h of w) this.changed.add(h);
|
|
12384
|
+
return kg(w);
|
|
12382
12385
|
}
|
|
12383
12386
|
/** A copy of this document with `changes` imported, checked as `mergeChanges` checks them. */
|
|
12384
12387
|
mergedDoc(A) {
|
|
@@ -12409,19 +12412,19 @@ class fA {
|
|
|
12409
12412
|
if (this.idle(), this.checkOpen(), !(A instanceof QA)) throw new O("invalid-value", "a version must be a `Version`");
|
|
12410
12413
|
if (!this.version().includes(A)) throw y.historyMissing(BN);
|
|
12411
12414
|
if (A.equals(this.version())) return tC([], {}, {}, () => null, !1);
|
|
12412
|
-
const Q = this.forkAt(A, this.actor), B = [...this.forkAt(A, this.actor).importChanges(this.exportChanges(A))].sort(j), D = (M,
|
|
12415
|
+
const Q = this.forkAt(A, this.actor), B = [...this.forkAt(A, this.actor).importChanges(this.exportChanges(A))].sort(j), D = (M, F) => {
|
|
12413
12416
|
try {
|
|
12414
|
-
return Ag(M,
|
|
12417
|
+
return Ag(M, F);
|
|
12415
12418
|
} catch {
|
|
12416
12419
|
return null;
|
|
12417
12420
|
}
|
|
12418
12421
|
}, i = (M) => {
|
|
12419
|
-
const
|
|
12420
|
-
for (const K of B) D(M, K) !== null && (
|
|
12421
|
-
return
|
|
12422
|
-
},
|
|
12423
|
-
let
|
|
12424
|
-
return I.textSpans && (
|
|
12422
|
+
const F = {};
|
|
12423
|
+
for (const K of B) D(M, K) !== null && (F[K] = VB(M, this.schema, K));
|
|
12424
|
+
return F;
|
|
12425
|
+
}, N = (M) => D(this.doc, M) ?? D(Q.doc, M), w = { objects: i(Q.doc) }, G = { objects: i(this.doc) };
|
|
12426
|
+
let h = mC(tC(B, w.objects, G.objects, N, !1), this.schema);
|
|
12427
|
+
return I.textSpans && (h = PC(h, w, G)), uC(h, this.schema, $.ofReplica(Q), $.ofReplica(this));
|
|
12425
12428
|
}
|
|
12426
12429
|
/** The whole document in canonical form; see `stateText`. */
|
|
12427
12430
|
stateJson() {
|
|
@@ -12485,30 +12488,30 @@ class fA {
|
|
|
12485
12488
|
}
|
|
12486
12489
|
history(A, I) {
|
|
12487
12490
|
this.idle(), this.checkOpen(), this.closeUndoGroup();
|
|
12488
|
-
const Q = this.othersRegisters().map(([
|
|
12489
|
-
for (const [
|
|
12491
|
+
const Q = this.othersRegisters().map(([w, G]) => [w, G, void 0]);
|
|
12492
|
+
for (const [w, G, h] of this.otherScopesRegisters(A)) Q.push([w, G, h]);
|
|
12490
12493
|
const { value: C, changed: B, registers: D } = EC(this.doc, () => {
|
|
12491
12494
|
try {
|
|
12492
12495
|
return I();
|
|
12493
|
-
} catch (
|
|
12494
|
-
throw y.engine(iA(
|
|
12496
|
+
} catch (w) {
|
|
12497
|
+
throw y.engine(iA(w));
|
|
12495
12498
|
}
|
|
12496
12499
|
});
|
|
12497
|
-
for (const
|
|
12498
|
-
for (const
|
|
12499
|
-
const G = this.registerValue(
|
|
12500
|
-
G.container || (this.ownRegisters.set(
|
|
12500
|
+
for (const w of B) this.changed.add(w);
|
|
12501
|
+
for (const w of D) {
|
|
12502
|
+
const G = this.registerValue(w);
|
|
12503
|
+
G.container || (this.ownRegisters.set(w, G.value), this.localWrites.set(w, { by: A, value: G.value }));
|
|
12501
12504
|
}
|
|
12502
12505
|
const i = new Set(D);
|
|
12503
|
-
let
|
|
12504
|
-
for (const [
|
|
12505
|
-
if (!i.has(
|
|
12506
|
-
const M = this.registerValue(
|
|
12506
|
+
let N = !1;
|
|
12507
|
+
for (const [w, G, h] of Q) {
|
|
12508
|
+
if (!i.has(w)) continue;
|
|
12509
|
+
const M = this.registerValue(w);
|
|
12507
12510
|
if (M.container || Gg(M.value, G)) continue;
|
|
12508
|
-
const [
|
|
12509
|
-
G === void 0 ? S.delete(K) : S.set(K, G),
|
|
12511
|
+
const [F, K] = PQ(w), S = this.doc.getContainerById(F);
|
|
12512
|
+
G === void 0 ? S.delete(K) : S.set(K, G), h !== void 0 ? this.localWrites.set(w, { by: h, value: G }) : (this.localWrites.delete(w), this.keptRegisters.set(w, G)), N = !0;
|
|
12510
12513
|
}
|
|
12511
|
-
return
|
|
12514
|
+
return N && this.doc.commit({ origin: dC, message: iI(OI("keep-later-changes"), this.schema.schemaVersion) }), C;
|
|
12512
12515
|
}
|
|
12513
12516
|
/**
|
|
12514
12517
|
* The registers whose current value this replica wrote in another scope than `scope` (or in a
|
|
@@ -12554,12 +12557,12 @@ class fA {
|
|
|
12554
12557
|
for (const { id: Q, field: C, key: B, value: D } of A) {
|
|
12555
12558
|
let i;
|
|
12556
12559
|
try {
|
|
12557
|
-
const
|
|
12558
|
-
if (C === null) i =
|
|
12560
|
+
const N = SA(this.doc, Q);
|
|
12561
|
+
if (C === null) i = N.id;
|
|
12559
12562
|
else {
|
|
12560
|
-
const
|
|
12561
|
-
if (!nA(
|
|
12562
|
-
i =
|
|
12563
|
+
const w = N.get(C);
|
|
12564
|
+
if (!nA(w) || w.kind() !== "Map") continue;
|
|
12565
|
+
i = w.id;
|
|
12563
12566
|
}
|
|
12564
12567
|
} catch {
|
|
12565
12568
|
continue;
|
|
@@ -12785,14 +12788,14 @@ function GN(g, A) {
|
|
|
12785
12788
|
get(I, Q) {
|
|
12786
12789
|
const C = Reflect.get(I, Q, I);
|
|
12787
12790
|
return typeof C != "function" ? C : Q === "create" ? (B, D, i) => {
|
|
12788
|
-
const
|
|
12789
|
-
return A.writes.push({ call: "create", type: B, fields: D, id:
|
|
12790
|
-
} : Q === "treeCreate" ? (B, D, i,
|
|
12791
|
-
const
|
|
12792
|
-
return A.writes.push({ call: "treeCreate", id: B, field: D, parent:
|
|
12793
|
-
} : Q === "treeMove" ? (B, D, i,
|
|
12794
|
-
const
|
|
12795
|
-
I.treeMove(B, D, i,
|
|
12791
|
+
const N = I.create(B, D, i);
|
|
12792
|
+
return A.writes.push({ call: "create", type: B, fields: D, id: N }), A.created.add(N), N;
|
|
12793
|
+
} : Q === "treeCreate" ? (B, D, i, N) => {
|
|
12794
|
+
const w = wC(I, B, D, i), G = I.treeCreate(B, D, i, N);
|
|
12795
|
+
return A.writes.push({ call: "treeCreate", id: B, field: D, parent: w, object: N }), A.touched.add(B), G;
|
|
12796
|
+
} : Q === "treeMove" ? (B, D, i, N) => {
|
|
12797
|
+
const w = wC(I, B, D, i), G = wC(I, B, D, N);
|
|
12798
|
+
I.treeMove(B, D, i, N), A.writes.push({ call: "treeMove", id: B, field: D, object: w, parent: G }), A.touched.add(B);
|
|
12796
12799
|
} : typeof Q == "string" && kN.has(Q) ? (...B) => {
|
|
12797
12800
|
const D = C.apply(I, B);
|
|
12798
12801
|
return A.writes.push({ call: "write", name: Q, args: B }), A.touched.add(B[0]), D;
|
|
@@ -12890,15 +12893,15 @@ class QQ {
|
|
|
12890
12893
|
const C = this.catchUp(), B = C.version(), D = C.stateJson();
|
|
12891
12894
|
try {
|
|
12892
12895
|
C.mergeChanges(A, I);
|
|
12893
|
-
} catch (
|
|
12894
|
-
throw new n("invalid-value", null, `the draft does not merge: ${CI(
|
|
12896
|
+
} catch (N) {
|
|
12897
|
+
throw new n("invalid-value", null, `the draft does not merge: ${CI(N)}`);
|
|
12895
12898
|
}
|
|
12896
12899
|
if (C.version().equals(B)) return WI(D, D);
|
|
12897
12900
|
const i = WI(D, C.stateJson());
|
|
12898
12901
|
try {
|
|
12899
12902
|
this.open.importChanges(C.exportChanges(B));
|
|
12900
|
-
} catch (
|
|
12901
|
-
throw this.forget(), new n("invalid-value", null, `${oC}: ${CI(
|
|
12903
|
+
} catch (N) {
|
|
12904
|
+
throw this.forget(), new n("invalid-value", null, `${oC}: ${CI(N)}`);
|
|
12902
12905
|
}
|
|
12903
12906
|
return this.redoSteps = [], this.undoSteps.push({ state: this.state(), step: { origin: I, writes: [], existing: [], stale: !1, merge: A.slice() } }), i;
|
|
12904
12907
|
}
|
|
@@ -12967,14 +12970,14 @@ class QQ {
|
|
|
12967
12970
|
if (!A.length || !this.scratch) return !1;
|
|
12968
12971
|
const B = this.catchUp(), { state: D, step: i } = A[A.length - 1];
|
|
12969
12972
|
if (Q && AB(B.stateText()) !== D) return !1;
|
|
12970
|
-
const
|
|
12973
|
+
const N = B.version();
|
|
12971
12974
|
if (!C(B, i))
|
|
12972
12975
|
return A.length = 0, B.clearRedo(), !1;
|
|
12973
|
-
if (A.pop(), !B.version().equals(
|
|
12976
|
+
if (A.pop(), !B.version().equals(N))
|
|
12974
12977
|
try {
|
|
12975
|
-
this.open.importChanges(B.exportChanges(
|
|
12976
|
-
} catch (
|
|
12977
|
-
throw this.forget(),
|
|
12978
|
+
this.open.importChanges(B.exportChanges(N));
|
|
12979
|
+
} catch (w) {
|
|
12980
|
+
throw this.forget(), w;
|
|
12978
12981
|
}
|
|
12979
12982
|
return i.stale = !1, I.push({ state: this.state(), step: i }), !0;
|
|
12980
12983
|
}
|