assistsx-js 0.0.2049 → 0.0.2050

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/Step.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Node } from "./Node";
2
+ import { StepError } from "./StepError";
2
3
  import { StepAsync } from "./StepAsync";
3
4
  export type StepResult = Step | undefined;
4
5
  export type StepImpl = (step: Step) => Promise<StepResult>;
@@ -16,6 +17,10 @@ export declare class Step {
16
17
  * 步骤拦截器列表
17
18
  */
18
19
  private static _interceptors;
20
+ /**
21
+ * 步骤异常变量,默认为空
22
+ */
23
+ static exception: StepError | undefined;
19
24
  /**
20
25
  * 运行步骤实现
21
26
  * @param impl 步骤实现函数
@@ -46,8 +51,9 @@ export declare class Step {
46
51
  static assignIdsToNodes(nodes: Node[], stepId: string | undefined): void;
47
52
  /**
48
53
  * 停止当前步骤执行
54
+ * @param exception 可选的异常对象,如果传入则使用该异常,否则使用默认的StepStopError
49
55
  */
50
- static stop(): void;
56
+ static stop(exception?: StepError): void;
51
57
  /**
52
58
  * 添加步骤拦截器
53
59
  * @param interceptor 拦截器函数
package/dist/Step.js CHANGED
@@ -5,7 +5,7 @@
5
5
  import { AssistsX } from "./AssistsX";
6
6
  import { useStepStore } from "./StepStateStore";
7
7
  import { generateUUID } from "./Utils";
8
- import { StepError } from "./StepError";
8
+ import { StepError, StepStopError } from "./StepError";
9
9
  import { StepAsync } from "./StepAsync";
10
10
  export class Step {
11
11
  /**
@@ -17,6 +17,7 @@ export class Step {
17
17
  */
18
18
  static async run(impl, { stepId, tag, data, delayMs = Step.delayMsDefault, } = {}) {
19
19
  var _a, _b, _c, _d, _e, _f;
20
+ this.exception = undefined;
20
21
  const stepStore = useStepStore();
21
22
  let implnName = impl.name;
22
23
  let currentStep;
@@ -131,7 +132,7 @@ export class Step {
131
132
  error: (_f = e === null || e === void 0 ? void 0 : e.message) !== null && _f !== void 0 ? _f : String(e),
132
133
  });
133
134
  stepStore.setError(errorMsg);
134
- throw new StepError(errorMsg, implnName, tag, data, e, currentStep || undefined);
135
+ throw e;
135
136
  }
136
137
  //步骤执行结束
137
138
  stepStore.completeStep();
