@ricsam/formula-engine 0.0.21 → 0.0.22
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.
- package/dist/cjs/core/commands/command-executor.cjs +3 -5
- package/dist/cjs/core/commands/command-executor.cjs.map +3 -3
- package/dist/cjs/core/commands/structure-commands.cjs.map +1 -1
- package/dist/cjs/core/commands/table-commands.cjs.map +1 -1
- package/dist/cjs/core/engine.cjs +56 -42
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/{api-schema-manager.cjs → schema-manager.cjs} +10 -7
- package/dist/cjs/core/managers/schema-manager.cjs.map +10 -0
- package/dist/cjs/core/{api → schema}/cell-orm.cjs +2 -2
- package/dist/cjs/core/{api → schema}/cell-orm.cjs.map +2 -2
- package/dist/cjs/core/{api/api-builder.cjs → schema/schema-builder.cjs} +13 -13
- package/dist/cjs/core/schema/schema-builder.cjs.map +10 -0
- package/dist/cjs/core/{api/api-helpers.cjs → schema/schema-helpers.cjs} +5 -5
- package/dist/cjs/core/schema/schema-helpers.cjs.map +10 -0
- package/dist/cjs/core/{api/api.cjs → schema/schema.cjs} +10 -12
- package/dist/cjs/core/schema/schema.cjs.map +10 -0
- package/dist/cjs/core/{api → schema}/table-orm.cjs +19 -19
- package/dist/cjs/core/schema/table-orm.cjs.map +10 -0
- package/dist/cjs/lib.cjs +7 -8
- package/dist/cjs/lib.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/commands/command-executor.mjs +3 -5
- package/dist/mjs/core/commands/command-executor.mjs.map +3 -3
- package/dist/mjs/core/commands/structure-commands.mjs.map +1 -1
- package/dist/mjs/core/commands/table-commands.mjs.map +1 -1
- package/dist/mjs/core/engine.mjs +57 -43
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/{api-schema-manager.mjs → schema-manager.mjs} +7 -4
- package/dist/mjs/core/managers/schema-manager.mjs.map +10 -0
- package/dist/mjs/core/{api → schema}/cell-orm.mjs +2 -2
- package/dist/mjs/core/{api → schema}/cell-orm.mjs.map +2 -2
- package/dist/mjs/core/{api/api-builder.mjs → schema/schema-builder.mjs} +10 -10
- package/dist/mjs/core/schema/schema-builder.mjs.map +10 -0
- package/dist/mjs/core/{api/api-helpers.mjs → schema/schema-helpers.mjs} +2 -2
- package/dist/mjs/core/schema/schema-helpers.mjs.map +10 -0
- package/dist/mjs/core/{api/api.mjs → schema/schema.mjs} +7 -9
- package/dist/mjs/core/schema/schema.mjs.map +10 -0
- package/dist/mjs/core/{api → schema}/table-orm.mjs +3 -3
- package/dist/mjs/core/schema/table-orm.mjs.map +10 -0
- package/dist/mjs/lib.mjs +6 -7
- package/dist/mjs/lib.mjs.map +2 -2
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/commands/command-executor.d.ts +1 -3
- package/dist/types/core/commands/structure-commands.d.ts +2 -2
- package/dist/types/core/commands/table-commands.d.ts +2 -2
- package/dist/types/core/engine.d.ts +31 -7
- package/dist/types/core/managers/{api-schema-manager.d.ts → schema-manager.d.ts} +6 -2
- package/dist/types/core/schema/schema-builder.d.ts +16 -0
- package/dist/types/core/{api/api-helpers.d.ts → schema/schema-helpers.d.ts} +1 -1
- package/dist/types/core/schema/schema.d.ts +90 -0
- package/dist/types/core/{api → schema}/table-orm.d.ts +1 -1
- package/dist/types/lib.d.ts +6 -6
- package/package.json +1 -1
- package/dist/cjs/core/api/api-builder.cjs.map +0 -10
- package/dist/cjs/core/api/api-helpers.cjs.map +0 -10
- package/dist/cjs/core/api/api.cjs.map +0 -10
- package/dist/cjs/core/api/table-orm.cjs.map +0 -10
- package/dist/cjs/core/managers/api-schema-manager.cjs.map +0 -10
- package/dist/mjs/core/api/api-builder.mjs.map +0 -10
- package/dist/mjs/core/api/api-helpers.mjs.map +0 -10
- package/dist/mjs/core/api/api.mjs.map +0 -10
- package/dist/mjs/core/api/table-orm.mjs.map +0 -10
- package/dist/mjs/core/managers/api-schema-manager.mjs.map +0 -10
- package/dist/types/core/api/api-builder.d.ts +0 -16
- package/dist/types/core/api/api.d.ts +0 -91
- /package/dist/types/core/{api → schema}/cell-orm.d.ts +0 -0
- /package/dist/types/core/{api/api.type-test.d.ts → schema/schema.type-test.d.ts} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/core/
|
|
3
|
+
"sources": ["../../../../src/core/schema/cell-orm.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
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.mjs\";\nimport type { FormulaEngine } from \"../engine.mjs\";\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
6
|
],
|
|
7
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": "
|
|
8
|
+
"debugId": "7C807D7F54F7BB5564756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
// src/core/
|
|
1
|
+
// src/core/schema/schema-builder.ts
|
|
2
2
|
import { TableOrm } from "./table-orm.mjs";
|
|
3
3
|
import { CellOrm } from "./cell-orm.mjs";
|
|
4
|
-
function
|
|
5
|
-
const
|
|
4
|
+
function buildSchemaFromDeclaration(engine, declaration, schemaManager) {
|
|
5
|
+
const schema = {};
|
|
6
6
|
for (const [namespace, def] of Object.entries(declaration)) {
|
|
7
7
|
if (def.type === "table") {
|
|
8
|
-
|
|
8
|
+
schema[namespace] = buildTableSchema(engine, namespace, def, schemaManager);
|
|
9
9
|
} else if (def.type === "cell") {
|
|
10
|
-
|
|
10
|
+
schema[namespace] = buildCellSchema(engine, namespace, def, schemaManager);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
return
|
|
13
|
+
return schema;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function buildTableSchema(engine, namespace, def, schemaManager) {
|
|
16
16
|
schemaManager.registerTableSchema(namespace, def.workbookName, def.tableName, def.headers);
|
|
17
17
|
return new TableOrm(engine, def.workbookName, def.tableName, def.headers, namespace);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function buildCellSchema(engine, namespace, def, schemaManager) {
|
|
20
20
|
schemaManager.registerCellSchema(namespace, def.cellAddress, def.parse);
|
|
21
21
|
return new CellOrm(engine, def.cellAddress, def.parse, namespace);
|
|
22
22
|
}
|
|
23
23
|
export {
|
|
24
|
-
|
|
24
|
+
buildSchemaFromDeclaration
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
//# debugId=
|
|
27
|
+
//# debugId=362026195AB1C12164756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/core/schema/schema-builder.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Schema Builder - Constructs the working schema from declarations\n *\n * This module is responsible for creating the actual working schema\n * from the schema declarations when attached to a FormulaEngine.\n */\n\nimport type { FormulaEngine } from \"../engine.mjs\";\nimport type { SchemaDeclaration, TableSchemaDefinition, CellSchemaDefinition, Schema } from \"./schema.mjs\";\nimport { TableOrm } from \"./table-orm.mjs\";\nimport { CellOrm } from \"./cell-orm.mjs\";\nimport type { SchemaManager } from \"../managers/schema-manager.mjs\";\n\n/**\n * Build the working schema surface from declarations\n *\n * This creates TableOrm and CellOrm instances for each declared schema\n * and returns them directly.\n */\nexport function buildSchemaFromDeclaration(\n engine: FormulaEngine<any, any>,\n declaration: SchemaDeclaration,\n schemaManager: SchemaManager\n): Schema {\n const schema: Schema = {};\n\n for (const [namespace, def] of Object.entries(declaration)) {\n if (def.type === \"table\") {\n schema[namespace] = buildTableSchema(engine, namespace, def, schemaManager);\n } else if (def.type === \"cell\") {\n schema[namespace] = buildCellSchema(engine, namespace, def, schemaManager);\n }\n }\n\n return schema;\n}\n\n/**\n * Build schema for a table schema - returns TableOrm instance directly\n */\nfunction buildTableSchema(\n engine: FormulaEngine<any, any>,\n namespace: string,\n def: TableSchemaDefinition,\n schemaManager: SchemaManager\n): TableOrm<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 and return the ORM instance directly\n return new TableOrm(\n engine,\n def.workbookName,\n def.tableName,\n def.headers,\n namespace\n );\n}\n\n/**\n * Build schema for a cell schema - returns CellOrm instance directly\n */\nfunction buildCellSchema(\n engine: FormulaEngine<any, any>,\n namespace: string,\n def: CellSchemaDefinition,\n schemaManager: SchemaManager\n): CellOrm<any> {\n // Register the schema with the schema manager\n schemaManager.registerCellSchema(namespace, def.cellAddress, def.parse);\n\n // Create and return the ORM instance directly\n return new CellOrm(engine, def.cellAddress, def.parse, namespace);\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AASA;AACA;AASO,SAAS,0BAA0B,CACxC,QACA,aACA,eACQ;AAAA,EACR,MAAM,SAAiB,CAAC;AAAA,EAExB,YAAY,WAAW,QAAQ,OAAO,QAAQ,WAAW,GAAG;AAAA,IAC1D,IAAI,IAAI,SAAS,SAAS;AAAA,MACxB,OAAO,aAAa,iBAAiB,QAAQ,WAAW,KAAK,aAAa;AAAA,IAC5E,EAAO,SAAI,IAAI,SAAS,QAAQ;AAAA,MAC9B,OAAO,aAAa,gBAAgB,QAAQ,WAAW,KAAK,aAAa;AAAA,IAC3E;AAAA,EACF;AAAA,EAEA,OAAO;AAAA;AAMT,SAAS,gBAAgB,CACvB,QACA,WACA,KACA,eACe;AAAA,EAEf,cAAc,oBACZ,WACA,IAAI,cACJ,IAAI,WACJ,IAAI,OACN;AAAA,EAGA,OAAO,IAAI,SACT,QACA,IAAI,cACJ,IAAI,WACJ,IAAI,SACJ,SACF;AAAA;AAMF,SAAS,eAAe,CACtB,QACA,WACA,KACA,eACc;AAAA,EAEd,cAAc,mBAAmB,WAAW,IAAI,aAAa,IAAI,KAAK;AAAA,EAGtE,OAAO,IAAI,QAAQ,QAAQ,IAAI,aAAa,IAAI,OAAO,SAAS;AAAA;",
|
|
8
|
+
"debugId": "362026195AB1C12164756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/core/
|
|
1
|
+
// src/core/schema/schema-helpers.ts
|
|
2
2
|
function rowToObject(engine, table, rowIndex, headers, getCellMetadata) {
|
|
3
3
|
const result = {};
|
|
4
4
|
for (const [columnName, header] of Object.entries(headers)) {
|
|
@@ -158,4 +158,4 @@ export {
|
|
|
158
158
|
getNextEmptyRow
|
|
159
159
|
};
|
|
160
160
|
|
|
161
|
-
//# debugId=
|
|
161
|
+
//# debugId=107165D9A940C78E64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/core/schema/schema-helpers.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Schema Helper utilities for row/object conversion and filtering\n */\n\nimport type { CellAddress, SerializedCellValue, TableDefinition } from \"../types.mjs\";\nimport type { FormulaEngine } from \"../engine.mjs\";\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": ";AAuBO,SAAS,WAAkD,CAChE,QACA,OACA,UACA,SACA,iBACO;AAAA,EACP,MAAM,SAAkC,CAAC;AAAA,EAEzC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AA,UACjC,UAAU;AAAA,QACZ;AAAA,QAEA,MAAM,QAAQ,OAAO,aAAa,WAAW;AAAA,QAC7C,IAAI,UAAU,MAAM,UAAU,WAAW;AAAA,UACvC,aAAa;AAAA,UACb;AAAA,QACF;AAAA,MACF;AAAA,MAEA,MAAM,EAAE,UAAU,KAAK,SAAS,CAAC,WAAW;AAAA,IAC9C;AAAA;AAAA;",
|
|
8
|
+
"debugId": "107165D9A940C78E64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// src/core/
|
|
2
|
-
function
|
|
1
|
+
// src/core/schema/schema.ts
|
|
2
|
+
function defineSchema() {
|
|
3
3
|
const declaration = {};
|
|
4
4
|
const builder = {
|
|
5
|
-
|
|
5
|
+
addTableSchema(namespace, address, headers) {
|
|
6
6
|
declaration[namespace] = {
|
|
7
7
|
type: "table",
|
|
8
8
|
tableName: address.tableName,
|
|
@@ -11,7 +11,7 @@ function defineApi() {
|
|
|
11
11
|
};
|
|
12
12
|
return builder;
|
|
13
13
|
},
|
|
14
|
-
|
|
14
|
+
addCellSchema(namespace, cellAddress, parse) {
|
|
15
15
|
declaration[namespace] = {
|
|
16
16
|
type: "cell",
|
|
17
17
|
cellAddress,
|
|
@@ -19,15 +19,13 @@ function defineApi() {
|
|
|
19
19
|
};
|
|
20
20
|
return builder;
|
|
21
21
|
},
|
|
22
|
-
|
|
22
|
+
schema: undefined,
|
|
23
23
|
declaration
|
|
24
24
|
};
|
|
25
25
|
return builder;
|
|
26
26
|
}
|
|
27
|
-
var createApi = defineApi;
|
|
28
27
|
export {
|
|
29
|
-
|
|
30
|
-
createApi
|
|
28
|
+
defineSchema
|
|
31
29
|
};
|
|
32
30
|
|
|
33
|
-
//# debugId=
|
|
31
|
+
//# debugId=DD0716E0FB48113C64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/core/schema/schema.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { CellAddress } from \"../types.mjs\";\n\n/**\n * Define a schema for the FormulaEngine.\n *\n * The returned object contains:\n * - `declaration`: The schema definitions for tables and cells\n * - `schema`: A type-only placeholder (undefined at runtime) for TypeScript inference\n *\n * The actual working schema is only available through `engine.schema` after\n * attaching the definition to a FormulaEngine instance.\n *\n * @example\n * ```typescript\n * const mySchema = defineSchema<CellMetadata>()\n * .addTableSchema(\"users\", { workbookName: \"wb1\", tableName: \"users\" }, headers)\n * .addCellSchema(\"config\", cellAddress, parse);\n *\n * const engine = new FormulaEngine(mySchema);\n * engine.schema.users.findWhere({ id: 1 }); // Works!\n * engine.schema.config.read(); // Works!\n * mySchema.schema.users.findWhere({ id: 1 }); // Error: schema is undefined at runtime\n * ```\n */\nexport function defineSchema<\n TCellMetadata = unknown,\n TCurrentSchema extends Record<string, object> = Record<string, object>,\n TCurrentDeclaration extends Record<string, TableSchemaDefinition | CellSchemaDefinition> = Record<\n string,\n TableSchemaDefinition | CellSchemaDefinition\n >\n>(): CreateSchema<TCellMetadata, TCurrentSchema, TCurrentDeclaration> {\n const declaration: Record<string, TableSchemaDefinition | CellSchemaDefinition> = {};\n\n const builder: CreateSchema<TCellMetadata, TCurrentSchema, TCurrentDeclaration> = {\n addTableSchema(namespace, address, headers) {\n declaration[namespace] = {\n type: \"table\",\n tableName: address.tableName,\n workbookName: address.workbookName,\n headers: headers as any,\n };\n return builder as any;\n },\n\n addCellSchema(namespace, cellAddress, parse) {\n declaration[namespace] = {\n type: \"cell\",\n cellAddress,\n parse: parse as any,\n };\n return builder as any;\n },\n\n // schema is undefined at runtime - it only exists for TypeScript type inference\n // The actual working schema is built by the FormulaEngine constructor\n schema: undefined as any as TCurrentSchema,\n\n declaration: declaration as TCurrentDeclaration,\n };\n\n return builder;\n}\n\ntype ParseFunction<TCellMetadata> = (\n value: unknown,\n metadata: TCellMetadata\n) => unknown;\n\nexport interface TableSchemaDefinition {\n type: \"table\";\n headers: Headers<unknown>;\n tableName: string;\n workbookName: string;\n}\n\nexport interface CellSchemaDefinition {\n type: \"cell\";\n cellAddress: CellAddress;\n parse: (value: unknown, metadata: unknown) => unknown;\n}\n\ntype Headers<TCellMetadata> = Record<\n string,\n {\n parse: ParseFunction<TCellMetadata>;\n index: number;\n }\n>;\n\n/**\n * Type representing the TableOrm methods exposed on the schema\n */\nexport type TableOrmSchema<TItem extends Record<string, unknown>> = {\n findWhere(filter: Partial<TItem>): TItem | undefined;\n findAllWhere(filter: Partial<TItem>): TItem[];\n append(item: TItem): TItem;\n updateWhere(filter: Partial<TItem>, update: Partial<TItem>): number;\n removeWhere(filter: Partial<TItem>): number;\n count(): number;\n};\n\n/**\n * Type representing the CellOrm methods exposed on the schema\n */\nexport type CellOrmSchema<TValue> = {\n read(): TValue;\n write(value: TValue): void;\n getAddress(): CellAddress;\n};\n\nexport type SchemaDeclaration = Record<string, TableSchemaDefinition | CellSchemaDefinition>;\nexport type Schema = Record<string, object>;\n\nexport type CreateSchema<\n TCellMetadata,\n TCurrentSchema extends Schema,\n TCurrentDeclaration extends SchemaDeclaration\n> = {\n addTableSchema<T extends string, THeaders extends Headers<TCellMetadata>>(\n namespace: T,\n address: { workbookName: string; tableName: string },\n headers: THeaders\n ): CreateSchema<\n TCellMetadata,\n TCurrentSchema & {\n [K in T]: TableOrmSchema<{\n [H in keyof THeaders]: ReturnType<THeaders[H][\"parse\"]>;\n }>;\n },\n TCurrentDeclaration & {\n [K in T]: {\n type: \"table\";\n tableName: string;\n workbookName: string;\n headers: THeaders;\n };\n }\n >;\n addCellSchema<T extends string, TValue>(\n namespace: T,\n cellAddress: CellAddress,\n parse: (value: unknown, metadata: TCellMetadata) => TValue\n ): CreateSchema<\n TCellMetadata,\n TCurrentSchema & {\n [K in T]: CellOrmSchema<TValue>;\n },\n TCurrentDeclaration & {\n [K in T]: {\n type: \"cell\";\n cellAddress: CellAddress;\n parse: (value: unknown, metadata: unknown) => unknown;\n };\n }\n >;\n schema: TCurrentSchema;\n declaration: TCurrentDeclaration;\n};\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAwBO,SAAS,YAOf,GAAqE;AAAA,EACpE,MAAM,cAA4E,CAAC;AAAA,EAEnF,MAAM,UAA4E;AAAA,IAChF,cAAc,CAAC,WAAW,SAAS,SAAS;AAAA,MAC1C,YAAY,aAAa;AAAA,QACvB,MAAM;AAAA,QACN,WAAW,QAAQ;AAAA,QACnB,cAAc,QAAQ;AAAA,QACtB;AAAA,MACF;AAAA,MACA,OAAO;AAAA;AAAA,IAGT,aAAa,CAAC,WAAW,aAAa,OAAO;AAAA,MAC3C,YAAY,aAAa;AAAA,QACvB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACF;AAAA,MACA,OAAO;AAAA;AAAA,IAKT,QAAQ;AAAA,IAER;AAAA,EACF;AAAA,EAEA,OAAO;AAAA;",
|
|
8
|
+
"debugId": "DD0716E0FB48113C64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/core/
|
|
1
|
+
// src/core/schema/table-orm.ts
|
|
2
2
|
import {
|
|
3
3
|
rowToObject,
|
|
4
4
|
objectToRowValues,
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
getTableRowCount,
|
|
7
7
|
getNextEmptyRow,
|
|
8
8
|
iterateTableRows
|
|
9
|
-
} from "./
|
|
9
|
+
} from "./schema-helpers.mjs";
|
|
10
10
|
|
|
11
11
|
class TableOrm {
|
|
12
12
|
engine;
|
|
@@ -145,4 +145,4 @@ export {
|
|
|
145
145
|
TableOrm
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
-
//# debugId=
|
|
148
|
+
//# debugId=266367D4DE8082EA64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/core/schema/table-orm.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * TableOrm - Object-Relational Mapping for table data\n *\n * Provides CRUD operations for table data with type-safe access.\n * Used as the `this` context for custom table API methods.\n */\n\nimport type { CellAddress, SerializedCellValue, TableDefinition } from \"../types.mjs\";\nimport type { FormulaEngine } from \"../engine.mjs\";\nimport {\n rowToObject,\n objectToRowValues,\n matchesFilter,\n getTableRowCount,\n getNextEmptyRow,\n iterateTableRows,\n type TableSchemaHeaders,\n} from \"./schema-helpers.mjs\";\n\nexport class TableOrm<TItem extends Record<string, unknown>> {\n constructor(\n private engine: FormulaEngine<any, any>,\n private workbookName: string,\n private tableName: string,\n private headers: TableSchemaHeaders,\n private namespace: string\n ) {}\n\n /**\n * Get the table definition from the engine\n */\n private getTable(): TableDefinition {\n const table = this.engine._tableManager.getTable({\n workbookName: this.workbookName,\n name: this.tableName,\n });\n\n if (!table) {\n throw new Error(\n `Table \"${this.tableName}\" not found in workbook \"${this.workbookName}\"`\n );\n }\n\n return table;\n }\n\n /**\n * Find the first row matching the filter\n */\n findWhere(filter: Partial<TItem>): TItem | undefined {\n const table = this.getTable();\n\n for (const { rowIndex, isEmpty } of iterateTableRows(this.engine, table)) {\n if (isEmpty) continue;\n\n try {\n const item = rowToObject<TItem>(\n this.engine,\n table,\n rowIndex,\n this.headers,\n (cell) => this.engine.getCellMetadata(cell)\n );\n\n if (matchesFilter(item, filter)) {\n return item;\n }\n } catch {\n // Skip rows that fail parsing\n continue;\n }\n }\n\n return undefined;\n }\n\n /**\n * Find all rows matching the filter\n */\n findAllWhere(filter: Partial<TItem>): TItem[] {\n const table = this.getTable();\n const results: TItem[] = [];\n\n for (const { rowIndex, isEmpty } of iterateTableRows(this.engine, table)) {\n if (isEmpty) continue;\n\n try {\n const item = rowToObject<TItem>(\n this.engine,\n table,\n rowIndex,\n this.headers,\n (cell) => this.engine.getCellMetadata(cell)\n );\n\n if (matchesFilter(item, filter)) {\n results.push(item);\n }\n } catch {\n // Skip rows that fail parsing\n continue;\n }\n }\n\n return results;\n }\n\n /**\n * Append a new row to the table\n */\n append(item: TItem): TItem {\n const table = this.getTable();\n const nextRow = getNextEmptyRow(this.engine, table);\n const values = objectToRowValues(item, this.headers);\n\n // Write each cell value\n for (const [colOffset, value] of values) {\n const cellAddress: CellAddress = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n colIndex: table.start.colIndex + colOffset,\n rowIndex: nextRow,\n };\n\n this.engine.setCellContent(cellAddress, value);\n }\n\n return item;\n }\n\n /**\n * Update all rows matching the filter\n * Returns the number of rows updated\n */\n updateWhere(filter: Partial<TItem>, update: Partial<TItem>): number {\n const table = this.getTable();\n let updatedCount = 0;\n\n for (const { rowIndex, isEmpty } of iterateTableRows(this.engine, table)) {\n if (isEmpty) continue;\n\n try {\n const item = rowToObject<TItem>(\n this.engine,\n table,\n rowIndex,\n this.headers,\n (cell) => this.engine.getCellMetadata(cell)\n );\n\n if (matchesFilter(item, filter)) {\n // Apply updates\n const values = objectToRowValues(update as TItem, this.headers);\n\n for (const [colOffset, value] of values) {\n const cellAddress: CellAddress = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n colIndex: table.start.colIndex + colOffset,\n rowIndex,\n };\n\n this.engine.setCellContent(cellAddress, value);\n }\n\n updatedCount++;\n }\n } catch {\n // Skip rows that fail parsing\n continue;\n }\n }\n\n return updatedCount;\n }\n\n /**\n * Remove all rows matching the filter\n * Returns the number of rows removed\n */\n removeWhere(filter: Partial<TItem>): number {\n const table = this.getTable();\n let removedCount = 0;\n\n // Collect rows to remove (in reverse order to avoid index shifting issues)\n const rowsToRemove: number[] = [];\n\n for (const { rowIndex, isEmpty } of iterateTableRows(this.engine, table)) {\n if (isEmpty) continue;\n\n try {\n const item = rowToObject<TItem>(\n this.engine,\n table,\n rowIndex,\n this.headers,\n (cell) => this.engine.getCellMetadata(cell)\n );\n\n if (matchesFilter(item, filter)) {\n rowsToRemove.push(rowIndex);\n }\n } catch {\n // Skip rows that fail parsing\n continue;\n }\n }\n\n // Remove rows in reverse order\n for (const rowIndex of rowsToRemove.reverse()) {\n // Clear all cells in the row\n for (const header of Object.values(this.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 this.engine.setCellContent(cellAddress, undefined);\n }\n\n removedCount++;\n }\n\n return removedCount;\n }\n\n /**\n * Get the count of data rows in the table\n */\n count(): number {\n const table = this.getTable();\n return getTableRowCount(this.engine, table);\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,MAAM,SAAgD;AAAA,EAEjD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EALV,WAAW,CACD,QACA,cACA,WACA,SACA,WACR;AAAA,IALQ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAMF,QAAQ,GAAoB;AAAA,IAClC,MAAM,QAAQ,KAAK,OAAO,cAAc,SAAS;AAAA,MAC/C,cAAc,KAAK;AAAA,MACnB,MAAM,KAAK;AAAA,IACb,CAAC;AAAA,IAED,IAAI,CAAC,OAAO;AAAA,MACV,MAAM,IAAI,MACR,UAAU,KAAK,qCAAqC,KAAK,eAC3D;AAAA,IACF;AAAA,IAEA,OAAO;AAAA;AAAA,EAMT,SAAS,CAAC,QAA2C;AAAA,IACnD,MAAM,QAAQ,KAAK,SAAS;AAAA,IAE5B,aAAa,UAAU,aAAa,iBAAiB,KAAK,QAAQ,KAAK,GAAG;AAAA,MACxE,IAAI;AAAA,QAAS;AAAA,MAEb,IAAI;AAAA,QACF,MAAM,OAAO,YACX,KAAK,QACL,OACA,UACA,KAAK,SACL,CAAC,SAAS,KAAK,OAAO,gBAAgB,IAAI,CAC5C;AAAA,QAEA,IAAI,cAAc,MAAM,MAAM,GAAG;AAAA,UAC/B,OAAO;AAAA,QACT;AAAA,Q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S;AAAA,MACnD;AAAA,MAEA;AAAA,IACF;AAAA,IAEA,OAAO;AAAA;AAAA,EAMT,KAAK,GAAW;AAAA,IACd,MAAM,QAAQ,KAAK,SAAS;AAAA,IAC5B,OAAO,iBAAiB,KAAK,QAAQ,KAAK;AAAA;AAE9C;",
|
|
8
|
+
"debugId": "266367D4DE8082EA64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/mjs/lib.mjs
CHANGED
|
@@ -4,14 +4,13 @@ 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 {
|
|
8
|
-
import { TableOrm } from "./core/
|
|
9
|
-
import { CellOrm } from "./core/
|
|
10
|
-
import { SchemaValidationError } from "./core/managers/
|
|
7
|
+
import { defineSchema } from "./core/schema/schema.mjs";
|
|
8
|
+
import { TableOrm } from "./core/schema/table-orm.mjs";
|
|
9
|
+
import { CellOrm } from "./core/schema/cell-orm.mjs";
|
|
10
|
+
import { SchemaValidationError } from "./core/managers/schema-manager.mjs";
|
|
11
11
|
import { SchemaIntegrityError } from "./core/commands/command-executor.mjs";
|
|
12
12
|
export {
|
|
13
|
-
|
|
14
|
-
createApi,
|
|
13
|
+
defineSchema,
|
|
15
14
|
TableOrm,
|
|
16
15
|
SchemaValidationError,
|
|
17
16
|
SchemaIntegrityError,
|
|
@@ -19,4 +18,4 @@ export {
|
|
|
19
18
|
CellOrm
|
|
20
19
|
};
|
|
21
20
|
|
|
22
|
-
//# debugId=
|
|
21
|
+
//# debugId=14E82C883ABC721064756E2164756E21
|
package/dist/mjs/lib.mjs.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"export { FormulaEngine } from \"./core/engine.mjs\";\nexport * from \"./core/types.mjs\";\nexport * from \"./core/utils.mjs\";\nexport * from \"./core/utils/color-utils.mjs\";\n\n//
|
|
5
|
+
"export { FormulaEngine } from \"./core/engine.mjs\";\nexport * from \"./core/types.mjs\";\nexport * from \"./core/utils.mjs\";\nexport * from \"./core/utils/color-utils.mjs\";\n\n// Schema exports\nexport { defineSchema } from \"./core/schema/schema.mjs\";\nexport type { CreateSchema, SchemaDeclaration, Schema, TableSchemaDefinition, CellSchemaDefinition, TableOrmSchema, CellOrmSchema } from \"./core/schema/schema.mjs\";\nexport { TableOrm } from \"./core/schema/table-orm.mjs\";\nexport { CellOrm } from \"./core/schema/cell-orm.mjs\";\nexport { SchemaValidationError } from \"./core/managers/schema-manager.mjs\";\nexport type { ValidationResult } from \"./core/managers/schema-manager.mjs\";\n\n// Command Pattern exports\nexport { SchemaIntegrityError } from \"./core/commands/command-executor.mjs\";\nexport type { EngineAction, EngineCommand } from \"./core/commands/types.mjs\";\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AAAA;AAAA;AACA;AACA;AACA;AAGA;AAEA;AACA;AACA;AAIA;",
|
|
8
|
-
"debugId": "
|
|
8
|
+
"debugId": "14E82C883ABC721064756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/mjs/package.json
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
* - Undo/redo stacks
|
|
9
9
|
* - Action serialization for persistence
|
|
10
10
|
*/
|
|
11
|
-
import type { Declaration } from "../api/api";
|
|
12
11
|
import type { EvaluationManager } from "../managers/evaluation-manager";
|
|
13
12
|
import type { EventManager } from "../managers/event-manager";
|
|
14
13
|
import type { EngineCommand, EngineAction, ExecuteOptions, SchemaValidationResult, SchemaValidationErrorInfo } from "./types";
|
|
@@ -24,14 +23,13 @@ export declare class SchemaIntegrityError extends Error {
|
|
|
24
23
|
* CommandExecutor manages command execution with validation and undo/redo support.
|
|
25
24
|
*/
|
|
26
25
|
export declare class CommandExecutor {
|
|
27
|
-
private apiDeclaration;
|
|
28
26
|
private evaluationManager;
|
|
29
27
|
private eventManager;
|
|
30
28
|
private validateAllSchemas;
|
|
31
29
|
private undoStack;
|
|
32
30
|
private redoStack;
|
|
33
31
|
private actionLog;
|
|
34
|
-
constructor(
|
|
32
|
+
constructor(evaluationManager: EvaluationManager, eventManager: EventManager, validateAllSchemas: () => SchemaValidationResult);
|
|
35
33
|
/**
|
|
36
34
|
* Execute a command with optional schema validation.
|
|
37
35
|
*
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* These commands all require re-evaluation after execution.
|
|
5
5
|
*/
|
|
6
|
-
import type {
|
|
6
|
+
import type { SchemaManager } from "../managers/schema-manager";
|
|
7
7
|
import type { NamedExpressionManager } from "../managers/named-expression-manager";
|
|
8
8
|
import type { ReferenceManager } from "../managers/reference-manager";
|
|
9
9
|
import type { StyleManager } from "../managers/style-manager";
|
|
@@ -19,7 +19,7 @@ export interface StructureCommandDeps {
|
|
|
19
19
|
tableManager: TableManager;
|
|
20
20
|
styleManager: StyleManager;
|
|
21
21
|
referenceManager: ReferenceManager;
|
|
22
|
-
apiSchemaManager:
|
|
22
|
+
apiSchemaManager: SchemaManager;
|
|
23
23
|
renameSheetInFormula: (opts: {
|
|
24
24
|
formula: string;
|
|
25
25
|
oldSheetName: string;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import type { TableManager } from "../managers/table-manager";
|
|
7
7
|
import type { NamedExpressionManager } from "../managers/named-expression-manager";
|
|
8
8
|
import type { WorkbookManager } from "../managers/workbook-manager";
|
|
9
|
-
import type {
|
|
9
|
+
import type { SchemaManager } from "../managers/schema-manager";
|
|
10
10
|
import type { CellAddress, SerializedCellValue, SpreadsheetRangeEnd, TableDefinition } from "../types";
|
|
11
11
|
import type { EngineCommand, EngineAction } from "./types";
|
|
12
12
|
/**
|
|
@@ -16,7 +16,7 @@ export interface TableCommandDeps {
|
|
|
16
16
|
tableManager: TableManager;
|
|
17
17
|
namedExpressionManager: NamedExpressionManager;
|
|
18
18
|
workbookManager: WorkbookManager;
|
|
19
|
-
apiSchemaManager:
|
|
19
|
+
apiSchemaManager: SchemaManager;
|
|
20
20
|
getCellValue: (cellAddress: CellAddress) => SerializedCellValue;
|
|
21
21
|
renameTableInFormula: (formula: string, oldName: string, newName: string) => string;
|
|
22
22
|
}
|
|
@@ -12,7 +12,10 @@ import { EventManager } from "./managers/event-manager";
|
|
|
12
12
|
import { EvaluationManager } from "./managers/evaluation-manager";
|
|
13
13
|
import { DependencyManager } from "./managers/dependency-manager";
|
|
14
14
|
import { StyleManager } from "./managers/style-manager";
|
|
15
|
-
import type {
|
|
15
|
+
import type { Schema, CreateSchema, SchemaDeclaration } from "./schema/schema";
|
|
16
|
+
import { TableOrm } from "./schema/table-orm";
|
|
17
|
+
import { CellOrm } from "./schema/cell-orm";
|
|
18
|
+
import type { TableSchemaHeaders } from "./managers/schema-manager";
|
|
16
19
|
import { type EngineAction } from "./commands/types";
|
|
17
20
|
type Metadata = {
|
|
18
21
|
cell?: unknown;
|
|
@@ -26,7 +29,7 @@ type MetadataType<TMetadata extends Metadata, TKey extends keyof Metadata> = TMe
|
|
|
26
29
|
* @template TSheetMetadata - Consumer-defined type for sheet metadata (text boxes, frozen panes, etc.)
|
|
27
30
|
* @template TWorkbookMetadata - Consumer-defined type for workbook metadata (themes, document properties, etc.)
|
|
28
31
|
*/
|
|
29
|
-
export declare class FormulaEngine<TMetadata extends Metadata = Metadata,
|
|
32
|
+
export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreateSchema extends CreateSchema<MetadataType<TMetadata, "cell">, Schema, SchemaDeclaration> | undefined = undefined> {
|
|
30
33
|
private workbookManager;
|
|
31
34
|
private namedExpressionManager;
|
|
32
35
|
private tableManager;
|
|
@@ -37,10 +40,10 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
|
|
|
37
40
|
private styleManager;
|
|
38
41
|
private copyManager;
|
|
39
42
|
private referenceManager;
|
|
40
|
-
private
|
|
43
|
+
private schemaManager;
|
|
41
44
|
private commandExecutor;
|
|
42
|
-
|
|
43
|
-
private
|
|
45
|
+
schema: TCreateSchema extends CreateSchema<MetadataType<TMetadata, "cell">, Schema, SchemaDeclaration> ? TCreateSchema["schema"] : undefined;
|
|
46
|
+
private schemaDeclaration;
|
|
44
47
|
/**
|
|
45
48
|
* Public access to the store manager for testing
|
|
46
49
|
*/
|
|
@@ -52,14 +55,35 @@ export declare class FormulaEngine<TMetadata extends Metadata = Metadata, TCreat
|
|
|
52
55
|
_autoFillManager: AutoFill;
|
|
53
56
|
_dependencyManager: DependencyManager;
|
|
54
57
|
_styleManager: StyleManager;
|
|
55
|
-
constructor(
|
|
58
|
+
constructor(schema?: TCreateSchema);
|
|
56
59
|
/**
|
|
57
60
|
* Static factory method to build an empty engine
|
|
58
61
|
* @template TC - Consumer-defined cell metadata type
|
|
59
62
|
* @template TS - Consumer-defined sheet metadata type
|
|
60
63
|
* @template TW - Consumer-defined workbook metadata type
|
|
61
64
|
*/
|
|
62
|
-
static buildEmpty<TMetadata extends Metadata = Metadata,
|
|
65
|
+
static buildEmpty<TMetadata extends Metadata = Metadata, TSchemaDeclaration extends CreateSchema<MetadataType<TMetadata, "cell">, any, any> | undefined = undefined>(schema?: TSchemaDeclaration): FormulaEngine<TMetadata, TSchemaDeclaration>;
|
|
66
|
+
/**
|
|
67
|
+
* Add a table schema at runtime
|
|
68
|
+
* @param namespace - Unique namespace for the schema
|
|
69
|
+
* @param address - Table address (workbookName and tableName)
|
|
70
|
+
* @param headers - Table headers with parse functions
|
|
71
|
+
* @returns The TableOrm instance for immediate use
|
|
72
|
+
*/
|
|
73
|
+
addTableSchema<THeaders extends TableSchemaHeaders<MetadataType<TMetadata, "cell">>>(namespace: string, address: {
|
|
74
|
+
workbookName: string;
|
|
75
|
+
tableName: string;
|
|
76
|
+
}, headers: THeaders): TableOrm<{
|
|
77
|
+
[K in keyof THeaders]: ReturnType<THeaders[K]["parse"]>;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Add a cell schema at runtime
|
|
81
|
+
* @param namespace - Unique namespace for the schema
|
|
82
|
+
* @param cellAddress - Address of the cell
|
|
83
|
+
* @param parse - Parse function for the cell value
|
|
84
|
+
* @returns The CellOrm instance for immediate use
|
|
85
|
+
*/
|
|
86
|
+
addCellSchema<TValue>(namespace: string, cellAddress: CellAddress, parse: (value: unknown, metadata: MetadataType<TMetadata, "cell">) => TValue): CellOrm<TValue>;
|
|
63
87
|
getCellEvaluationResult(cellAddress: CellAddress): SingleEvaluationResult | undefined;
|
|
64
88
|
getCellValue(cellAddress: CellAddress, debug?: boolean): SerializedCellValue;
|
|
65
89
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* SchemaManager - Manages schema definitions and validation
|
|
3
3
|
*
|
|
4
4
|
* Tracks registered schemas and provides validation for cell writes,
|
|
5
5
|
* spill operations, and copy/paste operations.
|
|
@@ -35,7 +35,7 @@ export declare class SchemaValidationError extends Error {
|
|
|
35
35
|
originalError?: Error | undefined;
|
|
36
36
|
constructor(message: string, cellAddress?: CellAddress | undefined, originalError?: Error | undefined);
|
|
37
37
|
}
|
|
38
|
-
export declare class
|
|
38
|
+
export declare class SchemaManager {
|
|
39
39
|
private tableManager;
|
|
40
40
|
private schemas;
|
|
41
41
|
constructor(tableManager: TableManager);
|
|
@@ -55,6 +55,10 @@ export declare class ApiSchemaManager {
|
|
|
55
55
|
* Remove a schema
|
|
56
56
|
*/
|
|
57
57
|
removeSchema(namespace: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Check if any schemas are registered
|
|
60
|
+
*/
|
|
61
|
+
hasSchemas(): boolean;
|
|
58
62
|
/**
|
|
59
63
|
* Check if a cell is protected by a schema
|
|
60
64
|
* Returns the schema info if protected, null otherwise
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Builder - Constructs the working schema from declarations
|
|
3
|
+
*
|
|
4
|
+
* This module is responsible for creating the actual working schema
|
|
5
|
+
* from the schema declarations when attached to a FormulaEngine.
|
|
6
|
+
*/
|
|
7
|
+
import type { FormulaEngine } from "../engine";
|
|
8
|
+
import type { SchemaDeclaration, Schema } from "./schema";
|
|
9
|
+
import type { SchemaManager } from "../managers/schema-manager";
|
|
10
|
+
/**
|
|
11
|
+
* Build the working schema surface from declarations
|
|
12
|
+
*
|
|
13
|
+
* This creates TableOrm and CellOrm instances for each declared schema
|
|
14
|
+
* and returns them directly.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildSchemaFromDeclaration(engine: FormulaEngine<any, any>, declaration: SchemaDeclaration, schemaManager: SchemaManager): Schema;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Schema Helper utilities for row/object conversion and filtering
|
|
3
3
|
*/
|
|
4
4
|
import type { CellAddress, SerializedCellValue, TableDefinition } from "../types";
|
|
5
5
|
import type { FormulaEngine } from "../engine";
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { CellAddress } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Define a schema for the FormulaEngine.
|
|
4
|
+
*
|
|
5
|
+
* The returned object contains:
|
|
6
|
+
* - `declaration`: The schema definitions for tables and cells
|
|
7
|
+
* - `schema`: A type-only placeholder (undefined at runtime) for TypeScript inference
|
|
8
|
+
*
|
|
9
|
+
* The actual working schema is only available through `engine.schema` after
|
|
10
|
+
* attaching the definition to a FormulaEngine instance.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const mySchema = defineSchema<CellMetadata>()
|
|
15
|
+
* .addTableSchema("users", { workbookName: "wb1", tableName: "users" }, headers)
|
|
16
|
+
* .addCellSchema("config", cellAddress, parse);
|
|
17
|
+
*
|
|
18
|
+
* const engine = new FormulaEngine(mySchema);
|
|
19
|
+
* engine.schema.users.findWhere({ id: 1 }); // Works!
|
|
20
|
+
* engine.schema.config.read(); // Works!
|
|
21
|
+
* mySchema.schema.users.findWhere({ id: 1 }); // Error: schema is undefined at runtime
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function defineSchema<TCellMetadata = unknown, TCurrentSchema extends Record<string, object> = Record<string, object>, TCurrentDeclaration extends Record<string, TableSchemaDefinition | CellSchemaDefinition> = Record<string, TableSchemaDefinition | CellSchemaDefinition>>(): CreateSchema<TCellMetadata, TCurrentSchema, TCurrentDeclaration>;
|
|
25
|
+
type ParseFunction<TCellMetadata> = (value: unknown, metadata: TCellMetadata) => unknown;
|
|
26
|
+
export interface TableSchemaDefinition {
|
|
27
|
+
type: "table";
|
|
28
|
+
headers: Headers<unknown>;
|
|
29
|
+
tableName: string;
|
|
30
|
+
workbookName: string;
|
|
31
|
+
}
|
|
32
|
+
export interface CellSchemaDefinition {
|
|
33
|
+
type: "cell";
|
|
34
|
+
cellAddress: CellAddress;
|
|
35
|
+
parse: (value: unknown, metadata: unknown) => unknown;
|
|
36
|
+
}
|
|
37
|
+
type Headers<TCellMetadata> = Record<string, {
|
|
38
|
+
parse: ParseFunction<TCellMetadata>;
|
|
39
|
+
index: number;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Type representing the TableOrm methods exposed on the schema
|
|
43
|
+
*/
|
|
44
|
+
export type TableOrmSchema<TItem extends Record<string, unknown>> = {
|
|
45
|
+
findWhere(filter: Partial<TItem>): TItem | undefined;
|
|
46
|
+
findAllWhere(filter: Partial<TItem>): TItem[];
|
|
47
|
+
append(item: TItem): TItem;
|
|
48
|
+
updateWhere(filter: Partial<TItem>, update: Partial<TItem>): number;
|
|
49
|
+
removeWhere(filter: Partial<TItem>): number;
|
|
50
|
+
count(): number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Type representing the CellOrm methods exposed on the schema
|
|
54
|
+
*/
|
|
55
|
+
export type CellOrmSchema<TValue> = {
|
|
56
|
+
read(): TValue;
|
|
57
|
+
write(value: TValue): void;
|
|
58
|
+
getAddress(): CellAddress;
|
|
59
|
+
};
|
|
60
|
+
export type SchemaDeclaration = Record<string, TableSchemaDefinition | CellSchemaDefinition>;
|
|
61
|
+
export type Schema = Record<string, object>;
|
|
62
|
+
export type CreateSchema<TCellMetadata, TCurrentSchema extends Schema, TCurrentDeclaration extends SchemaDeclaration> = {
|
|
63
|
+
addTableSchema<T extends string, THeaders extends Headers<TCellMetadata>>(namespace: T, address: {
|
|
64
|
+
workbookName: string;
|
|
65
|
+
tableName: string;
|
|
66
|
+
}, headers: THeaders): CreateSchema<TCellMetadata, TCurrentSchema & {
|
|
67
|
+
[K in T]: TableOrmSchema<{
|
|
68
|
+
[H in keyof THeaders]: ReturnType<THeaders[H]["parse"]>;
|
|
69
|
+
}>;
|
|
70
|
+
}, TCurrentDeclaration & {
|
|
71
|
+
[K in T]: {
|
|
72
|
+
type: "table";
|
|
73
|
+
tableName: string;
|
|
74
|
+
workbookName: string;
|
|
75
|
+
headers: THeaders;
|
|
76
|
+
};
|
|
77
|
+
}>;
|
|
78
|
+
addCellSchema<T extends string, TValue>(namespace: T, cellAddress: CellAddress, parse: (value: unknown, metadata: TCellMetadata) => TValue): CreateSchema<TCellMetadata, TCurrentSchema & {
|
|
79
|
+
[K in T]: CellOrmSchema<TValue>;
|
|
80
|
+
}, TCurrentDeclaration & {
|
|
81
|
+
[K in T]: {
|
|
82
|
+
type: "cell";
|
|
83
|
+
cellAddress: CellAddress;
|
|
84
|
+
parse: (value: unknown, metadata: unknown) => unknown;
|
|
85
|
+
};
|
|
86
|
+
}>;
|
|
87
|
+
schema: TCurrentSchema;
|
|
88
|
+
declaration: TCurrentDeclaration;
|
|
89
|
+
};
|
|
90
|
+
export {};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Used as the `this` context for custom table API methods.
|
|
6
6
|
*/
|
|
7
7
|
import type { FormulaEngine } from "../engine";
|
|
8
|
-
import { type TableSchemaHeaders } from "./
|
|
8
|
+
import { type TableSchemaHeaders } from "./schema-helpers";
|
|
9
9
|
export declare class TableOrm<TItem extends Record<string, unknown>> {
|
|
10
10
|
private engine;
|
|
11
11
|
private workbookName;
|
package/dist/types/lib.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ export { FormulaEngine } from "./core/engine";
|
|
|
2
2
|
export * from "./core/types";
|
|
3
3
|
export * from "./core/utils";
|
|
4
4
|
export * from "./core/utils/color-utils";
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
7
|
-
export { TableOrm } from "./core/
|
|
8
|
-
export { CellOrm } from "./core/
|
|
9
|
-
export { SchemaValidationError } from "./core/managers/
|
|
10
|
-
export type { ValidationResult } from "./core/managers/
|
|
5
|
+
export { defineSchema } from "./core/schema/schema";
|
|
6
|
+
export type { CreateSchema, SchemaDeclaration, Schema, TableSchemaDefinition, CellSchemaDefinition, TableOrmSchema, CellOrmSchema } from "./core/schema/schema";
|
|
7
|
+
export { TableOrm } from "./core/schema/table-orm";
|
|
8
|
+
export { CellOrm } from "./core/schema/cell-orm";
|
|
9
|
+
export { SchemaValidationError } from "./core/managers/schema-manager";
|
|
10
|
+
export type { ValidationResult } from "./core/managers/schema-manager";
|
|
11
11
|
export { SchemaIntegrityError } from "./core/commands/command-executor";
|
|
12
12
|
export type { EngineAction, EngineCommand } from "./core/commands/types";
|