@bilig/formula 0.1.2 → 0.1.4
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/builtins/placeholder.d.ts +2 -2
- package/dist/builtins/text-format-builtins.d.ts +14 -0
- package/dist/builtins/text-format-builtins.js +537 -0
- package/dist/builtins/text-format-builtins.js.map +1 -0
- package/dist/builtins/text-search-builtins.d.ts +21 -0
- package/dist/builtins/text-search-builtins.js +469 -0
- package/dist/builtins/text-search-builtins.js.map +1 -0
- package/dist/builtins/text.js +31 -968
- package/dist/builtins/text.js.map +1 -1
- package/dist/js-evaluator-array-special-calls.d.ts +28 -0
- package/dist/js-evaluator-array-special-calls.js +340 -0
- package/dist/js-evaluator-array-special-calls.js.map +1 -0
- package/dist/js-evaluator-context-special-calls.d.ts +24 -0
- package/dist/js-evaluator-context-special-calls.js +156 -0
- package/dist/js-evaluator-context-special-calls.js.map +1 -0
- package/dist/js-evaluator-types.d.ts +117 -0
- package/dist/js-evaluator-types.js +2 -0
- package/dist/js-evaluator-types.js.map +1 -0
- package/dist/js-evaluator-workbook-special-calls.d.ts +24 -0
- package/dist/js-evaluator-workbook-special-calls.js +185 -0
- package/dist/js-evaluator-workbook-special-calls.js.map +1 -0
- package/dist/js-evaluator.d.ts +3 -100
- package/dist/js-evaluator.js +58 -672
- package/dist/js-evaluator.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ErrorCode, ValueTag } from "@bilig/protocol";
|
|
2
|
+
export function evaluateContextSpecialCall(callee, rawArgs, context, argRefs, deps) {
|
|
3
|
+
switch (callee) {
|
|
4
|
+
case "ROW": {
|
|
5
|
+
if (rawArgs.length > 1) {
|
|
6
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
7
|
+
}
|
|
8
|
+
const row = deps.referenceRowNumber(argRefs[0], context);
|
|
9
|
+
return deps.stackScalar(row === undefined ? deps.error(ErrorCode.Value) : deps.numberValue(row));
|
|
10
|
+
}
|
|
11
|
+
case "COLUMN": {
|
|
12
|
+
if (rawArgs.length > 1) {
|
|
13
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
14
|
+
}
|
|
15
|
+
const column = deps.referenceColumnNumber(argRefs[0], context);
|
|
16
|
+
return deps.stackScalar(column === undefined ? deps.error(ErrorCode.Value) : deps.numberValue(column));
|
|
17
|
+
}
|
|
18
|
+
case "ISOMITTED": {
|
|
19
|
+
if (rawArgs.length !== 1) {
|
|
20
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
21
|
+
}
|
|
22
|
+
return deps.stackScalar({ tag: ValueTag.Boolean, value: rawArgs[0]?.kind === "omitted" });
|
|
23
|
+
}
|
|
24
|
+
case "FORMULATEXT":
|
|
25
|
+
case "FORMULA": {
|
|
26
|
+
if (rawArgs.length !== 1) {
|
|
27
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
28
|
+
}
|
|
29
|
+
const address = deps.referenceTopLeftAddress(argRefs[0]);
|
|
30
|
+
const sheetName = deps.referenceSheetName(argRefs[0], context);
|
|
31
|
+
if (!address || !sheetName) {
|
|
32
|
+
return deps.stackScalar(deps.error(ErrorCode.Ref));
|
|
33
|
+
}
|
|
34
|
+
const formula = context.resolveFormula?.(sheetName, address);
|
|
35
|
+
return deps.stackScalar(formula
|
|
36
|
+
? deps.stringValue(formula.startsWith("=") ? formula : `=${formula}`)
|
|
37
|
+
: deps.error(ErrorCode.NA));
|
|
38
|
+
}
|
|
39
|
+
case "PHONETIC": {
|
|
40
|
+
if (rawArgs.length !== 1) {
|
|
41
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
42
|
+
}
|
|
43
|
+
const target = rawArgs[0];
|
|
44
|
+
if (target.kind === "scalar") {
|
|
45
|
+
return deps.stackScalar(deps.stringValue(deps.toStringValue(target.value)));
|
|
46
|
+
}
|
|
47
|
+
if (target.kind === "range") {
|
|
48
|
+
return deps.stackScalar(deps.stringValue(deps.toStringValue(target.values[0] ?? deps.emptyValue())));
|
|
49
|
+
}
|
|
50
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
51
|
+
}
|
|
52
|
+
case "CHOOSE": {
|
|
53
|
+
if (rawArgs.length < 2) {
|
|
54
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
55
|
+
}
|
|
56
|
+
const indexValue = deps.isSingleCellValue(rawArgs[0]);
|
|
57
|
+
const choice = indexValue ? deps.toNumber(indexValue) : undefined;
|
|
58
|
+
if (choice === undefined || !Number.isFinite(choice)) {
|
|
59
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
60
|
+
}
|
|
61
|
+
const truncated = Math.trunc(choice);
|
|
62
|
+
if (truncated < 1 || truncated >= rawArgs.length) {
|
|
63
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
64
|
+
}
|
|
65
|
+
return deps.cloneStackValue(rawArgs[truncated]);
|
|
66
|
+
}
|
|
67
|
+
case "SHEET": {
|
|
68
|
+
if (rawArgs.length > 1) {
|
|
69
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
70
|
+
}
|
|
71
|
+
if (rawArgs.length === 0) {
|
|
72
|
+
const index = deps.sheetIndexByName(context.sheetName, context);
|
|
73
|
+
return deps.stackScalar(index === undefined ? deps.error(ErrorCode.NA) : deps.numberValue(index));
|
|
74
|
+
}
|
|
75
|
+
if (argRefs[0]) {
|
|
76
|
+
const index = deps.sheetIndexByName(deps.referenceSheetName(argRefs[0], context) ?? context.sheetName, context);
|
|
77
|
+
return deps.stackScalar(index === undefined ? deps.error(ErrorCode.NA) : deps.numberValue(index));
|
|
78
|
+
}
|
|
79
|
+
const scalar = deps.isSingleCellValue(rawArgs[0]);
|
|
80
|
+
if (scalar?.tag !== ValueTag.String) {
|
|
81
|
+
return deps.stackScalar(deps.error(ErrorCode.NA));
|
|
82
|
+
}
|
|
83
|
+
const index = deps.sheetIndexByName(scalar.value, context);
|
|
84
|
+
return deps.stackScalar(index === undefined ? deps.error(ErrorCode.NA) : deps.numberValue(index));
|
|
85
|
+
}
|
|
86
|
+
case "SHEETS": {
|
|
87
|
+
if (rawArgs.length > 1) {
|
|
88
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
89
|
+
}
|
|
90
|
+
if (rawArgs.length === 0) {
|
|
91
|
+
return deps.stackScalar(deps.numberValue(deps.sheetNames(context).length));
|
|
92
|
+
}
|
|
93
|
+
if (argRefs[0]) {
|
|
94
|
+
return deps.stackScalar(deps.numberValue(1));
|
|
95
|
+
}
|
|
96
|
+
const scalar = deps.isSingleCellValue(rawArgs[0]);
|
|
97
|
+
if (scalar?.tag !== ValueTag.String) {
|
|
98
|
+
return deps.stackScalar(deps.error(ErrorCode.NA));
|
|
99
|
+
}
|
|
100
|
+
return deps.stackScalar(deps.sheetIndexByName(scalar.value, context) === undefined
|
|
101
|
+
? deps.error(ErrorCode.NA)
|
|
102
|
+
: deps.numberValue(1));
|
|
103
|
+
}
|
|
104
|
+
case "CELL": {
|
|
105
|
+
if (rawArgs.length < 1 || rawArgs.length > 2) {
|
|
106
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
107
|
+
}
|
|
108
|
+
const infoType = deps.isSingleCellValue(rawArgs[0]);
|
|
109
|
+
if (infoType?.tag !== ValueTag.String) {
|
|
110
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
111
|
+
}
|
|
112
|
+
const ref = rawArgs.length === 2 ? argRefs[1] : deps.currentCellReference(context);
|
|
113
|
+
if (!ref) {
|
|
114
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
115
|
+
}
|
|
116
|
+
const normalizedInfoType = infoType.value.trim().toLowerCase();
|
|
117
|
+
switch (normalizedInfoType) {
|
|
118
|
+
case "address": {
|
|
119
|
+
const address = deps.absoluteAddress(ref, context);
|
|
120
|
+
return deps.stackScalar(address ? deps.stringValue(address) : deps.error(ErrorCode.Value));
|
|
121
|
+
}
|
|
122
|
+
case "row": {
|
|
123
|
+
const row = deps.referenceRowNumber(ref, context);
|
|
124
|
+
return deps.stackScalar(row === undefined ? deps.error(ErrorCode.Value) : deps.numberValue(row));
|
|
125
|
+
}
|
|
126
|
+
case "col": {
|
|
127
|
+
const column = deps.referenceColumnNumber(ref, context);
|
|
128
|
+
return deps.stackScalar(column === undefined ? deps.error(ErrorCode.Value) : deps.numberValue(column));
|
|
129
|
+
}
|
|
130
|
+
case "contents": {
|
|
131
|
+
const address = deps.referenceTopLeftAddress(ref);
|
|
132
|
+
const sheetName = deps.referenceSheetName(ref, context);
|
|
133
|
+
if (!address || !sheetName) {
|
|
134
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
135
|
+
}
|
|
136
|
+
return deps.stackScalar(context.resolveCell(sheetName, address));
|
|
137
|
+
}
|
|
138
|
+
case "type": {
|
|
139
|
+
const address = deps.referenceTopLeftAddress(ref);
|
|
140
|
+
const sheetName = deps.referenceSheetName(ref, context);
|
|
141
|
+
if (!address || !sheetName) {
|
|
142
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
143
|
+
}
|
|
144
|
+
return deps.stackScalar(deps.stringValue(deps.cellTypeCode(context.resolveCell(sheetName, address))));
|
|
145
|
+
}
|
|
146
|
+
case "filename":
|
|
147
|
+
return deps.stackScalar(deps.stringValue(""));
|
|
148
|
+
default:
|
|
149
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
default:
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=js-evaluator-context-special-calls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-evaluator-context-special-calls.js","sourceRoot":"","sources":["../src/js-evaluator-context-special-calls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,iBAAiB,CAAC;AAoCtE,MAAM,UAAU,0BA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@@
|
|
|
1
|
+
import type { ErrorCode, CellValue } from "@bilig/protocol";
|
|
2
|
+
import type { ArrayValue, EvaluationResult } from "./runtime-values.js";
|
|
3
|
+
export interface EvaluationContext {
|
|
4
|
+
sheetName: string;
|
|
5
|
+
currentAddress?: string;
|
|
6
|
+
resolveCell: (sheetName: string, address: string) => CellValue;
|
|
7
|
+
resolveRange: (sheetName: string, start: string, end: string, refKind: "cells" | "rows" | "cols") => CellValue[];
|
|
8
|
+
resolveName?: (name: string) => CellValue;
|
|
9
|
+
resolveFormula?: (sheetName: string, address: string) => string | undefined;
|
|
10
|
+
resolvePivotData?: (request: {
|
|
11
|
+
dataField: string;
|
|
12
|
+
sheetName: string;
|
|
13
|
+
address: string;
|
|
14
|
+
filters: ReadonlyArray<{
|
|
15
|
+
field: string;
|
|
16
|
+
item: CellValue;
|
|
17
|
+
}>;
|
|
18
|
+
}) => CellValue | undefined;
|
|
19
|
+
resolveMultipleOperations?: (request: {
|
|
20
|
+
formulaSheetName: string;
|
|
21
|
+
formulaAddress: string;
|
|
22
|
+
rowCellSheetName: string;
|
|
23
|
+
rowCellAddress: string;
|
|
24
|
+
rowReplacementSheetName: string;
|
|
25
|
+
rowReplacementAddress: string;
|
|
26
|
+
columnCellSheetName?: string;
|
|
27
|
+
columnCellAddress?: string;
|
|
28
|
+
columnReplacementSheetName?: string;
|
|
29
|
+
columnReplacementAddress?: string;
|
|
30
|
+
}) => CellValue | undefined;
|
|
31
|
+
listSheetNames?: () => string[];
|
|
32
|
+
resolveBuiltin?: (name: string) => ((...args: CellValue[]) => EvaluationResult) | undefined;
|
|
33
|
+
}
|
|
34
|
+
export interface ReferenceOperand {
|
|
35
|
+
kind: "cell" | "range" | "row" | "col";
|
|
36
|
+
sheetName?: string;
|
|
37
|
+
address?: string;
|
|
38
|
+
start?: string;
|
|
39
|
+
end?: string;
|
|
40
|
+
refKind?: "cells" | "rows" | "cols";
|
|
41
|
+
}
|
|
42
|
+
export type JsPlanInstruction = {
|
|
43
|
+
opcode: "push-number";
|
|
44
|
+
value: number;
|
|
45
|
+
} | {
|
|
46
|
+
opcode: "push-boolean";
|
|
47
|
+
value: boolean;
|
|
48
|
+
} | {
|
|
49
|
+
opcode: "push-string";
|
|
50
|
+
value: string;
|
|
51
|
+
} | {
|
|
52
|
+
opcode: "push-error";
|
|
53
|
+
code: ErrorCode;
|
|
54
|
+
} | {
|
|
55
|
+
opcode: "push-name";
|
|
56
|
+
name: string;
|
|
57
|
+
} | {
|
|
58
|
+
opcode: "push-cell";
|
|
59
|
+
sheetName?: string;
|
|
60
|
+
address: string;
|
|
61
|
+
} | {
|
|
62
|
+
opcode: "push-range";
|
|
63
|
+
sheetName?: string;
|
|
64
|
+
start: string;
|
|
65
|
+
end: string;
|
|
66
|
+
refKind: "cells" | "rows" | "cols";
|
|
67
|
+
} | {
|
|
68
|
+
opcode: "push-lambda";
|
|
69
|
+
params: string[];
|
|
70
|
+
body: JsPlanInstruction[];
|
|
71
|
+
} | {
|
|
72
|
+
opcode: "unary";
|
|
73
|
+
operator: "+" | "-";
|
|
74
|
+
} | {
|
|
75
|
+
opcode: "binary";
|
|
76
|
+
operator: "+" | "-" | "*" | "/" | "^" | "&" | "=" | "<>" | ">" | ">=" | "<" | "<=";
|
|
77
|
+
} | {
|
|
78
|
+
opcode: "call";
|
|
79
|
+
callee: string;
|
|
80
|
+
argc: number;
|
|
81
|
+
argRefs?: Array<ReferenceOperand | undefined>;
|
|
82
|
+
} | {
|
|
83
|
+
opcode: "invoke";
|
|
84
|
+
argc: number;
|
|
85
|
+
} | {
|
|
86
|
+
opcode: "begin-scope";
|
|
87
|
+
} | {
|
|
88
|
+
opcode: "bind-name";
|
|
89
|
+
name: string;
|
|
90
|
+
} | {
|
|
91
|
+
opcode: "end-scope";
|
|
92
|
+
} | {
|
|
93
|
+
opcode: "jump-if-false";
|
|
94
|
+
target: number;
|
|
95
|
+
} | {
|
|
96
|
+
opcode: "jump";
|
|
97
|
+
target: number;
|
|
98
|
+
} | {
|
|
99
|
+
opcode: "return";
|
|
100
|
+
};
|
|
101
|
+
export type StackValue = {
|
|
102
|
+
kind: "scalar";
|
|
103
|
+
value: CellValue;
|
|
104
|
+
} | {
|
|
105
|
+
kind: "omitted";
|
|
106
|
+
} | {
|
|
107
|
+
kind: "range";
|
|
108
|
+
values: CellValue[];
|
|
109
|
+
refKind: "cells" | "rows" | "cols";
|
|
110
|
+
rows: number;
|
|
111
|
+
cols: number;
|
|
112
|
+
} | {
|
|
113
|
+
kind: "lambda";
|
|
114
|
+
params: string[];
|
|
115
|
+
body: JsPlanInstruction[];
|
|
116
|
+
scopes: Array<Map<string, StackValue>>;
|
|
117
|
+
} | ArrayValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-evaluator-types.js","sourceRoot":"","sources":["../src/js-evaluator-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ErrorCode, type CellValue } from "@bilig/protocol";
|
|
2
|
+
import type { EvaluationContext, ReferenceOperand, StackValue } from "./js-evaluator-types.js";
|
|
3
|
+
interface MatrixLikeValue {
|
|
4
|
+
rows: number;
|
|
5
|
+
cols: number;
|
|
6
|
+
values: readonly CellValue[];
|
|
7
|
+
}
|
|
8
|
+
interface WorkbookSpecialCallDeps {
|
|
9
|
+
error: (code: ErrorCode) => CellValue;
|
|
10
|
+
stackScalar: (value: CellValue) => StackValue;
|
|
11
|
+
toStringValue: (value: CellValue) => string;
|
|
12
|
+
isSingleCellValue: (value: StackValue) => CellValue | undefined;
|
|
13
|
+
matrixFromStackValue: (value: StackValue) => MatrixLikeValue | undefined;
|
|
14
|
+
scalarIntegerArgument: (value: StackValue | undefined) => number | undefined;
|
|
15
|
+
vectorIntegerArgument: (value: StackValue | undefined) => number[] | undefined;
|
|
16
|
+
aggregateRangeSubset: (functionArg: StackValue, subset: readonly CellValue[], context: EvaluationContext, totalSet?: readonly CellValue[]) => CellValue;
|
|
17
|
+
referenceTopLeftAddress: (ref: ReferenceOperand | undefined) => string | undefined;
|
|
18
|
+
referenceSheetName: (ref: ReferenceOperand | undefined, context: EvaluationContext) => string | undefined;
|
|
19
|
+
coerceScalarTextArgument: (value: StackValue | undefined) => string | CellValue;
|
|
20
|
+
coerceOptionalBooleanArgument: (value: StackValue | undefined, fallback: boolean) => boolean | CellValue;
|
|
21
|
+
isCellValueError: (value: number | boolean | string | CellValue) => value is CellValue;
|
|
22
|
+
}
|
|
23
|
+
export declare function evaluateWorkbookSpecialCall(callee: string, rawArgs: StackValue[], context: EvaluationContext, argRefs: readonly (ReferenceOperand | undefined)[], deps: WorkbookSpecialCallDeps): StackValue | undefined;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { ErrorCode } from "@bilig/protocol";
|
|
2
|
+
import { parseCellAddress, parseRangeAddress } from "./addressing.js";
|
|
3
|
+
import { evaluateGroupBy, evaluatePivotBy } from "./group-pivot-evaluator.js";
|
|
4
|
+
import { isArrayValue } from "./runtime-values.js";
|
|
5
|
+
export function evaluateWorkbookSpecialCall(callee, rawArgs, context, argRefs, deps) {
|
|
6
|
+
switch (callee) {
|
|
7
|
+
case "GETPIVOTDATA": {
|
|
8
|
+
if (rawArgs.length < 2 || (rawArgs.length - 2) % 2 !== 0) {
|
|
9
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
10
|
+
}
|
|
11
|
+
const dataFieldValue = deps.isSingleCellValue(rawArgs[0]);
|
|
12
|
+
const address = deps.referenceTopLeftAddress(argRefs[1]);
|
|
13
|
+
const sheetName = deps.referenceSheetName(argRefs[1], context);
|
|
14
|
+
if (!dataFieldValue) {
|
|
15
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
16
|
+
}
|
|
17
|
+
if (!address || !sheetName) {
|
|
18
|
+
return deps.stackScalar(deps.error(ErrorCode.Ref));
|
|
19
|
+
}
|
|
20
|
+
const filters = [];
|
|
21
|
+
for (let index = 2; index < rawArgs.length; index += 2) {
|
|
22
|
+
const fieldValue = deps.isSingleCellValue(rawArgs[index]);
|
|
23
|
+
const itemValue = deps.isSingleCellValue(rawArgs[index + 1]);
|
|
24
|
+
if (!fieldValue || !itemValue) {
|
|
25
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
26
|
+
}
|
|
27
|
+
filters.push({ field: deps.toStringValue(fieldValue), item: itemValue });
|
|
28
|
+
}
|
|
29
|
+
return deps.stackScalar(context.resolvePivotData?.({
|
|
30
|
+
dataField: deps.toStringValue(dataFieldValue),
|
|
31
|
+
sheetName,
|
|
32
|
+
address,
|
|
33
|
+
filters,
|
|
34
|
+
}) ?? deps.error(ErrorCode.Ref));
|
|
35
|
+
}
|
|
36
|
+
case "GROUPBY": {
|
|
37
|
+
if (rawArgs.length < 3 || rawArgs.length > 8) {
|
|
38
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
39
|
+
}
|
|
40
|
+
const rowFields = deps.matrixFromStackValue(rawArgs[0]);
|
|
41
|
+
const values = deps.matrixFromStackValue(rawArgs[1]);
|
|
42
|
+
if (!rowFields || !values) {
|
|
43
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
44
|
+
}
|
|
45
|
+
const sortOrder = deps.vectorIntegerArgument(rawArgs[5]) ??
|
|
46
|
+
(rawArgs[5] ? [deps.scalarIntegerArgument(rawArgs[5]) ?? Number.NaN] : undefined);
|
|
47
|
+
const fieldHeadersMode = deps.scalarIntegerArgument(rawArgs[3]);
|
|
48
|
+
const totalDepth = deps.scalarIntegerArgument(rawArgs[4]);
|
|
49
|
+
const filterArray = rawArgs[6] ? deps.matrixFromStackValue(rawArgs[6]) : undefined;
|
|
50
|
+
const fieldRelationship = deps.scalarIntegerArgument(rawArgs[7]);
|
|
51
|
+
const result = evaluateGroupBy(rowFields, values, {
|
|
52
|
+
aggregate: (subset, totalSet) => deps.aggregateRangeSubset(rawArgs[2], subset, context, totalSet),
|
|
53
|
+
...(fieldHeadersMode !== undefined ? { fieldHeadersMode } : {}),
|
|
54
|
+
...(totalDepth !== undefined ? { totalDepth } : {}),
|
|
55
|
+
...(sortOrder?.every(Number.isFinite) ? { sortOrder } : {}),
|
|
56
|
+
...(filterArray !== undefined ? { filterArray } : {}),
|
|
57
|
+
...(fieldRelationship !== undefined ? { fieldRelationship } : {}),
|
|
58
|
+
});
|
|
59
|
+
return isArrayValue(result) ? result : deps.stackScalar(result);
|
|
60
|
+
}
|
|
61
|
+
case "PIVOTBY": {
|
|
62
|
+
if (rawArgs.length < 4 || rawArgs.length > 11) {
|
|
63
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
64
|
+
}
|
|
65
|
+
const rowFields = deps.matrixFromStackValue(rawArgs[0]);
|
|
66
|
+
const colFields = deps.matrixFromStackValue(rawArgs[1]);
|
|
67
|
+
const values = deps.matrixFromStackValue(rawArgs[2]);
|
|
68
|
+
if (!rowFields || !colFields || !values) {
|
|
69
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
70
|
+
}
|
|
71
|
+
const rowSortOrder = deps.vectorIntegerArgument(rawArgs[6]) ??
|
|
72
|
+
(rawArgs[6] ? [deps.scalarIntegerArgument(rawArgs[6]) ?? Number.NaN] : undefined);
|
|
73
|
+
const colSortOrder = deps.vectorIntegerArgument(rawArgs[8]) ??
|
|
74
|
+
(rawArgs[8] ? [deps.scalarIntegerArgument(rawArgs[8]) ?? Number.NaN] : undefined);
|
|
75
|
+
const fieldHeadersMode = deps.scalarIntegerArgument(rawArgs[4]);
|
|
76
|
+
const rowTotalDepth = deps.scalarIntegerArgument(rawArgs[5]);
|
|
77
|
+
const colTotalDepth = deps.scalarIntegerArgument(rawArgs[7]);
|
|
78
|
+
const filterArray = rawArgs[9] ? deps.matrixFromStackValue(rawArgs[9]) : undefined;
|
|
79
|
+
const relativeTo = deps.scalarIntegerArgument(rawArgs[10]);
|
|
80
|
+
const result = evaluatePivotBy(rowFields, colFields, values, {
|
|
81
|
+
aggregate: (subset, totalSet) => deps.aggregateRangeSubset(rawArgs[3], subset, context, totalSet),
|
|
82
|
+
...(fieldHeadersMode !== undefined ? { fieldHeadersMode } : {}),
|
|
83
|
+
...(rowTotalDepth !== undefined ? { rowTotalDepth } : {}),
|
|
84
|
+
...(rowSortOrder?.every(Number.isFinite) ? { rowSortOrder } : {}),
|
|
85
|
+
...(colTotalDepth !== undefined ? { colTotalDepth } : {}),
|
|
86
|
+
...(colSortOrder?.every(Number.isFinite) ? { colSortOrder } : {}),
|
|
87
|
+
...(filterArray !== undefined ? { filterArray } : {}),
|
|
88
|
+
...(relativeTo !== undefined ? { relativeTo } : {}),
|
|
89
|
+
});
|
|
90
|
+
return isArrayValue(result) ? result : deps.stackScalar(result);
|
|
91
|
+
}
|
|
92
|
+
case "MULTIPLE.OPERATIONS": {
|
|
93
|
+
if (rawArgs.length !== 3 && rawArgs.length !== 5) {
|
|
94
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
95
|
+
}
|
|
96
|
+
const formulaAddress = deps.referenceTopLeftAddress(argRefs[0]);
|
|
97
|
+
const formulaSheetName = deps.referenceSheetName(argRefs[0], context);
|
|
98
|
+
const rowCellAddress = deps.referenceTopLeftAddress(argRefs[1]);
|
|
99
|
+
const rowCellSheetName = deps.referenceSheetName(argRefs[1], context);
|
|
100
|
+
const rowReplacementAddress = deps.referenceTopLeftAddress(argRefs[2]);
|
|
101
|
+
const rowReplacementSheetName = deps.referenceSheetName(argRefs[2], context);
|
|
102
|
+
if (!formulaAddress ||
|
|
103
|
+
!formulaSheetName ||
|
|
104
|
+
!rowCellAddress ||
|
|
105
|
+
!rowCellSheetName ||
|
|
106
|
+
!rowReplacementAddress ||
|
|
107
|
+
!rowReplacementSheetName) {
|
|
108
|
+
return deps.stackScalar(deps.error(ErrorCode.Ref));
|
|
109
|
+
}
|
|
110
|
+
const columnCellAddress = rawArgs.length === 5 ? deps.referenceTopLeftAddress(argRefs[3]) : undefined;
|
|
111
|
+
const columnCellSheetName = rawArgs.length === 5 ? deps.referenceSheetName(argRefs[3], context) : undefined;
|
|
112
|
+
const columnReplacementAddress = rawArgs.length === 5 ? deps.referenceTopLeftAddress(argRefs[4]) : undefined;
|
|
113
|
+
const columnReplacementSheetName = rawArgs.length === 5 ? deps.referenceSheetName(argRefs[4], context) : undefined;
|
|
114
|
+
if (rawArgs.length === 5 &&
|
|
115
|
+
(!columnCellAddress ||
|
|
116
|
+
!columnCellSheetName ||
|
|
117
|
+
!columnReplacementAddress ||
|
|
118
|
+
!columnReplacementSheetName)) {
|
|
119
|
+
return deps.stackScalar(deps.error(ErrorCode.Ref));
|
|
120
|
+
}
|
|
121
|
+
return deps.stackScalar(context.resolveMultipleOperations?.({
|
|
122
|
+
formulaSheetName,
|
|
123
|
+
formulaAddress,
|
|
124
|
+
rowCellSheetName,
|
|
125
|
+
rowCellAddress,
|
|
126
|
+
rowReplacementSheetName,
|
|
127
|
+
rowReplacementAddress,
|
|
128
|
+
...(columnCellSheetName ? { columnCellSheetName } : {}),
|
|
129
|
+
...(columnCellAddress ? { columnCellAddress } : {}),
|
|
130
|
+
...(columnReplacementSheetName ? { columnReplacementSheetName } : {}),
|
|
131
|
+
...(columnReplacementAddress ? { columnReplacementAddress } : {}),
|
|
132
|
+
}) ?? deps.error(ErrorCode.Ref));
|
|
133
|
+
}
|
|
134
|
+
case "INDIRECT": {
|
|
135
|
+
if (rawArgs.length < 1 || rawArgs.length > 2) {
|
|
136
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
137
|
+
}
|
|
138
|
+
const refText = deps.coerceScalarTextArgument(rawArgs[0]);
|
|
139
|
+
if (deps.isCellValueError(refText)) {
|
|
140
|
+
return deps.stackScalar(refText);
|
|
141
|
+
}
|
|
142
|
+
const a1Mode = deps.coerceOptionalBooleanArgument(rawArgs[1], true);
|
|
143
|
+
if (deps.isCellValueError(a1Mode)) {
|
|
144
|
+
return deps.stackScalar(a1Mode);
|
|
145
|
+
}
|
|
146
|
+
if (!a1Mode) {
|
|
147
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
148
|
+
}
|
|
149
|
+
const normalizedRefText = refText.trim();
|
|
150
|
+
if (normalizedRefText === "") {
|
|
151
|
+
return deps.stackScalar(deps.error(ErrorCode.Ref));
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
const cell = parseCellAddress(normalizedRefText, context.sheetName);
|
|
155
|
+
return deps.stackScalar(context.resolveCell(cell.sheetName ?? context.sheetName, cell.text));
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
// fall through
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
const range = parseRangeAddress(normalizedRefText, context.sheetName);
|
|
162
|
+
if (range.kind !== "cells") {
|
|
163
|
+
return deps.stackScalar(deps.error(ErrorCode.Ref));
|
|
164
|
+
}
|
|
165
|
+
const targetSheetName = range.sheetName ?? context.sheetName;
|
|
166
|
+
const values = context.resolveRange(targetSheetName, range.start.text, range.end.text, "cells");
|
|
167
|
+
return {
|
|
168
|
+
kind: "range",
|
|
169
|
+
values,
|
|
170
|
+
refKind: "cells",
|
|
171
|
+
rows: range.end.row - range.start.row + 1,
|
|
172
|
+
cols: range.end.col - range.start.col + 1,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
// fall through
|
|
177
|
+
}
|
|
178
|
+
const resolvedName = context.resolveName?.(normalizedRefText);
|
|
179
|
+
return deps.stackScalar(resolvedName ?? deps.error(ErrorCode.Ref));
|
|
180
|
+
}
|
|
181
|
+
default:
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=js-evaluator-workbook-special-calls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-evaluator-workbook-special-calls.js","sourceRoot":"","sources":["../src/js-evaluator-workbook-special-calls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAkB,MAAM,iBAAiB,CAAC;AAC5D,OAAO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,GAAG,iBAAiB,CAAC,iBAAiB,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;gBACtE,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;oBAC3B,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;gBACrD,CAAC;gBACD,MAAM,eAAe,GAAG,KAAK,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC;gBAC7D,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CACjC,eAAe,EACf,KAAK,CAAC,KAAK,CAAC,IAAI,EAChB,KAAK,CAAC,GAAG,CAAC,IAAI,EACd,OAAO,CACR,CAAC;gBACF,OAAO;oBACL,IAAI,EAAE,OAAO;oBACb,MAAM;oBACN,OAAO,EAAE,OAAO;oBAChB,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;oBACzC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;iBAC1C,CAAC;YACJ,CAAC;YAAC,MAAM,CAAC;gBACP,eAAe;YACjB,CAAC;YAED,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,iBAAiB,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QACrE,CAAC;QACD;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
|
package/dist/js-evaluator.d.ts
CHANGED
|
@@ -1,107 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type CellValue } from "@bilig/protocol";
|
|
2
2
|
import type { FormulaNode } from "./ast.js";
|
|
3
|
+
import type { EvaluationContext, JsPlanInstruction } from "./js-evaluator-types.js";
|
|
3
4
|
import { type EvaluationResult } from "./runtime-values.js";
|
|
4
|
-
export
|
|
5
|
-
sheetName: string;
|
|
6
|
-
currentAddress?: string;
|
|
7
|
-
resolveCell: (sheetName: string, address: string) => CellValue;
|
|
8
|
-
resolveRange: (sheetName: string, start: string, end: string, refKind: "cells" | "rows" | "cols") => CellValue[];
|
|
9
|
-
resolveName?: (name: string) => CellValue;
|
|
10
|
-
resolveFormula?: (sheetName: string, address: string) => string | undefined;
|
|
11
|
-
resolvePivotData?: (request: {
|
|
12
|
-
dataField: string;
|
|
13
|
-
sheetName: string;
|
|
14
|
-
address: string;
|
|
15
|
-
filters: ReadonlyArray<{
|
|
16
|
-
field: string;
|
|
17
|
-
item: CellValue;
|
|
18
|
-
}>;
|
|
19
|
-
}) => CellValue | undefined;
|
|
20
|
-
resolveMultipleOperations?: (request: {
|
|
21
|
-
formulaSheetName: string;
|
|
22
|
-
formulaAddress: string;
|
|
23
|
-
rowCellSheetName: string;
|
|
24
|
-
rowCellAddress: string;
|
|
25
|
-
rowReplacementSheetName: string;
|
|
26
|
-
rowReplacementAddress: string;
|
|
27
|
-
columnCellSheetName?: string;
|
|
28
|
-
columnCellAddress?: string;
|
|
29
|
-
columnReplacementSheetName?: string;
|
|
30
|
-
columnReplacementAddress?: string;
|
|
31
|
-
}) => CellValue | undefined;
|
|
32
|
-
listSheetNames?: () => string[];
|
|
33
|
-
resolveBuiltin?: (name: string) => ((...args: CellValue[]) => EvaluationResult) | undefined;
|
|
34
|
-
}
|
|
35
|
-
interface ReferenceOperand {
|
|
36
|
-
kind: "cell" | "range" | "row" | "col";
|
|
37
|
-
sheetName?: string;
|
|
38
|
-
address?: string;
|
|
39
|
-
start?: string;
|
|
40
|
-
end?: string;
|
|
41
|
-
refKind?: "cells" | "rows" | "cols";
|
|
42
|
-
}
|
|
43
|
-
export type JsPlanInstruction = {
|
|
44
|
-
opcode: "push-number";
|
|
45
|
-
value: number;
|
|
46
|
-
} | {
|
|
47
|
-
opcode: "push-boolean";
|
|
48
|
-
value: boolean;
|
|
49
|
-
} | {
|
|
50
|
-
opcode: "push-string";
|
|
51
|
-
value: string;
|
|
52
|
-
} | {
|
|
53
|
-
opcode: "push-error";
|
|
54
|
-
code: ErrorCode;
|
|
55
|
-
} | {
|
|
56
|
-
opcode: "push-name";
|
|
57
|
-
name: string;
|
|
58
|
-
} | {
|
|
59
|
-
opcode: "push-cell";
|
|
60
|
-
sheetName?: string;
|
|
61
|
-
address: string;
|
|
62
|
-
} | {
|
|
63
|
-
opcode: "push-range";
|
|
64
|
-
sheetName?: string;
|
|
65
|
-
start: string;
|
|
66
|
-
end: string;
|
|
67
|
-
refKind: "cells" | "rows" | "cols";
|
|
68
|
-
} | {
|
|
69
|
-
opcode: "push-lambda";
|
|
70
|
-
params: string[];
|
|
71
|
-
body: JsPlanInstruction[];
|
|
72
|
-
} | {
|
|
73
|
-
opcode: "unary";
|
|
74
|
-
operator: "+" | "-";
|
|
75
|
-
} | {
|
|
76
|
-
opcode: "binary";
|
|
77
|
-
operator: "+" | "-" | "*" | "/" | "^" | "&" | "=" | "<>" | ">" | ">=" | "<" | "<=";
|
|
78
|
-
} | {
|
|
79
|
-
opcode: "call";
|
|
80
|
-
callee: string;
|
|
81
|
-
argc: number;
|
|
82
|
-
argRefs?: Array<ReferenceOperand | undefined>;
|
|
83
|
-
} | {
|
|
84
|
-
opcode: "invoke";
|
|
85
|
-
argc: number;
|
|
86
|
-
} | {
|
|
87
|
-
opcode: "begin-scope";
|
|
88
|
-
} | {
|
|
89
|
-
opcode: "bind-name";
|
|
90
|
-
name: string;
|
|
91
|
-
} | {
|
|
92
|
-
opcode: "end-scope";
|
|
93
|
-
} | {
|
|
94
|
-
opcode: "jump-if-false";
|
|
95
|
-
target: number;
|
|
96
|
-
} | {
|
|
97
|
-
opcode: "jump";
|
|
98
|
-
target: number;
|
|
99
|
-
} | {
|
|
100
|
-
opcode: "return";
|
|
101
|
-
};
|
|
5
|
+
export type { EvaluationContext, JsPlanInstruction } from "./js-evaluator-types.js";
|
|
102
6
|
export declare function lowerToPlan(node: FormulaNode): JsPlanInstruction[];
|
|
103
7
|
export declare function evaluatePlanResult(plan: readonly JsPlanInstruction[], context: EvaluationContext): EvaluationResult;
|
|
104
8
|
export declare function evaluatePlan(plan: readonly JsPlanInstruction[], context: EvaluationContext): CellValue;
|
|
105
9
|
export declare function evaluateAst(node: FormulaNode, context: EvaluationContext): CellValue;
|
|
106
10
|
export declare function evaluateAstResult(node: FormulaNode, context: EvaluationContext): EvaluationResult;
|
|
107
|
-
export {};
|