@ricsam/formula-engine 0.0.20 → 0.0.22
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/cjs/core/commands/command-executor.cjs +3 -5
- package/dist/cjs/core/commands/command-executor.cjs.map +3 -3
- package/dist/cjs/core/commands/structure-commands.cjs.map +1 -1
- package/dist/cjs/core/commands/table-commands.cjs.map +1 -1
- package/dist/cjs/core/engine.cjs +56 -42
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/{api-schema-manager.cjs → schema-manager.cjs} +10 -7
- package/dist/cjs/core/managers/schema-manager.cjs.map +10 -0
- package/dist/cjs/core/{api → schema}/cell-orm.cjs +2 -2
- package/dist/cjs/core/{api → schema}/cell-orm.cjs.map +2 -2
- package/dist/cjs/core/{api/api-builder.cjs → schema/schema-builder.cjs} +15 -25
- package/dist/cjs/core/schema/schema-builder.cjs.map +10 -0
- package/dist/cjs/core/{api/api-helpers.cjs → schema/schema-helpers.cjs} +5 -5
- package/dist/cjs/core/schema/schema-helpers.cjs.map +10 -0
- package/dist/cjs/core/{api/api.cjs → schema/schema.cjs} +12 -16
- package/dist/cjs/core/schema/schema.cjs.map +10 -0
- package/dist/cjs/core/{api → schema}/table-orm.cjs +19 -19
- package/dist/cjs/core/schema/table-orm.cjs.map +10 -0
- package/dist/cjs/lib.cjs +7 -8
- package/dist/cjs/lib.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/commands/command-executor.mjs +3 -5
- package/dist/mjs/core/commands/command-executor.mjs.map +3 -3
- package/dist/mjs/core/commands/structure-commands.mjs.map +1 -1
- package/dist/mjs/core/commands/table-commands.mjs.map +1 -1
- package/dist/mjs/core/engine.mjs +57 -43
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/{api-schema-manager.mjs → schema-manager.mjs} +7 -4
- package/dist/mjs/core/managers/schema-manager.mjs.map +10 -0
- package/dist/mjs/core/{api → schema}/cell-orm.mjs +2 -2
- package/dist/mjs/core/{api → schema}/cell-orm.mjs.map +2 -2
- package/dist/mjs/core/schema/schema-builder.mjs +27 -0
- package/dist/mjs/core/schema/schema-builder.mjs.map +10 -0
- package/dist/mjs/core/{api/api-helpers.mjs → schema/schema-helpers.mjs} +2 -2
- package/dist/mjs/core/schema/schema-helpers.mjs.map +10 -0
- package/dist/mjs/core/{api/api.mjs → schema/schema.mjs} +9 -13
- package/dist/mjs/core/schema/schema.mjs.map +10 -0
- package/dist/mjs/core/{api → schema}/table-orm.mjs +3 -3
- package/dist/mjs/core/schema/table-orm.mjs.map +10 -0
- package/dist/mjs/lib.mjs +6 -7
- package/dist/mjs/lib.mjs.map +2 -2
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/commands/command-executor.d.ts +1 -3
- package/dist/types/core/commands/structure-commands.d.ts +2 -2
- package/dist/types/core/commands/table-commands.d.ts +2 -2
- package/dist/types/core/engine.d.ts +31 -7
- package/dist/types/core/managers/{api-schema-manager.d.ts → schema-manager.d.ts} +6 -2
- package/dist/types/core/schema/schema-builder.d.ts +16 -0
- package/dist/types/core/{api/api-helpers.d.ts → schema/schema-helpers.d.ts} +1 -1
- package/dist/types/core/schema/schema.d.ts +90 -0
- package/dist/types/core/{api → schema}/table-orm.d.ts +1 -1
- package/dist/types/lib.d.ts +6 -6
- package/package.json +1 -1
- package/dist/cjs/core/api/api-builder.cjs.map +0 -10
- package/dist/cjs/core/api/api-helpers.cjs.map +0 -10
- package/dist/cjs/core/api/api.cjs.map +0 -10
- package/dist/cjs/core/api/table-orm.cjs.map +0 -10
- package/dist/cjs/core/managers/api-schema-manager.cjs.map +0 -10
- package/dist/mjs/core/api/api-builder.mjs +0 -37
- package/dist/mjs/core/api/api-builder.mjs.map +0 -10
- package/dist/mjs/core/api/api-helpers.mjs.map +0 -10
- package/dist/mjs/core/api/api.mjs.map +0 -10
- package/dist/mjs/core/api/table-orm.mjs.map +0 -10
- package/dist/mjs/core/managers/api-schema-manager.mjs.map +0 -10
- package/dist/types/core/api/api-builder.d.ts +0 -16
- package/dist/types/core/api/api.d.ts +0 -83
- /package/dist/types/core/{api → schema}/cell-orm.d.ts +0 -0
- /package/dist/types/core/{api/api.type-test.d.ts → schema/schema.type-test.d.ts} +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/core/schema/schema.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { CellAddress } from \"../types.cjs\";\n\n/**\n * Define a schema for the FormulaEngine.\n *\n * The returned object contains:\n * - `declaration`: The schema definitions for tables and cells\n * - `schema`: A type-only placeholder (undefined at runtime) for TypeScript inference\n *\n * The actual working schema is only available through `engine.schema` after\n * attaching the definition to a FormulaEngine instance.\n *\n * @example\n * ```typescript\n * const mySchema = defineSchema<CellMetadata>()\n * .addTableSchema(\"users\", { workbookName: \"wb1\", tableName: \"users\" }, headers)\n * .addCellSchema(\"config\", cellAddress, parse);\n *\n * const engine = new FormulaEngine(mySchema);\n * engine.schema.users.findWhere({ id: 1 }); // Works!\n * engine.schema.config.read(); // Works!\n * mySchema.schema.users.findWhere({ id: 1 }); // Error: schema is undefined at runtime\n * ```\n */\nexport function defineSchema<\n TCellMetadata = unknown,\n TCurrentSchema extends Record<string, object> = Record<string, object>,\n TCurrentDeclaration extends Record<string, TableSchemaDefinition | CellSchemaDefinition> = Record<\n string,\n TableSchemaDefinition | CellSchemaDefinition\n >\n>(): CreateSchema<TCellMetadata, TCurrentSchema, TCurrentDeclaration> {\n const declaration: Record<string, TableSchemaDefinition | CellSchemaDefinition> = {};\n\n const builder: CreateSchema<TCellMetadata, TCurrentSchema, TCurrentDeclaration> = {\n addTableSchema(namespace, address, headers) {\n declaration[namespace] = {\n type: \"table\",\n tableName: address.tableName,\n workbookName: address.workbookName,\n headers: headers as any,\n };\n return builder as any;\n },\n\n addCellSchema(namespace, cellAddress, parse) {\n declaration[namespace] = {\n type: \"cell\",\n cellAddress,\n parse: parse as any,\n };\n return builder as any;\n },\n\n // schema is undefined at runtime - it only exists for TypeScript type inference\n // The actual working schema is built by the FormulaEngine constructor\n schema: undefined as any as TCurrentSchema,\n\n declaration: declaration as TCurrentDeclaration,\n };\n\n return builder;\n}\n\ntype ParseFunction<TCellMetadata> = (\n value: unknown,\n metadata: TCellMetadata\n) => unknown;\n\nexport interface TableSchemaDefinition {\n type: \"table\";\n headers: Headers<unknown>;\n tableName: string;\n workbookName: string;\n}\n\nexport interface CellSchemaDefinition {\n type: \"cell\";\n cellAddress: CellAddress;\n parse: (value: unknown, metadata: unknown) => unknown;\n}\n\ntype Headers<TCellMetadata> = Record<\n string,\n {\n parse: ParseFunction<TCellMetadata>;\n index: number;\n }\n>;\n\n/**\n * Type representing the TableOrm methods exposed on the schema\n */\nexport type TableOrmSchema<TItem extends Record<string, unknown>> = {\n findWhere(filter: Partial<TItem>): TItem | undefined;\n findAllWhere(filter: Partial<TItem>): TItem[];\n append(item: TItem): TItem;\n updateWhere(filter: Partial<TItem>, update: Partial<TItem>): number;\n removeWhere(filter: Partial<TItem>): number;\n count(): number;\n};\n\n/**\n * Type representing the CellOrm methods exposed on the schema\n */\nexport type CellOrmSchema<TValue> = {\n read(): TValue;\n write(value: TValue): void;\n getAddress(): CellAddress;\n};\n\nexport type SchemaDeclaration = Record<string, TableSchemaDefinition | CellSchemaDefinition>;\nexport type Schema = Record<string, object>;\n\nexport type CreateSchema<\n TCellMetadata,\n TCurrentSchema extends Schema,\n TCurrentDeclaration extends SchemaDeclaration\n> = {\n addTableSchema<T extends string, THeaders extends Headers<TCellMetadata>>(\n namespace: T,\n address: { workbookName: string; tableName: string },\n headers: THeaders\n ): CreateSchema<\n TCellMetadata,\n TCurrentSchema & {\n [K in T]: TableOrmSchema<{\n [H in keyof THeaders]: ReturnType<THeaders[H][\"parse\"]>;\n }>;\n },\n TCurrentDeclaration & {\n [K in T]: {\n type: \"table\";\n tableName: string;\n workbookName: string;\n headers: THeaders;\n };\n }\n >;\n addCellSchema<T extends string, TValue>(\n namespace: T,\n cellAddress: CellAddress,\n parse: (value: unknown, metadata: TCellMetadata) => TValue\n ): CreateSchema<\n TCellMetadata,\n TCurrentSchema & {\n [K in T]: CellOrmSchema<TValue>;\n },\n TCurrentDeclaration & {\n [K in T]: {\n type: \"cell\";\n cellAddress: CellAddress;\n parse: (value: unknown, metadata: unknown) => unknown;\n };\n }\n >;\n schema: TCurrentSchema;\n declaration: TCurrentDeclaration;\n};\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,SAAS,YAOf,GAAqE;AAAA,EACpE,MAAM,cAA4E,CAAC;AAAA,EAEnF,MAAM,UAA4E;AAAA,IAChF,cAAc,CAAC,WAAW,SAAS,SAAS;AAAA,MAC1C,YAAY,aAAa;AAAA,QACvB,MAAM;AAAA,QACN,WAAW,QAAQ;AAAA,QACnB,cAAc,QAAQ;AAAA,QACtB;AAAA,MACF;AAAA,MACA,OAAO;AAAA;AAAA,IAGT,aAAa,CAAC,WAAW,aAAa,OAAO;AAAA,MAC3C,YAAY,aAAa;AAAA,QACvB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACF;AAAA,MACA,OAAO;AAAA;AAAA,IAKT,QAAQ;AAAA,IAER;AAAA,EACF;AAAA,EAEA,OAAO;AAAA;",
|
|
8
|
+
"debugId": "4B8F4F60ED902A2D64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -26,13 +26,13 @@ var __export = (target, all) => {
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
// src/core/
|
|
29
|
+
// src/core/schema/table-orm.ts
|
|
30
30
|
var exports_table_orm = {};
|
|
31
31
|
__export(exports_table_orm, {
|
|
32
32
|
TableOrm: () => TableOrm
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(exports_table_orm);
|
|
35
|
-
var
|
|
35
|
+
var import_schema_helpers = require("./schema-helpers.cjs");
|
|
36
36
|
|
|
37
37
|
class TableOrm {
|
|
38
38
|
engine;
|
|
@@ -59,12 +59,12 @@ class TableOrm {
|
|
|
59
59
|
}
|
|
60
60
|
findWhere(filter) {
|
|
61
61
|
const table = this.getTable();
|
|
62
|
-
for (const { rowIndex, isEmpty } of
|
|
62
|
+
for (const { rowIndex, isEmpty } of import_schema_helpers.iterateTableRows(this.engine, table)) {
|
|
63
63
|
if (isEmpty)
|
|
64
64
|
continue;
|
|
65
65
|
try {
|
|
66
|
-
const item =
|
|
67
|
-
if (
|
|
66
|
+
const item = import_schema_helpers.rowToObject(this.engine, table, rowIndex, this.headers, (cell) => this.engine.getCellMetadata(cell));
|
|
67
|
+
if (import_schema_helpers.matchesFilter(item, filter)) {
|
|
68
68
|
return item;
|
|
69
69
|
}
|
|
70
70
|
} catch {
|
|
@@ -76,12 +76,12 @@ class TableOrm {
|
|
|
76
76
|
findAllWhere(filter) {
|
|
77
77
|
const table = this.getTable();
|
|
78
78
|
const results = [];
|
|
79
|
-
for (const { rowIndex, isEmpty } of
|
|
79
|
+
for (const { rowIndex, isEmpty } of import_schema_helpers.iterateTableRows(this.engine, table)) {
|
|
80
80
|
if (isEmpty)
|
|
81
81
|
continue;
|
|
82
82
|
try {
|
|
83
|
-
const item =
|
|
84
|
-
if (
|
|
83
|
+
const item = import_schema_helpers.rowToObject(this.engine, table, rowIndex, this.headers, (cell) => this.engine.getCellMetadata(cell));
|
|
84
|
+
if (import_schema_helpers.matchesFilter(item, filter)) {
|
|
85
85
|
results.push(item);
|
|
86
86
|
}
|
|
87
87
|
} catch {
|
|
@@ -92,8 +92,8 @@ class TableOrm {
|
|
|
92
92
|
}
|
|
93
93
|
append(item) {
|
|
94
94
|
const table = this.getTable();
|
|
95
|
-
const nextRow =
|
|
96
|
-
const values =
|
|
95
|
+
const nextRow = import_schema_helpers.getNextEmptyRow(this.engine, table);
|
|
96
|
+
const values = import_schema_helpers.objectToRowValues(item, this.headers);
|
|
97
97
|
for (const [colOffset, value] of values) {
|
|
98
98
|
const cellAddress = {
|
|
99
99
|
workbookName: table.workbookName,
|
|
@@ -108,13 +108,13 @@ class TableOrm {
|
|
|
108
108
|
updateWhere(filter, update) {
|
|
109
109
|
const table = this.getTable();
|
|
110
110
|
let updatedCount = 0;
|
|
111
|
-
for (const { rowIndex, isEmpty } of
|
|
111
|
+
for (const { rowIndex, isEmpty } of import_schema_helpers.iterateTableRows(this.engine, table)) {
|
|
112
112
|
if (isEmpty)
|
|
113
113
|
continue;
|
|
114
114
|
try {
|
|
115
|
-
const item =
|
|
116
|
-
if (
|
|
117
|
-
const values =
|
|
115
|
+
const item = import_schema_helpers.rowToObject(this.engine, table, rowIndex, this.headers, (cell) => this.engine.getCellMetadata(cell));
|
|
116
|
+
if (import_schema_helpers.matchesFilter(item, filter)) {
|
|
117
|
+
const values = import_schema_helpers.objectToRowValues(update, this.headers);
|
|
118
118
|
for (const [colOffset, value] of values) {
|
|
119
119
|
const cellAddress = {
|
|
120
120
|
workbookName: table.workbookName,
|
|
@@ -136,12 +136,12 @@ class TableOrm {
|
|
|
136
136
|
const table = this.getTable();
|
|
137
137
|
let removedCount = 0;
|
|
138
138
|
const rowsToRemove = [];
|
|
139
|
-
for (const { rowIndex, isEmpty } of
|
|
139
|
+
for (const { rowIndex, isEmpty } of import_schema_helpers.iterateTableRows(this.engine, table)) {
|
|
140
140
|
if (isEmpty)
|
|
141
141
|
continue;
|
|
142
142
|
try {
|
|
143
|
-
const item =
|
|
144
|
-
if (
|
|
143
|
+
const item = import_schema_helpers.rowToObject(this.engine, table, rowIndex, this.headers, (cell) => this.engine.getCellMetadata(cell));
|
|
144
|
+
if (import_schema_helpers.matchesFilter(item, filter)) {
|
|
145
145
|
rowsToRemove.push(rowIndex);
|
|
146
146
|
}
|
|
147
147
|
} catch {
|
|
@@ -164,8 +164,8 @@ class TableOrm {
|
|
|
164
164
|
}
|
|
165
165
|
count() {
|
|
166
166
|
const table = this.getTable();
|
|
167
|
-
return
|
|
167
|
+
return import_schema_helpers.getTableRowCount(this.engine, table);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
//# debugId=
|
|
171
|
+
//# debugId=42E285D9A0E672C664756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/core/schema/table-orm.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * TableOrm - Object-Relational Mapping for table data\n *\n * Provides CRUD operations for table data with type-safe access.\n * Used as the `this` context for custom table API methods.\n */\n\nimport type { CellAddress, SerializedCellValue, TableDefinition } from \"../types.cjs\";\nimport type { FormulaEngine } from \"../engine.cjs\";\nimport {\n rowToObject,\n objectToRowValues,\n matchesFilter,\n getTableRowCount,\n getNextEmptyRow,\n iterateTableRows,\n type TableSchemaHeaders,\n} from \"./schema-helpers.cjs\";\n\nexport class TableOrm<TItem extends Record<string, unknown>> {\n constructor(\n private engine: FormulaEngine<any, any>,\n private workbookName: string,\n private tableName: string,\n private headers: TableSchemaHeaders,\n private namespace: string\n ) {}\n\n /**\n * Get the table definition from the engine\n */\n private getTable(): TableDefinition {\n const table = this.engine._tableManager.getTable({\n workbookName: this.workbookName,\n name: this.tableName,\n });\n\n if (!table) {\n throw new Error(\n `Table \"${this.tableName}\" not found in workbook \"${this.workbookName}\"`\n );\n }\n\n return table;\n }\n\n /**\n * Find the first row matching the filter\n */\n findWhere(filter: Partial<TItem>): TItem | undefined {\n const table = this.getTable();\n\n for (const { rowIndex, isEmpty } of iterateTableRows(this.engine, table)) {\n if (isEmpty) continue;\n\n try {\n const item = rowToObject<TItem>(\n this.engine,\n table,\n rowIndex,\n this.headers,\n (cell) => this.engine.getCellMetadata(cell)\n );\n\n if (matchesFilter(item, filter)) {\n return item;\n }\n } catch {\n // Skip rows that fail parsing\n continue;\n }\n }\n\n return undefined;\n }\n\n /**\n * Find all rows matching the filter\n */\n findAllWhere(filter: Partial<TItem>): TItem[] {\n const table = this.getTable();\n const results: TItem[] = [];\n\n for (const { rowIndex, isEmpty } of iterateTableRows(this.engine, table)) {\n if (isEmpty) continue;\n\n try {\n const item = rowToObject<TItem>(\n this.engine,\n table,\n rowIndex,\n this.headers,\n (cell) => this.engine.getCellMetadata(cell)\n );\n\n if (matchesFilter(item, filter)) {\n results.push(item);\n }\n } catch {\n // Skip rows that fail parsing\n continue;\n }\n }\n\n return results;\n }\n\n /**\n * Append a new row to the table\n */\n append(item: TItem): TItem {\n const table = this.getTable();\n const nextRow = getNextEmptyRow(this.engine, table);\n const values = objectToRowValues(item, this.headers);\n\n // Write each cell value\n for (const [colOffset, value] of values) {\n const cellAddress: CellAddress = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n colIndex: table.start.colIndex + colOffset,\n rowIndex: nextRow,\n };\n\n this.engine.setCellContent(cellAddress, value);\n }\n\n return item;\n }\n\n /**\n * Update all rows matching the filter\n * Returns the number of rows updated\n */\n updateWhere(filter: Partial<TItem>, update: Partial<TItem>): number {\n const table = this.getTable();\n let updatedCount = 0;\n\n for (const { rowIndex, isEmpty } of iterateTableRows(this.engine, table)) {\n if (isEmpty) continue;\n\n try {\n const item = rowToObject<TItem>(\n this.engine,\n table,\n rowIndex,\n this.headers,\n (cell) => this.engine.getCellMetadata(cell)\n );\n\n if (matchesFilter(item, filter)) {\n // Apply updates\n const values = objectToRowValues(update as TItem, this.headers);\n\n for (const [colOffset, value] of values) {\n const cellAddress: CellAddress = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n colIndex: table.start.colIndex + colOffset,\n rowIndex,\n };\n\n this.engine.setCellContent(cellAddress, value);\n }\n\n updatedCount++;\n }\n } catch {\n // Skip rows that fail parsing\n continue;\n }\n }\n\n return updatedCount;\n }\n\n /**\n * Remove all rows matching the filter\n * Returns the number of rows removed\n */\n removeWhere(filter: Partial<TItem>): number {\n const table = this.getTable();\n let removedCount = 0;\n\n // Collect rows to remove (in reverse order to avoid index shifting issues)\n const rowsToRemove: number[] = [];\n\n for (const { rowIndex, isEmpty } of iterateTableRows(this.engine, table)) {\n if (isEmpty) continue;\n\n try {\n const item = rowToObject<TItem>(\n this.engine,\n table,\n rowIndex,\n this.headers,\n (cell) => this.engine.getCellMetadata(cell)\n );\n\n if (matchesFilter(item, filter)) {\n rowsToRemove.push(rowIndex);\n }\n } catch {\n // Skip rows that fail parsing\n continue;\n }\n }\n\n // Remove rows in reverse order\n for (const rowIndex of rowsToRemove.reverse()) {\n // Clear all cells in the row\n for (const header of Object.values(this.headers)) {\n const cellAddress: CellAddress = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n colIndex: table.start.colIndex + header.index,\n rowIndex,\n };\n\n this.engine.setCellContent(cellAddress, undefined);\n }\n\n removedCount++;\n }\n\n return removedCount;\n }\n\n /**\n * Get the count of data rows in the table\n */\n count(): number {\n const table = this.getTable();\n return getTableRowCount(this.engine, table);\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBO,IARP;AAAA;AAUO,MAAM,SAAgD;AAAA,EAEjD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EALV,WAAW,CACD,QACA,cACA,WACA,SACA,WACR;AAAA,IALQ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAMF,QAAQ,GAAoB;AAAA,IAClC,MAAM,QAAQ,KAAK,OAAO,cAAc,SAAS;AAAA,MAC/C,cAAc,KAAK;AAAA,MACnB,MAAM,KAAK;AAAA,IACb,CAAC;AAAA,IAED,IAAI,CAAC,OAAO;AAAA,MACV,MAAM,IAAI,MACR,UAAU,KAAK,qCAAqC,KAAK,eAC3D;AAAA,IACF;AAAA,IAEA,OAAO;AAAA;AAAA,EAMT,SAAS,CAAC,QAA2C;AAAA,IACnD,MAAM,QAAQ,KAAK,SAAS;AAAA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AEN;AAAA;AAAA,IAEJ;AAAA,IAGA,WAAW,YAAY,aAAa,QAAQ,GAAG;AAAA,MAE7C,WAAW,UAAU,OAAO,OAAO,KAAK,OAAO,GAAG;AAAA,QAChD,MAAM,cAA2B;AAAA,UAC/B,cAAc,MAAM;AAAA,UACpB,WAAW,MAAM;AAAA,UACjB,UAAU,MAAM,MAAM,WAAW,OAAO;AAAA,UACxC;AAAA,QACF;AAAA,QAEA,KAAK,OAAO,eAAe,aAAa,SAAS;AAAA,MACnD;AAAA,MAEA;AAAA,IACF;AAAA,IAEA,OAAO;AAAA;AAAA,EAMT,KAAK,GAAW;AAAA,IACd,MAAM,QAAQ,KAAK,SAAS;AAAA,IAC5B,OAAO,uCAAiB,KAAK,QAAQ,KAAK;AAAA;AAE9C;",
|
|
8
|
+
"debugId": "42E285D9A0E672C664756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/cjs/lib.cjs
CHANGED
|
@@ -46,10 +46,9 @@ var __export = (target, all) => {
|
|
|
46
46
|
// src/lib.ts
|
|
47
47
|
var exports_lib = {};
|
|
48
48
|
__export(exports_lib, {
|
|
49
|
-
|
|
50
|
-
createApi: () => import_api.createApi,
|
|
49
|
+
defineSchema: () => import_schema.defineSchema,
|
|
51
50
|
TableOrm: () => import_table_orm.TableOrm,
|
|
52
|
-
SchemaValidationError: () =>
|
|
51
|
+
SchemaValidationError: () => import_schema_manager.SchemaValidationError,
|
|
53
52
|
SchemaIntegrityError: () => import_command_executor.SchemaIntegrityError,
|
|
54
53
|
FormulaEngine: () => import_engine.FormulaEngine,
|
|
55
54
|
CellOrm: () => import_cell_orm.CellOrm
|
|
@@ -59,10 +58,10 @@ var import_engine = require("./core/engine.cjs");
|
|
|
59
58
|
__reExport(exports_lib, require("./core/types.cjs"), module.exports);
|
|
60
59
|
__reExport(exports_lib, require("./core/utils.cjs"), module.exports);
|
|
61
60
|
__reExport(exports_lib, require("./core/utils/color-utils.cjs"), module.exports);
|
|
62
|
-
var
|
|
63
|
-
var import_table_orm = require("./core/
|
|
64
|
-
var import_cell_orm = require("./core/
|
|
65
|
-
var
|
|
61
|
+
var import_schema = require("./core/schema/schema.cjs");
|
|
62
|
+
var import_table_orm = require("./core/schema/table-orm.cjs");
|
|
63
|
+
var import_cell_orm = require("./core/schema/cell-orm.cjs");
|
|
64
|
+
var import_schema_manager = require("./core/managers/schema-manager.cjs");
|
|
66
65
|
var import_command_executor = require("./core/commands/command-executor.cjs");
|
|
67
66
|
|
|
68
|
-
//# debugId=
|
|
67
|
+
//# debugId=0F275ACDD498695964756E2164756E21
|
package/dist/cjs/lib.cjs.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"export { FormulaEngine } from \"./core/engine.cjs\";\nexport * from \"./core/types.cjs\";\nexport * from \"./core/utils.cjs\";\nexport * from \"./core/utils/color-utils.cjs\";\n\n//
|
|
5
|
+
"export { FormulaEngine } from \"./core/engine.cjs\";\nexport * from \"./core/types.cjs\";\nexport * from \"./core/utils.cjs\";\nexport * from \"./core/utils/color-utils.cjs\";\n\n// Schema exports\nexport { defineSchema } from \"./core/schema/schema.cjs\";\nexport type { CreateSchema, SchemaDeclaration, Schema, TableSchemaDefinition, CellSchemaDefinition, TableOrmSchema, CellOrmSchema } from \"./core/schema/schema.cjs\";\nexport { TableOrm } from \"./core/schema/table-orm.cjs\";\nexport { CellOrm } from \"./core/schema/cell-orm.cjs\";\nexport { SchemaValidationError } from \"./core/managers/schema-manager.cjs\";\nexport type { ValidationResult } from \"./core/managers/schema-manager.cjs\";\n\n// Command Pattern exports\nexport { SchemaIntegrityError } from \"./core/commands/command-executor.cjs\";\nexport type { EngineAction, EngineCommand } from \"./core/commands/types.cjs\";\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA8B,IAA9B;AACA;AACA;AACA;AAG6B,IAA7B;AAEyB,IAAzB;AACwB,IAAxB;AACsC,IAAtC;AAIqC,IAArC;",
|
|
8
|
+
"debugId": "0F275ACDD498695964756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/cjs/package.json
CHANGED
|
@@ -10,15 +10,13 @@ class SchemaIntegrityError extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
class CommandExecutor {
|
|
13
|
-
apiDeclaration;
|
|
14
13
|
evaluationManager;
|
|
15
14
|
eventManager;
|
|
16
15
|
validateAllSchemas;
|
|
17
16
|
undoStack = [];
|
|
18
17
|
redoStack = [];
|
|
19
18
|
actionLog = [];
|
|
20
|
-
constructor(
|
|
21
|
-
this.apiDeclaration = apiDeclaration;
|
|
19
|
+
constructor(evaluationManager, eventManager, validateAllSchemas) {
|
|
22
20
|
this.evaluationManager = evaluationManager;
|
|
23
21
|
this.eventManager = eventManager;
|
|
24
22
|
this.validateAllSchemas = validateAllSchemas;
|
|
@@ -32,7 +30,7 @@ class CommandExecutor {
|
|
|
32
30
|
command.execute();
|
|
33
31
|
if (command.requiresReevaluation) {
|
|
34
32
|
this.evaluationManager.clearEvaluationCache();
|
|
35
|
-
if (validate
|
|
33
|
+
if (validate) {
|
|
36
34
|
const validation = this.validateAllSchemas();
|
|
37
35
|
if (!validation.valid) {
|
|
38
36
|
command.undo();
|
|
@@ -106,4 +104,4 @@ export {
|
|
|
106
104
|
CommandExecutor
|
|
107
105
|
};
|
|
108
106
|
|
|
109
|
-
//# debugId=
|
|
107
|
+
//# debugId=383A6EB14F8F793264756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/core/commands/command-executor.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * CommandExecutor - Executes commands with undo/redo support and schema validation\n *\n * Handles:\n * - Command execution with optional re-evaluation\n * - Schema validation after re-evaluation\n * - Automatic rollback on validation failure\n * - Undo/redo stacks\n * - Action serialization for persistence\n */\n\nimport type {
|
|
5
|
+
"/**\n * CommandExecutor - Executes commands with undo/redo support and schema validation\n *\n * Handles:\n * - Command execution with optional re-evaluation\n * - Schema validation after re-evaluation\n * - Automatic rollback on validation failure\n * - Undo/redo stacks\n * - Action serialization for persistence\n */\n\nimport type { SchemaDeclaration } from \"../schema/schema.mjs\";\nimport type { FormulaEngine } from \"../engine.mjs\";\nimport type { EvaluationManager } from \"../managers/evaluation-manager.mjs\";\nimport type { EventManager } from \"../managers/event-manager.mjs\";\nimport type { CellAddress, SerializedCellValue } from \"../types.mjs\";\nimport type {\n EngineCommand,\n EngineAction,\n ExecuteOptions,\n SchemaValidationResult,\n SchemaValidationErrorInfo,\n} from \"./types.mjs\";\n\n/**\n * Error thrown when schema integrity validation fails.\n * Contains all validation errors that occurred.\n */\nexport class SchemaIntegrityError extends Error {\n constructor(public errors: SchemaValidationErrorInfo[]) {\n const messages = errors.map((e) => e.message).join(\"; \");\n super(`Schema integrity violation: ${messages}`);\n this.name = \"SchemaIntegrityError\";\n }\n}\n\n/**\n * CommandExecutor manages command execution with validation and undo/redo support.\n */\nexport class CommandExecutor {\n private undoStack: EngineCommand[] = [];\n private redoStack: EngineCommand[] = [];\n private actionLog: EngineAction[] = [];\n\n constructor(\n private evaluationManager: EvaluationManager,\n private eventManager: EventManager,\n private validateAllSchemas: () => SchemaValidationResult\n ) {}\n\n /**\n * Execute a command with optional schema validation.\n *\n * @param command - The command to execute\n * @param options - Execution options\n * @throws SchemaIntegrityError if validation fails\n */\n execute(command: EngineCommand, options: ExecuteOptions = {}): void {\n const {\n validate = false,\n skipUndoStack = false,\n skipEmitUpdate = false,\n } = options;\n\n // Execute the command\n command.execute();\n\n // Re-evaluate if needed\n if (command.requiresReevaluation) {\n this.evaluationManager.clearEvaluationCache();\n\n // Validate schemas if requested\n if (validate) {\n const validation = this.validateAllSchemas();\n\n if (!validation.valid) {\n // Rollback: undo the command and re-evaluate\n command.undo();\n this.evaluationManager.clearEvaluationCache();\n throw new SchemaIntegrityError(validation.errors);\n }\n }\n }\n\n // Add to undo stack\n if (!skipUndoStack) {\n this.undoStack.push(command);\n // Clear redo stack on new action\n this.redoStack = [];\n }\n\n // Log the action\n const action = command.toAction();\n action.timestamp = Date.now();\n this.actionLog.push(action);\n\n // Emit update event\n if (!skipEmitUpdate) {\n this.eventManager.emitUpdate();\n }\n }\n\n /**\n * Undo the last command.\n *\n * @returns true if undo was performed, false if nothing to undo\n */\n undo(): boolean {\n const command = this.undoStack.pop();\n if (!command) {\n return false;\n }\n\n command.undo();\n\n if (command.requiresReevaluation) {\n this.evaluationManager.clearEvaluationCache();\n }\n\n this.redoStack.push(command);\n this.eventManager.emitUpdate();\n\n return true;\n }\n\n /**\n * Redo the last undone command.\n *\n * @returns true if redo was performed, false if nothing to redo\n */\n redo(): boolean {\n const command = this.redoStack.pop();\n if (!command) {\n return false;\n }\n\n command.execute();\n\n if (command.requiresReevaluation) {\n this.evaluationManager.clearEvaluationCache();\n }\n\n this.undoStack.push(command);\n this.eventManager.emitUpdate();\n\n return true;\n }\n\n /**\n * Check if undo is available.\n */\n canUndo(): boolean {\n return this.undoStack.length > 0;\n }\n\n /**\n * Check if redo is available.\n */\n canRedo(): boolean {\n return this.redoStack.length > 0;\n }\n\n /**\n * Get the action log for persistence/collaboration.\n */\n getActionLog(): EngineAction[] {\n return [...this.actionLog];\n }\n\n /**\n * Clear the action log.\n */\n clearActionLog(): void {\n this.actionLog = [];\n }\n\n /**\n * Clear undo/redo stacks.\n */\n clearHistory(): void {\n this.undoStack = [];\n this.redoStack = [];\n }\n\n /**\n * Get the number of commands in the undo stack.\n */\n getUndoStackSize(): number {\n return this.undoStack.length;\n }\n\n /**\n * Get the number of commands in the redo stack.\n */\n getRedoStackSize(): number {\n return this.redoStack.length;\n }\n}\n"
|
|
6
6
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EAM3B,cAAc,GAAS;AAAA,IACrB,KAAK,YAAY,CAAC;AAAA;AAAA,EAMpB,YAAY,GAAS;AAAA,IACnB,KAAK,YAAY,CAAC;AAAA,IAClB,KAAK,YAAY,CAAC;AAAA;AAAA,EAMpB,gBAAgB,GAAW;AAAA,IACzB,OAAO,KAAK,UAAU;AAAA;AAAA,EAMxB,gBAAgB,GAAW;AAAA,IACzB,OAAO,KAAK,UAAU;AAAA;AAE1B;",
|
|
8
|
+
"debugId": "383A6EB14F8F793264756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/core/commands/structure-commands.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * Structure Commands - Commands that modify workbook/sheet structure\n *\n * These commands all require re-evaluation after execution.\n */\n\nimport type { ApiSchemaManager } from \"../managers/api-schema-manager.mjs\";\nimport type { NamedExpressionManager } from \"../managers/named-expression-manager.mjs\";\nimport type { ReferenceManager } from \"../managers/reference-manager.mjs\";\nimport type { StyleManager } from \"../managers/style-manager.mjs\";\nimport type { TableManager } from \"../managers/table-manager.mjs\";\nimport type { WorkbookManager } from \"../managers/workbook-manager.mjs\";\nimport type {\n ConditionalStyle,\n DirectCellStyle,\n NamedExpression,\n Sheet,\n TableDefinition,\n Workbook,\n} from \"../types.mjs\";\nimport type { EngineAction, EngineCommand } from \"./types.mjs\";\nimport { ActionTypes } from \"./types.mjs\";\n\n/**\n * Dependencies needed for structure commands.\n */\nexport interface StructureCommandDeps {\n workbookManager: WorkbookManager;\n namedExpressionManager: NamedExpressionManager;\n tableManager: TableManager;\n styleManager: StyleManager;\n referenceManager: ReferenceManager;\n apiSchemaManager: ApiSchemaManager;\n renameSheetInFormula: (opts: {\n formula: string;\n oldSheetName: string;\n newSheetName: string;\n }) => string;\n renameWorkbookInFormula: (opts: {\n formula: string;\n oldWorkbookName: string;\n newWorkbookName: string;\n }) => string;\n}\n\n// ============================================================================\n// Workbook Commands\n// ============================================================================\n\n/**\n * Command to add a workbook.\n */\nexport class AddWorkbookCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n\n constructor(\n private deps: StructureCommandDeps,\n private workbookName: string\n ) {}\n\n execute(): void {\n this.deps.workbookManager.addWorkbook(this.workbookName);\n this.deps.namedExpressionManager.addWorkbook(this.workbookName);\n this.deps.tableManager.addWorkbook(this.workbookName);\n }\n\n undo(): void {\n this.deps.workbookManager.removeWorkbook(this.workbookName);\n this.deps.namedExpressionManager.removeWorkbook(this.workbookName);\n this.deps.tableManager.removeWorkbook(this.workbookName);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.ADD_WORKBOOK,\n payload: { workbookName: this.workbookName },\n };\n }\n}\n\n/**\n * Captured state of a workbook for undo purposes.\n */\ninterface WorkbookSnapshot {\n workbook: Workbook;\n namedExpressions: {\n workbookLevel: Map<string, NamedExpression>;\n sheetLevel: Map<string, Map<string, NamedExpression>>;\n };\n tables: Map<string, TableDefinition>;\n conditionalStyles: ConditionalStyle[];\n cellStyles: DirectCellStyle[];\n}\n\n/**\n * Capture the full state of a workbook for later restoration.\n */\nfunction captureWorkbookSnapshot(\n deps: StructureCommandDeps,\n workbookName: string\n): WorkbookSnapshot | undefined {\n const workbook = deps.workbookManager.getWorkbooks().get(workbookName);\n if (!workbook) return undefined;\n\n // Deep clone workbook sheets\n const clonedSheets = new Map<string, Sheet>();\n for (const [name, sheet] of workbook.sheets) {\n clonedSheets.set(name, {\n name: sheet.name,\n index: sheet.index,\n content: new Map(sheet.content),\n metadata: new Map(sheet.metadata),\n sheetMetadata: sheet.sheetMetadata,\n });\n }\n\n const namedExpressions = deps.namedExpressionManager.getNamedExpressions();\n\n const snapshot: WorkbookSnapshot = {\n workbook: {\n name: workbook.name,\n sheets: clonedSheets,\n workbookMetadata: workbook.workbookMetadata,\n },\n namedExpressions: {\n workbookLevel: new Map(\n namedExpressions.workbookExpressions.get(workbookName) || []\n ),\n sheetLevel: new Map(),\n },\n tables: new Map(deps.tableManager.getTables(workbookName)),\n conditionalStyles: deps.styleManager\n .getAllConditionalStyles()\n .filter((s) => s.areas.some((a) => a.workbookName === workbookName)),\n cellStyles: deps.styleManager\n .getAllCellStyles()\n .filter((s) => s.areas.some((a) => a.workbookName === workbookName)),\n };\n\n // Capture sheet-level named expressions\n const sheetExpressions = namedExpressions.sheetExpressions.get(workbookName);\n if (sheetExpressions) {\n for (const [sheetName, expressions] of sheetExpressions) {\n snapshot.namedExpressions.sheetLevel.set(sheetName, new Map(expressions));\n }\n }\n\n return snapshot;\n}\n\n/**\n * Remove a workbook and all its associated data.\n */\nfunction removeWorkbook(\n deps: StructureCommandDeps,\n workbookName: string\n): void {\n deps.workbookManager.removeWorkbook(workbookName);\n deps.namedExpressionManager.removeWorkbook(workbookName);\n deps.tableManager.removeWorkbook(workbookName);\n deps.styleManager.removeWorkbookStyles(workbookName);\n deps.referenceManager.invalidateWorkbook(workbookName);\n}\n\n/**\n * Rename a workbook across all managers.\n */\nfunction renameWorkbookAcrossManagers(\n deps: StructureCommandDeps,\n oldName: string,\n newName: string\n): void {\n deps.workbookManager.renameWorkbook({\n workbookName: oldName,\n newWorkbookName: newName,\n });\n deps.namedExpressionManager.renameWorkbook({\n workbookName: oldName,\n newWorkbookName: newName,\n });\n deps.tableManager.updateTablesForWorkbookRename({\n workbookName: oldName,\n newWorkbookName: newName,\n });\n deps.styleManager.updateWorkbookName(oldName, newName);\n deps.workbookManager.updateAllFormulas((formula) =>\n deps.renameWorkbookInFormula({\n formula,\n oldWorkbookName: oldName,\n newWorkbookName: newName,\n })\n );\n deps.referenceManager.updateWorkbookName(oldName, newName);\n deps.apiSchemaManager.updateForWorkbookRename(oldName, newName);\n}\n\n/**\n * Rename a sheet across all managers.\n */\nfunction renameSheetAcrossManagers(\n deps: StructureCommandDeps,\n opts: { workbookName: string; sheetName: string; newSheetName: string }\n): void {\n deps.workbookManager.renameSheet(opts);\n deps.namedExpressionManager.renameSheet(opts);\n deps.tableManager.updateTablesForSheetRename(opts);\n deps.styleManager.updateSheetName(\n opts.workbookName,\n opts.sheetName,\n opts.newSheetName\n );\n deps.workbookManager.updateAllFormulas((formula) =>\n deps.renameSheetInFormula({\n formula,\n oldSheetName: opts.sheetName,\n newSheetName: opts.newSheetName,\n })\n );\n deps.referenceManager.updateSheetName(\n opts.workbookName,\n opts.sheetName,\n opts.newSheetName\n );\n deps.apiSchemaManager.updateForSheetRename(\n opts.workbookName,\n opts.sheetName,\n opts.newSheetName\n );\n}\n\n/**\n * Restore tables from a snapshot.\n */\nfunction restoreTables(\n tableManager: TableManager,\n tables: Map<string, TableDefinition>,\n workbookName: string\n): void {\n for (const [tableName, table] of tables) {\n tableManager.addTable({\n workbookName,\n tableName,\n sheetName: table.sheetName,\n start: `${String.fromCharCode(65 + table.start.colIndex)}${\n table.start.rowIndex + 1\n }`,\n numRows: table.endRow,\n numCols: table.headers.size,\n getCellValue: () => undefined,\n });\n }\n}\n\n/**\n * Restore styles from a snapshot.\n */\nfunction restoreStyles(\n styleManager: StyleManager,\n conditionalStyles: ConditionalStyle[],\n cellStyles: DirectCellStyle[]\n): void {\n for (const style of conditionalStyles) {\n styleManager.addConditionalStyle(style);\n }\n for (const style of cellStyles) {\n styleManager.addCellStyle(style);\n }\n}\n\n/**\n * Command to remove a workbook.\n */\nexport class RemoveWorkbookCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n private snapshot: WorkbookSnapshot | undefined;\n\n constructor(\n private deps: StructureCommandDeps,\n private workbookName: string\n ) {}\n\n execute(): void {\n this.snapshot = captureWorkbookSnapshot(this.deps, this.workbookName);\n removeWorkbook(this.deps, this.workbookName);\n }\n\n undo(): void {\n if (!this.snapshot) return;\n\n // Restore workbook structure\n this.deps.workbookManager.addWorkbook(this.workbookName);\n this.deps.namedExpressionManager.addWorkbook(this.workbookName);\n this.deps.tableManager.addWorkbook(this.workbookName);\n\n // Restore sheets\n for (const [sheetName, sheet] of this.snapshot.workbook.sheets) {\n this.deps.workbookManager.addSheet({\n workbookName: this.workbookName,\n sheetName,\n });\n this.deps.namedExpressionManager.addSheet({\n workbookName: this.workbookName,\n sheetName,\n });\n this.deps.workbookManager.setSheetContent(\n { workbookName: this.workbookName, sheetName },\n sheet.content\n );\n }\n\n // Restore named expressions\n for (const [name, expr] of this.snapshot.namedExpressions.workbookLevel) {\n this.deps.namedExpressionManager.addNamedExpression({\n expressionName: name,\n expression: expr.expression,\n workbookName: this.workbookName,\n });\n }\n for (const [sheetName, expressions] of this.snapshot.namedExpressions.sheetLevel) {\n for (const [name, expr] of expressions) {\n this.deps.namedExpressionManager.addNamedExpression({\n expressionName: name,\n expression: expr.expression,\n workbookName: this.workbookName,\n sheetName,\n });\n }\n }\n\n // Restore tables and styles\n restoreTables(this.deps.tableManager, this.snapshot.tables, this.workbookName);\n restoreStyles(this.deps.styleManager, this.snapshot.conditionalStyles, this.snapshot.cellStyles);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.REMOVE_WORKBOOK,\n payload: { workbookName: this.workbookName },\n };\n }\n}\n\n/**\n * Command to rename a workbook.\n */\nexport class RenameWorkbookCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n\n constructor(\n private deps: StructureCommandDeps,\n private workbookName: string,\n private newWorkbookName: string\n ) {}\n\n execute(): void {\n renameWorkbookAcrossManagers(this.deps, this.workbookName, this.newWorkbookName);\n }\n\n undo(): void {\n renameWorkbookAcrossManagers(this.deps, this.newWorkbookName, this.workbookName);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.RENAME_WORKBOOK,\n payload: {\n workbookName: this.workbookName,\n newWorkbookName: this.newWorkbookName,\n },\n };\n }\n}\n\n/**\n * Command to clone a workbook.\n * Undo simply removes the cloned workbook.\n */\nexport class CloneWorkbookCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n\n constructor(\n private deps: StructureCommandDeps,\n private fromWorkbookName: string,\n private toWorkbookName: string\n ) {}\n\n execute(): void {\n const {\n workbookManager,\n namedExpressionManager,\n tableManager,\n styleManager,\n renameWorkbookInFormula,\n } = this.deps;\n\n // Check if source workbook exists\n const sourceWorkbook = workbookManager\n .getWorkbooks()\n .get(this.fromWorkbookName);\n if (!sourceWorkbook) {\n throw new Error(`Source workbook \"${this.fromWorkbookName}\" not found`);\n }\n\n // Check if target workbook name already exists\n if (workbookManager.getWorkbooks().has(this.toWorkbookName)) {\n throw new Error(\n `Target workbook \"${this.toWorkbookName}\" already exists`\n );\n }\n\n // Create new workbook\n workbookManager.addWorkbook(this.toWorkbookName);\n namedExpressionManager.addWorkbook(this.toWorkbookName);\n tableManager.addWorkbook(this.toWorkbookName);\n\n // Clone all sheets from source workbook\n for (const [sheetName, sheet] of sourceWorkbook.sheets) {\n // Add sheet to target workbook\n workbookManager.addSheet({\n workbookName: this.toWorkbookName,\n sheetName: sheetName,\n });\n namedExpressionManager.addSheet({\n workbookName: this.toWorkbookName,\n sheetName: sheetName,\n });\n\n // Copy all cell content\n workbookManager.setSheetContent(\n { workbookName: this.toWorkbookName, sheetName: sheetName },\n new Map(sheet.content)\n );\n\n // Copy all cell metadata\n const targetSheet = workbookManager.getSheet({\n workbookName: this.toWorkbookName,\n sheetName: sheetName,\n });\n if (targetSheet) {\n targetSheet.metadata = new Map(sheet.metadata);\n\n // Copy sheet metadata\n if (sheet.sheetMetadata !== undefined) {\n targetSheet.sheetMetadata = structuredClone(sheet.sheetMetadata);\n }\n }\n }\n\n // Copy workbook metadata\n const targetWorkbook = workbookManager\n .getWorkbooks()\n .get(this.toWorkbookName);\n if (targetWorkbook && sourceWorkbook.workbookMetadata !== undefined) {\n targetWorkbook.workbookMetadata = structuredClone(\n sourceWorkbook.workbookMetadata\n );\n }\n\n // Clone workbook-scoped named expressions\n const allExpressions = namedExpressionManager.getNamedExpressions();\n const sourceWorkbookExpressions = allExpressions.workbookExpressions.get(\n this.fromWorkbookName\n );\n if (sourceWorkbookExpressions) {\n for (const [expressionName, expression] of sourceWorkbookExpressions) {\n namedExpressionManager.addNamedExpression({\n expressionName,\n expression: expression.expression,\n workbookName: this.toWorkbookName,\n });\n }\n }\n\n // Clone sheet-scoped named expressions\n const sourceSheetExpressions = allExpressions.sheetExpressions.get(\n this.fromWorkbookName\n );\n if (sourceSheetExpressions) {\n for (const [sheetName, sheetExpressions] of sourceSheetExpressions) {\n for (const [expressionName, expression] of sheetExpressions) {\n namedExpressionManager.addNamedExpression({\n expressionName,\n expression: expression.expression,\n workbookName: this.toWorkbookName,\n sheetName,\n });\n }\n }\n }\n\n // Clone tables\n const sourceTables = tableManager.tables.get(this.fromWorkbookName);\n if (sourceTables) {\n for (const [tableName] of sourceTables) {\n tableManager.copyTable(\n { workbookName: this.fromWorkbookName, tableName },\n { workbookName: this.toWorkbookName, tableName }\n );\n }\n }\n\n // Clone conditional styles\n const allConditionalStyles = styleManager.getAllConditionalStyles();\n for (const style of allConditionalStyles) {\n if (\n style.areas.some((area) => area.workbookName === this.fromWorkbookName)\n ) {\n const newStyle: ConditionalStyle = {\n ...style,\n areas: style.areas.map((area) =>\n area.workbookName === this.fromWorkbookName\n ? { ...area, workbookName: this.toWorkbookName }\n : area\n ),\n };\n styleManager.addConditionalStyle(newStyle);\n }\n }\n\n // Clone cell styles\n const allCellStyles = styleManager.getAllCellStyles();\n for (const style of allCellStyles) {\n if (\n style.areas.some((area) => area.workbookName === this.fromWorkbookName)\n ) {\n const newStyle: DirectCellStyle = {\n ...style,\n areas: style.areas.map((area) =>\n area.workbookName === this.fromWorkbookName\n ? { ...area, workbookName: this.toWorkbookName }\n : area\n ),\n };\n styleManager.addCellStyle(newStyle);\n }\n }\n\n // Update formulas in cloned workbook that reference the source workbook\n workbookManager.updateFormulasForWorkbook(this.toWorkbookName, (formula) =>\n renameWorkbookInFormula({\n formula,\n oldWorkbookName: this.fromWorkbookName,\n newWorkbookName: this.toWorkbookName,\n })\n );\n }\n\n undo(): void {\n // Undo clone = remove the cloned workbook\n removeWorkbook(this.deps, this.toWorkbookName);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.CLONE_WORKBOOK,\n payload: {\n fromWorkbookName: this.fromWorkbookName,\n toWorkbookName: this.toWorkbookName,\n },\n };\n }\n}\n\n// ============================================================================\n// Sheet Commands\n// ============================================================================\n\n/**\n * Command to add a sheet.\n */\nexport class AddSheetCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n\n constructor(\n private deps: StructureCommandDeps,\n private opts: { workbookName: string; sheetName: string }\n ) {}\n\n execute(): void {\n this.deps.workbookManager.addSheet(this.opts);\n this.deps.namedExpressionManager.addSheet(this.opts);\n }\n\n undo(): void {\n this.deps.workbookManager.removeSheet(this.opts);\n this.deps.namedExpressionManager.removeSheet(this.opts);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.ADD_SHEET,\n payload: this.opts,\n };\n }\n}\n\n/**\n * Captured state of a sheet for undo purposes.\n */\ninterface SheetSnapshot {\n sheet: Sheet;\n namedExpressions: Map<string, NamedExpression>;\n tables: Map<string, TableDefinition>;\n conditionalStyles: ConditionalStyle[];\n cellStyles: DirectCellStyle[];\n}\n\n/**\n * Command to remove a sheet.\n */\nexport class RemoveSheetCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n private snapshot: SheetSnapshot | undefined;\n\n constructor(\n private deps: StructureCommandDeps,\n private opts: { workbookName: string; sheetName: string }\n ) {}\n\n execute(): void {\n // Capture sheet state before removal\n const sheet = this.deps.workbookManager.getSheet(this.opts);\n if (sheet) {\n const namedExpressions =\n this.deps.namedExpressionManager.getNamedExpressions();\n const sheetExpressions =\n namedExpressions.sheetExpressions\n .get(this.opts.workbookName)\n ?.get(this.opts.sheetName) || new Map();\n\n // Get tables on this sheet\n const allTables = this.deps.tableManager.getTables(\n this.opts.workbookName\n );\n const sheetTables = new Map<string, TableDefinition>();\n for (const [name, table] of allTables) {\n if (table.sheetName === this.opts.sheetName) {\n sheetTables.set(name, table);\n }\n }\n\n this.snapshot = {\n sheet: {\n name: sheet.name,\n index: sheet.index,\n content: new Map(sheet.content),\n metadata: new Map(sheet.metadata),\n sheetMetadata: sheet.sheetMetadata,\n },\n namedExpressions: new Map(sheetExpressions),\n tables: sheetTables,\n conditionalStyles: this.deps.styleManager\n .getAllConditionalStyles()\n .filter((s) =>\n s.areas.some(\n (a) =>\n a.workbookName === this.opts.workbookName &&\n a.sheetName === this.opts.sheetName\n )\n ),\n cellStyles: this.deps.styleManager\n .getAllCellStyles()\n .filter((s) =>\n s.areas.some(\n (a) =>\n a.workbookName === this.opts.workbookName &&\n a.sheetName === this.opts.sheetName\n )\n ),\n };\n }\n\n // Execute removal\n this.deps.workbookManager.removeSheet(this.opts);\n this.deps.namedExpressionManager.removeSheet(this.opts);\n this.deps.tableManager.removeSheet(this.opts);\n this.deps.styleManager.removeSheetStyles(\n this.opts.workbookName,\n this.opts.sheetName\n );\n this.deps.referenceManager.invalidateSheet(\n this.opts.workbookName,\n this.opts.sheetName\n );\n }\n\n undo(): void {\n if (!this.snapshot) return;\n\n // Restore sheet structure\n this.deps.workbookManager.addSheet(this.opts);\n this.deps.namedExpressionManager.addSheet(this.opts);\n this.deps.workbookManager.setSheetContent(this.opts, this.snapshot.sheet.content);\n\n // Restore named expressions\n for (const [name, expr] of this.snapshot.namedExpressions) {\n this.deps.namedExpressionManager.addNamedExpression({\n expressionName: name,\n expression: expr.expression,\n workbookName: this.opts.workbookName,\n sheetName: this.opts.sheetName,\n });\n }\n\n // Restore tables and styles\n restoreTables(this.deps.tableManager, this.snapshot.tables, this.opts.workbookName);\n restoreStyles(this.deps.styleManager, this.snapshot.conditionalStyles, this.snapshot.cellStyles);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.REMOVE_SHEET,\n payload: this.opts,\n };\n }\n}\n\n/**\n * Command to rename a sheet.\n */\nexport class RenameSheetCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n\n constructor(\n private deps: StructureCommandDeps,\n private opts: {\n workbookName: string;\n sheetName: string;\n newSheetName: string;\n }\n ) {}\n\n execute(): void {\n renameSheetAcrossManagers(this.deps, this.opts);\n }\n\n undo(): void {\n renameSheetAcrossManagers(this.deps, {\n workbookName: this.opts.workbookName,\n sheetName: this.opts.newSheetName,\n newSheetName: this.opts.sheetName,\n });\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.RENAME_SHEET,\n payload: this.opts,\n };\n }\n}\n"
|
|
5
|
+
"/**\n * Structure Commands - Commands that modify workbook/sheet structure\n *\n * These commands all require re-evaluation after execution.\n */\n\nimport type { SchemaManager } from \"../managers/schema-manager.mjs\";\nimport type { NamedExpressionManager } from \"../managers/named-expression-manager.mjs\";\nimport type { ReferenceManager } from \"../managers/reference-manager.mjs\";\nimport type { StyleManager } from \"../managers/style-manager.mjs\";\nimport type { TableManager } from \"../managers/table-manager.mjs\";\nimport type { WorkbookManager } from \"../managers/workbook-manager.mjs\";\nimport type {\n ConditionalStyle,\n DirectCellStyle,\n NamedExpression,\n Sheet,\n TableDefinition,\n Workbook,\n} from \"../types.mjs\";\nimport type { EngineAction, EngineCommand } from \"./types.mjs\";\nimport { ActionTypes } from \"./types.mjs\";\n\n/**\n * Dependencies needed for structure commands.\n */\nexport interface StructureCommandDeps {\n workbookManager: WorkbookManager;\n namedExpressionManager: NamedExpressionManager;\n tableManager: TableManager;\n styleManager: StyleManager;\n referenceManager: ReferenceManager;\n apiSchemaManager: SchemaManager;\n renameSheetInFormula: (opts: {\n formula: string;\n oldSheetName: string;\n newSheetName: string;\n }) => string;\n renameWorkbookInFormula: (opts: {\n formula: string;\n oldWorkbookName: string;\n newWorkbookName: string;\n }) => string;\n}\n\n// ============================================================================\n// Workbook Commands\n// ============================================================================\n\n/**\n * Command to add a workbook.\n */\nexport class AddWorkbookCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n\n constructor(\n private deps: StructureCommandDeps,\n private workbookName: string\n ) {}\n\n execute(): void {\n this.deps.workbookManager.addWorkbook(this.workbookName);\n this.deps.namedExpressionManager.addWorkbook(this.workbookName);\n this.deps.tableManager.addWorkbook(this.workbookName);\n }\n\n undo(): void {\n this.deps.workbookManager.removeWorkbook(this.workbookName);\n this.deps.namedExpressionManager.removeWorkbook(this.workbookName);\n this.deps.tableManager.removeWorkbook(this.workbookName);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.ADD_WORKBOOK,\n payload: { workbookName: this.workbookName },\n };\n }\n}\n\n/**\n * Captured state of a workbook for undo purposes.\n */\ninterface WorkbookSnapshot {\n workbook: Workbook;\n namedExpressions: {\n workbookLevel: Map<string, NamedExpression>;\n sheetLevel: Map<string, Map<string, NamedExpression>>;\n };\n tables: Map<string, TableDefinition>;\n conditionalStyles: ConditionalStyle[];\n cellStyles: DirectCellStyle[];\n}\n\n/**\n * Capture the full state of a workbook for later restoration.\n */\nfunction captureWorkbookSnapshot(\n deps: StructureCommandDeps,\n workbookName: string\n): WorkbookSnapshot | undefined {\n const workbook = deps.workbookManager.getWorkbooks().get(workbookName);\n if (!workbook) return undefined;\n\n // Deep clone workbook sheets\n const clonedSheets = new Map<string, Sheet>();\n for (const [name, sheet] of workbook.sheets) {\n clonedSheets.set(name, {\n name: sheet.name,\n index: sheet.index,\n content: new Map(sheet.content),\n metadata: new Map(sheet.metadata),\n sheetMetadata: sheet.sheetMetadata,\n });\n }\n\n const namedExpressions = deps.namedExpressionManager.getNamedExpressions();\n\n const snapshot: WorkbookSnapshot = {\n workbook: {\n name: workbook.name,\n sheets: clonedSheets,\n workbookMetadata: workbook.workbookMetadata,\n },\n namedExpressions: {\n workbookLevel: new Map(\n namedExpressions.workbookExpressions.get(workbookName) || []\n ),\n sheetLevel: new Map(),\n },\n tables: new Map(deps.tableManager.getTables(workbookName)),\n conditionalStyles: deps.styleManager\n .getAllConditionalStyles()\n .filter((s) => s.areas.some((a) => a.workbookName === workbookName)),\n cellStyles: deps.styleManager\n .getAllCellStyles()\n .filter((s) => s.areas.some((a) => a.workbookName === workbookName)),\n };\n\n // Capture sheet-level named expressions\n const sheetExpressions = namedExpressions.sheetExpressions.get(workbookName);\n if (sheetExpressions) {\n for (const [sheetName, expressions] of sheetExpressions) {\n snapshot.namedExpressions.sheetLevel.set(sheetName, new Map(expressions));\n }\n }\n\n return snapshot;\n}\n\n/**\n * Remove a workbook and all its associated data.\n */\nfunction removeWorkbook(\n deps: StructureCommandDeps,\n workbookName: string\n): void {\n deps.workbookManager.removeWorkbook(workbookName);\n deps.namedExpressionManager.removeWorkbook(workbookName);\n deps.tableManager.removeWorkbook(workbookName);\n deps.styleManager.removeWorkbookStyles(workbookName);\n deps.referenceManager.invalidateWorkbook(workbookName);\n}\n\n/**\n * Rename a workbook across all managers.\n */\nfunction renameWorkbookAcrossManagers(\n deps: StructureCommandDeps,\n oldName: string,\n newName: string\n): void {\n deps.workbookManager.renameWorkbook({\n workbookName: oldName,\n newWorkbookName: newName,\n });\n deps.namedExpressionManager.renameWorkbook({\n workbookName: oldName,\n newWorkbookName: newName,\n });\n deps.tableManager.updateTablesForWorkbookRename({\n workbookName: oldName,\n newWorkbookName: newName,\n });\n deps.styleManager.updateWorkbookName(oldName, newName);\n deps.workbookManager.updateAllFormulas((formula) =>\n deps.renameWorkbookInFormula({\n formula,\n oldWorkbookName: oldName,\n newWorkbookName: newName,\n })\n );\n deps.referenceManager.updateWorkbookName(oldName, newName);\n deps.apiSchemaManager.updateForWorkbookRename(oldName, newName);\n}\n\n/**\n * Rename a sheet across all managers.\n */\nfunction renameSheetAcrossManagers(\n deps: StructureCommandDeps,\n opts: { workbookName: string; sheetName: string; newSheetName: string }\n): void {\n deps.workbookManager.renameSheet(opts);\n deps.namedExpressionManager.renameSheet(opts);\n deps.tableManager.updateTablesForSheetRename(opts);\n deps.styleManager.updateSheetName(\n opts.workbookName,\n opts.sheetName,\n opts.newSheetName\n );\n deps.workbookManager.updateAllFormulas((formula) =>\n deps.renameSheetInFormula({\n formula,\n oldSheetName: opts.sheetName,\n newSheetName: opts.newSheetName,\n })\n );\n deps.referenceManager.updateSheetName(\n opts.workbookName,\n opts.sheetName,\n opts.newSheetName\n );\n deps.apiSchemaManager.updateForSheetRename(\n opts.workbookName,\n opts.sheetName,\n opts.newSheetName\n );\n}\n\n/**\n * Restore tables from a snapshot.\n */\nfunction restoreTables(\n tableManager: TableManager,\n tables: Map<string, TableDefinition>,\n workbookName: string\n): void {\n for (const [tableName, table] of tables) {\n tableManager.addTable({\n workbookName,\n tableName,\n sheetName: table.sheetName,\n start: `${String.fromCharCode(65 + table.start.colIndex)}${\n table.start.rowIndex + 1\n }`,\n numRows: table.endRow,\n numCols: table.headers.size,\n getCellValue: () => undefined,\n });\n }\n}\n\n/**\n * Restore styles from a snapshot.\n */\nfunction restoreStyles(\n styleManager: StyleManager,\n conditionalStyles: ConditionalStyle[],\n cellStyles: DirectCellStyle[]\n): void {\n for (const style of conditionalStyles) {\n styleManager.addConditionalStyle(style);\n }\n for (const style of cellStyles) {\n styleManager.addCellStyle(style);\n }\n}\n\n/**\n * Command to remove a workbook.\n */\nexport class RemoveWorkbookCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n private snapshot: WorkbookSnapshot | undefined;\n\n constructor(\n private deps: StructureCommandDeps,\n private workbookName: string\n ) {}\n\n execute(): void {\n this.snapshot = captureWorkbookSnapshot(this.deps, this.workbookName);\n removeWorkbook(this.deps, this.workbookName);\n }\n\n undo(): void {\n if (!this.snapshot) return;\n\n // Restore workbook structure\n this.deps.workbookManager.addWorkbook(this.workbookName);\n this.deps.namedExpressionManager.addWorkbook(this.workbookName);\n this.deps.tableManager.addWorkbook(this.workbookName);\n\n // Restore sheets\n for (const [sheetName, sheet] of this.snapshot.workbook.sheets) {\n this.deps.workbookManager.addSheet({\n workbookName: this.workbookName,\n sheetName,\n });\n this.deps.namedExpressionManager.addSheet({\n workbookName: this.workbookName,\n sheetName,\n });\n this.deps.workbookManager.setSheetContent(\n { workbookName: this.workbookName, sheetName },\n sheet.content\n );\n }\n\n // Restore named expressions\n for (const [name, expr] of this.snapshot.namedExpressions.workbookLevel) {\n this.deps.namedExpressionManager.addNamedExpression({\n expressionName: name,\n expression: expr.expression,\n workbookName: this.workbookName,\n });\n }\n for (const [sheetName, expressions] of this.snapshot.namedExpressions.sheetLevel) {\n for (const [name, expr] of expressions) {\n this.deps.namedExpressionManager.addNamedExpression({\n expressionName: name,\n expression: expr.expression,\n workbookName: this.workbookName,\n sheetName,\n });\n }\n }\n\n // Restore tables and styles\n restoreTables(this.deps.tableManager, this.snapshot.tables, this.workbookName);\n restoreStyles(this.deps.styleManager, this.snapshot.conditionalStyles, this.snapshot.cellStyles);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.REMOVE_WORKBOOK,\n payload: { workbookName: this.workbookName },\n };\n }\n}\n\n/**\n * Command to rename a workbook.\n */\nexport class RenameWorkbookCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n\n constructor(\n private deps: StructureCommandDeps,\n private workbookName: string,\n private newWorkbookName: string\n ) {}\n\n execute(): void {\n renameWorkbookAcrossManagers(this.deps, this.workbookName, this.newWorkbookName);\n }\n\n undo(): void {\n renameWorkbookAcrossManagers(this.deps, this.newWorkbookName, this.workbookName);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.RENAME_WORKBOOK,\n payload: {\n workbookName: this.workbookName,\n newWorkbookName: this.newWorkbookName,\n },\n };\n }\n}\n\n/**\n * Command to clone a workbook.\n * Undo simply removes the cloned workbook.\n */\nexport class CloneWorkbookCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n\n constructor(\n private deps: StructureCommandDeps,\n private fromWorkbookName: string,\n private toWorkbookName: string\n ) {}\n\n execute(): void {\n const {\n workbookManager,\n namedExpressionManager,\n tableManager,\n styleManager,\n renameWorkbookInFormula,\n } = this.deps;\n\n // Check if source workbook exists\n const sourceWorkbook = workbookManager\n .getWorkbooks()\n .get(this.fromWorkbookName);\n if (!sourceWorkbook) {\n throw new Error(`Source workbook \"${this.fromWorkbookName}\" not found`);\n }\n\n // Check if target workbook name already exists\n if (workbookManager.getWorkbooks().has(this.toWorkbookName)) {\n throw new Error(\n `Target workbook \"${this.toWorkbookName}\" already exists`\n );\n }\n\n // Create new workbook\n workbookManager.addWorkbook(this.toWorkbookName);\n namedExpressionManager.addWorkbook(this.toWorkbookName);\n tableManager.addWorkbook(this.toWorkbookName);\n\n // Clone all sheets from source workbook\n for (const [sheetName, sheet] of sourceWorkbook.sheets) {\n // Add sheet to target workbook\n workbookManager.addSheet({\n workbookName: this.toWorkbookName,\n sheetName: sheetName,\n });\n namedExpressionManager.addSheet({\n workbookName: this.toWorkbookName,\n sheetName: sheetName,\n });\n\n // Copy all cell content\n workbookManager.setSheetContent(\n { workbookName: this.toWorkbookName, sheetName: sheetName },\n new Map(sheet.content)\n );\n\n // Copy all cell metadata\n const targetSheet = workbookManager.getSheet({\n workbookName: this.toWorkbookName,\n sheetName: sheetName,\n });\n if (targetSheet) {\n targetSheet.metadata = new Map(sheet.metadata);\n\n // Copy sheet metadata\n if (sheet.sheetMetadata !== undefined) {\n targetSheet.sheetMetadata = structuredClone(sheet.sheetMetadata);\n }\n }\n }\n\n // Copy workbook metadata\n const targetWorkbook = workbookManager\n .getWorkbooks()\n .get(this.toWorkbookName);\n if (targetWorkbook && sourceWorkbook.workbookMetadata !== undefined) {\n targetWorkbook.workbookMetadata = structuredClone(\n sourceWorkbook.workbookMetadata\n );\n }\n\n // Clone workbook-scoped named expressions\n const allExpressions = namedExpressionManager.getNamedExpressions();\n const sourceWorkbookExpressions = allExpressions.workbookExpressions.get(\n this.fromWorkbookName\n );\n if (sourceWorkbookExpressions) {\n for (const [expressionName, expression] of sourceWorkbookExpressions) {\n namedExpressionManager.addNamedExpression({\n expressionName,\n expression: expression.expression,\n workbookName: this.toWorkbookName,\n });\n }\n }\n\n // Clone sheet-scoped named expressions\n const sourceSheetExpressions = allExpressions.sheetExpressions.get(\n this.fromWorkbookName\n );\n if (sourceSheetExpressions) {\n for (const [sheetName, sheetExpressions] of sourceSheetExpressions) {\n for (const [expressionName, expression] of sheetExpressions) {\n namedExpressionManager.addNamedExpression({\n expressionName,\n expression: expression.expression,\n workbookName: this.toWorkbookName,\n sheetName,\n });\n }\n }\n }\n\n // Clone tables\n const sourceTables = tableManager.tables.get(this.fromWorkbookName);\n if (sourceTables) {\n for (const [tableName] of sourceTables) {\n tableManager.copyTable(\n { workbookName: this.fromWorkbookName, tableName },\n { workbookName: this.toWorkbookName, tableName }\n );\n }\n }\n\n // Clone conditional styles\n const allConditionalStyles = styleManager.getAllConditionalStyles();\n for (const style of allConditionalStyles) {\n if (\n style.areas.some((area) => area.workbookName === this.fromWorkbookName)\n ) {\n const newStyle: ConditionalStyle = {\n ...style,\n areas: style.areas.map((area) =>\n area.workbookName === this.fromWorkbookName\n ? { ...area, workbookName: this.toWorkbookName }\n : area\n ),\n };\n styleManager.addConditionalStyle(newStyle);\n }\n }\n\n // Clone cell styles\n const allCellStyles = styleManager.getAllCellStyles();\n for (const style of allCellStyles) {\n if (\n style.areas.some((area) => area.workbookName === this.fromWorkbookName)\n ) {\n const newStyle: DirectCellStyle = {\n ...style,\n areas: style.areas.map((area) =>\n area.workbookName === this.fromWorkbookName\n ? { ...area, workbookName: this.toWorkbookName }\n : area\n ),\n };\n styleManager.addCellStyle(newStyle);\n }\n }\n\n // Update formulas in cloned workbook that reference the source workbook\n workbookManager.updateFormulasForWorkbook(this.toWorkbookName, (formula) =>\n renameWorkbookInFormula({\n formula,\n oldWorkbookName: this.fromWorkbookName,\n newWorkbookName: this.toWorkbookName,\n })\n );\n }\n\n undo(): void {\n // Undo clone = remove the cloned workbook\n removeWorkbook(this.deps, this.toWorkbookName);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.CLONE_WORKBOOK,\n payload: {\n fromWorkbookName: this.fromWorkbookName,\n toWorkbookName: this.toWorkbookName,\n },\n };\n }\n}\n\n// ============================================================================\n// Sheet Commands\n// ============================================================================\n\n/**\n * Command to add a sheet.\n */\nexport class AddSheetCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n\n constructor(\n private deps: StructureCommandDeps,\n private opts: { workbookName: string; sheetName: string }\n ) {}\n\n execute(): void {\n this.deps.workbookManager.addSheet(this.opts);\n this.deps.namedExpressionManager.addSheet(this.opts);\n }\n\n undo(): void {\n this.deps.workbookManager.removeSheet(this.opts);\n this.deps.namedExpressionManager.removeSheet(this.opts);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.ADD_SHEET,\n payload: this.opts,\n };\n }\n}\n\n/**\n * Captured state of a sheet for undo purposes.\n */\ninterface SheetSnapshot {\n sheet: Sheet;\n namedExpressions: Map<string, NamedExpression>;\n tables: Map<string, TableDefinition>;\n conditionalStyles: ConditionalStyle[];\n cellStyles: DirectCellStyle[];\n}\n\n/**\n * Command to remove a sheet.\n */\nexport class RemoveSheetCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n private snapshot: SheetSnapshot | undefined;\n\n constructor(\n private deps: StructureCommandDeps,\n private opts: { workbookName: string; sheetName: string }\n ) {}\n\n execute(): void {\n // Capture sheet state before removal\n const sheet = this.deps.workbookManager.getSheet(this.opts);\n if (sheet) {\n const namedExpressions =\n this.deps.namedExpressionManager.getNamedExpressions();\n const sheetExpressions =\n namedExpressions.sheetExpressions\n .get(this.opts.workbookName)\n ?.get(this.opts.sheetName) || new Map();\n\n // Get tables on this sheet\n const allTables = this.deps.tableManager.getTables(\n this.opts.workbookName\n );\n const sheetTables = new Map<string, TableDefinition>();\n for (const [name, table] of allTables) {\n if (table.sheetName === this.opts.sheetName) {\n sheetTables.set(name, table);\n }\n }\n\n this.snapshot = {\n sheet: {\n name: sheet.name,\n index: sheet.index,\n content: new Map(sheet.content),\n metadata: new Map(sheet.metadata),\n sheetMetadata: sheet.sheetMetadata,\n },\n namedExpressions: new Map(sheetExpressions),\n tables: sheetTables,\n conditionalStyles: this.deps.styleManager\n .getAllConditionalStyles()\n .filter((s) =>\n s.areas.some(\n (a) =>\n a.workbookName === this.opts.workbookName &&\n a.sheetName === this.opts.sheetName\n )\n ),\n cellStyles: this.deps.styleManager\n .getAllCellStyles()\n .filter((s) =>\n s.areas.some(\n (a) =>\n a.workbookName === this.opts.workbookName &&\n a.sheetName === this.opts.sheetName\n )\n ),\n };\n }\n\n // Execute removal\n this.deps.workbookManager.removeSheet(this.opts);\n this.deps.namedExpressionManager.removeSheet(this.opts);\n this.deps.tableManager.removeSheet(this.opts);\n this.deps.styleManager.removeSheetStyles(\n this.opts.workbookName,\n this.opts.sheetName\n );\n this.deps.referenceManager.invalidateSheet(\n this.opts.workbookName,\n this.opts.sheetName\n );\n }\n\n undo(): void {\n if (!this.snapshot) return;\n\n // Restore sheet structure\n this.deps.workbookManager.addSheet(this.opts);\n this.deps.namedExpressionManager.addSheet(this.opts);\n this.deps.workbookManager.setSheetContent(this.opts, this.snapshot.sheet.content);\n\n // Restore named expressions\n for (const [name, expr] of this.snapshot.namedExpressions) {\n this.deps.namedExpressionManager.addNamedExpression({\n expressionName: name,\n expression: expr.expression,\n workbookName: this.opts.workbookName,\n sheetName: this.opts.sheetName,\n });\n }\n\n // Restore tables and styles\n restoreTables(this.deps.tableManager, this.snapshot.tables, this.opts.workbookName);\n restoreStyles(this.deps.styleManager, this.snapshot.conditionalStyles, this.snapshot.cellStyles);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.REMOVE_SHEET,\n payload: this.opts,\n };\n }\n}\n\n/**\n * Command to rename a sheet.\n */\nexport class RenameSheetCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n\n constructor(\n private deps: StructureCommandDeps,\n private opts: {\n workbookName: string;\n sheetName: string;\n newSheetName: string;\n }\n ) {}\n\n execute(): void {\n renameSheetAcrossManagers(this.deps, this.opts);\n }\n\n undo(): void {\n renameSheetAcrossManagers(this.deps, {\n workbookName: this.opts.workbookName,\n sheetName: this.opts.newSheetName,\n newSheetName: this.opts.sheetName,\n });\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.RENAME_SHEET,\n payload: this.opts,\n };\n }\n}\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AAq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,KAAK,IAAI;AAAA;AAAA,EAGhD,IAAI,GAAS;AAAA,IACX,0BAA0B,KAAK,MAAM;AAAA,MACnC,cAAc,KAAK,KAAK;AAAA,MACxB,WAAW,KAAK,KAAK;AAAA,MACrB,cAAc,KAAK,KAAK;AAAA,IAC1B,CAAC;AAAA;AAAA,EAGH,QAAQ,GAAiB;AAAA,IACvB,OAAO;AAAA,MACL,MAAM,YAAY;AAAA,MAClB,SAAS,KAAK;AAAA,IAChB;AAAA;AAEJ;",
|
|
8
8
|
"debugId": "39C98D842B86633B64756E2164756E21",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/core/commands/table-commands.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * Table Commands - Commands that modify table definitions\n *\n * These commands all require re-evaluation after execution.\n */\n\nimport type { TableManager } from \"../managers/table-manager.mjs\";\nimport type { NamedExpressionManager } from \"../managers/named-expression-manager.mjs\";\nimport type { WorkbookManager } from \"../managers/workbook-manager.mjs\";\nimport type {
|
|
5
|
+
"/**\n * Table Commands - Commands that modify table definitions\n *\n * These commands all require re-evaluation after execution.\n */\n\nimport type { TableManager } from \"../managers/table-manager.mjs\";\nimport type { NamedExpressionManager } from \"../managers/named-expression-manager.mjs\";\nimport type { WorkbookManager } from \"../managers/workbook-manager.mjs\";\nimport type { SchemaManager } from \"../managers/schema-manager.mjs\";\nimport type {\n CellAddress,\n SerializedCellValue,\n SpreadsheetRangeEnd,\n TableDefinition,\n} from \"../types.mjs\";\nimport type { EngineCommand, EngineAction } from \"./types.mjs\";\nimport { ActionTypes } from \"./types.mjs\";\n\n/**\n * Dependencies needed for table commands.\n */\nexport interface TableCommandDeps {\n tableManager: TableManager;\n namedExpressionManager: NamedExpressionManager;\n workbookManager: WorkbookManager;\n apiSchemaManager: SchemaManager;\n getCellValue: (cellAddress: CellAddress) => SerializedCellValue;\n renameTableInFormula: (\n formula: string,\n oldName: string,\n newName: string\n ) => string;\n}\n\n/**\n * Command to add a table.\n */\nexport class AddTableCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n\n constructor(\n private deps: TableCommandDeps,\n private props: {\n tableName: string;\n sheetName: string;\n workbookName: string;\n start: string;\n numRows: SpreadsheetRangeEnd;\n numCols: number;\n }\n ) {}\n\n execute(): void {\n this.deps.tableManager.addTable({\n ...this.props,\n getCellValue: this.deps.getCellValue,\n });\n }\n\n undo(): void {\n this.deps.tableManager.removeTable({\n workbookName: this.props.workbookName,\n tableName: this.props.tableName,\n });\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.ADD_TABLE,\n payload: this.props,\n };\n }\n}\n\n/**\n * Command to remove a table.\n */\nexport class RemoveTableCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n private removedTable: TableDefinition | undefined;\n\n constructor(\n private deps: TableCommandDeps,\n private opts: { tableName: string; workbookName: string }\n ) {}\n\n execute(): void {\n // Capture table before removal\n this.removedTable = this.deps.tableManager.getTable({\n workbookName: this.opts.workbookName,\n name: this.opts.tableName,\n });\n\n this.deps.tableManager.removeTable(this.opts);\n }\n\n undo(): void {\n if (!this.removedTable) return;\n\n // Recreate the table\n const { start, endRow, headers, sheetName } = this.removedTable;\n const startRef = `${String.fromCharCode(65 + start.colIndex)}${start.rowIndex + 1}`;\n\n this.deps.tableManager.addTable({\n workbookName: this.opts.workbookName,\n tableName: this.opts.tableName,\n sheetName,\n start: startRef,\n numRows: endRow,\n numCols: headers.size,\n getCellValue: this.deps.getCellValue,\n });\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.REMOVE_TABLE,\n payload: this.opts,\n };\n }\n}\n\n/**\n * Command to rename a table.\n */\nexport class RenameTableCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n\n constructor(\n private deps: TableCommandDeps,\n private workbookName: string,\n private oldName: string,\n private newName: string\n ) {}\n\n execute(): void {\n this.deps.tableManager.renameTable(this.workbookName, {\n oldName: this.oldName,\n newName: this.newName,\n });\n\n // Update formulas in sheet cells\n this.deps.workbookManager.updateAllFormulas((formula) =>\n this.deps.renameTableInFormula(formula, this.oldName, this.newName)\n );\n\n // Update named expressions\n this.deps.namedExpressionManager.updateAllNamedExpressions((formula) =>\n this.deps.renameTableInFormula(formula, this.oldName, this.newName)\n );\n\n // Update API schemas\n this.deps.apiSchemaManager.updateForTableRename(\n this.workbookName,\n this.oldName,\n this.newName\n );\n }\n\n undo(): void {\n // Rename back\n this.deps.tableManager.renameTable(this.workbookName, {\n oldName: this.newName,\n newName: this.oldName,\n });\n\n // Update formulas back\n this.deps.workbookManager.updateAllFormulas((formula) =>\n this.deps.renameTableInFormula(formula, this.newName, this.oldName)\n );\n\n // Update named expressions back\n this.deps.namedExpressionManager.updateAllNamedExpressions((formula) =>\n this.deps.renameTableInFormula(formula, this.newName, this.oldName)\n );\n\n // Update API schemas back\n this.deps.apiSchemaManager.updateForTableRename(\n this.workbookName,\n this.newName,\n this.oldName\n );\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.RENAME_TABLE,\n payload: {\n workbookName: this.workbookName,\n oldName: this.oldName,\n newName: this.newName,\n },\n };\n }\n}\n\n/**\n * Command to update a table.\n */\nexport class UpdateTableCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n private previousTable: TableDefinition | undefined;\n\n constructor(\n private deps: TableCommandDeps,\n private opts: {\n tableName: string;\n sheetName?: string;\n start?: string;\n numRows?: SpreadsheetRangeEnd;\n numCols?: number;\n workbookName: string;\n }\n ) {}\n\n execute(): void {\n // Capture previous table state\n this.previousTable = this.deps.tableManager.getTable({\n workbookName: this.opts.workbookName,\n name: this.opts.tableName,\n });\n\n this.deps.tableManager.updateTable({\n ...this.opts,\n getCellValue: this.deps.getCellValue,\n });\n }\n\n undo(): void {\n if (!this.previousTable) return;\n\n // Restore previous table state\n const { start, endRow, headers, sheetName } = this.previousTable;\n const startRef = `${String.fromCharCode(65 + start.colIndex)}${start.rowIndex + 1}`;\n\n this.deps.tableManager.updateTable({\n workbookName: this.opts.workbookName,\n tableName: this.opts.tableName,\n sheetName,\n start: startRef,\n numRows: endRow,\n numCols: headers.size,\n getCellValue: this.deps.getCellValue,\n });\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.UPDATE_TABLE,\n payload: this.opts,\n };\n }\n}\n\n/**\n * Command to reset all tables.\n */\nexport class ResetTablesCommand implements EngineCommand {\n readonly requiresReevaluation = true;\n private previousTables: Map<string, Map<string, TableDefinition>> | undefined;\n\n constructor(\n private deps: TableCommandDeps,\n private newTables: Map<string, Map<string, TableDefinition>>\n ) {}\n\n execute(): void {\n // Capture previous tables\n this.previousTables = new Map();\n for (const [workbookName, tables] of this.deps.tableManager.tables) {\n this.previousTables.set(workbookName, new Map(tables));\n }\n\n this.deps.tableManager.resetTables(this.newTables);\n }\n\n undo(): void {\n if (!this.previousTables) return;\n this.deps.tableManager.resetTables(this.previousTables);\n }\n\n toAction(): EngineAction {\n return {\n type: ActionTypes.RESET_TABLES,\n payload: {\n tables: Array.from(this.newTables.entries()).map(([wb, tables]) => [\n wb,\n Array.from(tables.entries()),\n ]),\n },\n };\n }\n}\n\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AAiBA;AAAA;AAqBO,MAAM,gBAAyC;AAAA,EAI1C;AAAA,EACA;AAAA,EAJD,uBAAuB;AAAA,EAEhC,WAAW,CACD,MACA,OAQR;AAAA,IATQ;AAAA,IACA;AAAA;AAAA,EAUV,OAAO,GAAS;AAAA,IACd,KAAK,KAAK,aAAa,SAAS;AAAA,SAC3B,KAAK;AAAA,MACR,cAAc,KAAK,KAAK;AAAA,IAC1B,CAAC;AAAA;AAAA,EAGH,IAAI,GAAS;AAAA,IACX,KAAK,KAAK,aAAa,YAAY;AAAA,MACjC,cAAc,KAAK,MAAM;AAAA,MACzB,WAAW,KAAK,MAAM;AAAA,IACxB,CAAC;AAAA;AAAA,EAGH,QAAQ,GAAiB;AAAA,IACvB,OAAO;AAAA,MACL,MAAM,YAAY;AAAA,MAClB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