interaqt 4.0.3 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/StateMachine.d.ts.map +1 -1
- package/dist/drivers/SQLite.d.ts.map +1 -1
- package/dist/drivers.js +2 -2
- package/dist/drivers.js.map +1 -1
- package/dist/index.js +1102 -1040
- package/dist/index.js.map +1 -1
- package/dist/runtime/ComputationSourceMap.d.ts.map +1 -1
- package/dist/runtime/Controller.d.ts.map +1 -1
- package/dist/runtime/MonoSystem.d.ts.map +1 -1
- package/dist/runtime/Scheduler.d.ts.map +1 -1
- package/dist/storage/erstorage/FilteredEntityManager.d.ts +18 -0
- package/dist/storage/erstorage/FilteredEntityManager.d.ts.map +1 -1
- package/dist/storage/erstorage/RecordQueryAgent.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -70,52 +70,52 @@ function Co(s) {
|
|
|
70
70
|
}
|
|
71
71
|
function Pa(s) {
|
|
72
72
|
const e = /* @__PURE__ */ new Map();
|
|
73
|
-
for (const
|
|
74
|
-
if (!Ot.get(
|
|
75
|
-
throw new Error(`Cannot create instance of unknown class "${
|
|
76
|
-
if (e.has(
|
|
77
|
-
throw new Error(`Duplicate uuid "${
|
|
78
|
-
e.set(
|
|
73
|
+
for (const l of s) {
|
|
74
|
+
if (!Ot.get(l.type))
|
|
75
|
+
throw new Error(`Cannot create instance of unknown class "${l.type}". Make sure the class is registered via registerKlass (see core/init.ts and builtins/init.ts).`);
|
|
76
|
+
if (e.has(l.uuid))
|
|
77
|
+
throw new Error(`Duplicate uuid "${l.uuid}" in serialized instances`);
|
|
78
|
+
e.set(l.uuid, l);
|
|
79
79
|
}
|
|
80
80
|
const t = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Map();
|
|
81
|
-
function a(
|
|
82
|
-
if (typeof
|
|
83
|
-
if (
|
|
84
|
-
return
|
|
85
|
-
if (
|
|
86
|
-
const d =
|
|
87
|
-
if (h) return
|
|
81
|
+
function a(l, u) {
|
|
82
|
+
if (typeof l == "string") {
|
|
83
|
+
if (l.startsWith("func::"))
|
|
84
|
+
return u(new Function("return " + l.substring(6))());
|
|
85
|
+
if (l.startsWith("uuid::")) {
|
|
86
|
+
const d = l.substring(6), h = t.get(d);
|
|
87
|
+
if (h) return u(h);
|
|
88
88
|
if (i.has(d)) {
|
|
89
89
|
const f = r.get(d) || [];
|
|
90
|
-
return f.push(
|
|
90
|
+
return f.push(u), r.set(d, f), u(void 0);
|
|
91
91
|
}
|
|
92
92
|
const m = e.get(d);
|
|
93
93
|
if (!m)
|
|
94
94
|
throw new Error(`Cannot resolve reference "uuid::${d}": no serialized instance with this uuid`);
|
|
95
|
-
return
|
|
95
|
+
return u(c(m));
|
|
96
96
|
}
|
|
97
|
-
return l
|
|
97
|
+
return u(l);
|
|
98
98
|
}
|
|
99
|
-
if (Array.isArray(
|
|
100
|
-
const d = new Array(
|
|
101
|
-
return
|
|
99
|
+
if (Array.isArray(l)) {
|
|
100
|
+
const d = new Array(l.length);
|
|
101
|
+
return l.forEach((h, m) => a(h, (f) => {
|
|
102
102
|
d[m] = f;
|
|
103
|
-
})),
|
|
103
|
+
})), u(d);
|
|
104
104
|
}
|
|
105
|
-
if (nt(
|
|
105
|
+
if (nt(l)) {
|
|
106
106
|
const d = {};
|
|
107
|
-
return Object.entries(
|
|
107
|
+
return Object.entries(l).forEach(([h, m]) => a(m, (f) => {
|
|
108
108
|
d[h] = f;
|
|
109
|
-
})),
|
|
109
|
+
})), u(d);
|
|
110
110
|
}
|
|
111
|
-
return l
|
|
111
|
+
return u(l);
|
|
112
112
|
}
|
|
113
113
|
const n = /* @__PURE__ */ new Set(["computation"]), o = [];
|
|
114
|
-
function c(
|
|
115
|
-
const { type:
|
|
114
|
+
function c(l) {
|
|
115
|
+
const { type: u, options: d = {}, uuid: h, public: m } = l, f = t.get(h);
|
|
116
116
|
if (f) return f;
|
|
117
117
|
i.add(h);
|
|
118
|
-
const p = Ot.get(
|
|
118
|
+
const p = Ot.get(u), y = {};
|
|
119
119
|
let b;
|
|
120
120
|
Object.entries(m || {}).forEach(([w, R]) => {
|
|
121
121
|
if (n.has(w)) {
|
|
@@ -133,9 +133,9 @@ function Pa(s) {
|
|
|
133
133
|
const g = r.get(h);
|
|
134
134
|
return g && (r.delete(h), g.forEach((w) => w(b))), b;
|
|
135
135
|
}
|
|
136
|
-
for (const
|
|
137
|
-
c(
|
|
138
|
-
if (o.forEach((
|
|
136
|
+
for (const l of s)
|
|
137
|
+
c(l);
|
|
138
|
+
if (o.forEach((l) => l()), r.size > 0)
|
|
139
139
|
throw new Error(`Unresolved instance references after deserialization: ${Array.from(r.keys()).join(", ")}`);
|
|
140
140
|
return t;
|
|
141
141
|
}
|
|
@@ -1053,10 +1053,30 @@ class st {
|
|
|
1053
1053
|
};
|
|
1054
1054
|
}
|
|
1055
1055
|
static create(e, t) {
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1056
|
+
if (!e.states || e.states.length === 0)
|
|
1057
|
+
throw new Error("StateMachine requires a non-empty states array.");
|
|
1058
|
+
const i = (o) => o !== null && typeof o == "object" && typeof o.name == "string";
|
|
1059
|
+
if (e.states.every(i) && i(e.initialState) && (e.transfers || []).every((o) => i(o?.current) && i(o?.next))) {
|
|
1060
|
+
const o = /* @__PURE__ */ new Set();
|
|
1061
|
+
for (const l of e.states) {
|
|
1062
|
+
if (o.has(l.name))
|
|
1063
|
+
throw new Error(`StateMachine declares duplicate state name "${l.name}". State names must be unique — transitions are keyed by state name, so duplicates make the machine ambiguous.`);
|
|
1064
|
+
o.add(l.name);
|
|
1065
|
+
}
|
|
1066
|
+
const c = new Set(e.states);
|
|
1067
|
+
if (!c.has(e.initialState))
|
|
1068
|
+
throw new Error(`StateMachine initialState "${e.initialState?.name}" is not in the states array. Declare every state node in states.`);
|
|
1069
|
+
for (const l of e.transfers || []) {
|
|
1070
|
+
if (!c.has(l.current))
|
|
1071
|
+
throw new Error(`StateMachine transfer references current state "${l.current?.name}" which is not in the states array. Declare every state node in states.`);
|
|
1072
|
+
if (!c.has(l.next))
|
|
1073
|
+
throw new Error(`StateMachine transfer references next state "${l.next?.name}" which is not in the states array. Declare every state node in states.`);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
const a = new st(e, t);
|
|
1077
|
+
if (this.instances.find((o) => o.uuid === a.uuid))
|
|
1078
|
+
throw new Error(`duplicate uuid in options ${a.uuid}, StateMachine`);
|
|
1079
|
+
return this.instances.push(a), a;
|
|
1060
1080
|
}
|
|
1061
1081
|
static stringify(e) {
|
|
1062
1082
|
return B(this, e);
|
|
@@ -1234,7 +1254,7 @@ class ct {
|
|
|
1234
1254
|
return this.create(M(t.public), { ...t.options, uuid: t.uuid });
|
|
1235
1255
|
}
|
|
1236
1256
|
}
|
|
1237
|
-
class
|
|
1257
|
+
class lt {
|
|
1238
1258
|
constructor(e, t) {
|
|
1239
1259
|
this._type = "Summation", this._options = t, this.uuid = q(t), this.record = e.record, this.property = e.property, this.direction = e.direction, this.attributeQuery = e.attributeQuery;
|
|
1240
1260
|
}
|
|
@@ -1272,7 +1292,7 @@ class ut {
|
|
|
1272
1292
|
};
|
|
1273
1293
|
}
|
|
1274
1294
|
static create(e, t) {
|
|
1275
|
-
const i = new
|
|
1295
|
+
const i = new lt(e, t);
|
|
1276
1296
|
if (this.instances.find((a) => a.uuid === i.uuid))
|
|
1277
1297
|
throw new Error(`duplicate uuid in options ${i.uuid}, Summation`);
|
|
1278
1298
|
return this.instances.push(i), i;
|
|
@@ -1299,7 +1319,7 @@ class ut {
|
|
|
1299
1319
|
return this.create(M(t.public), { ...t.options, uuid: t.uuid });
|
|
1300
1320
|
}
|
|
1301
1321
|
}
|
|
1302
|
-
class
|
|
1322
|
+
class ut {
|
|
1303
1323
|
constructor(e, t) {
|
|
1304
1324
|
this._type = "Average", this._options = t, this.uuid = q(t), this.record = e.record, this.property = e.property, this.direction = e.direction, this.attributeQuery = e.attributeQuery;
|
|
1305
1325
|
}
|
|
@@ -1337,7 +1357,7 @@ class lt {
|
|
|
1337
1357
|
};
|
|
1338
1358
|
}
|
|
1339
1359
|
static create(e, t) {
|
|
1340
|
-
const i = new
|
|
1360
|
+
const i = new ut(e, t);
|
|
1341
1361
|
if (this.instances.find((a) => a.uuid === i.uuid))
|
|
1342
1362
|
throw new Error(`duplicate uuid in options ${i.uuid}, Average`);
|
|
1343
1363
|
return this.instances.push(i), i;
|
|
@@ -2314,8 +2334,8 @@ const _a = [
|
|
|
2314
2334
|
st,
|
|
2315
2335
|
ot,
|
|
2316
2336
|
ct,
|
|
2317
|
-
ut,
|
|
2318
2337
|
lt,
|
|
2338
|
+
ut,
|
|
2319
2339
|
dt,
|
|
2320
2340
|
ht,
|
|
2321
2341
|
zt,
|
|
@@ -2746,15 +2766,15 @@ class E {
|
|
|
2746
2766
|
});
|
|
2747
2767
|
} else {
|
|
2748
2768
|
const t = e.data.key.split("."), { resolvedPath: i, matchExpression: r } = t.reduce((n, o) => {
|
|
2749
|
-
const c = [...n.resolvedPath, o],
|
|
2769
|
+
const c = [...n.resolvedPath, o], l = this.map.getInfoByPath(c), u = n.resolvedPath.concat(l?.isLinkFiltered() ? l.getBaseAttributeInfo().attributeName : o);
|
|
2750
2770
|
let d = n.matchExpression;
|
|
2751
|
-
if (
|
|
2752
|
-
const h =
|
|
2771
|
+
if (l?.isLinkFiltered()) {
|
|
2772
|
+
const h = l.getLinkInfo(), m = new E(h.getResolvedBaseRecordName(), this.map, h.getResolvedMatchExpression()), f = this.map.getReversePath(u), y = [l.isRecordSource() ? "source" : "target", ...f.slice(2)], b = m.rebase(y.join("."));
|
|
2753
2773
|
d = d ? d.and(b) : b;
|
|
2754
2774
|
}
|
|
2755
2775
|
return {
|
|
2756
2776
|
path: [...n.path, o],
|
|
2757
|
-
resolvedPath:
|
|
2777
|
+
resolvedPath: u,
|
|
2758
2778
|
matchExpression: d
|
|
2759
2779
|
};
|
|
2760
2780
|
}, { path: [this.entityName], resolvedPath: [this.entityName], matchExpression: void 0 });
|
|
@@ -2829,12 +2849,12 @@ class E {
|
|
|
2829
2849
|
);
|
|
2830
2850
|
}
|
|
2831
2851
|
getFinalFieldValue(e, t, i, r, a, n, o) {
|
|
2832
|
-
let c = "",
|
|
2833
|
-
const
|
|
2834
|
-
if (
|
|
2852
|
+
let c = "", l = [];
|
|
2853
|
+
const u = ["=", ">", "<", "<=", ">=", "like", "!="], d = typeof i[0] == "string" ? i[0].toLowerCase() : i[0];
|
|
2854
|
+
if (u.includes(d))
|
|
2835
2855
|
if (e) {
|
|
2836
2856
|
const h = this.getReferenceFieldValue(i[1]);
|
|
2837
|
-
c = `${i[0]} "${h.split(".")[0]}"."${h.split(".")[1]}"`,
|
|
2857
|
+
c = `${i[0]} "${h.split(".")[0]}"."${h.split(".")[1]}"`, l = [];
|
|
2838
2858
|
} else if (i[1] === null) {
|
|
2839
2859
|
if (i[0] === "=")
|
|
2840
2860
|
c = "IS NULL";
|
|
@@ -2842,12 +2862,12 @@ class E {
|
|
|
2842
2862
|
c = "IS NOT NULL";
|
|
2843
2863
|
else
|
|
2844
2864
|
throw new Error(`match operator '${i[0]}' does not support null for key "${t}". Use ['=', null] (IS NULL) or ['!=', null] (IS NOT NULL)`);
|
|
2845
|
-
|
|
2865
|
+
l = [];
|
|
2846
2866
|
} else if (a?.toLowerCase() === "json" && (i[0] === "=" || i[0] === "!=")) {
|
|
2847
2867
|
const h = o?.parseMatchExpression?.(t, i, r, a, e, this.getReferenceFieldValue.bind(this), n);
|
|
2848
|
-
h ? (c = h.fieldValue,
|
|
2868
|
+
h ? (c = h.fieldValue, l = h.fieldParams || []) : (c = `${i[0]} ${n()}`, l = [Tt(i[1])]);
|
|
2849
2869
|
} else
|
|
2850
|
-
c = `${i[0]} ${n()}`,
|
|
2870
|
+
c = `${i[0]} ${n()}`, l = [i[1]];
|
|
2851
2871
|
else if (d === "is null" || d === "is not null") {
|
|
2852
2872
|
if (i[1] !== null)
|
|
2853
2873
|
throw new Error(`match operator '${i[0]}' requires null as its value, got: ${JSON.stringify(i[1])} for key "${t}"`);
|
|
@@ -2860,22 +2880,22 @@ class E {
|
|
|
2860
2880
|
if (T(!e, "reference value cannot use IN to match"), !Array.isArray(i[1]))
|
|
2861
2881
|
throw new Error(`match operator 'in' requires an array value, got: ${JSON.stringify(i[1])} for key "${t}"`);
|
|
2862
2882
|
if (T(!i[1].some((h) => h === null), `'in' value list must have null split out before compilation (key "${t}")`), this.assertParamCountWithinDriverLimit(t, "in", i[1].length, o), i[1].length === 0)
|
|
2863
|
-
c = a?.toLowerCase() === "json" ? "IS NOT NULL AND 1=0" : "IN (NULL) AND 1=0",
|
|
2883
|
+
c = a?.toLowerCase() === "json" ? "IS NOT NULL AND 1=0" : "IN (NULL) AND 1=0", l = [];
|
|
2864
2884
|
else if (a?.toLowerCase() === "json") {
|
|
2865
2885
|
const h = o?.parseMatchExpression?.(t, i, r, a, e, this.getReferenceFieldValue.bind(this), n);
|
|
2866
|
-
h ? (c = h.fieldValue,
|
|
2886
|
+
h ? (c = h.fieldValue, l = h.fieldParams || []) : (c = `IN (${i[1].map((m) => n()).join(",")})`, l = i[1].map((m) => Tt(m)));
|
|
2867
2887
|
} else
|
|
2868
|
-
c = `IN (${i[1].map((h) => n()).join(",")})`,
|
|
2888
|
+
c = `IN (${i[1].map((h) => n()).join(",")})`, l = i[1];
|
|
2869
2889
|
} else if (d === "not in") {
|
|
2870
2890
|
if (T(!e, "reference value cannot use NOT IN to match"), !Array.isArray(i[1]))
|
|
2871
2891
|
throw new Error(`match operator 'not in' requires an array value, got: ${JSON.stringify(i[1])} for key "${t}"`);
|
|
2872
2892
|
if (T(!i[1].some((h) => h === null), `'not in' value list must have null split out before compilation (key "${t}")`), this.assertParamCountWithinDriverLimit(t, "not in", i[1].length, o), i[1].length === 0)
|
|
2873
|
-
c = a?.toLowerCase() === "json" ? "IS NULL OR 1=1" : "NOT IN (NULL) OR 1=1",
|
|
2893
|
+
c = a?.toLowerCase() === "json" ? "IS NULL OR 1=1" : "NOT IN (NULL) OR 1=1", l = [];
|
|
2874
2894
|
else if (a?.toLowerCase() === "json") {
|
|
2875
2895
|
const h = o?.parseMatchExpression?.(t, i, r, a, e, this.getReferenceFieldValue.bind(this), n);
|
|
2876
|
-
h ? (c = h.fieldValue,
|
|
2896
|
+
h ? (c = h.fieldValue, l = h.fieldParams || []) : (c = `NOT IN (${i[1].map((m) => n()).join(",")})`, l = i[1].map((m) => Tt(m)));
|
|
2877
2897
|
} else
|
|
2878
|
-
c = `NOT IN (${i[1].map((h) => n()).join(",")})`,
|
|
2898
|
+
c = `NOT IN (${i[1].map((h) => n()).join(",")})`, l = i[1];
|
|
2879
2899
|
} else if (d === "between") {
|
|
2880
2900
|
if (!Array.isArray(i[1]) || i[1].length !== 2)
|
|
2881
2901
|
throw new Error(`match operator 'between' requires a two-element array value [min, max], got: ${JSON.stringify(i[1])} for key "${t}"`);
|
|
@@ -2885,14 +2905,14 @@ class E {
|
|
|
2885
2905
|
);
|
|
2886
2906
|
if (e) {
|
|
2887
2907
|
const h = this.getReferenceFieldValue(i[1][0]), m = this.getReferenceFieldValue(i[1][1]);
|
|
2888
|
-
c = `BETWEEN "${h.split(".")[0]}"."${h.split(".")[1]}" AND "${m.split(".")[0]}"."${m.split(".")[1]}"`,
|
|
2908
|
+
c = `BETWEEN "${h.split(".")[0]}"."${h.split(".")[1]}" AND "${m.split(".")[0]}"."${m.split(".")[1]}"`, l = [];
|
|
2889
2909
|
} else
|
|
2890
|
-
c = `BETWEEN ${n()} AND ${n()}`,
|
|
2910
|
+
c = `BETWEEN ${n()} AND ${n()}`, l = [i[1][0], i[1][1]];
|
|
2891
2911
|
} else {
|
|
2892
2912
|
let h;
|
|
2893
|
-
o && (h = o.parseMatchExpression?.(t, i, r, a, e, this.getReferenceFieldValue.bind(this), n)), h ? (c = h.fieldValue,
|
|
2913
|
+
o && (h = o.parseMatchExpression?.(t, i, r, a, e, this.getReferenceFieldValue.bind(this), n)), h ? (c = h.fieldValue, l = h.fieldParams || []) : T(h, `unknown value expression ${JSON.stringify(i)}`);
|
|
2894
2914
|
}
|
|
2895
|
-
return [c,
|
|
2915
|
+
return [c, l];
|
|
2896
2916
|
}
|
|
2897
2917
|
// CAUTION SQL 三值逻辑下 `col IN (…, NULL)` 恒不匹配 NULL 行、`col NOT IN (…, NULL)` 对任意行
|
|
2898
2918
|
// 求值 UNKNOWN(静默过滤掉所有行)。含 null 的 in/not in 在编译期拆分成显式的 null 分支:
|
|
@@ -2916,14 +2936,14 @@ class E {
|
|
|
2916
2936
|
// 内层子查询分配,EXIST 之后的值原子编号就会和参数数组错位,导致查询结果静默错误。
|
|
2917
2937
|
buildFieldMatchExpression(e, t, i) {
|
|
2918
2938
|
return this.data ? this.data.map((r) => {
|
|
2919
|
-
const a = r.data.key.split("."), n = this.map.getInfoByPath([this.entityName].concat(a)), o = [this.entityName].concat(a),
|
|
2939
|
+
const a = r.data.key.split("."), n = this.map.getInfoByPath([this.entityName].concat(a)), o = [this.entityName].concat(a), l = this.map.spawnManyToManySymmetricPath(o)?.map((u) => u.slice(1, 1 / 0));
|
|
2920
2940
|
if (n.isValue) {
|
|
2921
2941
|
if (typeof r.data.value?.[0] == "string" && r.data.value[0].toLowerCase() === "contains" && !n.isCollection)
|
|
2922
2942
|
throw new Error(
|
|
2923
2943
|
`match operator 'contains' on key "${r.data.key}" requires a collection property, but "${this.entityName}.${r.data.key}" is not declared with collection: true. To match inside a non-collection JSON object, query a dedicated value property instead.`
|
|
2924
2944
|
);
|
|
2925
|
-
const
|
|
2926
|
-
if (!
|
|
2945
|
+
const u = E.splitNullInListValue(r.data.value), d = (f) => {
|
|
2946
|
+
if (!u) {
|
|
2927
2947
|
const [y, b] = this.getFinalFieldValue(r.data.isReferenceValue, r.data.key, r.data.value, f.join("."), n.fieldType, e, t);
|
|
2928
2948
|
return {
|
|
2929
2949
|
...r.data,
|
|
@@ -2933,7 +2953,7 @@ class E {
|
|
|
2933
2953
|
};
|
|
2934
2954
|
}
|
|
2935
2955
|
let p;
|
|
2936
|
-
for (const y of
|
|
2956
|
+
for (const y of u.parts) {
|
|
2937
2957
|
const [b, g] = this.getFinalFieldValue(r.data.isReferenceValue, r.data.key, y, f.join("."), n.fieldType, e, t), w = {
|
|
2938
2958
|
...r.data,
|
|
2939
2959
|
value: y,
|
|
@@ -2941,31 +2961,31 @@ class E {
|
|
|
2941
2961
|
fieldValue: b,
|
|
2942
2962
|
fieldParams: g
|
|
2943
2963
|
};
|
|
2944
|
-
p = p ?
|
|
2964
|
+
p = p ? u.connector === "or" ? p.or(w) : p.and(w) : k.atom(w);
|
|
2945
2965
|
}
|
|
2946
2966
|
return p;
|
|
2947
2967
|
}, h = (f) => f instanceof k ? f : k.atom(f);
|
|
2948
|
-
if (!
|
|
2968
|
+
if (!l)
|
|
2949
2969
|
return d(this.getFinalFieldName(a));
|
|
2950
2970
|
let m;
|
|
2951
|
-
for (const f of
|
|
2971
|
+
for (const f of l) {
|
|
2952
2972
|
const p = h(d(this.getFinalFieldName(f)));
|
|
2953
2973
|
m = m ? m.or(p) : p;
|
|
2954
2974
|
}
|
|
2955
2975
|
return m;
|
|
2956
2976
|
} else {
|
|
2957
|
-
const
|
|
2958
|
-
if (!
|
|
2959
|
-
return
|
|
2977
|
+
const u = i || ((h) => h);
|
|
2978
|
+
if (!l)
|
|
2979
|
+
return u({
|
|
2960
2980
|
...r.data,
|
|
2961
2981
|
namePath: o,
|
|
2962
2982
|
isFunctionMatch: !0
|
|
2963
2983
|
});
|
|
2964
2984
|
let d;
|
|
2965
|
-
for (const h of
|
|
2985
|
+
for (const h of l) {
|
|
2966
2986
|
const m = [this.entityName].concat(h);
|
|
2967
2987
|
T(m.length === o.length, `symmetric path variant must preserve length, ${m} ${o}`);
|
|
2968
|
-
const f =
|
|
2988
|
+
const f = u({
|
|
2969
2989
|
...r.data,
|
|
2970
2990
|
namePath: m,
|
|
2971
2991
|
isFunctionMatch: !0
|
|
@@ -2985,30 +3005,30 @@ class E {
|
|
|
2985
3005
|
const i = t.recordName, r = this.map.getReverseAttribute(this.entityName, e), a = (o) => {
|
|
2986
3006
|
if (o) {
|
|
2987
3007
|
if (o.isExpression()) {
|
|
2988
|
-
const c = a(o.left),
|
|
2989
|
-
if (!c && !
|
|
2990
|
-
if (!c) return
|
|
2991
|
-
if (!
|
|
2992
|
-
const
|
|
2993
|
-
if (
|
|
2994
|
-
return c.and(
|
|
2995
|
-
if (
|
|
2996
|
-
return c.or(
|
|
2997
|
-
if (
|
|
3008
|
+
const c = a(o.left), l = a(o.right);
|
|
3009
|
+
if (!c && !l) return;
|
|
3010
|
+
if (!c) return l;
|
|
3011
|
+
if (!l) return c;
|
|
3012
|
+
const u = o.raw.operator;
|
|
3013
|
+
if (u === "and")
|
|
3014
|
+
return c.and(l);
|
|
3015
|
+
if (u === "or")
|
|
3016
|
+
return c.or(l);
|
|
3017
|
+
if (u === "not")
|
|
2998
3018
|
return c.not();
|
|
2999
3019
|
} else if (o.isAtom()) {
|
|
3000
|
-
const c = o.data,
|
|
3001
|
-
if (
|
|
3002
|
-
const d =
|
|
3020
|
+
const c = o.data, l = c.key.split(".");
|
|
3021
|
+
if (l[0] === e) {
|
|
3022
|
+
const d = l.slice(1).join(".");
|
|
3003
3023
|
return k.atom({
|
|
3004
3024
|
key: d,
|
|
3005
3025
|
value: c.value,
|
|
3006
3026
|
isReferenceValue: c.isReferenceValue
|
|
3007
3027
|
});
|
|
3008
3028
|
}
|
|
3009
|
-
const
|
|
3029
|
+
const u = this.map.getShrinkedAttribute(i, `${r}.${c.key}`);
|
|
3010
3030
|
return k.atom({
|
|
3011
|
-
key:
|
|
3031
|
+
key: u,
|
|
3012
3032
|
value: c.value,
|
|
3013
3033
|
isReferenceValue: c.isReferenceValue
|
|
3014
3034
|
});
|
|
@@ -3087,10 +3107,10 @@ class Ur {
|
|
|
3087
3107
|
}
|
|
3088
3108
|
}
|
|
3089
3109
|
class G {
|
|
3090
|
-
constructor(e, t, i, r, a, n, o, c,
|
|
3091
|
-
this.recordName = e, this.map = t, this.matchExpression = i, this.attributeQuery = r, this.modifier = a, this.contextRootEntity = n, this.parentRecord = o, this.attributeName = c, this.onlyRelationData =
|
|
3110
|
+
constructor(e, t, i, r, a, n, o, c, l, u = !1, d, h, m, f) {
|
|
3111
|
+
this.recordName = e, this.map = t, this.matchExpression = i, this.attributeQuery = r, this.modifier = a, this.contextRootEntity = n, this.parentRecord = o, this.attributeName = c, this.onlyRelationData = l, this.allowNull = u, this.label = d, this.goto = h, this.exit = m, this.alias = f;
|
|
3092
3112
|
}
|
|
3093
|
-
static create(e, t, i, r, a, n, o, c = !1,
|
|
3113
|
+
static create(e, t, i, r, a, n, o, c = !1, l) {
|
|
3094
3114
|
const d = t.getRecordInfo(e).resolvedBaseRecordName, h = new E(e, t, i.matchExpression, r), m = c ? h : h.and({
|
|
3095
3115
|
key: "id",
|
|
3096
3116
|
value: ["not", null]
|
|
@@ -3109,7 +3129,7 @@ class G {
|
|
|
3109
3129
|
i.label,
|
|
3110
3130
|
i.goto,
|
|
3111
3131
|
i.exit,
|
|
3112
|
-
|
|
3132
|
+
l
|
|
3113
3133
|
);
|
|
3114
3134
|
}
|
|
3115
3135
|
getData() {
|
|
@@ -3203,8 +3223,8 @@ class K {
|
|
|
3203
3223
|
this.recordName = e, this.map = t, this.data = i, this.parentRecord = r, this.attributeName = a, this.shouldQueryParentLinkData = n, this.relatedRecords = [], this.xToManyRecords = [], this.xToOneRecords = [], this.valueAttributes = [];
|
|
3204
3224
|
let o = /* @__PURE__ */ new Set();
|
|
3205
3225
|
i.forEach((c) => {
|
|
3206
|
-
const
|
|
3207
|
-
if (
|
|
3226
|
+
const l = typeof c == "string" ? [c, {}, !1] : c, [u, d, h] = l;
|
|
3227
|
+
if (u === v) {
|
|
3208
3228
|
T(!!(this.parentRecord && this.attributeName), `parent record and attribute name cannot be empty when query link data, you passed ${this.parentRecord} ${this.attributeName}`);
|
|
3209
3229
|
const f = this.map.getInfo(this.parentRecord, this.attributeName);
|
|
3210
3230
|
let p = d;
|
|
@@ -3217,13 +3237,13 @@ class K {
|
|
|
3217
3237
|
}), this.parentLinkRecordQuery = G.create(f.linkName, this.map, p, void 0);
|
|
3218
3238
|
return;
|
|
3219
3239
|
}
|
|
3220
|
-
if (
|
|
3240
|
+
if (u === Ba) {
|
|
3221
3241
|
o = new Set(this.map.getRecordInfo(this.recordName).valueAttributes.map((f) => f.attributeName));
|
|
3222
3242
|
return;
|
|
3223
3243
|
}
|
|
3224
|
-
const m = this.map.getInfo(this.recordName,
|
|
3244
|
+
const m = this.map.getInfo(this.recordName, u);
|
|
3225
3245
|
if (m.isRecord) {
|
|
3226
|
-
let f =
|
|
3246
|
+
let f = u, p = d;
|
|
3227
3247
|
if (m.isLinkFiltered()) {
|
|
3228
3248
|
f = m.getBaseAttributeInfo().attributeName;
|
|
3229
3249
|
const b = d.matchExpression, g = m.getLinkInfo().getBaseLinkInfo(), R = new E(g.name, this.map, m.getMatchExpression()).rebase(m.isRecordSource() ? "target" : "source"), S = b ? R.and(b) : R;
|
|
@@ -3232,17 +3252,17 @@ class K {
|
|
|
3232
3252
|
matchExpression: S.data
|
|
3233
3253
|
};
|
|
3234
3254
|
}
|
|
3235
|
-
const y = G.create(m.recordName, this.map, p, void 0, this.recordName, f, h, !1,
|
|
3255
|
+
const y = G.create(m.recordName, this.map, p, void 0, this.recordName, f, h, !1, u);
|
|
3236
3256
|
this.relatedRecords.push(y), m.isXToMany ? this.xToManyRecords.push(y) : m.isXToOne && this.xToOneRecords.push(y);
|
|
3237
3257
|
} else
|
|
3238
|
-
o.add(
|
|
3258
|
+
o.add(u);
|
|
3239
3259
|
}), this.valueAttributes = Array.from(o), this.fullQueryTree = this.buildFullQueryTree();
|
|
3240
3260
|
}
|
|
3241
3261
|
static mergeAttributeQueryData(e, t) {
|
|
3242
|
-
const i = [...e, ...t], r = new Set(i.filter((c) => typeof c == "string")), a = i.filter((c) => typeof c != "string"), n = (c,
|
|
3262
|
+
const i = [...e, ...t], r = new Set(i.filter((c) => typeof c == "string")), a = i.filter((c) => typeof c != "string"), n = (c, l, u) => {
|
|
3243
3263
|
const d = {}, h = ["matchExpression", "modifier", "label", "goto", "exit"];
|
|
3244
3264
|
for (const m of h) {
|
|
3245
|
-
const f =
|
|
3265
|
+
const f = l[m], p = u[m];
|
|
3246
3266
|
if (!(f === void 0 && p === void 0)) {
|
|
3247
3267
|
if (f !== void 0 && p !== void 0 && JSON.stringify(f) !== JSON.stringify(p))
|
|
3248
3268
|
throw new Error(
|
|
@@ -3252,71 +3272,71 @@ class K {
|
|
|
3252
3272
|
}
|
|
3253
3273
|
}
|
|
3254
3274
|
return d;
|
|
3255
|
-
}, o = a.reduce((c,
|
|
3256
|
-
const [
|
|
3257
|
-
return m ? c[
|
|
3275
|
+
}, o = a.reduce((c, l) => {
|
|
3276
|
+
const [u, d, h] = l, m = c[u];
|
|
3277
|
+
return m ? c[u] = {
|
|
3258
3278
|
subQueryData: {
|
|
3259
|
-
...n(
|
|
3279
|
+
...n(u, m.subQueryData, d),
|
|
3260
3280
|
attributeQuery: K.mergeAttributeQueryData(m.subQueryData.attributeQuery || [], d.attributeQuery || [])
|
|
3261
3281
|
},
|
|
3262
3282
|
// onlyRelationData 表示"只取关系数据不取实体数据":任一方需要实体数据则取全量(false 更宽)。
|
|
3263
3283
|
onlyRelationData: m.onlyRelationData && !!h
|
|
3264
|
-
} : c[
|
|
3284
|
+
} : c[u] = { subQueryData: d, onlyRelationData: !!h }, c;
|
|
3265
3285
|
}, {});
|
|
3266
3286
|
return [
|
|
3267
3287
|
...r,
|
|
3268
3288
|
...Object.entries(o).map(
|
|
3269
|
-
([c, { subQueryData:
|
|
3289
|
+
([c, { subQueryData: l, onlyRelationData: u }]) => u ? [c, l, !0] : [c, l]
|
|
3270
3290
|
)
|
|
3271
3291
|
];
|
|
3272
3292
|
}
|
|
3273
3293
|
static getAttributeQueryDataForRecord(e, t, i, r, a, n) {
|
|
3274
3294
|
const o = t.getRecordInfo(e), c = t.getRecordInfo(o.resolvedBaseRecordName);
|
|
3275
|
-
let
|
|
3276
|
-
return i && c.sameTableReliance.forEach((
|
|
3277
|
-
const d = K.getAttributeQueryDataForRecord(
|
|
3278
|
-
|
|
3295
|
+
let l = c.valueAttributes.map((u) => u.attributeName);
|
|
3296
|
+
return i && c.sameTableReliance.forEach((u) => {
|
|
3297
|
+
const d = K.getAttributeQueryDataForRecord(u.recordName, t, !0, r), h = [
|
|
3298
|
+
u.attributeName,
|
|
3279
3299
|
{
|
|
3280
3300
|
attributeQuery: [...d]
|
|
3281
3301
|
}
|
|
3282
3302
|
];
|
|
3283
3303
|
if (!c.isRelation) {
|
|
3284
|
-
const m = K.getAttributeQueryDataForRecord(
|
|
3304
|
+
const m = K.getAttributeQueryDataForRecord(u.linkName, t, !0, r);
|
|
3285
3305
|
h[1].attributeQuery.push([v, { attributeQuery: m }]);
|
|
3286
3306
|
}
|
|
3287
|
-
|
|
3288
|
-
}), n && c.notRelianceCombined.forEach((
|
|
3289
|
-
const d = K.getAttributeQueryDataForRecord(
|
|
3290
|
-
|
|
3307
|
+
l = K.mergeAttributeQueryData(l, [h]);
|
|
3308
|
+
}), n && c.notRelianceCombined.forEach((u) => {
|
|
3309
|
+
const d = K.getAttributeQueryDataForRecord(u.recordName, t, !0, r), h = [
|
|
3310
|
+
u.attributeName,
|
|
3291
3311
|
{
|
|
3292
3312
|
attributeQuery: [...d]
|
|
3293
3313
|
}
|
|
3294
3314
|
];
|
|
3295
3315
|
if (!c.isRelation) {
|
|
3296
|
-
const m = K.getAttributeQueryDataForRecord(
|
|
3316
|
+
const m = K.getAttributeQueryDataForRecord(u.linkName, t, !0, r);
|
|
3297
3317
|
h[1].attributeQuery.push([v, { attributeQuery: m }]);
|
|
3298
3318
|
}
|
|
3299
|
-
|
|
3300
|
-
}), r && c.mergedRecordAttributes.forEach((
|
|
3301
|
-
const d = K.getAttributeQueryDataForRecord(
|
|
3302
|
-
|
|
3319
|
+
l = K.mergeAttributeQueryData(l, [h]);
|
|
3320
|
+
}), r && c.mergedRecordAttributes.forEach((u) => {
|
|
3321
|
+
const d = K.getAttributeQueryDataForRecord(u.linkName, t, i, !0);
|
|
3322
|
+
l = K.mergeAttributeQueryData(l, [
|
|
3303
3323
|
[
|
|
3304
|
-
|
|
3324
|
+
u.attributeName,
|
|
3305
3325
|
{
|
|
3306
3326
|
attributeQuery: ["id", [v, { attributeQuery: d }]]
|
|
3307
3327
|
}
|
|
3308
3328
|
]
|
|
3309
3329
|
]);
|
|
3310
|
-
}), a && c.managedRecordAttributes.forEach((
|
|
3311
|
-
|
|
3330
|
+
}), a && c.managedRecordAttributes.forEach((u) => {
|
|
3331
|
+
l = K.mergeAttributeQueryData(l, [
|
|
3312
3332
|
[
|
|
3313
|
-
|
|
3333
|
+
u.attributeName,
|
|
3314
3334
|
{
|
|
3315
3335
|
attributeQuery: ["id"]
|
|
3316
3336
|
}
|
|
3317
3337
|
]
|
|
3318
3338
|
]);
|
|
3319
|
-
}),
|
|
3339
|
+
}), l;
|
|
3320
3340
|
}
|
|
3321
3341
|
getValueAndXToOneRecordFields(e = [this.recordName], t = [this.recordName]) {
|
|
3322
3342
|
const r = (this.valueAttributes.includes("id") ? this.valueAttributes : ["id"].concat(this.valueAttributes)).map((a) => ({
|
|
@@ -3329,15 +3349,15 @@ class K {
|
|
|
3329
3349
|
r.push(
|
|
3330
3350
|
...a.attributeQuery.getValueAndXToOneRecordFields(n, o)
|
|
3331
3351
|
);
|
|
3332
|
-
const c = n.concat(v),
|
|
3352
|
+
const c = n.concat(v), l = o.concat(v);
|
|
3333
3353
|
a.attributeQuery.parentLinkRecordQuery && r.push(
|
|
3334
|
-
...a.attributeQuery.parentLinkRecordQuery.attributeQuery.getValueAndXToOneRecordFields(c,
|
|
3354
|
+
...a.attributeQuery.parentLinkRecordQuery.attributeQuery.getValueAndXToOneRecordFields(c, l)
|
|
3335
3355
|
);
|
|
3336
3356
|
}), this.shouldQueryParentLinkData && this.parentLinkRecordQuery) {
|
|
3337
|
-
const a = this.map.getInfo(this.parentRecord, this.attributeName).getReverseInfo()?.attributeName, n = e.concat(a, v), o = t.concat(a, v), c = this.map.spawnManyToManySymmetricPath(n),
|
|
3338
|
-
c ? c.forEach((
|
|
3357
|
+
const a = this.map.getInfo(this.parentRecord, this.attributeName).getReverseInfo()?.attributeName, n = e.concat(a, v), o = t.concat(a, v), c = this.map.spawnManyToManySymmetricPath(n), l = this.map.spawnManyToManySymmetricPath(o);
|
|
3358
|
+
c ? c.forEach((u, d) => {
|
|
3339
3359
|
r.push(
|
|
3340
|
-
...this.parentLinkRecordQuery.attributeQuery.getValueAndXToOneRecordFields(
|
|
3360
|
+
...this.parentLinkRecordQuery.attributeQuery.getValueAndXToOneRecordFields(u, l[d])
|
|
3341
3361
|
);
|
|
3342
3362
|
}) : r.push(
|
|
3343
3363
|
...this.parentLinkRecordQuery.attributeQuery.getValueAndXToOneRecordFields(n, o)
|
|
@@ -3377,25 +3397,25 @@ function Ua(s) {
|
|
|
3377
3397
|
function Qa(s) {
|
|
3378
3398
|
return s !== null && typeof s == "object" && "source" in s && "target" in s;
|
|
3379
3399
|
}
|
|
3380
|
-
class
|
|
3400
|
+
class ee {
|
|
3381
3401
|
constructor(e, t, i, r) {
|
|
3382
3402
|
this.map = e, this.originalRecordName = t, this.rawData = i, this.info = r, this.mergedLinkTargetNewRecords = [], this.mergedLinkTargetRecordIdRefs = [], this.mergedLinkTargetNullRecords = [], this.combinedNewRecords = [], this.combinedRecordIdRefs = [], this.combinedNullRecords = [], this.differentTableMergedLinkNewRecords = [], this.differentTableMergedLinkRecordIdRefs = [], this.differentTableMergedLinkNullRecords = [], this.isolatedNewRecords = [], this.isolatedRecordIdRefs = [], this.isolatedNullRecords = [], this.entityIdAttributes = [], this.relatedEntitiesData = [], this.valueAttributes = [], this.sameRowEntityIdRefs = [], this.defaultValues = {};
|
|
3383
3403
|
const a = this.map.getRecordInfo(t);
|
|
3384
3404
|
this.recordName = a.resolvedBaseRecordName;
|
|
3385
3405
|
const [n, o, c] = this.map.groupAttributes(this.recordName, i ? Object.keys(i) : []);
|
|
3386
3406
|
this.relatedEntitiesData = Ua(o.map(
|
|
3387
|
-
(
|
|
3407
|
+
(u) => Array.isArray(i[u.attributeName]) ? ee.dedupeRefItems(i[u.attributeName], u.attributeName, this.recordName).map((d) => new ee(this.map, u.recordName, d, u)) : new ee(this.map, u.recordName, i[u.attributeName], u)
|
|
3388
3408
|
)), this.valueAttributes = n, this.entityIdAttributes = c;
|
|
3389
|
-
const
|
|
3390
|
-
this.defaultValues =
|
|
3409
|
+
const l = this.map.getRecordInfo(this.recordName);
|
|
3410
|
+
this.defaultValues = l.valueAttributes.reduce((u, d) => {
|
|
3391
3411
|
const h = d.data;
|
|
3392
|
-
return !this.rawData?.hasOwnProperty(d.attributeName) && h.defaultValue && typeof h.defaultValue == "function" && (
|
|
3393
|
-
}, {}), this.relatedEntitiesData.forEach((
|
|
3394
|
-
|
|
3395
|
-
}), this.rawData?.[v] && (this.linkRecordData = new
|
|
3412
|
+
return !this.rawData?.hasOwnProperty(d.attributeName) && h.defaultValue && typeof h.defaultValue == "function" && (u[d.attributeName] = h.defaultValue(i, this.originalRecordName)), u;
|
|
3413
|
+
}, {}), this.relatedEntitiesData.forEach((u) => {
|
|
3414
|
+
u.info.isMergedWithParent() ? u.isNull() ? this.combinedNullRecords.push(u) : u.isRef() ? this.combinedRecordIdRefs.push(u) : this.combinedNewRecords.push(u) : u.info.isLinkMergedWithParent() ? u.isNull() ? this.mergedLinkTargetNullRecords.push(u) : u.isRef() ? this.mergedLinkTargetRecordIdRefs.push(u) : this.mergedLinkTargetNewRecords.push(u) : u.info.isLinkMergedWithAttribute() ? u.isNull() ? this.differentTableMergedLinkNullRecords.push(u) : u.isRef() ? this.differentTableMergedLinkRecordIdRefs.push(u) : this.differentTableMergedLinkNewRecords.push(u) : u.isNull() ? this.isolatedNullRecords.push(u) : u.isRef() ? this.isolatedRecordIdRefs.push(u) : this.isolatedNewRecords.push(u);
|
|
3415
|
+
}), this.rawData?.[v] && (this.linkRecordData = new ee(this.map, r?.linkName, this.rawData[v]));
|
|
3396
3416
|
}
|
|
3397
3417
|
merge(e) {
|
|
3398
|
-
const t = new
|
|
3418
|
+
const t = new ee(this.map, this.originalRecordName, { ...this.rawData, ...e }, this.info);
|
|
3399
3419
|
return this.recordName !== this.originalRecordName && (t.recordName = this.recordName), t;
|
|
3400
3420
|
}
|
|
3401
3421
|
getRef() {
|
|
@@ -3417,8 +3437,8 @@ class ie {
|
|
|
3417
3437
|
r.set(String(o), n), a.push(n);
|
|
3418
3438
|
continue;
|
|
3419
3439
|
}
|
|
3420
|
-
const
|
|
3421
|
-
if (
|
|
3440
|
+
const l = JSON.stringify(c[v] ?? null), u = JSON.stringify(n[v] ?? null);
|
|
3441
|
+
if (l !== u)
|
|
3422
3442
|
throw new Error(
|
|
3423
3443
|
`duplicate reference to id "${o}" in "${i}.${t}" carries conflicting '&' link data. A target may appear at most once, or its duplicates must declare identical link attributes.`
|
|
3424
3444
|
);
|
|
@@ -3436,64 +3456,64 @@ class ie {
|
|
|
3436
3456
|
}
|
|
3437
3457
|
getSameRowFieldAndValue(e = {}) {
|
|
3438
3458
|
const t = { ...e, ...this.rawData }, i = [], r = /* @__PURE__ */ new Set(), a = this.map.getRecordInfo(this.recordName), n = new Set(
|
|
3439
|
-
Object.keys(a.data.attributes).filter((
|
|
3440
|
-
), o = (
|
|
3459
|
+
Object.keys(a.data.attributes).filter((l) => a.data.attributes[l].isRecord)
|
|
3460
|
+
), o = (l, u) => new Proxy(l, {
|
|
3441
3461
|
get: (d, h) => {
|
|
3442
3462
|
if (typeof h == "string" && n.has(h))
|
|
3443
3463
|
throw new Error(
|
|
3444
|
-
`computed property "${
|
|
3464
|
+
`computed property "${u}" on "${this.recordName}" accessed relation property "${h}". "computed" only receives the record's own same-row value fields; relation data is not loaded here and would be silently stale. Use a reactive computation (Count/Summation/Custom/StateMachine, etc.) for derivations that depend on related records.`
|
|
3445
3465
|
);
|
|
3446
3466
|
return d[h];
|
|
3447
3467
|
}
|
|
3448
3468
|
}), c = /* @__PURE__ */ new Set();
|
|
3449
|
-
return this.valueAttributes.forEach((
|
|
3450
|
-
c.add(
|
|
3451
|
-
let
|
|
3452
|
-
const d =
|
|
3453
|
-
|
|
3454
|
-
name:
|
|
3455
|
-
field:
|
|
3456
|
-
value:
|
|
3457
|
-
fieldType:
|
|
3458
|
-
}),
|
|
3459
|
-
}), a.valueAttributes.forEach((
|
|
3460
|
-
const
|
|
3461
|
-
if (!c.has(
|
|
3462
|
-
const d = this.defaultValues[
|
|
3469
|
+
return this.valueAttributes.forEach((l) => {
|
|
3470
|
+
c.add(l.attributeName);
|
|
3471
|
+
let u = l.isComputed ? l.computed(o(t, l.attributeName)) : this.rawData[l.attributeName];
|
|
3472
|
+
const d = l.data;
|
|
3473
|
+
u === void 0 && d.defaultValue && typeof d.defaultValue == "function" && (u = d.defaultValue(this.rawData, this.originalRecordName)), i.push({
|
|
3474
|
+
name: l.attributeName,
|
|
3475
|
+
field: l.field,
|
|
3476
|
+
value: u,
|
|
3477
|
+
fieldType: l.fieldType
|
|
3478
|
+
}), l.isComputed && r.add(l.attributeName);
|
|
3479
|
+
}), a.valueAttributes.forEach((l) => {
|
|
3480
|
+
const u = l.data;
|
|
3481
|
+
if (!c.has(l.attributeName) && u.defaultValue && typeof u.defaultValue == "function" && this.rawData[l.attributeName] === void 0 && e[l.attributeName] === void 0) {
|
|
3482
|
+
const d = this.defaultValues[l.attributeName];
|
|
3463
3483
|
i.push({
|
|
3464
|
-
name:
|
|
3465
|
-
field:
|
|
3484
|
+
name: l.attributeName,
|
|
3485
|
+
field: l.field,
|
|
3466
3486
|
value: d,
|
|
3467
|
-
fieldType:
|
|
3487
|
+
fieldType: l.fieldType
|
|
3468
3488
|
});
|
|
3469
3489
|
}
|
|
3470
|
-
}), a.valueAttributes.forEach((
|
|
3471
|
-
if (
|
|
3472
|
-
const
|
|
3473
|
-
|
|
3474
|
-
name:
|
|
3475
|
-
field:
|
|
3476
|
-
value:
|
|
3477
|
-
fieldType:
|
|
3490
|
+
}), a.valueAttributes.forEach((l) => {
|
|
3491
|
+
if (l.isComputed && !r.has(l.attributeName)) {
|
|
3492
|
+
const u = l.computed(o(t, l.attributeName));
|
|
3493
|
+
u !== e[l.attributeName] && i.push({
|
|
3494
|
+
name: l.attributeName,
|
|
3495
|
+
field: l.field,
|
|
3496
|
+
value: u,
|
|
3497
|
+
fieldType: l.fieldType
|
|
3478
3498
|
});
|
|
3479
3499
|
}
|
|
3480
|
-
}), this.entityIdAttributes.forEach((
|
|
3500
|
+
}), this.entityIdAttributes.forEach((l) => {
|
|
3481
3501
|
i.push({
|
|
3482
|
-
name:
|
|
3483
|
-
field:
|
|
3484
|
-
value: this.rawData[
|
|
3502
|
+
name: l.attributeName,
|
|
3503
|
+
field: l.linkField,
|
|
3504
|
+
value: this.rawData[l.attributeName].id
|
|
3485
3505
|
});
|
|
3486
|
-
}), this.mergedLinkTargetRecordIdRefs.forEach((
|
|
3506
|
+
}), this.mergedLinkTargetRecordIdRefs.forEach((l) => {
|
|
3487
3507
|
if (i.push({
|
|
3488
|
-
name:
|
|
3489
|
-
field:
|
|
3490
|
-
value:
|
|
3491
|
-
}),
|
|
3492
|
-
const
|
|
3493
|
-
i.push(...
|
|
3508
|
+
name: l.info?.attributeName,
|
|
3509
|
+
field: l.info?.linkField,
|
|
3510
|
+
value: l.getRef().id
|
|
3511
|
+
}), l.linkRecordData) {
|
|
3512
|
+
const u = l.info?.attributeName, d = e[u]?.id === l.getRef().id ? e[u]?.[v] : void 0;
|
|
3513
|
+
i.push(...l.linkRecordData.getSameRowFieldAndValue(d).filter((h) => h.field !== l.info?.linkField));
|
|
3494
3514
|
}
|
|
3495
|
-
}), this.info && this.linkRecordData && this.info.isLinkMergedWithAttribute() && i.push(...this.linkRecordData.getSameRowFieldAndValue()), this.combinedNewRecords.concat(this.combinedRecordIdRefs).forEach((
|
|
3496
|
-
i.push(...
|
|
3515
|
+
}), this.info && this.linkRecordData && this.info.isLinkMergedWithAttribute() && i.push(...this.linkRecordData.getSameRowFieldAndValue()), this.combinedNewRecords.concat(this.combinedRecordIdRefs).forEach((l) => {
|
|
3516
|
+
i.push(...l.getSameRowFieldAndValue(e[l.info?.attributeName])), l.linkRecordData && i.push(...l.linkRecordData.getSameRowFieldAndValue(e[l.info?.attributeName]?.[v]));
|
|
3497
3517
|
}), i;
|
|
3498
3518
|
}
|
|
3499
3519
|
}
|
|
@@ -3537,10 +3557,10 @@ class ja {
|
|
|
3537
3557
|
);
|
|
3538
3558
|
const a = await this.createRecordDependency(e, i);
|
|
3539
3559
|
await this.unlinkOldOwnersOfExclusiveTargets(a, i);
|
|
3540
|
-
const n = await this.collectCreationLinkChecks(a, i), o = await this.insertSameRowData(a, t, i), c = await this.handleCreationReliance(a.merge(o), i),
|
|
3560
|
+
const n = await this.collectCreationLinkChecks(a, i), o = await this.insertSameRowData(a, t, i), c = await this.handleCreationReliance(a.merge(o), i), l = Object.assign({}, e.getData(), o, c);
|
|
3541
3561
|
await this.filteredEntityManager.settleMembershipChecks(n, i);
|
|
3542
|
-
const
|
|
3543
|
-
return delete
|
|
3562
|
+
const u = Object.assign({}, a.defaultValues, l);
|
|
3563
|
+
return delete u[Pe], await this.filteredEntityManager.handleRecordCreation(e.recordName, o.id, u, i), Object.assign(o, c);
|
|
3544
3564
|
}
|
|
3545
3565
|
/**
|
|
3546
3566
|
* 采集本次创建涉及的"既有记录端"成员资格快照:
|
|
@@ -3596,9 +3616,9 @@ class ja {
|
|
|
3596
3616
|
* keys = 本次实际写入的属性名(含被联动重算的 computed 属性),record 带 id,oldRecord 为变更前快照。
|
|
3597
3617
|
*/
|
|
3598
3618
|
buildSameRowUpdateEvent(e, t, i) {
|
|
3599
|
-
const r = e.getSameRowFieldAndValue(i), a = this.map.getRecordInfo(t), n = new Set(a.valueAttributes.map((
|
|
3600
|
-
return r.forEach((
|
|
3601
|
-
|
|
3619
|
+
const r = e.getSameRowFieldAndValue(i), a = this.map.getRecordInfo(t), n = new Set(a.valueAttributes.map((l) => l.attributeName)), o = { ...e.getData() }, c = [];
|
|
3620
|
+
return r.forEach((l) => {
|
|
3621
|
+
l.name !== "id" && n.has(l.name) && (o[l.name] = l.value, c.push(l.name));
|
|
3602
3622
|
}), c.length ? {
|
|
3603
3623
|
type: "update",
|
|
3604
3624
|
recordName: t,
|
|
@@ -3626,60 +3646,60 @@ class ja {
|
|
|
3626
3646
|
});
|
|
3627
3647
|
else {
|
|
3628
3648
|
if (e.valueAttributes.length) {
|
|
3629
|
-
const
|
|
3630
|
-
|
|
3649
|
+
const l = this.buildSameRowUpdateEvent(e, e.recordName, r);
|
|
3650
|
+
l && i?.push(l);
|
|
3631
3651
|
}
|
|
3632
|
-
for (const
|
|
3633
|
-
const
|
|
3634
|
-
if (!(!d?.id || a[
|
|
3635
|
-
if (
|
|
3636
|
-
const h = this.buildSameRowUpdateEvent(
|
|
3637
|
-
h && (i?.push(h), await this.filteredEntityManager.enqueuePostWriteUpdateCheck(i,
|
|
3652
|
+
for (const l of e.mergedLinkTargetRecordIdRefs.concat(e.combinedRecordIdRefs)) {
|
|
3653
|
+
const u = l.info.attributeName, d = r?.[u];
|
|
3654
|
+
if (!(!d?.id || a[u]?.id !== d.id)) {
|
|
3655
|
+
if (l.info.isMergedWithParent() && l.valueAttributes.length) {
|
|
3656
|
+
const h = this.buildSameRowUpdateEvent(l, l.recordName, d);
|
|
3657
|
+
h && (i?.push(h), await this.filteredEntityManager.enqueuePostWriteUpdateCheck(i, l.recordName, d.id, h.keys));
|
|
3638
3658
|
}
|
|
3639
|
-
if (
|
|
3640
|
-
const h = this.buildSameRowUpdateEvent(
|
|
3641
|
-
h && (i?.push(h), await this.filteredEntityManager.enqueuePostWriteUpdateCheck(i,
|
|
3659
|
+
if (l.linkRecordData?.valueAttributes.length && d[v]?.id) {
|
|
3660
|
+
const h = this.buildSameRowUpdateEvent(l.linkRecordData, l.info.linkName, d[v]);
|
|
3661
|
+
h && (i?.push(h), await this.filteredEntityManager.enqueuePostWriteUpdateCheck(i, l.info.linkName, d[v].id, h.keys));
|
|
3642
3662
|
}
|
|
3643
3663
|
}
|
|
3644
3664
|
}
|
|
3645
3665
|
}
|
|
3646
|
-
for (let
|
|
3647
|
-
a[
|
|
3648
|
-
...a[
|
|
3649
|
-
id: await this.database.getAutoId(
|
|
3666
|
+
for (let l of e.combinedNewRecords)
|
|
3667
|
+
a[l.info.attributeName] = {
|
|
3668
|
+
...a[l.info.attributeName],
|
|
3669
|
+
id: await this.database.getAutoId(l.info.recordName)
|
|
3650
3670
|
}, i?.push({
|
|
3651
3671
|
type: "create",
|
|
3652
|
-
recordName:
|
|
3653
|
-
record: a[
|
|
3672
|
+
recordName: l.recordName,
|
|
3673
|
+
record: a[l.info.attributeName]
|
|
3654
3674
|
}), this.filteredEntityManager.enqueuePostWriteCreationCheck(
|
|
3655
3675
|
i,
|
|
3656
|
-
|
|
3657
|
-
a[
|
|
3658
|
-
{ ...
|
|
3676
|
+
l.recordName,
|
|
3677
|
+
a[l.info.attributeName].id,
|
|
3678
|
+
{ ...l.defaultValues, ...a[l.info.attributeName] }
|
|
3659
3679
|
);
|
|
3660
|
-
for (let
|
|
3661
|
-
if (a[
|
|
3662
|
-
a[
|
|
3663
|
-
...a[
|
|
3664
|
-
id: await this.database.getAutoId(
|
|
3680
|
+
for (let l of e.mergedLinkTargetNewRecords.concat(e.mergedLinkTargetRecordIdRefs, e.combinedNewRecords))
|
|
3681
|
+
if (a[l.info.attributeName].id !== r?.[l.info.attributeName]?.id) {
|
|
3682
|
+
a[l.info.attributeName][v] = {
|
|
3683
|
+
...a[l.info.attributeName][v] || {},
|
|
3684
|
+
id: await this.database.getAutoId(l.info.linkName)
|
|
3665
3685
|
};
|
|
3666
|
-
const
|
|
3667
|
-
l
|
|
3686
|
+
const u = { ...a[l.info.attributeName][v] };
|
|
3687
|
+
u[l.info.isRecordSource() ? "target" : "source"] = l.getData(), u[l.info.isRecordSource() ? "source" : "target"] = { ...a }, delete u.target[v], delete u.source[v], i?.push({
|
|
3668
3688
|
type: "create",
|
|
3669
|
-
recordName:
|
|
3670
|
-
record:
|
|
3689
|
+
recordName: l.info.linkName,
|
|
3690
|
+
record: u
|
|
3671
3691
|
}), this.filteredEntityManager.enqueuePostWriteCreationCheck(
|
|
3672
3692
|
i,
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
{ ...
|
|
3693
|
+
l.info.linkName,
|
|
3694
|
+
u.id,
|
|
3695
|
+
{ ...l.linkRecordData?.defaultValues || {}, ...u }
|
|
3676
3696
|
);
|
|
3677
3697
|
}
|
|
3678
3698
|
const n = e.merge(a), o = /* @__PURE__ */ new Set();
|
|
3679
3699
|
if (t && r)
|
|
3680
|
-
for (const
|
|
3681
|
-
const
|
|
3682
|
-
r[
|
|
3700
|
+
for (const l of e.combinedRecordIdRefs) {
|
|
3701
|
+
const u = l.info.attributeName;
|
|
3702
|
+
r[u]?.id !== void 0 && r[u].id === l.getRef().id && o.add(u);
|
|
3683
3703
|
}
|
|
3684
3704
|
const c = await this.agent.flashOutCombinedRecordsAndMergedLinks(
|
|
3685
3705
|
e,
|
|
@@ -3718,15 +3738,15 @@ class ja {
|
|
|
3718
3738
|
const n = a.info.getReverseInfo(), o = E.atom({
|
|
3719
3739
|
key: "id",
|
|
3720
3740
|
value: ["=", a.getRef().id]
|
|
3721
|
-
}), c = a.getData()[v],
|
|
3741
|
+
}), c = a.getData()[v], l = {
|
|
3722
3742
|
[n.attributeName]: c === void 0 ? i : { ...i, [v]: c }
|
|
3723
|
-
}, [
|
|
3743
|
+
}, [u] = await this.agent.updateRecord(n.parentEntityName, o, new ee(this.map, n.parentEntityName, l), t);
|
|
3724
3744
|
a.info.isXToMany ? (r[a.info.attributeName] || (r[a.info.attributeName] = []), r[a.info.attributeName].push({
|
|
3725
|
-
...
|
|
3726
|
-
[v]:
|
|
3745
|
+
...u,
|
|
3746
|
+
[v]: u[n.attributeName][v]
|
|
3727
3747
|
})) : r[a.info.attributeName] = {
|
|
3728
|
-
...
|
|
3729
|
-
[v]:
|
|
3748
|
+
...u,
|
|
3749
|
+
[v]: u[n.attributeName][v]
|
|
3730
3750
|
};
|
|
3731
3751
|
}
|
|
3732
3752
|
for (let a of e.isolatedNewRecords) {
|
|
@@ -3735,36 +3755,36 @@ class ja {
|
|
|
3735
3755
|
source: a.info.isRecordSource() ? i : n,
|
|
3736
3756
|
target: a.info.isRecordSource() ? n : i
|
|
3737
3757
|
});
|
|
3738
|
-
const c = new
|
|
3758
|
+
const c = new ee(this.map, a.info.linkName, o), l = await this.createRecord(c, `create isolated related link record ${e.recordName}.${a.info?.attributeName}`, t);
|
|
3739
3759
|
a.info.isXToMany ? (r[a.info.attributeName] || (r[a.info.attributeName] = []), r[a.info.attributeName].push({
|
|
3740
3760
|
...n,
|
|
3741
|
-
[v]:
|
|
3761
|
+
[v]: l
|
|
3742
3762
|
})) : r[a.info.attributeName] = {
|
|
3743
3763
|
...n,
|
|
3744
|
-
[v]:
|
|
3764
|
+
[v]: l
|
|
3745
3765
|
};
|
|
3746
3766
|
}
|
|
3747
3767
|
for (let a in e.isolatedRecordIdRefs) {
|
|
3748
3768
|
const n = e.isolatedRecordIdRefs[a];
|
|
3749
3769
|
if (n.info.isXToOne) {
|
|
3750
|
-
const
|
|
3770
|
+
const u = E.atom({
|
|
3751
3771
|
key: n.info?.isRecordSource() ? "target.id" : "source.id",
|
|
3752
3772
|
value: ["=", n.getRef().id]
|
|
3753
3773
|
});
|
|
3754
|
-
await this.agent.unlink(n.info.linkName,
|
|
3774
|
+
await this.agent.unlink(n.info.linkName, u, !1, "unlink xToOne old link", t);
|
|
3755
3775
|
}
|
|
3756
3776
|
const o = n.linkRecordData?.getData() || {};
|
|
3757
3777
|
Object.assign(o, {
|
|
3758
3778
|
source: n.info.isRecordSource() ? i : n.getRef(),
|
|
3759
3779
|
target: n.info.isRecordSource() ? n.getRef() : i
|
|
3760
3780
|
});
|
|
3761
|
-
const c = new
|
|
3781
|
+
const c = new ee(this.map, n.info.linkName, o), l = await this.createRecord(c, `create isolated related link record of old related ${e.recordName}.${n.info?.attributeName}`, t);
|
|
3762
3782
|
n.info.isXToMany ? (r[n.info.attributeName] || (r[n.info.attributeName] = []), r[n.info.attributeName][a] = {
|
|
3763
3783
|
...n.getData(),
|
|
3764
|
-
[v]:
|
|
3784
|
+
[v]: l
|
|
3765
3785
|
}) : r[n.info.attributeName] = {
|
|
3766
3786
|
...n.getData(),
|
|
3767
|
-
[v]:
|
|
3787
|
+
[v]: l
|
|
3768
3788
|
};
|
|
3769
3789
|
}
|
|
3770
3790
|
return r;
|
|
@@ -3773,8 +3793,8 @@ class ja {
|
|
|
3773
3793
|
* 从记录添加链接
|
|
3774
3794
|
*/
|
|
3775
3795
|
addLinkFromRecord(e, t, i, r, a = {}, n) {
|
|
3776
|
-
const o = this.map.getLinkInfo(e, t), c = o.isRelationSource(e, t),
|
|
3777
|
-
return this.addLink(o.name,
|
|
3796
|
+
const o = this.map.getLinkInfo(e, t), c = o.isRelationSource(e, t), l = c ? i : r, u = c ? r : i;
|
|
3797
|
+
return this.addLink(o.name, l, u, a, !o.isRelationSource(e, t), n);
|
|
3778
3798
|
}
|
|
3779
3799
|
/**
|
|
3780
3800
|
* 添加链接
|
|
@@ -3795,16 +3815,16 @@ class ja {
|
|
|
3795
3815
|
if (!c.isMerged())
|
|
3796
3816
|
(c.isManyToOne || c.isOneToOne) && await this.agent.unlink(e, E.atom({ key: "source.id", value: ["=", t] }), !1, "unlink old link of exclusive source for add new link", n), (c.isOneToMany || c.isOneToOne) && await this.agent.unlink(e, E.atom({ key: "target.id", value: ["=", i] }), !1, "unlink old link of exclusive target for add new link", n);
|
|
3797
3817
|
else if (c.isOneToOne) {
|
|
3798
|
-
const
|
|
3799
|
-
await this.agent.unlink(e, E.atom({ key: `${
|
|
3818
|
+
const u = c.isMergedToSource() ? "target" : "source", d = u === "target" ? i : t;
|
|
3819
|
+
await this.agent.unlink(e, E.atom({ key: `${u}.id`, value: ["=", d] }), !1, "unlink old owner of exclusive 1:1 target for add new link", n);
|
|
3800
3820
|
}
|
|
3801
3821
|
}
|
|
3802
|
-
const
|
|
3822
|
+
const l = new ee(this.map, c.name, {
|
|
3803
3823
|
source: { id: t },
|
|
3804
3824
|
target: { id: i },
|
|
3805
3825
|
...r
|
|
3806
3826
|
});
|
|
3807
|
-
return this.createRecord(
|
|
3827
|
+
return this.createRecord(l, `create link record ${c.name}`, n);
|
|
3808
3828
|
}
|
|
3809
3829
|
/**
|
|
3810
3830
|
* 删除记录的同行数据(用于 flashOut)
|
|
@@ -3819,7 +3839,7 @@ function Ct(s) {
|
|
|
3819
3839
|
function oi(s, e) {
|
|
3820
3840
|
return `${s}:${e}`;
|
|
3821
3841
|
}
|
|
3822
|
-
function
|
|
3842
|
+
function lr(s, e) {
|
|
3823
3843
|
!s || !e || s === e || gi.set(s, Ct(e));
|
|
3824
3844
|
}
|
|
3825
3845
|
class Ha {
|
|
@@ -3840,19 +3860,33 @@ class Ha {
|
|
|
3840
3860
|
);
|
|
3841
3861
|
}
|
|
3842
3862
|
// ============ 依赖管理功能 ============
|
|
3863
|
+
/**
|
|
3864
|
+
* 实体名 → 物理 base 名的统一归一化。
|
|
3865
|
+
* CAUTION 名字空间收口(r22 F-1):同一条物理记录可以有多个声明名——filtered entity/
|
|
3866
|
+
* relation 的视图名、以 filtered entity 为端点的 relation 存下的 link.sourceRecord/
|
|
3867
|
+
* targetRecord(Setup 原样保存声明名)。依赖表按物理 base 名注册(initializeDependencies
|
|
3868
|
+
* 用 resolvedBaseRecordName),任何以声明名查询依赖的读者(collectLinkMembershipChecks
|
|
3869
|
+
* 经 link 端点名进来)都会拿到空集——查询面正确、成员资格事件整族缺失。
|
|
3870
|
+
* 所有「实体名 → 依赖/视图」的入口一律先经这里归一化,不允许第二套解析。
|
|
3871
|
+
*/
|
|
3872
|
+
resolveBaseRecordName(e) {
|
|
3873
|
+
return this.map.data.records[e]?.resolvedBaseRecordName || e;
|
|
3874
|
+
}
|
|
3843
3875
|
/**
|
|
3844
3876
|
* 分析 filtered entity 的过滤条件,提取所有依赖的实体和路径
|
|
3845
3877
|
*/
|
|
3846
3878
|
analyzeDependencies(e, t, i) {
|
|
3847
3879
|
const r = [];
|
|
3848
3880
|
this.extractDependenciesFromExpression(t, i, r);
|
|
3881
|
+
for (const o of r)
|
|
3882
|
+
o.entityName = this.resolveBaseRecordName(o.entityName);
|
|
3849
3883
|
const a = {
|
|
3850
3884
|
filteredEntityName: e,
|
|
3851
3885
|
baseEntityName: t,
|
|
3852
3886
|
matchExpression: i,
|
|
3853
3887
|
dependencies: r
|
|
3854
3888
|
}, n = new Set(r.map((o) => o.entityName));
|
|
3855
|
-
n.add(t);
|
|
3889
|
+
n.add(this.resolveBaseRecordName(t));
|
|
3856
3890
|
for (const o of n) {
|
|
3857
3891
|
this.dependencies.has(o) || this.dependencies.set(o, []);
|
|
3858
3892
|
const c = this.dependencies.get(o);
|
|
@@ -3868,35 +3902,36 @@ class Ha {
|
|
|
3868
3902
|
if (r.isExpression())
|
|
3869
3903
|
r.left && this.extractDependenciesFromExpression(e, r.left.raw, i), r.right && this.extractDependenciesFromExpression(e, r.right.raw, i);
|
|
3870
3904
|
else if (r.isAtom()) {
|
|
3871
|
-
const o = r.data.key.split("."), c = (
|
|
3905
|
+
const o = r.data.key.split("."), c = (l, u, d) => {
|
|
3872
3906
|
const h = i.find(
|
|
3873
|
-
(m) => m.entityName ===
|
|
3907
|
+
(m) => m.entityName === l && JSON.stringify(m.path) === JSON.stringify(u)
|
|
3874
3908
|
);
|
|
3875
3909
|
h ? h.attributes.includes(d) || h.attributes.push(d) : i.push({
|
|
3876
|
-
entityName:
|
|
3877
|
-
path:
|
|
3910
|
+
entityName: l,
|
|
3911
|
+
path: u,
|
|
3878
3912
|
attributes: [d]
|
|
3879
3913
|
});
|
|
3880
3914
|
};
|
|
3881
3915
|
if (o.length === 1)
|
|
3882
3916
|
c(e, [], o[0]);
|
|
3883
3917
|
else {
|
|
3884
|
-
const
|
|
3885
|
-
let
|
|
3918
|
+
const l = [e].concat(o);
|
|
3919
|
+
let u = e;
|
|
3886
3920
|
for (let m = 0; m < o.length - 1; m++) {
|
|
3887
|
-
const f = o[m], p = o.slice(0, m), y = this.map.getInfoByPath(
|
|
3888
|
-
c(
|
|
3921
|
+
const f = o[m], p = o.slice(0, m), y = this.map.getInfoByPath(l.slice(0, m + 2));
|
|
3922
|
+
c(u, p, f), y && y.isRecord && (u = y.recordName);
|
|
3889
3923
|
}
|
|
3890
3924
|
const d = o[o.length - 1], h = o.slice(0, o.length - 1);
|
|
3891
|
-
c(
|
|
3925
|
+
c(u, h, d);
|
|
3892
3926
|
}
|
|
3893
3927
|
}
|
|
3894
3928
|
}
|
|
3895
3929
|
/**
|
|
3896
3930
|
* 获取某个实体变更时影响的所有 filtered entity
|
|
3931
|
+
* (入口名可以是声明名——filtered 视图名、filtered 端点 relation 存下的端点名——统一归一化)
|
|
3897
3932
|
*/
|
|
3898
3933
|
getAffectedFilteredEntities(e) {
|
|
3899
|
-
return this.dependencies.get(e) || [];
|
|
3934
|
+
return this.dependencies.get(this.resolveBaseRecordName(e)) || [];
|
|
3900
3935
|
}
|
|
3901
3936
|
/**
|
|
3902
3937
|
* 清除所有依赖关系(同时失效按 MapData 共享的缓存)
|
|
@@ -3953,19 +3988,19 @@ class Ha {
|
|
|
3953
3988
|
if (r.has(n)) return;
|
|
3954
3989
|
r.add(n);
|
|
3955
3990
|
const c = this.map.getRecordInfo(n).filteredBy || [];
|
|
3956
|
-
for (const
|
|
3957
|
-
if (!i.has(
|
|
3958
|
-
i.add(
|
|
3959
|
-
const d = this.map.getRecordInfo(
|
|
3991
|
+
for (const l of c) {
|
|
3992
|
+
if (!i.has(l.name)) {
|
|
3993
|
+
i.add(l.name);
|
|
3994
|
+
const d = this.map.getRecordInfo(l.name).data.resolvedMatchExpression;
|
|
3960
3995
|
t.push({
|
|
3961
|
-
name:
|
|
3996
|
+
name: l.name,
|
|
3962
3997
|
matchExpression: d
|
|
3963
3998
|
});
|
|
3964
3999
|
}
|
|
3965
|
-
a(
|
|
4000
|
+
a(l.name);
|
|
3966
4001
|
}
|
|
3967
4002
|
};
|
|
3968
|
-
return a(e), t;
|
|
4003
|
+
return a(this.resolveBaseRecordName(e)), t;
|
|
3969
4004
|
}
|
|
3970
4005
|
// ============ 变更钩子:before(快照)/ settle(diff + 事件) ============
|
|
3971
4006
|
/**
|
|
@@ -3978,21 +4013,21 @@ class Ha {
|
|
|
3978
4013
|
*/
|
|
3979
4014
|
async collectMembershipChecks(e, t, i, r) {
|
|
3980
4015
|
if (!r || !t.length) return [];
|
|
3981
|
-
const a = this.
|
|
3982
|
-
if (!
|
|
3983
|
-
const
|
|
3984
|
-
for (const
|
|
3985
|
-
const
|
|
3986
|
-
for (const
|
|
3987
|
-
if (i && !i.filter((
|
|
4016
|
+
const a = this.resolveBaseRecordName(e), n = this.getAffectedFilteredEntities(a);
|
|
4017
|
+
if (!n.length) return [];
|
|
4018
|
+
const o = [];
|
|
4019
|
+
for (const c of n) {
|
|
4020
|
+
const l = c.dependencies.filter((m) => m.entityName === a), u = /* @__PURE__ */ new Set();
|
|
4021
|
+
for (const m of l) {
|
|
4022
|
+
if (i && !i.filter((y) => m.attributes.includes(y)).length)
|
|
3988
4023
|
continue;
|
|
3989
|
-
(await this.findAffectedSourceRecordIds(
|
|
4024
|
+
(await this.findAffectedSourceRecordIds(c, m.path, t)).forEach((p) => u.add(p));
|
|
3990
4025
|
}
|
|
3991
4026
|
if (!u.size) continue;
|
|
3992
|
-
const
|
|
3993
|
-
|
|
4027
|
+
const d = Array.from(u), h = await this.checkRecordsMatchFilter(d, c.baseEntityName, c.matchExpression);
|
|
4028
|
+
o.push({ dependency: c, recordIds: d, beforeMemberIds: h });
|
|
3994
4029
|
}
|
|
3995
|
-
return
|
|
4030
|
+
return o;
|
|
3996
4031
|
}
|
|
3997
4032
|
/**
|
|
3998
4033
|
* 关系(link)变更前采集:关系的建立/解除会改变两端实体的成员资格。
|
|
@@ -4015,21 +4050,21 @@ class Ha {
|
|
|
4015
4050
|
for (const r of e) {
|
|
4016
4051
|
const { dependency: a, recordIds: n, beforeMemberIds: o } = r;
|
|
4017
4052
|
if (!n.length) continue;
|
|
4018
|
-
const c = this.map.getRecordInfo(a.baseEntityName),
|
|
4053
|
+
const c = this.map.getRecordInfo(a.baseEntityName), l = await this.queryAgent.findRecords(
|
|
4019
4054
|
G.create(a.baseEntityName, this.map, {
|
|
4020
4055
|
matchExpression: E.atom({ key: "id", value: ["in", n] }),
|
|
4021
4056
|
attributeQuery: c.isRelation ? ["*", ["target", { attributeQuery: ["*"] }], ["source", { attributeQuery: ["*"] }]] : ["*"]
|
|
4022
4057
|
}),
|
|
4023
4058
|
`get current records for membership settle of ${a.filteredEntityName}`
|
|
4024
4059
|
);
|
|
4025
|
-
if (!
|
|
4026
|
-
const
|
|
4027
|
-
|
|
4060
|
+
if (!l.length) continue;
|
|
4061
|
+
const u = await this.checkRecordsMatchFilter(
|
|
4062
|
+
l.map((d) => d.id),
|
|
4028
4063
|
a.baseEntityName,
|
|
4029
4064
|
a.matchExpression
|
|
4030
4065
|
);
|
|
4031
|
-
for (const d of
|
|
4032
|
-
const h = oi(a.filteredEntityName, d.id), m =
|
|
4066
|
+
for (const d of l) {
|
|
4067
|
+
const h = oi(a.filteredEntityName, d.id), m = u.has(d.id), f = i.has(h) ? i.get(h) : o.has(d.id);
|
|
4033
4068
|
m !== f && t.push({
|
|
4034
4069
|
type: m ? "create" : "delete",
|
|
4035
4070
|
recordName: a.filteredEntityName,
|
|
@@ -4048,23 +4083,31 @@ class Ha {
|
|
|
4048
4083
|
if (!a.length) return;
|
|
4049
4084
|
const n = Ct(r);
|
|
4050
4085
|
for (const o of a) {
|
|
4051
|
-
const c = oi(o.name, t),
|
|
4052
|
-
|
|
4086
|
+
const c = oi(o.name, t), l = await this.checkRecordMatchesFilter(t, e, o.matchExpression), u = n.has(c) ? n.get(c) : !1;
|
|
4087
|
+
l && !u && r.push({
|
|
4053
4088
|
type: "create",
|
|
4054
4089
|
recordName: o.name,
|
|
4055
4090
|
record: { ...i, id: t }
|
|
4056
|
-
}), n.set(c,
|
|
4091
|
+
}), n.set(c, l);
|
|
4057
4092
|
}
|
|
4058
4093
|
}
|
|
4059
4094
|
// ============ 行内写路径(merged link / combined 记录)的视图成员资格 ============
|
|
4060
4095
|
/**
|
|
4061
4096
|
* 登记一个"物理写入完成后需要求值"的行内记录创建(merged link / combined 记录)。
|
|
4062
4097
|
* 写入完成点(insertSameRowData / updateSameRowData)调用 settlePostWriteChecks 统一结算。
|
|
4098
|
+
*
|
|
4099
|
+
* CAUTION 视图 create 事件的 payload 契约是 defaults + payload(与 base create 事件、
|
|
4100
|
+
* createRecord 的 membershipEventPayload 同构,r16 R-1)。行内记录的产生点(preprocess
|
|
4101
|
+
* 的 combined/merged link、flashOut 的抢夺新 link)拼 payload 时只有用户显式给出 `&`
|
|
4102
|
+
* 数据才带 defaults——「谓词/匹配字段仅有默认值」的形态下所有产生点都会漏(r22 I-4)。
|
|
4103
|
+
* 这里是行内视图 creation 检查的唯一入口,统一用 NewRecordData 的 defaults 规则补齐
|
|
4104
|
+
* (只补缺失键;物理写入本身已按同一规则落列,这里只是让事件 payload 与行一致)。
|
|
4063
4105
|
*/
|
|
4064
4106
|
enqueuePostWriteCreationCheck(e, t, i, r) {
|
|
4065
4107
|
if (!e || !this.getFilteredEntitiesForBase(t).length) return;
|
|
4066
|
-
|
|
4067
|
-
|
|
4108
|
+
const { [v]: a, ...n } = r, o = new ee(this.map, t, n).defaultValues;
|
|
4109
|
+
let c = Fe.get(e);
|
|
4110
|
+
c || (c = [], Fe.set(e, c)), c.push({ kind: "creation", recordName: t, recordId: i, fullRecord: { ...o, ...r } });
|
|
4068
4111
|
}
|
|
4069
4112
|
/**
|
|
4070
4113
|
* 登记一个行内记录的原地更新(同 id `&` 关系属性 / combined 嵌套值)。
|
|
@@ -4120,42 +4163,42 @@ class Ha {
|
|
|
4120
4163
|
const r = this.map.getRecordInfo(e), a = this.getFilteredEntitiesForBase(e), n = {
|
|
4121
4164
|
recordName: e,
|
|
4122
4165
|
membersByFilteredEntity: /* @__PURE__ */ new Map(),
|
|
4123
|
-
recordsById: new Map(t.map((
|
|
4166
|
+
recordsById: new Map(t.map((l) => [l.id, l])),
|
|
4124
4167
|
children: []
|
|
4125
4168
|
};
|
|
4126
4169
|
if (a.length) {
|
|
4127
|
-
const
|
|
4128
|
-
for (const
|
|
4129
|
-
const d = await this.checkRecordsMatchFilter(
|
|
4130
|
-
d.size && n.membersByFilteredEntity.set(
|
|
4170
|
+
const l = t.map((u) => u.id);
|
|
4171
|
+
for (const u of a) {
|
|
4172
|
+
const d = await this.checkRecordsMatchFilter(l, e, u.matchExpression);
|
|
4173
|
+
d.size && n.membersByFilteredEntity.set(u.name, d);
|
|
4131
4174
|
}
|
|
4132
4175
|
}
|
|
4133
|
-
for (const
|
|
4134
|
-
const
|
|
4135
|
-
if (
|
|
4136
|
-
const d = await this.collectDeletionMemberships(
|
|
4176
|
+
for (const l of r.sameTableReliance) {
|
|
4177
|
+
const u = t.map((d) => d[l.attributeName]).filter((d) => !!d?.id);
|
|
4178
|
+
if (u.length) {
|
|
4179
|
+
const d = await this.collectDeletionMemberships(l.recordName, u, i);
|
|
4137
4180
|
d && n.children.push(d);
|
|
4138
4181
|
}
|
|
4139
4182
|
}
|
|
4140
4183
|
const o = [
|
|
4141
4184
|
...r.mergedRecordAttributes,
|
|
4142
|
-
...r.notRelianceCombined.filter((
|
|
4185
|
+
...r.notRelianceCombined.filter((l) => !(r.isRelation && (l.attributeName === "source" || l.attributeName === "target"))),
|
|
4143
4186
|
...r.sameTableReliance
|
|
4144
4187
|
], c = /* @__PURE__ */ new Map();
|
|
4145
|
-
for (const
|
|
4146
|
-
for (const
|
|
4147
|
-
const d = u
|
|
4188
|
+
for (const l of t)
|
|
4189
|
+
for (const u of o) {
|
|
4190
|
+
const d = l[u.attributeName], h = d?.id !== void 0 ? d[v] : void 0;
|
|
4148
4191
|
if (!h?.id) continue;
|
|
4149
4192
|
const m = {
|
|
4150
4193
|
...h,
|
|
4151
|
-
[
|
|
4152
|
-
[
|
|
4194
|
+
[u.isRecordSource() ? "source" : "target"]: { id: l.id },
|
|
4195
|
+
[u.isRecordSource() ? "target" : "source"]: { id: d.id }
|
|
4153
4196
|
};
|
|
4154
|
-
let f = c.get(
|
|
4155
|
-
f || (f = [], c.set(
|
|
4197
|
+
let f = c.get(u.linkName);
|
|
4198
|
+
f || (f = [], c.set(u.linkName, f)), f.push(m);
|
|
4156
4199
|
}
|
|
4157
|
-
for (const [
|
|
4158
|
-
const d = await this.collectInlineDeletionSnapshot(
|
|
4200
|
+
for (const [l, u] of c) {
|
|
4201
|
+
const d = await this.collectInlineDeletionSnapshot(l, u, i);
|
|
4159
4202
|
d && n.children.push(d);
|
|
4160
4203
|
}
|
|
4161
4204
|
return n;
|
|
@@ -4171,13 +4214,13 @@ class Ha {
|
|
|
4171
4214
|
if (!n) return;
|
|
4172
4215
|
const o = Ct(a);
|
|
4173
4216
|
for (const c of i)
|
|
4174
|
-
for (const [
|
|
4175
|
-
const d = oi(
|
|
4176
|
-
if (o.has(d) ? o.get(d) :
|
|
4217
|
+
for (const [l, u] of n.membersByFilteredEntity) {
|
|
4218
|
+
const d = oi(l, c.id);
|
|
4219
|
+
if (o.has(d) ? o.get(d) : u.has(c.id)) {
|
|
4177
4220
|
const m = n.recordsById.get(c.id) || c;
|
|
4178
4221
|
r.push({
|
|
4179
4222
|
type: "delete",
|
|
4180
|
-
recordName:
|
|
4223
|
+
recordName: l,
|
|
4181
4224
|
record: { ...m }
|
|
4182
4225
|
});
|
|
4183
4226
|
}
|
|
@@ -4222,14 +4265,14 @@ class Wa {
|
|
|
4222
4265
|
* @returns [SQL字符串, 参数数组, 字段别名映射]
|
|
4223
4266
|
*/
|
|
4224
4267
|
buildXToOneFindQuery(e, t = "", i) {
|
|
4225
|
-
const r = e.attributeQuery.xToOneQueryTree, a = e.matchExpression.xToOneQueryTree, n = e.modifier.xToOneQueryTree, o = r.merge(a).merge(n), c = this.getJoinTables(o, [e.recordName]),
|
|
4226
|
-
|
|
4268
|
+
const r = e.attributeQuery.xToOneQueryTree, a = e.matchExpression.xToOneQueryTree, n = e.modifier.xToOneQueryTree, o = r.merge(a).merge(n), c = this.getJoinTables(o, [e.recordName]), l = i || this.getPlaceholder(), u = e.matchExpression.buildFieldMatchExpression(
|
|
4269
|
+
l,
|
|
4227
4270
|
this.database,
|
|
4228
|
-
(g) => this.parseFunctionMatchAtom(e.recordName, g, e.contextRootEntity,
|
|
4271
|
+
(g) => this.parseFunctionMatchAtom(e.recordName, g, e.contextRootEntity, l)
|
|
4229
4272
|
), [d, h] = this.buildWhereClause(
|
|
4230
|
-
|
|
4273
|
+
u,
|
|
4231
4274
|
t,
|
|
4232
|
-
|
|
4275
|
+
l
|
|
4233
4276
|
), [m, f] = this.buildSelectClause(
|
|
4234
4277
|
e.attributeQuery.getValueAndXToOneRecordFields(),
|
|
4235
4278
|
t
|
|
@@ -4260,8 +4303,8 @@ ${b}
|
|
|
4260
4303
|
`${this.withPrefix(t)}${o[0]}`,
|
|
4261
4304
|
...o.slice(1, 1 / 0),
|
|
4262
4305
|
n
|
|
4263
|
-
],
|
|
4264
|
-
return `"${this.withPrefix(t)}${a[0]}"."${a[1]}" AS "${
|
|
4306
|
+
], l = i.getAlias(c, !0);
|
|
4307
|
+
return `"${this.withPrefix(t)}${a[0]}"."${a[1]}" AS "${l}"`;
|
|
4265
4308
|
}).join(`,
|
|
4266
4309
|
`), i] : ["1", i];
|
|
4267
4310
|
}
|
|
@@ -4291,11 +4334,11 @@ ${b}
|
|
|
4291
4334
|
if (e.isAtom())
|
|
4292
4335
|
e.data.isInnerQuery ? (r = e.data.fieldValue, a.push(...e.data.fieldParams)) : (r = `("${this.withPrefix(t)}${e.data.fieldName[0]}"."${e.data.fieldName[1]}" ${e.data.fieldValue})`, a.push(...e.data.fieldParams));
|
|
4293
4336
|
else if (e.isAnd()) {
|
|
4294
|
-
const [n, o] = this.buildWhereClause(e.left, t, i), [c,
|
|
4295
|
-
r = `(${n} AND ${c})`, a.push(...o, ...
|
|
4337
|
+
const [n, o] = this.buildWhereClause(e.left, t, i), [c, l] = this.buildWhereClause(e.right, t, i);
|
|
4338
|
+
r = `(${n} AND ${c})`, a.push(...o, ...l);
|
|
4296
4339
|
} else if (e.isOr()) {
|
|
4297
|
-
const [n, o] = this.buildWhereClause(e.left, t, i), [c,
|
|
4298
|
-
r = `(${n} OR ${c})`, a.push(...o, ...
|
|
4340
|
+
const [n, o] = this.buildWhereClause(e.left, t, i), [c, l] = this.buildWhereClause(e.right, t, i);
|
|
4341
|
+
r = `(${n} OR ${c})`, a.push(...o, ...l);
|
|
4299
4342
|
} else {
|
|
4300
4343
|
const [n, o] = this.buildWhereClause(e.left, t, i);
|
|
4301
4344
|
r = `NOT (${n})`, a.push(...o);
|
|
@@ -4311,13 +4354,13 @@ ${b}
|
|
|
4311
4354
|
throw new Error(`modifier.limit must be a non-negative integer, got: ${JSON.stringify(r)}`);
|
|
4312
4355
|
if (a != null && (typeof a != "number" || !Number.isInteger(a) || a < 0))
|
|
4313
4356
|
throw new Error(`modifier.offset must be a non-negative integer, got: ${JSON.stringify(a)}`);
|
|
4314
|
-
return n.length && o.push(`ORDER BY ${n.map(({ attribute: c, recordName:
|
|
4315
|
-
const d = String(
|
|
4357
|
+
return n.length && o.push(`ORDER BY ${n.map(({ attribute: c, recordName: l, order: u }) => {
|
|
4358
|
+
const d = String(u).toUpperCase();
|
|
4316
4359
|
if (d !== "ASC" && d !== "DESC")
|
|
4317
|
-
throw new Error(`orderBy value must be 'ASC' or 'DESC', got: ${JSON.stringify(
|
|
4360
|
+
throw new Error(`orderBy value must be 'ASC' or 'DESC', got: ${JSON.stringify(u)} for attribute ${c}`);
|
|
4318
4361
|
const h = c.split(".");
|
|
4319
4362
|
let m, f;
|
|
4320
|
-
h.length === 1 ? (m = [
|
|
4363
|
+
h.length === 1 ? (m = [l], f = c) : (m = [l, ...h.slice(0, -1)], f = h[h.length - 1]);
|
|
4321
4364
|
const [p, y] = this.map.getTableAliasAndFieldName(
|
|
4322
4365
|
m,
|
|
4323
4366
|
f
|
|
@@ -4334,55 +4377,55 @@ ${b}
|
|
|
4334
4377
|
getJoinTables(e, t = [], i) {
|
|
4335
4378
|
const r = [];
|
|
4336
4379
|
if (!i) {
|
|
4337
|
-
const o = [t[0]], [c,
|
|
4338
|
-
i = [
|
|
4380
|
+
const o = [t[0]], [c, l, u] = this.map.getTableAliasAndFieldName(o, "id");
|
|
4381
|
+
i = [l, u, c];
|
|
4339
4382
|
}
|
|
4340
4383
|
const [a, ...n] = i;
|
|
4341
4384
|
return e.forEachRecords((o) => {
|
|
4342
|
-
const c = o.attributeName,
|
|
4343
|
-
if (!
|
|
4385
|
+
const c = o.attributeName, l = o.info;
|
|
4386
|
+
if (!l.isRecord)
|
|
4344
4387
|
throw new Error(`${t.concat(c).join(".")} is not a record`);
|
|
4345
|
-
const
|
|
4388
|
+
const u = t.concat(c), {
|
|
4346
4389
|
table: d,
|
|
4347
4390
|
alias: h,
|
|
4348
4391
|
linkTable: m,
|
|
4349
4392
|
linkAlias: f
|
|
4350
|
-
} = this.map.getTableAndAliasStack(
|
|
4351
|
-
if (!
|
|
4352
|
-
if (
|
|
4393
|
+
} = this.map.getTableAndAliasStack(u).at(-1), [, p] = this.map.getTableAliasAndFieldName(u, "id", !0);
|
|
4394
|
+
if (!l.isMergedWithParent())
|
|
4395
|
+
if (l.isLinkMergedWithParent()) {
|
|
4353
4396
|
if (o.onlyIdField()) return;
|
|
4354
4397
|
r.push({
|
|
4355
|
-
for:
|
|
4398
|
+
for: u,
|
|
4356
4399
|
joinSource: n,
|
|
4357
|
-
joinIdField: [
|
|
4400
|
+
joinIdField: [l.linkField, p],
|
|
4358
4401
|
joinTarget: [d, h]
|
|
4359
4402
|
});
|
|
4360
|
-
} else if (
|
|
4361
|
-
const y =
|
|
4403
|
+
} else if (l.isLinkMergedWithAttribute()) {
|
|
4404
|
+
const y = l.getReverseInfo();
|
|
4362
4405
|
if (!y.linkField)
|
|
4363
4406
|
throw new Error(`${y.parentEntityName}.${y.attributeName} has no field`);
|
|
4364
4407
|
r.push({
|
|
4365
|
-
for:
|
|
4408
|
+
for: u,
|
|
4366
4409
|
joinSource: n,
|
|
4367
4410
|
joinIdField: [a, y.linkField],
|
|
4368
4411
|
joinTarget: [d, h]
|
|
4369
4412
|
});
|
|
4370
4413
|
} else {
|
|
4371
|
-
const y =
|
|
4414
|
+
const y = l.getLinkInfo(), b = l.isLinkManyToManySymmetric() ? l.symmetricDirection === "source" : y.isRelationSource(l.parentEntityName, l.attributeName);
|
|
4372
4415
|
r.push({
|
|
4373
|
-
for:
|
|
4416
|
+
for: u,
|
|
4374
4417
|
joinSource: n,
|
|
4375
4418
|
joinIdField: [a, b ? y.record.attributes.source.field : y.record.attributes.target.field],
|
|
4376
4419
|
joinTarget: [m, f]
|
|
4377
4420
|
}), o.onlyIdField() || r.push({
|
|
4378
|
-
for:
|
|
4421
|
+
for: u,
|
|
4379
4422
|
joinSource: [m, f],
|
|
4380
4423
|
joinIdField: [b ? y.record.attributes.target.field : y.record.attributes.source.field, p],
|
|
4381
4424
|
joinTarget: [d, h]
|
|
4382
4425
|
});
|
|
4383
4426
|
}
|
|
4384
|
-
if (r.push(...this.getJoinTables(o,
|
|
4385
|
-
const y =
|
|
4427
|
+
if (r.push(...this.getJoinTables(o, u, [p, d, h])), o.parentLinkQueryTree && !o.parentLinkQueryTree.onlyIdField()) {
|
|
4428
|
+
const y = u.concat(v), [, b] = this.map.getTableAliasAndFieldName(y, "id", !0), g = [
|
|
4386
4429
|
b,
|
|
4387
4430
|
// link 的 idField
|
|
4388
4431
|
m,
|
|
@@ -4404,7 +4447,7 @@ ${b}
|
|
|
4404
4447
|
throw new Error(`match value is not a array ${t.key}`);
|
|
4405
4448
|
if (t.value[0].toLowerCase() !== "exist")
|
|
4406
4449
|
throw new Error(`we only support Exist function match on entity for now. yours: ${t.key} ${t.value[0]} ${t.value[1]}`);
|
|
4407
|
-
const a = this.map.getInfoByPath(t.namePath), { alias: n } = this.map.getTableAndAliasStack(t.namePath).at(-1), o = this.map.getReverseAttribute(a.parentEntityName, a.attributeName), c = t.namePath.slice(1, -1),
|
|
4450
|
+
const a = this.map.getInfoByPath(t.namePath), { alias: n } = this.map.getTableAndAliasStack(t.namePath).at(-1), o = this.map.getReverseAttribute(a.parentEntityName, a.attributeName), c = t.namePath.slice(1, -1), l = G.create(
|
|
4408
4451
|
a.recordName,
|
|
4409
4452
|
this.map,
|
|
4410
4453
|
{
|
|
@@ -4416,13 +4459,13 @@ ${b}
|
|
|
4416
4459
|
},
|
|
4417
4460
|
// 如果上层还有,就继承上层的,如果没有, context 就只这一层
|
|
4418
4461
|
i || e
|
|
4419
|
-
), [
|
|
4462
|
+
), [u, d] = this.buildXToOneFindQuery(l, n, r);
|
|
4420
4463
|
return {
|
|
4421
4464
|
...t,
|
|
4422
4465
|
isInnerQuery: !0,
|
|
4423
4466
|
fieldValue: `
|
|
4424
4467
|
EXISTS (
|
|
4425
|
-
${
|
|
4468
|
+
${u}
|
|
4426
4469
|
)
|
|
4427
4470
|
`,
|
|
4428
4471
|
fieldParams: d
|
|
@@ -4467,7 +4510,7 @@ VALUES
|
|
|
4467
4510
|
UPDATE "${a.table}"
|
|
4468
4511
|
SET ${i.map(({ field: c }) => `"${c}" = ${r()}`).join(",")}
|
|
4469
4512
|
WHERE "${a.idField}" = (${r()})
|
|
4470
|
-
`, o = [...i.map(({ value: c, fieldType:
|
|
4513
|
+
`, o = [...i.map(({ value: c, fieldType: l }) => this.prepareFieldValue(c, l)), t.id];
|
|
4471
4514
|
return [n, o];
|
|
4472
4515
|
}
|
|
4473
4516
|
/**
|
|
@@ -4557,30 +4600,30 @@ class Ga {
|
|
|
4557
4600
|
const r = /* @__PURE__ */ new Map(), a = (o) => {
|
|
4558
4601
|
const c = o.join(".");
|
|
4559
4602
|
if (r.has(c)) return r.get(c);
|
|
4560
|
-
let
|
|
4603
|
+
let l;
|
|
4561
4604
|
try {
|
|
4562
|
-
const
|
|
4563
|
-
if (
|
|
4564
|
-
const d =
|
|
4565
|
-
|
|
4605
|
+
const u = this.map.getInfoByPath([t, ...o]);
|
|
4606
|
+
if (u && u.isValue) {
|
|
4607
|
+
const d = u.data;
|
|
4608
|
+
l = d.collection || d.type === "object" || d.type === "json" ? "json" : d.type;
|
|
4566
4609
|
}
|
|
4567
4610
|
} catch {
|
|
4568
|
-
|
|
4611
|
+
l = void 0;
|
|
4569
4612
|
}
|
|
4570
|
-
return r.set(c,
|
|
4613
|
+
return r.set(c, l), l;
|
|
4571
4614
|
}, n = this.database.returnsParsedJSON === !0;
|
|
4572
4615
|
return e.map((o) => {
|
|
4573
4616
|
const c = {};
|
|
4574
|
-
return Object.entries(o).forEach(([
|
|
4575
|
-
const d = i.getPath(
|
|
4576
|
-
if (!n && typeof
|
|
4617
|
+
return Object.entries(o).forEach(([l, u]) => {
|
|
4618
|
+
const d = i.getPath(l).slice(1, 1 / 0), h = a(d);
|
|
4619
|
+
if (!n && typeof u == "string" && h === "json")
|
|
4577
4620
|
try {
|
|
4578
|
-
|
|
4621
|
+
u = JSON.parse(u);
|
|
4579
4622
|
} catch (m) {
|
|
4580
|
-
throw new Error(`Failed to parse JSON field "${t}.${d.join(".")}": ${m instanceof Error ? m.message : String(m)}. Raw value: ${
|
|
4623
|
+
throw new Error(`Failed to parse JSON field "${t}.${d.join(".")}": ${m instanceof Error ? m.message : String(m)}. Raw value: ${u.slice(0, 200)}`);
|
|
4581
4624
|
}
|
|
4582
|
-
else typeof
|
|
4583
|
-
|
|
4625
|
+
else typeof u == "number" && h === "boolean" && (u = u !== 0);
|
|
4626
|
+
u !== null && wt(c, d, u);
|
|
4584
4627
|
}), c;
|
|
4585
4628
|
});
|
|
4586
4629
|
}
|
|
@@ -4624,10 +4667,10 @@ class Ga {
|
|
|
4624
4667
|
limit: void 0,
|
|
4625
4668
|
offset: void 0
|
|
4626
4669
|
})
|
|
4627
|
-
}) : e, [
|
|
4628
|
-
a && h ? `${
|
|
4629
|
-
FOR UPDATE OF "${e.recordName}"` :
|
|
4630
|
-
|
|
4670
|
+
}) : e, [l, u, d] = this.sqlBuilder.buildXToOneFindQuery(c, ""), h = this.database.supportsSelectForUpdate ?? this.database.constructor.name !== "SQLiteDB", m = await this.database.query(
|
|
4671
|
+
a && h ? `${l}
|
|
4672
|
+
FOR UPDATE OF "${e.recordName}"` : l,
|
|
4673
|
+
u,
|
|
4631
4674
|
t
|
|
4632
4675
|
);
|
|
4633
4676
|
let f = this.dedupeIdenticalRows(m);
|
|
@@ -4737,15 +4780,15 @@ FOR UPDATE OF "${e.recordName}"` : u,
|
|
|
4737
4780
|
* 只是把"每个父记录一次查询"合并为"每批父记录一次查询"。
|
|
4738
4781
|
*/
|
|
4739
4782
|
async findXToManyRelatedRecordsBatched(e, t, i, r, a, n) {
|
|
4740
|
-
const
|
|
4783
|
+
const l = this.map.getInfo(e, t).getReverseInfo()?.attributeName, u = r.alias || r.attributeName, d = /* @__PURE__ */ new Map();
|
|
4741
4784
|
for (const y of i)
|
|
4742
|
-
y[
|
|
4785
|
+
y[u] = [], d.set(String(y.id), y);
|
|
4743
4786
|
const h = r.attributeQuery.data.some(
|
|
4744
|
-
(y) => (typeof y == "string" ? y : y[0]) ===
|
|
4745
|
-
), m = h ? r.attributeQuery.data : [...r.attributeQuery.data, [
|
|
4787
|
+
(y) => (typeof y == "string" ? y : y[0]) === l
|
|
4788
|
+
), m = h ? r.attributeQuery.data : [...r.attributeQuery.data, [l, { attributeQuery: ["id"] }]], f = r.attributeQuery.parentLinkRecordQuery, p = !!f;
|
|
4746
4789
|
for (let y = 0; y < i.length; y += 500) {
|
|
4747
4790
|
const b = i.slice(y, y + 500), g = r.matchExpression.and({
|
|
4748
|
-
key: `${
|
|
4791
|
+
key: `${l}.id`,
|
|
4749
4792
|
value: ["in", b.map((N) => N.id)]
|
|
4750
4793
|
}), w = new K(
|
|
4751
4794
|
r.recordName,
|
|
@@ -4764,8 +4807,8 @@ FOR UPDATE OF "${e.recordName}"` : u,
|
|
|
4764
4807
|
n
|
|
4765
4808
|
);
|
|
4766
4809
|
for (const N of S) {
|
|
4767
|
-
const $ = N[
|
|
4768
|
-
if (p ? (N[v] = N[
|
|
4810
|
+
const $ = N[l]?.id, I = $ !== void 0 ? d.get(String($)) : void 0;
|
|
4811
|
+
if (p ? (N[v] = N[l]?.[v], delete N[l]) : h || delete N[l], f)
|
|
4769
4812
|
for (let D of f.attributeQuery.xToManyRecords) {
|
|
4770
4813
|
const W = N[v].id;
|
|
4771
4814
|
wt(
|
|
@@ -4781,7 +4824,7 @@ FOR UPDATE OF "${e.recordName}"` : u,
|
|
|
4781
4824
|
)
|
|
4782
4825
|
);
|
|
4783
4826
|
}
|
|
4784
|
-
I && I[
|
|
4827
|
+
I && I[u].push(N);
|
|
4785
4828
|
}
|
|
4786
4829
|
}
|
|
4787
4830
|
}
|
|
@@ -4793,16 +4836,16 @@ FOR UPDATE OF "${e.recordName}"` : u,
|
|
|
4793
4836
|
const n = this.map.getInfo(e.parentRecord, e.attributeName).getReverseInfo()?.attributeName;
|
|
4794
4837
|
for (let o of e.attributeQuery.parentLinkRecordQuery.attributeQuery.xToOneRecords)
|
|
4795
4838
|
for (let c of o.attributeQuery.xToManyRecords)
|
|
4796
|
-
for (let
|
|
4797
|
-
if (!
|
|
4798
|
-
const
|
|
4799
|
-
|
|
4839
|
+
for (let l of t) {
|
|
4840
|
+
if (!l[n]?.[v]?.[o.attributeName]) continue;
|
|
4841
|
+
const u = e.label ? r.concat(l) : r;
|
|
4842
|
+
l[n][v][o.attributeName][c.attributeName] = await this.findXToManyRelatedRecords(
|
|
4800
4843
|
c.parentRecord,
|
|
4801
4844
|
c.attributeName,
|
|
4802
|
-
|
|
4845
|
+
l[n][v][o.attributeName].id,
|
|
4803
4846
|
c,
|
|
4804
4847
|
i,
|
|
4805
|
-
|
|
4848
|
+
u
|
|
4806
4849
|
);
|
|
4807
4850
|
}
|
|
4808
4851
|
}
|
|
@@ -4834,13 +4877,13 @@ FOR UPDATE OF "${e.recordName}"` : u,
|
|
|
4834
4877
|
* CAUTION 任何两个具体的实体之间只能有一条关系,但是可以在关系上有多条数据。1:n 的数据
|
|
4835
4878
|
*/
|
|
4836
4879
|
async findXToManyRelatedRecords(e, t, i, r, a, n) {
|
|
4837
|
-
const o = this.map.getInfo(e, t), c = o.getReverseInfo()?.attributeName,
|
|
4880
|
+
const o = this.map.getInfo(e, t), c = o.getReverseInfo()?.attributeName, l = r.matchExpression.and({
|
|
4838
4881
|
key: `${c}.id`,
|
|
4839
4882
|
// 这里不能用 EXIST,因为 EXIST 会把 join 变成子查询,而我们还需要关系上的数据,不能用子查询
|
|
4840
4883
|
value: ["=", i]
|
|
4841
|
-
}),
|
|
4842
|
-
matchExpression:
|
|
4843
|
-
attributeQuery:
|
|
4884
|
+
}), u = r.attributeQuery.parentLinkRecordQuery ? r.attributeQuery.withParentLinkData() : r.attributeQuery, d = r.derive({
|
|
4885
|
+
matchExpression: l,
|
|
4886
|
+
attributeQuery: u
|
|
4844
4887
|
}), h = await this.findRecords(d, `finding related record: ${r.parentRecord}.${r.attributeName}`, a, n);
|
|
4845
4888
|
let m;
|
|
4846
4889
|
if (!r.attributeQuery.parentLinkRecordQuery)
|
|
@@ -4904,11 +4947,11 @@ FOR UPDATE OF "${e.recordName}"` : u,
|
|
|
4904
4947
|
const a = t.split("."), n = a.at(-1), o = a.slice(0, -1), c = E.atom({
|
|
4905
4948
|
key: "id",
|
|
4906
4949
|
value: ["=", i]
|
|
4907
|
-
}),
|
|
4908
|
-
let d =
|
|
4950
|
+
}), l = K.getAttributeQueryDataForRecord(e, this.map, !0, !0, !1, !0), u = t;
|
|
4951
|
+
let d = l;
|
|
4909
4952
|
for (let p of o)
|
|
4910
4953
|
d.push([p, { attributeQuery: ["*"] }]), d = d.at(-1)[1].attributeQuery;
|
|
4911
|
-
d.push([n, { label:
|
|
4954
|
+
d.push([n, { label: u, attributeQuery: ["*"] }]), d = d.at(-1)[1].attributeQuery;
|
|
4912
4955
|
for (let p of o)
|
|
4913
4956
|
d.push([p, { attributeQuery: ["*"] }]), d = d.at(-1)[1].attributeQuery;
|
|
4914
4957
|
let h;
|
|
@@ -4917,10 +4960,10 @@ FOR UPDATE OF "${e.recordName}"` : u,
|
|
|
4917
4960
|
if (p.stack.at(-1)?.id === r)
|
|
4918
4961
|
return h = [...p.stack], !0;
|
|
4919
4962
|
};
|
|
4920
|
-
d.push([n, { goto:
|
|
4963
|
+
d.push([n, { goto: u, exit: m }]);
|
|
4921
4964
|
const f = (await this.findRecords(G.create(e, this.map, {
|
|
4922
4965
|
matchExpression: c,
|
|
4923
|
-
attributeQuery:
|
|
4966
|
+
attributeQuery: l
|
|
4924
4967
|
}), `find records for path ${e}.${t}`))[0];
|
|
4925
4968
|
return h ? [f, ...h] : void 0;
|
|
4926
4969
|
}
|
|
@@ -4950,10 +4993,10 @@ class Ja {
|
|
|
4950
4993
|
targetIds: n.map((h) => h.target?.id)
|
|
4951
4994
|
}, i) : [];
|
|
4952
4995
|
await this.deleteNotReliantSeparateLinkRecords(a.recordName, n, i);
|
|
4953
|
-
const
|
|
4954
|
-
|
|
4955
|
-
const { linkAndCascadeEvents:
|
|
4956
|
-
i?.push(...
|
|
4996
|
+
const l = [];
|
|
4997
|
+
lr(l, i), await this.deleteDifferentTableReliance(a.recordName, n, l);
|
|
4998
|
+
const { linkAndCascadeEvents: u, recordDeleteEvents: d } = await this.deleteRecordSameRowDataGrouped(a.recordName, n, r, o, i);
|
|
4999
|
+
i?.push(...u, ...l, ...d), await this.filteredEntityManager.settleMembershipChecks(c, i);
|
|
4957
5000
|
}
|
|
4958
5001
|
return n;
|
|
4959
5002
|
}
|
|
@@ -4975,9 +5018,9 @@ class Ja {
|
|
|
4975
5018
|
*/
|
|
4976
5019
|
async deleteRecordSameRowDataGrouped(e, t, i = !1, r, a) {
|
|
4977
5020
|
const n = [];
|
|
4978
|
-
|
|
5021
|
+
lr(n, a);
|
|
4979
5022
|
const o = this.map.getRecordInfo(e);
|
|
4980
|
-
for (let
|
|
5023
|
+
for (let l of t) {
|
|
4981
5024
|
if (!i) {
|
|
4982
5025
|
const d = G.create(
|
|
4983
5026
|
e,
|
|
@@ -4985,7 +5028,7 @@ class Ja {
|
|
|
4985
5028
|
{
|
|
4986
5029
|
matchExpression: E.atom({
|
|
4987
5030
|
key: "id",
|
|
4988
|
-
value: ["=",
|
|
5031
|
+
value: ["=", l.id]
|
|
4989
5032
|
}),
|
|
4990
5033
|
attributeQuery: K.getAttributeQueryDataForRecord(e, this.map, !0, !0, !0, !0),
|
|
4991
5034
|
modifier: { limit: 1 }
|
|
@@ -4995,76 +5038,76 @@ class Ja {
|
|
|
4995
5038
|
const f = o.combinedRecords.filter((b) => !(o.isRelation && (b.attributeName === "source" || b.attributeName === "target"))).flatMap((b) => b.getLinkInfo().recordInfo.sameRowFields), [p, y] = this.sqlBuilder.buildUpdateFieldsToNullSQL(
|
|
4996
5039
|
o.name,
|
|
4997
5040
|
[.../* @__PURE__ */ new Set([...o.sameRowFields, ...f])],
|
|
4998
|
-
|
|
5041
|
+
l
|
|
4999
5042
|
);
|
|
5000
5043
|
await this.database.update(p, y, o.idField, `use update to delete ${e} because of sameRowData`);
|
|
5001
5044
|
} else {
|
|
5002
|
-
const [f, p] = this.sqlBuilder.buildDeleteSQL(o.name, o.idField,
|
|
5045
|
+
const [f, p] = this.sqlBuilder.buildDeleteSQL(o.name, o.idField, l.id);
|
|
5003
5046
|
await this.database.delete(f, p, `delete record ${o.name} as row`);
|
|
5004
5047
|
}
|
|
5005
5048
|
}
|
|
5006
|
-
const
|
|
5049
|
+
const u = (d, h) => {
|
|
5007
5050
|
this.filteredEntityManager.settleDeletionMemberships(r, d, [h], n, a);
|
|
5008
5051
|
};
|
|
5009
5052
|
for (let d of o.sameTableReliance)
|
|
5010
|
-
if (
|
|
5053
|
+
if (l[d.attributeName]?.id) {
|
|
5011
5054
|
const h = {
|
|
5012
|
-
...
|
|
5055
|
+
...l[d.attributeName][v],
|
|
5013
5056
|
[d.isRecordSource() ? "source" : "target"]: {
|
|
5014
|
-
id:
|
|
5057
|
+
id: l.id
|
|
5015
5058
|
},
|
|
5016
5059
|
[d.isRecordSource() ? "target" : "source"]: {
|
|
5017
|
-
id:
|
|
5060
|
+
id: l[d.attributeName].id
|
|
5018
5061
|
}
|
|
5019
5062
|
};
|
|
5020
5063
|
n.push({
|
|
5021
5064
|
type: "delete",
|
|
5022
5065
|
recordName: d.linkName,
|
|
5023
5066
|
record: h
|
|
5024
|
-
}),
|
|
5067
|
+
}), u(d.linkName, h);
|
|
5025
5068
|
const m = r?.children.find((f) => f.recordName === d.recordName);
|
|
5026
|
-
await this.handleDeletedRecordReliance(d.recordName,
|
|
5069
|
+
await this.handleDeletedRecordReliance(d.recordName, l[d.attributeName], n, m, a);
|
|
5027
5070
|
}
|
|
5028
5071
|
o.mergedRecordAttributes.forEach((d) => {
|
|
5029
|
-
if (
|
|
5072
|
+
if (l[d.attributeName]?.id) {
|
|
5030
5073
|
const h = {
|
|
5031
|
-
...
|
|
5074
|
+
...l[d.attributeName][v],
|
|
5032
5075
|
[d.isRecordSource() ? "source" : "target"]: {
|
|
5033
|
-
id:
|
|
5076
|
+
id: l.id
|
|
5034
5077
|
},
|
|
5035
5078
|
[d.isRecordSource() ? "target" : "source"]: {
|
|
5036
|
-
id:
|
|
5079
|
+
id: l[d.attributeName].id
|
|
5037
5080
|
}
|
|
5038
5081
|
};
|
|
5039
5082
|
n.push({
|
|
5040
5083
|
type: "delete",
|
|
5041
5084
|
recordName: d.linkName,
|
|
5042
5085
|
record: h
|
|
5043
|
-
}),
|
|
5086
|
+
}), u(d.linkName, h);
|
|
5044
5087
|
}
|
|
5045
5088
|
}), o.notRelianceCombined.forEach((d) => {
|
|
5046
|
-
if (o.isRelation && (d.attributeName === "target" || d.attributeName === "source") ||
|
|
5089
|
+
if (o.isRelation && (d.attributeName === "target" || d.attributeName === "source") || l[d.attributeName]?.id === void 0) return;
|
|
5047
5090
|
const h = {
|
|
5048
|
-
...
|
|
5091
|
+
...l[d.attributeName][v],
|
|
5049
5092
|
[d.isRecordSource() ? "source" : "target"]: {
|
|
5050
|
-
id:
|
|
5093
|
+
id: l.id
|
|
5051
5094
|
},
|
|
5052
5095
|
[d.isRecordSource() ? "target" : "source"]: {
|
|
5053
|
-
id:
|
|
5096
|
+
id: l[d.attributeName].id
|
|
5054
5097
|
}
|
|
5055
5098
|
};
|
|
5056
5099
|
n.push({
|
|
5057
5100
|
type: "delete",
|
|
5058
5101
|
recordName: d.linkName,
|
|
5059
5102
|
record: h
|
|
5060
|
-
}),
|
|
5103
|
+
}), u(d.linkName, h);
|
|
5061
5104
|
});
|
|
5062
5105
|
}
|
|
5063
5106
|
this.filteredEntityManager.settleDeletionMemberships(r, e, t, n, a);
|
|
5064
|
-
const c = t.map((
|
|
5107
|
+
const c = t.map((l) => ({
|
|
5065
5108
|
type: "delete",
|
|
5066
5109
|
recordName: e,
|
|
5067
|
-
record:
|
|
5110
|
+
record: l
|
|
5068
5111
|
}));
|
|
5069
5112
|
return { linkAndCascadeEvents: n, recordDeleteEvents: c };
|
|
5070
5113
|
}
|
|
@@ -5096,14 +5139,14 @@ class Ja {
|
|
|
5096
5139
|
for (let n of r.differentTableReliance) {
|
|
5097
5140
|
const o = E.atom({
|
|
5098
5141
|
key: `${n.getReverseInfo()?.attributeName}.id`,
|
|
5099
|
-
value: ["in", t.map((
|
|
5142
|
+
value: ["in", t.map((l) => l.id)]
|
|
5100
5143
|
}), c = i?.length ?? 0;
|
|
5101
5144
|
if (await this.deleteRecord(n.recordName, o, i), i)
|
|
5102
|
-
for (let
|
|
5103
|
-
const
|
|
5104
|
-
if (
|
|
5105
|
-
const d = a.get(
|
|
5106
|
-
d && (
|
|
5145
|
+
for (let l = c; l < i.length; l++) {
|
|
5146
|
+
const u = i[l];
|
|
5147
|
+
if (u.recordName === n.linkName) {
|
|
5148
|
+
const d = a.get(u.record[n.isRecordSource() ? "source" : "target"].id);
|
|
5149
|
+
d && (u.record[n.isRecordSource() ? "source" : "target"] = d);
|
|
5107
5150
|
}
|
|
5108
5151
|
}
|
|
5109
5152
|
}
|
|
@@ -5128,11 +5171,11 @@ class Xa {
|
|
|
5128
5171
|
n.managedRecordAttributes.forEach((f) => o.add(f.attributeName));
|
|
5129
5172
|
const c = a.filter(
|
|
5130
5173
|
(f) => typeof f == "string" || o.has(f[0])
|
|
5131
|
-
),
|
|
5174
|
+
), l = G.create(e, this.map, {
|
|
5132
5175
|
matchExpression: t,
|
|
5133
5176
|
attributeQuery: c
|
|
5134
|
-
}),
|
|
5135
|
-
for (let f of
|
|
5177
|
+
}), u = await this.agent.findRecords(l, `find record for updating ${e}`), d = Object.keys(i.getData()), h = !!this.map.data.links[i.recordName], m = [];
|
|
5178
|
+
for (let f of u) {
|
|
5136
5179
|
if (h)
|
|
5137
5180
|
for (const S of ["source", "target"]) {
|
|
5138
5181
|
if (!Object.prototype.hasOwnProperty.call(i.rawData || {}, S)) continue;
|
|
@@ -5145,7 +5188,7 @@ class Xa {
|
|
|
5145
5188
|
const p = Array.from(/* @__PURE__ */ new Set([
|
|
5146
5189
|
...d,
|
|
5147
5190
|
...i.getSameRowFieldAndValue(f).map((S) => S.name)
|
|
5148
|
-
])), y = await this.filteredEntityManager.collectMembershipChecks(
|
|
5191
|
+
])), y = await this.filteredEntityManager.collectMembershipChecks(l.recordName, [f.id], p, r), b = r ? await this.collectUpdateLinkChecks(i, r) : [], g = await this.agent.createRecordDependency(i, r), w = await this.updateSameRowData(l.recordName, f, g, r), R = await this.handleUpdateReliance(l.recordName, f, i, r);
|
|
5149
5192
|
await this.filteredEntityManager.settleMembershipChecks(y.concat(b), r), m.push({ ...i.getData(), ...w.getData(), ...R });
|
|
5150
5193
|
}
|
|
5151
5194
|
return m;
|
|
@@ -5176,24 +5219,24 @@ class Xa {
|
|
|
5176
5219
|
i.mergedLinkTargetNullRecords,
|
|
5177
5220
|
i.mergedLinkTargetRecordIdRefs
|
|
5178
5221
|
);
|
|
5179
|
-
for (let
|
|
5180
|
-
const
|
|
5181
|
-
|
|
5182
|
-
|
|
5222
|
+
for (let l of a) {
|
|
5223
|
+
const u = l.info.getLinkInfo(), d = u.isRelationSource(e, l.info.attributeName) ? "source" : "target";
|
|
5224
|
+
l.isRef() && t[l.info?.attributeName]?.id === l.getData().id || await this.agent.unlink(
|
|
5225
|
+
u.name,
|
|
5183
5226
|
E.atom({
|
|
5184
5227
|
key: `${d}.id`,
|
|
5185
5228
|
value: ["=", t.id]
|
|
5186
5229
|
}),
|
|
5187
|
-
!
|
|
5188
|
-
`unlink ${
|
|
5230
|
+
!u.isRelationSource(e, l.info.attributeName),
|
|
5231
|
+
`unlink ${l.info?.parentEntityName} ${l.info?.attributeName} for update ${e}`,
|
|
5189
5232
|
r
|
|
5190
5233
|
);
|
|
5191
5234
|
}
|
|
5192
5235
|
await this.agent.unlinkOldOwnersOfExclusiveTargets(i, r, t);
|
|
5193
|
-
const n = await this.agent.preprocessSameRowData(i, !0, r, t), c = n.getSameRowFieldAndValue(t).map(({ field:
|
|
5194
|
-
field:
|
|
5236
|
+
const n = await this.agent.preprocessSameRowData(i, !0, r, t), c = n.getSameRowFieldAndValue(t).map(({ field: l, value: u, fieldType: d }) => ({
|
|
5237
|
+
field: l,
|
|
5195
5238
|
/// TODO value 要考虑引用自身或者 related entity 其他 field 的情况?例如 age+5
|
|
5196
|
-
value:
|
|
5239
|
+
value: u,
|
|
5197
5240
|
// fieldType 让 buildUpdateSQL 走 prepareFieldValue(json 规范序列化),与 create 路径一致。
|
|
5198
5241
|
fieldType: d
|
|
5199
5242
|
}));
|
|
@@ -5211,18 +5254,18 @@ class Xa {
|
|
|
5211
5254
|
i.isolatedNullRecords
|
|
5212
5255
|
), n = /* @__PURE__ */ new Set();
|
|
5213
5256
|
for (let c of a) {
|
|
5214
|
-
const
|
|
5215
|
-
if (n.has(
|
|
5257
|
+
const l = c.info.getLinkInfo();
|
|
5258
|
+
if (n.has(l.name))
|
|
5216
5259
|
continue;
|
|
5217
|
-
n.add(
|
|
5218
|
-
const
|
|
5219
|
-
key: `${
|
|
5260
|
+
n.add(l.name);
|
|
5261
|
+
const u = l.isRelationSource(e, c.info.attributeName) ? "source" : "target", d = c.info.isManyToMany && l.isSymmetric() ? E.atom({ key: "source.id", value: ["=", t.id] }).or({ key: "target.id", value: ["=", t.id] }) : E.atom({
|
|
5262
|
+
key: `${u}.id`,
|
|
5220
5263
|
value: ["=", t.id]
|
|
5221
5264
|
});
|
|
5222
5265
|
await this.agent.unlink(
|
|
5223
|
-
|
|
5266
|
+
l.name,
|
|
5224
5267
|
d,
|
|
5225
|
-
!
|
|
5268
|
+
!l.isRelationSource(e, c.info.attributeName),
|
|
5226
5269
|
"unlink old reliance for update",
|
|
5227
5270
|
r
|
|
5228
5271
|
);
|
|
@@ -5231,15 +5274,15 @@ class Xa {
|
|
|
5231
5274
|
for (let c of a) {
|
|
5232
5275
|
if (i.rawData[c.info?.attributeName] === null)
|
|
5233
5276
|
continue;
|
|
5234
|
-
let
|
|
5235
|
-
c.isRef() ?
|
|
5236
|
-
const
|
|
5277
|
+
let l;
|
|
5278
|
+
c.isRef() ? l = c.getRef() : l = await this.agent.createRecord(c, `create new related record for update ${i.recordName}.${c.info?.attributeName}`, r);
|
|
5279
|
+
const u = await this.agent.addLinkFromRecord(e, c.info?.attributeName, t.id, l.id, c.linkRecordData?.getData(), r);
|
|
5237
5280
|
c.info.isXToMany ? (o[c.info.attributeName] || (o[c.info.attributeName] = []), o[c.info.attributeName].push({
|
|
5238
|
-
...
|
|
5239
|
-
[v]:
|
|
5281
|
+
...l,
|
|
5282
|
+
[v]: u
|
|
5240
5283
|
})) : o[c.info.attributeName] = {
|
|
5241
|
-
...
|
|
5242
|
-
[v]:
|
|
5284
|
+
...l,
|
|
5285
|
+
[v]: u
|
|
5243
5286
|
};
|
|
5244
5287
|
}
|
|
5245
5288
|
return o;
|
|
@@ -5301,7 +5344,7 @@ class Ya {
|
|
|
5301
5344
|
const n = {}, o = r?.size ? e.combinedRecordIdRefs.filter((f) => !r.has(f.info.attributeName)) : e.combinedRecordIdRefs;
|
|
5302
5345
|
if (!o.length) return n;
|
|
5303
5346
|
let c;
|
|
5304
|
-
const
|
|
5347
|
+
const l = K.getAttributeQueryDataForRecord(e.recordName, this.map, !0, !0, !1, !0);
|
|
5305
5348
|
for (let f of o) {
|
|
5306
5349
|
const p = {
|
|
5307
5350
|
key: `${f.info.attributeName}.id`,
|
|
@@ -5309,10 +5352,10 @@ class Ya {
|
|
|
5309
5352
|
};
|
|
5310
5353
|
c ? c = c.or(p) : c = E.atom(p);
|
|
5311
5354
|
}
|
|
5312
|
-
const
|
|
5355
|
+
const u = G.create(e.recordName, this.map, {
|
|
5313
5356
|
matchExpression: c,
|
|
5314
|
-
attributeQuery:
|
|
5315
|
-
}, void 0, void 0, void 0, !1, !0), d = await this.queryExecutor.findRecords(
|
|
5357
|
+
attributeQuery: l
|
|
5358
|
+
}, void 0, void 0, void 0, !1, !0), d = await this.queryExecutor.findRecords(u, i, void 0), h = this.map.getRecordInfo(e.recordName).isRelation && !!this.map.data.links[e.recordName], m = [];
|
|
5316
5359
|
for (let f of d) {
|
|
5317
5360
|
if (h && f.id) {
|
|
5318
5361
|
const p = {
|
|
@@ -5427,15 +5470,15 @@ class Ya {
|
|
|
5427
5470
|
}), `finding combined records for relocate ${e}.${n}`, void 0), c = await this.filteredEntityManager.collectLinkMembershipChecks(e, {
|
|
5428
5471
|
sourceIds: o.map((d) => d.source?.id),
|
|
5429
5472
|
targetIds: o.map((d) => d.target?.id)
|
|
5430
|
-
}, r),
|
|
5431
|
-
await this.deleteRecordSameRowData(
|
|
5473
|
+
}, r), l = await this.filteredEntityManager.collectInlineDeletionSnapshot(e, o, r), u = this.map.getLinkInfoByName(e)[i ? "sourceRecordInfo" : "targetRecordInfo"];
|
|
5474
|
+
await this.deleteRecordSameRowData(u.name, o.map((d) => d[n]));
|
|
5432
5475
|
for (let d of o) {
|
|
5433
|
-
const h = new
|
|
5476
|
+
const h = new ee(this.map, u.name, d[n]);
|
|
5434
5477
|
await this.creationExecutor.insertSameRowData(h, void 0), r?.push({
|
|
5435
5478
|
type: "delete",
|
|
5436
5479
|
recordName: e,
|
|
5437
5480
|
record: d
|
|
5438
|
-
}), r &&
|
|
5481
|
+
}), r && l && this.filteredEntityManager.settleDeletionMemberships(l, e, [d], r, r);
|
|
5439
5482
|
}
|
|
5440
5483
|
return await this.filteredEntityManager.settleMembershipChecks(c, r), o;
|
|
5441
5484
|
}
|
|
@@ -5500,7 +5543,7 @@ function Qr(s) {
|
|
|
5500
5543
|
}
|
|
5501
5544
|
return { root: e, match: t };
|
|
5502
5545
|
}
|
|
5503
|
-
function
|
|
5546
|
+
function ur(s) {
|
|
5504
5547
|
const e = new Map(s.map((n) => [H(n), n])), t = [], i = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), a = (n) => {
|
|
5505
5548
|
const o = H(n);
|
|
5506
5549
|
if (!i.has(o)) {
|
|
@@ -5508,8 +5551,8 @@ function lr(s) {
|
|
|
5508
5551
|
throw new Error(`Circular merged item dependency detected at "${o}"`);
|
|
5509
5552
|
r.add(o);
|
|
5510
5553
|
for (const c of De(n) || []) {
|
|
5511
|
-
const
|
|
5512
|
-
|
|
5554
|
+
const l = H(c), u = e.get(l);
|
|
5555
|
+
u && a(u);
|
|
5513
5556
|
}
|
|
5514
5557
|
r.delete(o), i.add(o), t.push(n);
|
|
5515
5558
|
}
|
|
@@ -5522,10 +5565,10 @@ function Za(s, e) {
|
|
|
5522
5565
|
const p = H(f), { root: y } = Qr(f);
|
|
5523
5566
|
De(y) ? i.add(p) : o.set(p, H(y));
|
|
5524
5567
|
}
|
|
5525
|
-
const c = /* @__PURE__ */ new Map(),
|
|
5526
|
-
for (const f of u)
|
|
5527
|
-
hr(f, t, "entity", d, o, c, i, r, a);
|
|
5568
|
+
const c = /* @__PURE__ */ new Map(), l = ur(s.filter((f) => f.inputEntities)), u = ur(e.filter((f) => f.inputRelations)), d = dr(s), h = dr(e);
|
|
5528
5569
|
for (const f of l)
|
|
5570
|
+
hr(f, t, "entity", d, o, c, i, r, a);
|
|
5571
|
+
for (const f of u)
|
|
5529
5572
|
hr(f, t, "relation", h, o, c, i, r, a);
|
|
5530
5573
|
return { ...t.getAll(), abstractNames: i, discriminatorHostNames: r, inputWritablePropertyNames: a };
|
|
5531
5574
|
}
|
|
@@ -5560,9 +5603,9 @@ function en(s, e, t) {
|
|
|
5560
5603
|
throw new Error(`Merged item "${o}" has no input items (empty union) and cannot be used as the base of a filtered input.`);
|
|
5561
5604
|
return { memberCondition: n ? c.memberCondition.and(n) : c.memberCondition, hostedTypes: new Set(c.hostedTypes) };
|
|
5562
5605
|
}
|
|
5563
|
-
const
|
|
5606
|
+
const l = E.atom({ key: pe, value: ["=", o] });
|
|
5564
5607
|
return {
|
|
5565
|
-
memberCondition: n ?
|
|
5608
|
+
memberCondition: n ? l.and(n) : l,
|
|
5566
5609
|
hostedTypes: /* @__PURE__ */ new Set([o]),
|
|
5567
5610
|
rootToRebase: a
|
|
5568
5611
|
};
|
|
@@ -5573,11 +5616,11 @@ function en(s, e, t) {
|
|
|
5573
5616
|
};
|
|
5574
5617
|
}
|
|
5575
5618
|
function hr(s, e, t, i, r, a, n, o, c) {
|
|
5576
|
-
const
|
|
5619
|
+
const l = t === "entity", u = H(s), d = De(s) || [];
|
|
5577
5620
|
if (s.commonProperties) {
|
|
5578
5621
|
const N = d.filter(($) => s.commonProperties.some((I) => !$.properties.some((D) => D.name === I.name && D.type === I.type)));
|
|
5579
5622
|
if (N.length > 0)
|
|
5580
|
-
throw new Error(`Merged ${t} ${
|
|
5623
|
+
throw new Error(`Merged ${t} ${u} defined commonProperties, but these ${t}s do not have commonProperties: ${N.map(($) => H($)).join(", ")}`);
|
|
5581
5624
|
}
|
|
5582
5625
|
for (const N of d)
|
|
5583
5626
|
if (N.properties.some(($) => $.name === pe))
|
|
@@ -5590,7 +5633,7 @@ function hr(s, e, t, i, r, a, n, o, c) {
|
|
|
5590
5633
|
let f = h[0]?.memberCondition;
|
|
5591
5634
|
for (let N = 1; N < h.length; N++)
|
|
5592
5635
|
f = f.or(h[N].memberCondition);
|
|
5593
|
-
const p =
|
|
5636
|
+
const p = l ? e.getEntityByName(u) : e.getRelationByName(u), y = [
|
|
5594
5637
|
...rn(p, i, e),
|
|
5595
5638
|
tn(r),
|
|
5596
5639
|
...s.properties
|
|
@@ -5601,7 +5644,7 @@ function hr(s, e, t, i, r, a, n, o, c) {
|
|
|
5601
5644
|
);
|
|
5602
5645
|
e.replace(g, p);
|
|
5603
5646
|
let R = w;
|
|
5604
|
-
w !== g && (R = e.add(w), mt(g) ? g.baseEntity = R : g.baseRelation = R, n.add(H(R))), a.set(
|
|
5647
|
+
w !== g && (R = e.add(w), mt(g) ? g.baseEntity = R : g.baseRelation = R, n.add(H(R))), a.set(u, {
|
|
5605
5648
|
memberCondition: f,
|
|
5606
5649
|
hostedTypes: m,
|
|
5607
5650
|
physicalBaseName: H(R)
|
|
@@ -5609,13 +5652,13 @@ function hr(s, e, t, i, r, a, n, o, c) {
|
|
|
5609
5652
|
const S = /* @__PURE__ */ new Map();
|
|
5610
5653
|
for (const { inputItem: N, memberCondition: $ } of h) {
|
|
5611
5654
|
const I = H(N);
|
|
5612
|
-
c.set(I, pr(I, e,
|
|
5655
|
+
c.set(I, pr(I, e, l)), mr(I, R, $, e, l);
|
|
5613
5656
|
}
|
|
5614
5657
|
for (const { rootToRebase: N } of h)
|
|
5615
5658
|
N && H(N) !== H(R) && S.set(H(N), N);
|
|
5616
5659
|
for (const [N] of S) {
|
|
5617
5660
|
const $ = E.atom({ key: pe, value: ["=", N] });
|
|
5618
|
-
c.set(N, pr(N, e,
|
|
5661
|
+
c.set(N, pr(N, e, l)), mr(N, R, $, e, l);
|
|
5619
5662
|
}
|
|
5620
5663
|
}
|
|
5621
5664
|
function pr(s, e, t) {
|
|
@@ -5661,15 +5704,15 @@ function rn(s, e, t) {
|
|
|
5661
5704
|
let c = o;
|
|
5662
5705
|
for (; Te(c) && c.properties.length === 0; )
|
|
5663
5706
|
c = Te(c);
|
|
5664
|
-
const
|
|
5707
|
+
const l = Object.fromEntries(
|
|
5665
5708
|
c.properties.filter((h) => h.name !== pe).map((h) => [h.name, h])
|
|
5666
5709
|
);
|
|
5667
|
-
a.set(H(o),
|
|
5668
|
-
const
|
|
5710
|
+
a.set(H(o), l), Object.assign(n, l);
|
|
5711
|
+
const u = !!De(o), d = [...e.get(H(o)) || []];
|
|
5669
5712
|
for (; d.length; ) {
|
|
5670
5713
|
const h = d.shift();
|
|
5671
|
-
if (!
|
|
5672
|
-
a.set(h,
|
|
5714
|
+
if (!u)
|
|
5715
|
+
a.set(h, l);
|
|
5673
5716
|
else {
|
|
5674
5717
|
const m = t.getEntityByName(h) || t.getRelationByName(h), f = m && !!De(m);
|
|
5675
5718
|
if (m && !f) {
|
|
@@ -5684,10 +5727,10 @@ function rn(s, e, t) {
|
|
|
5684
5727
|
}
|
|
5685
5728
|
for (const o of Object.keys(n)) {
|
|
5686
5729
|
const c = x.clone(n[o], !0);
|
|
5687
|
-
c.defaultValue = (
|
|
5688
|
-
const d = a.get(
|
|
5730
|
+
c.defaultValue = (l, u) => {
|
|
5731
|
+
const d = a.get(u)?.[o];
|
|
5689
5732
|
if (d?.defaultValue)
|
|
5690
|
-
return d.defaultValue(
|
|
5733
|
+
return d.defaultValue(l, u);
|
|
5691
5734
|
}, r.push(c);
|
|
5692
5735
|
}
|
|
5693
5736
|
return r;
|
|
@@ -5795,18 +5838,18 @@ class bi {
|
|
|
5795
5838
|
const a = i && t[Ie] !== void 0;
|
|
5796
5839
|
for (const [n, o] of Object.entries(t)) {
|
|
5797
5840
|
if (n === Ie || n === Pe || n === v) continue;
|
|
5798
|
-
const [c] = this.map.getAttributeAndSymmetricDirection(n),
|
|
5799
|
-
if (!
|
|
5841
|
+
const [c] = this.map.getAttributeAndSymmetricDirection(n), l = r.attributes[c];
|
|
5842
|
+
if (!l) {
|
|
5800
5843
|
if (a) continue;
|
|
5801
5844
|
throw new Error(
|
|
5802
5845
|
`unknown attribute "${n}" in write payload for "${e}". Unknown keys were previously dropped silently (zero-warning data loss). Declared attributes: ${Object.keys(r.attributes).join(", ")}.`
|
|
5803
5846
|
);
|
|
5804
5847
|
}
|
|
5805
|
-
if (
|
|
5848
|
+
if (l.isRecord) {
|
|
5806
5849
|
if (!o || typeof o != "object") continue;
|
|
5807
|
-
this.validateWritePayload(
|
|
5808
|
-
const
|
|
5809
|
-
|
|
5850
|
+
this.validateWritePayload(l.recordName, o, !0);
|
|
5851
|
+
const u = o[v];
|
|
5852
|
+
u && l.linkName && this.validateWritePayload(l.linkName, u, !0);
|
|
5810
5853
|
} else if (!a && r.writablePropertyNames && !r.writablePropertyNames.includes(c))
|
|
5811
5854
|
throw new Error(
|
|
5812
5855
|
`property "${c}" is not declared on "${e}" — it belongs to another input of merged record "${r.resolvedBaseRecordName || e}". Writing it through "${e}" would silently pollute a column owned by a sibling input view. Properties writable through "${e}": ${r.writablePropertyNames.join(", ")}.`
|
|
@@ -5815,13 +5858,13 @@ class bi {
|
|
|
5815
5858
|
}
|
|
5816
5859
|
async create(e, t, i) {
|
|
5817
5860
|
this.validateWritePayload(e, t);
|
|
5818
|
-
const r = new
|
|
5861
|
+
const r = new ee(this.map, e, t);
|
|
5819
5862
|
return this.agent.createRecord(r, `create record ${e} from handle`, i);
|
|
5820
5863
|
}
|
|
5821
5864
|
// CAUTION 不能递归更新 relate entity 的 value,如果传入了 related entity 的值,说明是建立新的联系。
|
|
5822
5865
|
async update(e, t, i, r) {
|
|
5823
5866
|
this.validateWritePayload(e, i);
|
|
5824
|
-
const a = new
|
|
5867
|
+
const a = new ee(this.map, e, i);
|
|
5825
5868
|
return this.agent.updateRecord(e, t, a, r);
|
|
5826
5869
|
}
|
|
5827
5870
|
async delete(e, t, i) {
|
|
@@ -5834,7 +5877,7 @@ class bi {
|
|
|
5834
5877
|
return this.validateWritePayload(this.map.getInfo(e, t).linkName, a), this.agent.addLinkFromRecord(e, t, i, r, a, n);
|
|
5835
5878
|
}
|
|
5836
5879
|
async updateRelationByName(e, t, i, r) {
|
|
5837
|
-
return T(!i.source && !i.target, "Relation can only update attributes. Use addRelation/removeRelation to update source/target."), this.validateWritePayload(e, i), this.agent.updateRecord(e, t, new
|
|
5880
|
+
return T(!i.source && !i.target, "Relation can only update attributes. Use addRelation/removeRelation to update source/target."), this.validateWritePayload(e, i), this.agent.updateRecord(e, t, new ee(this.map, e, i), r);
|
|
5838
5881
|
}
|
|
5839
5882
|
async removeRelationByName(e, t, i) {
|
|
5840
5883
|
return this.agent.unlink(e, t, !1, `remove relation ${e}`, i);
|
|
@@ -6105,13 +6148,13 @@ class qe {
|
|
|
6105
6148
|
computeInfoByPath(e) {
|
|
6106
6149
|
const [t, ...i] = e;
|
|
6107
6150
|
T(this.data.records[t], `entity ${t} not found`), T(i.length > 0, "getInfoByPath should have a name path.");
|
|
6108
|
-
let r = t, a, n, o, c,
|
|
6109
|
-
const
|
|
6151
|
+
let r = t, a, n, o, c, l;
|
|
6152
|
+
const u = [];
|
|
6110
6153
|
for (; c = i.shift(); ) {
|
|
6111
|
-
|
|
6154
|
+
u.push(c);
|
|
6112
6155
|
const [d, h] = this.getAttributeAndSymmetricDirection(c);
|
|
6113
|
-
if (
|
|
6114
|
-
T(!!a && !!n, `reading link in wrong path ${
|
|
6156
|
+
if (l = h, d === v)
|
|
6157
|
+
T(!!a && !!n, `reading link in wrong path ${u.join(".")}`), a = this.data.records[a].attributes[n].linkName, n = void 0, r = o.linkName, o = void 0;
|
|
6115
6158
|
else {
|
|
6116
6159
|
const m = this.data.records[r];
|
|
6117
6160
|
if (!m)
|
|
@@ -6122,11 +6165,11 @@ class qe {
|
|
|
6122
6165
|
}
|
|
6123
6166
|
}
|
|
6124
6167
|
if (!(!a || !n))
|
|
6125
|
-
return new ke(a, n, this,
|
|
6168
|
+
return new ke(a, n, this, l);
|
|
6126
6169
|
}
|
|
6127
6170
|
getTableAndAliasStack(e) {
|
|
6128
6171
|
const [t, ...i] = e;
|
|
6129
|
-
let r = this.data.records[t], a = r.table, n = t, o, c,
|
|
6172
|
+
let r = this.data.records[t], a = r.table, n = t, o, c, l = !1, u;
|
|
6130
6173
|
const d = [{
|
|
6131
6174
|
// 最后一张表名
|
|
6132
6175
|
table: a,
|
|
@@ -6134,7 +6177,7 @@ class qe {
|
|
|
6134
6177
|
alias: n,
|
|
6135
6178
|
// 最后表代表的 entity 数据,
|
|
6136
6179
|
record: r,
|
|
6137
|
-
isLinkRecord:
|
|
6180
|
+
isLinkRecord: l,
|
|
6138
6181
|
// 上一张表和最后一张表的关联表(如果是 relation 和 entity 的连接,这个link 就是虚拟的,table 是空,因为肯定是个合并的),
|
|
6139
6182
|
// linkTable: relationTable,
|
|
6140
6183
|
// 上一张表和最后一张表的关联表的 alias.
|
|
@@ -6146,26 +6189,26 @@ class qe {
|
|
|
6146
6189
|
const [m, f] = this.getAttributeAndSymmetricDirection(i[h]), p = [t, ...i.slice(0, h + 1)];
|
|
6147
6190
|
if (m === v) {
|
|
6148
6191
|
const { linkTable: y, linkAlias: b, path: g } = d.pop();
|
|
6149
|
-
T(!
|
|
6192
|
+
T(!l, `last attribute in path is a link, cannot read link of a link ${g.join(".")}`), a = y, n = b, r = this.data.records[u.linkName], l = !0, o = "", c = "", u = void 0;
|
|
6150
6193
|
} else {
|
|
6151
|
-
|
|
6194
|
+
u = this.getInfoByPath(p);
|
|
6152
6195
|
const y = r.attributes[m];
|
|
6153
|
-
T(
|
|
6196
|
+
T(u.isRecord, `${i.slice(0, h + 1).join(".")} is not a entity attribute`);
|
|
6154
6197
|
const b = this.data.records[y.recordName], g = `${n}_${m}${f ? `_${f.toUpperCase()}` : ""}`, w = this.aliasManager?.registerTablePath(g) || g;
|
|
6155
|
-
if (
|
|
6198
|
+
if (u.isMergedWithParent() || u.isLinkMergedWithParent())
|
|
6156
6199
|
c = n;
|
|
6157
|
-
else if (
|
|
6200
|
+
else if (u.isLinkIsolated()) {
|
|
6158
6201
|
const R = `REL_${g}`;
|
|
6159
6202
|
c = this.aliasManager?.registerTablePath(R) || R;
|
|
6160
6203
|
} else
|
|
6161
6204
|
c = w;
|
|
6162
|
-
|
|
6205
|
+
u.isMergedWithParent() || (n = w), a = u.table, r = b, o = u.getLinkInfo()?.table, l = !1;
|
|
6163
6206
|
}
|
|
6164
6207
|
d.push({
|
|
6165
6208
|
table: a,
|
|
6166
6209
|
alias: n,
|
|
6167
6210
|
record: r,
|
|
6168
|
-
isLinkRecord:
|
|
6211
|
+
isLinkRecord: l,
|
|
6169
6212
|
linkTable: o,
|
|
6170
6213
|
linkAlias: c,
|
|
6171
6214
|
path: p
|
|
@@ -6174,14 +6217,14 @@ class qe {
|
|
|
6174
6217
|
return d;
|
|
6175
6218
|
}
|
|
6176
6219
|
getTableAliasAndFieldName(e, t, i = !1) {
|
|
6177
|
-
const r = this.getTableAndAliasStack(e), { table: a, alias: n, record: o, path: c, linkAlias:
|
|
6220
|
+
const r = this.getTableAndAliasStack(e), { table: a, alias: n, record: o, path: c, linkAlias: l, linkTable: u, isLinkRecord: d } = r.at(-1), h = !d && r.length > 1 ? this.getInfoByPath(c) : null;
|
|
6178
6221
|
if (!i && t === "id" && !d && e.length > 1 && (h?.isLinkMergedWithParent() || h?.isLinkIsolated()))
|
|
6179
6222
|
if (h?.isLinkMergedWithParent()) {
|
|
6180
6223
|
const { alias: f, table: p } = r.at(-2);
|
|
6181
6224
|
return [f, h.linkField, p];
|
|
6182
6225
|
} else {
|
|
6183
6226
|
const f = h.getLinkInfo().record, p = h?.isLinkManyToManySymmetric() ? h?.symmetricDirection === "source" ? f?.attributes.target.field : f?.attributes.source.field : h.isRecordSource() ? f?.attributes.target.field : f?.attributes.source.field;
|
|
6184
|
-
return [
|
|
6227
|
+
return [l, p, u];
|
|
6185
6228
|
}
|
|
6186
6229
|
else {
|
|
6187
6230
|
const [f] = this.getAttributeAndSymmetricDirection(t), p = o.attributes[f];
|
|
@@ -6277,9 +6320,9 @@ class qe {
|
|
|
6277
6320
|
for (; o < i.length; ) {
|
|
6278
6321
|
const c = i[o];
|
|
6279
6322
|
if (c === v && o > 0 && o < i.length - 1) {
|
|
6280
|
-
const
|
|
6323
|
+
const u = r[r.length - 1], d = i[o + 1];
|
|
6281
6324
|
if (d === "source" || d === "target") {
|
|
6282
|
-
const h = this.getInfo(n,
|
|
6325
|
+
const h = this.getInfo(n, u);
|
|
6283
6326
|
if (h.isRecord) {
|
|
6284
6327
|
const m = h.getLinkInfo().data, f = h.isRecordSource() ? m.targetRecord : m.sourceRecord, p = d === "source" ? m.sourceRecord : m.targetRecord;
|
|
6285
6328
|
if (f === p) {
|
|
@@ -6294,8 +6337,8 @@ class qe {
|
|
|
6294
6337
|
r.push(c), o++;
|
|
6295
6338
|
} else if (c !== v) {
|
|
6296
6339
|
if (n = a, a) {
|
|
6297
|
-
const
|
|
6298
|
-
|
|
6340
|
+
const u = this.getInfo(a, c);
|
|
6341
|
+
u.isRecord && (a = u.recordName);
|
|
6299
6342
|
}
|
|
6300
6343
|
r.push(c), o++;
|
|
6301
6344
|
} else
|
|
@@ -6451,10 +6494,10 @@ function sn(s, e, t) {
|
|
|
6451
6494
|
}
|
|
6452
6495
|
}
|
|
6453
6496
|
function wi(s, e, t, i, r, a) {
|
|
6454
|
-
const n = i.supportsCreateIndexIfNotExists ? " IF NOT EXISTS" : "", o = t.map((
|
|
6455
|
-
WHERE ${Object.entries(r).map(([
|
|
6456
|
-
const d = a?.(
|
|
6457
|
-
return sn(d,
|
|
6497
|
+
const n = i.supportsCreateIndexIfNotExists ? " IF NOT EXISTS" : "", o = t.map((l) => ce(l, i)).join(", "), c = r ? `
|
|
6498
|
+
WHERE ${Object.entries(r).map(([l, u]) => {
|
|
6499
|
+
const d = a?.(l) ?? l;
|
|
6500
|
+
return sn(d, u, i);
|
|
6458
6501
|
}).join(" AND ")}` : "";
|
|
6459
6502
|
return `CREATE UNIQUE INDEX${n} ${ce(s, i)} ON ${ce(e, i)} (${o})${c}`;
|
|
6460
6503
|
}
|
|
@@ -6488,7 +6531,7 @@ function cn(s, e) {
|
|
|
6488
6531
|
sql: `ALTER TABLE ${t} ADD CONSTRAINT ${i} CHECK (${r} IS NOT NULL)`
|
|
6489
6532
|
};
|
|
6490
6533
|
}
|
|
6491
|
-
class
|
|
6534
|
+
class ue {
|
|
6492
6535
|
constructor(e, t, i, r = []) {
|
|
6493
6536
|
this.entities = e, this.relations = t, this.database = i, this.mergeLinks = r, this.fieldNameMap = /* @__PURE__ */ new Map(), this.usedFieldNames = /* @__PURE__ */ new Set(), this.fieldCounter = 1, this.recordToTableMap = /* @__PURE__ */ new Map(), this.tableToRecordsMap = /* @__PURE__ */ new Map(), this.mergeLog = [], this.tables = {}, this.map = { links: {}, records: {} }, this.aliasManager = new nn(), this.constraintSchemaItems = [], this.mergedAbstractNames = /* @__PURE__ */ new Set(), this.mergedDiscriminatorHostNames = /* @__PURE__ */ new Set(), this.mergedInputWritablePropertyNames = /* @__PURE__ */ new Map(), this.buildMap(), this.buildTables(), this.buildConstraints();
|
|
6494
6537
|
}
|
|
@@ -6503,11 +6546,11 @@ class le {
|
|
|
6503
6546
|
const r = this.recordToTableMap.get(t), a = this.recordToTableMap.get(e), n = this.tableToRecordsMap.get(a);
|
|
6504
6547
|
if (T(!!r && !!a, `table not exists for ${t} ${r} to join ${e} ${a}`), r == a) return;
|
|
6505
6548
|
const o = this.tableToRecordsMap.get(r), c = [];
|
|
6506
|
-
if (o.forEach((
|
|
6507
|
-
n.has(
|
|
6549
|
+
if (o.forEach((l) => {
|
|
6550
|
+
n.has(l) && c.push(l);
|
|
6508
6551
|
}), c.length)
|
|
6509
6552
|
return this.mergeLog.push({ joinTargetRecord: e, record: t, link: i, conflicts: c }), c;
|
|
6510
|
-
this.tableToRecordsMap.set(r, /* @__PURE__ */ new Set()), o.forEach((
|
|
6553
|
+
this.tableToRecordsMap.set(r, /* @__PURE__ */ new Set()), o.forEach((l) => this.recordToTableMap.set(l, a)), this.tableToRecordsMap.set(a, new Set(Array.from(n).concat(Array.from(o)))), this.mergeLog.push({ joinTargetRecord: e, record: t, link: i });
|
|
6511
6554
|
}
|
|
6512
6555
|
combineRecordTable(e, t, i) {
|
|
6513
6556
|
let r;
|
|
@@ -6626,16 +6669,16 @@ class le {
|
|
|
6626
6669
|
}
|
|
6627
6670
|
createFilteredRelationRecord(e) {
|
|
6628
6671
|
const t = Object.fromEntries(e.properties.map((c) => {
|
|
6629
|
-
const
|
|
6672
|
+
const l = c;
|
|
6630
6673
|
return [
|
|
6631
|
-
|
|
6674
|
+
l.name,
|
|
6632
6675
|
{
|
|
6633
|
-
name:
|
|
6634
|
-
type:
|
|
6635
|
-
computed:
|
|
6636
|
-
collection:
|
|
6637
|
-
defaultValue:
|
|
6638
|
-
fieldType: this.database.mapToDBFieldType(
|
|
6676
|
+
name: l.name,
|
|
6677
|
+
type: l.type,
|
|
6678
|
+
computed: l.computed,
|
|
6679
|
+
collection: l.collection,
|
|
6680
|
+
defaultValue: l.defaultValue,
|
|
6681
|
+
fieldType: this.database.mapToDBFieldType(l.type, l.collection)
|
|
6639
6682
|
}
|
|
6640
6683
|
];
|
|
6641
6684
|
}));
|
|
@@ -6657,15 +6700,15 @@ class le {
|
|
|
6657
6700
|
resolveRootBaseRecordNameAndMatchExpression(e) {
|
|
6658
6701
|
const { baseEntity: t, baseRelation: i, matchExpression: r } = e;
|
|
6659
6702
|
let a, n, o = t || i;
|
|
6660
|
-
const
|
|
6703
|
+
const l = [r || e.matchExpression];
|
|
6661
6704
|
for (; o.baseEntity || o.baseRelation; ) {
|
|
6662
|
-
const
|
|
6663
|
-
d &&
|
|
6705
|
+
const u = o.baseEntity || o.baseRelation, d = o.matchExpression;
|
|
6706
|
+
d && l.push(d), o = u;
|
|
6664
6707
|
}
|
|
6665
|
-
if (a = o.name,
|
|
6666
|
-
n =
|
|
6667
|
-
for (let
|
|
6668
|
-
n = n.and(u
|
|
6708
|
+
if (a = o.name, l.length > 0) {
|
|
6709
|
+
n = l[0];
|
|
6710
|
+
for (let u = 1; u < l.length; u++)
|
|
6711
|
+
n = n.and(l[u]);
|
|
6669
6712
|
}
|
|
6670
6713
|
return { resolvedBaseRecordName: a, resolvedMatchExpression: n };
|
|
6671
6714
|
}
|
|
@@ -6781,7 +6824,7 @@ class le {
|
|
|
6781
6824
|
if (o.length) {
|
|
6782
6825
|
const c = this.resolveEndpointRootName(i);
|
|
6783
6826
|
throw new Error(
|
|
6784
|
-
`Filtered ${r} '${i.name}' cannot declare its own propert${o.length > 1 ? "ies" : "y"} ${o.map((
|
|
6827
|
+
`Filtered ${r} '${i.name}' cannot declare its own propert${o.length > 1 ? "ies" : "y"} ${o.map((l) => `'${l.name}'`).join(", ")}. Filtered ${r === "entity" ? "entities" : "relations"} are views sharing the base ${r}'s table row, so new properties (including computed/computation properties) must be declared on the base ${r} '${c}'. Re-declaring a property name that already exists on the base is allowed and resolves to the base column.`
|
|
6785
6828
|
);
|
|
6786
6829
|
}
|
|
6787
6830
|
};
|
|
@@ -6797,8 +6840,8 @@ class le {
|
|
|
6797
6840
|
this.relations.forEach((n) => {
|
|
6798
6841
|
if (n.source.baseEntity) {
|
|
6799
6842
|
const o = this.getBaseEntityChain(n.source), c = [];
|
|
6800
|
-
for (const
|
|
6801
|
-
this.getRelationPropertyNames(
|
|
6843
|
+
for (const l of o)
|
|
6844
|
+
this.getRelationPropertyNames(l.name).has(n.sourceProperty) && c.push(l.name);
|
|
6802
6845
|
if (c.length > 0)
|
|
6803
6846
|
throw new Error(
|
|
6804
6847
|
`Relation property name conflict: filtered entity '${n.source.name}' uses sourceProperty '${n.sourceProperty}', but this property name is already defined on base entity '${c[0]}'. Filtered entities inherit all relation properties from their base entities, so you cannot redefine the same property name. Please use a different property name for this relation.`
|
|
@@ -6806,8 +6849,8 @@ class le {
|
|
|
6806
6849
|
}
|
|
6807
6850
|
if (n.target.baseEntity && n.targetProperty) {
|
|
6808
6851
|
const o = this.getBaseEntityChain(n.target), c = [];
|
|
6809
|
-
for (const
|
|
6810
|
-
this.getRelationPropertyNames(
|
|
6852
|
+
for (const l of o)
|
|
6853
|
+
this.getRelationPropertyNames(l.name).has(n.targetProperty) && c.push(l.name);
|
|
6811
6854
|
if (c.length > 0)
|
|
6812
6855
|
throw new Error(
|
|
6813
6856
|
`Relation property name conflict: filtered entity '${n.target.name}' uses targetProperty '${n.targetProperty}', but this property name is already defined on base entity '${c[0]}'. Filtered entities inherit all relation properties from their base entities, so you cannot redefine the same property name. Please use a different property name for this relation.`
|
|
@@ -6816,19 +6859,19 @@ class le {
|
|
|
6816
6859
|
});
|
|
6817
6860
|
const e = /* @__PURE__ */ new Map(), t = (n, o, c) => {
|
|
6818
6861
|
if (!o) return;
|
|
6819
|
-
const
|
|
6820
|
-
let
|
|
6821
|
-
|
|
6822
|
-
let d =
|
|
6823
|
-
d ||
|
|
6862
|
+
const l = this.resolveEndpointRootName(n);
|
|
6863
|
+
let u = e.get(l);
|
|
6864
|
+
u || e.set(l, u = /* @__PURE__ */ new Map());
|
|
6865
|
+
let d = u.get(o);
|
|
6866
|
+
d || u.set(o, d = { relations: /* @__PURE__ */ new Set(), declarers: /* @__PURE__ */ new Set() }), d.relations.add(c), d.declarers.add(n.name);
|
|
6824
6867
|
};
|
|
6825
6868
|
this.relations.forEach((n) => {
|
|
6826
6869
|
t(n.source, n.sourceProperty, n), t(n.target, n.targetProperty, n);
|
|
6827
6870
|
}), e.forEach((n, o) => {
|
|
6828
|
-
n.forEach((c,
|
|
6871
|
+
n.forEach((c, l) => {
|
|
6829
6872
|
if (c.relations.size > 1)
|
|
6830
6873
|
throw new Error(
|
|
6831
|
-
`Relation property name conflict: property '${
|
|
6874
|
+
`Relation property name conflict: property '${l}' is declared by multiple relations within the same base record family '${o}' (declared on: ${Array.from(c.declarers).join(", ")}). Each relation property name must be unique across the base entity and all its filtered entities — otherwise the relations silently overwrite each other in the shared attribute namespace.`
|
|
6832
6875
|
);
|
|
6833
6876
|
});
|
|
6834
6877
|
});
|
|
@@ -6836,8 +6879,8 @@ class le {
|
|
|
6836
6879
|
const o = this.resolveEndpointRootName(n);
|
|
6837
6880
|
let c = i.get(o);
|
|
6838
6881
|
c || i.set(o, c = /* @__PURE__ */ new Map());
|
|
6839
|
-
for (const
|
|
6840
|
-
c.has(
|
|
6882
|
+
for (const l of n.properties || [])
|
|
6883
|
+
c.has(l.name) || c.set(l.name, n.name);
|
|
6841
6884
|
};
|
|
6842
6885
|
this.entities.forEach(r), this.relations.forEach(r);
|
|
6843
6886
|
const a = (n, o) => {
|
|
@@ -7001,15 +7044,15 @@ class le {
|
|
|
7001
7044
|
}
|
|
7002
7045
|
validateRecordNames() {
|
|
7003
7046
|
this.entities.forEach((e) => {
|
|
7004
|
-
if (typeof e.name != "string" || !
|
|
7005
|
-
throw new Error(`Entity name "${e.name}" is invalid. Entity names must match ${
|
|
7047
|
+
if (typeof e.name != "string" || !ue.VALID_NAME_FORMAT.test(e.name))
|
|
7048
|
+
throw new Error(`Entity name "${e.name}" is invalid. Entity names must match ${ue.VALID_NAME_FORMAT} (letters, numbers and underscore only).`);
|
|
7006
7049
|
}), this.relations.forEach((e) => {
|
|
7007
|
-
if (e.name !== void 0 && !
|
|
7008
|
-
throw new Error(`Relation name "${e.name}" is invalid. Relation names must match ${
|
|
7009
|
-
if (!
|
|
7010
|
-
throw new Error(`Relation sourceProperty "${e.sourceProperty}" is invalid. Property names must match ${
|
|
7011
|
-
if (e.targetProperty !== void 0 && !
|
|
7012
|
-
throw new Error(`Relation targetProperty "${e.targetProperty}" is invalid. Property names must match ${
|
|
7050
|
+
if (e.name !== void 0 && !ue.VALID_NAME_FORMAT.test(e.name))
|
|
7051
|
+
throw new Error(`Relation name "${e.name}" is invalid. Relation names must match ${ue.VALID_NAME_FORMAT} (letters, numbers and underscore only).`);
|
|
7052
|
+
if (!ue.VALID_NAME_FORMAT.test(e.sourceProperty))
|
|
7053
|
+
throw new Error(`Relation sourceProperty "${e.sourceProperty}" is invalid. Property names must match ${ue.VALID_NAME_FORMAT} (letters, numbers and underscore only).`);
|
|
7054
|
+
if (e.targetProperty !== void 0 && !ue.VALID_NAME_FORMAT.test(e.targetProperty))
|
|
7055
|
+
throw new Error(`Relation targetProperty "${e.targetProperty}" is invalid. Property names must match ${ue.VALID_NAME_FORMAT} (letters, numbers and underscore only).`);
|
|
7013
7056
|
});
|
|
7014
7057
|
}
|
|
7015
7058
|
buildMap() {
|
|
@@ -7041,7 +7084,7 @@ class le {
|
|
|
7041
7084
|
const [a, ...n] = r.split(".");
|
|
7042
7085
|
let o = a;
|
|
7043
7086
|
for (let c = 0; c < n.length; c++) {
|
|
7044
|
-
const
|
|
7087
|
+
const l = n[c], u = this.map.records[o].attributes[l], d = u.linkName, h = this.map.links[d], { relType: m, sourceRecord: f, targetRecord: p } = h;
|
|
7045
7088
|
T(
|
|
7046
7089
|
m[0] === "1" && m[1] === "1" && f !== p,
|
|
7047
7090
|
`only 1:1 can merge: ${a}.${n.slice(0, c + 1).join(".")}`
|
|
@@ -7049,27 +7092,27 @@ class le {
|
|
|
7049
7092
|
const y = f === o ? p : f, b = this.combineRecordTable(o, y, d);
|
|
7050
7093
|
if (b)
|
|
7051
7094
|
throw new Error(`conflict found when join ${d}, ${b.join(",")} already merged with ${o}`);
|
|
7052
|
-
h.mergedTo = "combined", i.push(h), o =
|
|
7095
|
+
h.mergedTo = "combined", i.push(h), o = u.recordName, delete e[d], delete t[d];
|
|
7053
7096
|
}
|
|
7054
7097
|
}), Object.values(e).forEach((r) => {
|
|
7055
7098
|
if (r.isFilteredRelation) return;
|
|
7056
7099
|
const { sourceRecord: a, targetRecord: n, recordName: o } = r;
|
|
7057
7100
|
if (a === n) {
|
|
7058
|
-
const
|
|
7059
|
-
this.joinTables(a, o,
|
|
7101
|
+
const l = this.map.records[o].attributes.source.linkName;
|
|
7102
|
+
this.joinTables(a, o, l) || (r.mergedTo = "source", i.push(r));
|
|
7060
7103
|
return;
|
|
7061
7104
|
}
|
|
7062
7105
|
const c = this.combineRecordTable(a, n, o);
|
|
7063
7106
|
if (!c)
|
|
7064
7107
|
r.mergedTo = "combined", i.push(r);
|
|
7065
7108
|
else {
|
|
7066
|
-
const
|
|
7067
|
-
this.joinTables(a, o,
|
|
7109
|
+
const l = this.map.records[o].attributes.source.linkName;
|
|
7110
|
+
this.joinTables(a, o, l) || (this.mergeLog.push(c), r.mergedTo = "source", i.push(r));
|
|
7068
7111
|
}
|
|
7069
7112
|
}), Object.values(t).forEach((r) => {
|
|
7070
7113
|
if (r.isFilteredRelation) return;
|
|
7071
|
-
const { relType: a, sourceRecord: n, targetRecord: o, recordName: c } = r,
|
|
7072
|
-
this.joinTables(
|
|
7114
|
+
const { relType: a, sourceRecord: n, targetRecord: o, recordName: c } = r, l = a[1] !== "n", u = l ? n : o, d = this.map.records[c].attributes[l ? "source" : "target"].linkName;
|
|
7115
|
+
this.joinTables(u, c, d) || (r.mergedTo = l ? "source" : "target", i.push(r));
|
|
7073
7116
|
}), Object.values(this.map.links).forEach((r) => {
|
|
7074
7117
|
r.isFilteredRelation || r.isSourceRelation && (r.mergedTo = "source");
|
|
7075
7118
|
}), i.forEach((r) => {
|
|
@@ -7098,8 +7141,8 @@ class le {
|
|
|
7098
7141
|
const a = this.map.records[i.resolvedBaseRecordName];
|
|
7099
7142
|
a && Object.entries(i.attributes).forEach(([n, o]) => {
|
|
7100
7143
|
if (o.isRecord) return;
|
|
7101
|
-
const c = o,
|
|
7102
|
-
|
|
7144
|
+
const c = o, l = a.attributes[n];
|
|
7145
|
+
l && l.field && (c.field = l.field, c.fieldType = l.fieldType);
|
|
7103
7146
|
});
|
|
7104
7147
|
}
|
|
7105
7148
|
}), Object.entries(this.map.links).forEach(([t, i]) => {
|
|
@@ -7309,12 +7352,12 @@ ${Object.values(this.tables[e].columns).map((i) => ` "${i.name}" ${i.fieldTyp
|
|
|
7309
7352
|
if (this.aliasManager.registerTablePath(t), r >= a) return;
|
|
7310
7353
|
const n = this.map.records[e];
|
|
7311
7354
|
n && Object.entries(n.attributes).forEach(([o, c]) => {
|
|
7312
|
-
const
|
|
7313
|
-
if (!
|
|
7314
|
-
const
|
|
7315
|
-
if (this.aliasManager.registerTablePath(d), this.aliasManager.registerTablePath(`${d}_SOURCE`), this.aliasManager.registerTablePath(`${d}_TARGET`), this.aliasManager.registerTablePath(`REL_${d}`), this.aliasManager.registerTablePath(`REL_${d}_SOURCE`), this.aliasManager.registerTablePath(`REL_${d}_TARGET`), i.has(
|
|
7355
|
+
const l = c;
|
|
7356
|
+
if (!l.isRecord) return;
|
|
7357
|
+
const u = l.recordName, d = `${t}_${o}`;
|
|
7358
|
+
if (this.aliasManager.registerTablePath(d), this.aliasManager.registerTablePath(`${d}_SOURCE`), this.aliasManager.registerTablePath(`${d}_TARGET`), this.aliasManager.registerTablePath(`REL_${d}`), this.aliasManager.registerTablePath(`REL_${d}_SOURCE`), this.aliasManager.registerTablePath(`REL_${d}_TARGET`), i.has(u)) return;
|
|
7316
7359
|
const h = new Set(i);
|
|
7317
|
-
h.add(
|
|
7360
|
+
h.add(u), this.generateAliasesForRecord(u, d, h, r + 1, a);
|
|
7318
7361
|
});
|
|
7319
7362
|
}
|
|
7320
7363
|
}
|
|
@@ -7469,7 +7512,7 @@ Stack trace:`, r.stack.split(`
|
|
|
7469
7512
|
return null;
|
|
7470
7513
|
}
|
|
7471
7514
|
}
|
|
7472
|
-
var
|
|
7515
|
+
var ie = /* @__PURE__ */ ((s) => (s.LOW = "low", s.MEDIUM = "medium", s.HIGH = "high", s.CRITICAL = "critical", s))(ie || {}), ve = /* @__PURE__ */ ((s) => (s.VALIDATION = "validation", s.PERMISSION = "permission", s.COMPUTATION = "computation", s.STORAGE = "storage", s.INTERACTION = "interaction", s.ACTIVITY = "activity", s.SYSTEM = "system", s.CONFIGURATION = "configuration", s))(ve || {});
|
|
7473
7516
|
class V extends ae {
|
|
7474
7517
|
constructor(e, t = {}) {
|
|
7475
7518
|
super(e, {
|
|
@@ -7483,14 +7526,14 @@ class V extends ae {
|
|
|
7483
7526
|
...t.context
|
|
7484
7527
|
},
|
|
7485
7528
|
causedBy: t.causedBy
|
|
7486
|
-
}), this.handleName = t.handleName, this.computationName = t.computationName, this.dataContext = t.dataContext, this.computationPhase = t.computationPhase, this.severity = t.severity ||
|
|
7529
|
+
}), this.handleName = t.handleName, this.computationName = t.computationName, this.dataContext = t.dataContext, this.computationPhase = t.computationPhase, this.severity = t.severity || ie.MEDIUM;
|
|
7487
7530
|
}
|
|
7488
7531
|
}
|
|
7489
7532
|
class ci extends V {
|
|
7490
7533
|
constructor(e, t = {}) {
|
|
7491
7534
|
super(e, {
|
|
7492
7535
|
...t,
|
|
7493
|
-
severity:
|
|
7536
|
+
severity: ie.HIGH,
|
|
7494
7537
|
context: {
|
|
7495
7538
|
errorType: "ComputationStateError",
|
|
7496
7539
|
stateKey: t.stateKey,
|
|
@@ -7505,7 +7548,7 @@ class Se extends V {
|
|
|
7505
7548
|
constructor(e, t = {}) {
|
|
7506
7549
|
super(e, {
|
|
7507
7550
|
...t,
|
|
7508
|
-
severity:
|
|
7551
|
+
severity: ie.MEDIUM,
|
|
7509
7552
|
context: {
|
|
7510
7553
|
errorType: "ComputationDataDepError",
|
|
7511
7554
|
depName: t.depName,
|
|
@@ -7520,7 +7563,7 @@ class z extends V {
|
|
|
7520
7563
|
constructor(e, t = {}) {
|
|
7521
7564
|
super(e, {
|
|
7522
7565
|
...t,
|
|
7523
|
-
severity:
|
|
7566
|
+
severity: ie.HIGH,
|
|
7524
7567
|
context: {
|
|
7525
7568
|
...t.context,
|
|
7526
7569
|
errorType: "ComputationProtocolError"
|
|
@@ -7541,7 +7584,7 @@ class Hr extends ae {
|
|
|
7541
7584
|
retryable: !1,
|
|
7542
7585
|
driver: t.driver,
|
|
7543
7586
|
rawCode: t.rawCode,
|
|
7544
|
-
severity:
|
|
7587
|
+
severity: ie.MEDIUM,
|
|
7545
7588
|
category: ve.STORAGE
|
|
7546
7589
|
},
|
|
7547
7590
|
causedBy: t.causedBy
|
|
@@ -7562,14 +7605,14 @@ class Ce extends ae {
|
|
|
7562
7605
|
retryable: !1,
|
|
7563
7606
|
driver: t.driver,
|
|
7564
7607
|
rawCode: t.rawCode,
|
|
7565
|
-
severity:
|
|
7608
|
+
severity: ie.HIGH,
|
|
7566
7609
|
category: ve.STORAGE
|
|
7567
7610
|
},
|
|
7568
7611
|
causedBy: t.causedBy
|
|
7569
7612
|
}), this.constraintName = t.constraintName, this.recordName = t.recordName, this.properties = t.properties;
|
|
7570
7613
|
}
|
|
7571
7614
|
}
|
|
7572
|
-
function
|
|
7615
|
+
function ln(s) {
|
|
7573
7616
|
let e = s;
|
|
7574
7617
|
const t = /* @__PURE__ */ new Set();
|
|
7575
7618
|
for (; e && !t.has(e); ) {
|
|
@@ -7577,7 +7620,7 @@ function un(s) {
|
|
|
7577
7620
|
e instanceof Error ? e = (e instanceof ae ? e.causedBy : void 0) || e.cause : e = void 0;
|
|
7578
7621
|
}
|
|
7579
7622
|
}
|
|
7580
|
-
function
|
|
7623
|
+
function un(s, e) {
|
|
7581
7624
|
for (const t of e) {
|
|
7582
7625
|
const i = s[t];
|
|
7583
7626
|
if (typeof i == "string" && i.length > 0) return i;
|
|
@@ -7593,7 +7636,7 @@ function dn(s) {
|
|
|
7593
7636
|
};
|
|
7594
7637
|
}
|
|
7595
7638
|
function xt(s, e) {
|
|
7596
|
-
const t = s && typeof s == "object" ? s : {}, i = s instanceof Error ? s.message : String(s), r = t.code ?? t.errno, a =
|
|
7639
|
+
const t = s && typeof s == "object" ? s : {}, i = s instanceof Error ? s.message : String(s), r = t.code ?? t.errno, a = un(t, ["constraint", "constraintName", "index", "sqlMessage"]), n = dn(i), o = r === "23505" || r === "SQLITE_CONSTRAINT_UNIQUE" || r === "SQLITE_CONSTRAINT" || r === 1062 || i.includes("UNIQUE constraint failed") || i.includes("duplicate key value violates unique constraint") || i.includes("Duplicate entry");
|
|
7597
7640
|
return {
|
|
7598
7641
|
driver: e?.constructor?.name,
|
|
7599
7642
|
message: i,
|
|
@@ -7616,7 +7659,7 @@ class Be extends ae {
|
|
|
7616
7659
|
...t.context
|
|
7617
7660
|
},
|
|
7618
7661
|
causedBy: t.causedBy
|
|
7619
|
-
}), this.schedulingPhase = t.schedulingPhase, this.failedComputations = t.failedComputations, this.severity =
|
|
7662
|
+
}), this.schedulingPhase = t.schedulingPhase, this.failedComputations = t.failedComputations, this.severity = ie.HIGH;
|
|
7620
7663
|
}
|
|
7621
7664
|
}
|
|
7622
7665
|
class br extends ae {
|
|
@@ -7632,7 +7675,7 @@ class br extends ae {
|
|
|
7632
7675
|
...t.context
|
|
7633
7676
|
},
|
|
7634
7677
|
causedBy: t.causedBy
|
|
7635
|
-
}), this.sideEffectName = t.sideEffectName, this.recordName = t.recordName, this.mutationType = t.mutationType, this.severity =
|
|
7678
|
+
}), this.sideEffectName = t.sideEffectName, this.recordName = t.recordName, this.mutationType = t.mutationType, this.severity = ie.MEDIUM;
|
|
7636
7679
|
}
|
|
7637
7680
|
}
|
|
7638
7681
|
class Ni extends ae {
|
|
@@ -7648,7 +7691,7 @@ class Ni extends ae {
|
|
|
7648
7691
|
...t.context
|
|
7649
7692
|
},
|
|
7650
7693
|
causedBy: t.causedBy
|
|
7651
|
-
}), this.checkType = t.checkType, this.fieldName = t.fieldName, this.payload = t.payload, this.evaluationError = t.evaluationError, this.error = t.evaluationError, this.type = t.type || e, this.severity = t.severity ||
|
|
7694
|
+
}), this.checkType = t.checkType, this.fieldName = t.fieldName, this.payload = t.payload, this.evaluationError = t.evaluationError, this.error = t.evaluationError, this.type = t.type || e, this.severity = t.severity || ie.HIGH;
|
|
7652
7695
|
}
|
|
7653
7696
|
/**
|
|
7654
7697
|
* Helper factory methods for common condition error scenarios
|
|
@@ -7660,7 +7703,7 @@ class Ni extends ae {
|
|
|
7660
7703
|
fieldName: e,
|
|
7661
7704
|
payload: i,
|
|
7662
7705
|
evaluationError: r,
|
|
7663
|
-
severity:
|
|
7706
|
+
severity: ie.MEDIUM,
|
|
7664
7707
|
type: a
|
|
7665
7708
|
// For backward compatibility
|
|
7666
7709
|
});
|
|
@@ -7669,7 +7712,7 @@ class Ni extends ae {
|
|
|
7669
7712
|
return new Ni(`Condition check failed: ${e.data.name}`, {
|
|
7670
7713
|
checkType: "condition",
|
|
7671
7714
|
evaluationError: e,
|
|
7672
|
-
severity:
|
|
7715
|
+
severity: ie.HIGH,
|
|
7673
7716
|
context: t,
|
|
7674
7717
|
type: "condition check failed"
|
|
7675
7718
|
// For backward compatibility
|
|
@@ -7732,7 +7775,7 @@ class Wr {
|
|
|
7732
7775
|
return this.data.transfers.filter((t) => wr(e, t.trigger));
|
|
7733
7776
|
}
|
|
7734
7777
|
}
|
|
7735
|
-
const Ao = 0,
|
|
7778
|
+
const Ao = 0, li = 1, Io = 2;
|
|
7736
7779
|
class zr {
|
|
7737
7780
|
constructor(e, t) {
|
|
7738
7781
|
this.controller = e, this.scheduler = t, this.sourceMaps = [], this.sourceMapTree = {}, this.filteredToPhysicalName = /* @__PURE__ */ new Map(), this.knownRecordNames = /* @__PURE__ */ new Set();
|
|
@@ -7793,6 +7836,15 @@ class zr {
|
|
|
7793
7836
|
* 被写进了注释,但只在数据驱动轨道上被执行——注释没有执行力,不变量有。
|
|
7794
7837
|
*/
|
|
7795
7838
|
assertListenerReachable(e) {
|
|
7839
|
+
if (e.type !== "create" && e.type !== "update" && e.type !== "delete")
|
|
7840
|
+
throw new z(
|
|
7841
|
+
`${this.describeComputation(e.computation)} listens to "${e.type}" events of record "${e.recordName}", but mutation events only have type 'create' | 'update' | 'delete' — this listener can never fire and the computation would stay silently stale. Check the trigger/eventDep type for a typo.`,
|
|
7842
|
+
{
|
|
7843
|
+
handleName: e.computation.constructor.name,
|
|
7844
|
+
dataContext: e.computation.dataContext,
|
|
7845
|
+
computationPhase: "source-map-initialization"
|
|
7846
|
+
}
|
|
7847
|
+
);
|
|
7796
7848
|
if (!this.knownRecordNames.has(e.recordName)) {
|
|
7797
7849
|
const t = this.controller.dict.some((i) => i.name === e.recordName) ? ` "${e.recordName}" is a global dictionary: dictionary changes are emitted as events on the "${Z}" record — declare { recordName: '${Z}', type: 'update', record: { key: '${e.recordName}' } } instead.` : " Check for a typo, and make sure the entity/relation is registered on the Controller.";
|
|
7798
7850
|
throw new z(
|
|
@@ -7843,7 +7895,7 @@ class zr {
|
|
|
7843
7895
|
}
|
|
7844
7896
|
);
|
|
7845
7897
|
const o = this.convertDataDepToERMutationEventsSourceMap(a, n, i);
|
|
7846
|
-
r[n.phase ||
|
|
7898
|
+
r[n.phase || li].push(...o);
|
|
7847
7899
|
}), i.dataContext.type === "property" && Object.values(i.dataDeps).some((a) => a.type === "global")) {
|
|
7848
7900
|
const a = i.dataContext.host.name;
|
|
7849
7901
|
if (!r.some(
|
|
@@ -7853,7 +7905,7 @@ class zr {
|
|
|
7853
7905
|
type: "records",
|
|
7854
7906
|
source: i.dataContext.host
|
|
7855
7907
|
};
|
|
7856
|
-
r[
|
|
7908
|
+
r[li].push(...this.convertDataDepToERMutationEventsSourceMap("_self", o, i, "create"));
|
|
7857
7909
|
}
|
|
7858
7910
|
}
|
|
7859
7911
|
r.forEach((a, n) => {
|
|
@@ -7862,7 +7914,7 @@ class zr {
|
|
|
7862
7914
|
} else {
|
|
7863
7915
|
const { eventDeps: r } = i;
|
|
7864
7916
|
for (const a of Object.values(r))
|
|
7865
|
-
t[a.phase ||
|
|
7917
|
+
t[a.phase || li].push({
|
|
7866
7918
|
type: a.type,
|
|
7867
7919
|
recordName: a.recordName,
|
|
7868
7920
|
record: a.record,
|
|
@@ -8036,37 +8088,37 @@ class zr {
|
|
|
8036
8088
|
return t;
|
|
8037
8089
|
}
|
|
8038
8090
|
convertAttrsToERMutationEventsSourceMap(e, t, i, r, a, n = !1) {
|
|
8039
|
-
const o = [], c = [],
|
|
8040
|
-
if (i.forEach((
|
|
8041
|
-
if (typeof
|
|
8042
|
-
c.push(
|
|
8043
|
-
else if (
|
|
8091
|
+
const o = [], c = [], l = [];
|
|
8092
|
+
if (i.forEach((u) => {
|
|
8093
|
+
if (typeof u == "string" && u !== "*")
|
|
8094
|
+
c.push(u);
|
|
8095
|
+
else if (u === "*")
|
|
8044
8096
|
c.push("*");
|
|
8045
|
-
else if (Array.isArray(
|
|
8046
|
-
|
|
8097
|
+
else if (Array.isArray(u))
|
|
8098
|
+
l.push(u);
|
|
8047
8099
|
else
|
|
8048
|
-
throw new Error(`unknown attribute type: ${
|
|
8100
|
+
throw new Error(`unknown attribute type: ${u}`);
|
|
8049
8101
|
}), c.length > 0) {
|
|
8050
|
-
let
|
|
8051
|
-
r.length > 0 && (r.at(-1) === "&" ?
|
|
8102
|
+
let u = t;
|
|
8103
|
+
r.length > 0 && (r.at(-1) === "&" ? u = this.controller.system.storage.getRelationName(t, r.slice(0, -1).join(".")) : u = this.controller.system.storage.getEntityName(t, r.join("."))), n && o.push({
|
|
8052
8104
|
dataDep: e,
|
|
8053
8105
|
type: "create",
|
|
8054
|
-
recordName:
|
|
8106
|
+
recordName: u,
|
|
8055
8107
|
sourceRecordName: t,
|
|
8056
8108
|
targetPath: r,
|
|
8057
8109
|
computation: a
|
|
8058
8110
|
}), o.push({
|
|
8059
8111
|
dataDep: e,
|
|
8060
8112
|
type: "update",
|
|
8061
|
-
recordName:
|
|
8113
|
+
recordName: u,
|
|
8062
8114
|
sourceRecordName: t,
|
|
8063
8115
|
targetPath: r,
|
|
8064
8116
|
attributes: c,
|
|
8065
8117
|
computation: a
|
|
8066
8118
|
});
|
|
8067
8119
|
}
|
|
8068
|
-
return
|
|
8069
|
-
o.push(...this.convertRelationAttrToERMutationEventsSourceMap(e, t, d.attributeQuery, r.concat(
|
|
8120
|
+
return l.forEach(([u, d]) => {
|
|
8121
|
+
o.push(...this.convertRelationAttrToERMutationEventsSourceMap(e, t, d.attributeQuery, r.concat(u), a));
|
|
8070
8122
|
}), o;
|
|
8071
8123
|
}
|
|
8072
8124
|
convertRelationAttrToERMutationEventsSourceMap(e, t, i, r, a) {
|
|
@@ -8330,16 +8382,16 @@ function Xr(s, e, t) {
|
|
|
8330
8382
|
);
|
|
8331
8383
|
};
|
|
8332
8384
|
(!Array.isArray(r.keys) || r.keys.length === 0) && a("trigger.keys must be a non-empty array of property names. An empty array matches every update vacuously — omit keys entirely to match any update.");
|
|
8333
|
-
const n = r.keys, o = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(["id"]),
|
|
8334
|
-
if (!
|
|
8335
|
-
const
|
|
8336
|
-
for (;
|
|
8337
|
-
const m =
|
|
8385
|
+
const n = r.keys, o = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(["id"]), l = s.entities.find((m) => m.name === r.recordName) ?? s.relations.find((m) => m.name === r.recordName);
|
|
8386
|
+
if (!l) continue;
|
|
8387
|
+
const u = [l], d = /* @__PURE__ */ new Set();
|
|
8388
|
+
for (; u.length; ) {
|
|
8389
|
+
const m = u.pop();
|
|
8338
8390
|
if (!(!m || d.has(m))) {
|
|
8339
8391
|
d.add(m), m.name && o.add(m.name);
|
|
8340
8392
|
for (const f of m.properties ?? []) c.add(f.name);
|
|
8341
|
-
m.baseEntity &&
|
|
8342
|
-
for (const f of m.inputEntities ?? [])
|
|
8393
|
+
m.baseEntity && u.push(m.baseEntity), m.baseRelation && u.push(m.baseRelation);
|
|
8394
|
+
for (const f of m.inputEntities ?? []) u.push(f);
|
|
8343
8395
|
}
|
|
8344
8396
|
}
|
|
8345
8397
|
const h = /* @__PURE__ */ new Set();
|
|
@@ -8372,15 +8424,15 @@ async function fn(s, e, t, i) {
|
|
|
8372
8424
|
`StateMachine computation of property "${t.host.name}.${t.id.name}" ${i()}: computeTarget returned a {source, target} endpoint form, but the host is not a relation. Return {id} (or an array of {id}) identifying the ${t.host.name} record(s) to transition.`,
|
|
8373
8425
|
{ handleName: "StateMachine", computationPhase: "compute-dirty-records" }
|
|
8374
8426
|
);
|
|
8375
|
-
const c = Array.isArray(o) ? [o[0]].flat() : [o.source].flat(),
|
|
8376
|
-
for (const
|
|
8377
|
-
for (const d of
|
|
8378
|
-
if (!
|
|
8427
|
+
const c = Array.isArray(o) ? [o[0]].flat() : [o.source].flat(), l = Array.isArray(o) ? [o[1]].flat() : [o.target].flat();
|
|
8428
|
+
for (const u of c)
|
|
8429
|
+
for (const d of l) {
|
|
8430
|
+
if (!u?.id || !d?.id)
|
|
8379
8431
|
throw new z(
|
|
8380
|
-
`StateMachine computation of property "${t.host.name}.${t.id.name}" ${i()}: computeTarget returned an endpoint form whose ${
|
|
8432
|
+
`StateMachine computation of property "${t.host.name}.${t.id.name}" ${i()}: computeTarget returned an endpoint form whose ${u?.id ? "target" : "source"} has no id (got ${JSON.stringify({ source: u, target: d })}). Every endpoint must be {id} (or an array of {id}); return undefined to skip the transfer explicitly.`,
|
|
8381
8433
|
{ handleName: "StateMachine", computationPhase: "compute-dirty-records" }
|
|
8382
8434
|
);
|
|
8383
|
-
const h = k.atom({ key: "source.id", value: ["=",
|
|
8435
|
+
const h = k.atom({ key: "source.id", value: ["=", u.id] }).and({ key: "target.id", value: ["=", d.id] }), m = await s.system.storage.find(t.host.name, h, void 0, ["id"]);
|
|
8384
8436
|
n.push(...m);
|
|
8385
8437
|
}
|
|
8386
8438
|
} else if (typeof o == "object" && o.id !== void 0)
|
|
@@ -8603,8 +8655,8 @@ class Ge {
|
|
|
8603
8655
|
let c = this.relation.baseRelation || this.relation;
|
|
8604
8656
|
for (; c.baseRelation; )
|
|
8605
8657
|
c = c.baseRelation;
|
|
8606
|
-
const
|
|
8607
|
-
_(
|
|
8658
|
+
const l = c.type.split(":");
|
|
8659
|
+
_(l[this.isSource ? 1 : 0] === "n", `property-level ${r.computationName} computation argument must be an x:n relation. ${i.host.name}.${t.property}" is a ${this.isSource ? l.join(":") : l.slice().reverse().join(":")} relation`);
|
|
8608
8660
|
}
|
|
8609
8661
|
this.relationAttr = this.isSource ? this.relation.sourceProperty : this.relation.targetProperty, this.relatedRecordName = this.isSource ? this.relation.target.name : this.relation.source.name, this.property = t.property || this.relationAttr, this.reverseProperty = this.isSource ? this.relation.targetProperty : this.relation.sourceProperty;
|
|
8610
8662
|
let a = this.relation;
|
|
@@ -8684,12 +8736,12 @@ class Ge {
|
|
|
8684
8736
|
);
|
|
8685
8737
|
if (!c)
|
|
8686
8738
|
return U.fullRecompute(`relation record ${o} not found for ${X(this.dataContext)}`);
|
|
8687
|
-
const
|
|
8688
|
-
if (!
|
|
8739
|
+
const l = c[this.relationSide];
|
|
8740
|
+
if (!l)
|
|
8689
8741
|
return U.fullRecompute(`relation ${this.relationSide} endpoint missing for ${X(this.dataContext)}`);
|
|
8690
|
-
|
|
8691
|
-
const
|
|
8692
|
-
return d instanceof U ? d : this.applyDelta(n,
|
|
8742
|
+
l[v] = c;
|
|
8743
|
+
const u = this.computeItemValue(l, r), d = await this.replaceItemState(c, u);
|
|
8744
|
+
return d instanceof U ? d : this.applyDelta(n, u, d.oldValue, 1);
|
|
8693
8745
|
}
|
|
8694
8746
|
if (a.type === "delete" && a.recordName === this.relation.name) {
|
|
8695
8747
|
let o;
|
|
@@ -8706,12 +8758,12 @@ class Ge {
|
|
|
8706
8758
|
);
|
|
8707
8759
|
if (!c)
|
|
8708
8760
|
return U.fullRecompute(`relation record not found by ${o} for ${X(this.dataContext)}`);
|
|
8709
|
-
const
|
|
8710
|
-
if (!
|
|
8761
|
+
const l = c[this.relationSide];
|
|
8762
|
+
if (!l)
|
|
8711
8763
|
return U.fullRecompute(`relation ${this.relationSide} endpoint missing for ${X(this.dataContext)}`);
|
|
8712
|
-
|
|
8713
|
-
const
|
|
8714
|
-
return d instanceof U ? d : this.applyDelta(n,
|
|
8764
|
+
l[v] = c;
|
|
8765
|
+
const u = this.computeItemValue(l, r), d = await this.replaceItemState(c, u);
|
|
8766
|
+
return d instanceof U ? d : this.applyDelta(n, u, d.oldValue, 0);
|
|
8715
8767
|
}
|
|
8716
8768
|
return U.fullRecompute(`unknown related mutation event for ${X(this.dataContext)}`);
|
|
8717
8769
|
}
|
|
@@ -9097,8 +9149,8 @@ async function Li(s, e, t = {}) {
|
|
|
9097
9149
|
}
|
|
9098
9150
|
if (Dn(o)) {
|
|
9099
9151
|
if (a < i) {
|
|
9100
|
-
const c = Nr[Math.min(a - 1, Nr.length - 1)],
|
|
9101
|
-
await Ln(c +
|
|
9152
|
+
const c = Nr[Math.min(a - 1, Nr.length - 1)], l = Math.floor(Math.random() * c);
|
|
9153
|
+
await Ln(c + l);
|
|
9102
9154
|
continue;
|
|
9103
9155
|
}
|
|
9104
9156
|
throw new It(
|
|
@@ -9187,11 +9239,11 @@ class Fn {
|
|
|
9187
9239
|
const i = this.dataContext, r = [];
|
|
9188
9240
|
if (t.type === "create") {
|
|
9189
9241
|
const a = E.atom({ key: "id", value: ["=", t.record.id] }), n = this.dataDeps._source, o = await this.controller.system.storage.findOne(n.source.name, a, void 0, n.attributeQuery), c = await this.transformCallback.call(this.controller, o);
|
|
9190
|
-
(Array.isArray(c) ? c : [c]).forEach((
|
|
9191
|
-
|
|
9242
|
+
(Array.isArray(c) ? c : [c]).forEach((u, d) => {
|
|
9243
|
+
u && (vt(u, this.dataContext), r.push({
|
|
9192
9244
|
type: "insert",
|
|
9193
9245
|
data: {
|
|
9194
|
-
...
|
|
9246
|
+
...u,
|
|
9195
9247
|
[this.state.sourceRecordId.key]: t.record.id,
|
|
9196
9248
|
[this.state.transformIndex.key]: d
|
|
9197
9249
|
}
|
|
@@ -9203,38 +9255,38 @@ class Fn {
|
|
|
9203
9255
|
const a = t.oldRecord?.id ?? t.record.id;
|
|
9204
9256
|
let n = [];
|
|
9205
9257
|
if (t.type === "update") {
|
|
9206
|
-
const
|
|
9207
|
-
|
|
9258
|
+
const u = this.dataDeps._source, d = await this.controller.system.storage.atomic.lockRecord(
|
|
9259
|
+
u.source.name,
|
|
9208
9260
|
a,
|
|
9209
|
-
|
|
9261
|
+
u.attributeQuery
|
|
9210
9262
|
);
|
|
9211
9263
|
if (d) {
|
|
9212
9264
|
const h = await this.transformCallback.call(this.controller, d);
|
|
9213
9265
|
n = Array.isArray(h) ? h : [h];
|
|
9214
9266
|
}
|
|
9215
9267
|
}
|
|
9216
|
-
const o = E.atom({ key: this.state.sourceRecordId.key, value: ["=", a] }),
|
|
9217
|
-
n.forEach((
|
|
9218
|
-
|
|
9268
|
+
const o = E.atom({ key: this.state.sourceRecordId.key, value: ["=", a] }), l = (await this.controller.system.storage.atomic.lockRows(i.id.name, o, ["*"])).reduce((u, d) => (u[Number(d[this.state.transformIndex.key])] = d, u), {});
|
|
9269
|
+
n.forEach((u, d) => {
|
|
9270
|
+
u && (vt(u, this.dataContext), l[d] ? (r.push({
|
|
9219
9271
|
type: "update",
|
|
9220
9272
|
data: {
|
|
9221
|
-
...
|
|
9273
|
+
...u,
|
|
9222
9274
|
[this.state.sourceRecordId.key]: a,
|
|
9223
9275
|
[this.state.transformIndex.key]: d
|
|
9224
9276
|
},
|
|
9225
|
-
affectedId:
|
|
9226
|
-
}), delete
|
|
9277
|
+
affectedId: l[d].id
|
|
9278
|
+
}), delete l[d]) : r.push({
|
|
9227
9279
|
type: "insert",
|
|
9228
9280
|
data: {
|
|
9229
|
-
...
|
|
9281
|
+
...u,
|
|
9230
9282
|
[this.state.sourceRecordId.key]: a,
|
|
9231
9283
|
[this.state.transformIndex.key]: d
|
|
9232
9284
|
}
|
|
9233
9285
|
}));
|
|
9234
|
-
}), Object.values(
|
|
9286
|
+
}), Object.values(l).forEach((u) => {
|
|
9235
9287
|
r.push({
|
|
9236
9288
|
type: "delete",
|
|
9237
|
-
affectedId:
|
|
9289
|
+
affectedId: u.id
|
|
9238
9290
|
});
|
|
9239
9291
|
});
|
|
9240
9292
|
}
|
|
@@ -9618,7 +9670,7 @@ class Qn extends ze {
|
|
|
9618
9670
|
super(e, t, i, { computationName: "Summation", requireAttributeQueryField: !0 }), this.itemStateKey = "itemValue", this.emptyItemValue = 0, this.sumFieldPath = Yt(this.args.attributeQuery, () => `Summation computation of ${X(i)}`);
|
|
9619
9671
|
}
|
|
9620
9672
|
static {
|
|
9621
|
-
this.computationType =
|
|
9673
|
+
this.computationType = lt;
|
|
9622
9674
|
}
|
|
9623
9675
|
static {
|
|
9624
9676
|
this.contextType = "global";
|
|
@@ -9648,7 +9700,7 @@ class jn extends Ge {
|
|
|
9648
9700
|
super(e, t, i, { computationName: "Summation", requireAttributeQueryField: !0 }), this.itemStateKey = "itemResult", this.emptyItemValue = 0, this.sumFieldPath = Yt(this.args.attributeQuery, () => `Summation computation of ${X(i)}`);
|
|
9649
9701
|
}
|
|
9650
9702
|
static {
|
|
9651
|
-
this.computationType =
|
|
9703
|
+
this.computationType = lt;
|
|
9652
9704
|
}
|
|
9653
9705
|
static {
|
|
9654
9706
|
this.contextType = "property";
|
|
@@ -9685,7 +9737,7 @@ class Kn extends ze {
|
|
|
9685
9737
|
super(e, t, i, { computationName: "Average", requireAttributeQueryField: !0 }), this.itemStateKey = "itemValue", this.emptyItemValue = 0, this.avgFieldPath = Yt(this.args.attributeQuery, () => `Average computation of ${X(i)}`);
|
|
9686
9738
|
}
|
|
9687
9739
|
static {
|
|
9688
|
-
this.computationType =
|
|
9740
|
+
this.computationType = ut;
|
|
9689
9741
|
}
|
|
9690
9742
|
static {
|
|
9691
9743
|
this.contextType = "global";
|
|
@@ -9724,7 +9776,7 @@ class Wn extends Ge {
|
|
|
9724
9776
|
super(e, t, i, { computationName: "Average", requireAttributeQueryField: !0 }), this.itemStateKey = "itemResult", this.emptyItemValue = 0, this.avgFieldPath = Yt(this.args.attributeQuery, () => `Average computation of ${X(i)}`);
|
|
9725
9777
|
}
|
|
9726
9778
|
static {
|
|
9727
|
-
this.computationType =
|
|
9779
|
+
this.computationType = ut;
|
|
9728
9780
|
}
|
|
9729
9781
|
static {
|
|
9730
9782
|
this.contextType = "property";
|
|
@@ -9772,37 +9824,37 @@ class Zt {
|
|
|
9772
9824
|
const [n, o] = a, c = {
|
|
9773
9825
|
controller: this.controller,
|
|
9774
9826
|
state: this.state,
|
|
9775
|
-
getState: (
|
|
9827
|
+
getState: (l) => this.state[l]
|
|
9776
9828
|
};
|
|
9777
9829
|
return await this.computeCallback.call(c, n, o);
|
|
9778
9830
|
}
|
|
9779
9831
|
}), t.incrementalCompute && (this.incrementalComputeCallback = t.incrementalCompute, this.incrementalCompute = async (...a) => {
|
|
9780
9832
|
if (this.incrementalComputeCallback) {
|
|
9781
|
-
const [n, o, c,
|
|
9833
|
+
const [n, o, c, l] = a, u = {
|
|
9782
9834
|
controller: this.controller,
|
|
9783
9835
|
state: this.state,
|
|
9784
9836
|
getState: (d) => this.state[d]
|
|
9785
9837
|
};
|
|
9786
|
-
return await this.incrementalComputeCallback.call(
|
|
9838
|
+
return await this.incrementalComputeCallback.call(u, n, o, c, l);
|
|
9787
9839
|
}
|
|
9788
9840
|
return U.fullRecompute("No incrementalCompute defined");
|
|
9789
9841
|
}), t.incrementalPatchCompute && (this.incrementalPatchComputeCallback = t.incrementalPatchCompute, this.incrementalPatchCompute = async (...a) => {
|
|
9790
9842
|
if (this.incrementalPatchComputeCallback) {
|
|
9791
|
-
const [n, o, c,
|
|
9843
|
+
const [n, o, c, l] = a, u = {
|
|
9792
9844
|
controller: this.controller,
|
|
9793
9845
|
state: this.state,
|
|
9794
9846
|
getState: (d) => this.state[d]
|
|
9795
9847
|
};
|
|
9796
|
-
return await this.incrementalPatchComputeCallback.call(
|
|
9848
|
+
return await this.incrementalPatchComputeCallback.call(u, n, o, c, l);
|
|
9797
9849
|
}
|
|
9798
9850
|
}), t.createState && (this.createStateCallback = t.createState), t.getInitialValue && (this.getInitialValueCallback = t.getInitialValue), t.asyncReturn && (this.asyncReturnCallback = t.asyncReturn, this.asyncReturn = async (...a) => {
|
|
9799
9851
|
if (this.asyncReturnCallback) {
|
|
9800
|
-
const [n, o, c] = a,
|
|
9852
|
+
const [n, o, c] = a, l = {
|
|
9801
9853
|
controller: this.controller,
|
|
9802
9854
|
state: this.state,
|
|
9803
|
-
getState: (
|
|
9855
|
+
getState: (u) => this.state[u]
|
|
9804
9856
|
};
|
|
9805
|
-
return await this.asyncReturnCallback.call(
|
|
9857
|
+
return await this.asyncReturnCallback.call(l, n, o, c);
|
|
9806
9858
|
}
|
|
9807
9859
|
}), (t.incrementalCompute || t.incrementalPatchCompute) && !t.planIncremental && !t.incrementalDataDeps)
|
|
9808
9860
|
throw new z("Custom incremental computation must declare planIncremental or incrementalDataDeps", {
|
|
@@ -10133,7 +10185,7 @@ function ca(s) {
|
|
|
10133
10185
|
function cs(s, e) {
|
|
10134
10186
|
return `computation:property:${s}.${e}:ScopedSequence`;
|
|
10135
10187
|
}
|
|
10136
|
-
const
|
|
10188
|
+
const ui = "_ASYNC_TASK_";
|
|
10137
10189
|
class Bt {
|
|
10138
10190
|
constructor(e, t, i, r, a) {
|
|
10139
10191
|
this.controller = e, this.computationsHandles = /* @__PURE__ */ new Map(), this.computationHandleMap = /* @__PURE__ */ new Map(), this.registeredMutationListeners = [], this.erMutationEventSources = [], this.dataSourceMapTree = {}, this.scopedSequenceScopeGuards = [], this.propagationContext = new Ai(), this.plainValuePropertyNamesBySource = /* @__PURE__ */ new WeakMap(), this.sourceMapManager = new zr(this.controller, this), this.buildComputationHandleMap(a);
|
|
@@ -10150,16 +10202,16 @@ class Bt {
|
|
|
10150
10202
|
c.computation && n.push({ dataContext: { type: "property", host: o, id: c }, args: c.computation });
|
|
10151
10203
|
});
|
|
10152
10204
|
}), i.forEach((o) => {
|
|
10153
|
-
o.properties?.forEach((
|
|
10154
|
-
|
|
10205
|
+
o.properties?.forEach((l) => {
|
|
10206
|
+
l.computation && n.push({ dataContext: { type: "property", host: o, id: l }, args: l.computation });
|
|
10155
10207
|
});
|
|
10156
10208
|
});
|
|
10157
10209
|
for (const o of n) {
|
|
10158
|
-
const c = o.dataContext,
|
|
10159
|
-
_(!!
|
|
10160
|
-
const d =
|
|
10161
|
-
_(!!d, `cannot find Computation handle for ${
|
|
10162
|
-
const h = new d(this.controller,
|
|
10210
|
+
const c = o.dataContext, l = o.args, u = this.computationHandleMap.get(l.constructor);
|
|
10211
|
+
_(!!u, `cannot find Computation handle map for ${l.constructor.displayName || l.constructor.name}`);
|
|
10212
|
+
const d = u[c.type];
|
|
10213
|
+
_(!!d, `cannot find Computation handle for ${l.constructor.displayName || l.constructor.name} with context type ${c.type}`);
|
|
10214
|
+
const h = new d(this.controller, l, c);
|
|
10163
10215
|
if (this.computationsHandles.set(c.id, h), this.isAsyncComputation(h)) {
|
|
10164
10216
|
const m = this.getAsyncTaskRecordKey(h);
|
|
10165
10217
|
if (h.dataContext.type === "property") {
|
|
@@ -10411,12 +10463,12 @@ class Bt {
|
|
|
10411
10463
|
for (const o of t.scope || []) {
|
|
10412
10464
|
const c = o.path.split(".")[0];
|
|
10413
10465
|
if (o.type === "ref") {
|
|
10414
|
-
const
|
|
10415
|
-
(
|
|
10466
|
+
const l = this.controller.relations.find(
|
|
10467
|
+
(u) => u.source?.name === r && u.sourceProperty === c || u.target?.name === r && u.targetProperty === c
|
|
10416
10468
|
);
|
|
10417
|
-
|
|
10418
|
-
relationName:
|
|
10419
|
-
hostIsSource:
|
|
10469
|
+
l ? n.set(c, {
|
|
10470
|
+
relationName: l.name,
|
|
10471
|
+
hostIsSource: l.source?.name === r && l.sourceProperty === c
|
|
10420
10472
|
}) : a.push(c);
|
|
10421
10473
|
} else
|
|
10422
10474
|
a.push(c);
|
|
@@ -10649,8 +10701,8 @@ class Bt {
|
|
|
10649
10701
|
getAsyncTaskRecordKey(e) {
|
|
10650
10702
|
if (e.dataContext.type === "property") {
|
|
10651
10703
|
const t = e.dataContext;
|
|
10652
|
-
return `${
|
|
10653
|
-
} else return e.dataContext.type === "global" ? `${
|
|
10704
|
+
return `${ui}_${t.host.name}_${t.id.name}`;
|
|
10705
|
+
} else return e.dataContext.type === "global" ? `${ui}_${e.dataContext.id.name}` : `${ui}_${e.dataContext.type}_${e.dataContext.id?.name}`;
|
|
10654
10706
|
}
|
|
10655
10707
|
getComputationName(e) {
|
|
10656
10708
|
return e.args.name || e.args.constructor.displayName;
|
|
@@ -10775,7 +10827,7 @@ class Bt {
|
|
|
10775
10827
|
requiresFullRecompute: !0,
|
|
10776
10828
|
reason: "records match over related path requires full recompute"
|
|
10777
10829
|
};
|
|
10778
|
-
const i = this.getPlainValuePropertyNames(e.source), r = t.oldRecord, a = t.type === "update" ? { ...t.oldRecord || {}, ...t.record || {} } : t.record, n = t.type === "create" ? !1 : this.evaluateRecordsMatch(e.match, r, i), o = t.type === "delete" ? !1 : this.evaluateRecordsMatch(e.match, a, i);
|
|
10830
|
+
const i = this.getPlainValuePropertyNames(e.source), r = t.type === "delete" ? t.record : t.oldRecord, a = t.type === "update" ? { ...t.oldRecord || {}, ...t.record || {} } : t.record, n = t.type === "create" ? !1 : this.evaluateRecordsMatch(e.match, r, i), o = t.type === "delete" ? !1 : this.evaluateRecordsMatch(e.match, a, i);
|
|
10779
10831
|
return n === void 0 || o === void 0 ? {
|
|
10780
10832
|
membershipChange: "unknown",
|
|
10781
10833
|
requiresFullRecompute: !0,
|
|
@@ -10799,15 +10851,15 @@ class Bt {
|
|
|
10799
10851
|
};
|
|
10800
10852
|
}
|
|
10801
10853
|
buildDataDepEventContext(e, t) {
|
|
10802
|
-
const i = Object.entries(e.dataDeps || {}).find(([, d]) => d === t.dataDep), r = i?.[0], a = i?.[1], n = new Set(e.primaryDataDepKeys || []), o = r === void 0 ? "unknown" : r === "_self" ? "self" : n.has(r) ? "primary" : "external", c = this.hasUnsafeRecordsModifier(a),
|
|
10854
|
+
const i = Object.entries(e.dataDeps || {}).find(([, d]) => d === t.dataDep), r = i?.[0], a = i?.[1], n = new Set(e.primaryDataDepKeys || []), o = r === void 0 ? "unknown" : r === "_self" ? "self" : n.has(r) ? "primary" : "external", c = this.hasUnsafeRecordsModifier(a), l = this.buildMatchEventContext(a, t), u = !!(c || l.requiresFullRecompute);
|
|
10803
10855
|
return {
|
|
10804
10856
|
depKey: r,
|
|
10805
10857
|
dep: a,
|
|
10806
10858
|
depRole: o,
|
|
10807
|
-
membershipChange: c ? "maybe" :
|
|
10808
|
-
requiresFullRecompute:
|
|
10809
|
-
skip:
|
|
10810
|
-
reason: c ? `records data dependency ${r} has modifier membership risk` :
|
|
10859
|
+
membershipChange: c ? "maybe" : l.membershipChange || "none",
|
|
10860
|
+
requiresFullRecompute: u,
|
|
10861
|
+
skip: l.skip,
|
|
10862
|
+
reason: c ? `records data dependency ${r} has modifier membership risk` : l.reason
|
|
10811
10863
|
};
|
|
10812
10864
|
}
|
|
10813
10865
|
normalizeLastValuePolicy(e) {
|
|
@@ -10888,7 +10940,7 @@ class Bt {
|
|
|
10888
10940
|
});
|
|
10889
10941
|
return { mode: "full", result: await e.compute(h, i) };
|
|
10890
10942
|
}
|
|
10891
|
-
const c = this.normalizePlanDataDepKeys(e, o.dataDepKeys),
|
|
10943
|
+
const c = this.normalizePlanDataDepKeys(e, o.dataDepKeys), l = await this.resolveSelectedDataDeps(e, i, c), u = await this.resolvePlannedLastValue(e, i, o, n), d = e.incrementalCompute ? await e.incrementalCompute(u, t, i, l) : await e.incrementalPatchCompute(u, t, i, l);
|
|
10892
10944
|
if (d instanceof Gr) {
|
|
10893
10945
|
if (this.controller.system.storage.getTransactionIsolation() !== "SERIALIZABLE")
|
|
10894
10946
|
throw new de(`full recompute ${e.args.name || e.args.constructor.displayName}`);
|
|
@@ -11011,7 +11063,7 @@ class Bt {
|
|
|
11011
11063
|
return;
|
|
11012
11064
|
a = c.result, n = c.mode;
|
|
11013
11065
|
} else if (r || !e.incrementalCompute && !e.incrementalPatchCompute) {
|
|
11014
|
-
const c = e,
|
|
11066
|
+
const c = e, l = c.dataDeps ? await this.resolveAllDataDeps(c, i) : {};
|
|
11015
11067
|
if (!c.compute)
|
|
11016
11068
|
throw new V("compute must be defined for full computation", {
|
|
11017
11069
|
handleName: e.constructor.name,
|
|
@@ -11019,18 +11071,18 @@ class Bt {
|
|
|
11019
11071
|
dataContext: e.dataContext,
|
|
11020
11072
|
computationPhase: "full-compute"
|
|
11021
11073
|
});
|
|
11022
|
-
a = await c.compute(
|
|
11074
|
+
a = await c.compute(l, i), n = "full";
|
|
11023
11075
|
} else if (e.incrementalCompute) {
|
|
11024
11076
|
let c;
|
|
11025
11077
|
if (e.useLastValue)
|
|
11026
11078
|
try {
|
|
11027
11079
|
c = await this.controller.retrieveLastValue(e.dataContext, i);
|
|
11028
|
-
} catch (
|
|
11080
|
+
} catch (l) {
|
|
11029
11081
|
throw new ci("Failed to retrieve last value for incremental computation", {
|
|
11030
11082
|
handleName: e.constructor.name,
|
|
11031
11083
|
computationName: e.args.constructor.displayName,
|
|
11032
11084
|
dataContext: e.dataContext,
|
|
11033
|
-
causedBy:
|
|
11085
|
+
causedBy: l instanceof Error ? l : new Error(String(l))
|
|
11034
11086
|
});
|
|
11035
11087
|
}
|
|
11036
11088
|
a = await e.incrementalCompute(c, t, i, {}), n = "incremental";
|
|
@@ -11039,12 +11091,12 @@ class Bt {
|
|
|
11039
11091
|
if (e.useLastValue)
|
|
11040
11092
|
try {
|
|
11041
11093
|
c = await this.controller.retrieveLastValue(e.dataContext, i);
|
|
11042
|
-
} catch (
|
|
11094
|
+
} catch (l) {
|
|
11043
11095
|
throw new ci("Failed to retrieve last value for incremental patch computation", {
|
|
11044
11096
|
handleName: e.constructor.name,
|
|
11045
11097
|
computationName: e.args.constructor.displayName,
|
|
11046
11098
|
dataContext: e.dataContext,
|
|
11047
|
-
causedBy:
|
|
11099
|
+
causedBy: l instanceof Error ? l : new Error(String(l))
|
|
11048
11100
|
});
|
|
11049
11101
|
}
|
|
11050
11102
|
a = await e.incrementalPatchCompute(c, t, i, {}), n = "patch";
|
|
@@ -11199,14 +11251,14 @@ class Bt {
|
|
|
11199
11251
|
}
|
|
11200
11252
|
}
|
|
11201
11253
|
const Vi = new Or();
|
|
11202
|
-
function
|
|
11254
|
+
function ls() {
|
|
11203
11255
|
return Vi.getStore()?.effects;
|
|
11204
11256
|
}
|
|
11205
11257
|
function Er(s) {
|
|
11206
11258
|
const e = Vi.getStore();
|
|
11207
11259
|
e?.effects && e.effects.push(...s);
|
|
11208
11260
|
}
|
|
11209
|
-
const
|
|
11261
|
+
const us = new Or(), _i = "_MigrationManifest_", Bi = "current", Pt = "3", ei = "_isDeleted_";
|
|
11210
11262
|
class C extends Error {
|
|
11211
11263
|
constructor(e, t) {
|
|
11212
11264
|
super(e), this.details = t, this.name = new.target.name;
|
|
@@ -11222,7 +11274,7 @@ class Ui extends C {
|
|
|
11222
11274
|
}
|
|
11223
11275
|
class he extends C {
|
|
11224
11276
|
}
|
|
11225
|
-
class
|
|
11277
|
+
class la extends C {
|
|
11226
11278
|
}
|
|
11227
11279
|
function Ne(s) {
|
|
11228
11280
|
return Lr("sha256").update(fe(s)).digest("hex");
|
|
@@ -11262,25 +11314,25 @@ function hs(s) {
|
|
|
11262
11314
|
for (const t of s) {
|
|
11263
11315
|
const i = `${t.kind}:${t.namePath}`;
|
|
11264
11316
|
if (e.get(i))
|
|
11265
|
-
throw new
|
|
11317
|
+
throw new la(`Migration identity is ambiguous for ${t.namePath}`);
|
|
11266
11318
|
e.set(i, t);
|
|
11267
11319
|
}
|
|
11268
11320
|
}
|
|
11269
11321
|
function L(s) {
|
|
11270
11322
|
return s.type === "property" ? `property:${s.host.name}.${s.id.name}` : `${s.type}:${s.id.name}`;
|
|
11271
11323
|
}
|
|
11272
|
-
function
|
|
11324
|
+
function ua(s) {
|
|
11273
11325
|
const e = s.constructor?.computationType?.displayName || s.args._type || s.args.constructor?.displayName || s.constructor?.displayName;
|
|
11274
11326
|
if (!e) {
|
|
11275
11327
|
const t = s.dataContext ? ` for ${L(s.dataContext)}` : "";
|
|
11276
|
-
throw new
|
|
11328
|
+
throw new la(
|
|
11277
11329
|
`Cannot derive a stable migration identity${t}: the computation type must declare an explicit name. Set a static 'displayName' on the computation type (or handle class), or an '_type' string on the computation args. Class names are not accepted because minified builds rewrite them.`
|
|
11278
11330
|
);
|
|
11279
11331
|
}
|
|
11280
11332
|
return e;
|
|
11281
11333
|
}
|
|
11282
11334
|
function yt(s) {
|
|
11283
|
-
return `computation:${L(s.dataContext)}:${
|
|
11335
|
+
return `computation:${L(s.dataContext)}:${ua(s)}`;
|
|
11284
11336
|
}
|
|
11285
11337
|
function ps(s) {
|
|
11286
11338
|
if (s.allocation?.kind !== "scoped-sequence" || !s.allocation.initializeFrom) return;
|
|
@@ -11432,8 +11484,8 @@ function Rs(s) {
|
|
|
11432
11484
|
return Ne(Ti(s));
|
|
11433
11485
|
}
|
|
11434
11486
|
function vs(s, e = !1) {
|
|
11435
|
-
const t = s.args, i = ys(s), r = gs(s), a = bs(s), n = a.map((S) => S.key), o = yt(s), c = L(s.dataContext),
|
|
11436
|
-
type:
|
|
11487
|
+
const t = s.args, i = ys(s), r = gs(s), a = bs(s), n = a.map((S) => S.key), o = yt(s), c = L(s.dataContext), l = s.dataContext.type === "entity" || s.dataContext.type === "relation" ? s.dataContext.id.name : void 0, u = ua(s), d = xe("computation", o, s.args.uuid), h = ws(t, e), m = Rs(t), { allocation: f, scopeSignature: p, allocationSignature: y } = ca(t), b = Ne({
|
|
11488
|
+
type: u,
|
|
11437
11489
|
dataContext: c,
|
|
11438
11490
|
dataDeps: i,
|
|
11439
11491
|
eventDeps: r,
|
|
@@ -11442,9 +11494,9 @@ function vs(s, e = !1) {
|
|
|
11442
11494
|
hasIncrementalCompute: typeof s.incrementalCompute == "function",
|
|
11443
11495
|
hasIncrementalPatchCompute: typeof s.incrementalPatchCompute == "function"
|
|
11444
11496
|
}), g = Ne({ stateKeys: n, boundStates: a }), w = Ne({
|
|
11445
|
-
type:
|
|
11497
|
+
type: u,
|
|
11446
11498
|
dataContext: c,
|
|
11447
|
-
outputRecord:
|
|
11499
|
+
outputRecord: l,
|
|
11448
11500
|
outputProperty: s.dataContext.type === "property" ? s.dataContext.id.name : void 0,
|
|
11449
11501
|
deps: i,
|
|
11450
11502
|
eventDeps: r,
|
|
@@ -11461,9 +11513,9 @@ function vs(s, e = !1) {
|
|
|
11461
11513
|
return {
|
|
11462
11514
|
id: o,
|
|
11463
11515
|
identity: d,
|
|
11464
|
-
type:
|
|
11516
|
+
type: u,
|
|
11465
11517
|
dataContext: c,
|
|
11466
|
-
outputRecord:
|
|
11518
|
+
outputRecord: l,
|
|
11467
11519
|
outputProperty: s.dataContext.type === "property" ? s.dataContext.id.name : void 0,
|
|
11468
11520
|
deps: i.map((S) => ({ type: String(S.type), source: S.source, phase: S.phase, attributeQuery: S.attributeQuery })),
|
|
11469
11521
|
eventDeps: r,
|
|
@@ -11471,12 +11523,12 @@ function vs(s, e = !1) {
|
|
|
11471
11523
|
boundStates: a,
|
|
11472
11524
|
asyncReturn: typeof s.asyncReturn == "function",
|
|
11473
11525
|
owner: s.dataContext.type === "entity" || s.dataContext.type === "relation" ? "exclusive" : void 0,
|
|
11474
|
-
ownershipProof:
|
|
11526
|
+
ownershipProof: l ? {
|
|
11475
11527
|
kind: "computed-output",
|
|
11476
11528
|
owner: "exclusive",
|
|
11477
11529
|
ownerComputationId: o,
|
|
11478
11530
|
dataContext: c,
|
|
11479
|
-
outputRecord:
|
|
11531
|
+
outputRecord: l
|
|
11480
11532
|
} : void 0,
|
|
11481
11533
|
outputSignature: b,
|
|
11482
11534
|
stateSignature: g,
|
|
@@ -11491,15 +11543,15 @@ function vs(s, e = !1) {
|
|
|
11491
11543
|
}
|
|
11492
11544
|
function Et(s, e = s.system.storage.schema, t = {}) {
|
|
11493
11545
|
const i = [
|
|
11494
|
-
...s.entities.map((
|
|
11495
|
-
const d = xe("entity", `entity:${
|
|
11546
|
+
...s.entities.map((u) => {
|
|
11547
|
+
const d = xe("entity", `entity:${u.name}`, u.uuid);
|
|
11496
11548
|
return {
|
|
11497
11549
|
id: Ve(d),
|
|
11498
11550
|
identity: d,
|
|
11499
|
-
name:
|
|
11551
|
+
name: u.name,
|
|
11500
11552
|
kind: "entity",
|
|
11501
|
-
properties: (
|
|
11502
|
-
const m = xe("property", `property:${
|
|
11553
|
+
properties: (u.properties || []).map((h) => {
|
|
11554
|
+
const m = xe("property", `property:${u.name}.${h.name}`, h.uuid);
|
|
11503
11555
|
return {
|
|
11504
11556
|
id: Ve(m),
|
|
11505
11557
|
identity: m,
|
|
@@ -11511,15 +11563,15 @@ function Et(s, e = s.system.storage.schema, t = {}) {
|
|
|
11511
11563
|
})
|
|
11512
11564
|
};
|
|
11513
11565
|
}),
|
|
11514
|
-
...s.relations.map((
|
|
11515
|
-
const d = xe("relation", `relation:${
|
|
11566
|
+
...s.relations.map((u) => {
|
|
11567
|
+
const d = xe("relation", `relation:${u.name}`, u.uuid);
|
|
11516
11568
|
return {
|
|
11517
11569
|
id: Ve(d),
|
|
11518
11570
|
identity: d,
|
|
11519
|
-
name:
|
|
11571
|
+
name: u.name,
|
|
11520
11572
|
kind: "relation",
|
|
11521
|
-
properties: (
|
|
11522
|
-
const m = xe("property", `property:${
|
|
11573
|
+
properties: (u.properties || []).map((h) => {
|
|
11574
|
+
const m = xe("property", `property:${u.name}.${h.name}`, h.uuid);
|
|
11523
11575
|
return {
|
|
11524
11576
|
id: Ve(m),
|
|
11525
11577
|
identity: m,
|
|
@@ -11531,45 +11583,45 @@ function Et(s, e = s.system.storage.schema, t = {}) {
|
|
|
11531
11583
|
})
|
|
11532
11584
|
};
|
|
11533
11585
|
})
|
|
11534
|
-
], r = s.relations.map((
|
|
11535
|
-
const d = xe("relation", `relation:${
|
|
11586
|
+
], r = s.relations.map((u) => {
|
|
11587
|
+
const d = xe("relation", `relation:${u.name}`, u.uuid);
|
|
11536
11588
|
return {
|
|
11537
11589
|
id: Ve(d),
|
|
11538
11590
|
identity: d,
|
|
11539
|
-
name:
|
|
11540
|
-
source:
|
|
11541
|
-
target:
|
|
11542
|
-
sourceProperty:
|
|
11543
|
-
targetProperty:
|
|
11544
|
-
type:
|
|
11591
|
+
name: u.name,
|
|
11592
|
+
source: u.source.name,
|
|
11593
|
+
target: u.target.name,
|
|
11594
|
+
sourceProperty: u.sourceProperty,
|
|
11595
|
+
targetProperty: u.targetProperty,
|
|
11596
|
+
type: u.type
|
|
11545
11597
|
};
|
|
11546
|
-
}), a = s.dict.map((
|
|
11547
|
-
const d = xe("dictionary", `dictionary:${
|
|
11598
|
+
}), a = s.dict.map((u) => {
|
|
11599
|
+
const d = xe("dictionary", `dictionary:${u.name}`, u.uuid);
|
|
11548
11600
|
return {
|
|
11549
11601
|
id: Ve(d),
|
|
11550
11602
|
identity: d,
|
|
11551
|
-
name:
|
|
11552
|
-
type:
|
|
11553
|
-
collection:
|
|
11554
|
-
computed: !!
|
|
11603
|
+
name: u.name,
|
|
11604
|
+
type: u.type,
|
|
11605
|
+
collection: u.collection === !0,
|
|
11606
|
+
computed: !!u.computation
|
|
11555
11607
|
};
|
|
11556
|
-
}), n = Array.from(s.scheduler.computationsHandles.values()).map((
|
|
11608
|
+
}), n = Array.from(s.scheduler.computationsHandles.values()).map((u) => vs(u, t.includeFunctionText === !0)), o = fs(n);
|
|
11557
11609
|
hs([
|
|
11558
|
-
...i.flatMap((
|
|
11559
|
-
...a.map((
|
|
11560
|
-
...n.map((
|
|
11610
|
+
...i.flatMap((u) => [u.identity, ...u.properties.map((d) => d.identity)]),
|
|
11611
|
+
...a.map((u) => u.identity),
|
|
11612
|
+
...n.map((u) => u.identity)
|
|
11561
11613
|
]);
|
|
11562
|
-
const c = n.map((
|
|
11563
|
-
...
|
|
11564
|
-
functionSignature:
|
|
11565
|
-
...
|
|
11614
|
+
const c = n.map((u) => ({
|
|
11615
|
+
...u,
|
|
11616
|
+
functionSignature: u.functionSignature ? {
|
|
11617
|
+
...u.functionSignature,
|
|
11566
11618
|
text: void 0
|
|
11567
11619
|
} : void 0
|
|
11568
|
-
})),
|
|
11620
|
+
})), l = Ei({ records: i, relations: r, dictionaries: a, computations: c, sequences: o, storage: e });
|
|
11569
11621
|
return {
|
|
11570
11622
|
version: 2,
|
|
11571
11623
|
frameworkVersion: Pt,
|
|
11572
|
-
modelHash: Ne(
|
|
11624
|
+
modelHash: Ne(l),
|
|
11573
11625
|
records: i,
|
|
11574
11626
|
relations: r,
|
|
11575
11627
|
dictionaries: a,
|
|
@@ -11637,16 +11689,16 @@ function fa(s, e, t) {
|
|
|
11637
11689
|
if (i.startsWith("property:")) {
|
|
11638
11690
|
const r = i.match(/^property:([^.]*)\.([^.]*)$/);
|
|
11639
11691
|
if (!r) return !1;
|
|
11640
|
-
const [, a, n] = r, o = s.records.find((d) => d.name === a), c = e.records.find((d) => d.name === a),
|
|
11641
|
-
return
|
|
11692
|
+
const [, a, n] = r, o = s.records.find((d) => d.name === a), c = e.records.find((d) => d.name === a), l = o?.properties.find((d) => d.name === n), u = c?.properties.find((d) => d.name === n);
|
|
11693
|
+
return l?.computed === !1 && u?.computed === !0;
|
|
11642
11694
|
}
|
|
11643
11695
|
if (i.startsWith("entity:") || i.startsWith("relation:")) {
|
|
11644
|
-
const [r, a] = i.split(":"), n = s.records.find((
|
|
11696
|
+
const [r, a] = i.split(":"), n = s.records.find((u) => u.kind === r && u.name === a), o = e.records.find((u) => u.kind === r && u.name === a);
|
|
11645
11697
|
if (!n || !o) return !1;
|
|
11646
|
-
const c = s.computations.some((
|
|
11647
|
-
(
|
|
11698
|
+
const c = s.computations.some((u) => u.dataContext === i), l = e.computations.some(
|
|
11699
|
+
(u) => u.id === t.id && u.dataContext === i && u.ownershipProof?.kind === "computed-output"
|
|
11648
11700
|
);
|
|
11649
|
-
return !c &&
|
|
11701
|
+
return !c && l;
|
|
11650
11702
|
}
|
|
11651
11703
|
return !1;
|
|
11652
11704
|
}
|
|
@@ -11684,20 +11736,20 @@ async function ks(s, e, t, i) {
|
|
|
11684
11736
|
if (!$s(o)) continue;
|
|
11685
11737
|
const c = o.logicalPath;
|
|
11686
11738
|
if (i.storage.records.some((h) => h.recordName === c) || !wa(t, i, c) || await Es(s, t, c) !== 0) continue;
|
|
11687
|
-
const
|
|
11739
|
+
const u = o.oldPhysicalPath;
|
|
11688
11740
|
r.add(c);
|
|
11689
11741
|
const d = "empty fact record was removed from the new schema and requires explicit approval before cleanup";
|
|
11690
11742
|
a.set(`empty-fact-record-removal:${c}`, {
|
|
11691
11743
|
kind: "empty-fact-record-removal",
|
|
11692
11744
|
id: `empty-fact-record-removal:${c}`,
|
|
11693
11745
|
recordName: c,
|
|
11694
|
-
tableName:
|
|
11746
|
+
tableName: u,
|
|
11695
11747
|
expectedCount: 0,
|
|
11696
11748
|
reason: d
|
|
11697
11749
|
}), n.set(`empty-fact-record-removal:${c}`, {
|
|
11698
11750
|
kind: "empty-fact-record-removal",
|
|
11699
11751
|
recordName: c,
|
|
11700
|
-
tableName:
|
|
11752
|
+
tableName: u,
|
|
11701
11753
|
expectedCount: 0,
|
|
11702
11754
|
reason: d
|
|
11703
11755
|
});
|
|
@@ -11719,8 +11771,8 @@ async function Ts(s, e, t, i, r) {
|
|
|
11719
11771
|
if (o.kind !== "computation" || o.recommendation !== "needs-review" || !e.requiredDecisions.find(
|
|
11720
11772
|
(h) => h.kind === "computation" && h.id === o.id && h.recommendedDecision === "unrebuildable"
|
|
11721
11773
|
)) continue;
|
|
11722
|
-
const
|
|
11723
|
-
!
|
|
11774
|
+
const l = i.computations.find((h) => h.id === o.id), u = l ? ms(l) : void 0;
|
|
11775
|
+
!u || (await Qt(s, t, u.hostRecord, ["id"], r)).length !== 0 || (a.set(re(u), u), n = !0);
|
|
11724
11776
|
}
|
|
11725
11777
|
return n && (e.requiredDecisions = Array.from(a.values()), e.summary = {
|
|
11726
11778
|
...e.summary,
|
|
@@ -11786,10 +11838,10 @@ async function Ra(s, e, t, i) {
|
|
|
11786
11838
|
if (e.startsWith("property:")) {
|
|
11787
11839
|
const n = e.match(/^property:([^.]*)\.([^.]*)$/);
|
|
11788
11840
|
if (!n) throw new C(`Invalid property data context for computation takeover: ${e}`);
|
|
11789
|
-
const [, o, c] = n,
|
|
11841
|
+
const [, o, c] = n, l = await Qt(s, t, o, ["id", c], i);
|
|
11790
11842
|
return {
|
|
11791
|
-
expectedExistingCount:
|
|
11792
|
-
expectedHostCount:
|
|
11843
|
+
expectedExistingCount: l.filter((u) => u[c] !== void 0 && u[c] !== null).length,
|
|
11844
|
+
expectedHostCount: l.length
|
|
11793
11845
|
};
|
|
11794
11846
|
}
|
|
11795
11847
|
const [, r] = e.split(":"), a = await Qt(s, t, r, ["id"], i);
|
|
@@ -11802,17 +11854,17 @@ async function Is(s, e, t, i, r) {
|
|
|
11802
11854
|
const a = new Map(e.changes.map((c) => [ji(c), c])), n = new Map(e.requiredDecisions.map((c) => [re(c), c])), o = new Map(e.safety.destructiveScopes.map((c) => [`${c.dataContext}:${c.recordName || ""}`, c]));
|
|
11803
11855
|
for (const c of i.computations) {
|
|
11804
11856
|
if (!fa(t, i, c)) continue;
|
|
11805
|
-
const
|
|
11857
|
+
const l = ya(c.dataContext), u = await Ra(s, c.dataContext, t, r), d = {
|
|
11806
11858
|
kind: "computation-takeover",
|
|
11807
11859
|
dataContext: c.dataContext,
|
|
11808
11860
|
computationId: c.id,
|
|
11809
|
-
targetType:
|
|
11861
|
+
targetType: l,
|
|
11810
11862
|
previousAuthority: "fact",
|
|
11811
11863
|
nextAuthority: "computation",
|
|
11812
11864
|
oldDataStrategy: "discard-and-rebuild",
|
|
11813
|
-
expectedExistingCount:
|
|
11814
|
-
expectedHostCount:
|
|
11815
|
-
destructiveScopeRef:
|
|
11865
|
+
expectedExistingCount: u.expectedExistingCount,
|
|
11866
|
+
expectedHostCount: u.expectedHostCount,
|
|
11867
|
+
destructiveScopeRef: l === "property" ? void 0 : `${c.dataContext}:${c.outputRecord || c.dataContext.split(":")[1]}`,
|
|
11816
11868
|
reason: `${c.dataContext} changes from fact authority to computation authority and existing output must be discarded before rebuild`
|
|
11817
11869
|
};
|
|
11818
11870
|
if (a.set(`computation-takeover:${c.dataContext}`, {
|
|
@@ -11820,20 +11872,20 @@ async function Is(s, e, t, i, r) {
|
|
|
11820
11872
|
id: `computation-takeover:${c.dataContext}`,
|
|
11821
11873
|
dataContext: c.dataContext,
|
|
11822
11874
|
computationId: c.id,
|
|
11823
|
-
targetType:
|
|
11875
|
+
targetType: l,
|
|
11824
11876
|
previousAuthority: "fact",
|
|
11825
11877
|
nextAuthority: "computation",
|
|
11826
|
-
expectedExistingCount:
|
|
11827
|
-
expectedHostCount:
|
|
11878
|
+
expectedExistingCount: u.expectedExistingCount,
|
|
11879
|
+
expectedHostCount: u.expectedHostCount,
|
|
11828
11880
|
reason: d.reason
|
|
11829
|
-
}), n.set(re(d), d),
|
|
11881
|
+
}), n.set(re(d), d), l !== "property") {
|
|
11830
11882
|
const h = c.outputRecord || c.dataContext.split(":")[1], m = `${c.dataContext}:${h}`;
|
|
11831
11883
|
if (!o.has(m)) {
|
|
11832
11884
|
const f = {
|
|
11833
11885
|
dataContext: c.dataContext,
|
|
11834
11886
|
recordName: h,
|
|
11835
|
-
ids:
|
|
11836
|
-
count:
|
|
11887
|
+
ids: u.ids || [],
|
|
11888
|
+
count: u.expectedExistingCount,
|
|
11837
11889
|
reason: "fact output records will be discarded during computation takeover"
|
|
11838
11890
|
};
|
|
11839
11891
|
o.set(m, f), n.set(re({ kind: "destructive-scope", ...f }), {
|
|
@@ -11863,9 +11915,9 @@ async function Is(s, e, t, i, r) {
|
|
|
11863
11915
|
}, e;
|
|
11864
11916
|
}
|
|
11865
11917
|
function Ps(s, e, t, i) {
|
|
11866
|
-
const r = [], a = [], n = new Map(s.computations.map((p) => [p.id, p])), o = new Map(e.computations.map((p) => [p.id, p])), c = new Map(s.records.map((p) => [p.id, p])),
|
|
11918
|
+
const r = [], a = [], n = new Map(s.computations.map((p) => [p.id, p])), o = new Map(e.computations.map((p) => [p.id, p])), c = new Map(s.records.map((p) => [p.id, p])), l = new Map(e.records.map((p) => [p.id, p])), u = new Map(s.relations.map((p) => [p.id, p])), d = new Map(e.relations.map((p) => [p.id, p])), h = new Map((s.dictionaries || []).map((p) => [p.id, p])), m = new Map((e.dictionaries || []).map((p) => [p.id, p]));
|
|
11867
11919
|
for (const p of s.records)
|
|
11868
|
-
|
|
11920
|
+
l.has(p.id) || r.push({
|
|
11869
11921
|
kind: "record",
|
|
11870
11922
|
id: p.id,
|
|
11871
11923
|
changeType: "removed",
|
|
@@ -11922,7 +11974,7 @@ function Ps(s, e, t, i) {
|
|
|
11922
11974
|
reason: "relation no longer exists in the new model"
|
|
11923
11975
|
});
|
|
11924
11976
|
for (const p of e.relations) {
|
|
11925
|
-
const y =
|
|
11977
|
+
const y = u.get(p.id);
|
|
11926
11978
|
y ? (y.name !== p.name || y.source !== p.source || y.target !== p.target || y.sourceProperty !== p.sourceProperty || y.targetProperty !== p.targetProperty || y.type !== p.type) && r.push({
|
|
11927
11979
|
kind: "relation",
|
|
11928
11980
|
id: p.id,
|
|
@@ -12066,20 +12118,20 @@ function Ms(s, e, t) {
|
|
|
12066
12118
|
if (!n || n.args?._type === "ScopedSequence") continue;
|
|
12067
12119
|
const o = typeof n.eventDeps == "object", c = typeof n.compute != "function";
|
|
12068
12120
|
if (o || c) {
|
|
12069
|
-
const
|
|
12121
|
+
const l = {
|
|
12070
12122
|
kind: "event-rebuild-handler",
|
|
12071
12123
|
dataContext: a.dataContext,
|
|
12072
12124
|
reason: o ? "event-based computation needs an external migration rebuild handler" : "computation without full compute support needs an external migration rebuild handler"
|
|
12073
12125
|
};
|
|
12074
|
-
r.set(re(
|
|
12126
|
+
r.set(re(l), l);
|
|
12075
12127
|
}
|
|
12076
12128
|
if (typeof n.asyncReturn == "function") {
|
|
12077
|
-
const
|
|
12129
|
+
const l = {
|
|
12078
12130
|
kind: "async-completion-handler",
|
|
12079
12131
|
dataContext: a.dataContext,
|
|
12080
12132
|
reason: "async computation needs an external migration completion handler"
|
|
12081
12133
|
};
|
|
12082
|
-
r.set(re(
|
|
12134
|
+
r.set(re(l), l);
|
|
12083
12135
|
}
|
|
12084
12136
|
}
|
|
12085
12137
|
return s.requiredDecisions = Array.from(r.values()), s.summary = {
|
|
@@ -12099,12 +12151,12 @@ function qs(s, e, t, i, r) {
|
|
|
12099
12151
|
const a = r || s, n = new Set(s.requiredDecisions.map(re)), o = /* @__PURE__ */ new Set([
|
|
12100
12152
|
...a.requiredDecisions.map(re),
|
|
12101
12153
|
...n
|
|
12102
|
-
]), c = new Set(a.changes.map(ji)),
|
|
12154
|
+
]), c = new Set(a.changes.map(ji)), l = /* @__PURE__ */ new Set();
|
|
12103
12155
|
for (const d of s.decisions) {
|
|
12104
12156
|
const h = Ss(d);
|
|
12105
|
-
if (
|
|
12157
|
+
if (l.has(h))
|
|
12106
12158
|
throw new C(`Duplicate migration decision: ${h}`);
|
|
12107
|
-
if (
|
|
12159
|
+
if (l.add(h), d.kind === "computation" && !c.has(`computation:${d.id}`))
|
|
12108
12160
|
throw new C(`Migration decision references a computation that is not present in the approved diff: ${d.id}`);
|
|
12109
12161
|
if (d.kind === "computation-takeover") {
|
|
12110
12162
|
if (!o.has(h))
|
|
@@ -12186,36 +12238,36 @@ function qs(s, e, t, i, r) {
|
|
|
12186
12238
|
throw new C(`Migration rename candidate decision does not match any Phase 1.5 executable review item: ${d.from} -> ${d.to}`);
|
|
12187
12239
|
}
|
|
12188
12240
|
for (const d of a.requiredDecisions)
|
|
12189
|
-
if (!
|
|
12241
|
+
if (!l.has(re(d)))
|
|
12190
12242
|
throw new C(`Missing migration decision for required review item: ${re(d)}`);
|
|
12191
|
-
const
|
|
12243
|
+
const u = new Set(t.computations.map((d) => d.id));
|
|
12192
12244
|
for (const d of s.decisions)
|
|
12193
|
-
if (d.kind === "computation" && !
|
|
12245
|
+
if (d.kind === "computation" && !u.has(d.id))
|
|
12194
12246
|
throw new C(`Migration decision references unknown computation: ${d.id}`);
|
|
12195
12247
|
}
|
|
12196
12248
|
function Ds(s, e, t) {
|
|
12197
|
-
const i = [], r = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), n = new Map(e.computations.map((
|
|
12198
|
-
(d) => d.kind === "scoped-sequence-seed" && d.id ===
|
|
12199
|
-
), c = (
|
|
12200
|
-
(d) => d.kind === "scoped-sequence-no-seed" && d.id ===
|
|
12249
|
+
const i = [], r = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), n = new Map(e.computations.map((u) => [u.id, u])), o = (u) => t.decisions.some(
|
|
12250
|
+
(d) => d.kind === "scoped-sequence-seed" && d.id === u.id && u.allocation?.kind === "scoped-sequence" && u.allocation.initializeFrom
|
|
12251
|
+
), c = (u) => t.decisions.some(
|
|
12252
|
+
(d) => d.kind === "scoped-sequence-no-seed" && d.id === u.id && u.allocation?.kind === "scoped-sequence" && !u.allocation.initializeFrom
|
|
12201
12253
|
);
|
|
12202
|
-
for (const
|
|
12203
|
-
if (
|
|
12204
|
-
const d = n.get(
|
|
12205
|
-
d &&
|
|
12254
|
+
for (const u of t.decisions) {
|
|
12255
|
+
if (u.kind !== "computation") continue;
|
|
12256
|
+
const d = n.get(u.id);
|
|
12257
|
+
d && u.decision !== "unrebuildable" && ((u.decision === "changed" || u.decision === "state-only") && i.push(d), u.decision === "changed" && r.add(u.id), u.decision === "state-only" && a.add(u.id));
|
|
12206
12258
|
}
|
|
12207
|
-
for (const
|
|
12208
|
-
if (!s.computations.some((d) => d.id ===
|
|
12259
|
+
for (const u of e.computations)
|
|
12260
|
+
if (!s.computations.some((d) => d.id === u.id) && !i.some((d) => d.id === u.id)) {
|
|
12209
12261
|
if (t.decisions.some(
|
|
12210
|
-
(h) => h.kind === "computation" && h.id ===
|
|
12211
|
-
) && (o(
|
|
12212
|
-
throw new C(`New computation requires approved changed decision: ${
|
|
12262
|
+
(h) => h.kind === "computation" && h.id === u.id && h.decision === "unrebuildable"
|
|
12263
|
+
) && (o(u) || c(u))) continue;
|
|
12264
|
+
throw new C(`New computation requires approved changed decision: ${u.id}`);
|
|
12213
12265
|
}
|
|
12214
|
-
const
|
|
12215
|
-
const d = n.get(
|
|
12266
|
+
const l = t.decisions.filter((u) => u.kind === "computation" && u.decision === "unrebuildable").filter((u) => {
|
|
12267
|
+
const d = n.get(u.id);
|
|
12216
12268
|
return !(d && (o(d) || c(d)));
|
|
12217
|
-
}).map((
|
|
12218
|
-
return { changedComputations: i, outputChangedIds: r, stateOnlyIds: a, blocking:
|
|
12269
|
+
}).map((u) => ({ kind: "unrebuildable-computation", logicalPath: u.dataContext, reason: u.reason }));
|
|
12270
|
+
return { changedComputations: i, outputChangedIds: r, stateOnlyIds: a, blocking: l };
|
|
12219
12271
|
}
|
|
12220
12272
|
function Os(s) {
|
|
12221
12273
|
return s.decisions.filter((e) => e.kind === "scoped-sequence-seed").map((e) => ({
|
|
@@ -12282,7 +12334,7 @@ function Wi(s, e, t) {
|
|
|
12282
12334
|
if (!Array.isArray(i) || typeof i[0] != "string") return [];
|
|
12283
12335
|
const r = Fs(s, e, i[0]);
|
|
12284
12336
|
if (!r) return [];
|
|
12285
|
-
const a = r.source === e ? r.target : r.source, n = i[1], c = (Array.isArray(n?.attributeQuery) ? n.attributeQuery : []).flatMap((
|
|
12337
|
+
const a = r.source === e ? r.target : r.source, n = i[1], c = (Array.isArray(n?.attributeQuery) ? n.attributeQuery : []).flatMap((l) => typeof l == "string" && l !== "*" && l !== v ? [`property:${a}.${l}`] : Array.isArray(l) && l[0] === v ? [`relation:${r.name}`] : Array.isArray(l) ? Wi(s, a, [l]) : []);
|
|
12286
12338
|
return [`relation:${r.name}`, ...c];
|
|
12287
12339
|
});
|
|
12288
12340
|
}
|
|
@@ -12298,7 +12350,7 @@ function Tr(s, e, t) {
|
|
|
12298
12350
|
if (s.type === "property") {
|
|
12299
12351
|
const i = e.dataContext.match(/^property:([^.]*)\./);
|
|
12300
12352
|
if (!i) return [];
|
|
12301
|
-
const r = i[1], a = Array.isArray(s.attributeQuery) ? s.attributeQuery : [], n = Wi(t, r, a), c = [...a.filter((
|
|
12353
|
+
const r = i[1], a = Array.isArray(s.attributeQuery) ? s.attributeQuery : [], n = Wi(t, r, a), c = [...a.filter((l) => typeof l == "string" && l !== "*").map((l) => `property:${r}.${l}`), ...n];
|
|
12302
12354
|
return c.length ? c : jt(t, r);
|
|
12303
12355
|
}
|
|
12304
12356
|
return [];
|
|
@@ -12324,14 +12376,14 @@ function xr(s, e, t, i = [], r = {}) {
|
|
|
12324
12376
|
const c = (g) => {
|
|
12325
12377
|
const w = g.match(/^property:([^.]*)\._isDeleted_$/);
|
|
12326
12378
|
return w ? jt(e, w[1]) : [];
|
|
12327
|
-
},
|
|
12379
|
+
}, l = /* @__PURE__ */ new Map();
|
|
12328
12380
|
for (const g of e.computations)
|
|
12329
12381
|
for (const w of c(g.dataContext))
|
|
12330
|
-
|
|
12331
|
-
const
|
|
12382
|
+
l.set(w, g);
|
|
12383
|
+
const u = (g) => {
|
|
12332
12384
|
const w = [], R = a.get(g);
|
|
12333
12385
|
R && w.push(R);
|
|
12334
|
-
const S =
|
|
12386
|
+
const S = l.get(g);
|
|
12335
12387
|
return S && S !== R && w.push(S), w;
|
|
12336
12388
|
}, d = new Set(t.map((g) => g.id)), m = [...t.filter((g) => {
|
|
12337
12389
|
const w = n.get(g.id);
|
|
@@ -12355,12 +12407,12 @@ function xr(s, e, t, i = [], r = {}) {
|
|
|
12355
12407
|
if (w) {
|
|
12356
12408
|
for (const R of w.deps)
|
|
12357
12409
|
for (const S of Tr(R, w, e))
|
|
12358
|
-
for (const N of
|
|
12410
|
+
for (const N of u(S))
|
|
12359
12411
|
N.id !== g && d.has(N.id) && b(N.id);
|
|
12360
12412
|
for (const R of w.eventDeps)
|
|
12361
12413
|
for (const S of Cr(R, e))
|
|
12362
12414
|
if (S !== w.dataContext)
|
|
12363
|
-
for (const N of
|
|
12415
|
+
for (const N of u(S))
|
|
12364
12416
|
N.id !== g && d.has(N.id) && b(N.id);
|
|
12365
12417
|
}
|
|
12366
12418
|
f.delete(g), p.add(g), y.push(g);
|
|
@@ -12381,51 +12433,51 @@ function di(s, e) {
|
|
|
12381
12433
|
return `${s || "?"}.${e || "?"}`;
|
|
12382
12434
|
}
|
|
12383
12435
|
function Ar(s, e) {
|
|
12384
|
-
const t = [], i = new Map(s.storage.records.map((
|
|
12385
|
-
for (const
|
|
12386
|
-
if (!r.has(
|
|
12387
|
-
const
|
|
12436
|
+
const t = [], i = new Map(s.storage.records.map((l) => [l.recordName, l])), r = new Map(e.storage.records.map((l) => [l.recordName, l])), a = new Map(s.records.map((l) => [l.name, l])), n = new Map(e.records.map((l) => [l.name, l])), o = (l) => l.startsWith("_ASYNC_TASK__"), c = (l) => s.computations.some((u) => u.outputRecord === l);
|
|
12437
|
+
for (const l of s.storage.records)
|
|
12438
|
+
if (!r.has(l.recordName) && !l.isFiltered) {
|
|
12439
|
+
const u = o(l.recordName) ? "framework-generated async task record cleanup is not supported by compute-route schema migration" : c(l.recordName) ? "computed output record physical cleanup is not supported by compute-route schema migration" : "fact record was removed from the new schema";
|
|
12388
12440
|
t.push({
|
|
12389
12441
|
kind: "unsupported-destructive-schema-change",
|
|
12390
|
-
logicalPath:
|
|
12391
|
-
oldPhysicalPath:
|
|
12392
|
-
reason:
|
|
12442
|
+
logicalPath: l.recordName,
|
|
12443
|
+
oldPhysicalPath: l.tableName,
|
|
12444
|
+
reason: u
|
|
12393
12445
|
});
|
|
12394
12446
|
}
|
|
12395
|
-
for (const
|
|
12396
|
-
const
|
|
12397
|
-
if (!
|
|
12398
|
-
|
|
12447
|
+
for (const l of e.storage.records) {
|
|
12448
|
+
const u = i.get(l.recordName);
|
|
12449
|
+
if (!u) continue;
|
|
12450
|
+
u.tableName !== l.tableName && t.push({
|
|
12399
12451
|
kind: "physical-path-move",
|
|
12400
|
-
logicalPath:
|
|
12401
|
-
oldPhysicalPath:
|
|
12402
|
-
newPhysicalPath:
|
|
12452
|
+
logicalPath: l.recordName,
|
|
12453
|
+
oldPhysicalPath: u.tableName,
|
|
12454
|
+
newPhysicalPath: l.tableName,
|
|
12403
12455
|
reason: "fact record table changed"
|
|
12404
12456
|
});
|
|
12405
|
-
const d = new Map((
|
|
12406
|
-
a.get(
|
|
12457
|
+
const d = new Map((u.attributeDetails || []).map((f) => [f.name, f])), h = new Map((l.attributeDetails || []).map((f) => [f.name, f]));
|
|
12458
|
+
a.get(u.recordName), n.get(l.recordName);
|
|
12407
12459
|
const m = (f, p, y) => y.records.find((g) => g.name === f)?.properties.find((g) => g.name === p)?.computed === !0;
|
|
12408
|
-
for (const f of
|
|
12460
|
+
for (const f of u.attributeDetails || [])
|
|
12409
12461
|
if (!h.get(f.name) && !f.name.startsWith("_")) {
|
|
12410
|
-
const y = m(
|
|
12462
|
+
const y = m(u.recordName, f.name, s);
|
|
12411
12463
|
t.push({
|
|
12412
12464
|
kind: "unsupported-destructive-schema-change",
|
|
12413
|
-
logicalPath: `${
|
|
12465
|
+
logicalPath: `${u.recordName}.${f.name}`,
|
|
12414
12466
|
oldPhysicalPath: di(f.tableName, f.fieldName || f.sourceField || f.targetField),
|
|
12415
12467
|
reason: y ? "computed attribute physical cleanup is not supported by compute-route schema migration" : "fact attribute was removed from the new schema"
|
|
12416
12468
|
});
|
|
12417
12469
|
}
|
|
12418
|
-
for (const f of
|
|
12470
|
+
for (const f of l.attributeDetails || []) {
|
|
12419
12471
|
const p = d.get(f.name);
|
|
12420
|
-
!p || m(
|
|
12472
|
+
!p || m(u.recordName, f.name, s) || m(l.recordName, f.name, e) || ((p.kind !== f.kind || p.tableName !== f.tableName || p.fieldName !== f.fieldName || p.sourceField !== f.sourceField || p.targetField !== f.targetField) && t.push({
|
|
12421
12473
|
kind: "physical-path-move",
|
|
12422
|
-
logicalPath: `${
|
|
12474
|
+
logicalPath: `${l.recordName}.${f.name}`,
|
|
12423
12475
|
oldPhysicalPath: di(p.tableName, p.fieldName || p.sourceField || p.targetField),
|
|
12424
12476
|
newPhysicalPath: di(f.tableName, f.fieldName || f.sourceField || f.targetField),
|
|
12425
12477
|
reason: "fact attribute physical path changed"
|
|
12426
12478
|
}), (p.type !== f.type || p.fieldType !== f.fieldType || p.collection !== f.collection) && t.push({
|
|
12427
12479
|
kind: "unsupported-destructive-schema-change",
|
|
12428
|
-
logicalPath: `${
|
|
12480
|
+
logicalPath: `${l.recordName}.${f.name}`,
|
|
12429
12481
|
oldPhysicalPath: `${p.type || "?"}/${p.fieldType || "?"}/${p.collection === !0}`,
|
|
12430
12482
|
newPhysicalPath: `${f.type || "?"}/${f.fieldType || "?"}/${f.collection === !0}`,
|
|
12431
12483
|
reason: "fact attribute type, field type, or collection flag changed"
|
|
@@ -12449,13 +12501,13 @@ function Qs(s, e, t = {}, i) {
|
|
|
12449
12501
|
if (!a.has(o)) continue;
|
|
12450
12502
|
const c = L(n.dataContext);
|
|
12451
12503
|
if (n.args._type === "ScopedSequence") {
|
|
12452
|
-
const
|
|
12453
|
-
if (
|
|
12504
|
+
const l = !!n.args.initializeFrom;
|
|
12505
|
+
if (l && Xe(
|
|
12454
12506
|
t.approvedDiff,
|
|
12455
|
-
(
|
|
12456
|
-
) || !
|
|
12507
|
+
(u) => u.kind === "scoped-sequence-seed" && u.id === o && u.dataContext === c
|
|
12508
|
+
) || !l && Xe(
|
|
12457
12509
|
t.approvedDiff,
|
|
12458
|
-
(
|
|
12510
|
+
(u) => u.kind === "scoped-sequence-no-seed" && u.id === o && u.dataContext === c
|
|
12459
12511
|
))
|
|
12460
12512
|
continue;
|
|
12461
12513
|
r.push({
|
|
@@ -12465,9 +12517,9 @@ function Qs(s, e, t = {}, i) {
|
|
|
12465
12517
|
});
|
|
12466
12518
|
continue;
|
|
12467
12519
|
}
|
|
12468
|
-
if (n.dataContext.type === "property" && n.dataContext.id.name === ei && !Xe(t.approvedDiff, (
|
|
12469
|
-
const
|
|
12470
|
-
(!
|
|
12520
|
+
if (n.dataContext.type === "property" && n.dataContext.id.name === ei && !Xe(t.approvedDiff, (l) => l.kind === "destructive-scope" && l.dataContext === c) && r.push({ kind: "destructive-computed-output", logicalPath: c, reason: "destructive computed output requires an approved destructive-scope decision" }), n.asyncReturn && !ma(t, c) && r.push({ kind: "async-computation", logicalPath: c, reason: "async computation requires an approved async-completion-handler decision and runtime handler" }), (n.dataContext.type === "entity" || n.dataContext.type === "relation") && !n.compute && r.push({ kind: "unrebuildable-computation", logicalPath: c, reason: "entity/relation output lacks a full compute contract" }), n.dataContext.type === "entity" || n.dataContext.type === "relation") {
|
|
12521
|
+
const l = n.state?.sourceRecordId?.key, u = n.state?.transformIndex?.key;
|
|
12522
|
+
(!l || !u || typeof n.eventDeps == "object") && r.push({
|
|
12471
12523
|
kind: "unrebuildable-computation",
|
|
12472
12524
|
logicalPath: c,
|
|
12473
12525
|
reason: "entity/relation output migration requires a data-based Transform with sourceRecordId and transformIndex state"
|
|
@@ -12484,18 +12536,18 @@ function Qs(s, e, t = {}, i) {
|
|
|
12484
12536
|
async function js(s, e, t, i, r, a, n, o) {
|
|
12485
12537
|
const c = ga(s);
|
|
12486
12538
|
if (typeof c?.query != "function" || !e) return;
|
|
12487
|
-
const
|
|
12488
|
-
if (!
|
|
12489
|
-
const
|
|
12539
|
+
const l = e.storage.records.find((P) => P.recordName === t);
|
|
12540
|
+
if (!l || l.isFiltered || !l.tableName) return;
|
|
12541
|
+
const u = new Map((l.attributeDetails || []).map((P) => [P.name, P])), d = u.get(i);
|
|
12490
12542
|
if (!d?.fieldName || d.kind !== "value") return;
|
|
12491
12543
|
const h = r.map((P) => {
|
|
12492
|
-
const A =
|
|
12544
|
+
const A = u.get(P.path);
|
|
12493
12545
|
return A?.fieldName && A.kind === "value" ? { ...P, fieldName: A.fieldName } : void 0;
|
|
12494
12546
|
});
|
|
12495
12547
|
if (h.some((P) => !P)) return;
|
|
12496
|
-
const m = Q(c), f = (P) => ce(P, m), p = Hs(o,
|
|
12548
|
+
const m = Q(c), f = (P) => ce(P, m), p = Hs(o, u, m);
|
|
12497
12549
|
if (!p) return;
|
|
12498
|
-
const y = f(
|
|
12550
|
+
const y = f(l.tableName), b = f(d.fieldName), g = p.sql ? ` WHERE ${p.sql}` : "", R = (await c.query(
|
|
12499
12551
|
`SELECT COUNT(*) AS ${f("__rowCount")}, COUNT(${b}) AS ${f("__validValueCount")} FROM ${y}${g}`,
|
|
12500
12552
|
p.params
|
|
12501
12553
|
))[0], S = Number(R?.__rowCount ?? 0), N = Number(R?.__validValueCount ?? 0);
|
|
@@ -12523,8 +12575,8 @@ async function js(s, e, t, i, r, a, n, o) {
|
|
|
12523
12575
|
}
|
|
12524
12576
|
function Hs(s, e, t) {
|
|
12525
12577
|
if (s == null) return { sql: "", params: [] };
|
|
12526
|
-
const i = [], r = (
|
|
12527
|
-
const d = n(
|
|
12578
|
+
const i = [], r = (u) => ce(u, t), a = () => t.name === "postgres" ? `$${i.length + 1}` : "?", n = (u) => u && typeof u == "object" && "raw" in u ? u.raw : u, o = (u) => u && typeof u == "object" && "id" in u ? u.id : u, c = (u) => {
|
|
12579
|
+
const d = n(u);
|
|
12528
12580
|
if (!(!d || typeof d != "object")) {
|
|
12529
12581
|
if (d.type === "atom") {
|
|
12530
12582
|
const h = d.data;
|
|
@@ -12567,8 +12619,8 @@ function Hs(s, e, t) {
|
|
|
12567
12619
|
if (h === "or") return `(${m} OR ${f})`;
|
|
12568
12620
|
}
|
|
12569
12621
|
}
|
|
12570
|
-
},
|
|
12571
|
-
return
|
|
12622
|
+
}, l = c(s);
|
|
12623
|
+
return l === void 0 ? void 0 : { sql: l, params: i };
|
|
12572
12624
|
}
|
|
12573
12625
|
async function Ks(s, e, t) {
|
|
12574
12626
|
for (const i of s.scheduler.computationsHandles.values()) {
|
|
@@ -12582,7 +12634,7 @@ async function Ks(s, e, t) {
|
|
|
12582
12634
|
throw new C(`ScopedSequence ${String(r.name)} initializeFrom requires an approved scoped-sequence-seed migration decision`);
|
|
12583
12635
|
const o = r.initializeFrom, c = o.record?.name;
|
|
12584
12636
|
if (!c) throw new Error(`ScopedSequence ${String(r.name)} initializeFrom.record is missing`);
|
|
12585
|
-
const
|
|
12637
|
+
const l = n.startsWith("property:") ? n.slice(9) : "", u = l.lastIndexOf("."), d = u >= 0 ? l.slice(0, u) : "", h = u >= 0 ? l.slice(u + 1) : "";
|
|
12586
12638
|
if (c !== d)
|
|
12587
12639
|
throw new C(`ScopedSequence ${String(r.name)} initializeFrom.record must match host record ${d}`);
|
|
12588
12640
|
if (String(o.valuePath) !== h)
|
|
@@ -12689,8 +12741,8 @@ async function Gs(s, e, t, i) {
|
|
|
12689
12741
|
if (o.type === "global") {
|
|
12690
12742
|
const c = await i.findOne(Z, E.atom({ key: "key", value: ["=", o.source.name] }), void 0, ["value"]);
|
|
12691
12743
|
if (c) return [n, c.value?.raw];
|
|
12692
|
-
const
|
|
12693
|
-
return [n,
|
|
12744
|
+
const l = s.dict.find((u) => u.name === o.source.name);
|
|
12745
|
+
return [n, l?.defaultValue !== void 0 ? l.defaultValue() : void 0];
|
|
12694
12746
|
}
|
|
12695
12747
|
throw new C(`Unknown data dependency type '${o.type}' for ${L(e.dataContext)}`);
|
|
12696
12748
|
}));
|
|
@@ -12701,41 +12753,41 @@ async function Ci(s, e, t, i) {
|
|
|
12701
12753
|
if (s.system.storage.queryHandle)
|
|
12702
12754
|
return s.system.storage.find(o, void 0, void 0, ["*"]);
|
|
12703
12755
|
if (!t) return;
|
|
12704
|
-
const
|
|
12705
|
-
if (!
|
|
12756
|
+
const l = t.storage.records.find((p) => p.recordName === o), u = l?.tableName, d = (l?.attributeDetails || []).filter((p) => p.kind === "value" && p.fieldName);
|
|
12757
|
+
if (!l || !u || d.length === 0) return;
|
|
12706
12758
|
const h = s.system.storage.db || s.system.db;
|
|
12707
12759
|
if (typeof h?.query != "function") return;
|
|
12708
12760
|
const m = (p) => `"${p.replace(/"/g, '""')}"`, f = d.map((p) => `${m(p.fieldName)} AS ${m(p.name)}`).join(", ");
|
|
12709
|
-
return h.query(`SELECT ${f} FROM ${m(
|
|
12761
|
+
return h.query(`SELECT ${f} FROM ${m(u)}`, []);
|
|
12710
12762
|
};
|
|
12711
12763
|
for (const o of e) {
|
|
12712
12764
|
const c = r.get(o.computationId);
|
|
12713
12765
|
if (c?.dataContext.type === "property" && c.dataContext.id.name === ei) {
|
|
12714
|
-
const
|
|
12715
|
-
if (
|
|
12716
|
-
for (const h of
|
|
12766
|
+
const l = c.dataContext.host.name, u = await n(l), d = [];
|
|
12767
|
+
if (u && typeof c.compute == "function")
|
|
12768
|
+
for (const h of u)
|
|
12717
12769
|
await c.compute(
|
|
12718
12770
|
await Gs(s, c, h, i),
|
|
12719
12771
|
h
|
|
12720
12772
|
) === !0 && d.push(String(h.id));
|
|
12721
12773
|
a.push({
|
|
12722
12774
|
dataContext: L(c.dataContext),
|
|
12723
|
-
recordName:
|
|
12775
|
+
recordName: l,
|
|
12724
12776
|
ids: d,
|
|
12725
|
-
count: d.length ||
|
|
12777
|
+
count: d.length || u?.length,
|
|
12726
12778
|
reason: "hard deletion computed property may delete host records whose recomputed value is true"
|
|
12727
12779
|
});
|
|
12728
12780
|
}
|
|
12729
|
-
if ((c?.dataContext.type === "entity" || c?.dataContext.type === "relation") && t?.storage.records.some((
|
|
12781
|
+
if ((c?.dataContext.type === "entity" || c?.dataContext.type === "relation") && t?.storage.records.some((l) => l.recordName === c.dataContext.id.name) && typeof c.compute == "function") {
|
|
12730
12782
|
if (!s.system.storage.queryHandle) continue;
|
|
12731
|
-
const
|
|
12732
|
-
if (!
|
|
12783
|
+
const l = c.dataContext.id.name, u = c.state?.sourceRecordId?.key, d = c.state?.transformIndex?.key;
|
|
12784
|
+
if (!u || !d) continue;
|
|
12733
12785
|
const h = await c.compute(await s.scheduler.resolveDataDeps(c));
|
|
12734
12786
|
if (!Array.isArray(h)) continue;
|
|
12735
|
-
const m = new Set(h.map((y) => `${y[
|
|
12787
|
+
const m = new Set(h.map((y) => `${y[u]}:${y[d]}`)), p = (await n(l) || []).filter((y) => !m.has(`${y[u]}:${y[d]}`)).map((y) => String(y.id));
|
|
12736
12788
|
p.length && a.push({
|
|
12737
12789
|
dataContext: L(c.dataContext),
|
|
12738
|
-
recordName:
|
|
12790
|
+
recordName: l,
|
|
12739
12791
|
ids: p,
|
|
12740
12792
|
count: p.length,
|
|
12741
12793
|
reason: "transform recompute would delete stale derived output records"
|
|
@@ -12764,10 +12816,10 @@ async function Ir(s, e, t, i) {
|
|
|
12764
12816
|
if (a.expectedHostCount !== void 0 && n.expectedHostCount !== a.expectedHostCount)
|
|
12765
12817
|
throw new he(`Computation takeover host count mismatch for ${a.dataContext}`);
|
|
12766
12818
|
if (a.targetType !== "property") {
|
|
12767
|
-
const o = [...n.ids || []].sort().join(","), c = a.dataContext.split(":")[1],
|
|
12768
|
-
(
|
|
12819
|
+
const o = [...n.ids || []].sort().join(","), c = a.dataContext.split(":")[1], l = e.approvedDiff?.decisions.find(
|
|
12820
|
+
(u) => u.kind === "destructive-scope" && u.dataContext === a.dataContext && u.recordName === c
|
|
12769
12821
|
);
|
|
12770
|
-
if (!
|
|
12822
|
+
if (!l || [...l.ids || []].sort().join(",") !== o)
|
|
12771
12823
|
throw new he(`Computation takeover destructive scope mismatch for ${a.dataContext}`);
|
|
12772
12824
|
}
|
|
12773
12825
|
}
|
|
@@ -12822,7 +12874,7 @@ async function Ae(s, e, t, i, r = {}, a = {}) {
|
|
|
12822
12874
|
if (!a.skipAsNull || e.dataContext.type !== "property") return;
|
|
12823
12875
|
const o = e.dataContext;
|
|
12824
12876
|
if (s.system.storage.schema.constraints.some(
|
|
12825
|
-
(
|
|
12877
|
+
(l) => l.kind === "non-null" && l.recordName === o.host.name && l.property === o.id.name
|
|
12826
12878
|
))
|
|
12827
12879
|
throw new C(`Computation takeover cannot keep old value for non-null property ${L(e.dataContext)} when computation returns skip`);
|
|
12828
12880
|
t = null;
|
|
@@ -12840,8 +12892,8 @@ async function Xs(s, e, t, i, r = {}) {
|
|
|
12840
12892
|
const a = Array.isArray(t) ? t : [t], n = [];
|
|
12841
12893
|
for (const o of a) {
|
|
12842
12894
|
if (!o || typeof o != "object" || !("type" in o)) {
|
|
12843
|
-
const
|
|
12844
|
-
|
|
12895
|
+
const l = await Ae(s, e, o, i, r);
|
|
12896
|
+
l && n.push(l);
|
|
12845
12897
|
continue;
|
|
12846
12898
|
}
|
|
12847
12899
|
const c = o;
|
|
@@ -12856,8 +12908,8 @@ async function Xs(s, e, t, i, r = {}) {
|
|
|
12856
12908
|
keys: c.data && typeof c.data == "object" ? Object.keys(c.data) : void 0
|
|
12857
12909
|
});
|
|
12858
12910
|
else {
|
|
12859
|
-
const
|
|
12860
|
-
|
|
12911
|
+
const l = $a(e.dataContext, c.data, void 0, i);
|
|
12912
|
+
l && n.push(l);
|
|
12861
12913
|
}
|
|
12862
12914
|
}
|
|
12863
12915
|
return n;
|
|
@@ -12920,25 +12972,25 @@ async function Ys(s, e, t = {}) {
|
|
|
12920
12972
|
}
|
|
12921
12973
|
return p;
|
|
12922
12974
|
}
|
|
12923
|
-
const c = await s.system.storage.find(r, void 0, void 0, ["*"]),
|
|
12975
|
+
const c = await s.system.storage.find(r, void 0, void 0, ["*"]), l = new Map(c.map((d) => [`${d[a]}:${d[n]}`, d])), u = [];
|
|
12924
12976
|
for (const d of i) {
|
|
12925
|
-
const h = `${d[a]}:${d[n]}`, m =
|
|
12926
|
-
if (
|
|
12927
|
-
rt({ ...m, id: void 0 }, { ...d, id: void 0 }) || (await s.system.storage.update(r, E.atom({ key: "id", value: ["=", m.id] }), d),
|
|
12977
|
+
const h = `${d[a]}:${d[n]}`, m = l.get(h);
|
|
12978
|
+
if (l.delete(h), m)
|
|
12979
|
+
rt({ ...m, id: void 0 }, { ...d, id: void 0 }) || (await s.system.storage.update(r, E.atom({ key: "id", value: ["=", m.id] }), d), u.push({ recordName: r, type: "update", record: { ...m, ...d }, oldRecord: m, keys: Object.keys(d) }));
|
|
12928
12980
|
else {
|
|
12929
12981
|
const f = await s.system.storage.create(r, d);
|
|
12930
|
-
|
|
12982
|
+
u.push({ recordName: r, type: "create", record: f });
|
|
12931
12983
|
}
|
|
12932
12984
|
}
|
|
12933
|
-
for (const d of
|
|
12985
|
+
for (const d of l.values()) {
|
|
12934
12986
|
if (!Ut(
|
|
12935
12987
|
t.approvedDiff,
|
|
12936
12988
|
(m) => m.kind === "destructive-scope" && m.dataContext === L(e.dataContext) && m.recordName === r
|
|
12937
12989
|
)?.ids.map(String).includes(String(d.id)))
|
|
12938
12990
|
throw new he(`Migration would delete stale derived ${r} record ${d.id}; approve destructive scope before executing`);
|
|
12939
|
-
await s.system.storage.delete(r, E.atom({ key: "id", value: ["=", d.id] })),
|
|
12991
|
+
await s.system.storage.delete(r, E.atom({ key: "id", value: ["=", d.id] })), u.push({ recordName: r, type: "delete", record: d });
|
|
12940
12992
|
}
|
|
12941
|
-
return
|
|
12993
|
+
return u;
|
|
12942
12994
|
}
|
|
12943
12995
|
async function Zs(s, e, t = {}, i = [], r) {
|
|
12944
12996
|
return Ea(t, await Ci(s, e, r)), new eo(s, e, t, i).run();
|
|
@@ -12981,27 +13033,27 @@ class eo {
|
|
|
12981
13033
|
const t = Hi(this.options.approvedDiff, L(e.dataContext)), i = t?.targetType === "property" ? { forceMutationEvent: !0, skipAsNull: !0 } : {}, r = qt(this.options, L(e.dataContext));
|
|
12982
13034
|
if (r && typeof e.compute != "function") {
|
|
12983
13035
|
if (e.dataContext.type === "property") {
|
|
12984
|
-
const
|
|
13036
|
+
const u = e.dataContext.host.name, d = await this.controller.system.storage.find(u, void 0, void 0, ["*"]), h = [];
|
|
12985
13037
|
for (const m of d) {
|
|
12986
13038
|
const f = t?.targetType === "property" ? Ye(m, e.dataContext.id.name) : m, p = await r({ controller: this.controller, dataContext: e.dataContext, record: f }), y = await Ae(this.controller, e, p, m, this.options, i);
|
|
12987
13039
|
y && h.push(y);
|
|
12988
13040
|
}
|
|
12989
13041
|
return h;
|
|
12990
13042
|
}
|
|
12991
|
-
const c = await r({ controller: this.controller, dataContext: e.dataContext }),
|
|
12992
|
-
return
|
|
13043
|
+
const c = await r({ controller: this.controller, dataContext: e.dataContext }), l = await Ae(this.controller, e, c, void 0, this.options);
|
|
13044
|
+
return l ? [l] : [];
|
|
12993
13045
|
}
|
|
12994
13046
|
if (e.dataContext.type === "global") {
|
|
12995
|
-
const c = await this.controller.scheduler.resolveDataDeps(e),
|
|
12996
|
-
return
|
|
13047
|
+
const c = await this.controller.scheduler.resolveDataDeps(e), l = await Ae(this.controller, e, await e.compute(c), void 0, this.options);
|
|
13048
|
+
return l ? [l] : [];
|
|
12997
13049
|
}
|
|
12998
13050
|
if (e.dataContext.type === "entity" || e.dataContext.type === "relation")
|
|
12999
13051
|
return Ys(this.controller, e, this.options);
|
|
13000
13052
|
const a = e.dataContext.host.name, n = await this.controller.system.storage.find(a, void 0, void 0, ["*"]), o = [];
|
|
13001
13053
|
for (const c of n) {
|
|
13002
|
-
const
|
|
13054
|
+
const l = await this.controller.scheduler.resolveDataDeps(e, c), u = t?.targetType === "property" ? Ye(c, e.dataContext.id.name) : c, d = t?.targetType === "property" ? Ye(l, e.dataContext.id.name) : l, h = await e.compute(
|
|
13003
13055
|
d,
|
|
13004
|
-
|
|
13056
|
+
u
|
|
13005
13057
|
), m = await Ae(this.controller, e, h, c, this.options, i);
|
|
13006
13058
|
m && o.push(m);
|
|
13007
13059
|
}
|
|
@@ -13027,22 +13079,22 @@ class eo {
|
|
|
13027
13079
|
const n = this.sourceMapManager.findSourceMapsForMutation(a).filter((o) => o.computation === e);
|
|
13028
13080
|
for (const o of n) {
|
|
13029
13081
|
if (!("dataDep" in o)) {
|
|
13030
|
-
const
|
|
13031
|
-
if (!
|
|
13082
|
+
const u = qt(this.options, L(e.dataContext));
|
|
13083
|
+
if (!u)
|
|
13032
13084
|
throw new it(`Event-based migration requires an approved event rebuild handler for ${L(e.dataContext)}`);
|
|
13033
13085
|
if (e.dataContext.type === "property") {
|
|
13034
13086
|
r || (r = !0, i.push(...await this.runFullRecompute(e)));
|
|
13035
13087
|
continue;
|
|
13036
13088
|
}
|
|
13037
|
-
const d = await
|
|
13089
|
+
const d = await u({ controller: this.controller, dataContext: e.dataContext, mutationEvent: a }), h = await Ae(this.controller, e, d, void 0, this.options);
|
|
13038
13090
|
h && i.push(h);
|
|
13039
13091
|
continue;
|
|
13040
13092
|
}
|
|
13041
13093
|
const c = await this.controller.scheduler.resolveFilteredUpdateEvent(o, a, t);
|
|
13042
13094
|
if (!c) continue;
|
|
13043
|
-
const
|
|
13044
|
-
for (const [
|
|
13045
|
-
i.push(...await this.runOneDirtyComputation(e, d,
|
|
13095
|
+
const l = await this.controller.scheduler.computeDataBasedDirtyRecordsAndEvents(o, c);
|
|
13096
|
+
for (const [u, d] of l)
|
|
13097
|
+
i.push(...await this.runOneDirtyComputation(e, d, u));
|
|
13046
13098
|
}
|
|
13047
13099
|
}
|
|
13048
13100
|
return i;
|
|
@@ -13071,7 +13123,7 @@ async function to(s, e, t) {
|
|
|
13071
13123
|
});
|
|
13072
13124
|
continue;
|
|
13073
13125
|
}
|
|
13074
|
-
const
|
|
13126
|
+
const l = a.oldRecord?.resolvedBaseRecordName ?? o, u = r(a.oldRecord?.resolvedMatchExpression), d = u ? await s.system.storage.find(l, u, void 0, ["*"]) : [], h = new Set(d.map((f) => String(f.id))), m = new Set(c.map((f) => String(f.id)));
|
|
13075
13127
|
for (const f of c)
|
|
13076
13128
|
h.has(String(f.id)) || i.push({
|
|
13077
13129
|
recordName: n.recordName,
|
|
@@ -13119,10 +13171,10 @@ class Wo {
|
|
|
13119
13171
|
dict: n = [],
|
|
13120
13172
|
recordMutationSideEffects: o = [],
|
|
13121
13173
|
computations: c = [],
|
|
13122
|
-
ignoreGuard:
|
|
13123
|
-
forceThrowDispatchError:
|
|
13174
|
+
ignoreGuard: l = !1,
|
|
13175
|
+
forceThrowDispatchError: u = !1
|
|
13124
13176
|
} = e;
|
|
13125
|
-
this.system = t, this.ignoreGuard =
|
|
13177
|
+
this.system = t, this.ignoreGuard = l, this.forceThrowDispatchError = u, this.entities = [...i], this.relations = [...r], this.dict = [...n], this.recordMutationSideEffects = [...o], this.eventSources = [...a];
|
|
13126
13178
|
for (const m of this.eventSources) {
|
|
13127
13179
|
if (m.name) {
|
|
13128
13180
|
const f = this.eventSourcesByName.get(m.name);
|
|
@@ -13132,9 +13184,16 @@ class Wo {
|
|
|
13132
13184
|
}
|
|
13133
13185
|
this.eventSourcesByUUID.set(m.uuid, m);
|
|
13134
13186
|
}
|
|
13135
|
-
const d = new
|
|
13136
|
-
for (const m of this.eventSources)
|
|
13137
|
-
|
|
13187
|
+
const d = new Map(this.entities.map((m) => [m.name, m]));
|
|
13188
|
+
for (const m of this.eventSources) {
|
|
13189
|
+
if (!m.entity || !m.entity.name) continue;
|
|
13190
|
+
const f = d.get(m.entity.name);
|
|
13191
|
+
if (f && f !== m.entity)
|
|
13192
|
+
throw new Error(
|
|
13193
|
+
`Entity name "${m.entity.name}" conflicts with the event entity of eventSource "${m.name || m.uuid}". Event records are written with the event source's own schema; shadowing it with a user entity silently drops event fields. Rename the user entity (names starting with "_" are reserved for system records).`
|
|
13194
|
+
);
|
|
13195
|
+
f || (this.entities.push(m.entity), d.set(m.entity.name, m.entity));
|
|
13196
|
+
}
|
|
13138
13197
|
const h = [
|
|
13139
13198
|
...In,
|
|
13140
13199
|
...Vn,
|
|
@@ -13167,8 +13226,8 @@ class Wo {
|
|
|
13167
13226
|
const o = this.system, c = o.prepareMigrationSchema;
|
|
13168
13227
|
if (typeof c != "function")
|
|
13169
13228
|
throw new Error("Current system does not support migration manifest validation");
|
|
13170
|
-
const
|
|
13171
|
-
if (d && $r(d), d && d.modelHash !==
|
|
13229
|
+
const l = await c.call(o, this.entities, this.relations, r, { internalRequirements: a }), u = Et(this, l.schema), d = await Mr(this);
|
|
13230
|
+
if (d && $r(d), d && d.modelHash !== u.modelHash)
|
|
13172
13231
|
throw new Error(`Model manifest mismatch. Call controller.generateMigrationDiff(), review it, then call controller.migrate({ approvedDiff }). Manifest key: ${_i}/${Bi}`);
|
|
13173
13232
|
if (!d && await this.system.hasExistingData?.())
|
|
13174
13233
|
throw new Mt("Existing database has no migration manifest. Call controller.createMigrationBaseline() before normal setup or migration.");
|
|
@@ -13240,13 +13299,13 @@ class Wo {
|
|
|
13240
13299
|
a,
|
|
13241
13300
|
n,
|
|
13242
13301
|
{ outputChangedIds: new Set(a.map((p) => p.id)) }
|
|
13243
|
-
), c = Ar(t, i),
|
|
13302
|
+
), c = Ar(t, i), l = kr(this, e), u = r.includeDestructiveScope === !0 ? await Ci(this, o, t, l) : [], d = {
|
|
13244
13303
|
blockingChanges: [
|
|
13245
13304
|
...e.blockingChanges,
|
|
13246
13305
|
...c
|
|
13247
13306
|
],
|
|
13248
|
-
destructiveScopes:
|
|
13249
|
-
}, h = await Is(this, Ps(t, i, e, d), t, i,
|
|
13307
|
+
destructiveScopes: u
|
|
13308
|
+
}, h = await Is(this, Ps(t, i, e, d), t, i, l), m = await ks(this, h, t, i), f = await Ts(this, m, t, i, l);
|
|
13250
13309
|
return Ms(f, this, o);
|
|
13251
13310
|
}
|
|
13252
13311
|
async generateMigrationDiff(e = {}) {
|
|
@@ -13260,7 +13319,7 @@ class Wo {
|
|
|
13260
13319
|
_(typeof r.applyMigrationSchema == "function", "Current system does not support schema migration application");
|
|
13261
13320
|
const { schemaPlan: a, previousManifest: n, nextManifest: o } = i, c = await this.buildCurrentMigrationDiff(a, n, o, { includeDestructiveScope: !1 });
|
|
13262
13321
|
qs(t.approvedDiff, n, o, t.handlers, c);
|
|
13263
|
-
const
|
|
13322
|
+
const l = t.approvedDiff, u = ds(l), d = Os(l), h = Ls(l), m = Ds(n, o, l), f = m.changedComputations, p = Pr(n, o), y = xr(n, o, f, p, {
|
|
13264
13323
|
outputChangedIds: m.outputChangedIds,
|
|
13265
13324
|
stateOnlyIds: m.stateOnlyIds
|
|
13266
13325
|
}), b = await Na(this, t.approvedDiff, n), g = As(n, b), w = {
|
|
@@ -13298,7 +13357,7 @@ class Wo {
|
|
|
13298
13357
|
},
|
|
13299
13358
|
blockingChanges: $,
|
|
13300
13359
|
deletionScope: D,
|
|
13301
|
-
approvedDiffHash:
|
|
13360
|
+
approvedDiffHash: u
|
|
13302
13361
|
};
|
|
13303
13362
|
if (P.dryRun) return P;
|
|
13304
13363
|
if ($.length)
|
|
@@ -13314,19 +13373,19 @@ ${$.join(`
|
|
|
13314
13373
|
try {
|
|
13315
13374
|
A = await r.beginMigration?.(
|
|
13316
13375
|
o.modelHash,
|
|
13317
|
-
|
|
13318
|
-
|
|
13319
|
-
|
|
13376
|
+
u,
|
|
13377
|
+
l.summary,
|
|
13378
|
+
l.decisions.length
|
|
13320
13379
|
);
|
|
13321
13380
|
const F = A?.phase || "pending";
|
|
13322
13381
|
await r.applyMigrationSchema(w, A?.id), ne(F, "schema-applied") || A && await r.updateMigrationPhase?.(A.id, "schema-applied"), ne(F, "manifest-written") || await this.system.storage.runInTransaction({ name: "migration recompute", isolation: "SERIALIZABLE" }, async () => {
|
|
13323
13382
|
if (!ne(F, "computation-applied")) {
|
|
13324
13383
|
await zs(this, W);
|
|
13325
13384
|
const Aa = await to(this, n, o);
|
|
13326
|
-
await Ir(this, t, n), await Zs(this, y, t, Aa, n), await Ks(this,
|
|
13385
|
+
await Ir(this, t, n), await Zs(this, y, t, Aa, n), await Ks(this, l, n), A && await r.updateMigrationPhase?.(A.id, "computation-applied");
|
|
13327
13386
|
}
|
|
13328
13387
|
ne(F, "constraints-applied") || (await xs(this, t.approvedDiff, n), await r.verifyMigrationSchema?.(w, A?.id), await r.applyMigrationPostSchema?.(w, A?.id), A && await r.updateMigrationPhase?.(A.id, "constraints-applied"));
|
|
13329
|
-
const ye = `manifest:current:${o.modelHash}:${
|
|
13388
|
+
const ye = `manifest:current:${o.modelHash}:${u}`;
|
|
13330
13389
|
await r.isMigrationOperationComplete?.(A?.id, ye) || (await hi(this, o), await r.markMigrationOperationComplete?.(A?.id, ye)), A && await r.updateMigrationPhase?.(A.id, "manifest-written");
|
|
13331
13390
|
}), A && await r.finishMigration?.(A.id, "succeeded");
|
|
13332
13391
|
} catch (F) {
|
|
@@ -13484,12 +13543,12 @@ ${$.join(`
|
|
|
13484
13543
|
};
|
|
13485
13544
|
let n;
|
|
13486
13545
|
try {
|
|
13487
|
-
n = await
|
|
13488
|
-
const c = this.cloneDispatchArgs(t),
|
|
13489
|
-
return Vi.run(
|
|
13546
|
+
n = await us.run(a, () => Li(e.name || "dispatch", async (o) => {
|
|
13547
|
+
const c = this.cloneDispatchArgs(t), l = { effects: [] };
|
|
13548
|
+
return Vi.run(l, async () => this.system.storage.runInTransaction({ name: e.name, isolation: o }, async () => qr.run({ eventSourceName: e.name }, async () => {
|
|
13490
13549
|
!this.ignoreGuard && e.guard && await e.guard.call(this, c);
|
|
13491
|
-
const
|
|
13492
|
-
await this.system.storage.create(e.entity.name,
|
|
13550
|
+
const u = e.mapEventData ? await e.mapEventData(c) : {};
|
|
13551
|
+
await this.system.storage.create(e.entity.name, u);
|
|
13493
13552
|
let d;
|
|
13494
13553
|
e.resolve && (d = await e.resolve.call(this, c));
|
|
13495
13554
|
let h;
|
|
@@ -13497,7 +13556,7 @@ ${$.join(`
|
|
|
13497
13556
|
const m = await e.afterDispatch.call(this, c, { data: d });
|
|
13498
13557
|
m && (h = m);
|
|
13499
13558
|
}
|
|
13500
|
-
return { data: d, effects:
|
|
13559
|
+
return { data: d, effects: l.effects, sideEffects: {}, context: h };
|
|
13501
13560
|
})));
|
|
13502
13561
|
}));
|
|
13503
13562
|
} catch (o) {
|
|
@@ -13581,7 +13640,7 @@ function Dr(s) {
|
|
|
13581
13640
|
const e = JSON.stringify(s);
|
|
13582
13641
|
return encodeURI(e === void 0 ? "null" : e);
|
|
13583
13642
|
}
|
|
13584
|
-
function
|
|
13643
|
+
function le(s, e) {
|
|
13585
13644
|
return Array.from({ length: e }, (t, i) => s === "postgres" ? `$${i + 1}` : "?");
|
|
13586
13645
|
}
|
|
13587
13646
|
function io(s) {
|
|
@@ -13674,17 +13733,17 @@ class ro {
|
|
|
13674
13733
|
return this.db.runInTransaction({ name: e.name, isolation: i }, o);
|
|
13675
13734
|
await this.db.scheme("BEGIN", e.name);
|
|
13676
13735
|
try {
|
|
13677
|
-
const
|
|
13678
|
-
return await this.db.scheme("COMMIT", e.name),
|
|
13679
|
-
} catch (
|
|
13680
|
-
throw await this.db.scheme("ROLLBACK", e.name),
|
|
13736
|
+
const l = await o();
|
|
13737
|
+
return await this.db.scheme("COMMIT", e.name), l;
|
|
13738
|
+
} catch (l) {
|
|
13739
|
+
throw await this.db.scheme("ROLLBACK", e.name), l;
|
|
13681
13740
|
}
|
|
13682
13741
|
};
|
|
13683
13742
|
if (r.concurrentTransactions === "unsupported") {
|
|
13684
|
-
const
|
|
13685
|
-
return this.transactionQueue =
|
|
13743
|
+
const l = this.transactionQueue.then(() => c());
|
|
13744
|
+
return this.transactionQueue = l.then(() => {
|
|
13686
13745
|
}, () => {
|
|
13687
|
-
}),
|
|
13746
|
+
}), l;
|
|
13688
13747
|
}
|
|
13689
13748
|
return c();
|
|
13690
13749
|
}
|
|
@@ -13760,7 +13819,7 @@ class ro {
|
|
|
13760
13819
|
await this.db.open(i), i && this.db.setupInternalComputationState && await this.db.setupInternalComputationState(), i && this.requiresScopedSequenceState(r) && this.db.setupScopedSequenceState && await this.db.setupScopedSequenceState();
|
|
13761
13820
|
let a;
|
|
13762
13821
|
try {
|
|
13763
|
-
a = new
|
|
13822
|
+
a = new ue(
|
|
13764
13823
|
e,
|
|
13765
13824
|
t,
|
|
13766
13825
|
this.db
|
|
@@ -13777,13 +13836,13 @@ class ro {
|
|
|
13777
13836
|
if (i && await a.createTables(), await this.createConstraints(a), this.db.setupRecordSequences) {
|
|
13778
13837
|
const n = new qe(a.map, a.aliasManager);
|
|
13779
13838
|
await this.db.setupRecordSequences(Object.keys(a.map.records).map((o) => {
|
|
13780
|
-
const c = n.getRecordInfo(o),
|
|
13781
|
-
if (!
|
|
13839
|
+
const c = n.getRecordInfo(o), l = c.idField;
|
|
13840
|
+
if (!l)
|
|
13782
13841
|
throw new Error(`id field not found for ${o}`);
|
|
13783
13842
|
return {
|
|
13784
13843
|
recordName: o,
|
|
13785
13844
|
tableName: c.table,
|
|
13786
|
-
idField:
|
|
13845
|
+
idField: l
|
|
13787
13846
|
};
|
|
13788
13847
|
}));
|
|
13789
13848
|
}
|
|
@@ -13793,29 +13852,29 @@ class ro {
|
|
|
13793
13852
|
await this.ensureDbOpenForSchemaRead(), this.db.setupInternalComputationState;
|
|
13794
13853
|
let r;
|
|
13795
13854
|
try {
|
|
13796
|
-
r = new
|
|
13855
|
+
r = new ue(
|
|
13797
13856
|
e,
|
|
13798
13857
|
t,
|
|
13799
13858
|
this.db
|
|
13800
13859
|
);
|
|
13801
|
-
} catch (
|
|
13860
|
+
} catch (l) {
|
|
13802
13861
|
throw new Ce(
|
|
13803
|
-
|
|
13862
|
+
l instanceof Error ? l.message : String(l),
|
|
13804
13863
|
{
|
|
13805
13864
|
driver: this.db.constructor?.name,
|
|
13806
|
-
causedBy:
|
|
13865
|
+
causedBy: l instanceof Error ? l : void 0
|
|
13807
13866
|
}
|
|
13808
13867
|
);
|
|
13809
13868
|
}
|
|
13810
13869
|
const a = await this.createAdditiveSchemaPlan(r), n = await this.getExistingTables();
|
|
13811
13870
|
if (this.requiresScopedSequenceState(i) && this.db.setupScopedSequenceState && !n.has("_ScopedSequence_")) {
|
|
13812
|
-
const
|
|
13871
|
+
const l = Q(this.db).name;
|
|
13813
13872
|
a.unshift({
|
|
13814
13873
|
kind: "create-table",
|
|
13815
13874
|
tableName: "_ScopedSequence_",
|
|
13816
13875
|
logicalPath: "internal:_ScopedSequence_",
|
|
13817
13876
|
description: "create scoped sequence state table",
|
|
13818
|
-
sql:
|
|
13877
|
+
sql: l === "sqlite" ? 'CREATE TABLE IF NOT EXISTS "_ScopedSequence_" ("sequenceName" TEXT NOT NULL, "scopeKey" TEXT NOT NULL, "scope" JSON NOT NULL, "lastValue" NUMERIC NOT NULL, PRIMARY KEY ("sequenceName", "scopeKey"))' : 'CREATE TABLE IF NOT EXISTS "_ScopedSequence_" ("sequenceName" TEXT NOT NULL, "scopeKey" TEXT NOT NULL, "scope" JSONB NOT NULL, "lastValue" NUMERIC NOT NULL, PRIMARY KEY ("sequenceName", "scopeKey"))'
|
|
13819
13878
|
});
|
|
13820
13879
|
}
|
|
13821
13880
|
const { verificationDDL: o, postRecomputeDDL: c } = this.createPostRecomputeSchemaPlan(r);
|
|
@@ -13834,7 +13893,7 @@ class ro {
|
|
|
13834
13893
|
}
|
|
13835
13894
|
async isMigrationOperationComplete(e, t) {
|
|
13836
13895
|
if (!e) return !1;
|
|
13837
|
-
const i = Q(this.db).name, [r, a] =
|
|
13896
|
+
const i = Q(this.db).name, [r, a] = le(i, 2);
|
|
13838
13897
|
return (await this.db.query(
|
|
13839
13898
|
`SELECT "status" FROM "__interaqt_migration_operation_log" WHERE "migrationId" = ${r} AND "operationKey" = ${a} LIMIT 1`,
|
|
13840
13899
|
[e, t],
|
|
@@ -13843,7 +13902,7 @@ class ro {
|
|
|
13843
13902
|
}
|
|
13844
13903
|
async markMigrationOperationComplete(e, t) {
|
|
13845
13904
|
if (!e) return;
|
|
13846
|
-
const i = Q(this.db).name, [r, a] =
|
|
13905
|
+
const i = Q(this.db).name, [r, a] = le(i, 2), n = i === "mysql" ? 'ON DUPLICATE KEY UPDATE "status" = VALUES("status")' : 'ON CONFLICT ("migrationId", "operationKey") DO UPDATE SET "status" = EXCLUDED."status"';
|
|
13847
13906
|
await this.db.update(
|
|
13848
13907
|
`INSERT INTO "__interaqt_migration_operation_log" ("migrationId", "operationKey", "status") VALUES (${r}, ${a}, 'succeeded') ${n}`,
|
|
13849
13908
|
[e, t],
|
|
@@ -14173,8 +14232,8 @@ class ro {
|
|
|
14173
14232
|
increment: async (t, i) => {
|
|
14174
14233
|
const r = this.getPlaceholder();
|
|
14175
14234
|
if (this.isRecordTarget(t)) {
|
|
14176
|
-
const { tableName:
|
|
14177
|
-
`UPDATE "${
|
|
14235
|
+
const { tableName: l, idField: u, fieldName: d } = this.resolveRecordTarget(t), h = r(), m = r(), f = await this.db.query(
|
|
14236
|
+
`UPDATE "${l}" SET "${d}" = COALESCE("${d}", 0) + ${h} WHERE "${u}" = ${m} RETURNING "${d}" AS value`,
|
|
14178
14237
|
[i, t.id],
|
|
14179
14238
|
`atomic increment ${t.recordName}.${t.field}`
|
|
14180
14239
|
);
|
|
@@ -14214,12 +14273,12 @@ RETURNING "numberValue" AS value`,
|
|
|
14214
14273
|
`SELECT "${a}" AS value FROM "_ComputationState_" WHERE "key" = ${o}${this.supportsForUpdate() ? " FOR UPDATE" : ""}`,
|
|
14215
14274
|
[t.key],
|
|
14216
14275
|
`atomic replace lock ${t.key}`
|
|
14217
|
-
),
|
|
14276
|
+
), l = e.filter((y) => y !== a).map((y) => `"${y}" = NULL`).join(", "), u = this.parseGlobalValue(c[0]?.value, a) ?? t.defaultValue ?? null, d = this.getPlaceholder(), h = d(), m = d(), f = [`"${a}" = ${h}`, l].filter(Boolean).join(", "), p = await this.db.query(
|
|
14218
14277
|
`UPDATE "_ComputationState_" SET ${f} WHERE "key" = ${m} RETURNING "${a}" AS value`,
|
|
14219
14278
|
[n, t.key],
|
|
14220
14279
|
`atomic replace ${t.key}`
|
|
14221
14280
|
);
|
|
14222
|
-
return { oldValue:
|
|
14281
|
+
return { oldValue: u, newValue: this.parseGlobalValue(p[0]?.value, a) ?? i };
|
|
14223
14282
|
}
|
|
14224
14283
|
),
|
|
14225
14284
|
compareAndSet: async (t, i, r, a) => {
|
|
@@ -14232,17 +14291,17 @@ RETURNING "numberValue" AS value`,
|
|
|
14232
14291
|
`atomic compareAndSet ${t.recordName}.${t.field}`
|
|
14233
14292
|
)).length > 0;
|
|
14234
14293
|
}
|
|
14235
|
-
const c = this.resolveGlobalColumn(t, r),
|
|
14294
|
+
const c = this.resolveGlobalColumn(t, r), l = this.normalizeGlobalValue(r, c), u = this.normalizeGlobalValue(o, c), d = this.normalizeGlobalValue(i, c), h = n(), m = n(), f = n(), p = n();
|
|
14236
14295
|
if ((await this.db.query(
|
|
14237
14296
|
`UPDATE "_ComputationState_" SET "${c}" = ${h} WHERE "key" = ${m} AND COALESCE("${c}", ${f}) = ${p} RETURNING "${c}" AS value`,
|
|
14238
|
-
[
|
|
14297
|
+
[l, t.key, u, d],
|
|
14239
14298
|
`atomic compareAndSet ${t.key}`
|
|
14240
14299
|
)).length) return !0;
|
|
14241
|
-
if (d !==
|
|
14300
|
+
if (d !== u) return !1;
|
|
14242
14301
|
const b = this.getPlaceholder(), g = b(), w = b();
|
|
14243
14302
|
return (await this.db.query(
|
|
14244
14303
|
`INSERT INTO "_ComputationState_" ("key", "${c}") VALUES (${g}, ${w}) ON CONFLICT ("key") DO NOTHING RETURNING "${c}" AS value`,
|
|
14245
|
-
[t.key,
|
|
14304
|
+
[t.key, l],
|
|
14246
14305
|
`atomic compareAndSet insert ${t.key}`
|
|
14247
14306
|
)).length > 0;
|
|
14248
14307
|
},
|
|
@@ -14259,8 +14318,8 @@ RETURNING "numberValue" AS value`,
|
|
|
14259
14318
|
},
|
|
14260
14319
|
nextSequenceValue: async (t) => {
|
|
14261
14320
|
this.validateAtomicSequenceTarget(t), this.requireTransaction(`atomic scoped sequence ${t.sequenceName}`);
|
|
14262
|
-
const i = this.sequenceScopeKey(t.scope), r = JSON.stringify(this.normalizeSequenceScope(t.scope)), a = t.initialValue + t.step, n = this.getPlaceholder(), o = n(), c = n(),
|
|
14263
|
-
`INSERT INTO "_ScopedSequence_" ("sequenceName", "scopeKey", "scope", "lastValue") VALUES (${o}, ${c}, ${
|
|
14321
|
+
const i = this.sequenceScopeKey(t.scope), r = JSON.stringify(this.normalizeSequenceScope(t.scope)), a = t.initialValue + t.step, n = this.getPlaceholder(), o = n(), c = n(), l = n(), u = n(), d = n(), h = await this.db.query(
|
|
14322
|
+
`INSERT INTO "_ScopedSequence_" ("sequenceName", "scopeKey", "scope", "lastValue") VALUES (${o}, ${c}, ${l}, ${u})
|
|
14264
14323
|
ON CONFLICT ("sequenceName", "scopeKey") DO UPDATE SET "lastValue" = "_ScopedSequence_"."lastValue" + ${d}
|
|
14265
14324
|
RETURNING "lastValue" AS value`,
|
|
14266
14325
|
[t.sequenceName, i, r, a, t.step],
|
|
@@ -14273,9 +14332,9 @@ RETURNING "lastValue" AS value`,
|
|
|
14273
14332
|
if (this.validateAtomicSequenceTarget(t), t.mode !== void 0 && t.mode !== "max" && t.mode !== "replace")
|
|
14274
14333
|
throw new Error('Atomic sequence seed mode must be "max" or "replace"');
|
|
14275
14334
|
this.requireTransaction(`atomic scoped sequence seed ${t.sequenceName}`);
|
|
14276
|
-
const i = this.sequenceScopeKey(t.scope), r = JSON.stringify(this.normalizeSequenceScope(t.scope)), a = t.mode ?? "max", n = this.getPlaceholder(), o = n(), c = n(),
|
|
14335
|
+
const i = this.sequenceScopeKey(t.scope), r = JSON.stringify(this.normalizeSequenceScope(t.scope)), a = t.mode ?? "max", n = this.getPlaceholder(), o = n(), c = n(), l = n(), u = n(), d = n(), m = Q(this.db).name === "sqlite" ? `MAX("_ScopedSequence_"."lastValue", ${d})` : `GREATEST("_ScopedSequence_"."lastValue", ${d})`, f = a === "replace" ? `${d}` : m;
|
|
14277
14336
|
await this.db.query(
|
|
14278
|
-
`INSERT INTO "_ScopedSequence_" ("sequenceName", "scopeKey", "scope", "lastValue") VALUES (${o}, ${c}, ${
|
|
14337
|
+
`INSERT INTO "_ScopedSequence_" ("sequenceName", "scopeKey", "scope", "lastValue") VALUES (${o}, ${c}, ${l}, ${u})
|
|
14279
14338
|
ON CONFLICT ("sequenceName", "scopeKey") DO UPDATE SET "lastValue" = ${f}
|
|
14280
14339
|
RETURNING "lastValue" AS value`,
|
|
14281
14340
|
[t.sequenceName, i, r, t.value, t.value],
|
|
@@ -14299,17 +14358,17 @@ RETURNING "lastValue" AS value`,
|
|
|
14299
14358
|
`SELECT "jsonValue" AS value FROM "_ComputationState_" WHERE "key" = ${n()}${this.supportsForUpdate() ? " FOR UPDATE" : ""}`,
|
|
14300
14359
|
[t.key],
|
|
14301
14360
|
`atomic updateGlobalFields lock ${t.key}`
|
|
14302
|
-
), c = this.parseGlobalValue(o[0]?.value, "jsonValue") ?? {},
|
|
14361
|
+
), c = this.parseGlobalValue(o[0]?.value, "jsonValue") ?? {}, l = { ...r, ...c };
|
|
14303
14362
|
Object.entries(i).forEach(([m, f]) => {
|
|
14304
|
-
|
|
14363
|
+
l[m] = Number(l[m] ?? r[m] ?? 0) + f;
|
|
14305
14364
|
});
|
|
14306
|
-
const
|
|
14365
|
+
const u = this.getPlaceholder(), d = u(), h = u();
|
|
14307
14366
|
return await this.db.update(
|
|
14308
14367
|
`UPDATE "_ComputationState_" SET "jsonValue" = ${d} WHERE "key" = ${h}`,
|
|
14309
|
-
[JSON.stringify(
|
|
14368
|
+
[JSON.stringify(l), t.key],
|
|
14310
14369
|
void 0,
|
|
14311
14370
|
`atomic updateGlobalFields ${t.key}`
|
|
14312
|
-
),
|
|
14371
|
+
), l;
|
|
14313
14372
|
},
|
|
14314
14373
|
lockRecord: async (t, i, r = ["*"]) => {
|
|
14315
14374
|
this.requireTransaction(`atomic lockRecord ${t}`);
|
|
@@ -14324,7 +14383,7 @@ RETURNING "lastValue" AS value`,
|
|
|
14324
14383
|
lockRows: async (t, i, r = ["*"]) => {
|
|
14325
14384
|
this.requireTransaction(`atomic lockRows ${t}`);
|
|
14326
14385
|
const { tableName: a, idField: n } = this.resolveRecordTable(t), o = 5, c = /* @__PURE__ */ new Map();
|
|
14327
|
-
for (let
|
|
14386
|
+
for (let u = 0; u < o; u++) {
|
|
14328
14387
|
const h = (await this.queryHandle.find(t, i, void 0, ["id"])).map((y) => y.id).filter((y) => !c.has(String(y)));
|
|
14329
14388
|
if (!h.length) {
|
|
14330
14389
|
if (!c.size) return [];
|
|
@@ -14340,13 +14399,13 @@ RETURNING "lastValue" AS value`,
|
|
|
14340
14399
|
if (await this.db.query(
|
|
14341
14400
|
`SELECT "${n}" AS id FROM "${a}" WHERE "${n}" IN (${p})${this.supportsForUpdate() ? " FOR UPDATE" : ""}`,
|
|
14342
14401
|
m,
|
|
14343
|
-
`atomic lockRows ${t} (round ${
|
|
14402
|
+
`atomic lockRows ${t} (round ${u + 1})`
|
|
14344
14403
|
), m.forEach((y) => c.set(String(y), y)), !this.supportsForUpdate()) break;
|
|
14345
14404
|
}
|
|
14346
|
-
const
|
|
14347
|
-
return
|
|
14405
|
+
const l = [...c.values()];
|
|
14406
|
+
return l.length ? this.queryHandle.find(
|
|
14348
14407
|
t,
|
|
14349
|
-
i.and({ key: "id", value: ["in",
|
|
14408
|
+
i.and({ key: "id", value: ["in", l] }),
|
|
14350
14409
|
void 0,
|
|
14351
14410
|
r
|
|
14352
14411
|
) : [];
|
|
@@ -14394,7 +14453,7 @@ RETURNING "lastValue" AS value`,
|
|
|
14394
14453
|
});
|
|
14395
14454
|
}
|
|
14396
14455
|
mapConstraintError(e) {
|
|
14397
|
-
const t =
|
|
14456
|
+
const t = ln(e);
|
|
14398
14457
|
if (t) return t;
|
|
14399
14458
|
const i = xt(e, this.db);
|
|
14400
14459
|
if (!i.isUniqueViolation) return e;
|
|
@@ -14414,13 +14473,16 @@ RETURNING "lastValue" AS value`,
|
|
|
14414
14473
|
);
|
|
14415
14474
|
}
|
|
14416
14475
|
async callWithEvents(e, t, i = [], r) {
|
|
14417
|
-
if (!this.isInTransaction())
|
|
14418
|
-
|
|
14476
|
+
if (!this.isInTransaction()) {
|
|
14477
|
+
let a = [];
|
|
14478
|
+
const n = await this.withAtomicTransaction("storage mutation with events", async () => (a = [], this.callWithEvents(e, t, a, r)));
|
|
14479
|
+
return i.push(...a), n;
|
|
14480
|
+
}
|
|
14419
14481
|
try {
|
|
14420
14482
|
const a = [], n = await e(...t, a), o = r ? a.filter(r) : a, c = await this.dispatch(o);
|
|
14421
14483
|
i.push(...a, ...c);
|
|
14422
|
-
const
|
|
14423
|
-
return
|
|
14484
|
+
const l = ls();
|
|
14485
|
+
return l && o.length > 0 && Er(o), l && c.length > 0 && Er(c), n;
|
|
14424
14486
|
} catch (a) {
|
|
14425
14487
|
throw this.mapConstraintError(a);
|
|
14426
14488
|
}
|
|
@@ -14552,7 +14614,7 @@ CREATE TABLE IF NOT EXISTS "__interaqt_migration_operation_log" (
|
|
|
14552
14614
|
}
|
|
14553
14615
|
async readMigrationManifest() {
|
|
14554
14616
|
if (!(await this.storage.getExistingTables()).has("__interaqt_migration_manifest")) return;
|
|
14555
|
-
const t = Q(this.db).name, [i] =
|
|
14617
|
+
const t = Q(this.db).name, [i] = le(t, 1), r = await this.db.query(
|
|
14556
14618
|
`SELECT "value" FROM "__interaqt_migration_manifest" WHERE "key" = ${i} LIMIT 1`,
|
|
14557
14619
|
["current"],
|
|
14558
14620
|
"read migration manifest"
|
|
@@ -14561,7 +14623,7 @@ CREATE TABLE IF NOT EXISTS "__interaqt_migration_operation_log" (
|
|
|
14561
14623
|
}
|
|
14562
14624
|
async writeMigrationManifest(e) {
|
|
14563
14625
|
await this.ensureMigrationManifestTable();
|
|
14564
|
-
const t = JSON.stringify(e), i = Q(this.db).name, [r, a] =
|
|
14626
|
+
const t = JSON.stringify(e), i = Q(this.db).name, [r, a] = le(i, 2), n = i === "mysql" ? 'ON DUPLICATE KEY UPDATE "value" = VALUES("value")' : 'ON CONFLICT ("key") DO UPDATE SET "value" = EXCLUDED."value"';
|
|
14565
14627
|
await this.db.update(
|
|
14566
14628
|
`INSERT INTO "__interaqt_migration_manifest" ("key", "value") VALUES (${r}, ${a}) ${n}`,
|
|
14567
14629
|
["current", t],
|
|
@@ -14583,7 +14645,7 @@ CREATE TABLE IF NOT EXISTS "__interaqt_migration_operation_log" (
|
|
|
14583
14645
|
return !1;
|
|
14584
14646
|
}
|
|
14585
14647
|
async acquireMigrationLock(e) {
|
|
14586
|
-
const t = Q(this.db).name, [i] =
|
|
14648
|
+
const t = Q(this.db).name, [i] = le(t, 1);
|
|
14587
14649
|
try {
|
|
14588
14650
|
await this.db.update(
|
|
14589
14651
|
`INSERT INTO "__interaqt_migration_lock" ("key", "migrationId") VALUES ('current', ${i})`,
|
|
@@ -14597,23 +14659,23 @@ CREATE TABLE IF NOT EXISTS "__interaqt_migration_operation_log" (
|
|
|
14597
14659
|
}
|
|
14598
14660
|
async beginMigration(e, t, i, r = 0) {
|
|
14599
14661
|
await this.ensureMigrationManifestTable();
|
|
14600
|
-
const a = Q(this.db).name, [n] =
|
|
14662
|
+
const a = Q(this.db).name, [n] = le(a, 1), o = await this.db.query(
|
|
14601
14663
|
`SELECT "migrationId" FROM "__interaqt_migration_lock" WHERE "key" = ${n} LIMIT 1`,
|
|
14602
14664
|
["current"],
|
|
14603
14665
|
"read migration lock"
|
|
14604
14666
|
);
|
|
14605
14667
|
if (o[0])
|
|
14606
14668
|
throw new Error(`Migration is already running: ${o[0].migrationId}. If that process crashed, call controller.forceReleaseMigrationLock() after confirming no migration is actually running, then retry.`);
|
|
14607
|
-
const [c,
|
|
14608
|
-
`SELECT "id", "phase", "status" FROM "__interaqt_migration_log" WHERE "modelHash" = ${c} AND COALESCE("approvedDiffHash", '') = ${
|
|
14669
|
+
const [c, l] = le(a, 2), u = await this.db.query(
|
|
14670
|
+
`SELECT "id", "phase", "status" FROM "__interaqt_migration_log" WHERE "modelHash" = ${c} AND COALESCE("approvedDiffHash", '') = ${l} AND "status" IN ('pending', 'failed') AND "phase" IN ('pending', 'schema-applied', 'computation-applied', 'constraints-applied', 'manifest-written') ORDER BY "updatedAt" DESC LIMIT 1`,
|
|
14609
14671
|
[e, t || ""],
|
|
14610
14672
|
"read resumable migration"
|
|
14611
14673
|
);
|
|
14612
|
-
if (
|
|
14613
|
-
return await this.acquireMigrationLock(
|
|
14674
|
+
if (u[0])
|
|
14675
|
+
return await this.acquireMigrationLock(u[0].id), { id: u[0].id, phase: u[0].phase };
|
|
14614
14676
|
const d = `${Date.now()}-${Math.random().toString(36).slice(2)}`, h = (/* @__PURE__ */ new Date()).toISOString(), m = i === void 0 ? null : JSON.stringify(i);
|
|
14615
14677
|
await this.acquireMigrationLock(d);
|
|
14616
|
-
const f =
|
|
14678
|
+
const f = le(a, 8);
|
|
14617
14679
|
return await this.db.update(
|
|
14618
14680
|
`INSERT INTO "__interaqt_migration_log" ("id", "modelHash", "approvedDiffHash", "approvedDiffSummary", "decisionCount", "reviewedAt", "phase", "status", "createdAt", "updatedAt") VALUES (${f[0]}, ${f[1]}, ${f[2]}, ${f[3]}, ${f[4]}, ${f[5]}, 'pending', 'pending', ${f[6]}, ${f[7]})`,
|
|
14619
14681
|
[d, e, t || "", m, r, h, h, h],
|
|
@@ -14623,7 +14685,7 @@ CREATE TABLE IF NOT EXISTS "__interaqt_migration_operation_log" (
|
|
|
14623
14685
|
}
|
|
14624
14686
|
async updateMigrationPhase(e, t) {
|
|
14625
14687
|
await this.ensureMigrationManifestTable();
|
|
14626
|
-
const i = (/* @__PURE__ */ new Date()).toISOString(), [r, a, n] =
|
|
14688
|
+
const i = (/* @__PURE__ */ new Date()).toISOString(), [r, a, n] = le(Q(this.db).name, 3);
|
|
14627
14689
|
await this.db.update(
|
|
14628
14690
|
`UPDATE "__interaqt_migration_log" SET "phase" = ${r}, "status" = 'pending', "updatedAt" = ${a} WHERE "id" = ${n}`,
|
|
14629
14691
|
[t, i, e],
|
|
@@ -14633,14 +14695,14 @@ CREATE TABLE IF NOT EXISTS "__interaqt_migration_operation_log" (
|
|
|
14633
14695
|
}
|
|
14634
14696
|
async finishMigration(e, t, i) {
|
|
14635
14697
|
await this.ensureMigrationManifestTable();
|
|
14636
|
-
const r = (/* @__PURE__ */ new Date()).toISOString(), a = i === void 0 ? null : String(i instanceof Error ? i.message : i), n = Q(this.db).name, [o, c,
|
|
14698
|
+
const r = (/* @__PURE__ */ new Date()).toISOString(), a = i === void 0 ? null : String(i instanceof Error ? i.message : i), n = Q(this.db).name, [o, c, l, u] = le(n, 4);
|
|
14637
14699
|
await this.db.update(
|
|
14638
|
-
`UPDATE "__interaqt_migration_log" SET "status" = ${o}, "error" = ${c}, "updatedAt" = ${
|
|
14700
|
+
`UPDATE "__interaqt_migration_log" SET "status" = ${o}, "error" = ${c}, "updatedAt" = ${l} WHERE "id" = ${u}`,
|
|
14639
14701
|
[t, a, r, e],
|
|
14640
14702
|
void 0,
|
|
14641
14703
|
"finish migration log"
|
|
14642
14704
|
);
|
|
14643
|
-
const [d] =
|
|
14705
|
+
const [d] = le(n, 1);
|
|
14644
14706
|
await this.db.update(
|
|
14645
14707
|
`DELETE FROM "__interaqt_migration_lock" WHERE "key" = 'current' AND "migrationId" = ${d}`,
|
|
14646
14708
|
[e],
|
|
@@ -14663,8 +14725,8 @@ CREATE TABLE IF NOT EXISTS "__interaqt_migration_operation_log" (
|
|
|
14663
14725
|
await this.ensureMigrationManifestTable(), await this.storage.markMigrationOperationComplete(e, t);
|
|
14664
14726
|
}
|
|
14665
14727
|
async setup(e, t, i, r = !1) {
|
|
14666
|
-
const a = typeof r == "boolean" ? r : r.install === !0, n = typeof r == "boolean" ? { install: a } : r, o = new fi(e, t), { entities: c, relations:
|
|
14667
|
-
i.forEach(({ dataContext:
|
|
14728
|
+
const a = typeof r == "boolean" ? r : r.install === !0, n = typeof r == "boolean" ? { install: a } : r, o = new fi(e, t), { entities: c, relations: l } = o.getAll();
|
|
14729
|
+
i.forEach(({ dataContext: u, state: d }) => {
|
|
14668
14730
|
Object.entries(d).forEach(([h, m]) => {
|
|
14669
14731
|
if (m instanceof O) {
|
|
14670
14732
|
if (!m.record)
|
|
@@ -14690,7 +14752,7 @@ CREATE TABLE IF NOT EXISTS "__interaqt_migration_operation_log" (
|
|
|
14690
14752
|
});
|
|
14691
14753
|
}), await this.storage.setup(
|
|
14692
14754
|
[...c, gr, yr],
|
|
14693
|
-
|
|
14755
|
+
l,
|
|
14694
14756
|
a,
|
|
14695
14757
|
n
|
|
14696
14758
|
), await this.setupTransformUniqueIndexes(i);
|
|
@@ -14702,18 +14764,18 @@ CREATE TABLE IF NOT EXISTS "__interaqt_migration_operation_log" (
|
|
|
14702
14764
|
if (c instanceof O) {
|
|
14703
14765
|
if (!c.record)
|
|
14704
14766
|
return;
|
|
14705
|
-
let
|
|
14706
|
-
if (
|
|
14767
|
+
let l = r.getEntityByName(c.record);
|
|
14768
|
+
if (l || (l = r.getRelationByName(c.record)), !l)
|
|
14707
14769
|
throw new Error(`Entity or Relation not found: ${c.record}`);
|
|
14708
|
-
for (;
|
|
14709
|
-
|
|
14770
|
+
for (; l.baseEntity || l.baseRelation; )
|
|
14771
|
+
l = l.baseEntity || l.baseRelation;
|
|
14710
14772
|
if (c.defaultValue instanceof x)
|
|
14711
|
-
c.defaultValue.name = c.key,
|
|
14773
|
+
c.defaultValue.name = c.key, l.properties.push(c.defaultValue);
|
|
14712
14774
|
else {
|
|
14713
|
-
const
|
|
14714
|
-
|
|
14775
|
+
const u = typeof c.defaultValue;
|
|
14776
|
+
l.properties.push(x.create({
|
|
14715
14777
|
name: c.key,
|
|
14716
|
-
type:
|
|
14778
|
+
type: u,
|
|
14717
14779
|
// 应该系统定义
|
|
14718
14780
|
collection: Array.isArray(c.defaultValue),
|
|
14719
14781
|
defaultValue: () => c.defaultValue
|
|
@@ -14762,9 +14824,9 @@ CREATE TABLE IF NOT EXISTS "__interaqt_migration_operation_log" (
|
|
|
14762
14824
|
const r = i.sourceRecordId, a = i.transformIndex;
|
|
14763
14825
|
if (!(r instanceof O) || !(a instanceof O) || r.unique === !1 || t.type !== "entity" && t.type !== "relation")
|
|
14764
14826
|
continue;
|
|
14765
|
-
const n = t.id.name, o = this.storage, c = o.queryHandle.map,
|
|
14827
|
+
const n = t.id.name, o = this.storage, c = o.queryHandle.map, l = c.getRecordInfo(n), [, u] = c.getTableAliasAndFieldName([n], r.key, !0), [, d] = c.getTableAliasAndFieldName([n], a.key, !0), h = `idx_transform_${this.hashIdentifier(`${l.table}_${u}_${d}`)}`, m = Q(o.db);
|
|
14766
14828
|
await o.db.scheme(
|
|
14767
|
-
wi(h,
|
|
14829
|
+
wi(h, l.table, [u, d], m),
|
|
14768
14830
|
`setup transform unique index ${n}`
|
|
14769
14831
|
);
|
|
14770
14832
|
}
|
|
@@ -14774,16 +14836,16 @@ CREATE TABLE IF NOT EXISTS "__interaqt_migration_operation_log" (
|
|
|
14774
14836
|
if (!i) return [];
|
|
14775
14837
|
const r = new qe(i.map, i.aliasManager), a = Q(this.storage.db);
|
|
14776
14838
|
return t.flatMap(({ dataContext: n, state: o }) => {
|
|
14777
|
-
const c = o.sourceRecordId,
|
|
14778
|
-
if (!(c instanceof O) || !(
|
|
14839
|
+
const c = o.sourceRecordId, l = o.transformIndex;
|
|
14840
|
+
if (!(c instanceof O) || !(l instanceof O) || c.unique === !1 || n.type !== "entity" && n.type !== "relation")
|
|
14779
14841
|
return [];
|
|
14780
|
-
const
|
|
14842
|
+
const u = n.id.name, d = r.getRecordInfo(u), [, h] = r.getTableAliasAndFieldName([u], c.key, !0), [, m] = r.getTableAliasAndFieldName([u], l.key, !0), f = `idx_transform_${this.hashIdentifier(`${d.table}_${h}_${m}`)}`;
|
|
14781
14843
|
return [{
|
|
14782
14844
|
kind: "create-constraint",
|
|
14783
14845
|
sql: wi(f, d.table, [h, m], a),
|
|
14784
14846
|
tableName: d.table,
|
|
14785
|
-
logicalPath: `${
|
|
14786
|
-
description: `migration setup transform unique index ${
|
|
14847
|
+
logicalPath: `${u}.${c.key}.${l.key}`,
|
|
14848
|
+
description: `migration setup transform unique index ${u}`
|
|
14787
14849
|
}];
|
|
14788
14850
|
});
|
|
14789
14851
|
}
|
|
@@ -14995,7 +15057,7 @@ class Zi {
|
|
|
14995
15057
|
const a = new Zi(e, t);
|
|
14996
15058
|
if (this.instances.find((o) => o.uuid === a.uuid))
|
|
14997
15059
|
throw new Error(`duplicate uuid in options ${a.uuid}, Interaction`);
|
|
14998
|
-
return a.entity = Yi, a.guard = co(a), a.mapEventData =
|
|
15060
|
+
return a.entity = Yi, a.guard = co(a), a.mapEventData = lo(a), r && (a.resolve = uo(a)), this.instances.push(a), a;
|
|
14999
15061
|
}
|
|
15000
15062
|
// CAUTION 必须走统一的 stringifyInstance 管线:嵌套的 Klass 实例(Action/Conditions/Payload/Entity 等)
|
|
15001
15063
|
// 会被编码为 `uuid::` 引用、函数编码为 `func::`。此前手写的 JSON.stringify 会把嵌套实例内联成
|
|
@@ -15034,7 +15096,7 @@ function co(s) {
|
|
|
15034
15096
|
await Ta(this, s, e);
|
|
15035
15097
|
};
|
|
15036
15098
|
}
|
|
15037
|
-
function
|
|
15099
|
+
function lo(s) {
|
|
15038
15100
|
return (e) => ({
|
|
15039
15101
|
interactionName: s.name,
|
|
15040
15102
|
interactionId: s.uuid,
|
|
@@ -15044,7 +15106,7 @@ function uo(s) {
|
|
|
15044
15106
|
context: e.context || {}
|
|
15045
15107
|
});
|
|
15046
15108
|
}
|
|
15047
|
-
function
|
|
15109
|
+
function uo(s) {
|
|
15048
15110
|
return async function(e) {
|
|
15049
15111
|
return fo(this, s, e);
|
|
15050
15112
|
};
|
|
@@ -15061,8 +15123,8 @@ async function ho(s, e, t) {
|
|
|
15061
15123
|
try {
|
|
15062
15124
|
o = await n.content.call(s, t);
|
|
15063
15125
|
} catch (c) {
|
|
15064
|
-
const
|
|
15065
|
-
return `Condition '${n.name}' threw exception: ${
|
|
15126
|
+
const l = c instanceof Error ? c.message : String(c);
|
|
15127
|
+
return `Condition '${n.name}' threw exception: ${l}`;
|
|
15066
15128
|
}
|
|
15067
15129
|
return typeof o != "boolean" ? `Condition '${n.name}' returned ${o === void 0 ? "undefined" : JSON.stringify(o)} (${typeof o}); guard callbacks must explicitly return a boolean (did you forget a return statement, or a !! coercion?)` : o;
|
|
15068
15130
|
}, a = await i.evaluateAsync(r);
|
|
@@ -15102,16 +15164,16 @@ async function mo(s, e, t) {
|
|
|
15102
15164
|
);
|
|
15103
15165
|
const c = po[n.type];
|
|
15104
15166
|
if (c) {
|
|
15105
|
-
const
|
|
15106
|
-
for (const
|
|
15107
|
-
if (!c(
|
|
15167
|
+
const l = n.isCollection ? o : [o];
|
|
15168
|
+
for (const u of l)
|
|
15169
|
+
if (!c(u))
|
|
15108
15170
|
throw new ge(
|
|
15109
|
-
`Payload validation failed for field '${n.name}': expected ${n.type}, got ${
|
|
15171
|
+
`Payload validation failed for field '${n.name}': expected ${n.type}, got ${u === null ? "null" : typeof u}`,
|
|
15110
15172
|
{ type: `${n.name} type mismatch`, checkType: "payload" }
|
|
15111
15173
|
);
|
|
15112
15174
|
}
|
|
15113
15175
|
if (n.isCollection) {
|
|
15114
|
-
if (n.isRef && !o.every((
|
|
15176
|
+
if (n.isRef && !o.every((l) => !!l.id))
|
|
15115
15177
|
throw new ge(
|
|
15116
15178
|
`Payload validation failed for field '${n.name}': data not every is ref`,
|
|
15117
15179
|
{ type: `${n.name} data not every is ref`, checkType: "payload" }
|
|
@@ -15122,21 +15184,21 @@ async function mo(s, e, t) {
|
|
|
15122
15184
|
{ type: `${n.name} data is not a ref`, checkType: "payload" }
|
|
15123
15185
|
);
|
|
15124
15186
|
if (n.base) {
|
|
15125
|
-
const
|
|
15126
|
-
for (const d of
|
|
15187
|
+
const l = n.base.name, u = n.isCollection ? o : [o];
|
|
15188
|
+
for (const d of u) {
|
|
15127
15189
|
if (!d || typeof d != "object" || Array.isArray(d))
|
|
15128
15190
|
throw new ge(
|
|
15129
|
-
`Payload validation failed for field '${n.name}': expected ${
|
|
15191
|
+
`Payload validation failed for field '${n.name}': expected ${l} data (object), got ${d === null ? "null" : Array.isArray(d) ? "array" : typeof d}`,
|
|
15130
15192
|
{ type: `${n.name} check concept failed`, checkType: "payload" }
|
|
15131
15193
|
);
|
|
15132
15194
|
if (n.isRef && !await s.system.storage.findOne(
|
|
15133
|
-
|
|
15195
|
+
l,
|
|
15134
15196
|
k.atom({ key: "id", value: ["=", d.id] }),
|
|
15135
15197
|
void 0,
|
|
15136
15198
|
["id"]
|
|
15137
15199
|
))
|
|
15138
15200
|
throw new ge(
|
|
15139
|
-
`Payload validation failed for field '${n.name}': referenced ${
|
|
15201
|
+
`Payload validation failed for field '${n.name}': referenced ${l} with id '${d.id}' does not exist`,
|
|
15140
15202
|
{ type: `${n.name} ref not found`, checkType: "payload" }
|
|
15141
15203
|
);
|
|
15142
15204
|
}
|
|
@@ -15147,13 +15209,13 @@ async function fo(s, e, t) {
|
|
|
15147
15209
|
if (j.is(e.data) || Y.is(e.data)) {
|
|
15148
15210
|
const i = e.data.name, r = e.dataPolicy?.match, a = e.dataPolicy?.modifier, n = { ...t.query?.modifier || {}, ...a || {} };
|
|
15149
15211
|
if (a && typeof a == "object" && "limit" in a) {
|
|
15150
|
-
const
|
|
15212
|
+
const u = t.query?.modifier || {};
|
|
15151
15213
|
for (const d of ["offset", "orderBy"])
|
|
15152
|
-
if (!(d in a) && d in
|
|
15214
|
+
if (!(d in a) && d in u)
|
|
15153
15215
|
throw new Error(`Interaction "${e.name}": caller cannot override modifier "${d}" restricted by dataPolicy`);
|
|
15154
15216
|
}
|
|
15155
|
-
const o = e.dataPolicy?.attributeQuery ?? (t.query?.attributeQuery || []), c = typeof r == "function" ? await r.call(s, t) : r,
|
|
15156
|
-
return s.system.storage.find(i,
|
|
15217
|
+
const o = e.dataPolicy?.attributeQuery ?? (t.query?.attributeQuery || []), c = typeof r == "function" ? await r.call(s, t) : r, l = k.and(c, t.query?.match);
|
|
15218
|
+
return s.system.storage.find(i, l, n, o);
|
|
15157
15219
|
}
|
|
15158
15220
|
}
|
|
15159
15221
|
class er {
|
|
@@ -15805,14 +15867,14 @@ class be extends ae {
|
|
|
15805
15867
|
...t.context
|
|
15806
15868
|
},
|
|
15807
15869
|
causedBy: t.causedBy
|
|
15808
|
-
}), this.activityName = t.activityName, this.activityId = t.activityId, this.activityInstanceId = t.activityInstanceId, this.currentState = t.currentState, this.severity = t.severity ||
|
|
15870
|
+
}), this.activityName = t.activityName, this.activityId = t.activityId, this.activityInstanceId = t.activityInstanceId, this.currentState = t.currentState, this.severity = t.severity || ie.MEDIUM;
|
|
15809
15871
|
}
|
|
15810
15872
|
}
|
|
15811
15873
|
class Me extends be {
|
|
15812
15874
|
constructor(e, t = {}) {
|
|
15813
15875
|
super(e, {
|
|
15814
15876
|
...t,
|
|
15815
|
-
severity:
|
|
15877
|
+
severity: ie.HIGH,
|
|
15816
15878
|
context: {
|
|
15817
15879
|
errorType: "ActivityStateError",
|
|
15818
15880
|
expectedState: t.expectedState,
|
|
@@ -15828,12 +15890,12 @@ class Ke {
|
|
|
15828
15890
|
}
|
|
15829
15891
|
static createInitialState(e) {
|
|
15830
15892
|
return {
|
|
15831
|
-
current:
|
|
15893
|
+
current: te.createInitialState(e)
|
|
15832
15894
|
};
|
|
15833
15895
|
}
|
|
15834
15896
|
static create(e, t, i) {
|
|
15835
15897
|
const r = new Ke(t, i);
|
|
15836
|
-
return e.current && (r.current =
|
|
15898
|
+
return e.current && (r.current = te.create(e.current, t, r)), r;
|
|
15837
15899
|
}
|
|
15838
15900
|
isInteractionAvailable(e) {
|
|
15839
15901
|
return this.current ? this.current?.children ? Object.values(this.current.children).some((t) => t.isInteractionAvailable(e)) : this.current.node.uuid === e : !1;
|
|
@@ -15850,8 +15912,8 @@ class Ke {
|
|
|
15850
15912
|
transferToNext(e) {
|
|
15851
15913
|
const t = this.graph.getNodeByUUID(e);
|
|
15852
15914
|
if (delete this.current, t.next) {
|
|
15853
|
-
const i =
|
|
15854
|
-
this.current =
|
|
15915
|
+
const i = te.createInitialState(t.next);
|
|
15916
|
+
this.current = te.create(i, this.graph, this);
|
|
15855
15917
|
}
|
|
15856
15918
|
this.parent?.onChange(e, t.next?.uuid);
|
|
15857
15919
|
}
|
|
@@ -15861,7 +15923,7 @@ class Ke {
|
|
|
15861
15923
|
};
|
|
15862
15924
|
}
|
|
15863
15925
|
}
|
|
15864
|
-
class
|
|
15926
|
+
class te {
|
|
15865
15927
|
constructor(e, t, i) {
|
|
15866
15928
|
this.node = e, this.graph = t, this.parent = i;
|
|
15867
15929
|
}
|
|
@@ -15875,12 +15937,12 @@ class ee {
|
|
|
15875
15937
|
static create(e, t, i) {
|
|
15876
15938
|
const r = t.getNodeByUUID(e.uuid);
|
|
15877
15939
|
if (He.is(r.content)) {
|
|
15878
|
-
const n =
|
|
15940
|
+
const n = te.GroupStateNodeType.get(r.content.type);
|
|
15879
15941
|
_(!!n, `unknown ActivityGroup type "${r.content.type}"`);
|
|
15880
15942
|
const o = new n(r, t, i);
|
|
15881
15943
|
return o.isGroup = !0, o.children = e?.children?.map((c) => Ke.create(c, t, o)), o;
|
|
15882
15944
|
} else
|
|
15883
|
-
return new
|
|
15945
|
+
return new te(r, t, i);
|
|
15884
15946
|
}
|
|
15885
15947
|
toJSON() {
|
|
15886
15948
|
return {
|
|
@@ -15932,8 +15994,8 @@ class Ue {
|
|
|
15932
15994
|
this.uuidToNode.set(n.uuid, o), this.rawToNode.set(n, o);
|
|
15933
15995
|
}
|
|
15934
15996
|
for (let n of e.groups) {
|
|
15935
|
-
if (!
|
|
15936
|
-
const c = Array.from(
|
|
15997
|
+
if (!te.GroupStateNodeType.has(n.type)) {
|
|
15998
|
+
const c = Array.from(te.GroupStateNodeType.keys()).map((l) => `'${l}'`).join(", ");
|
|
15937
15999
|
throw new be(`ActivityGroup type "${n.type}" in activity "${e.name}" is not supported. Supported types: ${c}.`, { activityName: e.name });
|
|
15938
16000
|
}
|
|
15939
16001
|
if (this.uuidToNode.has(n.uuid))
|
|
@@ -16047,7 +16109,7 @@ class Ue {
|
|
|
16047
16109
|
await this.setActivity(e, t, { state: n });
|
|
16048
16110
|
}
|
|
16049
16111
|
}
|
|
16050
|
-
class go extends
|
|
16112
|
+
class go extends te {
|
|
16051
16113
|
onChange(e, t) {
|
|
16052
16114
|
if (this.graph.isStartNode(e))
|
|
16053
16115
|
if (t)
|
|
@@ -16059,19 +16121,19 @@ class go extends ee {
|
|
|
16059
16121
|
this.isGroupCompleted() && this.complete();
|
|
16060
16122
|
}
|
|
16061
16123
|
}
|
|
16062
|
-
|
|
16063
|
-
class bo extends
|
|
16124
|
+
te.GroupStateNodeType.set("any", go);
|
|
16125
|
+
class bo extends te {
|
|
16064
16126
|
onChange(e, t) {
|
|
16065
16127
|
this.isGroupCompleted() && this.complete();
|
|
16066
16128
|
}
|
|
16067
16129
|
}
|
|
16068
|
-
|
|
16069
|
-
class wo extends
|
|
16130
|
+
te.GroupStateNodeType.set("every", bo);
|
|
16131
|
+
class wo extends te {
|
|
16070
16132
|
onChange(e, t) {
|
|
16071
16133
|
this.graph.isEndNode(e) && this.complete();
|
|
16072
16134
|
}
|
|
16073
16135
|
}
|
|
16074
|
-
|
|
16136
|
+
te.GroupStateNodeType.set("race", wo);
|
|
16075
16137
|
const No = "_Activity_", xa = j.create({
|
|
16076
16138
|
name: No,
|
|
16077
16139
|
properties: [
|
|
@@ -16128,8 +16190,8 @@ class Zo {
|
|
|
16128
16190
|
const r = i.isActivityHead(t), a = async function(c) {
|
|
16129
16191
|
if (r && !c.activityId) {
|
|
16130
16192
|
await i.fullGuard(this, t, c);
|
|
16131
|
-
const
|
|
16132
|
-
c.activityId =
|
|
16193
|
+
const l = await i.create(this);
|
|
16194
|
+
c.activityId = l.activityId;
|
|
16133
16195
|
} else if (r && c.activityId)
|
|
16134
16196
|
await i.checkActivityState(this, c.activityId, t.uuid), await i.fullGuard(this, t, c);
|
|
16135
16197
|
else {
|
|
@@ -16138,14 +16200,14 @@ class Zo {
|
|
|
16138
16200
|
await i.checkActivityState(this, c.activityId, t.uuid), await i.fullGuard(this, t, c);
|
|
16139
16201
|
}
|
|
16140
16202
|
}, n = async (c) => {
|
|
16141
|
-
const
|
|
16142
|
-
return c.activityId && (
|
|
16143
|
-
}, o = async function(c,
|
|
16144
|
-
const
|
|
16145
|
-
return await i.completeInteractionState(this,
|
|
16146
|
-
...(t.afterDispatch ? await t.afterDispatch.call(this, c,
|
|
16147
|
-
activityId:
|
|
16148
|
-
nextState: await i.getState(this,
|
|
16203
|
+
const l = t.mapEventData ? await t.mapEventData(c) : {};
|
|
16204
|
+
return c.activityId && (l.activity = { id: c.activityId }), l;
|
|
16205
|
+
}, o = async function(c, l) {
|
|
16206
|
+
const u = c.activityId;
|
|
16207
|
+
return await i.completeInteractionState(this, u, t.uuid), {
|
|
16208
|
+
...(t.afterDispatch ? await t.afterDispatch.call(this, c, l) : void 0) || {},
|
|
16209
|
+
activityId: u,
|
|
16210
|
+
nextState: await i.getState(this, u)
|
|
16149
16211
|
};
|
|
16150
16212
|
};
|
|
16151
16213
|
return {
|
|
@@ -16197,13 +16259,13 @@ class ec extends ae {
|
|
|
16197
16259
|
...t.context
|
|
16198
16260
|
},
|
|
16199
16261
|
causedBy: t.causedBy
|
|
16200
|
-
}), this.interactionName = t.interactionName, this.userId = t.userId, this.payload = t.payload, this.executionPhase = t.executionPhase, this.severity = t.severity ||
|
|
16262
|
+
}), this.interactionName = t.interactionName, this.userId = t.userId, this.payload = t.payload, this.executionPhase = t.executionPhase, this.severity = t.severity || ie.HIGH;
|
|
16201
16263
|
}
|
|
16202
16264
|
}
|
|
16203
16265
|
export {
|
|
16204
16266
|
No as ACTIVITY_RECORD,
|
|
16205
16267
|
Ba as ALL_ATTR_SYMBOL,
|
|
16206
|
-
|
|
16268
|
+
ui as ASYNC_TASK_RECORD,
|
|
16207
16269
|
ti as Action,
|
|
16208
16270
|
er as Activity,
|
|
16209
16271
|
Ue as ActivityCall,
|
|
@@ -16214,13 +16276,13 @@ export {
|
|
|
16214
16276
|
xa as ActivityStateEntity,
|
|
16215
16277
|
Me as ActivityStateError,
|
|
16216
16278
|
nn as AliasManager,
|
|
16217
|
-
|
|
16279
|
+
la as AmbiguousComputationSignatureError,
|
|
16218
16280
|
ht as Any,
|
|
16219
16281
|
Cn as AnyHandles,
|
|
16220
16282
|
Ui as AsyncMigrationComputationError,
|
|
16221
16283
|
ke as AttributeInfo,
|
|
16222
16284
|
K as AttributeQuery,
|
|
16223
|
-
|
|
16285
|
+
ut as Average,
|
|
16224
16286
|
zn as AverageHandles,
|
|
16225
16287
|
Gt as BoolAtomData,
|
|
16226
16288
|
k as BoolExp,
|
|
@@ -16247,7 +16309,7 @@ export {
|
|
|
16247
16309
|
Zn as CustomHandles,
|
|
16248
16310
|
Ji as DBConsoleLogger,
|
|
16249
16311
|
ao as DBLogLevel,
|
|
16250
|
-
|
|
16312
|
+
ue as DBSetup,
|
|
16251
16313
|
fr as DEFAULT_SCHEMA_DIALECT,
|
|
16252
16314
|
Vo as DELETED_STATE,
|
|
16253
16315
|
Z as DICTIONARY_RECORD,
|
|
@@ -16261,7 +16323,7 @@ export {
|
|
|
16261
16323
|
qe as EntityToTableMap,
|
|
16262
16324
|
Fi as Equation,
|
|
16263
16325
|
ve as ErrorCategory,
|
|
16264
|
-
|
|
16326
|
+
ie as ErrorSeverity,
|
|
16265
16327
|
ar as Event,
|
|
16266
16328
|
Oi as EventSource,
|
|
16267
16329
|
dt as Every,
|
|
@@ -16303,11 +16365,11 @@ export {
|
|
|
16303
16365
|
Fo as NON_DELETED_STATE,
|
|
16304
16366
|
Lo as NON_EXIST_STATE,
|
|
16305
16367
|
Pn as NestedDispatchError,
|
|
16306
|
-
|
|
16368
|
+
ee as NewRecordData,
|
|
16307
16369
|
Mi as NonNullConstraint,
|
|
16308
16370
|
Io as PHASE_AFTER_ALL,
|
|
16309
16371
|
Ao as PHASE_BEFORE_ALL,
|
|
16310
|
-
|
|
16372
|
+
li as PHASE_NORMAL,
|
|
16311
16373
|
nr as Payload,
|
|
16312
16374
|
Ze as PayloadItem,
|
|
16313
16375
|
Qo as PhysicalLayoutChangeError,
|
|
@@ -16351,7 +16413,7 @@ export {
|
|
|
16351
16413
|
bn as StateMachineHandles,
|
|
16352
16414
|
We as StateNode,
|
|
16353
16415
|
qi as StateTransfer,
|
|
16354
|
-
|
|
16416
|
+
lt as Summation,
|
|
16355
16417
|
Hn as SummationHandles,
|
|
16356
16418
|
Xi as SystemConsoleLogger,
|
|
16357
16419
|
yr as SystemEntity,
|
|
@@ -16379,7 +16441,7 @@ export {
|
|
|
16379
16441
|
$r as assertManifestGeneratorCurrent,
|
|
16380
16442
|
Cs as assertScopedSequenceNoSeedDecisions,
|
|
16381
16443
|
Vi as asyncEffectsContext,
|
|
16382
|
-
|
|
16444
|
+
us as asyncInteractionContext,
|
|
16383
16445
|
zs as backfillNewFactPropertyDefaults,
|
|
16384
16446
|
xr as buildAffectedRebuildPlan,
|
|
16385
16447
|
Ps as buildMigrationDiff,
|
|
@@ -16409,7 +16471,7 @@ export {
|
|
|
16409
16471
|
Oo as everyWithErrorAsync,
|
|
16410
16472
|
hn as externalDataDepKeys,
|
|
16411
16473
|
Po as filterMap,
|
|
16412
|
-
|
|
16474
|
+
ln as findConstraintViolationError,
|
|
16413
16475
|
On as findErrorByCode,
|
|
16414
16476
|
Yo as findRootActivity,
|
|
16415
16477
|
Ca as forEachInteraction,
|
|
@@ -16417,7 +16479,7 @@ export {
|
|
|
16417
16479
|
Na as getApprovedEmptyFactRecordRemovals,
|
|
16418
16480
|
jo as getChangedComputations,
|
|
16419
16481
|
Ds as getChangedComputationsFromApprovedDiff,
|
|
16420
|
-
|
|
16482
|
+
ls as getCurrentEffects,
|
|
16421
16483
|
Ci as getDestructiveDeletionScope,
|
|
16422
16484
|
Oa as getEffectiveScopedSequenceInitializerMatch,
|
|
16423
16485
|
zi as getFilteredRecordChanges,
|