@ai-matrx/records 0.96.3 → 0.96.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog — @ai-matrx/records
2
2
 
3
+ ## 0.96.5
4
+
5
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
6
+ `git diff npm/records/v0.96.4..npm/records/v0.96.5 -- apps/shared/records`).
7
+ No source changes intended and no consumer action required.
8
+
9
+ ## 0.96.4
10
+
11
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
12
+ `git diff npm/records/v0.96.3..npm/records/v0.96.4 -- apps/shared/records`).
13
+ No source changes intended and no consumer action required.
14
+
3
15
  ## 0.96.3
4
16
 
5
17
  Automatic changed-only republish (docs/metadata drift since the last tag — see
@@ -1878,11 +1878,28 @@ function compileInstallPlan(written) {
1878
1878
  const spec = tokenizeValues({ ...written, attachments: void 0 }, attachmentKeys);
1879
1879
  const bound = new Map(allTables(spec).filter((t) => t.bindsTo?.tableId).map((t) => [t.token, t.bindsTo]));
1880
1880
  const has = (token, key) => bound.get(token)?.fields.includes(key) ?? false;
1881
+ const resolves = (target, v) => {
1882
+ const b = bound.get(target);
1883
+ return !b || !!b.seedRows || typeof v === "string" && !!b.rowIds?.[v];
1884
+ };
1881
1885
  const tables = allTables(spec).map((t) => {
1882
- if (bound.has(t.token)) return { ...t, rows: [] };
1883
- const toBound = t.fields.filter((f) => f.parityType === "relation" && f.relationTarget && bound.has(f.relationTarget)).map((f) => f.key);
1886
+ if (bound.has(t.token)) return bound.get(t.token).seedRows ? t : { ...t, rows: [] };
1887
+ const toBound = t.fields.filter((f) => f.parityType === "relation" && f.relationTarget && bound.has(f.relationTarget));
1884
1888
  if (!toBound.length) return t;
1885
- return { ...t, rows: t.rows.map((r) => ({ ...r, values: Object.fromEntries(Object.entries(r.values ?? {}).filter(([k]) => !toBound.includes(k))) })) };
1889
+ const lost = /* @__PURE__ */ new Set();
1890
+ const rows = t.rows.map((r) => {
1891
+ const values = { ...r.values ?? {} };
1892
+ for (const f of toBound) {
1893
+ const v = values[f.key];
1894
+ if (v === null || v === void 0) continue;
1895
+ const keep = Array.isArray(v) ? v.filter((x) => resolves(f.relationTarget, x)) : resolves(f.relationTarget, v) ? v : null;
1896
+ if (Array.isArray(keep) ? keep.length < v.length : keep === null) lost.add(f.key);
1897
+ if (keep === null || Array.isArray(keep) && !keep.length) delete values[f.key];
1898
+ else values[f.key] = keep;
1899
+ }
1900
+ return { ...r, values };
1901
+ });
1902
+ return { ...t, rows, fields: t.fields.map((f) => lost.has(f.key) && f.required ? { ...f, required: false } : f) };
1886
1903
  });
1887
1904
  const steps = [];
1888
1905
  const tableRef = (token) => {
@@ -1958,6 +1975,7 @@ function compileInstallPlan(written) {
1958
1975
  }
1959
1976
  const rowIds = /* @__PURE__ */ new Map();
1960
1977
  for (const t of tables) for (const r of t.rows) rowIds.set(`${t.token}.${r.key}`, minted(`row.${t.token}.${r.key}`));
1978
+ for (const [token, b] of bound) if (!b.seedRows) for (const [key, id] of Object.entries(b.rowIds ?? {})) rowIds.set(`${token}.${key}`, id);
1961
1979
  const deferred = deferredRelations(tables);
1962
1980
  for (const level of rowLevels(tables)) {
1963
1981
  for (const t of level) {