@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.
@@ -1,5 +1,5 @@
1
1
  import { d as RecordsDataSource, a as RecordsConfig } from '../ports-DEkN-WfA.cjs';
2
- import { T as TemplateSpec } from '../types-BhGs3f8s.cjs';
2
+ import { T as TemplateSpec } from '../types-KdeN9-5L.cjs';
3
3
  import { P as PgError } from '../record-zwSBU5PQ.cjs';
4
4
  import '../field-DjS7iId2.cjs';
5
5
  import '../subscription-ycCVo9e2.cjs';
@@ -1,5 +1,5 @@
1
1
  import { d as RecordsDataSource, a as RecordsConfig } from '../ports-YOhD5T7h.js';
2
- import { T as TemplateSpec } from '../types-DAruHh1G.js';
2
+ import { T as TemplateSpec } from '../types-qvGJwpw3.js';
3
3
  import { P as PgError } from '../record-zwSBU5PQ.js';
4
4
  import '../field-D-1OKy5r.js';
5
5
  import '../subscription-DucBLG-Y.js';
@@ -1840,11 +1840,28 @@ function compileInstallPlan(written) {
1840
1840
  const spec = tokenizeValues({ ...written, attachments: void 0 }, attachmentKeys);
1841
1841
  const bound = new Map(allTables(spec).filter((t) => t.bindsTo?.tableId).map((t) => [t.token, t.bindsTo]));
1842
1842
  const has = (token, key) => bound.get(token)?.fields.includes(key) ?? false;
1843
+ const resolves = (target, v) => {
1844
+ const b = bound.get(target);
1845
+ return !b || !!b.seedRows || typeof v === "string" && !!b.rowIds?.[v];
1846
+ };
1843
1847
  const tables = allTables(spec).map((t) => {
1844
- if (bound.has(t.token)) return { ...t, rows: [] };
1845
- const toBound = t.fields.filter((f) => f.parityType === "relation" && f.relationTarget && bound.has(f.relationTarget)).map((f) => f.key);
1848
+ if (bound.has(t.token)) return bound.get(t.token).seedRows ? t : { ...t, rows: [] };
1849
+ const toBound = t.fields.filter((f) => f.parityType === "relation" && f.relationTarget && bound.has(f.relationTarget));
1846
1850
  if (!toBound.length) return t;
1847
- return { ...t, rows: t.rows.map((r) => ({ ...r, values: Object.fromEntries(Object.entries(r.values ?? {}).filter(([k]) => !toBound.includes(k))) })) };
1851
+ const lost = /* @__PURE__ */ new Set();
1852
+ const rows = t.rows.map((r) => {
1853
+ const values = { ...r.values ?? {} };
1854
+ for (const f of toBound) {
1855
+ const v = values[f.key];
1856
+ if (v === null || v === void 0) continue;
1857
+ const keep = Array.isArray(v) ? v.filter((x) => resolves(f.relationTarget, x)) : resolves(f.relationTarget, v) ? v : null;
1858
+ if (Array.isArray(keep) ? keep.length < v.length : keep === null) lost.add(f.key);
1859
+ if (keep === null || Array.isArray(keep) && !keep.length) delete values[f.key];
1860
+ else values[f.key] = keep;
1861
+ }
1862
+ return { ...r, values };
1863
+ });
1864
+ return { ...t, rows, fields: t.fields.map((f) => lost.has(f.key) && f.required ? { ...f, required: false } : f) };
1848
1865
  });
1849
1866
  const steps = [];
1850
1867
  const tableRef = (token) => {
@@ -1920,6 +1937,7 @@ function compileInstallPlan(written) {
1920
1937
  }
1921
1938
  const rowIds = /* @__PURE__ */ new Map();
1922
1939
  for (const t of tables) for (const r of t.rows) rowIds.set(`${t.token}.${r.key}`, minted(`row.${t.token}.${r.key}`));
1940
+ for (const [token, b] of bound) if (!b.seedRows) for (const [key, id] of Object.entries(b.rowIds ?? {})) rowIds.set(`${token}.${key}`, id);
1923
1941
  const deferred = deferredRelations(tables);
1924
1942
  for (const level of rowLevels(tables)) {
1925
1943
  for (const t of level) {