@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.
Files changed (101) hide show
  1. package/README.md +1 -3
  2. package/dist/cjs/core/engine.cjs +518 -149
  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 +532 -190
  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 -116
  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
  "version": 3,
3
3
  "sources": ["../../../../src/core/managers/evaluation-manager.ts"],
4
4
  "sourcesContent": [
5
- "import { flags } from \"../../debug/flags.mjs\";\nimport { AstEvaluationNode } from \"../../evaluator/dependency-nodes/ast-evaluation-node.mjs\";\nimport { CellValueNode } from \"../../evaluator/dependency-nodes/cell-value-node.mjs\";\nimport { EvaluationContext } from \"../../evaluator/evaluation-context.mjs\";\nimport {\n EvaluationError,\n SheetNotFoundError,\n} from \"../../evaluator/evaluation-error.mjs\";\nimport { RangeEvaluationNode } from \"../../evaluator/range-evaluation-node.mjs\";\nimport { normalizeSerializedCellValue } from \"../../parser/formatter.mjs\";\nimport { FormulaEvaluator } from \"../../evaluator/formula-evaluator.mjs\";\nimport {\n FormulaError,\n type CellAddress,\n type CellInRangeResult,\n type CellValue,\n type ErrorEvaluationResult,\n type EvaluateAllCellsResult,\n type EvaluationOrder,\n type FunctionEvaluationResult,\n type SerializedCellValue,\n type SingleEvaluationResult,\n type SpreadsheetRange,\n type ValueEvaluationResult,\n} from \"../types.mjs\";\nimport {\n captureEvaluationErrors,\n getAbsoluteRange,\n cellAddressToKey,\n checkRangeIntersection,\n getCellReference,\n getRangeIntersection,\n getRelativeRange,\n isCellInRange,\n parseCellReference,\n rangeAddressToKey,\n} from \"../utils.mjs\";\nimport type { DependencyManager } from \"./dependency-manager.mjs\";\nimport type { WorkbookManager } from \"./workbook-manager.mjs\";\nimport { SpillMetaNode } from \"../../evaluator/dependency-nodes/spill-meta-node.mjs\";\nimport { EmptyCellEvaluationNode } from \"../../evaluator/dependency-nodes/empty-cell-evaluation-node.mjs\";\nimport type { TableManager } from \"./table-manager.mjs\";\nimport type { DependencyNode } from \"./dependency-node.mjs\";\nimport { VirtualCellValueNode } from \"../../evaluator/dependency-nodes/virtual-cell-value-node.mjs\";\nimport { ResourceDependencyNode } from \"../../evaluator/dependency-nodes/resource-dependency-node.mjs\";\nimport type {\n NodeSnapshotId,\n SerializedCellInRangeResultSnapshot,\n SerializedErrorEvaluationResultSnapshot,\n SerializedEvaluateAllCellsResultSnapshot,\n SerializedFunctionEvaluationResultSnapshot,\n SerializedSingleEvaluationResultSnapshot,\n SerializedSpillMetaEvaluationResultSnapshot,\n SerializedSpilledValuesEvaluationResultSnapshot,\n} from \"../engine-snapshot.mjs\";\nimport type { MutationInvalidation } from \"../commands/types.mjs\";\n\nexport class EvaluationManager {\n private isEvaluating = false;\n\n constructor(\n private workbookManager: WorkbookManager,\n private tableManager: TableManager,\n private formulaEvaluator: FormulaEvaluator,\n private dependencyManager: DependencyManager\n ) {}\n\n clearEvaluationCache(): void {\n this.dependencyManager.clearEvaluationCache();\n }\n\n private dependsOnNode(\n candidate: DependencyNode,\n target: DependencyNode,\n visited: Set<DependencyNode> = new Set()\n ): boolean {\n if (candidate === target) {\n return true;\n }\n\n if (visited.has(candidate)) {\n return false;\n }\n visited.add(candidate);\n\n for (const dep of candidate.getDependencies()) {\n if (this.dependsOnNode(dep, target, visited)) {\n return true;\n }\n }\n\n return false;\n }\n\n invalidateFromMutation(footprint: MutationInvalidation): void {\n this.dependencyManager.invalidateFromMutation(footprint);\n }\n\n evaluationResultToSerializedValue(\n evaluation: SingleEvaluationResult,\n cellAddress: CellAddress,\n debug?: boolean\n ): SerializedCellValue {\n if (\n evaluation.type !== \"error\" &&\n evaluation.type !== \"awaiting-evaluation\"\n ) {\n const value = evaluation.result;\n\n return value.type === \"infinity\"\n ? value.sign === \"positive\"\n ? \"INFINITY\"\n : \"-INFINITY\"\n : value.value;\n }\n\n if (evaluation.type === \"awaiting-evaluation\") {\n return (\n evaluation.errAddress.key +\n \" is awaiting evaluation of \" +\n evaluation.waitingFor.key\n );\n }\n\n if (debug) {\n const errAddress = evaluation.errAddress.key;\n if (errAddress === cellAddressToKey(cellAddress)) {\n return evaluation.err + \" \" + evaluation.message;\n }\n return (\n evaluation.err +\n \" in \" +\n evaluation.errAddress.key +\n \" \" +\n evaluation.message\n );\n }\n\n return evaluation.err;\n }\n\n private buildSnapshotOrigin(\n node: CellValueNode | SpillMetaNode | AstEvaluationNode\n ): CellAddress {\n if (\"cellAddress\" in node) {\n return node.cellAddress;\n }\n\n const contextDependency = node.getContextDependency();\n return {\n workbookName: contextDependency.workbookName ?? \"__snapshot__\",\n sheetName: contextDependency.sheetName ?? \"__snapshot__\",\n colIndex: contextDependency.colIndex ?? 0,\n rowIndex: contextDependency.rowIndex ?? 0,\n };\n }\n\n private serializeErrorEvaluationResultSnapshot(\n evaluation: Exclude<ErrorEvaluationResult, { type: \"awaiting-evaluation\" }>,\n getNodeSnapshotId: (node: DependencyNode) => NodeSnapshotId\n ): SerializedErrorEvaluationResultSnapshot {\n return {\n type: \"error\",\n err: evaluation.err,\n message: evaluation.message,\n errAddressId: getNodeSnapshotId(evaluation.errAddress),\n sourceCell: evaluation.sourceCell,\n };\n }\n\n serializeSingleEvaluationResultSnapshot(\n evaluation: SingleEvaluationResult,\n getNodeSnapshotId: (node: DependencyNode) => NodeSnapshotId\n ): SerializedSingleEvaluationResultSnapshot | undefined {\n if (evaluation.type === \"awaiting-evaluation\") {\n return undefined;\n }\n\n if (evaluation.type === \"error\") {\n return this.serializeErrorEvaluationResultSnapshot(\n evaluation,\n getNodeSnapshotId\n );\n }\n\n return {\n type: \"value\",\n result: evaluation.result,\n sourceCell: evaluation.sourceCell,\n };\n }\n\n deserializeSingleEvaluationResultSnapshot(\n evaluation: SerializedSingleEvaluationResultSnapshot,\n resolveNodeSnapshotId: (nodeId: NodeSnapshotId) => DependencyNode\n ): SingleEvaluationResult {\n if (evaluation.type === \"error\") {\n return {\n type: \"error\",\n err: evaluation.err,\n message: evaluation.message,\n errAddress: resolveNodeSnapshotId(evaluation.errAddressId),\n sourceCell: evaluation.sourceCell,\n };\n }\n\n return {\n type: \"value\",\n result: evaluation.result,\n sourceCell: evaluation.sourceCell,\n };\n }\n\n serializeEvaluateAllCellsResultSnapshot(\n evaluation: EvaluateAllCellsResult,\n getNodeSnapshotId: (node: DependencyNode) => NodeSnapshotId\n ): SerializedEvaluateAllCellsResultSnapshot | undefined {\n if (evaluation.type === \"awaiting-evaluation\") {\n return undefined;\n }\n\n if (evaluation.type === \"error\") {\n return this.serializeErrorEvaluationResultSnapshot(\n evaluation,\n getNodeSnapshotId\n );\n }\n\n const values: SerializedCellInRangeResultSnapshot[] = [];\n for (const value of evaluation.values) {\n const serialized = this.serializeSingleEvaluationResultSnapshot(\n value.result,\n getNodeSnapshotId\n );\n if (!serialized) {\n return undefined;\n }\n values.push({\n relativePos: value.relativePos,\n result: serialized,\n });\n }\n\n return {\n type: \"values\",\n values,\n };\n }\n\n deserializeEvaluateAllCellsResultSnapshot(\n evaluation: SerializedEvaluateAllCellsResultSnapshot,\n resolveNodeSnapshotId: (nodeId: NodeSnapshotId) => DependencyNode\n ): EvaluateAllCellsResult {\n if (evaluation.type === \"error\") {\n return this.deserializeSingleEvaluationResultSnapshot(\n evaluation,\n resolveNodeSnapshotId\n ) as ErrorEvaluationResult;\n }\n\n return {\n type: \"values\",\n values: evaluation.values.map((value) => ({\n relativePos: value.relativePos,\n result: this.deserializeSingleEvaluationResultSnapshot(\n value.result,\n resolveNodeSnapshotId\n ),\n })),\n };\n }\n\n serializeFunctionEvaluationResultSnapshot(\n evaluation: FunctionEvaluationResult,\n options: {\n sourceNode: CellValueNode | SpillMetaNode | AstEvaluationNode;\n getNodeSnapshotId: (node: DependencyNode) => NodeSnapshotId;\n }\n ): SerializedFunctionEvaluationResultSnapshot | undefined {\n if (evaluation.type !== \"spilled-values\") {\n return this.serializeSingleEvaluationResultSnapshot(\n evaluation,\n options.getNodeSnapshotId\n );\n }\n\n const origin = this.buildSnapshotOrigin(options.sourceNode);\n const spillArea = evaluation.spillArea(origin);\n const relativeSpillArea = getRelativeRange(spillArea, {\n colIndex: origin.colIndex,\n rowIndex: origin.rowIndex,\n });\n\n if (evaluation.sourceRange) {\n return {\n type: \"spilled-values\",\n spill: {\n kind: \"source-range\",\n relativeSpillArea,\n source: evaluation.source,\n sourceCell: evaluation.sourceCell,\n sourceRange: evaluation.sourceRange,\n },\n };\n }\n\n if (\n relativeSpillArea.width.type !== \"number\" ||\n relativeSpillArea.height.type !== \"number\"\n ) {\n return undefined;\n }\n\n const context = new EvaluationContext(\n this.tableManager,\n options.sourceNode,\n origin\n );\n const values: SerializedCellInRangeResultSnapshot[] = [];\n\n for (let y = 0; y < relativeSpillArea.height.value; y++) {\n for (let x = 0; x < relativeSpillArea.width.value; x++) {\n const result = captureEvaluationErrors(options.sourceNode, () =>\n evaluation.evaluate({ x, y }, context)\n );\n const serialized = this.serializeSingleEvaluationResultSnapshot(\n result,\n options.getNodeSnapshotId\n );\n if (!serialized) {\n return undefined;\n }\n values.push({\n relativePos: { x, y },\n result: serialized,\n });\n }\n }\n\n return {\n type: \"spilled-values\",\n spill: {\n kind: \"materialized\",\n relativeSpillArea,\n source: evaluation.source,\n sourceCell: evaluation.sourceCell,\n sourceRange: evaluation.sourceRange,\n values,\n },\n };\n }\n\n deserializeFunctionEvaluationResultSnapshot(\n evaluation: SerializedFunctionEvaluationResultSnapshot,\n resolveNodeSnapshotId: (nodeId: NodeSnapshotId) => DependencyNode\n ): FunctionEvaluationResult {\n if (evaluation.type !== \"spilled-values\") {\n return this.deserializeSingleEvaluationResultSnapshot(\n evaluation,\n resolveNodeSnapshotId\n );\n }\n\n const spillSnapshot = evaluation.spill;\n if (spillSnapshot.kind === \"materialized\") {\n const values = new Map(\n spillSnapshot.values.map((value) => [\n `${value.relativePos.x},${value.relativePos.y}`,\n this.deserializeSingleEvaluationResultSnapshot(\n value.result,\n resolveNodeSnapshotId\n ),\n ])\n );\n\n return {\n type: \"spilled-values\",\n source: spillSnapshot.source,\n sourceCell: spillSnapshot.sourceCell,\n sourceRange: spillSnapshot.sourceRange,\n spillArea: (origin) =>\n getAbsoluteRange(spillSnapshot.relativeSpillArea, {\n colIndex: origin.colIndex,\n rowIndex: origin.rowIndex,\n }),\n evaluate: (spillOffset) =>\n values.get(`${spillOffset.x},${spillOffset.y}`) ?? {\n type: \"value\",\n result: this.convertScalarValueToCellValue(\"\"),\n },\n evaluateAllCells: () => ({\n type: \"values\",\n values: spillSnapshot.values.map((value) => ({\n relativePos: value.relativePos,\n result: this.deserializeSingleEvaluationResultSnapshot(\n value.result,\n resolveNodeSnapshotId\n ),\n })),\n }),\n };\n }\n\n return {\n type: \"spilled-values\",\n source: spillSnapshot.source,\n sourceCell: spillSnapshot.sourceCell,\n sourceRange: spillSnapshot.sourceRange,\n spillArea: (origin) =>\n getAbsoluteRange(spillSnapshot.relativeSpillArea, {\n colIndex: origin.colIndex,\n rowIndex: origin.rowIndex,\n }),\n evaluate: (spillOffset, context) => {\n const cellAddress: CellAddress = {\n workbookName: spillSnapshot.sourceRange.workbookName,\n sheetName: spillSnapshot.sourceRange.sheetName,\n colIndex: spillSnapshot.sourceRange.range.start.col + spillOffset.x,\n rowIndex: spillSnapshot.sourceRange.range.start.row + spillOffset.y,\n };\n\n const evalNode = this.dependencyManager.getCellValueOrEmptyCellNode(\n cellAddressToKey(cellAddress)\n );\n context.dependencyNode.addDependency(evalNode);\n return evalNode.evaluationResult;\n },\n evaluateAllCells: ({ intersection, context, origin }) => {\n let range = spillSnapshot.sourceRange.range;\n if (intersection) {\n const relativeRange = getRelativeRange(intersection, origin);\n const projectedIntersection = getAbsoluteRange(relativeRange, {\n colIndex: spillSnapshot.sourceRange.range.start.col,\n rowIndex: spillSnapshot.sourceRange.range.start.row,\n });\n const nextRange = getRangeIntersection(\n spillSnapshot.sourceRange.range,\n projectedIntersection\n );\n if (nextRange) {\n range = nextRange;\n }\n }\n\n const rangeAddress = {\n workbookName: spillSnapshot.sourceRange.workbookName,\n sheetName: spillSnapshot.sourceRange.sheetName,\n range,\n };\n\n const rangeNode = this.dependencyManager.getRangeNode(\n rangeAddressToKey(rangeAddress)\n );\n context.dependencyNode.addDependency(rangeNode);\n return rangeNode.result;\n },\n };\n }\n\n serializeSpillMetaEvaluationResultSnapshot(\n evaluation: SpillMetaNode[\"evaluationResult\"],\n options: {\n sourceNode: CellValueNode | SpillMetaNode | AstEvaluationNode;\n getNodeSnapshotId: (node: DependencyNode) => NodeSnapshotId;\n }\n ): SerializedSpillMetaEvaluationResultSnapshot | undefined {\n if (evaluation.type === \"does-not-spill\") {\n return { type: \"does-not-spill\" };\n }\n\n if (evaluation.type === \"error\") {\n return this.serializeErrorEvaluationResultSnapshot(\n evaluation,\n options.getNodeSnapshotId\n );\n }\n\n const serialized = this.serializeFunctionEvaluationResultSnapshot(\n evaluation,\n options\n );\n if (!serialized || serialized.type !== \"spilled-values\") {\n return undefined;\n }\n\n return serialized;\n }\n\n deserializeSpillMetaEvaluationResultSnapshot(\n evaluation: SerializedSpillMetaEvaluationResultSnapshot,\n resolveNodeSnapshotId: (nodeId: NodeSnapshotId) => DependencyNode\n ): SpillMetaNode[\"evaluationResult\"] {\n if (evaluation.type === \"does-not-spill\") {\n return evaluation;\n }\n\n if (evaluation.type === \"error\") {\n return this.deserializeSingleEvaluationResultSnapshot(\n evaluation,\n resolveNodeSnapshotId\n ) as SpillMetaNode[\"evaluationResult\"];\n }\n\n return this.deserializeFunctionEvaluationResultSnapshot(\n evaluation,\n resolveNodeSnapshotId\n ) as SpillMetaNode[\"evaluationResult\"];\n }\n\n evaluateEmptyCell(node: EmptyCellEvaluationNode): void {\n if (node.resolved) {\n const result = node.evaluationResult;\n if (result && result.type !== \"awaiting-evaluation\") {\n return;\n }\n }\n\n this.dependencyManager.unregisterNode(node);\n node.resetDirectDepsUpdated();\n\n const ctx = new EvaluationContext(\n this.tableManager,\n node,\n node.cellAddress\n );\n const inSpilled = this.dependencyManager.getSpillValue(node.cellAddress);\n\n if (inSpilled) {\n // if we are spilling then we can just add the spill origin as a dependency and evaluate the spilled value\n const spillTarget = this.dependencyManager.getSpilledAddress(\n node.cellAddress,\n inSpilled\n );\n const spillOriginKey = cellAddressToKey(inSpilled.origin).replace(\n /^[^:]+:/,\n \"spill-meta:\"\n );\n const spillMetaNode =\n this.dependencyManager.getSpillMetaNode(spillOriginKey);\n node.addDependency(spillMetaNode);\n const result = spillMetaNode.evaluationResult;\n if (result.type === \"spilled-values\") {\n // let's evaluate the spilled value to extract dependencies\n const evaluation = captureEvaluationErrors(spillMetaNode, () => {\n return result.evaluate(spillTarget.spillOffset, ctx);\n });\n node.setEvaluationResult(evaluation);\n }\n } else {\n // upgrade any frontier dependencies that spill into the range\n node.upgradeFrontierDependencies();\n\n const evaluationResult: SingleEvaluationResult = {\n type: \"value\",\n result: this.convertScalarValueToCellValue(\"\"),\n };\n // for now let's just store the empty value, the next time the cell is evaluated isSpilled will be true and the spilled value will be evaluated\n node.setEvaluationResult(evaluationResult);\n }\n\n this.dependencyManager.registerNode(node);\n }\n\n evaluateRangeNode(node: RangeEvaluationNode): void {\n if (node.resolved) {\n return;\n }\n\n this.dependencyManager.unregisterNode(node);\n node.resetDirectDepsUpdated();\n\n const result = captureEvaluationErrors(node, (): EvaluateAllCellsResult => {\n node.upgradeFrontierDependencies();\n\n const evalOrder = node.getRangeEvalOrder();\n const circularEntryCache = new Map<DependencyNode, boolean>();\n const shouldSkipCircularEntry = (candidate: DependencyNode) => {\n const cached = circularEntryCache.get(candidate);\n if (cached !== undefined) {\n return cached;\n }\n\n // If a cell inside the range depends back on the range itself, including\n // its current value would count a circular result back into the same\n // aggregate on a later rerun.\n const isCircular = this.dependsOnNode(candidate, node);\n circularEntryCache.set(candidate, isCircular);\n return isCircular;\n };\n\n const results: CellInRangeResult[] = [];\n\n for (const entry of evalOrder) {\n if (entry.type === \"value\") {\n if (shouldSkipCircularEntry(entry.node)) {\n continue;\n }\n\n const entryAddress = entry.address;\n const result = entry.node.evaluationResult;\n\n const relativePos = {\n x: entryAddress.colIndex - node.address.range.start.col,\n y: entryAddress.rowIndex - node.address.range.start.row,\n };\n\n results.push({ result: result, relativePos });\n } else if (\n entry.type === \"empty_cell\" ||\n entry.type === \"empty_range\"\n ) {\n for (const candidateNode of entry.candidates) {\n if (shouldSkipCircularEntry(candidateNode)) {\n continue;\n }\n\n if (candidateNode.evaluationResult.type === \"spilled-values\") {\n const spillArea = candidateNode.evaluationResult.spillArea(\n candidateNode.cellAddress\n );\n if (entry.type === \"empty_range\") {\n const intersects = checkRangeIntersection(\n spillArea,\n entry.address.range\n );\n if (intersects) {\n // When a spilled range intersects with our target range, we need to evaluate\n // only the cells that fall within the intersection area.\n //\n // Example: If cell A10 contains a spilled range that covers A10:B11,\n // and our target range is B10:INFINITY, then we only want to evaluate\n // the intersection B10:B11 from the spilled range.\n //\n // The evaluateAllCells method expects the intersection to be passed\n // so it can limit evaluation to only the relevant cells.\n const ctx = new EvaluationContext(\n this.tableManager,\n node,\n candidateNode.cellAddress\n );\n const spilledResults =\n candidateNode.evaluationResult.evaluateAllCells.call(\n this.formulaEvaluator,\n {\n context: ctx,\n evaluate: candidateNode.evaluationResult.evaluate,\n intersection: entry.address.range,\n origin: candidateNode.cellAddress,\n lookupOrder: \"col-major\",\n }\n );\n\n if (spilledResults.type === \"values\") {\n results.push(...spilledResults.values);\n } else {\n return spilledResults;\n }\n }\n } else {\n const intersects = isCellInRange(entry.address, spillArea);\n if (intersects) {\n // When a spilled range intersects with our target range, we need to evaluate\n // only the cells that fall within the intersection area.\n //\n // Example: If cell A10 contains a spilled range that covers A10:B11,\n // and our target range is B10:INFINITY, then we only want to evaluate\n // the intersection B10:B11 from the spilled range.\n //\n // The evaluateAllCells method expects the intersection to be passed\n // so it can limit evaluation to only the relevant cells.\n\n const relativePos = {\n x:\n entry.address.colIndex -\n candidateNode.cellAddress.colIndex,\n y:\n entry.address.rowIndex -\n candidateNode.cellAddress.rowIndex,\n };\n const ctx = new EvaluationContext(\n this.tableManager,\n node,\n candidateNode.cellAddress\n );\n const spilledResult = candidateNode.evaluationResult.evaluate(\n relativePos,\n ctx\n );\n\n results.push({\n relativePos: {\n x: entry.address.colIndex - node.address.range.start.col,\n y: entry.address.rowIndex - node.address.range.start.row,\n },\n result: spilledResult,\n });\n }\n }\n }\n }\n }\n }\n\n return {\n type: \"values\",\n values: results,\n };\n });\n\n node.setResult(result);\n this.dependencyManager.registerNode(node);\n }\n\n evaluateCellNode(\n node: CellValueNode | SpillMetaNode | VirtualCellValueNode\n ): void {\n // Enable caching for resolved nodes\n if (node.resolved) {\n return;\n }\n\n const finalizePersistentNode = () => {\n if (node instanceof VirtualCellValueNode) {\n return;\n }\n\n this.dependencyManager.registerNode(node);\n };\n\n if (!(node instanceof VirtualCellValueNode)) {\n this.dependencyManager.unregisterNode(node);\n }\n node.resetDirectDepsUpdated();\n\n const ctx = new EvaluationContext(\n this.tableManager,\n node,\n node.cellAddress\n );\n\n if (node instanceof CellValueNode && node.spillMeta) {\n // we are evaluating a e.g. A1 in A1=SEQUENCE(10), where we want the value in the cell in A1, i.e. 1\n // As A1 is already pointing to a spill meta node, everything has been setup already,\n // we just need to evaluate the spill origin and assign the result to the currentDepNode\n const spillOrigin = node.spillMeta;\n if (spillOrigin.evaluationResult.type === \"spilled-values\") {\n const result = spillOrigin.evaluationResult.evaluate(\n { x: 0, y: 0 },\n ctx\n );\n node.setEvaluationResult(result);\n finalizePersistentNode();\n return;\n }\n }\n\n let content: SerializedCellValue;\n try {\n if (node instanceof VirtualCellValueNode) {\n content = node.cellValue;\n } else {\n content = this.workbookManager.getSerializedCellValue(node.cellAddress);\n }\n } catch (err) {\n const evaluationResult: ErrorEvaluationResult = {\n type: \"error\",\n err: FormulaError.ERROR,\n message: \"Syntax error\",\n errAddress: node,\n };\n node.setEvaluationResult(evaluationResult);\n if (!(node instanceof VirtualCellValueNode)) {\n this.dependencyManager.registerNode(node);\n }\n return;\n }\n\n if (typeof content !== \"string\" || !content.startsWith(\"=\")) {\n if (node instanceof SpillMetaNode) {\n node.setEvaluationResult({\n type: \"does-not-spill\",\n });\n finalizePersistentNode();\n return;\n }\n // Static value cells cannot have frontier dependencies\n const result: ValueEvaluationResult = {\n type: \"value\",\n result: this.convertScalarValueToCellValue(content),\n };\n node.setEvaluationResult(result);\n finalizePersistentNode();\n return;\n }\n\n let evaluation: FunctionEvaluationResult = captureEvaluationErrors(\n node,\n () => this.formulaEvaluator.evaluateFormula(content.slice(1), ctx)\n );\n\n // the evaluated cell IS A spilling formula, e.g. if dependencyKey points to A1, then the formula is e.g. A1=SEQUENCE(10), or A1=A3:B5\n if (evaluation.type === \"spilled-values\") {\n const spillArea = evaluation.spillArea(node.cellAddress);\n\n if (!this.canSpill(node.cellAddress, spillArea)) {\n // Override evaluation with SPILL error, but continue execution to set up nodes\n evaluation = {\n type: \"error\",\n err: FormulaError.SPILL,\n message: \"Cannot spill - area is blocked\",\n errAddress: node,\n };\n } else {\n // Spill succeeds - register it\n this.dependencyManager.setSpilledValue(node.key, {\n spillOnto: spillArea,\n origin: node.cellAddress,\n });\n }\n\n // Set up spill meta node and evaluation results (even if spill failed)\n if (node instanceof SpillMetaNode) {\n // we have already setup an origin/spill meta node relationship,\n // so we are just reevaluating the spill meta node here\n node.setEvaluationResult(evaluation);\n finalizePersistentNode();\n } else {\n const spillMetaNode = this.dependencyManager.getSpillMetaNode(\n node.key.replace(/^[^:]+:/, \"spill-meta:\")\n );\n\n node.addDependency(spillMetaNode);\n node.setSpillMetaNode(spillMetaNode);\n spillMetaNode.setEvaluationResult(evaluation);\n this.dependencyManager.registerNode(spillMetaNode);\n\n if (evaluation.type === \"spilled-values\") {\n const originResult = evaluation.evaluate({ x: 0, y: 0 }, ctx);\n node.setEvaluationResult(originResult);\n } else {\n // Spill failed - set error on origin cell\n node.setEvaluationResult(evaluation);\n }\n }\n finalizePersistentNode();\n return;\n }\n\n if (evaluation.type === \"value\") {\n if (node instanceof SpillMetaNode) {\n node.setEvaluationResult({\n type: \"does-not-spill\",\n });\n finalizePersistentNode();\n return;\n } else {\n node.setEvaluationResult(evaluation);\n finalizePersistentNode();\n return;\n }\n }\n\n node.setEvaluationResult(evaluation);\n finalizePersistentNode();\n }\n\n evaluateDependencyNode(dependency: DependencyNode): void {\n if (dependency instanceof EmptyCellEvaluationNode) {\n this.evaluateEmptyCell(dependency);\n return;\n }\n if (dependency instanceof RangeEvaluationNode) {\n this.evaluateRangeNode(dependency);\n return;\n }\n if (\n dependency instanceof CellValueNode ||\n dependency instanceof VirtualCellValueNode\n ) {\n this.evaluateCellNode(dependency);\n return;\n }\n if (dependency instanceof AstEvaluationNode) {\n return;\n }\n if (dependency instanceof ResourceDependencyNode) {\n return;\n }\n if (dependency instanceof SpillMetaNode) {\n this.evaluateCellNode(dependency);\n return;\n }\n throw new Error(\"Invalid dependency: \" + (dependency as any).key);\n }\n\n /**\n * User exposed method to evaluate a formula\n */\n evaluateFormula(\n /**\n * formula for example\n */\n cellValue: SerializedCellValue,\n cellAddress: CellAddress\n ): SerializedCellValue {\n if (this.isEvaluating) {\n throw new Error(\"Evaluation in progress\");\n }\n\n const node = this.dependencyManager.getVirtualCellValueNode(\n cellAddress,\n cellValue\n );\n\n if (node.evaluationResult.type === \"awaiting-evaluation\") {\n this.evaluateCell(node);\n }\n\n const result = node.evaluationResult;\n\n return this.evaluationResultToSerializedValue(result, cellAddress);\n }\n\n /**\n * Evaluates a cell by building the evaluation order and evaluating the dependencies in order\n */\n evaluateCell(\n node: CellValueNode | EmptyCellEvaluationNode | VirtualCellValueNode\n ): void {\n if (this.isEvaluating) {\n throw new Error(\"Evaluation in progress\");\n }\n this.isEvaluating = true;\n\n let precalculatedPlan: EvaluationOrder | undefined;\n\n let requiresReRun = true;\n while (requiresReRun) {\n requiresReRun = false;\n\n // Use DependencyManager to build evaluation order\n const evaluationPlan =\n precalculatedPlan ?? this.dependencyManager.buildEvaluationOrder(node);\n\n if (evaluationPlan.hasCycle) {\n const evaluationResult: ErrorEvaluationResult = {\n type: \"error\",\n err: FormulaError.CYCLE,\n message: Array.from(evaluationPlan.cycleNodes ?? [])\n .map((node) => node.key)\n .join(\" -> \"),\n errAddress: node,\n };\n // cycle detected\n if (evaluationPlan.cycleNodes) {\n for (const node of evaluationPlan.cycleNodes) {\n if (\n !(node instanceof RangeEvaluationNode) &&\n !(node instanceof ResourceDependencyNode)\n ) {\n node.setEvaluationResult(evaluationResult);\n }\n }\n }\n this.isEvaluating = false;\n }\n\n // Evaluate all dependencies in order\n const timeStart = performance.now();\n const durations: { duration: number; key: string }[] = [];\n let numResolved = 0;\n if (flags.isProfiling && evaluationPlan.evaluationOrder.size > -1) {\n // console.profile();\n }\n evaluationPlan.evaluationOrder.forEach((dependency) => {\n const start = performance.now();\n if (dependency.resolved) {\n numResolved++;\n }\n this.evaluateDependencyNode(dependency);\n\n const end = performance.now();\n if (flags.isProfiling && evaluationPlan.evaluationOrder.size > -1) {\n durations.push({ duration: end - start, key: dependency.key });\n }\n });\n if (flags.isProfiling && evaluationPlan.evaluationOrder.size > -1) {\n // console.profileEnd();\n }\n if (flags.isProfiling && evaluationPlan.evaluationOrder.size > -1) {\n const percentResolved = Math.round(\n (100 * numResolved) / evaluationPlan.evaluationOrder.size\n );\n const avgDuration =\n durations.reduce((a, b) => a + b.duration, 0) / durations.length || 0;\n console.log(\n `%c[Evaluation] %c${evaluationPlan.evaluationOrder.size} deps | %c${(\n performance.now() - timeStart\n ).toFixed(\n 1\n )}ms | %c${percentResolved}% resolved | %c${avgDuration.toFixed(\n 2\n )}ms avg`,\n \"color:#83aaff;font-weight:bold;\",\n \"color:#fff;font-weight:bold;\",\n \"color:#7fff9e\",\n \"color:#85baff\",\n \"color:#ffdfa3\"\n );\n }\n\n this.dependencyManager.markResolvedNodes(node);\n\n const nextEvaluationPlan =\n this.dependencyManager.buildEvaluationOrder(node);\n\n this.dependencyManager.updateResolvedSCCs(nextEvaluationPlan);\n\n precalculatedPlan = nextEvaluationPlan;\n\n // Check if new dependencies were discovered during evaluation\n if (nextEvaluationPlan.hash !== evaluationPlan.hash) {\n requiresReRun = true;\n } else {\n this.isEvaluating = false;\n return;\n }\n }\n this.isEvaluating = false;\n }\n\n convertScalarValueToCellValue(val: SerializedCellValue): CellValue {\n if (val === \"INFINITY\") {\n return { type: \"infinity\", sign: \"positive\" };\n }\n if (val === \"-INFINITY\") {\n return { type: \"infinity\", sign: \"negative\" };\n }\n if (typeof val === \"number\") {\n return { type: \"number\", value: val };\n }\n if (typeof val === \"boolean\") {\n return { type: \"boolean\", value: val };\n }\n if (typeof val === \"undefined\") {\n return { type: \"string\", value: \"\" };\n }\n return { type: \"string\", value: val };\n }\n\n // todo optimize using workbook manager\n canSpill(spillCandidate: CellAddress, spillArea: SpreadsheetRange): boolean {\n // Check if the spill origin cell is inside a table - spilling formulas cannot exist in tables\n if (this.tableManager.isCellInTable(spillCandidate)) {\n return false;\n }\n\n // Check if the spill area would intersect with any table - formulas cannot spill into tables\n if (\n this.tableManager.doesRangeIntersectTable(\n spillCandidate.workbookName,\n spillCandidate.sheetName,\n spillArea\n )\n ) {\n return false;\n }\n\n const sheet = this.workbookManager.getSheet(spillCandidate);\n if (!sheet) {\n throw new SheetNotFoundError(spillCandidate.sheetName);\n }\n const cellId = getCellReference(spillCandidate);\n const content = sheet.content.get(cellId);\n if (!content) {\n throw new EvaluationError(FormulaError.REF, `Cell not found: ${cellId}`);\n }\n for (const spilledValue of this.dependencyManager.spilledValues) {\n if (\n spilledValue.origin.workbookName !== spillCandidate.workbookName ||\n spilledValue.origin.sheetName !== spillCandidate.sheetName\n ) {\n continue;\n }\n if (\n spilledValue.origin.colIndex === spillCandidate.colIndex &&\n spilledValue.origin.rowIndex === spillCandidate.rowIndex\n ) {\n // we are already have a spill, this one will be replaced\n continue;\n }\n\n if (checkRangeIntersection(spillArea, spilledValue.spillOnto)) {\n return false;\n }\n }\n // let's just check the raw data if there is something in the range\n for (const key of sheet.content.keys()) {\n const cellAddress = parseCellReference(key);\n const endCol = spillArea.end.col;\n const endRow = spillArea.end.row;\n\n if (\n cellAddress.colIndex === spillCandidate.colIndex &&\n cellAddress.rowIndex === spillCandidate.rowIndex\n ) {\n continue;\n }\n\n if (endCol.type === \"number\" && endRow.type === \"number\") {\n if (\n cellAddress.colIndex >= spillArea.start.col &&\n cellAddress.colIndex <= endCol.value &&\n cellAddress.rowIndex >= spillArea.start.row &&\n cellAddress.rowIndex <= endRow.value\n ) {\n if (\n normalizeSerializedCellValue(sheet.content.get(key)) !== undefined\n ) {\n // there is something in the range, so we can't spill\n return false;\n }\n }\n }\n }\n\n return true;\n }\n\n getCellEvaluationResult(\n cellAddress: CellAddress\n ): SingleEvaluationResult | undefined {\n if (this.isEvaluating) {\n throw new Error(\"Evaluation in progress\");\n }\n\n const nodeKey = cellAddressToKey(cellAddress);\n const node = this.dependencyManager.getCellValueOrEmptyCellNode(nodeKey);\n\n const sheet = this.workbookManager.getSheet(cellAddress);\n if (!sheet) {\n throw new SheetNotFoundError(cellAddress.sheetName);\n }\n\n if (node.evaluationResult.type === \"awaiting-evaluation\") {\n // if (cellAddressToKey(cellAddress).includes(\"G10\")) {\n // console.group(\"Evaluation of G10\");\n // flags.isProfiling = true;\n // console.time(\"Evaluation of G10\");\n // console.profile(\"Evaluation of G10\");\n // }\n this.evaluateCell(node);\n // if (flags.isProfiling) {\n // flags.isProfiling = false;\n // console.timeEnd(\"Evaluation of G10\");\n // console.profileEnd(\"Evaluation of G10\");\n // console.groupEnd();\n // }\n }\n\n const result = node.evaluationResult;\n\n return result;\n }\n}\n"
5
+ "import { flags } from \"../../debug/flags.mjs\";\nimport { AstEvaluationNode } from \"../../evaluator/dependency-nodes/ast-evaluation-node.mjs\";\nimport { CellValueNode } from \"../../evaluator/dependency-nodes/cell-value-node.mjs\";\nimport { EvaluationContext } from \"../../evaluator/evaluation-context.mjs\";\nimport {\n EvaluationError,\n SheetNotFoundError,\n} from \"../../evaluator/evaluation-error.mjs\";\nimport { RangeEvaluationNode } from \"../../evaluator/range-evaluation-node.mjs\";\nimport { normalizeSerializedCellValue } from \"../../parser/formatter.mjs\";\nimport { FormulaEvaluator } from \"../../evaluator/formula-evaluator.mjs\";\nimport {\n FormulaError,\n type CellAddress,\n type CellInRangeResult,\n type CellValue,\n type ErrorEvaluationResult,\n type EvaluateAllCellsResult,\n type EvaluationOrder,\n type FunctionEvaluationResult,\n type SerializedCellValue,\n type SingleEvaluationResult,\n type SpreadsheetRange,\n type ValueEvaluationResult,\n} from \"../types.mjs\";\nimport {\n captureEvaluationErrors,\n getAbsoluteRange,\n cellAddressToKey,\n checkRangeIntersection,\n getCellReference,\n getRangeIntersection,\n getRelativeRange,\n isCellInRange,\n parseCellReference,\n rangeAddressToKey,\n} from \"../utils.mjs\";\nimport type { DependencyManager } from \"./dependency-manager.mjs\";\nimport type { WorkbookManager } from \"./workbook-manager.mjs\";\nimport { SpillMetaNode } from \"../../evaluator/dependency-nodes/spill-meta-node.mjs\";\nimport { EmptyCellEvaluationNode } from \"../../evaluator/dependency-nodes/empty-cell-evaluation-node.mjs\";\nimport type { TableManager } from \"./table-manager.mjs\";\nimport type { DependencyNode } from \"./dependency-node.mjs\";\nimport { VirtualCellValueNode } from \"../../evaluator/dependency-nodes/virtual-cell-value-node.mjs\";\nimport { ResourceDependencyNode } from \"../../evaluator/dependency-nodes/resource-dependency-node.mjs\";\nimport type {\n NodeSnapshotId,\n SerializedCellInRangeResultSnapshot,\n SerializedErrorEvaluationResultSnapshot,\n SerializedEvaluateAllCellsResultSnapshot,\n SerializedFunctionEvaluationResultSnapshot,\n SerializedSingleEvaluationResultSnapshot,\n SerializedSpillMetaEvaluationResultSnapshot,\n SerializedSpilledValuesEvaluationResultSnapshot,\n} from \"../engine-snapshot.mjs\";\nimport type { MutationInvalidation } from \"../mutation-invalidation.mjs\";\n\nexport class EvaluationManager {\n private isEvaluating = false;\n\n constructor(\n private workbookManager: WorkbookManager,\n private tableManager: TableManager,\n private formulaEvaluator: FormulaEvaluator,\n private dependencyManager: DependencyManager\n ) {}\n\n clearEvaluationCache(): void {\n this.dependencyManager.clearEvaluationCache();\n }\n\n private dependsOnNode(\n candidate: DependencyNode,\n target: DependencyNode,\n visited: Set<DependencyNode> = new Set()\n ): boolean {\n if (candidate === target) {\n return true;\n }\n\n if (visited.has(candidate)) {\n return false;\n }\n visited.add(candidate);\n\n for (const dep of candidate.getDependencies()) {\n if (this.dependsOnNode(dep, target, visited)) {\n return true;\n }\n }\n\n return false;\n }\n\n invalidateFromMutation(footprint: MutationInvalidation): void {\n this.dependencyManager.invalidateFromMutation(footprint);\n }\n\n evaluationResultToSerializedValue(\n evaluation: SingleEvaluationResult,\n cellAddress: CellAddress,\n debug?: boolean\n ): SerializedCellValue {\n if (\n evaluation.type !== \"error\" &&\n evaluation.type !== \"awaiting-evaluation\"\n ) {\n const value = evaluation.result;\n\n return value.type === \"infinity\"\n ? value.sign === \"positive\"\n ? \"INFINITY\"\n : \"-INFINITY\"\n : value.value;\n }\n\n if (evaluation.type === \"awaiting-evaluation\") {\n return (\n evaluation.errAddress.key +\n \" is awaiting evaluation of \" +\n evaluation.waitingFor.key\n );\n }\n\n if (debug) {\n const errAddress = evaluation.errAddress.key;\n if (errAddress === cellAddressToKey(cellAddress)) {\n return evaluation.err + \" \" + evaluation.message;\n }\n return (\n evaluation.err +\n \" in \" +\n evaluation.errAddress.key +\n \" \" +\n evaluation.message\n );\n }\n\n return evaluation.err;\n }\n\n private buildSnapshotOrigin(\n node: CellValueNode | SpillMetaNode | AstEvaluationNode\n ): CellAddress {\n if (\"cellAddress\" in node) {\n return node.cellAddress;\n }\n\n const contextDependency = node.getContextDependency();\n return {\n workbookName: contextDependency.workbookName ?? \"__snapshot__\",\n sheetName: contextDependency.sheetName ?? \"__snapshot__\",\n colIndex: contextDependency.colIndex ?? 0,\n rowIndex: contextDependency.rowIndex ?? 0,\n };\n }\n\n private serializeErrorEvaluationResultSnapshot(\n evaluation: Exclude<ErrorEvaluationResult, { type: \"awaiting-evaluation\" }>,\n getNodeSnapshotId: (node: DependencyNode) => NodeSnapshotId\n ): SerializedErrorEvaluationResultSnapshot {\n return {\n type: \"error\",\n err: evaluation.err,\n message: evaluation.message,\n errAddressId: getNodeSnapshotId(evaluation.errAddress),\n sourceCell: evaluation.sourceCell,\n };\n }\n\n serializeSingleEvaluationResultSnapshot(\n evaluation: SingleEvaluationResult,\n getNodeSnapshotId: (node: DependencyNode) => NodeSnapshotId\n ): SerializedSingleEvaluationResultSnapshot | undefined {\n if (evaluation.type === \"awaiting-evaluation\") {\n return undefined;\n }\n\n if (evaluation.type === \"error\") {\n return this.serializeErrorEvaluationResultSnapshot(\n evaluation,\n getNodeSnapshotId\n );\n }\n\n return {\n type: \"value\",\n result: evaluation.result,\n sourceCell: evaluation.sourceCell,\n };\n }\n\n deserializeSingleEvaluationResultSnapshot(\n evaluation: SerializedSingleEvaluationResultSnapshot,\n resolveNodeSnapshotId: (nodeId: NodeSnapshotId) => DependencyNode\n ): SingleEvaluationResult {\n if (evaluation.type === \"error\") {\n return {\n type: \"error\",\n err: evaluation.err,\n message: evaluation.message,\n errAddress: resolveNodeSnapshotId(evaluation.errAddressId),\n sourceCell: evaluation.sourceCell,\n };\n }\n\n return {\n type: \"value\",\n result: evaluation.result,\n sourceCell: evaluation.sourceCell,\n };\n }\n\n serializeEvaluateAllCellsResultSnapshot(\n evaluation: EvaluateAllCellsResult,\n getNodeSnapshotId: (node: DependencyNode) => NodeSnapshotId\n ): SerializedEvaluateAllCellsResultSnapshot | undefined {\n if (evaluation.type === \"awaiting-evaluation\") {\n return undefined;\n }\n\n if (evaluation.type === \"error\") {\n return this.serializeErrorEvaluationResultSnapshot(\n evaluation,\n getNodeSnapshotId\n );\n }\n\n const values: SerializedCellInRangeResultSnapshot[] = [];\n for (const value of evaluation.values) {\n const serialized = this.serializeSingleEvaluationResultSnapshot(\n value.result,\n getNodeSnapshotId\n );\n if (!serialized) {\n return undefined;\n }\n values.push({\n relativePos: value.relativePos,\n result: serialized,\n });\n }\n\n return {\n type: \"values\",\n values,\n };\n }\n\n deserializeEvaluateAllCellsResultSnapshot(\n evaluation: SerializedEvaluateAllCellsResultSnapshot,\n resolveNodeSnapshotId: (nodeId: NodeSnapshotId) => DependencyNode\n ): EvaluateAllCellsResult {\n if (evaluation.type === \"error\") {\n return this.deserializeSingleEvaluationResultSnapshot(\n evaluation,\n resolveNodeSnapshotId\n ) as ErrorEvaluationResult;\n }\n\n return {\n type: \"values\",\n values: evaluation.values.map((value) => ({\n relativePos: value.relativePos,\n result: this.deserializeSingleEvaluationResultSnapshot(\n value.result,\n resolveNodeSnapshotId\n ),\n })),\n };\n }\n\n serializeFunctionEvaluationResultSnapshot(\n evaluation: FunctionEvaluationResult,\n options: {\n sourceNode: CellValueNode | SpillMetaNode | AstEvaluationNode;\n getNodeSnapshotId: (node: DependencyNode) => NodeSnapshotId;\n }\n ): SerializedFunctionEvaluationResultSnapshot | undefined {\n if (evaluation.type !== \"spilled-values\") {\n return this.serializeSingleEvaluationResultSnapshot(\n evaluation,\n options.getNodeSnapshotId\n );\n }\n\n const origin = this.buildSnapshotOrigin(options.sourceNode);\n const spillArea = evaluation.spillArea(origin);\n const relativeSpillArea = getRelativeRange(spillArea, {\n colIndex: origin.colIndex,\n rowIndex: origin.rowIndex,\n });\n\n if (evaluation.sourceRange) {\n return {\n type: \"spilled-values\",\n spill: {\n kind: \"source-range\",\n relativeSpillArea,\n source: evaluation.source,\n sourceCell: evaluation.sourceCell,\n sourceRange: evaluation.sourceRange,\n },\n };\n }\n\n if (\n relativeSpillArea.width.type !== \"number\" ||\n relativeSpillArea.height.type !== \"number\"\n ) {\n return undefined;\n }\n\n const context = new EvaluationContext(\n this.tableManager,\n options.sourceNode,\n origin\n );\n const values: SerializedCellInRangeResultSnapshot[] = [];\n\n for (let y = 0; y < relativeSpillArea.height.value; y++) {\n for (let x = 0; x < relativeSpillArea.width.value; x++) {\n const result = captureEvaluationErrors(options.sourceNode, () =>\n evaluation.evaluate({ x, y }, context)\n );\n const serialized = this.serializeSingleEvaluationResultSnapshot(\n result,\n options.getNodeSnapshotId\n );\n if (!serialized) {\n return undefined;\n }\n values.push({\n relativePos: { x, y },\n result: serialized,\n });\n }\n }\n\n return {\n type: \"spilled-values\",\n spill: {\n kind: \"materialized\",\n relativeSpillArea,\n source: evaluation.source,\n sourceCell: evaluation.sourceCell,\n sourceRange: evaluation.sourceRange,\n values,\n },\n };\n }\n\n deserializeFunctionEvaluationResultSnapshot(\n evaluation: SerializedFunctionEvaluationResultSnapshot,\n resolveNodeSnapshotId: (nodeId: NodeSnapshotId) => DependencyNode\n ): FunctionEvaluationResult {\n if (evaluation.type !== \"spilled-values\") {\n return this.deserializeSingleEvaluationResultSnapshot(\n evaluation,\n resolveNodeSnapshotId\n );\n }\n\n const spillSnapshot = evaluation.spill;\n if (spillSnapshot.kind === \"materialized\") {\n const values = new Map(\n spillSnapshot.values.map((value) => [\n `${value.relativePos.x},${value.relativePos.y}`,\n this.deserializeSingleEvaluationResultSnapshot(\n value.result,\n resolveNodeSnapshotId\n ),\n ])\n );\n\n return {\n type: \"spilled-values\",\n source: spillSnapshot.source,\n sourceCell: spillSnapshot.sourceCell,\n sourceRange: spillSnapshot.sourceRange,\n spillArea: (origin) =>\n getAbsoluteRange(spillSnapshot.relativeSpillArea, {\n colIndex: origin.colIndex,\n rowIndex: origin.rowIndex,\n }),\n evaluate: (spillOffset) =>\n values.get(`${spillOffset.x},${spillOffset.y}`) ?? {\n type: \"value\",\n result: this.convertScalarValueToCellValue(\"\"),\n },\n evaluateAllCells: () => ({\n type: \"values\",\n values: spillSnapshot.values.map((value) => ({\n relativePos: value.relativePos,\n result: this.deserializeSingleEvaluationResultSnapshot(\n value.result,\n resolveNodeSnapshotId\n ),\n })),\n }),\n };\n }\n\n return {\n type: \"spilled-values\",\n source: spillSnapshot.source,\n sourceCell: spillSnapshot.sourceCell,\n sourceRange: spillSnapshot.sourceRange,\n spillArea: (origin) =>\n getAbsoluteRange(spillSnapshot.relativeSpillArea, {\n colIndex: origin.colIndex,\n rowIndex: origin.rowIndex,\n }),\n evaluate: (spillOffset, context) => {\n const cellAddress: CellAddress = {\n workbookName: spillSnapshot.sourceRange.workbookName,\n sheetName: spillSnapshot.sourceRange.sheetName,\n colIndex: spillSnapshot.sourceRange.range.start.col + spillOffset.x,\n rowIndex: spillSnapshot.sourceRange.range.start.row + spillOffset.y,\n };\n\n const evalNode = this.dependencyManager.getCellValueOrEmptyCellNode(\n cellAddressToKey(cellAddress)\n );\n context.dependencyNode.addDependency(evalNode);\n return evalNode.evaluationResult;\n },\n evaluateAllCells: ({ intersection, context, origin }) => {\n let range = spillSnapshot.sourceRange.range;\n if (intersection) {\n const relativeRange = getRelativeRange(intersection, origin);\n const projectedIntersection = getAbsoluteRange(relativeRange, {\n colIndex: spillSnapshot.sourceRange.range.start.col,\n rowIndex: spillSnapshot.sourceRange.range.start.row,\n });\n const nextRange = getRangeIntersection(\n spillSnapshot.sourceRange.range,\n projectedIntersection\n );\n if (nextRange) {\n range = nextRange;\n }\n }\n\n const rangeAddress = {\n workbookName: spillSnapshot.sourceRange.workbookName,\n sheetName: spillSnapshot.sourceRange.sheetName,\n range,\n };\n\n const rangeNode = this.dependencyManager.getRangeNode(\n rangeAddressToKey(rangeAddress)\n );\n context.dependencyNode.addDependency(rangeNode);\n return rangeNode.result;\n },\n };\n }\n\n serializeSpillMetaEvaluationResultSnapshot(\n evaluation: SpillMetaNode[\"evaluationResult\"],\n options: {\n sourceNode: CellValueNode | SpillMetaNode | AstEvaluationNode;\n getNodeSnapshotId: (node: DependencyNode) => NodeSnapshotId;\n }\n ): SerializedSpillMetaEvaluationResultSnapshot | undefined {\n if (evaluation.type === \"does-not-spill\") {\n return { type: \"does-not-spill\" };\n }\n\n if (evaluation.type === \"error\") {\n return this.serializeErrorEvaluationResultSnapshot(\n evaluation,\n options.getNodeSnapshotId\n );\n }\n\n const serialized = this.serializeFunctionEvaluationResultSnapshot(\n evaluation,\n options\n );\n if (!serialized || serialized.type !== \"spilled-values\") {\n return undefined;\n }\n\n return serialized;\n }\n\n deserializeSpillMetaEvaluationResultSnapshot(\n evaluation: SerializedSpillMetaEvaluationResultSnapshot,\n resolveNodeSnapshotId: (nodeId: NodeSnapshotId) => DependencyNode\n ): SpillMetaNode[\"evaluationResult\"] {\n if (evaluation.type === \"does-not-spill\") {\n return evaluation;\n }\n\n if (evaluation.type === \"error\") {\n return this.deserializeSingleEvaluationResultSnapshot(\n evaluation,\n resolveNodeSnapshotId\n ) as SpillMetaNode[\"evaluationResult\"];\n }\n\n return this.deserializeFunctionEvaluationResultSnapshot(\n evaluation,\n resolveNodeSnapshotId\n ) as SpillMetaNode[\"evaluationResult\"];\n }\n\n evaluateEmptyCell(node: EmptyCellEvaluationNode): void {\n if (node.resolved) {\n const result = node.evaluationResult;\n if (result && result.type !== \"awaiting-evaluation\") {\n return;\n }\n }\n\n this.dependencyManager.unregisterNode(node);\n node.resetDirectDepsUpdated();\n\n const ctx = new EvaluationContext(\n this.tableManager,\n node,\n node.cellAddress\n );\n const inSpilled = this.dependencyManager.getSpillValue(node.cellAddress);\n\n if (inSpilled) {\n // if we are spilling then we can just add the spill origin as a dependency and evaluate the spilled value\n const spillTarget = this.dependencyManager.getSpilledAddress(\n node.cellAddress,\n inSpilled\n );\n const spillOriginKey = cellAddressToKey(inSpilled.origin).replace(\n /^[^:]+:/,\n \"spill-meta:\"\n );\n const spillMetaNode =\n this.dependencyManager.getSpillMetaNode(spillOriginKey);\n node.addDependency(spillMetaNode);\n const result = spillMetaNode.evaluationResult;\n if (result.type === \"spilled-values\") {\n // let's evaluate the spilled value to extract dependencies\n const evaluation = captureEvaluationErrors(spillMetaNode, () => {\n return result.evaluate(spillTarget.spillOffset, ctx);\n });\n node.setEvaluationResult(evaluation);\n }\n } else {\n // upgrade any frontier dependencies that spill into the range\n node.upgradeFrontierDependencies();\n\n const evaluationResult: SingleEvaluationResult = {\n type: \"value\",\n result: this.convertScalarValueToCellValue(\"\"),\n };\n // for now let's just store the empty value, the next time the cell is evaluated isSpilled will be true and the spilled value will be evaluated\n node.setEvaluationResult(evaluationResult);\n }\n\n this.dependencyManager.registerNode(node);\n }\n\n evaluateRangeNode(node: RangeEvaluationNode): void {\n if (node.resolved) {\n return;\n }\n\n this.dependencyManager.unregisterNode(node);\n node.resetDirectDepsUpdated();\n\n const result = captureEvaluationErrors(node, (): EvaluateAllCellsResult => {\n node.upgradeFrontierDependencies();\n\n const evalOrder = node.getRangeEvalOrder();\n const circularEntryCache = new Map<DependencyNode, boolean>();\n const shouldSkipCircularEntry = (candidate: DependencyNode) => {\n const cached = circularEntryCache.get(candidate);\n if (cached !== undefined) {\n return cached;\n }\n\n // If a cell inside the range depends back on the range itself, including\n // its current value would count a circular result back into the same\n // aggregate on a later rerun.\n const isCircular = this.dependsOnNode(candidate, node);\n circularEntryCache.set(candidate, isCircular);\n return isCircular;\n };\n\n const results: CellInRangeResult[] = [];\n\n for (const entry of evalOrder) {\n if (entry.type === \"value\") {\n if (shouldSkipCircularEntry(entry.node)) {\n continue;\n }\n\n const entryAddress = entry.address;\n const result = entry.node.evaluationResult;\n\n const relativePos = {\n x: entryAddress.colIndex - node.address.range.start.col,\n y: entryAddress.rowIndex - node.address.range.start.row,\n };\n\n results.push({ result: result, relativePos });\n } else if (\n entry.type === \"empty_cell\" ||\n entry.type === \"empty_range\"\n ) {\n for (const candidateNode of entry.candidates) {\n if (shouldSkipCircularEntry(candidateNode)) {\n continue;\n }\n\n if (candidateNode.evaluationResult.type === \"spilled-values\") {\n const spillArea = candidateNode.evaluationResult.spillArea(\n candidateNode.cellAddress\n );\n if (entry.type === \"empty_range\") {\n const intersects = checkRangeIntersection(\n spillArea,\n entry.address.range\n );\n if (intersects) {\n // When a spilled range intersects with our target range, we need to evaluate\n // only the cells that fall within the intersection area.\n //\n // Example: If cell A10 contains a spilled range that covers A10:B11,\n // and our target range is B10:INFINITY, then we only want to evaluate\n // the intersection B10:B11 from the spilled range.\n //\n // The evaluateAllCells method expects the intersection to be passed\n // so it can limit evaluation to only the relevant cells.\n const ctx = new EvaluationContext(\n this.tableManager,\n node,\n candidateNode.cellAddress\n );\n const spilledResults =\n candidateNode.evaluationResult.evaluateAllCells.call(\n this.formulaEvaluator,\n {\n context: ctx,\n evaluate: candidateNode.evaluationResult.evaluate,\n intersection: entry.address.range,\n origin: candidateNode.cellAddress,\n lookupOrder: \"col-major\",\n }\n );\n\n if (spilledResults.type === \"values\") {\n results.push(...spilledResults.values);\n } else {\n return spilledResults;\n }\n }\n } else {\n const intersects = isCellInRange(entry.address, spillArea);\n if (intersects) {\n // When a spilled range intersects with our target range, we need to evaluate\n // only the cells that fall within the intersection area.\n //\n // Example: If cell A10 contains a spilled range that covers A10:B11,\n // and our target range is B10:INFINITY, then we only want to evaluate\n // the intersection B10:B11 from the spilled range.\n //\n // The evaluateAllCells method expects the intersection to be passed\n // so it can limit evaluation to only the relevant cells.\n\n const relativePos = {\n x:\n entry.address.colIndex -\n candidateNode.cellAddress.colIndex,\n y:\n entry.address.rowIndex -\n candidateNode.cellAddress.rowIndex,\n };\n const ctx = new EvaluationContext(\n this.tableManager,\n node,\n candidateNode.cellAddress\n );\n const spilledResult = candidateNode.evaluationResult.evaluate(\n relativePos,\n ctx\n );\n\n results.push({\n relativePos: {\n x: entry.address.colIndex - node.address.range.start.col,\n y: entry.address.rowIndex - node.address.range.start.row,\n },\n result: spilledResult,\n });\n }\n }\n }\n }\n }\n }\n\n return {\n type: \"values\",\n values: results,\n };\n });\n\n node.setResult(result);\n this.dependencyManager.registerNode(node);\n }\n\n evaluateCellNode(\n node: CellValueNode | SpillMetaNode | VirtualCellValueNode\n ): void {\n // Enable caching for resolved nodes\n if (node.resolved) {\n return;\n }\n\n const finalizePersistentNode = () => {\n if (node instanceof VirtualCellValueNode) {\n return;\n }\n\n this.dependencyManager.registerNode(node);\n };\n\n if (!(node instanceof VirtualCellValueNode)) {\n this.dependencyManager.unregisterNode(node);\n }\n node.resetDirectDepsUpdated();\n\n const ctx = new EvaluationContext(\n this.tableManager,\n node,\n node.cellAddress\n );\n\n if (node instanceof CellValueNode && node.spillMeta) {\n // we are evaluating a e.g. A1 in A1=SEQUENCE(10), where we want the value in the cell in A1, i.e. 1\n // As A1 is already pointing to a spill meta node, everything has been setup already,\n // we just need to evaluate the spill origin and assign the result to the currentDepNode\n const spillOrigin = node.spillMeta;\n if (spillOrigin.evaluationResult.type === \"spilled-values\") {\n const result = spillOrigin.evaluationResult.evaluate(\n { x: 0, y: 0 },\n ctx\n );\n node.setEvaluationResult(result);\n finalizePersistentNode();\n return;\n }\n }\n\n let content: SerializedCellValue;\n try {\n if (node instanceof VirtualCellValueNode) {\n content = node.cellValue;\n } else {\n content = this.workbookManager.getSerializedCellValue(node.cellAddress);\n }\n } catch (err) {\n const evaluationResult: ErrorEvaluationResult = {\n type: \"error\",\n err: FormulaError.ERROR,\n message: \"Syntax error\",\n errAddress: node,\n };\n node.setEvaluationResult(evaluationResult);\n if (!(node instanceof VirtualCellValueNode)) {\n this.dependencyManager.registerNode(node);\n }\n return;\n }\n\n if (typeof content !== \"string\" || !content.startsWith(\"=\")) {\n if (node instanceof SpillMetaNode) {\n node.setEvaluationResult({\n type: \"does-not-spill\",\n });\n finalizePersistentNode();\n return;\n }\n // Static value cells cannot have frontier dependencies\n const result: ValueEvaluationResult = {\n type: \"value\",\n result: this.convertScalarValueToCellValue(content),\n };\n node.setEvaluationResult(result);\n finalizePersistentNode();\n return;\n }\n\n let evaluation: FunctionEvaluationResult = captureEvaluationErrors(\n node,\n () => this.formulaEvaluator.evaluateFormula(content.slice(1), ctx)\n );\n\n // the evaluated cell IS A spilling formula, e.g. if dependencyKey points to A1, then the formula is e.g. A1=SEQUENCE(10), or A1=A3:B5\n if (evaluation.type === \"spilled-values\") {\n const spillArea = evaluation.spillArea(node.cellAddress);\n\n if (!this.canSpill(node.cellAddress, spillArea)) {\n // Override evaluation with SPILL error, but continue execution to set up nodes\n evaluation = {\n type: \"error\",\n err: FormulaError.SPILL,\n message: \"Cannot spill - area is blocked\",\n errAddress: node,\n };\n } else {\n // Spill succeeds - register it\n this.dependencyManager.setSpilledValue(node.key, {\n spillOnto: spillArea,\n origin: node.cellAddress,\n });\n }\n\n // Set up spill meta node and evaluation results (even if spill failed)\n if (node instanceof SpillMetaNode) {\n // we have already setup an origin/spill meta node relationship,\n // so we are just reevaluating the spill meta node here\n node.setEvaluationResult(evaluation);\n finalizePersistentNode();\n } else {\n const spillMetaNode = this.dependencyManager.getSpillMetaNode(\n node.key.replace(/^[^:]+:/, \"spill-meta:\")\n );\n\n node.addDependency(spillMetaNode);\n node.setSpillMetaNode(spillMetaNode);\n spillMetaNode.setEvaluationResult(evaluation);\n this.dependencyManager.registerNode(spillMetaNode);\n\n if (evaluation.type === \"spilled-values\") {\n const originResult = evaluation.evaluate({ x: 0, y: 0 }, ctx);\n node.setEvaluationResult(originResult);\n } else {\n // Spill failed - set error on origin cell\n node.setEvaluationResult(evaluation);\n }\n }\n finalizePersistentNode();\n return;\n }\n\n if (evaluation.type === \"value\") {\n if (node instanceof SpillMetaNode) {\n node.setEvaluationResult({\n type: \"does-not-spill\",\n });\n finalizePersistentNode();\n return;\n } else {\n node.setEvaluationResult(evaluation);\n finalizePersistentNode();\n return;\n }\n }\n\n node.setEvaluationResult(evaluation);\n finalizePersistentNode();\n }\n\n evaluateDependencyNode(dependency: DependencyNode): void {\n if (dependency instanceof EmptyCellEvaluationNode) {\n this.evaluateEmptyCell(dependency);\n return;\n }\n if (dependency instanceof RangeEvaluationNode) {\n this.evaluateRangeNode(dependency);\n return;\n }\n if (\n dependency instanceof CellValueNode ||\n dependency instanceof VirtualCellValueNode\n ) {\n this.evaluateCellNode(dependency);\n return;\n }\n if (dependency instanceof AstEvaluationNode) {\n return;\n }\n if (dependency instanceof ResourceDependencyNode) {\n return;\n }\n if (dependency instanceof SpillMetaNode) {\n this.evaluateCellNode(dependency);\n return;\n }\n throw new Error(\"Invalid dependency: \" + (dependency as any).key);\n }\n\n /**\n * User exposed method to evaluate a formula\n */\n evaluateFormula(\n /**\n * formula for example\n */\n cellValue: SerializedCellValue,\n cellAddress: CellAddress\n ): SerializedCellValue {\n if (this.isEvaluating) {\n throw new Error(\"Evaluation in progress\");\n }\n\n const node = this.dependencyManager.getVirtualCellValueNode(\n cellAddress,\n cellValue\n );\n\n if (node.evaluationResult.type === \"awaiting-evaluation\") {\n this.evaluateCell(node);\n }\n\n const result = node.evaluationResult;\n\n return this.evaluationResultToSerializedValue(result, cellAddress);\n }\n\n /**\n * Evaluates a cell by building the evaluation order and evaluating the dependencies in order\n */\n evaluateCell(\n node: CellValueNode | EmptyCellEvaluationNode | VirtualCellValueNode\n ): void {\n if (this.isEvaluating) {\n throw new Error(\"Evaluation in progress\");\n }\n this.isEvaluating = true;\n\n let precalculatedPlan: EvaluationOrder | undefined;\n\n let requiresReRun = true;\n while (requiresReRun) {\n requiresReRun = false;\n\n // Use DependencyManager to build evaluation order\n const evaluationPlan =\n precalculatedPlan ?? this.dependencyManager.buildEvaluationOrder(node);\n\n if (evaluationPlan.hasCycle) {\n const evaluationResult: ErrorEvaluationResult = {\n type: \"error\",\n err: FormulaError.CYCLE,\n message: Array.from(evaluationPlan.cycleNodes ?? [])\n .map((node) => node.key)\n .join(\" -> \"),\n errAddress: node,\n };\n // cycle detected\n if (evaluationPlan.cycleNodes) {\n for (const node of evaluationPlan.cycleNodes) {\n if (\n !(node instanceof RangeEvaluationNode) &&\n !(node instanceof ResourceDependencyNode)\n ) {\n node.setEvaluationResult(evaluationResult);\n }\n }\n }\n this.isEvaluating = false;\n }\n\n // Evaluate all dependencies in order\n const timeStart = performance.now();\n const durations: { duration: number; key: string }[] = [];\n let numResolved = 0;\n if (flags.isProfiling && evaluationPlan.evaluationOrder.size > -1) {\n // console.profile();\n }\n evaluationPlan.evaluationOrder.forEach((dependency) => {\n const start = performance.now();\n if (dependency.resolved) {\n numResolved++;\n }\n this.evaluateDependencyNode(dependency);\n\n const end = performance.now();\n if (flags.isProfiling && evaluationPlan.evaluationOrder.size > -1) {\n durations.push({ duration: end - start, key: dependency.key });\n }\n });\n if (flags.isProfiling && evaluationPlan.evaluationOrder.size > -1) {\n // console.profileEnd();\n }\n if (flags.isProfiling && evaluationPlan.evaluationOrder.size > -1) {\n const percentResolved = Math.round(\n (100 * numResolved) / evaluationPlan.evaluationOrder.size\n );\n const avgDuration =\n durations.reduce((a, b) => a + b.duration, 0) / durations.length || 0;\n console.log(\n `%c[Evaluation] %c${evaluationPlan.evaluationOrder.size} deps | %c${(\n performance.now() - timeStart\n ).toFixed(\n 1\n )}ms | %c${percentResolved}% resolved | %c${avgDuration.toFixed(\n 2\n )}ms avg`,\n \"color:#83aaff;font-weight:bold;\",\n \"color:#fff;font-weight:bold;\",\n \"color:#7fff9e\",\n \"color:#85baff\",\n \"color:#ffdfa3\"\n );\n }\n\n this.dependencyManager.markResolvedNodes(node);\n\n const nextEvaluationPlan =\n this.dependencyManager.buildEvaluationOrder(node);\n\n this.dependencyManager.updateResolvedSCCs(nextEvaluationPlan);\n\n precalculatedPlan = nextEvaluationPlan;\n\n // Check if new dependencies were discovered during evaluation\n if (nextEvaluationPlan.hash !== evaluationPlan.hash) {\n requiresReRun = true;\n } else {\n this.isEvaluating = false;\n return;\n }\n }\n this.isEvaluating = false;\n }\n\n convertScalarValueToCellValue(val: SerializedCellValue): CellValue {\n if (val === \"INFINITY\") {\n return { type: \"infinity\", sign: \"positive\" };\n }\n if (val === \"-INFINITY\") {\n return { type: \"infinity\", sign: \"negative\" };\n }\n if (typeof val === \"number\") {\n return { type: \"number\", value: val };\n }\n if (typeof val === \"boolean\") {\n return { type: \"boolean\", value: val };\n }\n if (typeof val === \"undefined\") {\n return { type: \"string\", value: \"\" };\n }\n return { type: \"string\", value: val };\n }\n\n // todo optimize using workbook manager\n canSpill(spillCandidate: CellAddress, spillArea: SpreadsheetRange): boolean {\n // Check if the spill origin cell is inside a table - spilling formulas cannot exist in tables\n if (this.tableManager.isCellInTable(spillCandidate)) {\n return false;\n }\n\n // Check if the spill area would intersect with any table - formulas cannot spill into tables\n if (\n this.tableManager.doesRangeIntersectTable(\n spillCandidate.workbookName,\n spillCandidate.sheetName,\n spillArea\n )\n ) {\n return false;\n }\n\n const sheet = this.workbookManager.getSheet(spillCandidate);\n if (!sheet) {\n throw new SheetNotFoundError(spillCandidate.sheetName);\n }\n const cellId = getCellReference(spillCandidate);\n const content = sheet.content.get(cellId);\n if (!content) {\n throw new EvaluationError(FormulaError.REF, `Cell not found: ${cellId}`);\n }\n for (const spilledValue of this.dependencyManager.spilledValues) {\n if (\n spilledValue.origin.workbookName !== spillCandidate.workbookName ||\n spilledValue.origin.sheetName !== spillCandidate.sheetName\n ) {\n continue;\n }\n if (\n spilledValue.origin.colIndex === spillCandidate.colIndex &&\n spilledValue.origin.rowIndex === spillCandidate.rowIndex\n ) {\n // we are already have a spill, this one will be replaced\n continue;\n }\n\n if (checkRangeIntersection(spillArea, spilledValue.spillOnto)) {\n return false;\n }\n }\n // let's just check the raw data if there is something in the range\n for (const key of sheet.content.keys()) {\n const cellAddress = parseCellReference(key);\n const endCol = spillArea.end.col;\n const endRow = spillArea.end.row;\n\n if (\n cellAddress.colIndex === spillCandidate.colIndex &&\n cellAddress.rowIndex === spillCandidate.rowIndex\n ) {\n continue;\n }\n\n if (endCol.type === \"number\" && endRow.type === \"number\") {\n if (\n cellAddress.colIndex >= spillArea.start.col &&\n cellAddress.colIndex <= endCol.value &&\n cellAddress.rowIndex >= spillArea.start.row &&\n cellAddress.rowIndex <= endRow.value\n ) {\n if (\n normalizeSerializedCellValue(sheet.content.get(key)) !== undefined\n ) {\n // there is something in the range, so we can't spill\n return false;\n }\n }\n }\n }\n\n return true;\n }\n\n getCellEvaluationResult(\n cellAddress: CellAddress\n ): SingleEvaluationResult | undefined {\n if (this.isEvaluating) {\n throw new Error(\"Evaluation in progress\");\n }\n\n const nodeKey = cellAddressToKey(cellAddress);\n const node = this.dependencyManager.getCellValueOrEmptyCellNode(nodeKey);\n\n const sheet = this.workbookManager.getSheet(cellAddress);\n if (!sheet) {\n throw new SheetNotFoundError(cellAddress.sheetName);\n }\n\n if (node.evaluationResult.type === \"awaiting-evaluation\") {\n // if (cellAddressToKey(cellAddress).includes(\"G10\")) {\n // console.group(\"Evaluation of G10\");\n // flags.isProfiling = true;\n // console.time(\"Evaluation of G10\");\n // console.profile(\"Evaluation of G10\");\n // }\n this.evaluateCell(node);\n // if (flags.isProfiling) {\n // flags.isProfiling = false;\n // console.timeEnd(\"Evaluation of G10\");\n // console.profileEnd(\"Evaluation of G10\");\n // console.groupEnd();\n // }\n }\n\n const result = node.evaluationResult;\n\n return result;\n }\n}\n"
6
6
  ],
