@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.
@@ -244,6 +244,7 @@ __export(core_exports, {
244
244
  recordChangeTrigger: () => recordChangeTrigger,
245
245
  recordSourceKey: () => recordSourceKey,
246
246
  recordSourceTable: () => recordSourceTable,
247
+ recordingDataSource: () => recordingDataSource,
247
248
  recordsUseSentence: () => recordsUseSentence,
248
249
  rehomeSentence: () => rehomeSentence,
249
250
  relationNameIndexOf: () => relationNameIndexOf,
@@ -257,6 +258,9 @@ __export(core_exports, {
257
258
  safeLinkHref: () => safeLinkHref,
258
259
  sameDocument: () => sameDocument,
259
260
  scopeChip: () => scopeChip,
261
+ seedIndex: () => seedIndex,
262
+ seedKey: () => seedKey,
263
+ seededDataSource: () => seededDataSource,
260
264
  sheetSyncSpec: () => sheetSyncSpec,
261
265
  sourceArchivedOf: () => sourceArchivedOf,
262
266
  splitListCell: () => splitListCell,
@@ -10241,4 +10245,74 @@ function fromMatrix(matrix) {
10241
10245
  });
10242
10246
  return { headers, rows: rows2 };
10243
10247
  }
10248
+
10249
+ // src/core/seed.ts
10250
+ var BUNDLE_DOORS = /* @__PURE__ */ new Set(["table_page_bundle", "record_page_bundle"]);
10251
+ function seedKey(door, args) {
10252
+ return `${door}|${canonicalArgs(args)}`;
10253
+ }
10254
+ function answersOf(door, args, data) {
10255
+ const out = [{ door, args, data }];
10256
+ if (!BUNDLE_DOORS.has(door) || !data || typeof data !== "object") return out;
10257
+ const parts = data.parts;
10258
+ if (!Array.isArray(parts)) return out;
10259
+ for (const part of parts) {
10260
+ if (part.error !== void 0 || part.data === void 0) continue;
10261
+ if (typeof part.door !== "string" || !part.args || typeof part.args !== "object") continue;
10262
+ out.push({ door: part.door, args: part.args, data: part.data });
10263
+ }
10264
+ return out;
10265
+ }
10266
+ function recordingDataSource(source) {
10267
+ const kept = /* @__PURE__ */ new Map();
10268
+ const recording = {
10269
+ ...source.opensInOneCall ? { opensInOneCall: true } : {},
10270
+ rpc(fn, args, options) {
10271
+ return Promise.resolve(source.rpc(fn, args, options)).then((answer) => {
10272
+ if (!answer.error && (options?.schema ?? "custom") === "custom") {
10273
+ for (const a of answersOf(fn, args, answer.data)) kept.set(seedKey(a.door, a.args), a);
10274
+ }
10275
+ return answer;
10276
+ });
10277
+ },
10278
+ schema: (name) => source.schema(name)
10279
+ };
10280
+ return { source: recording, seed: () => ({ at: Date.now(), answers: [...kept.values()] }) };
10281
+ }
10282
+ function seedIndex(seed) {
10283
+ const index = /* @__PURE__ */ new Map();
10284
+ for (const a of seed.answers) {
10285
+ for (const spread of answersOf(a.door, a.args, a.data)) index.set(seedKey(spread.door, spread.args), spread.data);
10286
+ }
10287
+ return index;
10288
+ }
10289
+ var MISS = { code: "SEED_MISS", message: "Not in the page's seed.", details: null, hint: null };
10290
+ function missingQuery(onMiss) {
10291
+ const answer = () => {
10292
+ onMiss();
10293
+ return Promise.resolve({ data: null, error: MISS, count: null });
10294
+ };
10295
+ const chain = new Proxy(function() {
10296
+ }, {
10297
+ get(_target, prop) {
10298
+ if (prop === "then") return (ok2, bad) => answer().then(ok2, bad);
10299
+ return () => chain;
10300
+ },
10301
+ apply: () => chain
10302
+ });
10303
+ return { select: () => chain };
10304
+ }
10305
+ function seededDataSource(index) {
10306
+ let missed = false;
10307
+ const source = {
10308
+ rpc(fn, args) {
10309
+ const key = seedKey(fn, args);
10310
+ if (index.has(key)) return Promise.resolve({ data: index.get(key), error: null });
10311
+ missed = true;
10312
+ return Promise.resolve({ data: null, error: MISS });
10313
+ },
10314
+ schema: () => ({ from: () => missingQuery(() => missed = true) })
10315
+ };
10316
+ return { source, missed: () => missed };
10317
+ }
10244
10318
  //# sourceMappingURL=index.cjs.map