@ricsam/formula-engine 0.2.7 → 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.
- package/README.md +1 -3
- package/dist/cjs/core/engine.cjs +518 -149
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/dependency-manager.cjs.map +2 -2
- package/dist/cjs/core/managers/evaluation-manager.cjs.map +1 -1
- package/dist/cjs/core/mutation-invalidation.cjs +241 -0
- package/dist/cjs/core/mutation-invalidation.cjs.map +10 -0
- package/dist/cjs/lib.cjs +2 -13
- package/dist/cjs/lib.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/engine.mjs +532 -190
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/dependency-manager.mjs.map +2 -2
- package/dist/mjs/core/managers/evaluation-manager.mjs.map +1 -1
- package/dist/mjs/core/mutation-invalidation.mjs +201 -0
- package/dist/mjs/core/mutation-invalidation.mjs.map +10 -0
- package/dist/mjs/lib.mjs +2 -13
- package/dist/mjs/lib.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/engine.d.ts +17 -116
- package/dist/types/core/managers/dependency-manager.d.ts +1 -1
- package/dist/types/core/managers/evaluation-manager.d.ts +1 -1
- package/dist/types/core/mutation-invalidation.d.ts +46 -0
- package/dist/types/lib.d.ts +0 -8
- package/package.json +1 -1
- package/dist/cjs/core/commands/command-executor.cjs +0 -149
- package/dist/cjs/core/commands/command-executor.cjs.map +0 -10
- package/dist/cjs/core/commands/content-commands.cjs +0 -857
- package/dist/cjs/core/commands/content-commands.cjs.map +0 -10
- package/dist/cjs/core/commands/metadata-commands.cjs +0 -160
- package/dist/cjs/core/commands/metadata-commands.cjs.map +0 -10
- package/dist/cjs/core/commands/named-expression-commands.cjs +0 -363
- package/dist/cjs/core/commands/named-expression-commands.cjs.map +0 -10
- package/dist/cjs/core/commands/structure-commands.cjs +0 -696
- package/dist/cjs/core/commands/structure-commands.cjs.map +0 -10
- package/dist/cjs/core/commands/style-commands.cjs +0 -229
- package/dist/cjs/core/commands/style-commands.cjs.map +0 -10
- package/dist/cjs/core/commands/table-commands.cjs +0 -495
- package/dist/cjs/core/commands/table-commands.cjs.map +0 -10
- package/dist/cjs/core/commands/types.cjs +0 -99
- package/dist/cjs/core/commands/types.cjs.map +0 -10
- package/dist/cjs/core/managers/schema-manager.cjs +0 -374
- package/dist/cjs/core/managers/schema-manager.cjs.map +0 -10
- package/dist/cjs/core/schema/cell-orm.cjs +0 -76
- package/dist/cjs/core/schema/cell-orm.cjs.map +0 -10
- package/dist/cjs/core/schema/grid-orm.cjs +0 -125
- package/dist/cjs/core/schema/grid-orm.cjs.map +0 -10
- package/dist/cjs/core/schema/schema-builder.cjs +0 -74
- package/dist/cjs/core/schema/schema-builder.cjs.map +0 -10
- package/dist/cjs/core/schema/schema-helpers.cjs +0 -200
- package/dist/cjs/core/schema/schema-helpers.cjs.map +0 -10
- package/dist/cjs/core/schema/schema.cjs +0 -91
- package/dist/cjs/core/schema/schema.cjs.map +0 -10
- package/dist/cjs/core/schema/table-orm.cjs +0 -189
- package/dist/cjs/core/schema/table-orm.cjs.map +0 -10
- package/dist/mjs/core/commands/command-executor.mjs +0 -109
- package/dist/mjs/core/commands/command-executor.mjs.map +0 -10
- package/dist/mjs/core/commands/content-commands.mjs +0 -821
- package/dist/mjs/core/commands/content-commands.mjs.map +0 -10
- package/dist/mjs/core/commands/metadata-commands.mjs +0 -120
- package/dist/mjs/core/commands/metadata-commands.mjs.map +0 -10
- package/dist/mjs/core/commands/named-expression-commands.mjs +0 -323
- package/dist/mjs/core/commands/named-expression-commands.mjs.map +0 -10
- package/dist/mjs/core/commands/structure-commands.mjs +0 -661
- package/dist/mjs/core/commands/structure-commands.mjs.map +0 -10
- package/dist/mjs/core/commands/style-commands.mjs +0 -189
- package/dist/mjs/core/commands/style-commands.mjs.map +0 -10
- package/dist/mjs/core/commands/table-commands.mjs +0 -459
- package/dist/mjs/core/commands/table-commands.mjs.map +0 -10
- package/dist/mjs/core/commands/types.mjs +0 -59
- package/dist/mjs/core/commands/types.mjs.map +0 -10
- package/dist/mjs/core/managers/schema-manager.mjs +0 -334
- package/dist/mjs/core/managers/schema-manager.mjs.map +0 -10
- package/dist/mjs/core/schema/cell-orm.mjs +0 -35
- package/dist/mjs/core/schema/cell-orm.mjs.map +0 -10
- package/dist/mjs/core/schema/grid-orm.mjs +0 -84
- package/dist/mjs/core/schema/grid-orm.mjs.map +0 -10
- package/dist/mjs/core/schema/schema-builder.mjs +0 -34
- package/dist/mjs/core/schema/schema-builder.mjs.map +0 -10
- package/dist/mjs/core/schema/schema-helpers.mjs +0 -160
- package/dist/mjs/core/schema/schema-helpers.mjs.map +0 -10
- package/dist/mjs/core/schema/schema.mjs +0 -51
- package/dist/mjs/core/schema/schema.mjs.map +0 -10
- package/dist/mjs/core/schema/table-orm.mjs +0 -156
- package/dist/mjs/core/schema/table-orm.mjs.map +0 -10
- package/dist/types/core/commands/command-executor.d.ts +0 -81
- package/dist/types/core/commands/content-commands.d.ts +0 -172
- package/dist/types/core/commands/metadata-commands.d.ts +0 -55
- package/dist/types/core/commands/named-expression-commands.d.ts +0 -130
- package/dist/types/core/commands/structure-commands.d.ts +0 -155
- package/dist/types/core/commands/style-commands.d.ts +0 -76
- package/dist/types/core/commands/table-commands.d.ts +0 -119
- package/dist/types/core/commands/types.d.ts +0 -143
- package/dist/types/core/managers/schema-manager.d.ts +0 -142
- package/dist/types/core/schema/cell-orm.d.ts +0 -33
- package/dist/types/core/schema/grid-orm.d.ts +0 -63
- package/dist/types/core/schema/schema-builder.d.ts +0 -16
- package/dist/types/core/schema/schema-helpers.d.ts +0 -49
- package/dist/types/core/schema/schema.d.ts +0 -167
- package/dist/types/core/schema/schema.type-test.d.ts +0 -1
- 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
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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,54 +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(
|
|
47
|
+
constructor();
|
|
60
48
|
/**
|
|
61
49
|
* Static factory method to build an empty engine
|
|
62
|
-
* @template
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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">>;
|
|
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;
|
|
107
58
|
getCellEvaluationResult(cellAddress: CellAddress): SingleEvaluationResult | undefined;
|
|
108
59
|
getCellValue(cellAddress: CellAddress, debug?: boolean): SerializedCellValue;
|
|
109
60
|
/**
|
|
@@ -241,6 +192,7 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
|
|
|
241
192
|
tableName: string;
|
|
242
193
|
workbookName: string;
|
|
243
194
|
}): void;
|
|
195
|
+
private getAllTables;
|
|
244
196
|
/**
|
|
245
197
|
* Check if a table exists
|
|
246
198
|
*/
|
|
@@ -258,12 +210,6 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
|
|
|
258
210
|
resetTables(tables: Map<string, Map<string, TableDefinition>>): void;
|
|
259
211
|
getTables(workbookName: string): Map<string, TableDefinition>;
|
|
260
212
|
isCellInTable(cellAddress: CellAddress): TableDefinition | undefined;
|
|
261
|
-
/**
|
|
262
|
-
* Get all data cells in a table (excluding header row).
|
|
263
|
-
* Since spills cannot enter tables (they get #SPILL! error), this only
|
|
264
|
-
* needs to return cells with direct content.
|
|
265
|
-
*/
|
|
266
|
-
private getTableDataCells;
|
|
267
213
|
/**
|
|
268
214
|
* Add a conditional style rule
|
|
269
215
|
*/
|
|
@@ -319,6 +265,9 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
|
|
|
319
265
|
* Adjusts existing style ranges rather than deleting them entirely
|
|
320
266
|
*/
|
|
321
267
|
clearCellStyles(range: RangeAddress): void;
|
|
268
|
+
private getTopLeftCell;
|
|
269
|
+
private dedupeAddresses;
|
|
270
|
+
private getPasteTouchedAddresses;
|
|
322
271
|
/**
|
|
323
272
|
* Paste cells from source to target
|
|
324
273
|
*/
|
|
@@ -480,7 +429,6 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
|
|
|
480
429
|
* @param sheetName - The name of the sheet to set the content of
|
|
481
430
|
* @param content - A map of cell addresses to their serialized values
|
|
482
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.
|
|
483
|
-
* @throws SchemaIntegrityError if any evaluated cell value violates a schema constraint
|
|
484
432
|
*/
|
|
485
433
|
setSheetContent(opts: {
|
|
486
434
|
sheetName: string;
|
|
@@ -488,7 +436,6 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
|
|
|
488
436
|
}, content: Map<string, SerializedCellValue>): void;
|
|
489
437
|
/**
|
|
490
438
|
* Set the content of a single cell.
|
|
491
|
-
* @throws SchemaIntegrityError if the evaluated value violates a schema constraint
|
|
492
439
|
*/
|
|
493
440
|
setCellContent(address: CellAddress, content: SerializedCellValue): void;
|
|
494
441
|
/**
|
|
@@ -531,51 +478,5 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
|
|
|
531
478
|
private buildSerializedSnapshot;
|
|
532
479
|
serializeEngine(): string;
|
|
533
480
|
resetToSerializedEngine(data: string): void;
|
|
534
|
-
/**
|
|
535
|
-
* Undo the last command.
|
|
536
|
-
* @returns true if undo was performed, false if nothing to undo
|
|
537
|
-
*/
|
|
538
|
-
undo(): boolean;
|
|
539
|
-
/**
|
|
540
|
-
* Redo the last undone command.
|
|
541
|
-
* @returns true if redo was performed, false if nothing to redo
|
|
542
|
-
*/
|
|
543
|
-
redo(): boolean;
|
|
544
|
-
/**
|
|
545
|
-
* Check if undo is available.
|
|
546
|
-
*/
|
|
547
|
-
canUndo(): boolean;
|
|
548
|
-
/**
|
|
549
|
-
* Check if redo is available.
|
|
550
|
-
*/
|
|
551
|
-
canRedo(): boolean;
|
|
552
|
-
/**
|
|
553
|
-
* Get the action log for persistence/collaboration.
|
|
554
|
-
* Actions can be serialized and replayed to reconstruct state.
|
|
555
|
-
*/
|
|
556
|
-
getActionLog(): EngineAction[];
|
|
557
|
-
/**
|
|
558
|
-
* Clear the action log.
|
|
559
|
-
*/
|
|
560
|
-
clearActionLog(): void;
|
|
561
|
-
/**
|
|
562
|
-
* Clear undo/redo history.
|
|
563
|
-
*/
|
|
564
|
-
clearHistory(): void;
|
|
565
|
-
/**
|
|
566
|
-
* Get dependencies for structure commands.
|
|
567
|
-
* @internal
|
|
568
|
-
*/
|
|
569
|
-
private getStructureCommandDeps;
|
|
570
|
-
/**
|
|
571
|
-
* Get dependencies for table commands.
|
|
572
|
-
* @internal
|
|
573
|
-
*/
|
|
574
|
-
private getTableCommandDeps;
|
|
575
|
-
/**
|
|
576
|
-
* Get dependencies for named expression commands.
|
|
577
|
-
* @internal
|
|
578
|
-
*/
|
|
579
|
-
private getNamedExpressionCommandDeps;
|
|
580
481
|
}
|
|
581
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 "../
|
|
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 "../
|
|
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 {};
|
package/dist/types/lib.d.ts
CHANGED
|
@@ -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,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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