@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.
@@ -80,6 +80,16 @@ function announceRecordChanged(recordId) {
80
80
  }
81
81
  }
82
82
  }
83
+ var removed = /* @__PURE__ */ new Set();
84
+ function markRecordRemoved(recordId) {
85
+ removed.add(recordId);
86
+ }
87
+ function markRecordRestored(recordId) {
88
+ removed.delete(recordId);
89
+ }
90
+ function isRecordRemoved(recordId) {
91
+ return removed.has(recordId);
92
+ }
83
93
  function onRecordChanged(listener) {
84
94
  listeners.add(listener);
85
95
  return () => listeners.delete(listener);
@@ -4277,6 +4287,7 @@ function createRecordsClient(given) {
4277
4287
  }
4278
4288
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
4279
4289
  }
4290
+ const readsInFlight = /* @__PURE__ */ new Map();
4280
4291
  async function callDoor(door, args, where) {
4281
4292
  const primed = primedFor(door, args);
4282
4293
  if (primed) return ok(primed.data);
@@ -4287,7 +4298,19 @@ function createRecordsClient(given) {
4287
4298
  scream({ code: refusal3.code, message: refusal3.message, ...refusal3.hint ? { hint: refusal3.hint } : {}, where });
4288
4299
  return err(refusal3);
4289
4300
  }
4290
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
4301
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
4302
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
4303
+ const response = await (flying ?? (() => {
4304
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
4305
+ if (flightKey) {
4306
+ readsInFlight.set(flightKey, call);
4307
+ const forget = () => {
4308
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
4309
+ };
4310
+ call.then(forget, forget);
4311
+ }
4312
+ return call;
4313
+ })());
4291
4314
  if (response.error) {
4292
4315
  const refusal3 = mapPgError(response.error, where);
4293
4316
  scream({ code: refusal3.code, message: refusal3.message, ...refusal3.hint ? { hint: refusal3.hint } : {}, where });
@@ -4597,7 +4620,10 @@ function createRecordsClient(given) {
4597
4620
  { p_organization_id: org, p_record_id: record_id },
4598
4621
  "recordDelete"
4599
4622
  );
4600
- if (result.ok) announceRecordChanged(record_id);
4623
+ if (result.ok) {
4624
+ markRecordRemoved(record_id);
4625
+ announceRecordChanged(record_id);
4626
+ }
4601
4627
  return result;
4602
4628
  },
4603
4629
  async recordRestore({ record_id }) {
@@ -4606,7 +4632,10 @@ function createRecordsClient(given) {
4606
4632
  { p_organization_id: org, p_record_id: record_id },
4607
4633
  "recordRestore"
4608
4634
  );
4609
- if (result.ok) announceRecordChanged(record_id);
4635
+ if (result.ok) {
4636
+ markRecordRestored(record_id);
4637
+ announceRecordChanged(record_id);
4638
+ }
4610
4639
  return result;
4611
4640
  },
4612
4641
  async tableArchive({ table_id, chunk, includeTable }) {
@@ -8369,7 +8398,7 @@ function liveRecordFor(recordId, tableId) {
8369
8398
  const stops = [];
8370
8399
  stops.push(
8371
8400
  onRecordChanged((changed) => {
8372
- if (changed === recordId) entry.refetch();
8401
+ if (changed === recordId && !isRecordRemoved(recordId)) entry.refetch();
8373
8402
  })
8374
8403
  );
8375
8404
  const client = entry.client;
@@ -8380,7 +8409,7 @@ function liveRecordFor(recordId, tableId) {
8380
8409
  { organization_id: client.config.organizationId, table_id: tableId },
8381
8410
  {
8382
8411
  records(ids) {
8383
- if (ids === null || ids.includes(recordId)) entry.refetch();
8412
+ if ((ids === null || ids.includes(recordId)) && !isRecordRemoved(recordId)) entry.refetch();
8384
8413
  },
8385
8414
  shape() {
8386
8415
  tableShapeChanged(tableId);