@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.
@@ -130,6 +130,7 @@ __export(react_exports, {
130
130
  autonumberPrefixOf: () => autonumberPrefixOf,
131
131
  autonumberSearchOf: () => autonumberSearchOf,
132
132
  autonumberWords: () => autonumberWords,
133
+ baseCopyName: () => baseCopyName,
133
134
  bookingPath: () => bookingPath,
134
135
  buttonNeeds: () => buttonNeeds,
135
136
  buttonOf: () => buttonOf,
@@ -155,6 +156,7 @@ __export(react_exports, {
155
156
  defineTypedTable: () => defineTypedTable,
156
157
  drillAnswerOf: () => drillAnswerOf,
157
158
  drillFindingKnob: () => drillFindingKnob,
159
+ duplicateBase: () => duplicateBase,
158
160
  durationText: () => durationText,
159
161
  emptyArchiveLine: () => emptyArchiveLine,
160
162
  emptyPortalArchiveLine: () => emptyPortalArchiveLine,
@@ -256,6 +258,7 @@ __export(react_exports, {
256
258
  removeAppRow: () => removeAppRow,
257
259
  removedChoicesInUse: () => removedChoicesInUse,
258
260
  resolveObjectOrganization: () => resolveObjectOrganization,
261
+ restoreSnapshot: () => restoreSnapshot,
259
262
  richTextPlain: () => richTextPlain,
260
263
  rowFromDocument: () => rowFromDocument,
261
264
  ruleThatRefuses: () => ruleThatRefuses,
@@ -265,6 +268,7 @@ __export(react_exports, {
265
268
  scopeChip: () => scopeChip,
266
269
  sha256Hex: () => sha256Hex2,
267
270
  sheetSyncSpec: () => sheetSyncSpec,
271
+ snapshotBase: () => snapshotBase,
268
272
  sourceArchivedOf: () => sourceArchivedOf,
269
273
  splitListCell: () => splitListCell,
270
274
  splitLockedRows: () => splitLockedRows,
@@ -13347,6 +13351,80 @@ var BUILT_KIND_WORD = {
13347
13351
  checklist: "Checklist"
13348
13352
  };
13349
13353
 
13354
+ // src/base.ts
13355
+ function baseCopyName(name) {
13356
+ return `${name.trim() || "Base"} (copy)`;
13357
+ }
13358
+ async function duplicateBase(port, args) {
13359
+ const made = [];
13360
+ const pairs = {};
13361
+ const notCopied = /* @__PURE__ */ new Set();
13362
+ for (const [i, table] of args.tables.entries()) {
13363
+ const res = await port.tableDuplicate({
13364
+ tableId: table.id,
13365
+ withRecords: args.withRecords,
13366
+ organizationId: args.organizationId,
13367
+ name: args.nameFor ? args.nameFor(table) : table.name,
13368
+ onProgress: (pass) => args.onProgress?.({ at: i + 1, of: args.tables.length, tableName: table.name, pass })
13369
+ });
13370
+ if (!res.ok) return { ok: false, error: res.error, stoppedAt: table, made };
13371
+ pairs[table.id] = res.data.table.id;
13372
+ made.push({ from: table, copy: res.data.table, records: res.data.copied.records });
13373
+ for (const n of res.data.notCopied) notCopied.add(n);
13374
+ }
13375
+ const fin = args.tables.length > 1 ? await port.finish({ organizationId: args.organizationId, pairs }) : null;
13376
+ if (fin && !fin.ok) return { ok: false, error: fin.error, stoppedAt: args.tables[args.tables.length - 1], made };
13377
+ return {
13378
+ ok: true,
13379
+ data: {
13380
+ pairs,
13381
+ tables: made,
13382
+ relinkedColumns: fin?.ok ? fin.data.relinked_columns : 0,
13383
+ relinkedCells: fin?.ok ? fin.data.relinked_cells : 0,
13384
+ notCopied: [...notCopied]
13385
+ }
13386
+ };
13387
+ }
13388
+ async function snapshotBase(port, args) {
13389
+ const copied = await duplicateBase(port, {
13390
+ organizationId: args.organizationId,
13391
+ tables: args.tables,
13392
+ withRecords: true,
13393
+ nameFor: (t) => `Snapshot ${args.label} \xB7 ${t.name}`,
13394
+ ...args.onProgress ? { onProgress: args.onProgress } : {}
13395
+ });
13396
+ if (!copied.ok) {
13397
+ for (const m of copied.made) await port.archive?.(m.copy.id);
13398
+ return { ok: false, error: copied.error, stoppedAt: copied.stoppedAt };
13399
+ }
13400
+ for (const t of copied.data.tables) {
13401
+ const away = await port.archive?.(t.copy.id);
13402
+ if (away && !away.ok) return { ok: false, error: away.error, stoppedAt: t.from };
13403
+ }
13404
+ return {
13405
+ ok: true,
13406
+ snapshot: {
13407
+ label: args.label,
13408
+ origin: args.origin ?? "manual",
13409
+ tables: copied.data.tables.map((t) => ({ table_id: t.from.id, snapshot_table_id: t.copy.id, name: t.from.name, records: t.records }))
13410
+ }
13411
+ };
13412
+ }
13413
+ async function restoreSnapshot(port, args) {
13414
+ const sources = args.snapshot.tables.map((t) => ({ id: t.snapshot_table_id, name: t.name }));
13415
+ const byCopy = new Map(args.snapshot.tables.map((t) => [t.snapshot_table_id, t.name]));
13416
+ for (const s of sources) await port.unarchive?.(s.id);
13417
+ const out = await duplicateBase(port, {
13418
+ organizationId: args.organizationId,
13419
+ tables: sources,
13420
+ withRecords: true,
13421
+ nameFor: (t) => `${byCopy.get(t.id) ?? t.name} (restored)`,
13422
+ ...args.onProgress ? { onProgress: args.onProgress } : {}
13423
+ });
13424
+ for (const s of sources) await port.archive?.(s.id);
13425
+ return out;
13426
+ }
13427
+
13350
13428
  // src/capture-queue.ts
13351
13429
  var DB_NAME = "matrx-capture";
13352
13430
  var DB_VERSION = 1;