@ricsam/formula-engine 0.2.8 → 0.2.9

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.
Files changed (101) hide show
  1. package/README.md +1 -3
  2. package/dist/cjs/core/engine.cjs +515 -166
  3. package/dist/cjs/core/engine.cjs.map +3 -3
  4. package/dist/cjs/core/managers/dependency-manager.cjs.map +2 -2
  5. package/dist/cjs/core/managers/evaluation-manager.cjs.map +1 -1
  6. package/dist/cjs/core/mutation-invalidation.cjs +241 -0
  7. package/dist/cjs/core/mutation-invalidation.cjs.map +10 -0
  8. package/dist/cjs/lib.cjs +2 -13
  9. package/dist/cjs/lib.cjs.map +3 -3
  10. package/dist/cjs/package.json +1 -1
  11. package/dist/mjs/core/engine.mjs +529 -207
  12. package/dist/mjs/core/engine.mjs.map +3 -3
  13. package/dist/mjs/core/managers/dependency-manager.mjs.map +2 -2
  14. package/dist/mjs/core/managers/evaluation-manager.mjs.map +1 -1
  15. package/dist/mjs/core/mutation-invalidation.mjs +201 -0
  16. package/dist/mjs/core/mutation-invalidation.mjs.map +10 -0
  17. package/dist/mjs/lib.mjs +2 -13
  18. package/dist/mjs/lib.mjs.map +3 -3
  19. package/dist/mjs/package.json +1 -1
  20. package/dist/types/core/engine.d.ts +17 -135
  21. package/dist/types/core/managers/dependency-manager.d.ts +1 -1
  22. package/dist/types/core/managers/evaluation-manager.d.ts +1 -1
  23. package/dist/types/core/mutation-invalidation.d.ts +46 -0
  24. package/dist/types/lib.d.ts +0 -8
  25. package/package.json +1 -1
  26. package/dist/cjs/core/commands/command-executor.cjs +0 -149
  27. package/dist/cjs/core/commands/command-executor.cjs.map +0 -10
  28. package/dist/cjs/core/commands/content-commands.cjs +0 -857
  29. package/dist/cjs/core/commands/content-commands.cjs.map +0 -10
  30. package/dist/cjs/core/commands/metadata-commands.cjs +0 -160
  31. package/dist/cjs/core/commands/metadata-commands.cjs.map +0 -10
  32. package/dist/cjs/core/commands/named-expression-commands.cjs +0 -363
  33. package/dist/cjs/core/commands/named-expression-commands.cjs.map +0 -10
  34. package/dist/cjs/core/commands/structure-commands.cjs +0 -696
  35. package/dist/cjs/core/commands/structure-commands.cjs.map +0 -10
  36. package/dist/cjs/core/commands/style-commands.cjs +0 -229
  37. package/dist/cjs/core/commands/style-commands.cjs.map +0 -10
  38. package/dist/cjs/core/commands/table-commands.cjs +0 -495
  39. package/dist/cjs/core/commands/table-commands.cjs.map +0 -10
  40. package/dist/cjs/core/commands/types.cjs +0 -99
  41. package/dist/cjs/core/commands/types.cjs.map +0 -10
  42. package/dist/cjs/core/managers/schema-manager.cjs +0 -374
  43. package/dist/cjs/core/managers/schema-manager.cjs.map +0 -10
  44. package/dist/cjs/core/schema/cell-orm.cjs +0 -76
  45. package/dist/cjs/core/schema/cell-orm.cjs.map +0 -10
  46. package/dist/cjs/core/schema/grid-orm.cjs +0 -125
  47. package/dist/cjs/core/schema/grid-orm.cjs.map +0 -10
  48. package/dist/cjs/core/schema/schema-builder.cjs +0 -74
  49. package/dist/cjs/core/schema/schema-builder.cjs.map +0 -10
  50. package/dist/cjs/core/schema/schema-helpers.cjs +0 -200
  51. package/dist/cjs/core/schema/schema-helpers.cjs.map +0 -10
  52. package/dist/cjs/core/schema/schema.cjs +0 -91
  53. package/dist/cjs/core/schema/schema.cjs.map +0 -10
  54. package/dist/cjs/core/schema/table-orm.cjs +0 -189
  55. package/dist/cjs/core/schema/table-orm.cjs.map +0 -10
  56. package/dist/mjs/core/commands/command-executor.mjs +0 -109
  57. package/dist/mjs/core/commands/command-executor.mjs.map +0 -10
  58. package/dist/mjs/core/commands/content-commands.mjs +0 -821
  59. package/dist/mjs/core/commands/content-commands.mjs.map +0 -10
  60. package/dist/mjs/core/commands/metadata-commands.mjs +0 -120
  61. package/dist/mjs/core/commands/metadata-commands.mjs.map +0 -10
  62. package/dist/mjs/core/commands/named-expression-commands.mjs +0 -323
  63. package/dist/mjs/core/commands/named-expression-commands.mjs.map +0 -10
  64. package/dist/mjs/core/commands/structure-commands.mjs +0 -661
  65. package/dist/mjs/core/commands/structure-commands.mjs.map +0 -10
  66. package/dist/mjs/core/commands/style-commands.mjs +0 -189
  67. package/dist/mjs/core/commands/style-commands.mjs.map +0 -10
  68. package/dist/mjs/core/commands/table-commands.mjs +0 -459
  69. package/dist/mjs/core/commands/table-commands.mjs.map +0 -10
  70. package/dist/mjs/core/commands/types.mjs +0 -59
  71. package/dist/mjs/core/commands/types.mjs.map +0 -10
  72. package/dist/mjs/core/managers/schema-manager.mjs +0 -334
  73. package/dist/mjs/core/managers/schema-manager.mjs.map +0 -10
  74. package/dist/mjs/core/schema/cell-orm.mjs +0 -35
  75. package/dist/mjs/core/schema/cell-orm.mjs.map +0 -10
  76. package/dist/mjs/core/schema/grid-orm.mjs +0 -84
  77. package/dist/mjs/core/schema/grid-orm.mjs.map +0 -10
  78. package/dist/mjs/core/schema/schema-builder.mjs +0 -34
  79. package/dist/mjs/core/schema/schema-builder.mjs.map +0 -10
  80. package/dist/mjs/core/schema/schema-helpers.mjs +0 -160
  81. package/dist/mjs/core/schema/schema-helpers.mjs.map +0 -10
  82. package/dist/mjs/core/schema/schema.mjs +0 -51
  83. package/dist/mjs/core/schema/schema.mjs.map +0 -10
  84. package/dist/mjs/core/schema/table-orm.mjs +0 -156
  85. package/dist/mjs/core/schema/table-orm.mjs.map +0 -10
  86. package/dist/types/core/commands/command-executor.d.ts +0 -81
  87. package/dist/types/core/commands/content-commands.d.ts +0 -172
  88. package/dist/types/core/commands/metadata-commands.d.ts +0 -55
  89. package/dist/types/core/commands/named-expression-commands.d.ts +0 -130
  90. package/dist/types/core/commands/structure-commands.d.ts +0 -155
  91. package/dist/types/core/commands/style-commands.d.ts +0 -76
  92. package/dist/types/core/commands/table-commands.d.ts +0 -119
  93. package/dist/types/core/commands/types.d.ts +0 -143
  94. package/dist/types/core/managers/schema-manager.d.ts +0 -142
  95. package/dist/types/core/schema/cell-orm.d.ts +0 -33
  96. package/dist/types/core/schema/grid-orm.d.ts +0 -63
  97. package/dist/types/core/schema/schema-builder.d.ts +0 -16
  98. package/dist/types/core/schema/schema-helpers.d.ts +0 -49
  99. package/dist/types/core/schema/schema.d.ts +0 -167
  100. package/dist/types/core/schema/schema.type-test.d.ts +0 -1
  101. package/dist/types/core/schema/table-orm.d.ts +0 -46
