@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.
@@ -498,6 +498,12 @@ declare function primeRecordPageBundle(input: {
498
498
  recordId: string;
499
499
  answer: Promise<PrimedBundleAnswer> | PrimedBundleAnswer;
500
500
  }): void;
501
+ /** How long a primed door answer stays servable, counted from when the server asked. */
502
+ declare const PRIMED_DOOR_TTL_MS = 10000;
503
+ /** Keep one door's answer (`key` = door name + canonical arguments, as `seedKey` builds it). */
504
+ declare function primeDoorAnswer(key: string, data: unknown, at: number): void;
505
+ /** A write happened: nothing primed is trusted any more. */
506
+ declare function dropPrimedDoorAnswers(): void;
501
507
 
502
508
  /**
503
509
  * The structural shape of the supabase client this adapter needs. Deliberately
@@ -713,4 +719,4 @@ declare function seededDataSource(index: Map<string, unknown>): {
713
719
  missed: () => boolean;
714
720
  };
715
721
 
716
- export { type BlockOutcome, DEFAULT_DOCUMENT_MAX_BYTES, DEFAULT_VALUE_MAX_BYTES, DOORS, type DoorKey, type ExportRow, Field, LANDING_SOURCE_TYPE, LANDING_TARGET_TYPES, type Landing, type LandingBlock, type LandingOutcomes, type LandingState, type LandingStore, MAPPED_SQLSTATES, type MirrorLimits, OUTPUT_KEPT_KEY, PRODUCED_BY_LABEL, type ParsedImport, PgError, PredictedRefusal, type PrimedBundleAnswer, type ReadFileText, ReadValue, RecordDocument, RecordsDataSource, RecordsError, RecordsResult, type RecordsSeed, type RecordsSeedAnswer, StaleWriteDetail, type SupabaseLike, TableKindFacts, Uuid, WHOLE_VALUE_SOURCE_KIND, type WholeValuePointer, announceRecordChanged, announceTableStructureChanged, asRecordsDataSource, blockLandedInStore, cellText, doorAbsent, doorCensus, doorExists, doorReady, exportCellText, exportCsv, exportXlsx, forgetPrimedTablePageBundles, importCsv, importXlsx, landingOutcomesFor, mapPgError, onRecordChanged, onTableStructureChanged, outcomeForBlock, outputIsKept, parseCsv, predictEnvelopeRefusal, predictSizeRefusal, predictValueRefusals, predictWriteRefusals, primeRecordPageBundle, primeTablePageBundle, recordingDataSource, seedIndex, seedKey, seededDataSource, staleWriteDetail, supabaseDataSource, tableKindFacts, takePrimedTablePageBundle, toAoa, valuesAreUnconfirmed, wholeValueNotRead, wholeValueOf, wholeValueOfRead, wholeValueSize, withWholeValues };
722
+ export { type BlockOutcome, DEFAULT_DOCUMENT_MAX_BYTES, DEFAULT_VALUE_MAX_BYTES, DOORS, type DoorKey, type ExportRow, Field, LANDING_SOURCE_TYPE, LANDING_TARGET_TYPES, type Landing, type LandingBlock, type LandingOutcomes, type LandingState, type LandingStore, MAPPED_SQLSTATES, type MirrorLimits, OUTPUT_KEPT_KEY, PRIMED_DOOR_TTL_MS, PRODUCED_BY_LABEL, type ParsedImport, PgError, PredictedRefusal, type PrimedBundleAnswer, type ReadFileText, ReadValue, RecordDocument, RecordsDataSource, RecordsError, RecordsResult, type RecordsSeed, type RecordsSeedAnswer, StaleWriteDetail, type SupabaseLike, TableKindFacts, Uuid, WHOLE_VALUE_SOURCE_KIND, type WholeValuePointer, announceRecordChanged, announceTableStructureChanged, asRecordsDataSource, blockLandedInStore, cellText, doorAbsent, doorCensus, doorExists, doorReady, dropPrimedDoorAnswers, exportCellText, exportCsv, exportXlsx, forgetPrimedTablePageBundles, importCsv, importXlsx, landingOutcomesFor, mapPgError, onRecordChanged, onTableStructureChanged, outcomeForBlock, outputIsKept, parseCsv, predictEnvelopeRefusal, predictSizeRefusal, predictValueRefusals, predictWriteRefusals, primeDoorAnswer, primeRecordPageBundle, primeTablePageBundle, recordingDataSource, seedIndex, seedKey, seededDataSource, staleWriteDetail, supabaseDataSource, tableKindFacts, takePrimedTablePageBundle, toAoa, valuesAreUnconfirmed, wholeValueNotRead, wholeValueOf, wholeValueOfRead, wholeValueSize, withWholeValues };
@@ -498,6 +498,12 @@ declare function primeRecordPageBundle(input: {
498
498
  recordId: string;
499
499
  answer: Promise<PrimedBundleAnswer> | PrimedBundleAnswer;
500
500
  }): void;
501
+ /** How long a primed door answer stays servable, counted from when the server asked. */
502
+ declare const PRIMED_DOOR_TTL_MS = 10000;
503
+ /** Keep one door's answer (`key` = door name + canonical arguments, as `seedKey` builds it). */
504
+ declare function primeDoorAnswer(key: string, data: unknown, at: number): void;
505
+ /** A write happened: nothing primed is trusted any more. */
506
+ declare function dropPrimedDoorAnswers(): void;
501
507
 
