@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.
@@ -419,6 +419,13 @@ function announceRecordChanged(recordId) {
419
419
  }
420
420
  }
421
421
  }
422
+ var removed = /* @__PURE__ */ new Set();
423
+ function markRecordRemoved(recordId) {
424
+ removed.add(recordId);
425
+ }
426
+ function markRecordRestored(recordId) {
427
+ removed.delete(recordId);
428
+ }
422
429
  function onRecordChanged(listener) {
423
430
  listeners.add(listener);
424
431
  return () => listeners.delete(listener);
@@ -2891,6 +2898,7 @@ function createRecordsClient(given) {
2891
2898
  }
2892
2899
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
2893
2900
  }
2901
+ const readsInFlight = /* @__PURE__ */ new Map();
2894
2902
  async function callDoor(door, args, where) {
2895
2903
  const primed = primedFor(door, args);
2896
2904
  if (primed) return ok(primed.data);
@@ -2901,7 +2909,19 @@ function createRecordsClient(given) {
2901
2909
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
2902
2910
  return err(refusal2);
2903
2911
  }
2904
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
2912
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
2913
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
2914
+ const response = await (flying ?? (() => {
2915
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
2916
+ if (flightKey) {
2917
+ readsInFlight.set(flightKey, call);
2918
+ const forget = () => {
2919
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
2920
+ };
2921
+ call.then(forget, forget);
2922
+ }
2923
+ return call;
2924
+ })());
2905
2925
  if (response.error) {
2906
2926
  const refusal2 = mapPgError(response.error, where);
2907
2927
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
@@ -3211,7 +3231,10 @@ function createRecordsClient(given) {
3211
3231
  { p_organization_id: org, p_record_id: record_id },
3212
3232
  "recordDelete"
3213
3233
  );
3214
- if (result.ok) announceRecordChanged(record_id);
3234
+ if (result.ok) {
3235
+ markRecordRemoved(record_id);
3236
+ announceRecordChanged(record_id);
3237
+ }
3215
3238
  return result;
3216
3239
  },
3217
3240
  async recordRestore({ record_id }) {
@@ -3220,7 +3243,10 @@ function createRecordsClient(given) {
3220
3243
  { p_organization_id: org, p_record_id: record_id },
3221
3244
  "recordRestore"
3222
3245
  );
3223
- if (result.ok) announceRecordChanged(record_id);
3246
+ if (result.ok) {
3247
+ markRecordRestored(record_id);
3248
+ announceRecordChanged(record_id);
3249
+ }
3224
3250
  return result;
3225
3251
  },
3226
3252
  async tableArchive({ table_id, chunk, includeTable }) {