7
7
  "mappings": ";AAAA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAIA;AACA;AAEA;AAAA;AAAA;AAcA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA;AACA;AAGA;AACA;AAAA;AAaO,MAAM,kBAAkB;AAAA,EAInB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EANF,eAAe;AAAA,EAEvB,WAAW,CACD,iBACA,cACA,kBACA,mBACR;AAAA,IAJQ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAGV,oBAAoB,GAAS;AAAA,IAC3B,KAAK,kBAAkB,qBAAqB;AAAA;AAAA,EAGtC,aAAa,CACnB,WACA,QACA,UAA+B,IAAI,KAC1B;AAAA,IACT,IAAI,cAAc,QAAQ;AAAA,MACxB,OAAO;AAAA,IACT;AAAA,IAEA,IAAI,QAAQ,IAAI,SAAS,GAAG;AAAA,MAC1B,OAAO;AAAA,IACT;AAAA,IACA,QAAQ,IAAI,SAAS;AAAA,IAErB,WAAW,OAAO,UAAU,gBAAgB,GAAG;AAAA,MAC7C,IAAI,KAAK,cAAc,KAAK,QAAQ,OAAO,GAAG;AAAA,QAC5C,OAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,OAAO;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AK,cAAc;AAAA,MACrB,MAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AAAA,IAEA,MAAM,UAAU,iBAAiB,WAAW;AAAA,IAC5C,MAAM,OAAO,KAAK,kBAAkB,4BAA4B,OAAO;AAAA,IAEvE,MAAM,QAAQ,KAAK,gBAAgB,SAAS,WAAW;AAAA,IACvD,IAAI,CAAC,OAAO;AAAA,MACV,MAAM,IAAI,mBAAmB,YAAY,SAAS;AAAA,IACpD;AAAA,IAEA,IAAI,KAAK,iBAAiB,SAAS,uBAAuB;AAAA,MAOxD,KAAK,aAAa,IAAI;AAAA,IAOxB;AAAA,IAEA,MAAM,SAAS,KAAK;AAAA,IAEpB,OAAO;AAAA;AAEX;",
