interaqt 0.4.10 → 0.4.12

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/index.js CHANGED
@@ -1,63 +1,63 @@
1
- import { uuidv7 as he } from "uuidv7";
2
- import { parse as xe } from "acorn";
3
- import { AsyncLocalStorage as pe } from "async_hooks";
4
- import Me from "better-sqlite3";
5
- import $e from "pg";
6
- import { PGlite as Pe } from "@electric-sql/pglite";
1
+ import { uuidv7 as pe } from "uuidv7";
2
+ import { parse as Me } from "acorn";
3
+ import { AsyncLocalStorage as fe } from "async_hooks";
4
+ import $e from "better-sqlite3";
5
+ import Pe from "pg";
6
+ import { PGlite as De } from "@electric-sql/pglite";
7
7
  import ae from "mysql2/promise";
8
- function fe(u) {
8
+ function me(u) {
9
9
  return u !== null && typeof u == "object";
10
10
  }
11
- function me(u) {
12
- if (!fe(u)) return !1;
11
+ function ye(u) {
12
+ if (!me(u)) return !1;
13
13
  const t = Object.getPrototypeOf(u);
14
14
  return t === null ? !0 : t === Object.prototype || t === null;
15
15
  }
16
- function De(u, t) {
16
+ function Oe(u, t) {
17
17
  const e = {};
18
18
  for (const r of u)
19
19
  r && r[t] !== void 0 && (e[String(r[t])] = r);
20
20
  return e;
21
21
  }
22
22
  function w(u) {
23
- return typeof u == "function" ? `func::${u.toString()}` : Array.isArray(u) ? u : fe(u) && !me(u) ? `uuid::${u.uuid}` : u;
23
+ return typeof u == "function" ? `func::${u.toString()}` : Array.isArray(u) ? u : me(u) && !ye(u) ? `uuid::${u.uuid}` : u;
24
24
  }
25
- function wt(u, t) {
25
+ function Rt(u, t) {
26
26
  if (u == null || typeof u != "object") return u;
27
- if (Array.isArray(u)) return u.map((r) => wt(r, t));
28
- if (me(u))
29
- return Object.fromEntries(Object.entries(u).map(([r, i]) => [r, wt(i, t)]));
27
+ if (Array.isArray(u)) return u.map((r) => Rt(r, t));
28
+ if (ye(u))
29
+ return Object.fromEntries(Object.entries(u).map(([r, i]) => [r, Rt(i, t)]));
30
30
  if (u instanceof Set)
31
- return new Set(Array.from(u.values()).map((r) => wt(r, t)));
31
+ return new Set(Array.from(u.values()).map((r) => Rt(r, t)));
32
32
  if (u instanceof Map)
33
- return new Map(Array.from(u.entries()).map(([r, i]) => [r, wt(i, t)]));
33
+ return new Map(Array.from(u.entries()).map(([r, i]) => [r, Rt(i, t)]));
34
34
  const e = u;
35
35
  return t && e._type && e.constructor?.clone ? e.constructor.clone(u, t) : u;
36
36
  }
37
- function wi(...u) {
37
+ function Ni(...u) {
38
38
  for (const t of u)
39
39
  t.instances.length = 0;
40
40
  }
41
- function Ni() {
41
+ function Ti() {
42
42
  }
43
- const qt = /* @__PURE__ */ new Map();
44
- function Oe(u, t) {
45
- t && t.isKlass && t.displayName && qt.set(u, t);
43
+ const _t = /* @__PURE__ */ new Map();
44
+ function Fe(u, t) {
45
+ t && t.isKlass && t.displayName && _t.set(u, t);
46
46
  }
47
- function Ti() {
47
+ function Si() {
48
48
  const u = [];
49
- return Array.from(qt.entries()).forEach(([, t]) => {
49
+ return Array.from(_t.entries()).forEach(([, t]) => {
50
50
  t.instances && Array.isArray(t.instances) && t.stringify && u.push(...t.instances.map((e) => t.stringify(e)));
51
51
  }), `[${u.join(",")}]`;
52
52
  }
53
- function Si(u) {
53
+ function vi(u) {
54
54
  const t = JSON.parse(u);
55
- return Fe(t);
55
+ return Qe(t);
56
56
  }
57
- function Fe(u) {
57
+ function Qe(u) {
58
58
  const t = /* @__PURE__ */ new Map();
59
59
  return u.forEach(({ type: e, options: r = {}, uuid: i, public: s }) => {
60
- const a = qt.get(e);
60
+ const a = _t.get(e);
61
61
  if (!a) {
62
62
  console.warn(`Class ${e} not found in KlassByName`);
63
63
  return;
@@ -66,10 +66,10 @@ function Fe(u) {
66
66
  t.set(i, o);
67
67
  }), t;
68
68
  }
69
- function vi(u) {
69
+ function ki(u) {
70
70
  return console.warn("createClass is deprecated in refactored code"), null;
71
71
  }
72
- class ki {
72
+ class Ai {
73
73
  static {
74
74
  this.isKlass = !0;
75
75
  }
@@ -92,9 +92,9 @@ class ki {
92
92
  }
93
93
  }
94
94
  function S(u) {
95
- return u?.uuid || he();
95
+ return u?.uuid || pe();
96
96
  }
97
- const Qe = /^[a-zA-Z0-9_]+$/;
97
+ const Ve = /^[a-zA-Z0-9_]+$/;
98
98
  class C {
99
99
  // for Merged Entity
100
100
  constructor(t, e) {
@@ -115,7 +115,7 @@ class C {
115
115
  type: "string",
116
116
  required: !0,
117
117
  constraints: {
118
- nameFormat: ({ name: t }) => Qe.test(t)
118
+ nameFormat: ({ name: t }) => Ve.test(t)
119
119
  }
120
120
  },
121
121
  properties: {
@@ -196,8 +196,8 @@ class C {
196
196
  return this.create(e.public, e.options);
197
197
  }
198
198
  }
199
- var _t = /* @__PURE__ */ ((u) => (u.String = "string", u.Number = "number", u.Boolean = "boolean", u.Timestamp = "timestamp", u))(_t || {});
200
- const Ve = /^[a-zA-Z0-9_]+$/;
199
+ var qt = /* @__PURE__ */ ((u) => (u.String = "string", u.Number = "number", u.Boolean = "boolean", u.Timestamp = "timestamp", u))(qt || {});
200
+ const Le = /^[a-zA-Z0-9_]+$/;
201
201
  class Bt {
202
202
  constructor(t, e) {
203
203
  this._type = "Dictionary", this._options = e, this.uuid = S(e), this.name = t.name, this.type = t.type, this.collection = t.collection ?? !1, this.args = t.args, this.defaultValue = t.defaultValue, this.computation = t.computation;
@@ -218,7 +218,7 @@ class Bt {
218
218
  required: !0,
219
219
  collection: !1,
220
220
  constraints: {
221
- format: ({ name: t }) => Ve.test(t),
221
+ format: ({ name: t }) => Le.test(t),
222
222
  length: ({ name: t }) => t.length > 1 && t.length < 5
223
223
  }
224
224
  },
@@ -226,7 +226,7 @@ class Bt {
226
226
  type: "string",
227
227
  required: !0,
228
228
  collection: !1,
229
- options: Array.from(Object.values(_t))
229
+ options: Array.from(Object.values(qt))
230
230
  },
231
231
  collection: {
232
232
  type: "boolean",
@@ -291,7 +291,7 @@ class Bt {
291
291
  return this.create(e.public, e.options);
292
292
  }
293
293
  }
294
- const Le = /^[a-zA-Z0-9_]+$/;
294
+ const _e = /^[a-zA-Z0-9_]+$/;
295
295
  class T {
296
296
  constructor(t, e) {
297
297
  this._type = "Property", this._options = e, this.uuid = S(e), this.name = t.name, this.type = t.type, this.collection = t.collection, this.defaultValue = t.defaultValue, this.computed = t.computed, this.computation = t.computation;
@@ -311,14 +311,14 @@ class T {
311
311
  type: "string",
312
312
  required: !0,
313
313
  constraints: {
314
- format: ({ name: t }) => Le.test(t),
314
+ format: ({ name: t }) => _e.test(t),
315
315
  length: ({ name: t }) => t.length > 1 && t.length < 5
316
316
  }
317
317
  },
318
318
  type: {
319
319
  type: "string",
320
320
  required: !0,
321
- options: () => Object.values(_t)
321
+ options: () => Object.values(qt)
322
322
  },
323
323
  collection: {
324
324
  type: "boolean",
@@ -741,7 +741,7 @@ class Jt {
741
741
  return this.create(e.public, e.options);
742
742
  }
743
743
  }
744
- class it {
744
+ class rt {
745
745
  constructor(t, e) {
746
746
  this._type = "ActivityGroup", this._options = e, this.uuid = S(e), this.type = t.type, this.activities = t.activities || [];
747
747
  }
@@ -770,7 +770,7 @@ class it {
770
770
  };
771
771
  }
772
772
  static create(t, e) {
773
- const r = new it(t, e);
773
+ const r = new rt(t, e);
774
774
  if (this.instances.find((s) => s.uuid === r.uuid))
775
775
  throw new Error(`duplicate uuid in options ${r.uuid}, ActivityGroup`);
776
776
  return this.instances.push(r), r;
@@ -804,7 +804,7 @@ class it {
804
804
  return this.create(e.public, e.options);
805
805
  }
806
806
  }
807
- class ye {
807
+ class ge {
808
808
  constructor(t, e) {
809
809
  this._type = "Transfer", this._options = e, this.uuid = S(e), this.name = t.name, this.source = t.source, this.target = t.target;
810
810
  }
@@ -837,7 +837,7 @@ class ye {
837
837
  };
838
838
  }
839
839
  static create(t, e) {
840
- const r = new ye(t, e);
840
+ const r = new ge(t, e);
841
841
  if (this.instances.find((s) => s.uuid === r.uuid))
842
842
  throw new Error(`duplicate uuid in options ${r.uuid}, Transfer`);
843
843
  return this.instances.push(r), r;
@@ -873,19 +873,19 @@ class ye {
873
873
  return this.create(e.public, e.options);
874
874
  }
875
875
  }
876
- function ge(u, t, e) {
876
+ function be(u, t, e) {
877
877
  u.interactions.forEach((r) => t(r, e)), u.groups.forEach((r) => {
878
- r.activities?.forEach((i) => ge(i, t, r));
878
+ r.activities?.forEach((i) => be(i, t, r));
879
879
  });
880
880
  }
881
- function Ai(u) {
881
+ function Ei(u) {
882
882
  const t = [];
883
- return ge(u, (e) => t.push(e)), t;
883
+ return be(u, (e) => t.push(e)), t;
884
884
  }
885
- function Ei(u) {
885
+ function Ii(u) {
886
886
  return null;
887
887
  }
888
- class nt {
888
+ class ot {
889
889
  constructor(t, e) {
890
890
  this._type = "BoolAtomData", this._options = e, this.uuid = S(e), this.type = t.type || "atom", this.data = t.data;
891
891
  }
@@ -914,7 +914,7 @@ class nt {
914
914
  };
915
915
  }
916
916
  static create(t, e) {
917
- const r = new nt(t, e);
917
+ const r = new ot(t, e);
918
918
  if (this.instances.find((s) => s.uuid === r.uuid))
919
919
  throw new Error(`duplicate uuid in options ${r.uuid}, BoolAtomData`);
920
920
  return this.instances.push(r), r;
@@ -948,7 +948,7 @@ class nt {
948
948
  return this.create(e.public, e.options);
949
949
  }
950
950
  }
951
- class ct {
951
+ class nt {
952
952
  constructor(t, e) {
953
953
  this._type = "BoolExpressionData", this._options = e, this.uuid = S(e), this.type = t.type || "expression", this.operator = t.operator || "and", this.left = t.left, this.right = t.right;
954
954
  }
@@ -989,7 +989,7 @@ class ct {
989
989
  };
990
990
  }
991
991
  static create(t, e) {
992
- const r = new ct(t, e);
992
+ const r = new nt(t, e);
993
993
  if (this.instances.find((s) => s.uuid === r.uuid))
994
994
  throw new Error(`duplicate uuid in options ${r.uuid}, BoolExpressionData`);
995
995
  return this.instances.push(r), r;
@@ -1180,16 +1180,16 @@ const qe = {
1180
1180
  "||": "or",
1181
1181
  "!": "not"
1182
1182
  };
1183
- function _e(u) {
1183
+ function Be(u) {
1184
1184
  return { key: u };
1185
1185
  }
1186
- function Nt(u, t, e) {
1186
+ function wt(u, t, e) {
1187
1187
  if (u.type === "LogicalExpression")
1188
1188
  return {
1189
1189
  type: "expression",
1190
1190
  operator: qe[u.operator],
1191
- left: Nt(u.left, t, e),
1192
- right: Nt(u.right, t, e)
1191
+ left: wt(u.left, t, e),
1192
+ right: wt(u.right, t, e)
1193
1193
  };
1194
1194
  if (u.type === "Identifier")
1195
1195
  return {
@@ -1200,14 +1200,14 @@ function Nt(u, t, e) {
1200
1200
  return {
1201
1201
  type: "expression",
1202
1202
  operator: "not",
1203
- left: Nt(u.argument, t, e)
1203
+ left: wt(u.argument, t, e)
1204
1204
  };
1205
1205
  throw new Error("unknown ast node type");
1206
1206
  }
1207
- function Ii(u, t = [], e = _e) {
1208
- const r = De(t, "name"), i = xe(u, { ecmaVersion: 2020 });
1207
+ function Ci(u, t = [], e = Be) {
1208
+ const r = Oe(t, "name"), i = Me(u, { ecmaVersion: 2020 });
1209
1209
  return new R(
1210
- Nt(i.body[0].expression, r, e)
1210
+ wt(i.body[0].expression, r, e)
1211
1211
  );
1212
1212
  }
1213
1213
  class X {
@@ -1278,7 +1278,7 @@ class X {
1278
1278
  return r.content && typeof r.content == "string" && r.content.startsWith("func::") && (r.content = new Function("return " + r.content.substring(6))()), this.create(r, e.options);
1279
1279
  }
1280
1280
  }
1281
- class It {
1281
+ class Et {
1282
1282
  constructor(t, e) {
1283
1283
  this._type = "Attributives", this._options = e, this.uuid = S(e), this.content = t.content;
1284
1284
  }
@@ -1301,7 +1301,7 @@ class It {
1301
1301
  };
1302
1302
  }
1303
1303
  static create(t, e) {
1304
- const r = new It(t, e);
1304
+ const r = new Et(t, e);
1305
1305
  if (this.instances.find((s) => s.uuid === r.uuid))
1306
1306
  throw new Error(`duplicate uuid in options ${r.uuid}, Attributives`);
1307
1307
  return this.instances.push(r), r;
@@ -1335,20 +1335,20 @@ class It {
1335
1335
  function Ot(u) {
1336
1336
  if (!u) return;
1337
1337
  if (u.raw.type === "atom")
1338
- return nt.create({
1338
+ return ot.create({
1339
1339
  type: "atom",
1340
1340
  data: u.raw.data
1341
1341
  });
1342
1342
  const t = u.raw;
1343
- return ct.create({
1343
+ return nt.create({
1344
1344
  type: "expression",
1345
1345
  operator: t.operator,
1346
1346
  left: Ot(u.left),
1347
1347
  right: Ot(u.right)
1348
1348
  });
1349
1349
  }
1350
- function Ci(u) {
1351
- return It.create({
1350
+ function xi(u) {
1351
+ return Et.create({
1352
1352
  content: Ot(u)
1353
1353
  });
1354
1354
  }
@@ -1472,7 +1472,7 @@ class jt {
1472
1472
  return r.content && typeof r.content == "string" && r.content.startsWith("func::") && (r.content = new Function("return " + r.content.substring(6))()), this.create(r, e.options);
1473
1473
  }
1474
1474
  }
1475
- class be {
1475
+ class Re {
1476
1476
  constructor(t, e) {
1477
1477
  this._type = "QueryItem", this._options = e, this.uuid = S(e), this.name = t.name, this.value = t.value;
1478
1478
  }
@@ -1500,7 +1500,7 @@ class be {
1500
1500
  };
1501
1501
  }
1502
1502
  static create(t, e) {
1503
- const r = new be(t, e);
1503
+ const r = new Re(t, e);
1504
1504
  if (this.instances.find((s) => s.uuid === r.uuid))
1505
1505
  throw new Error(`duplicate uuid in options ${r.uuid}, QueryItem`);
1506
1506
  return this.instances.push(r), r;
@@ -1534,7 +1534,7 @@ class be {
1534
1534
  return this.create(e.public, e.options);
1535
1535
  }
1536
1536
  }
1537
- class Re {
1537
+ class we {
1538
1538
  constructor(t, e) {
1539
1539
  this._type = "Query", this._options = e, this.uuid = S(e), this.items = t.items;
1540
1540
  }
@@ -1557,7 +1557,7 @@ class Re {
1557
1557
  };
1558
1558
  }
1559
1559
  static create(t, e) {
1560
- const r = new Re(t, e);
1560
+ const r = new we(t, e);
1561
1561
  if (this.instances.find((s) => s.uuid === r.uuid))
1562
1562
  throw new Error(`duplicate uuid in options ${r.uuid}, Query`);
1563
1563
  return this.instances.push(r), r;
@@ -1589,7 +1589,7 @@ class Re {
1589
1589
  return this.create(e.public, e.options);
1590
1590
  }
1591
1591
  }
1592
- class Ct {
1592
+ class It {
1593
1593
  constructor(t, e) {
1594
1594
  this._type = "Action", this._options = e, this.uuid = S(e), this.name = t.name;
1595
1595
  }
@@ -1611,7 +1611,7 @@ class Ct {
1611
1611
  };
1612
1612
  }
1613
1613
  static create(t, e) {
1614
- const r = new Ct(t, e);
1614
+ const r = new It(t, e);
1615
1615
  if (this.instances.find((s) => s.uuid === r.uuid))
1616
1616
  throw new Error(`duplicate uuid in options ${r.uuid}, Action`);
1617
1617
  return this.instances.push(r), r;
@@ -1643,8 +1643,8 @@ class Ct {
1643
1643
  return this.create(e.public, e.options);
1644
1644
  }
1645
1645
  }
1646
- const Be = Ct.create({ name: "get" });
1647
- class st {
1646
+ const We = It.create({ name: "get" });
1647
+ class it {
1648
1648
  constructor(t, e) {
1649
1649
  this._type = "Gateway", this._options = e, this.uuid = S(e), this.name = t.name;
1650
1650
  }
@@ -1666,7 +1666,7 @@ class st {
1666
1666
  };
1667
1667
  }
1668
1668
  static create(t, e) {
1669
- const r = new st(t, e);
1669
+ const r = new it(t, e);
1670
1670
  if (this.instances.find((s) => s.uuid === r.uuid))
1671
1671
  throw new Error(`duplicate uuid in options ${r.uuid}, Gateway`);
1672
1672
  return this.instances.push(r), r;
@@ -1892,7 +1892,7 @@ class Gt {
1892
1892
  return this.create(e.public, e.options);
1893
1893
  }
1894
1894
  }
1895
- class lt {
1895
+ class ct {
1896
1896
  constructor(t, e) {
1897
1897
  this._type = "StateMachine", this._options = e, this.uuid = S(e), this.states = t.states, this.transfers = t.transfers, this.defaultState = t.defaultState;
1898
1898
  }
@@ -1925,7 +1925,7 @@ class lt {
1925
1925
  };
1926
1926
  }
1927
1927
  static create(t, e) {
1928
- const r = new lt(t, e);
1928
+ const r = new ct(t, e);
1929
1929
  if (this.instances.find((s) => s.uuid === r.uuid))
1930
1930
  throw new Error(`duplicate uuid in options ${r.uuid}, StateMachine`);
1931
1931
  return this.instances.push(r), r;
@@ -1961,7 +1961,7 @@ class lt {
1961
1961
  return this.create(e.public, e.options);
1962
1962
  }
1963
1963
  }
1964
- class ut {
1964
+ class lt {
1965
1965
  constructor(t, e) {
1966
1966
  this._type = "WeightedSummation", this._options = e, this.uuid = S(e), this.record = t.record, this.property = t.property, this.direction = t.direction, this.callback = t.callback, this.attributeQuery = t.attributeQuery, this.dataDeps = t.dataDeps;
1967
1967
  }
@@ -2009,7 +2009,7 @@ class ut {
2009
2009
  };
2010
2010
  }
2011
2011
  static create(t, e) {
2012
- const r = new ut(t, e);
2012
+ const r = new lt(t, e);
2013
2013
  if (this.instances.find((s) => s.uuid === r.uuid))
2014
2014
  throw new Error(`duplicate uuid in options ${r.uuid}, WeightedSummation`);
2015
2015
  return this.instances.push(r), r;
@@ -2051,7 +2051,7 @@ class ut {
2051
2051
  return r.callback && typeof r.callback == "string" && r.callback.startsWith("func::") && (r.callback = new Function("return " + r.callback.substring(6))()), this.create(r, e.options);
2052
2052
  }
2053
2053
  }
2054
- class dt {
2054
+ class ut {
2055
2055
  constructor(t, e) {
2056
2056
  this._type = "Count", this._options = e, this.uuid = S(e), this.record = t.record, this.property = t.property, this.direction = t.direction, this.callback = t.callback, this.attributeQuery = t.attributeQuery, this.dataDeps = t.dataDeps;
2057
2057
  }
@@ -2094,7 +2094,7 @@ class dt {
2094
2094
  };
2095
2095
  }
2096
2096
  static create(t, e) {
2097
- const r = new dt(t, e);
2097
+ const r = new ut(t, e);
2098
2098
  if (this.instances.find((s) => s.uuid === r.uuid))
2099
2099
  throw new Error(`duplicate uuid in options ${r.uuid}, Count`);
2100
2100
  return this.instances.push(r), r;
@@ -2135,7 +2135,7 @@ class dt {
2135
2135
  return r.callback && typeof r.callback == "string" && r.callback.startsWith("func::") && (r.callback = new Function("return " + r.callback.substring(6))()), this.create(r, e.options);
2136
2136
  }
2137
2137
  }
2138
- class ht {
2138
+ class dt {
2139
2139
  constructor(t, e) {
2140
2140
  this._type = "Summation", this._options = e, this.uuid = S(e), this.record = t.record, this.property = t.property, this.direction = t.direction, this.attributeQuery = t.attributeQuery;
2141
2141
  }
@@ -2168,7 +2168,7 @@ class ht {
2168
2168
  };
2169
2169
  }
2170
2170
  static create(t, e) {
2171
- const r = new ht(t, e);
2171
+ const r = new dt(t, e);
2172
2172
  if (this.instances.find((s) => s.uuid === r.uuid))
2173
2173
  throw new Error(`duplicate uuid in options ${r.uuid}, Summation`);
2174
2174
  return this.instances.push(r), r;
@@ -2203,7 +2203,7 @@ class ht {
2203
2203
  return this.create(e.public, e.options);
2204
2204
  }
2205
2205
  }
2206
- class pt {
2206
+ class ht {
2207
2207
  constructor(t, e) {
2208
2208
  this._type = "Average", this._options = e, this.uuid = S(e), this.record = t.record, this.property = t.property, this.direction = t.direction, this.attributeQuery = t.attributeQuery;
2209
2209
  }
@@ -2236,7 +2236,7 @@ class pt {
2236
2236
  };
2237
2237
  }
2238
2238
  static create(t, e) {
2239
- const r = new pt(t, e);
2239
+ const r = new ht(t, e);
2240
2240
  if (this.instances.find((s) => s.uuid === r.uuid))
2241
2241
  throw new Error(`duplicate uuid in options ${r.uuid}, Average`);
2242
2242
  return this.instances.push(r), r;
@@ -2271,7 +2271,7 @@ class pt {
2271
2271
  return this.create(e.public, e.options);
2272
2272
  }
2273
2273
  }
2274
- class ft {
2274
+ class pt {
2275
2275
  constructor(t, e) {
2276
2276
  this._type = "Every", this._options = e, this.uuid = S(e), this.record = t.record, this.property = t.property, this.direction = t.direction, this.callback = t.callback, this.attributeQuery = t.attributeQuery, this.dataDeps = t.dataDeps, this.notEmpty = t.notEmpty;
2277
2277
  }
@@ -2319,7 +2319,7 @@ class ft {
2319
2319
  };
2320
2320
  }
2321
2321
  static create(t, e) {
2322
- const r = new ft(t, e);
2322
+ const r = new pt(t, e);
2323
2323
  if (this.instances.find((s) => s.uuid === r.uuid))
2324
2324
  throw new Error(`duplicate uuid in options ${r.uuid}, Every`);
2325
2325
  return this.instances.push(r), r;
@@ -2356,7 +2356,7 @@ class ft {
2356
2356
  return r.callback && typeof r.callback == "string" && r.callback.startsWith("func::") && (r.callback = new Function("return " + r.callback.substring(6))()), this.create(r, e.options);
2357
2357
  }
2358
2358
  }
2359
- class mt {
2359
+ class ft {
2360
2360
  constructor(t, e) {
2361
2361
  this._type = "Any", this._options = e, this.uuid = S(e), this.record = t.record, this.property = t.property, this.direction = t.direction, this.callback = t.callback, this.attributeQuery = t.attributeQuery, this.dataDeps = t.dataDeps;
2362
2362
  }
@@ -2404,7 +2404,7 @@ class mt {
2404
2404
  };
2405
2405
  }
2406
2406
  static create(t, e) {
2407
- const r = new mt(t, e);
2407
+ const r = new ft(t, e);
2408
2408
  if (this.instances.find((s) => s.uuid === r.uuid))
2409
2409
  throw new Error(`duplicate uuid in options ${r.uuid}, Any`);
2410
2410
  return this.instances.push(r), r;
@@ -2446,7 +2446,7 @@ class mt {
2446
2446
  return r.callback && typeof r.callback == "string" && r.callback.startsWith("func::") && (r.callback = new Function("return " + r.callback.substring(6))()), this.create(r, e.options);
2447
2447
  }
2448
2448
  }
2449
- class xt {
2449
+ class Ct {
2450
2450
  constructor(t, e) {
2451
2451
  this._type = "Transform", this._options = e, this.uuid = S(e), this.record = t.record, this.eventDeps = t.eventDeps, this.attributeQuery = t.attributeQuery, this.callback = t.callback;
2452
2452
  }
@@ -2479,7 +2479,7 @@ class xt {
2479
2479
  };
2480
2480
  }
2481
2481
  static create(t, e) {
2482
- const r = new xt(t, e);
2482
+ const r = new Ct(t, e);
2483
2483
  if (this.instances.find((s) => s.uuid === r.uuid))
2484
2484
  throw new Error(`duplicate uuid in options ${r.uuid}, Transform`);
2485
2485
  return this.instances.push(r), r;
@@ -2516,7 +2516,7 @@ class xt {
2516
2516
  return typeof r.callback == "string" && r.callback.startsWith("func::") && (r.callback = new Function("return " + r.callback.substring(6))()), this.create(r, e.options);
2517
2517
  }
2518
2518
  }
2519
- class yt {
2519
+ class mt {
2520
2520
  constructor(t, e) {
2521
2521
  this._type = "RealTimeValue", this._options = e, this.uuid = S(e), this.attributeQuery = t.attributeQuery, this.dataDeps = t.dataDeps, this.nextRecomputeTime = t.nextRecomputeTime, this.callback = t.callback;
2522
2522
  }
@@ -2554,7 +2554,7 @@ class yt {
2554
2554
  };
2555
2555
  }
2556
2556
  static create(t, e) {
2557
- const r = new yt(t, e);
2557
+ const r = new mt(t, e);
2558
2558
  if (this.instances.find((s) => s.uuid === r.uuid))
2559
2559
  throw new Error(`duplicate uuid in options ${r.uuid}, RealTimeValue`);
2560
2560
  return this.instances.push(r), r;
@@ -2800,19 +2800,19 @@ class Yt {
2800
2800
  function Ft(u) {
2801
2801
  if (!u) return;
2802
2802
  if (u.raw.type === "atom")
2803
- return nt.create({
2803
+ return ot.create({
2804
2804
  type: "atom",
2805
2805
  data: u.raw.data
2806
2806
  });
2807
2807
  const t = u.raw;
2808
- return ct.create({
2808
+ return nt.create({
2809
2809
  type: "expression",
2810
2810
  operator: t.operator,
2811
2811
  left: Ft(u.left),
2812
2812
  right: Ft(u.right)
2813
2813
  });
2814
2814
  }
2815
- class Mt {
2815
+ class xt {
2816
2816
  constructor(t, e) {
2817
2817
  this._type = "Conditions", this._options = e, this.uuid = S(e), t.content && t.content instanceof R ? this.content = Ft(t.content) : this.content = t.content;
2818
2818
  }
@@ -2835,7 +2835,7 @@ class Mt {
2835
2835
  };
2836
2836
  }
2837
2837
  static create(t, e) {
2838
- const r = new Mt(t, e);
2838
+ const r = new xt(t, e);
2839
2839
  if (this.instances.find((s) => s.uuid === r.uuid))
2840
2840
  throw new Error(`duplicate uuid in options ${r.uuid}, Conditions`);
2841
2841
  return this.instances.push(r), r;
@@ -2920,7 +2920,7 @@ class zt {
2920
2920
  return this.create(e.public, e.options);
2921
2921
  }
2922
2922
  }
2923
- const We = [
2923
+ const Je = [
2924
2924
  C,
2925
2925
  P,
2926
2926
  T,
@@ -2929,31 +2929,31 @@ const We = [
2929
2929
  X,
2930
2930
  Ht,
2931
2931
  jt,
2932
- Ct,
2933
- st,
2932
+ It,
2933
+ it,
2934
2934
  Ut,
2935
2935
  Y,
2936
2936
  Gt,
2937
+ ct,
2937
2938
  lt,
2938
2939
  ut,
2939
2940
  dt,
2940
2941
  ht,
2941
2942
  pt,
2942
2943
  ft,
2944
+ Ct,
2943
2945
  mt,
2944
- xt,
2945
- yt,
2946
2946
  Kt,
2947
2947
  Xt,
2948
2948
  Yt,
2949
2949
  Bt,
2950
+ ot,
2950
2951
  nt,
2951
- ct,
2952
- Mt,
2952
+ xt,
2953
2953
  zt
2954
2954
  ];
2955
- We.forEach((u) => {
2956
- u && u.displayName && Oe(u.displayName, u);
2955
+ Je.forEach((u) => {
2956
+ u && u.displayName && Fe(u.displayName, u);
2957
2957
  });
2958
2958
  class Zt {
2959
2959
  constructor(t, e) {
@@ -3062,7 +3062,7 @@ class Zt {
3062
3062
  }), this.create(r, e.options);
3063
3063
  }
3064
3064
  }
3065
- class we {
3065
+ class Ne {
3066
3066
  constructor(t = [], e = []) {
3067
3067
  this.clonedEntities = /* @__PURE__ */ new Map(), this.clonedRelations = /* @__PURE__ */ new Map(), this.reverseEntityMap = /* @__PURE__ */ new Map(), this.reverseRelationMap = /* @__PURE__ */ new Map(), this.originalEntities = [...t], this.originalRelations = [...e], (t.length > 0 || e.length > 0) && this.initializeClones();
3068
3068
  }
@@ -3273,7 +3273,7 @@ class we {
3273
3273
  return null;
3274
3274
  }
3275
3275
  }
3276
- function xi({ name: u, isRef: t = !1 }, e) {
3276
+ function Mi({ name: u, isRef: t = !1 }, e) {
3277
3277
  return X.create({
3278
3278
  name: u,
3279
3279
  content: u ? new Function("user", `return user.roles.includes('${u}')`) : function() {
@@ -3286,7 +3286,7 @@ function g(u, t) {
3286
3286
  if (!u)
3287
3287
  throw new Error(t);
3288
3288
  }
3289
- function Pt(u, t, e) {
3289
+ function $t(u, t, e) {
3290
3290
  const r = [...t];
3291
3291
  let i = u, s;
3292
3292
  const a = r.pop();
@@ -3430,7 +3430,7 @@ class m {
3430
3430
  const a = this.map.getRecordInfo(t);
3431
3431
  this.entityName = a.isFilteredEntity || a.isFilteredRelation ? a.baseRecordName : t;
3432
3432
  const o = a.isFilteredEntity || a.isFilteredRelation;
3433
- this.xToOneQueryTree = new q(this.entityName, this.map);
3433
+ this.xToOneQueryTree = new _(this.entityName, this.map);
3434
3434
  let n = r;
3435
3435
  o && (n = r ? a.matchExpression.and(r) : a.matchExpression), n && (this.data = this.convertFilteredRelation(n), this.buildQueryTree(this.data, this.xToOneQueryTree));
3436
3436
  }
@@ -3646,7 +3646,7 @@ class m {
3646
3646
  );
3647
3647
  }
3648
3648
  }
3649
- class Je {
3649
+ class He {
3650
3650
  constructor(t, e, r, i) {
3651
3651
  this.recordName = t, this.map = e, this.data = r, this.fromRelation = i;
3652
3652
  }
@@ -3682,7 +3682,7 @@ class M {
3682
3682
  e,
3683
3683
  N,
3684
3684
  new x(h, e, r.attributeQuery || [], s, a),
3685
- new Je(h, e, r.modifier),
3685
+ new He(h, e, r.modifier),
3686
3686
  i,
3687
3687
  s,
3688
3688
  a,
@@ -3721,7 +3721,7 @@ class M {
3721
3721
  );
3722
3722
  }
3723
3723
  }
3724
- class q {
3724
+ class _ {
3725
3725
  // 父节点和自己这个几点 link 上的 query
3726
3726
  constructor(t, e, r, i, s, a, o) {
3727
3727
  this.recordName = t, this.map = e, this.parentRecord = r, this.attributeName = i, this.data = s, this.parent = a, this.parentLinkQueryTree = o, this.fields = [], g(!!t, "recordName cannot be empty"), this.fields = s?.fields || [], this.records = s?.records || {}, r && (this.info = this.map.getInfo(this.parentRecord, this.attributeName));
@@ -3731,26 +3731,26 @@ class q {
3731
3731
  if (t.length === 1)
3732
3732
  this.fields.push(e);
3733
3733
  else if (e === f)
3734
- this.parentLinkQueryTree || (this.parentLinkQueryTree = new q(this.info.linkName, this.map)), this.parentLinkQueryTree.addField(r);
3734
+ this.parentLinkQueryTree || (this.parentLinkQueryTree = new _(this.info.linkName, this.map)), this.parentLinkQueryTree.addField(r);
3735
3735
  else {
3736
3736
  const i = this.map.getInfo(this.recordName, e);
3737
- this.records[e] || (this.records[e] = new q(i.recordName, this.map, this.recordName, e, void 0, this)), this.records[e].addField(r);
3737
+ this.records[e] || (this.records[e] = new _(i.recordName, this.map, this.recordName, e, void 0, this)), this.records[e].addField(r);
3738
3738
  }
3739
3739
  }
3740
3740
  addRecord(t, e) {
3741
3741
  const [r, ...i] = t;
3742
3742
  if (t.length === 1)
3743
3743
  if (r === f)
3744
- this.parentLinkQueryTree || (this.parentLinkQueryTree = new q(this.info.linkName, this.map)), e && (this.parentLinkQueryTree = this.parentLinkQueryTree.merge(e));
3744
+ this.parentLinkQueryTree || (this.parentLinkQueryTree = new _(this.info.linkName, this.map)), e && (this.parentLinkQueryTree = this.parentLinkQueryTree.merge(e));
3745
3745
  else {
3746
- const s = this.map.getInfo(this.recordName, r), a = e || new q(s.recordName, this.map, this.recordName, r, void 0, this);
3746
+ const s = this.map.getInfo(this.recordName, r), a = e || new _(s.recordName, this.map, this.recordName, r, void 0, this);
3747
3747
  this.records[r] = this.records[r] ? this.records[r].merge(a) : a;
3748
3748
  }
3749
3749
  else if (r === f)
3750
- this.parentLinkQueryTree || (this.parentLinkQueryTree = new q(this.info.linkName, this.map)), this.parentLinkQueryTree.addRecord(i, e);
3750
+ this.parentLinkQueryTree || (this.parentLinkQueryTree = new _(this.info.linkName, this.map)), this.parentLinkQueryTree.addRecord(i, e);
3751
3751
  else {
3752
3752
  const s = this.map.getInfo(this.recordName, r);
3753
- this.records[r] = new q(s.recordName, this.map, this.recordName, r, void 0, this), this.records[r].addRecord(i, e);
3753
+ this.records[r] = new _(s.recordName, this.map, this.recordName, r, void 0, this), this.records[r].addRecord(i, e);
3754
3754
  }
3755
3755
  }
3756
3756
  forEachRecords(t) {
@@ -3765,7 +3765,7 @@ class q {
3765
3765
  this.records[a] && t.records[a] ? i[a] = this.records[a].merge(t.records[a]) : this.records[a] ? i[a] = this.records[a] : i[a] = t.records[a];
3766
3766
  });
3767
3767
  let s;
3768
- return this.parentLinkQueryTree && t.parentLinkQueryTree ? s = this.parentLinkQueryTree.merge(t.parentLinkQueryTree) : s = this.parentLinkQueryTree || t.parentLinkQueryTree, new q(this.recordName, this.map, this.parentRecord, this.attributeName, { fields: e, records: i }, this.parent, s);
3768
+ return this.parentLinkQueryTree && t.parentLinkQueryTree ? s = this.parentLinkQueryTree.merge(t.parentLinkQueryTree) : s = this.parentLinkQueryTree || t.parentLinkQueryTree, new _(this.recordName, this.map, this.parentRecord, this.attributeName, { fields: e, records: i }, this.parent, s);
3769
3769
  }
3770
3770
  getData() {
3771
3771
  const t = {
@@ -3776,7 +3776,7 @@ class q {
3776
3776
  }), this.parentLinkQueryTree && (t[f] = this.parentLinkQueryTree.getData()), t;
3777
3777
  }
3778
3778
  }
3779
- const f = "&", He = "*";
3779
+ const f = "&", je = "*";
3780
3780
  class x {
3781
3781
  constructor(t, e, r = [], i, s, a) {
3782
3782
  this.recordName = t, this.map = e, this.data = r, this.parentRecord = i, this.attributeName = s, this.shouldQueryParentLinkData = a, this.relatedRecords = [], this.xToManyRecords = [], this.xToOneRecords = [], this.valueAttributes = [], this.id = Math.random();
@@ -3789,7 +3789,7 @@ class x {
3789
3789
  this.parentLinkRecordQuery = M.create(y.linkName, this.map, d, void 0);
3790
3790
  return;
3791
3791
  }
3792
- if (l === He) {
3792
+ if (l === je) {
3793
3793
  o = new Set(this.map.getRecordInfo(this.recordName).valueAttributes.map((y) => y.attributeName));
3794
3794
  return;
3795
3795
  }
@@ -3798,10 +3798,10 @@ class x {
3798
3798
  let y = l, N = d;
3799
3799
  if (p.isLinkFiltered()) {
3800
3800
  y = p.getBaseAttributeInfo().attributeName;
3801
- const k = d.matchExpression, F = p.getLinkInfo().getBaseLinkInfo(), se = new m(F.name, this.map, p.getMatchExpression()).rebase(p.isRecordSource() ? "target" : "source"), Ce = k ? se.and(k.data) : se;
3801
+ const k = d.matchExpression, F = p.getLinkInfo().getBaseLinkInfo(), se = new m(F.name, this.map, p.getMatchExpression()).rebase(p.isRecordSource() ? "target" : "source"), xe = k ? se.and(k.data) : se;
3802
3802
  N = {
3803
3803
  ...d,
3804
- matchExpression: Ce.data
3804
+ matchExpression: xe.data
3805
3805
  };
3806
3806
  }
3807
3807
  const b = M.create(p.recordName, this.map, N, void 0, this.recordName, y, h, !1, l);
@@ -3898,7 +3898,7 @@ class x {
3898
3898
  return this.buildXToOneQueryTree();
3899
3899
  }
3900
3900
  buildXToOneQueryTree() {
3901
- const t = new q(this.recordName, this.map, this.parentRecord, this.attributeName);
3901
+ const t = new _(this.recordName, this.map, this.parentRecord, this.attributeName);
3902
3902
  if (this.data.forEach((e) => {
3903
3903
  Array.isArray(e) || t.addField([e]);
3904
3904
  }), this.xToOneRecords.forEach((e) => {
@@ -3910,7 +3910,7 @@ class x {
3910
3910
  return t;
3911
3911
  }
3912
3912
  buildFullQueryTree() {
3913
- const t = new q(this.recordName, this.map, this.parentRecord, this.attributeName);
3913
+ const t = new _(this.recordName, this.map, this.parentRecord, this.attributeName);
3914
3914
  return this.relatedRecords.forEach((e) => {
3915
3915
  t.addRecord([e.attributeName], e.attributeQuery.fullQueryTree);
3916
3916
  }), t;
@@ -3919,7 +3919,7 @@ class x {
3919
3919
  return this.parentLinkRecordQuery ? new x(this.recordName, this.map, this.data, this.parentRecord, this.attributeName, !0) : this;
3920
3920
  }
3921
3921
  }
3922
- function je(u) {
3922
+ function Ue(u) {
3923
3923
  const t = [];
3924
3924
  return u.forEach((e) => t.push(...Array.isArray(e) ? e : [e])), t;
3925
3925
  }
@@ -3929,7 +3929,7 @@ class L {
3929
3929
  const s = this.map.getRecordInfo(e);
3930
3930
  this.recordName = s.isFilteredEntity || s.isFilteredRelation ? s.resolvedBaseRecordName : e;
3931
3931
  const [a, o, n] = this.map.groupAttributes(this.recordName, r ? Object.keys(r) : []);
3932
- this.relatedEntitiesData = je(o.map(
3932
+ this.relatedEntitiesData = Ue(o.map(
3933
3933
  (l) => Array.isArray(r[l.attributeName]) ? r[l.attributeName].map((d) => new L(this.map, l.recordName, d, l)) : new L(this.map, l.recordName, r[l.attributeName], l)
3934
3934
  )), this.valueAttributes = a, this.entityIdAttributes = n;
3935
3935
  const c = this.map.getRecordInfo(this.recordName);
@@ -4006,7 +4006,7 @@ class L {
4006
4006
  }), r;
4007
4007
  }
4008
4008
  }
4009
- class Ue {
4009
+ class Ge {
4010
4010
  constructor(t, e) {
4011
4011
  this.map = t, this.queryAgent = e, this.dependencies = /* @__PURE__ */ new Map();
4012
4012
  }
@@ -4232,7 +4232,7 @@ class Ue {
4232
4232
  }
4233
4233
  }
4234
4234
  }
4235
- class Ge {
4235
+ class Ke {
4236
4236
  constructor() {
4237
4237
  this.aliasToPath = /* @__PURE__ */ new Map(), this.pathStrToAlias = /* @__PURE__ */ new Map(), this.aliasPlaceholder = 0;
4238
4238
  }
@@ -4246,24 +4246,24 @@ class Ge {
4246
4246
  return this.aliasToPath.get(t);
4247
4247
  }
4248
4248
  }
4249
- const Ne = ":root";
4250
- class St {
4249
+ const Te = ":root";
4250
+ class Tt {
4251
4251
  constructor(t, e, r = []) {
4252
4252
  this.label = t, this.parent = e, this.stack = r;
4253
4253
  }
4254
4254
  concat(t) {
4255
- return new St(this.label, this.parent, [...this.stack, t]);
4255
+ return new Tt(this.label, this.parent, [...this.stack, t]);
4256
4256
  }
4257
4257
  getStack(t) {
4258
4258
  return [...this.stack];
4259
4259
  }
4260
4260
  spawn(t) {
4261
- return new St(t, this);
4261
+ return new Tt(t, this);
4262
4262
  }
4263
4263
  }
4264
- class Ke {
4264
+ class Xe {
4265
4265
  constructor(t) {
4266
- this.recordQuery = t, this.recordQueryByName = /* @__PURE__ */ new Map(), this.set(Ne, t), this.recursiveSaveLabelledRecordQuery(t);
4266
+ this.recordQuery = t, this.recordQueryByName = /* @__PURE__ */ new Map(), this.set(Te, t), this.recursiveSaveLabelledRecordQuery(t);
4267
4267
  }
4268
4268
  recursiveSaveLabelledRecordQuery(t) {
4269
4269
  t.attributeQuery?.relatedRecords.forEach((e) => {
@@ -4277,9 +4277,9 @@ class Ke {
4277
4277
  return this.recordQueryByName.get(t);
4278
4278
  }
4279
4279
  }
4280
- class Xe {
4280
+ class Ye {
4281
4281
  constructor(t, e) {
4282
- this.map = t, this.database = e, this.getPlaceholder = e.getPlaceholder || (() => (r) => "?"), this.filteredEntityManager = new Ue(t, this), this.initializeFilteredEntityDependencies();
4282
+ this.map = t, this.database = e, this.getPlaceholder = e.getPlaceholder || (() => (r) => "?"), this.filteredEntityManager = new Ge(t, this), this.initializeFilteredEntityDependencies();
4283
4283
  }
4284
4284
  /**
4285
4285
  * 初始化所有 filtered entity 的依赖关系
@@ -4331,15 +4331,15 @@ ${b}
4331
4331
  const s = {};
4332
4332
  return Object.entries(i).forEach(([a, o]) => {
4333
4333
  const n = r.getPath(a).slice(1, 1 / 0);
4334
- n.length === 1 && e.includes(n[0]) && typeof o == "string" && (o = JSON.parse(o)), o !== null && Pt(s, n, o);
4334
+ n.length === 1 && e.includes(n[0]) && typeof o == "string" && (o = JSON.parse(o)), o !== null && $t(s, n, o);
4335
4335
  }), s;
4336
4336
  });
4337
4337
  }
4338
4338
  // 查 entity 和 查 relation 都是一样的。具体在 entityQuery 里面区别。
4339
4339
  // TODO 为了性能,也可以把信息丢到客户端,然客户端去结构化???
4340
4340
  // CAUTION findRelatedRecords 中的递归调用会使得 includeRelationData 变为 true
4341
- async findRecords(t, e = "", r, i = new St(Ne)) {
4342
- if (r || (r = new Ke(t)), t.goto) {
4341
+ async findRecords(t, e = "", r, i = new Tt(Te)) {
4342
+ if (r || (r = new Xe(t)), t.goto) {
4343
4343
  if (t.exit && await t.exit(i))
4344
4344
  return [];
4345
4345
  const l = r.get(t.goto);
@@ -4378,7 +4378,7 @@ ${b}
4378
4378
  value: ["=", b]
4379
4379
  })
4380
4380
  }), F = t.label ? c.concat(N) : c;
4381
- Pt(
4381
+ $t(
4382
4382
  N,
4383
4383
  [l.alias || l.attributeName, f, h.attributeName],
4384
4384
  await this.findRecords(
@@ -4466,7 +4466,7 @@ ${b}
4466
4466
  for (let b of N.attributeQuery.xToManyRecords)
4467
4467
  for (let k of p) {
4468
4468
  const F = k[f].id, ie = d.label ? y.concat(k) : y;
4469
- Pt(
4469
+ $t(
4470
4470
  k,
4471
4471
  [f, b.attributeName],
4472
4472
  await this.findXToManyRelatedRecords(
@@ -4548,7 +4548,7 @@ ${b}
4548
4548
  return t ? `${t}___` : "";
4549
4549
  }
4550
4550
  buildSelectClause(t, e = "") {
4551
- const r = new Ge();
4551
+ const r = new Ke();
4552
4552
  return t.length ? [t.map(({ tableAliasAndField: s, attribute: a, nameContext: o }) => {
4553
4553
  const n = [
4554
4554
  `${this.withPrefix(e)}${o[0]}`,
@@ -5120,9 +5120,9 @@ WHERE "${s.idField}" = ${l()}
5120
5120
  return p ? [N, ...p] : void 0;
5121
5121
  }
5122
5122
  }
5123
- class Ye {
5123
+ class ze {
5124
5124
  constructor(t, e) {
5125
- this.map = t, this.database = e, this.agent = new Xe(t, e);
5125
+ this.map = t, this.database = e, this.agent = new Ye(t, e);
5126
5126
  }
5127
5127
  async findOne(t, e, r = {}, i) {
5128
5128
  const s = {
@@ -5145,7 +5145,6 @@ class Ye {
5145
5145
  return this.agent.findRecords(s, `finding ${t} from handle`);
5146
5146
  }
5147
5147
  async create(t, e, r) {
5148
- g(e[et] === null || e[et] === void 0, `${et} should be null or undefined when creating new record`);
5149
5148
  const i = new L(this.map, t, e);
5150
5149
  return this.agent.createRecord(i, `create record ${t} from handle`, r);
5151
5150
  }
@@ -5192,7 +5191,7 @@ class Ye {
5192
5191
  return this.map.getInfo(t, e).recordName;
5193
5192
  }
5194
5193
  }
5195
- class at {
5194
+ class st {
5196
5195
  constructor(t, e) {
5197
5196
  this.name = t, this.map = e, this.data = this.map.data.records[t];
5198
5197
  }
@@ -5263,7 +5262,7 @@ class at {
5263
5262
  return this.data.matchExpression;
5264
5263
  }
5265
5264
  get filteredBy() {
5266
- return this.data.filteredBy?.map((t) => new at(t, this.map));
5265
+ return this.data.filteredBy?.map((t) => new st(t, this.map));
5267
5266
  }
5268
5267
  get isFilteredEntity() {
5269
5268
  return this.data?.isFilteredEntity;
@@ -5281,7 +5280,7 @@ class at {
5281
5280
  return this.data?.resolvedMatchExpression;
5282
5281
  }
5283
5282
  }
5284
- class vt {
5283
+ class St {
5285
5284
  constructor(t, e, r, i = !0) {
5286
5285
  this.name = t, this.data = e, this.map = r, this.isFromSource = i;
5287
5286
  }
@@ -5310,10 +5309,10 @@ class vt {
5310
5309
  return this.data.sourceRecord;
5311
5310
  }
5312
5311
  get sourceRecordInfo() {
5313
- return new at(this.data.sourceRecord, this.map);
5312
+ return new st(this.data.sourceRecord, this.map);
5314
5313
  }
5315
5314
  get targetRecordInfo() {
5316
- return new at(this.data.targetRecord, this.map);
5315
+ return new st(this.data.targetRecord, this.map);
5317
5316
  }
5318
5317
  get targetRecord() {
5319
5318
  return this.data.targetRecord;
@@ -5369,7 +5368,7 @@ class vt {
5369
5368
  getBaseLinkInfo() {
5370
5369
  g(this.isFilteredRelation(), "only filtered relation can get base link info");
5371
5370
  const t = this.data.baseLinkName;
5372
- return new vt(t, this.map.data.links[t], this.map);
5371
+ return new St(t, this.map.data.links[t], this.map);
5373
5372
  }
5374
5373
  getMatchExpression() {
5375
5374
  if (this.isFilteredRelation())
@@ -5383,7 +5382,7 @@ class vt {
5383
5382
  return g(this.isFilteredRelation(), "only filtered relation can get resolved record name"), this.data.resolvedBaseRecordName;
5384
5383
  }
5385
5384
  }
5386
- class ze {
5385
+ class Ze {
5387
5386
  constructor(t) {
5388
5387
  this.data = t;
5389
5388
  }
@@ -5397,7 +5396,7 @@ class ze {
5397
5396
  return this.data.records[t].attributes[this.getAttributeAndSymmetricDirection(e)[0]];
5398
5397
  }
5399
5398
  getRecordInfo(t) {
5400
- return new at(t, this);
5399
+ return new st(t, this);
5401
5400
  }
5402
5401
  getInfo(t, e) {
5403
5402
  const r = this.getInfoByPath([t, ...e.split(".")]);
@@ -5408,10 +5407,10 @@ class ze {
5408
5407
  }
5409
5408
  getLinkInfo(t, e) {
5410
5409
  const r = this.getAttributeAndSymmetricDirection(e)[0], { linkName: i, isSource: s } = this.data.records[t].attributes[r];
5411
- return g(!!i, `cannot find relation ${t} ${r}`), new vt(i, this.data.links[i], this, !!s);
5410
+ return g(!!i, `cannot find relation ${t} ${r}`), new St(i, this.data.links[i], this, !!s);
5412
5411
  }
5413
5412
  getLinkInfoByName(t) {
5414
- return g(!!this.data.links[t], `cannot find link ${t}`), new vt(t, this.data.links[t], this);
5413
+ return g(!!this.data.links[t], `cannot find link ${t}`), new St(t, this.data.links[t], this);
5415
5414
  }
5416
5415
  getInfoByPath(t) {
5417
5416
  const [e, ...r] = t;
@@ -5579,7 +5578,7 @@ class ze {
5579
5578
  return i.join(".");
5580
5579
  }
5581
5580
  }
5582
- function Ze(u) {
5581
+ function tr(u) {
5583
5582
  const t = /* @__PURE__ */ new Map();
5584
5583
  for (const e of u)
5585
5584
  if (e.inputEntities)
@@ -5590,7 +5589,7 @@ function Ze(u) {
5590
5589
  }
5591
5590
  return t;
5592
5591
  }
5593
- function tr(u) {
5592
+ function er(u) {
5594
5593
  const t = /* @__PURE__ */ new Map();
5595
5594
  for (const e of u) {
5596
5595
  const r = e.name || `${e.source.name}_${e.sourceProperty}_${e.targetProperty}_${e.target.name}`;
@@ -5604,8 +5603,8 @@ function tr(u) {
5604
5603
  }
5605
5604
  return t;
5606
5605
  }
5607
- function er(u, t) {
5608
- const e = new we(u, t), r = Ze(u), i = tr(t);
5606
+ function rr(u, t) {
5607
+ const e = new Ne(u, t), r = tr(u), i = er(t);
5609
5608
  return oe(
5610
5609
  u,
5611
5610
  e,
@@ -5620,30 +5619,30 @@ function er(u, t) {
5620
5619
  }
5621
5620
  function oe(u, t, e, r) {
5622
5621
  const i = u.filter((s) => {
5623
- const a = bt(s);
5622
+ const a = gt(s);
5624
5623
  return a && a.length > 0;
5625
5624
  });
5626
5625
  if (i.length !== 0)
5627
5626
  for (const s of i)
5628
- rr(
5627
+ ir(
5629
5628
  s,
5630
5629
  t,
5631
5630
  r,
5632
5631
  e
5633
5632
  );
5634
5633
  }
5635
- function rr(u, t, e, r) {
5636
- const i = e === "entity", a = `__${z(u)}_input_${e}`, o = i ? t.getEntityByName(u.name) : t.getRelationByName(u.name), [n, c] = nr(
5634
+ function ir(u, t, e, r) {
5635
+ const i = e === "entity", a = `__${z(u)}_input_${e}`, o = i ? t.getEntityByName(u.name) : t.getRelationByName(u.name), [n, c] = cr(
5637
5636
  o,
5638
5637
  a,
5639
5638
  r,
5640
5639
  t
5641
5640
  );
5642
5641
  t.replace(n, u), c !== n && t.add(c);
5643
- const l = bt(u);
5642
+ const l = gt(u);
5644
5643
  if (l)
5645
5644
  for (const d of l)
5646
- ir(
5645
+ sr(
5647
5646
  d,
5648
5647
  c,
5649
5648
  a,
@@ -5651,8 +5650,8 @@ function rr(u, t, e, r) {
5651
5650
  i
5652
5651
  );
5653
5652
  }
5654
- function ir(u, t, e, r, i) {
5655
- const [s, a] = cr(
5653
+ function sr(u, t, e, r, i) {
5654
+ const [s, a] = lr(
5656
5655
  u,
5657
5656
  t,
5658
5657
  e
@@ -5662,8 +5661,8 @@ function ir(u, t, e, r, i) {
5662
5661
  const o = z(a), n = i ? r.getEntityByName(o) : r.getRelationByName(o);
5663
5662
  n && r.replace(s, n);
5664
5663
  }
5665
- function sr(u, t) {
5666
- const e = /* @__PURE__ */ new Map(), r = bt(u);
5664
+ function ar(u, t) {
5665
+ const e = /* @__PURE__ */ new Map(), r = gt(u);
5667
5666
  if (r && r.length > 0)
5668
5667
  for (const i of r) {
5669
5668
  const s = z(i), a = [...t.get(s) || []], o = e.get(s) || [];
@@ -5676,27 +5675,27 @@ function sr(u, t) {
5676
5675
  }
5677
5676
  return e;
5678
5677
  }
5679
- function ar(u, t, e) {
5680
- const r = sr(t, e);
5678
+ function or(u, t, e) {
5679
+ const r = ar(t, e);
5681
5680
  return T.create({
5682
5681
  name: u,
5683
5682
  type: "json",
5684
5683
  defaultValue: (i, s) => {
5685
- const a = bt(t), n = (r.get(s) || []).filter(
5684
+ const a = gt(t), n = (r.get(s) || []).filter(
5686
5685
  (c) => a.some((l) => z(l) === c)
5687
5686
  );
5688
5687
  return n.length > 0 ? n : [s];
5689
5688
  }
5690
5689
  });
5691
5690
  }
5692
- function or(u, t, e) {
5693
- const r = bt(u), i = [], s = /* @__PURE__ */ new Map(), a = {};
5691
+ function nr(u, t, e) {
5692
+ const r = gt(u), i = [], s = /* @__PURE__ */ new Map(), a = {};
5694
5693
  for (const o of r) {
5695
5694
  let n = o;
5696
- if (gt(n))
5695
+ if (yt(n))
5697
5696
  for (; n.baseEntity && n.properties.length === 0; )
5698
5697
  n = n.baseEntity;
5699
- else if (ur(n))
5698
+ else if (dr(n))
5700
5699
  for (; n.baseRelation && n.properties.length === 0; )
5701
5700
  n = n.baseRelation;
5702
5701
  const c = Object.fromEntries(n.properties.map((h) => [h.name, h]));
@@ -5726,13 +5725,13 @@ function or(u, t, e) {
5726
5725
  }
5727
5726
  return i;
5728
5727
  }
5729
- function nr(u, t, e, r) {
5730
- const i = ar(
5728
+ function cr(u, t, e, r) {
5729
+ const i = or(
5731
5730
  t,
5732
5731
  u,
5733
5732
  e
5734
5733
  ), s = [
5735
- ...or(
5734
+ ...nr(
5736
5735
  u,
5737
5736
  e,
5738
5737
  r
@@ -5740,7 +5739,7 @@ function nr(u, t, e, r) {
5740
5739
  i,
5741
5740
  ...u.properties
5742
5741
  ];
5743
- if (gt(u)) {
5742
+ if (yt(u)) {
5744
5743
  const a = r.getEntityByName(u.name), o = C.create({
5745
5744
  name: a.name
5746
5745
  });
@@ -5790,8 +5789,8 @@ function nr(u, t, e, r) {
5790
5789
  return [o, n || o];
5791
5790
  }
5792
5791
  }
5793
- function cr(u, t, e) {
5794
- if (gt(u)) {
5792
+ function lr(u, t, e) {
5793
+ if (yt(u)) {
5795
5794
  const r = u, i = t;
5796
5795
  let s = r;
5797
5796
  if (r.baseEntity)
@@ -5804,7 +5803,7 @@ function cr(u, t, e) {
5804
5803
  }), [a, s];
5805
5804
  } else {
5806
5805
  const r = u, i = t, s = z(r);
5807
- return r.baseRelation ? [r, lr(r)] : [P.create({
5806
+ return r.baseRelation ? [r, ur(r)] : [P.create({
5808
5807
  name: s,
5809
5808
  baseRelation: i,
5810
5809
  sourceProperty: r.sourceProperty,
@@ -5816,25 +5815,25 @@ function cr(u, t, e) {
5816
5815
  }), r];
5817
5816
  }
5818
5817
  }
5819
- function lr(u) {
5818
+ function ur(u) {
5820
5819
  let t = u;
5821
5820
  for (; t.baseRelation; )
5822
5821
  t = t.baseRelation;
5823
5822
  return t;
5824
5823
  }
5825
- function gt(u) {
5824
+ function yt(u) {
5826
5825
  return "inputEntities" in u || !("sourceProperty" in u);
5827
5826
  }
5828
- function ur(u) {
5827
+ function dr(u) {
5829
5828
  return "sourceProperty" in u;
5830
5829
  }
5831
- function bt(u) {
5832
- return gt(u) ? u.inputEntities || [] : u.inputRelations || [];
5830
+ function gt(u) {
5831
+ return yt(u) ? u.inputEntities || [] : u.inputRelations || [];
5833
5832
  }
5834
5833
  function z(u) {
5835
- return gt(u), u.name;
5834
+ return yt(u), u.name;
5836
5835
  }
5837
- class dr {
5836
+ class hr {
5838
5837
  constructor(t, e, r, i = []) {
5839
5838
  this.entities = t, this.relations = e, this.database = r, this.mergeLinks = i, 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.buildMap(), this.buildTables();
5840
5839
  }
@@ -5929,8 +5928,8 @@ class dr {
5929
5928
  }
5930
5929
  ];
5931
5930
  }));
5932
- e && g(!r.source && !r.target, "source and target is reserved name for relation attributes"), r[et] = {
5933
- name: et,
5931
+ e && g(!r.source && !r.target, "source and target is reserved name for relation attributes"), r[ne] = {
5932
+ name: ne,
5934
5933
  type: "id",
5935
5934
  fieldType: this.database.mapToDBFieldType("pk")
5936
5935
  };
@@ -6113,7 +6112,7 @@ class dr {
6113
6112
  * 统一处理 merged entities 和 merged relations
6114
6113
  */
6115
6114
  processMergedItems() {
6116
- const t = er(
6115
+ const t = rr(
6117
6116
  this.entities,
6118
6117
  this.relations
6119
6118
  );
@@ -6182,8 +6181,8 @@ class dr {
6182
6181
  buildTables() {
6183
6182
  Object.entries(this.map.records).forEach(([t, e]) => {
6184
6183
  this.tables[e.table] || (this.tables[e.table] = { columns: {
6185
- [ot]: {
6186
- name: ot,
6184
+ [at]: {
6185
+ name: at,
6187
6186
  type: "pk",
6188
6187
  fieldType: this.database.mapToDBFieldType("pk")
6189
6188
  }
@@ -6227,86 +6226,345 @@ ${Object.values(this.tables[t].columns).map((r) => ` "${r.name}" ${r.fieldTyp
6227
6226
  return this.fieldCounter++, this.fieldNameMap.set(t, i), this.usedFieldNames.add(i), i;
6228
6227
  }
6229
6228
  }
6230
- class A {
6231
- static {
6232
- this.skip = () => new kt();
6233
- }
6234
- static {
6235
- this.resolved = (t, e) => new ve(t, e);
6236
- }
6237
- static {
6238
- this.async = (t) => new Se(t);
6239
- }
6240
- static {
6241
- this.fullRecompute = (t) => new Te(t);
6242
- }
6243
- }
6244
- class kt extends A {
6245
- }
6246
- class Te extends A {
6247
- constructor(t) {
6248
- super(), this.reason = t;
6249
- }
6250
- }
6251
- class Se extends A {
6252
- constructor(t) {
6253
- super(), this.args = t;
6254
- }
6255
- }
6256
- class ve extends A {
6229
+ const tt = "_System_", q = "_Dictionary_", ne = "id", at = "_rowId", pr = C.create({
6230
+ name: tt,
6231
+ properties: [
6232
+ T.create({
6233
+ name: "concept",
6234
+ type: "string",
6235
+ collection: !1
6236
+ }),
6237
+ T.create({
6238
+ name: "key",
6239
+ type: "string",
6240
+ collection: !1
6241
+ }),
6242
+ T.create({
6243
+ name: "value",
6244
+ type: "string",
6245
+ collection: !1
6246
+ })
6247
+ ]
6248
+ }), fr = C.create({
6249
+ name: q,
6250
+ properties: [
6251
+ T.create({
6252
+ name: "key",
6253
+ type: "string",
6254
+ collection: !1
6255
+ }),
6256
+ T.create({
6257
+ name: "value",
6258
+ type: "json",
6259
+ collection: !1
6260
+ })
6261
+ ]
6262
+ }), $i = 0, Pt = 1, Pi = 2;
6263
+ class mr {
6257
6264
  constructor(t, e) {
6258
- super(), this.result = t, this.args = e;
6265
+ this.controller = t, this.scheduler = e, this.sourceMaps = [], this.sourceMapTree = {};
6259
6266
  }
6260
- }
6261
- class E {
6262
- constructor(t, e) {
6263
- this.defaultValue = t, this.record = e;
6267
+ /**
6268
+ * 初始化或重新初始化 SourceMap 数据
6269
+ * @param sourceMaps EntityEventSourceMap 数组
6270
+ */
6271
+ initialize(t) {
6272
+ const e = [[], [], []];
6273
+ for (const r of t)
6274
+ if (this.scheduler.isDataBasedComputation(r)) {
6275
+ if (Object.entries(r.dataDeps).forEach(([i, s]) => {
6276
+ const a = this.convertDataDepToERMutationEventsSourceMap(i, s, r);
6277
+ e[s.phase || Pt].push(...a);
6278
+ }), r.dataContext.type === "property" && Object.values(r.dataDeps).some((i) => i.type === "global")) {
6279
+ const i = {
6280
+ type: "records",
6281
+ source: r.dataContext.host
6282
+ };
6283
+ e[Pt].push(...this.convertDataDepToERMutationEventsSourceMap("_self", i, r, "create"));
6284
+ }
6285
+ } else {
6286
+ const { eventDeps: i } = r;
6287
+ for (const s of Object.values(i))
6288
+ e[s.phase || Pt].push({
6289
+ type: s.type,
6290
+ recordName: s.recordName,
6291
+ record: s.record,
6292
+ oldRecord: s.oldRecord,
6293
+ computation: r
6294
+ });
6295
+ }
6296
+ this.sourceMaps = e.flat(), this.sourceMapTree = this.buildDataSourceMapTree(this.sourceMaps);
6264
6297
  }
6265
- async set(t, e) {
6266
- return await this.controller.system.storage.update(this.record, m.atom({ key: "id", value: ["=", t.id] }), { [this.key]: e }), e;
6298
+ /**
6299
+ * 添加新的 SourceMap
6300
+ * @param sourceMap 要添加的 EntityEventSourceMap
6301
+ */
6302
+ addSourceMap(t) {
6303
+ this.sourceMaps.push(t), this.addToTree(t);
6267
6304
  }
6268
- async get(t) {
6269
- if (t[this.key] === void 0) {
6270
- const r = (await this.controller.system.storage.findOne(this.record, m.atom({ key: "id", value: ["=", t.id] }), void 0, [this.key]))?.[this.key];
6271
- return r !== void 0 ? r : this.defaultValue;
6272
- }
6273
- return t[this.key];
6305
+ /**
6306
+ * 批量添加 SourceMap
6307
+ * @param sourceMaps 要添加的 EntityEventSourceMap 数组
6308
+ */
6309
+ addSourceMaps(t) {
6310
+ this.sourceMaps.push(...t), t.forEach((e) => this.addToTree(e));
6274
6311
  }
6275
- }
6276
- class B {
6277
- constructor(t) {
6278
- this.defaultValue = t;
6312
+ /**
6313
+ * 根据 mutation event 查找对应的 SourceMap
6314
+ * @param mutationEvent RecordMutationEvent
6315
+ * @returns 匹配的 EntityEventSourceMap 数组
6316
+ */
6317
+ findSourceMapsForMutation(t) {
6318
+ return this.sourceMapTree[t.recordName]?.[t.type] || [];
6279
6319
  }
6280
- async set(t) {
6281
- return await this.controller.system.storage.dict.set(this.key, t), t;
6320
+ /**
6321
+ * 检查 update 类型的更新对 DataBasedComputation 是否需要触发计算
6322
+ * @param source EntityEventSourceMap
6323
+ * @param mutationEvent RecordMutationEvent
6324
+ * @returns 是否需要触发计算
6325
+ */
6326
+ shouldTriggerUpdateComputation(t, e) {
6327
+ return t.type !== "update" || !("dataDep" in t) ? !0 : t.dataDep.type === "global" && e.recordName === q ? e.record?.key === t.dataDep.source.name : !t.attributes.filter((i) => i !== "id").every(
6328
+ (i) => !e.record.hasOwnProperty(i) || e.record[i] === e.oldRecord[i]
6329
+ );
6282
6330
  }
6283
- async get() {
6284
- return await this.controller.system.storage.dict.get(this.key);
6331
+ /**
6332
+ * 检查 EventBasedComputation 的 eventDep 是否匹配当前的 mutation event
6333
+ * @param source EventBasedEntityEventsSourceMap
6334
+ * @param mutationEvent RecordMutationEvent
6335
+ * @returns 是否匹配
6336
+ */
6337
+ shouldTriggerEventBasedComputation(t, e) {
6338
+ const r = t;
6339
+ if (r.record !== void 0) {
6340
+ let i = e.record;
6341
+ if (e.type === "update" && e.oldRecord && (i = { ...e.oldRecord, ...e.record }), !this.deepMatch(i, r.record))
6342
+ return !1;
6343
+ }
6344
+ return !(r.oldRecord !== void 0 && !this.deepMatch(e.oldRecord, r.oldRecord));
6285
6345
  }
6286
- }
6287
- function Qt(u, t) {
6288
- if (t == null || u === t) return !0;
6289
- if (typeof t != "object" || t === null)
6290
- return u === t;
6291
- if (typeof u != "object" || u === null)
6292
- return !1;
6293
- for (const e in t)
6294
- if (!(e in u) || !Qt(u[e], t[e]))
6346
+ /**
6347
+ * 深度匹配对象
6348
+ * @param actual 实际的对象
6349
+ * @param expected 期望匹配的模式
6350
+ * @returns 是否匹配
6351
+ */
6352
+ deepMatch(t, e) {
6353
+ if (e == null || typeof e != "object")
6354
+ return t === e;
6355
+ if (typeof t != "object" || t === null)
6295
6356
  return !1;
6296
- return !0;
6297
- }
6298
- class ke {
6299
- constructor(t) {
6300
- this.data = t, this.map = {};
6301
- for (const e of t.transfers)
6302
- this.map[e.current.name] || (this.map[e.current.name] = []), this.map[e.current.name].push({
6303
- trigger: e.trigger,
6304
- next: e.next
6305
- });
6357
+ for (const r in e)
6358
+ if (e.hasOwnProperty(r) && (!(r in t) || !this.deepMatch(t[r], e[r])))
6359
+ return !1;
6360
+ return !0;
6306
6361
  }
6307
- findNextState(t, e) {
6308
- const r = this.map[t];
6309
- if (r) {
6362
+ convertDataDepToERMutationEventsSourceMap(t, e, r, i, s = !1) {
6363
+ const a = [];
6364
+ if (e.type === "records")
6365
+ (!i || i === "create") && a.push({
6366
+ dataDep: e,
6367
+ type: "create",
6368
+ recordName: e.source.name,
6369
+ sourceRecordName: e.source.name,
6370
+ computation: r,
6371
+ isInitial: s
6372
+ }), (!i || i === "delete") && a.push({
6373
+ dataDep: e,
6374
+ type: "delete",
6375
+ recordName: e.source.name,
6376
+ sourceRecordName: e.source.name,
6377
+ computation: r
6378
+ }), (!i || i === "update") && e.attributeQuery && a.push(...this.convertAttrsToERMutationEventsSourceMap(e, e.source.name, e.attributeQuery, [], r, !1));
6379
+ else if (e.type === "property") {
6380
+ const o = r.dataContext;
6381
+ e.attributeQuery && a.push(...this.convertAttrsToERMutationEventsSourceMap(e, o.host.name, e.attributeQuery, [], r, !0));
6382
+ } else e.type === "global" && ((!i || i === "update") && a.push({
6383
+ dataDep: e,
6384
+ type: "update",
6385
+ recordName: q,
6386
+ sourceRecordName: q,
6387
+ attributes: ["value"],
6388
+ computation: r
6389
+ }), (!i || i === "create") && a.push({
6390
+ dataDep: e,
6391
+ type: "create",
6392
+ recordName: q,
6393
+ sourceRecordName: q,
6394
+ computation: r
6395
+ }));
6396
+ return a;
6397
+ }
6398
+ convertAttrsToERMutationEventsSourceMap(t, e, r, i, s, a = !1) {
6399
+ const o = [], n = [], c = [];
6400
+ if (r.forEach((l) => {
6401
+ if (typeof l == "string" && l !== "*")
6402
+ n.push(l);
6403
+ else if (l !== "*") if (Array.isArray(l))
6404
+ c.push(l);
6405
+ else
6406
+ throw new Error(`unknown attribute type: ${l}`);
6407
+ }), n.length > 0) {
6408
+ let l = e;
6409
+ i.length > 0 && (i.at(-1) === "&" ? l = this.controller.system.storage.getRelationName(e, i.slice(0, -1).join(".")) : l = this.controller.system.storage.getEntityName(e, i.join("."))), a && o.push({
6410
+ dataDep: t,
6411
+ type: "create",
6412
+ recordName: l,
6413
+ sourceRecordName: e,
6414
+ targetPath: i,
6415
+ computation: s
6416
+ }), o.push({
6417
+ dataDep: t,
6418
+ type: "update",
6419
+ recordName: l,
6420
+ sourceRecordName: e,
6421
+ targetPath: i,
6422
+ attributes: n,
6423
+ computation: s
6424
+ });
6425
+ }
6426
+ return c.forEach(([l, d]) => {
6427
+ o.push(...this.convertRelationAttrToERMutationEventsSourceMap(t, e, d.attributeQuery, i.concat(l), s));
6428
+ }), o;
6429
+ }
6430
+ convertRelationAttrToERMutationEventsSourceMap(t, e, r, i, s) {
6431
+ const a = [];
6432
+ if (i.at(-1) !== "&") {
6433
+ const o = this.controller.system.storage.getRelationName(e, i.join("."));
6434
+ a.push({
6435
+ dataDep: t,
6436
+ type: "create",
6437
+ recordName: o,
6438
+ sourceRecordName: e,
6439
+ isRelation: !0,
6440
+ targetPath: i,
6441
+ computation: s
6442
+ }, {
6443
+ dataDep: t,
6444
+ type: "delete",
6445
+ recordName: o,
6446
+ sourceRecordName: e,
6447
+ isRelation: !0,
6448
+ targetPath: i,
6449
+ computation: s
6450
+ });
6451
+ }
6452
+ return r.length > 0 && a.push(...this.convertAttrsToERMutationEventsSourceMap(t, e, r, i, s)), a;
6453
+ }
6454
+ /**
6455
+ * 获取 SourceMapTree 的只读副本
6456
+ * @returns DataSourceMapTree 的副本
6457
+ */
6458
+ getSourceMapTree() {
6459
+ const t = {};
6460
+ for (const [e, r] of Object.entries(this.sourceMapTree)) {
6461
+ t[e] = {};
6462
+ for (const [i, s] of Object.entries(r))
6463
+ t[e][i] = [...s];
6464
+ }
6465
+ return t;
6466
+ }
6467
+ /**
6468
+ * 私有方法:构建 SourceMap 树结构
6469
+ * @param sourceMaps EntityEventSourceMap 数组
6470
+ * @returns 两层结构的树,第一层是 recordName,第二层是 type
6471
+ */
6472
+ buildDataSourceMapTree(t) {
6473
+ const e = {};
6474
+ return t.forEach((r) => {
6475
+ this.addToTree(r, e);
6476
+ }), e;
6477
+ }
6478
+ /**
6479
+ * 私有方法:将单个 SourceMap 添加到树结构中
6480
+ * @param source EntityEventSourceMap
6481
+ * @param tree 可选的目标树,默认使用实例的 sourceMapTree
6482
+ */
6483
+ addToTree(t, e) {
6484
+ const r = e || this.sourceMapTree;
6485
+ r[t.recordName] || (r[t.recordName] = {}), r[t.recordName][t.type] || (r[t.recordName][t.type] = []), r[t.recordName][t.type].push(t);
6486
+ }
6487
+ }
6488
+ class A {
6489
+ static {
6490
+ this.skip = () => new vt();
6491
+ }
6492
+ static {
6493
+ this.resolved = (t, e) => new ke(t, e);
6494
+ }
6495
+ static {
6496
+ this.async = (t) => new ve(t);
6497
+ }
6498
+ static {
6499
+ this.fullRecompute = (t) => new Se(t);
6500
+ }
6501
+ }
6502
+ class vt extends A {
6503
+ }
6504
+ class Se extends A {
6505
+ constructor(t) {
6506
+ super(), this.reason = t;
6507
+ }
6508
+ }
6509
+ class ve extends A {
6510
+ constructor(t) {
6511
+ super(), this.args = t;
6512
+ }
6513
+ }
6514
+ class ke extends A {
6515
+ constructor(t, e) {
6516
+ super(), this.result = t, this.args = e;
6517
+ }
6518
+ }
6519
+ class E {
6520
+ constructor(t, e) {
6521
+ this.defaultValue = t, this.record = e;
6522
+ }
6523
+ async set(t, e) {
6524
+ return await this.controller.system.storage.update(this.record, m.atom({ key: "id", value: ["=", t.id] }), { [this.key]: e }), e;
6525
+ }
6526
+ async get(t) {
6527
+ if (t[this.key] === void 0) {
6528
+ const r = (await this.controller.system.storage.findOne(this.record, m.atom({ key: "id", value: ["=", t.id] }), void 0, [this.key]))?.[this.key];
6529
+ return r !== void 0 ? r : this.defaultValue;
6530
+ }
6531
+ return t[this.key];
6532
+ }
6533
+ }
6534
+ class B {
6535
+ constructor(t) {
6536
+ this.defaultValue = t;
6537
+ }
6538
+ async set(t) {
6539
+ return await this.controller.system.storage.dict.set(this.key, t), t;
6540
+ }
6541
+ async get() {
6542
+ return await this.controller.system.storage.dict.get(this.key);
6543
+ }
6544
+ }
6545
+ function Qt(u, t) {
6546
+ if (t == null || u === t) return !0;
6547
+ if (typeof t != "object" || t === null)
6548
+ return u === t;
6549
+ if (typeof u != "object" || u === null)
6550
+ return !1;
6551
+ for (const e in t)
6552
+ if (!(e in u) || !Qt(u[e], t[e]))
6553
+ return !1;
6554
+ return !0;
6555
+ }
6556
+ class Ae {
6557
+ constructor(t) {
6558
+ this.data = t, this.map = {};
6559
+ for (const e of t.transfers)
6560
+ this.map[e.current.name] || (this.map[e.current.name] = []), this.map[e.current.name].push({
6561
+ trigger: e.trigger,
6562
+ next: e.next
6563
+ });
6564
+ }
6565
+ findNextState(t, e) {
6566
+ const r = this.map[t];
6567
+ if (r) {
6310
6568
  for (const i of r)
6311
6569
  if (Qt(e, i.trigger))
6312
6570
  return i.next;
@@ -6321,32 +6579,32 @@ function v(u, t) {
6321
6579
  if (!u)
6322
6580
  throw new Error(t);
6323
6581
  }
6324
- function Mi(u, t) {
6582
+ function Di(u, t) {
6325
6583
  return new Map(Array.from(u.entries()).map(([e, r]) => [e, t(e, r)]));
6326
6584
  }
6327
- function $i(u, t) {
6585
+ function Oi(u, t) {
6328
6586
  return Object.fromEntries(Object.entries(u).map(([e, r]) => [e, t(e, r)]));
6329
6587
  }
6330
- async function Pi(u, t) {
6588
+ async function Fi(u, t) {
6331
6589
  for (let e of u)
6332
6590
  if (!await t(e)) return !1;
6333
6591
  return !0;
6334
6592
  }
6335
- async function hr(u, t) {
6593
+ async function yr(u, t) {
6336
6594
  for (let e of u)
6337
6595
  if (await t(e)) return !0;
6338
6596
  return !1;
6339
6597
  }
6340
- async function pr(u, t) {
6598
+ async function gr(u, t) {
6341
6599
  for (let e of u) {
6342
6600
  const r = await t(e);
6343
6601
  if (r !== !0) return r;
6344
6602
  }
6345
6603
  return !0;
6346
6604
  }
6347
- class fr {
6605
+ class br {
6348
6606
  constructor(t, e, r) {
6349
- this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.eventDeps = {}, this.useMutationEvent = !0, this.transitionFinder = new ke(this.args), this.defaultState = this.args.defaultState;
6607
+ this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.eventDeps = {}, this.useMutationEvent = !0, this.transitionFinder = new Ae(this.args), this.defaultState = this.args.defaultState;
6350
6608
  for (const i of this.args.transfers) {
6351
6609
  const s = `${i.trigger.recordName}_${i.trigger.type}`;
6352
6610
  this.eventDeps[s] = {
@@ -6356,7 +6614,7 @@ class fr {
6356
6614
  }
6357
6615
  }
6358
6616
  static {
6359
- this.computationType = lt;
6617
+ this.computationType = ct;
6360
6618
  }
6361
6619
  static {
6362
6620
  this.contextType = "global";
@@ -6375,9 +6633,9 @@ class fr {
6375
6633
  return s ? (await this.state.currentState.set(s.name), s.computeValue ? await s.computeValue.call(this.controller, t, e) : s.name) : A.skip();
6376
6634
  }
6377
6635
  }
6378
- class mr {
6636
+ class Rr {
6379
6637
  constructor(t, e, r) {
6380
- this.controller = t, this.args = e, this.useLastValue = !0, this.eventDeps = {}, this.useMutationEvent = !0, this.transitionFinder = new ke(this.args), this.defaultState = this.args.defaultState, this.dataContext = r;
6638
+ this.controller = t, this.args = e, this.useLastValue = !0, this.eventDeps = {}, this.useMutationEvent = !0, this.transitionFinder = new Ae(this.args), this.defaultState = this.args.defaultState, this.dataContext = r;
6381
6639
  for (const i of this.args.transfers) {
6382
6640
  const s = `${i.trigger.recordName}_${i.trigger.type}`;
6383
6641
  this.eventDeps[s] = {
@@ -6387,7 +6645,7 @@ class mr {
6387
6645
  }
6388
6646
  }
6389
6647
  static {
6390
- this.computationType = lt;
6648
+ this.computationType = ct;
6391
6649
  }
6392
6650
  static {
6393
6651
  this.contextType = "property";
@@ -6423,17 +6681,17 @@ Or if you want to use state name as value, you should not set ${this.dataContext
6423
6681
  };
6424
6682
  }
6425
6683
  }
6426
- const Di = Y.create({
6684
+ const Qi = Y.create({
6427
6685
  name: "nonExistent",
6428
6686
  computeValue: () => null
6429
- }), Oi = Y.create({
6687
+ }), Vi = Y.create({
6430
6688
  name: "nonDeleted",
6431
6689
  computeValue: () => !1
6432
- }), Fi = Y.create({
6690
+ }), Li = Y.create({
6433
6691
  name: "deleted",
6434
6692
  computeValue: () => !0
6435
- }), yr = [fr, mr];
6436
- class gr {
6693
+ }), wr = [br, Rr];
6694
+ class Nr {
6437
6695
  constructor(t, e, r) {
6438
6696
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, this.matchRecordToWeight = this.args.callback.bind(this.controller), this.record = this.args.record, this.dataDeps = {
6439
6697
  main: {
@@ -6445,7 +6703,7 @@ class gr {
6445
6703
  };
6446
6704
  }
6447
6705
  static {
6448
- this.computationType = ut;
6706
+ this.computationType = lt;
6449
6707
  }
6450
6708
  static {
6451
6709
  this.contextType = "global";
@@ -6486,7 +6744,7 @@ class gr {
6486
6744
  return r;
6487
6745
  }
6488
6746
  }
6489
- class br {
6747
+ class Tr {
6490
6748
  constructor(t, e, r) {
6491
6749
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, this.matchRecordToWeight = this.args.callback.bind(this.controller), this.relation = this.controller.relations.find((a) => a.source === r.host && a.sourceProperty === this.args.property || a.target === r.host && a.targetProperty === this.args.property), v(this.relation, "weighted summation computation must specify property"), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === r.host.name, v(this.isSource ? this.relation.source === r.host : this.relation.target === r.host, "weighted summation computation relation direction error"), this.relationAttr = this.isSource ? this.relation.sourceProperty : this.relation.targetProperty, this.relatedRecordName = this.isSource ? this.relation.target.name : this.relation.source.name, this.property = this.args.property || this.relationAttr, this.reverseProperty = this.isSource ? this.relation.targetProperty : this.relation.sourceProperty;
6492
6750
  const i = this.args.attributeQuery || [];
@@ -6504,7 +6762,7 @@ class br {
6504
6762
  };
6505
6763
  }
6506
6764
  static {
6507
- this.computationType = ut;
6765
+ this.computationType = lt;
6508
6766
  }
6509
6767
  static {
6510
6768
  this.contextType = "property";
@@ -6562,8 +6820,8 @@ class br {
6562
6820
  return s;
6563
6821
  }
6564
6822
  }
6565
- const Rr = [gr, br];
6566
- class wr {
6823
+ const Sr = [Nr, Tr];
6824
+ class vr {
6567
6825
  constructor(t, e, r) {
6568
6826
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, this.callback = this.args.callback.bind(this.controller), this.dataDeps = {
6569
6827
  main: {
@@ -6575,7 +6833,7 @@ class wr {
6575
6833
  }, this.defaultValue = !this.args.notEmpty;
6576
6834
  }
6577
6835
  static {
6578
- this.computationType = ft;
6836
+ this.computationType = pt;
6579
6837
  }
6580
6838
  static {
6581
6839
  this.contextType = "global";
@@ -6616,7 +6874,7 @@ class wr {
6616
6874
  return a === s;
6617
6875
  }
6618
6876
  }
6619
- class Nr {
6877
+ class kr {
6620
6878
  constructor(t, e, r) {
6621
6879
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, this.callback = this.args.callback.bind(this.controller), this.relation = this.controller.relations.find((a) => a.source === r.host && a.sourceProperty === this.args.property || a.target === r.host && a.targetProperty === this.args.property), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === r.host.name, v(this.isSource ? this.relation.source === r.host : this.relation.target === r.host, "every computation relation direction error"), this.relationAttr = this.isSource ? this.relation.sourceProperty : this.relation.targetProperty, this.relatedRecordName = this.isSource ? this.relation.target.name : this.relation.source.name, this.property = this.args.property, this.reverseProperty = this.isSource ? this.relation.targetProperty : this.relation.sourceProperty;
6622
6880
  const i = this.args.attributeQuery || [];
@@ -6635,7 +6893,7 @@ class Nr {
6635
6893
  };
6636
6894
  }
6637
6895
  static {
6638
- this.computationType = ft;
6896
+ this.computationType = pt;
6639
6897
  }
6640
6898
  static {
6641
6899
  this.contextType = "property";
@@ -6690,8 +6948,8 @@ class Nr {
6690
6948
  return a === o;
6691
6949
  }
6692
6950
  }
6693
- const Tr = [wr, Nr];
6694
- class Sr {
6951
+ const Ar = [vr, kr];
6952
+ class Er {
6695
6953
  constructor(t, e, r) {
6696
6954
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, this.callback = this.args.callback.bind(this.controller), this.dataDeps = {
6697
6955
  main: {
@@ -6703,7 +6961,7 @@ class Sr {
6703
6961
  };
6704
6962
  }
6705
6963
  static {
6706
- this.computationType = mt;
6964
+ this.computationType = ft;
6707
6965
  }
6708
6966
  static {
6709
6967
  this.contextType = "global";
@@ -6744,7 +7002,7 @@ class Sr {
6744
7002
  return s > 0;
6745
7003
  }
6746
7004
  }
6747
- class vr {
7005
+ class Ir {
6748
7006
  constructor(t, e, r) {
6749
7007
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, this.callback = this.args.callback.bind(this.controller), this.relation = this.controller.relations.find((n) => n.source === r.host && n.sourceProperty === this.args.property || n.target === r.host && n.targetProperty === this.args.property), v(this.relation, `cannot find relation for property ${this.args.property} in "Any" computation`), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === r.host.name, v(this.isSource ? this.relation.source === r.host : this.relation.target === r.host, "any computation relation direction error");
6750
7008
  let i = this.relation.baseRelation || this.relation;
@@ -6767,7 +7025,7 @@ class vr {
6767
7025
  };
6768
7026
  }
6769
7027
  static {
6770
- this.computationType = mt;
7028
+ this.computationType = ft;
6771
7029
  }
6772
7030
  static {
6773
7031
  this.contextType = "property";
@@ -6820,8 +7078,8 @@ class vr {
6820
7078
  return s > 0;
6821
7079
  }
6822
7080
  }
6823
- const kr = [Sr, vr];
6824
- class Ar {
7081
+ const Cr = [Er, Ir];
7082
+ class xr {
6825
7083
  constructor(t, e, r) {
6826
7084
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, this.record = this.args.record, this.callback = this.args.callback?.bind(this) || (() => !0), this.dataDeps = {
6827
7085
  main: {
@@ -6833,7 +7091,7 @@ class Ar {
6833
7091
  };
6834
7092
  }
6835
7093
  static {
6836
- this.computationType = dt;
7094
+ this.computationType = ut;
6837
7095
  }
6838
7096
  static {
6839
7097
  this.contextType = "global";
@@ -6871,7 +7129,7 @@ class Ar {
6871
7129
  return s = Math.max(0, s), await this.state.count.set(s), s;
6872
7130
  }
6873
7131
  }
6874
- class Er {
7132
+ class Mr {
6875
7133
  constructor(t, e, r) {
6876
7134
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, this.callback = this.args.callback?.bind(this.controller), this.args.property ? this.relation = this.controller.relations.find((a) => a.source === r.host && a.sourceProperty === this.args.property || a.target === r.host && a.targetProperty === this.args.property) : this.relation = this.args.record, this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === r.host.name, v(this.isSource ? this.relation.source === r.host : this.relation.target === r.host, "count computation relation direction error"), this.relationAttr = this.isSource ? this.relation.sourceProperty : this.relation.targetProperty, this.relatedRecordName = this.isSource ? this.relation.target.name : this.relation.source.name, this.property = this.args.property || this.relationAttr, this.reverseProperty = this.isSource ? this.relation.targetProperty : this.relation.sourceProperty;
6877
7135
  const i = this.args.attributeQuery || [];
@@ -6889,7 +7147,7 @@ class Er {
6889
7147
  };
6890
7148
  }
6891
7149
  static {
6892
- this.computationType = dt;
7150
+ this.computationType = ut;
6893
7151
  }
6894
7152
  static {
6895
7153
  this.contextType = "property";
@@ -6953,8 +7211,8 @@ class Er {
6953
7211
  return a;
6954
7212
  }
6955
7213
  }
6956
- const Ir = [Ar, Er];
6957
- class Cr {
7214
+ const $r = [xr, Mr];
7215
+ class Pr {
6958
7216
  constructor(t, e, r) {
6959
7217
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, v(!(this.args.record && this.args.eventDeps), "Transform must have either record or eventDep"), v(!(this.args.dataDeps && this.args.eventDeps), "Transform must have either dataDeps or eventDeps"), this.transformCallback = this.args.callback.bind(this.controller), this.args.eventDeps ? this.eventDeps = this.args.eventDeps : (v(this.args.dataDeps?._source === void 0, "dataDep name `_source` is reserved for Transform"), this.dataDeps = {
6960
7218
  ...this.args.dataDeps || {},
@@ -6966,7 +7224,7 @@ class Cr {
6966
7224
  });
6967
7225
  }
6968
7226
  static {
6969
- this.computationType = xt;
7227
+ this.computationType = Ct;
6970
7228
  }
6971
7229
  static {
6972
7230
  this.contextType = ["entity", "relation"];
@@ -7062,7 +7320,7 @@ class Cr {
7062
7320
  return i;
7063
7321
  }
7064
7322
  }
7065
- const xr = [Cr];
7323
+ const Dr = [Pr];
7066
7324
  class $ {
7067
7325
  constructor(t) {
7068
7326
  this.node = t;
@@ -7161,10 +7419,10 @@ class $ {
7161
7419
  }
7162
7420
  }
7163
7421
  gt(t) {
7164
- return new At(this, ">", t);
7422
+ return new kt(this, ">", t);
7165
7423
  }
7166
7424
  lt(t) {
7167
- return new At(this, "<", t);
7425
+ return new kt(this, "<", t);
7168
7426
  }
7169
7427
  eq(t) {
7170
7428
  return new te(this, t);
@@ -7264,7 +7522,7 @@ class $ {
7264
7522
  }
7265
7523
  }
7266
7524
  }
7267
- class At {
7525
+ class kt {
7268
7526
  constructor(t, e, r) {
7269
7527
  this.left = t, this.operator = e, this.right = r;
7270
7528
  }
@@ -7334,12 +7592,12 @@ class te {
7334
7592
  }
7335
7593
  }
7336
7594
  }
7337
- class Mr {
7595
+ class Or {
7338
7596
  constructor(t, e, r) {
7339
7597
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !1, this.dataDeps = this.args.dataDeps ?? {}, this.callback = (i, s) => this.args.callback.call(this.controller, i, s), this.nextRecomputeTime = this.args.nextRecomputeTime ? (i, s) => this.args.nextRecomputeTime.call(this.controller, i, s) : void 0;
7340
7598
  }
7341
7599
  static {
7342
- this.computationType = yt;
7600
+ this.computationType = mt;
7343
7601
  }
7344
7602
  static {
7345
7603
  this.contextType = "global";
@@ -7359,14 +7617,14 @@ class Mr {
7359
7617
  let i, s;
7360
7618
  if (e instanceof $)
7361
7619
  i = e.evaluate({ now: r }), s = r + this.nextRecomputeTime(r, t);
7362
- else if (e instanceof At || e instanceof te)
7620
+ else if (e instanceof kt || e instanceof te)
7363
7621
  i = e.evaluate({ now: r }), s = e.solve();
7364
7622
  else
7365
7623
  throw new Error("Invalid result type");
7366
7624
  return await this.state.lastRecomputeTime.set(r), await this.state.nextRecomputeTime.set(s), i;
7367
7625
  }
7368
7626
  }
7369
- class $r {
7627
+ class Fr {
7370
7628
  constructor(t, e, r) {
7371
7629
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !1, this.dataDeps = {
7372
7630
  _current: {
@@ -7377,7 +7635,7 @@ class $r {
7377
7635
  }, this.isResultNumber = this.dataContext.id.type === "number", this.callback = (i, s) => this.args.callback.call(this.controller, i, s), this.nextRecomputeTime = this.args.nextRecomputeTime ? (i, s) => this.args.nextRecomputeTime.call(this.controller, i, s) : void 0;
7378
7636
  }
7379
7637
  static {
7380
- this.computationType = yt;
7638
+ this.computationType = mt;
7381
7639
  }
7382
7640
  static {
7383
7641
  this.contextType = "property";
@@ -7397,15 +7655,15 @@ class $r {
7397
7655
  let s, a;
7398
7656
  if (r instanceof $)
7399
7657
  s = r.evaluate({ now: i }), a = i + this.nextRecomputeTime(i, t);
7400
- else if (r instanceof At || r instanceof te)
7658
+ else if (r instanceof kt || r instanceof te)
7401
7659
  s = r.evaluate({ now: i }), a = r.solve();
7402
7660
  else
7403
7661
  throw new Error("Invalid result type");
7404
7662
  return await this.state.lastRecomputeTime.set(e, i), await this.state.nextRecomputeTime.set(e, a), s;
7405
7663
  }
7406
7664
  }
7407
- const Pr = [Mr, $r];
7408
- class Dr {
7665
+ const Qr = [Or, Fr];
7666
+ class Vr {
7409
7667
  constructor(t, e, r) {
7410
7668
  if (this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, this.record = this.args.record, !this.args.attributeQuery || this.args.attributeQuery.length === 0)
7411
7669
  throw new Error("Sum computation requires attributeQuery with at least one field");
@@ -7422,7 +7680,7 @@ class Dr {
7422
7680
  };
7423
7681
  }
7424
7682
  static {
7425
- this.computationType = ht;
7683
+ this.computationType = dt;
7426
7684
  }
7427
7685
  static {
7428
7686
  this.contextType = "global";
@@ -7466,7 +7724,7 @@ class Dr {
7466
7724
  return s;
7467
7725
  }
7468
7726
  }
7469
- class Or {
7727
+ class Lr {
7470
7728
  constructor(t, e, r) {
7471
7729
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, this.relation = this.controller.relations.find((o) => o.source === r.host && o.sourceProperty === this.args.property || o.target === r.host && o.targetProperty === this.args.property), v(this.relation, "summation computation must specify either property or record"), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === r.host.name, v(this.isSource ? this.relation.source === r.host : this.relation.target === r.host, "summation computation relation direction error"), this.relationAttr = this.isSource ? this.relation.sourceProperty : this.relation.targetProperty, this.relatedRecordName = this.isSource ? this.relation.target.name : this.relation.source.name, this.property = this.args.property, this.reverseProperty = this.isSource ? this.relation.targetProperty : this.relation.sourceProperty;
7472
7730
  const i = this.args.attributeQuery || [];
@@ -7487,7 +7745,7 @@ class Or {
7487
7745
  };
7488
7746
  }
7489
7747
  static {
7490
- this.computationType = ht;
7748
+ this.computationType = dt;
7491
7749
  }
7492
7750
  static {
7493
7751
  this.contextType = "property";
@@ -7555,8 +7813,8 @@ class Or {
7555
7813
  return a;
7556
7814
  }
7557
7815
  }
7558
- const Fr = [Dr, Or];
7559
- class Qr {
7816
+ const _r = [Vr, Lr];
7817
+ class qr {
7560
7818
  constructor(t, e, r) {
7561
7819
  if (this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, this.record = this.args.record, !this.args.attributeQuery || this.args.attributeQuery.length === 0)
7562
7820
  throw new Error("Average computation requires attributeQuery with at least one field");
@@ -7573,7 +7831,7 @@ class Qr {
7573
7831
  };
7574
7832
  }
7575
7833
  static {
7576
- this.computationType = pt;
7834
+ this.computationType = ht;
7577
7835
  }
7578
7836
  static {
7579
7837
  this.contextType = "global";
@@ -7629,7 +7887,7 @@ class Qr {
7629
7887
  return await this.state.sum.set(a), await this.state.count.set(s), s > 0 ? a / s : 0;
7630
7888
  }
7631
7889
  }
7632
- class Vr {
7890
+ class Br {
7633
7891
  constructor(t, e, r) {
7634
7892
  this.controller = t, this.args = e, this.dataContext = r, this.useLastValue = !0, this.dataDeps = {}, this.relation = this.controller.relations.find((o) => o.source === r.host && o.sourceProperty === this.args.property || o.target === r.host && o.targetProperty === this.args.property), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === r.host.name, v(this.isSource ? this.relation.source === r.host : this.relation.target === r.host, "average computation relation direction error"), this.relationAttr = this.isSource ? this.relation.sourceProperty : this.relation.targetProperty, this.relatedRecordName = this.isSource ? this.relation.target.name : this.relation.source.name, this.property = this.args.property || this.relationAttr, this.reverseProperty = this.isSource ? this.relation.targetProperty : this.relation.sourceProperty;
7635
7893
  const i = this.args.attributeQuery || [];
@@ -7650,7 +7908,7 @@ class Vr {
7650
7908
  };
7651
7909
  }
7652
7910
  static {
7653
- this.computationType = pt;
7911
+ this.computationType = ht;
7654
7912
  }
7655
7913
  static {
7656
7914
  this.contextType = "property";
@@ -7713,8 +7971,8 @@ class Vr {
7713
7971
  return await this.state.count.set(e.record, a), a > 0 ? o / a : 0;
7714
7972
  }
7715
7973
  }
7716
- const Lr = [Qr, Vr];
7717
- class $t {
7974
+ const Wr = [qr, Br];
7975
+ class Mt {
7718
7976
  constructor(t, e, r) {
7719
7977
  this.controller = t, this.args = e, this.dataContext = r, this.state = {}, this.dataDeps = {}, this.useLastValue = e.useLastValue !== void 0 ? e.useLastValue : !0, e.dataDeps && (this.dataDeps = e.dataDeps), e.compute && (this.computeCallback = e.compute, this.compute = async (...i) => {
7720
7978
  if (this.computeCallback) {
@@ -7785,22 +8043,22 @@ class $t {
7785
8043
  return A.skip();
7786
8044
  }
7787
8045
  }
7788
- class qr extends $t {
8046
+ class Jr extends Mt {
7789
8047
  static {
7790
8048
  this.contextType = "global";
7791
8049
  }
7792
8050
  }
7793
- class _r extends $t {
8051
+ class Hr extends Mt {
7794
8052
  static {
7795
8053
  this.contextType = "entity";
7796
8054
  }
7797
8055
  }
7798
- class Br extends $t {
8056
+ class jr extends Mt {
7799
8057
  static {
7800
8058
  this.contextType = "relation";
7801
8059
  }
7802
8060
  }
7803
- class Wr extends $t {
8061
+ class Ur extends Mt {
7804
8062
  static {
7805
8063
  this.contextType = "property";
7806
8064
  }
@@ -7815,11 +8073,11 @@ If you want to use aggregated data from all records in the entity/relation, you
7815
8073
  super(t, e, r);
7816
8074
  }
7817
8075
  }
7818
- const Jr = [
7819
- qr,
7820
- _r,
7821
- Br,
7822
- Wr
8076
+ const Gr = [
8077
+ Jr,
8078
+ Hr,
8079
+ jr,
8080
+ Ur
7823
8081
  ];
7824
8082
  class j extends Error {
7825
8083
  constructor(t, e = {}) {
@@ -7955,7 +8213,7 @@ class U extends j {
7955
8213
  }), this.interactionName = e.interactionName, this.userId = e.userId, this.payload = e.payload, this.executionPhase = e.executionPhase, this.severity = e.severity || V.HIGH;
7956
8214
  }
7957
8215
  }
7958
- class ne extends j {
8216
+ class ce extends j {
7959
8217
  constructor(t, e = {}) {
7960
8218
  super(t, {
7961
8219
  errorType: e.context?.errorType || "ActivityError",
@@ -7987,7 +8245,7 @@ class Q extends j {
7987
8245
  }), this.handleName = e.handleName, this.computationName = e.computationName, this.dataContext = e.dataContext, this.computationPhase = e.computationPhase, this.severity = e.severity || V.MEDIUM;
7988
8246
  }
7989
8247
  }
7990
- class ce extends Q {
8248
+ class le extends Q {
7991
8249
  constructor(t, e = {}) {
7992
8250
  super(t, {
7993
8251
  ...e,
@@ -8104,235 +8362,10 @@ class O extends j {
8104
8362
  });
8105
8363
  }
8106
8364
  }
8107
- const tt = "_System_", _ = "_Dictionary_", et = "id", ot = "_rowId", Hr = C.create({
8108
- name: tt,
8109
- properties: [
8110
- T.create({
8111
- name: "concept",
8112
- type: "string",
8113
- collection: !1
8114
- }),
8115
- T.create({
8116
- name: "key",
8117
- type: "string",
8118
- collection: !1
8119
- }),
8120
- T.create({
8121
- name: "value",
8122
- type: "string",
8123
- collection: !1
8124
- })
8125
- ]
8126
- }), jr = C.create({
8127
- name: _,
8128
- properties: [
8129
- T.create({
8130
- name: "key",
8131
- type: "string",
8132
- collection: !1
8133
- }),
8134
- T.create({
8135
- name: "value",
8136
- type: "json",
8137
- collection: !1
8138
- })
8139
- ]
8140
- });
8141
- class Ur {
8142
- constructor(t, e) {
8143
- this.controller = t, this.scheduler = e, this.sourceMaps = [], this.sourceMapTree = {};
8144
- }
8145
- /**
8146
- * 初始化或重新初始化 SourceMap 数据
8147
- * @param sourceMaps EntityEventSourceMap 数组
8148
- */
8149
- initialize(t) {
8150
- const e = [];
8151
- for (const r of t)
8152
- if (this.scheduler.isDataBasedComputation(r)) {
8153
- if (e.push(
8154
- ...Object.entries(r.dataDeps).map(([i, s]) => this.convertDataDepToERMutationEventsSourceMap(i, s, r)).flat()
8155
- ), r.dataContext.type === "property" && Object.values(r.dataDeps).some((i) => i.type === "global")) {
8156
- const i = {
8157
- type: "records",
8158
- source: r.dataContext.host
8159
- };
8160
- e.push(...this.convertDataDepToERMutationEventsSourceMap("_self", i, r, "create"));
8161
- }
8162
- } else {
8163
- const { eventDeps: i } = r;
8164
- for (const s of Object.values(i))
8165
- e.push({
8166
- type: s.type,
8167
- recordName: s.recordName,
8168
- computation: r
8169
- });
8170
- }
8171
- this.sourceMaps = [...e], this.sourceMapTree = this.buildDataSourceMapTree(this.sourceMaps);
8172
- }
8173
- /**
8174
- * 添加新的 SourceMap
8175
- * @param sourceMap 要添加的 EntityEventSourceMap
8176
- */
8177
- addSourceMap(t) {
8178
- this.sourceMaps.push(t), this.addToTree(t);
8179
- }
8180
- /**
8181
- * 批量添加 SourceMap
8182
- * @param sourceMaps 要添加的 EntityEventSourceMap 数组
8183
- */
8184
- addSourceMaps(t) {
8185
- this.sourceMaps.push(...t), t.forEach((e) => this.addToTree(e));
8186
- }
8187
- /**
8188
- * 根据 mutation event 查找对应的 SourceMap
8189
- * @param mutationEvent RecordMutationEvent
8190
- * @returns 匹配的 EntityEventSourceMap 数组
8191
- */
8192
- findSourceMapsForMutation(t) {
8193
- return this.sourceMapTree[t.recordName]?.[t.type] || [];
8194
- }
8195
- /**
8196
- * 检查 update 类型的更新对 DataBasedComputation 是否需要触发计算
8197
- * @param source EntityEventSourceMap
8198
- * @param mutationEvent RecordMutationEvent
8199
- * @returns 是否需要触发计算
8200
- */
8201
- shouldTriggerUpdateComputation(t, e) {
8202
- return t.type !== "update" || !("dataDep" in t) ? !0 : t.dataDep.type === "global" && e.recordName === _ ? e.record?.key === t.dataDep.source.name : !t.attributes.filter((i) => i !== "id").every(
8203
- (i) => !e.record.hasOwnProperty(i) || e.record[i] === e.oldRecord[i]
8204
- );
8205
- }
8206
- convertDataDepToERMutationEventsSourceMap(t, e, r, i, s = !1) {
8207
- const a = [];
8208
- if (e.type === "records")
8209
- (!i || i === "create") && a.push({
8210
- dataDep: e,
8211
- type: "create",
8212
- recordName: e.source.name,
8213
- sourceRecordName: e.source.name,
8214
- computation: r,
8215
- isInitial: s
8216
- }), (!i || i === "delete") && a.push({
8217
- dataDep: e,
8218
- type: "delete",
8219
- recordName: e.source.name,
8220
- sourceRecordName: e.source.name,
8221
- computation: r
8222
- }), (!i || i === "update") && e.attributeQuery && a.push(...this.convertAttrsToERMutationEventsSourceMap(e, e.source.name, e.attributeQuery, [], r, !1));
8223
- else if (e.type === "property") {
8224
- const o = r.dataContext;
8225
- e.attributeQuery && a.push(...this.convertAttrsToERMutationEventsSourceMap(e, o.host.name, e.attributeQuery, [], r, !0));
8226
- } else e.type === "global" && ((!i || i === "update") && a.push({
8227
- dataDep: e,
8228
- type: "update",
8229
- recordName: _,
8230
- sourceRecordName: _,
8231
- attributes: ["value"],
8232
- computation: r
8233
- }), (!i || i === "create") && a.push({
8234
- dataDep: e,
8235
- type: "create",
8236
- recordName: _,
8237
- sourceRecordName: _,
8238
- computation: r
8239
- }));
8240
- return a;
8241
- }
8242
- convertAttrsToERMutationEventsSourceMap(t, e, r, i, s, a = !1) {
8243
- const o = [], n = [], c = [];
8244
- if (r.forEach((l) => {
8245
- if (typeof l == "string" && l !== "*")
8246
- n.push(l);
8247
- else if (l !== "*") if (Array.isArray(l))
8248
- c.push(l);
8249
- else
8250
- throw new Error(`unknown attribute type: ${l}`);
8251
- }), n.length > 0) {
8252
- let l = e;
8253
- i.length > 0 && (i.at(-1) === "&" ? l = this.controller.system.storage.getRelationName(e, i.slice(0, -1).join(".")) : l = this.controller.system.storage.getEntityName(e, i.join("."))), a && o.push({
8254
- dataDep: t,
8255
- type: "create",
8256
- recordName: l,
8257
- sourceRecordName: e,
8258
- targetPath: i,
8259
- computation: s
8260
- }), o.push({
8261
- dataDep: t,
8262
- type: "update",
8263
- recordName: l,
8264
- sourceRecordName: e,
8265
- targetPath: i,
8266
- attributes: n,
8267
- computation: s
8268
- });
8269
- }
8270
- return c.forEach(([l, d]) => {
8271
- o.push(...this.convertRelationAttrToERMutationEventsSourceMap(t, e, d.attributeQuery, i.concat(l), s));
8272
- }), o;
8273
- }
8274
- convertRelationAttrToERMutationEventsSourceMap(t, e, r, i, s) {
8275
- const a = [];
8276
- if (i.at(-1) !== "&") {
8277
- const o = this.controller.system.storage.getRelationName(e, i.join("."));
8278
- a.push({
8279
- dataDep: t,
8280
- type: "create",
8281
- recordName: o,
8282
- sourceRecordName: e,
8283
- isRelation: !0,
8284
- targetPath: i,
8285
- computation: s
8286
- }, {
8287
- dataDep: t,
8288
- type: "delete",
8289
- recordName: o,
8290
- sourceRecordName: e,
8291
- isRelation: !0,
8292
- targetPath: i,
8293
- computation: s
8294
- });
8295
- }
8296
- return r.length > 0 && a.push(...this.convertAttrsToERMutationEventsSourceMap(t, e, r, i, s)), a;
8297
- }
8298
- /**
8299
- * 获取 SourceMapTree 的只读副本
8300
- * @returns DataSourceMapTree 的副本
8301
- */
8302
- getSourceMapTree() {
8303
- const t = {};
8304
- for (const [e, r] of Object.entries(this.sourceMapTree)) {
8305
- t[e] = {};
8306
- for (const [i, s] of Object.entries(r))
8307
- t[e][i] = [...s];
8308
- }
8309
- return t;
8310
- }
8311
- /**
8312
- * 私有方法:构建 SourceMap 树结构
8313
- * @param sourceMaps EntityEventSourceMap 数组
8314
- * @returns 两层结构的树,第一层是 recordName,第二层是 type
8315
- */
8316
- buildDataSourceMapTree(t) {
8317
- const e = {};
8318
- return t.forEach((r) => {
8319
- this.addToTree(r, e);
8320
- }), e;
8321
- }
8322
- /**
8323
- * 私有方法:将单个 SourceMap 添加到树结构中
8324
- * @param source EntityEventSourceMap
8325
- * @param tree 可选的目标树,默认使用实例的 sourceMapTree
8326
- */
8327
- addToTree(t, e) {
8328
- const r = e || this.sourceMapTree;
8329
- r[t.recordName] || (r[t.recordName] = {}), r[t.recordName][t.type] || (r[t.recordName][t.type] = []), r[t.recordName][t.type].push(t);
8330
- }
8331
- }
8332
8365
  const Dt = "_ASYNC_TASK_";
8333
- class Gr {
8366
+ class Kr {
8334
8367
  constructor(t, e, r, i, s) {
8335
- this.controller = t, this.computationsHandles = /* @__PURE__ */ new Map(), this.computationHandleMap = /* @__PURE__ */ new Map(), this.erMutationEventSources = [], this.dataSourceMapTree = {}, this.sourceMapManager = new Ur(this.controller, this), this.buildComputationHandleMap(s);
8368
+ this.controller = t, this.computationsHandles = /* @__PURE__ */ new Map(), this.computationHandleMap = /* @__PURE__ */ new Map(), this.erMutationEventSources = [], this.dataSourceMapTree = {}, this.sourceMapManager = new mr(this.controller, this), this.buildComputationHandleMap(s);
8336
8369
  const a = [];
8337
8370
  i.forEach((o) => {
8338
8371
  o.computation && a.push({ dataContext: { type: "global", id: o }, args: o.computation });
@@ -8529,7 +8562,7 @@ class Gr {
8529
8562
  const r = this.sourceMapManager.findSourceMapsForMutation(e);
8530
8563
  if (r.length > 0)
8531
8564
  for (const i of r)
8532
- this.sourceMapManager.shouldTriggerUpdateComputation(i, e) && await this.runDirtyRecordsComputation(i, e);
8565
+ this.sourceMapManager.shouldTriggerUpdateComputation(i, e) && (!("dataDep" in i) && !this.sourceMapManager.shouldTriggerEventBasedComputation(i, e) || await this.runDirtyRecordsComputation(i, e));
8533
8566
  }
8534
8567
  });
8535
8568
  }
@@ -8571,7 +8604,7 @@ class Gr {
8571
8604
  }
8572
8605
  async computeDataBasedDirtyRecordsAndEvents(t, e) {
8573
8606
  let r = [];
8574
- if (t.dataDep.type === "global" && e.recordName === _)
8607
+ if (t.dataDep.type === "global" && e.recordName === q)
8575
8608
  if (t.computation.dataContext.type === "property") {
8576
8609
  const i = t.computation.dataContext;
8577
8610
  r = (await this.controller.system.storage.find(i.host.name, m.atom({ key: "id", value: ["not", null] }), {}, ["*"])).map((a) => [a, {
@@ -8723,7 +8756,7 @@ class Gr {
8723
8756
  try {
8724
8757
  o = await this.controller.retrieveLastValue(t.dataContext, r);
8725
8758
  } catch (n) {
8726
- throw new ce("Failed to retrieve last value for incremental computation", {
8759
+ throw new le("Failed to retrieve last value for incremental computation", {
8727
8760
  handleName: t.constructor.name,
8728
8761
  computationName: t.args.constructor.displayName,
8729
8762
  dataContext: t.dataContext,
@@ -8737,7 +8770,7 @@ class Gr {
8737
8770
  try {
8738
8771
  o = await this.controller.retrieveLastValue(t.dataContext, r);
8739
8772
  } catch (n) {
8740
- throw new ce("Failed to retrieve last value for incremental patch computation", {
8773
+ throw new le("Failed to retrieve last value for incremental patch computation", {
8741
8774
  handleName: t.constructor.name,
8742
8775
  computationName: t.args.constructor.displayName,
8743
8776
  dataContext: t.dataContext,
@@ -8752,7 +8785,7 @@ class Gr {
8752
8785
  dataContext: t.dataContext,
8753
8786
  computationPhase: "type-validation"
8754
8787
  });
8755
- if (s instanceof Te) {
8788
+ if (s instanceof Se) {
8756
8789
  const o = t;
8757
8790
  if (!o.compute)
8758
8791
  throw new Q("compute must be defined for computation when incrementalCompute returns ComputationResultFullRecompute", {
@@ -8773,9 +8806,9 @@ class Gr {
8773
8806
  causedBy: o instanceof Error ? o : new Error(String(o))
8774
8807
  });
8775
8808
  }
8776
- if (s instanceof kt)
8809
+ if (s instanceof vt)
8777
8810
  return;
8778
- if (s instanceof Se)
8811
+ if (s instanceof ve)
8779
8812
  try {
8780
8813
  return await this.createAsyncTask(t, s.args, r);
8781
8814
  } catch (o) {
@@ -8788,7 +8821,7 @@ class Gr {
8788
8821
  });
8789
8822
  }
8790
8823
  try {
8791
- const o = s instanceof ve ? await t.asyncReturn(s.result, s.args) : s;
8824
+ const o = s instanceof ke ? await t.asyncReturn(s.result, s.args) : s;
8792
8825
  t.incrementalPatchCompute ? await this.controller.applyResultPatch(t.dataContext, o, r) : await this.controller.applyResult(t.dataContext, o, r);
8793
8826
  } catch (o) {
8794
8827
  throw new Q("Failed to apply computation result", {
@@ -8909,7 +8942,7 @@ class Gr {
8909
8942
  }
8910
8943
  }
8911
8944
  }
8912
- class Ae {
8945
+ class Ee {
8913
8946
  constructor(t, e, r) {
8914
8947
  this.interaction = t, this.controller = e, this.activitySeqCall = r, this.system = e.system;
8915
8948
  }
@@ -8937,7 +8970,7 @@ class Ae {
8937
8970
  async checkUser(t, e, r) {
8938
8971
  let i;
8939
8972
  if (!this.interaction.userAttributives) return !0;
8940
- const s = It.is(this.interaction.userAttributives) ? R.fromValue(
8973
+ const s = Et.is(this.interaction.userAttributives) ? R.fromValue(
8941
8974
  this.interaction.userAttributives.content
8942
8975
  ) : R.atom(
8943
8976
  this.interaction.userAttributives
@@ -8963,7 +8996,7 @@ class Ae {
8963
8996
  }
8964
8997
  if (this.isConceptAlias(e)) {
8965
8998
  const s = [];
8966
- return await hr(e.for, async (o) => {
8999
+ return await yr(e.for, async (o) => {
8967
9000
  const n = await this.isConcept(t, o);
8968
9001
  return n === !0 ? !0 : (s.push(n), !1);
8969
9002
  }) ? !0 : { name: e.name, type: "conceptAlias", stack: i, error: s };
@@ -9003,7 +9036,7 @@ class Ae {
9003
9036
  throw O.payloadValidationFailed(i.name, "data is not a ref", s);
9004
9037
  if (i.base)
9005
9038
  if (i.isCollection) {
9006
- const a = await pr(s, (o) => this.checkConcept(o, i.base));
9039
+ const a = await gr(s, (o) => this.checkConcept(o, i.base));
9007
9040
  if (a !== !0)
9008
9041
  throw O.conceptCheckFailed(i.name, a);
9009
9042
  } else {
@@ -9025,7 +9058,7 @@ class Ae {
9025
9058
  }
9026
9059
  async checkCondition(t) {
9027
9060
  if (this.interaction.conditions) {
9028
- const e = Mt.is(this.interaction.conditions) ? new R(this.interaction.conditions.content) : R.atom(this.interaction.conditions), r = async (s) => {
9061
+ const e = xt.is(this.interaction.conditions) ? new R(this.interaction.conditions.content) : R.atom(this.interaction.conditions), r = async (s) => {
9029
9062
  if (!s) return !0;
9030
9063
  if (s.content) {
9031
9064
  const a = s.content;
@@ -9059,7 +9092,7 @@ class Ae {
9059
9092
  v(!r.sideEffects[o], `sideEffect ${o} already exists`), r.sideEffects[o] = { result: n, error: c };
9060
9093
  }
9061
9094
  isGetInteraction() {
9062
- return this.interaction.action === Be;
9095
+ return this.interaction.action === We;
9063
9096
  }
9064
9097
  async saveEvent(t) {
9065
9098
  return await this.controller.activityManager.saveEvent(t);
@@ -9149,11 +9182,11 @@ class D {
9149
9182
  }
9150
9183
  static createInitialState(t) {
9151
9184
  const e = { uuid: t.uuid };
9152
- return it.is(t.content) && (e.children = t.childSeqs.map((r) => G.createInitialState(r.head))), e;
9185
+ return rt.is(t.content) && (e.children = t.childSeqs.map((r) => G.createInitialState(r.head))), e;
9153
9186
  }
9154
9187
  static create(t, e, r) {
9155
9188
  const i = e.getNodeByUUID(t.uuid);
9156
- if (it.is(i.content)) {
9189
+ if (rt.is(i.content)) {
9157
9190
  const a = D.GroupStateNodeType.get(i.content.type), o = new a(i, e, r);
9158
9191
  return o.isGroup = !0, o.children = t?.children?.map((n) => G.create(n, e, o)), o;
9159
9192
  } else
@@ -9175,7 +9208,7 @@ class D {
9175
9208
  this.parent.transferToNext(this.node.uuid);
9176
9209
  }
9177
9210
  }
9178
- class le {
9211
+ class ue {
9179
9212
  constructor(t, e) {
9180
9213
  this.graph = e, this.root = G.create(t, this.graph);
9181
9214
  }
@@ -9192,7 +9225,7 @@ class le {
9192
9225
  return this.root.toJSON();
9193
9226
  }
9194
9227
  }
9195
- class rt {
9228
+ class et {
9196
9229
  constructor(t, e) {
9197
9230
  this.activity = t, this.controller = e, this.uuidToNode = /* @__PURE__ */ new Map(), this.uuidToInteractionCall = /* @__PURE__ */ new Map(), this.interactionCallByName = /* @__PURE__ */ new Map(), this.rawToNode = /* @__PURE__ */ new Map(), this.checkUserRef = async (r, i, s) => (v(r.isRef, "attributive must be ref"), ((await this.getActivity(s))?.refs)[r.name] === i.id), this.system = e.system, this.graph = this.buildGraph(t);
9198
9231
  }
@@ -9201,8 +9234,8 @@ class rt {
9201
9234
  }
9202
9235
  static {
9203
9236
  this.from = (t, e) => {
9204
- let r = rt.cache.get(t);
9205
- return r || (r = new rt(t, e), rt.cache.set(t, r)), r;
9237
+ let r = et.cache.get(t);
9238
+ return r || (r = new et(t, e), et.cache.set(t, r)), r;
9206
9239
  };
9207
9240
  }
9208
9241
  buildGraph(t, e) {
@@ -9210,7 +9243,7 @@ class rt {
9210
9243
  for (let o of t.interactions) {
9211
9244
  const n = { content: o, next: null, uuid: o.uuid, parentGroup: e, parentSeq: i };
9212
9245
  this.uuidToNode.set(o.uuid, n), this.rawToNode.set(o, n);
9213
- const c = new Ae(o, this.controller, this);
9246
+ const c = new Ee(o, this.controller, this);
9214
9247
  this.uuidToInteractionCall.set(o.uuid, c), o.name && this.interactionCallByName.set(o.name, c);
9215
9248
  }
9216
9249
  for (let o of t.gateways) {
@@ -9230,7 +9263,7 @@ class rt {
9230
9263
  const s = /* @__PURE__ */ new Set([...Object.values(t.interactions), ...Object.values(t.groups)]), a = /* @__PURE__ */ new Set([...Object.values(t.interactions), ...Object.values(t.groups)]);
9231
9264
  if (t.transfers?.forEach((o) => {
9232
9265
  const n = this.rawToNode.get(o.source) || r.get(o.source), c = this.rawToNode.get(o.target) || r.get(o.target);
9233
- v(!!n, `cannot find source ${o.source.name}`), v(!!c, `cannot find target ${o.source.name}`), st.is(n) ? n.next.push(c) : n.next = c, st.is(c) ? c.prev.push(n) : c.prev = n, a.delete(o.source), s.delete(o.target);
9266
+ v(!!n, `cannot find source ${o.source.name}`), v(!!c, `cannot find target ${o.source.name}`), it.is(n) ? n.next.push(c) : n.next = c, it.is(c) ? c.prev.push(n) : c.prev = n, a.delete(o.source), s.delete(o.target);
9234
9267
  }), s.size !== 1) throw new Error(`start node must one, current: ${s.size}`);
9235
9268
  if (a.size !== 1) throw new Error(`end node must be one, current: ${a.size}`);
9236
9269
  return Object.assign(i, {
@@ -9239,7 +9272,7 @@ class rt {
9239
9272
  }), i;
9240
9273
  }
9241
9274
  async create() {
9242
- const t = le.createInitialState(this.graph.head);
9275
+ const t = ue.createInitialState(this.graph.head);
9243
9276
  return {
9244
9277
  activityId: (await this.controller.activityManager.createActivity({
9245
9278
  name: this.activity.name,
@@ -9286,7 +9319,7 @@ class rt {
9286
9319
  return e.parentSeq.tail === e;
9287
9320
  }
9288
9321
  isActivityHead(t, e = this.graph.head) {
9289
- return it.is(this.graph.head.content) ? !!this.graph.head.childSeqs?.some((r) => this.isActivityHead(t, r.head)) : t === this.graph.head.content;
9322
+ return rt.is(this.graph.head.content) ? !!this.graph.head.childSeqs?.some((r) => this.isActivityHead(t, r.head)) : t === this.graph.head.content;
9290
9323
  }
9291
9324
  async callInteraction(t, e, r) {
9292
9325
  const i = this.uuidToInteractionCall.get(e);
@@ -9298,7 +9331,7 @@ class rt {
9298
9331
  s = (await this.create()).activityId;
9299
9332
  }
9300
9333
  } else if (!t) return { error: "activityId must be provided for non-head interaction of an activity" };
9301
- const a = new le(await this.getState(s), this);
9334
+ const a = new ue(await this.getState(s), this);
9302
9335
  if (!a.isInteractionAvailable(e)) return { error: `interaction ${e} not available` };
9303
9336
  const o = await i.call(r, s, this.checkUserRef);
9304
9337
  if (o.error)
@@ -9326,7 +9359,7 @@ class rt {
9326
9359
  }), await this.setActivity(t, { refs: i });
9327
9360
  }
9328
9361
  }
9329
- class Kr extends D {
9362
+ class Xr extends D {
9330
9363
  onChange(t, e) {
9331
9364
  if (this.graph.isStartNode(t)) {
9332
9365
  if (e)
@@ -9337,24 +9370,24 @@ class Kr extends D {
9337
9370
  }
9338
9371
  }
9339
9372
  }
9340
- D.GroupStateNodeType.set("any", Kr);
9341
- class Xr extends D {
9373
+ D.GroupStateNodeType.set("any", Xr);
9374
+ class Yr extends D {
9342
9375
  onChange(t, e) {
9343
9376
  this.isGroupCompleted() && this.complete();
9344
9377
  }
9345
9378
  }
9346
- D.GroupStateNodeType.set("every", Xr);
9347
- class Yr extends D {
9379
+ D.GroupStateNodeType.set("every", Yr);
9380
+ class zr extends D {
9348
9381
  onChange(t, e) {
9349
9382
  this.graph.isEndNode(t) && this.complete();
9350
9383
  }
9351
9384
  }
9352
- D.GroupStateNodeType.set("race", Yr);
9353
- class zr extends D {
9385
+ D.GroupStateNodeType.set("race", zr);
9386
+ class Zr extends D {
9354
9387
  // 可以根据 group 上的具体配置逻辑,来动态决定。
9355
9388
  }
9356
- D.GroupStateNodeType.set("program", zr);
9357
- const I = new pe(), Vt = "_Interaction_", Tt = "_Activity_", Ee = C.create({
9389
+ D.GroupStateNodeType.set("program", Zr);
9390
+ const I = new fe(), Vt = "_Interaction_", Nt = "_Activity_", Ie = C.create({
9358
9391
  name: Vt,
9359
9392
  properties: [
9360
9393
  T.create({
@@ -9383,8 +9416,8 @@ const I = new pe(), Vt = "_Interaction_", Tt = "_Activity_", Ee = C.create({
9383
9416
  collection: !1
9384
9417
  })
9385
9418
  ]
9386
- }), Ie = C.create({
9387
- name: Tt,
9419
+ }), Ce = C.create({
9420
+ name: Nt,
9388
9421
  properties: [
9389
9422
  T.create({
9390
9423
  name: "name",
@@ -9407,21 +9440,21 @@ const I = new pe(), Vt = "_Interaction_", Tt = "_Activity_", Ee = C.create({
9407
9440
  collection: !1
9408
9441
  })
9409
9442
  ]
9410
- }), Zr = P.create({
9443
+ }), ti = P.create({
9411
9444
  name: "activityInteraction",
9412
- source: Ie,
9445
+ source: Ce,
9413
9446
  sourceProperty: "interaction",
9414
- target: Ee,
9447
+ target: Ie,
9415
9448
  targetProperty: "activity",
9416
9449
  type: "1:n"
9417
9450
  });
9418
- class ti {
9451
+ class ei {
9419
9452
  constructor(t, e, r) {
9420
- this.controller = t, this.activityCalls = /* @__PURE__ */ new Map(), this.activityCallsByName = /* @__PURE__ */ new Map(), this.interactionCallsByName = /* @__PURE__ */ new Map(), this.interactionCalls = /* @__PURE__ */ new Map(), this.controller.entities.push(Ie, Ee), this.controller.relations.push(Zr), e.forEach((i) => {
9421
- const s = new rt(i, t);
9453
+ this.controller = t, this.activityCalls = /* @__PURE__ */ new Map(), this.activityCallsByName = /* @__PURE__ */ new Map(), this.interactionCallsByName = /* @__PURE__ */ new Map(), this.interactionCalls = /* @__PURE__ */ new Map(), this.controller.entities.push(Ce, Ie), this.controller.relations.push(ti), e.forEach((i) => {
9454
+ const s = new et(i, t);
9422
9455
  this.activityCalls.set(i.uuid, s), i.name && (v(!this.activityCallsByName.has(i.name), `activity name ${i.name} is duplicated`), this.activityCallsByName.set(i.name, s));
9423
9456
  }), r.forEach((i) => {
9424
- const s = new Ae(i, t);
9457
+ const s = new Ee(i, t);
9425
9458
  this.interactionCalls.set(i.uuid, s), i.name && (v(!this.interactionCallsByName.has(i.name), `interaction name ${i.name} is duplicated`), this.interactionCallsByName.set(i.name, s));
9426
9459
  });
9427
9460
  }
@@ -9473,7 +9506,7 @@ class ti {
9473
9506
  try {
9474
9507
  const o = this.activityCallsByName.get(t);
9475
9508
  if (!o)
9476
- throw new ne(`Cannot find activity for ${t}`, {
9509
+ throw new ce(`Cannot find activity for ${t}`, {
9477
9510
  activityName: t,
9478
9511
  context: {
9479
9512
  interactionName: e,
@@ -9496,7 +9529,7 @@ class ti {
9496
9529
  const c = await o.callInteraction(r, n.interaction.uuid, i);
9497
9530
  return c.error ? (a.error({ label: "activity", message: o.activity.name }), await this.controller.system.storage.rollbackTransaction(o.activity.name)) : (await this.controller.system.storage.commitTransaction(o.activity.name), await this.runRecordChangeSideEffects(c, a)), c;
9498
9531
  } catch (o) {
9499
- throw new ne("Unexpected error during activity interaction call", {
9532
+ throw new ce("Unexpected error during activity interaction call", {
9500
9533
  activityName: t,
9501
9534
  context: {
9502
9535
  interactionName: e,
@@ -9535,7 +9568,7 @@ class ti {
9535
9568
  }
9536
9569
  }
9537
9570
  async createActivity(t) {
9538
- return this.controller.system.storage.create(Tt, {
9571
+ return this.controller.system.storage.create(Nt, {
9539
9572
  ...t,
9540
9573
  state: t.state,
9541
9574
  refs: t.refs
@@ -9545,10 +9578,10 @@ class ti {
9545
9578
  const r = {
9546
9579
  ...e
9547
9580
  };
9548
- return delete r.state, delete r.refs, e.state && (r.state = e.state), e.refs && (r.refs = e.refs), this.controller.system.storage.update(Tt, t, r);
9581
+ return delete r.state, delete r.refs, e.state && (r.state = e.state), e.refs && (r.refs = e.refs), this.controller.system.storage.update(Nt, t, r);
9549
9582
  }
9550
9583
  async getActivity(t) {
9551
- return (await this.controller.system.storage.find(Tt, t, void 0, ["*"])).map((e) => ({
9584
+ return (await this.controller.system.storage.find(Nt, t, void 0, ["*"])).map((e) => ({
9552
9585
  ...e,
9553
9586
  state: e.state,
9554
9587
  refs: e.refs
@@ -9575,15 +9608,15 @@ class ti {
9575
9608
  return this.interactionCallsByName.get(t);
9576
9609
  }
9577
9610
  }
9578
- const Et = new pe();
9579
- function ei() {
9580
- return Et.getStore()?.effects;
9611
+ const At = new fe();
9612
+ function ri() {
9613
+ return At.getStore()?.effects;
9581
9614
  }
9582
- function ue(u) {
9583
- const t = Et.getStore();
9615
+ function de(u) {
9616
+ const t = At.getStore();
9584
9617
  t?.effects && t.effects.push(...u);
9585
9618
  }
9586
- const Qi = "User";
9619
+ const _i = "User";
9587
9620
  class K {
9588
9621
  constructor(t) {
9589
9622
  this.name = t.name, this.record = t.record, this.content = t.content;
@@ -9592,7 +9625,7 @@ class K {
9592
9625
  return new K(t);
9593
9626
  }
9594
9627
  }
9595
- const Lt = "_isDeleted_", Vi = {
9628
+ const Lt = "_isDeleted_", qi = {
9596
9629
  create() {
9597
9630
  return T.create({
9598
9631
  name: Lt,
@@ -9600,7 +9633,7 @@ const Lt = "_isDeleted_", Vi = {
9600
9633
  });
9601
9634
  }
9602
9635
  };
9603
- class Li {
9636
+ class Bi {
9604
9637
  constructor(t) {
9605
9638
  this.recordNameToSideEffects = /* @__PURE__ */ new Map(), this.globals = {
9606
9639
  BoolExp: R,
@@ -9619,21 +9652,21 @@ class Li {
9619
9652
  forceThtrowInteractionError: d = !1
9620
9653
  // 会 catch 住 error,并在 result 中返回。
9621
9654
  } = t;
9622
- this.system = e, this.ignorePermission = l, this.forceThtrowInteractionError = d, this.entities = [...r], this.relations = [...i], this.activities = [...s], this.interactions = [...a], this.dict = [...o], this.recordMutationSideEffects = [...n], this.activityManager = new ti(this, s, a);
9655
+ this.system = e, this.ignorePermission = l, this.forceThtrowInteractionError = d, this.entities = [...r], this.relations = [...i], this.activities = [...s], this.interactions = [...a], this.dict = [...o], this.recordMutationSideEffects = [...n], this.activityManager = new ei(this, s, a);
9623
9656
  const h = [
9624
- ...Ir,
9625
- ...xr,
9626
- ...kr,
9627
- ...Tr,
9628
- ...Rr,
9629
- ...Fr,
9630
- ...Lr,
9631
- ...Pr,
9632
- ...yr,
9633
- ...Jr,
9657
+ ...$r,
9658
+ ...Dr,
9659
+ ...Cr,
9660
+ ...Ar,
9661
+ ...Sr,
9662
+ ..._r,
9663
+ ...Wr,
9664
+ ...Qr,
9665
+ ...wr,
9666
+ ...Gr,
9634
9667
  ...c
9635
9668
  ];
9636
- this.scheduler = new Gr(this, this.entities, this.relations, this.dict, h), n.forEach((p) => {
9669
+ this.scheduler = new Kr(this, this.entities, this.relations, this.dict, h), n.forEach((p) => {
9637
9670
  let y = this.recordNameToSideEffects.get(p.record.name);
9638
9671
  y || this.recordNameToSideEffects.set(p.record.name, y = /* @__PURE__ */ new Set()), y.add(p);
9639
9672
  });
@@ -9653,7 +9686,7 @@ class Li {
9653
9686
  }
9654
9687
  }
9655
9688
  async applyResult(t, e, r) {
9656
- if (!(e instanceof kt)) {
9689
+ if (!(e instanceof vt)) {
9657
9690
  if (t.type === "global")
9658
9691
  return this.system.storage.dict.set(t.id.name, e);
9659
9692
  if (t.type === "entity") {
@@ -9677,7 +9710,7 @@ class Li {
9677
9710
  }
9678
9711
  }
9679
9712
  async applyResultPatch(t, e, r) {
9680
- if (e instanceof kt || e === void 0) return;
9713
+ if (e instanceof vt || e === void 0) return;
9681
9714
  const i = Array.isArray(e) ? e : [e];
9682
9715
  for (const s of i) {
9683
9716
  if (t.type === "global")
@@ -9701,7 +9734,7 @@ class Li {
9701
9734
  }
9702
9735
  async callInteraction(t, e) {
9703
9736
  try {
9704
- const r = { effects: [] }, i = await Et.run(r, async () => await this.activityManager.callInteraction(t, e));
9737
+ const r = { effects: [] }, i = await At.run(r, async () => await this.activityManager.callInteraction(t, e));
9705
9738
  if (i.effects = r.effects, i.error && this.forceThtrowInteractionError)
9706
9739
  throw i.error;
9707
9740
  return i;
@@ -9717,7 +9750,7 @@ class Li {
9717
9750
  }
9718
9751
  async callActivityInteraction(t, e, r, i) {
9719
9752
  try {
9720
- const s = { effects: [] }, a = await Et.run(s, async () => await this.activityManager.callActivityInteraction(t, e, r, i));
9753
+ const s = { effects: [] }, a = await At.run(s, async () => await this.activityManager.callActivityInteraction(t, e, r, i));
9721
9754
  if (a.effects && s.effects.length > 0) {
9722
9755
  const o = s.effects.filter(
9723
9756
  (n) => !a.effects.some(
@@ -9770,7 +9803,7 @@ class Li {
9770
9803
  this.callbacks.has(t) || this.callbacks.set(t, /* @__PURE__ */ new Set()), this.callbacks.get(t).add(e);
9771
9804
  }
9772
9805
  }
9773
- let ri = class {
9806
+ let ii = class {
9774
9807
  constructor(t) {
9775
9808
  this.db = t;
9776
9809
  }
@@ -9782,12 +9815,12 @@ let ri = class {
9782
9815
  return e === void 0 ? await this.db.scheme(`INSERT INTO _IDS_ (name, last) VALUES ('${t}', ${r})`, i) : await this.db.update("UPDATE _IDS_ SET last = ? WHERE name = ?", [r, t], void 0, i), r;
9783
9816
  }
9784
9817
  };
9785
- class ii {
9818
+ class si {
9786
9819
  constructor(t = ":memory:", e) {
9787
- this.file = t, this.options = e, this.idSystem = new ri(this), this.logger = this.options?.logger || Rt;
9820
+ this.file = t, this.options = e, this.idSystem = new ii(this), this.logger = this.options?.logger || bt;
9788
9821
  }
9789
9822
  async open() {
9790
- this.db = new Me(this.file, this.options), await this.idSystem.setup();
9823
+ this.db = new $e(this.file, this.options), await this.idSystem.setup();
9791
9824
  }
9792
9825
  async query(t, e = [], r = "") {
9793
9826
  const i = I.getStore(), s = this.logger.child(i?.logContext || {}), a = e.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
@@ -9814,7 +9847,7 @@ class ii {
9814
9847
  name: r,
9815
9848
  sql: t,
9816
9849
  params: a
9817
- }), this.db.prepare(`${t} RETURNING ${ot}`).run(...a);
9850
+ }), this.db.prepare(`${t} RETURNING ${at}`).run(...a);
9818
9851
  }
9819
9852
  async delete(t, e, r = "") {
9820
9853
  const i = I.getStore(), s = this.logger.child(i?.logContext || {}), a = e.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
@@ -9854,22 +9887,22 @@ class ii {
9854
9887
  return t === "pk" ? "INTEGER PRIMARY KEY" : t === "id" ? "INT" : e || t === "object" || t === "json" ? "JSON" : t === "string" ? "TEXT" : t === "boolean" ? "INT(2)" : t === "number" || t === "timestamp" ? "INT" : t;
9855
9888
  }
9856
9889
  }
9857
- function si(u) {
9890
+ function ai(u) {
9858
9891
  return encodeURI(JSON.stringify(u));
9859
9892
  }
9860
- function ai(u) {
9893
+ function oi(u) {
9861
9894
  return u === void 0 ? void 0 : JSON.parse(decodeURI(u));
9862
9895
  }
9863
- class oi {
9896
+ class ni {
9864
9897
  constructor(t) {
9865
9898
  this.db = t, this.callbacks = /* @__PURE__ */ new Set(), this.dict = {
9866
9899
  get: async (e) => {
9867
9900
  const r = m.atom({ key: "key", value: ["=", e] });
9868
- return (await this.queryHandle.findOne(_, r, void 0, ["value"]))?.value?.raw;
9901
+ return (await this.queryHandle.findOne(q, r, void 0, ["value"]))?.value?.raw;
9869
9902
  },
9870
9903
  set: async (e, r) => {
9871
- const i = m.atom({ key: "key", value: ["=", e] }), s = await this.queryHandle.findOne(_, i, void 0, ["value"]);
9872
- return s ? this.callWithEvents(this.queryHandle.update.bind(this.queryHandle), [_, m.atom({ key: "id", value: ["=", s.id] }), { key: e, value: { raw: r } }], []) : this.callWithEvents(this.queryHandle.create.bind(this.queryHandle), [_, { key: e, value: { raw: r } }], []);
9904
+ const i = m.atom({ key: "key", value: ["=", e] }), s = await this.queryHandle.findOne(q, i, void 0, ["value"]);
9905
+ return s ? this.callWithEvents(this.queryHandle.update.bind(this.queryHandle), [q, m.atom({ key: "id", value: ["=", s.id] }), { key: e, value: { raw: r } }], []) : this.callWithEvents(this.queryHandle.create.bind(this.queryHandle), [q, { key: e, value: { raw: r } }], []);
9873
9906
  }
9874
9907
  };
9875
9908
  }
@@ -9885,20 +9918,20 @@ class oi {
9885
9918
  // CAUTION kv 结构数据的实现也用 er。这是系统约定,因为也需要 Record 事件!
9886
9919
  async get(t, e, r) {
9887
9920
  const i = m.atom({ key: "key", value: ["=", e] }).and({ key: "concept", value: ["=", t] }), s = (await this.queryHandle.findOne(tt, i, void 0, ["value"]))?.value;
9888
- return s === void 0 ? r : ai(s);
9921
+ return s === void 0 ? r : oi(s);
9889
9922
  }
9890
9923
  async set(t, e, r, i) {
9891
9924
  const s = m.atom({ key: "key", value: ["=", e] }).and({ key: "concept", value: ["=", t] });
9892
- return await this.queryHandle.findOne(tt, s, void 0, ["value"]) ? this.callWithEvents(this.queryHandle.update.bind(this.queryHandle), [tt, s, { concept: t, key: e.toString(), value: si(r) }], i) : this.callWithEvents(this.queryHandle.create.bind(this.queryHandle), [tt, { concept: t, key: e.toString(), value: encodeURI(JSON.stringify(r)) }], i);
9925
+ return await this.queryHandle.findOne(tt, s, void 0, ["value"]) ? this.callWithEvents(this.queryHandle.update.bind(this.queryHandle), [tt, s, { concept: t, key: e.toString(), value: ai(r) }], i) : this.callWithEvents(this.queryHandle.create.bind(this.queryHandle), [tt, { concept: t, key: e.toString(), value: encodeURI(JSON.stringify(r)) }], i);
9893
9926
  }
9894
9927
  async setup(t, e, r = !1) {
9895
9928
  await this.db.open(r);
9896
- const i = new dr(
9929
+ const i = new hr(
9897
9930
  t,
9898
9931
  e,
9899
9932
  this.db
9900
9933
  );
9901
- r && await i.createTables(), this.queryHandle = new Ye(new ze(i.map), this.db), this.map = i.map;
9934
+ r && await i.createTables(), this.queryHandle = new ze(new Ze(i.map), this.db), this.map = i.map;
9902
9935
  }
9903
9936
  findOne(...t) {
9904
9937
  return this.queryHandle.findOne(...t);
@@ -9918,8 +9951,8 @@ class oi {
9918
9951
  async callWithEvents(t, e, r = []) {
9919
9952
  const i = [], s = await t(...e, i), a = await this.dispatch(i);
9920
9953
  r.push(...i, ...a);
9921
- const o = ei();
9922
- return o && i.length > 0 && ue(i), o && a.length > 0 && ue(a), s;
9954
+ const o = ri();
9955
+ return o && i.length > 0 && de(i), o && a.length > 0 && de(a), s;
9923
9956
  }
9924
9957
  findRelationByName(...t) {
9925
9958
  return this.queryHandle.findRelationByName(...t);
@@ -9957,7 +9990,7 @@ class oi {
9957
9990
  return this.db.close();
9958
9991
  }
9959
9992
  }
9960
- var ni = /* @__PURE__ */ ((u) => (u[u.ERROR = 0] = "ERROR", u[u.INFO = 1] = "INFO", u))(ni || {});
9993
+ var ci = /* @__PURE__ */ ((u) => (u[u.ERROR = 0] = "ERROR", u[u.INFO = 1] = "INFO", u))(ci || {});
9961
9994
  class ee {
9962
9995
  constructor(t = 0) {
9963
9996
  this.level = t;
@@ -9972,7 +10005,7 @@ class ee {
9972
10005
  return new ee(this.level);
9973
10006
  }
9974
10007
  }
9975
- var ci = /* @__PURE__ */ ((u) => (u[u.MUTE = -1] = "MUTE", u[u.ERROR = 0] = "ERROR", u[u.INFO = 1] = "INFO", u[u.DEBUG = 2] = "DEBUG", u))(ci || {});
10008
+ var li = /* @__PURE__ */ ((u) => (u[u.MUTE = -1] = "MUTE", u[u.ERROR = 0] = "ERROR", u[u.INFO = 1] = "INFO", u[u.DEBUG = 2] = "DEBUG", u))(li || {});
9976
10009
  class re {
9977
10010
  constructor(t = 0) {
9978
10011
  this.level = t;
@@ -9990,13 +10023,13 @@ class re {
9990
10023
  return new re(this.level);
9991
10024
  }
9992
10025
  }
9993
- const Rt = new ee(), li = new re();
9994
- class _i {
9995
- constructor(t = new ii(void 0, { logger: Rt }), e = li) {
9996
- this.logger = e, this.conceptClass = /* @__PURE__ */ new Map(), this.storage = new oi(t);
10026
+ const bt = new ee(), ui = new re();
10027
+ class Ji {
10028
+ constructor(t = new si(void 0, { logger: bt }), e = ui) {
10029
+ this.logger = e, this.conceptClass = /* @__PURE__ */ new Map(), this.storage = new ni(t);
9997
10030
  }
9998
10031
  setup(t, e, r, i = !1) {
9999
- const s = new we(t, e), { entities: a, relations: o } = s.getAll();
10032
+ const s = new Ne(t, e), { entities: a, relations: o } = s.getAll();
10000
10033
  return r.forEach(({ dataContext: n, state: c }) => {
10001
10034
  Object.entries(c).forEach(([l, d]) => {
10002
10035
  if (d instanceof E) {
@@ -10022,7 +10055,7 @@ class _i {
10022
10055
  }
10023
10056
  });
10024
10057
  }), this.storage.setup(
10025
- [...a, jr, Hr],
10058
+ [...a, fr, pr],
10026
10059
  o,
10027
10060
  i
10028
10061
  );
@@ -10031,8 +10064,8 @@ class _i {
10031
10064
  this.storage.destroy();
10032
10065
  }
10033
10066
  }
10034
- const { Client: de } = $e;
10035
- let ui = class {
10067
+ const { Client: he } = Pe;
10068
+ let di = class {
10036
10069
  constructor(t) {
10037
10070
  this.db = t;
10038
10071
  }
@@ -10044,14 +10077,14 @@ let ui = class {
10044
10077
  return e === void 0 ? await this.db.scheme(`INSERT INTO "_IDS_" (name, last) VALUES ('${t}', ${r})`, i) : await this.db.update('UPDATE "_IDS_" SET last = $1 WHERE name = $2', [r, t], void 0, i), r;
10045
10078
  }
10046
10079
  };
10047
- class Wi {
10080
+ class ji {
10048
10081
  constructor(t, e = {}) {
10049
- this.database = t, this.options = e, this.idSystem = new ui(this), this.logger = this.options?.logger || Rt, this.db = new de({
10082
+ this.database = t, this.options = e, this.idSystem = new di(this), this.logger = this.options?.logger || bt, this.db = new he({
10050
10083
  ...e
10051
10084
  });
10052
10085
  }
10053
10086
  async open(t = !1) {
10054
- await this.db.connect(), (await this.db.query(`SELECT FROM pg_database WHERE datname = '${this.database}'`)).rows.length === 0 ? await this.db.query(`CREATE DATABASE ${this.database}`) : (t && (await this.db.query(`DROP DATABASE ${this.database}`), await this.db.query(`CREATE DATABASE ${this.database}`)), this.db = new de({
10087
+ await this.db.connect(), (await this.db.query(`SELECT FROM pg_database WHERE datname = '${this.database}'`)).rows.length === 0 ? await this.db.query(`CREATE DATABASE ${this.database}`) : (t && (await this.db.query(`DROP DATABASE ${this.database}`), await this.db.query(`CREATE DATABASE ${this.database}`)), this.db = new he({
10055
10088
  ...this.options,
10056
10089
  database: this.database
10057
10090
  }), await this.db.connect()), await this.idSystem.setup();
@@ -10082,7 +10115,7 @@ class Wi {
10082
10115
  sql: t,
10083
10116
  params: a
10084
10117
  });
10085
- const o = `${t} RETURNING "${ot}"`;
10118
+ const o = `${t} RETURNING "${at}"`;
10086
10119
  return (await this.db.query(o, a)).rows[0];
10087
10120
  }
10088
10121
  async delete(t, e, r = "") {
@@ -10125,7 +10158,7 @@ class Wi {
10125
10158
  return t === "pk" ? "INT GENERATED ALWAYS AS IDENTITY" : t === "id" ? "INT" : e || t === "object" ? "JSON" : t === "string" ? "TEXT" : t === "boolean" ? "BOOLEAN" : t === "number" ? "INT" : t === "timestamp" ? "TIMESTAMP" : t;
10126
10159
  }
10127
10160
  }
10128
- let di = class {
10161
+ let hi = class {
10129
10162
  constructor(t) {
10130
10163
  this.db = t;
10131
10164
  }
@@ -10133,12 +10166,12 @@ let di = class {
10133
10166
  return this.db.scheme('CREATE Table IF NOT EXISTS "_IDS_" (last INTEGER, name TEXT)');
10134
10167
  }
10135
10168
  async getAutoId(t) {
10136
- return he();
10169
+ return pe();
10137
10170
  }
10138
10171
  };
10139
- class Hi {
10172
+ class Gi {
10140
10173
  constructor(t, e = {}) {
10141
- this.database = t, this.options = e, this.idSystem = new di(this), this.logger = this.options?.logger || Rt, this.db = new Pe(this.database);
10174
+ this.database = t, this.options = e, this.idSystem = new hi(this), this.logger = this.options?.logger || bt, this.db = new De(this.database);
10142
10175
  }
10143
10176
  async open(t = !1) {
10144
10177
  if (t) {
@@ -10190,7 +10223,7 @@ class Hi {
10190
10223
  sql: t,
10191
10224
  params: a
10192
10225
  });
10193
- const o = `${t} RETURNING "${ot}"`;
10226
+ const o = `${t} RETURNING "${at}"`;
10194
10227
  try {
10195
10228
  return (await this.db.query(o, a)).rows[0];
10196
10229
  } catch (n) {
@@ -10253,7 +10286,7 @@ class Hi {
10253
10286
  return t === "pk" ? "SERIAL PRIMARY KEY" : t === "id" ? "UUID" : e || t === "object" ? "JSON" : t === "string" ? "TEXT" : t === "boolean" ? "BOOL" : t === "number" ? "INT" : t === "timestamp" ? "TIMESTAMP" : t;
10254
10287
  }
10255
10288
  }
10256
- class hi {
10289
+ class pi {
10257
10290
  constructor(t) {
10258
10291
  this.db = t;
10259
10292
  }
@@ -10265,9 +10298,9 @@ class hi {
10265
10298
  return e === void 0 ? await this.db.scheme(`INSERT INTO "_IDS_" (name, last) VALUES ('${t}', ${r})`, i) : await this.db.update('UPDATE "_IDS_" SET last = ? WHERE name = ?', [r, t], void 0, i), r;
10266
10299
  }
10267
10300
  }
10268
- class ji {
10301
+ class Ki {
10269
10302
  constructor(t, e = {}) {
10270
- this.database = t, this.options = e, this.idSystem = new hi(this), this.logger = this.options?.logger || Rt;
10303
+ this.database = t, this.options = e, this.idSystem = new pi(this), this.logger = this.options?.logger || bt;
10271
10304
  }
10272
10305
  async open(t = !1) {
10273
10306
  ({ ...this.options }, this.db = await ae.createConnection({
@@ -10346,173 +10379,176 @@ class ji {
10346
10379
  }
10347
10380
  }
10348
10381
  export {
10349
- Tt as ACTIVITY_RECORD,
10350
- He as ALL_ATTR_SYMBOL,
10382
+ Nt as ACTIVITY_RECORD,
10383
+ je as ALL_ATTR_SYMBOL,
10351
10384
  Dt as ASYNC_TASK_RECORD,
10352
- Ct as Action,
10385
+ It as Action,
10353
10386
  Jt as Activity,
10354
- rt as ActivityCall,
10355
- it as ActivityGroup,
10356
- Zr as ActivityInteractionRelation,
10357
- ti as ActivityManager,
10358
- Ie as ActivityStateEntity,
10359
- mt as Any,
10360
- kr as AnyHandles,
10387
+ et as ActivityCall,
10388
+ rt as ActivityGroup,
10389
+ ti as ActivityInteractionRelation,
10390
+ ei as ActivityManager,
10391
+ Ce as ActivityStateEntity,
10392
+ ft as Any,
10393
+ Cr as AnyHandles,
10361
10394
  W as AttributeInfo,
10362
10395
  x as AttributeQuery,
10363
10396
  X as Attributive,
10364
- It as Attributives,
10365
- pt as Average,
10366
- Lr as AverageHandles,
10367
- ki as BaseKlass,
10368
- nt as BoolAtomData,
10397
+ Et as Attributives,
10398
+ ht as Average,
10399
+ Wr as AverageHandles,
10400
+ Ai as BaseKlass,
10401
+ ot as BoolAtomData,
10369
10402
  R as BoolExp,
10370
- ct as BoolExpressionData,
10403
+ nt as BoolExpressionData,
10371
10404
  J as ComputationDataDepError,
10372
10405
  Q as ComputationError,
10373
10406
  A as ComputationResult,
10374
- Se as ComputationResultAsync,
10375
- Te as ComputationResultFullRecompute,
10376
- ve as ComputationResultResolved,
10377
- kt as ComputationResultSkip,
10378
- ce as ComputationStateError,
10407
+ ve as ComputationResultAsync,
10408
+ Se as ComputationResultFullRecompute,
10409
+ ke as ComputationResultResolved,
10410
+ vt as ComputationResultSkip,
10411
+ le as ComputationStateError,
10379
10412
  Ht as Condition,
10380
10413
  O as ConditionError,
10381
- Mt as Conditions,
10382
- Li as Controller,
10383
- dt as Count,
10384
- Ir as CountHandles,
10414
+ xt as Conditions,
10415
+ Bi as Controller,
10416
+ ut as Count,
10417
+ $r as CountHandles,
10385
10418
  Zt as Custom,
10386
- Jr as CustomHandles,
10419
+ Gr as CustomHandles,
10387
10420
  ee as DBConsoleLogger,
10388
- ni as DBLogLevel,
10389
- dr as DBSetup,
10390
- Fi as DELETED_STATE,
10391
- _ as DICTIONARY_RECORD,
10421
+ ci as DBLogLevel,
10422
+ hr as DBSetup,
10423
+ Li as DELETED_STATE,
10424
+ q as DICTIONARY_RECORD,
10392
10425
  jt as DataAttributive,
10393
10426
  zt as DataAttributives,
10394
10427
  Bt as Dictionary,
10395
- jr as DictionaryEntity,
10428
+ fr as DictionaryEntity,
10396
10429
  C as Entity,
10397
- _r as EntityCustomHandle,
10398
- Ye as EntityQueryHandle,
10399
- ze as EntityToTableMap,
10430
+ Hr as EntityCustomHandle,
10431
+ ze as EntityQueryHandle,
10432
+ Ze as EntityToTableMap,
10400
10433
  te as Equation,
10401
10434
  Ut as Event,
10402
- ft as Every,
10403
- Tr as EveryHandles,
10435
+ pt as Every,
10436
+ Ar as EveryHandles,
10404
10437
  $ as Expression,
10405
- st as Gateway,
10406
- Be as GetAction,
10407
- Sr as GlobalAnyHandle,
10408
- Qr as GlobalAverageHandle,
10438
+ it as Gateway,
10439
+ We as GetAction,
10440
+ Er as GlobalAnyHandle,
10441
+ qr as GlobalAverageHandle,
10409
10442
  B as GlobalBoundState,
10410
- Ar as GlobalCountHandle,
10411
- qr as GlobalCustomHandle,
10412
- wr as GlobalEveryHandle,
10413
- Mr as GlobalRealTimeComputation,
10414
- fr as GlobalStateMachineHandle,
10415
- Dr as GlobalSumHandle,
10416
- gr as GlobalWeightedSummationHandle,
10443
+ xr as GlobalCountHandle,
10444
+ Jr as GlobalCustomHandle,
10445
+ vr as GlobalEveryHandle,
10446
+ Or as GlobalRealTimeComputation,
10447
+ br as GlobalStateMachineHandle,
10448
+ Vr as GlobalSumHandle,
10449
+ Nr as GlobalWeightedSummationHandle,
10417
10450
  Lt as HARD_DELETION_PROPERTY_NAME,
10418
- Vi as HardDeletionProperty,
10419
- et as ID_ATTR,
10451
+ qi as HardDeletionProperty,
10452
+ ne as ID_ATTR,
10420
10453
  Vt as INTERACTION_RECORD,
10421
- At as Inequality,
10454
+ kt as Inequality,
10422
10455
  Wt as Interaction,
10423
- Ae as InteractionCall,
10424
- Ee as InteractionEventEntity,
10425
- qt as KlassByName,
10456
+ Ee as InteractionCall,
10457
+ Ie as InteractionEventEntity,
10458
+ _t as KlassByName,
10426
10459
  f as LINK_SYMBOL,
10427
- vt as LinkInfo,
10460
+ St as LinkInfo,
10428
10461
  m as MatchExp,
10429
- Je as Modifier,
10430
- _i as MonoSystem,
10431
- ji as MysqlDB,
10432
- Oi as NON_DELETED_STATE,
10433
- Di as NON_EXIST_STATE,
10462
+ He as Modifier,
10463
+ Ji as MonoSystem,
10464
+ Ki as MysqlDB,
10465
+ Vi as NON_DELETED_STATE,
10466
+ Qi as NON_EXIST_STATE,
10434
10467
  L as NewRecordData,
10435
- Hi as PGLiteDB,
10468
+ Gi as PGLiteDB,
10469
+ Pi as PHASE_AFTER_ALL,
10470
+ $i as PHASE_BEFORE_ALL,
10471
+ Pt as PHASE_NORMAL,
10436
10472
  Xt as Payload,
10437
10473
  Kt as PayloadItem,
10438
- Wi as PostgreSQLDB,
10474
+ ji as PostgreSQLDB,
10439
10475
  T as Property,
10440
- vr as PropertyAnyHandle,
10441
- Vr as PropertyAverageHandle,
10442
- Er as PropertyCountHandle,
10443
- Wr as PropertyCustomHandle,
10444
- Nr as PropertyEveryHandle,
10445
- $r as PropertyRealTimeComputation,
10446
- mr as PropertyStateMachineHandle,
10447
- Or as PropertySumHandle,
10448
- _t as PropertyTypes,
10449
- br as PropertyWeightedSummationHandle,
10450
- Re as Query,
10451
- be as QueryItem,
10452
- Ne as ROOT_LABEL,
10453
- ot as ROW_ID_ATTR,
10454
- yt as RealTime,
10455
- Pr as RealTimeHandles,
10476
+ Ir as PropertyAnyHandle,
10477
+ Br as PropertyAverageHandle,
10478
+ Mr as PropertyCountHandle,
10479
+ Ur as PropertyCustomHandle,
10480
+ kr as PropertyEveryHandle,
10481
+ Fr as PropertyRealTimeComputation,
10482
+ Rr as PropertyStateMachineHandle,
10483
+ Lr as PropertySumHandle,
10484
+ qt as PropertyTypes,
10485
+ Tr as PropertyWeightedSummationHandle,
10486
+ we as Query,
10487
+ Re as QueryItem,
10488
+ Te as ROOT_LABEL,
10489
+ at as ROW_ID_ATTR,
10490
+ mt as RealTime,
10491
+ Qr as RealTimeHandles,
10456
10492
  E as RecordBoundState,
10457
- at as RecordInfo,
10493
+ st as RecordInfo,
10458
10494
  K as RecordMutationSideEffect,
10459
10495
  M as RecordQuery,
10460
- Xe as RecordQueryAgent,
10461
- q as RecordQueryTree,
10462
- Cr as RecordsTransformHandle,
10463
- St as RecursiveContext,
10464
- we as RefContainer,
10496
+ Ye as RecordQueryAgent,
10497
+ _ as RecordQueryTree,
10498
+ Pr as RecordsTransformHandle,
10499
+ Tt as RecursiveContext,
10500
+ Ne as RefContainer,
10465
10501
  P as Relation,
10466
- Br as RelationCustomHandle,
10467
- ii as SQLiteDB,
10502
+ jr as RelationCustomHandle,
10503
+ si as SQLiteDB,
10468
10504
  tt as SYSTEM_RECORD,
10469
- Gr as Scheduler,
10505
+ Kr as Scheduler,
10470
10506
  Yt as SideEffect,
10471
- lt as StateMachine,
10472
- yr as StateMachineHandles,
10507
+ ct as StateMachine,
10508
+ wr as StateMachineHandles,
10473
10509
  Y as StateNode,
10474
10510
  Gt as StateTransfer,
10475
- ht as Summation,
10476
- Fr as SummationHandles,
10511
+ dt as Summation,
10512
+ _r as SummationHandles,
10477
10513
  re as SystemConsoleLogger,
10478
- Hr as SystemEntity,
10479
- ci as SystemLogLevel,
10480
- ye as Transfer,
10481
- xt as Transform,
10482
- xr as TransformHandles,
10483
- Qi as USER_ENTITY,
10484
- ut as WeightedSummation,
10485
- Rr as WeightedSummationHandles,
10486
- ue as addToCurrentEffects,
10514
+ pr as SystemEntity,
10515
+ li as SystemLogLevel,
10516
+ ge as Transfer,
10517
+ Ct as Transform,
10518
+ Dr as TransformHandles,
10519
+ _i as USER_ENTITY,
10520
+ lt as WeightedSummation,
10521
+ Sr as WeightedSummationHandles,
10522
+ de as addToCurrentEffects,
10487
10523
  v as assert,
10488
- Et as asyncEffectsContext,
10524
+ At as asyncEffectsContext,
10489
10525
  I as asyncInteractionContext,
10490
- Ci as boolExpToAttributives,
10491
- wi as clearAllInstances,
10492
- vi as createClass,
10493
- Fe as createInstances,
10494
- Si as createInstancesFromString,
10495
- xi as createUserRoleAttributive,
10496
- Rt as dbConsoleLogger,
10497
- wt as deepClone,
10498
- Pi as everyAsync,
10499
- pr as everyWithErrorAsync,
10500
- Mi as filterMap,
10501
- Ei as findRootActivity,
10502
- ge as forEachInteraction,
10526
+ xi as boolExpToAttributives,
10527
+ Ni as clearAllInstances,
10528
+ ki as createClass,
10529
+ Qe as createInstances,
10530
+ vi as createInstancesFromString,
10531
+ Mi as createUserRoleAttributive,
10532
+ bt as dbConsoleLogger,
10533
+ Rt as deepClone,
10534
+ Fi as everyAsync,
10535
+ gr as everyWithErrorAsync,
10536
+ Di as filterMap,
10537
+ Ii as findRootActivity,
10538
+ be as forEachInteraction,
10503
10539
  S as generateUUID,
10504
- ei as getCurrentEffects,
10505
- Ai as getInteractions,
10506
- De as indexBy,
10507
- fe as isObject,
10508
- me as isPlainObject,
10509
- $i as mapObject,
10510
- Ii as parse,
10511
- Oe as registerKlass,
10512
- Ni as removeAllInstance,
10513
- hr as someAsync,
10514
- Ti as stringifyAllInstances,
10540
+ ri as getCurrentEffects,
10541
+ Ei as getInteractions,
10542
+ Oe as indexBy,
10543
+ me as isObject,
10544
+ ye as isPlainObject,
10545
+ Oi as mapObject,
10546
+ Ci as parse,
10547
+ Fe as registerKlass,
10548
+ Ti as removeAllInstance,
10549
+ yr as someAsync,
10550
+ Si as stringifyAllInstances,
10515
10551
  w as stringifyAttribute,
10516
- li as systemConsoleLogger
10552
+ ui as systemConsoleLogger
10517
10553
  };
10518
10554
  //# sourceMappingURL=index.js.map