@ricsam/formula-engine 0.0.20 → 0.0.21

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.
@@ -47,21 +47,11 @@ function buildApiFromDeclaration(engine, declaration, schemaManager) {
47
47
  }
48
48
  function buildTableApi(engine, namespace, def, schemaManager) {
49
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;
50
+ return new import_table_orm.TableOrm(engine, def.workbookName, def.tableName, def.headers, namespace);
56
51
  }
57
52
  function buildCellApi(engine, namespace, def, schemaManager) {
58
53
  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;
54
+ return new import_cell_orm.CellOrm(engine, def.cellAddress, def.parse, namespace);
65
55
  }
66
56
 
67
- //# debugId=1A339C89282699D664756E2164756E21
57
+ //# debugId=EDDFC14633608D2364756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/api/api-builder.ts"],
4
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"
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 returns them directly.\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 for a table schema - returns TableOrm instance directly\n */\nfunction buildTableApi(\n engine: FormulaEngine<any, any>,\n namespace: string,\n def: TableApi,\n schemaManager: ApiSchemaManager\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 API for a cell schema - returns CellOrm instance directly\n */\nfunction buildCellApi(\n engine: FormulaEngine<any, any>,\n namespace: string,\n def: CellApi,\n schemaManager: ApiSchemaManager\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
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",
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,eACe;AAAA,EAEf,cAAc,oBACZ,WACA,IAAI,cACJ,IAAI,WACJ,IAAI,OACN;AAAA,EAGA,OAAO,IAAI,0BACT,QACA,IAAI,cACJ,IAAI,WACJ,IAAI,SACJ,SACF;AAAA;AAMF,SAAS,YAAY,CACnB,QACA,WACA,KACA,eACc;AAAA,EAEd,cAAc,mBAAmB,WAAW,IAAI,aAAa,IAAI,KAAK;AAAA,EAGtE,OAAO,IAAI,wBAAQ,QAAQ,IAAI,aAAa,IAAI,OAAO,SAAS;AAAA;",
8
+ "debugId": "EDDFC14633608D2364756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -36,22 +36,20 @@ module.exports = __toCommonJS(exports_api);
36
36
  function defineApi() {
37
37
  const declaration = {};
38
38
  const builder = {
39
- addTableApi(namespace, address, headers, methods) {
39
+ addTableApi(namespace, address, headers) {
40
40
  declaration[namespace] = {
41
41
  type: "table",
42
42
  tableName: address.tableName,
43
43
  workbookName: address.workbookName,
44
- headers,
45
- methods
44
+ headers
46
45
  };
47
46
  return builder;
48
47
  },
49
- addCellApi(namespace, cellAddress, parse, methods) {
48
+ addCellApi(namespace, cellAddress, parse) {
50
49
  declaration[namespace] = {
51
50
  type: "cell",
52
51
  cellAddress,
53
- parse,
54
- methods
52
+ parse
55
53
  };
56
54
  return builder;
57
55
  },
@@ -62,4 +60,4 @@ function defineApi() {
62
60
  }
63
61
  var createApi = defineApi;
64
62
 
65
- //# debugId=00202A4557ACD94664756E2164756E21
63
+ //# debugId=071184DEA6DB276964756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/api/api.ts"],
4
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"
5
+ "import type { CellAddress } from \"../types.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)\n * .addCellApi(\"config\", cellAddress, parse);\n *\n * const engine = new FormulaEngine(myApi);\n * engine.api.users.findWhere({ id: 1 }); // Works!\n * engine.api.config.read(); // Works!\n * myApi.api.users.findWhere({ id: 1 }); // Error: api is undefined at runtime\n * ```\n */\nexport function defineApi<\n TCellMetadata = unknown,\n TCurrentApi extends Record<string, object> = Record<string, object>,\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) {\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 addCellApi(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 // 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}\n\nexport interface CellApi {\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 API\n */\nexport type TableOrmApi<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 API\n */\nexport type CellOrmApi<TValue> = {\n read(): TValue;\n write(value: TValue): void;\n getAddress(): CellAddress;\n};\n\nexport type Declaration = Record<string, TableApi | CellApi>;\nexport type Api = Record<string, object>;\n\nexport type CreateApi<\n TCellMetadata,\n TCurrentApi extends Api,\n TCurrentDeclaration extends Declaration\n> = {\n addTableApi<T extends string, THeaders extends Headers<TCellMetadata>>(\n namespace: T,\n address: { workbookName: string; tableName: string },\n headers: THeaders\n ): CreateApi<\n TCellMetadata,\n TCurrentApi & {\n [K in T]: TableOrmApi<{\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 addCellApi<T extends string, TValue>(\n namespace: T,\n cellAddress: CellAddress,\n parse: (value: unknown, metadata: TCellMetadata) => TValue\n ): CreateApi<\n TCellMetadata,\n TCurrentApi & {\n [K in T]: CellOrmApi<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 api: TCurrentApi;\n declaration: TCurrentDeclaration;\n};\n"
6
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",
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,SAAS,SAOf,GAA+D;AAAA,EAC9D,MAAM,cAAkD,CAAC;AAAA,EAEzD,MAAM,UAAsE;AAAA,IAC1E,WAAW,CAAC,WAAW,SAAS,SAAS;AAAA,MACvC,YAAY,aAAa;AAAA,QACvB,MAAM;AAAA,QACN,WAAW,QAAQ;AAAA,QACnB,cAAc,QAAQ;AAAA,QACtB;AAAA,MACF;AAAA,MACA,OAAO;AAAA;AAAA,IAGT,UAAU,CAAC,WAAW,aAAa,OAAO;AAAA,MACxC,YAAY,aAAa;AAAA,QACvB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACF;AAAA,MACA,OAAO;AAAA;AAAA,IAKT,KAAK;AAAA,IAEL;AAAA,EACF;AAAA,EAEA,OAAO;AAAA;AAIF,IAAM,YAAY;",
8
+ "debugId": "071184DEA6DB276964756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "type": "commonjs"
5
5
  }
@@ -14,24 +14,14 @@ function buildApiFromDeclaration(engine, declaration, schemaManager) {
14
14
  }
15
15
  function buildTableApi(engine, namespace, def, schemaManager) {
16
16
  schemaManager.registerTableSchema(namespace, def.workbookName, def.tableName, def.headers);
17
- const orm = new TableOrm(engine, def.workbookName, def.tableName, def.headers, namespace);
18
- const boundMethods = {};
19
- for (const [methodName, methodFn] of Object.entries(def.methods)) {
20
- boundMethods[methodName] = methodFn.bind(orm);
21
- }
22
- return boundMethods;
17
+ return new TableOrm(engine, def.workbookName, def.tableName, def.headers, namespace);
23
18
  }
24
19
  function buildCellApi(engine, namespace, def, schemaManager) {
25
20
  schemaManager.registerCellSchema(namespace, def.cellAddress, def.parse);
26
- const orm = new CellOrm(engine, def.cellAddress, def.parse, namespace);
27
- const boundMethods = {};
28
- for (const [methodName, methodFn] of Object.entries(def.methods)) {
29
- boundMethods[methodName] = methodFn.bind(orm);
30
- }
31
- return boundMethods;
21
+ return new CellOrm(engine, def.cellAddress, def.parse, namespace);
32
22
  }
33
23
  export {
34
24
  buildApiFromDeclaration
35
25
  };
36
26
 
37
- //# debugId=D8642EAD6BFC352164756E2164756E21
27
+ //# debugId=3B353A0CD99B342764756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/api/api-builder.ts"],
4
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.mjs\";\nimport type { Declaration, TableApi, CellApi, Api } from \"./api.mjs\";\nimport { TableOrm } from \"./table-orm.mjs\";\nimport { CellOrm } from \"./cell-orm.mjs\";\nimport type { ApiSchemaManager } from \"../managers/api-schema-manager.mjs\";\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"
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.mjs\";\nimport type { Declaration, TableApi, CellApi, Api } from \"./api.mjs\";\nimport { TableOrm } from \"./table-orm.mjs\";\nimport { CellOrm } from \"./cell-orm.mjs\";\nimport type { ApiSchemaManager } from \"../managers/api-schema-manager.mjs\";\n\n/**\n * Build the working API surface from declarations\n *\n * This creates TableOrm and CellOrm instances for each declared schema\n * and returns them directly.\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 for a table schema - returns TableOrm instance directly\n */\nfunction buildTableApi(\n engine: FormulaEngine<any, any>,\n namespace: string,\n def: TableApi,\n schemaManager: ApiSchemaManager\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 API for a cell schema - returns CellOrm instance directly\n */\nfunction buildCellApi(\n engine: FormulaEngine<any, any>,\n namespace: string,\n def: CellApi,\n schemaManager: ApiSchemaManager\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
6
  ],
7
- "mappings": ";AASA;AACA;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,SACd,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,QAAQ,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": "D8642EAD6BFC352164756E2164756E21",
7
+ "mappings": ";AASA;AACA;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,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,YAAY,CACnB,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": "3B353A0CD99B342764756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -2,22 +2,20 @@
2
2
  function defineApi() {
3
3
  const declaration = {};
4
4
  const builder = {
5
- addTableApi(namespace, address, headers, methods) {
5
+ addTableApi(namespace, address, headers) {
6
6
  declaration[namespace] = {
7
7
  type: "table",
8
8
  tableName: address.tableName,
9
9
  workbookName: address.workbookName,
10
- headers,
11
- methods
10
+ headers
12
11
  };
13
12
  return builder;
14
13
  },
15
- addCellApi(namespace, cellAddress, parse, methods) {
14
+ addCellApi(namespace, cellAddress, parse) {
16
15
  declaration[namespace] = {
17
16
  type: "cell",
18
17
  cellAddress,
19
- parse,
20
- methods
18
+ parse
21
19
  };
22
20
  return builder;
23
21
  },
@@ -32,4 +30,4 @@ export {
32
30
  createApi
33
31
  };
34
32
 
35
- //# debugId=9CD7AE5B7F689F5D64756E2164756E21
33
+ //# debugId=6D6EFC9F69FE55CC64756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/api/api.ts"],
4
4
  "sourcesContent": [
5
- "import type { CellAddress } from \"../types.mjs\";\nimport type { CellOrm } from \"./cell-orm.mjs\";\nimport type { TableOrm } from \"./table-orm.mjs\";\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"
5
+ "import type { CellAddress } from \"../types.mjs\";\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)\n * .addCellApi(\"config\", cellAddress, parse);\n *\n * const engine = new FormulaEngine(myApi);\n * engine.api.users.findWhere({ id: 1 }); // Works!\n * engine.api.config.read(); // Works!\n * myApi.api.users.findWhere({ id: 1 }); // Error: api is undefined at runtime\n * ```\n */\nexport function defineApi<\n TCellMetadata = unknown,\n TCurrentApi extends Record<string, object> = Record<string, object>,\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) {\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 addCellApi(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 // 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}\n\nexport interface CellApi {\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 API\n */\nexport type TableOrmApi<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 API\n */\nexport type CellOrmApi<TValue> = {\n read(): TValue;\n write(value: TValue): void;\n getAddress(): CellAddress;\n};\n\nexport type Declaration = Record<string, TableApi | CellApi>;\nexport type Api = Record<string, object>;\n\nexport type CreateApi<\n TCellMetadata,\n TCurrentApi extends Api,\n TCurrentDeclaration extends Declaration\n> = {\n addTableApi<T extends string, THeaders extends Headers<TCellMetadata>>(\n namespace: T,\n address: { workbookName: string; tableName: string },\n headers: THeaders\n ): CreateApi<\n TCellMetadata,\n TCurrentApi & {\n [K in T]: TableOrmApi<{\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 addCellApi<T extends string, TValue>(\n namespace: T,\n cellAddress: CellAddress,\n parse: (value: unknown, metadata: TCellMetadata) => TValue\n ): CreateApi<\n TCellMetadata,\n TCurrentApi & {\n [K in T]: CellOrmApi<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 api: TCurrentApi;\n declaration: TCurrentDeclaration;\n};\n"
6
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": "9CD7AE5B7F689F5D64756E2164756E21",
7
+ "mappings": ";AAwBO,SAAS,SAOf,GAA+D;AAAA,EAC9D,MAAM,cAAkD,CAAC;AAAA,EAEzD,MAAM,UAAsE;AAAA,IAC1E,WAAW,CAAC,WAAW,SAAS,SAAS;AAAA,MACvC,YAAY,aAAa;AAAA,QACvB,MAAM;AAAA,QACN,WAAW,QAAQ;AAAA,QACnB,cAAc,QAAQ;AAAA,QACtB;AAAA,MACF;AAAA,MACA,OAAO;AAAA;AAAA,IAGT,UAAU,CAAC,WAAW,aAAa,OAAO;AAAA,MACxC,YAAY,aAAa;AAAA,QACvB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACF;AAAA,MACA,OAAO;AAAA;AAAA,IAKT,KAAK;AAAA,IAEL;AAAA,EACF;AAAA,EAEA,OAAO;AAAA;AAIF,IAAM,YAAY;",
8
+ "debugId": "6D6EFC9F69FE55CC64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "type": "module"
5
5
  }
@@ -11,6 +11,6 @@ import type { ApiSchemaManager } from "../managers/api-schema-manager";
11
11
  * Build the working API surface from declarations
12
12
  *
13
13
  * This creates TableOrm and CellOrm instances for each declared schema
14
- * and binds the custom methods to them.
14
+ * and returns them directly.
15
15
  */
16
16
  export declare function buildApiFromDeclaration(engine: FormulaEngine<any, any>, declaration: Declaration, schemaManager: ApiSchemaManager): Api;
@@ -1,6 +1,4 @@
1
1
  import type { CellAddress } from "../types";
2
- import type { CellOrm } from "./cell-orm";
3
- import type { TableOrm } from "./table-orm";
4
2
  /**
5
3
  * Define an API schema for the FormulaEngine.
6
4
  *
@@ -14,15 +12,16 @@ import type { TableOrm } from "./table-orm";
14
12
  * @example
15
13
  * ```typescript
16
14
  * const myApi = defineApi<CellMetadata>()
17
- * .addTableApi("users", { workbookName: "wb1", tableName: "users" }, headers, methods)
18
- * .addCellApi("config", cellAddress, parse, methods);
15
+ * .addTableApi("users", { workbookName: "wb1", tableName: "users" }, headers)
16
+ * .addCellApi("config", cellAddress, parse);
19
17
  *
20
18
  * const engine = new FormulaEngine(myApi);
21
- * engine.api.users.get(1); // Works!
22
- * myApi.api.users.get(1); // Error: api is undefined at runtime
19
+ * engine.api.users.findWhere({ id: 1 }); // Works!
20
+ * engine.api.config.read(); // Works!
21
+ * myApi.api.users.findWhere({ id: 1 }); // Error: api is undefined at runtime
23
22
  * ```
24
23
  */
25
- export declare function defineApi<TCellMetadata = unknown, TCurrentApi extends Record<string, Record<string, (...args: any[]) => any>> = Record<string, Record<string, (...args: any[]) => any>>, TCurrentDeclaration extends Record<string, TableApi | CellApi> = Record<string, TableApi | CellApi>>(): CreateApi<TCellMetadata, TCurrentApi, TCurrentDeclaration>;
24
+ export declare function defineApi<TCellMetadata = unknown, TCurrentApi extends Record<string, object> = Record<string, object>, TCurrentDeclaration extends Record<string, TableApi | CellApi> = Record<string, TableApi | CellApi>>(): CreateApi<TCellMetadata, TCurrentApi, TCurrentDeclaration>;
26
25
  export declare const createApi: typeof defineApi;
27
26
  type ParseFunction<TCellMetadata> = (value: unknown, metadata: TCellMetadata) => unknown;
28
27
  export interface TableApi {
@@ -30,51 +29,60 @@ export interface TableApi {
30
29
  headers: Headers<unknown>;
31
30
  tableName: string;
32
31
  workbookName: string;
33
- methods: TableMethods<Record<string, unknown>>;
34
32
  }
35
33
  export interface CellApi {
36
34
  type: "cell";
37
35
  cellAddress: CellAddress;
38
36
  parse: (value: unknown, metadata: unknown) => unknown;
39
- methods: CellMethods<unknown>;
40
37
  }
41
38
  type Headers<TCellMetadata> = Record<string, {
42
39
  parse: ParseFunction<TCellMetadata>;
43
40
  index: number;
44
41
  }>;
45
- type TableMethods<TItem extends Record<string, unknown>> = Record<string, (this: TableOrm<TItem>, ...args: any[]) => any>;
46
- type CellMethods<TValue> = Record<string, (this: CellOrm<TValue>, ...args: any[]) => any>;
42
+ /**
43
+ * Type representing the TableOrm methods exposed on the API
44
+ */
45
+ export type TableOrmApi<TItem extends Record<string, unknown>> = {
46
+ findWhere(filter: Partial<TItem>): TItem | undefined;
47
+ findAllWhere(filter: Partial<TItem>): TItem[];
48
+ append(item: TItem): TItem;
49
+ updateWhere(filter: Partial<TItem>, update: Partial<TItem>): number;
50
+ removeWhere(filter: Partial<TItem>): number;
51
+ count(): number;
52
+ };
53
+ /**
54
+ * Type representing the CellOrm methods exposed on the API
55
+ */
56
+ export type CellOrmApi<TValue> = {
57
+ read(): TValue;
58
+ write(value: TValue): void;
59
+ getAddress(): CellAddress;
60
+ };
47
61
  export type Declaration = Record<string, TableApi | CellApi>;
48
- export type Api = Record<string, Record<string, (...args: any[]) => any>>;
62
+ export type Api = Record<string, object>;
49
63
  export type CreateApi<TCellMetadata, TCurrentApi extends Api, TCurrentDeclaration extends Declaration> = {
50
- addTableApi<T extends string, THeaders extends Headers<TCellMetadata>, TMethods extends TableMethods<{
51
- [K in keyof THeaders]: ReturnType<THeaders[K]["parse"]>;
52
- }>>(namespace: T, address: {
64
+ addTableApi<T extends string, THeaders extends Headers<TCellMetadata>>(namespace: T, address: {
53
65
  workbookName: string;
54
66
  tableName: string;
55
- }, headers: THeaders, methods: TMethods): CreateApi<TCellMetadata, TCurrentApi & {
56
- [K in T]: {
57
- [M in keyof TMethods]: (...args: Parameters<TMethods[M]>) => ReturnType<TMethods[M]>;
58
- };
67
+ }, headers: THeaders): CreateApi<TCellMetadata, TCurrentApi & {
68
+ [K in T]: TableOrmApi<{
69
+ [H in keyof THeaders]: ReturnType<THeaders[H]["parse"]>;
70
+ }>;
59
71
  }, TCurrentDeclaration & {
60
72
  [K in T]: {
61
73
  type: "table";
62
74
  tableName: string;
63
75
  workbookName: string;
64
76
  headers: THeaders;
65
- methods: TMethods;
66
77
  };
67
78
  }>;
68
- addCellApi<T extends string, TValue, TMethods extends CellMethods<TValue>>(namespace: T, cellAddress: CellAddress, parse: (value: unknown, metadata: TCellMetadata) => TValue, methods: TMethods): CreateApi<TCellMetadata, TCurrentApi & {
69
- [K in T]: {
70
- [M in keyof TMethods]: (...args: Parameters<TMethods[M]>) => ReturnType<TMethods[M]>;
71
- };
79
+ addCellApi<T extends string, TValue>(namespace: T, cellAddress: CellAddress, parse: (value: unknown, metadata: TCellMetadata) => TValue): CreateApi<TCellMetadata, TCurrentApi & {
80
+ [K in T]: CellOrmApi<TValue>;
72
81
  }, TCurrentDeclaration & {
73
82
  [K in T]: {
74
83
  type: "cell";
75
84
  cellAddress: CellAddress;
76
85
  parse: (value: unknown, metadata: unknown) => unknown;
77
- methods: TMethods;
78
86
  };
79
87
  }>;
80
88
  api: TCurrentApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "module": "./dist/mjs/lib.mjs",
5
5
  "scripts": {
6
6
  "test": "bun test",