@@ -148,11 +149,12 @@ export class Step {
148
149
  * @param stepId 要验证的步骤ID
149
150
  */
150
151
  static assert(stepId) {
152
+ // 检查异常变量,如果不为空则直接抛出
153
+ if (Step.exception) {
154
+ throw Step.exception;
155
+ }
151
156
  if (stepId && Step.stepId != stepId) {
152
- if (Step.stepId === "STEP_STOP") {
153
- throw new Error("主动中断步骤");
154
- }
155
- throw new Error("StepId mismatch");
157
+ throw new StepError("StepId mismatch", { stepId, currentStepId: Step.stepId });
156
158
  }
157
159
  }
158
160
  /**
@@ -169,9 +171,16 @@ export class Step {
169
171
  }
170
172
  /**
171
173
  * 停止当前步骤执行
174
+ * @param exception 可选的异常对象,如果传入则使用该异常,否则使用默认的StepStopError
172
175
  */
173
- static stop() {
176
+ static stop(exception) {
174
177
  this._stepId = "STEP_STOP";
178
+ if (exception) {
179
+ this.exception = exception;
180
+ }
181
+ else {
182
+ this.exception = new StepStopError("主动中断步骤", { stepId: this._stepId });
183
+ }
175
184
  }
176
185
  /**
177
186
  * 添加步骤拦截器
@@ -622,3 +631,7 @@ Step._stepId = undefined;
622
631
  * 步骤拦截器列表
623
632
  */
624
633
  Step._interceptors = [];
634
+ /**
635
+ * 步骤异常变量,默认为空
636
+ */
637
+ Step.exception = undefined;
@@ -1,27 +1,35 @@
1
1
  /**
2
2
  * 步骤执行错误类
3
3
  * 用于携带步骤执行过程中的错误信息和当前步骤对象
4
+ * 支持传入可选数据:message,data任何类型的数据
4
5
  */
5
6
  export declare class StepError extends Error {
6
7
  /**
7
8
  * 步骤实现函数名
8
9
  */
9
- readonly impl: string;
10
+ readonly impl?: string;
10
11
  /**
11
12
  * 步骤标签
12
13
  */
13
- readonly tag: string | undefined;
14
+ readonly tag?: string | undefined;
14
15
  /**
15
- * 步骤数据
16
+ * 步骤数据,可以是任何类型
16
17
  */
17
- readonly data: any | undefined;
18
+ readonly data?: any;
18
19
  /**
19
20
  * 原始错误
20
21
  */
21
- readonly originalError: any;
22
+ readonly originalError?: any;
22
23
  /**
23
24
  * 当前步骤对象
24
25
  */
25
- readonly currentStep: any | undefined;
26
- constructor(message: string, impl: string, tag: string | undefined, data: any | undefined, originalError: any, currentStep: any | undefined);
26
+ readonly currentStep?: any;
27
+ constructor(message?: string, data?: any, impl?: string, tag?: string | undefined, originalError?: any, currentStep?: any | undefined);
28
+ }
29
+ /**
30
+ * 主动停止异常类
31
+ * 用于表示步骤被主动停止执行
32
+ */
33
+ export declare class StepStopError extends StepError {
34
+ constructor(message?: string, data?: any);
27
35
  }
package/dist/StepError.js CHANGED
@@ -1,15 +1,26 @@
1
1
  /**
2
2
  * 步骤执行错误类
3
3
  * 用于携带步骤执行过程中的错误信息和当前步骤对象
4
+ * 支持传入可选数据:message,data任何类型的数据
4
5
  */
5
6
  export class StepError extends Error {
6
- constructor(message, impl, tag, data, originalError, currentStep) {
7
+ constructor(message, data, impl, tag, originalError, currentStep) {
7
8
  super(message);
8
9
  this.name = "StepError";
10
+ this.data = data;
9
11
  this.impl = impl;
10
12
  this.tag = tag;
11
- this.data = data;
12
13
  this.originalError = originalError;
13
14
  this.currentStep = currentStep;
14
15
  }
15
16
  }
17
+ /**
18
+ * 主动停止异常类
19
+ * 用于表示步骤被主动停止执行
20
+ */
21
+ export class StepStopError extends StepError {
22
+ constructor(message, data) {
23
+ super(message || "主动中断步骤", data);
24
+ this.name = "StepStopError";
25
+ }
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assistsx-js",
3
- "version": "0.0.2049",
3
+ "version": "0.0.2050",
4
4
  "description": "assistsx-js自动化开发SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/Step.ts CHANGED
@@ -7,7 +7,7 @@ import { Node } from "./Node";
7
7
  import { CallMethod } from "./CallMethod";
8
8
  import { useStepStore } from "./StepStateStore";
9
9
  import { generateUUID } from "./Utils";
10
- import { StepError } from "./StepError";
10
+ import { StepError, StepStopError } from "./StepError";
11
11
  import { StepAsync } from "./StepAsync";
12
12
 
13
13
  // 步骤结果类型,可以是Step实例或undefined
@@ -35,6 +35,11 @@ export class Step {
35
35
  */
36
36
  private static _interceptors: StepInterceptor[] = [];
37
37
 
38
+ /**
39
+ * 步骤异常变量,默认为空
40
+ */
41
+ public static exception: StepError | undefined = undefined;
42
+
38
43
  /**
39
44
  * 运行步骤实现
40
45
  * @param impl 步骤实现函数
@@ -56,6 +61,7 @@ export class Step {
56
61
  delayMs?: number;
57
62
  } = {}
58
63
  ): Promise<Step | undefined> {
64
+ this.exception = undefined;
59
65
  const stepStore = useStepStore();
60
66
  let implnName = impl.name;
61
67
  let currentStep: Step | undefined;
@@ -180,14 +186,7 @@ export class Step {
180
186
  error: e?.message ?? String(e),
181
187
  });
182
188
  stepStore.setError(errorMsg);
183
- throw new StepError(
184
- errorMsg,
185
- implnName,
186
- tag,
187
- data,
188
- e,
189
- currentStep || undefined
190
- );
189
+ throw e
191
190
  }
192
191
  //步骤执行结束
193
192
  stepStore.completeStep();
@@ -206,11 +205,12 @@ export class Step {
206
205
  * @param stepId 要验证的步骤ID
207
206
  */
208
207
  static assert(stepId: string | undefined) {
208
+ // 检查异常变量,如果不为空则直接抛出
209
+ if (Step.exception) {
210
+ throw Step.exception;
211
+ }
209
212
  if (stepId && Step.stepId != stepId) {
210
- if (Step.stepId === "STEP_STOP") {
211
- throw new Error("主动中断步骤");
212
- }
213
- throw new Error("StepId mismatch");
213
+ throw new StepError("StepId mismatch", { stepId, currentStepId: Step.stepId });
214
214
  }
215
215
  }
216
216
 
@@ -229,9 +229,15 @@ export class Step {
229
229
 
230
230
  /**
231
231
  * 停止当前步骤执行
232
+ * @param exception 可选的异常对象,如果传入则使用该异常,否则使用默认的StepStopError
232
233
  */
233
- static stop(): void {
234
+ static stop(exception?: StepError): void {
234
235
  this._stepId = "STEP_STOP";
236
+ if (exception) {
237
+ this.exception = exception;
238
+ } else {
239
+ this.exception = new StepStopError("主动中断步骤", { stepId: this._stepId });
240
+ }
235
241
  }
236
242
 
237
243
  /**
package/src/StepError.ts CHANGED
@@ -1,47 +1,59 @@
1
1
  /**
2
2
  * 步骤执行错误类
3
3
  * 用于携带步骤执行过程中的错误信息和当前步骤对象
4
+ * 支持传入可选数据:message,data任何类型的数据
4
5
  */
5
6
  export class StepError extends Error {
6
- /**
7
- * 步骤实现函数名
8
- */
9
- readonly impl: string;
7
+ /**
8
+ * 步骤实现函数名
9
+ */
10
+ readonly impl?: string;
10
11
 
11
- /**
12
- * 步骤标签
13
- */
14
- readonly tag: string | undefined;
12
+ /**
13
+ * 步骤标签
14
+ */
15
+ readonly tag?: string | undefined;
15
16
 
16
- /**
17
- * 步骤数据
18
- */
19
- readonly data: any | undefined;
17
+ /**
18
+ * 步骤数据,可以是任何类型
19
+ */
20
+ readonly data?: any;
20
21
 
21
- /**
22
- * 原始错误
23
- */
24
- readonly originalError: any;
22
+ /**
23
+ * 原始错误
24
+ */
25
+ readonly originalError?: any;
25
26
 
26
- /**
27
- * 当前步骤对象
28
- */
29
- readonly currentStep: any | undefined;
27
+ /**
28
+ * 当前步骤对象
29
+ */
30
+ readonly currentStep?: any;
30
31
 
31
- constructor(
32
- message: string,
33
- impl: string,
34
- tag: string | undefined,
35
- data: any | undefined,
36
- originalError: any,
37
- currentStep: any | undefined
38
- ) {
39
- super(message);
40
- this.name = "StepError";
41
- this.impl = impl;
42
- this.tag = tag;
43
- this.data = data;
44
- this.originalError = originalError;
45
- this.currentStep = currentStep;
46
- }
32
+ constructor(
33
+ message?: string,
34
+ data?: any,
35
+ impl?: string,
36
+ tag?: string | undefined,
37
+ originalError?: any,
38
+ currentStep?: any | undefined
39
+ ) {
40
+ super(message);
41
+ this.name = "StepError";
42
+ this.data = data;
43
+ this.impl = impl;
44
+ this.tag = tag;
45
+ this.originalError = originalError;
46
+ this.currentStep = currentStep;
47
+ }
48
+ }
49
+
50
+ /**
51
+ * 主动停止异常类
52
+ * 用于表示步骤被主动停止执行
53
+ */
54
+ export class StepStopError extends StepError {
55
+ constructor(message?: string, data?: any) {
56
+ super(message || "主动中断步骤", data);
57
+ this.name = "StepStopError";
58
+ }
47
59
  }