@variojs/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/__tests__/README.md +101 -0
  2. package/__tests__/errors.test.ts +139 -0
  3. package/__tests__/expression/cache.test.ts +118 -0
  4. package/__tests__/expression/compiler.test.ts +111 -0
  5. package/__tests__/expression/evaluate.test.ts +95 -0
  6. package/__tests__/expression/parser.test.ts +57 -0
  7. package/__tests__/expression/whitelist.test.ts +59 -0
  8. package/__tests__/performance.test.ts +379 -0
  9. package/__tests__/runtime/create-context.test.ts +78 -0
  10. package/__tests__/runtime/loop-context-pool.test.ts +74 -0
  11. package/__tests__/runtime/path.test.ts +128 -0
  12. package/__tests__/vm/executor-timeout.test.ts +117 -0
  13. package/__tests__/vm/executor.test.ts +173 -0
  14. package/__tests__/vm/handlers/array.test.ts +113 -0
  15. package/__tests__/vm/handlers/call.test.ts +93 -0
  16. package/dist/errors.d.ts +100 -0
  17. package/dist/errors.d.ts.map +1 -0
  18. package/dist/errors.js +132 -0
  19. package/dist/errors.js.map +1 -0
  20. package/dist/expression/cache.d.ts +53 -0
  21. package/dist/expression/cache.d.ts.map +1 -0
  22. package/dist/expression/cache.js +158 -0
  23. package/dist/expression/cache.js.map +1 -0
  24. package/dist/expression/compiler.d.ts +34 -0
  25. package/dist/expression/compiler.d.ts.map +1 -0
  26. package/dist/expression/compiler.js +123 -0
  27. package/dist/expression/compiler.js.map +1 -0
  28. package/dist/expression/dependencies.d.ts +17 -0
  29. package/dist/expression/dependencies.d.ts.map +1 -0
  30. package/dist/expression/dependencies.js +106 -0
  31. package/dist/expression/dependencies.js.map +1 -0
  32. package/dist/expression/evaluate.d.ts +22 -0
  33. package/dist/expression/evaluate.d.ts.map +1 -0
  34. package/dist/expression/evaluate.js +75 -0
  35. package/dist/expression/evaluate.js.map +1 -0
  36. package/dist/expression/evaluator.d.ts +22 -0
  37. package/dist/expression/evaluator.d.ts.map +1 -0
  38. package/dist/expression/evaluator.js +506 -0
  39. package/dist/expression/evaluator.js.map +1 -0
  40. package/dist/expression/index.d.ts +12 -0
  41. package/dist/expression/index.d.ts.map +1 -0
  42. package/dist/expression/index.js +12 -0
  43. package/dist/expression/index.js.map +1 -0
  44. package/dist/expression/parser.d.ts +15 -0
  45. package/dist/expression/parser.d.ts.map +1 -0
  46. package/dist/expression/parser.js +42 -0
  47. package/dist/expression/parser.js.map +1 -0
  48. package/dist/expression/utils.d.ts +46 -0
  49. package/dist/expression/utils.d.ts.map +1 -0
  50. package/dist/expression/utils.js +78 -0
  51. package/dist/expression/utils.js.map +1 -0
  52. package/dist/expression/whitelist.d.ts +24 -0
  53. package/dist/expression/whitelist.d.ts.map +1 -0
  54. package/dist/expression/whitelist.js +198 -0
  55. package/dist/expression/whitelist.js.map +1 -0
  56. package/dist/index.d.ts +19 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +21 -0
  59. package/dist/index.js.map +1 -0
  60. package/dist/runtime/context.d.ts +8 -0
  61. package/dist/runtime/context.d.ts.map +1 -0
  62. package/dist/runtime/context.js +7 -0
  63. package/dist/runtime/context.js.map +1 -0
  64. package/dist/runtime/create-context.d.ts +50 -0
  65. package/dist/runtime/create-context.d.ts.map +1 -0
  66. package/dist/runtime/create-context.js +73 -0
  67. package/dist/runtime/create-context.js.map +1 -0
  68. package/dist/runtime/index.d.ts +10 -0
  69. package/dist/runtime/index.d.ts.map +1 -0
  70. package/dist/runtime/index.js +10 -0
  71. package/dist/runtime/index.js.map +1 -0
  72. package/dist/runtime/loop-context-pool.d.ts +58 -0
  73. package/dist/runtime/loop-context-pool.d.ts.map +1 -0
  74. package/dist/runtime/loop-context-pool.js +114 -0
  75. package/dist/runtime/loop-context-pool.js.map +1 -0
  76. package/dist/runtime/path.d.ts +114 -0
  77. package/dist/runtime/path.d.ts.map +1 -0
  78. package/dist/runtime/path.js +302 -0
  79. package/dist/runtime/path.js.map +1 -0
  80. package/dist/runtime/proxy.d.ts +18 -0
  81. package/dist/runtime/proxy.d.ts.map +1 -0
  82. package/dist/runtime/proxy.js +53 -0
  83. package/dist/runtime/proxy.js.map +1 -0
  84. package/dist/runtime/sandbox.d.ts +20 -0
  85. package/dist/runtime/sandbox.d.ts.map +1 -0
  86. package/dist/runtime/sandbox.js +32 -0
  87. package/dist/runtime/sandbox.js.map +1 -0
  88. package/dist/types.d.ts +175 -0
  89. package/dist/types.d.ts.map +1 -0
  90. package/dist/types.js +22 -0
  91. package/dist/types.js.map +1 -0
  92. package/dist/vm/action.d.ts +11 -0
  93. package/dist/vm/action.d.ts.map +1 -0
  94. package/dist/vm/action.js +10 -0
  95. package/dist/vm/action.js.map +1 -0
  96. package/dist/vm/errors.d.ts +5 -0
  97. package/dist/vm/errors.d.ts.map +1 -0
  98. package/dist/vm/errors.js +5 -0
  99. package/dist/vm/errors.js.map +1 -0
  100. package/dist/vm/executor.d.ts +35 -0
  101. package/dist/vm/executor.d.ts.map +1 -0
  102. package/dist/vm/executor.js +137 -0
  103. package/dist/vm/executor.js.map +1 -0
  104. package/dist/vm/handlers/array/pop.d.ts +12 -0
  105. package/dist/vm/handlers/array/pop.d.ts.map +1 -0
  106. package/dist/vm/handlers/array/pop.js +28 -0
  107. package/dist/vm/handlers/array/pop.js.map +1 -0
  108. package/dist/vm/handlers/array/push.d.ts +13 -0
  109. package/dist/vm/handlers/array/push.d.ts.map +1 -0
  110. package/dist/vm/handlers/array/push.js +42 -0
  111. package/dist/vm/handlers/array/push.js.map +1 -0
  112. package/dist/vm/handlers/array/shift.d.ts +12 -0
  113. package/dist/vm/handlers/array/shift.d.ts.map +1 -0
  114. package/dist/vm/handlers/array/shift.js +28 -0
  115. package/dist/vm/handlers/array/shift.js.map +1 -0
  116. package/dist/vm/handlers/array/splice.d.ts +12 -0
  117. package/dist/vm/handlers/array/splice.d.ts.map +1 -0
  118. package/dist/vm/handlers/array/splice.js +59 -0
  119. package/dist/vm/handlers/array/splice.js.map +1 -0
  120. package/dist/vm/handlers/array/unshift.d.ts +13 -0
  121. package/dist/vm/handlers/array/unshift.d.ts.map +1 -0
  122. package/dist/vm/handlers/array/unshift.js +42 -0
  123. package/dist/vm/handlers/array/unshift.js.map +1 -0
  124. package/dist/vm/handlers/array/utils.d.ts +10 -0
  125. package/dist/vm/handlers/array/utils.d.ts.map +1 -0
  126. package/dist/vm/handlers/array/utils.js +33 -0
  127. package/dist/vm/handlers/array/utils.js.map +1 -0
  128. package/dist/vm/handlers/batch.d.ts +12 -0
  129. package/dist/vm/handlers/batch.d.ts.map +1 -0
  130. package/dist/vm/handlers/batch.js +40 -0
  131. package/dist/vm/handlers/batch.js.map +1 -0
  132. package/dist/vm/handlers/call.d.ts +14 -0
  133. package/dist/vm/handlers/call.d.ts.map +1 -0
  134. package/dist/vm/handlers/call.js +65 -0
  135. package/dist/vm/handlers/call.js.map +1 -0
  136. package/dist/vm/handlers/emit.d.ts +12 -0
  137. package/dist/vm/handlers/emit.d.ts.map +1 -0
  138. package/dist/vm/handlers/emit.js +26 -0
  139. package/dist/vm/handlers/emit.js.map +1 -0
  140. package/dist/vm/handlers/if.d.ts +13 -0
  141. package/dist/vm/handlers/if.d.ts.map +1 -0
  142. package/dist/vm/handlers/if.js +35 -0
  143. package/dist/vm/handlers/if.js.map +1 -0
  144. package/dist/vm/handlers/index.d.ts +11 -0
  145. package/dist/vm/handlers/index.d.ts.map +1 -0
  146. package/dist/vm/handlers/index.js +46 -0
  147. package/dist/vm/handlers/index.js.map +1 -0
  148. package/dist/vm/handlers/log.d.ts +12 -0
  149. package/dist/vm/handlers/log.d.ts.map +1 -0
  150. package/dist/vm/handlers/log.js +41 -0
  151. package/dist/vm/handlers/log.js.map +1 -0
  152. package/dist/vm/handlers/loop.d.ts +12 -0
  153. package/dist/vm/handlers/loop.d.ts.map +1 -0
  154. package/dist/vm/handlers/loop.js +71 -0
  155. package/dist/vm/handlers/loop.js.map +1 -0
  156. package/dist/vm/handlers/navigate.d.ts +12 -0
  157. package/dist/vm/handlers/navigate.d.ts.map +1 -0
  158. package/dist/vm/handlers/navigate.js +43 -0
  159. package/dist/vm/handlers/navigate.js.map +1 -0
  160. package/dist/vm/handlers/set.d.ts +15 -0
  161. package/dist/vm/handlers/set.d.ts.map +1 -0
  162. package/dist/vm/handlers/set.js +30 -0
  163. package/dist/vm/handlers/set.js.map +1 -0
  164. package/dist/vm/index.d.ts +8 -0
  165. package/dist/vm/index.d.ts.map +1 -0
  166. package/dist/vm/index.js +7 -0
  167. package/dist/vm/index.js.map +1 -0
  168. package/package.json +34 -0
  169. package/src/errors.ts +194 -0
  170. package/src/expression/README.md +192 -0
  171. package/src/expression/cache.ts +199 -0
  172. package/src/expression/compiler.ts +144 -0
  173. package/src/expression/dependencies.ts +116 -0
  174. package/src/expression/evaluate.ts +95 -0
  175. package/src/expression/evaluator.ts +640 -0
  176. package/src/expression/index.ts +27 -0
  177. package/src/expression/parser.ts +54 -0
  178. package/src/expression/utils.ts +89 -0
  179. package/src/expression/whitelist.ts +224 -0
  180. package/src/globals.d.ts +10 -0
  181. package/src/index.ts +72 -0
  182. package/src/runtime/context.ts +8 -0
  183. package/src/runtime/create-context.ts +133 -0
  184. package/src/runtime/index.ts +28 -0
  185. package/src/runtime/loop-context-pool.ts +134 -0
  186. package/src/runtime/path.ts +372 -0
  187. package/src/runtime/proxy.ts +66 -0
  188. package/src/runtime/sandbox.ts +43 -0
  189. package/src/types.ts +177 -0
  190. package/src/vm/errors.ts +10 -0
  191. package/src/vm/executor.ts +210 -0
  192. package/src/vm/handlers/array/pop.ts +47 -0
  193. package/src/vm/handlers/array/push.ts +68 -0
  194. package/src/vm/handlers/array/shift.ts +47 -0
  195. package/src/vm/handlers/array/splice.ts +78 -0
  196. package/src/vm/handlers/array/unshift.ts +68 -0
  197. package/src/vm/handlers/array/utils.ts +41 -0
  198. package/src/vm/handlers/batch.ts +57 -0
  199. package/src/vm/handlers/call.ts +92 -0
  200. package/src/vm/handlers/emit.ts +39 -0
  201. package/src/vm/handlers/if.ts +48 -0
  202. package/src/vm/handlers/index.ts +52 -0
  203. package/src/vm/handlers/log.ts +54 -0
  204. package/src/vm/handlers/loop.ts +102 -0
  205. package/src/vm/handlers/navigate.ts +64 -0
  206. package/src/vm/handlers/set.ts +43 -0
  207. package/src/vm/index.ts +8 -0
  208. package/tsconfig.json +17 -0
  209. package/vitest.config.ts +30 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * batch 动作处理器
