@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.
@@ -79,6 +79,7 @@ __export(core_exports, {
79
79
  PIPELINE_RULE_KINDS: () => PIPELINE_RULE_KINDS,
80
80
  PORTAL_ACCENTS: () => PORTAL_ACCENTS,
81
81
  PORTAL_ARCHIVE_FILTERS: () => PORTAL_ARCHIVE_FILTERS,
82
+ PRIMED_DOOR_TTL_MS: () => PRIMED_DOOR_TTL_MS,
82
83
  PRODUCED_BY_LABEL: () => PRODUCED_BY_LABEL,
83
84
  REFUSALS_WORTH_REPEATING: () => REFUSALS_WORTH_REPEATING,
84
85
  RELATION_BINDINGS: () => RELATION_BINDINGS,
@@ -144,6 +145,7 @@ __export(core_exports, {
144
145
  doorReady: () => doorReady,
145
146
  drillAnswerOf: () => drillAnswerOf,
146
147
  drillFindingKnob: () => drillFindingKnob,
148
+ dropPrimedDoorAnswers: () => dropPrimedDoorAnswers,
147
149
  durationText: () => durationText,
148
150
  emptyArchiveLine: () => emptyArchiveLine,
149
151
  emptyPortalArchiveLine: () => emptyPortalArchiveLine,
@@ -232,6 +234,7 @@ __export(core_exports, {
232
234
  predictWriteRefusals: () => predictWriteRefusals,
233
235
  previewRetype: () => previewRetype,
234
236
  previewRuleChange: () => previewRuleChange,
237
+ primeDoorAnswer: () => primeDoorAnswer,
235
238
  primeRecordPageBundle: () => primeRecordPageBundle,
236
239
  primeTablePageBundle: () => primeTablePageBundle,
237
240
  publicFormPath: () => publicFormPath,
@@ -5173,6 +5176,29 @@ function forgetPrimedTablePageBundles() {
5173
5176
  function primeRecordPageBundle(input) {
5174
5177
  primeTablePageBundle({ organizationId: input.organizationId, tableId: `record:${input.recordId}`, answer: input.answer });
5175
5178
  }
5179
+ var DOOR_REGISTRY = /* @__PURE__ */ Symbol.for("@ai-matrx/records/primed-door-answers");
5180
+ function doorRegistry() {
5181
+ const g = globalThis;
5182
+ return g[DOOR_REGISTRY] ??= /* @__PURE__ */ new Map();
5183
+ }
5184
+ var PRIMED_DOOR_TTL_MS = 1e4;
5185
+ function primeDoorAnswer(key, data, at) {
5186
+ doorRegistry().set(key, { data, at });
5187
+ }
5188
+ function takePrimedDoorAnswer(key) {
5189
+ const registry2 = doorRegistry();
5190
+ const held = registry2.get(key);
5191
+ if (!held) return null;
5192
+ if (Date.now() - held.at < PRIMED_DOOR_TTL_MS) return { data: held.data };
5193
+ registry2.delete(key);
5194
+ return null;
5195
+ }
5196
+ function dropPrimedDoorAnswers() {
5197
+ doorRegistry().clear();
5198
+ }
5199
+ function isWritingDoor(door) {
5200
+ 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);
5201
+ }
5176
5202
 
5177
5203
  // src/core/recordChanges.ts
5178
5204
  var listeners = /* @__PURE__ */ new Set();
@@ -6244,7 +6270,16 @@ function createRecordsClient(given) {
6244
6270
  bundleAsked.delete(tableId);
6245
6271
  for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
6246
6272
  }
6273
+ function primedFor(door, args) {
6274
+ if (isWritingDoor(door)) {
6275
+ dropPrimedDoorAnswers();
6276
+ return null;
6277
+ }
6278
+ return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
6279
+ }
6247
6280
  async function callDoor(door, args, where) {
6281
+ const primed = primedFor(door, args);
6282
+ if (primed) return ok(primed.data);
6248
6283
  const bundled = await fromBundle(door, args);
6249
6284
  if (bundled) return ok(bundled.data);
6250
6285
  if (!doorReady(config, door)) {
@@ -6269,6 +6304,8 @@ function createRecordsClient(given) {
6269
6304
  }
6270
6305
  async function owedDoor(door, args, where) {
6271
6306
  if (doorExists(door)) return callDoor(door, args, where);
6307
+ const primed = primedFor(door, args);
6308
+ if (primed) return ok(primed.data);
6272
6309
  const response = await config.dataSource.rpc(door, args, { schema });
6273
6310
  if (response.error) {
6274
6311
  const code = response.error.code;
@@ -6334,6 +6371,8 @@ function createRecordsClient(given) {
6334
6371
  return ok(response.data);
6335
6372
  }
6336
6373
  async function drillDoor(door, args, where) {
6374
+ const primed = primedFor(door, args);
6375
+ if (primed) return ok(primed.data);
6337
6376
  const response = await config.dataSource.rpc(door, args, { schema: DRILL_SCHEMA });
6338
6377
  if (response.error) {
6339
6378
  const refusal = mapPgError(response.error, where);