@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.
@@ -368,6 +368,16 @@ function announceRecordChanged(recordId) {
368
368
  }
369
369
  }
370
370
  }
371
+ var removed = /* @__PURE__ */ new Set();
372
+ function markRecordRemoved(recordId) {
373
+ removed.add(recordId);
374
+ }
375
+ function markRecordRestored(recordId) {
376
+ removed.delete(recordId);
377
+ }
378
+ function isRecordRemoved(recordId) {
379
+ return removed.has(recordId);
380
+ }
371
381
  function onRecordChanged(listener) {
372
382
  listeners.add(listener);
373
383
  return () => listeners.delete(listener);
@@ -4565,6 +4575,7 @@ function createRecordsClient(given) {
4565
4575
  }
4566
4576
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
4567
4577
  }
4578
+ const readsInFlight = /* @__PURE__ */ new Map();
4568
4579
  async function callDoor(door, args, where) {
4569
4580
  const primed = primedFor(door, args);
4570
4581
  if (primed) return ok(primed.data);
@@ -4575,7 +4586,19 @@ function createRecordsClient(given) {
4575
4586
  scream({ code: refusal3.code, message: refusal3.message, ...refusal3.hint ? { hint: refusal3.hint } : {}, where });
4576
4587
  return err(refusal3);
4577
4588
  }
4578
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
4589
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
4590
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
4591
+ const response = await (flying ?? (() => {
4592
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
4593
+ if (flightKey) {
4594
+ readsInFlight.set(flightKey, call);
4595
+ const forget = () => {
4596
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
4597
+ };
4598
+ call.then(forget, forget);
4599
+ }
4600
+ return call;
4601
+ })());
4579
4602
  if (response.error) {
4580
4603
  const refusal3 = mapPgError(response.error, where);
4581
4604
  scream({ code: refusal3.code, message: refusal3.message, ...refusal3.hint ? { hint: refusal3.hint } : {}, where });
@@ -4885,7 +4908,10 @@ function createRecordsClient(given) {
4885
4908
  { p_organization_id: org, p_record_id: record_id },
4886
4909
  "recordDelete"
4887
4910
  );
4888
- if (result.ok) announceRecordChanged(record_id);
4911
+ if (result.ok) {
4912
+ markRecordRemoved(record_id);
4913
+ announceRecordChanged(record_id);
4914
+ }
4889
4915
  return result;
4890
4916
  },
4891
4917
  async recordRestore({ record_id }) {
@@ -4894,7 +4920,10 @@ function createRecordsClient(given) {
4894
4920
  { p_organization_id: org, p_record_id: record_id },
4895
4921
  "recordRestore"
4896
4922
  );
4897
- if (result.ok) announceRecordChanged(record_id);
4923
+ if (result.ok) {
4924
+ markRecordRestored(record_id);
4925
+ announceRecordChanged(record_id);
4926
+ }
4898
4927
  return result;
4899
4928
  },
4900
4929
  async tableArchive({ table_id, chunk, includeTable }) {
@@ -8657,7 +8686,7 @@ function liveRecordFor(recordId, tableId) {
8657
8686
  const stops = [];
8658
8687
  stops.push(
8659
8688
  onRecordChanged((changed) => {
8660
- if (changed === recordId) entry.refetch();
8689
+ if (changed === recordId && !isRecordRemoved(recordId)) entry.refetch();
8661
8690
  })
8662
8691
  );
8663
8692
  const client = entry.client;
@@ -8668,7 +8697,7 @@ function liveRecordFor(recordId, tableId) {
8668
8697
  { organization_id: client.config.organizationId, table_id: tableId },
8669
8698
  {
8670
8699
  records(ids) {
8671
- if (ids === null || ids.includes(recordId)) entry.refetch();
8700
+ if ((ids === null || ids.includes(recordId)) && !isRecordRemoved(recordId)) entry.refetch();
8672
8701
  },
8673
8702
  shape() {
8674
8703
  tableShapeChanged(tableId);