@ai-matrx/records 0.99.26 → 0.99.28

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
@@ -204,6 +204,7 @@ __export(src_exports, {
204
204
  parseTableHome: () => parseTableHome,
205
205
  parseTableMoved: () => parseTableMoved,
206
206
  personStampText: () => personStampText,
207
+ pointAtCopies: () => pointAtCopies,
207
208
  portalArchiveConsequence: () => portalArchiveConsequence,
208
209
  portalConfirmLine: () => portalConfirmLine,
209
210
  portalPath: () => portalPath,
@@ -1982,6 +1983,7 @@ async function duplicateBase(port, args) {
1982
1983
  }
1983
1984
  const fin = args.tables.length > 1 ? await port.finish({ organizationId: args.organizationId, pairs }) : null;
1984
1985
  if (fin && !fin.ok) return { ok: false, error: fin.error, stoppedAt: args.tables[args.tables.length - 1], made };
1986
+ const extras = await copyExtras(port, args.tables, pairs);
1985
1987
  return {
1986
1988
  ok: true,
1987
1989
  data: {
@@ -1989,10 +1991,53 @@ async function duplicateBase(port, args) {
1989
1991
  tables: made,
1990
1992
  relinkedColumns: fin?.ok ? fin.data.relinked_columns : 0,
1991
1993
  relinkedCells: fin?.ok ? fin.data.relinked_cells : 0,
1994
+ ...extras,
1992
1995
  notCopied: [...notCopied]
1993
1996
  }
1994
1997
  };
1995
1998
  }
1999
+ function pointAtCopies(doc, pairs) {
2000
+ let text = JSON.stringify(doc);
2001
+ for (const [from, to] of Object.entries(pairs)) text = text.split(from).join(to);
2002
+ return JSON.parse(text);
2003
+ }
2004
+ async function copyExtras(port, tables, pairs) {
2005
+ let automations = 0;
2006
+ let pages = 0;
2007
+ const extrasRefused = [];
2008
+ for (const t of tables) {
2009
+ const copy = pairs[t.id];
2010
+ if (!copy) continue;
2011
+ if (port.automations && port.automationDeclare) {
2012
+ const list = await port.automations(t.id);
2013
+ if (list.ok) {
2014
+ for (const a of list.data.automations) {
2015
+ const made = await port.automationDeclare({ table_id: copy, spec: pointAtCopies(a.spec, pairs) });
2016
+ if (made.ok && made.data.ok && made.data.automation_id) {
2017
+ await port.automationSetEnabled?.({ automation_id: made.data.automation_id, enabled: false });
2018
+ automations += 1;
2019
+ } else extrasRefused.push(`Automation "${a.name}" on ${t.name} was not copied.`);
2020
+ }
2021
+ }
2022
+ }
2023
+ if (port.dashboards && port.dashboardDeclare) {
2024
+ const list = await port.dashboards(t.id);
2025
+ if (list.ok) {
2026
+ for (const d of list.data) {
2027
+ const made = await port.dashboardDeclare({
2028
+ table_id: copy,
2029
+ name: d.name,
2030
+ blocks: pointAtCopies(d.blocks, pairs),
2031
+ presentation: pointAtCopies(d.presentation, pairs)
2032
+ });
2033
+ if (made.ok) pages += 1;
2034
+ else extrasRefused.push(`Page "${d.name}" on ${t.name} was not copied.`);
2035
+ }
2036
+ }
2037
+ }
2038
+ }
2039
+ return { automations, pages, extrasRefused };
2040
+ }
1996
2041
  async function snapshotBase(port, args) {
1997
2042
  const copied = await duplicateBase(port, {
1998
2043
  organizationId: args.organizationId,