502
508
  /**
503
509
  * The structural shape of the supabase client this adapter needs. Deliberately
@@ -713,4 +719,4 @@ declare function seededDataSource(index: Map<string, unknown>): {
713
719
  missed: () => boolean;
714
720
  };
715
721
 
716
- export { type BlockOutcome, DEFAULT_DOCUMENT_MAX_BYTES, DEFAULT_VALUE_MAX_BYTES, DOORS, type DoorKey, type ExportRow, Field, LANDING_SOURCE_TYPE, LANDING_TARGET_TYPES, type Landing, type LandingBlock, type LandingOutcomes, type LandingState, type LandingStore, MAPPED_SQLSTATES, type MirrorLimits, OUTPUT_KEPT_KEY, PRODUCED_BY_LABEL, type ParsedImport, PgError, PredictedRefusal, type PrimedBundleAnswer, type ReadFileText, ReadValue, RecordDocument, RecordsDataSource, RecordsError, RecordsResult, type RecordsSeed, type RecordsSeedAnswer, StaleWriteDetail, type SupabaseLike, TableKindFacts, Uuid, WHOLE_VALUE_SOURCE_KIND, type WholeValuePointer, announceRecordChanged, announceTableStructureChanged, asRecordsDataSource, blockLandedInStore, cellText, doorAbsent, doorCensus, doorExists, doorReady, exportCellText, exportCsv, exportXlsx, forgetPrimedTablePageBundles, importCsv, importXlsx, landingOutcomesFor, mapPgError, onRecordChanged, onTableStructureChanged, outcomeForBlock, outputIsKept, parseCsv, predictEnvelopeRefusal, predictSizeRefusal, predictValueRefusals, predictWriteRefusals, primeRecordPageBundle, primeTablePageBundle, recordingDataSource, seedIndex, seedKey, seededDataSource, staleWriteDetail, supabaseDataSource, tableKindFacts, takePrimedTablePageBundle, toAoa, valuesAreUnconfirmed, wholeValueNotRead, wholeValueOf, wholeValueOfRead, wholeValueSize, withWholeValues };
722
+ export { type BlockOutcome, DEFAULT_DOCUMENT_MAX_BYTES, DEFAULT_VALUE_MAX_BYTES, DOORS, type DoorKey, type ExportRow, Field, LANDING_SOURCE_TYPE, LANDING_TARGET_TYPES, type Landing, type LandingBlock, type LandingOutcomes, type LandingState, type LandingStore, MAPPED_SQLSTATES, type MirrorLimits, OUTPUT_KEPT_KEY, PRIMED_DOOR_TTL_MS, PRODUCED_BY_LABEL, type ParsedImport, PgError, PredictedRefusal, type PrimedBundleAnswer, type ReadFileText, ReadValue, RecordDocument, RecordsDataSource, RecordsError, RecordsResult, type RecordsSeed, type RecordsSeedAnswer, StaleWriteDetail, type SupabaseLike, TableKindFacts, Uuid, WHOLE_VALUE_SOURCE_KIND, type WholeValuePointer, announceRecordChanged, announceTableStructureChanged, asRecordsDataSource, blockLandedInStore, cellText, doorAbsent, doorCensus, doorExists, doorReady, dropPrimedDoorAnswers, exportCellText, exportCsv, exportXlsx, forgetPrimedTablePageBundles, importCsv, importXlsx, landingOutcomesFor, mapPgError, onRecordChanged, onTableStructureChanged, outcomeForBlock, outputIsKept, parseCsv, predictEnvelopeRefusal, predictSizeRefusal, predictValueRefusals, predictWriteRefusals, primeDoorAnswer, primeRecordPageBundle, primeTablePageBundle, recordingDataSource, seedIndex, seedKey, seededDataSource, staleWriteDetail, supabaseDataSource, tableKindFacts, takePrimedTablePageBundle, toAoa, valuesAreUnconfirmed, wholeValueNotRead, wholeValueOf, wholeValueOfRead, wholeValueSize, withWholeValues };
@@ -4876,6 +4876,29 @@ function forgetPrimedTablePageBundles() {
4876
4876
  function primeRecordPageBundle(input) {
4877
4877
  primeTablePageBundle({ organizationId: input.organizationId, tableId: `record:${input.recordId}`, answer: input.answer });
4878
4878
  }
4879
+ var DOOR_REGISTRY = /* @__PURE__ */ Symbol.for("@ai-matrx/records/primed-door-answers");
4880
+ function doorRegistry() {
4881
+ const g = globalThis;
4882
+ return g[DOOR_REGISTRY] ??= /* @__PURE__ */ new Map();
4883
+ }
4884
+ var PRIMED_DOOR_TTL_MS = 1e4;
4885
+ function primeDoorAnswer(key, data, at) {
4886
+ doorRegistry().set(key, { data, at });
4887
+ }
4888
+ function takePrimedDoorAnswer(key) {
4889
+ const registry2 = doorRegistry();
4890
+ const held = registry2.get(key);
4891
+ if (!held) return null;
4892
+ if (Date.now() - held.at < PRIMED_DOOR_TTL_MS) return { data: held.data };
4893
+ registry2.delete(key);
4894
+ return null;
4895
+ }
4896
+ function dropPrimedDoorAnswers() {
4897
+ doorRegistry().clear();
4898
+ }
4899
+ function isWritingDoor(door) {
4900
+ 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);
4901
+ }
4879
4902
 