8
8
  "debugId": "E28F2E811FD149C364756E2164756E21",
@@ -0,0 +1,201 @@
1
+ // src/core/mutation-invalidation.ts
2
+ import { getNamedExpressionResourceKey } from "./resource-keys.mjs";
3
+ import { getCellReference, parseCellReference } from "./utils.mjs";
4
+ function getSerializedCellValueKind(value) {
5
+ if (value === undefined || typeof value === "string" && value.length === 0) {
6
+ return "empty";
7
+ }
8
+ if (typeof value === "string" && value.startsWith("=")) {
9
+ return "formula";
10
+ }
11
+ return "scalar";
12
+ }
13
+ function getMutationAddressKey(address) {
14
+ return `${address.workbookName}:${address.sheetName}:${getCellReference(address)}`;
15
+ }
16
+ function buildTouchedCells(cells) {
17
+ const deduped = new Map;
18
+ for (const cell of cells) {
19
+ deduped.set(getMutationAddressKey(cell.address), {
20
+ address: cell.address,
21
+ beforeKind: getSerializedCellValueKind(cell.before),
22
+ afterKind: getSerializedCellValueKind(cell.after)
23
+ });
24
+ }
25
+ return Array.from(deduped.values());
26
+ }
27
+ function buildFormulaTouchedCells(cells) {
28
+ return cells.map((address) => ({
29
+ address,
30
+ beforeKind: "formula",
31
+ afterKind: "formula"
32
+ }));
33
+ }
34
+ function captureCellContents(workbookManager, addresses) {
35
+ const contents = new Map;
36
+ for (const address of addresses) {
37
+ try {
38
+ contents.set(getMutationAddressKey(address), workbookManager.getCellContent(address));
39
+ } catch {
40
+ contents.set(getMutationAddressKey(address), undefined);
41
+ }
42
+ }
43
+ return contents;
44
+ }
45
+ function buildSheetContentTouchedCells(opts, beforeContent, afterContent) {
46
+ const touchedKeys = new Set([
47
+ ...Array.from(beforeContent?.keys() ?? []),
48
+ ...Array.from(afterContent.keys())
49
+ ]);
50
+ return buildTouchedCells(Array.from(touchedKeys, (key) => ({
51
+ address: {
52
+ workbookName: opts.workbookName,
53
+ sheetName: opts.sheetName,
54
+ ...parseCellReference(key)
55
+ },
56
+ before: beforeContent?.get(key),
57
+ after: afterContent.get(key)
58
+ })));
59
+ }
60
+ function getTableCellKey(address) {
61
+ return `${address.workbookName}:${address.sheetName}:${address.rowIndex}:${address.colIndex}`;
62
+ }
63
+ function collectTableFootprintCells(workbookManager, table) {
64
+ const cells = new Map;
65
+ const sheet = workbookManager.getSheet({
66
+ workbookName: table.workbookName,
67
+ sheetName: table.sheetName
68
+ });
69
+ if (!sheet) {
70
+ return [];
71
+ }
72
+ const startColIndex = table.start.colIndex;
73
+ const endColIndex = startColIndex + table.headers.size - 1;
74
+ if (table.endRow.type === "number") {
75
+ for (let rowIndex = table.start.rowIndex;rowIndex <= table.endRow.value; rowIndex++) {
76
+ for (let colIndex = startColIndex;colIndex <= endColIndex; colIndex++) {
77
+ const address = {
78
+ workbookName: table.workbookName,
79
+ sheetName: table.sheetName,
80
+ rowIndex,
81
+ colIndex
82
+ };
83
+ cells.set(getTableCellKey(address), {
84
+ address,
85
+ content: workbookManager.getCellContent(address)
86
+ });
87
+ }
88
+ }
89
+ return Array.from(cells.values());
90
+ }
91
+ for (const [ref, content] of sheet.content.entries()) {
92
+ const { rowIndex, colIndex } = parseCellReference(ref);
93
+ if (rowIndex < table.start.rowIndex) {
94
+ continue;
95
+ }
96
+ if (colIndex < startColIndex || colIndex > endColIndex) {
97
+ continue;
98
+ }
99
+ const address = {
100
+ workbookName: table.workbookName,
101
+ sheetName: table.sheetName,
102
+ rowIndex,
103
+ colIndex
104
+ };
105
+ cells.set(getTableCellKey(address), {
106
+ address,
107
+ content
108
+ });
109
+ }
110
+ return Array.from(cells.values());
111
+ }
112
+ function buildTableTouchedCells(workbookManager, tables) {
113
+ const touchedCells = new Map;
114
+ for (const table of tables) {
115
+ if (!table) {
116
+ continue;
117
+ }
118
+ for (const cell of collectTableFootprintCells(workbookManager, table)) {
119
+ touchedCells.set(getTableCellKey(cell.address), {
120
+ address: cell.address,
121
+ beforeKind: getSerializedCellValueKind(cell.content),
122
+ afterKind: getSerializedCellValueKind(cell.content)
123
+ });
124
+ }
125
+ }
126
+ return Array.from(touchedCells.values());
127
+ }
128
+ function buildTableContextChangedCells(workbookManager, tables) {
129
+ const changedCells = new Map;
130
+ for (const table of tables) {
131
+ if (!table) {
132
+ continue;
133
+ }
134
+ for (const cell of collectTableFootprintCells(workbookManager, table)) {
135
+ changedCells.set(getTableCellKey(cell.address), cell.address);
136
+ }
137
+ }
138
+ return Array.from(changedCells.values());
139
+ }
140
+ function mergeTouchedCells(...groups) {
141
+ const precedence = {
142
+ empty: 0,
143
+ scalar: 1,
144
+ formula: 2
145
+ };
146
+ const merged = new Map;
147
+ for (const group of groups) {
148
+ for (const touchedCell of group) {
149
+ const key = getTableCellKey(touchedCell.address);
150
+ const existing = merged.get(key);
151
+ if (!existing) {
152
+ merged.set(key, touchedCell);
153
+ continue;
154
+ }
155
+ merged.set(key, {
156
+ address: touchedCell.address,
157
+ beforeKind: precedence[touchedCell.beforeKind] >= precedence[existing.beforeKind] ? touchedCell.beforeKind : existing.beforeKind,
158
+ afterKind: precedence[touchedCell.afterKind] >= precedence[existing.afterKind] ? touchedCell.afterKind : existing.afterKind
159
+ });
160
+ }
161
+ }
162
+ return Array.from(merged.values());
163
+ }
164
+ function getNamedExpressionScopeResourceKeys(expressions, opts) {
165
+ return Array.from(new Set(Array.from(expressions, (expressionName) => getNamedExpressionResourceKey({
166
+ expressionName,
167
+ workbookName: opts.workbookName,
168
+ sheetName: opts.sheetName
169
+ }))));
170
+ }
171
+ function getFiniteRangeAddresses(address) {
172
+ if (address.range.end.col.type === "infinity" || address.range.end.row.type === "infinity") {
173
+ return [];
174
+ }
175
+ const cells = [];
176
+ for (let colIndex = address.range.start.col;colIndex <= address.range.end.col.value; colIndex++) {
177
+ for (let rowIndex = address.range.start.row;rowIndex <= address.range.end.row.value; rowIndex++) {
178
+ cells.push({
179
+ workbookName: address.workbookName,
180
+ sheetName: address.sheetName,
181
+ colIndex,
182
+ rowIndex
183
+ });
184
+ }
185
+ }
186
+ return cells;
187
+ }
188
+ export {
189
+ mergeTouchedCells,
190
+ getNamedExpressionScopeResourceKeys,
191
+ getMutationAddressKey,
192
+ getFiniteRangeAddresses,
193
+ captureCellContents,
194
+ buildTouchedCells,
195
+ buildTableTouchedCells,
196
+ buildTableContextChangedCells,
197
+ buildSheetContentTouchedCells,
198
+ buildFormulaTouchedCells
199
+ };
200
+
201
+ //# debugId=94265036334F30FD64756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/core/mutation-invalidation.ts"],
4
+ "sourcesContent": [
5
+ "import type { WorkbookManager } from \"./managers/workbook-manager.mjs\";\nimport type {\n CellAddress,\n RangeAddress,\n SerializedCellValue,\n TableDefinition,\n} from \"./types.mjs\";\nimport { getNamedExpressionResourceKey } from \"./resource-keys.mjs\";\nimport { getCellReference, parseCellReference } from \"./utils.mjs\";\n\ntype CellContentKind = \"empty\" | \"scalar\" | \"formula\";\n\nexport type RemovedScope =\n | { type: \"workbook\"; workbookName: string }\n | { type: \"sheet\"; workbookName: string; sheetName: string };\n\nexport type MutationInvalidation = {\n touchedCells: Array<{\n address: CellAddress;\n beforeKind: CellContentKind;\n afterKind: CellContentKind;\n }>;\n /**\n * Cells whose table membership or implicit current-row table context changed\n * without necessarily changing their formula text.\n */\n tableContextChangedCells?: CellAddress[];\n resourceKeys: string[];\n removedScopes?: RemovedScope[];\n};\n\nfunction getSerializedCellValueKind(\n value: SerializedCellValue | undefined\n): CellContentKind {\n if (\n value === undefined ||\n (typeof value === \"string\" && value.length === 0)\n ) {\n return \"empty\";\n }\n if (typeof value === \"string\" && value.startsWith(\"=\")) {\n return \"formula\";\n }\n return \"scalar\";\n}\n\nfunction emptyMutationInvalidation(): MutationInvalidation {\n return {\n touchedCells: [],\n resourceKeys: [],\n };\n}\n\nexport function getMutationAddressKey(address: CellAddress): string {\n return `${address.workbookName}:${address.sheetName}:${getCellReference(\n address\n )}`;\n}\n\nexport function buildTouchedCells(\n cells: Array<{\n address: CellAddress;\n before: SerializedCellValue | undefined;\n after: SerializedCellValue | undefined;\n }>\n): MutationInvalidation[\"touchedCells\"] {\n const deduped = new Map<\n string,\n MutationInvalidation[\"touchedCells\"][number]\n >();\n\n for (const cell of cells) {\n deduped.set(getMutationAddressKey(cell.address), {\n address: cell.address,\n beforeKind: getSerializedCellValueKind(cell.before),\n afterKind: getSerializedCellValueKind(cell.after),\n });\n }\n\n return Array.from(deduped.values());\n}\n\nexport function buildFormulaTouchedCells(\n cells: CellAddress[]\n): MutationInvalidation[\"touchedCells\"] {\n return cells.map((address) => ({\n address,\n beforeKind: \"formula\",\n afterKind: \"formula\",\n }));\n}\n\nexport function captureCellContents(\n workbookManager: WorkbookManager,\n addresses: CellAddress[]\n): Map<string, SerializedCellValue | undefined> {\n const contents = new Map<string, SerializedCellValue | undefined>();\n for (const address of addresses) {\n try {\n contents.set(\n getMutationAddressKey(address),\n workbookManager.getCellContent(address)\n );\n } catch {\n contents.set(getMutationAddressKey(address), undefined);\n }\n }\n return contents;\n}\n\nexport function buildSheetContentTouchedCells(\n opts: { workbookName: string; sheetName: string },\n beforeContent: Map<string, SerializedCellValue> | undefined,\n afterContent: Map<string, SerializedCellValue>\n): MutationInvalidation[\"touchedCells\"] {\n const touchedKeys = new Set<string>([\n ...Array.from(beforeContent?.keys() ?? []),\n ...Array.from(afterContent.keys()),\n ]);\n\n return buildTouchedCells(\n Array.from(touchedKeys, (key) => ({\n address: {\n workbookName: opts.workbookName,\n sheetName: opts.sheetName,\n ...parseCellReference(key),\n },\n before: beforeContent?.get(key),\n after: afterContent.get(key),\n }))\n );\n}\n\nfunction getTableCellKey(address: CellAddress): string {\n return `${address.workbookName}:${address.sheetName}:${address.rowIndex}:${address.colIndex}`;\n}\n\nfunction collectTableFootprintCells(\n workbookManager: WorkbookManager,\n table: TableDefinition\n): Array<{\n address: CellAddress;\n content: SerializedCellValue | undefined;\n}> {\n const cells = new Map<\n string,\n {\n address: CellAddress;\n content: SerializedCellValue | undefined;\n }\n >();\n const sheet = workbookManager.getSheet({\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n });\n if (!sheet) {\n return [];\n }\n\n const startColIndex = table.start.colIndex;\n const endColIndex = startColIndex + table.headers.size - 1;\n\n if (table.endRow.type === \"number\") {\n for (\n let rowIndex = table.start.rowIndex;\n rowIndex <= table.endRow.value;\n rowIndex++\n ) {\n for (\n let colIndex = startColIndex;\n colIndex <= endColIndex;\n colIndex++\n ) {\n const address = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n rowIndex,\n colIndex,\n };\n cells.set(getTableCellKey(address), {\n address,\n content: workbookManager.getCellContent(address),\n });\n }\n }\n return Array.from(cells.values());\n }\n\n for (const [ref, content] of sheet.content.entries()) {\n const { rowIndex, colIndex } = parseCellReference(ref);\n if (rowIndex < table.start.rowIndex) {\n continue;\n }\n if (colIndex < startColIndex || colIndex > endColIndex) {\n continue;\n }\n\n const address = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n rowIndex,\n colIndex,\n };\n cells.set(getTableCellKey(address), {\n address,\n content,\n });\n }\n\n return Array.from(cells.values());\n}\n\nexport function buildTableTouchedCells(\n workbookManager: WorkbookManager,\n tables: Array<TableDefinition | undefined>\n): MutationInvalidation[\"touchedCells\"] {\n const touchedCells = new Map<\n string,\n MutationInvalidation[\"touchedCells\"][number]\n >();\n\n for (const table of tables) {\n if (!table) {\n continue;\n }\n for (const cell of collectTableFootprintCells(workbookManager, table)) {\n touchedCells.set(getTableCellKey(cell.address), {\n address: cell.address,\n beforeKind: getSerializedCellValueKind(cell.content),\n afterKind: getSerializedCellValueKind(cell.content),\n });\n }\n }\n\n return Array.from(touchedCells.values());\n}\n\nexport function buildTableContextChangedCells(\n workbookManager: WorkbookManager,\n tables: Array<TableDefinition | undefined>\n): CellAddress[] {\n const changedCells = new Map<string, CellAddress>();\n\n for (const table of tables) {\n if (!table) {\n continue;\n }\n for (const cell of collectTableFootprintCells(workbookManager, table)) {\n changedCells.set(getTableCellKey(cell.address), cell.address);\n }\n }\n\n return Array.from(changedCells.values());\n}\n\nexport function mergeTouchedCells(\n ...groups: MutationInvalidation[\"touchedCells\"][]\n): MutationInvalidation[\"touchedCells\"] {\n const precedence = {\n empty: 0,\n scalar: 1,\n formula: 2,\n } as const;\n const merged = new Map<\n string,\n MutationInvalidation[\"touchedCells\"][number]\n >();\n\n for (const group of groups) {\n for (const touchedCell of group) {\n const key = getTableCellKey(touchedCell.address);\n const existing = merged.get(key);\n if (!existing) {\n merged.set(key, touchedCell);\n continue;\n }\n\n merged.set(key, {\n address: touchedCell.address,\n beforeKind:\n precedence[touchedCell.beforeKind] >= precedence[existing.beforeKind]\n ? touchedCell.beforeKind\n : existing.beforeKind,\n afterKind:\n precedence[touchedCell.afterKind] >= precedence[existing.afterKind]\n ? touchedCell.afterKind\n : existing.afterKind,\n });\n }\n }\n\n return Array.from(merged.values());\n}\n\nexport function getNamedExpressionScopeResourceKeys(\n expressions: Iterable<string>,\n opts: {\n workbookName?: string;\n sheetName?: string;\n }\n): string[] {\n return Array.from(\n new Set(\n Array.from(expressions, (expressionName) =>\n getNamedExpressionResourceKey({\n expressionName,\n workbookName: opts.workbookName,\n sheetName: opts.sheetName,\n })\n )\n )\n );\n}\n\nexport function getFiniteRangeAddresses(address: RangeAddress): CellAddress[] {\n if (\n address.range.end.col.type === \"infinity\" ||\n address.range.end.row.type === \"infinity\"\n ) {\n return [];\n }\n\n const cells: CellAddress[] = [];\n for (\n let colIndex = address.range.start.col;\n colIndex <= address.range.end.col.value;\n colIndex++\n ) {\n for (\n let rowIndex = address.range.start.row;\n rowIndex <= address.range.end.row.value;\n rowIndex++\n ) {\n cells.push({\n workbookName: address.workbookName,\n sheetName: address.sheetName,\n colIndex,\n rowIndex,\n });\n }\n }\n return cells;\n}\n"
6
+ ],
7
+ "mappings": ";AAOA;AACA;AAuBA,SAAS,0BAA0B,CACjC,OACiB;AAAA,EACjB,IACE,UAAU,aACT,OAAO,UAAU,YAAY,MAAM,WAAW,GAC/C;AAAA,IACA,OAAO;AAAA,EACT;AAAA,EACA,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAAG,GAAG;AAAA,IACtD,OAAO;AAAA,EACT;AAAA,EACA,OAAO;AAAA;AAUF,SAAS,qBAAqB,CAAC,SAA8B;AAAA,EAClE,OAAO,GAAG,QAAQ,gBAAgB,QAAQ,aAAa,iBACrD,OACF;AAAA;AAGK,SAAS,iBAAiB,CAC/B,OAKsC;AAAA,EACtC,MAAM,UAAU,IAAI;AAAA,EAKpB,WAAW,QAAQ,OAAO;AAAA,IACxB,QAAQ,IAAI,sBAAsB,KAAK,OAAO,GAAG;AAAA,MAC/C,SAAS,KAAK;AAAA,MACd,YAAY,2BAA2B,KAAK,MAAM;AAAA,MAClD,WAAW,2BAA2B,KAAK,KAAK;AAAA,IAClD,CAAC;AAAA,EACH;AAAA,EAEA,OAAO,MAAM,KAAK,QAAQ,OAAO,CAAC;AAAA;AAG7B,SAAS,wBAAwB,CACtC,OACsC;AAAA,EACtC,OAAO,MAAM,IAAI,CAAC,aAAa;AAAA,IAC7B;AAAA,IACA,YAAY;AAAA,IACZ,WAAW;AAAA,EACb,EAAE;AAAA;AAGG,SAAS,mBAAmB,CACjC,iBACA,WAC8C;AAAA,EAC9C,MAAM,WAAW,IAAI;AAAA,EACrB,WAAW,WAAW,WAAW;AAAA,IAC/B,IAAI;AAAA,MACF,SAAS,IACP,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AAA;AAGK,SAAS,uBAAuB,CAAC,SAAsC;AAAA,EAC5E,IACE,QAAQ,MAAM,IAAI,IAAI,SAAS,cAC/B,QAAQ,MAAM,IAAI,IAAI,SAAS,YAC/B;AAAA,IACA,OAAO,CAAC;AAAA,EACV;AAAA,EAEA,MAAM,QAAuB,CAAC;AAAA,EAC9B,SACM,WAAW,QAAQ,MAAM,MAAM,IACnC,YAAY,QAAQ,MAAM,IAAI,IAAI,OAClC,YACA;AAAA,IACA,SACM,WAAW,QAAQ,MAAM,MAAM,IACnC,YAAY,QAAQ,MAAM,IAAI,IAAI,OAClC,YACA;AAAA,MACA,MAAM,KAAK;AAAA,QACT,cAAc,QAAQ;AAAA,QACtB,WAAW,QAAQ;AAAA,QACnB;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EACA,OAAO;AAAA;",
8
+ "debugId": "94265036334F30FD64756E2164756E21",
9
+ "names": []
10
+ }
package/dist/mjs/lib.mjs CHANGED
@@ -4,19 +4,8 @@ import { FormulaEngine } from "./core/engine.mjs";
4
4
  export * from "./core/types.mjs";
