@fayz-ai/core 0.38.0 → 0.40.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.
- package/dist/{chunk-MFFT663T.js → chunk-6FCJLF55.js} +3 -3
- package/dist/{chunk-MFFT663T.js.map → chunk-6FCJLF55.js.map} +1 -1
- package/dist/chunk-DRDQ5JJG.js +146 -0
- package/dist/chunk-DRDQ5JJG.js.map +1 -0
- package/dist/{chunk-KGZK47XI.js → chunk-G4F6RON5.js} +64 -127
- package/dist/chunk-G4F6RON5.js.map +1 -0
- package/dist/{chunk-EFMUJACX.js → chunk-ITUYZLT6.js} +3 -3
- package/dist/{chunk-EFMUJACX.js.map → chunk-ITUYZLT6.js.map} +1 -1
- package/dist/{chunk-ODTOKMD3.js → chunk-RXIOJQFH.js} +22 -3
- package/dist/chunk-RXIOJQFH.js.map +1 -0
- package/dist/{chunk-X3GYBLGO.js → chunk-VAHWWJC2.js} +4 -4
- package/dist/{chunk-X3GYBLGO.js.map → chunk-VAHWWJC2.js.map} +1 -1
- package/dist/{chunk-QZ22VPRZ.js → chunk-X5EJ532G.js} +4 -4
- package/dist/{chunk-QZ22VPRZ.js.map → chunk-X5EJ532G.js.map} +1 -1
- package/dist/data/index.js +4 -3
- package/dist/data/metadata-fields.d.ts +19 -0
- package/dist/data/metadata-fields.d.ts.map +1 -0
- package/dist/data/resolve.d.ts.map +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/shell-translations.en.d.ts.map +1 -1
- package/dist/i18n/shell-translations.pt-br.d.ts.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +123 -19
- package/dist/index.js.map +1 -1
- package/dist/integrations/index.js +4 -3
- package/dist/lib/connectivity.d.ts +17 -0
- package/dist/lib/connectivity.d.ts.map +1 -0
- package/dist/lib/error-message.d.ts +7 -0
- package/dist/lib/error-message.d.ts.map +1 -1
- package/dist/lib/impersonation.d.ts +30 -0
- package/dist/lib/impersonation.d.ts.map +1 -0
- package/dist/plugin/index.js +3 -2
- package/dist/{shell-translations.pt-br-TTVH5GSD.js → shell-translations.pt-br-UM63CUBG.js} +21 -2
- package/dist/shell-translations.pt-br-UM63CUBG.js.map +1 -0
- package/dist/telemetry/errors.d.ts +3 -0
- package/dist/telemetry/errors.d.ts.map +1 -1
- package/dist/testing/index.js +5 -4
- package/dist/types/crud.d.ts +6 -0
- package/dist/types/crud.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-6TVRNKWW.js +0 -17
- package/dist/chunk-6TVRNKWW.js.map +0 -1
- package/dist/chunk-KGZK47XI.js.map +0 -1
- package/dist/chunk-ODTOKMD3.js.map +0 -1
- package/dist/shell-translations.pt-br-TTVH5GSD.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { globalCache, getActiveTenantId, getSupabaseClientOptional, parseRangeFilter, matchesRange, assertWrote, stableKey, DEFAULT_CACHE_TTL, getScopedResource, createSupabaseProvider, resolveUnitScope, applyUnitScope, applyRangeToQuery, isFilterObject, clearGlobalCache } from './chunk-
|
|
1
|
+
import { globalCache, getActiveTenantId, getSupabaseClientOptional, parseRangeFilter, matchesRange, assertWrote, stableKey, DEFAULT_CACHE_TTL, getScopedResource, createSupabaseProvider, resolveUnitScope, applyUnitScope, applyRangeToQuery, isFilterObject, clearGlobalCache } from './chunk-6FCJLF55.js';
|
|
2
2
|
import { declaredCustomFields, validateEntityRecordData } from './chunk-EWKX4VUM.js';
|
|
3
|
-
import { errorMessage } from './chunk-
|
|
3
|
+
import { toDataError, DataError, errorMessage } from './chunk-DRDQ5JJG.js';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
|
|
6
6
|
// src/data/count.ts
|
|
@@ -602,126 +602,6 @@ function withCache(provider, options) {
|
|
|
602
602
|
};
|
|
603
603
|
}
|
|
604
604
|
|
|
605
|
-
// src/data/errors.ts
|
|
606
|
-
var RETRYABLE_KINDS = ["offline", "server"];
|
|
607
|
-
var DataError = class extends Error {
|
|
608
|
-
constructor(kind, message, options = {}) {
|
|
609
|
-
super(message);
|
|
610
|
-
this.name = "DataError";
|
|
611
|
-
this.kind = kind;
|
|
612
|
-
this.retryable = RETRYABLE_KINDS.includes(kind);
|
|
613
|
-
this.cause = options.cause;
|
|
614
|
-
this.status = options.status;
|
|
615
|
-
this.code = options.code;
|
|
616
|
-
this.details = options.details;
|
|
617
|
-
this.hint = options.hint;
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
|
-
var CODE_KINDS = {
|
|
621
|
-
// PostgREST
|
|
622
|
-
PGRST100: "invalid",
|
|
623
|
-
// parse error in the query string
|
|
624
|
-
PGRST106: "missing-object",
|
|
625
|
-
// schema not exposed
|
|
626
|
-
PGRST116: "not-found",
|
|
627
|
-
// zero rows where exactly one was requested
|
|
628
|
-
PGRST202: "missing-object",
|
|
629
|
-
// function not found in schema cache
|
|
630
|
-
PGRST204: "missing-object",
|
|
631
|
-
// column not found in schema cache
|
|
632
|
-
PGRST205: "missing-object",
|
|
633
|
-
// table not found in schema cache
|
|
634
|
-
PGRST301: "unauthorized",
|
|
635
|
-
// JWT invalid or expired
|
|
636
|
-
PGRST302: "unauthorized",
|
|
637
|
-
// anonymous access disabled
|
|
638
|
-
// Postgres
|
|
639
|
-
"22007": "invalid",
|
|
640
|
-
// invalid datetime format
|
|
641
|
-
"22P02": "invalid",
|
|
642
|
-
// invalid input syntax
|
|
643
|
-
"23502": "invalid",
|
|
644
|
-
// not-null violation
|
|
645
|
-
"23505": "conflict",
|
|
646
|
-
// unique violation
|
|
647
|
-
"23514": "invalid",
|
|
648
|
-
// check violation
|
|
649
|
-
"42501": "forbidden",
|
|
650
|
-
// insufficient privilege / permission denied
|
|
651
|
-
"42883": "missing-object",
|
|
652
|
-
// undefined function
|
|
653
|
-
"42P01": "missing-object",
|
|
654
|
-
// undefined table
|
|
655
|
-
"53300": "server",
|
|
656
|
-
// too many connections
|
|
657
|
-
"57014": "server"
|
|
658
|
-
// statement timeout, server side
|
|
659
|
-
};
|
|
660
|
-
var OFFLINE_CODES = /* @__PURE__ */ new Set(["ECONNREFUSED", "ECONNRESET", "ENOTFOUND", "ETIMEDOUT", "EAI_AGAIN"]);
|
|
661
|
-
var OFFLINE_TEXT = /failed to fetch|fetch failed|network ?error|networkrequestfailed|load failed|connection (refused|reset|closed)|err_internet_disconnected|aborted|signal is aborted|the operation was aborted|timed out|timeout/i;
|
|
662
|
-
function statusKind(status) {
|
|
663
|
-
if (status === 401) return "unauthorized";
|
|
664
|
-
if (status === 403) return "forbidden";
|
|
665
|
-
if (status === 404 || status === 406) return "not-found";
|
|
666
|
-
if (status === 408) return "offline";
|
|
667
|
-
if (status === 409) return "conflict";
|
|
668
|
-
if (status === 400 || status === 422) return "invalid";
|
|
669
|
-
if (status >= 500) return "server";
|
|
670
|
-
return "server";
|
|
671
|
-
}
|
|
672
|
-
function textKind(message) {
|
|
673
|
-
const m = message.toLowerCase();
|
|
674
|
-
if (/permission denied|row-level security|row level security|insufficient privilege/.test(m)) return "forbidden";
|
|
675
|
-
if (/does not exist|undefined table|undefined function|schema cache|could not find the (table|function)/.test(m)) return "missing-object";
|
|
676
|
-
if (/jwt|not authenticated|invalid token|unauthorized|no api key/.test(m)) return "unauthorized";
|
|
677
|
-
if (/duplicate key|already exists|conflict/.test(m)) return "conflict";
|
|
678
|
-
if (/invalid input (syntax|value)|violates (not-null|check) constraint|invalid request/.test(m)) return "invalid";
|
|
679
|
-
if (/no rows|not found/.test(m)) return "not-found";
|
|
680
|
-
return void 0;
|
|
681
|
-
}
|
|
682
|
-
function pick(source, key) {
|
|
683
|
-
const value = source[key];
|
|
684
|
-
return value === null ? void 0 : value;
|
|
685
|
-
}
|
|
686
|
-
function readStatus(source) {
|
|
687
|
-
for (const key of ["status", "statusCode", "httpStatus"]) {
|
|
688
|
-
const value = pick(source, key);
|
|
689
|
-
if (typeof value === "number") return value;
|
|
690
|
-
if (typeof value === "string" && /^\d{3}$/.test(value)) return Number(value);
|
|
691
|
-
}
|
|
692
|
-
const response = pick(source, "response");
|
|
693
|
-
if (response && typeof response === "object") {
|
|
694
|
-
const status = response.status;
|
|
695
|
-
if (typeof status === "number") return status;
|
|
696
|
-
}
|
|
697
|
-
return void 0;
|
|
698
|
-
}
|
|
699
|
-
function isOffline(name, message, code, status) {
|
|
700
|
-
if (name === "AbortError" || name === "TimeoutError") return true;
|
|
701
|
-
if (code && OFFLINE_CODES.has(code)) return true;
|
|
702
|
-
if (status !== void 0) return false;
|
|
703
|
-
const nav = globalThis.navigator;
|
|
704
|
-
if (nav && nav.onLine === false) return true;
|
|
705
|
-
return OFFLINE_TEXT.test(message);
|
|
706
|
-
}
|
|
707
|
-
function toDataError(err) {
|
|
708
|
-
if (err instanceof DataError) return err;
|
|
709
|
-
const source = err && typeof err === "object" ? err : {};
|
|
710
|
-
const name = typeof source.name === "string" ? source.name : "";
|
|
711
|
-
const rawMessage = typeof source.message === "string" ? source.message : "";
|
|
712
|
-
const message = rawMessage || (typeof err === "string" ? err : "") || "data request failed";
|
|
713
|
-
const codeValue = pick(source, "code");
|
|
714
|
-
const code = typeof codeValue === "string" ? codeValue : typeof codeValue === "number" ? String(codeValue) : void 0;
|
|
715
|
-
const status = readStatus(source);
|
|
716
|
-
const details = typeof source.details === "string" ? source.details : void 0;
|
|
717
|
-
const hint = typeof source.hint === "string" ? source.hint : void 0;
|
|
718
|
-
let kind = code ? CODE_KINDS[code] : void 0;
|
|
719
|
-
if (!kind && isOffline(name, message, code, status)) kind = "offline";
|
|
720
|
-
if (!kind && status !== void 0) kind = statusKind(status);
|
|
721
|
-
if (!kind) kind = textKind(message);
|
|
722
|
-
return new DataError(kind ?? "server", message, { cause: err, status, code, details, hint });
|
|
723
|
-
}
|
|
724
|
-
|
|
725
605
|
// src/events/bus.ts
|
|
726
606
|
function createEventBus() {
|
|
727
607
|
const handlers = /* @__PURE__ */ new Map();
|
|
@@ -1381,6 +1261,63 @@ function resetActiveUnit() {
|
|
|
1381
1261
|
notify();
|
|
1382
1262
|
}
|
|
1383
1263
|
|
|
1264
|
+
// src/data/metadata-fields.ts
|
|
1265
|
+
function withMetadataFields(provider, fields) {
|
|
1266
|
+
const paths = Array.isArray(fields) ? fields.map((k) => [k, [k]]) : Object.entries(fields).map(([k, p]) => [k, p.split(".")]);
|
|
1267
|
+
if (paths.length === 0) return provider;
|
|
1268
|
+
const getIn = (obj, path) => path.reduce((o, seg) => o && typeof o === "object" ? o[seg] : void 0, obj);
|
|
1269
|
+
const setIn = (obj, path, value) => {
|
|
1270
|
+
const [head, ...rest] = path;
|
|
1271
|
+
if (!head) return obj;
|
|
1272
|
+
if (rest.length === 0) return { ...obj, [head]: value };
|
|
1273
|
+
const child = obj[head] && typeof obj[head] === "object" && !Array.isArray(obj[head]) ? obj[head] : {};
|
|
1274
|
+
return { ...obj, [head]: setIn(child, rest, value) };
|
|
1275
|
+
};
|
|
1276
|
+
const lift = (row) => {
|
|
1277
|
+
const meta = row.metadata;
|
|
1278
|
+
if (!meta || typeof meta !== "object") return row;
|
|
1279
|
+
const out = { ...row };
|
|
1280
|
+
for (const [k, p] of paths) {
|
|
1281
|
+
const v = getIn(meta, p);
|
|
1282
|
+
if (out[k] === void 0 && v !== void 0) out[k] = v;
|
|
1283
|
+
}
|
|
1284
|
+
return out;
|
|
1285
|
+
};
|
|
1286
|
+
const split = (data) => {
|
|
1287
|
+
const rest = { ...data };
|
|
1288
|
+
const patch = [];
|
|
1289
|
+
for (const [k, p] of paths) {
|
|
1290
|
+
if (k in rest) {
|
|
1291
|
+
patch.push([p, rest[k] === "" ? null : rest[k]]);
|
|
1292
|
+
delete rest[k];
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
return { rest, patch };
|
|
1296
|
+
};
|
|
1297
|
+
const apply = (base, patch) => patch.reduce((acc, [p, v]) => setIn(acc, p, v), base);
|
|
1298
|
+
return {
|
|
1299
|
+
...provider,
|
|
1300
|
+
async list(query) {
|
|
1301
|
+
const r = await provider.list(query);
|
|
1302
|
+
return { ...r, data: r.data.map(lift) };
|
|
1303
|
+
},
|
|
1304
|
+
async create(data) {
|
|
1305
|
+
const { rest, patch } = split(data);
|
|
1306
|
+
if (patch.length === 0) return lift(await provider.create(data));
|
|
1307
|
+
const base = rest.metadata ?? {};
|
|
1308
|
+
return lift(await provider.create({ ...rest, metadata: apply(base, patch) }));
|
|
1309
|
+
},
|
|
1310
|
+
async update(id, data) {
|
|
1311
|
+
const { rest, patch } = split(data);
|
|
1312
|
+
if (patch.length === 0) return lift(await provider.update(id, data));
|
|
1313
|
+
const { data: rows } = await provider.list({ filters: { id }, pageSize: 1, countMode: "none" });
|
|
1314
|
+
const current = rows[0]?.metadata ?? {};
|
|
1315
|
+
const incoming = rest.metadata ?? {};
|
|
1316
|
+
return lift(await provider.update(id, { ...rest, metadata: apply({ ...current, ...incoming }, patch) }));
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1384
1321
|
// src/data/custom-fields.ts
|
|
1385
1322
|
var KEY = "customFields";
|
|
1386
1323
|
function patchOf(data) {
|
|
@@ -1633,7 +1570,7 @@ function resolveDataProvider(entityDef, mockData, options = {}) {
|
|
|
1633
1570
|
...unitConfig
|
|
1634
1571
|
}), entityDef.data.archetype)));
|
|
1635
1572
|
}
|
|
1636
|
-
return cached(withAddress(createSupabaseProvider(entityDef.data.table, {
|
|
1573
|
+
return cached(withAddress(withMetadataFields(createSupabaseProvider(entityDef.data.table, {
|
|
1637
1574
|
schema: entityDef.data.schema,
|
|
1638
1575
|
tenantId: entityDef.data.tenantScoped === false ? void 0 : tenantId,
|
|
1639
1576
|
tenantIdColumn: entityDef.data.tenantIdColumn,
|
|
@@ -1643,7 +1580,7 @@ function resolveDataProvider(entityDef, mockData, options = {}) {
|
|
|
1643
1580
|
filters: entityDef.data.filters,
|
|
1644
1581
|
defaults: entityDef.data.defaults,
|
|
1645
1582
|
...unitConfig
|
|
1646
|
-
})));
|
|
1583
|
+
}), entityDef.data.metadataFields ?? [])));
|
|
1647
1584
|
}
|
|
1648
1585
|
if (entityDef.data?.table) {
|
|
1649
1586
|
console.warn(
|
|
@@ -1932,6 +1869,6 @@ async function bulkRemove(provider, ids, options) {
|
|
|
1932
1869
|
return { removed, failed };
|
|
1933
1870
|
}
|
|
1934
1871
|
|
|
1935
|
-
export { CustomFieldsError, DATA_CHANGED_EVENT,
|
|
1936
|
-
//# sourceMappingURL=chunk-
|
|
1937
|
-
//# sourceMappingURL=chunk-
|
|
1872
|
+
export { CustomFieldsError, DATA_CHANGED_EVENT, 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, useActiveUnitId, useDataChanged, useUnitMode, validateCustomFields, withCache, withOffline };
|
|
1873
|
+
//# sourceMappingURL=chunk-G4F6RON5.js.map
|
|
1874
|
+
//# sourceMappingURL=chunk-G4F6RON5.js.map
|