@ricsam/formula-engine 0.2.2 → 0.2.3

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 (337) hide show
  1. package/dist/cjs/core/ast-traverser.cjs +19 -9
  2. package/dist/cjs/core/ast-traverser.cjs.map +2 -2
  3. package/dist/cjs/core/autofill-utils.cjs +19 -9
  4. package/dist/cjs/core/autofill-utils.cjs.map +2 -2
  5. package/dist/cjs/core/cell-mover.cjs +19 -9
  6. package/dist/cjs/core/cell-mover.cjs.map +2 -2
  7. package/dist/cjs/core/commands/command-executor.cjs +24 -13
  8. package/dist/cjs/core/commands/command-executor.cjs.map +3 -3
  9. package/dist/cjs/core/commands/content-commands.cjs +292 -9
  10. package/dist/cjs/core/commands/content-commands.cjs.map +3 -3
  11. package/dist/cjs/core/commands/metadata-commands.cjs +19 -9
  12. package/dist/cjs/core/commands/metadata-commands.cjs.map +2 -2
  13. package/dist/cjs/core/commands/named-expression-commands.cjs +138 -13
  14. package/dist/cjs/core/commands/named-expression-commands.cjs.map +3 -3
  15. package/dist/cjs/core/commands/structure-commands.cjs +216 -15
  16. package/dist/cjs/core/commands/structure-commands.cjs.map +3 -3
  17. package/dist/cjs/core/commands/style-commands.cjs +19 -9
  18. package/dist/cjs/core/commands/style-commands.cjs.map +2 -2
  19. package/dist/cjs/core/commands/table-commands.cjs +134 -13
  20. package/dist/cjs/core/commands/table-commands.cjs.map +3 -3
  21. package/dist/cjs/core/commands/types.cjs +36 -9
  22. package/dist/cjs/core/commands/types.cjs.map +3 -3
  23. package/dist/cjs/core/engine-snapshot.cjs +51 -0
  24. package/dist/cjs/core/engine-snapshot.cjs.map +10 -0
  25. package/dist/cjs/core/engine.cjs +51 -34
  26. package/dist/cjs/core/engine.cjs.map +3 -3
  27. package/dist/cjs/core/managers/cache-manager.cjs +123 -9
  28. package/dist/cjs/core/managers/cache-manager.cjs.map +3 -3
  29. package/dist/cjs/core/managers/copy-manager.cjs +19 -9
  30. package/dist/cjs/core/managers/copy-manager.cjs.map +2 -2
  31. package/dist/cjs/core/managers/dependency-manager.cjs +697 -9
  32. package/dist/cjs/core/managers/dependency-manager.cjs.map +3 -3
  33. package/dist/cjs/core/managers/dependency-node.cjs +14 -8
  34. package/dist/cjs/core/managers/dependency-node.cjs.map +1 -1
  35. package/dist/cjs/core/managers/evaluation-manager.cjs +296 -11
  36. package/dist/cjs/core/managers/evaluation-manager.cjs.map +3 -3
  37. package/dist/cjs/core/managers/event-manager.cjs +19 -9
  38. package/dist/cjs/core/managers/event-manager.cjs.map +2 -2
  39. package/dist/cjs/core/managers/frontier-dependency-manager.cjs +65 -12
  40. package/dist/cjs/core/managers/frontier-dependency-manager.cjs.map +3 -3
  41. package/dist/cjs/core/managers/isDependencyNode.cjs +19 -9
  42. package/dist/cjs/core/managers/isDependencyNode.cjs.map +2 -2
  43. package/dist/cjs/core/managers/named-expression-manager.cjs +121 -29
  44. package/dist/cjs/core/managers/named-expression-manager.cjs.map +3 -3
  45. package/dist/cjs/core/managers/range-eval-order-builder.cjs +19 -9
  46. package/dist/cjs/core/managers/range-eval-order-builder.cjs.map +2 -2
  47. package/dist/cjs/core/managers/reference-manager.cjs +25 -9
  48. package/dist/cjs/core/managers/reference-manager.cjs.map +3 -3
  49. package/dist/cjs/core/managers/schema-manager.cjs +19 -9
  50. package/dist/cjs/core/managers/schema-manager.cjs.map +2 -2
  51. package/dist/cjs/core/managers/style-manager.cjs +28 -9
  52. package/dist/cjs/core/managers/style-manager.cjs.map +3 -3
  53. package/dist/cjs/core/managers/table-manager.cjs +25 -9
  54. package/dist/cjs/core/managers/table-manager.cjs.map +3 -3
  55. package/dist/cjs/core/managers/workbook-manager.cjs +38 -13
  56. package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
  57. package/dist/cjs/core/map-serializer.cjs +19 -9
  58. package/dist/cjs/core/map-serializer.cjs.map +2 -2
  59. package/dist/cjs/core/named-expression-renamer.cjs +19 -9
  60. package/dist/cjs/core/named-expression-renamer.cjs.map +2 -2
  61. package/dist/cjs/core/resource-keys.cjs +67 -0
  62. package/dist/cjs/core/resource-keys.cjs.map +10 -0
  63. package/dist/cjs/core/schema/cell-orm.cjs +19 -9
  64. package/dist/cjs/core/schema/cell-orm.cjs.map +2 -2
  65. package/dist/cjs/core/schema/grid-orm.cjs +19 -9
  66. package/dist/cjs/core/schema/grid-orm.cjs.map +2 -2
  67. package/dist/cjs/core/schema/schema-builder.cjs +19 -9
  68. package/dist/cjs/core/schema/schema-builder.cjs.map +2 -2
  69. package/dist/cjs/core/schema/schema-helpers.cjs +19 -9
  70. package/dist/cjs/core/schema/schema-helpers.cjs.map +2 -2
  71. package/dist/cjs/core/schema/schema.cjs +19 -9
  72. package/dist/cjs/core/schema/schema.cjs.map +2 -2
  73. package/dist/cjs/core/schema/table-orm.cjs +19 -9
  74. package/dist/cjs/core/schema/table-orm.cjs.map +2 -2
  75. package/dist/cjs/core/sheet-renamer.cjs +19 -9
  76. package/dist/cjs/core/sheet-renamer.cjs.map +2 -2
  77. package/dist/cjs/core/sheet-utils.cjs +19 -9
  78. package/dist/cjs/core/sheet-utils.cjs.map +2 -2
  79. package/dist/cjs/core/table-renamer.cjs +19 -9
  80. package/dist/cjs/core/table-renamer.cjs.map +2 -2
  81. package/dist/cjs/core/types.cjs +19 -9
  82. package/dist/cjs/core/types.cjs.map +2 -2
  83. package/dist/cjs/core/utils/color-utils.cjs +19 -9
  84. package/dist/cjs/core/utils/color-utils.cjs.map +2 -2
  85. package/dist/cjs/core/utils/range-serializer.cjs +19 -9
  86. package/dist/cjs/core/utils/range-serializer.cjs.map +2 -2
  87. package/dist/cjs/core/utils/range-utils.cjs +19 -9
  88. package/dist/cjs/core/utils/range-utils.cjs.map +2 -2
  89. package/dist/cjs/core/utils/spreadsheet-visualizer.cjs +19 -9
  90. package/dist/cjs/core/utils/spreadsheet-visualizer.cjs.map +2 -2
  91. package/dist/cjs/core/utils.cjs +19 -9
  92. package/dist/cjs/core/utils.cjs.map +2 -2
  93. package/dist/cjs/core/workbook-renamer.cjs +19 -9
  94. package/dist/cjs/core/workbook-renamer.cjs.map +2 -2
  95. package/dist/cjs/debug/flags.cjs +19 -9
  96. package/dist/cjs/debug/flags.cjs.map +2 -2
  97. package/dist/cjs/evaluator/arithmetic/add/add.cjs +19 -9
  98. package/dist/cjs/evaluator/arithmetic/add/add.cjs.map +2 -2
  99. package/dist/cjs/evaluator/arithmetic/divide/divide.cjs +19 -9
  100. package/dist/cjs/evaluator/arithmetic/divide/divide.cjs.map +2 -2
  101. package/dist/cjs/evaluator/arithmetic/multiply/multiply.cjs +19 -9
  102. package/dist/cjs/evaluator/arithmetic/multiply/multiply.cjs.map +2 -2
  103. package/dist/cjs/evaluator/arithmetic/power/power.cjs +19 -9
  104. package/dist/cjs/evaluator/arithmetic/power/power.cjs.map +2 -2
  105. package/dist/cjs/evaluator/arithmetic/subtract/subtract.cjs +19 -9
  106. package/dist/cjs/evaluator/arithmetic/subtract/subtract.cjs.map +2 -2
  107. package/dist/cjs/evaluator/comparison/equals.cjs +19 -9
  108. package/dist/cjs/evaluator/comparison/equals.cjs.map +2 -2
  109. package/dist/cjs/evaluator/comparison/greater-than-or-equal.cjs +19 -9
  110. package/dist/cjs/evaluator/comparison/greater-than-or-equal.cjs.map +2 -2
  111. package/dist/cjs/evaluator/comparison/greater-than.cjs +19 -9
  112. package/dist/cjs/evaluator/comparison/greater-than.cjs.map +2 -2
  113. package/dist/cjs/evaluator/comparison/less-than-or-equal.cjs +19 -9
  114. package/dist/cjs/evaluator/comparison/less-than-or-equal.cjs.map +2 -2
  115. package/dist/cjs/evaluator/comparison/less-than.cjs +19 -9
  116. package/dist/cjs/evaluator/comparison/less-than.cjs.map +2 -2
  117. package/dist/cjs/evaluator/comparison/not-equals.cjs +19 -9
  118. package/dist/cjs/evaluator/comparison/not-equals.cjs.map +2 -2
  119. package/dist/cjs/evaluator/concatenation/concatenate.cjs +19 -9
  120. package/dist/cjs/evaluator/concatenation/concatenate.cjs.map +2 -2
  121. package/dist/cjs/evaluator/dependency-nodes/ast-evaluation-node.cjs +19 -9
  122. package/dist/cjs/evaluator/dependency-nodes/ast-evaluation-node.cjs.map +2 -2
  123. package/dist/cjs/evaluator/dependency-nodes/base-eval-node.cjs +35 -9
  124. package/dist/cjs/evaluator/dependency-nodes/base-eval-node.cjs.map +3 -3
  125. package/dist/cjs/evaluator/dependency-nodes/cell-value-node.cjs +22 -9
  126. package/dist/cjs/evaluator/dependency-nodes/cell-value-node.cjs.map +3 -3
  127. package/dist/cjs/evaluator/dependency-nodes/empty-cell-evaluation-node.cjs +35 -11
  128. package/dist/cjs/evaluator/dependency-nodes/empty-cell-evaluation-node.cjs.map +3 -3
  129. package/dist/cjs/evaluator/dependency-nodes/resource-dependency-node.cjs +61 -0
  130. package/dist/cjs/evaluator/dependency-nodes/resource-dependency-node.cjs.map +10 -0
  131. package/dist/cjs/evaluator/dependency-nodes/spill-meta-node.cjs +19 -9
  132. package/dist/cjs/evaluator/dependency-nodes/spill-meta-node.cjs.map +2 -2
  133. package/dist/cjs/evaluator/dependency-nodes/virtual-cell-value-node.cjs +22 -9
  134. package/dist/cjs/evaluator/dependency-nodes/virtual-cell-value-node.cjs.map +3 -3
  135. package/dist/cjs/evaluator/evaluate-scalar-operator.cjs +19 -9
  136. package/dist/cjs/evaluator/evaluate-scalar-operator.cjs.map +2 -2
  137. package/dist/cjs/evaluator/evaluation-context.cjs +19 -9
  138. package/dist/cjs/evaluator/evaluation-context.cjs.map +2 -2
  139. package/dist/cjs/evaluator/evaluation-error.cjs +19 -9
  140. package/dist/cjs/evaluator/evaluation-error.cjs.map +2 -2
  141. package/dist/cjs/evaluator/formula-evaluator.cjs +55 -12
  142. package/dist/cjs/evaluator/formula-evaluator.cjs.map +3 -3
  143. package/dist/cjs/evaluator/range-evaluation-node.cjs +35 -11
  144. package/dist/cjs/evaluator/range-evaluation-node.cjs.map +3 -3
  145. package/dist/cjs/functions/_template/template.cjs +19 -9
  146. package/dist/cjs/functions/_template/template.cjs.map +2 -2
  147. package/dist/cjs/functions/array/sequence/sequence.cjs +19 -9
  148. package/dist/cjs/functions/array/sequence/sequence.cjs.map +2 -2
  149. package/dist/cjs/functions/criteria-parser.cjs +19 -9
  150. package/dist/cjs/functions/criteria-parser.cjs.map +2 -2
  151. package/dist/cjs/functions/criteria-utils.cjs +19 -9
  152. package/dist/cjs/functions/criteria-utils.cjs.map +2 -2
  153. package/dist/cjs/functions/function-registry.cjs +19 -9
  154. package/dist/cjs/functions/function-registry.cjs.map +2 -2
  155. package/dist/cjs/functions/function-utils.cjs +19 -9
  156. package/dist/cjs/functions/function-utils.cjs.map +2 -2
  157. package/dist/cjs/functions/information/cell/cell.cjs +19 -9
  158. package/dist/cjs/functions/information/cell/cell.cjs.map +2 -2
  159. package/dist/cjs/functions/information/column/column.cjs +19 -9
  160. package/dist/cjs/functions/information/column/column.cjs.map +2 -2
  161. package/dist/cjs/functions/information/row/row.cjs +19 -9
  162. package/dist/cjs/functions/information/row/row.cjs.map +2 -2
  163. package/dist/cjs/functions/logical/and/and.cjs +19 -9
  164. package/dist/cjs/functions/logical/and/and.cjs.map +2 -2
  165. package/dist/cjs/functions/logical/if/if.cjs +19 -9
  166. package/dist/cjs/functions/logical/if/if.cjs.map +2 -2
  167. package/dist/cjs/functions/logical/iferror/iferror.cjs +19 -9
  168. package/dist/cjs/functions/logical/iferror/iferror.cjs.map +2 -2
  169. package/dist/cjs/functions/logical/or/or.cjs +19 -9
  170. package/dist/cjs/functions/logical/or/or.cjs.map +2 -2
  171. package/dist/cjs/functions/lookup/count/count-utils.cjs +19 -9
  172. package/dist/cjs/functions/lookup/count/count-utils.cjs.map +2 -2
  173. package/dist/cjs/functions/lookup/count/count.cjs +19 -9
  174. package/dist/cjs/functions/lookup/count/count.cjs.map +2 -2
  175. package/dist/cjs/functions/lookup/count/countif.cjs +19 -9
  176. package/dist/cjs/functions/lookup/count/countif.cjs.map +2 -2
  177. package/dist/cjs/functions/lookup/count/countifs.cjs +19 -9
  178. package/dist/cjs/functions/lookup/count/countifs.cjs.map +2 -2
  179. package/dist/cjs/functions/lookup/index-lookup/index-lookup.cjs +19 -9
  180. package/dist/cjs/functions/lookup/index-lookup/index-lookup.cjs.map +2 -2
  181. package/dist/cjs/functions/lookup/match/match.cjs +21 -10
  182. package/dist/cjs/functions/lookup/match/match.cjs.map +3 -3
  183. package/dist/cjs/functions/lookup/xlookup/xlookup.cjs +19 -9
  184. package/dist/cjs/functions/lookup/xlookup/xlookup.cjs.map +2 -2
  185. package/dist/cjs/functions/math/average/average-utils.cjs +19 -9
  186. package/dist/cjs/functions/math/average/average-utils.cjs.map +2 -2
  187. package/dist/cjs/functions/math/average/average.cjs +19 -9
  188. package/dist/cjs/functions/math/average/average.cjs.map +2 -2
  189. package/dist/cjs/functions/math/average/averageif.cjs +19 -9
  190. package/dist/cjs/functions/math/average/averageif.cjs.map +2 -2
  191. package/dist/cjs/functions/math/average/averageifs.cjs +19 -9
  192. package/dist/cjs/functions/math/average/averageifs.cjs.map +2 -2
  193. package/dist/cjs/functions/math/ceiling/ceiling.cjs +19 -9
  194. package/dist/cjs/functions/math/ceiling/ceiling.cjs.map +2 -2
  195. package/dist/cjs/functions/math/max/max-utils.cjs +19 -9
  196. package/dist/cjs/functions/math/max/max-utils.cjs.map +2 -2
  197. package/dist/cjs/functions/math/max/max.cjs +19 -9
  198. package/dist/cjs/functions/math/max/max.cjs.map +2 -2
  199. package/dist/cjs/functions/math/max/maxif.cjs +19 -9
  200. package/dist/cjs/functions/math/max/maxif.cjs.map +2 -2
  201. package/dist/cjs/functions/math/max/maxifs.cjs +19 -9
  202. package/dist/cjs/functions/math/max/maxifs.cjs.map +2 -2
  203. package/dist/cjs/functions/math/min/min-utils.cjs +19 -9
  204. package/dist/cjs/functions/math/min/min-utils.cjs.map +2 -2
  205. package/dist/cjs/functions/math/min/min.cjs +19 -9
  206. package/dist/cjs/functions/math/min/min.cjs.map +2 -2
  207. package/dist/cjs/functions/math/min/minif.cjs +19 -9
  208. package/dist/cjs/functions/math/min/minif.cjs.map +2 -2
  209. package/dist/cjs/functions/math/min/minifs.cjs +19 -9
  210. package/dist/cjs/functions/math/min/minifs.cjs.map +2 -2
  211. package/dist/cjs/functions/math/sum/sum.cjs +19 -9
  212. package/dist/cjs/functions/math/sum/sum.cjs.map +2 -2
  213. package/dist/cjs/functions/math/sum/sumif.cjs +19 -9
  214. package/dist/cjs/functions/math/sum/sumif.cjs.map +2 -2
  215. package/dist/cjs/functions/math/sum/sumifs.cjs +19 -9
  216. package/dist/cjs/functions/math/sum/sumifs.cjs.map +2 -2
  217. package/dist/cjs/functions/math/sum/summation-utils.cjs +19 -9
  218. package/dist/cjs/functions/math/sum/summation-utils.cjs.map +2 -2
  219. package/dist/cjs/functions/reference/address/address.cjs +19 -9
  220. package/dist/cjs/functions/reference/address/address.cjs.map +2 -2
  221. package/dist/cjs/functions/reference/indirect/indirect.cjs +19 -9
  222. package/dist/cjs/functions/reference/indirect/indirect.cjs.map +2 -2
  223. package/dist/cjs/functions/reference/offset/offset.cjs +19 -9
  224. package/dist/cjs/functions/reference/offset/offset.cjs.map +2 -2
  225. package/dist/cjs/functions/text/concatenate/concatenate.cjs +21 -9
  226. package/dist/cjs/functions/text/concatenate/concatenate.cjs.map +3 -3
  227. package/dist/cjs/functions/text/exact/exact.cjs +19 -9
  228. package/dist/cjs/functions/text/exact/exact.cjs.map +2 -2
  229. package/dist/cjs/functions/text/find/find.cjs +19 -9
  230. package/dist/cjs/functions/text/find/find.cjs.map +2 -2
  231. package/dist/cjs/functions/text/left/left.cjs +19 -9
  232. package/dist/cjs/functions/text/left/left.cjs.map +2 -2
  233. package/dist/cjs/functions/text/len/len.cjs +19 -9
  234. package/dist/cjs/functions/text/len/len.cjs.map +2 -2
  235. package/dist/cjs/functions/text/mid/mid.cjs +19 -9
  236. package/dist/cjs/functions/text/mid/mid.cjs.map +2 -2
  237. package/dist/cjs/functions/text/right/right.cjs +19 -9
  238. package/dist/cjs/functions/text/right/right.cjs.map +2 -2
  239. package/dist/cjs/functions/text/text-helpers.cjs +19 -9
  240. package/dist/cjs/functions/text/text-helpers.cjs.map +2 -2
  241. package/dist/cjs/functions/text/textjoin/textjoin.cjs +19 -9
  242. package/dist/cjs/functions/text/textjoin/textjoin.cjs.map +2 -2
  243. package/dist/cjs/lib.cjs +24 -13
  244. package/dist/cjs/lib.cjs.map +2 -2
  245. package/dist/cjs/package.json +1 -1
  246. package/dist/cjs/parser/ast.cjs +19 -9
  247. package/dist/cjs/parser/ast.cjs.map +2 -2
  248. package/dist/cjs/parser/formatter.cjs +19 -9
  249. package/dist/cjs/parser/formatter.cjs.map +2 -2
  250. package/dist/cjs/parser/grammar.cjs +19 -9
  251. package/dist/cjs/parser/grammar.cjs.map +2 -2
  252. package/dist/cjs/parser/lexer.cjs +19 -9
  253. package/dist/cjs/parser/lexer.cjs.map +2 -2
  254. package/dist/cjs/parser/parser.cjs +19 -9
  255. package/dist/cjs/parser/parser.cjs.map +2 -2
  256. package/dist/cjs/react/hooks.cjs +31 -10
  257. package/dist/cjs/react/hooks.cjs.map +2 -2
  258. package/dist/mjs/core/commands/command-executor.mjs +7 -5
  259. package/dist/mjs/core/commands/command-executor.mjs.map +3 -3
  260. package/dist/mjs/core/commands/content-commands.mjs +279 -2
  261. package/dist/mjs/core/commands/content-commands.mjs.map +3 -3
  262. package/dist/mjs/core/commands/named-expression-commands.mjs +121 -6
  263. package/dist/mjs/core/commands/named-expression-commands.mjs.map +3 -3
  264. package/dist/mjs/core/commands/structure-commands.mjs +204 -8
  265. package/dist/mjs/core/commands/structure-commands.mjs.map +3 -3
  266. package/dist/mjs/core/commands/table-commands.mjs +117 -6
  267. package/dist/mjs/core/commands/table-commands.mjs.map +3 -3
  268. package/dist/mjs/core/commands/types.mjs +18 -1
  269. package/dist/mjs/core/commands/types.mjs.map +3 -3
  270. package/dist/mjs/core/engine-snapshot.mjs +11 -0
  271. package/dist/mjs/core/engine-snapshot.mjs.map +10 -0
  272. package/dist/mjs/core/engine.mjs +35 -26
  273. package/dist/mjs/core/engine.mjs.map +3 -3
  274. package/dist/mjs/core/managers/cache-manager.mjs +105 -1
  275. package/dist/mjs/core/managers/cache-manager.mjs.map +3 -3
  276. package/dist/mjs/core/managers/dependency-manager.mjs +687 -2
  277. package/dist/mjs/core/managers/dependency-manager.mjs.map +3 -3
  278. package/dist/mjs/core/managers/evaluation-manager.mjs +283 -4
  279. package/dist/mjs/core/managers/evaluation-manager.mjs.map +3 -3
  280. package/dist/mjs/core/managers/frontier-dependency-manager.mjs +47 -4
  281. package/dist/mjs/core/managers/frontier-dependency-manager.mjs.map +3 -3
  282. package/dist/mjs/core/managers/named-expression-manager.mjs +104 -21
  283. package/dist/mjs/core/managers/named-expression-manager.mjs.map +3 -3
  284. package/dist/mjs/core/managers/reference-manager.mjs +7 -1
  285. package/dist/mjs/core/managers/reference-manager.mjs.map +3 -3
  286. package/dist/mjs/core/managers/style-manager.mjs +10 -1
  287. package/dist/mjs/core/managers/style-manager.mjs.map +3 -3
  288. package/dist/mjs/core/managers/table-manager.mjs +7 -1
  289. package/dist/mjs/core/managers/table-manager.mjs.map +3 -3
  290. package/dist/mjs/core/managers/workbook-manager.mjs +20 -5
  291. package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
  292. package/dist/mjs/core/resource-keys.mjs +27 -0
  293. package/dist/mjs/core/resource-keys.mjs.map +10 -0
  294. package/dist/mjs/evaluator/dependency-nodes/base-eval-node.mjs +17 -1
  295. package/dist/mjs/evaluator/dependency-nodes/base-eval-node.mjs.map +3 -3
  296. package/dist/mjs/evaluator/dependency-nodes/cell-value-node.mjs +4 -1
  297. package/dist/mjs/evaluator/dependency-nodes/cell-value-node.mjs.map +3 -3
  298. package/dist/mjs/evaluator/dependency-nodes/empty-cell-evaluation-node.mjs +17 -3
  299. package/dist/mjs/evaluator/dependency-nodes/empty-cell-evaluation-node.mjs.map +3 -3
  300. package/dist/mjs/evaluator/dependency-nodes/resource-dependency-node.mjs +21 -0
  301. package/dist/mjs/evaluator/dependency-nodes/resource-dependency-node.mjs.map +10 -0
  302. package/dist/mjs/evaluator/dependency-nodes/virtual-cell-value-node.mjs +4 -1
  303. package/dist/mjs/evaluator/dependency-nodes/virtual-cell-value-node.mjs.map +3 -3
  304. package/dist/mjs/evaluator/formula-evaluator.mjs +42 -4
  305. package/dist/mjs/evaluator/formula-evaluator.mjs.map +3 -3
  306. package/dist/mjs/evaluator/range-evaluation-node.mjs +17 -3
  307. package/dist/mjs/evaluator/range-evaluation-node.mjs.map +3 -3
  308. package/dist/mjs/functions/lookup/match/match.mjs +3 -2
  309. package/dist/mjs/functions/lookup/match/match.mjs.map +3 -3
  310. package/dist/mjs/functions/text/concatenate/concatenate.mjs +3 -1
  311. package/dist/mjs/functions/text/concatenate/concatenate.mjs.map +3 -3
  312. package/dist/mjs/package.json +1 -1
  313. package/dist/types/core/commands/content-commands.d.ts +31 -1
  314. package/dist/types/core/commands/named-expression-commands.d.ts +16 -1
  315. package/dist/types/core/commands/structure-commands.d.ts +24 -1
  316. package/dist/types/core/commands/table-commands.d.ts +16 -1
  317. package/dist/types/core/commands/types.d.ts +25 -1
  318. package/dist/types/core/engine-snapshot.d.ts +138 -0
  319. package/dist/types/core/engine.d.ts +1 -0
  320. package/dist/types/core/managers/cache-manager.d.ts +9 -0
  321. package/dist/types/core/managers/dependency-manager.d.ts +56 -1
  322. package/dist/types/core/managers/dependency-node.d.ts +2 -1
  323. package/dist/types/core/managers/evaluation-manager.d.ts +21 -1
  324. package/dist/types/core/managers/frontier-dependency-manager.d.ts +12 -2
  325. package/dist/types/core/managers/named-expression-manager.d.ts +17 -1
  326. package/dist/types/core/managers/reference-manager.d.ts +3 -0
  327. package/dist/types/core/managers/style-manager.d.ts +3 -0
  328. package/dist/types/core/managers/table-manager.d.ts +3 -0
  329. package/dist/types/core/managers/workbook-manager.d.ts +4 -1
  330. package/dist/types/core/resource-keys.d.ts +14 -0
  331. package/dist/types/evaluator/dependency-nodes/base-eval-node.d.ts +5 -0
  332. package/dist/types/evaluator/dependency-nodes/cell-value-node.d.ts +1 -0
  333. package/dist/types/evaluator/dependency-nodes/empty-cell-evaluation-node.d.ts +8 -1
  334. package/dist/types/evaluator/dependency-nodes/resource-dependency-node.d.ts +8 -0
  335. package/dist/types/evaluator/dependency-nodes/virtual-cell-value-node.d.ts +1 -0
  336. package/dist/types/evaluator/range-evaluation-node.d.ts +8 -1
  337. package/package.json +6 -2
