@ai-matrx/records 0.80.8 → 0.81.1
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 +23 -0
- package/dist/app-table/index.cjs.map +1 -1
- package/dist/app-table/index.js.map +1 -1
- package/dist/core/index.cjs +74 -0
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +35 -1
- package/dist/core/index.d.ts +35 -1
- package/dist/core/index.js +74 -0
- package/dist/core/index.js.map +1 -1
- package/dist/data/index.cjs.map +1 -1
- package/dist/data/index.js.map +1 -1
- package/dist/memory/index.cjs.map +1 -1
- package/dist/memory/index.js.map +1 -1
- package/dist/react/index.cjs +268 -98
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +60 -1
- package/dist/react/index.d.ts +60 -1
- package/dist/react/index.js +206 -36
- package/dist/react/index.js.map +1 -1
- package/dist/templates/index.cjs +1 -1
- package/dist/templates/index.cjs.map +1 -1
- package/dist/templates/index.js +1 -1
- package/dist/templates/index.js.map +1 -1
- package/package.json +18 -3
package/dist/react/index.js
CHANGED
|
@@ -18,6 +18,10 @@ function registry() {
|
|
|
18
18
|
return g[REGISTRY] ??= /* @__PURE__ */ new Map();
|
|
19
19
|
}
|
|
20
20
|
var primedKey = (organizationId, tableId, viewId) => `${organizationId}|${tableId}|${viewId ?? ""}`;
|
|
21
|
+
function primeTablePageBundle(input) {
|
|
22
|
+
const answer = Promise.resolve(input.answer).catch((thrown) => ({ data: null, error: thrown }));
|
|
23
|
+
registry().set(primedKey(input.organizationId, input.tableId, input.viewId), { answer, at: Date.now() });
|
|
24
|
+
}
|
|
21
25
|
function takePrimedTablePageBundle(organizationId, tableId, viewId) {
|
|
22
26
|
if (!organizationId) return null;
|
|
23
27
|
const key = primedKey(organizationId, tableId, viewId);
|
|
@@ -27,6 +31,9 @@ function takePrimedTablePageBundle(organizationId, tableId, viewId) {
|
|
|
27
31
|
primed.delete(key);
|
|
28
32
|
return Date.now() - held.at < PRIMED_TTL_MS ? held.answer : null;
|
|
29
33
|
}
|
|
34
|
+
function primeRecordPageBundle(input) {
|
|
35
|
+
primeTablePageBundle({ organizationId: input.organizationId, tableId: `record:${input.recordId}`, answer: input.answer });
|
|
36
|
+
}
|
|
30
37
|
|
|
31
38
|
// src/core/recordChanges.ts
|
|
32
39
|
var listeners = /* @__PURE__ */ new Set();
|
|
@@ -144,8 +151,8 @@ function liftWithheld(rows) {
|
|
|
144
151
|
}
|
|
145
152
|
|
|
146
153
|
// src/subscription.ts
|
|
147
|
-
function hasQuietHours(
|
|
148
|
-
return Boolean(
|
|
154
|
+
function hasQuietHours(quiet2) {
|
|
155
|
+
return Boolean(quiet2?.start && quiet2?.end);
|
|
149
156
|
}
|
|
150
157
|
function callersTimeZone() {
|
|
151
158
|
try {
|
|
@@ -7569,7 +7576,7 @@ function useRecordsActor() {
|
|
|
7569
7576
|
}
|
|
7570
7577
|
|
|
7571
7578
|
// src/react/hooks.ts
|
|
7572
|
-
import { useCallback, useEffect as
|
|
7579
|
+
import { use, useCallback, useEffect as useEffect3, useId, useMemo as useMemo2, useRef as useRef2, useState, useSyncExternalStore } from "react";
|
|
7573
7580
|
|
|
7574
7581
|
// src/react/dataCache.ts
|
|
7575
7582
|
var RECORDS_CACHE_GRACE_MS = 3e4;
|
|
@@ -7722,6 +7729,12 @@ function releaseEntry(handle) {
|
|
|
7722
7729
|
entry.refs = Math.max(0, entry.refs - 1);
|
|
7723
7730
|
if (entry.refs === 0) scheduleClose(entry);
|
|
7724
7731
|
}
|
|
7732
|
+
function seedEntry(handle, data, stale) {
|
|
7733
|
+
const entry = handle;
|
|
7734
|
+
if (entry.started || entry.snapshot.data !== null) return;
|
|
7735
|
+
entry.snapshot = { data, loading: false, error: null };
|
|
7736
|
+
entry.started = !stale;
|
|
7737
|
+
}
|
|
7725
7738
|
function openHold(holdKey) {
|
|
7726
7739
|
const holds = root().holds;
|
|
7727
7740
|
let hold = holds.get(holdKey);
|
|
@@ -7752,17 +7765,154 @@ function recordsCacheCounters() {
|
|
|
7752
7765
|
return { ...root().counters };
|
|
7753
7766
|
}
|
|
7754
7767
|
|
|
7755
|
-
// src/react/
|
|
7768
|
+
// src/react/seed.tsx
|
|
7756
7769
|
import { createContext as createContext2, createElement as createElement2, useContext as useContext2, useEffect } from "react";
|
|
7757
|
-
|
|
7770
|
+
|
|
7771
|
+
// src/core/seed.ts
|
|
7772
|
+
var BUNDLE_DOORS = /* @__PURE__ */ new Set(["table_page_bundle", "record_page_bundle"]);
|
|
7773
|
+
function seedKey(door, args) {
|
|
7774
|
+
return `${door}|${canonicalArgs(args)}`;
|
|
7775
|
+
}
|
|
7776
|
+
function answersOf(door, args, data) {
|
|
7777
|
+
const out = [{ door, args, data }];
|
|
7778
|
+
if (!BUNDLE_DOORS.has(door) || !data || typeof data !== "object") return out;
|
|
7779
|
+
const parts = data.parts;
|
|
7780
|
+
if (!Array.isArray(parts)) return out;
|
|
7781
|
+
for (const part of parts) {
|
|
7782
|
+
if (part.error !== void 0 || part.data === void 0) continue;
|
|
7783
|
+
if (typeof part.door !== "string" || !part.args || typeof part.args !== "object") continue;
|
|
7784
|
+
out.push({ door: part.door, args: part.args, data: part.data });
|
|
7785
|
+
}
|
|
7786
|
+
return out;
|
|
7787
|
+
}
|
|
7788
|
+
function seedIndex(seed) {
|
|
7789
|
+
const index = /* @__PURE__ */ new Map();
|
|
7790
|
+
for (const a of seed.answers) {
|
|
7791
|
+
for (const spread of answersOf(a.door, a.args, a.data)) index.set(seedKey(spread.door, spread.args), spread.data);
|
|
7792
|
+
}
|
|
7793
|
+
return index;
|
|
7794
|
+
}
|
|
7795
|
+
var MISS = { code: "SEED_MISS", message: "Not in the page's seed.", details: null, hint: null };
|
|
7796
|
+
function missingQuery(onMiss) {
|
|
7797
|
+
const answer = () => {
|
|
7798
|
+
onMiss();
|
|
7799
|
+
return Promise.resolve({ data: null, error: MISS, count: null });
|
|
7800
|
+
};
|
|
7801
|
+
const chain = new Proxy(function() {
|
|
7802
|
+
}, {
|
|
7803
|
+
get(_target, prop) {
|
|
7804
|
+
if (prop === "then") return (ok2, bad) => answer().then(ok2, bad);
|
|
7805
|
+
return () => chain;
|
|
7806
|
+
},
|
|
7807
|
+
apply: () => chain
|
|
7808
|
+
});
|
|
7809
|
+
return { select: () => chain };
|
|
7810
|
+
}
|
|
7811
|
+
function seededDataSource(index) {
|
|
7812
|
+
let missed = false;
|
|
7813
|
+
const source = {
|
|
7814
|
+
rpc(fn, args) {
|
|
7815
|
+
const key = seedKey(fn, args);
|
|
7816
|
+
if (index.has(key)) return Promise.resolve({ data: index.get(key), error: null });
|
|
7817
|
+
missed = true;
|
|
7818
|
+
return Promise.resolve({ data: null, error: MISS });
|
|
7819
|
+
},
|
|
7820
|
+
schema: () => ({ from: () => missingQuery(() => missed = true) })
|
|
7821
|
+
};
|
|
7822
|
+
return { source, missed: () => missed };
|
|
7823
|
+
}
|
|
7824
|
+
|
|
7825
|
+
// src/react/seed.tsx
|
|
7826
|
+
var SEED_FRESH_MS = 3e4;
|
|
7827
|
+
var stores = /* @__PURE__ */ new WeakMap();
|
|
7828
|
+
var quiet = () => {
|
|
7829
|
+
};
|
|
7830
|
+
function storeFor(seed) {
|
|
7831
|
+
const held = stores.get(seed);
|
|
7832
|
+
if (held) return held;
|
|
7833
|
+
const index = seedIndex(seed);
|
|
7834
|
+
const runs = /* @__PURE__ */ new Map();
|
|
7835
|
+
const store = {
|
|
7836
|
+
live: true,
|
|
7837
|
+
run(slot, run, config) {
|
|
7838
|
+
const asked = runs.get(slot);
|
|
7839
|
+
if (asked) return asked;
|
|
7840
|
+
const { source, missed } = seededDataSource(index);
|
|
7841
|
+
const { realtime: _live, ...quietConfig } = config;
|
|
7842
|
+
const client = createRecordsClient({ ...quietConfig, dataSource: source, onError: quiet });
|
|
7843
|
+
const stale = typeof seed.at !== "number" || Date.now() - seed.at > SEED_FRESH_MS;
|
|
7844
|
+
const outcome = Promise.resolve().then(() => run(client)).then(
|
|
7845
|
+
(answer) => answer.ok && !missed() ? { seeded: true, data: answer.data, stale } : { seeded: false },
|
|
7846
|
+
() => ({ seeded: false })
|
|
7847
|
+
);
|
|
7848
|
+
runs.set(slot, outcome);
|
|
7849
|
+
return outcome;
|
|
7850
|
+
}
|
|
7851
|
+
};
|
|
7852
|
+
stores.set(seed, store);
|
|
7853
|
+
if (typeof window !== "undefined") {
|
|
7854
|
+
for (const a of seed.answers) {
|
|
7855
|
+
const org = a.args["p_organization_id"];
|
|
7856
|
+
if (typeof org !== "string") continue;
|
|
7857
|
+
if (a.door === "table_page_bundle" && typeof a.args["p_table_id"] === "string") {
|
|
7858
|
+
const view = a.args["p_view_id"];
|
|
7859
|
+
primeTablePageBundle({ organizationId: org, tableId: a.args["p_table_id"], viewId: typeof view === "string" ? view : null, answer: { data: a.data, error: null } });
|
|
7860
|
+
} else if (a.door === "record_page_bundle" && typeof a.args["p_record_id"] === "string") {
|
|
7861
|
+
primeRecordPageBundle({ organizationId: org, recordId: a.args["p_record_id"], answer: { data: a.data, error: null } });
|
|
7862
|
+
}
|
|
7863
|
+
}
|
|
7864
|
+
}
|
|
7865
|
+
return store;
|
|
7866
|
+
}
|
|
7867
|
+
var SeedContext = createContext2(null);
|
|
7868
|
+
function RecordsSeedProvider({ seed, children }) {
|
|
7869
|
+
const store = seed && Array.isArray(seed.answers) ? storeFor(seed) : null;
|
|
7870
|
+
useEffect(() => {
|
|
7871
|
+
if (store) store.live = false;
|
|
7872
|
+
}, [store]);
|
|
7873
|
+
return createElement2(SeedContext.Provider, { value: store }, children);
|
|
7874
|
+
}
|
|
7875
|
+
function useSeedStore() {
|
|
7876
|
+
const store = useContext2(SeedContext);
|
|
7877
|
+
return store && store.live ? store : null;
|
|
7878
|
+
}
|
|
7879
|
+
|
|
7880
|
+
// src/react/hold.tsx
|
|
7881
|
+
import { createContext as createContext3, createElement as createElement3, useContext as useContext3, useEffect as useEffect2 } from "react";
|
|
7882
|
+
var HoldContext = createContext3(null);
|
|
7758
7883
|
function RecordsHoldScope({ holdKey, children }) {
|
|
7759
|
-
return
|
|
7884
|
+
return createElement3(HoldContext.Provider, { value: holdKey }, children);
|
|
7760
7885
|
}
|
|
7761
7886
|
function useRecordsHold(holdKey) {
|
|
7762
|
-
|
|
7887
|
+
useEffect2(() => holdKey ? openHold(holdKey) : void 0, [holdKey]);
|
|
7763
7888
|
}
|
|
7764
7889
|
function useHoldKey() {
|
|
7765
|
-
return
|
|
7890
|
+
return useContext3(HoldContext);
|
|
7891
|
+
}
|
|
7892
|
+
|
|
7893
|
+
// src/react/pageOrder.ts
|
|
7894
|
+
function pageOrderOf(sort, narrowed) {
|
|
7895
|
+
return { sortFields: (sort ?? []).map((key) => key.field), narrowed };
|
|
7896
|
+
}
|
|
7897
|
+
var same = (a, b) => {
|
|
7898
|
+
if (a === b) return true;
|
|
7899
|
+
if ((a === null || a === void 0 || a === "") && (b === null || b === void 0 || b === "")) return true;
|
|
7900
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
7901
|
+
};
|
|
7902
|
+
function patchMovesRows(held, fresh, order) {
|
|
7903
|
+
if (order.sortFields.length === 0 && !order.narrowed) return false;
|
|
7904
|
+
for (const row of held) {
|
|
7905
|
+
const next = fresh.get(row.id);
|
|
7906
|
+
if (!next) continue;
|
|
7907
|
+
const was = row.document ?? {};
|
|
7908
|
+
const now = next.document ?? {};
|
|
7909
|
+
if (order.narrowed) {
|
|
7910
|
+
if (!same(was, now)) return true;
|
|
7911
|
+
continue;
|
|
7912
|
+
}
|
|
7913
|
+
for (const field2 of order.sortFields) if (!same(was[field2], now[field2])) return true;
|
|
7914
|
+
}
|
|
7915
|
+
return false;
|
|
7766
7916
|
}
|
|
7767
7917
|
|
|
7768
7918
|
// src/react/hooks.ts
|
|
@@ -7777,12 +7927,17 @@ function useAsync(run, key, live) {
|
|
|
7777
7927
|
);
|
|
7778
7928
|
entry.run = run;
|
|
7779
7929
|
entry.client = client;
|
|
7930
|
+
const seed = useSeedStore();
|
|
7931
|
+
if (seed && entry.snapshot.data === null && !entry.snapshot.error && !entry.started) {
|
|
7932
|
+
const outcome = use(seed.run(`${identityOf(client)}|${key}`, run, client.config));
|
|
7933
|
+
if (outcome.seeded) seedEntry(entry, outcome.data, outcome.stale);
|
|
7934
|
+
}
|
|
7780
7935
|
const snapshot = useSyncExternalStore(entry.subscribe, entry.getSnapshot, entry.getSnapshot);
|
|
7781
|
-
|
|
7936
|
+
useEffect3(() => {
|
|
7782
7937
|
acquireEntry(entry);
|
|
7783
7938
|
return () => releaseEntry(entry);
|
|
7784
7939
|
}, [entry]);
|
|
7785
|
-
|
|
7940
|
+
useEffect3(() => {
|
|
7786
7941
|
if (holdKey) pinToHold(holdKey, slot, entry);
|
|
7787
7942
|
}, [holdKey, slot, entry]);
|
|
7788
7943
|
const lastData = useRef2(null);
|
|
@@ -7792,25 +7947,33 @@ function useAsync(run, key, live) {
|
|
|
7792
7947
|
const setData = useCallback((update) => entry.setData(update), [entry]);
|
|
7793
7948
|
return { ...shown, reload, setData };
|
|
7794
7949
|
}
|
|
7950
|
+
function useSeededAnswer(key, run) {
|
|
7951
|
+
const client = useRecordsClient();
|
|
7952
|
+
const seed = useSeedStore();
|
|
7953
|
+
if (!seed || key === null) return void 0;
|
|
7954
|
+
const outcome = use(seed.run(`${identityOf(client)}|own:${key}`, run, client.config));
|
|
7955
|
+
return outcome.seeded ? outcome.data : void 0;
|
|
7956
|
+
}
|
|
7795
7957
|
function serverEntry(run, client) {
|
|
7796
|
-
const
|
|
7797
|
-
return {
|
|
7958
|
+
const entry = {
|
|
7798
7959
|
key: "server",
|
|
7799
|
-
snapshot,
|
|
7960
|
+
snapshot: { data: null, loading: true, error: null },
|
|
7800
7961
|
run,
|
|
7801
7962
|
client,
|
|
7802
7963
|
subscribe: () => () => {
|
|
7803
7964
|
},
|
|
7804
|
-
|
|
7965
|
+
// Read through the entry: a page seed may answer it during this render (`seedEntry`).
|
|
7966
|
+
getSnapshot: () => entry.snapshot,
|
|
7805
7967
|
refetch: () => {
|
|
7806
7968
|
},
|
|
7807
7969
|
setData: () => {
|
|
7808
7970
|
}
|
|
7809
7971
|
};
|
|
7972
|
+
return entry;
|
|
7810
7973
|
}
|
|
7811
7974
|
function useTable(tableId) {
|
|
7812
7975
|
const revision = useShapeRevision(tableId);
|
|
7813
|
-
|
|
7976
|
+
useEffect3(() => {
|
|
7814
7977
|
if (tableId) registerShapeInterest(tableId);
|
|
7815
7978
|
}, [tableId]);
|
|
7816
7979
|
return useAsync(
|
|
@@ -7872,7 +8035,7 @@ function useShapeRevision(tableId) {
|
|
|
7872
8035
|
}
|
|
7873
8036
|
function useFields(tableId, recordType) {
|
|
7874
8037
|
const revision = useShapeRevision(tableId);
|
|
7875
|
-
|
|
8038
|
+
useEffect3(() => {
|
|
7876
8039
|
if (tableId) registerShapeInterest(tableId);
|
|
7877
8040
|
}, [tableId]);
|
|
7878
8041
|
return useAsync(
|
|
@@ -7908,7 +8071,7 @@ function useReverseColumns(tableId) {
|
|
|
7908
8071
|
}
|
|
7909
8072
|
function useReverseLinks(tableId, columns, recordIds, limit = 3, offset = 0) {
|
|
7910
8073
|
const [writes, setWrites] = useState(0);
|
|
7911
|
-
|
|
8074
|
+
useEffect3(() => onRecordChanged(() => setWrites((n) => n + 1)), []);
|
|
7912
8075
|
const idsKey = recordIds.join(",");
|
|
7913
8076
|
const columnsKey = columns.map((c) => c.source_field_id).join(",");
|
|
7914
8077
|
return useAsync(
|
|
@@ -7935,7 +8098,7 @@ function useReverseLinks(tableId, columns, recordIds, limit = 3, offset = 0) {
|
|
|
7935
8098
|
tableId ? `reverse-links:${tableId}:${columnsKey}:${limit}:${offset}:${idsKey}:${writes}` : "reverse-links:none"
|
|
7936
8099
|
);
|
|
7937
8100
|
}
|
|
7938
|
-
function liveRowsFor(tableId) {
|
|
8101
|
+
function liveRowsFor(tableId, order = { sortFields: [], narrowed: false }) {
|
|
7939
8102
|
return (entry) => {
|
|
7940
8103
|
const client = entry.client;
|
|
7941
8104
|
const realtime = client.config.realtime;
|
|
@@ -7954,6 +8117,10 @@ function liveRowsFor(tableId) {
|
|
|
7954
8117
|
entry.refetch();
|
|
7955
8118
|
return;
|
|
7956
8119
|
}
|
|
8120
|
+
if (patchMovesRows(held, fresh, order)) {
|
|
8121
|
+
entry.refetch();
|
|
8122
|
+
return;
|
|
8123
|
+
}
|
|
7957
8124
|
entry.setData(
|
|
7958
8125
|
(current) => current === null ? current : {
|
|
7959
8126
|
...current,
|
|
@@ -8061,7 +8228,7 @@ function useRecords(tableId, options = {}) {
|
|
|
8061
8228
|
// on every render must not re-read the page on every render, and a parent
|
|
8062
8229
|
// that changes the question must re-read on the first one.
|
|
8063
8230
|
`records:${tableId ?? "none"}:${pageSize}:${page2}:${filterKey}:s${shape}`,
|
|
8064
|
-
liveRowsFor(tableId)
|
|
8231
|
+
liveRowsFor(tableId, pageOrderOf(void 0, filterKey !== "{}"))
|
|
8065
8232
|
);
|
|
8066
8233
|
const { live, liveReason } = liveStatus(useRecordsClient(), tableId);
|
|
8067
8234
|
return { ...useSharedRows(useKeptPage(tableId, base)), live, liveReason };
|
|
@@ -8089,14 +8256,14 @@ function useRecordPage(tableId, options = {}) {
|
|
|
8089
8256
|
return answered.ok ? { ok: true, data: { rows: answered.data.rows, total: answered.data.total, sortIgnored: answered.data.sort_ignored ?? [] } } : answered;
|
|
8090
8257
|
},
|
|
8091
8258
|
`page:${tableId ?? "none"}:${pageSize}:${page2}:${filterKey}:${search ?? ""}:${sortKey}:${viewId ?? ""}:s${shape}`,
|
|
8092
|
-
liveRowsFor(tableId)
|
|
8259
|
+
liveRowsFor(tableId, pageOrderOf(options.sort, filterKey !== "{}" || search !== null))
|
|
8093
8260
|
);
|
|
8094
8261
|
const { live, liveReason } = liveStatus(useRecordsClient(), tableId);
|
|
8095
8262
|
return { ...useSharedRows(useKeptPage(tableId, base)), live, liveReason };
|
|
8096
8263
|
}
|
|
8097
8264
|
function useRecordChangeRevision(recordId) {
|
|
8098
8265
|
const [revision, setRevision] = useState(0);
|
|
8099
|
-
|
|
8266
|
+
useEffect3(() => {
|
|
8100
8267
|
if (!recordId) return;
|
|
8101
8268
|
return onRecordChanged((changed) => {
|
|
8102
8269
|
if (changed === recordId) setRevision((n) => n + 1);
|
|
@@ -8467,7 +8634,7 @@ function useMergeField(key, state) {
|
|
|
8467
8634
|
const client = useRecordsClient();
|
|
8468
8635
|
const [resolution, setResolution] = useState(null);
|
|
8469
8636
|
const resolver = client.config.resolver;
|
|
8470
|
-
|
|
8637
|
+
useEffect3(() => {
|
|
8471
8638
|
if (!key) {
|
|
8472
8639
|
setResolution(null);
|
|
8473
8640
|
return;
|
|
@@ -8502,11 +8669,11 @@ function useMergeField(key, state) {
|
|
|
8502
8669
|
}
|
|
8503
8670
|
|
|
8504
8671
|
// src/react/entity-reference.ts
|
|
8505
|
-
import { useEffect as
|
|
8672
|
+
import { useEffect as useEffect4, useState as useState2 } from "react";
|
|
8506
8673
|
function useEntityReferenceKinds() {
|
|
8507
8674
|
const client = useRecordsClient();
|
|
8508
8675
|
const [state, setState] = useState2({ data: null, loading: true, error: null });
|
|
8509
|
-
|
|
8676
|
+
useEffect4(() => {
|
|
8510
8677
|
let live = true;
|
|
8511
8678
|
void entityReferenceKinds(client.config.dataSource).then((res) => {
|
|
8512
8679
|
if (!live) return;
|
|
@@ -8522,7 +8689,7 @@ function useEntityReferenceWords(refs) {
|
|
|
8522
8689
|
const client = useRecordsClient();
|
|
8523
8690
|
const key = refs.map((r) => `${r.token}:${r.id}`).join(",");
|
|
8524
8691
|
const [state, setState] = useState2({ data: null, loading: refs.length > 0, error: null });
|
|
8525
|
-
|
|
8692
|
+
useEffect4(() => {
|
|
8526
8693
|
let live = true;
|
|
8527
8694
|
void entityReferenceWords(client.config.dataSource, client.config.organizationId, refs).then((res) => {
|
|
8528
8695
|
if (!live) return;
|
|
@@ -8538,7 +8705,7 @@ function useEntityReferenceSearch(tokens, search, enabled = true) {
|
|
|
8538
8705
|
const client = useRecordsClient();
|
|
8539
8706
|
const key = `${tokens.join(",")}|${search.trim()}|${enabled ? 1 : 0}`;
|
|
8540
8707
|
const [state, setState] = useState2({ data: null, loading: enabled && tokens.length > 0, error: null });
|
|
8541
|
-
|
|
8708
|
+
useEffect4(() => {
|
|
8542
8709
|
if (!enabled || tokens.length === 0) {
|
|
8543
8710
|
setState({ data: [], loading: false, error: null });
|
|
8544
8711
|
return;
|
|
@@ -8560,7 +8727,7 @@ function useEntityReferenceSearch(tokens, search, enabled = true) {
|
|
|
8560
8727
|
}
|
|
8561
8728
|
|
|
8562
8729
|
// src/react/useAppTable.ts
|
|
8563
|
-
import { useCallback as useCallback2, useEffect as
|
|
8730
|
+
import { useCallback as useCallback2, useEffect as useEffect5, useRef as useRef3, useState as useState3 } from "react";
|
|
8564
8731
|
|
|
8565
8732
|
// src/core/declareTable.ts
|
|
8566
8733
|
function tokenFor(name) {
|
|
@@ -8864,7 +9031,7 @@ function useAppTable(def, options = {}) {
|
|
|
8864
9031
|
const [revision, setRevision] = useState3(0);
|
|
8865
9032
|
const rowsRef = useRef3([]);
|
|
8866
9033
|
rowsRef.current = rows;
|
|
8867
|
-
|
|
9034
|
+
useEffect5(() => {
|
|
8868
9035
|
let live = true;
|
|
8869
9036
|
setLoading(true);
|
|
8870
9037
|
(async () => {
|
|
@@ -8925,7 +9092,7 @@ function archivedTableOf(error) {
|
|
|
8925
9092
|
}
|
|
8926
9093
|
|
|
8927
9094
|
// src/react/useStoreTable.ts
|
|
8928
|
-
import { useEffect as
|
|
9095
|
+
import { useEffect as useEffect7, useMemo as useMemo4 } from "react";
|
|
8929
9096
|
|
|
8930
9097
|
// src/app-table/store-table.ts
|
|
8931
9098
|
function storeTable(def) {
|
|
@@ -10160,7 +10327,7 @@ function createTableDataPort({ client, aliases }) {
|
|
|
10160
10327
|
}
|
|
10161
10328
|
|
|
10162
10329
|
// src/data/react.tsx
|
|
10163
|
-
import { createContext as
|
|
10330
|
+
import { createContext as createContext4, createElement as createElement4, useContext as useContext4, useEffect as useEffect6, useMemo as useMemo3, useRef as useRef4 } from "react";
|
|
10164
10331
|
import {
|
|
10165
10332
|
QueryClient as QueryClientClass,
|
|
10166
10333
|
QueryClientContext,
|
|
@@ -10214,13 +10381,13 @@ function retryable(failureCount, thrown) {
|
|
|
10214
10381
|
const code = thrown instanceof DataRefusal ? thrown.error.code : "unreachable";
|
|
10215
10382
|
return (code === "unreachable" || code === "timed_out") && failureCount < 2;
|
|
10216
10383
|
}
|
|
10217
|
-
var DataPortContext =
|
|
10384
|
+
var DataPortContext = createContext4(null);
|
|
10218
10385
|
function hostEvents(port) {
|
|
10219
10386
|
return { on: (event, listener) => port.subscribe(event, listener) };
|
|
10220
10387
|
}
|
|
10221
10388
|
var warnedNotLive = false;
|
|
10222
10389
|
function useDataPort(scope) {
|
|
10223
|
-
const held =
|
|
10390
|
+
const held = useContext4(DataPortContext);
|
|
10224
10391
|
if (scope) return scope;
|
|
10225
10392
|
if (!held) {
|
|
10226
10393
|
throw new Error(
|
|
@@ -10506,7 +10673,7 @@ function acquireLive(qc, port, events, portKey, alias) {
|
|
|
10506
10673
|
}
|
|
10507
10674
|
var FALLBACK_KEY = /* @__PURE__ */ Symbol.for("@ai-matrx/records/data-query-client");
|
|
10508
10675
|
function useRecordsQueryClient() {
|
|
10509
|
-
const provided =
|
|
10676
|
+
const provided = useContext4(QueryClientContext);
|
|
10510
10677
|
if (provided) return provided;
|
|
10511
10678
|
const g = globalThis;
|
|
10512
10679
|
let held = g[FALLBACK_KEY];
|
|
@@ -10519,7 +10686,7 @@ function useRecordsQueryClient() {
|
|
|
10519
10686
|
function useLive(alias, scope) {
|
|
10520
10687
|
const qc = useRecordsQueryClient();
|
|
10521
10688
|
const { port, portKey, events } = useDataPort(scope);
|
|
10522
|
-
|
|
10689
|
+
useEffect6(() => {
|
|
10523
10690
|
if (!alias) return;
|
|
10524
10691
|
return acquireLive(qc, port, events, portKey, alias);
|
|
10525
10692
|
}, [qc, port, events, portKey, alias]);
|
|
@@ -10555,7 +10722,7 @@ function useDataRows(alias, query = {}, scope) {
|
|
|
10555
10722
|
const keyHash = hashKey(rowsKey);
|
|
10556
10723
|
const loaded = q.data?.pages.length ?? 0;
|
|
10557
10724
|
const { isFetching, hasNextPage, isFetchNextPageError, fetchNextPage } = q;
|
|
10558
|
-
|
|
10725
|
+
useEffect6(() => {
|
|
10559
10726
|
const w = want.current;
|
|
10560
10727
|
if (w.key !== keyHash || isFetching || loaded >= w.pages) return;
|
|
10561
10728
|
if (!hasNextPage || isFetchNextPageError) {
|
|
@@ -10732,7 +10899,7 @@ function useStoreTable(table, options = {}) {
|
|
|
10732
10899
|
const limit = Math.min(options.limit ?? STORE_ROWS_CEILING, STORE_ROWS_CEILING);
|
|
10733
10900
|
const read = useDataRows(alias, built.ok ? built.data : { pageSize: 1 }, scope);
|
|
10734
10901
|
const write = useDataMutations(alias, scope);
|
|
10735
|
-
|
|
10902
|
+
useEffect7(() => {
|
|
10736
10903
|
if (built.ok && read.hasMore && !read.loadingMore && !read.loading && !read.error && read.rows.length < limit) read.loadMore();
|
|
10737
10904
|
}, [built.ok, read.hasMore, read.loadingMore, read.loading, read.error, read.rows.length, limit, read]);
|
|
10738
10905
|
const rows = useMemo4(() => read.rows.slice(0, limit).filter((r) => r["_pending"] !== true).map((r) => toNamed(table, r)), [read.rows, limit, table]);
|
|
@@ -12203,6 +12370,8 @@ export {
|
|
|
12203
12370
|
RULE_USES,
|
|
12204
12371
|
RecordsHoldScope,
|
|
12205
12372
|
RecordsProvider,
|
|
12373
|
+
RecordsSeedProvider,
|
|
12374
|
+
SEED_FRESH_MS,
|
|
12206
12375
|
SHOWN_TO_LABEL,
|
|
12207
12376
|
SHOWN_TO_VALUES,
|
|
12208
12377
|
SHOWN_TO_WHO_MAY_CHANGE,
|
|
@@ -12394,6 +12563,7 @@ export {
|
|
|
12394
12563
|
useReverseColumns,
|
|
12395
12564
|
useReverseLinks,
|
|
12396
12565
|
useRowActions,
|
|
12566
|
+
useSeededAnswer,
|
|
12397
12567
|
useStoreTable,
|
|
12398
12568
|
useTable,
|
|
12399
12569
|
useTableArchive,
|