3
+ *
4
+ * 功能:批量执行动作(保证原子性)
5
+ * 示例:{ "type": "batch", "actions": [...] }
6
+ */
7
+ import { ActionError, BatchError, ErrorCodes } from '../../errors.js';
8
+ import { execute } from '../executor.js';
9
+ /**
10
+ * 处理 batch 动作
11
+ */
12
+ export async function handleBatch(ctx, action) {
13
+ const { actions } = action;
14
+ if (!actions || !Array.isArray(actions)) {
15
+ throw new ActionError(action, 'batch action requires "actions" parameter (array)', ErrorCodes.ACTION_MISSING_PARAM, { metadata: { param: 'actions' } });
16
+ }
17
+ const errors = [];
18
+ // 批量执行,收集错误
19
+ for (const act of actions) {
20
+ try {
21
+ await execute([act], ctx);
22
+ }
23
+ catch (error) {
24
+ errors.push({
25
+ action: act,
26
+ error: error instanceof Error ? error : new Error(String(error))
27
+ });
28
+ }
29
+ }
30
+ // 如果有错误,抛出 BatchError
31
+ if (errors.length > 0) {
32
+ throw new BatchError(errors, `${errors.length} actions failed in batch`, {
33
+ metadata: {
34
+ failedCount: errors.length,
35
+ totalCount: actions.length
36
+ }
37
+ });
38
+ }
39
+ }
40
+ //# sourceMappingURL=batch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.js","sourceRoot":"","sources":["../../../src/vm/handlers/batch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAExC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,GAAmB,EACnB,MAAc;IAEd,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAE1B,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,WAAW,CACnB,MAAM,EACN,mDAAmD,EACnD,UAAU,CAAC,oBAAoB,EAC/B,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,CACnC,CAAA;IACH,CAAC;IAED,MAAM,MAAM,GAA4C,EAAE,CAAA;IAE1D,YAAY;IACZ,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;QAC3B,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC;gBACV,MAAM,EAAE,GAAG;gBACX,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACjE,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,sBAAsB;IACtB,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,UAAU,CAClB,MAAM,EACN,GAAG,MAAM,CAAC,MAAM,0BAA0B,EAC1C;YACE,QAAQ,EAAE;gBACR,WAAW,EAAE,MAAM,CAAC,MAAM;gBAC1B,UAAU,EAAE,OAAO,CAAC,MAAM;aAC3B;SACF,CACF,CAAA;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * call 动作处理器
3
+ *
4
+ * 功能:调用 method(通过 $methods)
5
+ * 示例:{ "type": "call", "method": "services.fetchUser", "params": {...}, "resultTo": "user" }
6
+ *
7
+ * 参考文档:action-reference.md - call 动作
8
+ */
9
+ import type { RuntimeContext, Action } from '../../types.js';
10
+ /**
11
+ * 处理 call 动作
12
+ */
13
+ export declare function handleCall(ctx: RuntimeContext, action: Action): Promise<unknown>;
14
+ //# sourceMappingURL=call.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call.d.ts","sourceRoot":"","sources":["../../../src/vm/handlers/call.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAKxD;;GAEG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAuElB"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * call 动作处理器
3
+ *
4
+ * 功能:调用 method(通过 $methods)
5
+ * 示例:{ "type": "call", "method": "services.fetchUser", "params": {...}, "resultTo": "user" }
6
+ *
7
+ * 参考文档:action-reference.md - call 动作
8
+ */
9
+ import { ActionError, ServiceError, ErrorCodes } from '../../errors.js';
10
+ import { evaluate } from '../../expression/evaluate.js';
11
+ import { invalidateCache } from '../../expression/cache.js';
12
+ /**
13
+ * 处理 call 动作
14
+ */
15
+ export async function handleCall(ctx, action) {
16
+ const method = action.method;
17
+ const params = (action.params || {});
18
+ const resultTo = action.resultTo;
19
+ if (!method || typeof method !== 'string') {
20
+ throw new ActionError(action, 'call action requires "method" parameter', ErrorCodes.ACTION_MISSING_PARAM, { metadata: { param: 'method' } });
21
+ }
22
+ // 查找方法(通过 $methods)
23
+ const handler = ctx.$methods[method];
24
+ if (!handler) {
25
+ throw new ServiceError(method, `Method "${method}" not found in $methods`, undefined, {
26
+ metadata: { method }
27
+ });
28
+ }
29
+ // 求值参数(支持表达式)
30
+ const finalParams = {};
31
+ try {
32
+ for (const [key, value] of Object.entries(params)) {
33
+ if (typeof value === 'string' && value.startsWith('{{') && value.endsWith('}}')) {
34
+ const expr = value.slice(2, -2).trim();
35
+ finalParams[key] = evaluate(expr, ctx);
36
+ }
37
+ else {
38
+ finalParams[key] = value;
39
+ }
40
+ }
41
+ // 调用 method
42
+ const result = await handler(ctx, finalParams);
43
+ // 如果指定了 resultTo,保存结果到状态
44
+ if (resultTo) {
45
+ ctx._set(resultTo, result);
46
+ invalidateCache(resultTo, ctx);
47
+ }
48
+ return result;
49
+ }
50
+ catch (error) {
51
+ // 如果错误已经是 ServiceError,直接抛出
52
+ if (error instanceof ServiceError) {
53
+ throw error;
54
+ }
55
+ const errorMessage = error instanceof Error ? error.message : String(error);
56
+ const originalError = error instanceof Error ? error : undefined;
57
+ throw new ServiceError(method, `Service call failed: ${errorMessage}`, originalError, {
58
+ metadata: {
59
+ method,
60
+ params: finalParams
61
+ }
62
+ });
63
+ }
64
+ }
65
+ //# sourceMappingURL=call.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call.js","sourceRoot":"","sources":["../../../src/vm/handlers/call.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAmB,EACnB,MAAc;IAEd,MAAM,MAAM,GAAG,MAAM,CAAC,MAA4B,CAAA;IAClD,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAA4B,CAAA;IAC/D,MAAM,QAAQ,GAAG,MAAM,CAAC,QAA8B,CAAA;IAEtD,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,MAAM,IAAI,WAAW,CACnB,MAAM,EACN,yCAAyC,EACzC,UAAU,CAAC,oBAAoB,EAC/B,EAAE,QAAQ,EAAE,E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QAC5B,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;YAClC,MAAM,KAAK,CAAA;QACb,CAAC;QAED,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAC3E,MAAM,aAAa,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;QAEhE,MAAM,IAAI,YAAY,CACpB,MAAM,EACN,wBAAwB,YAAY,EAAE,EACtC,aAAa,EACb;YACE,QAAQ,EAAE;gBACR,MAAM;gBACN,MAAM,EAAE,WAAW;aACpB;SACF,CACF,CAAA;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * emit 动作处理器
3
+ *
4
+ * 功能:触发事件
5
+ * 示例:{ "type": "emit", "event": "submit", "data": { "userId": 123 } }
6
+ */
7
+ import type { RuntimeContext, Action } from '../../types.js';
8
+ /**
9
+ * 处理 emit 动作
10
+ */
11
+ export declare function handleEmit(ctx: RuntimeContext, action: Action): Promise<void>;
12
+ //# sourceMappingURL=emit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../../src/vm/handlers/emit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAIxD;;GAEG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAqBf"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * emit 动作处理器
3
+ *
4
+ * 功能:触发事件
5
+ * 示例:{ "type": "emit", "event": "submit", "data": { "userId": 123 } }
6
+ */
7
+ import { ActionError, ErrorCodes } from '../../errors.js';
8
+ import { evaluate } from '../../expression/evaluate.js';
9
+ /**
10
+ * 处理 emit 动作
11
+ */
12
+ export async function handleEmit(ctx, action) {
13
+ const { event, data } = action;
14
+ if (!event || typeof event !== 'string') {
15
+ throw new ActionError(action, 'emit action requires "event" parameter', ErrorCodes.ACTION_MISSING_PARAM, { metadata: { param: 'event' } });
16
+ }
17
+ // 求值 data(支持表达式)
18
+ let finalData = data;
19
+ if (typeof data === 'string' && data.startsWith('{{') && data.endsWith('}}')) {
20
+ const expr = data.slice(2, -2).trim();
21
+ finalData = evaluate(expr, ctx);
22
+ }
23
+ // 触发事件
24
+ ctx.$emit(event, finalData);
25
+ }
26
+ //# sourceMappingURL=emit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit.js","sourceRoot":"","sources":["../../../src/vm/handlers/emit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAmB,EACnB,MAAc;IAEd,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAAA;IAE9B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,WAAW,CACnB,MAAM,EACN,wCAAwC,EACxC,UAAU,CAAC,oBAAoB,EAC/B,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CACjC,CAAA;IACH,CAAC;IAED,iBAAiB;IACjB,IAAI,SAAS,GAAG,IAAI,CAAA;IACpB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7E,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QACrC,SAAS,GAAG,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IACjC,CAAC;IAED,OAAO;IACP,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;AAC7B,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * if 动作处理器
3
+ *
4
+ * 功能:条件分支
5
+ * 示例:{ "type": "if", "cond": "user.age > 18", "then": [...], "else": [...] }
6
+ * 示例:{ "type": "if", "cond": "{{ counter < 10 }}", "then": [...], "else": [...] }
7
+ */
8
+ import type { RuntimeContext, Action } from '../../types.js';
9
+ /**
10
+ * 处理 if 动作
11
+ */
12
+ export declare function handleIf(ctx: RuntimeContext, action: Action): Promise<void>;
13
+ //# sourceMappingURL=if.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if.d.ts","sourceRoot":"","sources":["../../../src/vm/handlers/if.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAKxD;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CA4Bf"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * if 动作处理器
3
+ *
4
+ * 功能:条件分支
5
+ * 示例:{ "type": "if", "cond": "user.age > 18", "then": [...], "else": [...] }
6
+ * 示例:{ "type": "if", "cond": "{{ counter < 10 }}", "then": [...], "else": [...] }
7
+ */
8
+ import { ActionError, ErrorCodes } from '../../errors.js';
9
+ import { evaluate, extractExpression } from '../../expression/index.js';
10
+ import { execute } from '../executor.js';
11
+ /**
12
+ * 处理 if 动作
13
+ */
14
+ export async function handleIf(ctx, action) {
15
+ const { cond, then, else: elseBranch } = action;
16
+ if (!cond || typeof cond !== 'string') {
17
+ throw new ActionError(action, 'if action requires "cond" parameter', ErrorCodes.ACTION_MISSING_PARAM, { metadata: { param: 'cond' } });
18
+ }
19
+ // 提取表达式(支持 {{ }} 格式)
20
+ const condExpr = extractExpression(cond);
21
+ // 求值条件表达式
22
+ const condition = evaluate(condExpr, ctx);
23
+ // 执行对应的分支
24
+ if (condition) {
25
+ if (then && Array.isArray(then)) {
26
+ await execute(then, ctx);
27
+ }
28
+ }
29
+ else {
30
+ if (elseBranch && Array.isArray(elseBranch)) {
31
+ await execute(elseBranch, ctx);
32
+ }
33
+ }
34
+ }
35
+ //# sourceMappingURL=if.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if.js","sourceRoot":"","sources":["../../../src/vm/handlers/if.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAExC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,GAAmB,EACnB,MAAc;IAEd,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;IAE/C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC,MAAM,IAAI,WAAW,CACnB,MAAM,EACN,qCAAqC,EACrC,UAAU,CAAC,oBAAoB,EAC/B,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAChC,CAAA;IACH,CAAC;IAED,qBAAqB;IACrB,MAAM,QAAQ,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAExC,UAAU;IACV,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IAEzC,UAAU;IACV,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChC,MAAM,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QAC1B,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAC5C,MAAM,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;QAChC,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 内置动作处理器
3
+ *
4
+ * 所有内置动作统一注册到 ctx.$methods
5
+ */
6
+ import type { RuntimeContext } from '../../types.js';
7
+ /**
8
+ * 注册所有内置动作到 $methods
9
+ */
10
+ export declare function registerBuiltinMethods(ctx: RuntimeContext): void;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vm/handlers/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,YAAY,CAAA;AAe/D;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI,CA2BhE"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * 内置动作处理器
3
+ *
4
+ * 所有内置动作统一注册到 ctx.$methods
5
+ */
6
+ import { handleSet } from './set.js';
7
+ import { handleEmit } from './emit.js';
8
+ import { handleIf } from './if.js';
9
+ import { handleLoop } from './loop.js';
10
+ import { handleCall } from './call.js';
11
+ import { handleBatch } from './batch.js';
12
+ import { handleNavigate } from './navigate.js';
13
+ import { handleLog } from './log.js';
14
+ import { handlePush } from './array/push.js';
15
+ import { handlePop } from './array/pop.js';
16
+ import { handleShift } from './array/shift.js';
17
+ import { handleUnshift } from './array/unshift.js';
18
+ import { handleSplice } from './array/splice.js';
19
+ /**
20
+ * 注册所有内置动作到 $methods
21
+ */
22
+ export function registerBuiltinMethods(ctx) {
23
+ // 动作处理器作为特殊的方法注册,参数是 Action
24
+ ctx.$methods = {
25
+ // 原子动作
26
+ 'set': handleSet,
27
+ 'emit': handleEmit,
28
+ 'navigate': handleNavigate,
29
+ 'log': handleLog,
30
+ // 控制流动作
31
+ 'if': handleIf,
32
+ 'loop': handleLoop,
33
+ // 复合动作
34
+ 'call': handleCall,
35
+ 'batch': handleBatch,
36
+ // 数组操作动作
37
+ 'push': handlePush,
38
+ 'pop': handlePop,
39
+ 'shift': handleShift,
40
+ 'unshift': handleUnshift,
41
+ 'splice': handleSplice,
42
+ // 保留已有的方法(允许覆盖或扩展)
43
+ ...ctx.$methods
44
+ };
45
+ }
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/vm/handlers/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAAmB;IACxD,4BAA4B;IAC5B,GAAG,CAAC,QAAQ,GAAG;QACb,OAAO;QACP,KAAK,EAAE,SAA0B;QACjC,MAAM,EAAE,UAA2B;QACnC,UAAU,EAAE,cAA+B;QAC3C,KAAK,EAAE,SAA0B;QAEjC,QAAQ;QACR,IAAI,EAAE,QAAyB;QAC/B,MAAM,EAAE,UAA2B;QAEnC,OAAO;QACP,MAAM,EAAE,UAA2B;QACnC,OAAO,EAAE,WAA4B;QAErC,SAAS;QACT,MAAM,EAAE,UAA2B;QACnC,KAAK,EAAE,SAA0B;QACjC,OAAO,EAAE,WAA4B;QACrC,SAAS,EAAE,aAA8B;QACzC,QAAQ,EAAE,YAA6B;QAEvC,mBAAmB;QACnB,GAAG,GAAG,CAAC,QAAQ;KAChB,CAAA;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * log 动作处理器
3
+ *
4
+ * 功能:调试输出
5
+ * 示例:{ "type": "log", "level": "info", "message": "User logged in" }
6
+ */
7
+ import type { RuntimeContext, Action } from '../../types.js';
8
+ /**
9
+ * 处理 log 动作
10
+ */
11
+ export declare function handleLog(ctx: RuntimeContext, action: Action): Promise<void>;
12
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/vm/handlers/log.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAIxD;;GAEG;AACH,wBAAsB,SAAS,CAC7B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoCf"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * log 动作处理器
3
+ *
4
+ * 功能:调试输出
5
+ * 示例:{ "type": "log", "level": "info", "message": "User logged in" }
6
+ */
7
+ import { ActionError, ErrorCodes } from '../../errors.js';
8
+ import { evaluate } from '../../expression/evaluate.js';
9
+ /**
10
+ * 处理 log 动作
11
+ */
12
+ export async function handleLog(ctx, action) {
13
+ const { level = 'info', message } = action;
14
+ if (!message) {
15
+ throw new ActionError(action, 'log action requires "message" parameter', ErrorCodes.ACTION_MISSING_PARAM, { metadata: { param: 'message' } });
16
+ }
17
+ // 求值 message(支持表达式)
18
+ let finalMessage = message;
19
+ if (typeof message === 'string' && message.startsWith('{{') && message.endsWith('}}')) {
20
+ const expr = message.slice(2, -2).trim();
21
+ finalMessage = evaluate(expr, ctx);
22
+ }
23
+ // 输出日志(将 finalMessage 转换为字符串)
24
+ const logLevel = String(level).toLowerCase();
25
+ const messageStr = String(finalMessage);
26
+ if (typeof console !== 'undefined') {
27
+ switch (logLevel) {
28
+ case 'error':
29
+ console.error('[Vario]', messageStr);
30
+ break;
31
+ case 'warn':
32
+ console.warn('[Vario]', messageStr);
33
+ break;
34
+ case 'info':
35
+ default:
36
+ console.log('[Vario]', messageStr);
37
+ break;
38
+ }
39
+ }
40
+ }
41
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/vm/handlers/log.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,GAAmB,EACnB,MAAc;IAEd,MAAM,EAAE,KAAK,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAE1C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,WAAW,CACnB,MAAM,EACN,yCAAyC,EACzC,UAAU,CAAC,oBAAoB,EAC/B,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,CACnC,CAAA;IACH,CAAC;IAED,oBAAoB;IACpB,IAAI,YAAY,GAAY,OAAO,CAAA;IACnC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACtF,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QACxC,YAAY,GAAG,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IACpC,CAAC;IAED,8BAA8B;IAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAA;IAC5C,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;IACvC,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACnC,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,OAAO;gBACV,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;gBACpC,MAAK;YACP,KAAK,MAAM;gBACT,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;gBACnC,MAAK;YACP,KAAK,MAAM,CAAC;YACZ;gBACE,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;gBAClC,MAAK;QACT,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * loop 动作处理器
3
+ *
4
+ * 功能:循环执行
5
+ * 示例:{ "type": "loop", "var": "item", "in": "items", "body": [...] }
6
+ */
7
+ import type { RuntimeContext, Action } from '../../types.js';
8
+ /**
9
+ * 处理 loop 动作
10
+ */
11
+ export declare function handleLoop(ctx: RuntimeContext, action: Action): Promise<void>;
12
+ //# sourceMappingURL=loop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../../src/vm/handlers/loop.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAOxD;;GAEG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAiFf"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * loop 动作处理器
3
+ *
4
+ * 功能:循环执行
5
+ * 示例:{ "type": "loop", "var": "item", "in": "items", "body": [...] }
6
+ */
7
+ import { ActionError, ErrorCodes } from '../../errors.js';
8
+ import { evaluate } from '../../expression/evaluate.js';
9
+ import { invalidateCache } from '../../expression/cache.js';
10
+ import { execute } from '../executor.js';
11
+ import { createLoopContext, releaseLoopContext } from '../../runtime/loop-context-pool.js';
12
+ /**
13
+ * 处理 loop 动作
14
+ */
15
+ export async function handleLoop(ctx, action) {
16
+ const { var: varName, in: inExpr, body } = action;
17
+ if (!varName || typeof varName !== 'string') {
18
+ throw new ActionError(action, 'loop action requires "var" parameter', ErrorCodes.ACTION_MISSING_PARAM, { metadata: { param: 'var' } });
19
+ }
20
+ if (!inExpr || typeof inExpr !== 'string') {
21
+ throw new ActionError(action, 'loop action requires "in" parameter', ErrorCodes.ACTION_MISSING_PARAM, { metadata: { param: 'in' } });
22
+ }
23
+ if (!body || !Array.isArray(body)) {
24
+ throw new ActionError(action, 'loop action requires "body" parameter (array of actions)', ErrorCodes.ACTION_MISSING_PARAM, { metadata: { param: 'body' } });
25
+ }
26
+ // 求值 in 表达式,获取要遍历的数组或对象
27
+ const iterable = evaluate(inExpr, ctx);
28
+ if (iterable == null) {
29
+ return;
30
+ }
31
+ // 遍历数组
32
+ if (Array.isArray(iterable)) {
33
+ for (let i = 0; i < iterable.length; i++) {
34
+ // 使用对象池创建循环上下文
35
+ const loopCtx = createLoopContext(ctx, iterable[i], i);
36
+ loopCtx[varName] = iterable[i];
37
+ try {
38
+ // 触发缓存失效,确保表达式重新求值
39
+ invalidateCache(varName, loopCtx);
40
+ await execute(body, loopCtx);
41
+ }
42
+ finally {
43
+ // 释放循环上下文回对象池
44
+ releaseLoopContext(loopCtx);
45
+ }
46
+ }
47
+ }
48
+ // 遍历对象
49
+ else if (typeof iterable === 'object' && iterable !== null) {
50
+ const entries = Object.entries(iterable);
51
+ for (let i = 0; i < entries.length; i++) {
52
+ const [, value] = entries[i];
53
+ // 使用对象池创建循环上下文
54
+ const loopCtx = createLoopContext(ctx, value, i);
55
+ loopCtx[varName] = value;
56
+ try {
57
+ // 触发缓存失效,确保表达式重新求值
58
+ invalidateCache(varName, loopCtx);
59
+ await execute(body, loopCtx);
60
+ }
61
+ finally {
62
+ // 释放循环上下文回对象池
63
+ releaseLoopContext(loopCtx);
64
+ }
65
+ }
66
+ }
67
+ else {
68
+ throw new ActionError(action, `loop "in" expression must evaluate to an array or object, got ${typeof iterable}`, ErrorCodes.ACTION_INVALID_PARAM, { metadata: { param: 'in', actualType: typeof iterable } });
69
+ }
70
+ }
71
+ //# sourceMappingURL=loop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop.js","sourceRoot":"","sources":["../../../src/vm/handlers/loop.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAEtF;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAmB,EACnB,MAAc;IAEd,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE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
+ * navigate 动作处理器
3
+ *
4
+ * 功能:路由导航
5
+ * 示例:{ "type": "navigate", "to": "/users/123" }
6
+ */
7
+ import type { RuntimeContext, Action } from '../../types.js';
8
+ /**
9
+ * 处理 navigate 动作
10
+ */
11
+ export declare function handleNavigate(ctx: RuntimeContext, action: Action): Promise<void>;
12
+ //# sourceMappingURL=navigate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigate.d.ts","sourceRoot":"","sources":["../../../src/vm/handlers/navigate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAIxD;;GAEG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CA8Cf"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * navigate 动作处理器
3
+ *
4
+ * 功能:路由导航
5
+ * 示例:{ "type": "navigate", "to": "/users/123" }
6
+ */
7
+ import { ActionError, ErrorCodes } from '../../errors.js';
8
+ import { evaluate } from '../../expression/evaluate.js';
9
+ /**
10
+ * 处理 navigate 动作
11
+ */
12
+ export async function handleNavigate(ctx, action) {
13
+ const { to } = action;
14
+ if (!to || typeof to !== 'string') {
15
+ throw new ActionError(action, 'navigate action requires "to" parameter', ErrorCodes.ACTION_MISSING_PARAM, { metadata: { param: 'to' } });
16
+ }
17
+ // 求值 to(支持表达式)
18
+ let finalTo = to;
19
+ if (to.startsWith('{{') && to.endsWith('}}')) {
20
+ const expr = to.slice(2, -2).trim();
21
+ const result = evaluate(expr, ctx);
22
+ if (typeof result !== 'string') {
23
+ throw new ActionError(action, `navigate "to" expression must evaluate to a string, got ${typeof result}`, ErrorCodes.ACTION_INVALID_PARAM, { metadata: { param: 'to', actualType: typeof result } });
24
+ }
25
+ finalTo = result;
26
+ }
27
+ // 调用路由导航方法(如果已注册)
28
+ const navigateHandler = ctx.$methods['navigate'] || ctx.$methods['$navigate'];
29
+ if (navigateHandler) {
30
+ await navigateHandler(ctx, { to: finalTo });
31
+ }
32
+ else {
33
+ // 如果没有注册导航方法,使用默认行为(浏览器导航)
34
+ // 使用类型安全的 window 访问
35
+ if (typeof window !== 'undefined' && window.location) {
36
+ window.location.href = finalTo;
37
+ }
38
+ else {
39
+ throw new ActionError(action, 'navigate method not registered and window.location is not available', ErrorCodes.ACTION_EXECUTION_ERROR, { metadata: { reason: 'navigate_not_available' } });
40
+ }
41
+ }
42
+ }
43
+ //# sourceMappingURL=navigate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigate.js","sourceRoot":"","sources":["../../../src/vm/handlers/navigate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,GAAmB,EACnB,MAAc;IAEd,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,CAAA;IAErB,IAAI,CAAC,EAAE,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;QAClC,MAAM,IAAI,WAAW,CACnB,MAAM,EACN,yCAAyC,EACzC,UAAU,CAAC,oBAAoB,EAC/B,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAC9B,CAAA;IACH,CAAC;IAED,eAAe;IACf,IAAI,OAAO,GAAW,EAAE,CAAA;IACxB,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QACnC,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QAClC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,MAAM,IAAI,WAAW,CACnB,MAAM,EACN,2DAA2D,OAAO,MAAM,EAAE,EAC1E,UAAU,CAAC,oBAAoB,EAC/B,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,MAAM,EAAE,EAAE,CACzD,CAAA;QACH,CAAC;QACD,OAAO,GAAG,MAAM,CAAA;IAClB,CAAC;IAED,kBAAkB;IAClB,MAAM,eAAe,GAAG,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;IAC7E,IAAI,eAAe,EAAE,CAAC;QACpB,MAAM,eAAe,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;IAC7C,CAAC;SAAM,CAAC;QACN,2BAA2B;QAC3B,oBAAoB;QACpB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAK,MAA0C,CAAC,QAAQ,EAAE,CAAC;YACxF,MAAqD,CAAC,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAA;QACjF,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,WAAW,CACnB,MAAM,EACN,qEAAqE,EACrE,UAAU,CAAC,sBAAsB,EACjC,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,wBAAwB,EAAE,EAAE,CACnD,CAAA;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * set 动作处理器
3
+ *
4
+ * 功能:修改状态
5
+ * 示例:{ "type": "set", "path": "user.name", "value": "张三" }
6
+ *
7
+ * 注意:缓存失效通过 RuntimeContext 的 onStateChange 钩子处理
8
+ * 框架集成层应在创建上下文时注册该钩子
9
+ */
10
+ import type { RuntimeContext, Action } from '../../types.js';
11
+ /**
12
+ * 处理 set 动作
13
+ */
14
+ export declare function handleSet(ctx: RuntimeContext, action: Action): Promise<void>;
15
+ //# sourceMappingURL=set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../../../src/vm/handlers/set.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAIxD;;GAEG;AACH,wBAAsB,SAAS,CAC7B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAsBf"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * set 动作处理器
3
+ *
4
+ * 功能:修改状态
5
+ * 示例:{ "type": "set", "path": "user.name", "value": "张三" }
6
+ *
7
+ * 注意:缓存失效通过 RuntimeContext 的 onStateChange 钩子处理
8
+ * 框架集成层应在创建上下文时注册该钩子
9
+ */
10
+ import { ActionError, ErrorCodes } from '../../errors.js';
11
+ import { evaluate } from '../../expression/evaluate.js';
12
+ /**
13
+ * 处理 set 动作
14
+ */
15
+ export async function handleSet(ctx, action) {
16
+ const { path, value } = action;
17
+ if (!path || typeof path !== 'string') {
18
+ throw new ActionError(action, 'set action requires "path" parameter', ErrorCodes.ACTION_MISSING_PARAM, { metadata: { param: 'path' } });
19
+ }
20
+ // 求值 value(支持表达式)
21
+ let finalValue = value;
22
+ if (typeof value === 'string' && value.startsWith('{{') && value.endsWith('}}')) {
23
+ // 表达式插值:{{ user.age + 1 }}
24
+ const expr = value.slice(2, -2).trim();
25
+ finalValue = evaluate(expr, ctx);
26
+ }
27
+ // 设置状态(缓存失效通过 onStateChange 钩子自动处理)
28
+ ctx._set(path, finalValue);
29
+ }
30
+ //# sourceMappingURL=set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set.js","sourceRoot":"","sources":["../../../src/vm/handlers/set.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,GAAmB,EACnB,MAAc;IAEd,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IAE9B,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC,MAAM,IAAI,WAAW,CACnB,MAAM,EACN,sCAAsC,EACtC,UAAU,CAAC,oBAAoB,EAC/B,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAChC,CAAA;IACH,CAAC;IAED,kBAAkB;IAClB,IAAI,UAAU,GAAG,KAAK,CAAA;IACtB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAChF,2BAA2B;QAC3B,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QACtC,UAAU,GAAG,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAClC,CAAC;IAED,oCAAoC;IACpC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;AAC5B,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * VM 模块导出
3
+ */
4
+ export { execute } from './executor.js';
5
+ export type { ExecuteOptions } from './executor.js';
6
+ export { registerBuiltinMethods } from './handlers/index.js';
7
+ export * from './errors.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vm/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAC5D,cAAc,aAAa,CAAA"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * VM 模块导出
3
+ */
4
+ export { execute } from './executor.js';
5
+ export { registerBuiltinMethods } from './handlers/index.js';
6
+ export * from './errors.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/vm/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAC5D,cAAc,aAAa,CAAA"}