@fayz-ai/core 0.38.0 → 0.39.0

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.
@@ -1381,6 +1381,63 @@ function resetActiveUnit() {
1381
1381
  notify();
1382
1382
  }
1383
1383
 
1384
+ // src/data/metadata-fields.ts
1385
+ function withMetadataFields(provider, fields) {
1386
+ const paths = Array.isArray(fields) ? fields.map((k) => [k, [k]]) : Object.entries(fields).map(([k, p]) => [k, p.split(".")]);
1387
+ if (paths.length === 0) return provider;
1388
+ const getIn = (obj, path) => path.reduce((o, seg) => o && typeof o === "object" ? o[seg] : void 0, obj);
1389
+ const setIn = (obj, path, value) => {
1390
+ const [head, ...rest] = path;
1391
+ if (!head) return obj;
1392
+ if (rest.length === 0) return { ...obj, [head]: value };
1393
+ const child = obj[head] && typeof obj[head] === "object" && !Array.isArray(obj[head]) ? obj[head] : {};
1394
+ return { ...obj, [head]: setIn(child, rest, value) };
1395
+ };
1396
+ const lift = (row) => {
1397
+ const meta = row.metadata;
1398
+ if (!meta || typeof meta !== "object") return row;
1399
+ const out = { ...row };
1400
+ for (const [k, p] of paths) {
1401
+ const v = getIn(meta, p);
1402
+ if (out[k] === void 0 && v !== void 0) out[k] = v;
1403
+ }
1404
+ return out;
1405
+ };
1406
+ const split = (data) => {
1407
+ const rest = { ...data };
1408
+ const patch = [];
1409
+ for (const [k, p] of paths) {
1410
+ if (k in rest) {
1411
+ patch.push([p, rest[k] === "" ? null : rest[k]]);
1412
+ delete rest[k];
1413
+ }
1414
+ }
1415
+ return { rest, patch };
1416
+ };
1417
+ const apply = (base, patch) => patch.reduce((acc, [p, v]) => setIn(acc, p, v), base);
1418
+ return {
1419
+ ...provider,
1420
+ async list(query) {
1421
+ const r = await provider.list(query);
1422
+ return { ...r, data: r.data.map(lift) };
1423
+ },
1424
+ async create(data) {
1425
+ const { rest, patch } = split(data);
1426
+ if (patch.length === 0) return lift(await provider.create(data));
1427
+ const base = rest.metadata ?? {};
1428
+ return lift(await provider.create({ ...rest, metadata: apply(base, patch) }));
1429
+ },
1430
+ async update(id, data) {
1431
+ const { rest, patch } = split(data);
1432
+ if (patch.length === 0) return lift(await provider.update(id, data));
1433
+ const { data: rows } = await provider.list({ filters: { id }, pageSize: 1, countMode: "none" });
1434
+ const current = rows[0]?.metadata ?? {};
1435
+ const incoming = rest.metadata ?? {};
1436
+ return lift(await provider.update(id, { ...rest, metadata: apply({ ...current, ...incoming }, patch) }));
1437
+ }
1438
+ };
1439
+ }
1440
+
1384
1441
  // src/data/custom-fields.ts
1385
1442
  var KEY = "customFields";
1386
1443
  function patchOf(data) {
@@ -1633,7 +1690,7 @@ function resolveDataProvider(entityDef, mockData, options = {}) {
1633
1690
  ...unitConfig
1634
1691
  }), entityDef.data.archetype)));
1635
1692
  }
1636
- return cached(withAddress(createSupabaseProvider(entityDef.data.table, {
1693
+ return cached(withAddress(withMetadataFields(createSupabaseProvider(entityDef.data.table, {
1637
1694
  schema: entityDef.data.schema,
1638
1695
  tenantId: entityDef.data.tenantScoped === false ? void 0 : tenantId,
1639
1696
  tenantIdColumn: entityDef.data.tenantIdColumn,
@@ -1643,7 +1700,7 @@ function resolveDataProvider(entityDef, mockData, options = {}) {
1643
1700
  filters: entityDef.data.filters,
1644
1701
  defaults: entityDef.data.defaults,
1645
1702
  ...unitConfig
1646
- })));
1703
+ }), entityDef.data.metadataFields ?? [])));
1647
1704
  }
1648
1705
  if (entityDef.data?.table) {
1649
1706
  console.warn(
@@ -1933,5 +1990,5 @@ async function bulkRemove(provider, ids, options) {
1933
1990
  }
1934
1991
 
1935
1992
  export { CustomFieldsError, DATA_CHANGED_EVENT, DataError, FIELDS_TABLE, attachPersistentCache, bulkCreate, bulkRemove, cacheKeyFor, cachePrefixFor, clearCustomFieldsCache, countByTenant, createArchetypeProvider, createEventBus, createFayzApiProvider, createMockProvider, dataCall, dataQuery, emitDataChanged, eventBus, getActiveUnitId, getPersistentCache, invalidateCount, isKnownMissing, isUnitMode, localList, matchesDataChange, mergeCustomFields, onDataChanged, registerDataTelemetry, rememberIfMissing, replicaKeyFor, resetActiveUnit, resetMissingObjects, resolveCustomFields, resolveDataProvider, setActiveUnitId, setUnitMode, subscribeActiveUnit, syncReplica, toDataError, useActiveUnitId, useDataChanged, useUnitMode, validateCustomFields, withCache, withOffline };
1936
- //# sourceMappingURL=chunk-KGZK47XI.js.map
1937
- //# sourceMappingURL=chunk-KGZK47XI.js.map
1993
+ //# sourceMappingURL=chunk-U2K7ZEDA.js.map
1994
+ //# sourceMappingURL=chunk-U2K7ZEDA.js.map