@ai-matrx/records 0.99.28 → 0.99.30

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/{client-B7LYr-aE.d.cts → client-B7KEs9hi.d.cts} +10 -0
  3. package/dist/{client-m4soDpHA.d.ts → client-Dthx26hr.d.ts} +10 -0
  4. package/dist/core/index.cjs +76 -10
  5. package/dist/core/index.cjs.map +1 -1
  6. package/dist/core/index.d.cts +3 -3
  7. package/dist/core/index.d.ts +3 -3
  8. package/dist/core/index.js +76 -10
  9. package/dist/core/index.js.map +1 -1
  10. package/dist/data/index.cjs +12 -1
  11. package/dist/data/index.cjs.map +1 -1
  12. package/dist/data/index.d.cts +1 -1
  13. package/dist/data/index.d.ts +1 -1
  14. package/dist/data/index.js +12 -1
  15. package/dist/data/index.js.map +1 -1
  16. package/dist/{declareTable-D5Zs-SjU.d.ts → declareTable-CvBu5dTJ.d.ts} +1 -1
  17. package/dist/{declareTable-Bnrzv-Bg.d.cts → declareTable-enQs2N0E.d.cts} +1 -1
  18. package/dist/entity/index.cjs +1 -1
  19. package/dist/entity/index.cjs.map +1 -1
  20. package/dist/entity/index.d.cts +3 -3
  21. package/dist/entity/index.d.ts +3 -3
  22. package/dist/entity/index.js +1 -1
  23. package/dist/entity/index.js.map +1 -1
  24. package/dist/entity/react.cjs +1 -1
  25. package/dist/entity/react.cjs.map +1 -1
  26. package/dist/entity/react.js +1 -1
  27. package/dist/entity/react.js.map +1 -1
  28. package/dist/first-page/index.d.cts +2 -0
  29. package/dist/first-page/index.d.ts +2 -0
  30. package/dist/index.cjs +64 -9
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +29 -3
  33. package/dist/index.d.ts +29 -3
  34. package/dist/index.js +64 -9
  35. package/dist/index.js.map +1 -1
  36. package/dist/{port-DWHLj_Sa.d.ts → port-Bk7TG0aE.d.ts} +3 -3
  37. package/dist/{port-BbWB9Pgq.d.cts → port-rqQEGhew.d.cts} +3 -3
  38. package/dist/questions/index.d.cts +1 -1
  39. package/dist/questions/index.d.ts +1 -1
  40. package/dist/react/index.cjs +82 -128
  41. package/dist/react/index.cjs.map +1 -1
  42. package/dist/react/index.d.cts +37 -2
  43. package/dist/react/index.d.ts +37 -2
  44. package/dist/react/index.js +81 -127
  45. package/dist/react/index.js.map +1 -1
  46. package/dist/realtime/index.cjs +1 -1
  47. package/dist/realtime/index.cjs.map +1 -1
  48. package/dist/realtime/index.d.cts +4 -4
  49. package/dist/realtime/index.d.ts +4 -4
  50. package/dist/realtime/index.js +1 -1
  51. package/dist/realtime/index.js.map +1 -1
  52. package/dist/setup/index.cjs +15 -4
  53. package/dist/setup/index.cjs.map +1 -1
  54. package/dist/setup/index.d.cts +3 -3
  55. package/dist/setup/index.d.ts +3 -3
  56. package/dist/setup/index.js +15 -4
  57. package/dist/setup/index.js.map +1 -1
  58. package/dist/typed-table/index.cjs +16 -117
  59. package/dist/typed-table/index.cjs.map +1 -1
  60. package/dist/typed-table/index.d.cts +3 -4
  61. package/dist/typed-table/index.d.ts +3 -4
  62. package/dist/typed-table/index.js +15 -116
  63. package/dist/typed-table/index.js.map +1 -1
  64. package/dist/views/index.d.cts +1 -1
  65. package/dist/views/index.d.ts +1 -1
  66. package/package.json +7 -5
