@ricsam/formula-engine 0.2.8 → 0.2.10

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 (130) hide show
  1. package/README.md +41 -3
  2. package/dist/cjs/core/engine.cjs +551 -166
  3. package/dist/cjs/core/engine.cjs.map +3 -3
  4. package/dist/cjs/core/managers/dependency-manager.cjs +151 -67
  5. package/dist/cjs/core/managers/dependency-manager.cjs.map +3 -3
  6. package/dist/cjs/core/managers/evaluation-manager.cjs.map +1 -1
  7. package/dist/cjs/core/managers/workbook-manager.cjs +197 -1
  8. package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
  9. package/dist/cjs/core/mutation-invalidation.cjs +241 -0
  10. package/dist/cjs/core/mutation-invalidation.cjs.map +10 -0
  11. package/dist/cjs/core/types.cjs.map +2 -2
  12. package/dist/cjs/core/workbook-renamer.cjs.map +1 -1
  13. package/dist/cjs/evaluator/formula-evaluator.cjs +22 -48
  14. package/dist/cjs/evaluator/formula-evaluator.cjs.map +3 -3
  15. package/dist/cjs/functions/math/sum/summation-utils.cjs +2 -2
  16. package/dist/cjs/functions/math/sum/summation-utils.cjs.map +2 -2
  17. package/dist/cjs/lib.cjs +2 -13
  18. package/dist/cjs/lib.cjs.map +3 -3
  19. package/dist/cjs/package.json +1 -1
  20. package/dist/cjs/parser/formatter.cjs +3 -4
  21. package/dist/cjs/parser/formatter.cjs.map +3 -3
  22. package/dist/cjs/parser/parser.cjs +24 -216
  23. package/dist/cjs/parser/parser.cjs.map +3 -3
  24. package/dist/mjs/core/engine.mjs +565 -207
  25. package/dist/mjs/core/engine.mjs.map +3 -3
  26. package/dist/mjs/core/managers/dependency-manager.mjs +151 -67
  27. package/dist/mjs/core/managers/dependency-manager.mjs.map +3 -3
  28. package/dist/mjs/core/managers/evaluation-manager.mjs.map +1 -1
  29. package/dist/mjs/core/managers/workbook-manager.mjs +197 -1
  30. package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
  31. package/dist/mjs/core/mutation-invalidation.mjs +201 -0
  32. package/dist/mjs/core/mutation-invalidation.mjs.map +10 -0
  33. package/dist/mjs/core/types.mjs.map +2 -2
  34. package/dist/mjs/core/workbook-renamer.mjs.map +1 -1
  35. package/dist/mjs/evaluator/formula-evaluator.mjs +22 -48
  36. package/dist/mjs/evaluator/formula-evaluator.mjs.map +3 -3
  37. package/dist/mjs/functions/math/sum/summation-utils.mjs +2 -2
  38. package/dist/mjs/functions/math/sum/summation-utils.mjs.map +2 -2
  39. package/dist/mjs/lib.mjs +2 -13
  40. package/dist/mjs/lib.mjs.map +3 -3
  41. package/dist/mjs/package.json +1 -1
  42. package/dist/mjs/parser/formatter.mjs +3 -4
  43. package/dist/mjs/parser/formatter.mjs.map +3 -3
  44. package/dist/mjs/parser/parser.mjs +24 -216
  45. package/dist/mjs/parser/parser.mjs.map +3 -3
  46. package/dist/types/core/engine.d.ts +31 -135
  47. package/dist/types/core/managers/dependency-manager.d.ts +5 -1
  48. package/dist/types/core/managers/evaluation-manager.d.ts +1 -1
  49. package/dist/types/core/managers/workbook-manager.d.ts +23 -1
  50. package/dist/types/core/mutation-invalidation.d.ts +46 -0
  51. package/dist/types/core/types.d.ts +35 -0
  52. package/dist/types/lib.d.ts +0 -8
  53. package/dist/types/parser/parser.d.ts +4 -6
  54. package/package.json +1 -1
  55. package/dist/cjs/core/commands/command-executor.cjs +0 -149
  56. package/dist/cjs/core/commands/command-executor.cjs.map +0 -10
  57. package/dist/cjs/core/commands/content-commands.cjs +0 -857
  58. package/dist/cjs/core/commands/content-commands.cjs.map +0 -10
  59. package/dist/cjs/core/commands/metadata-commands.cjs +0 -160
  60. package/dist/cjs/core/commands/metadata-commands.cjs.map +0 -10
  61. package/dist/cjs/core/commands/named-expression-commands.cjs +0 -363
  62. package/dist/cjs/core/commands/named-expression-commands.cjs.map +0 -10
  63. package/dist/cjs/core/commands/structure-commands.cjs +0 -696
  64. package/dist/cjs/core/commands/structure-commands.cjs.map +0 -10
  65. package/dist/cjs/core/commands/style-commands.cjs +0 -229
  66. package/dist/cjs/core/commands/style-commands.cjs.map +0 -10
  67. package/dist/cjs/core/commands/table-commands.cjs +0 -495
  68. package/dist/cjs/core/commands/table-commands.cjs.map +0 -10
  69. package/dist/cjs/core/commands/types.cjs +0 -99
  70. package/dist/cjs/core/commands/types.cjs.map +0 -10
  71. package/dist/cjs/core/managers/schema-manager.cjs +0 -374
  72. package/dist/cjs/core/managers/schema-manager.cjs.map +0 -10
  73. package/dist/cjs/core/schema/cell-orm.cjs +0 -76
  74. package/dist/cjs/core/schema/cell-orm.cjs.map +0 -10
  75. package/dist/cjs/core/schema/grid-orm.cjs +0 -125
  76. package/dist/cjs/core/schema/grid-orm.cjs.map +0 -10
  77. package/dist/cjs/core/schema/schema-builder.cjs +0 -74
  78. package/dist/cjs/core/schema/schema-builder.cjs.map +0 -10
  79. package/dist/cjs/core/schema/schema-helpers.cjs +0 -200
  80. package/dist/cjs/core/schema/schema-helpers.cjs.map +0 -10
  81. package/dist/cjs/core/schema/schema.cjs +0 -91
  82. package/dist/cjs/core/schema/schema.cjs.map +0 -10
  83. package/dist/cjs/core/schema/table-orm.cjs +0 -189
  84. package/dist/cjs/core/schema/table-orm.cjs.map +0 -10
  85. package/dist/mjs/core/commands/command-executor.mjs +0 -109
  86. package/dist/mjs/core/commands/command-executor.mjs.map +0 -10
  87. package/dist/mjs/core/commands/content-commands.mjs +0 -821
  88. package/dist/mjs/core/commands/content-commands.mjs.map +0 -10
  89. package/dist/mjs/core/commands/metadata-commands.mjs +0 -120
  90. package/dist/mjs/core/commands/metadata-commands.mjs.map +0 -10
  91. package/dist/mjs/core/commands/named-expression-commands.mjs +0 -323
  92. package/dist/mjs/core/commands/named-expression-commands.mjs.map +0 -10
  93. package/dist/mjs/core/commands/structure-commands.mjs +0 -661
  94. package/dist/mjs/core/commands/structure-commands.mjs.map +0 -10
  95. package/dist/mjs/core/commands/style-commands.mjs +0 -189
  96. package/dist/mjs/core/commands/style-commands.mjs.map +0 -10
  97. package/dist/mjs/core/commands/table-commands.mjs +0 -459
  98. package/dist/mjs/core/commands/table-commands.mjs.map +0 -10
  99. package/dist/mjs/core/commands/types.mjs +0 -59
  100. package/dist/mjs/core/commands/types.mjs.map +0 -10
  101. package/dist/mjs/core/managers/schema-manager.mjs +0 -334
  102. package/dist/mjs/core/managers/schema-manager.mjs.map +0 -10
  103. package/dist/mjs/core/schema/cell-orm.mjs +0 -35
  104. package/dist/mjs/core/schema/cell-orm.mjs.map +0 -10
  105. package/dist/mjs/core/schema/grid-orm.mjs +0 -84
  106. package/dist/mjs/core/schema/grid-orm.mjs.map +0 -10
  107. package/dist/mjs/core/schema/schema-builder.mjs +0 -34
  108. package/dist/mjs/core/schema/schema-builder.mjs.map +0 -10
  109. package/dist/mjs/core/schema/schema-helpers.mjs +0 -160
  110. package/dist/mjs/core/schema/schema-helpers.mjs.map +0 -10
  111. package/dist/mjs/core/schema/schema.mjs +0 -51
  112. package/dist/mjs/core/schema/schema.mjs.map +0 -10
  113. package/dist/mjs/core/schema/table-orm.mjs +0 -156
  114. package/dist/mjs/core/schema/table-orm.mjs.map +0 -10
  115. package/dist/types/core/commands/command-executor.d.ts +0 -81
  116. package/dist/types/core/commands/content-commands.d.ts +0 -172
  117. package/dist/types/core/commands/metadata-commands.d.ts +0 -55
  118. package/dist/types/core/commands/named-expression-commands.d.ts +0 -130
  119. package/dist/types/core/commands/structure-commands.d.ts +0 -155
  120. package/dist/types/core/commands/style-commands.d.ts +0 -76
  121. package/dist/types/core/commands/table-commands.d.ts +0 -119
  122. package/dist/types/core/commands/types.d.ts +0 -143
  123. package/dist/types/core/managers/schema-manager.d.ts +0 -142
  124. package/dist/types/core/schema/cell-orm.d.ts +0 -33
  125. package/dist/types/core/schema/grid-orm.d.ts +0 -63
  126. package/dist/types/core/schema/schema-builder.d.ts +0 -16
  127. package/dist/types/core/schema/schema-helpers.d.ts +0 -49
  128. package/dist/types/core/schema/schema.d.ts +0 -167
  129. package/dist/types/core/schema/schema.type-test.d.ts +0 -1
  130. package/dist/types/core/schema/table-orm.d.ts +0 -46