@@ -1,9 +1,17 @@
1
1
  // src/core/managers/dependency-manager.ts
2
+ import {
3
+ getAstNodeSnapshotId
4
+ } from "../engine-snapshot.mjs";
2
5
  import {
3
6
  eligibleKeysForContext,
4
7
  getContextDependencyKey
5
8
  } from "../../evaluator/evaluation-context.mjs";
6
- import { cellAddressToKey, isCellInRange, keyToCellAddress } from "../utils.mjs";
9
+ import {
10
+ cellAddressToKey,
11
+ checkRangeIntersection,
12
+ isCellInRange,
13
+ keyToCellAddress
14
+ } from "../utils.mjs";
7
15
  import { AstEvaluationNode } from "../../evaluator/dependency-nodes/ast-evaluation-node.mjs";
8
16
  import { CellValueNode } from "../../evaluator/dependency-nodes/cell-value-node.mjs";
9
17
  import { EmptyCellEvaluationNode } from "../../evaluator/dependency-nodes/empty-cell-evaluation-node.mjs";
@@ -15,6 +23,7 @@ import {
15
23
  } from "../../parser/formatter.mjs";
16
24
  import { VirtualCellValueNode } from "../../evaluator/dependency-nodes/virtual-cell-value-node.mjs";
17
25
  import { parseFormula } from "../../parser/parser.mjs";