@@ -5836,6 +5836,15 @@ function createRecordsClient(given) {
5836
5836
  }
5837
5837
  return result;
5838
5838
  },
5839
+ async recordReparent({ record_id, parent_id }) {
5840
+ const result = await callDoor(
5841
+ DOORS.recordReparent,
5842
+ { p_organization_id: org, p_record_id: record_id, p_parent_id: parent_id },
5843
+ "recordReparent"
5844
+ );
5845
+ if (result.ok) announceRecordChanged(record_id);
5846
+ return result;
5847
+ },
5839
5848
  async recordRestore({ record_id }) {
5840
5849
  const result = await callDoor(
5841
5850
  DOORS.recordRestore,
@@ -6383,7 +6392,9 @@ function createRecordsClient(given) {
6383
6392
  }
6384
6393
  const tables = read.map((row) => {
6385
6394
  const { document } = unfold(row.document);
6386
- return { ...document, id: row.id, organization_id: org };
6395
+ const doc = document;
6396
+ const home = typeof doc.home_id === "string" ? doc.home_id : typeof doc.parent_id === "string" ? doc.parent_id : null;
6397
+ return { ...doc, home_id: home, id: row.id, organization_id: org };
6387
6398
  });
6388
6399
  tables.sort((a, b) => (a.name ?? "").localeCompare(b.name ?? ""));
6389
6400
  return ok(tables);
@@ -12339,6 +12350,9 @@ function useStoreTable(table, options = {}) {
12339
12350
  };
12340
12351
  }
12341
12352
 
12353
+ // src/typed-table/define.ts
12354
+ import { sha256Hex as sha256Hex2 } from "@ai-matrx/kit/sha256";
12355
+
12342
12356
  // src/typed-table/graduate.ts
12343
12357
  import { isUuidShape as isUuidShape6 } from "@ai-matrx/kit/uuid";
12344
12358
  var TO_CUSTOM_FIELDS = "custom_fields";
@@ -12500,8 +12514,8 @@ var f = {
12500
12514
  };
12501
12515
  var SLUG = /^[a-z][a-z0-9_]*$/;
12502
12516
  var WORD = /^[a-z][a-z0-9_]*$/;
12503
- function refuse3(slug, sentence) {
12504
- throw new Error(`defineTypedTable(${JSON.stringify(slug)}): ${sentence}`);
12517
+ function refuse3(slug, sentence2) {
12518
+ throw new Error(`defineTypedTable(${JSON.stringify(slug)}): ${sentence2}`);
12505
12519
  }
12506
12520
  function labelFor(key) {
12507
12521
  const words = key.replace(/_+/g, " ").trim();
@@ -12613,120 +12627,6 @@ function defineTypedTable(input) {
12613
12627
  } : null
12614
12628
  });
12615
12629
  }