@@ -2,7 +2,7 @@
2
2
  * Main FormulaEngine class
3
3
  * Core API implementation for spreadsheet calculations
4
4
  */
5
- import { type CellAddress, type CellStyle, type ConditionalStyle, type CopyCellsOptions, type DirectCellStyle, type FiniteSpreadsheetRange, type NamedExpression, type RangeAddress, type SerializedCellValue, type Sheet, type SingleEvaluationResult, type SpreadsheetRange, type SpreadsheetRangeEnd, type TableDefinition } from "./types";
5
+ import { type CellAddress, type CellStyle, type ConditionalStyle, type CopyCellsOptions, type DirectCellStyle, type NamedExpression, type RangeAddress, type SerializedCellValue, type Sheet, type SingleEvaluationResult, type SpreadsheetRange, type SpreadsheetRangeEnd, type TableDefinition } from "./types";
6
6
  import type { FillDirection } from "@ricsam/selection-manager";
7
7
  import { AutoFill } from "./autofill-utils";
8
8
  import { WorkbookManager } from "./managers/workbook-manager";
@@ -12,12 +12,6 @@ import { EventManager } from "./managers/event-manager";
12
12
  import { EvaluationManager } from "./managers/evaluation-manager";
13
13
  import { DependencyManager } from "./managers/dependency-manager";