5
5
  export * from "./core/utils.mjs";
6
6
  export * from "./core/utils/color-utils.mjs";
7
- import { defineSchema, defineHeader } from "./core/schema/schema.mjs";
8
- import { TableOrm } from "./core/schema/table-orm.mjs";
9
- import { CellOrm } from "./core/schema/cell-orm.mjs";
10
- import { SchemaValidationError } from "./core/managers/schema-manager.mjs";
11
- import { SchemaIntegrityError } from "./core/commands/command-executor.mjs";
12
7
  export {
13
- defineSchema,
14
- defineHeader,
15
- TableOrm,
16
- SchemaValidationError,
17
- SchemaIntegrityError,
18
- FormulaEngine,
19
- CellOrm
8
+ FormulaEngine
20
9
  };
21
10
 
22
- //# debugId=D42F2BBEF074B4FE64756E2164756E21
11
+ //# debugId=33910997D1B8156A64756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib.ts"],
4
4
  "sourcesContent": [
5
- "export { FormulaEngine } from \"./core/engine.mjs\";\nexport * from \"./core/types.mjs\";\nexport * from \"./core/utils.mjs\";\nexport * from \"./core/utils/color-utils.mjs\";\n\n// Schema exports\nexport { defineSchema, defineHeader } from \"./core/schema/schema.mjs\";\nexport type { CreateSchema, SchemaDeclaration, Schema, TableSchemaDefinition, CellSchemaDefinition, TableOrmSchema, CellOrmSchema } from \"./core/schema/schema.mjs\";\nexport { TableOrm } from \"./core/schema/table-orm.mjs\";\nexport { CellOrm } from \"./core/schema/cell-orm.mjs\";\nexport { SchemaValidationError } from \"./core/managers/schema-manager.mjs\";\nexport type { ValidationResult } from \"./core/managers/schema-manager.mjs\";\n\n// Command Pattern exports\nexport { SchemaIntegrityError } from \"./core/commands/command-executor.mjs\";\nexport type { EngineAction, EngineCommand } from \"./core/commands/types.mjs\";\n"
5
+ "export { FormulaEngine } from \"./core/engine.mjs\";\nexport * from \"./core/types.mjs\";\nexport * from \"./core/utils.mjs\";\nexport * from \"./core/utils/color-utils.mjs\";\n"
6
6
  ],
7
- "mappings": ";AAAA;AAAA;AACA;AACA;AACA;AAGA;AAEA;AACA;AACA;AAIA;",
8
- "debugId": "D42F2BBEF074B4FE64756E2164756E21",
7
+ "mappings": ";AAAA;AAAA;AACA;AACA;AACA;",
8
+ "debugId": "33910997D1B8156A64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "type": "module"
5
5
  }