12616
- var K256 = new Uint32Array([
12617
- 1116352408,
12618
- 1899447441,
12619
- 3049323471,
12620
- 3921009573,
12621
- 961987163,
12622
- 1508970993,
12623
- 2453635748,
12624
- 2870763221,
12625
- 3624381080,
12626
- 310598401,
12627
- 607225278,
12628
- 1426881987,
12629
- 1925078388,
12630
- 2162078206,
12631
- 2614888103,
12632
- 3248222580,
12633
- 3835390401,
12634
- 4022224774,
12635
- 264347078,
12636
- 604807628,
12637
- 770255983,
12638
- 1249150122,
12639
- 1555081692,
12640
- 1996064986,
12641
- 2554220882,
12642
- 2821834349,
12643
- 2952996808,
12644
- 3210313671,
12645
- 3336571891,
12646
- 3584528711,
12647
- 113926993,
12648
- 338241895,
12649
- 666307205,
12650
- 773529912,
12651
- 1294757372,
12652
- 1396182291,
12653
- 1695183700,
12654
- 1986661051,
12655
- 2177026350,
12656
- 2456956037,
12657
- 2730485921,
12658
- 2820302411,
12659
- 3259730800,
12660
- 3345764771,
12661
- 3516065817,
12662
- 3600352804,
12663
- 4094571909,
12664
- 275423344,
12665
- 430227734,
12666
- 506948616,
12667
- 659060556,
12668
- 883997877,
12669
- 958139571,
12670
- 1322822218,
12671
- 1537002063,
12672
- 1747873779,
12673
- 1955562222,
12674
- 2024104815,
12675
- 2227730452,
12676
- 2361852424,
12677
- 2428436474,
12678
- 2756734187,
12679
- 3204031479,
12680
- 3329325298
12681
- ]);
12682
- function sha256Hex2(text2) {
12683
- const bytes = new TextEncoder().encode(text2);
12684
- const bitLength = bytes.length * 8;
12685
- const padded = new Uint8Array(bytes.length + 9 + 63 >> 6 << 6);
12686
- padded.set(bytes);
12687
- padded[bytes.length] = 128;
12688
- const view = new DataView(padded.buffer);
12689
- view.setUint32(padded.length - 8, Math.floor(bitLength / 4294967296));
12690
- view.setUint32(padded.length - 4, bitLength >>> 0);
12691
- const h = new Uint32Array([1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]);
12692
- const w = new Uint32Array(64);
12693
- const rotr = (x, n) => x >>> n | x << 32 - n;
12694
- for (let off = 0; off < padded.length; off += 64) {
12695
- for (let i = 0; i < 16; i++) w[i] = view.getUint32(off + i * 4);
12696
- for (let i = 16; i < 64; i++) {
12697
- const a2 = w[i - 15], b2 = w[i - 2];
12698
- const s0 = rotr(a2, 7) ^ rotr(a2, 18) ^ a2 >>> 3;
12699
- const s1 = rotr(b2, 17) ^ rotr(b2, 19) ^ b2 >>> 10;
12700
- w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
12701
- }
12702
- let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f2 = h[5], g = h[6], hh = h[7];
12703
- for (let i = 0; i < 64; i++) {
12704
- const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
12705
- const ch = e & f2 ^ ~e & g;
12706
- const t1 = hh + S1 + ch + K256[i] + w[i] >>> 0;
12707
- const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
12708
- const maj = a & b ^ a & c ^ b & c;
12709
- const t2 = S0 + maj >>> 0;
12710
- hh = g;
12711
- g = f2;
12712
- f2 = e;
12713
- e = d + t1 >>> 0;
12714
- d = c;
12715
- c = b;
12716
- b = a;
12717
- a = t1 + t2 >>> 0;
12718
- }
12719
- h[0] = h[0] + a >>> 0;
12720
- h[1] = h[1] + b >>> 0;
12721
- h[2] = h[2] + c >>> 0;
12722
- h[3] = h[3] + d >>> 0;
12723
- h[4] = h[4] + e >>> 0;
12724
- h[5] = h[5] + f2 >>> 0;
12725
- h[6] = h[6] + g >>> 0;
12726
- h[7] = h[7] + hh >>> 0;
12727
- }
12728
- return Array.from(h, (x) => x.toString(16).padStart(8, "0")).join("");
12729
- }
12730
12630
 
12731
12631
  // src/typed-table/archive.ts
12732
12632
  var MAX_PASSES = 200;
