@ai-matrx/records 0.99.26 → 0.99.27

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.
@@ -231,6 +231,7 @@ __export(react_exports, {
231
231
  parseTableHome: () => parseTableHome,
232
232
  parseTableMoved: () => parseTableMoved,
233
233
  personStampText: () => personStampText,
234
+ pointAtCopies: () => pointAtCopies,
234
235
  portalArchiveConsequence: () => portalArchiveConsequence,
235
236
  portalConfirmLine: () => portalConfirmLine,
236
237
  portalPath: () => portalPath,
@@ -13483,6 +13484,7 @@ async function duplicateBase(port, args) {
13483
13484
  }
13484
13485
  const fin = args.tables.length > 1 ? await port.finish({ organizationId: args.organizationId, pairs }) : null;
13485
13486
  if (fin && !fin.ok) return { ok: false, error: fin.error, stoppedAt: args.tables[args.tables.length - 1], made };
13487
+ const extras = await copyExtras(port, args.tables, pairs);
13486
13488
  return {
13487
13489
  ok: true,
13488
13490
  data: {
@@ -13490,10 +13492,53 @@ async function duplicateBase(port, args) {
13490
13492
  tables: made,
13491
13493
  relinkedColumns: fin?.ok ? fin.data.relinked_columns : 0,
13492
13494
  relinkedCells: fin?.ok ? fin.data.relinked_cells : 0,
13495
+ ...extras,
13493
13496
  notCopied: [...notCopied]
13494
13497
  }
13495
13498
  };
13496
13499
  }
13500
+ function pointAtCopies(doc, pairs) {
13501
+ let text2 = JSON.stringify(doc);
13502
+ for (const [from, to] of Object.entries(pairs)) text2 = text2.split(from).join(to);
13503
+ return JSON.parse(text2);
13504
+ }
13505
+ async function copyExtras(port, tables, pairs) {
13506
+ let automations = 0;
13507
+ let pages = 0;
13508
+ const extrasRefused = [];
13509
+ for (const t of tables) {
13510
+ const copy = pairs[t.id];
13511
+ if (!copy) continue;
13512
+ if (port.automations && port.automationDeclare) {
13513
+ const list = await port.automations(t.id);
13514
+ if (list.ok) {
13515
+ for (const a of list.data.automations) {
13516
+ const made = await port.automationDeclare({ table_id: copy, spec: pointAtCopies(a.spec, pairs) });
13517
+ if (made.ok && made.data.ok && made.data.automation_id) {
13518
+ await port.automationSetEnabled?.({ automation_id: made.data.automation_id, enabled: false });
13519
+ automations += 1;
13520
+ } else extrasRefused.push(`Automation "${a.name}" on ${t.name} was not copied.`);
13521
+ }
13522
+ }
13523
+ }
13524
+ if (port.dashboards && port.dashboardDeclare) {
13525
+ const list = await port.dashboards(t.id);
13526
+ if (list.ok) {
13527
+ for (const d of list.data) {
13528
+ const made = await port.dashboardDeclare({
13529
+ table_id: copy,
13530
+ name: d.name,
13531
+ blocks: pointAtCopies(d.blocks, pairs),
13532
+ presentation: pointAtCopies(d.presentation, pairs)
13533
+ });
13534
+ if (made.ok) pages += 1;
13535
+ else extrasRefused.push(`Page "${d.name}" on ${t.name} was not copied.`);
13536
+ }
13537
+ }
13538
+ }
13539
+ }
13540
+ return { automations, pages, extrasRefused };
13541
+ }
13497
13542
  async function snapshotBase(port, args) {
13498
13543
  const copied = await duplicateBase(port, {
13499
13544
  organizationId: args.organizationId,