@ricsam/formula-engine 0.0.22 → 0.2.0
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/engine.cjs +3 -3
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/schema-manager.cjs +58 -1
- package/dist/cjs/core/managers/schema-manager.cjs.map +3 -3
- package/dist/cjs/core/schema/cell-orm.cjs +8 -22
- package/dist/cjs/core/schema/cell-orm.cjs.map +3 -3
- package/dist/cjs/core/schema/grid-orm.cjs +115 -0
- package/dist/cjs/core/schema/grid-orm.cjs.map +10 -0
- package/dist/cjs/core/schema/schema-builder.cjs +9 -2
- package/dist/cjs/core/schema/schema-builder.cjs.map +3 -3
- package/dist/cjs/core/schema/schema-helpers.cjs +8 -9
- package/dist/cjs/core/schema/schema-helpers.cjs.map +3 -3
- package/dist/cjs/core/schema/schema.cjs +24 -4
- package/dist/cjs/core/schema/schema.cjs.map +3 -3
- package/dist/cjs/core/schema/table-orm.cjs +11 -3
- package/dist/cjs/core/schema/table-orm.cjs.map +3 -3
- package/dist/cjs/lib.cjs +2 -1
- package/dist/cjs/lib.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/engine.mjs +3 -3
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/schema-manager.mjs +58 -1
- package/dist/mjs/core/managers/schema-manager.mjs.map +3 -3
- package/dist/mjs/core/schema/cell-orm.mjs +8 -22
- package/dist/mjs/core/schema/cell-orm.mjs.map +3 -3
- package/dist/mjs/core/schema/grid-orm.mjs +84 -0
- package/dist/mjs/core/schema/grid-orm.mjs.map +10 -0
- package/dist/mjs/core/schema/schema-builder.mjs +9 -2
- package/dist/mjs/core/schema/schema-builder.mjs.map +3 -3
- package/dist/mjs/core/schema/schema-helpers.mjs +8 -9
- package/dist/mjs/core/schema/schema-helpers.mjs.map +3 -3
- package/dist/mjs/core/schema/schema.mjs +24 -4
- package/dist/mjs/core/schema/schema.mjs.map +3 -3
- package/dist/mjs/core/schema/table-orm.mjs +11 -3
- package/dist/mjs/core/schema/table-orm.mjs.map +3 -3
- package/dist/mjs/lib.mjs +3 -2
- package/dist/mjs/lib.mjs.map +2 -2
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/engine.d.ts +4 -1
- package/dist/types/core/managers/schema-manager.d.ts +20 -3
- package/dist/types/core/schema/cell-orm.d.ts +8 -4
- package/dist/types/core/schema/grid-orm.d.ts +63 -0
- package/dist/types/core/schema/schema-builder.d.ts +1 -1
- package/dist/types/core/schema/schema-helpers.d.ts +15 -3
- package/dist/types/core/schema/schema.d.ts +91 -14
- package/dist/types/lib.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GridOrm - Object-Relational Mapping for grid/range data
|
|
3
|
+
*
|
|
4
|
+
* Provides read/write operations for a 2D range of cells with type-safe access.
|
|
5
|
+
* Supports both column-major and row-major array access patterns.
|
|
6
|
+
*/
|
|
7
|
+
import type { FiniteSpreadsheetRange, SerializedCellValue } from "../types";
|
|
8
|
+
import type { FormulaEngine } from "../engine";
|
|
9
|
+
export type GridParseFunction<TCellMetadata, TValue> = (value: unknown, metadata: TCellMetadata) => TValue;
|
|
10
|
+
export type GridWriteFunction<TCellMetadata, TValue> = (value: TValue) => {
|
|
11
|
+
value: SerializedCellValue;
|
|
12
|
+
metadata?: TCellMetadata;
|
|
13
|
+
};
|
|
14
|
+
export declare class GridOrm<TValue, TCellMetadata = unknown> {
|
|
15
|
+
private engine;
|
|
16
|
+
private workbookName;
|
|
17
|
+
private sheetName;
|
|
18
|
+
private range;
|
|
19
|
+
private parser;
|
|
20
|
+
private writer;
|
|
21
|
+
private namespace;
|
|
22
|
+
private numCols;
|
|
23
|
+
private numRows;
|
|
24
|
+
constructor(engine: FormulaEngine<any, any>, workbookName: string, sheetName: string, range: FiniteSpreadsheetRange, parser: GridParseFunction<TCellMetadata, TValue>, writer: GridWriteFunction<TCellMetadata, TValue>, namespace: string);
|
|
25
|
+
/**
|
|
26
|
+
* Get the cell address for a given column and row index within the grid
|
|
27
|
+
*/
|
|
28
|
+
private getCellAddress;
|
|
29
|
+
/**
|
|
30
|
+
* Read a single cell and parse it
|
|
31
|
+
*/
|
|
32
|
+
private readCell;
|
|
33
|
+
/**
|
|
34
|
+
* Write a single cell using the write function
|
|
35
|
+
*/
|
|
36
|
+
private writeCell;
|
|
37
|
+
/**
|
|
38
|
+
* Get all cells as a column-major 2D array (readonly)
|
|
39
|
+
* columns[colIndex][rowIndex]
|
|
40
|
+
*/
|
|
41
|
+
get columns(): readonly (readonly TValue[])[];
|
|
42
|
+
/**
|
|
43
|
+
* Get all cells as a row-major 2D array (readonly)
|
|
44
|
+
* rows[rowIndex][colIndex]
|
|
45
|
+
*/
|
|
46
|
+
get rows(): readonly (readonly TValue[])[];
|
|
47
|
+
/**
|
|
48
|
+
* Set a single value at the specified position
|
|
49
|
+
* Position is relative to the grid (0-indexed)
|
|
50
|
+
*/
|
|
51
|
+
setValue(value: TValue, position: {
|
|
52
|
+
col: number;
|
|
53
|
+
row: number;
|
|
54
|
+
}): void;
|
|
55
|
+
/**
|
|
56
|
+
* Get a single value at the specified position
|
|
57
|
+
* Position is relative to the grid (0-indexed)
|
|
58
|
+
*/
|
|
59
|
+
getValue(position: {
|
|
60
|
+
col: number;
|
|
61
|
+
row: number;
|
|
62
|
+
}): TValue;
|
|
63
|
+
}
|
|
@@ -10,7 +10,7 @@ import type { SchemaManager } from "../managers/schema-manager";
|
|
|
10
10
|
/**
|
|
11
11
|
* Build the working schema surface from declarations
|
|
12
12
|
*
|
|
13
|
-
* This creates TableOrm and
|
|
13
|
+
* This creates TableOrm, CellOrm, and GridOrm instances for each declared schema
|
|
14
14
|
* and returns them directly.
|
|
15
15
|
*/
|
|
16
16
|
export declare function buildSchemaFromDeclaration(engine: FormulaEngine<any, any>, declaration: SchemaDeclaration, schemaManager: SchemaManager): Schema;
|
|
@@ -3,9 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { CellAddress, SerializedCellValue, TableDefinition } from "../types";
|
|
5
5
|
import type { FormulaEngine } from "../engine";
|
|
6
|
-
export type ParseFunction<TCellMetadata = unknown> = (value:
|
|
6
|
+
export type ParseFunction<TCellMetadata = unknown> = (value: SerializedCellValue, metadata: TCellMetadata) => unknown;
|
|
7
|
+
export type WriteFunction<TCellMetadata = unknown> = (value: unknown) => {
|
|
8
|
+
value: SerializedCellValue;
|
|
9
|
+
metadata?: TCellMetadata;
|
|
10
|
+
};
|
|
7
11
|
export type TableSchemaHeaders<TCellMetadata = unknown> = Record<string, {
|
|
8
12
|
parse: ParseFunction<TCellMetadata>;
|
|
13
|
+
write: WriteFunction<TCellMetadata>;
|
|
9
14
|
index: number;
|
|
10
15
|
}>;
|
|
11
16
|
/**
|
|
@@ -13,9 +18,16 @@ export type TableSchemaHeaders<TCellMetadata = unknown> = Record<string, {
|
|
|
13
18
|
*/
|
|
14
19
|
export declare function rowToObject<TItem extends Record<string, unknown>>(engine: FormulaEngine<any, any>, table: TableDefinition, rowIndex: number, headers: TableSchemaHeaders, getCellMetadata?: (cell: CellAddress) => unknown): TItem;
|
|
15
20
|
/**
|
|
16
|
-
*
|
|
21
|
+
* Result from objectToRowValues including both values and optional metadata
|
|
17
22
|
*/
|
|
18
|
-
export
|
|
23
|
+
export type RowValuesResult<TCellMetadata = unknown> = {
|
|
24
|
+
values: Map<number, SerializedCellValue>;
|
|
25
|
+
metadata: Map<number, TCellMetadata>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Convert a typed object to cell values based on headers using write functions
|
|
29
|
+
*/
|
|
30
|
+
export declare function objectToRowValues<TItem extends Record<string, unknown>, TCellMetadata = unknown>(obj: TItem, headers: TableSchemaHeaders<TCellMetadata>): RowValuesResult<TCellMetadata>;
|
|
19
31
|
/**
|
|
20
32
|
* Check if an object matches a filter predicate
|
|
21
33
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CellAddress } from "../types";
|
|
1
|
+
import type { CellAddress, FiniteSpreadsheetRange, SerializedCellValue } from "../types";
|
|
2
2
|
/**
|
|
3
3
|
* Define a schema for the FormulaEngine.
|
|
4
4
|
*
|
|
@@ -21,8 +21,7 @@ import type { CellAddress } from "../types";
|
|
|
21
21
|
* mySchema.schema.users.findWhere({ id: 1 }); // Error: schema is undefined at runtime
|
|
22
22
|
* ```
|
|
23
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;
|
|
24
|
+
export declare function defineSchema<TCellMetadata = unknown, TCurrentSchema extends Record<string, object> = Record<string, object>, TCurrentDeclaration extends Record<string, TableSchemaDefinition | CellSchemaDefinition | GridSchemaDefinition> = Record<string, TableSchemaDefinition | CellSchemaDefinition | GridSchemaDefinition>>(): CreateSchema<TCellMetadata, TCurrentSchema, TCurrentDeclaration>;
|
|
26
25
|
export interface TableSchemaDefinition {
|
|
27
26
|
type: "table";
|
|
28
27
|
headers: Headers<unknown>;
|
|
@@ -33,9 +32,28 @@ export interface CellSchemaDefinition {
|
|
|
33
32
|
type: "cell";
|
|
34
33
|
cellAddress: CellAddress;
|
|
35
34
|
parse: (value: unknown, metadata: unknown) => unknown;
|
|
35
|
+
write: (value: unknown) => {
|
|
36
|
+
value: SerializedCellValue;
|
|
37
|
+
metadata?: unknown;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface GridSchemaDefinition {
|
|
41
|
+
type: "grid";
|
|
42
|
+
workbookName: string;
|
|
43
|
+
sheetName: string;
|
|
44
|
+
range: FiniteSpreadsheetRange;
|
|
45
|
+
parse: (value: unknown, metadata: unknown) => unknown;
|
|
46
|
+
write: (value: unknown) => {
|
|
47
|
+
value: SerializedCellValue;
|
|
48
|
+
metadata?: unknown;
|
|
49
|
+
};
|
|
36
50
|
}
|
|
37
51
|
type Headers<TCellMetadata> = Record<string, {
|
|
38
|
-
parse:
|
|
52
|
+
parse: (value: SerializedCellValue, metadata: TCellMetadata) => unknown;
|
|
53
|
+
write: (value: any) => {
|
|
54
|
+
value: SerializedCellValue;
|
|
55
|
+
metadata?: TCellMetadata;
|
|
56
|
+
};
|
|
39
57
|
index: number;
|
|
40
58
|
}>;
|
|
41
59
|
/**
|
|
@@ -57,8 +75,53 @@ export type CellOrmSchema<TValue> = {
|
|
|
57
75
|
write(value: TValue): void;
|
|
58
76
|
getAddress(): CellAddress;
|
|
59
77
|
};
|
|
60
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Type representing the GridOrm methods exposed on the schema
|
|
80
|
+
*/
|
|
81
|
+
export type GridOrmSchema<TValue> = {
|
|
82
|
+
columns: readonly TValue[][];
|
|
83
|
+
rows: readonly TValue[][];
|
|
84
|
+
setValue(value: TValue, position: {
|
|
85
|
+
col: number;
|
|
86
|
+
row: number;
|
|
87
|
+
}): void;
|
|
88
|
+
getValue(position: {
|
|
89
|
+
col: number;
|
|
90
|
+
row: number;
|
|
91
|
+
}): TValue;
|
|
92
|
+
};
|
|
93
|
+
export type SchemaDeclaration = Record<string, TableSchemaDefinition | CellSchemaDefinition | GridSchemaDefinition>;
|
|
61
94
|
export type Schema = Record<string, object>;
|
|
95
|
+
/**
|
|
96
|
+
* Write function type for converting parsed values back to serializable form
|
|
97
|
+
*/
|
|
98
|
+
type WriteFunction<TValue, TCellMetadata> = (value: TValue) => {
|
|
99
|
+
value: SerializedCellValue;
|
|
100
|
+
metadata?: TCellMetadata;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Helper type to create the return type for addCellSchema/addGridSchema
|
|
104
|
+
*/
|
|
105
|
+
type AddCellSchemaResult<TCellMetadata, TCurrentSchema extends Schema, TCurrentDeclaration extends SchemaDeclaration, T extends string, TValue> = CreateSchema<TCellMetadata, TCurrentSchema & {
|
|
106
|
+
[K in T]: CellOrmSchema<TValue>;
|
|
107
|
+
}, TCurrentDeclaration & {
|
|
108
|
+
[K in T]: {
|
|
109
|
+
type: "cell";
|
|
110
|
+
cellAddress: CellAddress;
|
|
111
|
+
parse: (value: unknown, metadata: unknown) => unknown;
|
|
112
|
+
};
|
|
113
|
+
}>;
|
|
114
|
+
type AddGridSchemaResult<TCellMetadata, TCurrentSchema extends Schema, TCurrentDeclaration extends SchemaDeclaration, T extends string, TValue> = CreateSchema<TCellMetadata, TCurrentSchema & {
|
|
115
|
+
[K in T]: GridOrmSchema<TValue>;
|
|
116
|
+
}, TCurrentDeclaration & {
|
|
117
|
+
[K in T]: {
|
|
118
|
+
type: "grid";
|
|
119
|
+
workbookName: string;
|
|
120
|
+
sheetName: string;
|
|
121
|
+
range: FiniteSpreadsheetRange;
|
|
122
|
+
parse: (value: unknown, metadata: unknown) => unknown;
|
|
123
|
+
};
|
|
124
|
+
}>;
|
|
62
125
|
export type CreateSchema<TCellMetadata, TCurrentSchema extends Schema, TCurrentDeclaration extends SchemaDeclaration> = {
|
|
63
126
|
addTableSchema<T extends string, THeaders extends Headers<TCellMetadata>>(namespace: T, address: {
|
|
64
127
|
workbookName: string;
|
|
@@ -75,16 +138,30 @@ export type CreateSchema<TCellMetadata, TCurrentSchema extends Schema, TCurrentD
|
|
|
75
138
|
headers: THeaders;
|
|
76
139
|
};
|
|
77
140
|
}>;
|
|
78
|
-
addCellSchema<T extends string, TValue>(namespace: T, cellAddress: CellAddress, parse: (value: unknown, metadata: TCellMetadata) => TValue):
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
141
|
+
addCellSchema<T extends string, TValue>(namespace: T, cellAddress: CellAddress, parse: (value: unknown, metadata: TCellMetadata) => TValue, write: WriteFunction<TValue, TCellMetadata>): AddCellSchemaResult<TCellMetadata, TCurrentSchema, TCurrentDeclaration, T, TValue>;
|
|
142
|
+
addCellSchema<T extends string, TValue extends SerializedCellValue>(namespace: T, cellAddress: CellAddress, parse: (value: unknown, metadata: TCellMetadata) => TValue, write?: WriteFunction<TValue, TCellMetadata>): AddCellSchemaResult<TCellMetadata, TCurrentSchema, TCurrentDeclaration, T, TValue>;
|
|
143
|
+
addGridSchema<T extends string, TValue>(namespace: T, address: {
|
|
144
|
+
workbookName: string;
|
|
145
|
+
sheetName: string;
|
|
146
|
+
}, range: FiniteSpreadsheetRange, parse: (value: unknown, metadata: TCellMetadata) => TValue, write: WriteFunction<TValue, TCellMetadata>): AddGridSchemaResult<TCellMetadata, TCurrentSchema, TCurrentDeclaration, T, TValue>;
|
|
147
|
+
addGridSchema<T extends string, TValue extends SerializedCellValue>(namespace: T, address: {
|
|
148
|
+
workbookName: string;
|
|
149
|
+
sheetName: string;
|
|
150
|
+
}, range: FiniteSpreadsheetRange, parse: (value: unknown, metadata: TCellMetadata) => TValue, write?: WriteFunction<TValue, TCellMetadata>): AddGridSchemaResult<TCellMetadata, TCurrentSchema, TCurrentDeclaration, T, TValue>;
|
|
87
151
|
schema: TCurrentSchema;
|
|
88
152
|
declaration: TCurrentDeclaration;
|
|
89
153
|
};
|
|
154
|
+
export declare const defineHeader: <TValue, TMetadata>(index: number, parse: (value: SerializedCellValue, metadata: TMetadata) => TValue, write?: (value: TValue) => {
|
|
155
|
+
value: SerializedCellValue;
|
|
156
|
+
metadata?: TMetadata;
|
|
157
|
+
}) => {
|
|
158
|
+
parse: (value: SerializedCellValue, metadata: TMetadata) => TValue;
|
|
159
|
+
write: ((value: TValue) => {
|
|
160
|
+
value: SerializedCellValue;
|
|
161
|
+
metadata?: TMetadata;
|
|
162
|
+
}) | ((value: TValue) => {
|
|
163
|
+
value: TValue;
|
|
164
|
+
});
|
|
165
|
+
index: number;
|
|
166
|
+
};
|
|
90
167
|
export {};
|
package/dist/types/lib.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ 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 { defineSchema } from "./core/schema/schema";
|
|
5
|
+
export { defineSchema, defineHeader } from "./core/schema/schema";
|
|
6
6
|
export type { CreateSchema, SchemaDeclaration, Schema, TableSchemaDefinition, CellSchemaDefinition, TableOrmSchema, CellOrmSchema } from "./core/schema/schema";
|
|
7
7
|
export { TableOrm } from "./core/schema/table-orm";
|
|
8
8
|
export { CellOrm } from "./core/schema/cell-orm";
|