26
+ import { ResourceDependencyNode } from "../../evaluator/dependency-nodes/resource-dependency-node.mjs";
18
27
 
19
28
  class DependencyManager {
20
29
  cacheManager;
@@ -25,10 +34,175 @@ class DependencyManager {
25
34
  virtualCellValueNodes = new Map;
26
35
  _spilledValues = new Map;
27
36
  ranges = new Map;
37
+ resourceNodes = new Map;
38
+ hardDependents = new Map;
39
+ frontierDependents = new Map;
40
+ registeredDependencies = new Map;
41
+ coverageWatchersBySheet = new Map;
42
+ frontierWatchersBySheet = new Map;
28
43
  constructor(cacheManager, workbookManager) {
29
44
  this.cacheManager = cacheManager;
30
45
  this.workbookManager = workbookManager;
31
46
  }
47
+ getSheetWatcherKey(address) {
48
+ return `${address.workbookName}:${address.sheetName}`;
49
+ }
50
+ addReverseEdge(map, dependency, dependent) {
51
+ const dependents = map.get(dependency) ?? new Set;
52
+ dependents.add(dependent);
53
+ map.set(dependency, dependents);
54
+ }
55
+ removeReverseEdge(map, dependency, dependent) {
56
+ const dependents = map.get(dependency);
57
+ if (!dependents) {
58
+ return;
59
+ }
60
+ dependents.delete(dependent);
61
+ if (dependents.size === 0) {
62
+ map.delete(dependency);
63
+ }
64
+ }
65
+ getWatcherRange(node) {
66
+ return node instanceof RangeEvaluationNode ? node.address : node.getFrontierRange();
67
+ }
68
+ addWatcher(map, node) {
69
+ const watcherKey = this.getSheetWatcherKey(this.getWatcherRange(node));
70
+ const watchers = map.get(watcherKey) ?? new Set;
71
+ watchers.add(node);
72
+ map.set(watcherKey, watchers);
73
+ }
74
+ removeWatcher(map, node) {
75
+ const watcherKey = this.getSheetWatcherKey(this.getWatcherRange(node));
76
+ const watchers = map.get(watcherKey);
77
+ if (!watchers) {
78
+ return;
79
+ }
80
+ watchers.delete(node);
81
+ if (watchers.size === 0) {
82
+ map.delete(watcherKey);
83
+ }
84
+ }
85
+ registerWatcherNode(node) {
86
+ this.addWatcher(this.coverageWatchersBySheet, node);
87
+ this.addWatcher(this.frontierWatchersBySheet, node);
88
+ }
89
+ unregisterWatcherNode(node) {
90
+ this.removeWatcher(this.coverageWatchersBySheet, node);
91
+ this.removeWatcher(this.frontierWatchersBySheet, node);
92
+ }
93
+ isWatcherNodeResolved(node) {
94
+ return node instanceof RangeEvaluationNode ? node.result.type !== "awaiting-evaluation" : node.evaluationResult.type !== "awaiting-evaluation";
95
+ }
96
+ getAllPersistentNodes() {
97
+ const astNodes = [];
98
+ for (const astEntries of this.asts.values()) {
99
+ for (const astEntry of astEntries.entries.values()) {
100
+ astNodes.push(astEntry.evalNode);
101
+ }
102
+ }
103
+ return [
104
+ ...this.cellNodes.values(),
105
+ ...this.spillMetaNodes.values(),
106
+ ...this.emptyCells.values(),
107
+ ...this.ranges.values(),
108
+ ...this.resourceNodes.values(),
109
+ ...astNodes
110
+ ];
111
+ }
112
+ getExistingCellValueNode(nodeKey) {
113
+ return this.cellNodes.get(nodeKey);
114
+ }
115
+ getExistingSpillMetaNode(nodeKey) {
116
+ return this.spillMetaNodes.get(nodeKey);
117
+ }
118
+ getExistingEmptyCellNode(nodeKey) {
119
+ return this.emptyCells.get(nodeKey);
120
+ }
121
+ collectExistingNodesForCell(address) {
122
+ const baseKey = cellAddressToKey(address);
123
+ const nodes = [
124
+ this.getExistingCellValueNode(baseKey),
125
+ this.getExistingEmptyCellNode(baseKey.replace(/^cell-value:/, "empty:")),
126
+ this.getExistingSpillMetaNode(baseKey.replace(/^cell-value:/, "spill-meta:"))
127
+ ];
128
+ return nodes.filter((node) => node !== undefined);
129
+ }
130
+ collectSpillOriginsAffectingCell(address) {
131
+ const affected = new Set;
132
+ for (const [spillOriginKey, spilledValue] of this._spilledValues.entries()) {
133
+ if (spilledValue.origin.workbookName !== address.workbookName || spilledValue.origin.sheetName !== address.sheetName) {
134
+ continue;
135
+ }
136
+ const isOriginCell = spilledValue.origin.colIndex === address.colIndex && spilledValue.origin.rowIndex === address.rowIndex;
137
+ if (isOriginCell || !isCellInRange(address, spilledValue.spillOnto)) {
138
+ continue;
139
+ }
140
+ const cellValueNode = this.cellNodes.get(`cell-value:${spillOriginKey}`);
141
+ if (cellValueNode) {
142
+ affected.add(cellValueNode);
143
+ }
144
+ const spillMetaNode = this.spillMetaNodes.get(`spill-meta:${spillOriginKey}`);
145
+ if (spillMetaNode) {
146
+ affected.add(spillMetaNode);
147
+ }
148
+ }
149
+ return affected;
150
+ }
151
+ getLinkedSpillMetaNode(node) {
152
+ if (node instanceof SpillMetaNode) {
153
+ return node;
154
+ }
155
+ return this.spillMetaNodes.get(node.key.replace(/^cell-value:/, "spill-meta:"));
156
+ }
157
+ getLinkedCellValueNode(node) {
158
+ if (node instanceof CellValueNode) {
159
+ return node;
160
+ }
161
+ return this.cellNodes.get(node.key.replace(/^spill-meta:/, "cell-value:"));
162
+ }
163
+ registerNode(node) {
164
+ this.unregisterNode(node);
165
+ const hardDependencies = new Set(node.getDependencies());
166
+ const frontierDependencies = node instanceof RangeEvaluationNode || node instanceof EmptyCellEvaluationNode ? new Set(node.getFrontierDependencies()) : new Set;
167
+ this.registeredDependencies.set(node, {
168
+ hard: hardDependencies,
169
+ frontier: frontierDependencies
170
+ });
171
+ for (const dependency of hardDependencies) {
172
+ this.addReverseEdge(this.hardDependents, dependency, node);
173
+ }
174
+ for (const dependency of frontierDependencies) {
175
+ this.addReverseEdge(this.frontierDependents, dependency, node);
176
+ }
177
+ if ((node instanceof RangeEvaluationNode || node instanceof EmptyCellEvaluationNode) && this.isWatcherNodeResolved(node)) {
178
+ this.registerWatcherNode(node);
179
+ }
180
+ }
181
+ unregisterNode(node) {
182
+ const registration = this.registeredDependencies.get(node);
183
+ if (registration) {
184
+ for (const dependency of registration.hard) {
185
+ this.removeReverseEdge(this.hardDependents, dependency, node);
186
+ }
187
+ for (const dependency of registration.frontier) {
188
+ this.removeReverseEdge(this.frontierDependents, dependency, node);
189
+ }
190
+ this.registeredDependencies.delete(node);
191
+ }
192
+ if (node instanceof RangeEvaluationNode || node instanceof EmptyCellEvaluationNode) {
193
+ this.unregisterWatcherNode(node);
194
+ }
195
+ }
196
+ rebuildRuntimeIndexes() {
197
+ this.hardDependents.clear();
198
+ this.frontierDependents.clear();
199
+ this.registeredDependencies.clear();
200
+ this.coverageWatchersBySheet.clear();
201
+ this.frontierWatchersBySheet.clear();
202
+ for (const node of this.getAllPersistentNodes()) {
203
+ this.registerNode(node);
204
+ }
205
+ }
32
206
  get spilledValues() {
33
207
  return this._spilledValues.values();
34
208
  }
@@ -82,7 +256,272 @@ class DependencyManager {
82
256
  this.asts.clear();
83
257
  this.spillMetaNodes.clear();
84
258
  this.ranges.clear();
259
+ this.resourceNodes.clear();
85
260
  this._spilledValues.clear();
261
+ this.hardDependents.clear();
262
+ this.frontierDependents.clear();
263
+ this.registeredDependencies.clear();
264
+ this.coverageWatchersBySheet.clear();
265
+ this.frontierWatchersBySheet.clear();
266
+ }
267
+ toSnapshot(evaluationManager) {
268
+ const isNodeSnapshotEligible = (node) => {
269
+ if (node instanceof ResourceDependencyNode) {
270
+ return true;
271
+ }
272
+ if (node instanceof RangeEvaluationNode) {
273
+ return node.result.type !== "awaiting-evaluation";
274
+ }
275
+ return node.evaluationResult.type !== "awaiting-evaluation";
276
+ };
277
+ const astNodes = new Set;
278
+ for (const astEntries of this.asts.values()) {
279
+ for (const { evalNode } of astEntries.entries.values()) {
280
+ if (isNodeSnapshotEligible(evalNode)) {
281
+ astNodes.add(evalNode);
282
+ }
283
+ }
284
+ }
285
+ const resolvedNodes = [
286
+ ...Array.from(this.cellNodes.values()).filter(isNodeSnapshotEligible),
287
+ ...Array.from(this.spillMetaNodes.values()).filter(isNodeSnapshotEligible),
288
+ ...Array.from(this.emptyCells.values()).filter(isNodeSnapshotEligible),
289
+ ...Array.from(this.ranges.values()).filter(isNodeSnapshotEligible),
290
+ ...Array.from(this.resourceNodes.values()).filter(isNodeSnapshotEligible),
291
+ ...Array.from(astNodes.values())
292
+ ];
293
+ const allNodeSnapshotIds = new Map;
294
+ for (const node of resolvedNodes) {
295
+ if (node instanceof AstEvaluationNode) {
296
+ allNodeSnapshotIds.set(node, getAstNodeSnapshotId(node));
297
+ } else {
298
+ allNodeSnapshotIds.set(node, node.key);
299
+ }
300
+ }
301
+ const getAllNodeSnapshotId = (node) => {
302
+ const snapshotId = allNodeSnapshotIds.get(node);
303
+ if (!snapshotId) {
304
+ throw new Error(`Missing snapshot id for dependency node ${node.key}`);
305
+ }
306
+ return snapshotId;
307
+ };
308
+ const nodeSnapshots = [];
309
+ const includedSnapshotIds = new Set;
310
+ for (const node of resolvedNodes) {
311
+ const snapshot = this.serializeNodeSnapshot(node, evaluationManager, getAllNodeSnapshotId, allNodeSnapshotIds);
312
+ if (!snapshot) {
313
+ continue;
314
+ }
315
+ includedSnapshotIds.add(snapshot.snapshotId);
316
+ nodeSnapshots.push(snapshot);
317
+ }
318
+ const filteredNodeSnapshots = nodeSnapshots.map((snapshot) => {
319
+ const dependencies = snapshot.dependencies.filter((dependency2) => includedSnapshotIds.has(dependency2));
320
+ if (snapshot.kind === "cell-value") {
321
+ return {
322
+ ...snapshot,
323
+ dependencies,
324
+ spillMetaSnapshotId: snapshot.spillMetaSnapshotId && includedSnapshotIds.has(snapshot.spillMetaSnapshotId) ? snapshot.spillMetaSnapshotId : undefined
325
+ };
326
+ }
327
+ return {
328
+ ...snapshot,
329
+ dependencies
330
+ };
331
+ });
332
+ const dependency = {
333
+ nodes: filteredNodeSnapshots,
334
+ spilledValues: Array.from(this._spilledValues.entries())
335
+ };
336
+ const cache = this.cacheManager.toSnapshot((node) => {
337
+ const snapshotId = allNodeSnapshotIds.get(node);
338
+ if (!snapshotId || !includedSnapshotIds.has(snapshotId)) {
339
+ return;
340
+ }
341
+ return snapshotId;
342
+ });
343
+ return { dependency, cache };
344
+ }
345
+ restoreFromSnapshot(snapshots, evaluationManager) {
346
+ this.clearEvaluationCache();
347
+ const nodesBySnapshotId = new Map;
348
+ for (const snapshot of snapshots.dependency.nodes) {
349
+ const node = this.createNodeFromSnapshot(snapshot);
350
+ nodesBySnapshotId.set(snapshot.snapshotId, node);
351
+ }
352
+ const resolveNodeSnapshotId = (snapshotId) => nodesBySnapshotId.get(snapshotId);
353
+ const resolveRequiredNodeSnapshotId = (snapshotId) => {
354
+ const node = resolveNodeSnapshotId(snapshotId);
355
+ if (!node) {
356
+ throw new Error(`Unknown node snapshot id: ${snapshotId}`);
357
+ }
358
+ return node;
359
+ };
360
+ for (const snapshot of snapshots.dependency.nodes) {
361
+ const dependencies = new Set(snapshot.dependencies.map(resolveNodeSnapshotId).filter((node2) => node2 !== undefined));
362
+ if (snapshot.kind === "cell-value") {
363
+ const node2 = nodesBySnapshotId.get(snapshot.snapshotId);
364
+ node2.restoreResolvedSnapshot({
365
+ dependencies,
366
+ evaluationResult: evaluationManager.deserializeSingleEvaluationResultSnapshot(snapshot.evaluationResult, resolveRequiredNodeSnapshotId)
367
+ });
368
+ if (snapshot.spillMetaSnapshotId) {
369
+ const spillMetaNode = resolveNodeSnapshotId(snapshot.spillMetaSnapshotId);
370
+ if (spillMetaNode instanceof SpillMetaNode) {
371
+ node2.setSpillMetaNode(spillMetaNode);
372
+ }
373
+ }
374
+ continue;
375
+ }
376
+ if (snapshot.kind === "spill-meta") {
377
+ const node2 = nodesBySnapshotId.get(snapshot.snapshotId);
378
+ node2.restoreResolvedSnapshot({
379
+ dependencies,
380
+ evaluationResult: evaluationManager.deserializeSpillMetaEvaluationResultSnapshot(snapshot.evaluationResult, resolveRequiredNodeSnapshotId)
381
+ });
382
+ continue;
383
+ }
384
+ if (snapshot.kind === "empty") {
385
+ const node2 = nodesBySnapshotId.get(snapshot.snapshotId);
386
+ node2.restoreResolvedSnapshot({
387
+ dependencies,
388
+ evaluationResult: evaluationManager.deserializeSingleEvaluationResultSnapshot(snapshot.evaluationResult, resolveRequiredNodeSnapshotId)
389
+ });
390
+ continue;
391
+ }
392
+ if (snapshot.kind === "range") {
393
+ const node2 = nodesBySnapshotId.get(snapshot.snapshotId);
394
+ node2.restoreResolvedSnapshot({
395
+ dependencies,
396
+ result: evaluationManager.deserializeEvaluateAllCellsResultSnapshot(snapshot.result, resolveRequiredNodeSnapshotId)
397
+ });
398
+ continue;
399
+ }
400
+ if (snapshot.kind === "resource") {
401
+ continue;
402
+ }
403
+ const node = nodesBySnapshotId.get(snapshot.snapshotId);
404
+ node.restoreResolvedSnapshot({
405
+ dependencies,
406
+ evaluationResult: evaluationManager.deserializeFunctionEvaluationResultSnapshot(snapshot.evaluationResult, resolveRequiredNodeSnapshotId)
407
+ });
408
+ this.saveAstNode(node, snapshot.contextDependency);
409
+ }
410
+ this._spilledValues = new Map(snapshots.dependency.spilledValues);
411
+ this.rebuildRuntimeIndexes();
412
+ this.cacheManager.restoreFromSnapshot(snapshots.cache, resolveNodeSnapshotId);
413
+ }
414
+ serializeNodeSnapshot(node, evaluationManager, getNodeSnapshotId, allNodeSnapshotIds) {
415
+ const snapshotId = getNodeSnapshotId(node);
416
+ const dependencies = Array.from(node.getDependencies()).map((dependency) => allNodeSnapshotIds.get(dependency)).filter((dependency) => dependency !== undefined);
417
+ if (node instanceof CellValueNode) {
418
+ const evaluationResult2 = evaluationManager.serializeSingleEvaluationResultSnapshot(node.evaluationResult, getNodeSnapshotId);
419
+ if (!evaluationResult2) {
420
+ return;
421
+ }
422
+ return {
423
+ kind: "cell-value",
424
+ snapshotId,
425
+ key: node.key,
426
+ dependencies,
427
+ evaluationResult: evaluationResult2,
428
+ spillMetaSnapshotId: node.spillMeta ? allNodeSnapshotIds.get(node.spillMeta) : undefined
429
+ };
430
+ }
431
+ if (node instanceof SpillMetaNode) {
432
+ const evaluationResult2 = evaluationManager.serializeSpillMetaEvaluationResultSnapshot(node.evaluationResult, {
433
+ sourceNode: node,
434
+ getNodeSnapshotId
435
+ });
436
+ if (!evaluationResult2) {
437
+ return;
438
+ }
439
+ return {
440
+ kind: "spill-meta",
441
+ snapshotId,
442
+ key: node.key,
443
+ dependencies,
444
+ evaluationResult: evaluationResult2
445
+ };
446
+ }
447
+ if (node instanceof EmptyCellEvaluationNode) {
448
+ const evaluationResult2 = evaluationManager.serializeSingleEvaluationResultSnapshot(node.evaluationResult, getNodeSnapshotId);
449
+ if (!evaluationResult2) {
450
+ return;
451
+ }
452
+ return {
453
+ kind: "empty",
454
+ snapshotId,
455
+ key: node.key,
456
+ dependencies,
457
+ evaluationResult: evaluationResult2
458
+ };
459
+ }
460
+ if (node instanceof RangeEvaluationNode) {
461
+ const result = evaluationManager.serializeEvaluateAllCellsResultSnapshot(node.result, getNodeSnapshotId);
462
+ if (!result) {
463
+ return;
464
+ }
465
+ return {
466
+ kind: "range",
467
+ snapshotId,
468
+ key: node.key,
469
+ dependencies,
470
+ result
471
+ };
472
+ }
473
+ if (node instanceof ResourceDependencyNode) {
474
+ return {
475
+ kind: "resource",
476
+ snapshotId,
477
+ key: node.key,
478
+ dependencies
479
+ };
480
+ }
481
+ const evaluationResult = evaluationManager.serializeFunctionEvaluationResultSnapshot(node.evaluationResult, {
482
+ sourceNode: node,
483
+ getNodeSnapshotId
484
+ });
485
+ if (!evaluationResult) {
486
+ return;
487
+ }
488
+ return {
489
+ kind: "ast",
490
+ snapshotId,
491
+ key: node.key,
492
+ dependencies,
493
+ contextDependency: node.getContextDependency(),
494
+ evaluationResult
495
+ };
496
+ }
497
+ createNodeFromSnapshot(snapshot) {
498
+ if (snapshot.kind === "cell-value") {
499
+ const node2 = new CellValueNode(snapshot.key);
500
+ this.cellNodes.set(snapshot.key, node2);
501
+ return node2;
502
+ }
503
+ if (snapshot.kind === "spill-meta") {
504
+ const node2 = new SpillMetaNode(snapshot.key);
505
+ this.spillMetaNodes.set(snapshot.key, node2);
506
+ return node2;
507
+ }
508
+ if (snapshot.kind === "empty") {
509
+ const node2 = new EmptyCellEvaluationNode(snapshot.key, this, this.workbookManager, { skipInitialBuild: true });
510
+ this.emptyCells.set(snapshot.key, node2);
511
+ return node2;
512
+ }
513
+ if (snapshot.kind === "range") {
514
+ const node2 = new RangeEvaluationNode(snapshot.key, this, this.workbookManager, { skipInitialBuild: true });
515
+ this.ranges.set(snapshot.key, node2);
516
+ return node2;
517
+ }
518
+ if (snapshot.kind === "resource") {
519
+ const node2 = new ResourceDependencyNode(snapshot.key);
520
+ this.resourceNodes.set(snapshot.key, node2);
521
+ return node2;
522
+ }
523
+ const node = new AstEvaluationNode(parseFormula(snapshot.key.slice(4)), snapshot.contextDependency);
524
+ return node;
86
525
  }
87
526
  setSpilledValue(nodeKey, spilledValue) {
88
527
  this._spilledValues.set(nodeKey.replace(/^[^:]+:/, ""), spilledValue);
@@ -90,6 +529,9 @@ class DependencyManager {
90
529
  getSpilledValue(nodeKey) {
91
530
  return this._spilledValues.get(nodeKey.replace(/^[^:]+:/, ""));
92
531
  }
532
+ deleteSpilledValue(nodeKey) {
533
+ this._spilledValues.delete(nodeKey.replace(/^[^:]+:/, ""));
534
+ }
93
535
  getEmptyCellNode(nodeKey) {
94
536
  if (!nodeKey.startsWith("empty:")) {
95
537
  throw new Error("Invalid empty cell node key: " + nodeKey);
@@ -123,6 +565,14 @@ class DependencyManager {
123
565
  }
124
566
  return this.cellNodes.get(nodeKey);
125
567
  }
568
+ getResourceNode(resourceKey) {
569
+ if (!this.resourceNodes.has(resourceKey)) {
570
+ const node = new ResourceDependencyNode(resourceKey);
571
+ this.resourceNodes.set(resourceKey, node);
572
+ return node;
573
+ }
574
+ return this.resourceNodes.get(resourceKey);
575
+ }
126
576
  getCellValueOrEmptyCellNode(nodeKey) {
127
577
  const cellAddress = keyToCellAddress(nodeKey);
128
578
  const emptyKey = nodeKey.replace(/^[^:]+:/, "empty:");
@@ -209,6 +659,241 @@ class DependencyManager {
209
659
  });
210
660
  }
211
661
  }
662
+ isFiniteEndAfter(value, end) {
663
+ return end.type === "infinity" || value < end.value;
664
+ }
665
+ doesAddressAffectWatcherFrontier(address, watcher) {
666
+ const watcherRange = this.getWatcherRange(watcher).range;
667
+ const rowWithinRange = address.rowIndex >= watcherRange.start.row && (watcherRange.end.row.type === "infinity" || address.rowIndex <= watcherRange.end.row.value);
668
+ const colWithinRange = address.colIndex >= watcherRange.start.col && (watcherRange.end.col.type === "infinity" || address.colIndex <= watcherRange.end.col.value);
669
+ const canReachFurtherRows = this.isFiniteEndAfter(address.rowIndex, watcherRange.end.row);
670
+ const canReachFurtherCols = this.isFiniteEndAfter(address.colIndex, watcherRange.end.col);
671
+ return rowWithinRange && canReachFurtherCols || colWithinRange && canReachFurtherRows || canReachFurtherRows && canReachFurtherCols;
672
+ }
673
+ collectCoverageWatchers(address) {
674
+ const watchers = this.coverageWatchersBySheet.get(this.getSheetWatcherKey(address)) ?? new Set;
675
+ const affected = new Set;
676
+ for (const watcher of watchers) {
677
+ if (isCellInRange(address, this.getWatcherRange(watcher).range)) {
678
+ affected.add(watcher);
679
+ }
680
+ }
681
+ return affected;
682
+ }
683
+ collectFrontierWatchers(address) {
684
+ const watchers = this.frontierWatchersBySheet.get(this.getSheetWatcherKey(address)) ?? new Set;
685
+ const affected = new Set;
686
+ for (const watcher of watchers) {
687
+ if (this.doesAddressAffectWatcherFrontier(address, watcher)) {
688
+ affected.add(watcher);
689
+ }
690
+ }
691
+ return affected;
692
+ }
693
+ collectWatchersIntersectingRange(address) {
694
+ const watchers = this.coverageWatchersBySheet.get(this.getSheetWatcherKey(address)) ?? new Set;
695
+ const affected = new Set;
696
+ for (const watcher of watchers) {
697
+ if (checkRangeIntersection(address.range, this.getWatcherRange(watcher).range)) {
698
+ affected.add(watcher);
699
+ }
700
+ }
701
+ return affected;
702
+ }
703
+ getNodeDependents(node) {
704
+ return (this.hardDependents.get(node) ?? new Set).union(this.frontierDependents.get(node) ?? new Set);
705
+ }
706
+ collectInvalidationExtras(node) {
707
+ const extras = new Set;
708
+ if (node instanceof CellValueNode || node instanceof SpillMetaNode) {
709
+ const spillMetaNode = this.getLinkedSpillMetaNode(node);
710
+ if (spillMetaNode) {
711
+ extras.add(spillMetaNode);
712
+ }
713
+ const cellNode = this.getLinkedCellValueNode(node);
714
+ if (cellNode) {
715
+ extras.add(cellNode);
716
+ }
717
+ const spill = this.getSpilledValue(node.key);
718
+ if (spill) {
719
+ for (const watcher of this.collectWatchersIntersectingRange({
720
+ workbookName: spill.origin.workbookName,
721
+ sheetName: spill.origin.sheetName,
722
+ range: spill.spillOnto
723
+ })) {
724
+ extras.add(watcher);
725
+ }
726
+ }
727
+ const cellAddress = node.cellAddress;
728
+ for (const watcher of this.collectCoverageWatchers(cellAddress)) {
729
+ extras.add(watcher);
730
+ }
731
+ for (const watcher of this.collectFrontierWatchers(cellAddress)) {
732
+ extras.add(watcher);
733
+ }
734
+ }
735
+ return extras;
736
+ }
737
+ invalidateNodeState(node, invalidatedKeys) {
738
+ this.unregisterNode(node);
739
+ invalidatedKeys.add(node.key);
740
+ if (node instanceof CellValueNode) {
741
+ node.clearSpillMetaNode();
742
+ this.deleteSpilledValue(node.key);
743
+ node.invalidate();
744
+ return;
745
+ }
746
+ if (node instanceof SpillMetaNode) {
747
+ this.deleteSpilledValue(node.key);
748
+ this.getLinkedCellValueNode(node)?.clearSpillMetaNode();
749
+ node.invalidate();
750
+ return;
751
+ }
752
+ if (node instanceof EmptyCellEvaluationNode || node instanceof RangeEvaluationNode || node instanceof AstEvaluationNode) {
753
+ node.invalidate();
754
+ return;
755
+ }
756
+ if (node instanceof ResourceDependencyNode) {
757
+ return;
758
+ }
759
+ }
760
+ isResourceNodeInRemovedScope(resourceKey, scope) {
761
+ if (scope.type === "workbook") {
762
+ return resourceKey === `resource:workbook:${scope.workbookName}` || resourceKey.startsWith(`resource:sheet:${scope.workbookName}:`) || resourceKey.startsWith(`resource:table:${scope.workbookName}:`) || resourceKey.startsWith(`resource:named:workbook:${scope.workbookName}:`) || resourceKey.startsWith(`resource:named:sheet:${scope.workbookName}:`);
763
+ }
764
+ return resourceKey === `resource:sheet:${scope.workbookName}:${scope.sheetName}` || resourceKey.startsWith(`resource:named:sheet:${scope.workbookName}:${scope.sheetName}:`);
765
+ }
766
+ isNodeInRemovedScope(node, scope) {
767
+ if (node instanceof ResourceDependencyNode) {
768
+ return this.isResourceNodeInRemovedScope(node.key, scope);
769
+ }
770
+ if (node instanceof AstEvaluationNode) {
771
+ const contextDependency = node.getContextDependency();
772
+ if (scope.type === "workbook") {
773
+ return contextDependency.workbookName === scope.workbookName;
774
+ }
775
+ return contextDependency.workbookName === scope.workbookName && contextDependency.sheetName === scope.sheetName;
776
+ }
777
+ const workbookName = node instanceof RangeEvaluationNode ? node.address.workbookName : node.cellAddress.workbookName;
778
+ const sheetName = node instanceof RangeEvaluationNode ? node.address.sheetName : node.cellAddress.sheetName;
779
+ if (scope.type === "workbook") {
780
+ return workbookName === scope.workbookName;
781
+ }
782
+ return workbookName === scope.workbookName && sheetName === scope.sheetName;
783
+ }
784
+ collectNodesForRemovedScopes(removedScopes) {
785
+ const affected = new Set;
786
+ for (const node of this.getAllPersistentNodes()) {
787
+ if (removedScopes.some((scope) => this.isNodeInRemovedScope(node, scope))) {
788
+ affected.add(node);
789
+ }
790
+ }
791
+ return affected;
792
+ }
793
+ purgeRemovedScopes(removedScopes) {
794
+ const shouldRemoveAddress = (address) => removedScopes.some((scope) => scope.type === "workbook" ? address.workbookName === scope.workbookName : address.workbookName === scope.workbookName && address.sheetName === scope.sheetName);
795
+ for (const [key, node] of Array.from(this.cellNodes.entries())) {
796
+ if (shouldRemoveAddress(node.cellAddress)) {
797
+ this.unregisterNode(node);
798
+ this.cellNodes.delete(key);
799
+ }
800
+ }
801
+ for (const [key, node] of Array.from(this.spillMetaNodes.entries())) {
802
+ if (shouldRemoveAddress(node.cellAddress)) {
803
+ this.unregisterNode(node);
804
+ this.spillMetaNodes.delete(key);
805
+ }
806
+ }
807
+ for (const [key, node] of Array.from(this.emptyCells.entries())) {
808
+ if (shouldRemoveAddress(node.cellAddress)) {
809
+ this.unregisterNode(node);
810
+ this.emptyCells.delete(key);
811
+ }
812
+ }
813
+ for (const [key, node] of Array.from(this.ranges.entries())) {
814
+ if (shouldRemoveAddress({
815
+ workbookName: node.address.workbookName,
816
+ sheetName: node.address.sheetName
817
+ })) {
818
+ this.unregisterNode(node);
819
+ this.ranges.delete(key);
820
+ }
821
+ }
822
+ for (const [key, node] of Array.from(this.resourceNodes.entries())) {
823
+ if (removedScopes.some((scope) => this.isResourceNodeInRemovedScope(key, scope))) {
824
+ this.unregisterNode(node);
825
+ this.resourceNodes.delete(key);
826
+ }
827
+ }
828
+ for (const [astKey, astEntries] of Array.from(this.asts.entries())) {
829
+ for (const [contextKey, astEntry] of Array.from(astEntries.entries.entries())) {
830
+ if (removedScopes.some((scope) => this.isNodeInRemovedScope(astEntry.evalNode, scope))) {
831
+ this.unregisterNode(astEntry.evalNode);
832
+ astEntries.entries.delete(contextKey);
833
+ }
834
+ }
835
+ if (astEntries.entries.size === 0) {
836
+ this.asts.delete(astKey);
837
+ }
838
+ }
839
+ for (const [spillOriginKey, spilledValue] of Array.from(this._spilledValues.entries())) {
840
+ if (shouldRemoveAddress({
841
+ workbookName: spilledValue.origin.workbookName,
842
+ sheetName: spilledValue.origin.sheetName
843
+ })) {
844
+ this._spilledValues.delete(spillOriginKey);
845
+ }
846
+ }
847
+ }
848
+ invalidateFromMutation(footprint) {
849
+ const queue = [];
850
+ const visited = new Set;
851
+ const invalidatedNodeKeys = new Set;
852
+ for (const touchedCell of footprint.touchedCells) {
853
+ for (const node of this.collectExistingNodesForCell(touchedCell.address)) {
854
+ queue.push(node);
855
+ }
856
+ for (const node of this.collectSpillOriginsAffectingCell(touchedCell.address)) {
857
+ queue.push(node);
858
+ }
859
+ for (const watcher of this.collectCoverageWatchers(touchedCell.address)) {
860
+ queue.push(watcher);
861
+ }
862
+ for (const watcher of this.collectFrontierWatchers(touchedCell.address)) {
863
+ queue.push(watcher);
864
+ }
865
+ }
866
+ for (const resourceKey of footprint.resourceKeys) {
867
+ const resourceNode = this.resourceNodes.get(resourceKey);
868
+ if (resourceNode) {
869
+ queue.push(resourceNode);
870
+ }
871
+ }
872
+ if (footprint.removedScopes?.length) {
873
+ for (const node of this.collectNodesForRemovedScopes(footprint.removedScopes)) {
874
+ queue.push(node);
875
+ }
876
+ }
877
+ while (queue.length > 0) {
878
+ const node = queue.pop();
879
+ if (!node || visited.has(node)) {
880
+ continue;
881
+ }
882
+ visited.add(node);
883
+ for (const dependent of this.getNodeDependents(node)) {
884
+ queue.push(dependent);
885
+ }
886
+ for (const extra of this.collectInvalidationExtras(node)) {
887
+ queue.push(extra);
888
+ }
889
+ this.invalidateNodeState(node, invalidatedNodeKeys);
890
+ }
891
+ this.cacheManager.deleteEvaluationOrders(invalidatedNodeKeys);
892
+ this.cacheManager.clearSCCCache();
893
+ if (footprint.removedScopes?.length) {
894
+ this.purgeRemovedScopes(footprint.removedScopes);
895
+ }
896
+ }
212
897
  getTransitiveDepsForEvalOrder(node, visited = new Set) {
213
898
  if (visited.has(node)) {
214
899
  return new Set;
@@ -586,4 +1271,4 @@ export {
586
1271
  DependencyManager
587
1272
  };
588
1273
 
589
- //# debugId=E85B3068E2F7410364756E2164756E21
1274
+ //# debugId=BF56F8AB7402F63364756E2164756E21