interaqt 0.8.10 → 0.8.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
@@ -1154,7 +1154,10 @@ class R {
1154
1154
  const r = e.concat(this.raw);
1155
1155
  if (this.isAtom()) {
1156
1156
  const s = this.raw.data, a = await t(s);
1157
- return a && !i || !a && i ? !0 : { data: s, inverse: i, stack: e, error: "atom evaluate error" };
1157
+ if (typeof a == "string")
1158
+ return { data: s, inverse: i, stack: e, error: a };
1159
+ const o = a;
1160
+ return o && !i || !o && i ? !0 : { data: s, inverse: i, stack: e, error: "atom evaluate error" };
1158
1161
  }
1159
1162
  if (this.isOr())
1160
1163
  return await this.left.evaluateAsync(t, r) === !0 ? !0 : this.right.evaluateAsync(t, r);
@@ -3380,8 +3383,8 @@ class m {
3380
3383
  const n = [...a.resolvedPath, o], c = this.map.getInfoByPath(n), l = a.resolvedPath.concat(c?.isLinkFiltered() ? c.getBaseAttributeInfo().attributeName : o);
3381
3384
  let d = a.matchExpression;
3382
3385
  if (c?.isLinkFiltered()) {
3383
- const h = c.getLinkInfo(), p = new m(h.getResolvedBaseRecordName(), this.map, h.getResolvedMatchExpression()), y = this.map.getReversePath(l), g = [c.isRecordSource() ? "source" : "target", ...y.slice(2)], A = p.rebase(g.join("."));
3384
- d = d ? d.and(A) : A;
3386
+ const h = c.getLinkInfo(), p = new m(h.getResolvedBaseRecordName(), this.map, h.getResolvedMatchExpression()), y = this.map.getReversePath(l), g = [c.isRecordSource() ? "source" : "target", ...y.slice(2)], k = p.rebase(g.join("."));
3387
+ d = d ? d.and(k) : k;
3385
3388
  }
3386
3389
  return {
3387
3390
  path: [...a.path, o],
@@ -3570,6 +3573,21 @@ class $e {
3570
3573
  order: e
3571
3574
  }));
3572
3575
  }
3576
+ /**
3577
+ * 构建 xToOne 查询树
3578
+ * 用于确保 ORDER BY 中引用的关联字段会触发相应的 JOIN
3579
+ */
3580
+ get xToOneQueryTree() {
3581
+ const t = new L(this.recordName, this.map);
3582
+ return Object.keys(this.data?.orderBy || {}).forEach((e) => {
3583
+ const i = e.split(".");
3584
+ if (i.length === 1) {
3585
+ t.addField([e]);
3586
+ return;
3587
+ }
3588
+ i.slice(0, -1), t.addField(i);
3589
+ }), t;
3590
+ }
3573
3591
  }
