@ai-matrx/records 0.87.3 → 0.87.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6706,7 +6706,8 @@ async function ensureAppAutomations(client, def, specs, options = {}) {
6706
6706
  actions.push({
6707
6707
  do: "edit_rows",
6708
6708
  table_id: other.data.table,
6709
- where: keyed(a.where, theirs.data, own.data, a.table.name),
6709
+ // A Rule (`{ op, args }`) is the store's filter; a flat `{ key: value }` map is keyed.
6710
+ where: typeof a.where.op === "string" ? rewriteWhere(a.where, theirs.data, own.data) : keyed(a.where, theirs.data, own.data, a.table.name),
6710
6711
  values: keyed(a.values, theirs.data, own.data, a.table.name),
6711
6712
  ...a.limit ? { limit: a.limit } : {}
6712
6713
  });
@@ -6731,6 +6732,19 @@ async function ensureAppAutomations(client, def, specs, options = {}) {
6731
6732
  }
6732
6733
  return { ok: true, data: ids };
6733
6734
  }
6735
+ function rewriteWhere(node, target, source) {
6736
+ const walk = (n) => {
6737
+ if (Array.isArray(n)) return n.map(walk);
6738
+ if (n && typeof n === "object") {
6739
+ const o = n;
6740
+ if (Object.keys(o).length === 1 && typeof o.field === "string") return { field: byId(target, o.field, "the edited table") };
6741
+ if (Object.keys(o).length === 1 && typeof o.trigger === "string") return { trigger: byId(source, o.trigger, "the triggering table") };
6742
+ return Object.fromEntries(Object.entries(o).map(([k, v]) => [k, walk(v)]));
6743
+ }
6744
+ return n;
6745
+ };
6746
+ return walk(node);
6747
+ }
6734
6748
  function rewriteCondition(node, ids) {
6735
6749
  const walk = (n) => {
6736
6750
  if (Array.isArray(n)) return n.map(walk);