@@ -1,119 +0,0 @@
1
- /**
2
- * Table Commands - Commands that modify table definitions
3
- *
4
- * These commands all require re-evaluation after execution.
5
- */
6
- import type { TableManager } from "../managers/table-manager";
7
- import type { NamedExpressionManager } from "../managers/named-expression-manager";
8
- import type { WorkbookManager } from "../managers/workbook-manager";
9
- import type { SchemaManager } from "../managers/schema-manager";
10
- import type { CellAddress, SerializedCellValue, SpreadsheetRangeEnd, TableDefinition } from "../types";
11
- import type { EngineCommand, EngineAction, MutationInvalidation } from "./types";
12
- /**
13
- * Dependencies needed for table commands.
14
- */
15
- export interface TableCommandDeps {
16
- tableManager: TableManager;
17
- namedExpressionManager: NamedExpressionManager;
18
- workbookManager: WorkbookManager;
19
- apiSchemaManager: SchemaManager;
20
- getCellValue: (cellAddress: CellAddress) => SerializedCellValue;
21
- renameTableInFormula: (formula: string, oldName: string, newName: string) => string;
22
- }
23
- /**
24
- * Command to add a table.
25
- */
26
- export declare class AddTableCommand implements EngineCommand {
27
- private deps;
28
- private props;
29
- readonly requiresReevaluation = true;
30
- private executeFootprint;
31
- private undoFootprint;
32
- constructor(deps: TableCommandDeps, props: {
33
- tableName: string;
34
- sheetName: string;
35
- workbookName: string;
36
- start: string;
37
- numRows: SpreadsheetRangeEnd;
38
- numCols: number;
39
- });
40
- execute(): void;
41
- undo(): void;
42
- getInvalidationFootprint(phase: "execute" | "undo"): MutationInvalidation;
43
- toAction(): EngineAction;
44
- }
45
- /**
46
- * Command to remove a table.
47
- */
48
- export declare class RemoveTableCommand implements EngineCommand {
49
- private deps;
50
- private opts;
51
- readonly requiresReevaluation = true;
52
- private removedTable;
53
- private executeFootprint;
54
- private undoFootprint;
55
- constructor(deps: TableCommandDeps, opts: {
56
- tableName: string;
57
- workbookName: string;
58
- });
59
- execute(): void;
60
- undo(): void;
61
- getInvalidationFootprint(phase: "execute" | "undo"): MutationInvalidation;
62
- toAction(): EngineAction;
63
- }
64
- /**
65
- * Command to rename a table.
66
- */
67
- export declare class RenameTableCommand implements EngineCommand {
68
- private deps;
69
- private workbookName;
70
- private oldName;
71
- private newName;
72
- readonly requiresReevaluation = true;
73
- private executeFootprint;
74
- private undoFootprint;
75
- constructor(deps: TableCommandDeps, workbookName: string, oldName: string, newName: string);
76
- execute(): void;
77
- undo(): void;
78
- getInvalidationFootprint(phase: "execute" | "undo"): MutationInvalidation;
79
- toAction(): EngineAction;
80
- }
81
- /**
82
- * Command to update a table.
83
- */
84
- export declare class UpdateTableCommand implements EngineCommand {
85
- private deps;
86
- private opts;
87
- readonly requiresReevaluation = true;
88
- private previousTable;
89
- private executeFootprint;
90
- private undoFootprint;
91
- constructor(deps: TableCommandDeps, opts: {
92
- tableName: string;
93
- sheetName?: string;
94
- start?: string;
95
- numRows?: SpreadsheetRangeEnd;
96
- numCols?: number;
97
- workbookName: string;
98
- });
99
- execute(): void;
100
- undo(): void;
101
- getInvalidationFootprint(phase: "execute" | "undo"): MutationInvalidation;
102
- toAction(): EngineAction;
103
- }
104
- /**
105
- * Command to reset all tables.
106
- */
107
- export declare class ResetTablesCommand implements EngineCommand {
108
- private deps;
109
- private newTables;
110
- readonly requiresReevaluation = true;
111
- private previousTables;
112
- private executeFootprint;
113
- private undoFootprint;
114
- constructor(deps: TableCommandDeps, newTables: Map<string, Map<string, TableDefinition>>);
115
- execute(): void;
116
- undo(): void;
117
- getInvalidationFootprint(phase: "execute" | "undo"): MutationInvalidation;
118
- toAction(): EngineAction;
119
- }
@@ -1,143 +0,0 @@
1
- /**
2
- * Command Pattern Types for FormulaEngine
3
- *
4
- * Commands encapsulate all mutating operations on the engine,
5
- * enabling undo/redo, schema validation with rollback, and action serialization.
6
- */
7
- import type { CellAddress, SerializedCellValue } from "../types";
8
- export type CellContentKind = "empty" | "scalar" | "formula";
9
- export type RemovedScope = {
10
- type: "workbook";
11
- workbookName: string;
12
- } | {
13
- type: "sheet";
14
- workbookName: string;
15
- sheetName: string;
16
- };
17
- export type MutationInvalidation = {
18
- touchedCells: Array<{
19
- address: CellAddress;
20
- beforeKind: CellContentKind;
21
- afterKind: CellContentKind;
22
- }>;
23
- /**
24
- * Cells whose table membership or implicit current-row table context changed
25
- * without necessarily changing their formula text.
26
- */
27
- tableContextChangedCells?: CellAddress[];
28
- resourceKeys: string[];
29
- removedScopes?: RemovedScope[];
30
- };
31
- export declare function getSerializedCellValueKind(value: SerializedCellValue | undefined): CellContentKind;
32
- export declare function emptyMutationInvalidation(): MutationInvalidation;
33
- /**
34
- * Serializable action representation of a command.
35
- * Used for persistence, collaboration, and changelog functionality.
36
- */
37
- export interface EngineAction {
38
- type: string;
39
- payload: unknown;
40
- timestamp?: number;
41
- }
42
- /**
43
- * Base interface for all engine commands.
44
- */
45
- export interface EngineCommand {
46
- /**
47
- * Whether this command affects cell values/formulas and requires re-evaluation.
48
- * Commands that only affect metadata or styles don't need re-evaluation.
49
- */
50
- readonly requiresReevaluation: boolean;
51
- /**
52
- * Returns the exact mutation footprint for the last execute/undo pass.
53
- */
54
- getInvalidationFootprint?(phase: "execute" | "undo"): MutationInvalidation;
55
- /**
56
- * Execute the command (forward operation).
57
- */
58
- execute(): void;
59
- /**
60
- * Undo the command (reverse operation).
61
- */
62
- undo(): void;
63
- /**
64
- * Convert the command to a serializable action for persistence/collaboration.
65
- */
66
- toAction(): EngineAction;
67
- }
68
- /**
69
- * Options for command execution.
70
- */
71
- export interface ExecuteOptions {
72
- /**
73
- * Whether to validate schema constraints after execution.
74
- * Only applies to commands that require re-evaluation.
75
- */
76
- validate?: boolean;
77
- /**
78
- * Whether to skip adding to undo stack (for internal use).
79
- */
80
- skipUndoStack?: boolean;
81
- /**
82
- * Whether to skip emitting update events.
83
- */
84
- skipEmitUpdate?: boolean;
85
- }
86
- /**
87
- * Result of schema validation.
88
- */
89
- export interface SchemaValidationResult {
90
- valid: boolean;
91
- errors: SchemaValidationErrorInfo[];
92
- }
93
- /**
94
- * Information about a schema validation error.
95
- */
96
- export interface SchemaValidationErrorInfo {
97
- message: string;
98
- cellAddress?: CellAddress;
99
- schemaNamespace?: string;
100
- columnName?: string;
101
- originalError?: Error;
102
- }
103
- /**
104
- * Action types for all commands.
105
- * Used for serialization and deserialization.
106
- */
107
- export declare const ActionTypes: {
108
- readonly SET_CELL_CONTENT: "SET_CELL_CONTENT";
109
- readonly SET_SHEET_CONTENT: "SET_SHEET_CONTENT";
110
- readonly CLEAR_RANGE: "CLEAR_RANGE";
111
- readonly PASTE_CELLS: "PASTE_CELLS";
112
- readonly FILL_AREAS: "FILL_AREAS";
113
- readonly MOVE_CELL: "MOVE_CELL";
114
- readonly MOVE_RANGE: "MOVE_RANGE";
115
- readonly AUTO_FILL: "AUTO_FILL";
116
- readonly ADD_WORKBOOK: "ADD_WORKBOOK";
117
- readonly REMOVE_WORKBOOK: "REMOVE_WORKBOOK";
118
- readonly RENAME_WORKBOOK: "RENAME_WORKBOOK";
119
- readonly CLONE_WORKBOOK: "CLONE_WORKBOOK";
120
- readonly ADD_SHEET: "ADD_SHEET";
121
- readonly REMOVE_SHEET: "REMOVE_SHEET";
122
- readonly RENAME_SHEET: "RENAME_SHEET";
123
- readonly ADD_TABLE: "ADD_TABLE";
124
- readonly REMOVE_TABLE: "REMOVE_TABLE";
125
- readonly RENAME_TABLE: "RENAME_TABLE";
126
- readonly UPDATE_TABLE: "UPDATE_TABLE";
127
- readonly RESET_TABLES: "RESET_TABLES";
128
- readonly ADD_NAMED_EXPRESSION: "ADD_NAMED_EXPRESSION";
129
- readonly REMOVE_NAMED_EXPRESSION: "REMOVE_NAMED_EXPRESSION";
130
- readonly UPDATE_NAMED_EXPRESSION: "UPDATE_NAMED_EXPRESSION";
131
- readonly RENAME_NAMED_EXPRESSION: "RENAME_NAMED_EXPRESSION";
132
- readonly SET_NAMED_EXPRESSIONS: "SET_NAMED_EXPRESSIONS";
133
- readonly SET_CELL_METADATA: "SET_CELL_METADATA";
134
- readonly SET_SHEET_METADATA: "SET_SHEET_METADATA";
135
- readonly SET_WORKBOOK_METADATA: "SET_WORKBOOK_METADATA";
136
- readonly ADD_CONDITIONAL_STYLE: "ADD_CONDITIONAL_STYLE";
137
- readonly REMOVE_CONDITIONAL_STYLE: "REMOVE_CONDITIONAL_STYLE";
138
- readonly ADD_CELL_STYLE: "ADD_CELL_STYLE";
139
- readonly REMOVE_CELL_STYLE: "REMOVE_CELL_STYLE";
140
- readonly CLEAR_CELL_STYLES: "CLEAR_CELL_STYLES";
141
- readonly RESET_TO_SERIALIZED: "RESET_TO_SERIALIZED";
142
- };
143
- export type ActionType = (typeof ActionTypes)[keyof typeof ActionTypes];
@@ -1,142 +0,0 @@
1
- /**
2
- * SchemaManager - Manages schema definitions and validation
3
- *
4
- * Tracks registered schemas and provides validation for cell writes,
5
- * spill operations, and copy/paste operations.
6
- */
7
- import type { CellAddress, FiniteSpreadsheetRange, SerializedCellValue, SpreadsheetRange, TableDefinition } from "../types";
8
- import type { TableManager } from "./table-manager";
9
- export type ParseFunction<TCellMetadata = unknown> = (value: SerializedCellValue, metadata: TCellMetadata) => unknown;
10
- export type WriteFunction<TCellMetadata = unknown> = (value: any) => {
11
- value: SerializedCellValue;
12
- metadata?: TCellMetadata;
13
- };
14
- export type TableSchemaHeaders<TCellMetadata = unknown> = Record<string, {
15
- parse: ParseFunction<TCellMetadata>;
16
- write: WriteFunction<TCellMetadata>;
17
- index: number;
18
- }>;
19
- export interface RegisteredTableSchema {
20
- type: "table";
21
- namespace: string;
22
- workbookName: string;
23
- tableName: string;
24
- headers: TableSchemaHeaders;
25
- }
26
- export interface RegisteredCellSchema {
27
- type: "cell";
28
- namespace: string;
29
- cellAddress: CellAddress;
30
- parse: ParseFunction;
31
- }
32
- export interface RegisteredGridSchema {
33
- type: "grid";
34
- namespace: string;
35
- workbookName: string;
36
- sheetName: string;
37
- range: FiniteSpreadsheetRange;
38
- parse: ParseFunction;
39
- }
40
- export type RegisteredSchema = RegisteredTableSchema | RegisteredCellSchema | RegisteredGridSchema;
41
- export interface ValidationResult {
42
- valid: boolean;
43
- error?: string;
44
- originalError?: Error;
45
- }
46
- export declare class SchemaValidationError extends Error {
47
- cellAddress?: CellAddress | undefined;
48
- originalError?: Error | undefined;
49
- constructor(message: string, cellAddress?: CellAddress | undefined, originalError?: Error | undefined);
50
- }
51
- export declare class SchemaManager {
52
- private tableManager;
53
- private schemas;
54
- constructor(tableManager: TableManager);
55
- /**
56
- * Register a table schema
57
- */
58
- registerTableSchema(namespace: string, workbookName: string, tableName: string, headers: TableSchemaHeaders): void;
59
- /**
60
- * Register a cell schema
61
- */
62
- registerCellSchema(namespace: string, cellAddress: CellAddress, parse: ParseFunction): void;
63
- /**
64
- * Register a grid schema
65
- */
66
- registerGridSchema(namespace: string, workbookName: string, sheetName: string, range: FiniteSpreadsheetRange, parse: ParseFunction): void;
67
- /**
68
- * Get a schema by namespace
69
- */
70
- getSchema(namespace: string): RegisteredSchema | undefined;
71
- /**
72
- * Remove a schema
73
- */
74
- removeSchema(namespace: string): boolean;
75
- /**
76
- * Check if any schemas are registered
77
- */
78
- hasSchemas(): boolean;
79
- /**
80
- * Check if a cell is protected by a schema
81
- * Returns the schema info if protected, null otherwise
82
- */
83
- isCellProtected(cell: CellAddress): {
84
- schema: RegisteredSchema;
85
- columnName?: string;
86
- } | null;
87
- /**
88
- * Check if a cell is within a table's data range (excluding header row)
89
- */
90
- private isCellInTableDataRange;
91
- /**
92
- * Get column name by index from headers
93
- */
94
- private getColumnNameByIndex;
95
- /**
96
- * Validate a cell write against schemas
97
- */
98
- validateCellWrite(cell: CellAddress, value: SerializedCellValue, metadata?: unknown): ValidationResult;
99
- /**
100
- * Validate a spill area against schemas
101
- * Returns validation result - if invalid, spill should produce #SPILL! error
102
- */
103
- validateSpillArea(origin: CellAddress, spillArea: SpreadsheetRange, getSpillValue: (row: number, col: number) => SerializedCellValue, getMetadata?: (cell: CellAddress) => unknown): ValidationResult;
104
- /**
105
- * Update schemas when a table is renamed
106
- */
107
- updateForTableRename(workbookName: string, oldTableName: string, newTableName: string): void;
108
- /**
109
- * Update schemas when a sheet is renamed
110
- */
111
- updateForSheetRename(workbookName: string, oldSheetName: string, newSheetName: string): void;
112
- /**
113
- * Update schemas when a workbook is renamed
114
- */
115
- updateForWorkbookRename(oldWorkbookName: string, newWorkbookName: string): void;
116
- /**
117
- * Get all schemas (for debugging/testing)
118
- */
119
- getAllSchemas(): Map<string, RegisteredSchema>;
120
- /**
121
- * Validate all schema constraints using evaluated cell values.
122
- *
123
- * This is the key method for schema validation with rollback:
124
- * - It validates EVALUATED values, not raw content
125
- * - A cell with "=123+123" validates as number (246), not string
126
- * - Called after re-evaluation to check all schema-constrained cells
127
- *
128
- * @param getCellValue - Function to get the evaluated value of a cell
129
- * @param getCellMetadata - Optional function to get cell metadata
130
- * @returns Validation result with all errors found
131
- */
132
- validateAllSchemaConstraints(getCellValue: (cell: CellAddress) => SerializedCellValue, getCellMetadata?: (cell: CellAddress) => unknown, getTableDataCells?: (table: TableDefinition) => CellAddress[]): {
133
- valid: boolean;
134
- errors: Array<{
135
- message: string;
136
- cellAddress?: CellAddress;
137
- schemaNamespace?: string;
138
- columnName?: string;
139
- originalError?: Error;
140
- }>;
141
- };
142
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * CellOrm - Object-Relational Mapping for single cell data
3
- *
4
- * Provides read/write operations for a single cell with type-safe access.
5
- * Used as the `this` context for custom cell API methods.
6
- */
7
- import type { CellAddress, SerializedCellValue } from "../types";
8
- import type { FormulaEngine } from "../engine";
9
- export type CellParseFunction<TCellMetadata, TValue> = (value: unknown, metadata: TCellMetadata) => TValue;
10
- export type CellWriteFunction<TCellMetadata, TValue> = (value: TValue) => {
11
- value: SerializedCellValue;
12
- metadata?: TCellMetadata;
13
- };
14
- export declare class CellOrm<TValue, TCellMetadata = unknown> {
15
- private engine;
16
- private cellAddress;
17
- private parser;
18
- private writer;
19
- private namespace;
20
- constructor(engine: FormulaEngine<any, any>, cellAddress: CellAddress, parser: CellParseFunction<TCellMetadata, TValue>, writer: CellWriteFunction<TCellMetadata, TValue>, namespace: string);
21
- /**
22
- * Read the cell value and parse it using the schema's parse function
23
- */
24
- read(): TValue;
25
- /**
26
- * Write a value to the cell using the schema's write function
27
- */
28
- write(value: TValue): void;
29
- /**
30
- * Get the cell address
31
- */
32
- getAddress(): CellAddress;
33
- }
@@ -1,63 +0,0 @@
1
- /**
2
- * GridOrm - Object-Relational Mapping for grid/range data
3
- *
4
- * Provides read/write operations for a 2D range of cells with type-safe access.
5
- * Supports both column-major and row-major array access patterns.
6
- */
7
- import type { FiniteSpreadsheetRange, SerializedCellValue } from "../types";
8
- import type { FormulaEngine } from "../engine";
9
- export type GridParseFunction<TCellMetadata, TValue> = (value: unknown, metadata: TCellMetadata) => TValue;
10
- export type GridWriteFunction<TCellMetadata, TValue> = (value: TValue) => {
11
- value: SerializedCellValue;
12
- metadata?: TCellMetadata;
13
- };
14
- export declare class GridOrm<TValue, TCellMetadata = unknown> {
15
- private engine;
16
- private workbookName;
17
- private sheetName;
18
- private range;
19
- private parser;
20
- private writer;
21
- private namespace;
22
- private numCols;
23
- private numRows;
24
- constructor(engine: FormulaEngine<any, any>, workbookName: string, sheetName: string, range: FiniteSpreadsheetRange, parser: GridParseFunction<TCellMetadata, TValue>, writer: GridWriteFunction<TCellMetadata, TValue>, namespace: string);
25
- /**
26
- * Get the cell address for a given column and row index within the grid
27
- */
28
- private getCellAddress;
29
- /**
30
- * Read a single cell and parse it
31
- */
32
- private readCell;
33
- /**
34
- * Write a single cell using the write function
35
- */
36
- private writeCell;
37
- /**
38
- * Get all cells as a column-major 2D array (readonly)
39
- * columns[colIndex][rowIndex]
40
- */
41
- get columns(): readonly (readonly TValue[])[];
42
- /**
43
- * Get all cells as a row-major 2D array (readonly)
44
- * rows[rowIndex][colIndex]
45
- */
46
- get rows(): readonly (readonly TValue[])[];
47
- /**
48
- * Set a single value at the specified position
49
- * Position is relative to the grid (0-indexed)
50
- */
51
- setValue(value: TValue, position: {
52
- col: number;
53
- row: number;
54
- }): void;
55
- /**
56
- * Get a single value at the specified position
57
- * Position is relative to the grid (0-indexed)
58
- */
59
- getValue(position: {
60
- col: number;
61
- row: number;
62
- }): TValue;
63
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * Schema Builder - Constructs the working schema from declarations
3
- *
4
- * This module is responsible for creating the actual working schema
5
- * from the schema declarations when attached to a FormulaEngine.
6
- */
7
- import type { FormulaEngine } from "../engine";
8
- import type { SchemaDeclaration, Schema } from "./schema";
9
- import type { SchemaManager } from "../managers/schema-manager";
10
- /**
11
- * Build the working schema surface from declarations
12
- *
13
- * This creates TableOrm, CellOrm, and GridOrm instances for each declared schema
14
- * and returns them directly.
15
- */
16
- export declare function buildSchemaFromDeclaration(engine: FormulaEngine<any, any>, declaration: SchemaDeclaration, schemaManager: SchemaManager): Schema;
@@ -1,49 +0,0 @@
1
- /**
2
- * Schema Helper utilities for row/object conversion and filtering
3
- */
4
- import type { CellAddress, SerializedCellValue, TableDefinition } from "../types";
5
- import type { FormulaEngine } from "../engine";
6
- export type ParseFunction<TCellMetadata = unknown> = (value: SerializedCellValue, metadata: TCellMetadata) => unknown;
7
- export type WriteFunction<TCellMetadata = unknown> = (value: unknown) => {
8
- value: SerializedCellValue;
9
- metadata?: TCellMetadata;
10
- };
11
- export type TableSchemaHeaders<TCellMetadata = unknown> = Record<string, {
12
- parse: ParseFunction<TCellMetadata>;
13
- write: WriteFunction<TCellMetadata>;
14
- index: number;
15
- }>;
16
- /**
17
- * Convert a spreadsheet row to a typed object using header parsers
18
- */
19
- export declare function rowToObject<TItem extends Record<string, unknown>>(engine: FormulaEngine<any, any>, table: TableDefinition, rowIndex: number, headers: TableSchemaHeaders, getCellMetadata?: (cell: CellAddress) => unknown): TItem;
20
- /**
21
- * Result from objectToRowValues including both values and optional metadata
22
- */
23
- export type RowValuesResult<TCellMetadata = unknown> = {
24
- values: Map<number, SerializedCellValue>;
25
- metadata: Map<number, TCellMetadata>;
26
- };
27
- /**
28
- * Convert a typed object to cell values based on headers using write functions
29
- */
30
- export declare function objectToRowValues<TItem extends Record<string, unknown>, TCellMetadata = unknown>(obj: TItem, headers: TableSchemaHeaders<TCellMetadata>): RowValuesResult<TCellMetadata>;
31
- /**
32
- * Check if an object matches a filter predicate
33
- */
34
- export declare function matchesFilter<TItem extends Record<string, unknown>>(item: TItem, filter: Partial<TItem>): boolean;
35
- /**
36
- * Get the number of data rows in a table (excluding header)
37
- */
38
- export declare function getTableRowCount(engine: FormulaEngine<any, any>, table: TableDefinition): number;
39
- /**
40
- * Get the next empty row index for appending data
41
- */
42
- export declare function getNextEmptyRow(engine: FormulaEngine<any, any>, table: TableDefinition): number;
43
- /**
44
- * Iterate over all data rows in a table
45
- */
46
- export declare function iterateTableRows(engine: FormulaEngine<any, any>, table: TableDefinition): Generator<{
47
- rowIndex: number;
48
- isEmpty: boolean;
49
- }>;