@ai-matrx/records 0.84.2 → 0.84.4

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.
@@ -5193,9 +5193,20 @@ function takePrimedDoorAnswer(key) {
5193
5193
  registry2.delete(key);
5194
5194
  return null;
5195
5195
  }
5196
- function dropPrimedDoorAnswers() {
5197
- doorRegistry().clear();
5196
+ function dropPrimedDoorAnswers(doors) {
5197
+ const registry2 = doorRegistry();
5198
+ if (!doors) {
5199
+ registry2.clear();
5200
+ return;
5201
+ }
5202
+ for (const key of [...registry2.keys()]) if (doors.some((door) => key.startsWith(`${door}|`))) registry2.delete(key);
5198
5203
  }
5204
+ var LOOK_WRITES = {
5205
+ view_declare: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
5206
+ view_designate: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
5207
+ view_look_set: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
5208
+ view_record_order_set: ["views", "view_look_read", "grid_layout", "table_page_bundle"]
5209
+ };
5199
5210
  function isWritingDoor(door) {
5200
5211
  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
5212
  }
@@ -6271,12 +6282,18 @@ function createRecordsClient(given) {
6271
6282
  for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
6272
6283
  }
6273
6284
  function primedFor(door, args) {
6285
+ const look = LOOK_WRITES[door];
6286
+ if (look) {
6287
+ dropPrimedDoorAnswers(look);
6288
+ return null;
6289
+ }
6274
6290
  if (isWritingDoor(door)) {
6275
6291
  dropPrimedDoorAnswers();
6276
6292
  return null;
6277
6293
  }
6278
6294
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
6279
6295
  }
6296
+ const readsInFlight = /* @__PURE__ */ new Map();
6280
6297
  async function callDoor(door, args, where) {
6281
6298
  const primed = primedFor(door, args);
6282
6299
  if (primed) return ok(primed.data);
@@ -6287,7 +6304,19 @@ function createRecordsClient(given) {
6287
6304
  scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });
6288
6305
  return err(refusal);
6289
6306
  }
6290
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
6307
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
6308
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
6309
+ const response = await (flying ?? (() => {
6310
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
6311
+ if (flightKey) {
6312
+ readsInFlight.set(flightKey, call);
6313
+ const forget = () => {
6314
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
6315
+ };
6316
+ call.then(forget, forget);
6317
+ }
6318
+ return call;
6319
+ })());
6291
6320
  if (response.error) {
6292
6321
  const refusal = mapPgError(response.error, where);
6293
6322
  scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });