@variojs/core 0.1.1 → 0.1.2
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/index.d.ts +103 -289
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +10 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,293 +1,7 @@
|
|
|
1
|
-
import { SchemaNode } from '@variojs/
|
|
1
|
+
import { CreateContextOptions, RuntimeContext, SchemaNode, ExpressionOptions, Action } from '@variojs/types';
|
|
2
|
+
export { Action, ActionHandler, ActionMap, CreateContextOptions, ErrorContext, ExpressionCache, ExpressionOptions, MethodHandler, MethodsRegistry, PathSegment, RuntimeContext } from '@variojs/types';
|
|
2
3
|
import * as ESTree from '@babel/types';
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
* Vario 错误处理体系
|
|
6
|
-
*
|
|
7
|
-
* 统一的错误基类和错误码系统
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 错误上下文信息
|
|
12
|
-
*/
|
|
13
|
-
interface ErrorContext {
|
|
14
|
-
/** Schema 路径(如 "events.click[0]") */
|
|
15
|
-
schemaPath?: string;
|
|
16
|
-
/** 表达式字符串 */
|
|
17
|
-
expression?: string;
|
|
18
|
-
/** 动作对象 */
|
|
19
|
-
action?: Action;
|
|
20
|
-
/** 调用栈(简化版) */
|
|
21
|
-
stack?: string[];
|
|
22
|
-
/** 额外上下文信息 */
|
|
23
|
-
metadata?: Record<string, unknown>;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Vario 错误基类
|
|
27
|
-
*
|
|
28
|
-
* 所有 Vario 相关错误都应继承此类
|
|
29
|
-
*/
|
|
30
|
-
declare class VarioError extends Error {
|
|
31
|
-
/** 错误码 */
|
|
32
|
-
readonly code: string;
|
|
33
|
-
/** 错误上下文 */
|
|
34
|
-
readonly context: ErrorContext;
|
|
35
|
-
constructor(message: string, code: string, context?: ErrorContext);
|
|
36
|
-
/**
|
|
37
|
-
* 获取友好的错误消息
|
|
38
|
-
*/
|
|
39
|
-
getFriendlyMessage(): string;
|
|
40
|
-
/**
|
|
41
|
-
* 转换为 JSON(用于序列化)
|
|
42
|
-
*/
|
|
43
|
-
toJSON(): Record<string, unknown>;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* 动作执行错误
|
|
47
|
-
*/
|
|
48
|
-
declare class ActionError extends VarioError {
|
|
49
|
-
constructor(action: Action, message: string, code?: string, context?: Omit<ErrorContext, 'action'>);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* 表达式求值错误
|
|
53
|
-
*/
|
|
54
|
-
declare class ExpressionError extends VarioError {
|
|
55
|
-
constructor(expression: string, message: string, code?: string, context?: Omit<ErrorContext, 'expression'>);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* 服务调用错误
|
|
59
|
-
*/
|
|
60
|
-
declare class ServiceError extends VarioError {
|
|
61
|
-
readonly service: string;
|
|
62
|
-
readonly originalError?: Error;
|
|
63
|
-
constructor(service: string, message: string, originalError?: Error, context?: ErrorContext);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* 批量执行错误
|
|
67
|
-
*/
|
|
68
|
-
declare class BatchError extends VarioError {
|
|
69
|
-
readonly failedActions: Array<{
|
|
70
|
-
action: Action;
|
|
71
|
-
error: Error;
|
|
72
|
-
}>;
|
|
73
|
-
constructor(failedActions: Array<{
|
|
74
|
-
action: Action;
|
|
75
|
-
error: Error;
|
|
76
|
-
}>, message: string, context?: ErrorContext);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* 错误码定义
|
|
80
|
-
*/
|
|
81
|
-
declare const ErrorCodes: {
|
|
82
|
-
readonly ACTION_UNKNOWN_TYPE: "ACTION_UNKNOWN_TYPE";
|
|
83
|
-
readonly ACTION_EXECUTION_ERROR: "ACTION_EXECUTION_ERROR";
|
|
84
|
-
readonly ACTION_ABORTED: "ACTION_ABORTED";
|
|
85
|
-
readonly ACTION_TIMEOUT: "ACTION_TIMEOUT";
|
|
86
|
-
readonly ACTION_MAX_STEPS_EXCEEDED: "ACTION_MAX_STEPS_EXCEEDED";
|
|
87
|
-
readonly ACTION_MISSING_PARAM: "ACTION_MISSING_PARAM";
|
|
88
|
-
readonly ACTION_INVALID_PARAM: "ACTION_INVALID_PARAM";
|
|
89
|
-
readonly EXPRESSION_PARSE_ERROR: "EXPRESSION_PARSE_ERROR";
|
|
90
|
-
readonly EXPRESSION_VALIDATION_ERROR: "EXPRESSION_VALIDATION_ERROR";
|
|
91
|
-
readonly EXPRESSION_EVALUATION_ERROR: "EXPRESSION_EVALUATION_ERROR";
|
|
92
|
-
readonly EXPRESSION_TIMEOUT: "EXPRESSION_TIMEOUT";
|
|
93
|
-
readonly EXPRESSION_MAX_STEPS_EXCEEDED: "EXPRESSION_MAX_STEPS_EXCEEDED";
|
|
94
|
-
readonly EXPRESSION_UNSAFE_ACCESS: "EXPRESSION_UNSAFE_ACCESS";
|
|
95
|
-
readonly EXPRESSION_FUNCTION_NOT_WHITELISTED: "EXPRESSION_FUNCTION_NOT_WHITELISTED";
|
|
96
|
-
readonly SERVICE_NOT_FOUND: "SERVICE_NOT_FOUND";
|
|
97
|
-
readonly SERVICE_CALL_ERROR: "SERVICE_CALL_ERROR";
|
|
98
|
-
readonly BATCH_ERROR: "BATCH_ERROR";
|
|
99
|
-
readonly SCHEMA_VALIDATION_ERROR: "SCHEMA_VALIDATION_ERROR";
|
|
100
|
-
readonly SCHEMA_INVALID_ACTION: "SCHEMA_INVALID_ACTION";
|
|
101
|
-
};
|
|
102
|
-
type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes];
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Vario Core Types
|
|
106
|
-
*
|
|
107
|
-
* 复杂类型集中在此定义,便于推演类型关系、保持业务/运行时逻辑代码简洁。
|
|
108
|
-
* 核心:RuntimeContext、路径值推导(GetPathValue/SetPathValue)、上下文创建选项(CreateContextOptions)等。
|
|
109
|
-
*/
|
|
110
|
-
/**
|
|
111
|
-
* 方法处理器类型
|
|
112
|
-
* 所有注册到 $methods 的方法必须符合此签名
|
|
113
|
-
*
|
|
114
|
-
* 注意:动作处理器也通过 $methods 注册,但它们的参数是 Action
|
|
115
|
-
*/
|
|
116
|
-
type MethodHandler<TParams = unknown, TResult = unknown> = (ctx: RuntimeContext, params: TParams) => Promise<TResult> | TResult;
|
|
117
|
-
/**
|
|
118
|
-
* 动作处理器类型(特殊的方法处理器)
|
|
119
|
-
*/
|
|
120
|
-
type ActionHandler = MethodHandler<Action, void>;
|
|
121
|
-
/**
|
|
122
|
-
* 方法注册表类型
|
|
123
|
-
* 支持普通方法和指令处理器
|
|
124
|
-
*/
|
|
125
|
-
type MethodsRegistry = Record<string, MethodHandler>;
|
|
126
|
-
/**
|
|
127
|
-
* 表达式求值选项
|
|
128
|
-
*/
|
|
129
|
-
interface ExpressionOptions {
|
|
130
|
-
/**
|
|
131
|
-
* 是否允许访问全局对象(默认 false)
|
|
132
|
-
*/
|
|
133
|
-
allowGlobals?: boolean;
|
|
134
|
-
/**
|
|
135
|
-
* 最大求值步数
|
|
136
|
-
*/
|
|
137
|
-
maxSteps?: number;
|
|
138
|
-
/**
|
|
139
|
-
* 求值超时(毫秒)
|
|
140
|
-
*/
|
|
141
|
-
timeout?: number;
|
|
142
|
-
/**
|
|
143
|
-
* 最大嵌套深度(防止 DoS 攻击,默认 50)
|
|
144
|
-
*/
|
|
145
|
-
maxNestingDepth?: number;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* 运行时上下文接口
|
|
149
|
-
* 扁平化状态设计:直接属性访问,无 models. 前缀
|
|
150
|
-
*
|
|
151
|
-
* @template TState 状态类型,用于类型推导和约束
|
|
152
|
-
*
|
|
153
|
-
* 设计说明:
|
|
154
|
-
* - 使用接口 + 索引签名,既支持类型推导又支持动态属性
|
|
155
|
-
* - 状态属性通过 TState 泛型约束
|
|
156
|
-
* - 系统 API 使用具体类型定义,确保类型安全
|
|
157
|
-
*/
|
|
158
|
-
/**
|
|
159
|
-
* 运行时上下文类型
|
|
160
|
-
* 使用交叉类型结合接口,既支持状态类型推导又支持动态属性
|
|
161
|
-
*/
|
|
162
|
-
type RuntimeContext<TState extends Record<string, unknown> = Record<string, unknown>> = TState & {
|
|
163
|
-
$emit: (event: string, data?: unknown) => void;
|
|
164
|
-
$methods: MethodsRegistry;
|
|
165
|
-
$exprOptions?: ExpressionOptions;
|
|
166
|
-
/**
|
|
167
|
-
* 事件值(在事件处理中可用)
|
|
168
|
-
* - 对于 DOM 原生事件:Event 对象
|
|
169
|
-
* - 对于 Vue 组件 emit:emit 的参数值(如 string[]、number 等)
|
|
170
|
-
*/
|
|
171
|
-
$event?: unknown;
|
|
172
|
-
$item?: TState[keyof TState];
|
|
173
|
-
$index?: number;
|
|
174
|
-
_get: <TPath extends string>(path: TPath) => GetPathValue<TState, TPath>;
|
|
175
|
-
_set: <TPath extends string>(path: TPath, value: SetPathValue<TState, TPath>, options?: {
|
|
176
|
-
skipCallback?: boolean;
|
|
177
|
-
}) => void;
|
|
178
|
-
} & Record<string, unknown>;
|
|
179
|
-
/**
|
|
180
|
-
* 路径值类型推导工具
|
|
181
|
-
* 根据路径字符串推导对应的值类型,支持对象嵌套与数组索引
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* GetPathValue<{ user: { name: string } }, 'user.name'> // string
|
|
185
|
-
* GetPathValue<{ items: number[] }, 'items.0'> // number
|
|
186
|
-
* GetPathValue<{ list: { id: number }[] }, 'list.0.id'> // number
|
|
187
|
-
*/
|
|
188
|
-
type GetPathValue<T, TPath extends string> = TPath extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? T[Key] extends Record<string, unknown> ? GetPathValue<T[Key], Rest> : T[Key] extends readonly (infer E)[] ? Rest extends `${number}` ? E : Rest extends `${number}.${infer R}` ? GetPathValue<E, R> : unknown : unknown : unknown : TPath extends keyof T ? T[TPath] : unknown;
|
|
189
|
-
/**
|
|
190
|
-
* 路径设置值类型推导工具
|
|
191
|
-
* 根据路径字符串推导可以设置的值类型
|
|
192
|
-
*/
|
|
193
|
-
type SetPathValue<T, TPath extends string> = GetPathValue<T, TPath>;
|
|
194
|
-
/**
|
|
195
|
-
* 状态变更回调:path 与 value 类型联动,TPath 由 path 推导,value 为 GetPathValue<TState, TPath>
|
|
196
|
-
*/
|
|
197
|
-
type OnStateChangeCallback<TState extends Record<string, unknown>> = <TPath extends string>(path: TPath, value: GetPathValue<TState, TPath>, ctx: RuntimeContext<TState>) => void;
|
|
198
|
-
/**
|
|
199
|
-
* RuntimeContext 创建选项
|
|
200
|
-
* @template TState 与 context 一致的状态类型,供 onStateChange 等回调获得完整类型推导
|
|
201
|
-
*/
|
|
202
|
-
interface CreateContextOptions<TState extends Record<string, unknown> = Record<string, unknown>> {
|
|
203
|
-
onEmit?: (event: string, data?: unknown) => void;
|
|
204
|
-
methods?: MethodsRegistry;
|
|
205
|
-
/** 在 _set 调用后触发,value 类型随 path 推导 */
|
|
206
|
-
onStateChange?: OnStateChangeCallback<TState>;
|
|
207
|
-
createObject?: () => Record<string, unknown>;
|
|
208
|
-
createArray?: () => unknown[];
|
|
209
|
-
exprOptions?: ExpressionOptions;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* 动作接口
|
|
213
|
-
* 使用泛型约束,根据 type 类型推导参数结构
|
|
214
|
-
*/
|
|
215
|
-
interface Action {
|
|
216
|
-
type: string;
|
|
217
|
-
[key: string]: unknown;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* 动作类型映射
|
|
221
|
-
* 根据 type 值推导对应的动作参数类型
|
|
222
|
-
*/
|
|
223
|
-
type ActionMap = {
|
|
224
|
-
set: {
|
|
225
|
-
path: string;
|
|
226
|
-
value: string | unknown;
|
|
227
|
-
};
|
|
228
|
-
emit: {
|
|
229
|
-
event: string;
|
|
230
|
-
data?: string | unknown;
|
|
231
|
-
};
|
|
232
|
-
navigate: {
|
|
233
|
-
to: string;
|
|
234
|
-
};
|
|
235
|
-
log: {
|
|
236
|
-
level?: 'info' | 'warn' | 'error';
|
|
237
|
-
message: string;
|
|
238
|
-
};
|
|
239
|
-
if: {
|
|
240
|
-
cond: string;
|
|
241
|
-
then?: Action[];
|
|
242
|
-
else?: Action[];
|
|
243
|
-
};
|
|
244
|
-
loop: {
|
|
245
|
-
var: string;
|
|
246
|
-
in: string;
|
|
247
|
-
body: Action[];
|
|
248
|
-
};
|
|
249
|
-
call: {
|
|
250
|
-
method: string;
|
|
251
|
-
params?: Record<string, unknown>;
|
|
252
|
-
args?: unknown[];
|
|
253
|
-
resultTo?: string;
|
|
254
|
-
modifiers?: Record<string, boolean>;
|
|
255
|
-
};
|
|
256
|
-
batch: {
|
|
257
|
-
actions: Action[];
|
|
258
|
-
};
|
|
259
|
-
push: {
|
|
260
|
-
path: string;
|
|
261
|
-
value: string | unknown;
|
|
262
|
-
};
|
|
263
|
-
pop: {
|
|
264
|
-
path: string;
|
|
265
|
-
};
|
|
266
|
-
shift: {
|
|
267
|
-
path: string;
|
|
268
|
-
};
|
|
269
|
-
unshift: {
|
|
270
|
-
path: string;
|
|
271
|
-
value: string | unknown;
|
|
272
|
-
};
|
|
273
|
-
splice: {
|
|
274
|
-
path: string;
|
|
275
|
-
start: number | string;
|
|
276
|
-
deleteCount?: number | string;
|
|
277
|
-
items?: string | unknown[];
|
|
278
|
-
};
|
|
279
|
-
};
|
|
280
|
-
/**
|
|
281
|
-
* 表达式缓存接口
|
|
282
|
-
* 结果类型使用 unknown,因为表达式求值结果类型无法静态推导
|
|
283
|
-
*/
|
|
284
|
-
interface ExpressionCache {
|
|
285
|
-
expr: string;
|
|
286
|
-
result: unknown;
|
|
287
|
-
dependencies: string[];
|
|
288
|
-
timestamp: number;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
5
|
/**
|
|
292
6
|
* RuntimeContext 创建工厂
|
|
293
7
|
*
|
|
@@ -719,6 +433,106 @@ declare function execute(actions: Action[], ctx: RuntimeContext, options?: Execu
|
|
|
719
433
|
*/
|
|
720
434
|
declare function registerBuiltinMethods(ctx: RuntimeContext): void;
|
|
721
435
|
|
|
436
|
+
/**
|
|
437
|
+
* Vario 错误处理体系
|
|
438
|
+
*
|
|
439
|
+
* 统一的错误基类和错误码系统
|
|
440
|
+
*/
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* 错误上下文信息
|
|
444
|
+
*/
|
|
445
|
+
interface ErrorContext {
|
|
446
|
+
/** Schema 路径(如 "events.click[0]") */
|
|
447
|
+
schemaPath?: string;
|
|
448
|
+
/** 表达式字符串 */
|
|
449
|
+
expression?: string;
|
|
450
|
+
/** 动作对象 */
|
|
451
|
+
action?: Action;
|
|
452
|
+
/** 调用栈(简化版) */
|
|
453
|
+
stack?: string[];
|
|
454
|
+
/** 额外上下文信息 */
|
|
455
|
+
metadata?: Record<string, unknown>;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Vario 错误基类
|
|
459
|
+
*
|
|
460
|
+
* 所有 Vario 相关错误都应继承此类
|
|
461
|
+
*/
|
|
462
|
+
declare class VarioError extends Error {
|
|
463
|
+
/** 错误码 */
|
|
464
|
+
readonly code: string;
|
|
465
|
+
/** 错误上下文 */
|
|
466
|
+
readonly context: ErrorContext;
|
|
467
|
+
constructor(message: string, code: string, context?: ErrorContext);
|
|
468
|
+
/**
|
|
469
|
+
* 获取友好的错误消息
|
|
470
|
+
*/
|
|
471
|
+
getFriendlyMessage(): string;
|
|
472
|
+
/**
|
|
473
|
+
* 转换为 JSON(用于序列化)
|
|
474
|
+
*/
|
|
475
|
+
toJSON(): Record<string, unknown>;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* 动作执行错误
|
|
479
|
+
*/
|
|
480
|
+
declare class ActionError extends VarioError {
|
|
481
|
+
constructor(action: Action, message: string, code?: string, context?: Omit<ErrorContext, 'action'>);
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* 表达式求值错误
|
|
485
|
+
*/
|
|
486
|
+
declare class ExpressionError extends VarioError {
|
|
487
|
+
constructor(expression: string, message: string, code?: string, context?: Omit<ErrorContext, 'expression'>);
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* 服务调用错误
|
|
491
|
+
*/
|
|
492
|
+
declare class ServiceError extends VarioError {
|
|
493
|
+
readonly service: string;
|
|
494
|
+
readonly originalError?: Error;
|
|
495
|
+
constructor(service: string, message: string, originalError?: Error, context?: ErrorContext);
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* 批量执行错误
|
|
499
|
+
*/
|
|
500
|
+
declare class BatchError extends VarioError {
|
|
501
|
+
readonly failedActions: Array<{
|
|
502
|
+
action: Action;
|
|
503
|
+
error: Error;
|
|
504
|
+
}>;
|
|
505
|
+
constructor(failedActions: Array<{
|
|
506
|
+
action: Action;
|
|
507
|
+
error: Error;
|
|
508
|
+
}>, message: string, context?: ErrorContext);
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* 错误码定义
|
|
512
|
+
*/
|
|
513
|
+
declare const ErrorCodes: {
|
|
514
|
+
readonly ACTION_UNKNOWN_TYPE: "ACTION_UNKNOWN_TYPE";
|
|
515
|
+
readonly ACTION_EXECUTION_ERROR: "ACTION_EXECUTION_ERROR";
|
|
516
|
+
readonly ACTION_ABORTED: "ACTION_ABORTED";
|
|
517
|
+
readonly ACTION_TIMEOUT: "ACTION_TIMEOUT";
|
|
518
|
+
readonly ACTION_MAX_STEPS_EXCEEDED: "ACTION_MAX_STEPS_EXCEEDED";
|
|
519
|
+
readonly ACTION_MISSING_PARAM: "ACTION_MISSING_PARAM";
|
|
520
|
+
readonly ACTION_INVALID_PARAM: "ACTION_INVALID_PARAM";
|
|
521
|
+
readonly EXPRESSION_PARSE_ERROR: "EXPRESSION_PARSE_ERROR";
|
|
522
|
+
readonly EXPRESSION_VALIDATION_ERROR: "EXPRESSION_VALIDATION_ERROR";
|
|
523
|
+
readonly EXPRESSION_EVALUATION_ERROR: "EXPRESSION_EVALUATION_ERROR";
|
|
524
|
+
readonly EXPRESSION_TIMEOUT: "EXPRESSION_TIMEOUT";
|
|
525
|
+
readonly EXPRESSION_MAX_STEPS_EXCEEDED: "EXPRESSION_MAX_STEPS_EXCEEDED";
|
|
526
|
+
readonly EXPRESSION_UNSAFE_ACCESS: "EXPRESSION_UNSAFE_ACCESS";
|
|
527
|
+
readonly EXPRESSION_FUNCTION_NOT_WHITELISTED: "EXPRESSION_FUNCTION_NOT_WHITELISTED";
|
|
528
|
+
readonly SERVICE_NOT_FOUND: "SERVICE_NOT_FOUND";
|
|
529
|
+
readonly SERVICE_CALL_ERROR: "SERVICE_CALL_ERROR";
|
|
530
|
+
readonly BATCH_ERROR: "BATCH_ERROR";
|
|
531
|
+
readonly SCHEMA_VALIDATION_ERROR: "SCHEMA_VALIDATION_ERROR";
|
|
532
|
+
readonly SCHEMA_INVALID_ACTION: "SCHEMA_INVALID_ACTION";
|
|
533
|
+
};
|
|
534
|
+
type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes];
|
|
535
|
+
|
|
722
536
|
/**
|
|
723
537
|
* Schema 分析器 - 框架无关的纯函数实现
|
|
724
538
|
*
|
|
@@ -828,4 +642,4 @@ declare function createQueryEngine(options: QueryEngineOptions): {
|
|
|
828
642
|
getParent: (path: string) => NodeResult | null;
|
|
829
643
|
};
|
|
830
644
|
|
|
831
|
-
export {
|
|
645
|
+
export { ActionError, type AnalysisResult, BatchError, type ErrorCode, ErrorCodes, type ExecuteOptions, ExpressionError, type NodeResult, type QueryEngineOptions, type SchemaIndex, type SchemaStats, ServiceError, type TraversalCallback, VarioError, analyzeSchema, clearCache, clearPathCache, createExpressionSandbox, createLoopContext, createProxy, createQueryEngine, createRuntimeContext, evaluate, evaluateExpression, execute, extractDependencies, extractExpression, findNode, findNodes, findPathById, getCacheStats, getCachedExpression, getLastSegment, getParentPath, getPathValue, invalidateCache, isSafePropertyAccess, matchPath, parseExpression, parsePath, parsePathCached, registerBuiltinMethods, releaseLoopContext, setCachedExpression, setPathValue, stringifyPath, traverseSchema, validateAST };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {parse}from'@babel/parser';function W(e){let n=["$event","$item","$index","$self","$parent","$siblings","$children"];return new Proxy(e,{set(t,r,o){let i=String(r);if(i.startsWith("$")||i.startsWith("_")){if(n.includes(i))return Reflect.set(t,r,o);throw new Error(`Cannot override system API: ${i}. Properties starting with "$" or "_" are protected.`)}return Reflect.set(t,r,o)},get(t,r){return Reflect.get(t,r)},has(t,r){return Reflect.has(t,r)},deleteProperty(t,r){let o=String(r);if(o.startsWith("$")||o.startsWith("_")){if(n.includes(o))return Reflect.deleteProperty(t,r);throw new Error(`Cannot delete system API: ${o}`)}return Reflect.deleteProperty(t,r)}})}var
|
|
1
|
+
import {parse}from'@babel/parser';function W(e){let n=["$event","$item","$index","$self","$parent","$siblings","$children"];return new Proxy(e,{set(t,r,o){let i=String(r);if(i.startsWith("$")||i.startsWith("_")){if(n.includes(i))return Reflect.set(t,r,o);throw new Error(`Cannot override system API: ${i}. Properties starting with "$" or "_" are protected.`)}return Reflect.set(t,r,o)},get(t,r){return Reflect.get(t,r)},has(t,r){return Reflect.has(t,r)},deleteProperty(t,r){let o=String(r);if(o.startsWith("$")||o.startsWith("_")){if(n.includes(o))return Reflect.deleteProperty(t,r);throw new Error(`Cannot delete system API: ${o}`)}return Reflect.deleteProperty(t,r)}})}var I=class e extends Error{code;context;constructor(n,t,r={}){super(n),this.name="VarioError",this.code=t,this.context=r,Error.captureStackTrace&&Error.captureStackTrace(this,e);}getFriendlyMessage(){let n=[this.message];return this.context.schemaPath&&n.push(`
|
|
2
2
|
Schema \u8DEF\u5F84: ${this.context.schemaPath}`),this.context.expression&&n.push(`
|
|
3
3
|
\u8868\u8FBE\u5F0F: ${this.context.expression}`),this.context.action&&n.push(`
|
|
4
|
-
\u52A8\u4F5C\u7C7B\u578B: ${this.context.action.type}`),n.join("")}toJSON(){return {name:this.name,message:this.message,code:this.code,context:this.context,stack:this.stack}}},
|
|
4
|
+
\u52A8\u4F5C\u7C7B\u578B: ${this.context.action.type}`),n.join("")}toJSON(){return {name:this.name,message:this.message,code:this.code,context:this.context,stack:this.stack}}},h=class extends I{constructor(n,t,r="ACTION_ERROR",o={}){super(t,r,{...o,action:n}),this.name="ActionError";}},y=class extends I{constructor(n,t,r="EXPRESSION_ERROR",o={}){super(t,r,{...o,expression:n}),this.name="ExpressionError";}},N=class extends I{service;originalError;constructor(n,t,r,o={}){super(t,"SERVICE_ERROR",o),this.name="ServiceError",this.service=n,this.originalError=r;}},_=class extends I{failedActions;constructor(n,t,r={}){super(t,"BATCH_ERROR",r),this.name="BatchError",this.failedActions=n;}},c={ACTION_UNKNOWN_TYPE:"ACTION_UNKNOWN_TYPE",ACTION_EXECUTION_ERROR:"ACTION_EXECUTION_ERROR",ACTION_ABORTED:"ACTION_ABORTED",ACTION_TIMEOUT:"ACTION_TIMEOUT",ACTION_MAX_STEPS_EXCEEDED:"ACTION_MAX_STEPS_EXCEEDED",ACTION_MISSING_PARAM:"ACTION_MISSING_PARAM",ACTION_INVALID_PARAM:"ACTION_INVALID_PARAM",EXPRESSION_PARSE_ERROR:"EXPRESSION_PARSE_ERROR",EXPRESSION_VALIDATION_ERROR:"EXPRESSION_VALIDATION_ERROR",EXPRESSION_EVALUATION_ERROR:"EXPRESSION_EVALUATION_ERROR",EXPRESSION_TIMEOUT:"EXPRESSION_TIMEOUT",EXPRESSION_MAX_STEPS_EXCEEDED:"EXPRESSION_MAX_STEPS_EXCEEDED",EXPRESSION_UNSAFE_ACCESS:"EXPRESSION_UNSAFE_ACCESS",EXPRESSION_FUNCTION_NOT_WHITELISTED:"EXPRESSION_FUNCTION_NOT_WHITELISTED",SERVICE_NOT_FOUND:"SERVICE_NOT_FOUND",SERVICE_CALL_ERROR:"SERVICE_CALL_ERROR",BATCH_ERROR:"BATCH_ERROR",SCHEMA_VALIDATION_ERROR:"SCHEMA_VALIDATION_ERROR",SCHEMA_INVALID_ACTION:"SCHEMA_INVALID_ACTION"};function B(e){try{let t=parse(`(${e})`,{plugins:["typescript"],sourceType:"module",allowReturnOutsideFunction:!0}).program.body[0];if(t?.type==="ExpressionStatement")return t.expression;throw new y(e,`Failed to parse expression: ${e}`,c.EXPRESSION_PARSE_ERROR)}catch(n){if(n instanceof y)throw n;let t=n instanceof Error?n.message:String(n);throw new y(e,`Expression parse error: ${t}`,c.EXPRESSION_PARSE_ERROR,{metadata:{originalError:n instanceof Error?n.name:"Unknown"}})}}var ue=new Set(["String","Number","Boolean","BigInt","Symbol","Array","Object","Math","Date"]),Fe=new Set(["Array.isArray","Object.is","Number.isFinite","Number.isInteger","Number.isNaN","Number.isSafeInteger","Math.abs","Math.round","Math.floor","Math.ceil","Math.random","Math.max","Math.min","Date.now"]);function He(e){return ["window","document","global","globalThis","self"].includes(e)}var qe=new Set(["MemberExpression","OptionalMemberExpression","ArrayExpression","ObjectExpression","ObjectProperty","Literal","NumericLiteral","StringLiteral","BooleanLiteral","NullLiteral","Identifier","BinaryExpression","LogicalExpression","UnaryExpression","ConditionalExpression","CallExpression","TemplateLiteral","SequenceExpression","NullishCoalescingExpression"]),Je=new Set(["AssignmentExpression","UpdateExpression","FunctionExpression","ArrowFunctionExpression","ThisExpression","NewExpression","YieldExpression","AwaitExpression","ImportExpression","MetaProperty","SpreadElement"]),ze=50;function F(e,n){let t=n?.allowGlobals===true,r=n?.maxNestingDepth??ze,o=[];function i(s){if(s.type==="Identifier")return s.name;if(s.type==="MemberExpression"){let u=s;if(u.object.type==="Identifier"&&u.property.type==="Identifier")return `${u.object.name}.${u.property.name}`}return null}function a(s,u="root",d=0){if(d>r){o.push(`Maximum nesting depth (${r}) exceeded at ${u}`);return}if(Je.has(s.type)){o.push(`Forbidden node type "${s.type}" at ${u}`);return}if(s.type==="CallExpression"){let f=s,S=i(f.callee);if(S){if(["eval","Function","setTimeout","setInterval","execScript"].includes(S)||S.startsWith("eval")||S.startsWith("Function")){o.push(`Dangerous function "${S}" is not allowed at ${u}`);return}if(!t){let E=Fe.has(S)||ue.has(S.split(".")[0]),k=false;if(f.callee.type==="MemberExpression"){let m=f.callee;if(m.object.type==="Identifier"){let p=m.object.name;!ue.has(p)&&!He(p)&&(k=true);}}if(!E&&!k&&!S.startsWith("$")){o.push(`Function "${S}" is not in whitelist at ${u}`);return}}}}if(!qe.has(s.type)&&s.type!=="Program"){o.push(`Unknown node type "${s.type}" at ${u}`);return}for(let f in s){let S=s[f];S!=null&&(Array.isArray(S)?S.forEach((g,E)=>{g&&typeof g=="object"&&"type"in g&&a(g,`${u}[${E}]`,d+1);}):S&&typeof S=="object"&&"type"in S&&a(S,`${u}.${f}`,d+1));}}if(a(e,"root",0),o.length>0)throw new y(JSON.stringify(e),`AST validation failed:
|
|
5
5
|
${o.join(`
|
|
6
|
-
`)}`,c.EXPRESSION_VALIDATION_ERROR,{metadata:{errors:o,nodeType:e.type}})}function me(e){return {...e}}function H(e,n,t={}){return !(!(t.allowGlobals??n.$exprOptions?.allowGlobals??false)&&["window","document","global","globalThis","self"].includes(e))}var fe=new Set(["String","Number","Boolean","BigInt","Symbol","Array","Object","Math","Date"]),Ke=new Set(["Array.isArray","Object.is","Number.isFinite","Number.isInteger","Number.isNaN","Number.isSafeInteger","Math.abs","Math.round","Math.floor","Math.ceil","Math.random","Math.max","Math.min","Date.now"]),de=new Set(["slice","concat","filter","map","flat","flatMap","toReversed","toSorted","toSpliced","with","indexOf","lastIndexOf","includes","find","findIndex","findLast","findLastIndex","every","some","at","join","toString","toLocaleString","reverse","sort"]),Qe=new Set(["constructor","prototype","__proto__"]);function he(e){return typeof e=="string"&&Qe.has(e)}var Z={$truncate:(e,n)=>{if(typeof e!="string")return e;let t=typeof n=="number"?n:0;return e.length>t?e.slice(0,t)+"...":e},$format:(e,n)=>(typeof e=="number"?new Date(e):e).toISOString()};function q(e,n,t={}){let r={...n.$exprOptions,...t},o=r.allowGlobals===true,i=r.maxSteps??1e3,a=r.timeout??100,s=0,u=Date.now();function h(E){if(o)return E==="globalThis"?globalThis:E==="window"&&typeof window<"u"?window:E==="document"&&typeof document<"u"?document:E==="global"&&typeof global<"u"?global:E==="self"&&typeof self<"u"?self:globalThis[E]}function f(E){return ["window","document","global","globalThis","self"].includes(E)}function S(){if(s++,s>i)throw new g(JSON.stringify(e),`Expression evaluation exceeded max steps (${i})`,c.EXPRESSION_MAX_STEPS_EXCEEDED,{metadata:{maxSteps:i,currentSteps:s}});if(Date.now()-u>a)throw new g(JSON.stringify(e),`Expression evaluation exceeded timeout (${a}ms)`,c.EXPRESSION_TIMEOUT,{metadata:{timeout:a,elapsedTime:Date.now()-u}})}function y(E){switch(S(),E.type){case "NumericLiteral":case "StringLiteral":case "BooleanLiteral":case "BigIntLiteral":case "DecimalLiteral":case "RegExpLiteral":return E.value;case "NullLiteral":return null;case "Literal":{let m=E;return "value"in m&&m.value!==void 0?m.value:m.type==="NullLiteral"?null:m.value??void 0}case "Identifier":{let m=E.name;if(f(m)&&!o)throw new g(m,`Access to global "${m}" is not allowed in expressions`,c.EXPRESSION_UNSAFE_ACCESS);if(m in n&&!f(m))return n[m];if(o){let p=h(m);if(p!==void 0)return p}return fe.has(m)?globalThis[m]:void 0}case "MemberExpression":{let m=E,p=y(m.object);if(p==null)return;if(!o&&(p===globalThis||typeof window<"u"&&p===window||typeof global<"u"&&p===global||typeof self<"u"&&p===self))throw new g(JSON.stringify(E),"Access to global object is not allowed in expressions",c.EXPRESSION_UNSAFE_ACCESS);let l;if(m.computed?l=y(m.property):l=m.property.name,!o&&he(l))throw new g(String(l),`Access to "${l}" is not allowed in expressions`,c.EXPRESSION_UNSAFE_ACCESS);return p[l]}case "OptionalMemberExpression":{let m=E,p=y(m.object);if(p==null)return;if(!o&&(p===globalThis||typeof window<"u"&&p===window||typeof global<"u"&&p===global||typeof self<"u"&&p===self))throw new g(JSON.stringify(E),"Access to global object is not allowed in expressions",c.EXPRESSION_UNSAFE_ACCESS);let l;if(m.computed?l=y(m.property):l=m.property.name,!o&&he(l))throw new g(String(l),`Access to "${l}" is not allowed in expressions`,c.EXPRESSION_UNSAFE_ACCESS);return p?.[l]}case "BinaryExpression":{let m=E,p=y(m.left),l=y(m.right),C=m.operator;switch(C){case "+":return p+l;case "-":return p-l;case "*":return p*l;case "/":return p/l;case "%":return p%l;case "**":return p**l;case "==":return p==l;case "!=":return p!=l;case "===":return p===l;case "!==":return p!==l;case "<":return p<l;case "<=":return p<=l;case ">":return p>l;case ">=":return p>=l;case "<<":return p<<l;case ">>":return p>>l;case ">>>":return p>>>l;case "&":return p&l;case "|":return p|l;case "^":return p^l;case "in":return p in l;case "instanceof":{if(typeof l!="function"&&typeof l!="object")throw new g(JSON.stringify(E),"Right-hand side of instanceof must be a constructor",c.EXPRESSION_EVALUATION_ERROR);return p instanceof l}default:throw new g(JSON.stringify(E),`Unsupported binary operator: ${C}`,c.EXPRESSION_EVALUATION_ERROR)}}case "LogicalExpression":{let m=E,p=y(m.left),l=m.operator;if(l==="&&")return p&&y(m.right);if(l==="||")return p||y(m.right);if(l==="??")return p??y(m.right);throw new g(JSON.stringify(E),`Unsupported logical operator: ${l}`,c.EXPRESSION_EVALUATION_ERROR)}case "UnaryExpression":{let m=E,p=y(m.argument),l=m.operator;switch(l){case "+":return +p;case "-":return -p;case "!":return !p;case "~":return ~p;case "typeof":return typeof p;case "void":return;case "delete":throw new g(JSON.stringify(E),"delete operator is not allowed",c.EXPRESSION_EVALUATION_ERROR);default:throw new g(JSON.stringify(E),`Unsupported unary operator: ${l}`,c.EXPRESSION_EVALUATION_ERROR)}}case "ConditionalExpression":{let m=E,p=y(m.test);return y(p?m.consequent:m.alternate)}case "CallExpression":{let m=E,p=m.callee,l,C,P=null;if(p.type==="Identifier"){if(l=p.name,!H(l,n,{allowGlobals:o}))throw new g(l,`Access to global "${l}" is not allowed in expressions`,"UNSAFE_ACCESS");C=n[l]??globalThis[l],P=null;}else if(p.type==="MemberExpression"){let R=p,w=y(R.object);if(w==null)throw new g(JSON.stringify(E),`Cannot call method on ${w===null?"null":"undefined"}`,c.EXPRESSION_EVALUATION_ERROR);if(!o&&(w===globalThis||typeof window<"u"&&w===window||typeof global<"u"&&w===global||typeof self<"u"&&w===self))throw new g(JSON.stringify(E),"Access to global object is not allowed in expressions",c.EXPRESSION_UNSAFE_ACCESS);if(Array.isArray(w)&&!R.computed&&R.property.type==="Identifier"){let b=R.property.name;de.has(b)?(C=w[b],l=`Array.${b}`,P=w):(l=`${R.object.type==="Identifier"?R.object.name:String(w)}.${b}`,C=w?.[b],P=w);}else {let b="";if(R.object.type==="Identifier"?b=R.object.name:b=String(w),R.computed){let v=y(R.property);l=`${b}[${String(v)}]`,C=w?.[v],P=w;}else {let v=R.property.name;l=`${b}.${v}`,C=w?.[v],P=w;}}}else throw new g(JSON.stringify(E),"Invalid function call: only Identifier and MemberExpression are allowed",c.EXPRESSION_EVALUATION_ERROR);let We=l.startsWith("Array.")&&de.has(l.split(".")[1])||Ke.has(l)||fe.has(l.split(".")[0])||Z[l]!==void 0;if(!o&&!We)throw new g(l,`Function "${l}" is not in whitelist`,c.EXPRESSION_FUNCTION_NOT_WHITELISTED);let Y=m.arguments.map(R=>{if(R.type==="SpreadElement")throw new g(JSON.stringify(E),"Spread operator is not allowed",c.EXPRESSION_EVALUATION_ERROR);return y(R)});if(Z[l])return Z[l](...Y);if(typeof C=="function")try{return P!==null?C.apply(P,Y):C(...Y)}catch(R){let w=R instanceof Error?R.message:String(R);throw new g(l,`Error calling "${l}": ${w}`,c.EXPRESSION_EVALUATION_ERROR)}throw new g(l,`"${l}" is not a function${C===void 0?" (undefined)":C===null?" (null)":""}`,c.EXPRESSION_EVALUATION_ERROR)}case "ArrayExpression":return E.elements.map(p=>{if(p==null)return null;if(p.type==="SpreadElement")throw new g(JSON.stringify(E),"Spread operator is not allowed",c.EXPRESSION_EVALUATION_ERROR);return y(p)});case "ObjectExpression":{let m=E,p={};for(let l of m.properties){if(l.type==="ObjectMethod"||l.type==="SpreadElement")throw new g(JSON.stringify(E),"Object methods and spread are not allowed",c.EXPRESSION_EVALUATION_ERROR);let C=l.key.type==="Identifier"?l.key.name:String(y(l.key));p[C]=y(l.value);}return p}case "TemplateLiteral":{let m=E,p="";for(let l=0;l<m.quasis.length;l++)p+=m.quasis[l].value.cooked,l<m.expressions.length&&(p+=String(y(m.expressions[l])));return p}default:throw new g(JSON.stringify(E),`Unsupported node type: ${E.type}`,c.EXPRESSION_EVALUATION_ERROR)}}return y(e)}function L(e){let n=new Set;function t(r,o=""){switch(r.type){case "Identifier":{let i=r;Ye(i.name)||n.add(i.name);break}case "MemberExpression":{let i=r,a=i.object;if(a.type==="Identifier"){let s=a.name;if(i.computed)n.add(`${s}.*`),t(i.property,o);else {let u=i.property.name;n.add(`${s}.${u}`),n.add(`${s}.*`);}}else t(a,o);break}case "OptionalMemberExpression":{let i=r,a=i.object;if(a.type==="Identifier"){let s=a.name;if(i.computed)n.add(`${s}.*`),t(i.property,o);else {let u=i.property.name;n.add(`${s}.${u}`),n.add(`${s}.*`);}}else t(a,o);break}default:for(let i in r){let a=r[i];a!=null&&(Array.isArray(a)?a.forEach(s=>{s&&typeof s=="object"&&"type"in s&&t(s,o);}):a&&typeof a=="object"&&"type"in a&&t(a,o));}}}return t(e),Array.from(n)}function Ye(e){return new Set(["String","Number","Boolean","BigInt","Symbol","Array","Object","Math","Date","console","JSON","parseInt","parseFloat","isNaN","isFinite"]).has(e)}var ee=new Map,Ze=["constructor","prototype","__proto__"];function et(e){return e.split(".").some(t=>Ze.includes(t))}function Ee(e){if(e.type==="Identifier")return e.name;if(e.type==="MemberExpression"){let n=Ee(e.object);if(!n)return null;if(e.computed){if(e.property.type==="NumericLiteral"){let t=e.property.value;return `${n}.${String(t)}`}if(e.property.type==="StringLiteral"){let t=e.property.value;return `${n}.${String(t)}`}return null}else return e.property.type==="Identifier"?`${n}.${e.property.name}`:null}return null}function ye(e){if(e.type==="NumericLiteral"){let t=e.value;return ()=>t}if(e.type==="StringLiteral"){let t=e.value;return ()=>t}if(e.type==="BooleanLiteral"){let t=e.value;return ()=>t}if(e.type==="NullLiteral")return ()=>null;if(e.type==="Identifier"){let t=e.name;return ["window","document","global","globalThis","self"].includes(t)?null:o=>o._get(t)}let n=Ee(e);if(n){let t=["window","document","global","globalThis","self"],r=n.split(".")[0];return t.includes(r)||et(n)?null:o=>o._get(n)}return null}function te(e,n){if(ee.has(e))return ee.get(e)||null;let t=ye(n);return ee.set(e,t),t}var re={parsed:new Map};function oe(e){if(!e||e.length===0)return [];let n=[],t="",r=0;for(;r<e.length;){let o=e[r];if(o===".")t&&(n.push(ne(t)),t=""),r++;else if(o==="["){t&&(n.push(ne(t)),t="");let i=e.indexOf("]",r);if(i===-1)t+=o,r++;else {let a=e.slice(r+1,i);a===""?n.push(-1):/^\d+$/.test(a)?n.push(parseInt(a,10)):n.push(a),r=i+1,e[r]==="."&&r++;}}else t+=o,r++;}return t&&n.push(ne(t)),n}function ne(e){return /^\d+$/.test(e)?parseInt(e,10):e}function $(e){if(!e||e.length===0)return [];let n=re.parsed.get(e);if(n)return n;let t=oe(e);return re.parsed.set(e,t),t}function ge(){re.parsed.clear();}function ie(e){return e.map(String).join(".")}function M(e,n){let t=typeof n=="string"?$(n):n;if(t.length===0)return e;let r=e;for(let o of t){if(r==null)return;if(typeof o=="number"){if(!Array.isArray(r))return;r=r[o];}else {if(typeof r!="object")return;r=r[o];}}return r}function J(e,n,t,r={}){let{createIntermediate:o=true,createObject:i=()=>({}),createArray:a=()=>[]}=r,s=typeof n=="string"?$(n):n;if(s.length===0)return false;let u=s[s.length-1],h=s.slice(0,-1),f=e;for(let S=0;S<h.length;S++){let y=h[S],k=typeof(h[S+1]??u)=="number";if(typeof y=="number"){if(!Array.isArray(f))return false;for(;f.length<=y;)f.push(void 0);if(f[y]==null||typeof f[y]!="object"){if(!o)return false;f[y]=k?a():i();}f=f[y];}else {if(typeof f!="object"||f===null)return false;let m=f;if(m[y]==null||typeof m[y]!="object"){if(!o)return false;m[y]=k?a():i();}f=m[y];}}if(typeof u=="number"){if(!Array.isArray(f))return false;for(;f.length<=u;)f.push(void 0);f[u]=t;}else {if(typeof f!="object"||f===null)return false;f[u]=t;}return true}function D(e,n){if(e===n||n.startsWith(e+"."))return true;if(e.includes("*")){let t=e.split(".*")[0];return n.startsWith(t+".")||n===t}return !!e.startsWith(n+".")}function Se(e){let n=$(e);return n.length<=1?"":ie(n.slice(0,-1))}function xe(e){let n=$(e);return n[n.length-1]}var Ae=new WeakMap,se={maxSize:100};function V(e){let n=Ae.get(e);return n||(n=new Map,Ae.set(e,n)),n}function tt(e,n){return e.dependencies.every(t=>{if(t.includes("*")){let r=t.split(".*")[0];return n._get(r)!=null}return n._get(t)!==void 0})}function nt(e){let n=null,t=1/0;for(let[r,o]of e.entries())o.timestamp<t&&(t=o.timestamp,n=r);n&&e.delete(n);}function z(e,n){let t=V(n),r=t.get(e);return r?tt(r,n)?(r.timestamp=Date.now(),r.result):(t.delete(e),null):null}function U(e,n,t,r){let o=V(r);o.size>=se.maxSize&&nt(o),o.set(e,{expr:e,result:n,dependencies:t,timestamp:Date.now()});}function x(e,n){let t=V(n),r=[];for(let[o,i]of t.entries())i.dependencies.some(s=>D(s,e)||D(e,s))&&r.push(o);for(let o of r)t.delete(o);}function we(e){V(e).clear();}function Re(e){let n=V(e);return {size:n.size,expressions:Array.from(n.keys())}}function A(e,n,t={}){try{let r={...n.$exprOptions,...t},o=z(e,n);if(o!==null)return o;let i=B(e);F(i,{allowGlobals:r.allowGlobals,maxNestingDepth:r.maxNestingDepth});let a=te(e,i);if(a){let h=a(n),f=L(i);return U(e,h,f,n),h}let s=q(i,n,r),u=L(i);return U(e,s,u,n),s}catch(r){if(r instanceof g)throw r;let o=r instanceof Error?r.message:String(r);throw new g(e,`Expression evaluation failed: ${o}`,c.EXPRESSION_EVALUATION_ERROR,{metadata:{originalError:r instanceof Error?r.name:"Unknown",stack:r instanceof Error?r.stack?.split(`
|
|
7
|
-
`).slice(0,5):void 0}})}}async function Ce(e,n){let{path:t,value:r}=n;if(!t||typeof t!="string")throw new
|
|
8
|
-
`).slice(0,5):void 0}})}}}async function Te(e,n){let{cond:t,then:r,else:o}=n;if(!t||typeof t!="string")throw new d(n,'if action requires "cond" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"cond"}});let i=K(t);A(i,e)?r&&Array.isArray(r)&&await T(r,e):o&&Array.isArray(o)&&await T(o,e);}var le=class{pool=[];maxSize;constructor(n=10){this.maxSize=n;}acquire(){return this.pool.length>0?this.pool.pop():{}}release(n){"$item"in n&&delete n.$item,"$index"in n&&delete n.$index;let t=[];for(let r in n)!r.startsWith("$")&&!r.startsWith("_")&&t.push(r);for(let r of t)delete n[r];this.pool.length<this.maxSize&&this.pool.push(n);}clear(){this.pool.length=0;}get size(){return this.pool.length}},ae=null;function ce(){return ae||(ae=new le),ae}function X(e,n,t){let o=ce().acquire(),i=Object.create(e);return Object.assign(i,o),i.$item=n,i.$index=t,i}function G(e){ce().release(e);}async function Oe(e,n){let{var:t,in:r,body:o}=n;if(!t||typeof t!="string")throw new d(n,'loop action requires "var" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"var"}});if(!r||typeof r!="string")throw new d(n,'loop action requires "in" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"in"}});if(!o||!Array.isArray(o))throw new d(n,'loop action requires "body" parameter (array of actions)',c.ACTION_MISSING_PARAM,{metadata:{param:"body"}});let i=A(r,e);if(i!=null)if(Array.isArray(i))for(let a=0;a<i.length;a++){let s=X(e,i[a],a);s[t]=i[a];try{x(t,s),await T(o,s);}finally{G(s);}}else if(typeof i=="object"&&i!==null){let a=Object.entries(i);for(let s=0;s<a.length;s++){let[,u]=a[s],h=X(e,u,s);h[t]=u;try{x(t,h),await T(o,h);}finally{G(h);}}}else throw new d(n,`loop "in" expression must evaluate to an array or object, got ${typeof i}`,c.ACTION_INVALID_PARAM,{metadata:{param:"in",actualType:typeof i}})}async function Ie(e,n){let t=n.method,r=n.params,o=n.resultTo;if(!t||typeof t!="string")throw new d(n,'call action requires "method" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"method"}});let i=e.$methods[t];if(!i)throw new N(t,`Method "${t}" not found in $methods`,void 0,{metadata:{method:t}});let a=r??{};try{if(typeof r=="string"&&r.startsWith("{{")&&r.endsWith("}}")){let u=r.slice(2,-2).trim();a=A(u,e);}else if(r!=null&&typeof r=="object"&&!Array.isArray(r)){let u={};for(let[h,f]of Object.entries(r))if(typeof f=="string"&&f.startsWith("{{")&&f.endsWith("}}")){let S=f.slice(2,-2).trim();u[h]=A(S,e);}else u[h]=f;a=u;}let s=await i(e,a);return o&&(e._set(o,s),x(o,e)),s}catch(s){if(s instanceof N)throw s;let u=s instanceof Error?s.message:String(s),h=s instanceof Error?s:void 0;throw new N(t,`Service call failed: ${u}`,h,{metadata:{method:t,params:a}})}}async function Pe(e,n){let{actions:t}=n;if(!t||!Array.isArray(t))throw new d(n,'batch action requires "actions" parameter (array)',c.ACTION_MISSING_PARAM,{metadata:{param:"actions"}});let r=[];for(let o of t)try{await T([o],e);}catch(i){r.push({action:o,error:i instanceof Error?i:new Error(String(i))});}if(r.length>0)throw new _(r,`${r.length} actions failed in batch`,{metadata:{failedCount:r.length,totalCount:t.length}})}async function _e(e,n){let{to:t}=n;if(!t||typeof t!="string")throw new d(n,'navigate action requires "to" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"to"}});let r=t;if(t.startsWith("{{")&&t.endsWith("}}")){let i=t.slice(2,-2).trim(),a=A(i,e);if(typeof a!="string")throw new d(n,`navigate "to" expression must evaluate to a string, got ${typeof a}`,c.ACTION_INVALID_PARAM,{metadata:{param:"to",actualType:typeof a}});r=a;}let o=e.$methods.navigate||e.$methods.$navigate;if(o)await o(e,{to:r});else if(typeof window<"u"&&window.location)window.location.href=r;else throw new d(n,"navigate method not registered and window.location is not available",c.ACTION_EXECUTION_ERROR,{metadata:{reason:"navigate_not_available"}})}async function Me(e,n){let{level:t="info",message:r}=n;if(!r)throw new d(n,'log action requires "message" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"message"}});let o=r;if(typeof r=="string"&&r.startsWith("{{")&&r.endsWith("}}")){let s=r.slice(2,-2).trim();o=A(s,e);}let i=String(t).toLowerCase(),a=String(o);if(typeof console<"u")switch(i){case "error":console.error("[Vario]",a);break;case "warn":console.warn("[Vario]",a);break;default:console.log("[Vario]",a);break}}function I(e,n){if(typeof e=="string"){if(e.startsWith("{{")&&e.endsWith("}}")){let t=e.slice(2,-2).trim();return A(t,n)}return e}if(Array.isArray(e))return e.map(t=>I(t,n));if(e&&typeof e=="object"){let t={};for(let[r,o]of Object.entries(e))t[r]=I(o,n);return t}return e}async function ke(e,n){let{path:t,value:r,items:o}=n;if(!t||typeof t!="string")throw new d(n,'push action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let i=e._get(t);if(!Array.isArray(i))throw new d(n,`Path "${t}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:t,actualType:typeof i}});let a=o!==void 0?o:r;if(a===void 0)throw new d(n,'push action requires "value" or "items" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"value|items"}});let s=I(a,e);Array.isArray(s)?i.push(...s):i.push(s),x(t,e),x(`${t}.*`,e);}async function ve(e,n){let{path:t}=n;if(!t||typeof t!="string")throw new d(n,'pop action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let r=e._get(t);if(!Array.isArray(r))throw new d(n,`Path "${t}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:t,actualType:typeof r}});r.pop(),x(t,e),x(`${t}.*`,e);}async function $e(e,n){let{path:t}=n;if(!t||typeof t!="string")throw new d(n,'shift action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let r=e._get(t);if(!Array.isArray(r))throw new d(n,`Path "${t}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:t,actualType:typeof r}});r.shift(),x(t,e),x(`${t}.*`,e);}async function je(e,n){let{path:t,value:r,items:o}=n;if(!t||typeof t!="string")throw new d(n,'unshift action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let i=e._get(t);if(!Array.isArray(i))throw new d(n,`Path "${t}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:t,actualType:typeof i}});let a=o!==void 0?o:r;if(a===void 0)throw new d(n,'unshift action requires "value" or "items" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"value|items"}});let s=I(a,e);Array.isArray(s)?i.unshift(...s):i.unshift(s),x(t,e),x(`${t}.*`,e);}async function Le(e,n){let{path:t,start:r,deleteCount:o=0,items:i}=n;if(!t||typeof t!="string")throw new d(n,'splice action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let a=e._get(t);if(!Array.isArray(a))throw new d(n,`Path "${t}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:t,actualType:typeof a}});let s;if(typeof r=="string"&&r.startsWith("{{")&&r.endsWith("}}")){let f=r.slice(2,-2).trim();s=Number(A(f,e));}else s=Number(r);let u;if(typeof o=="string"&&o.startsWith("{{")&&o.endsWith("}}")){let f=o.slice(2,-2).trim();u=Number(A(f,e));}else u=Number(o);let h=[];if(i!=null){let f=I(i,e);Array.isArray(f)?h=f:h=[f];}a.splice(s,u,...h),x(t,e),x(`${t}.*`,e);}var rt={set:Ce,emit:be,navigate:_e,log:Me,if:Te,loop:Oe,call:Ie,batch:Pe,push:ke,pop:ve,shift:$e,unshift:je,splice:Le};function Q(e){for(let[n,t]of Object.entries(rt))n in e.$methods||(e.$methods[n]=t);}function De(e={},n={}){ot(e);let{onEmit:t,methods:r={},onStateChange:o,createObject:i=()=>({}),createArray:a=()=>[],exprOptions:s}=n,u=null,h={...e,$emit:(S,y)=>{t&&t(S,y);},$methods:r,$exprOptions:s,_get:S=>M(h,S),_set:(S,y,E)=>{J(h,S,y,{createObject:i,createArray:a}),x(S,u||h),o&&!E?.skipCallback&&o(S,y,u||h);}};Q(h);let f=W(h);return u=f,f}function ot(e){for(let n in e)if(n.startsWith("$")||n.startsWith("_"))throw new Error(`Property name "${n}" conflicts with system API. Properties starting with "$" or "_" are reserved. Use a different name.`)}function j(e,n,t="."){function r(o,i,a,s){if(!(!o||typeof o!="object"||n(o,i,a,s)===false)&&o.children){if(Array.isArray(o.children))o.children.forEach((h,f)=>{if(h&&typeof h=="object"){let S=i?`${i}${t}children${t}${f}`:`children${t}${f}`;r(h,S,a+1,o);}});else if(typeof o.children=="object"){let h=i?`${i}${t}children`:"children";r(o.children,h,a+1,o);}}}r(e,"",0,null);}function Ve(e,n={}){let t={nodeCount:0,maxDepth:0},r=new Map,o=n.buildPathMap?new Map:void 0;return j(e,(i,a,s)=>{t.nodeCount++,s>t.maxDepth&&(t.maxDepth=s);let u=i;u.id&&typeof u.id=="string"&&r.set(u.id,a),o&&o.set(a,i),n.onNode?.(i,a,s);}),{stats:t,index:{idMap:r,pathMap:o}}}function Ue(e,n){let t=[];return j(e,(r,o)=>{n(r)&&t.push({node:r,path:o});}),t}function pe(e,n){let t=null;return j(e,(r,o)=>{if(n(r))return t={node:r,path:o},false}),t}function Xe(e,n){return pe(e,r=>r.id===n)?.path||null}function Ge(e){let{schema:n,index:t}=e;return {findById:i=>{if(t?.idMap){let a=t.idMap.get(i);if(!a)return null;if(t.pathMap){let u=t.pathMap.get(a);return u?{node:u,path:a}:null}let s=M(n,a);return s?{node:s,path:a}:null}return null},getParent:i=>{if(!i||!i.includes("."))return null;let a=i;for(;;){let s=a.lastIndexOf(".");if(s===-1)return {node:n,path:""};a=a.substring(0,s);let u=a.split(".").pop();if(u&&["children","definitions","items"].includes(u))continue;let h=M(n,a);if(!(Array.isArray(h)||typeof h=="string")&&h&&typeof h=="object")return {node:h,path:a}}}}}export{d as ActionError,_ as BatchError,c as ErrorCodes,g as ExpressionError,N as ServiceError,O as VarioError,Ve as analyzeSchema,we as clearCache,ge as clearPathCache,me as createExpressionSandbox,X as createLoopContext,W as createProxy,Ge as createQueryEngine,De as createRuntimeContext,A as evaluate,q as evaluateExpression,T as execute,L as extractDependencies,K as extractExpression,pe as findNode,Ue as findNodes,Xe as findPathById,Re as getCacheStats,z as getCachedExpression,xe as getLastSegment,Se as getParentPath,M as getPathValue,x as invalidateCache,H as isSafePropertyAccess,D as matchPath,B as parseExpression,oe as parsePath,$ as parsePathCached,Q as registerBuiltinMethods,G as releaseLoopContext,U as setCachedExpression,J as setPathValue,ie as stringifyPath,j as traverseSchema,F as validateAST};//# sourceMappingURL=index.js.map
|
|
6
|
+
`)}`,c.EXPRESSION_VALIDATION_ERROR,{metadata:{errors:o,nodeType:e.type}})}function me(e){return {...e}}function H(e,n,t={}){return !(!(t.allowGlobals??n.$exprOptions?.allowGlobals??false)&&["window","document","global","globalThis","self"].includes(e))}var fe=new Set(["String","Number","Boolean","BigInt","Symbol","Array","Object","Math","Date"]),Ke=new Set(["Array.isArray","Object.is","Number.isFinite","Number.isInteger","Number.isNaN","Number.isSafeInteger","Math.abs","Math.round","Math.floor","Math.ceil","Math.random","Math.max","Math.min","Date.now"]),de=new Set(["slice","concat","filter","map","flat","flatMap","toReversed","toSorted","toSpliced","with","indexOf","lastIndexOf","includes","find","findIndex","findLast","findLastIndex","every","some","at","join","toString","toLocaleString","reverse","sort"]),Qe=new Set(["constructor","prototype","__proto__"]);function he(e){return typeof e=="string"&&Qe.has(e)}var Z={$truncate:(e,n)=>{if(typeof e!="string")return e;let t=typeof n=="number"?n:0;return e.length>t?e.slice(0,t)+"...":e},$format:(e,n)=>(typeof e=="number"?new Date(e):e).toISOString()};function q(e,n,t={}){let r={...n.$exprOptions,...t},o=r.allowGlobals===true,i=r.maxSteps??1e3,a=r.timeout??100,s=0,u=Date.now();function d(E){if(o)return E==="globalThis"?globalThis:E==="window"&&typeof window<"u"?window:E==="document"&&typeof document<"u"?document:E==="global"&&typeof global<"u"?global:E==="self"&&typeof self<"u"?self:globalThis[E]}function f(E){return ["window","document","global","globalThis","self"].includes(E)}function S(){if(s++,s>i)throw new y(JSON.stringify(e),`Expression evaluation exceeded max steps (${i})`,c.EXPRESSION_MAX_STEPS_EXCEEDED,{metadata:{maxSteps:i,currentSteps:s}});if(Date.now()-u>a)throw new y(JSON.stringify(e),`Expression evaluation exceeded timeout (${a}ms)`,c.EXPRESSION_TIMEOUT,{metadata:{timeout:a,elapsedTime:Date.now()-u}})}function g(E){switch(S(),E.type){case "NumericLiteral":case "StringLiteral":case "BooleanLiteral":case "BigIntLiteral":case "DecimalLiteral":case "RegExpLiteral":return E.value;case "NullLiteral":return null;case "Literal":{let m=E;return "value"in m&&m.value!==void 0?m.value:m.type==="NullLiteral"?null:m.value??void 0}case "Identifier":{let m=E.name;if(f(m)&&!o)throw new y(m,`Access to global "${m}" is not allowed in expressions`,c.EXPRESSION_UNSAFE_ACCESS);if(m in n&&!f(m))return n[m];if(o){let p=d(m);if(p!==void 0)return p}return fe.has(m)?globalThis[m]:void 0}case "MemberExpression":{let m=E,p=g(m.object);if(p==null)return;if(!o&&(p===globalThis||typeof window<"u"&&p===window||typeof global<"u"&&p===global||typeof self<"u"&&p===self))throw new y(JSON.stringify(E),"Access to global object is not allowed in expressions",c.EXPRESSION_UNSAFE_ACCESS);let l;if(m.computed?l=g(m.property):l=m.property.name,!o&&he(l))throw new y(String(l),`Access to "${l}" is not allowed in expressions`,c.EXPRESSION_UNSAFE_ACCESS);return p[l]}case "OptionalMemberExpression":{let m=E,p=g(m.object);if(p==null)return;if(!o&&(p===globalThis||typeof window<"u"&&p===window||typeof global<"u"&&p===global||typeof self<"u"&&p===self))throw new y(JSON.stringify(E),"Access to global object is not allowed in expressions",c.EXPRESSION_UNSAFE_ACCESS);let l;if(m.computed?l=g(m.property):l=m.property.name,!o&&he(l))throw new y(String(l),`Access to "${l}" is not allowed in expressions`,c.EXPRESSION_UNSAFE_ACCESS);return p?.[l]}case "BinaryExpression":{let m=E,p=g(m.left),l=g(m.right),C=m.operator;switch(C){case "+":return p+l;case "-":return p-l;case "*":return p*l;case "/":return p/l;case "%":return p%l;case "**":return p**l;case "==":return p==l;case "!=":return p!=l;case "===":return p===l;case "!==":return p!==l;case "<":return p<l;case "<=":return p<=l;case ">":return p>l;case ">=":return p>=l;case "<<":return p<<l;case ">>":return p>>l;case ">>>":return p>>>l;case "&":return p&l;case "|":return p|l;case "^":return p^l;case "in":return p in l;case "instanceof":{if(typeof l!="function"&&typeof l!="object")throw new y(JSON.stringify(E),"Right-hand side of instanceof must be a constructor",c.EXPRESSION_EVALUATION_ERROR);return p instanceof l}default:throw new y(JSON.stringify(E),`Unsupported binary operator: ${C}`,c.EXPRESSION_EVALUATION_ERROR)}}case "LogicalExpression":{let m=E,p=g(m.left),l=m.operator;if(l==="&&")return p&&g(m.right);if(l==="||")return p||g(m.right);if(l==="??")return p??g(m.right);throw new y(JSON.stringify(E),`Unsupported logical operator: ${l}`,c.EXPRESSION_EVALUATION_ERROR)}case "UnaryExpression":{let m=E,p=g(m.argument),l=m.operator;switch(l){case "+":return +p;case "-":return -p;case "!":return !p;case "~":return ~p;case "typeof":return typeof p;case "void":return;case "delete":throw new y(JSON.stringify(E),"delete operator is not allowed",c.EXPRESSION_EVALUATION_ERROR);default:throw new y(JSON.stringify(E),`Unsupported unary operator: ${l}`,c.EXPRESSION_EVALUATION_ERROR)}}case "ConditionalExpression":{let m=E,p=g(m.test);return g(p?m.consequent:m.alternate)}case "CallExpression":{let m=E,p=m.callee,l,C,P=null;if(p.type==="Identifier"){if(l=p.name,!H(l,n,{allowGlobals:o}))throw new y(l,`Access to global "${l}" is not allowed in expressions`,"UNSAFE_ACCESS");C=n[l]??globalThis[l],P=null;}else if(p.type==="MemberExpression"){let R=p,w=g(R.object);if(w==null)throw new y(JSON.stringify(E),`Cannot call method on ${w===null?"null":"undefined"}`,c.EXPRESSION_EVALUATION_ERROR);if(!o&&(w===globalThis||typeof window<"u"&&w===window||typeof global<"u"&&w===global||typeof self<"u"&&w===self))throw new y(JSON.stringify(E),"Access to global object is not allowed in expressions",c.EXPRESSION_UNSAFE_ACCESS);if(Array.isArray(w)&&!R.computed&&R.property.type==="Identifier"){let b=R.property.name;de.has(b)?(C=w[b],l=`Array.${b}`,P=w):(l=`${R.object.type==="Identifier"?R.object.name:String(w)}.${b}`,C=w?.[b],P=w);}else {let b="";if(R.object.type==="Identifier"?b=R.object.name:b=String(w),R.computed){let M=g(R.property);l=`${b}[${String(M)}]`,C=w?.[M],P=w;}else {let M=R.property.name;l=`${b}.${M}`,C=w?.[M],P=w;}}}else throw new y(JSON.stringify(E),"Invalid function call: only Identifier and MemberExpression are allowed",c.EXPRESSION_EVALUATION_ERROR);let We=l.startsWith("Array.")&&de.has(l.split(".")[1])||Ke.has(l)||fe.has(l.split(".")[0])||Z[l]!==void 0;if(!o&&!We)throw new y(l,`Function "${l}" is not in whitelist`,c.EXPRESSION_FUNCTION_NOT_WHITELISTED);let Y=m.arguments.map(R=>{if(R.type==="SpreadElement")throw new y(JSON.stringify(E),"Spread operator is not allowed",c.EXPRESSION_EVALUATION_ERROR);return g(R)});if(Z[l])return Z[l](...Y);if(typeof C=="function")try{return P!==null?C.apply(P,Y):C(...Y)}catch(R){let w=R instanceof Error?R.message:String(R);throw new y(l,`Error calling "${l}": ${w}`,c.EXPRESSION_EVALUATION_ERROR)}throw new y(l,`"${l}" is not a function${C===void 0?" (undefined)":C===null?" (null)":""}`,c.EXPRESSION_EVALUATION_ERROR)}case "ArrayExpression":return E.elements.map(p=>{if(p==null)return null;if(p.type==="SpreadElement")throw new y(JSON.stringify(E),"Spread operator is not allowed",c.EXPRESSION_EVALUATION_ERROR);return g(p)});case "ObjectExpression":{let m=E,p={};for(let l of m.properties){if(l.type==="ObjectMethod"||l.type==="SpreadElement")throw new y(JSON.stringify(E),"Object methods and spread are not allowed",c.EXPRESSION_EVALUATION_ERROR);let C=l.key.type==="Identifier"?l.key.name:String(g(l.key));p[C]=g(l.value);}return p}case "TemplateLiteral":{let m=E,p="";for(let l=0;l<m.quasis.length;l++)p+=m.quasis[l].value.cooked,l<m.expressions.length&&(p+=String(g(m.expressions[l])));return p}default:throw new y(JSON.stringify(E),`Unsupported node type: ${E.type}`,c.EXPRESSION_EVALUATION_ERROR)}}return g(e)}function L(e){let n=new Set;function t(r,o=""){switch(r.type){case "Identifier":{let i=r;Ye(i.name)||n.add(i.name);break}case "MemberExpression":{let i=r,a=i.object;if(a.type==="Identifier"){let s=a.name;if(i.computed)n.add(`${s}.*`),t(i.property,o);else {let u=i.property.name;n.add(`${s}.${u}`),n.add(`${s}.*`);}}else t(a,o);break}case "OptionalMemberExpression":{let i=r,a=i.object;if(a.type==="Identifier"){let s=a.name;if(i.computed)n.add(`${s}.*`),t(i.property,o);else {let u=i.property.name;n.add(`${s}.${u}`),n.add(`${s}.*`);}}else t(a,o);break}default:for(let i in r){let a=r[i];a!=null&&(Array.isArray(a)?a.forEach(s=>{s&&typeof s=="object"&&"type"in s&&t(s,o);}):a&&typeof a=="object"&&"type"in a&&t(a,o));}}}return t(e),Array.from(n)}function Ye(e){return new Set(["String","Number","Boolean","BigInt","Symbol","Array","Object","Math","Date","console","JSON","parseInt","parseFloat","isNaN","isFinite"]).has(e)}var ee=new Map,Ze=["constructor","prototype","__proto__"];function et(e){return e.split(".").some(t=>Ze.includes(t))}function Ee(e){if(e.type==="Identifier")return e.name;if(e.type==="MemberExpression"){let n=Ee(e.object);if(!n)return null;if(e.computed){if(e.property.type==="NumericLiteral"){let t=e.property.value;return `${n}.${String(t)}`}if(e.property.type==="StringLiteral"){let t=e.property.value;return `${n}.${String(t)}`}return null}else return e.property.type==="Identifier"?`${n}.${e.property.name}`:null}return null}function ge(e){if(e.type==="NumericLiteral"){let t=e.value;return ()=>t}if(e.type==="StringLiteral"){let t=e.value;return ()=>t}if(e.type==="BooleanLiteral"){let t=e.value;return ()=>t}if(e.type==="NullLiteral")return ()=>null;if(e.type==="Identifier"){let t=e.name;return ["window","document","global","globalThis","self"].includes(t)?null:o=>o._get(t)}let n=Ee(e);if(n){let t=["window","document","global","globalThis","self"],r=n.split(".")[0];return t.includes(r)||et(n)?null:o=>o._get(n)}return null}function te(e,n){if(ee.has(e))return ee.get(e)||null;let t=ge(n);return ee.set(e,t),t}var re={parsed:new Map};function oe(e){if(!e||e.length===0)return [];let n=[],t="",r=0;for(;r<e.length;){let o=e[r];if(o===".")t&&(n.push(ne(t)),t=""),r++;else if(o==="["){t&&(n.push(ne(t)),t="");let i=e.indexOf("]",r);if(i===-1)t+=o,r++;else {let a=e.slice(r+1,i);a===""?n.push(-1):/^\d+$/.test(a)?n.push(parseInt(a,10)):n.push(a),r=i+1,e[r]==="."&&r++;}}else t+=o,r++;}return t&&n.push(ne(t)),n}function ne(e){return /^\d+$/.test(e)?parseInt(e,10):e}function $(e){if(!e||e.length===0)return [];let n=re.parsed.get(e);if(n)return n;let t=oe(e);return re.parsed.set(e,t),t}function ye(){re.parsed.clear();}function ie(e){return e.map(String).join(".")}function v(e,n){let t=typeof n=="string"?$(n):n;if(t.length===0)return e;let r=e;for(let o of t){if(r==null)return;if(typeof o=="number"){if(!Array.isArray(r))return;r=r[o];}else {if(typeof r!="object")return;r=r[o];}}return r}function J(e,n,t,r={}){let{createIntermediate:o=true,createObject:i=()=>({}),createArray:a=()=>[]}=r,s=typeof n=="string"?$(n):n;if(s.length===0)return false;let u=s[s.length-1],d=s.slice(0,-1),f=e;for(let S=0;S<d.length;S++){let g=d[S],k=typeof(d[S+1]??u)=="number";if(typeof g=="number"){if(!Array.isArray(f))return false;for(;f.length<=g;)f.push(void 0);if(f[g]==null||typeof f[g]!="object"){if(!o)return false;f[g]=k?a():i();}f=f[g];}else {if(typeof f!="object"||f===null)return false;let m=f;if(m[g]==null||typeof m[g]!="object"){if(!o)return false;m[g]=k?a():i();}f=m[g];}}if(typeof u=="number"){if(!Array.isArray(f))return false;for(;f.length<=u;)f.push(void 0);f[u]=t;}else {if(typeof f!="object"||f===null)return false;f[u]=t;}return true}function D(e,n){if(e===n||n.startsWith(e+"."))return true;if(e.includes("*")){let t=e.split(".*")[0];return n.startsWith(t+".")||n===t}return !!e.startsWith(n+".")}function Se(e){let n=$(e);return n.length<=1?"":ie(n.slice(0,-1))}function xe(e){let n=$(e);return n[n.length-1]}var Ae=new WeakMap,se={maxSize:100};function V(e){let n=Ae.get(e);return n||(n=new Map,Ae.set(e,n)),n}function tt(e,n){return e.dependencies.every(t=>{if(t.includes("*")){let r=t.split(".*")[0];return n._get(r)!=null}return n._get(t)!==void 0})}function nt(e){let n=null,t=1/0;for(let[r,o]of e.entries())o.timestamp<t&&(t=o.timestamp,n=r);n&&e.delete(n);}function z(e,n){let t=V(n),r=t.get(e);return r?tt(r,n)?(r.timestamp=Date.now(),r.result):(t.delete(e),null):null}function U(e,n,t,r){let o=V(r);o.size>=se.maxSize&&nt(o),o.set(e,{expr:e,result:n,dependencies:t,timestamp:Date.now()});}function x(e,n){let t=V(n),r=[];for(let[o,i]of t.entries())i.dependencies.some(s=>D(s,e)||D(e,s))&&r.push(o);for(let o of r)t.delete(o);}function we(e){V(e).clear();}function Re(e){let n=V(e);return {size:n.size,expressions:Array.from(n.keys())}}function A(e,n,t={}){try{let r={...n.$exprOptions,...t},o=z(e,n);if(o!==null)return o;let i=B(e);F(i,{allowGlobals:r.allowGlobals,maxNestingDepth:r.maxNestingDepth});let a=te(e,i);if(a){let d=a(n),f=L(i);return U(e,d,f,n),d}let s=q(i,n,r),u=L(i);return U(e,s,u,n),s}catch(r){if(r instanceof y)throw r;let o=r instanceof Error?r.message:String(r);throw new y(e,`Expression evaluation failed: ${o}`,c.EXPRESSION_EVALUATION_ERROR,{metadata:{originalError:r instanceof Error?r.name:"Unknown",stack:r instanceof Error?r.stack?.split(`
|
|
7
|
+
`).slice(0,5):void 0}})}}async function Ce(e,n){let{path:t,value:r}=n;if(!t||typeof t!="string")throw new h(n,'set action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let o=r;if(typeof r=="string"&&r.startsWith("{{")&&r.endsWith("}}")){let i=r.slice(2,-2).trim();o=A(i,e);}e._set(t,o);}async function be(e,n){let{event:t,data:r}=n;if(!t||typeof t!="string")throw new h(n,'emit action requires "event" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"event"}});let o=r;if(typeof r=="string"&&r.startsWith("{{")&&r.endsWith("}}")){let i=r.slice(2,-2).trim();o=A(i,e);}e.$emit(t,o);}function K(e){return typeof e!="string"?String(e):e.startsWith("{{")&&e.endsWith("}}")?e.slice(2,-2).trim():e.trim()}async function T(e,n,t={}){let r=t.timeout??5e3,o=t.maxSteps??1e4,i=Date.now(),a=0,s=null;if(typeof AbortController<"u"){s=new AbortController;let u=setTimeout(()=>{s?.abort();},r),d=()=>clearTimeout(u);try{await Ne(e,n,s.signal,o,()=>{if(a++,a>o)throw new h(e[e.length-1]||{type:"unknown"},`Action execution exceeded max steps (${o})`,c.ACTION_MAX_STEPS_EXCEEDED,{metadata:{maxSteps:o,currentSteps:a}});if(Date.now()-i>r)throw new h(e[e.length-1]||{type:"unknown"},`Action execution exceeded timeout (${r}ms)`,c.ACTION_TIMEOUT,{metadata:{timeout:r,elapsedTime:Date.now()-i}})}),d();}catch(f){throw d(),f}}else await Ne(e,n,null,o,()=>{if(a++,a>o)throw new h(e[e.length-1]||{type:"unknown"},`Action execution exceeded max steps (${o})`,c.ACTION_MAX_STEPS_EXCEEDED,{metadata:{maxSteps:o,currentSteps:a}});if(Date.now()-i>r)throw new h(e[e.length-1]||{type:"unknown"},`Action execution exceeded timeout (${r}ms)`,c.ACTION_TIMEOUT,{metadata:{timeout:r,elapsedTime:Date.now()-i}})});if(Date.now()-i>r)throw new h(e[e.length-1]||{type:"unknown"},`Action execution exceeded timeout (${r}ms)`,c.ACTION_TIMEOUT,{metadata:{timeout:r,elapsedTime:Date.now()-i,actionCount:e.length}})}async function Ne(e,n,t,r,o){for(let i of e){if(t?.aborted)throw new h(i,"Action execution was aborted",c.ACTION_ABORTED);o();let a=n.$methods[i.type];if(!a)throw new h(i,`Unknown action type: ${i.type}. Make sure the action is registered in $methods`,c.ACTION_UNKNOWN_TYPE);try{await a(n,i);}catch(s){if(s instanceof h||s instanceof N)throw s;let u=s instanceof Error?s.message:String(s);throw new h(i,`Action execution failed: ${u}`,c.ACTION_EXECUTION_ERROR,{metadata:{originalError:s instanceof Error?s.name:"Unknown",stack:s instanceof Error?s.stack?.split(`
|
|
8
|
+
`).slice(0,5):void 0}})}}}async function Te(e,n){let{cond:t,then:r,else:o}=n;if(!t||typeof t!="string")throw new h(n,'if action requires "cond" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"cond"}});let i=K(t);A(i,e)?r&&Array.isArray(r)&&await T(r,e):o&&Array.isArray(o)&&await T(o,e);}var le=class{pool=[];maxSize;constructor(n=10){this.maxSize=n;}acquire(){return this.pool.length>0?this.pool.pop():{}}release(n){"$item"in n&&delete n.$item,"$index"in n&&delete n.$index;let t=[];for(let r in n)!r.startsWith("$")&&!r.startsWith("_")&&t.push(r);for(let r of t)delete n[r];this.pool.length<this.maxSize&&this.pool.push(n);}clear(){this.pool.length=0;}get size(){return this.pool.length}},ae=null;function ce(){return ae||(ae=new le),ae}function X(e,n,t){let o=ce().acquire(),i=Object.create(e);return Object.assign(i,o),i.$item=n,i.$index=t,i}function G(e){ce().release(e);}async function Ie(e,n){let{var:t,in:r,body:o}=n;if(!t||typeof t!="string")throw new h(n,'loop action requires "var" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"var"}});if(!r||typeof r!="string")throw new h(n,'loop action requires "in" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"in"}});if(!o||!Array.isArray(o))throw new h(n,'loop action requires "body" parameter (array of actions)',c.ACTION_MISSING_PARAM,{metadata:{param:"body"}});let i=A(r,e);if(i!=null)if(Array.isArray(i))for(let a=0;a<i.length;a++){let s=X(e,i[a],a);s[t]=i[a];try{x(t,s),await T(o,s);}finally{G(s);}}else if(typeof i=="object"&&i!==null){let a=Object.entries(i);for(let s=0;s<a.length;s++){let[,u]=a[s],d=X(e,u,s);d[t]=u;try{x(t,d),await T(o,d);}finally{G(d);}}}else throw new h(n,`loop "in" expression must evaluate to an array or object, got ${typeof i}`,c.ACTION_INVALID_PARAM,{metadata:{param:"in",actualType:typeof i}})}async function Oe(e,n){let{method:t,params:r,resultTo:o}=n;if(!t||typeof t!="string")throw new h(n,'call action requires "method" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"method"}});let i=e.$methods[t];if(!i)throw new N(t,`Method "${t}" not found in $methods`,void 0,{metadata:{method:t}});let a;try{if(r==null)a={};else if(typeof r=="string"&&r.startsWith("{{")&&r.endsWith("}}")){let u=r.slice(2,-2).trim();a=A(u,e);}else if(Array.isArray(r)){let u=[];for(let d of r)if(typeof d=="string"&&d.startsWith("{{")&&d.endsWith("}}")){let f=d.slice(2,-2).trim();u.push(A(f,e));}else u.push(d);a=u;}else if(typeof r=="object"){let u={};for(let[d,f]of Object.entries(r))if(typeof f=="string"&&f.startsWith("{{")&&f.endsWith("}}")){let S=f.slice(2,-2).trim();u[d]=A(S,e);}else u[d]=f;a=u;}else a=r;let s=await i(e,a);return o&&(e._set(o,s),x(o,e)),s}catch(s){if(s instanceof N)throw s;let u=s instanceof Error?s.message:String(s),d=s instanceof Error?s:void 0;throw new N(t,`Service call failed: ${u}`,d,{metadata:{method:t,params:a}})}}async function Pe(e,n){let{actions:t}=n;if(!t||!Array.isArray(t))throw new h(n,'batch action requires "actions" parameter (array)',c.ACTION_MISSING_PARAM,{metadata:{param:"actions"}});let r=[];for(let o of t)try{await T([o],e);}catch(i){r.push({action:o,error:i instanceof Error?i:new Error(String(i))});}if(r.length>0)throw new _(r,`${r.length} actions failed in batch`,{metadata:{failedCount:r.length,totalCount:t.length}})}async function _e(e,n){let{to:t}=n;if(!t||typeof t!="string")throw new h(n,'navigate action requires "to" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"to"}});let r=t;if(t.startsWith("{{")&&t.endsWith("}}")){let i=t.slice(2,-2).trim(),a=A(i,e);if(typeof a!="string")throw new h(n,`navigate "to" expression must evaluate to a string, got ${typeof a}`,c.ACTION_INVALID_PARAM,{metadata:{param:"to",actualType:typeof a}});r=a;}let o=e.$methods.navigate||e.$methods.$navigate;if(o)await o(e,{to:r});else if(typeof window<"u"&&window.location)window.location.href=r;else throw new h(n,"navigate method not registered and window.location is not available",c.ACTION_EXECUTION_ERROR,{metadata:{reason:"navigate_not_available"}})}async function ve(e,n){let{level:t="info",message:r}=n;if(!r)throw new h(n,'log action requires "message" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"message"}});let o=r;if(typeof r=="string"&&r.startsWith("{{")&&r.endsWith("}}")){let s=r.slice(2,-2).trim();o=A(s,e);}let i=String(t).toLowerCase(),a=String(o);if(typeof console<"u")switch(i){case "error":console.error("[Vario]",a);break;case "warn":console.warn("[Vario]",a);break;default:console.log("[Vario]",a);break}}function O(e,n){if(typeof e=="string"){if(e.startsWith("{{")&&e.endsWith("}}")){let t=e.slice(2,-2).trim();return A(t,n)}return e}if(Array.isArray(e))return e.map(t=>O(t,n));if(e&&typeof e=="object"){let t={};for(let[r,o]of Object.entries(e))t[r]=O(o,n);return t}return e}async function ke(e,n){let{path:t,value:r,items:o}=n;if(!t||typeof t!="string")throw new h(n,'push action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let i=e._get(t);if(!Array.isArray(i))throw new h(n,`Path "${t}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:t,actualType:typeof i}});let a=o!==void 0?o:r;if(a===void 0)throw new h(n,'push action requires "value" or "items" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"value|items"}});let s=O(a,e);Array.isArray(s)?i.push(...s):i.push(s),x(t,e),x(`${t}.*`,e);}async function Me(e,n){let{path:t}=n;if(!t||typeof t!="string")throw new h(n,'pop action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let r=e._get(t);if(!Array.isArray(r))throw new h(n,`Path "${t}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:t,actualType:typeof r}});r.pop(),x(t,e),x(`${t}.*`,e);}async function $e(e,n){let{path:t}=n;if(!t||typeof t!="string")throw new h(n,'shift action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let r=e._get(t);if(!Array.isArray(r))throw new h(n,`Path "${t}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:t,actualType:typeof r}});r.shift(),x(t,e),x(`${t}.*`,e);}async function je(e,n){let{path:t,value:r,items:o}=n;if(!t||typeof t!="string")throw new h(n,'unshift action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let i=e._get(t);if(!Array.isArray(i))throw new h(n,`Path "${t}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:t,actualType:typeof i}});let a=o!==void 0?o:r;if(a===void 0)throw new h(n,'unshift action requires "value" or "items" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"value|items"}});let s=O(a,e);Array.isArray(s)?i.unshift(...s):i.unshift(s),x(t,e),x(`${t}.*`,e);}async function Le(e,n){let{path:t,start:r,deleteCount:o=0,items:i}=n;if(!t||typeof t!="string")throw new h(n,'splice action requires "path" parameter',c.ACTION_MISSING_PARAM,{metadata:{param:"path"}});let a=e._get(t);if(!Array.isArray(a))throw new h(n,`Path "${t}" does not point to an array`,c.ACTION_INVALID_PARAM,{metadata:{param:"path",path:t,actualType:typeof a}});let s;if(typeof r=="string"&&r.startsWith("{{")&&r.endsWith("}}")){let f=r.slice(2,-2).trim();s=Number(A(f,e));}else s=Number(r);let u;if(typeof o=="string"&&o.startsWith("{{")&&o.endsWith("}}")){let f=o.slice(2,-2).trim();u=Number(A(f,e));}else u=Number(o);let d=[];if(i!=null){let f=O(i,e);Array.isArray(f)?d=f:d=[f];}a.splice(s,u,...d),x(t,e),x(`${t}.*`,e);}var rt={set:Ce,emit:be,navigate:_e,log:ve,if:Te,loop:Ie,call:Oe,batch:Pe,push:ke,pop:Me,shift:$e,unshift:je,splice:Le};function Q(e){for(let[n,t]of Object.entries(rt))n in e.$methods||(e.$methods[n]=t);}function De(e={},n={}){ot(e);let{onEmit:t,methods:r={},onStateChange:o,createObject:i=()=>({}),createArray:a=()=>[],exprOptions:s}=n,u=null,d={...e,$emit:(S,g)=>{t&&t(S,g);},$methods:r,$exprOptions:s,_get:S=>v(d,S),_set:(S,g,E)=>{J(d,S,g,{createObject:i,createArray:a}),x(S,u||d),o&&!E?.skipCallback&&o(S,g,u||d);}};Q(d);let f=W(d);return u=f,f}function ot(e){for(let n in e)if(n.startsWith("$")||n.startsWith("_"))throw new Error(`Property name "${n}" conflicts with system API. Properties starting with "$" or "_" are reserved. Use a different name.`)}function j(e,n,t="."){function r(o,i,a,s){if(!(!o||typeof o!="object"||n(o,i,a,s)===false)&&o.children){if(Array.isArray(o.children))o.children.forEach((d,f)=>{if(d&&typeof d=="object"){let S=i?`${i}${t}children${t}${f}`:`children${t}${f}`;r(d,S,a+1,o);}});else if(typeof o.children=="object"){let d=i?`${i}${t}children`:"children";r(o.children,d,a+1,o);}}}r(e,"",0,null);}function Ve(e,n={}){let t={nodeCount:0,maxDepth:0},r=new Map,o=n.buildPathMap?new Map:void 0;return j(e,(i,a,s)=>{t.nodeCount++,s>t.maxDepth&&(t.maxDepth=s);let u=i;u.id&&typeof u.id=="string"&&r.set(u.id,a),o&&o.set(a,i),n.onNode?.(i,a,s);}),{stats:t,index:{idMap:r,pathMap:o}}}function Ue(e,n){let t=[];return j(e,(r,o)=>{n(r)&&t.push({node:r,path:o});}),t}function pe(e,n){let t=null;return j(e,(r,o)=>{if(n(r))return t={node:r,path:o},false}),t}function Xe(e,n){return pe(e,r=>r.id===n)?.path||null}function Ge(e){let{schema:n,index:t}=e;return {findById:i=>{if(t?.idMap){let a=t.idMap.get(i);if(!a)return null;if(t.pathMap){let u=t.pathMap.get(a);return u?{node:u,path:a}:null}let s=v(n,a);return s?{node:s,path:a}:null}return null},getParent:i=>{if(!i||!i.includes("."))return null;let a=i;for(;;){let s=a.lastIndexOf(".");if(s===-1)return {node:n,path:""};a=a.substring(0,s);let u=a.split(".").pop();if(u&&["children","definitions","items"].includes(u))continue;let d=v(n,a);if(!(Array.isArray(d)||typeof d=="string")&&d&&typeof d=="object")return {node:d,path:a}}}}}export{h as ActionError,_ as BatchError,c as ErrorCodes,y as ExpressionError,N as ServiceError,I as VarioError,Ve as analyzeSchema,we as clearCache,ye as clearPathCache,me as createExpressionSandbox,X as createLoopContext,W as createProxy,Ge as createQueryEngine,De as createRuntimeContext,A as evaluate,q as evaluateExpression,T as execute,L as extractDependencies,K as extractExpression,pe as findNode,Ue as findNodes,Xe as findPathById,Re as getCacheStats,z as getCachedExpression,xe as getLastSegment,Se as getParentPath,v as getPathValue,x as invalidateCache,H as isSafePropertyAccess,D as matchPath,B as parseExpression,oe as parsePath,$ as parsePathCached,Q as registerBuiltinMethods,G as releaseLoopContext,U as setCachedExpression,J as setPathValue,ie as stringifyPath,j as traverseSchema,F as validateAST};//# sourceMappingURL=index.js.map
|
|
9
9
|
//# sourceMappingURL=index.js.map
|