@ai-matrx/records 0.84.1 → 0.84.2
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 +6 -0
- package/dist/app-table/index.cjs +33 -0
- package/dist/app-table/index.cjs.map +1 -1
- package/dist/app-table/index.js +33 -0
- package/dist/app-table/index.js.map +1 -1
- package/dist/core/index.cjs +39 -0
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +7 -1
- package/dist/core/index.d.ts +7 -1
- package/dist/core/index.js +39 -0
- package/dist/core/index.js.map +1 -1
- package/dist/data/index.cjs +33 -0
- package/dist/data/index.cjs.map +1 -1
- package/dist/data/index.js +33 -0
- package/dist/data/index.js.map +1 -1
- package/dist/react/index.cjs +42 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +17 -1
- package/dist/react/index.d.ts +17 -1
- package/dist/react/index.js +42 -1
- package/dist/react/index.js.map +1 -1
- package/package.json +3 -3
package/dist/react/index.cjs
CHANGED
|
@@ -281,6 +281,7 @@ __export(react_exports, {
|
|
|
281
281
|
useRowActions: () => useRowActions,
|
|
282
282
|
useSeededAggregate: () => useSeededAggregate,
|
|
283
283
|
useSeededAnswer: () => useSeededAnswer,
|
|
284
|
+
useSeededAnswerAt: () => useSeededAnswerAt,
|
|
284
285
|
useSeededSource: () => useSeededSource,
|
|
285
286
|
useStoreTable: () => useStoreTable,
|
|
286
287
|
useTable: () => useTable,
|
|
@@ -321,6 +322,29 @@ function takePrimedTablePageBundle(organizationId, tableId, viewId) {
|
|
|
321
322
|
function primeRecordPageBundle(input) {
|
|
322
323
|
primeTablePageBundle({ organizationId: input.organizationId, tableId: `record:${input.recordId}`, answer: input.answer });
|
|
323
324
|
}
|
|
325
|
+
var DOOR_REGISTRY = /* @__PURE__ */ Symbol.for("@ai-matrx/records/primed-door-answers");
|
|
326
|
+
function doorRegistry() {
|
|
327
|
+
const g = globalThis;
|
|
328
|
+
return g[DOOR_REGISTRY] ??= /* @__PURE__ */ new Map();
|
|
329
|
+
}
|
|
330
|
+
var PRIMED_DOOR_TTL_MS = 1e4;
|
|
331
|
+
function primeDoorAnswer(key, data, at) {
|
|
332
|
+
doorRegistry().set(key, { data, at });
|
|
333
|
+
}
|
|
334
|
+
function takePrimedDoorAnswer(key) {
|
|
335
|
+
const registry2 = doorRegistry();
|
|
336
|
+
const held = registry2.get(key);
|
|
337
|
+
if (!held) return null;
|
|
338
|
+
if (Date.now() - held.at < PRIMED_DOOR_TTL_MS) return { data: held.data };
|
|
339
|
+
registry2.delete(key);
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
function dropPrimedDoorAnswers() {
|
|
343
|
+
doorRegistry().clear();
|
|
344
|
+
}
|
|
345
|
+
function isWritingDoor(door) {
|
|
346
|
+
return /(_declare|_set(_|$)|_update|_write|_delete|_restore|_archive|_upsert|_reparent|_change|_duplicate|_move|_decide|_run$|_submit|_publish|_import_|_start$|_complete|_sign$|_add$|_retire|_propose|_promote|_land$|_pin$|_mute|_snooze|_unsnooze|_clear|_unclear|_revoke|_issue|_bind|_unbind|_apply|_backfill|_sync$|_decorate|_designate|_ensure|^migrate_|^home_add|^capture_|^claim_|^record_stage|^anon_|^io_import_|^io_comment_resolve|^enrich_(declare|land|pin)|^field_(declare|duplicate|propose|restore|retire|update)|^table_(declare|ensure|from_example|move|sync)|^value_restore|^relation_own)/.test(door);
|
|
347
|
+
}
|
|
324
348
|
|
|
325
349
|
// src/core/recordChanges.ts
|
|
326
350
|
var listeners = /* @__PURE__ */ new Set();
|
|
@@ -4518,7 +4542,16 @@ function createRecordsClient(given) {
|
|
|
4518
4542
|
bundleAsked.delete(tableId);
|
|
4519
4543
|
for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
|
|
4520
4544
|
}
|
|
4545
|
+
function primedFor(door, args) {
|
|
4546
|
+
if (isWritingDoor(door)) {
|
|
4547
|
+
dropPrimedDoorAnswers();
|
|
4548
|
+
return null;
|
|
4549
|
+
}
|
|
4550
|
+
return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
|
|
4551
|
+
}
|
|
4521
4552
|
async function callDoor(door, args, where) {
|
|
4553
|
+
const primed = primedFor(door, args);
|
|
4554
|
+
if (primed) return ok(primed.data);
|
|
4522
4555
|
const bundled = await fromBundle(door, args);
|
|
4523
4556
|
if (bundled) return ok(bundled.data);
|
|
4524
4557
|
if (!doorReady(config, door)) {
|
|
@@ -4543,6 +4576,8 @@ function createRecordsClient(given) {
|
|
|
4543
4576
|
}
|
|
4544
4577
|
async function owedDoor(door, args, where) {
|
|
4545
4578
|
if (doorExists(door)) return callDoor(door, args, where);
|
|
4579
|
+
const primed = primedFor(door, args);
|
|
4580
|
+
if (primed) return ok(primed.data);
|
|
4546
4581
|
const response = await config.dataSource.rpc(door, args, { schema });
|
|
4547
4582
|
if (response.error) {
|
|
4548
4583
|
const code = response.error.code;
|
|
@@ -4608,6 +4643,8 @@ function createRecordsClient(given) {
|
|
|
4608
4643
|
return ok(response.data);
|
|
4609
4644
|
}
|
|
4610
4645
|
async function drillDoor(door, args, where) {
|
|
4646
|
+
const primed = primedFor(door, args);
|
|
4647
|
+
if (primed) return ok(primed.data);
|
|
4611
4648
|
const response = await config.dataSource.rpc(door, args, { schema: DRILL_SCHEMA });
|
|
4612
4649
|
if (response.error) {
|
|
4613
4650
|
const refusal3 = mapPgError(response.error, where);
|
|
@@ -8152,6 +8189,7 @@ function storeFor(seed) {
|
|
|
8152
8189
|
};
|
|
8153
8190
|
stores.set(seed, store);
|
|
8154
8191
|
if (typeof window !== "undefined") {
|
|
8192
|
+
for (const [key, data] of index) primeDoorAnswer(key, data, typeof seed.at === "number" ? seed.at : Date.now());
|
|
8155
8193
|
for (const a of seed.answers) {
|
|
8156
8194
|
const org = a.args["p_organization_id"];
|
|
8157
8195
|
if (typeof org !== "string") continue;
|
|
@@ -8255,11 +8293,14 @@ function useAsync(run, key, live) {
|
|
|
8255
8293
|
return { ...shown, reload, setData };
|
|
8256
8294
|
}
|
|
8257
8295
|
function useSeededAnswer(key, run) {
|
|
8296
|
+
return useSeededAnswerAt(key, run)?.data;
|
|
8297
|
+
}
|
|
8298
|
+
function useSeededAnswerAt(key, run) {
|
|
8258
8299
|
const client = useRecordsClient();
|
|
8259
8300
|
const seed = useSeedStore();
|
|
8260
8301
|
if (!seed || key === null) return void 0;
|
|
8261
8302
|
const outcome = (0, import_react4.use)(seed.run(`${identityOf(client)}|own:${key}`, run, client.config));
|
|
8262
|
-
return outcome.seeded ? outcome.data : void 0;
|
|
8303
|
+
return outcome.seeded ? { data: outcome.data, at: seed.at } : void 0;
|
|
8263
8304
|
}
|
|
8264
8305
|
function useSeededAggregate(tableId, spec) {
|
|
8265
8306
|
return useSeededAnswer(
|