@ai-matrx/records-ui 0.115.87 → 0.115.88

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/pickers.cjs CHANGED
@@ -4547,6 +4547,10 @@ function knownPerson(id) {
4547
4547
  return null;
4548
4548
  }
4549
4549
 
4550
+ // src/recordVersions.ts
4551
+ var recordVersions_exports = {};
4552
+ __reExport(recordVersions_exports, require("@ai-matrx/records/versions"));
4553
+
4550
4554
  // src/memberNames.ts
4551
4555
  var import_react36 = require("react");
4552
4556
  var import_react37 = require("@ai-matrx/records/react");
@@ -5665,7 +5669,7 @@ async function readPersonColumn(client, tableId, key) {
5665
5669
  const out = [];
5666
5670
  for (let offset = 0; offset < CEILING; offset += PAGE) {
5667
5671
  const page = await client.list({ table_id: tableId, limit: PAGE, offset });
5668
- if (!page.ok) throw new Error(page.error.message ?? "The records could not be read");
5672
+ if (!page.ok) throw new Error(refusalSentence(page.error));
5669
5673
  for (const row of page.data.rows) {
5670
5674
  const doc = row.document ?? {};
5671
5675
  let ids = idsIn(doc[key]);
@@ -5703,17 +5707,36 @@ function previewPersonWords(rows, people, as) {
5703
5707
  }
5704
5708
  return { converts, keptAside, examples, partial: false };
5705
5709
  }
5710
+ async function versionsNow(client, ids) {
5711
+ const out = /* @__PURE__ */ new Map();
5712
+ for (let i = 0; i < ids.length; i += 200) {
5713
+ const got = await client.recordHeaders({ ids: ids.slice(i, i + 200) });
5714
+ if (!got.ok) throw new Error(refusalSentence(got.error));
5715
+ for (const h of got.data ?? []) if (typeof h.version === "number") out.set(h.id, h.version);
5716
+ }
5717
+ return out;
5718
+ }
5719
+ async function writeRecordPatches(client, tableId, patches) {
5720
+ const versions = await versionsNow(client, patches.map((p) => p.recordId));
5721
+ for (let i = 0; i < patches.length; i += 100) {
5722
+ const changes = patches.slice(i, i + 100).map((p) => ({
5723
+ op: "update",
5724
+ record_id: p.recordId,
5725
+ patch: p.patch,
5726
+ expected_version: versions.get(p.recordId) ?? null
5727
+ }));
5728
+ const done = await (0, recordVersions_exports.changeRecordsAt)(client, { table_id: tableId, changes });
5729
+ if (!done.ok) throw new Error(refusalSentence(done.error));
5730
+ }
5731
+ }
5706
5732
  async function writePersonWords(client, tableId, rows, people, key, as) {
5707
- const changes = [];
5733
+ const patches = [];
5708
5734
  for (const row of rows) {
5709
5735
  const words = wordsFor(row.ids, people, as);
5710
- if (words !== null) changes.push({ op: "update", record_id: row.recordId, patch: { [key]: words } });
5711
- }
5712
- for (let i = 0; i < changes.length; i += 100) {
5713
- const done = await client.recordChangeMany({ table_id: tableId, changes: changes.slice(i, i + 100) });
5714
- if (!done.ok) throw new Error(done.error.message ?? "The words could not be written");
5736
+ if (words !== null) patches.push({ recordId: row.recordId, patch: { [key]: words } });
5715
5737
  }
5716
- return changes.length;
5738
+ await writeRecordPatches(client, tableId, patches);
5739
+ return patches.length;
5717
5740
  }
5718
5741
 
5719
5742
  // src/FieldRetype.tsx
@@ -5846,11 +5869,11 @@ function FieldRetype({ field, tableId, onRetyped }) {
5846
5869
  const back = await client.migrateUndo({ migration_id: migration });
5847
5870
  if (!back.ok) throw new Error(refusalSentence(back.error));
5848
5871
  if (wasPerson) {
5849
- const changes = wasPerson.rows.map((r) => ({ op: "update", record_id: r.recordId, patch: { [field.key]: field.multi ? r.ids : r.ids[0] ?? null } }));
5850
- for (let i = 0; i < changes.length; i += 100) {
5851
- const put = await client.recordChangeMany({ table_id: tableId, changes: changes.slice(i, i + 100) });
5852
- if (!put.ok) throw new Error(refusalSentence(put.error));
5853
- }
5872
+ await writeRecordPatches(
5873
+ client,
5874
+ tableId,
5875
+ wasPerson.rows.map((r) => ({ recordId: r.recordId, patch: { [field.key]: field.multi ? r.ids : r.ids[0] ?? null } }))
5876
+ );
5854
5877
  }
5855
5878
  (0, import_react44.tableShapeChanged)(tableId);
5856
5879
  onRetyped?.();