@@ -13137,6 +13037,9 @@ function automationWebhookUrl(serverBase, item2) {
13137
13037
  function baseCopyName(name) {
13138
13038
  return `${name.trim() || "Base"} (copy)`;
13139
13039
  }
13040
+ function restoredBaseName(name, on) {
13041
+ return `${name.trim() || "Base"} (restored ${on})`;
13042
+ }
13140
13043
  async function duplicateBase(port, args) {
13141
13044
  const made = [];
13142
13045
  const pairs = {};
@@ -13156,10 +13059,21 @@ async function duplicateBase(port, args) {
13156
13059
  }
13157
13060
  const fin = args.tables.length > 1 ? await port.finish({ organizationId: args.organizationId, pairs }) : null;
13158
13061
  if (fin && !fin.ok) return { ok: false, error: fin.error, stoppedAt: args.tables[args.tables.length - 1], made };
13062
+ let homeId = null;
13063
+ if (args.homeName && port.createHome && port.moveInto) {
13064
+ const home = await port.createHome(args.homeName);
13065
+ if (!home.ok) return { ok: false, error: home.error, stoppedAt: args.tables[args.tables.length - 1], made };
13066
+ homeId = home.data;
13067
+ for (const m of made) {
13068
+ const moved = await port.moveInto(m.copy.id, homeId);
13069
+ if (!moved.ok) return { ok: false, error: moved.error, stoppedAt: m.from, made };
13070
+ }
13071
+ }
13159
13072
  const extras = await copyExtras(port, args.tables, pairs);
13160
13073
  return {
13161
13074
  ok: true,
13162
13075
  data: {
13076
+ homeId,
13163
13077
  pairs,
13164
13078
  tables: made,
13165
13079
  relinkedColumns: fin?.ok ? fin.data.relinked_columns : 0,
@@ -13174,10 +13088,47 @@ function pointAtCopies(doc, pairs) {
13174
13088
  for (const [from, to] of Object.entries(pairs)) text2 = text2.split(from).join(to);
13175
13089
  return JSON.parse(text2);
13176
13090
  }
13091
+ function sentence(error) {
13092
+ const m = error?.message;
13093
+ return typeof m === "string" && m ? m : "the store gave no reason.";
13094
+ }
13095
+ function refusedSentence(data) {
13096
+ const errors = data?._errors;
13097
+ const lines = errors ? Object.entries(errors).map(([path, why]) => `${path}: ${why}`) : [];
13098
+ return lines.length ? lines.join("; ") : "the store gave no reason.";
13099
+ }
13100
+ async function idsOfCopies(port, pairs) {
13101
+ const ids = { ...pairs };
13102
+ if (!port.fieldsOf && !port.viewsOf) return ids;
13103
+ for (const [from, to] of Object.entries(pairs)) {
13104
+ if (port.fieldsOf) {
13105
+ const [a, b] = await Promise.all([port.fieldsOf(from), port.fieldsOf(to)]);
13106
+ if (a.ok && b.ok) {
13107
+ const byKey = new Map(b.data.map((f2) => [f2.key, f2.id]));
13108
+ for (const f2 of a.data) {
13109
+ const n = byKey.get(f2.key);
13110
+ if (n && n !== f2.id) ids[f2.id] = n;
13111
+ }
13112
+ }
13113
+ }
13114
+ if (port.viewsOf) {
13115
+ const [a, b] = await Promise.all([port.viewsOf(from), port.viewsOf(to)]);
13116
+ if (a.ok && b.ok) {
13117
+ const byName = new Map(b.data.map((v) => [v.name, v.id]));
13118
+ for (const v of a.data) {
13119
+ const n = byName.get(v.name);
13120
+ if (n && n !== v.id) ids[v.id] = n;
13121
+ }
13122
+ }
13123
+ }
13124
+ }
13125
+ return ids;
13126
+ }
13177
13127
  async function copyExtras(port, tables, pairs) {
13178
13128
  let automations = 0;
13179
13129
  let pages = 0;
13180
13130
  const extrasRefused = [];
13131
+ const ids = await idsOfCopies(port, pairs);
13181
13132
  for (const t of tables) {
13182
13133
  const copy = pairs[t.id];
13183
13134
  if (!copy) continue;
@@ -13185,13 +13136,14 @@ async function copyExtras(port, tables, pairs) {
13185
13136
  const list = await port.automations(t.id);
13186
13137
  if (list.ok) {
13187
13138
  for (const a of list.data.automations) {
13188
- const made = await port.automationDeclare({ table_id: copy, spec: pointAtCopies(a.spec, pairs) });
13139
+ const made = await port.automationDeclare({ table_id: copy, spec: pointAtCopies(a.spec, ids) });
13189
13140
  if (made.ok && made.data.ok && made.data.automation_id) {
13190
- await port.automationSetEnabled?.({ automation_id: made.data.automation_id, enabled: false });
13191
- automations += 1;
13192
- } else extrasRefused.push(`Automation "${a.name}" on ${t.name} was not copied.`);
13141
+ const off = await port.automationSetEnabled?.({ automation_id: made.data.automation_id, enabled: false });
13142
+ if (off && !off.ok) extrasRefused.push(`Automation "${a.name}" on ${t.name} was copied but could not be switched off: ${sentence(off.error)}`);
13143
+ else automations += 1;
13144
+ } else extrasRefused.push(`Automation "${a.name}" on ${t.name} was not copied: ${made.ok ? refusedSentence(made.data) : sentence(made.error)}`);
13193
13145
  }
13194
- }
13146
+ } else extrasRefused.push(`The automations of ${t.name} could not be read: ${sentence(list.error)}`);
13195
13147
  }
13196
13148
  if (port.dashboards && port.dashboardDeclare) {
13197
13149
  const list = await port.dashboards(t.id);
@@ -13200,13 +13152,13 @@ async function copyExtras(port, tables, pairs) {
13200
13152
  const made = await port.dashboardDeclare({
13201
13153
  table_id: copy,
13202
13154
  name: d.name,
13203
- blocks: pointAtCopies(d.blocks, pairs),
13204
- presentation: pointAtCopies(d.presentation, pairs)
13155
+ blocks: pointAtCopies(d.blocks, ids),
13156
+ presentation: pointAtCopies(d.presentation, ids)
13205
13157
  });
13206
13158
  if (made.ok) pages += 1;
13207
- else extrasRefused.push(`Page "${d.name}" on ${t.name} was not copied.`);
13159
+ else extrasRefused.push(`Page "${d.name}" on ${t.name} was not copied: ${sentence(made.error)}`);
13208
13160
  }
13209
- }
13161
+ } else extrasRefused.push(`The pages of ${t.name} could not be read: ${sentence(list.error)}`);
13210
13162
  }
13211
13163
  }
13212
13164
  return { automations, pages, extrasRefused };
@@ -13245,6 +13197,7 @@ async function restoreSnapshot(port, args) {
13245
13197
  tables: sources,
13246
13198
  withRecords: true,
13247
13199
  nameFor: (t) => `${byCopy.get(t.id) ?? t.name} (restored)`,
13200
+ homeName: restoredBaseName(args.baseName ?? "Base", args.restoredOn ?? (/* @__PURE__ */ new Date()).toLocaleDateString()),
13248
13201
  ...args.onProgress ? { onProgress: args.onProgress } : {}
13249
13202
  });
13250
13203
  for (const s of sources) await port.archive?.(s.id);
@@ -14174,6 +14127,7 @@ export {
14174
14127
  hasQuietHours,
14175
14128
  highestLevel,
14176
14129
  holdsARetiredChoice,
14130
+ idsOfCopies,
14177
14131
  indexedDbStore,
14178
14132
  isAddressValue,
14179
14133
  isArchiveLane,
@@ -14254,6 +14208,7 @@ export {
14254
14208
  removedChoicesInUse,
14255
14209
  resolveObjectOrganization,
14256
14210
  restoreSnapshot,
14211
+ restoredBaseName,
14257
14212
  richTextPlain,
14258
14213
  rowFromDocument,
14259
14214
  ruleThatRefuses,
@@ -14261,7 +14216,6 @@ export {
14261
14216
  safeLinkHref,
14262
14217
  sameDocument,
14263
14218
  scopeChip,
14264
- sha256Hex2 as sha256Hex,
14265
14219
  sheetSyncSpec,
14266
14220
  snapshotBase,
14267
14221
  sourceArchivedOf,