@ai-matrx/records 0.96.2 → 0.96.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.
@@ -6125,11 +6125,28 @@ function compileInstallPlan(written) {
6125
6125
  const spec = tokenizeValues({ ...written, attachments: void 0 }, attachmentKeys);
6126
6126
  const bound = new Map(allTables(spec).filter((t) => t.bindsTo?.tableId).map((t) => [t.token, t.bindsTo]));
6127
6127
  const has = (token, key) => bound.get(token)?.fields.includes(key) ?? false;
6128
+ const resolves = (target, v) => {
6129
+ const b = bound.get(target);
6130
+ return !b || !!b.seedRows || typeof v === "string" && !!b.rowIds?.[v];
6131
+ };
6128
6132
  const tables = allTables(spec).map((t) => {
6129
- if (bound.has(t.token)) return { ...t, rows: [] };
6130
- const toBound = t.fields.filter((f) => f.parityType === "relation" && f.relationTarget && bound.has(f.relationTarget)).map((f) => f.key);
6133
+ if (bound.has(t.token)) return bound.get(t.token).seedRows ? t : { ...t, rows: [] };
6134
+ const toBound = t.fields.filter((f) => f.parityType === "relation" && f.relationTarget && bound.has(f.relationTarget));
6131
6135
  if (!toBound.length) return t;
6132
- return { ...t, rows: t.rows.map((r) => ({ ...r, values: Object.fromEntries(Object.entries(r.values ?? {}).filter(([k]) => !toBound.includes(k))) })) };
6136
+ const lost = /* @__PURE__ */ new Set();
6137
+ const rows = t.rows.map((r) => {
6138
+ const values = { ...r.values ?? {} };
6139
+ for (const f of toBound) {
6140
+ const v = values[f.key];
6141
+ if (v === null || v === void 0) continue;
6142
+ const keep = Array.isArray(v) ? v.filter((x) => resolves(f.relationTarget, x)) : resolves(f.relationTarget, v) ? v : null;
6143
+ if (Array.isArray(keep) ? keep.length < v.length : keep === null) lost.add(f.key);
6144
+ if (keep === null || Array.isArray(keep) && !keep.length) delete values[f.key];
6145
+ else values[f.key] = keep;
6146
+ }
6147
+ return { ...r, values };
6148
+ });
6149
+ return { ...t, rows, fields: t.fields.map((f) => lost.has(f.key) && f.required ? { ...f, required: false } : f) };
6133
6150
  });
6134
6151
  const steps = [];
6135
6152
  const tableRef = (token) => {
@@ -6205,6 +6222,7 @@ function compileInstallPlan(written) {
6205
6222
  }
6206
6223
  const rowIds = /* @__PURE__ */ new Map();
6207
6224
  for (const t of tables) for (const r of t.rows) rowIds.set(`${t.token}.${r.key}`, minted(`row.${t.token}.${r.key}`));
6225
+ for (const [token, b] of bound) if (!b.seedRows) for (const [key, id] of Object.entries(b.rowIds ?? {})) rowIds.set(`${token}.${key}`, id);
6208
6226
  const deferred = deferredRelations(tables);
6209
6227
  for (const level of rowLevels(tables)) {
6210
6228
  for (const t of level) {