@ricsam/formula-engine 0.0.17 → 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 (101) 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 +3 -5
  12. package/dist/cjs/core/autofill-utils.cjs.map +3 -3
  13. package/dist/cjs/core/commands/command-executor.cjs +140 -0
  14. package/dist/cjs/core/commands/command-executor.cjs.map +10 -0
  15. package/dist/cjs/core/commands/content-commands.cjs +574 -0
  16. package/dist/cjs/core/commands/content-commands.cjs.map +10 -0
  17. package/dist/cjs/core/commands/index.cjs +95 -0
  18. package/dist/cjs/core/commands/index.cjs.map +10 -0
  19. package/dist/cjs/core/commands/metadata-commands.cjs +150 -0
  20. package/dist/cjs/core/commands/metadata-commands.cjs.map +10 -0
  21. package/dist/cjs/core/commands/named-expression-commands.cjs +238 -0
  22. package/dist/cjs/core/commands/named-expression-commands.cjs.map +10 -0
  23. package/dist/cjs/core/commands/structure-commands.cjs +495 -0
  24. package/dist/cjs/core/commands/structure-commands.cjs.map +10 -0
  25. package/dist/cjs/core/commands/style-commands.cjs +219 -0
  26. package/dist/cjs/core/commands/style-commands.cjs.map +10 -0
  27. package/dist/cjs/core/commands/table-commands.cjs +226 -0
  28. package/dist/cjs/core/commands/table-commands.cjs.map +10 -0
  29. package/dist/cjs/core/commands/types.cjs +72 -0
  30. package/dist/cjs/core/commands/types.cjs.map +10 -0
  31. package/dist/cjs/core/engine.cjs +159 -296
  32. package/dist/cjs/core/engine.cjs.map +3 -3
  33. package/dist/cjs/core/managers/api-schema-manager.cjs +304 -0
  34. package/dist/cjs/core/managers/api-schema-manager.cjs.map +10 -0
  35. package/dist/cjs/core/managers/copy-manager.cjs +1 -2
  36. package/dist/cjs/core/managers/copy-manager.cjs.map +3 -3
  37. package/dist/cjs/core/types.cjs.map +2 -2
  38. package/dist/cjs/lib.cjs +13 -2
  39. package/dist/cjs/lib.cjs.map +3 -3
  40. package/dist/cjs/package.json +1 -1
  41. package/dist/mjs/core/api/api-builder.mjs +37 -0
  42. package/dist/mjs/core/api/api-builder.mjs.map +10 -0
  43. package/dist/mjs/core/api/api-helpers.mjs +161 -0
  44. package/dist/mjs/core/api/api-helpers.mjs.map +10 -0
  45. package/dist/mjs/core/api/api.mjs +35 -0
  46. package/dist/mjs/core/api/api.mjs.map +10 -0
  47. package/dist/mjs/core/api/cell-orm.mjs +49 -0
  48. package/dist/mjs/core/api/cell-orm.mjs.map +10 -0
  49. package/dist/mjs/core/api/table-orm.mjs +148 -0
  50. package/dist/mjs/core/api/table-orm.mjs.map +10 -0
  51. package/dist/mjs/core/autofill-utils.mjs +3 -5
  52. package/dist/mjs/core/autofill-utils.mjs.map +3 -3
  53. package/dist/mjs/core/commands/command-executor.mjs +109 -0
  54. package/dist/mjs/core/commands/command-executor.mjs.map +10 -0
  55. package/dist/mjs/core/commands/content-commands.mjs +544 -0
  56. package/dist/mjs/core/commands/content-commands.mjs.map +10 -0
  57. package/dist/mjs/core/commands/index.mjs +87 -0
  58. package/dist/mjs/core/commands/index.mjs.map +10 -0
  59. package/dist/mjs/core/commands/metadata-commands.mjs +120 -0
  60. package/dist/mjs/core/commands/metadata-commands.mjs.map +10 -0
  61. package/dist/mjs/core/commands/named-expression-commands.mjs +208 -0
  62. package/dist/mjs/core/commands/named-expression-commands.mjs.map +10 -0
  63. package/dist/mjs/core/commands/structure-commands.mjs +465 -0
  64. package/dist/mjs/core/commands/structure-commands.mjs.map +10 -0
  65. package/dist/mjs/core/commands/style-commands.mjs +189 -0
  66. package/dist/mjs/core/commands/style-commands.mjs.map +10 -0
  67. package/dist/mjs/core/commands/table-commands.mjs +196 -0
  68. package/dist/mjs/core/commands/table-commands.mjs.map +10 -0
  69. package/dist/mjs/core/commands/types.mjs +42 -0
  70. package/dist/mjs/core/commands/types.mjs.map +10 -0
  71. package/dist/mjs/core/engine.mjs +194 -296
  72. package/dist/mjs/core/engine.mjs.map +3 -3
  73. package/dist/mjs/core/managers/api-schema-manager.mjs +274 -0
  74. package/dist/mjs/core/managers/api-schema-manager.mjs.map +10 -0
  75. package/dist/mjs/core/managers/copy-manager.mjs +1 -2
  76. package/dist/mjs/core/managers/copy-manager.mjs.map +3 -3
  77. package/dist/mjs/core/types.mjs.map +2 -2
  78. package/dist/mjs/lib.mjs +13 -2
  79. package/dist/mjs/lib.mjs.map +3 -3
  80. package/dist/mjs/package.json +1 -1
  81. package/dist/types/core/api/api-builder.d.ts +16 -0
  82. package/dist/types/core/api/api-helpers.d.ts +37 -0
  83. package/dist/types/core/api/api.d.ts +83 -0
  84. package/dist/types/core/api/api.type-test.d.ts +1 -0
  85. package/dist/types/core/api/cell-orm.d.ts +29 -0
  86. package/dist/types/core/api/table-orm.d.ts +46 -0
  87. package/dist/types/core/autofill-utils.d.ts +2 -9
  88. package/dist/types/core/commands/command-executor.d.ts +83 -0
  89. package/dist/types/core/commands/content-commands.d.ts +142 -0
  90. package/dist/types/core/commands/index.d.ts +16 -0
  91. package/dist/types/core/commands/metadata-commands.d.ts +55 -0
  92. package/dist/types/core/commands/named-expression-commands.d.ts +115 -0
  93. package/dist/types/core/commands/structure-commands.d.ts +132 -0
  94. package/dist/types/core/commands/style-commands.d.ts +76 -0
  95. package/dist/types/core/commands/table-commands.d.ts +104 -0
  96. package/dist/types/core/commands/types.d.ts +114 -0
  97. package/dist/types/core/engine.d.ts +130 -26
  98. package/dist/types/core/managers/api-schema-manager.d.ts +121 -0
  99. package/dist/types/core/types.d.ts +1 -1
  100. package/dist/types/lib.d.ts +8 -0
  101. package/package.json +1 -1
