@ai-matrx/records 0.84.3 → 0.84.5

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.
@@ -337,6 +337,12 @@ declare function doorCensus(): {
337
337
  type Listener = (recordId: string) => void;
338
338
  /** Called by the client after a write door answered yes. */
339
339
  declare function announceRecordChanged(recordId: string): void;
340
+ /** Called by the client after `record_delete` answered yes (before it announces the change). */
341
+ declare function markRecordRemoved(recordId: string): void;
342
+ /** Called by the client after `record_restore` answered yes (before it announces the change). */
343
+ declare function markRecordRestored(recordId: string): void;
344
+ /** Whether this page archived the record and has not brought it back. */
345
+ declare function isRecordRemoved(recordId: string): boolean;
340
346
  /** Hear every record this page writes. Returns the unsubscribe. */
341
347
  declare function onRecordChanged(listener: Listener): () => void;
342
348
  type TableListener = (tableId: string | null) => void;
@@ -722,4 +728,4 @@ declare function seededDataSource(index: Map<string, unknown>): {
722
728
  missed: () => boolean;
723
729
  };
724
730
 
725
- 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 };
731
+ 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, isRecordRemoved, landingOutcomesFor, mapPgError, markRecordRemoved, markRecordRestored, 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 };
@@ -337,6 +337,12 @@ declare function doorCensus(): {
337
337
  type Listener = (recordId: string) => void;
338
338
  /** Called by the client after a write door answered yes. */
339
339
  declare function announceRecordChanged(recordId: string): void;
340
+ /** Called by the client after `record_delete` answered yes (before it announces the change). */
341
+ declare function markRecordRemoved(recordId: string): void;
342
+ /** Called by the client after `record_restore` answered yes (before it announces the change). */
343
+ declare function markRecordRestored(recordId: string): void;
344
+ /** Whether this page archived the record and has not brought it back. */
345
+ declare function isRecordRemoved(recordId: string): boolean;
340
346
  /** Hear every record this page writes. Returns the unsubscribe. */
341
347
  declare function onRecordChanged(listener: Listener): () => void;
342
348
  type TableListener = (tableId: string | null) => void;
@@ -722,4 +728,4 @@ declare function seededDataSource(index: Map<string, unknown>): {
722
728
  missed: () => boolean;
723
729
  };
724
730
 
725
- 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 };
731
+ 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, isRecordRemoved, landingOutcomesFor, mapPgError, markRecordRemoved, markRecordRestored, 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 };
@@ -4922,6 +4922,16 @@ function announceRecordChanged(recordId) {
4922
4922
  }
4923
4923
  }
4924
4924
  }
4925
+ var removed = /* @__PURE__ */ new Set();
4926
+ function markRecordRemoved(recordId) {
4927
+ removed.add(recordId);
4928
+ }
4929
+ function markRecordRestored(recordId) {
4930
+ removed.delete(recordId);
4931
+ }
4932
+ function isRecordRemoved(recordId) {
4933
+ return removed.has(recordId);
4934
+ }
4925
4935
  function onRecordChanged(listener) {
4926
4936
  listeners.add(listener);
4927
4937
  return () => listeners.delete(listener);
@@ -5993,6 +6003,7 @@ function createRecordsClient(given) {
5993
6003
  }
5994
6004
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
5995
6005
  }
6006
+ const readsInFlight = /* @__PURE__ */ new Map();
5996
6007
  async function callDoor(door, args, where) {
5997
6008
  const primed = primedFor(door, args);
5998
6009
  if (primed) return ok(primed.data);
@@ -6003,7 +6014,19 @@ function createRecordsClient(given) {
6003
6014
  scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });
6004
6015
  return err(refusal);
6005
6016
  }
6006
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
6017
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
6018
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
6019
+ const response = await (flying ?? (() => {
6020
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
6021
+ if (flightKey) {
6022
+ readsInFlight.set(flightKey, call);
6023
+ const forget = () => {
6024
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
6025
+ };
6026
+ call.then(forget, forget);
6027
+ }
6028
+ return call;
6029
+ })());
6007
6030
  if (response.error) {
6008
6031
  const refusal = mapPgError(response.error, where);
6009
6032
  scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });
@@ -6313,7 +6336,10 @@ function createRecordsClient(given) {
6313
6336
  { p_organization_id: org, p_record_id: record_id },
6314
6337
  "recordDelete"
6315
6338
  );
6316
- if (result.ok) announceRecordChanged(record_id);
6339
+ if (result.ok) {
6340
+ markRecordRemoved(record_id);
6341
+ announceRecordChanged(record_id);
6342
+ }
6317
6343
  return result;
6318
6344
  },
6319
6345
  async recordRestore({ record_id }) {
@@ -6322,7 +6348,10 @@ function createRecordsClient(given) {
6322
6348
  { p_organization_id: org, p_record_id: record_id },
6323
6349
  "recordRestore"
6324
6350
  );
6325
- if (result.ok) announceRecordChanged(record_id);
6351
+ if (result.ok) {
6352
+ markRecordRestored(record_id);
6353
+ announceRecordChanged(record_id);
6354
+ }
6326
6355
  return result;
6327
6356
  },
6328
6357
  async tableArchive({ table_id, chunk, includeTable }) {
@@ -9391,8 +9420,8 @@ async function declareTable(client, spec) {
9391
9420
  return { ok: true, data: table.data, homeId: home.data };
9392
9421
  }
9393
9422
  async function undo(client, tableId, homeId, name, refusal) {
9394
- const removed = await client.recordDelete({ record_id: tableId });
9395
- if (removed.ok) {
9423
+ const removed2 = await client.recordDelete({ record_id: tableId });
9424
+ if (removed2.ok) {
9396
9425
  await client.recordDelete({ record_id: homeId });
9397
9426
  return { ok: false, error: refusal };
9398
9427
  }
@@ -10250,6 +10279,7 @@ export {
10250
10279
  isPersonStamp,
10251
10280
  isPortalAccent,
10252
10281
  isPortalArchiveFilter,
10282
+ isRecordRemoved,
10253
10283
  isRecordsErr,
10254
10284
  isRuleFilter,
10255
10285
  isShownTo,
@@ -10263,6 +10293,8 @@ export {
10263
10293
  localeDateOrder,
10264
10294
  looksLikeAnId,
10265
10295
  mapPgError,
10296
+ markRecordRemoved,
10297
+ markRecordRestored,
10266
10298
  mayDrag,
10267
10299
  measureKey,
10268
10300
  memoryStore,