@cloudpss/expression 0.6.0-alpha.1 → 0.6.0-alpha.11
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/analyze.d.ts +6 -3
- package/dist/analyze.d.ts.map +1 -1
- package/dist/analyze.js +67 -33
- package/dist/analyze.js.map +1 -1
- package/dist/definitions/argument.d.ts +2 -10
- package/dist/definitions/argument.d.ts.map +1 -1
- package/dist/definitions/constraint.d.ts +2 -2
- package/dist/definitions/constraint.d.ts.map +1 -1
- package/dist/definitions/constraint.js +1 -1
- package/dist/definitions/constraint.js.map +1 -1
- package/dist/definitions/parameter-decoration.d.ts +3 -3
- package/dist/definitions/parameter-decoration.d.ts.map +1 -1
- package/dist/definitions/parameter-decoration.js +0 -7
- package/dist/definitions/parameter-decoration.js.map +1 -1
- package/dist/definitions/parameter-group.d.ts +0 -4
- package/dist/definitions/parameter-group.d.ts.map +1 -1
- package/dist/definitions/parameter-group.js +5 -17
- package/dist/definitions/parameter-group.js.map +1 -1
- package/dist/definitions/parameter.d.ts +47 -40
- package/dist/definitions/parameter.d.ts.map +1 -1
- package/dist/definitions/parameter.js +9 -21
- package/dist/definitions/parameter.js.map +1 -1
- package/dist/definitions/utils.d.ts +19 -0
- package/dist/definitions/utils.d.ts.map +1 -0
- package/dist/definitions/utils.js +177 -0
- package/dist/definitions/utils.js.map +1 -0
- package/dist/definitions/variable.d.ts +0 -2
- package/dist/definitions/variable.d.ts.map +1 -1
- package/dist/definitions/variable.js +1 -5
- package/dist/definitions/variable.js.map +1 -1
- package/dist/definitions.d.ts +1 -0
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js +1 -0
- package/dist/definitions.js.map +1 -1
- package/dist/eval.d.ts +3 -5
- package/dist/eval.d.ts.map +1 -1
- package/dist/eval.js +12 -20
- package/dist/eval.js.map +1 -1
- package/dist/expression.d.ts +10 -4
- package/dist/expression.d.ts.map +1 -1
- package/dist/expression.js +4 -4
- package/dist/expression.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interface.d.ts +30 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/interface.js +6 -0
- package/dist/interface.js.map +1 -0
- package/dist/main.d.ts +41 -28
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +145 -141
- package/dist/main.js.map +1 -1
- package/dist/migrate.d.ts +3 -2
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +25 -3
- package/dist/migrate.js.map +1 -1
- package/dist/migrator/access.d.ts.map +1 -1
- package/dist/migrator/access.js +44 -24
- package/dist/migrator/access.js.map +1 -1
- package/dist/migrator/call.d.ts.map +1 -1
- package/dist/migrator/call.js +254 -217
- package/dist/migrator/call.js.map +1 -1
- package/dist/migrator/concat.d.ts.map +1 -1
- package/dist/migrator/concat.js +15 -2
- package/dist/migrator/concat.js.map +1 -1
- package/dist/migrator/interface.d.ts +3 -1
- package/dist/migrator/interface.d.ts.map +1 -1
- package/dist/migrator/interface.js.map +1 -1
- package/dist/migrator/node.js +1 -1
- package/dist/migrator/node.js.map +1 -1
- package/dist/migrator/operator.d.ts.map +1 -1
- package/dist/migrator/operator.js +43 -29
- package/dist/migrator/operator.js.map +1 -1
- package/dist/migrator/state.d.ts +2 -2
- package/dist/migrator/state.d.ts.map +1 -1
- package/dist/migrator/state.js +1 -2
- package/dist/migrator/state.js.map +1 -1
- package/dist/migrator/symbol.d.ts.map +1 -1
- package/dist/migrator/symbol.js +13 -0
- package/dist/migrator/symbol.js.map +1 -1
- package/dist/migrator/to-type.d.ts.map +1 -1
- package/dist/migrator/to-type.js +20 -3
- package/dist/migrator/to-type.js.map +1 -1
- package/dist/migrator/utils.d.ts +4 -0
- package/dist/migrator/utils.d.ts.map +1 -1
- package/dist/migrator/utils.js +25 -0
- package/dist/migrator/utils.js.map +1 -1
- package/dist/parser.d.ts +2 -2
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +25 -8
- package/dist/parser.js.map +1 -1
- package/dist/re-exports.d.ts +4 -0
- package/dist/re-exports.d.ts.map +1 -0
- package/dist/re-exports.js +3 -0
- package/dist/re-exports.js.map +1 -0
- package/dist/scope.d.ts +13 -16
- package/dist/scope.d.ts.map +1 -1
- package/dist/scope.js +56 -49
- package/dist/scope.js.map +1 -1
- package/dist/type.d.ts +14 -5
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js +35 -11
- package/dist/type.js.map +1 -1
- package/package.json +7 -4
- package/src/analyze.ts +77 -37
- package/src/definitions/argument.ts +2 -12
- package/src/definitions/constraint.ts +3 -3
- package/src/definitions/parameter-decoration.ts +3 -9
- package/src/definitions/parameter-group.ts +4 -19
- package/src/definitions/parameter.ts +62 -61
- package/src/definitions/utils.ts +175 -0
- package/src/definitions/variable.ts +1 -6
- package/src/definitions.ts +1 -0
- package/src/eval.ts +13 -26
- package/src/expression.ts +14 -6
- package/src/index.ts +3 -1
- package/src/interface.ts +35 -0
- package/src/main.ts +213 -194
- package/src/migrate.ts +30 -6
- package/src/migrator/access.ts +49 -32
- package/src/migrator/call.ts +246 -203
- package/src/migrator/concat.ts +15 -2
- package/src/migrator/interface.ts +3 -1
- package/src/migrator/node.ts +1 -1
- package/src/migrator/operator.ts +47 -33
- package/src/migrator/state.ts +2 -2
- package/src/migrator/symbol.ts +13 -0
- package/src/migrator/to-type.ts +22 -3
- package/src/migrator/utils.ts +29 -0
- package/src/parser.ts +27 -8
- package/src/re-exports.ts +28 -0
- package/src/scope.ts +75 -61
- package/src/type.ts +32 -11
- package/tests/analyze.ts +40 -6
- package/tests/compile.ts +65 -0
- package/tests/condition.ts +13 -5
- package/tests/definition.ts +205 -18
- package/tests/eval-complex.ts +7 -10
- package/tests/eval.ts +59 -12
- package/tests/import.ts +18 -4
- package/tests/main.ts +9 -0
- package/tests/migrate.ts +202 -0
- package/tests/scope.ts +3 -3
- package/tests/template.ts +36 -0
- package/dist/context.d.ts +0 -41
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -18
- package/dist/context.js.map +0 -1
- package/jest.config.js +0 -3
- package/src/context.ts +0 -54
- package/tests/tsconfig.json +0 -3
- package/tsconfig.json +0 -3
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { klona } from 'klona';
|
|
2
|
+
import { isVmArray, type VmPrimitive, type VmValue } from '@mirascript/mirascript';
|
|
3
|
+
import { Expression, isExpression } from '../expression.js';
|
|
4
|
+
import type { ChoiceParameterType, Parameter, ParameterMap } from './parameter.js';
|
|
5
|
+
import { TypeInfo } from '../type.js';
|
|
6
|
+
import type { ArgumentMap, ArgumentValue } from './argument.js';
|
|
7
|
+
import type { ParameterGroup } from './parameter-group.js';
|
|
8
|
+
const { isArray } = Array;
|
|
9
|
+
|
|
10
|
+
/** 推测枚举类型 */
|
|
11
|
+
export function enumType(definition: Pick<ParameterMap[ChoiceParameterType], 'type' | 'choices'>): TypeInfo | null {
|
|
12
|
+
const { choices } = definition;
|
|
13
|
+
if (typeof choices == 'function' || isExpression(choices)) return null;
|
|
14
|
+
let defaultType: TypeInfo = definition.type === 'logical' ? 'boolean' : 'number';
|
|
15
|
+
if ('value' in definition) {
|
|
16
|
+
const { value } = definition;
|
|
17
|
+
if (typeof value == 'boolean') defaultType = 'boolean';
|
|
18
|
+
else if (typeof value == 'number') defaultType = 'number';
|
|
19
|
+
else if (typeof value == 'string') defaultType = 'string';
|
|
20
|
+
}
|
|
21
|
+
if (choices == null || choices.length === 0) return defaultType;
|
|
22
|
+
|
|
23
|
+
let type: TypeInfo | null = null;
|
|
24
|
+
for (const choice of choices) {
|
|
25
|
+
const v = choice?.key;
|
|
26
|
+
const t = v == null ? defaultType : typeof v;
|
|
27
|
+
if (t === 'string') {
|
|
28
|
+
if (type == null) type = 'string';
|
|
29
|
+
else if (type !== 'string') return null;
|
|
30
|
+
} else if (t === 'number') {
|
|
31
|
+
if (type == null) type = 'number';
|
|
32
|
+
else if (type !== 'number') return null;
|
|
33
|
+
} else if (t === 'boolean') {
|
|
34
|
+
if (type == null) type = 'boolean';
|
|
35
|
+
else if (type !== 'boolean') return null;
|
|
36
|
+
} else {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return type;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 转换参数值的类型,不回退到 {@link Parameter.value} 提供的默认值
|
|
45
|
+
*/
|
|
46
|
+
export function toArgumentValue<V extends ArgumentValue>(value: VmValue, definition: Parameter): V {
|
|
47
|
+
// 避免无效的 VmValue 导致错误
|
|
48
|
+
value ??= null;
|
|
49
|
+
|
|
50
|
+
switch (definition.type) {
|
|
51
|
+
case 'real':
|
|
52
|
+
case 'integer':
|
|
53
|
+
return TypeInfo.toNumber(value) as V;
|
|
54
|
+
case 'text':
|
|
55
|
+
case 'file':
|
|
56
|
+
case 'code':
|
|
57
|
+
case 'pinLike' as never:
|
|
58
|
+
case 'cssColor' as never:
|
|
59
|
+
case 'cssBackground' as never:
|
|
60
|
+
case 'resourceId' as never:
|
|
61
|
+
return TypeInfo.toString(value) as V;
|
|
62
|
+
|
|
63
|
+
case 'choice':
|
|
64
|
+
case 'logical': {
|
|
65
|
+
if (value == null && Array.isArray(definition.choices) && definition.choices.length > 0) {
|
|
66
|
+
value = definition.choices[0]?.key;
|
|
67
|
+
}
|
|
68
|
+
const type = enumType(definition);
|
|
69
|
+
if (!type) return value as V;
|
|
70
|
+
return TypeInfo.to(value, type) as V;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
case 'multiSelect': {
|
|
74
|
+
const v = isVmArray(value) ? value : value != null ? ([value] as const) : [];
|
|
75
|
+
if (v.length === 0) return v as V;
|
|
76
|
+
const type = enumType(definition);
|
|
77
|
+
if (!type) return v as V;
|
|
78
|
+
return v.map((x) => TypeInfo.to(x, type)) as readonly VmPrimitive[] as V;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
case 'table': {
|
|
82
|
+
const v = isVmArray(value) ? value : value != null ? ([value] as const) : [];
|
|
83
|
+
return v as V;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
case 'grouped':
|
|
87
|
+
case 'record':
|
|
88
|
+
default:
|
|
89
|
+
return value as V;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 参数定义数组 */
|
|
94
|
+
type ParameterDefinitions = ReadonlyArray<Pick<ParameterGroup, 'items'>>;
|
|
95
|
+
/** 是否为包含参数组的参数定义数组 */
|
|
96
|
+
function checkParameterDefinitions(value: ParameterDefinitions | undefined): value is ParameterDefinitions {
|
|
97
|
+
return value != null && isArray(value as unknown[]) && value.length > 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 查找指定参数 */
|
|
101
|
+
function findParameterImpl(items: readonly Parameter[], key: string): Parameter | undefined {
|
|
102
|
+
if (items.length === 0) return undefined;
|
|
103
|
+
for (const item of items) {
|
|
104
|
+
if (item == null) continue;
|
|
105
|
+
if (item.key === key) return item;
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** 查找指定参数 */
|
|
111
|
+
export function findParameter(definition: ParameterDefinitions | undefined, key: string): Parameter | undefined {
|
|
112
|
+
if (!checkParameterDefinitions(definition)) return undefined;
|
|
113
|
+
for (const group of definition) {
|
|
114
|
+
if (group == null || !isArray(group.items)) continue;
|
|
115
|
+
const found = findParameterImpl(group.items, key);
|
|
116
|
+
if (found) return found;
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** 获取参数默认值,修复现有的参数,填充缺失的参数,删除未定义的参数 */
|
|
122
|
+
export function fillArgumentMap<T extends Record<string, ArgumentValue>>(
|
|
123
|
+
definition: ParameterDefinitions | undefined,
|
|
124
|
+
args?: ArgumentMap<T> | null,
|
|
125
|
+
): ArgumentMap<T> {
|
|
126
|
+
args ??= {} as ArgumentMap<T>;
|
|
127
|
+
if (!checkParameterDefinitions(definition)) return args;
|
|
128
|
+
|
|
129
|
+
/** 参数键的类型 */
|
|
130
|
+
type K = keyof T & string;
|
|
131
|
+
/** 参数值的类型 */
|
|
132
|
+
type V = NonNullable<T[K]>;
|
|
133
|
+
const keys = new Set(Object.keys(args) as K[]);
|
|
134
|
+
|
|
135
|
+
// 根据定义填充或修复参数
|
|
136
|
+
for (const group of definition) {
|
|
137
|
+
for (const param of group.items) {
|
|
138
|
+
const key = param.key as K;
|
|
139
|
+
if (!key) continue;
|
|
140
|
+
const currentValue = keys.has(key) ? args[key] : undefined;
|
|
141
|
+
if (currentValue == null) {
|
|
142
|
+
// 使用默认值填充
|
|
143
|
+
const defaultValue = param.value;
|
|
144
|
+
if (isExpression(defaultValue)) {
|
|
145
|
+
args[key] = Expression<V>(defaultValue.source);
|
|
146
|
+
} else {
|
|
147
|
+
const value =
|
|
148
|
+
defaultValue != null && typeof defaultValue == 'object' ? klona(defaultValue) : defaultValue;
|
|
149
|
+
args[key] = toArgumentValue<V>(value, param);
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
// 已存在的参数值
|
|
153
|
+
if (isExpression(currentValue)) {
|
|
154
|
+
// 保留表达式
|
|
155
|
+
} else {
|
|
156
|
+
// 修复现有的参数值
|
|
157
|
+
const castedValue = toArgumentValue<V>(currentValue, param);
|
|
158
|
+
if (castedValue != null && castedValue !== currentValue) {
|
|
159
|
+
args[key] = castedValue;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
keys.delete(key);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// 删除多余的参数
|
|
168
|
+
for (const key of keys) {
|
|
169
|
+
// 保留特殊参数和私有字段
|
|
170
|
+
const k0 = key[0];
|
|
171
|
+
if (k0 === '_' || k0 === '$' || k0 === '@' || k0 === 'ɵ') continue;
|
|
172
|
+
delete args[key];
|
|
173
|
+
}
|
|
174
|
+
return args;
|
|
175
|
+
}
|
|
@@ -12,12 +12,7 @@ export type Variable<T extends ArgumentValue = ArgumentValue> = {
|
|
|
12
12
|
/** 检查是否为 `Variable` */
|
|
13
13
|
export function isVariable(obj: unknown): obj is Variable {
|
|
14
14
|
if (obj == null || typeof obj != 'object') return false;
|
|
15
|
-
if ('condition' in obj || 'description' in obj) return false;
|
|
15
|
+
if ('condition' in obj || 'description' in obj || 'type' in obj) return false;
|
|
16
16
|
const v = obj as Variable;
|
|
17
17
|
return typeof v.key == 'string' && 'value' in v;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
/** 创建空白 `Variable` */
|
|
21
|
-
export function Variable(): Variable {
|
|
22
|
-
return { key: '', value: '' };
|
|
23
|
-
}
|
package/src/definitions.ts
CHANGED
package/src/eval.ts
CHANGED
|
@@ -1,64 +1,51 @@
|
|
|
1
1
|
import type { VmValue } from '@mirascript/mirascript';
|
|
2
|
-
import type { Context } from './context.js';
|
|
3
2
|
import type { EvalExpressionCache, ExpressionCache } from './parser.js';
|
|
4
3
|
import { Scope, unwrap } from './scope.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export const DEFAULTS = Symbol('defaults');
|
|
4
|
+
import type { Evaluator } from './main.js';
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* 表达式求值
|
|
11
8
|
*/
|
|
12
9
|
export function evaluateEval<T extends VmValue>(
|
|
13
|
-
|
|
10
|
+
evaluator: Evaluator,
|
|
14
11
|
expression: EvalExpressionCache,
|
|
15
12
|
scope: Scope,
|
|
16
|
-
): T |
|
|
13
|
+
): T | null {
|
|
17
14
|
try {
|
|
18
15
|
const result = expression.func(scope.proxy);
|
|
19
|
-
if (result == null) return
|
|
16
|
+
if (result == null) return null;
|
|
20
17
|
return unwrap(result as T);
|
|
21
18
|
} catch (error: unknown) {
|
|
22
19
|
if (scope.throws) throw error;
|
|
23
|
-
|
|
20
|
+
evaluator.logger.warn(
|
|
24
21
|
`Failed to execute expression "${expression.source}": ${(error as Error).message || String(error)}.`,
|
|
25
22
|
{
|
|
26
23
|
error,
|
|
27
24
|
scope,
|
|
28
25
|
},
|
|
29
26
|
);
|
|
30
|
-
return
|
|
27
|
+
return null;
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
/**
|
|
35
32
|
* 表达式求值
|
|
36
33
|
*/
|
|
37
|
-
export function evaluate<T extends VmValue,
|
|
38
|
-
|
|
39
|
-
expression: ExpressionCache,
|
|
40
|
-
returnType: TypeInfo | null,
|
|
41
|
-
scope: Scope | undefined,
|
|
42
|
-
defaults: D,
|
|
43
|
-
): D | T {
|
|
44
|
-
let ret: T | typeof DEFAULTS;
|
|
34
|
+
export function evaluate<T extends VmValue>(evaluator: Evaluator, expression: ExpressionCache, scope: Scope): T | null {
|
|
35
|
+
let ret: T | null = null;
|
|
45
36
|
if (expression.func != null) {
|
|
46
37
|
scope ??= new Scope();
|
|
47
|
-
const reset = scope.reset(
|
|
38
|
+
const reset = scope.reset(evaluator);
|
|
48
39
|
try {
|
|
49
|
-
ret = evaluateEval<T>(
|
|
40
|
+
ret = evaluateEval<T>(evaluator, expression, scope);
|
|
50
41
|
} finally {
|
|
51
42
|
reset();
|
|
52
43
|
}
|
|
53
44
|
} else if (expression.error != null) {
|
|
54
|
-
if (scope
|
|
45
|
+
if (scope.throws) {
|
|
55
46
|
throw expression.error;
|
|
56
47
|
}
|
|
57
|
-
ret = DEFAULTS;
|
|
58
|
-
} else {
|
|
59
|
-
ret = DEFAULTS;
|
|
60
48
|
}
|
|
61
|
-
if (ret
|
|
62
|
-
|
|
63
|
-
return TypeInfo.to(ret, returnType) as T;
|
|
49
|
+
if (ret == null) return null;
|
|
50
|
+
return ret;
|
|
64
51
|
}
|
package/src/expression.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { VmValue } from '@mirascript/mirascript';
|
|
|
2
2
|
import type { Tagged } from 'type-fest';
|
|
3
3
|
import type { LegacyType, TsTypeOf, TypeInfo } from './type.js';
|
|
4
4
|
import type { Scope } from './scope.js';
|
|
5
|
+
import type { Evaluator } from './main.js';
|
|
5
6
|
|
|
6
7
|
/** 表达式的标记属性 */
|
|
7
8
|
export const ExpressionTag = 'ɵexp' as const;
|
|
@@ -18,10 +19,7 @@ export type Expression<T extends VmValue = VmValue> = {
|
|
|
18
19
|
/**
|
|
19
20
|
* 编译后的表达式
|
|
20
21
|
*/
|
|
21
|
-
export
|
|
22
|
-
(scope: Scope, defaults: T): T;
|
|
23
|
-
(scope?: Scope): T | undefined;
|
|
24
|
-
}
|
|
22
|
+
export type CompiledExpression<T extends VmValue = VmValue> = Expression<T> & ExpressionFunction<T>;
|
|
25
23
|
|
|
26
24
|
/** 表示一个表达式内容 */
|
|
27
25
|
export type ExpressionSource<T extends VmValue = VmValue> = Tagged<string, 'ExpressionResult', T>;
|
|
@@ -41,9 +39,9 @@ export function Expression<T extends VmValue = VmValue>(
|
|
|
41
39
|
source: string | Expression<T>,
|
|
42
40
|
returnType: TypeInfo | LegacyType | '' = '',
|
|
43
41
|
): Expression<T> {
|
|
44
|
-
if (
|
|
42
|
+
if (source == null) throw new TypeError(`Invalid expression ${String(source)}`);
|
|
45
43
|
const s = isExpression(source) ? source.source : source;
|
|
46
|
-
if (
|
|
44
|
+
if (typeof s != 'string') throw new TypeError(`Invalid expression ${String(s)}`);
|
|
47
45
|
return { [ExpressionTag]: returnType, source: s as ExpressionSource<T> };
|
|
48
46
|
}
|
|
49
47
|
|
|
@@ -60,3 +58,13 @@ export type ExpressionResult<T> = T extends Expression<infer R> ? R : T;
|
|
|
60
58
|
export type ExpressionResultObject<T> = {
|
|
61
59
|
[K in keyof T]: ExpressionResult<T[K]>;
|
|
62
60
|
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 表示一个具有类似表达式功能的 JS 函数
|
|
64
|
+
*/
|
|
65
|
+
export type ExpressionFunction<out T> = (
|
|
66
|
+
/** 当前作用域 */
|
|
67
|
+
scope: Scope,
|
|
68
|
+
/** 当前求值器 */
|
|
69
|
+
evaluator: Evaluator,
|
|
70
|
+
) => T | null;
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export type { Options,
|
|
1
|
+
export type { Options, Logger } from './interface.js';
|
|
2
2
|
export { Scope } from './scope.js';
|
|
3
3
|
export { Evaluator } from './main.js';
|
|
4
|
+
export type { AccessChain } from './analyze.js';
|
|
4
5
|
export * from './expression.js';
|
|
5
6
|
export * from './type.js';
|
|
7
|
+
export * from './re-exports.js';
|
package/src/interface.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** 日志 */
|
|
2
|
+
export interface Logger {
|
|
3
|
+
/**
|
|
4
|
+
* error
|
|
5
|
+
*/
|
|
6
|
+
error(...args: unknown[]): void;
|
|
7
|
+
/**
|
|
8
|
+
* warning
|
|
9
|
+
*/
|
|
10
|
+
warn(...args: unknown[]): void;
|
|
11
|
+
/**
|
|
12
|
+
* info
|
|
13
|
+
*/
|
|
14
|
+
info(...args: unknown[]): void;
|
|
15
|
+
/**
|
|
16
|
+
* debug
|
|
17
|
+
*/
|
|
18
|
+
debug(...args: unknown[]): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 选项 */
|
|
22
|
+
export interface Options {
|
|
23
|
+
/** 日志 */
|
|
24
|
+
logger: Logger;
|
|
25
|
+
/** 表达式缓存 */
|
|
26
|
+
expressionCacheSize: number;
|
|
27
|
+
/** 模板缓存 */
|
|
28
|
+
templateCacheSize: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const defaultOptions: Options = {
|
|
32
|
+
logger: console,
|
|
33
|
+
expressionCacheSize: 50,
|
|
34
|
+
templateCacheSize: 50,
|
|
35
|
+
};
|