@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.
- package/dist/cjs/core/api/api-builder.cjs +3 -13
- package/dist/cjs/core/api/api-builder.cjs.map +3 -3
- package/dist/cjs/core/api/api.cjs +5 -7
- package/dist/cjs/core/api/api.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/api/api-builder.mjs +3 -13
- package/dist/mjs/core/api/api-builder.mjs.map +3 -3
- package/dist/mjs/core/api/api.mjs +5 -7
- package/dist/mjs/core/api/api.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/api/api-builder.d.ts +1 -1
- package/dist/types/core/api/api.d.ts +33 -25
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
-
|
|
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=
|
|
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
|
|
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,
|
|
8
|
-
"debugId": "
|
|
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
|
|
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
|
|
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=
|
|
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\";\
|
|
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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8
|
-
"debugId": "
|
|
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
|
}
|
package/dist/cjs/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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=
|
|
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
|
|
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,
|
|
8
|
-
"debugId": "
|
|
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
|
|
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
|
|
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=
|
|
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\";\
|
|
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": ";
|
|
8
|
-
"debugId": "
|
|
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
|
}
|
package/dist/mjs/package.json
CHANGED
|
@@ -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
|
|
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
|
|
18
|
-
* .addCellApi("config", cellAddress, parse
|
|
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.
|
|
22
|
-
*
|
|
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,
|
|
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
|
-
|
|
46
|
-
|
|
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,
|
|
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
|
|
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
|
|
56
|
-
[K in T]: {
|
|
57
|
-
[
|
|
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
|
|
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;
|