4880
4903
  // src/core/recordChanges.ts
4881
4904
  var listeners = /* @__PURE__ */ new Set();
@@ -5947,7 +5970,16 @@ function createRecordsClient(given) {
5947
5970
  bundleAsked.delete(tableId);
5948
5971
  for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
5949
5972
  }
5973
+ function primedFor(door, args) {
5974
+ if (isWritingDoor(door)) {
5975
+ dropPrimedDoorAnswers();
5976
+ return null;
5977
+ }
5978
+ return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
5979
+ }
5950
5980
  async function callDoor(door, args, where) {
5981
+ const primed = primedFor(door, args);
5982
+ if (primed) return ok(primed.data);
5951
5983
  const bundled = await fromBundle(door, args);
5952
5984
  if (bundled) return ok(bundled.data);
5953
5985
  if (!doorReady(config, door)) {
@@ -5972,6 +6004,8 @@ function createRecordsClient(given) {
5972
6004
  }
5973
6005
  async function owedDoor(door, args, where) {
5974
6006
  if (doorExists(door)) return callDoor(door, args, where);
6007
+ const primed = primedFor(door, args);
6008
+ if (primed) return ok(primed.data);
5975
6009
  const response = await config.dataSource.rpc(door, args, { schema });
5976
6010
  if (response.error) {
5977
6011
  const code = response.error.code;
@@ -6037,6 +6071,8 @@ function createRecordsClient(given) {
6037
6071
  return ok(response.data);
6038
6072
  }
6039
6073
  async function drillDoor(door, args, where) {
6074
+ const primed = primedFor(door, args);
6075
+ if (primed) return ok(primed.data);
6040
6076
  const response = await config.dataSource.rpc(door, args, { schema: DRILL_SCHEMA });
6041
6077
  if (response.error) {
6042
6078
  const refusal = mapPgError(response.error, where);
@@ -10094,6 +10130,7 @@ export {
10094
10130
  PIPELINE_RULE_KINDS,
10095
10131
  PORTAL_ACCENTS,
10096
10132
  PORTAL_ARCHIVE_FILTERS,
10133
+ PRIMED_DOOR_TTL_MS,
10097
10134
  PRODUCED_BY_LABEL,
10098
10135
  REFUSALS_WORTH_REPEATING,
10099
10136
  RELATION_BINDINGS,
@@ -10159,6 +10196,7 @@ export {
10159
10196
  doorReady,
10160
10197
  drillAnswerOf,
10161
10198
  drillFindingKnob,
10199
+ dropPrimedDoorAnswers,
10162
10200
  durationText,
10163
10201
  emptyArchiveLine,
10164
10202
  emptyPortalArchiveLine,
@@ -10247,6 +10285,7 @@ export {
10247
10285
  predictWriteRefusals,
10248
10286
  previewRetype,
10249
10287
  previewRuleChange,
10288
+ primeDoorAnswer,
10250
10289
  primeRecordPageBundle,
10251
10290
  primeTablePageBundle,
10252
10291
  publicFormPath,