@ricsam/formula-engine 0.0.16 → 0.0.18

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 (122) hide show
  1. package/dist/cjs/core/api/api-builder.cjs +67 -0
  2. package/dist/cjs/core/api/api-builder.cjs.map +10 -0
  3. package/dist/cjs/core/api/api-helpers.cjs +191 -0
  4. package/dist/cjs/core/api/api-helpers.cjs.map +10 -0
  5. package/dist/cjs/core/api/api.cjs +65 -0
  6. package/dist/cjs/core/api/api.cjs.map +10 -0
  7. package/dist/cjs/core/api/cell-orm.cjs +80 -0
  8. package/dist/cjs/core/api/cell-orm.cjs.map +10 -0
  9. package/dist/cjs/core/api/table-orm.cjs +171 -0
  10. package/dist/cjs/core/api/table-orm.cjs.map +10 -0
  11. package/dist/cjs/core/autofill-utils.cjs +75 -39
  12. package/dist/cjs/core/autofill-utils.cjs.map +3 -3
  13. package/dist/cjs/core/cell-mover.cjs +178 -0
  14. package/dist/cjs/core/cell-mover.cjs.map +10 -0
  15. package/dist/cjs/core/commands/command-executor.cjs +140 -0
  16. package/dist/cjs/core/commands/command-executor.cjs.map +10 -0
  17. package/dist/cjs/core/commands/content-commands.cjs +574 -0
  18. package/dist/cjs/core/commands/content-commands.cjs.map +10 -0
  19. package/dist/cjs/core/commands/index.cjs +95 -0
  20. package/dist/cjs/core/commands/index.cjs.map +10 -0
  21. package/dist/cjs/core/commands/metadata-commands.cjs +150 -0
  22. package/dist/cjs/core/commands/metadata-commands.cjs.map +10 -0
  23. package/dist/cjs/core/commands/named-expression-commands.cjs +238 -0
  24. package/dist/cjs/core/commands/named-expression-commands.cjs.map +10 -0
  25. package/dist/cjs/core/commands/structure-commands.cjs +495 -0
  26. package/dist/cjs/core/commands/structure-commands.cjs.map +10 -0
  27. package/dist/cjs/core/commands/style-commands.cjs +219 -0
  28. package/dist/cjs/core/commands/style-commands.cjs.map +10 -0
  29. package/dist/cjs/core/commands/table-commands.cjs +226 -0
  30. package/dist/cjs/core/commands/table-commands.cjs.map +10 -0
  31. package/dist/cjs/core/commands/types.cjs +72 -0
  32. package/dist/cjs/core/commands/types.cjs.map +10 -0
  33. package/dist/cjs/core/engine.cjs +218 -263
  34. package/dist/cjs/core/engine.cjs.map +3 -3
  35. package/dist/cjs/core/managers/api-schema-manager.cjs +304 -0
  36. package/dist/cjs/core/managers/api-schema-manager.cjs.map +10 -0
  37. package/dist/cjs/core/managers/copy-manager.cjs +336 -82
  38. package/dist/cjs/core/managers/copy-manager.cjs.map +3 -3
  39. package/dist/cjs/core/managers/reference-manager.cjs +124 -0
  40. package/dist/cjs/core/managers/reference-manager.cjs.map +10 -0
  41. package/dist/cjs/core/managers/style-manager.cjs +115 -147
  42. package/dist/cjs/core/managers/style-manager.cjs.map +3 -3
  43. package/dist/cjs/core/managers/workbook-manager.cjs +87 -3
  44. package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
  45. package/dist/cjs/core/types.cjs.map +1 -1
  46. package/dist/cjs/lib.cjs +13 -2
  47. package/dist/cjs/lib.cjs.map +3 -3
  48. package/dist/cjs/package.json +1 -1
  49. package/dist/mjs/core/api/api-builder.mjs +37 -0
  50. package/dist/mjs/core/api/api-builder.mjs.map +10 -0
  51. package/dist/mjs/core/api/api-helpers.mjs +161 -0
  52. package/dist/mjs/core/api/api-helpers.mjs.map +10 -0
  53. package/dist/mjs/core/api/api.mjs +35 -0
  54. package/dist/mjs/core/api/api.mjs.map +10 -0
  55. package/dist/mjs/core/api/cell-orm.mjs +49 -0
  56. package/dist/mjs/core/api/cell-orm.mjs.map +10 -0
  57. package/dist/mjs/core/api/table-orm.mjs +148 -0
  58. package/dist/mjs/core/api/table-orm.mjs.map +10 -0
  59. package/dist/mjs/core/autofill-utils.mjs +75 -39
  60. package/dist/mjs/core/autofill-utils.mjs.map +3 -3
  61. package/dist/mjs/core/cell-mover.mjs +148 -0
  62. package/dist/mjs/core/cell-mover.mjs.map +10 -0
  63. package/dist/mjs/core/commands/command-executor.mjs +109 -0
  64. package/dist/mjs/core/commands/command-executor.mjs.map +10 -0
  65. package/dist/mjs/core/commands/content-commands.mjs +544 -0
  66. package/dist/mjs/core/commands/content-commands.mjs.map +10 -0
  67. package/dist/mjs/core/commands/index.mjs +87 -0
  68. package/dist/mjs/core/commands/index.mjs.map +10 -0
  69. package/dist/mjs/core/commands/metadata-commands.mjs +120 -0
  70. package/dist/mjs/core/commands/metadata-commands.mjs.map +10 -0
  71. package/dist/mjs/core/commands/named-expression-commands.mjs +208 -0
  72. package/dist/mjs/core/commands/named-expression-commands.mjs.map +10 -0
  73. package/dist/mjs/core/commands/structure-commands.mjs +465 -0
  74. package/dist/mjs/core/commands/structure-commands.mjs.map +10 -0
  75. package/dist/mjs/core/commands/style-commands.mjs +189 -0
  76. package/dist/mjs/core/commands/style-commands.mjs.map +10 -0
  77. package/dist/mjs/core/commands/table-commands.mjs +196 -0
  78. package/dist/mjs/core/commands/table-commands.mjs.map +10 -0
  79. package/dist/mjs/core/commands/types.mjs +42 -0
  80. package/dist/mjs/core/commands/types.mjs.map +10 -0
  81. package/dist/mjs/core/engine.mjs +253 -263
  82. package/dist/mjs/core/engine.mjs.map +3 -3
  83. package/dist/mjs/core/managers/api-schema-manager.mjs +274 -0
  84. package/dist/mjs/core/managers/api-schema-manager.mjs.map +10 -0
  85. package/dist/mjs/core/managers/copy-manager.mjs +338 -82
  86. package/dist/mjs/core/managers/copy-manager.mjs.map +3 -3
  87. package/dist/mjs/core/managers/reference-manager.mjs +93 -0
  88. package/dist/mjs/core/managers/reference-manager.mjs.map +10 -0
  89. package/dist/mjs/core/managers/style-manager.mjs +115 -147
  90. package/dist/mjs/core/managers/style-manager.mjs.map +3 -3
  91. package/dist/mjs/core/managers/workbook-manager.mjs +87 -3
  92. package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
  93. package/dist/mjs/core/types.mjs.map +1 -1
  94. package/dist/mjs/lib.mjs +13 -2
  95. package/dist/mjs/lib.mjs.map +3 -3
  96. package/dist/mjs/package.json +1 -1
  97. package/dist/types/core/api/api-builder.d.ts +16 -0
  98. package/dist/types/core/api/api-helpers.d.ts +37 -0
  99. package/dist/types/core/api/api.d.ts +83 -0
  100. package/dist/types/core/api/api.type-test.d.ts +1 -0
  101. package/dist/types/core/api/cell-orm.d.ts +29 -0
  102. package/dist/types/core/api/table-orm.d.ts +46 -0
  103. package/dist/types/core/autofill-utils.d.ts +6 -9
  104. package/dist/types/core/cell-mover.d.ts +63 -0
  105. package/dist/types/core/commands/command-executor.d.ts +83 -0
  106. package/dist/types/core/commands/content-commands.d.ts +142 -0
  107. package/dist/types/core/commands/index.d.ts +16 -0
  108. package/dist/types/core/commands/metadata-commands.d.ts +55 -0
  109. package/dist/types/core/commands/named-expression-commands.d.ts +115 -0
  110. package/dist/types/core/commands/structure-commands.d.ts +132 -0
  111. package/dist/types/core/commands/style-commands.d.ts +76 -0
  112. package/dist/types/core/commands/table-commands.d.ts +104 -0
  113. package/dist/types/core/commands/types.d.ts +114 -0
  114. package/dist/types/core/engine.d.ts +241 -23
  115. package/dist/types/core/managers/api-schema-manager.d.ts +121 -0
  116. package/dist/types/core/managers/copy-manager.d.ts +47 -2
  117. package/dist/types/core/managers/reference-manager.d.ts +54 -0
  118. package/dist/types/core/managers/style-manager.d.ts +6 -6
  119. package/dist/types/core/managers/workbook-manager.d.ts +39 -1
  120. package/dist/types/core/types.d.ts +52 -11
  121. package/dist/types/lib.d.ts +8 -0
  122. package/package.json +1 -1
@@ -81,7 +81,8 @@ class WorkbookManager {
81
81
  }
82
82
  this.workbooks.set(workbookName, {
83
83
  name: workbookName,
84
- sheets: new Map
84
+ sheets: new Map,
85
+ workbookMetadata: undefined
85
86
  });
86
87
  }
