@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.
@@ -283,6 +283,13 @@ function announceRecordChanged(recordId) {
283
283
  }
284
284
  }
285
285
  }
286
+ var removed = /* @__PURE__ */ new Set();
287
+ function markRecordRemoved(recordId) {
288
+ removed.add(recordId);
289
+ }
290
+ function markRecordRestored(recordId) {
291
+ removed.delete(recordId);
292
+ }
286
293
  function onRecordChanged(listener) {
287
294
  listeners.add(listener);
288
295
  return () => listeners.delete(listener);
@@ -2779,6 +2786,7 @@ function createRecordsClient(given) {
2779
2786
  }
2780
2787
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
2781
2788
  }
2789
+ const readsInFlight = /* @__PURE__ */ new Map();
2782
2790
  async function callDoor(door, args, where) {
2783
2791
  const primed = primedFor(door, args);
2784
2792
  if (primed) return ok(primed.data);
@@ -2789,7 +2797,19 @@ function createRecordsClient(given) {
2789
2797
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
2790
2798
  return err(refusal2);
2791
2799
  }
2792
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
2800
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
2801
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
2802
+ const response = await (flying ?? (() => {
2803
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
2804
+ if (flightKey) {
2805
+ readsInFlight.set(flightKey, call);
2806
+ const forget = () => {
2807
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
2808
+ };
2809
+ call.then(forget, forget);
2810
+ }
2811
+ return call;
2812
+ })());
2793
2813
  if (response.error) {
2794
2814
  const refusal2 = mapPgError(response.error, where);
2795
2815
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
@@ -3099,7 +3119,10 @@ function createRecordsClient(given) {
3099
3119
  { p_organization_id: org, p_record_id: record_id },
3100
3120
  "recordDelete"
3101
3121
  );
3102
- if (result.ok) announceRecordChanged(record_id);
3122
+ if (result.ok) {
3123
+ markRecordRemoved(record_id);
3124
+ announceRecordChanged(record_id);
3125
+ }
3103
3126
  return result;
3104
3127
  },
3105
3128
  async recordRestore({ record_id }) {
@@ -3108,7 +3131,10 @@ function createRecordsClient(given) {
3108
3131
  { p_organization_id: org, p_record_id: record_id },
3109
3132
  "recordRestore"
3110
3133
  );
3111
- if (result.ok) announceRecordChanged(record_id);
3134
+ if (result.ok) {
3135
+ markRecordRestored(record_id);
3136
+ announceRecordChanged(record_id);
3137
+ }
3112
3138
  return result;
3113
3139
  },
3114
3140
  async tableArchive({ table_id, chunk, includeTable }) {