3574
3592
  class C {
3575
3593
  constructor(t, e, i, r, s, a, o, n, c, l = !1, d, h, p, y) {
@@ -3702,7 +3720,7 @@ class x {
3702
3720
  let y = l, v = d;
3703
3721
  if (p.isLinkFiltered()) {
3704
3722
  y = p.getBaseAttributeInfo().attributeName;
3705
- const A = d.matchExpression, D = p.getLinkInfo().getBaseLinkInfo(), z = new m(D.name, this.map, p.getMatchExpression()).rebase(p.isRecordSource() ? "target" : "source"), ke = A ? z.and(A.data) : z;
3723
+ const k = d.matchExpression, D = p.getLinkInfo().getBaseLinkInfo(), z = new m(D.name, this.map, p.getMatchExpression()).rebase(p.isRecordSource() ? "target" : "source"), ke = k ? z.and(k.data) : z;
3706
3724
  v = {
3707
3725
  ...d,
3708
3726
  matchExpression: ke.data
@@ -4379,28 +4397,28 @@ class Le {
4379
4397
  * @returns [SQL字符串, 参数数组, 字段别名映射]
4380
4398
  */
4381
4399
  buildXToOneFindQuery(t, e = "", i) {
4382
- const r = t.attributeQuery.xToOneQueryTree, s = t.matchExpression.xToOneQueryTree, a = r.merge(s), o = this.getJoinTables(a, [t.recordName]), n = i || this.getPlaceholder(), c = t.matchExpression.buildFieldMatchExpression(n, this.database), [l, d] = this.buildWhereClause(
4383
- this.parseMatchExpressionValue(t.recordName, c, t.contextRootEntity, n),
4400
+ const r = t.attributeQuery.xToOneQueryTree, s = t.matchExpression.xToOneQueryTree, a = t.modifier.xToOneQueryTree, o = r.merge(s).merge(a), n = this.getJoinTables(o, [t.recordName]), c = i || this.getPlaceholder(), l = t.matchExpression.buildFieldMatchExpression(c, this.database), [d, h] = this.buildWhereClause(
4401
+ this.parseMatchExpressionValue(t.recordName, l, t.contextRootEntity, c),
4384
4402
  e,
4385
- n
4386
- ), [h, p] = this.buildSelectClause(
4403
+ c
4404
+ ), [p, y] = this.buildSelectClause(
4387
4405
  t.attributeQuery.getValueAndXToOneRecordFields(),
4388
4406
  e
4389
- ), y = this.buildFromClause(t.recordName, e), v = this.buildJoinClause(o, e), g = this.buildModifierClause(t.modifier, e, p);
4407
+ ), v = this.buildFromClause(t.recordName, e), g = this.buildJoinClause(n, e), k = this.buildModifierClause(t.modifier, e, y);
4390
4408
  return [
4391
4409
  `
4392
4410
  SELECT
4393
- ${h}
4411
+ ${p}
4394
4412
  FROM
4395
- ${y}
4396
4413
  ${v}
4414
+ ${g}
4397
4415
  WHERE
4398
- ${l}
4416
+ ${d}
4399
4417
 
4400
- ${g}
4418
+ ${k}
4401
4419
  `,
4402
- d,
4403
- p
4420
+ h,
4421
+ y
4404
4422
  ];
4405
4423
  }
4406
4424
  /**
@@ -4461,11 +4479,14 @@ ${g}
4461
4479
  buildModifierClause(t, e = "", i) {
4462
4480
  const { limit: r, offset: s, orderBy: a } = t, o = [];
4463
4481
  return a.length && o.push(`ORDER BY ${a.map(({ attribute: n, recordName: c, order: l }) => {
4464
- const d = [
4465
- `${this.withPrefix(e)}${c}`,
4466
- n
4467
- ];
4468
- return `"${i.getAlias(d) || d.join(".")}" ${l}`;
4482
+ const d = n.split(".");
4483
+ let h, p;
4484
+ d.length === 1 ? (h = [c], p = n) : (h = [c, ...d.slice(0, -1)], p = d[d.length - 1]);
4485
+ const [y, v] = this.map.getTableAliasAndFieldName(
4486
+ h,
4487
+ p
4488
+ );
4489
+ return `"${`${this.withPrefix(e)}${y}`}"."${v}" ${l}`;
4469
4490
  }).join(",")}`), r && o.push(`LIMIT ${r}`), s && o.push(`OFFSET ${s}`), o.join(`
4470
4491
  `);
4471
4492
  }
@@ -4511,22 +4532,22 @@ ${g}
4511
4532
  joinTarget: [d, h]
4512
4533
  });
4513
4534
  } else {
4514
- const g = c.getLinkInfo(), A = c.isLinkManyToManySymmetric() ? c.symmetricDirection === "source" : g.isRelationSource(c.parentEntityName, c.attributeName);
4535
+ const g = c.getLinkInfo(), k = c.isLinkManyToManySymmetric() ? c.symmetricDirection === "source" : g.isRelationSource(c.parentEntityName, c.attributeName);
4515
4536
  r.push({
4516
4537
  for: l,
4517
4538
  joinSource: a,
4518
- joinIdField: [s, A ? g.record.attributes.source.field : g.record.attributes.target.field],
4539
+ joinIdField: [s, k ? g.record.attributes.source.field : g.record.attributes.target.field],
4519
4540
  joinTarget: [p, y]
4520
4541
  }), o.onlyIdField() || r.push({
4521
4542
  for: l,
4522
4543
  joinSource: [p, y],
4523
- joinIdField: [A ? g.record.attributes.target.field : g.record.attributes.source.field, v],
4544
+ joinIdField: [k ? g.record.attributes.target.field : g.record.attributes.source.field, v],
4524
4545
  joinTarget: [d, h]
4525
4546
  });
4526
4547
  }
4527
4548
  if (r.push(...this.getJoinTables(o, l, [v, d, h])), o.parentLinkQueryTree && !o.parentLinkQueryTree.onlyIdField()) {
4528
- const g = l.concat(f), [, A] = this.map.getTableAliasAndFieldName(g, "id", !0), D = [
4529
- A,
4549
+ const g = l.concat(f), [, k] = this.map.getTableAliasAndFieldName(g, "id", !0), D = [
4550
+ k,
4530
4551
  // link 的 idField
4531
4552
  p,
4532
4553
  // link 的 tableName
@@ -4732,8 +4753,8 @@ class Be {
4732
4753
  value: ["=", y.id]
4733
4754
  }), g = d.derive({
4734
4755
  matchExpression: v
4735
- }), A = t.label ? l.concat(y) : l;
4736
- y[d.alias || d.attributeName] = await this.findRecords(g, e, i, A);
4756
+ }), k = t.label ? l.concat(y) : l;
4757
+ y[d.alias || d.attributeName] = await this.findRecords(g, e, i, k);
4737
4758
  }
4738
4759
  }
4739
4760
  for (let d of t.attributeQuery.xToOneRecords) {
@@ -4742,10 +4763,10 @@ class Be {
4742
4763
  for (let p of h.attributeQuery.xToManyRecords) {
4743
4764
  const v = this.map.getInfo(p.parentRecord, p.attributeName).getReverseInfo()?.attributeName;
4744
4765
  for (let g of c) {
4745
- const A = g[d.attributeName][f].id, D = p.derive({
4766
+ const k = g[d.attributeName][f].id, D = p.derive({
4746
4767
  matchExpression: p.matchExpression.and({
4747
4768
  key: `${v}.id`,
4748
- value: ["=", A]
4769
+ value: ["=", k]
4749
4770
  })
4750
4771
  }), J = t.label ? l.concat(g) : l;
4751
4772
  Et(
@@ -4831,21 +4852,21 @@ class Be {
4831
4852
  matchExpression: c,
4832
4853
  attributeQuery: l
4833
4854
  }), h = await this.findRecords(d, `finding related record: ${r.parentRecord}.${r.attributeName}`, s, a), p = r.attributeQuery.parentLinkRecordQuery ? h.map((g) => {
4834
- let A;
4835
- return o.isLinkManyToManySymmetric() ? (A = {
4855
+ let k;
4856
+ return o.isLinkManyToManySymmetric() ? (k = {
4836
4857
  ...g,
4837
4858
  [f]: g[`${n}:source`]?.[f]?.id ? g[`${n}:source`]?.[f] : g[`${n}:target`]?.[f]
4838
- }, delete A[`${n}:source`], delete A[`${n}:target`]) : (A = {
4859
+ }, delete k[`${n}:source`], delete k[`${n}:target`]) : (k = {
4839
4860
  ...g,
4840
4861
  [f]: g[n][f]
4841
- }, delete A[n]), A;
4862
+ }, delete k[n]), k;
4842
4863
  }) : h, y = d.label && d.label !== a.label ? a.spawn(d.label) : a, v = r.attributeQuery.parentLinkRecordQuery;
4843
4864
  if (v)
4844
4865
  for (let g of v.attributeQuery.xToManyRecords)
4845
- for (let A of p) {
4846
- const D = A[f].id, J = d.label ? y.concat(A) : y;
4866
+ for (let k of p) {
4867
+ const D = k[f].id, J = d.label ? y.concat(k) : y;
4847
4868
  Et(
4848
- A,
4869
+ k,
4849
4870
  [f, g.attributeName],
4850
4871
  await this.findXToManyRelatedRecords(
4851
4872
  g.parentRecord,
@@ -5654,13 +5675,13 @@ class je {
5654
5675
  for (let h = 0; h < i.length; h++) {
5655
5676
  const [p, y] = this.getAttributeAndSymmetricDirection(i[h]), v = [e, ...i.slice(0, h + 1)];
5656
5677
  if (p === f) {
5657
- const { linkTable: g, linkAlias: A, path: D } = d.pop();
5658
- b(!c, `last attribute in path is a link, cannot read link of a link ${D.join(".")}`), s = g, a = A, r = this.data.records[l.linkName], c = !0, o = "", n = "", l = void 0;
5678
+ const { linkTable: g, linkAlias: k, path: D } = d.pop();
5679
+ b(!c, `last attribute in path is a link, cannot read link of a link ${D.join(".")}`), s = g, a = k, r = this.data.records[l.linkName], c = !0, o = "", n = "", l = void 0;
5659
5680
  } else {
5660
5681
  l = this.getInfoByPath(v);
5661
5682
  const g = r.attributes[p];
5662
5683
  b(l.isRecord, `${i.slice(0, h + 1).join(".")} is not a entity attribute`);
5663
- const A = this.data.records[g.recordName], D = `${a}_${p}${y ? `_${y.toUpperCase()}` : ""}`, J = this.aliasManager?.getTableAlias(D) || D;
5684
+ const k = this.data.records[g.recordName], D = `${a}_${p}${y ? `_${y.toUpperCase()}` : ""}`, J = this.aliasManager?.getTableAlias(D) || D;
5664
5685
  if (l.isMergedWithParent() || l.isLinkMergedWithParent())
5665
5686
  n = a;
5666
5687
  else if (l.isLinkIsolated()) {
@@ -5668,7 +5689,7 @@ class je {
5668
5689
  n = this.aliasManager?.getTableAlias(z) || z;
5669
5690
  } else
5670
5691
  n = J;
5671
- l.isMergedWithParent() || (a = J), s = l.table, r = A, o = l.getLinkInfo()?.table, c = !1;
5692
+ l.isMergedWithParent() || (a = J), s = l.table, r = k, o = l.getLinkInfo()?.table, c = !1;
5672
5693
  }
5673
5694
  d.push({
5674
5695
  table: s,
@@ -6538,9 +6559,9 @@ class oi {
6538
6559
  p[0] === "1" && p[1] === "1" && y !== v,
6539
6560
  `only 1:1 can merge: ${s}.${a.slice(0, n + 1).join(".")}`
6540
6561
  );
6541
- const g = y === o ? v : y, A = this.combineRecordTable(o, g, d);
6542
- if (A)
6543
- throw new Error(`conflict found when join ${d}, ${A.join(",")} already merged with ${o}`);
6562
+ const g = y === o ? v : y, k = this.combineRecordTable(o, g, d);
6563
+ if (k)
6564
+ throw new Error(`conflict found when join ${d}, ${k.join(",")} already merged with ${o}`);
6544
6565
  h.mergedTo = "combined", i.push(h), o = l.recordName, delete t[d], delete e[d];
6545
6566
  }
6546
6567
  }), Object.values(t).forEach((r) => {
@@ -7022,7 +7043,7 @@ class Re {
7022
7043
  return this.data.transfers.filter((e) => $t(t, e.trigger));
7023
7044
  }
7024
7045
  }
7025
- function k(u, t) {
7046
+ function A(u, t) {
7026
7047
  if (!u)
7027
7048
  throw new Error(t);
7028
7049
  }
@@ -7103,7 +7124,7 @@ class pi {
7103
7124
  }
7104
7125
  async getInitialValue(t) {
7105
7126
  const e = t[this.dataContext.id.name];
7106
- return k(
7127
+ return A(
7107
7128
  !(e !== void 0 && !this.initialState.computeValue),
7108
7129
  `${this.dataContext.host.name}.${this.dataContext.id.name} have been set when ${this.dataContext.host.name} created,
7109
7130
  if you want to save the use the initial value, you need to define computeValue in initialState to save it.
@@ -7191,7 +7212,7 @@ class mi {
7191
7212
  }
7192
7213
  class yi {
7193
7214
  constructor(t, e, i) {
7194
- this.controller = t, this.args = e, this.dataContext = i, this.useLastValue = !0, this.dataDeps = {}, this.matchRecordToWeight = this.args.callback.bind(this.controller), this.relation = this.controller.relations.find((a) => a.source === i.host && a.sourceProperty === this.args.property || a.target === i.host && a.targetProperty === this.args.property), k(this.relation, "weighted summation computation must specify property"), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === i.host.name, k(this.isSource ? this.relation.source === i.host : this.relation.target === i.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;
7215
+ this.controller = t, this.args = e, this.dataContext = i, this.useLastValue = !0, this.dataDeps = {}, this.matchRecordToWeight = this.args.callback.bind(this.controller), this.relation = this.controller.relations.find((a) => a.source === i.host && a.sourceProperty === this.args.property || a.target === i.host && a.targetProperty === this.args.property), A(this.relation, "weighted summation computation must specify property"), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === i.host.name, A(this.isSource ? this.relation.source === i.host : this.relation.target === i.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;
7195
7216
  const r = this.args.attributeQuery || [];
7196
7217
  this.relatedAttributeQuery = this.args.attributeQuery?.filter((a) => a[0] !== f) || [];
7197
7218
  const s = (r.find((a) => a[0] === f) || [])[1]?.attributeQuery;
@@ -7321,7 +7342,7 @@ class bi {
7321
7342
  }
7322
7343
  class Ri {
7323
7344
  constructor(t, e, i) {
7324
- this.controller = t, this.args = e, this.dataContext = i, this.useLastValue = !0, this.dataDeps = {}, this.callback = this.args.callback.bind(this.controller), this.relation = this.controller.relations.find((a) => a.source === i.host && a.sourceProperty === this.args.property || a.target === i.host && a.targetProperty === this.args.property), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === i.host.name, k(this.isSource ? this.relation.source === i.host : this.relation.target === i.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;
7345
+ this.controller = t, this.args = e, this.dataContext = i, this.useLastValue = !0, this.dataDeps = {}, this.callback = this.args.callback.bind(this.controller), this.relation = this.controller.relations.find((a) => a.source === i.host && a.sourceProperty === this.args.property || a.target === i.host && a.targetProperty === this.args.property), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === i.host.name, A(this.isSource ? this.relation.source === i.host : this.relation.target === i.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;
7325
7346
  const r = this.args.attributeQuery || [];
7326
7347
  this.relatedAttributeQuery = this.args.attributeQuery?.filter((a) => a[0] !== f) || [];
7327
7348
  const s = (r.find((a) => a[0] === f) || [])[1]?.attributeQuery;
@@ -7449,12 +7470,12 @@ class Ni {
7449
7470
  }
7450
7471
  class vi {
7451
7472
  constructor(t, e, i) {
7452
- this.controller = t, this.args = e, this.dataContext = i, this.useLastValue = !0, this.dataDeps = {}, this.callback = this.args.callback.bind(this.controller), this.relation = this.controller.relations.find((n) => n.source === i.host && n.sourceProperty === this.args.property || n.target === i.host && n.targetProperty === this.args.property), k(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 === i.host.name, k(this.isSource ? this.relation.source === i.host : this.relation.target === i.host, "any computation relation direction error");
7473
+ this.controller = t, this.args = e, this.dataContext = i, this.useLastValue = !0, this.dataDeps = {}, this.callback = this.args.callback.bind(this.controller), this.relation = this.controller.relations.find((n) => n.source === i.host && n.sourceProperty === this.args.property || n.target === i.host && n.targetProperty === this.args.property), A(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 === i.host.name, A(this.isSource ? this.relation.source === i.host : this.relation.target === i.host, "any computation relation direction error");
7453
7474
  let r = this.relation.baseRelation || this.relation;
7454
7475
  for (; r.baseRelation; )
7455
7476
  r = r.baseRelation;
7456
7477
  const s = r.type.split(":");
7457
- k(s[this.isSource ? 1 : 0] === "n", `property-level Any computation argument must be an x:n relation. ${this.dataContext.host.name}.${this.args.property}" is a ${this.isSource ? s.join(":") : s.slice().reverse().join(":")} relation`), 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;
7478
+ A(s[this.isSource ? 1 : 0] === "n", `property-level Any computation argument must be an x:n relation. ${this.dataContext.host.name}.${this.args.property}" is a ${this.isSource ? s.join(":") : s.slice().reverse().join(":")} relation`), 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;
7458
7479
  const a = this.args.attributeQuery || [];
7459
7480
  this.relatedAttributeQuery = this.args.attributeQuery?.filter((n) => n[0] !== f) || [];
7460
7481
  const o = (a.find((n) => n[0] === f) || [])[1]?.attributeQuery;
@@ -7576,7 +7597,7 @@ class ki {
7576
7597
  }
7577
7598
  class Ai {
7578
7599
  constructor(t, e, i) {
7579
- this.controller = t, this.args = e, this.dataContext = i, 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 === i.host && a.sourceProperty === this.args.property || a.target === i.host && a.targetProperty === this.args.property) : this.relation = this.args.record, this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === i.host.name, k(this.isSource ? this.relation.source === i.host : this.relation.target === i.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;
7600
+ this.controller = t, this.args = e, this.dataContext = i, 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 === i.host && a.sourceProperty === this.args.property || a.target === i.host && a.targetProperty === this.args.property) : this.relation = this.args.record, this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === i.host.name, A(this.isSource ? this.relation.source === i.host : this.relation.target === i.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;
7580
7601
  const r = this.args.attributeQuery || [];
7581
7602
  this.relatedAttributeQuery = r.filter((a) => a && a[0] !== f) || [];
7582
7603
  const s = (r.find((a) => a && a[0] === f) || [])[1]?.attributeQuery;
@@ -7659,7 +7680,7 @@ class Ai {
7659
7680
  const Si = [ki, Ai];
7660
7681
  class Ei {
7661
7682
  constructor(t, e, i) {
7662
- this.controller = t, this.args = e, this.dataContext = i, this.useLastValue = !0, this.dataDeps = {}, k(!(this.args.record && this.args.eventDeps), "Transform must have either record or eventDep"), k(!(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 : (k(this.args.dataDeps?._source === void 0, "dataDep name `_source` is reserved for Transform"), this.dataDeps = {
7683
+ this.controller = t, this.args = e, this.dataContext = i, this.useLastValue = !0, this.dataDeps = {}, A(!(this.args.record && this.args.eventDeps), "Transform must have either record or eventDep"), A(!(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 : (A(this.args.dataDeps?._source === void 0, "dataDep name `_source` is reserved for Transform"), this.dataDeps = {
7663
7684
  ...this.args.dataDeps || {},
7664
7685
  _source: {
7665
7686
  type: "records",
@@ -7684,7 +7705,7 @@ class Ei {
7684
7705
  return [];
7685
7706
  }
7686
7707
  async compute({ _source: t }) {
7687
- k(!this.eventDeps, "Transform compute should not be called with eventDeps");
7708
+ A(!this.eventDeps, "Transform compute should not be called with eventDeps");
7688
7709
  const e = [];
7689
7710
  for (const i of t) {
7690
7711
  const r = await this.transformCallback.call(this.controller, i);
@@ -7699,7 +7720,7 @@ class Ei {
7699
7720
  return e;
7700
7721
  }
7701
7722
  async computeDirtyRecords(t) {
7702
- return k(this.eventDeps, "computeDirtyRecords should be called with eventDeps"), [{}];
7723
+ return A(this.eventDeps, "computeDirtyRecords should be called with eventDeps"), [{}];
7703
7724
  }
7704
7725
  async incrementalPatchCompute(t, e) {
7705
7726
  return this.eventDeps ? this.eventBasedIncrementalPatchCompute(t, e) : this.dataBasedIncrementalPatchCompute(t, e);
@@ -8171,7 +8192,7 @@ class Pi {
8171
8192
  }
8172
8193
  class $i {
8173
8194
  constructor(t, e, i) {
8174
- this.controller = t, this.args = e, this.dataContext = i, this.useLastValue = !0, this.dataDeps = {}, this.relation = this.controller.relations.find((o) => o.source === i.host && o.sourceProperty === this.args.property || o.target === i.host && o.targetProperty === this.args.property), k(this.relation, "summation computation must specify either property or record"), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === i.host.name, k(this.isSource ? this.relation.source === i.host : this.relation.target === i.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;
8195
+ this.controller = t, this.args = e, this.dataContext = i, this.useLastValue = !0, this.dataDeps = {}, this.relation = this.controller.relations.find((o) => o.source === i.host && o.sourceProperty === this.args.property || o.target === i.host && o.targetProperty === this.args.property), A(this.relation, "summation computation must specify either property or record"), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === i.host.name, A(this.isSource ? this.relation.source === i.host : this.relation.target === i.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;
8175
8196
  const r = this.args.attributeQuery || [];
8176
8197
  this.relatedAttributeQuery = this.args.attributeQuery?.filter((o) => o[0] !== f) || [];
8177
8198
  const s = (r.find((o) => o[0] === f) || [])[1]?.attributeQuery;
@@ -8334,7 +8355,7 @@ class Oi {
8334
8355
  }
8335
8356
  class Di {
8336
8357
  constructor(t, e, i) {
8337
- this.controller = t, this.args = e, this.dataContext = i, this.useLastValue = !0, this.dataDeps = {}, this.relation = this.controller.relations.find((o) => o.source === i.host && o.sourceProperty === this.args.property || o.target === i.host && o.targetProperty === this.args.property), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === i.host.name, k(this.isSource ? this.relation.source === i.host : this.relation.target === i.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;
8358
+ this.controller = t, this.args = e, this.dataContext = i, this.useLastValue = !0, this.dataDeps = {}, this.relation = this.controller.relations.find((o) => o.source === i.host && o.sourceProperty === this.args.property || o.target === i.host && o.targetProperty === this.args.property), this.isSource = this.args.direction ? this.args.direction === "source" : this.relation.source.name === i.host.name, A(this.isSource ? this.relation.source === i.host : this.relation.target === i.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;
8338
8359
  const r = this.args.attributeQuery || [];
8339
8360
  this.relatedAttributeQuery = r.filter((o) => o && o[0] !== f) || [];
8340
8361
  const s = (r.find((o) => o && o[0] === f) || [])[1]?.attributeQuery;
@@ -8510,7 +8531,7 @@ class Bi extends St {
8510
8531
  constructor(t, e, i) {
8511
8532
  if (e.dataDeps) {
8512
8533
  const r = Object.keys(e.dataDeps).filter((s) => e.dataDeps[s].type === "records");
8513
- k(r.length === 0, `property-level custom computation dataDeps should not contain "records” type dataDeps, but got ${r.join(", ")}
8534
+ A(r.length === 0, `property-level custom computation dataDeps should not contain "records” type dataDeps, but got ${r.join(", ")}
8514
8535
  If you want to use related entity/relation as dataDeps, please use "property" type dataDeps with args: { type: "property", attributeQuery: [attributeQuery] }
8515
8536
  If you want to use aggregated data from all records in the entity/relation, you should define a different dict value to store the aggregated data, and then use the dict value as dataDeps.
8516
8537
  `);
@@ -8846,9 +8867,9 @@ class Ji {
8846
8867
  });
8847
8868
  for (const o of a) {
8848
8869
  const n = o.dataContext, c = o.args, l = this.computationHandleMap.get(c.constructor);
8849
- k(!!l, `cannot find Computation handle map for ${c.constructor.displayName || c.constructor.name}`);
8870
+ A(!!l, `cannot find Computation handle map for ${c.constructor.displayName || c.constructor.name}`);
8850
8871
  const d = l[n.type];
8851
- k(!!d, `cannot find Computation handle for ${c.constructor.displayName || c.constructor.name} with context type ${n.type}`);
8872
+ A(!!d, `cannot find Computation handle for ${c.constructor.displayName || c.constructor.name} with context type ${n.type}`);
8852
8873
  const h = new d(this.controller, c, n);
8853
8874
  if (this.computationsHandles.set(n.id, h), this.isAsyncComputation(h)) {
8854
8875
  if (h.dataContext.type === "property") {
@@ -8960,7 +8981,7 @@ class Ji {
8960
8981
  const r = this.computationHandleMap.get(i.computationType);
8961
8982
  if (Array.isArray(i.contextType))
8962
8983
  for (const s of i.contextType)
8963
- k(!r[s], `${s} for ${i.computationType.name} is already registered.`), r[s] = e;
8984
+ A(!r[s], `${s} for ${i.computationType.name} is already registered.`), r[s] = e;
8964
8985
  else
8965
8986
  r[i.contextType] = e;
8966
8987
  }
@@ -8990,13 +9011,13 @@ class Ji {
8990
9011
  }
8991
9012
  async createStateData(t, ...e) {
8992
9013
  const i = this.computationsHandles.get(t);
8993
- return k(!!i, "cannot find computation handle"), i.createStateData?.(...e) ?? {};
9014
+ return A(!!i, "cannot find computation handle"), i.createStateData?.(...e) ?? {};
8994
9015
  }
8995
9016
  addMutationPropertyComputationDefaultValueListeners() {
8996
9017
  for (const t of this.computationsHandles.values())
8997
9018
  if (t.getInitialValue && t.dataContext.type === "property") {
8998
9019
  const e = t.dataContext;
8999
- k(!e.id.defaultValue, `${e.host.name}.${e.id.name} property shuold not has a defaultValue, because it will be overridden by computation`), this.controller.system.storage.listen(async (i) => {
9020
+ A(!e.id.defaultValue, `${e.host.name}.${e.id.name} property shuold not has a defaultValue, because it will be overridden by computation`), this.controller.system.storage.listen(async (i) => {
9000
9021
  for (let r of i)
9001
9022
  if (r.type === "create" && r.recordName === e.host.name) {
9002
9023
  const s = await t.getInitialValue?.(r.record);
@@ -9035,11 +9056,11 @@ class Ji {
9035
9056
  return [e.oldRecord ?? e.record];
9036
9057
  let i = [];
9037
9058
  if (!t.isRelation)
9038
- k(t.type === "update", "only support update event for entity"), i = await this.controller.system.storage.find(t.sourceRecordName, m.atom({
9059
+ A(t.type === "update", "only support update event for entity"), i = await this.controller.system.storage.find(t.sourceRecordName, m.atom({
9039
9060
  key: t.targetPath.concat("id").join("."),
9040
9061
  value: ["=", e.oldRecord.id]
9041
9062
  }), void 0);
9042
- else if (k(t.type === "create" || t.type === "delete", "only support create/delete event for relation"), t.dataDep, t.type === "create")
9063
+ else if (A(t.type === "create" || t.type === "delete", "only support create/delete event for relation"), t.dataDep, t.type === "create")
9043
9064
  i = await this.controller.system.storage.find(t.sourceRecordName, m.atom({
9044
9065
  key: t.targetPath.concat(["&", "id"]).join("."),
9045
9066
  value: ["=", e.record.id]
@@ -9499,7 +9520,9 @@ class we {
9499
9520
  try {
9500
9521
  o = await a.call(this.controller, t);
9501
9522
  } catch (n) {
9502
- console.warn("check function throw", n), o = !1;
9523
+ console.warn("check function throw", n);
9524
+ const c = n instanceof Error ? n.message : String(n);
9525
+ return `Condition '${s.name}' threw exception: ${c}`;
9503
9526
  }
9504
9527
  return o === void 0 ? (console.warn(`condition ${s.name} returned undefined, maybe not implemented, we will return true for now`), !0) : o;
9505
9528
  } else
@@ -9522,7 +9545,7 @@ class we {
9522
9545
  return [o.name, { result: n, error: c }];
9523
9546
  })()), a = await Promise.all(s);
9524
9547
  for (let [o, { result: n, error: c }] of a)
9525
- k(!i.sideEffects[o], `sideEffect ${o} already exists`), i.sideEffects[o] = { result: n, error: c };
9548
+ A(!i.sideEffects[o], `sideEffect ${o} already exists`), i.sideEffects[o] = { result: n, error: c };
9526
9549
  }
9527
9550
  isGetInteraction() {
9528
9551
  return this.interaction.action === Me;
@@ -9538,7 +9561,7 @@ class we {
9538
9561
  const a = { ...t.query?.modifier || {}, ...s || {} }, o = t.query?.attributeQuery || [], n = typeof r == "function" ? await r.call(this.controller, t) : r, c = R.and(n, t.query?.match);
9539
9562
  e = await this.system.storage.find(i, c, a, o);
9540
9563
  } else
9541
- k(!1, `unknown data type ${this.interaction.data}`);
9564
+ A(!1, `unknown data type ${this.interaction.data}`);
9542
9565
  return e;
9543
9566
  }
9544
9567
  async check(t, e, i, r) {
@@ -9657,7 +9680,7 @@ class oe {
9657
9680
  }
9658
9681
  class tt {
9659
9682
  constructor(t, e) {
9660
- 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 (i, r, s) => (k(i.isRef, "attributive must be ref"), ((await this.getActivity(s))?.refs)[i.name] === r.id), this.system = e.system, this.graph = this.buildGraph(t);
9683
+ 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 (i, r, s) => (A(i.isRef, "attributive must be ref"), ((await this.getActivity(s))?.refs)[i.name] === r.id), this.system = e.system, this.graph = this.buildGraph(t);
9661
9684
  }
9662
9685
  static {
9663
9686
  this.cache = /* @__PURE__ */ new Map();
@@ -9693,7 +9716,7 @@ class tt {
9693
9716
  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)]);
9694
9717
  if (t.transfers?.forEach((o) => {
9695
9718
  const n = this.rawToNode.get(o.source) || i.get(o.source), c = this.rawToNode.get(o.target) || i.get(o.target);
9696
- k(!!n, `cannot find source ${o.source.name}`), k(!!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);
9719
+ A(!!n, `cannot find source ${o.source.name}`), A(!!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);
9697
9720
  }), s.size !== 1) throw new Error(`start node must one, current: ${s.size}`);
9698
9721
  if (a.size !== 1) throw new Error(`end node must be one, current: ${a.size}`);
9699
9722
  return Object.assign(r, {
@@ -9768,7 +9791,7 @@ class tt {
9768
9791
  return o;
9769
9792
  await this.saveUserRefs(s, r, i);
9770
9793
  const n = a.completeInteraction(e);
9771
- k(n, "change activity state failed");
9794
+ A(n, "change activity state failed");
9772
9795
  const c = a.toJSON();
9773
9796
  return await this.setActivity(s, { state: c }), {
9774
9797
  ...o,
@@ -9882,10 +9905,10 @@ class Xi {
9882
9905
  constructor(t, e, i) {
9883
9906
  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(ve, Ne), this.controller.relations.push(Gi), e.forEach((r) => {
9884
9907
  const s = new tt(r, t);
9885
- this.activityCalls.set(r.uuid, s), r.name && (k(!this.activityCallsByName.has(r.name), `activity name ${r.name} is duplicated`), this.activityCallsByName.set(r.name, s));
9908
+ this.activityCalls.set(r.uuid, s), r.name && (A(!this.activityCallsByName.has(r.name), `activity name ${r.name} is duplicated`), this.activityCallsByName.set(r.name, s));
9886
9909
  }), i.forEach((r) => {
9887
9910
  const s = new we(r, t);
9888
- this.interactionCalls.set(r.uuid, s), r.name && (k(!this.interactionCallsByName.has(r.name), `interaction name ${r.name} is duplicated`), this.interactionCallsByName.set(r.name, s));
9911
+ this.interactionCalls.set(r.uuid, s), r.name && (A(!this.interactionCallsByName.has(r.name), `interaction name ${r.name} is duplicated`), this.interactionCallsByName.set(r.name, s));
9889
9912
  });
9890
9913
  }
9891
9914
  async callInteraction(t, e) {
@@ -10131,7 +10154,7 @@ class Sr {
10131
10154
  }
10132
10155
  } else {
10133
10156
  const a = t;
10134
- a.id.name === Ot && s.data ? (k(s.type !== "delete", "Hard deletion property cannot be deleted"), await this.system.storage.delete(a.host.name, R.atom({ key: "id", value: ["=", i.id] }))) : s.type === "insert" ? await this.system.storage.update(a.host.name, R.atom({ key: "id", value: ["=", i.id] }), { [a.id.name]: s.data }) : s.type === "update" ? await this.system.storage.update(a.host.name, R.atom({ key: "id", value: ["=", i.id] }), { [a.id.name]: s.data }) : s.type === "delete" && await this.system.storage.update(a.host.name, R.atom({ key: "id", value: ["=", i.id] }), { [a.id.name]: null });
10157
+ a.id.name === Ot && s.data ? (A(s.type !== "delete", "Hard deletion property cannot be deleted"), await this.system.storage.delete(a.host.name, R.atom({ key: "id", value: ["=", i.id] }))) : s.type === "insert" ? await this.system.storage.update(a.host.name, R.atom({ key: "id", value: ["=", i.id] }), { [a.id.name]: s.data }) : s.type === "update" ? await this.system.storage.update(a.host.name, R.atom({ key: "id", value: ["=", i.id] }), { [a.id.name]: s.data }) : s.type === "delete" && await this.system.storage.update(a.host.name, R.atom({ key: "id", value: ["=", i.id] }), { [a.id.name]: null });
10135
10158
  }
10136
10159
  }
10137
10160
  }
@@ -10512,7 +10535,7 @@ export {
10512
10535
  ct as WeightedSummation,
10513
10536
  gi as WeightedSummationHandles,
10514
10537
  ce as addToCurrentEffects,
10515
- k as assert,
10538
+ A as assert,
10516
10539
  Yt as asyncEffectsContext,
10517
10540
  ne as asyncInteractionContext,
10518
10541
  fr as boolExpToAttributives,