@ai-matrx/records-ui 0.110.5 → 0.110.7

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.
package/dist/index.cjs CHANGED
@@ -1702,12 +1702,33 @@ function inColumnWords(error, fields) {
1702
1702
 
1703
1703
  // src/askOnce.ts
1704
1704
  var asked = /* @__PURE__ */ new WeakMap();
1705
- function askOnce(client, key, ask, freshMs) {
1705
+ var byPerson = /* @__PURE__ */ new WeakMap();
1706
+ function heldFor(client) {
1707
+ const config = client.config;
1708
+ const source = config?.dataSource;
1709
+ if (source && typeof source === "object" && config?.actor) {
1710
+ const who = [config.actor.actor ?? "-", config.actor.user_id ?? "-", config.actor.on_behalf_of ?? "-"].join("|");
1711
+ let persons = byPerson.get(source);
1712
+ if (!persons) {
1713
+ persons = /* @__PURE__ */ new Map();
1714
+ byPerson.set(source, persons);
1715
+ }
1716
+ let held2 = persons.get(who);
1717
+ if (!held2) {
1718
+ held2 = /* @__PURE__ */ new Map();
1719
+ persons.set(who, held2);
1720
+ }
1721
+ return held2;
1722
+ }
1706
1723
  let held = asked.get(client);
1707
1724
  if (!held) {
1708
1725
  held = /* @__PURE__ */ new Map();
1709
1726
  asked.set(client, held);
1710
1727
  }
1728
+ return held;
1729
+ }
1730
+ function askOnce(client, key, ask, freshMs) {
1731
+ const held = heldFor(client);
1711
1732
  const now = Date.now();
1712
1733
  const kept = held.get(key);
1713
1734
  if (kept && now - kept.at <= freshMs) return kept.answer;
@@ -1725,8 +1746,7 @@ function askOnce(client, key, ask, freshMs) {
1725
1746
  return answer;
1726
1747
  }
1727
1748
  function forgetAsked(client, prefix) {
1728
- const held = asked.get(client);
1729
- if (!held) return;
1749
+ const held = heldFor(client);
1730
1750
  for (const key of [...held.keys()]) if (key.startsWith(prefix)) held.delete(key);
1731
1751
  }
1732
1752
  var FIELD_OPTIONS_FRESH_MS = 2e3;
@@ -3382,6 +3402,12 @@ function asRefusal(thrown, sentence2, remedy, code = "internal") {
3382
3402
  return refusalFromThrown(thrown, sentence2, remedy, code);
3383
3403
  }
3384
3404
 
3405
+ // src/rowVersion.ts
3406
+ function ownVersion(row) {
3407
+ const v = row.version;
3408
+ return typeof v === "number" ? v : null;
3409
+ }
3410
+
3385
3411
  // src/recordVersions.ts
3386
3412
  var STALE_MOVE_LABEL = "Changed by someone else";
3387
3413
  var VERSION_UNREAD_LABEL = "Could not check for changes";
@@ -3398,10 +3424,6 @@ function isVersionUnread(error) {
3398
3424
  function isChangedElsewhere(error) {
3399
3425
  return error?.code === "stale_write";
3400
3426
  }
3401
- function ownVersion(row) {
3402
- const v = row.version;
3403
- return typeof v === "number" ? v : null;
3404
- }
3405
3427
  function signatureOf(row) {
3406
3428
  const own3 = ownVersion(row);
3407
3429
  if (own3 !== null) return `v${own3}`;
@@ -3411,6 +3433,7 @@ function signatureOf(row) {
3411
3433
  return String(Math.random());
3412
3434
  }
3413
3435
  }
3436
+ var HEADERS_SHARED_MS = 3e3;
3414
3437
  function useRecordVersions(client, rows, mayRead) {
3415
3438
  const versions = (0, import_react13.useRef)(/* @__PURE__ */ new Map());
3416
3439
  const drawn = (0, import_react13.useRef)(/* @__PURE__ */ new Map());
@@ -3428,7 +3451,7 @@ function useRecordVersions(client, rows, mayRead) {
3428
3451
  unread.current.delete(id);
3429
3452
  };
3430
3453
  const readHeaders = (0, import_react13.useCallback)(
3431
- (toRead) => {
3454
+ (toRead, shared = false) => {
3432
3455
  if (toRead.length === 0) return;
3433
3456
  generation.current += 1;
3434
3457
  const gen = generation.current;
@@ -3436,7 +3459,8 @@ function useRecordVersions(client, rows, mayRead) {
3436
3459
  versions.current.delete(id);
3437
3460
  unread.current.add(id);
3438
3461
  };
3439
- const read = client.recordHeaders({ ids: toRead }).then(
3462
+ const asking = shared ? askOnce(client, `record_headers:${toRead.join(",")}`, () => client.recordHeaders({ ids: toRead }), HEADERS_SHARED_MS) : client.recordHeaders({ ids: toRead });
3463
+ const read = asking.then(
3440
3464
  (res) => {
3441
3465
  const found = /* @__PURE__ */ new Set();
3442
3466
  if (res.ok) {
@@ -3469,7 +3493,7 @@ function useRecordVersions(client, rows, mayRead) {
3469
3493
  if (own3 !== null) raise(row.id, own3);
3470
3494
  else toRead.push(row.id);
3471
3495
  }
3472
- readHeaders(toRead);
3496
+ readHeaders(toRead, true);
3473
3497
  }, [readHeaders, key]);
3474
3498
  const refresh = (0, import_react13.useCallback)((ids) => readHeaders([...ids]), [readHeaders]);
3475
3499
  const seen = (0, import_react13.useCallback)(async (id) => {