interaqt 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -40,13 +40,13 @@ function wi(...u) {
40
40
  }
41
41
  function Ni() {
42
42
  }
43
- const _t = /* @__PURE__ */ new Map();
43
+ const qt = /* @__PURE__ */ new Map();
44
44
  function Oe(u, t) {
45
- t && t.isKlass && t.displayName && _t.set(u, t);
45
+ t && t.isKlass && t.displayName && qt.set(u, t);
46
46
  }
47
47
  function Ti() {
48
48
  const u = [];
49
- return Array.from(_t.entries()).forEach(([, t]) => {
49
+ return Array.from(qt.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
  }
@@ -57,7 +57,7 @@ function Si(u) {
57
57
  function Fe(u) {
58
58
  const t = /* @__PURE__ */ new Map();
59
59
  return u.forEach(({ type: e, options: r = {}, uuid: i, public: s }) => {
60
- const a = _t.get(e);
60
+ const a = qt.get(e);
61
61
  if (!a) {
62
62
  console.warn(`Class ${e} not found in KlassByName`);
63
63
  return;
@@ -196,7 +196,7 @@ class C {
196
196
  return this.create(e.public, e.options);
197
197
  }
198
198
  }
199
- var qt = /* @__PURE__ */ ((u) => (u.String = "string", u.Number = "number", u.Boolean = "boolean", u.Timestamp = "timestamp", u))(qt || {});
199
+ var _t = /* @__PURE__ */ ((u) => (u.String = "string", u.Number = "number", u.Boolean = "boolean", u.Timestamp = "timestamp", u))(_t || {});
200
200
  const Ve = /^[a-zA-Z0-9_]+$/;
201
201
  class Bt {
202
202
  constructor(t, e) {
@@ -226,7 +226,7 @@ class Bt {
226
226
  type: "string",
227
227
  required: !0,
228
228
  collection: !1,
229
- options: Array.from(Object.values(qt))
229
+ options: Array.from(Object.values(_t))
230
230
  },
231
231
  collection: {
232
232
  type: "boolean",
@@ -318,7 +318,7 @@ class T {
318
318
  type: {
319
319
  type: "string",
320
320
  required: !0,
321
- options: () => Object.values(qt)
321
+ options: () => Object.values(_t)
322
322
  },
323
323
  collection: {
324
324
  type: "boolean",
@@ -1063,6 +1063,12 @@ class R {
1063
1063
  static fromValue(t) {
1064
1064
  return new R(t);
1065
1065
  }
1066
+ toJSON() {
1067
+ return this.raw;
1068
+ }
1069
+ static fromJSON(t) {
1070
+ return new R(t);
1071
+ }
1066
1072
  isExpression() {
1067
1073
  return this.raw.type === "expression";
1068
1074
  }
@@ -1161,19 +1167,19 @@ class R {
1161
1167
  throw new Error(`invalid bool expression type: ${JSON.stringify(this.raw)}`);
1162
1168
  }
1163
1169
  }
1164
- const _e = {
1170
+ const qe = {
1165
1171
  "&&": "and",
1166
1172
  "||": "or",
1167
1173
  "!": "not"
1168
1174
  };
1169
- function qe(u) {
1175
+ function _e(u) {
1170
1176
  return { key: u };
1171
1177
  }
1172
1178
  function Nt(u, t, e) {
1173
1179
  if (u.type === "LogicalExpression")
1174
1180
  return {
1175
1181
  type: "expression",
1176
- operator: _e[u.operator],
1182
+ operator: qe[u.operator],
1177
1183
  left: Nt(u.left, t, e),
1178
1184
  right: Nt(u.right, t, e)
1179
1185
  };
@@ -1190,7 +1196,7 @@ function Nt(u, t, e) {
1190
1196
  };
1191
1197
  throw new Error("unknown ast node type");
1192
1198
  }
1193
- function Ii(u, t = [], e = qe) {
1199
+ function Ii(u, t = [], e = _e) {
1194
1200
  const r = De(t, "name"), i = xe(u, { ecmaVersion: 2020 });
1195
1201
  return new R(
1196
1202
  Nt(i.body[0].expression, r, e)
@@ -3416,7 +3422,7 @@ class m {
3416
3422
  const a = this.map.getRecordInfo(t);
3417
3423
  this.entityName = a.isFilteredEntity || a.isFilteredRelation ? a.baseRecordName : t;
3418
3424
  const o = a.isFilteredEntity || a.isFilteredRelation;
3419
- this.xToOneQueryTree = new _(this.entityName, this.map);
3425
+ this.xToOneQueryTree = new q(this.entityName, this.map);
3420
3426
  let n = r;
3421
3427
  o && (n = r ? a.matchExpression.and(r) : a.matchExpression), n && (this.data = this.convertFilteredRelation(n), this.buildQueryTree(this.data, this.xToOneQueryTree));
3422
3428
  }
@@ -3603,6 +3609,34 @@ class m {
3603
3609
  }, a = this.data ? s(this.data) : void 0;
3604
3610
  return new m(r, this.map, a, this.contextRootEntity, this.fromRelation);
3605
3611
  }
3612
+ /**
3613
+ * 将 MatchExp 实例序列化为 JSON 格式
3614
+ * @returns JSON 可序列化的对象
3615
+ */
3616
+ toJSON() {
3617
+ return {
3618
+ entityName: this.entityName,
3619
+ data: this.data ? this.data.raw : void 0,
3620
+ contextRootEntity: this.contextRootEntity,
3621
+ fromRelation: this.fromRelation
3622
+ };
3623
+ }
3624
+ /**
3625
+ * 从 JSON 对象创建 MatchExp 实例
3626
+ * @param json JSON 对象
3627
+ * @param map EntityToTableMap 实例
3628
+ * @returns MatchExp 实例
3629
+ */
3630
+ static fromJSON(t, e) {
3631
+ const r = t.data ? R.fromValue(t.data) : void 0;
3632
+ return new m(
3633
+ t.entityName,
3634
+ e,
3635
+ r,
3636
+ t.contextRootEntity,
3637
+ t.fromRelation
3638
+ );
3639
+ }
3606
3640
  }
3607
3641
  class Je {
3608
3642
  constructor(t, e, r, i) {
@@ -3679,7 +3713,7 @@ class M {
3679
3713
  );
3680
3714
  }
3681
3715
  }
3682
- class _ {
3716
+ class q {
3683
3717
  // 父节点和自己这个几点 link 上的 query
3684
3718
  constructor(t, e, r, i, s, a, o) {
3685
3719
  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));
@@ -3689,26 +3723,26 @@ class _ {
3689
3723
  if (t.length === 1)
3690
3724
  this.fields.push(e);
3691
3725
  else if (e === f)
3692
- this.parentLinkQueryTree || (this.parentLinkQueryTree = new _(this.info.linkName, this.map)), this.parentLinkQueryTree.addField(r);
3726
+ this.parentLinkQueryTree || (this.parentLinkQueryTree = new q(this.info.linkName, this.map)), this.parentLinkQueryTree.addField(r);
3693
3727
  else {
3694
3728
  const i = this.map.getInfo(this.recordName, e);
3695
- this.records[e] || (this.records[e] = new _(i.recordName, this.map, this.recordName, e, void 0, this)), this.records[e].addField(r);
3729
+ this.records[e] || (this.records[e] = new q(i.recordName, this.map, this.recordName, e, void 0, this)), this.records[e].addField(r);
3696
3730
  }
3697
3731
  }
3698
3732
  addRecord(t, e) {
3699
3733
  const [r, ...i] = t;
3700
3734
  if (t.length === 1)
3701
3735
  if (r === f)
3702
- this.parentLinkQueryTree || (this.parentLinkQueryTree = new _(this.info.linkName, this.map)), e && (this.parentLinkQueryTree = this.parentLinkQueryTree.merge(e));
3736
+ this.parentLinkQueryTree || (this.parentLinkQueryTree = new q(this.info.linkName, this.map)), e && (this.parentLinkQueryTree = this.parentLinkQueryTree.merge(e));
3703
3737
  else {
3704
- const s = this.map.getInfo(this.recordName, r), a = e || new _(s.recordName, this.map, this.recordName, r, void 0, this);
3738
+ const s = this.map.getInfo(this.recordName, r), a = e || new q(s.recordName, this.map, this.recordName, r, void 0, this);
3705
3739
  this.records[r] = this.records[r] ? this.records[r].merge(a) : a;
3706
3740
  }
3707
3741
  else if (r === f)
3708
- this.parentLinkQueryTree || (this.parentLinkQueryTree = new _(this.info.linkName, this.map)), this.parentLinkQueryTree.addRecord(i, e);
3742
+ this.parentLinkQueryTree || (this.parentLinkQueryTree = new q(this.info.linkName, this.map)), this.parentLinkQueryTree.addRecord(i, e);
3709
3743
  else {
3710
3744
  const s = this.map.getInfo(this.recordName, r);
3711
- this.records[r] = new _(s.recordName, this.map, this.recordName, r, void 0, this), this.records[r].addRecord(i, e);
3745
+ this.records[r] = new q(s.recordName, this.map, this.recordName, r, void 0, this), this.records[r].addRecord(i, e);
3712
3746
  }
3713
3747
  }
3714
3748
  forEachRecords(t) {
@@ -3723,7 +3757,7 @@ class _ {
3723
3757
  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];
3724
3758
  });
3725
3759
  let s;
3726
- 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);
3760
+ 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);
3727
3761
  }
3728
3762
  getData() {
3729
3763
  const t = {
@@ -3856,7 +3890,7 @@ class x {
3856
3890
  return this.buildXToOneQueryTree();
3857
3891
  }
3858
3892
  buildXToOneQueryTree() {
3859
- const t = new _(this.recordName, this.map, this.parentRecord, this.attributeName);
3893
+ const t = new q(this.recordName, this.map, this.parentRecord, this.attributeName);
3860
3894
  if (this.data.forEach((e) => {
3861
3895
  Array.isArray(e) || t.addField([e]);
3862
3896
  }), this.xToOneRecords.forEach((e) => {
@@ -3868,7 +3902,7 @@ class x {
3868
3902
  return t;
3869
3903
  }
3870
3904
  buildFullQueryTree() {
3871
- const t = new _(this.recordName, this.map, this.parentRecord, this.attributeName);
3905
+ const t = new q(this.recordName, this.map, this.parentRecord, this.attributeName);
3872
3906
  return this.relatedRecords.forEach((e) => {
3873
3907
  t.addRecord([e.attributeName], e.attributeQuery.fullQueryTree);
3874
3908
  }), t;
@@ -7737,12 +7771,12 @@ class $t {
7737
7771
  return A.skip();
7738
7772
  }
7739
7773
  }
7740
- class _r extends $t {
7774
+ class qr extends $t {
7741
7775
  static {
7742
7776
  this.contextType = "global";
7743
7777
  }
7744
7778
  }
7745
- class qr extends $t {
7779
+ class _r extends $t {
7746
7780
  static {
7747
7781
  this.contextType = "entity";
7748
7782
  }
@@ -7768,8 +7802,8 @@ If you want to use aggregated data from all records in the entity/relation, you
7768
7802
  }
7769
7803
  }
7770
7804
  const Jr = [
7771
- _r,
7772
7805
  qr,
7806
+ _r,
7773
7807
  Br,
7774
7808
  Wr
7775
7809
  ];
@@ -8056,7 +8090,7 @@ class O extends H {
8056
8090
  });
8057
8091
  }
8058
8092
  }
8059
- const tt = "_System_", q = "_Dictionary_", et = "id", ot = "_rowId", jr = C.create({
8093
+ const tt = "_System_", _ = "_Dictionary_", et = "id", ot = "_rowId", jr = C.create({
8060
8094
  name: tt,
8061
8095
  properties: [
8062
8096
  T.create({
@@ -8076,7 +8110,7 @@ const tt = "_System_", q = "_Dictionary_", et = "id", ot = "_rowId", jr = C.crea
8076
8110
  })
8077
8111
  ]
8078
8112
  }), Hr = C.create({
8079
- name: q,
8113
+ name: _,
8080
8114
  properties: [
8081
8115
  T.create({
8082
8116
  name: "key",
@@ -8151,7 +8185,7 @@ class Ur {
8151
8185
  * @returns 是否需要触发计算
8152
8186
  */
8153
8187
  shouldTriggerUpdateComputation(t, e) {
8154
- 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(
8188
+ 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(
8155
8189
  (i) => !e.record.hasOwnProperty(i) || e.record[i] === e.oldRecord[i]
8156
8190
  );
8157
8191
  }
@@ -8178,15 +8212,15 @@ class Ur {
8178
8212
  } else e.type === "global" && ((!i || i === "update") && a.push({
8179
8213
  dataDep: e,
8180
8214
  type: "update",
8181
- recordName: q,
8182
- sourceRecordName: q,
8215
+ recordName: _,
8216
+ sourceRecordName: _,
8183
8217
  attributes: ["value"],
8184
8218
  computation: r
8185
8219
  }), (!i || i === "create") && a.push({
8186
8220
  dataDep: e,
8187
8221
  type: "create",
8188
- recordName: q,
8189
- sourceRecordName: q,
8222
+ recordName: _,
8223
+ sourceRecordName: _,
8190
8224
  computation: r
8191
8225
  }));
8192
8226
  return a;
@@ -8515,7 +8549,7 @@ class Gr {
8515
8549
  }
8516
8550
  async computeDataBasedDirtyRecordsAndEvents(t, e) {
8517
8551
  let r = [];
8518
- if (t.dataDep.type === "global" && e.recordName === q)
8552
+ if (t.dataDep.type === "global" && e.recordName === _)
8519
8553
  if (t.computation.dataContext.type === "property") {
8520
8554
  const i = t.computation.dataContext;
8521
8555
  r = (await this.controller.system.storage.find(i.host.name, m.atom({ key: "id", value: ["not", null] }), {}, ["*"])).map((a) => [a, {
@@ -9011,10 +9045,15 @@ class Ae {
9011
9045
  async retrieveData(t) {
9012
9046
  let e;
9013
9047
  if (C.is(this.interaction.data) || P.is(this.interaction.data)) {
9014
- const r = this.interaction.data.name, { modifier: i, attributeQuery: s } = Object.fromEntries(
9015
- this.interaction.query?.items?.map((n) => [n.name, n.value]) || []
9016
- ), a = { ...t.query?.modifier || {}, ...i || {} }, o = t.query?.attributeQuery || [];
9017
- e = await this.system.storage.find(r, t.query?.match, a, o);
9048
+ const r = this.interaction.data.name, i = Object.fromEntries(
9049
+ this.interaction.query?.items?.map((d) => [d.name, d.value]) || []
9050
+ ), s = i.modifier;
9051
+ i.attributeQuery;
9052
+ let a = i.match, o;
9053
+ a && typeof a == "object" && "raw" in a ? o = a : a && (o = R.fromValue(a));
9054
+ const n = { ...t.query?.modifier || {}, ...s || {} }, c = t.query?.attributeQuery || [];
9055
+ let l = t.query?.match;
9056
+ o && l ? l = o.and(l) : o && (l = o), e = await this.system.storage.find(r, l, n, c);
9018
9057
  } else
9019
9058
  v(!1, `unknown data type ${this.interaction.data}`);
9020
9059
  return e;
@@ -9809,11 +9848,11 @@ class oi {
9809
9848
  this.db = t, this.callbacks = /* @__PURE__ */ new Set(), this.dict = {
9810
9849
  get: async (e) => {
9811
9850
  const r = m.atom({ key: "key", value: ["=", e] });
9812
- return (await this.queryHandle.findOne(q, r, void 0, ["value"]))?.value?.raw;
9851
+ return (await this.queryHandle.findOne(_, r, void 0, ["value"]))?.value?.raw;
9813
9852
  },
9814
9853
  set: async (e, r) => {
9815
- const i = m.atom({ key: "key", value: ["=", e] }), s = await this.queryHandle.findOne(q, i, void 0, ["value"]);
9816
- 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 } }], []);
9854
+ const i = m.atom({ key: "key", value: ["=", e] }), s = await this.queryHandle.findOne(_, i, void 0, ["value"]);
9855
+ 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 } }], []);
9817
9856
  }
9818
9857
  };
9819
9858
  }
@@ -9935,7 +9974,7 @@ class re {
9935
9974
  }
9936
9975
  }
9937
9976
  const Rt = new ee(), li = new re();
9938
- class qi {
9977
+ class _i {
9939
9978
  constructor(t = new ii(void 0, { logger: Rt }), e = li) {
9940
9979
  this.logger = e, this.conceptClass = /* @__PURE__ */ new Map(), this.storage = new oi(t);
9941
9980
  }
@@ -10332,13 +10371,13 @@ export {
10332
10371
  ni as DBLogLevel,
10333
10372
  dr as DBSetup,
10334
10373
  Fi as DELETED_STATE,
10335
- q as DICTIONARY_RECORD,
10374
+ _ as DICTIONARY_RECORD,
10336
10375
  Ht as DataAttributive,
10337
10376
  zt as DataAttributives,
10338
10377
  Bt as Dictionary,
10339
10378
  Hr as DictionaryEntity,
10340
10379
  C as Entity,
10341
- qr as EntityCustomHandle,
10380
+ _r as EntityCustomHandle,
10342
10381
  Ye as EntityQueryHandle,
10343
10382
  ze as EntityToTableMap,
10344
10383
  te as Equation,
@@ -10352,7 +10391,7 @@ export {
10352
10391
  Qr as GlobalAverageHandle,
10353
10392
  B as GlobalBoundState,
10354
10393
  Ar as GlobalCountHandle,
10355
- _r as GlobalCustomHandle,
10394
+ qr as GlobalCustomHandle,
10356
10395
  wr as GlobalEveryHandle,
10357
10396
  Mr as GlobalRealTimeComputation,
10358
10397
  fr as GlobalStateMachineHandle,
@@ -10366,12 +10405,12 @@ export {
10366
10405
  Wt as Interaction,
10367
10406
  Ae as InteractionCall,
10368
10407
  Ee as InteractionEventEntity,
10369
- _t as KlassByName,
10408
+ qt as KlassByName,
10370
10409
  f as LINK_SYMBOL,
10371
10410
  vt as LinkInfo,
10372
10411
  m as MatchExp,
10373
10412
  Je as Modifier,
10374
- qi as MonoSystem,
10413
+ _i as MonoSystem,
10375
10414
  Hi as MysqlDB,
10376
10415
  Oi as NON_DELETED_STATE,
10377
10416
  Di as NON_EXIST_STATE,
@@ -10389,7 +10428,7 @@ export {
10389
10428
  $r as PropertyRealTimeComputation,
10390
10429
  mr as PropertyStateMachineHandle,
10391
10430
  Or as PropertySumHandle,
10392
- qt as PropertyTypes,
10431
+ _t as PropertyTypes,
10393
10432
  br as PropertyWeightedSummationHandle,
10394
10433
  Re as Query,
10395
10434
  be as QueryItem,
@@ -10402,7 +10441,7 @@ export {
10402
10441
  K as RecordMutationSideEffect,
10403
10442
  M as RecordQuery,
10404
10443
  Xe as RecordQueryAgent,
10405
- _ as RecordQueryTree,
10444
+ q as RecordQueryTree,
10406
10445
  Cr as RecordsTransformHandle,
10407
10446
  St as RecursiveContext,
10408
10447
  we as RefContainer,