@ai-matrx/records 0.99.22 → 0.99.23

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
@@ -116,6 +116,7 @@ __export(src_exports, {
116
116
  autonumberPrefixOf: () => autonumberPrefixOf,
117
117
  autonumberSearchOf: () => autonumberSearchOf,
118
118
  autonumberWords: () => autonumberWords,
119
+ baseCopyName: () => baseCopyName,
119
120
  bookingPath: () => bookingPath,
120
121
  buttonNeeds: () => buttonNeeds,
121
122
  buttonOf: () => buttonOf,
@@ -135,6 +136,7 @@ __export(src_exports, {
135
136
  defaultOpLedger: () => defaultOpLedger,
136
137
  drillAnswerOf: () => drillAnswerOf,
137
138
  drillFindingKnob: () => drillFindingKnob,
139
+ duplicateBase: () => duplicateBase,
138
140
  durationText: () => durationText,
139
141
  emptyArchiveLine: () => emptyArchiveLine,
140
142
  emptyPortalArchiveLine: () => emptyPortalArchiveLine,
@@ -226,6 +228,7 @@ __export(src_exports, {
226
228
  rememberedOpCount: () => rememberedOpCount,
227
229
  removedChoicesInUse: () => removedChoicesInUse,
228
230
  resolveObjectOrganization: () => resolveObjectOrganization,
231
+ restoreSnapshot: () => restoreSnapshot,
229
232
  richTextPlain: () => richTextPlain,
230
233
  ruleThatRefuses: () => ruleThatRefuses,
231
234
  rulesWithTopStar: () => rulesWithTopStar,
@@ -233,6 +236,7 @@ __export(src_exports, {
233
236
  sameDocument: () => sameDocument,
234
237
  scopeChip: () => scopeChip,
235
238
  sheetSyncSpec: () => sheetSyncSpec,
239
+ snapshotBase: () => snapshotBase,
236
240
  sourceArchivedOf: () => sourceArchivedOf,
237
241
  splitListCell: () => splitListCell,
238
242
  splitLockedRows: () => splitLockedRows,
@@ -1948,6 +1952,80 @@ function moveConsequence(home, to) {
1948
1952
  return `${home.table.name} moves to ${to.name} with its ${parts.join(", ")}` + (c.tablesInside > 0 ? `, the ${plural(c.tablesInside, "table", "tables")} that live${c.tablesInside === 1 ? "s" : ""} inside it or its rows (with their own rows)` : "") + (extra > 0 ? `, and ${plural(extra, "thing", "things")} built only on it (choice lists, rules, dashboards, templates)` : "") + `, its comments, forms, saved views and history. ` + (c.linksAcross > 0 ? `${plural(c.linksAcross, "link", "links")} to rows that stay in ${home.organization.name} keep${c.linksAcross === 1 ? "s" : ""} pointing there, across the two organizations. ` : "") + `People who see it only because they are in ${home.organization.name} stop seeing it; people it was shared with by name keep it. You can move it back from the same place.`;
1949
1953
  }
1950
1954
 
1955
+ // src/base.ts
1956
+ function baseCopyName(name) {
1957
+ return `${name.trim() || "Base"} (copy)`;
1958
+ }
1959
+ async function duplicateBase(port, args) {
1960
+ const made = [];
1961
+ const pairs = {};
1962
+ const notCopied = /* @__PURE__ */ new Set();
1963
+ for (const [i, table] of args.tables.entries()) {
1964
+ const res = await port.tableDuplicate({
1965
+ tableId: table.id,
1966
+ withRecords: args.withRecords,
1967
+ organizationId: args.organizationId,
1968
+ name: args.nameFor ? args.nameFor(table) : table.name,
1969
+ onProgress: (pass) => args.onProgress?.({ at: i + 1, of: args.tables.length, tableName: table.name, pass })
1970
+ });
1971
+ if (!res.ok) return { ok: false, error: res.error, stoppedAt: table, made };
1972
+ pairs[table.id] = res.data.table.id;
1973
+ made.push({ from: table, copy: res.data.table, records: res.data.copied.records });
1974
+ for (const n of res.data.notCopied) notCopied.add(n);
1975
+ }
1976
+ const fin = args.tables.length > 1 ? await port.finish({ organizationId: args.organizationId, pairs }) : null;
1977
+ if (fin && !fin.ok) return { ok: false, error: fin.error, stoppedAt: args.tables[args.tables.length - 1], made };
1978
+ return {
1979
+ ok: true,
1980
+ data: {
1981
+ pairs,
1982
+ tables: made,
1983
+ relinkedColumns: fin?.ok ? fin.data.relinked_columns : 0,
1984
+ relinkedCells: fin?.ok ? fin.data.relinked_cells : 0,
1985
+ notCopied: [...notCopied]
1986
+ }
1987
+ };
1988
+ }
1989
+ async function snapshotBase(port, args) {
1990
+ const copied = await duplicateBase(port, {
1991
+ organizationId: args.organizationId,
1992
+ tables: args.tables,
1993
+ withRecords: true,
1994
+ nameFor: (t) => `Snapshot ${args.label} \xB7 ${t.name}`,
1995
+ ...args.onProgress ? { onProgress: args.onProgress } : {}
1996
+ });
1997
+ if (!copied.ok) {
1998
+ for (const m of copied.made) await port.archive?.(m.copy.id);
1999
+ return { ok: false, error: copied.error, stoppedAt: copied.stoppedAt };
2000
+ }
2001
+ for (const t of copied.data.tables) {
2002
+ const away = await port.archive?.(t.copy.id);
2003
+ if (away && !away.ok) return { ok: false, error: away.error, stoppedAt: t.from };
2004
+ }
2005
+ return {
2006
+ ok: true,
2007
+ snapshot: {
2008
+ label: args.label,
2009
+ origin: args.origin ?? "manual",
2010
+ tables: copied.data.tables.map((t) => ({ table_id: t.from.id, snapshot_table_id: t.copy.id, name: t.from.name, records: t.records }))
2011
+ }
2012
+ };
2013
+ }
2014
+ async function restoreSnapshot(port, args) {
2015
+ const sources = args.snapshot.tables.map((t) => ({ id: t.snapshot_table_id, name: t.name }));
2016
+ const byCopy = new Map(args.snapshot.tables.map((t) => [t.snapshot_table_id, t.name]));
2017
+ for (const s of sources) await port.unarchive?.(s.id);
2018
+ const out = await duplicateBase(port, {
2019
+ organizationId: args.organizationId,
2020
+ tables: sources,
2021
+ withRecords: true,
2022
+ nameFor: (t) => `${byCopy.get(t.id) ?? t.name} (restored)`,
2023
+ ...args.onProgress ? { onProgress: args.onProgress } : {}
2024
+ });
2025
+ for (const s of sources) await port.archive?.(s.id);
2026
+ return out;
2027
+ }
2028
+
1951
2029
  // src/capture-queue.ts
1952
2030
  var DB_NAME = "matrx-capture";
1953
2031
  var DB_VERSION = 1;