14
14
  import { StyleManager } from "./managers/style-manager";
15
- import type { Schema, CreateSchema, SchemaDeclaration } from "./schema/schema";
16
- import { TableOrm } from "./schema/table-orm";
17
- import { CellOrm } from "./schema/cell-orm";
18
- import { GridOrm } from "./schema/grid-orm";
19
- import type { TableSchemaHeaders } from "./managers/schema-manager";
20
- import { type EngineAction } from "./commands/types";
21
15
  type Metadata = {
22
16
  cell?: unknown;
23
17
  sheet?: unknown;
@@ -26,11 +20,9 @@ type Metadata = {
26
20
  type MetadataType<TMetadata extends Metadata, TKey extends keyof Metadata> = TMetadata[TKey];
27
21
  /**
28
22
  * Main FormulaEngine class
29
- * @template TCellMetadata - Consumer-defined type for cell metadata (rich text, links, custom data, etc.)
30
- * @template TSheetMetadata - Consumer-defined type for sheet metadata (text boxes, frozen panes, etc.)
31
- * @template TWorkbookMetadata - Consumer-defined type for workbook metadata (themes, document properties, etc.)
32
- */
33
- export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreateSchema extends CreateSchema<MetadataType<TMetadata, "cell">, Schema, SchemaDeclaration> | undefined = undefined> {
23
+ * @template TMetadata - Consumer-defined metadata shape with optional cell, sheet, and workbook entries.
24
+ */
25
+ export declare class FormulaEngine<TMetadata extends Metadata = Metadata> {
34
26
  private workbookManager;
35
27
  private namedExpressionManager;
36
28
  private tableManager;
@@ -41,10 +33,6 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
41
33
  private styleManager;
42
34
  private copyManager;
43
35
  private referenceManager;
44
- private schemaManager;
45
- private commandExecutor;
46
- schema: TCreateSchema extends CreateSchema<MetadataType<TMetadata, "cell">, Schema, SchemaDeclaration> ? TCreateSchema["schema"] : undefined;
47
- private schemaDeclaration;
48
36
  /**
49
37
  * Public access to the store manager for testing
50
38
  */
@@ -56,73 +44,17 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
56
44
  _autoFillManager: AutoFill;
57
45
  _dependencyManager: DependencyManager;
58
46
  _styleManager: StyleManager;
59
- constructor(schema?: TCreateSchema);
47
+ constructor();
60
48
  /**
61
49
  * Static factory method to build an empty engine
62
- * @template TC - Consumer-defined cell metadata type
63
- * @template TS - Consumer-defined sheet metadata type
64
- * @template TW - Consumer-defined workbook metadata type
65
- */
66
- static buildEmpty<TMetadata extends Metadata = Metadata, TSchemaDeclaration extends CreateSchema<MetadataType<TMetadata, "cell">, any, any> | undefined = undefined>(schema?: TSchemaDeclaration): FormulaEngine<TMetadata, TSchemaDeclaration>;
67
- /**
68
- * Add a table schema at runtime
69
- * @param namespace - Unique namespace for the schema
70
- * @param address - Table address (workbookName and tableName)
71
- * @param headers - Table headers with parse functions
72
- * @returns The TableOrm instance for immediate use
73
- */
74
- addTableSchema<THeaders extends TableSchemaHeaders<MetadataType<TMetadata, "cell">>>(namespace: string, address: {
75
- workbookName: string;
76
- tableName: string;
77
- }, headers: THeaders): TableOrm<{
78
- [K in keyof THeaders]: ReturnType<THeaders[K]["parse"]>;
79
- }>;
80
- /**
81
- * Add a cell schema at runtime
82
- * @param namespace - Unique namespace for the schema
83
- * @param cellAddress - Address of the cell
84
- * @param parse - Parse function for the cell value
85
- * @returns The CellOrm instance for immediate use
86
- */
87
- addCellSchema<TValue>(namespace: string, cellAddress: CellAddress, parse: (value: unknown, metadata: MetadataType<TMetadata, "cell">) => TValue, write?: (value: TValue) => {
88
- value: SerializedCellValue;
89
- metadata?: MetadataType<TMetadata, "cell">;
90
- }): CellOrm<TValue>;
91
- /**
92
- * Add a grid schema at runtime
93
- * @param namespace - Unique namespace for the schema
94
- * @param address - Grid address (workbookName and sheetName)
95
- * @param range - Finite range of cells for the grid
96
- * @param parse - Parse function for the cell values
97
- * @param write - Write function for serializing values (optional for primitive types)
98
- * @returns The GridOrm instance for immediate use
99
- */
100
- addGridSchema<TValue>(namespace: string, address: {
101
- workbookName: string;
102
- sheetName: string;
103
- }, range: FiniteSpreadsheetRange, parse: (value: unknown, metadata: MetadataType<TMetadata, "cell">) => TValue, write?: (value: TValue) => {
104
- value: SerializedCellValue;
105
- metadata?: MetadataType<TMetadata, "cell">;
106
- }): GridOrm<TValue, MetadataType<TMetadata, "cell">>;
107
- /**
108
- * Remove a table schema at runtime.
109
- * @param namespace - Namespace of the table schema to remove
110
- * @returns true when a matching table schema was removed, false otherwise
111
- */
112
- removeTableSchema(namespace: string): boolean;
113
- /**
114
- * Remove a cell schema at runtime.
115
- * @param namespace - Namespace of the cell schema to remove
116
- * @returns true when a matching cell schema was removed, false otherwise
117
- */
118
- removeCellSchema(namespace: string): boolean;
119
- /**
120
- * Remove a grid schema at runtime.
121
- * @param namespace - Namespace of the grid schema to remove
122
- * @returns true when a matching grid schema was removed, false otherwise
123
- */
124
- removeGridSchema(namespace: string): boolean;
125
- private removeSchemaOfType;
50
+ * @template TMetadata - Consumer-defined metadata shape with optional cell, sheet, and workbook entries.
51
+ */
52
+ static buildEmpty<TMetadata extends Metadata = Metadata>(): FormulaEngine<TMetadata>;
53
+ private emitMutation;
54
+ private emitUpdate;
55
+ private getExistingSheetContent;
56
+ private getWorkbookResourceKeys;
57
+ private getSheetResourceKeys;
126
58
  getCellEvaluationResult(cellAddress: CellAddress): SingleEvaluationResult | undefined;
127
59
  getCellValue(cellAddress: CellAddress, debug?: boolean): SerializedCellValue;
128
60
  /**
@@ -260,6 +192,7 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
260
192
  tableName: string;
261
193
  workbookName: string;
262
194
  }): void;
195
+ private getAllTables;
263
196
  /**
264
197
  * Check if a table exists
265
198
  */
@@ -277,12 +210,6 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
277
210
  resetTables(tables: Map<string, Map<string, TableDefinition>>): void;
278
211
  getTables(workbookName: string): Map<string, TableDefinition>;
279
212
  isCellInTable(cellAddress: CellAddress): TableDefinition | undefined;
280
- /**
281
- * Get all data cells in a table (excluding header row).
282
- * Since spills cannot enter tables (they get #SPILL! error), this only
283
- * needs to return cells with direct content.
284
- */
285
- private getTableDataCells;
286
213
  /**
287
214
  * Add a conditional style rule
288
215
  */
@@ -338,6 +265,9 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
338
265
  * Adjusts existing style ranges rather than deleting them entirely
339
266
  */
340
267
  clearCellStyles(range: RangeAddress): void;
268
+ private getTopLeftCell;
269
+ private dedupeAddresses;
270
+ private getPasteTouchedAddresses;
341
271
  /**
342
272
  * Paste cells from source to target
343
273
  */
@@ -499,7 +429,6 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
499
429
  * @param sheetName - The name of the sheet to set the content of
500
430
  * @param content - A map of cell addresses to their serialized values
501
431
  * @remarks This method is used to set the content of a sheet. It will re-evaluate all sheets to ensure all dependencies are resolved correctly.
502
- * @throws SchemaIntegrityError if any evaluated cell value violates a schema constraint
503
432
  */
504
433
  setSheetContent(opts: {
505
434
  sheetName: string;
@@ -507,7 +436,6 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
507
436
  }, content: Map<string, SerializedCellValue>): void;
508
437
  /**
509
438
  * Set the content of a single cell.
510
- * @throws SchemaIntegrityError if the evaluated value violates a schema constraint
511
439
  */
512
440
  setCellContent(address: CellAddress, content: SerializedCellValue): void;
513
441
  /**
@@ -550,51 +478,5 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
550
478
  private buildSerializedSnapshot;
551
479
  serializeEngine(): string;
552
480
  resetToSerializedEngine(data: string): void;
553
- /**
554
- * Undo the last command.
555
- * @returns true if undo was performed, false if nothing to undo
556
- */
557
- undo(): boolean;
558
- /**
559
- * Redo the last undone command.
560
- * @returns true if redo was performed, false if nothing to redo
561
- */
562
- redo(): boolean;
563
- /**
564
- * Check if undo is available.
565
- */
566
- canUndo(): boolean;
567
- /**
568
- * Check if redo is available.
569
- */
570
- canRedo(): boolean;
571
- /**
572
- * Get the action log for persistence/collaboration.
573
- * Actions can be serialized and replayed to reconstruct state.
574
- */
575
- getActionLog(): EngineAction[];
576
- /**
577
- * Clear the action log.
578
- */
579
- clearActionLog(): void;
580
- /**
581
- * Clear undo/redo history.
582
- */
583
- clearHistory(): void;
584
- /**
585
- * Get dependencies for structure commands.
586
- * @internal
587
- */
588
- private getStructureCommandDeps;
589
- /**
590
- * Get dependencies for table commands.
591
- * @internal
592
- */
593
- private getTableCommandDeps;
594
- /**
595
- * Get dependencies for named expression commands.
596
- * @internal
597
- */
598
- private getNamedExpressionCommandDeps;
599
481
  }
600
482
  export {};
@@ -12,7 +12,7 @@ import type { DependencyNode } from "./dependency-node";
12
12
  import { WorkbookManager } from "./workbook-manager";
13
13
  import { VirtualCellValueNode } from "../../evaluator/dependency-nodes/virtual-cell-value-node";
14
14
  import type { EvaluationManager } from "./evaluation-manager";
15
- import type { MutationInvalidation } from "../commands/types";
15
+ import type { MutationInvalidation } from "../mutation-invalidation";
16
16
  import { ResourceDependencyNode } from "../../evaluator/dependency-nodes/resource-dependency-node";
17
17
  export interface DependencyTreeNode {
18
18
  type: "cell" | "range" | "empty";
@@ -11,7 +11,7 @@ import type { TableManager } from "./table-manager";
11
11
  import type { DependencyNode } from "./dependency-node";
12
12
  import { VirtualCellValueNode } from "../../evaluator/dependency-nodes/virtual-cell-value-node";
13
13
  import type { NodeSnapshotId, SerializedEvaluateAllCellsResultSnapshot, SerializedFunctionEvaluationResultSnapshot, SerializedSingleEvaluationResultSnapshot, SerializedSpillMetaEvaluationResultSnapshot } from "../engine-snapshot";
14
- import type { MutationInvalidation } from "../commands/types";
14
+ import type { MutationInvalidation } from "../mutation-invalidation";
15
15
  export declare class EvaluationManager {
16
16
  private workbookManager;
17
17
  private tableManager;
@@ -0,0 +1,46 @@
1
+ import type { WorkbookManager } from "./managers/workbook-manager";
2
+ import type { CellAddress, RangeAddress, SerializedCellValue, TableDefinition } from "./types";
3
+ type CellContentKind = "empty" | "scalar" | "formula";
4
+ export type RemovedScope = {
5
+ type: "workbook";
6
+ workbookName: string;
7
+ } | {
8
+ type: "sheet";
9
+ workbookName: string;
10
+ sheetName: string;
11
+ };
12
+ export type MutationInvalidation = {
13
+ touchedCells: Array<{
14
+ address: CellAddress;
15
+ beforeKind: CellContentKind;
16
+ afterKind: CellContentKind;
17
+ }>;
18
+ /**
19
+ * Cells whose table membership or implicit current-row table context changed
20
+ * without necessarily changing their formula text.
21
+ */
22
+ tableContextChangedCells?: CellAddress[];
23
+ resourceKeys: string[];
24
+ removedScopes?: RemovedScope[];
25
+ };
26
+ export declare function getMutationAddressKey(address: CellAddress): string;
27
+ export declare function buildTouchedCells(cells: Array<{
28
+ address: CellAddress;
29
+ before: SerializedCellValue | undefined;
30
+ after: SerializedCellValue | undefined;
31
+ }>): MutationInvalidation["touchedCells"];
32
+ export declare function buildFormulaTouchedCells(cells: CellAddress[]): MutationInvalidation["touchedCells"];
33
+ export declare function captureCellContents(workbookManager: WorkbookManager, addresses: CellAddress[]): Map<string, SerializedCellValue | undefined>;
34
+ export declare function buildSheetContentTouchedCells(opts: {
35
+ workbookName: string;
36
+ sheetName: string;
37
+ }, beforeContent: Map<string, SerializedCellValue> | undefined, afterContent: Map<string, SerializedCellValue>): MutationInvalidation["touchedCells"];
38
+ export declare function buildTableTouchedCells(workbookManager: WorkbookManager, tables: Array<TableDefinition | undefined>): MutationInvalidation["touchedCells"];
39
+ export declare function buildTableContextChangedCells(workbookManager: WorkbookManager, tables: Array<TableDefinition | undefined>): CellAddress[];
40
+ export declare function mergeTouchedCells(...groups: MutationInvalidation["touchedCells"][]): MutationInvalidation["touchedCells"];
41
+ export declare function getNamedExpressionScopeResourceKeys(expressions: Iterable<string>, opts: {
42
+ workbookName?: string;
43
+ sheetName?: string;
44
+ }): string[];
45
+ export declare function getFiniteRangeAddresses(address: RangeAddress): CellAddress[];
46
+ export {};
@@ -2,11 +2,3 @@ export { FormulaEngine } from "./core/engine";
2
2
  export * from "./core/types";
3
3
  export * from "./core/utils";
4
4
  export * from "./core/utils/color-utils";
5
- export { defineSchema, defineHeader } from "./core/schema/schema";
6
- export type { CreateSchema, SchemaDeclaration, Schema, TableSchemaDefinition, CellSchemaDefinition, TableOrmSchema, CellOrmSchema } from "./core/schema/schema";
7
- export { TableOrm } from "./core/schema/table-orm";
8
- export { CellOrm } from "./core/schema/cell-orm";
9
- export { SchemaValidationError } from "./core/managers/schema-manager";
10
- export type { ValidationResult } from "./core/managers/schema-manager";
11
- export { SchemaIntegrityError } from "./core/commands/command-executor";
12
- export type { EngineAction, EngineCommand } from "./core/commands/types";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "module": "./dist/mjs/lib.mjs",
5
5
  "scripts": {
6
6
  "test": "bun test",
@@ -1,149 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- function __accessProp(key) {
6
- return this[key];
7
- }
8
- var __toCommonJS = (from) => {
9
- var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
- if (entry)
11
- return entry;
12
- entry = __defProp({}, "__esModule", { value: true });
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (var key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(entry, key))
16
- __defProp(entry, key, {
17
- get: __accessProp.bind(from, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
20
- }
21
- __moduleCache.set(from, entry);
22
- return entry;
23
- };
24
- var __moduleCache;
25
- var __returnValue = (v) => v;
26
- function __exportSetter(name, newValue) {
27
- this[name] = __returnValue.bind(null, newValue);
28
- }
29
- var __export = (target, all) => {
30
- for (var name in all)
31
- __defProp(target, name, {
32
- get: all[name],
33
- enumerable: true,
34
- configurable: true,
35
- set: __exportSetter.bind(all, name)
36
- });
37
- };
38
-
39
- // src/core/commands/command-executor.ts
40
- var exports_command_executor = {};
41
- __export(exports_command_executor, {
42
- SchemaIntegrityError: () => SchemaIntegrityError,
43
- CommandExecutor: () => CommandExecutor
44
- });
45
- module.exports = __toCommonJS(exports_command_executor);
46
- var import_types = require("./types.cjs");
47
-
48
- class SchemaIntegrityError extends Error {
49
- errors;
50
- constructor(errors) {
51
- const messages = errors.map((e) => e.message).join("; ");
52
- super(`Schema integrity violation: ${messages}`);
53
- this.errors = errors;
54
- this.name = "SchemaIntegrityError";
55
- }
56
- }
57
-
58
- class CommandExecutor {
59
- evaluationManager;
60
- eventManager;
61
- validateAllSchemas;
62
- undoStack = [];
63
- redoStack = [];
64
- actionLog = [];
65
- constructor(evaluationManager, eventManager, validateAllSchemas) {
66
- this.evaluationManager = evaluationManager;
67
- this.eventManager = eventManager;
68
- this.validateAllSchemas = validateAllSchemas;
69
- }
70
- execute(command, options = {}) {
71
- const {
72
- validate = false,
73
- skipUndoStack = false,
74
- skipEmitUpdate = false
75
- } = options;
76
- command.execute();
77
- if (command.requiresReevaluation) {
78
- this.evaluationManager.invalidateFromMutation(command.getInvalidationFootprint?.("execute") ?? import_types.emptyMutationInvalidation());
79
- if (validate) {
80
- const validation = this.validateAllSchemas();
81
- if (!validation.valid) {
82
- command.undo();
83
- this.evaluationManager.invalidateFromMutation(command.getInvalidationFootprint?.("undo") ?? import_types.emptyMutationInvalidation());
84
- throw new SchemaIntegrityError(validation.errors);
85
- }
86
- }
87
- }
88
- if (!skipUndoStack) {
89
- this.undoStack.push(command);
90
- this.redoStack = [];
91
- }
92
- const action = command.toAction();
93
- action.timestamp = Date.now();
94
- this.actionLog.push(action);
95
- if (!skipEmitUpdate) {
96
- this.eventManager.emitUpdate();
97
- }
98
- }
99
- undo() {
100
- const command = this.undoStack.pop();
101
- if (!command) {
102
- return false;
103
- }
104
- command.undo();
105
- if (command.requiresReevaluation) {
106
- this.evaluationManager.invalidateFromMutation(command.getInvalidationFootprint?.("undo") ?? import_types.emptyMutationInvalidation());
107
- }
108
- this.redoStack.push(command);
109
- this.eventManager.emitUpdate();
110
- return true;
111
- }
112
- redo() {
113
- const command = this.redoStack.pop();
114
- if (!command) {
115
- return false;
116
- }
117
- command.execute();
118
- if (command.requiresReevaluation) {
119
- this.evaluationManager.invalidateFromMutation(command.getInvalidationFootprint?.("execute") ?? import_types.emptyMutationInvalidation());
120
- }
121
- this.undoStack.push(command);
122
- this.eventManager.emitUpdate();
123
- return true;
124
- }
125
- canUndo() {
126
- return this.undoStack.length > 0;
127
- }
128
- canRedo() {
129
- return this.redoStack.length > 0;
130
- }
131
- getActionLog() {
132
- return [...this.actionLog];
133
- }
134
- clearActionLog() {
135
- this.actionLog = [];
136
- }
137
- clearHistory() {
138
- this.undoStack = [];
139
- this.redoStack = [];
140
- }
141
- getUndoStackSize() {
142
- return this.undoStack.length;
143
- }
144
- getRedoStackSize() {
145
- return this.redoStack.length;
146
- }
147
- }
148
-
149
- //# debugId=43DC9858A49109E564756E2164756E21
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/core/commands/command-executor.ts"],
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 { SchemaDeclaration } from \"../schema/schema.cjs\";\nimport type { FormulaEngine } from \"../engine.cjs\";\nimport type { EvaluationManager } from \"../managers/evaluation-manager.cjs\";\nimport type { EventManager } from \"../managers/event-manager.cjs\";\nimport type { CellAddress, SerializedCellValue } from \"../types.cjs\";\nimport type {\n EngineCommand,\n EngineAction,\n ExecuteOptions,\n SchemaValidationResult,\n SchemaValidationErrorInfo,\n} from \"./types.cjs\";\nimport { emptyMutationInvalidation } from \"./types.cjs\";\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.invalidateFromMutation(\n command.getInvalidationFootprint?.(\"execute\") ??\n emptyMutationInvalidation()\n );\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.invalidateFromMutation(\n command.getInvalidationFootprint?.(\"undo\") ??\n emptyMutationInvalidation()\n );\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.invalidateFromMutation(\n command.getInvalidationFootprint?.(\"undo\") ??\n emptyMutationInvalidation()\n );\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.invalidateFromMutation(\n command.getInvalidationFootprint?.(\"execute\") ??\n emptyMutationInvalidation()\n );\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
- ],
7
- "mappings": "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",
8
- "debugId": "43DC9858A49109E564756E2164756E21",
9
- "names": []
10
- }