@@ -0,0 +1,67 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+
29
+ // src/core/api/api-builder.ts
30
+ var exports_api_builder = {};
31
+ __export(exports_api_builder, {
32
+ buildApiFromDeclaration: () => buildApiFromDeclaration
33
+ });
34
+ module.exports = __toCommonJS(exports_api_builder);
35
+ var import_table_orm = require("./table-orm.cjs");
36
+ var import_cell_orm = require("./cell-orm.cjs");
37
+ function buildApiFromDeclaration(engine, declaration, schemaManager) {
38
+ const api = {};
39
+ for (const [namespace, def] of Object.entries(declaration)) {
40
+ if (def.type === "table") {
41
+ api[namespace] = buildTableApi(engine, namespace, def, schemaManager);
42
+ } else if (def.type === "cell") {
43
+ api[namespace] = buildCellApi(engine, namespace, def, schemaManager);
44
+ }
45
+ }
46
+ return api;
47
+ }
48
+ function buildTableApi(engine, namespace, def, schemaManager) {
49
+ schemaManager.registerTableSchema(namespace, def.workbookName, def.tableName, def.headers);
50
+ const orm = new import_table_orm.TableOrm(engine, def.workbookName, def.tableName, def.headers, namespace);
51
+ const boundMethods = {};
52
+ for (const [methodName, methodFn] of Object.entries(def.methods)) {
53
+ boundMethods[methodName] = methodFn.bind(orm);
54
+ }
55
+ return boundMethods;
56
+ }
57
+ function buildCellApi(engine, namespace, def, schemaManager) {
58
+ schemaManager.registerCellSchema(namespace, def.cellAddress, def.parse);
59
+ const orm = new import_cell_orm.CellOrm(engine, def.cellAddress, def.parse, namespace);
60
+ const boundMethods = {};
61
+ for (const [methodName, methodFn] of Object.entries(def.methods)) {
62
+ boundMethods[methodName] = methodFn.bind(orm);
63
+ }
64
+ return boundMethods;
65
+ }
66
+
67
+ //# debugId=1A339C89282699D664756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/core/api/api-builder.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * API Builder - Constructs the working API from declarations\n *\n * This module is responsible for creating the actual working API\n * from the schema declarations when attached to a FormulaEngine.\n */\n\nimport type { FormulaEngine } from \"../engine.cjs\";\nimport type { Declaration, TableApi, CellApi, Api } from \"./api.cjs\";\nimport { TableOrm } from \"./table-orm.cjs\";\nimport { CellOrm } from \"./cell-orm.cjs\";\nimport type { ApiSchemaManager } from \"../managers/api-schema-manager.cjs\";\n\n/**\n * Build the working API surface from declarations\n *\n * This creates TableOrm and CellOrm instances for each declared schema\n * and binds the custom methods to them.\n */\nexport function buildApiFromDeclaration(\n engine: FormulaEngine<any, any>,\n declaration: Declaration,\n schemaManager: ApiSchemaManager\n): Api {\n const api: Api = {};\n\n for (const [namespace, def] of Object.entries(declaration)) {\n if (def.type === \"table\") {\n api[namespace] = buildTableApi(engine, namespace, def, schemaManager);\n } else if (def.type === \"cell\") {\n api[namespace] = buildCellApi(engine, namespace, def, schemaManager);\n }\n }\n\n return api;\n}\n\n/**\n * Build API methods for a table schema\n */\nfunction buildTableApi(\n engine: FormulaEngine<any, any>,\n namespace: string,\n def: TableApi,\n schemaManager: ApiSchemaManager\n): Record<string, (...args: any[]) => any> {\n // Register the schema with the schema manager\n schemaManager.registerTableSchema(\n namespace,\n def.workbookName,\n def.tableName,\n def.headers\n );\n\n // Create the ORM instance\n const orm = new TableOrm(\n engine,\n def.workbookName,\n def.tableName,\n def.headers,\n namespace\n );\n\n // Bind all custom methods to the ORM instance\n const boundMethods: Record<string, (...args: any[]) => any> = {};\n\n for (const [methodName, methodFn] of Object.entries(def.methods)) {\n boundMethods[methodName] = methodFn.bind(orm);\n }\n\n return boundMethods;\n}\n\n/**\n * Build API methods for a cell schema\n */\nfunction buildCellApi(\n engine: FormulaEngine<any, any>,\n namespace: string,\n def: CellApi,\n schemaManager: ApiSchemaManager\n): Record<string, (...args: any[]) => any> {\n // Register the schema with the schema manager\n schemaManager.registerCellSchema(namespace, def.cellAddress, def.parse);\n\n // Create the ORM instance\n const orm = new CellOrm(engine, def.cellAddress, def.parse, namespace);\n\n // Bind all custom methods to the ORM instance\n const boundMethods: Record<string, (...args: any[]) => any> = {};\n\n for (const [methodName, methodFn] of Object.entries(def.methods)) {\n boundMethods[methodName] = methodFn.bind(orm);\n }\n\n return boundMethods;\n}\n\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASyB,IAAzB;AACwB,IAAxB;AASO,SAAS,uBAAuB,CACrC,QACA,aACA,eACK;AAAA,EACL,MAAM,MAAW,CAAC;AAAA,EAElB,YAAY,WAAW,QAAQ,OAAO,QAAQ,WAAW,GAAG;AAAA,IAC1D,IAAI,IAAI,SAAS,SAAS;AAAA,MACxB,IAAI,aAAa,cAAc,QAAQ,WAAW,KAAK,aAAa;AAAA,IACtE,EAAO,SAAI,IAAI,SAAS,QAAQ;AAAA,MAC9B,IAAI,aAAa,aAAa,QAAQ,WAAW,KAAK,aAAa;AAAA,IACrE;AAAA,EACF;AAAA,EAEA,OAAO;AAAA;AAMT,SAAS,aAAa,CACpB,QACA,WACA,KACA,eACyC;AAAA,EAEzC,cAAc,oBACZ,WACA,IAAI,cACJ,IAAI,WACJ,IAAI,OACN;AAAA,EAGA,MAAM,MAAM,IAAI,0BACd,QACA,IAAI,cACJ,IAAI,WACJ,IAAI,SACJ,SACF;AAAA,EAGA,MAAM,eAAwD,CAAC;AAAA,EAE/D,YAAY,YAAY,aAAa,OAAO,QAAQ,IAAI,OAAO,GAAG;AAAA,IAChE,aAAa,cAAc,SAAS,KAAK,GAAG;AAAA,EAC9C;AAAA,EAEA,OAAO;AAAA;AAMT,SAAS,YAAY,CACnB,QACA,WACA,KACA,eACyC;AAAA,EAEzC,cAAc,mBAAmB,WAAW,IAAI,aAAa,IAAI,KAAK;AAAA,EAGtE,MAAM,MAAM,IAAI,wBAAQ,QAAQ,IAAI,aAAa,IAAI,OAAO,SAAS;AAAA,EAGrE,MAAM,eAAwD,CAAC;AAAA,EAE/D,YAAY,YAAY,aAAa,OAAO,QAAQ,IAAI,OAAO,GAAG;AAAA,IAChE,aAAa,cAAc,SAAS,KAAK,GAAG;AAAA,EAC9C;AAAA,EAEA,OAAO;AAAA;",
8
+ "debugId": "1A339C89282699D664756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,191 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+
29
+ // src/core/api/api-helpers.ts
30
+ var exports_api_helpers = {};
31
+ __export(exports_api_helpers, {
32
+ rowToObject: () => rowToObject,
33
+ objectToRowValues: () => objectToRowValues,
34
+ matchesFilter: () => matchesFilter,
35
+ iterateTableRows: () => iterateTableRows,
36
+ getTableRowCount: () => getTableRowCount,
37
+ getNextEmptyRow: () => getNextEmptyRow
38
+ });
39
+ module.exports = __toCommonJS(exports_api_helpers);
40
+ function rowToObject(engine, table, rowIndex, headers, getCellMetadata) {
41
+ const result = {};
42
+ for (const [columnName, header] of Object.entries(headers)) {
43
+ const cellAddress = {
44
+ workbookName: table.workbookName,
45
+ sheetName: table.sheetName,
46
+ colIndex: table.start.colIndex + header.index,
47
+ rowIndex
48
+ };
49
+ const value = engine.getCellValue(cellAddress);
50
+ const metadata = getCellMetadata ? getCellMetadata(cellAddress) : undefined;
51
+ result[columnName] = header.parse(value, metadata);
52
+ }
53
+ return result;
54
+ }
55
+ function objectToRowValues(obj, headers) {
56
+ const values = new Map;
57
+ for (const [columnName, header] of Object.entries(headers)) {
58
+ if (columnName in obj) {
59
+ const value = obj[columnName];
60
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
61
+ values.set(header.index, value);
62
+ } else if (value === null || value === undefined) {
63
+ values.set(header.index, undefined);
64
+ } else {
65
+ values.set(header.index, String(value));
66
+ }
67
+ }
68
+ }
69
+ return values;
70
+ }
71
+ function matchesFilter(item, filter) {
72
+ for (const [key, value] of Object.entries(filter)) {
73
+ if (item[key] !== value) {
74
+ return false;
75
+ }
76
+ }
77
+ return true;
78
+ }
79
+ function getTableRowCount(engine, table) {
80
+ if (table.endRow.type === "infinity") {
81
+ let count = 0;
82
+ let emptyRowStreak = 0;
83
+ const maxEmptyRows = 10;
84
+ for (let row = table.start.rowIndex + 1;emptyRowStreak < maxEmptyRows; row++) {
85
+ let hasContent = false;
86
+ for (let col = 0;col < table.headers.size; col++) {
87
+ const cellAddress = {
88
+ workbookName: table.workbookName,
89
+ sheetName: table.sheetName,
90
+ colIndex: table.start.colIndex + col,
91
+ rowIndex: row
92
+ };
93
+ const value = engine.getCellValue(cellAddress);
94
+ if (value !== "" && value !== undefined) {
95
+ hasContent = true;
96
+ break;
97
+ }
98
+ }
99
+ if (hasContent) {
100
+ count++;
101
+ emptyRowStreak = 0;
102
+ } else {
103
+ emptyRowStreak++;
104
+ }
105
+ }
106
+ return count;
107
+ } else {
108
+ return table.endRow.value - table.start.rowIndex;
109
+ }
110
+ }
111
+ function getNextEmptyRow(engine, table) {
112
+ const dataStartRow = table.start.rowIndex + 1;
113
+ if (table.endRow.type === "infinity") {
114
+ let emptyRowStreak = 0;
115
+ const maxEmptyRows = 10;
116
+ for (let row = dataStartRow;; row++) {
117
+ let hasContent = false;
118
+ for (let col = 0;col < table.headers.size; col++) {
119
+ const cellAddress = {
120
+ workbookName: table.workbookName,
121
+ sheetName: table.sheetName,
122
+ colIndex: table.start.colIndex + col,
123
+ rowIndex: row
124
+ };
125
+ const value = engine.getCellValue(cellAddress);
126
+ if (value !== "" && value !== undefined) {
127
+ hasContent = true;
128
+ break;
129
+ }
130
+ }
131
+ if (!hasContent) {
132
+ return row;
133
+ }
134
+ emptyRowStreak = hasContent ? 0 : emptyRowStreak + 1;
135
+ if (emptyRowStreak >= maxEmptyRows) {
136
+ return row - maxEmptyRows + 1;
137
+ }
138
+ }
139
+ } else {
140
+ return table.endRow.value + 1;
141
+ }
142
+ }
143
+ function* iterateTableRows(engine, table) {
144
+ const dataStartRow = table.start.rowIndex + 1;
145
+ if (table.endRow.type === "infinity") {
146
+ let emptyRowStreak = 0;
147
+ const maxEmptyRows = 10;
148
+ for (let row = dataStartRow;emptyRowStreak < maxEmptyRows; row++) {
149
+ let hasContent = false;
150
+ for (let col = 0;col < table.headers.size; col++) {
151
+ const cellAddress = {
152
+ workbookName: table.workbookName,
153
+ sheetName: table.sheetName,
154
+ colIndex: table.start.colIndex + col,
155
+ rowIndex: row
156
+ };
157
+ const value = engine.getCellValue(cellAddress);
158
+ if (value !== "" && value !== undefined) {
159
+ hasContent = true;
160
+ break;
161
+ }
162
+ }
163
+ if (hasContent) {
164
+ emptyRowStreak = 0;
165
+ yield { rowIndex: row, isEmpty: false };
166
+ } else {
167
+ emptyRowStreak++;
168
+ }
169
+ }
170
+ } else {
171
+ for (let row = dataStartRow;row <= table.endRow.value; row++) {
172
+ let hasContent = false;
173
+ for (let col = 0;col < table.headers.size; col++) {
174
+ const cellAddress = {
175
+ workbookName: table.workbookName,
176
+ sheetName: table.sheetName,
177
+ colIndex: table.start.colIndex + col,
178
+ rowIndex: row
179
+ };
180
+ const value = engine.getCellValue(cellAddress);
181
+ if (value !== "" && value !== undefined) {
182
+ hasContent = true;
183
+ break;
184
+ }
185
+ }
186
+ yield { rowIndex: row, isEmpty: !hasContent };
187
+ }
188
+ }
189
+ }
190
+
191
+ //# debugId=3AEF0EFABA7782E064756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/core/api/api-helpers.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * API Helper utilities for row/object conversion and filtering\n */\n\nimport type { CellAddress, SerializedCellValue, TableDefinition } from \"../types.cjs\";\nimport type { FormulaEngine } from \"../engine.cjs\";\n\nexport type ParseFunction<TCellMetadata = unknown> = (\n value: unknown,\n metadata: TCellMetadata\n) => unknown;\n\nexport type TableSchemaHeaders<TCellMetadata = unknown> = Record<\n string,\n {\n parse: ParseFunction<TCellMetadata>;\n index: number;\n }\n>;\n\n/**\n * Convert a spreadsheet row to a typed object using header parsers\n */\nexport function rowToObject<TItem extends Record<string, unknown>>(\n engine: FormulaEngine<any, any>,\n table: TableDefinition,\n rowIndex: number,\n headers: TableSchemaHeaders,\n getCellMetadata?: (cell: CellAddress) => unknown\n): TItem {\n const result: Record<string, unknown> = {};\n\n for (const [columnName, header] of Object.entries(headers)) {\n const cellAddress: CellAddress = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n colIndex: table.start.colIndex + header.index,\n rowIndex,\n };\n\n const value = engine.getCellValue(cellAddress);\n const metadata = getCellMetadata ? getCellMetadata(cellAddress) : undefined;\n\n // Parse the value using the column's parse function\n result[columnName] = header.parse(value, metadata);\n }\n\n return result as TItem;\n}\n\n/**\n * Convert a typed object to cell values based on headers\n */\nexport function objectToRowValues<TItem extends Record<string, unknown>>(\n obj: TItem,\n headers: TableSchemaHeaders\n): Map<number, SerializedCellValue> {\n const values = new Map<number, SerializedCellValue>();\n\n for (const [columnName, header] of Object.entries(headers)) {\n if (columnName in obj) {\n const value = obj[columnName];\n // Convert to serializable value\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\"\n ) {\n values.set(header.index, value);\n } else if (value === null || value === undefined) {\n values.set(header.index, undefined);\n } else {\n // For complex types, convert to string\n values.set(header.index, String(value));\n }\n }\n }\n\n return values;\n}\n\n/**\n * Check if an object matches a filter predicate\n */\nexport function matchesFilter<TItem extends Record<string, unknown>>(\n item: TItem,\n filter: Partial<TItem>\n): boolean {\n for (const [key, value] of Object.entries(filter)) {\n if (item[key] !== value) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Get the number of data rows in a table (excluding header)\n */\nexport function getTableRowCount(\n engine: FormulaEngine<any, any>,\n table: TableDefinition\n): number {\n if (table.endRow.type === \"infinity\") {\n // For infinite tables, count non-empty rows\n // Start from data row (after header)\n let count = 0;\n let emptyRowStreak = 0;\n const maxEmptyRows = 10; // Stop after 10 consecutive empty rows\n\n for (let row = table.start.rowIndex + 1; emptyRowStreak < maxEmptyRows; row++) {\n let hasContent = false;\n\n for (let col = 0; col < table.headers.size; col++) {\n const cellAddress: CellAddress = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n colIndex: table.start.colIndex + col,\n rowIndex: row,\n };\n\n const value = engine.getCellValue(cellAddress);\n if (value !== \"\" && value !== undefined) {\n hasContent = true;\n break;\n }\n }\n\n if (hasContent) {\n count++;\n emptyRowStreak = 0;\n } else {\n emptyRowStreak++;\n }\n }\n\n return count;\n } else {\n // For finite tables, calculate from endRow\n return table.endRow.value - table.start.rowIndex;\n }\n}\n\n/**\n * Get the next empty row index for appending data\n */\nexport function getNextEmptyRow(\n engine: FormulaEngine<any, any>,\n table: TableDefinition\n): number {\n const dataStartRow = table.start.rowIndex + 1;\n\n if (table.endRow.type === \"infinity\") {\n // Find first empty row\n let emptyRowStreak = 0;\n const maxEmptyRows = 10;\n\n for (let row = dataStartRow; ; row++) {\n let hasContent = false;\n\n for (let col = 0; col < table.headers.size; col++) {\n const cellAddress: CellAddress = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n colIndex: table.start.colIndex + col,\n rowIndex: row,\n };\n\n const value = engine.getCellValue(cellAddress);\n if (value !== \"\" && value !== undefined) {\n hasContent = true;\n break;\n }\n }\n\n if (!hasContent) {\n return row;\n }\n\n emptyRowStreak = hasContent ? 0 : emptyRowStreak + 1;\n if (emptyRowStreak >= maxEmptyRows) {\n return row - maxEmptyRows + 1;\n }\n }\n } else {\n // For finite tables, return the row after the last data row\n return table.endRow.value + 1;\n }\n}\n\n/**\n * Iterate over all data rows in a table\n */\nexport function* iterateTableRows(\n engine: FormulaEngine<any, any>,\n table: TableDefinition\n): Generator<{ rowIndex: number; isEmpty: boolean }> {\n const dataStartRow = table.start.rowIndex + 1;\n\n if (table.endRow.type === \"infinity\") {\n let emptyRowStreak = 0;\n const maxEmptyRows = 10;\n\n for (let row = dataStartRow; emptyRowStreak < maxEmptyRows; row++) {\n let hasContent = false;\n\n for (let col = 0; col < table.headers.size; col++) {\n const cellAddress: CellAddress = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n colIndex: table.start.colIndex + col,\n rowIndex: row,\n };\n\n const value = engine.getCellValue(cellAddress);\n if (value !== \"\" && value !== undefined) {\n hasContent = true;\n break;\n }\n }\n\n if (hasContent) {\n emptyRowStreak = 0;\n yield { rowIndex: row, isEmpty: false };\n } else {\n emptyRowStreak++;\n // Don't yield empty rows at the end\n }\n }\n } else {\n for (let row = dataStartRow; row <= table.endRow.value; row++) {\n let hasContent = false;\n\n for (let col = 0; col < table.headers.size; col++) {\n const cellAddress: CellAddress = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n colIndex: table.start.colIndex + col,\n rowIndex: row,\n };\n\n const value = engine.getCellValue(cellAddress);\n if (value !== \"\" && value !== undefined) {\n hasContent = true;\n break;\n }\n }\n\n yield { rowIndex: row, isEmpty: !hasContent };\n }\n }\n}\n\n"
6
+ ],
7
+ "mappings": "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",
8
+ "debugId": "3AEF0EFABA7782E064756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,65 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+
29
+ // src/core/api/api.ts
30
+ var exports_api = {};
31
+ __export(exports_api, {
32
+ defineApi: () => defineApi,
33
+ createApi: () => createApi
34
+ });
35
+ module.exports = __toCommonJS(exports_api);
36
+ function defineApi() {
37
+ const declaration = {};
38
+ const builder = {
39
+ addTableApi(namespace, address, headers, methods) {
40
+ declaration[namespace] = {
41
+ type: "table",
42
+ tableName: address.tableName,
43
+ workbookName: address.workbookName,
44
+ headers,
45
+ methods
46
+ };
47
+ return builder;
48
+ },
49
+ addCellApi(namespace, cellAddress, parse, methods) {
50
+ declaration[namespace] = {
51
+ type: "cell",
52
+ cellAddress,
53
+ parse,
54
+ methods
55
+ };
56
+ return builder;
57
+ },
58
+ api: undefined,
59
+ declaration
60
+ };
61
+ return builder;
62
+ }
63
+ var createApi = defineApi;
64
+
65
+ //# debugId=00202A4557ACD94664756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/core/api/api.ts"],
4
+ "sourcesContent": [
5
+ "import type { CellAddress } from \"../types.cjs\";\nimport type { CellOrm } from \"./cell-orm.cjs\";\nimport type { TableOrm } from \"./table-orm.cjs\";\n\n/**\n * Define an API schema for the FormulaEngine.\n *\n * The returned object contains:\n * - `declaration`: The schema definitions for tables and cells\n * - `api`: A type-only placeholder (undefined at runtime) for TypeScript inference\n *\n * The actual working API is only available through `engine.api` after\n * attaching the definition to a FormulaEngine instance.\n *\n * @example\n * ```typescript\n * const myApi = defineApi<CellMetadata>()\n * .addTableApi(\"users\", { workbookName: \"wb1\", tableName: \"users\" }, headers, methods)\n * .addCellApi(\"config\", cellAddress, parse, methods);\n *\n * const engine = new FormulaEngine(myApi);\n * engine.api.users.get(1); // Works!\n * myApi.api.users.get(1); // Error: api is undefined at runtime\n * ```\n */\nexport function defineApi<\n TCellMetadata = unknown,\n TCurrentApi extends Record<\n string,\n Record<string, (...args: any[]) => any>\n > = Record<string, Record<string, (...args: any[]) => any>>,\n TCurrentDeclaration extends Record<string, TableApi | CellApi> = Record<\n string,\n TableApi | CellApi\n >\n>(): CreateApi<TCellMetadata, TCurrentApi, TCurrentDeclaration> {\n const declaration: Record<string, TableApi | CellApi> = {};\n\n const builder: CreateApi<TCellMetadata, TCurrentApi, TCurrentDeclaration> = {\n addTableApi(namespace, address, headers, methods) {\n declaration[namespace] = {\n type: \"table\",\n tableName: address.tableName,\n workbookName: address.workbookName,\n headers: headers as any,\n methods: methods as any,\n };\n return builder as any;\n },\n\n addCellApi(namespace, cellAddress, parse, methods) {\n declaration[namespace] = {\n type: \"cell\",\n cellAddress,\n parse: parse as any,\n methods: methods as any,\n };\n return builder as any;\n },\n\n // api is undefined at runtime - it only exists for TypeScript type inference\n // The actual working API is built by the FormulaEngine constructor\n api: undefined as any as TCurrentApi,\n\n declaration: declaration as TCurrentDeclaration,\n };\n\n return builder;\n}\n\n// Keep createApi as an alias for backwards compatibility\nexport const createApi = defineApi;\n\ntype ParseFunction<TCellMetadata> = (\n value: unknown,\n metadata: TCellMetadata\n) => unknown;\n\nexport interface TableApi {\n type: \"table\";\n headers: Headers<unknown>;\n tableName: string;\n workbookName: string;\n methods: TableMethods<Record<string, unknown>>;\n}\n\nexport interface CellApi {\n type: \"cell\";\n cellAddress: CellAddress;\n parse: (value: unknown, metadata: unknown) => unknown;\n methods: CellMethods<unknown>;\n}\n\ntype Headers<TCellMetadata> = Record<\n string,\n {\n parse: ParseFunction<TCellMetadata>;\n index: number;\n }\n>;\n\ntype TableMethods<TItem extends Record<string, unknown>> = Record<\n string,\n (this: TableOrm<TItem>, ...args: any[]) => any\n>;\n\ntype CellMethods<TValue> = Record<\n string,\n (this: CellOrm<TValue>, ...args: any[]) => any\n>;\n\nexport type Declaration = Record<string, TableApi | CellApi>;\nexport type Api = Record<string, Record<string, (...args: any[]) => any>>;\n\nexport type CreateApi<\n TCellMetadata,\n TCurrentApi extends Api,\n TCurrentDeclaration extends Declaration\n> = {\n addTableApi<\n T extends string,\n THeaders extends Headers<TCellMetadata>,\n TMethods extends TableMethods<{\n [K in keyof THeaders]: ReturnType<THeaders[K][\"parse\"]>;\n }>\n >(\n namespace: T,\n address: { workbookName: string; tableName: string },\n headers: THeaders,\n methods: TMethods\n ): CreateApi<\n TCellMetadata,\n TCurrentApi & {\n [K in T]: {\n [M in keyof TMethods]: (\n ...args: Parameters<TMethods[M]>\n ) => ReturnType<TMethods[M]>;\n };\n },\n TCurrentDeclaration & {\n [K in T]: {\n type: \"table\";\n tableName: string;\n workbookName: string;\n headers: THeaders;\n methods: TMethods;\n };\n }\n >;\n addCellApi<T extends string, TValue, TMethods extends CellMethods<TValue>>(\n namespace: T,\n cellAddress: CellAddress,\n parse: (value: unknown, metadata: TCellMetadata) => TValue,\n methods: TMethods\n ): CreateApi<\n TCellMetadata,\n TCurrentApi & {\n [K in T]: {\n [M in keyof TMethods]: (\n ...args: Parameters<TMethods[M]>\n ) => ReturnType<TMethods[M]>;\n };\n },\n TCurrentDeclaration & {\n [K in T]: {\n type: \"cell\";\n cellAddress: CellAddress;\n parse: (value: unknown, metadata: unknown) => unknown;\n methods: TMethods;\n };\n }\n >;\n api: TCurrentApi;\n declaration: TCurrentDeclaration;\n};\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,SAAS,SAUf,GAA+D;AAAA,EAC9D,MAAM,cAAkD,CAAC;AAAA,EAEzD,MAAM,UAAsE;AAAA,IAC1E,WAAW,CAAC,WAAW,SAAS,SAAS,SAAS;AAAA,MAChD,YAAY,aAAa;AAAA,QACvB,MAAM;AAAA,QACN,WAAW,QAAQ;AAAA,QACnB,cAAc,QAAQ;AAAA,QACtB;AAAA,QACA;AAAA,MACF;AAAA,MACA,OAAO;AAAA;AAAA,IAGT,UAAU,CAAC,WAAW,aAAa,OAAO,SAAS;AAAA,MACjD,YAAY,aAAa;AAAA,QACvB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA,OAAO;AAAA;AAAA,IAKT,KAAK;AAAA,IAEL;AAAA,EACF;AAAA,EAEA,OAAO;AAAA;AAIF,IAAM,YAAY;",
8
+ "debugId": "00202A4557ACD94664756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,80 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+
29
+ // src/core/api/cell-orm.ts
30
+ var exports_cell_orm = {};
31
+ __export(exports_cell_orm, {
32
+ CellOrm: () => CellOrm
33
+ });
34
+ module.exports = __toCommonJS(exports_cell_orm);
35
+
36
+ class CellOrm {
37
+ engine;
38
+ cellAddress;
39
+ parser;
40
+ namespace;
41
+ constructor(engine, cellAddress, parser, namespace) {
42
+ this.engine = engine;
43
+ this.cellAddress = cellAddress;
44
+ this.parser = parser;
45
+ this.namespace = namespace;
46
+ }
47
+ read() {
48
+ const value = this.engine.getCellValue(this.cellAddress);
49
+ const metadata = this.engine.getCellMetadata(this.cellAddress);
50
+ return this.parser(value, metadata);
51
+ }
52
+ write(value) {
53
+ let serializedValue;
54
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
55
+ serializedValue = value;
56
+ } else if (value === null || value === undefined) {
57
+ serializedValue = undefined;
58
+ } else if (typeof value === "object") {
59
+ const obj = value;
60
+ if ("value" in obj) {
61
+ const innerValue = obj.value;
62
+ if (typeof innerValue === "string" || typeof innerValue === "number" || typeof innerValue === "boolean") {
63
+ serializedValue = innerValue;
64
+ } else {
65
+ serializedValue = String(innerValue);
66
+ }
67
+ } else {
68
+ serializedValue = JSON.stringify(value);
69
+ }
70
+ } else {
71
+ serializedValue = String(value);
72
+ }
73
+ this.engine.setCellContent(this.cellAddress, serializedValue);
74
+ }
75
+ getAddress() {
76
+ return { ...this.cellAddress };
77
+ }
78
+ }
79
+
80
+ //# debugId=65719C8FCB16AB7864756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/core/api/cell-orm.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * CellOrm - Object-Relational Mapping for single cell data\n *\n * Provides read/write operations for a single cell with type-safe access.\n * Used as the `this` context for custom cell API methods.\n */\n\nimport type { CellAddress, SerializedCellValue } from \"../types.cjs\";\nimport type { FormulaEngine } from \"../engine.cjs\";\n\nexport type CellParseFunction<TCellMetadata, TValue> = (\n value: unknown,\n metadata: TCellMetadata\n) => TValue;\n\nexport class CellOrm<TValue, TCellMetadata = unknown> {\n constructor(\n private engine: FormulaEngine<any, any>,\n private cellAddress: CellAddress,\n private parser: CellParseFunction<TCellMetadata, TValue>,\n private namespace: string\n ) {}\n\n /**\n * Read the cell value and parse it using the schema's parse function\n */\n read(): TValue {\n const value = this.engine.getCellValue(this.cellAddress);\n const metadata = this.engine.getCellMetadata(this.cellAddress) as TCellMetadata;\n return this.parser(value, metadata);\n }\n\n /**\n * Write a value to the cell\n * The value should be the parsed type - it will be converted to a serializable value\n */\n write(value: TValue): void {\n // Convert TValue to SerializedCellValue\n let serializedValue: SerializedCellValue;\n\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\"\n ) {\n serializedValue = value;\n } else if (value === null || value === undefined) {\n serializedValue = undefined;\n } else if (typeof value === \"object\") {\n // For objects, we need to extract the actual cell value\n // This assumes the parsed type might be an object with a 'value' property\n const obj = value as Record<string, unknown>;\n if (\"value\" in obj) {\n const innerValue = obj.value;\n if (\n typeof innerValue === \"string\" ||\n typeof innerValue === \"number\" ||\n typeof innerValue === \"boolean\"\n ) {\n serializedValue = innerValue;\n } else {\n serializedValue = String(innerValue);\n }\n } else {\n // Fallback: convert to string\n serializedValue = JSON.stringify(value);\n }\n } else {\n serializedValue = String(value);\n }\n\n this.engine.setCellContent(this.cellAddress, serializedValue);\n }\n\n /**\n * Get the cell address\n */\n getAddress(): CellAddress {\n return { ...this.cellAddress };\n }\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeO,MAAM,QAAyC;AAAA,EAE1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAJV,WAAW,CACD,QACA,aACA,QACA,WACR;AAAA,IAJQ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAMV,IAAI,GAAW;AAAA,IACb,MAAM,QAAQ,KAAK,OAAO,aAAa,KAAK,WAAW;AAAA,IACvD,MAAM,WAAW,KAAK,OAAO,gBAAgB,KAAK,WAAW;AAAA,IAC7D,OAAO,KAAK,OAAO,OAAO,QAAQ;AAAA;AAAA,EAOpC,KAAK,CAAC,OAAqB;AAAA,IAEzB,IAAI;AAAA,IAEJ,IACE,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU,WACjB;AAAA,MACA,kBAAkB;AAAA,IACpB,EAAO,SAAI,UAAU,QAAQ,UAAU,WAAW;AAAA,MAChD,kBAAkB;AAAA,IACpB,EAAO,SAAI,OAAO,UAAU,UAAU;AAAA,MAGpC,MAAM,MAAM;AAAA,MACZ,IAAI,WAAW,KAAK;AAAA,QAClB,MAAM,aAAa,IAAI;AAAA,QACvB,IACE,OAAO,eAAe,YACtB,OAAO,eAAe,YACtB,OAAO,eAAe,WACtB;AAAA,UACA,kBAAkB;AAAA,QACpB,EAAO;AAAA,UACL,kBAAkB,OAAO,UAAU;AAAA;AAAA,MAEvC,EAAO;AAAA,QAEL,kBAAkB,KAAK,UAAU,KAAK;AAAA;AAAA,IAE1C,EAAO;AAAA,MACL,kBAAkB,OAAO,KAAK;AAAA;AAAA,IAGhC,KAAK,OAAO,eAAe,KAAK,aAAa,eAAe;AAAA;AAAA,EAM9D,UAAU,GAAgB;AAAA,IACxB,OAAO,KAAK,KAAK,YAAY;AAAA;AAEjC;",
8
+ "debugId": "65719C8FCB16AB7864756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,171 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+
29
+ // src/core/api/table-orm.ts
30
+ var exports_table_orm = {};
31
+ __export(exports_table_orm, {
32
+ TableOrm: () => TableOrm
33
+ });
34
+ module.exports = __toCommonJS(exports_table_orm);
35
+ var import_api_helpers = require("./api-helpers.cjs");
36
+
37
+ class TableOrm {
38
+ engine;
39
+ workbookName;
40
+ tableName;
41
+ headers;
42
+ namespace;
43
+ constructor(engine, workbookName, tableName, headers, namespace) {
44
+ this.engine = engine;
45
+ this.workbookName = workbookName;
46
+ this.tableName = tableName;
47
+ this.headers = headers;
48
+ this.namespace = namespace;
49
+ }
50
+ getTable() {
51
+ const table = this.engine._tableManager.getTable({
52
+ workbookName: this.workbookName,
53
+ name: this.tableName
54
+ });
55
+ if (!table) {
56
+ throw new Error(`Table "${this.tableName}" not found in workbook "${this.workbookName}"`);
57
+ }
58
+ return table;
59
+ }
60
+ findWhere(filter) {
61
+ const table = this.getTable();
62
+ for (const { rowIndex, isEmpty } of import_api_helpers.iterateTableRows(this.engine, table)) {
63
+ if (isEmpty)
64
+ continue;
65
+ try {
66
+ const item = import_api_helpers.rowToObject(this.engine, table, rowIndex, this.headers, (cell) => this.engine.getCellMetadata(cell));
67
+ if (import_api_helpers.matchesFilter(item, filter)) {
68
+ return item;
69
+ }
70
+ } catch {
71
+ continue;
72
+ }
73
+ }
74
+ return;
75
+ }
76
+ findAllWhere(filter) {
77
+ const table = this.getTable();
78
+ const results = [];
79
+ for (const { rowIndex, isEmpty } of import_api_helpers.iterateTableRows(this.engine, table)) {
80
+ if (isEmpty)
81
+ continue;
82
+ try {
83
+ const item = import_api_helpers.rowToObject(this.engine, table, rowIndex, this.headers, (cell) => this.engine.getCellMetadata(cell));
84
+ if (import_api_helpers.matchesFilter(item, filter)) {
85
+ results.push(item);
86
+ }
87
+ } catch {
88
+ continue;
89
+ }
90
+ }
91
+ return results;
92
+ }
93
+ append(item) {
94
+ const table = this.getTable();
95
+ const nextRow = import_api_helpers.getNextEmptyRow(this.engine, table);
96
+ const values = import_api_helpers.objectToRowValues(item, this.headers);
97
+ for (const [colOffset, value] of values) {
98
+ const cellAddress = {
99
+ workbookName: table.workbookName,
100
+ sheetName: table.sheetName,
101
+ colIndex: table.start.colIndex + colOffset,
102
+ rowIndex: nextRow
103
+ };
104
+ this.engine.setCellContent(cellAddress, value);
105
+ }
106
+ return item;
107
+ }
108
+ updateWhere(filter, update) {
109
+ const table = this.getTable();
110
+ let updatedCount = 0;
111
+ for (const { rowIndex, isEmpty } of import_api_helpers.iterateTableRows(this.engine, table)) {
112
+ if (isEmpty)
113
+ continue;
114
+ try {
115
+ const item = import_api_helpers.rowToObject(this.engine, table, rowIndex, this.headers, (cell) => this.engine.getCellMetadata(cell));
116
+ if (import_api_helpers.matchesFilter(item, filter)) {
117
+ const values = import_api_helpers.objectToRowValues(update, this.headers);
118
+ for (const [colOffset, value] of values) {
119
+ const cellAddress = {
120
+ workbookName: table.workbookName,
121
+ sheetName: table.sheetName,
122
+ colIndex: table.start.colIndex + colOffset,
123
+ rowIndex
124
+ };
125
+ this.engine.setCellContent(cellAddress, value);
126
+ }
127
+ updatedCount++;
128
+ }
129
+ } catch {
130
+ continue;
131
+ }
132
+ }
133
+ return updatedCount;
134
+ }
135
+ removeWhere(filter) {
136
+ const table = this.getTable();
137
+ let removedCount = 0;
138
+ const rowsToRemove = [];
139
+ for (const { rowIndex, isEmpty } of import_api_helpers.iterateTableRows(this.engine, table)) {
140
+ if (isEmpty)
141
+ continue;
142
+ try {
143
+ const item = import_api_helpers.rowToObject(this.engine, table, rowIndex, this.headers, (cell) => this.engine.getCellMetadata(cell));
144
+ if (import_api_helpers.matchesFilter(item, filter)) {
145
+ rowsToRemove.push(rowIndex);
146
+ }
147
+ } catch {
148
+ continue;
149
+ }
150
+ }
151
+ for (const rowIndex of rowsToRemove.reverse()) {
152
+ for (const header of Object.values(this.headers)) {
153
+ const cellAddress = {
154
+ workbookName: table.workbookName,
155
+ sheetName: table.sheetName,
156
+ colIndex: table.start.colIndex + header.index,
157
+ rowIndex
158
+ };
159
+ this.engine.setCellContent(cellAddress, undefined);
160
+ }
161
+ removedCount++;
162
+ }
163
+ return removedCount;
164
+ }
165
+ count() {
166
+ const table = this.getTable();
167
+ return import_api_helpers.getTableRowCount(this.engine, table);
168
+ }
169
+ }
170
+
171
+ //# debugId=EAD2C30DE3B432C664756E2164756E21