87
88
  removeWorkbook(workbookName) {
@@ -163,7 +164,9 @@ class WorkbookManager {
163
164
  const sheet = {
164
165
  name: sheetName,
165
166
  index: workbook.sheets.size,
166
- content: new Map
167
+ content: new Map,
168
+ metadata: new Map,
169
+ sheetMetadata: undefined
167
170
  };
168
171
  if (workbook.sheets.has(sheet.name)) {
169
172
  throw new Error("Sheet already exists");
@@ -235,6 +238,26 @@ class WorkbookManager {
235
238
  update(workbook.sheets);
236
239
  });
237
240
  }
241
+ updateFormulasExcluding(excludeCellsSet, updateCallback) {
242
+ this.workbooks.forEach((workbook, workbookName) => {
243
+ workbook.sheets.forEach((sheet, sheetName) => {
244
+ sheet.content.forEach((cell, key) => {
245
+ if (typeof cell === "string" && cell.startsWith("=")) {
246
+ const { colIndex, rowIndex } = parseCellReference(key);
247
+ const cellKey = `${workbookName}:${sheetName}:${colIndex}:${rowIndex}`;
248
+ if (excludeCellsSet.has(cellKey)) {
249
+ return;
250
+ }
251
+ const formula = cell.slice(1);
252
+ const updatedFormula = updateCallback(formula);
253
+ if (updatedFormula !== formula) {
254
+ sheet.content.set(key, `=${updatedFormula}`);
255
+ }
256
+ }
257
+ });
258
+ });
259
+ });
260
+ }
238
261
  updateFormulasForWorkbook(workbookName, updateCallback) {
239
262
  const workbook = this.workbooks.get(workbookName);
240
263
  if (!workbook) {
@@ -342,6 +365,64 @@ class WorkbookManager {
342
365
  this.addCellToGroups(indexes, address.rowIndex, address.colIndex, adr);
343
366
  }
344
367
  }
368
+ setCellMetadata(address, metadata) {
369
+ const sheet = this.getSheet({
370
+ workbookName: address.workbookName,
371
+ sheetName: address.sheetName
372
+ });
373
+ if (!sheet) {
374
+ throw new SheetNotFoundError(address.sheetName);
375
+ }
376
+ const key = getCellReference(address);
377
+ if (metadata === undefined) {
378
+ sheet.metadata.delete(key);
379
+ } else {
380
+ sheet.metadata.set(key, metadata);
381
+ }
382
+ }
383
+ getCellMetadata(address) {
384
+ const sheet = this.getSheet({
385
+ workbookName: address.workbookName,
386
+ sheetName: address.sheetName
387
+ });
388
+ if (!sheet) {
389
+ return;
390
+ }
391
+ const key = getCellReference(address);
392
+ return sheet.metadata.get(key);
393
+ }
394
+ getSheetMetadataSerialized(opts) {
395
+ const sheet = this.getSheet(opts);
396
+ return sheet?.metadata || new Map;
397
+ }
398
+ setSheetMetadata(opts, metadata) {
399
+ const sheet = this.getSheet(opts);
400
+ if (!sheet) {
401
+ throw new SheetNotFoundError(opts.sheetName);
402
+ }
403
+ sheet.sheetMetadata = metadata;
404
+ }
405
+ getSheetMetadata(opts) {
406
+ const sheet = this.getSheet(opts);
407
+ if (!sheet) {
408
+ return;
409
+ }
410
+ return sheet.sheetMetadata;
411
+ }
412
+ setWorkbookMetadata(workbookName, metadata) {
413
+ const workbook = this.workbooks.get(workbookName);
414
+ if (!workbook) {
415
+ throw new Error(`Workbook "${workbookName}" not found`);
416
+ }
417
+ workbook.workbookMetadata = metadata;
418
+ }
419
+ getWorkbookMetadata(workbookName) {
420
+ const workbook = this.workbooks.get(workbookName);
421
+ if (!workbook) {
422
+ return;
423
+ }
424
+ return workbook.workbookMetadata;
425
+ }
345
426
  setSheetContent(opts, newContent) {
346
427
  const sheet = this.getSheet(opts);
347
428
  if (!sheet) {
@@ -368,11 +449,14 @@ class WorkbookManager {
368
449
  throw new SheetNotFoundError(address.sheetName);
369
450
  }
370
451
  const newContent = new Map(sheet.content);
452
+ const newMetadata = new Map(sheet.metadata);
371
453
  for (const cellAddress of this.iterateCellsInRange(address)) {
372
454
  const cellRef = getCellReference(cellAddress);
373
455
  newContent.delete(cellRef);
456
+ newMetadata.delete(cellRef);
374
457
  }
375
458
  this.setSheetContent(address, newContent);
459
+ sheet.metadata = newMetadata;
376
460
  }
377
461
  *iterateCellsInRange(address) {
378
462
  const sheet = this.getSheet(address);
@@ -461,4 +545,4 @@ export {
461
545
  IndexEntryBinarySearch
462
546
  };
463
547
 
464
- //# debugId=D632FC8B4BBFB4AF64756E2164756E21
548
+ //# debugId=495D50D4550C2C5B64756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/managers/workbook-manager.ts"],
4
4
  "sourcesContent": [
5
- "import {\n FormulaError,\n type CellAddress,\n type FiniteSpreadsheetRange,\n type LocalCellAddress,\n type SerializedCellValue,\n type Sheet,\n type SpreadsheetRange,\n type Workbook,\n} from \"../types.mjs\";\nimport { getCellReference, parseCellReference } from \"../utils.mjs\";\n\nimport type { RangeAddress } from \"../types.mjs\";\nimport { buildRangeEvalOrder } from \"./range-eval-order-builder.mjs\";\nimport {\n EvaluationError,\n SheetNotFoundError,\n WorkbookNotFoundError,\n} from \"../../evaluator/evaluation-error.mjs\";\nimport { normalizeSerializedCellValue } from \"../../parser/formatter.mjs\";\n\ninterface IndexEntry {\n number: number;\n key: string;\n}\n\nexport interface SheetIndexes {\n // lookup maps - cells grouped by row/column\n rowGroups: Map<number, IndexEntry[]>; // row number -> cells in that row (sorted by col)\n colGroups: Map<number, IndexEntry[]>; // col number -> cells in that col (sorted by row)\n\n // Sorted flat indexes - for finding cells before a given row/col\n cellsSortedByRow: IndexEntry[];\n cellsSortedByCol: IndexEntry[];\n}\n\n/**\n * Utility class for binary search operations on IndexEntry arrays\n */\nexport class IndexEntryBinarySearch {\n /**\n * Find the insertion point for a number in a sorted IndexEntry array\n * Returns the index where the number should be inserted to maintain sort order\n */\n static findInsertionPoint(entries: IndexEntry[], target: number): number {\n let left = 0;\n let right = entries.length;\n\n while (left < right) {\n const mid = Math.floor((left + right) / 2);\n const midEntry = entries[mid];\n if (midEntry && midEntry.number < target) {\n left = mid + 1;\n } else {\n right = mid;\n }\n }\n\n return left;\n }\n\n /**\n * Find the first element >= target\n * Returns the index of the first element, or -1 if not found\n */\n static findFirstGreaterOrEqual(\n entries: IndexEntry[],\n target: number\n ): number {\n if (entries.length === 0) return -1;\n\n let left = 0;\n let right = entries.length - 1;\n let result = -1;\n\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n const midEntry = entries[mid];\n if (midEntry && midEntry.number >= target) {\n result = mid;\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n }\n\n return result;\n }\n\n /**\n * Find the rightmost position where we could insert a target value\n * Useful for finding elements that come before a target\n */\n static findRightmostInsertionPoint(\n entries: IndexEntry[],\n target: number\n ): number {\n return IndexEntryBinarySearch.findInsertionPoint(entries, target);\n }\n}\n\nexport class WorkbookManager {\n private workbooks: Map<string, Workbook> = new Map();\n\n // Map from \"workbookName|sheetName\" to indexes\n private sheetIndexes: Map<string, SheetIndexes> = new Map();\n\n /**\n * Generate a key for the sheet indexes map\n */\n private getSheetIndexKey(workbookName: string, sheetName: string): string {\n return `${workbookName}|${sheetName}`;\n }\n\n /**\n * Get or create indexes for a sheet\n */\n public getSheetIndexes(opts: {\n workbookName: string;\n sheetName: string;\n }): SheetIndexes {\n const key = this.getSheetIndexKey(opts.workbookName, opts.sheetName);\n let indexes = this.sheetIndexes.get(key);\n\n if (!indexes) {\n indexes = {\n rowGroups: new Map(),\n colGroups: new Map(),\n cellsSortedByRow: [],\n cellsSortedByCol: [],\n };\n this.sheetIndexes.set(key, indexes);\n }\n\n return indexes;\n }\n\n getSheets(workbookName: string): Map<string, Sheet> {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n return workbook.sheets;\n }\n\n getWorkbooks(): Map<string, Workbook> {\n return this.workbooks;\n }\n\n addWorkbook(workbookName: string): void {\n if (this.workbooks.has(workbookName)) {\n throw new Error(\"Workbook already exists\");\n }\n this.workbooks.set(workbookName, {\n name: workbookName,\n sheets: new Map(),\n });\n }\n\n removeWorkbook(workbookName: string): void {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n // Clean up indexes for all sheets in this workbook\n for (const sheetName of workbook.sheets.keys()) {\n const key = this.getSheetIndexKey(workbookName, sheetName);\n this.sheetIndexes.delete(key);\n }\n\n this.workbooks.delete(workbookName);\n }\n\n isContentEmpty(content: SerializedCellValue): boolean {\n return content === \"\" || content === undefined;\n }\n\n renameWorkbook(opts: {\n workbookName: string;\n newWorkbookName: string;\n }): void {\n const workbook = this.workbooks.get(opts.workbookName);\n if (!workbook) {\n throw new Error(\"Workbook not found\");\n }\n\n // Update indexes for all sheets in this workbook\n for (const sheetName of workbook.sheets.keys()) {\n const oldKey = this.getSheetIndexKey(opts.workbookName, sheetName);\n const newKey = this.getSheetIndexKey(opts.newWorkbookName, sheetName);\n const indexes = this.sheetIndexes.get(oldKey);\n if (indexes) {\n this.sheetIndexes.set(newKey, indexes);\n this.sheetIndexes.delete(oldKey);\n }\n }\n\n this.workbooks.set(opts.newWorkbookName, workbook);\n this.workbooks.delete(opts.workbookName);\n workbook.name = opts.newWorkbookName;\n }\n\n resetWorkbooks(workbooks: Map<string, Workbook>): void {\n this.workbooks.clear();\n this.sheetIndexes.clear();\n\n workbooks.forEach((workbook, workbookName) => {\n this.workbooks.set(workbookName, workbook);\n workbook.sheets.forEach((sheet) => {\n // Initialize indexes for this sheet\n const indexes = this.getSheetIndexes({\n workbookName,\n sheetName: sheet.name,\n });\n indexes.rowGroups.clear();\n indexes.colGroups.clear();\n indexes.cellsSortedByRow = [];\n indexes.cellsSortedByCol = [];\n\n sheet.content.forEach((value, key) => {\n this.setCellContent(\n {\n workbookName,\n sheetName: sheet.name,\n colIndex: parseCellReference(key).colIndex,\n rowIndex: parseCellReference(key).rowIndex,\n },\n value,\n {\n sheet,\n buildingFromScratch: true,\n }\n );\n });\n });\n });\n }\n\n getSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Sheet | undefined {\n const workbook = this.workbooks.get(workbookName);\n const sheet = workbook?.sheets.get(sheetName);\n return sheet;\n }\n\n addSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Sheet {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = {\n name: sheetName,\n index: workbook.sheets.size,\n content: new Map(),\n };\n\n if (workbook.sheets.has(sheet.name)) {\n throw new Error(\"Sheet already exists\");\n }\n\n workbook.sheets.set(sheetName, sheet);\n\n // Initialize empty indexes for this sheet\n this.getSheetIndexes({ workbookName, sheetName });\n\n return sheet;\n }\n\n removeSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Sheet {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = workbook.sheets.get(sheetName);\n if (!sheet) {\n throw new Error(\"Sheet not found\");\n }\n\n // Remove the sheet\n workbook.sheets.delete(sheetName);\n\n // Clean up indexes for this sheet\n const key = this.getSheetIndexKey(workbookName, sheetName);\n this.sheetIndexes.delete(key);\n\n return sheet;\n }\n\n renameSheet({\n workbookName,\n sheetName,\n newSheetName,\n }: {\n workbookName: string;\n sheetName: string;\n newSheetName: string;\n }): Sheet {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = workbook.sheets.get(sheetName);\n if (!sheet) {\n throw new SheetNotFoundError(sheetName);\n }\n\n if (workbook.sheets.has(newSheetName)) {\n throw new Error(\"Sheet with new name already exists\");\n }\n\n // Update sheet name\n sheet.name = newSheetName;\n\n // Update sheets map\n workbook.sheets.set(newSheetName, sheet);\n workbook.sheets.delete(sheetName);\n\n // Move indexes to new key\n const oldKey = this.getSheetIndexKey(workbookName, sheetName);\n const newKey = this.getSheetIndexKey(workbookName, newSheetName);\n const indexes = this.sheetIndexes.get(oldKey);\n if (indexes) {\n this.sheetIndexes.set(newKey, indexes);\n this.sheetIndexes.delete(oldKey);\n }\n\n return sheet;\n }\n\n updateAllFormulas(updateCallback: (formula: string) => string): void {\n const update = (map: Map<string, Sheet>) => {\n map.forEach((sheet) => {\n sheet.content.forEach((cell, key) => {\n if (typeof cell === \"string\" && cell.startsWith(\"=\")) {\n const formula = cell.slice(1);\n const updatedFormula = updateCallback(formula);\n\n // Only update if the formula actually changed\n if (updatedFormula !== formula) {\n sheet.content.set(key, `=${updatedFormula}`);\n }\n }\n });\n });\n };\n\n this.workbooks.forEach((workbook) => {\n update(workbook.sheets);\n });\n }\n\n updateFormulasForWorkbook(\n workbookName: string,\n updateCallback: (formula: string) => string\n ): void {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n workbook.sheets.forEach((sheet) => {\n sheet.content.forEach((cell, key) => {\n if (typeof cell === \"string\" && cell.startsWith(\"=\")) {\n const formula = cell.slice(1);\n const updatedFormula = updateCallback(formula);\n\n // Only update if the formula actually changed\n if (updatedFormula !== formula) {\n sheet.content.set(key, `=${updatedFormula}`);\n }\n }\n });\n });\n }\n\n getSheetSerialized({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Map<string, SerializedCellValue> {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = workbook.sheets.get(sheetName);\n if (!sheet) {\n throw new SheetNotFoundError(sheetName);\n }\n\n return sheet.content;\n }\n\n /**\n * Add a cell to the grouped indexes\n */\n private addCellToGroups(\n indexes: SheetIndexes,\n rowIndex: number,\n colIndex: number,\n key: string\n ): void {\n // Add to row group (cells in this row, sorted by column)\n let rowGroup = indexes.rowGroups.get(rowIndex);\n if (!rowGroup) {\n rowGroup = [];\n indexes.rowGroups.set(rowIndex, rowGroup);\n }\n const colEntry: IndexEntry = { number: colIndex, key };\n const colInsertIdx = this.findInsertIndex(rowGroup, colIndex);\n rowGroup.splice(colInsertIdx, 0, colEntry);\n\n // Add to column group (cells in this column, sorted by row)\n let colGroup = indexes.colGroups.get(colIndex);\n if (!colGroup) {\n colGroup = [];\n indexes.colGroups.set(colIndex, colGroup);\n }\n const rowEntry: IndexEntry = { number: rowIndex, key };\n const rowInsertIdx = this.findInsertIndex(colGroup, rowIndex);\n colGroup.splice(rowInsertIdx, 0, rowEntry);\n\n // Add to sorted flat indexes\n this.insertSorted(indexes.cellsSortedByRow, { number: rowIndex, key });\n this.insertSorted(indexes.cellsSortedByCol, { number: colIndex, key });\n }\n\n /**\n * Remove a cell from the grouped indexes\n */\n private removeCellFromGroups(\n indexes: SheetIndexes,\n rowIndex: number,\n colIndex: number,\n key: string\n ): void {\n // Remove from row group\n const rowGroup = indexes.rowGroups.get(rowIndex);\n if (rowGroup) {\n const filteredGroup = rowGroup.filter((e) => e.key !== key);\n if (filteredGroup.length === 0) {\n indexes.rowGroups.delete(rowIndex);\n } else {\n indexes.rowGroups.set(rowIndex, filteredGroup);\n }\n }\n\n // Remove from column group\n const colGroup = indexes.colGroups.get(colIndex);\n if (colGroup) {\n const filteredGroup = colGroup.filter((e) => e.key !== key);\n if (filteredGroup.length === 0) {\n indexes.colGroups.delete(colIndex);\n } else {\n indexes.colGroups.set(colIndex, filteredGroup);\n }\n }\n\n // Remove from sorted flat indexes\n indexes.cellsSortedByRow = indexes.cellsSortedByRow.filter(\n (item) => item.key !== key\n );\n indexes.cellsSortedByCol = indexes.cellsSortedByCol.filter(\n (item) => item.key !== key\n );\n }\n\n /**\n * Find insertion index in sorted array\n */\n private findInsertIndex(entries: IndexEntry[], n: number): number {\n return IndexEntryBinarySearch.findInsertionPoint(entries, n);\n }\n\n /**\n * Inserts an item into a sorted array by number, maintaining sort order.\n * If an item with the same number and key already exists, it won't be added again.\n */\n private insertSorted(array: IndexEntry[], item: IndexEntry): void {\n // Check if item already exists (same number and key)\n const existingIndex = array.findIndex(\n (existing) => existing.number === item.number && existing.key === item.key\n );\n\n if (existingIndex !== -1) {\n // Item already exists, no need to add it again\n return;\n }\n\n // Find the insertion point using binary search for efficiency\n const insertionPoint = IndexEntryBinarySearch.findInsertionPoint(\n array,\n item.number\n );\n\n // Insert at the found position\n array.splice(insertionPoint, 0, item);\n }\n\n setCellContent(\n address: CellAddress,\n content: SerializedCellValue,\n options?: {\n /**\n * for extra performance, if the sheet is already known, it can be passed in\n */\n sheet?: Sheet;\n /**\n * if the sheet is being built from scratch, we can skip some checks\n */\n buildingFromScratch?: boolean;\n }\n ): void {\n const sheet =\n options?.sheet ||\n this.getSheet({\n sheetName: address.sheetName,\n workbookName: address.workbookName,\n });\n\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n const indexes = this.getSheetIndexes({\n workbookName: address.workbookName,\n sheetName: address.sheetName,\n });\n const adr = getCellReference(address);\n\n if (this.isContentEmpty(content)) {\n if (!options?.buildingFromScratch) {\n sheet.content.delete(adr);\n // Remove from all indexes\n this.removeCellFromGroups(\n indexes,\n address.rowIndex,\n address.colIndex,\n adr\n );\n }\n } else {\n sheet.content.set(adr, content);\n // Add to all indexes\n this.addCellToGroups(indexes, address.rowIndex, address.colIndex, adr);\n }\n }\n\n /**\n * Replace all content for a sheet (safely, without breaking references)\n * This method clears the existing Map and repopulates it rather than replacing the Map reference\n */\n setSheetContent(\n opts: { sheetName: string; workbookName: string },\n newContent: Map<string, SerializedCellValue>\n ): void {\n const sheet = this.getSheet(opts);\n if (!sheet) {\n throw new SheetNotFoundError(opts.sheetName);\n }\n\n // Clear existing content without breaking the Map reference\n sheet.content.clear();\n\n // Clean up indexes for this sheet\n const key = this.getSheetIndexKey(opts.workbookName, opts.sheetName);\n this.sheetIndexes.delete(key);\n\n // Repopulate with new content\n newContent.forEach((value, key) => {\n this.setCellContent(\n {\n workbookName: opts.workbookName,\n sheetName: opts.sheetName,\n colIndex: parseCellReference(key).colIndex,\n rowIndex: parseCellReference(key).rowIndex,\n },\n value,\n {\n sheet,\n buildingFromScratch: true,\n }\n );\n });\n }\n\n /**\n * Removes the content in the spreadsheet that is inside the range.\n * OPTIMIZED: Uses indexes to only process cells that actually exist.\n * ENHANCED: Now supports infinite ranges.\n */\n clearSpreadsheetRange(address: RangeAddress) {\n const sheet = this.getSheet(address);\n\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n // Get current sheet content and prepare new content with cleared cells\n const newContent = new Map(sheet.content);\n\n // Use iterateCellsInRange to only process cells that actually exist\n // This handles both finite and infinite ranges efficiently\n for (const cellAddress of this.iterateCellsInRange(address)) {\n const cellRef = getCellReference(cellAddress);\n\n // Remove from content\n newContent.delete(cellRef);\n }\n\n // setSheetContent will rebuild indexes from scratch, so no need to manually update them\n this.setSheetContent(address, newContent);\n }\n\n /**\n * Optimized generator to iterate over cells defined in the content within a range\n * Uses indexes to efficiently find and yield only cells that exist within the range\n */\n *iterateCellsInRange(address: RangeAddress): Generator<CellAddress> {\n // First check if the sheet exists\n const sheet = this.getSheet(address);\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n const indexes = this.getSheetIndexes(address);\n\n const range = address.range;\n\n // Use the sorted index to find only rows that actually contain cells\n // This avoids iterating through empty rows regardless of finite/infinite bounds\n\n if (range.end.row.type === \"number\") {\n // Finite bounds: Use binary search to find the range of cells to check\n const startIndex = IndexEntryBinarySearch.findFirstGreaterOrEqual(\n indexes.cellsSortedByRow,\n range.start.row\n );\n\n if (startIndex === -1) return; // No cells at or after start row\n\n // Process cells from startIndex until we exceed the end row\n for (let i = startIndex; i < indexes.cellsSortedByRow.length; i++) {\n const cellEntry = indexes.cellsSortedByRow[i];\n if (!cellEntry) continue;\n\n const parsed = parseCellReference(cellEntry.key);\n\n // Stop if we've gone beyond the row range\n if (parsed.rowIndex > range.end.row.value) break;\n\n // Check if cell is within column bounds\n if (parsed.colIndex < range.start.col) continue;\n\n if (\n range.end.col.type === \"number\" &&\n parsed.colIndex > range.end.col.value\n ) {\n continue; // Skip this cell but keep checking others in different rows\n }\n\n yield {\n rowIndex: parsed.rowIndex,\n colIndex: parsed.colIndex,\n sheetName: address.sheetName,\n workbookName: address.workbookName,\n };\n }\n } else {\n // Infinite row bounds: Use binary search to find starting point\n const startIndex = IndexEntryBinarySearch.findFirstGreaterOrEqual(\n indexes.cellsSortedByRow,\n range.start.row\n );\n\n if (startIndex === -1) return; // No cells at or after start row\n\n // Process all cells from startIndex to end\n for (let i = startIndex; i < indexes.cellsSortedByRow.length; i++) {\n const cellEntry = indexes.cellsSortedByRow[i];\n if (!cellEntry) continue;\n\n const parsed = parseCellReference(cellEntry.key);\n\n // Check if cell is within column bounds\n if (parsed.colIndex < range.start.col) continue;\n\n if (\n range.end.col.type === \"number\" &&\n parsed.colIndex > range.end.col.value\n ) {\n continue; // Skip this cell but keep checking others in different rows\n }\n\n yield {\n rowIndex: parsed.rowIndex,\n colIndex: parsed.colIndex,\n sheetName: address.sheetName,\n workbookName: address.workbookName,\n };\n }\n }\n }\n\n getCellsInRange(address: RangeAddress): CellAddress[] {\n return Array.from(this.iterateCellsInRange(address));\n }\n\n private getCellContent(cellAddress: CellAddress): SerializedCellValue {\n const sheet = this.getSheet(cellAddress);\n if (!sheet) {\n throw new SheetNotFoundError(cellAddress.sheetName);\n }\n return sheet.content.get(getCellReference(cellAddress));\n }\n\n public getSerializedCellValue(cellAddress: CellAddress): SerializedCellValue {\n const sheet = this.getSheet(cellAddress);\n if (!sheet) {\n throw new SheetNotFoundError(cellAddress.sheetName);\n }\n return normalizeSerializedCellValue(\n sheet.content.get(getCellReference(cellAddress))\n );\n }\n\n public isCellEmpty(cellAddress: CellAddress): boolean {\n const content = this.getCellContent(cellAddress);\n return (\n content === undefined || (typeof content === \"string\" && content === \"\")\n );\n }\n public isFormulaCell(cellAddress: CellAddress): boolean {\n const content = this.getCellContent(cellAddress);\n return typeof content === \"string\" && content.startsWith(\"=\");\n }\n\n /**\n * Build evaluation order for a range\n * Delegates to the buildRangeEvalOrder function\n */\n public buildRangeEvalOrder(\n lookupOrder: \"row-major\" | \"col-major\",\n lookupRange: RangeAddress\n ) {\n // Import and call the function\n return buildRangeEvalOrder.call(this, lookupOrder, lookupRange);\n }\n}\n"
5
+ "import {\n FormulaError,\n type CellAddress,\n type FiniteSpreadsheetRange,\n type LocalCellAddress,\n type SerializedCellValue,\n type Sheet,\n type SpreadsheetRange,\n type Workbook,\n} from \"../types.mjs\";\nimport { getCellReference, parseCellReference } from \"../utils.mjs\";\n\nimport type { RangeAddress } from \"../types.mjs\";\nimport { buildRangeEvalOrder } from \"./range-eval-order-builder.mjs\";\nimport {\n EvaluationError,\n SheetNotFoundError,\n WorkbookNotFoundError,\n} from \"../../evaluator/evaluation-error.mjs\";\nimport { normalizeSerializedCellValue } from \"../../parser/formatter.mjs\";\n\ninterface IndexEntry {\n number: number;\n key: string;\n}\n\nexport interface SheetIndexes {\n // lookup maps - cells grouped by row/column\n rowGroups: Map<number, IndexEntry[]>; // row number -> cells in that row (sorted by col)\n colGroups: Map<number, IndexEntry[]>; // col number -> cells in that col (sorted by row)\n\n // Sorted flat indexes - for finding cells before a given row/col\n cellsSortedByRow: IndexEntry[];\n cellsSortedByCol: IndexEntry[];\n}\n\n/**\n * Utility class for binary search operations on IndexEntry arrays\n */\nexport class IndexEntryBinarySearch {\n /**\n * Find the insertion point for a number in a sorted IndexEntry array\n * Returns the index where the number should be inserted to maintain sort order\n */\n static findInsertionPoint(entries: IndexEntry[], target: number): number {\n let left = 0;\n let right = entries.length;\n\n while (left < right) {\n const mid = Math.floor((left + right) / 2);\n const midEntry = entries[mid];\n if (midEntry && midEntry.number < target) {\n left = mid + 1;\n } else {\n right = mid;\n }\n }\n\n return left;\n }\n\n /**\n * Find the first element >= target\n * Returns the index of the first element, or -1 if not found\n */\n static findFirstGreaterOrEqual(\n entries: IndexEntry[],\n target: number\n ): number {\n if (entries.length === 0) return -1;\n\n let left = 0;\n let right = entries.length - 1;\n let result = -1;\n\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n const midEntry = entries[mid];\n if (midEntry && midEntry.number >= target) {\n result = mid;\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n }\n\n return result;\n }\n\n /**\n * Find the rightmost position where we could insert a target value\n * Useful for finding elements that come before a target\n */\n static findRightmostInsertionPoint(\n entries: IndexEntry[],\n target: number\n ): number {\n return IndexEntryBinarySearch.findInsertionPoint(entries, target);\n }\n}\n\nexport class WorkbookManager {\n private workbooks: Map<string, Workbook> = new Map();\n\n // Map from \"workbookName|sheetName\" to indexes\n private sheetIndexes: Map<string, SheetIndexes> = new Map();\n\n /**\n * Generate a key for the sheet indexes map\n */\n private getSheetIndexKey(workbookName: string, sheetName: string): string {\n return `${workbookName}|${sheetName}`;\n }\n\n /**\n * Get or create indexes for a sheet\n */\n public getSheetIndexes(opts: {\n workbookName: string;\n sheetName: string;\n }): SheetIndexes {\n const key = this.getSheetIndexKey(opts.workbookName, opts.sheetName);\n let indexes = this.sheetIndexes.get(key);\n\n if (!indexes) {\n indexes = {\n rowGroups: new Map(),\n colGroups: new Map(),\n cellsSortedByRow: [],\n cellsSortedByCol: [],\n };\n this.sheetIndexes.set(key, indexes);\n }\n\n return indexes;\n }\n\n getSheets(workbookName: string): Map<string, Sheet> {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n return workbook.sheets;\n }\n\n getWorkbooks(): Map<string, Workbook> {\n return this.workbooks;\n }\n\n addWorkbook(workbookName: string): void {\n if (this.workbooks.has(workbookName)) {\n throw new Error(\"Workbook already exists\");\n }\n this.workbooks.set(workbookName, {\n name: workbookName,\n sheets: new Map(),\n workbookMetadata: undefined,\n });\n }\n\n removeWorkbook(workbookName: string): void {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n // Clean up indexes for all sheets in this workbook\n for (const sheetName of workbook.sheets.keys()) {\n const key = this.getSheetIndexKey(workbookName, sheetName);\n this.sheetIndexes.delete(key);\n }\n\n this.workbooks.delete(workbookName);\n }\n\n isContentEmpty(content: SerializedCellValue): boolean {\n return content === \"\" || content === undefined;\n }\n\n renameWorkbook(opts: {\n workbookName: string;\n newWorkbookName: string;\n }): void {\n const workbook = this.workbooks.get(opts.workbookName);\n if (!workbook) {\n throw new Error(\"Workbook not found\");\n }\n\n // Update indexes for all sheets in this workbook\n for (const sheetName of workbook.sheets.keys()) {\n const oldKey = this.getSheetIndexKey(opts.workbookName, sheetName);\n const newKey = this.getSheetIndexKey(opts.newWorkbookName, sheetName);\n const indexes = this.sheetIndexes.get(oldKey);\n if (indexes) {\n this.sheetIndexes.set(newKey, indexes);\n this.sheetIndexes.delete(oldKey);\n }\n }\n\n this.workbooks.set(opts.newWorkbookName, workbook);\n this.workbooks.delete(opts.workbookName);\n workbook.name = opts.newWorkbookName;\n }\n\n resetWorkbooks(workbooks: Map<string, Workbook>): void {\n this.workbooks.clear();\n this.sheetIndexes.clear();\n\n workbooks.forEach((workbook, workbookName) => {\n this.workbooks.set(workbookName, workbook);\n workbook.sheets.forEach((sheet) => {\n // Initialize indexes for this sheet\n const indexes = this.getSheetIndexes({\n workbookName,\n sheetName: sheet.name,\n });\n indexes.rowGroups.clear();\n indexes.colGroups.clear();\n indexes.cellsSortedByRow = [];\n indexes.cellsSortedByCol = [];\n\n sheet.content.forEach((value, key) => {\n this.setCellContent(\n {\n workbookName,\n sheetName: sheet.name,\n colIndex: parseCellReference(key).colIndex,\n rowIndex: parseCellReference(key).rowIndex,\n },\n value,\n {\n sheet,\n buildingFromScratch: true,\n }\n );\n });\n });\n });\n }\n\n getSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Sheet | undefined {\n const workbook = this.workbooks.get(workbookName);\n const sheet = workbook?.sheets.get(sheetName);\n return sheet;\n }\n\n addSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Sheet {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = {\n name: sheetName,\n index: workbook.sheets.size,\n content: new Map(),\n metadata: new Map(),\n sheetMetadata: undefined,\n };\n\n if (workbook.sheets.has(sheet.name)) {\n throw new Error(\"Sheet already exists\");\n }\n\n workbook.sheets.set(sheetName, sheet);\n\n // Initialize empty indexes for this sheet\n this.getSheetIndexes({ workbookName, sheetName });\n\n return sheet;\n }\n\n removeSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Sheet {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = workbook.sheets.get(sheetName);\n if (!sheet) {\n throw new Error(\"Sheet not found\");\n }\n\n // Remove the sheet\n workbook.sheets.delete(sheetName);\n\n // Clean up indexes for this sheet\n const key = this.getSheetIndexKey(workbookName, sheetName);\n this.sheetIndexes.delete(key);\n\n return sheet;\n }\n\n renameSheet({\n workbookName,\n sheetName,\n newSheetName,\n }: {\n workbookName: string;\n sheetName: string;\n newSheetName: string;\n }): Sheet {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = workbook.sheets.get(sheetName);\n if (!sheet) {\n throw new SheetNotFoundError(sheetName);\n }\n\n if (workbook.sheets.has(newSheetName)) {\n throw new Error(\"Sheet with new name already exists\");\n }\n\n // Update sheet name\n sheet.name = newSheetName;\n\n // Update sheets map\n workbook.sheets.set(newSheetName, sheet);\n workbook.sheets.delete(sheetName);\n\n // Move indexes to new key\n const oldKey = this.getSheetIndexKey(workbookName, sheetName);\n const newKey = this.getSheetIndexKey(workbookName, newSheetName);\n const indexes = this.sheetIndexes.get(oldKey);\n if (indexes) {\n this.sheetIndexes.set(newKey, indexes);\n this.sheetIndexes.delete(oldKey);\n }\n\n return sheet;\n }\n\n updateAllFormulas(updateCallback: (formula: string) => string): void {\n const update = (map: Map<string, Sheet>) => {\n map.forEach((sheet) => {\n sheet.content.forEach((cell, key) => {\n if (typeof cell === \"string\" && cell.startsWith(\"=\")) {\n const formula = cell.slice(1);\n const updatedFormula = updateCallback(formula);\n\n // Only update if the formula actually changed\n if (updatedFormula !== formula) {\n sheet.content.set(key, `=${updatedFormula}`);\n }\n }\n });\n });\n };\n\n this.workbooks.forEach((workbook) => {\n update(workbook.sheets);\n });\n }\n\n updateFormulasExcluding(\n excludeCellsSet: Set<string>,\n updateCallback: (formula: string) => string\n ): void {\n this.workbooks.forEach((workbook, workbookName) => {\n workbook.sheets.forEach((sheet, sheetName) => {\n sheet.content.forEach((cell, key) => {\n if (typeof cell === \"string\" && cell.startsWith(\"=\")) {\n const { colIndex, rowIndex } = parseCellReference(key);\n const cellKey = `${workbookName}:${sheetName}:${colIndex}:${rowIndex}`;\n \n // Skip if this cell is in the exclude set\n if (excludeCellsSet.has(cellKey)) {\n return;\n }\n\n const formula = cell.slice(1);\n const updatedFormula = updateCallback(formula);\n\n // Only update if the formula actually changed\n if (updatedFormula !== formula) {\n sheet.content.set(key, `=${updatedFormula}`);\n }\n }\n });\n });\n });\n }\n\n updateFormulasForWorkbook(\n workbookName: string,\n updateCallback: (formula: string) => string\n ): void {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n workbook.sheets.forEach((sheet) => {\n sheet.content.forEach((cell, key) => {\n if (typeof cell === \"string\" && cell.startsWith(\"=\")) {\n const formula = cell.slice(1);\n const updatedFormula = updateCallback(formula);\n\n // Only update if the formula actually changed\n if (updatedFormula !== formula) {\n sheet.content.set(key, `=${updatedFormula}`);\n }\n }\n });\n });\n }\n\n getSheetSerialized({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Map<string, SerializedCellValue> {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = workbook.sheets.get(sheetName);\n if (!sheet) {\n throw new SheetNotFoundError(sheetName);\n }\n\n return sheet.content;\n }\n\n /**\n * Add a cell to the grouped indexes\n */\n private addCellToGroups(\n indexes: SheetIndexes,\n rowIndex: number,\n colIndex: number,\n key: string\n ): void {\n // Add to row group (cells in this row, sorted by column)\n let rowGroup = indexes.rowGroups.get(rowIndex);\n if (!rowGroup) {\n rowGroup = [];\n indexes.rowGroups.set(rowIndex, rowGroup);\n }\n const colEntry: IndexEntry = { number: colIndex, key };\n const colInsertIdx = this.findInsertIndex(rowGroup, colIndex);\n rowGroup.splice(colInsertIdx, 0, colEntry);\n\n // Add to column group (cells in this column, sorted by row)\n let colGroup = indexes.colGroups.get(colIndex);\n if (!colGroup) {\n colGroup = [];\n indexes.colGroups.set(colIndex, colGroup);\n }\n const rowEntry: IndexEntry = { number: rowIndex, key };\n const rowInsertIdx = this.findInsertIndex(colGroup, rowIndex);\n colGroup.splice(rowInsertIdx, 0, rowEntry);\n\n // Add to sorted flat indexes\n this.insertSorted(indexes.cellsSortedByRow, { number: rowIndex, key });\n this.insertSorted(indexes.cellsSortedByCol, { number: colIndex, key });\n }\n\n /**\n * Remove a cell from the grouped indexes\n */\n private removeCellFromGroups(\n indexes: SheetIndexes,\n rowIndex: number,\n colIndex: number,\n key: string\n ): void {\n // Remove from row group\n const rowGroup = indexes.rowGroups.get(rowIndex);\n if (rowGroup) {\n const filteredGroup = rowGroup.filter((e) => e.key !== key);\n if (filteredGroup.length === 0) {\n indexes.rowGroups.delete(rowIndex);\n } else {\n indexes.rowGroups.set(rowIndex, filteredGroup);\n }\n }\n\n // Remove from column group\n const colGroup = indexes.colGroups.get(colIndex);\n if (colGroup) {\n const filteredGroup = colGroup.filter((e) => e.key !== key);\n if (filteredGroup.length === 0) {\n indexes.colGroups.delete(colIndex);\n } else {\n indexes.colGroups.set(colIndex, filteredGroup);\n }\n }\n\n // Remove from sorted flat indexes\n indexes.cellsSortedByRow = indexes.cellsSortedByRow.filter(\n (item) => item.key !== key\n );\n indexes.cellsSortedByCol = indexes.cellsSortedByCol.filter(\n (item) => item.key !== key\n );\n }\n\n /**\n * Find insertion index in sorted array\n */\n private findInsertIndex(entries: IndexEntry[], n: number): number {\n return IndexEntryBinarySearch.findInsertionPoint(entries, n);\n }\n\n /**\n * Inserts an item into a sorted array by number, maintaining sort order.\n * If an item with the same number and key already exists, it won't be added again.\n */\n private insertSorted(array: IndexEntry[], item: IndexEntry): void {\n // Check if item already exists (same number and key)\n const existingIndex = array.findIndex(\n (existing) => existing.number === item.number && existing.key === item.key\n );\n\n if (existingIndex !== -1) {\n // Item already exists, no need to add it again\n return;\n }\n\n // Find the insertion point using binary search for efficiency\n const insertionPoint = IndexEntryBinarySearch.findInsertionPoint(\n array,\n item.number\n );\n\n // Insert at the found position\n array.splice(insertionPoint, 0, item);\n }\n\n setCellContent(\n address: CellAddress,\n content: SerializedCellValue,\n options?: {\n /**\n * for extra performance, if the sheet is already known, it can be passed in\n */\n sheet?: Sheet;\n /**\n * if the sheet is being built from scratch, we can skip some checks\n */\n buildingFromScratch?: boolean;\n }\n ): void {\n const sheet =\n options?.sheet ||\n this.getSheet({\n sheetName: address.sheetName,\n workbookName: address.workbookName,\n });\n\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n const indexes = this.getSheetIndexes({\n workbookName: address.workbookName,\n sheetName: address.sheetName,\n });\n const adr = getCellReference(address);\n\n if (this.isContentEmpty(content)) {\n if (!options?.buildingFromScratch) {\n sheet.content.delete(adr);\n // Remove from all indexes\n this.removeCellFromGroups(\n indexes,\n address.rowIndex,\n address.colIndex,\n adr\n );\n }\n } else {\n sheet.content.set(adr, content);\n // Add to all indexes\n this.addCellToGroups(indexes, address.rowIndex, address.colIndex, adr);\n }\n }\n\n /**\n * Set metadata for a cell\n */\n setCellMetadata<TMetadata = unknown>(address: CellAddress, metadata: TMetadata | undefined): void {\n const sheet = this.getSheet({\n workbookName: address.workbookName,\n sheetName: address.sheetName,\n });\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n const key = getCellReference(address);\n if (metadata === undefined) {\n sheet.metadata.delete(key);\n } else {\n sheet.metadata.set(key, metadata);\n }\n }\n\n /**\n * Get metadata for a cell\n */\n getCellMetadata<TMetadata = unknown>(address: CellAddress): TMetadata | undefined {\n const sheet = this.getSheet({\n workbookName: address.workbookName,\n sheetName: address.sheetName,\n });\n if (!sheet) {\n return undefined;\n }\n\n const key = getCellReference(address);\n return sheet.metadata.get(key) as TMetadata | undefined;\n }\n\n /**\n * Get all metadata for a sheet\n */\n getSheetMetadataSerialized<TMetadata = unknown>(opts: {\n sheetName: string;\n workbookName: string;\n }): Map<string, TMetadata> {\n const sheet = this.getSheet(opts);\n return sheet?.metadata || new Map();\n }\n\n /**\n * Set metadata for a sheet\n */\n setSheetMetadata<TSheetMetadata = unknown>(\n opts: { workbookName: string; sheetName: string },\n metadata: TSheetMetadata\n ): void {\n const sheet = this.getSheet(opts);\n if (!sheet) {\n throw new SheetNotFoundError(opts.sheetName);\n }\n sheet.sheetMetadata = metadata;\n }\n\n /**\n * Get metadata for a sheet\n */\n getSheetMetadata<TSheetMetadata = unknown>(\n opts: { workbookName: string; sheetName: string }\n ): TSheetMetadata | undefined {\n const sheet = this.getSheet(opts);\n if (!sheet) {\n return undefined;\n }\n return sheet.sheetMetadata as TSheetMetadata | undefined;\n }\n\n /**\n * Set metadata for a workbook\n */\n setWorkbookMetadata<TWorkbookMetadata = unknown>(\n workbookName: string,\n metadata: TWorkbookMetadata\n ): void {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new Error(`Workbook \"${workbookName}\" not found`);\n }\n workbook.workbookMetadata = metadata;\n }\n\n /**\n * Get metadata for a workbook\n */\n getWorkbookMetadata<TWorkbookMetadata = unknown>(\n workbookName: string\n ): TWorkbookMetadata | undefined {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n return undefined;\n }\n return workbook.workbookMetadata as TWorkbookMetadata | undefined;\n }\n\n /**\n * Replace all content for a sheet (safely, without breaking references)\n * This method clears the existing Map and repopulates it rather than replacing the Map reference\n */\n setSheetContent(\n opts: { sheetName: string; workbookName: string },\n newContent: Map<string, SerializedCellValue>\n ): void {\n const sheet = this.getSheet(opts);\n if (!sheet) {\n throw new SheetNotFoundError(opts.sheetName);\n }\n\n // Clear existing content without breaking the Map reference\n sheet.content.clear();\n\n // Clean up indexes for this sheet\n const key = this.getSheetIndexKey(opts.workbookName, opts.sheetName);\n this.sheetIndexes.delete(key);\n\n // Repopulate with new content\n newContent.forEach((value, key) => {\n this.setCellContent(\n {\n workbookName: opts.workbookName,\n sheetName: opts.sheetName,\n colIndex: parseCellReference(key).colIndex,\n rowIndex: parseCellReference(key).rowIndex,\n },\n value,\n {\n sheet,\n buildingFromScratch: true,\n }\n );\n });\n }\n\n /**\n * Removes the content in the spreadsheet that is inside the range.\n * OPTIMIZED: Uses indexes to only process cells that actually exist.\n * ENHANCED: Now supports infinite ranges.\n */\n clearSpreadsheetRange(address: RangeAddress) {\n const sheet = this.getSheet(address);\n\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n // Get current sheet content and prepare new content with cleared cells\n const newContent = new Map(sheet.content);\n const newMetadata = new Map(sheet.metadata);\n\n // Use iterateCellsInRange to only process cells that actually exist\n // This handles both finite and infinite ranges efficiently\n for (const cellAddress of this.iterateCellsInRange(address)) {\n const cellRef = getCellReference(cellAddress);\n\n // Remove from content and metadata\n newContent.delete(cellRef);\n newMetadata.delete(cellRef);\n }\n\n // Update content\n this.setSheetContent(address, newContent);\n \n // Update metadata\n sheet.metadata = newMetadata;\n }\n\n /**\n * Optimized generator to iterate over cells defined in the content within a range\n * Uses indexes to efficiently find and yield only cells that exist within the range\n */\n *iterateCellsInRange(address: RangeAddress): Generator<CellAddress> {\n // First check if the sheet exists\n const sheet = this.getSheet(address);\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n const indexes = this.getSheetIndexes(address);\n\n const range = address.range;\n\n // Use the sorted index to find only rows that actually contain cells\n // This avoids iterating through empty rows regardless of finite/infinite bounds\n\n if (range.end.row.type === \"number\") {\n // Finite bounds: Use binary search to find the range of cells to check\n const startIndex = IndexEntryBinarySearch.findFirstGreaterOrEqual(\n indexes.cellsSortedByRow,\n range.start.row\n );\n\n if (startIndex === -1) return; // No cells at or after start row\n\n // Process cells from startIndex until we exceed the end row\n for (let i = startIndex; i < indexes.cellsSortedByRow.length; i++) {\n const cellEntry = indexes.cellsSortedByRow[i];\n if (!cellEntry) continue;\n\n const parsed = parseCellReference(cellEntry.key);\n\n // Stop if we've gone beyond the row range\n if (parsed.rowIndex > range.end.row.value) break;\n\n // Check if cell is within column bounds\n if (parsed.colIndex < range.start.col) continue;\n\n if (\n range.end.col.type === \"number\" &&\n parsed.colIndex > range.end.col.value\n ) {\n continue; // Skip this cell but keep checking others in different rows\n }\n\n yield {\n rowIndex: parsed.rowIndex,\n colIndex: parsed.colIndex,\n sheetName: address.sheetName,\n workbookName: address.workbookName,\n };\n }\n } else {\n // Infinite row bounds: Use binary search to find starting point\n const startIndex = IndexEntryBinarySearch.findFirstGreaterOrEqual(\n indexes.cellsSortedByRow,\n range.start.row\n );\n\n if (startIndex === -1) return; // No cells at or after start row\n\n // Process all cells from startIndex to end\n for (let i = startIndex; i < indexes.cellsSortedByRow.length; i++) {\n const cellEntry = indexes.cellsSortedByRow[i];\n if (!cellEntry) continue;\n\n const parsed = parseCellReference(cellEntry.key);\n\n // Check if cell is within column bounds\n if (parsed.colIndex < range.start.col) continue;\n\n if (\n range.end.col.type === \"number\" &&\n parsed.colIndex > range.end.col.value\n ) {\n continue; // Skip this cell but keep checking others in different rows\n }\n\n yield {\n rowIndex: parsed.rowIndex,\n colIndex: parsed.colIndex,\n sheetName: address.sheetName,\n workbookName: address.workbookName,\n };\n }\n }\n }\n\n getCellsInRange(address: RangeAddress): CellAddress[] {\n return Array.from(this.iterateCellsInRange(address));\n }\n\n public getCellContent(cellAddress: CellAddress): SerializedCellValue {\n const sheet = this.getSheet(cellAddress);\n if (!sheet) {\n throw new SheetNotFoundError(cellAddress.sheetName);\n }\n return sheet.content.get(getCellReference(cellAddress));\n }\n\n public getSerializedCellValue(cellAddress: CellAddress): SerializedCellValue {\n const sheet = this.getSheet(cellAddress);\n if (!sheet) {\n throw new SheetNotFoundError(cellAddress.sheetName);\n }\n return normalizeSerializedCellValue(\n sheet.content.get(getCellReference(cellAddress))\n );\n }\n\n public isCellEmpty(cellAddress: CellAddress): boolean {\n const content = this.getCellContent(cellAddress);\n return (\n content === undefined || (typeof content === \"string\" && content === \"\")\n );\n }\n public isFormulaCell(cellAddress: CellAddress): boolean {\n const content = this.getCellContent(cellAddress);\n return typeof content === \"string\" && content.startsWith(\"=\");\n }\n\n /**\n * Build evaluation order for a range\n * Delegates to the buildRangeEvalOrder function\n */\n public buildRangeEvalOrder(\n lookupOrder: \"row-major\" | \"col-major\",\n lookupRange: RangeAddress\n ) {\n // Import and call the function\n return buildRangeEvalOrder.call(this, lookupOrder, lookupRange);\n }\n}\n"
6
6
  ],
7
- "mappings": ";AAUA;AAGA;AACA;AAAA;AAAA;AAAA;AAKA;AAAA;AAoBO,MAAM,uBAAuB;AAAA,SAK3B,kBAAkB,CAAC,SAAuB,QAAwB;AAAA,IACvE,IAAI,OAAO;AAAA,IACX,IAAI,QAAQ,QAAQ;AAAA,IAEpB,OAAO,OAAO,OAAO;AAAA,MACnB,MAAM,MAAM,KAAK,OAAO,OAAO,SAAS,CAAC;AAAA,MACzC,MAAM,WAAW,QAAQ;AAAA,MACzB,IAAI,YAAY,SAAS,SAAS,QAAQ;AAAA,QACxC,OAAO,MAAM;AAAA,MACf,EAAO;AAAA,QACL,QAAQ;AAAA;AAAA,IAEZ;AAAA,IAEA,OAAO;AAAA;AAAA,SAOF,uBAAuB,CAC5B,SACA,QACQ;AAAA,IACR,IAAI,QAAQ,WAAW;AAAA,MAAG,OAAO;AAAA,IAEjC,IAAI,OAAO;AAAA,IACX,IAAI,QAAQ,QAAQ,SAAS;AAAA,IAC7B,IAAI,SAAS;AAAA,IAEb,OAAO,QAAQ,OAAO;AAAA,MACpB,MAAM,MAAM,KAAK,OAAO,OAAO,SAAS,CAAC;AAAA,MACzC,MAAM,WAAW,QAAQ;AAAA,MACzB,IAAI,YAAY,SAAS,UAAU,QAAQ;AAAA,QACzC,SAAS;AAAA,QACT,QAAQ,MAAM;AAAA,MAChB,EAAO;AAAA,QACL,OAAO,MAAM;AAAA;AAAA,IAEjB;AAAA,IAEA,OAAO;AAAA;AAAA,SAOF,2BAA2B,CAChC,SACA,QACQ;AAAA,IACR,OAAO,uBAAuB,mBAAmB,SAAS,MAAM;AAAA;AAEpE;AAAA;AAEO,MAAM,gB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AAAA,UACJ,UAAU,OAAO;AAAA,UACjB,UAAU,OAAO;AAAA,UACjB,WAAW,QAAQ;AAAA,UACnB,cAAc,QAAQ;AAAA,QACxB;AAAA,MACF;AAAA;AAAA;AAAA,EAIJ,eAAe,CAAC,SAAsC;AAAA,IACpD,OAAO,MAAM,KAAK,KAAK,oBAAoB,OAAO,CAAC;AAAA;AAAA,EAG9C,cAAc,CAAC,aAA+C;AAAA,IACnE,MAAM,QAAQ,KAAK,SAAS,WAAW;AAAA,IACvC,IAAI,CAAC,OAAO;AAAA,MACV,MAAM,IAAI,mBAAmB,YAAY,SAAS;AAAA,IACpD;AAAA,IACA,OAAO,MAAM,QAAQ,IAAI,iBAAiB,WAAW,CAAC;AAAA;AAAA,EAGjD,sBAAsB,CAAC,aAA+C;AAAA,IAC3E,MAAM,QAAQ,KAAK,SAAS,WAAW;AAAA,IACvC,IAAI,CAAC,OAAO;AAAA,MACV,MAAM,IAAI,mBAAmB,YAAY,SAAS;AAAA,IACpD;AAAA,IACA,OAAO,6BACL,MAAM,QAAQ,IAAI,iBAAiB,WAAW,CAAC,CACjD;AAAA;AAAA,EAGK,WAAW,CAAC,aAAmC;AAAA,IACpD,MAAM,UAAU,KAAK,eAAe,WAAW;AAAA,IAC/C,OACE,YAAY,aAAc,OAAO,YAAY,YAAY,YAAY;AAAA;AAAA,EAGlE,aAAa,CAAC,aAAmC;AAAA,IACtD,MAAM,UAAU,KAAK,eAAe,WAAW;AAAA,IAC/C,OAAO,OAAO,YAAY,YAAY,QAAQ,WAAW,GAAG;AAAA;AAAA,EAOvD,mBAAmB,CACxB,aACA,aACA;AAAA,IAEA,OAAO,oBAAoB,KAAK,MAAM,aAAa,WAAW;AAAA;AAElE;",
8
+ "debugId": "495D50D4550C2C5B64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/core/types.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * Core type definitions for FormulaEngine\n * This file contains all fundamental types used throughout the engine\n */\n\nimport type { EvaluationContext } from \"../evaluator/evaluation-context.mjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.mjs\";\nimport type { FunctionNode } from \"../parser/ast.mjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.mjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.mjs\";\n\n// Cell addressing types\nexport interface CellAddress {\n sheetName: string;\n workbookName: string;\n colIndex: number;\n rowIndex: number;\n}\n\nexport interface RangeAddress {\n sheetName: string;\n workbookName: string;\n range: SpreadsheetRange;\n}\n\nexport interface LocalCellAddress {\n colIndex: number;\n rowIndex: number;\n}\n\nexport type ArethmeticEvaluator = (\n left: CellValue,\n right: CellValue,\n context: EvaluationContext\n) => CellValue | ErrorEvaluationResult;\n\nexport type PositiveInfinity = {\n type: \"infinity\";\n sign: \"positive\";\n};\n\nexport type CellInfinity = {\n type: \"infinity\";\n sign: \"positive\" | \"negative\";\n};\n\nexport type CellNumber = {\n type: \"number\";\n value: number;\n};\n\nexport type SpreadsheetRangeEnd = CellNumber | PositiveInfinity;\n\nexport type SpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: SpreadsheetRangeEnd;\n row: SpreadsheetRangeEnd;\n };\n};\n\nexport type RelativeRange = {\n start: {\n col: number;\n row: number;\n };\n width: SpreadsheetRangeEnd;\n height: SpreadsheetRangeEnd;\n};\n\nexport type FiniteSpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: number;\n row: number;\n };\n};\n\nexport type CellString = {\n type: \"string\";\n value: string;\n};\n\nexport type CellBoolean = {\n type: \"boolean\";\n value: boolean;\n};\n\n// Cell value types\nexport type CellValue = CellNumber | CellString | CellBoolean | CellInfinity;\n/**\n * undefined and \"\" are considered empty values\n * undefineds are converted to \"\" in the engine\n *\n * any empty values are deleted from the sheet content\n */\nexport type SerializedCellValue = string | number | boolean | undefined;\n\n// Named expressions\nexport interface NamedExpression {\n name: string;\n expression: string;\n}\n\nexport interface TableDefinition {\n name: string;\n start: {\n rowIndex: number;\n colIndex: number;\n };\n headers: Map<string, { name: string; index: number }>;\n endRow: SpreadsheetRangeEnd;\n sheetName: string;\n workbookName: string;\n}\n\n// Formula errors\nexport enum FormulaError {\n DIV0 = \"#DIV/0!\",\n NA = \"#N/A\",\n NAME = \"#NAME?\",\n NUM = \"#NUM!\",\n REF = \"#REF!\",\n VALUE = \"#VALUE!\",\n CYCLE = \"#CYCLE!\",\n ERROR = \"#ERROR!\",\n SPILL = \"#SPILL!\",\n}\n\n// Sheet structure\nexport interface Sheet {\n name: string;\n index: number; // 0-based index of the sheet\n content: Map<string, SerializedCellValue>;\n}\n\nexport interface Workbook {\n name: string;\n sheets: Map<string, Sheet>;\n}\n\nexport type ValueEvaluationResult = {\n type: \"value\";\n result: CellValue;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type AwaitingEvaluationResult = {\n type: \"awaiting-evaluation\";\n waitingFor: DependencyNode;\n errAddress: DependencyNode;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type DoesNotSpillResult = {\n type: \"does-not-spill\";\n};\n\nexport type ErrorEvaluationResult =\n | {\n type: \"error\";\n err: FormulaError;\n errAddress: DependencyNode;\n message: string;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n }\n | AwaitingEvaluationResult;\n\nexport type SingleEvaluationResult =\n | ValueEvaluationResult\n | ErrorEvaluationResult;\n\nexport type SpilledValuesEvaluator = (\n spillOffset: { x: number; y: number },\n context: EvaluationContext\n) => SingleEvaluationResult;\n\nexport type SpilledValuesEvaluationResult = {\n type: \"spilled-values\";\n\n /**\n * When a raw range is evaluated, we will add it to the sourceRange so it can be used e.g. for context dependent functions\n */\n sourceRange?: RangeAddress;\n\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n * sourceCell will only be defined on a spilledValue when a single value is looked up,\n */\n sourceCell?: CellAddress;\n\n spillArea: (origin: CellAddress) => SpreadsheetRange;\n /**\n * for debugging we add a source string to denote where the spilled values were created\n */\n source: string;\n evaluate: SpilledValuesEvaluator;\n /**\n * evaluateAllCells evaluates all non-empty cells in the spilled range.\n * Because a spilled range can be open-ended, we need to have logic for which cells we should evaluate.\n * e.g. when evaluating a range such as D:D only the cells in the current sheet residing in\n * column D should be evaluated and cells producing spilled values that spill onto D:D.\n *\n * In order to evaluate spilled cells in D:D the range evaluateAllCells need to get all cells in the\n * the intersection of the spilled range and D:D, for that reason evaluateAllCells gets an intersection parameter,\n * where the intersection is relative to the origin.\n *\n * #### Producers:\n * In e.g. SEQUENCE and evaluateRange we have logic for which cells in a spilled range we should evaluate,\n *\n * #### Nesting:\n * e.g. evaluation of scalar operators where we want to nest e.g. `5 * right.evaluate()`\n * can be implemented by calling\n * ```ts\n * const vals = child.evaluateAllCells.call(this, options);\n * return vals.map(val => ({ ...val, result: 5 * val.result }));\n * ```\n *\n * #### Consumers:\n * Only functions that need access to all spilled values in a range end up calling evaluateAllCells, e.g.\n * SUM, MIN, MAX, MATCH. Other types of functions like INDEX doesn't need to evaluate all cells in a range,\n * but does a lookup into a spilled range using the evaluate method.\n *\n */\n evaluateAllCells: (\n this: FormulaEvaluator,\n options: {\n /**\n * an intersection relative to the origin\n */\n intersection?: SpreadsheetRange;\n evaluate: SpilledValuesEvaluator;\n context: EvaluationContext;\n /**\n * origin is the cell address that the spilled range is spilled from\n * e.g. in A3=B2:B4 the origin is A3\n */\n origin: CellAddress;\n\n lookupOrder: LookupOrder;\n }\n ) => EvaluateAllCellsResult;\n};\n\nexport type EvaluateAllCellsResult =\n | ErrorEvaluationResult\n | {\n type: \"values\";\n values: CellInRangeResult[];\n };\n\nexport type CellInRangeResult = {\n result: SingleEvaluationResult;\n relativePos: { x: number; y: number };\n};\n\nexport type FunctionEvaluationResult =\n | SingleEvaluationResult\n | SpilledValuesEvaluationResult;\n\nexport type SpilledValue = {\n /**\n * spillOnto is the range that the spilled value is spilled onto\n */\n spillOnto: SpreadsheetRange;\n /**\n * origin is the cell address that the spilled value is spilled from\n */\n origin: CellAddress;\n};\n\n/**\n * Function definition\n */\nexport interface FunctionDefinition {\n name: string;\n evaluate: (\n this: FormulaEvaluator,\n node: FunctionNode,\n context: EvaluationContext\n ) => FunctionEvaluationResult;\n aliases?: string[];\n}\n\n/**\n * Evaluation result\n */\nexport type EvaluationResult = {\n dependencies: Set<string>;\n} & FunctionEvaluationResult;\n\nexport type SCC = {\n id: number;\n nodes: Set<DependencyNode>; // All nodes considering soft + hard edges\n evaluationOrder: DependencyNode[]; // Flat topologically ordered list\n resolved: boolean;\n hardEdgeSCCs: Set<DependencyNode>[]; // SCCs formed by only hard edges (regular dependencies)\n};\n\nexport type SCCDAG = {\n sccList: SCC[];\n sccGraph: Map<number, Set<number>>; // Adjacency list of SCC dependencies\n};\n\nexport type EvaluationOrder = {\n evaluationOrder: Set<DependencyNode>;\n hasCycle: boolean;\n cycleNodes?: Set<DependencyNode>;\n hash: string;\n sccDAG?: SCCDAG;\n};\n\n// Conditional Styling types\nexport interface LCHColor {\n l: number; // Lightness: 0-100\n c: number; // Chroma: 0-150+\n h: number; // Hue: 0-360\n}\n\nexport interface FormulaStyleCondition {\n type: \"formula\";\n formula: string;\n color: LCHColor;\n}\n\nexport interface GradientStyleCondition {\n type: \"gradient\";\n min:\n | { type: \"lowest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n max:\n | { type: \"highest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n}\n\nexport type StyleCondition = FormulaStyleCondition | GradientStyleCondition;\n\nexport interface ConditionalStyle {\n area: RangeAddress;\n condition: StyleCondition;\n}\n\nexport interface DirectCellStyle {\n area: RangeAddress;\n style: CellStyle\n}\n\nexport interface CellStyle {\n backgroundColor?: string; // Hex color format\n color?: string; // Text color in hex format\n fontSize?: number; // Font size in pixels\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n}\n\nexport interface CopyCellsOptions {\n cut: boolean;\n /**\n * all: Copy everything from the source to the target\n * content: Copy only the content from the source to the target\n * style: Copy only the style from the source to the target\n */\n target: 'all' | 'content' | 'style';\n /**\n * The type of the content to copy\n * value: Copy the value from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the value is 246\n * formula: Copy the formula from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the formula is =123 + 123 is copied\n */\n type: \"value\" | \"formula\";\n}\n"
5
+ "/**\n * Core type definitions for FormulaEngine\n * This file contains all fundamental types used throughout the engine\n */\n\nimport type { EvaluationContext } from \"../evaluator/evaluation-context.mjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.mjs\";\nimport type { FunctionNode } from \"../parser/ast.mjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.mjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.mjs\";\n\n// Cell addressing types\nexport interface CellAddress {\n sheetName: string;\n workbookName: string;\n colIndex: number;\n rowIndex: number;\n}\n\nexport interface RangeAddress {\n sheetName: string;\n workbookName: string;\n range: SpreadsheetRange;\n}\n\nexport interface LocalCellAddress {\n colIndex: number;\n rowIndex: number;\n}\n\nexport type ArethmeticEvaluator = (\n left: CellValue,\n right: CellValue,\n context: EvaluationContext\n) => CellValue | ErrorEvaluationResult;\n\nexport type PositiveInfinity = {\n type: \"infinity\";\n sign: \"positive\";\n};\n\nexport type CellInfinity = {\n type: \"infinity\";\n sign: \"positive\" | \"negative\";\n};\n\nexport type CellNumber = {\n type: \"number\";\n value: number;\n};\n\nexport type SpreadsheetRangeEnd = CellNumber | PositiveInfinity;\n\nexport type SpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: SpreadsheetRangeEnd;\n row: SpreadsheetRangeEnd;\n };\n};\n\nexport type RelativeRange = {\n start: {\n col: number;\n row: number;\n };\n width: SpreadsheetRangeEnd;\n height: SpreadsheetRangeEnd;\n};\n\nexport type FiniteSpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: number;\n row: number;\n };\n};\n\nexport type CellString = {\n type: \"string\";\n value: string;\n};\n\nexport type CellBoolean = {\n type: \"boolean\";\n value: boolean;\n};\n\n// Cell value types\nexport type CellValue = CellNumber | CellString | CellBoolean | CellInfinity;\n/**\n * undefined and \"\" are considered empty values\n * undefineds are converted to \"\" in the engine\n *\n * any empty values are deleted from the sheet content\n */\nexport type SerializedCellValue = string | number | boolean | undefined;\n\n// Named expressions\nexport interface NamedExpression {\n name: string;\n expression: string;\n}\n\nexport interface TableDefinition {\n name: string;\n start: {\n rowIndex: number;\n colIndex: number;\n };\n headers: Map<string, { name: string; index: number }>;\n endRow: SpreadsheetRangeEnd;\n sheetName: string;\n workbookName: string;\n}\n\n// Formula errors\nexport enum FormulaError {\n DIV0 = \"#DIV/0!\",\n NA = \"#N/A\",\n NAME = \"#NAME?\",\n NUM = \"#NUM!\",\n REF = \"#REF!\",\n VALUE = \"#VALUE!\",\n CYCLE = \"#CYCLE!\",\n ERROR = \"#ERROR!\",\n SPILL = \"#SPILL!\",\n}\n\n// Sheet structure\nexport interface Sheet<TCellMetadata = unknown, TSheetMetadata = unknown> {\n name: string;\n index: number; // 0-based index of the sheet\n content: Map<string, SerializedCellValue>;\n /**\n * Cell metadata - arbitrary consumer-defined data per cell\n * Examples: rich text content, links, comments, custom app data\n * The engine stores and copies this data but doesn't interpret it\n * Keyed by cell reference (e.g., \"A1\")\n */\n metadata: Map<string, TCellMetadata>;\n /**\n * Sheet-level metadata - arbitrary consumer-defined data for the entire sheet\n * Examples: text boxes, drawings, frozen panes, print settings\n * The engine stores and copies this data but doesn't interpret it\n */\n sheetMetadata: TSheetMetadata;\n}\n\nexport interface Workbook<\n TCellMetadata = unknown,\n TSheetMetadata = unknown,\n TWorkbookMetadata = unknown\n> {\n name: string;\n sheets: Map<string, Sheet<TCellMetadata, TSheetMetadata>>;\n /**\n * Workbook-level metadata - arbitrary consumer-defined data for the entire workbook\n * Examples: themes, custom ribbons, document properties, workbook settings\n * The engine stores and copies this data but doesn't interpret it\n */\n workbookMetadata: TWorkbookMetadata;\n}\n\n/**\n * Tracked reference - a stable reference to a range that updates automatically\n * when workbooks/sheets are renamed and becomes invalid when they're deleted\n */\nexport interface TrackedReference {\n id: string; // UUID\n address: RangeAddress; // The range being tracked\n isValid: boolean; // False if sheet/workbook deleted\n}\n\nexport type ValueEvaluationResult = {\n type: \"value\";\n result: CellValue;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type AwaitingEvaluationResult = {\n type: \"awaiting-evaluation\";\n waitingFor: DependencyNode;\n errAddress: DependencyNode;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type DoesNotSpillResult = {\n type: \"does-not-spill\";\n};\n\nexport type ErrorEvaluationResult =\n | {\n type: \"error\";\n err: FormulaError;\n errAddress: DependencyNode;\n message: string;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n }\n | AwaitingEvaluationResult;\n\nexport type SingleEvaluationResult =\n | ValueEvaluationResult\n | ErrorEvaluationResult;\n\nexport type SpilledValuesEvaluator = (\n spillOffset: { x: number; y: number },\n context: EvaluationContext\n) => SingleEvaluationResult;\n\nexport type SpilledValuesEvaluationResult = {\n type: \"spilled-values\";\n\n /**\n * When a raw range is evaluated, we will add it to the sourceRange so it can be used e.g. for context dependent functions\n */\n sourceRange?: RangeAddress;\n\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n * sourceCell will only be defined on a spilledValue when a single value is looked up,\n */\n sourceCell?: CellAddress;\n\n spillArea: (origin: CellAddress) => SpreadsheetRange;\n /**\n * for debugging we add a source string to denote where the spilled values were created\n */\n source: string;\n evaluate: SpilledValuesEvaluator;\n /**\n * evaluateAllCells evaluates all non-empty cells in the spilled range.\n * Because a spilled range can be open-ended, we need to have logic for which cells we should evaluate.\n * e.g. when evaluating a range such as D:D only the cells in the current sheet residing in\n * column D should be evaluated and cells producing spilled values that spill onto D:D.\n *\n * In order to evaluate spilled cells in D:D the range evaluateAllCells need to get all cells in the\n * the intersection of the spilled range and D:D, for that reason evaluateAllCells gets an intersection parameter,\n * where the intersection is relative to the origin.\n *\n * #### Producers:\n * In e.g. SEQUENCE and evaluateRange we have logic for which cells in a spilled range we should evaluate,\n *\n * #### Nesting:\n * e.g. evaluation of scalar operators where we want to nest e.g. `5 * right.evaluate()`\n * can be implemented by calling\n * ```ts\n * const vals = child.evaluateAllCells.call(this, options);\n * return vals.map(val => ({ ...val, result: 5 * val.result }));\n * ```\n *\n * #### Consumers:\n * Only functions that need access to all spilled values in a range end up calling evaluateAllCells, e.g.\n * SUM, MIN, MAX, MATCH. Other types of functions like INDEX doesn't need to evaluate all cells in a range,\n * but does a lookup into a spilled range using the evaluate method.\n *\n */\n evaluateAllCells: (\n this: FormulaEvaluator,\n options: {\n /**\n * an intersection relative to the origin\n */\n intersection?: SpreadsheetRange;\n evaluate: SpilledValuesEvaluator;\n context: EvaluationContext;\n /**\n * origin is the cell address that the spilled range is spilled from\n * e.g. in A3=B2:B4 the origin is A3\n */\n origin: CellAddress;\n\n lookupOrder: LookupOrder;\n }\n ) => EvaluateAllCellsResult;\n};\n\nexport type EvaluateAllCellsResult =\n | ErrorEvaluationResult\n | {\n type: \"values\";\n values: CellInRangeResult[];\n };\n\nexport type CellInRangeResult = {\n result: SingleEvaluationResult;\n relativePos: { x: number; y: number };\n};\n\nexport type FunctionEvaluationResult =\n | SingleEvaluationResult\n | SpilledValuesEvaluationResult;\n\nexport type SpilledValue = {\n /**\n * spillOnto is the range that the spilled value is spilled onto\n */\n spillOnto: SpreadsheetRange;\n /**\n * origin is the cell address that the spilled value is spilled from\n */\n origin: CellAddress;\n};\n\n/**\n * Function definition\n */\nexport interface FunctionDefinition {\n name: string;\n evaluate: (\n this: FormulaEvaluator,\n node: FunctionNode,\n context: EvaluationContext\n ) => FunctionEvaluationResult;\n aliases?: string[];\n}\n\n/**\n * Evaluation result\n */\nexport type EvaluationResult = {\n dependencies: Set<string>;\n} & FunctionEvaluationResult;\n\nexport type SCC = {\n id: number;\n nodes: Set<DependencyNode>; // All nodes considering soft + hard edges\n evaluationOrder: DependencyNode[]; // Flat topologically ordered list\n resolved: boolean;\n hardEdgeSCCs: Set<DependencyNode>[]; // SCCs formed by only hard edges (regular dependencies)\n};\n\nexport type SCCDAG = {\n sccList: SCC[];\n sccGraph: Map<number, Set<number>>; // Adjacency list of SCC dependencies\n};\n\nexport type EvaluationOrder = {\n evaluationOrder: Set<DependencyNode>;\n hasCycle: boolean;\n cycleNodes?: Set<DependencyNode>;\n hash: string;\n sccDAG?: SCCDAG;\n};\n\n// Conditional Styling types\nexport interface LCHColor {\n l: number; // Lightness: 0-100\n c: number; // Chroma: 0-150+\n h: number; // Hue: 0-360\n}\n\nexport interface FormulaStyleCondition {\n type: \"formula\";\n formula: string;\n color: LCHColor;\n}\n\nexport interface GradientStyleCondition {\n type: \"gradient\";\n min:\n | { type: \"lowest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n max:\n | { type: \"highest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n}\n\nexport type StyleCondition = FormulaStyleCondition | GradientStyleCondition;\n\nexport interface ConditionalStyle {\n areas: RangeAddress[];\n condition: StyleCondition;\n}\n\nexport interface DirectCellStyle {\n areas: RangeAddress[];\n style: CellStyle;\n}\n\nexport interface CellStyle {\n backgroundColor?: string; // Hex color format\n color?: string; // Text color in hex format\n fontSize?: number; // Font size in pixels\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n}\n\nexport interface CopyCellsOptions {\n /**\n * Whether this is a cut operation (clears source cells after copying)\n * @default false\n */\n cut?: boolean;\n /**\n * What to include in the copy operation.\n * - Use 'all' as shorthand for ['content', 'style', 'metadata']\n * - Use array for fine-grained control over what to copy:\n * - ['content'] - copy only values/formulas\n * - ['style'] - copy only formatting\n * - ['metadata'] - copy only metadata (rich text, links, etc.)\n * - ['content', 'style'] - copy content and formatting\n * - ['content', 'metadata'] - copy content and metadata\n * - ['style', 'metadata'] - copy formatting and metadata\n * - ['content', 'style', 'metadata'] - same as 'all'\n * @default 'all'\n */\n include?: \"all\" | (\"content\" | \"style\" | \"metadata\")[];\n /**\n * The type of the content to copy\n * value: Copy the value from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the value is 246\n * formula: Copy the formula from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the formula is =123 + 123 is copied\n * @default 'formula'\n */\n type?: \"value\" | \"formula\";\n}\n"
6
6
  ],
7
7
  "mappings": ";AA2HO,IAAK;AAAA,CAAL,CAAK,kBAAL;AAAA,EACL,wBAAO;AAAA,EACP,sBAAK;AAAA,EACL,wBAAO;AAAA,EACP,uBAAM;AAAA,EACN,uBAAM;AAAA,EACN,yBAAQ;AAAA,EACR,yBAAQ;AAAA,EACR,yBAAQ;AAAA,EACR,yBAAQ;AAAA,GATE;",
8
8
  "debugId": "0E7C5AF634572D3964756E2164756E21",
package/dist/mjs/lib.mjs CHANGED
@@ -4,8 +4,19 @@ 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 { defineApi, createApi } from "./core/api/api.mjs";
8
+ import { TableOrm } from "./core/api/table-orm.mjs";
9
+ import { CellOrm } from "./core/api/cell-orm.mjs";
10
+ import { SchemaValidationError } from "./core/managers/api-schema-manager.mjs";
11
+ import { SchemaIntegrityError } from "./core/commands.mjs";
7
12
  export {
8
- FormulaEngine
13
+ defineApi,
14
+ createApi,
15
+ TableOrm,
16
+ SchemaValidationError,
17
+ SchemaIntegrityError,
18
+ FormulaEngine,
19
+ CellOrm
9
20
  };
10
21
 
11
- //# debugId=33910997D1B8156A64756E2164756E21
22
+ //# debugId=71B0D4615CC7C29C64756E2164756E21
@@ -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"
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// API Schema exports\nexport { defineApi, createApi } from \"./core/api/api.mjs\";\nexport type { CreateApi, Declaration, Api, TableApi, CellApi } from \"./core/api/api.mjs\";\nexport { TableOrm } from \"./core/api/table-orm.mjs\";\nexport { CellOrm } from \"./core/api/cell-orm.mjs\";\nexport { SchemaValidationError } from \"./core/managers/api-schema-manager.mjs\";\nexport type { ValidationResult } from \"./core/managers/api-schema-manager.mjs\";\n\n// Command Pattern exports\nexport { SchemaIntegrityError } from \"./core/commands.mjs\";\nexport type { EngineAction, EngineCommand } from \"./core/commands.mjs\";\n"
6
6
  ],
7
- "mappings": ";AAAA;AAAA;AACA;AACA;AACA;",
8
- "debugId": "33910997D1B8156A64756E2164756E21",
7
+ "mappings": ";AAAA;AAAA;AACA;AACA;AACA;AAGA;AAEA;AACA;AACA;AAIA;",
8
+ "debugId": "71B0D4615CC7C29C64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "type": "module"
5
5
  }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * API Builder - Constructs the working API from declarations
3
+ *
4
+ * This module is responsible for creating the actual working API
5
+ * from the schema declarations when attached to a FormulaEngine.
6
+ */
7
+ import type { FormulaEngine } from "../engine";
8
+ import type { Declaration, Api } from "./api";
9
+ import type { ApiSchemaManager } from "../managers/api-schema-manager";
10
+ /**
11
+ * Build the working API surface from declarations
12
+ *
13
+ * This creates TableOrm and CellOrm instances for each declared schema
14
+ * and binds the custom methods to them.
15
+ */
16
+ export declare function buildApiFromDeclaration(engine: FormulaEngine<any, any>, declaration: Declaration, schemaManager: ApiSchemaManager): Api;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * API Helper utilities for row/object conversion and filtering
3
+ */
4
+ import type { CellAddress, SerializedCellValue, TableDefinition } from "../types";
5
+ import type { FormulaEngine } from "../engine";
6
+ export type ParseFunction<TCellMetadata = unknown> = (value: unknown, metadata: TCellMetadata) => unknown;
7
+ export type TableSchemaHeaders<TCellMetadata = unknown> = Record<string, {
8
+ parse: ParseFunction<TCellMetadata>;
9
+ index: number;
10
+ }>;
11
+ /**
12
+ * Convert a spreadsheet row to a typed object using header parsers
13
+ */
14
+ export declare function rowToObject<TItem extends Record<string, unknown>>(engine: FormulaEngine<any, any>, table: TableDefinition, rowIndex: number, headers: TableSchemaHeaders, getCellMetadata?: (cell: CellAddress) => unknown): TItem;
15
+ /**
16
+ * Convert a typed object to cell values based on headers
17
+ */
18
+ export declare function objectToRowValues<TItem extends Record<string, unknown>>(obj: TItem, headers: TableSchemaHeaders): Map<number, SerializedCellValue>;
19
+ /**
20
+ * Check if an object matches a filter predicate
21
+ */
22
+ export declare function matchesFilter<TItem extends Record<string, unknown>>(item: TItem, filter: Partial<TItem>): boolean;
23
+ /**
24
+ * Get the number of data rows in a table (excluding header)
25
+ */
26
+ export declare function getTableRowCount(engine: FormulaEngine<any, any>, table: TableDefinition): number;
27
+ /**
28
+ * Get the next empty row index for appending data
29
+ */
30
+ export declare function getNextEmptyRow(engine: FormulaEngine<any, any>, table: TableDefinition): number;
31
+ /**
32
+ * Iterate over all data rows in a table
33
+ */
34
+ export declare function iterateTableRows(engine: FormulaEngine<any, any>, table: TableDefinition): Generator<{
35
+ rowIndex: number;
36
+ isEmpty: boolean;
37
+ }>;
@@ -0,0 +1,83 @@
1
+ import type { CellAddress } from "../types";
2
+ import type { CellOrm } from "./cell-orm";
3
+ import type { TableOrm } from "./table-orm";
4
+ /**
5
+ * Define an API schema for the FormulaEngine.
6
+ *
7
+ * The returned object contains:
8
+ * - `declaration`: The schema definitions for tables and cells
9
+ * - `api`: A type-only placeholder (undefined at runtime) for TypeScript inference
10
+ *
11
+ * The actual working API is only available through `engine.api` after
12
+ * attaching the definition to a FormulaEngine instance.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const myApi = defineApi<CellMetadata>()
17
+ * .addTableApi("users", { workbookName: "wb1", tableName: "users" }, headers, methods)
18
+ * .addCellApi("config", cellAddress, parse, methods);
19
+ *
20
+ * const engine = new FormulaEngine(myApi);
21
+ * engine.api.users.get(1); // Works!
22
+ * myApi.api.users.get(1); // Error: api is undefined at runtime
23
+ * ```
24
+ */
25
+ export declare function defineApi<TCellMetadata = unknown, TCurrentApi extends Record<string, Record<string, (...args: any[]) => any>> = Record<string, Record<string, (...args: any[]) => any>>, TCurrentDeclaration extends Record<string, TableApi | CellApi> = Record<string, TableApi | CellApi>>(): CreateApi<TCellMetadata, TCurrentApi, TCurrentDeclaration>;
26
+ export declare const createApi: typeof defineApi;
27
+ type ParseFunction<TCellMetadata> = (value: unknown, metadata: TCellMetadata) => unknown;
28
+ export interface TableApi {
29
+ type: "table";
30
+ headers: Headers<unknown>;
31
+ tableName: string;
32
+ workbookName: string;
33
+ methods: TableMethods<Record<string, unknown>>;
34
+ }
35
+ export interface CellApi {
36
+ type: "cell";
37
+ cellAddress: CellAddress;
38
+ parse: (value: unknown, metadata: unknown) => unknown;
39
+ methods: CellMethods<unknown>;
40
+ }
41
+ type Headers<TCellMetadata> = Record<string, {
42
+ parse: ParseFunction<TCellMetadata>;
43
+ index: number;
44
+ }>;
45
+ type TableMethods<TItem extends Record<string, unknown>> = Record<string, (this: TableOrm<TItem>, ...args: any[]) => any>;
46
+ type CellMethods<TValue> = Record<string, (this: CellOrm<TValue>, ...args: any[]) => any>;
47
+ export type Declaration = Record<string, TableApi | CellApi>;
48
+ export type Api = Record<string, Record<string, (...args: any[]) => any>>;
49
+ export type CreateApi<TCellMetadata, TCurrentApi extends Api, TCurrentDeclaration extends Declaration> = {
50
+ addTableApi<T extends string, THeaders extends Headers<TCellMetadata>, TMethods extends TableMethods<{
51
+ [K in keyof THeaders]: ReturnType<THeaders[K]["parse"]>;
52
+ }>>(namespace: T, address: {
53
+ workbookName: string;
54
+ tableName: string;
55
+ }, headers: THeaders, methods: TMethods): CreateApi<TCellMetadata, TCurrentApi & {
56
+ [K in T]: {
57
+ [M in keyof TMethods]: (...args: Parameters<TMethods[M]>) => ReturnType<TMethods[M]>;
58
+ };
59
+ }, TCurrentDeclaration & {
60
+ [K in T]: {
61
+ type: "table";
62
+ tableName: string;
63
+ workbookName: string;
64
+ headers: THeaders;
65
+ methods: TMethods;
66
+ };
67
+ }>;
68
+ addCellApi<T extends string, TValue, TMethods extends CellMethods<TValue>>(namespace: T, cellAddress: CellAddress, parse: (value: unknown, metadata: TCellMetadata) => TValue, methods: TMethods): CreateApi<TCellMetadata, TCurrentApi & {
69
+ [K in T]: {
70
+ [M in keyof TMethods]: (...args: Parameters<TMethods[M]>) => ReturnType<TMethods[M]>;
71
+ };
72
+ }, TCurrentDeclaration & {
73
+ [K in T]: {
74
+ type: "cell";
75
+ cellAddress: CellAddress;
76
+ parse: (value: unknown, metadata: unknown) => unknown;
77
+ methods: TMethods;
78
+ };
79
+ }>;
80
+ api: TCurrentApi;
81
+ declaration: TCurrentDeclaration;
82
+ };
83
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ /**
2
+ * CellOrm - Object-Relational Mapping for single cell data
3
+ *
4
+ * Provides read/write operations for a single cell with type-safe access.
5
+ * Used as the `this` context for custom cell API methods.
6
+ */
7
+ import type { CellAddress } from "../types";
8
+ import type { FormulaEngine } from "../engine";
9
+ export type CellParseFunction<TCellMetadata, TValue> = (value: unknown, metadata: TCellMetadata) => TValue;
10
+ export declare class CellOrm<TValue, TCellMetadata = unknown> {
11
+ private engine;
12
+ private cellAddress;
13
+ private parser;
14
+ private namespace;
15
+ constructor(engine: FormulaEngine<any, any>, cellAddress: CellAddress, parser: CellParseFunction<TCellMetadata, TValue>, namespace: string);
16
+ /**
17
+ * Read the cell value and parse it using the schema's parse function
18
+ */
19
+ read(): TValue;
20
+ /**
21
+ * Write a value to the cell
22
+ * The value should be the parsed type - it will be converted to a serializable value
23
+ */
24
+ write(value: TValue): void;
25
+ /**
26
+ * Get the cell address
27
+ */
28
+ getAddress(): CellAddress;
29
+ }