duron 0.3.0-beta.9 → 0.3.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.
- package/dist/action-job.d.ts +33 -2
- package/dist/action-job.d.ts.map +1 -1
- package/dist/action-job.js +88 -23
- package/dist/action-manager.d.ts +44 -2
- package/dist/action-manager.d.ts.map +1 -1
- package/dist/action-manager.js +64 -3
- package/dist/action.d.ts +388 -7
- package/dist/action.d.ts.map +1 -1
- package/dist/action.js +44 -23
- package/dist/adapters/adapter.d.ts +365 -8
- package/dist/adapters/adapter.d.ts.map +1 -1
- package/dist/adapters/adapter.js +221 -15
- package/dist/adapters/postgres/base.d.ts +184 -6
- package/dist/adapters/postgres/base.d.ts.map +1 -1
- package/dist/adapters/postgres/base.js +436 -75
- package/dist/adapters/postgres/pglite.d.ts +37 -0
- package/dist/adapters/postgres/pglite.d.ts.map +1 -1
- package/dist/adapters/postgres/pglite.js +38 -0
- package/dist/adapters/postgres/postgres.d.ts +35 -0
- package/dist/adapters/postgres/postgres.d.ts.map +1 -1
- package/dist/adapters/postgres/postgres.js +42 -0
- package/dist/adapters/postgres/schema.d.ts +150 -37
- package/dist/adapters/postgres/schema.d.ts.map +1 -1
- package/dist/adapters/postgres/schema.default.d.ts +151 -38
- package/dist/adapters/postgres/schema.default.d.ts.map +1 -1
- package/dist/adapters/postgres/schema.default.js +2 -2
- package/dist/adapters/postgres/schema.js +60 -23
- package/dist/adapters/schemas.d.ts +124 -80
- package/dist/adapters/schemas.d.ts.map +1 -1
- package/dist/adapters/schemas.js +139 -26
- package/dist/client.d.ts +426 -22
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +370 -20
- package/dist/constants.js +6 -0
- package/dist/errors.d.ts +140 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +152 -9
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/server.d.ts +99 -37
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +84 -25
- package/dist/step-manager.d.ts +111 -4
- package/dist/step-manager.d.ts.map +1 -1
- package/dist/step-manager.js +403 -75
- package/dist/telemetry/index.d.ts +1 -4
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +2 -4
- package/dist/telemetry/local-span-exporter.d.ts +56 -0
- package/dist/telemetry/local-span-exporter.d.ts.map +1 -0
- package/dist/telemetry/local-span-exporter.js +118 -0
- package/dist/utils/p-retry.d.ts +5 -0
- package/dist/utils/p-retry.d.ts.map +1 -1
- package/dist/utils/p-retry.js +8 -0
- package/dist/utils/wait-for-abort.d.ts +1 -0
- package/dist/utils/wait-for-abort.d.ts.map +1 -1
- package/dist/utils/wait-for-abort.js +1 -0
- package/migrations/postgres/{20260119153838_flimsy_thor_girl → 20260121160012_normal_bloodstrike}/migration.sql +32 -20
- package/migrations/postgres/{20260119153838_flimsy_thor_girl → 20260121160012_normal_bloodstrike}/snapshot.json +241 -66
- package/package.json +42 -26
- package/src/action-job.ts +33 -29
- package/src/action-manager.ts +5 -5
- package/src/action.ts +317 -149
- package/src/adapters/adapter.ts +54 -54
- package/src/adapters/postgres/base.ts +266 -86
- package/src/adapters/postgres/schema.default.ts +2 -2
- package/src/adapters/postgres/schema.ts +52 -24
- package/src/adapters/schemas.ts +91 -36
- package/src/client.ts +322 -68
- package/src/errors.ts +84 -12
- package/src/index.ts +2 -0
- package/src/server.ts +39 -37
- package/src/step-manager.ts +246 -95
- package/src/telemetry/index.ts +2 -20
- package/src/telemetry/local-span-exporter.ts +148 -0
- package/dist/telemetry/adapter.d.ts +0 -107
- package/dist/telemetry/adapter.d.ts.map +0 -1
- package/dist/telemetry/adapter.js +0 -134
- package/dist/telemetry/local.d.ts +0 -22
- package/dist/telemetry/local.d.ts.map +0 -1
- package/dist/telemetry/local.js +0 -243
- package/dist/telemetry/noop.d.ts +0 -17
- package/dist/telemetry/noop.d.ts.map +0 -1
- package/dist/telemetry/noop.js +0 -66
- package/dist/telemetry/opentelemetry.d.ts +0 -25
- package/dist/telemetry/opentelemetry.d.ts.map +0 -1
- package/dist/telemetry/opentelemetry.js +0 -312
- package/src/telemetry/adapter.ts +0 -642
- package/src/telemetry/local.ts +0 -429
- package/src/telemetry/noop.ts +0 -141
- package/src/telemetry/opentelemetry.ts +0 -453
package/dist/constants.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Job Status Constants
|
|
3
|
+
// ============================================================================
|
|
1
4
|
export const JOB_STATUS_CREATED = 'created';
|
|
2
5
|
export const JOB_STATUS_ACTIVE = 'active';
|
|
3
6
|
export const JOB_STATUS_COMPLETED = 'completed';
|
|
@@ -10,6 +13,9 @@ export const JOB_STATUSES = [
|
|
|
10
13
|
JOB_STATUS_FAILED,
|
|
11
14
|
JOB_STATUS_CANCELLED,
|
|
12
15
|
];
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Step Status Constants
|
|
18
|
+
// ============================================================================
|
|
13
19
|
export const STEP_STATUS_ACTIVE = 'active';
|
|
14
20
|
export const STEP_STATUS_COMPLETED = 'completed';
|
|
15
21
|
export const STEP_STATUS_FAILED = 'failed';
|
package/dist/errors.d.ts
CHANGED
|
@@ -8,62 +8,199 @@ export declare const ERROR_CODES: {
|
|
|
8
8
|
readonly UNHANDLED_CHILD_STEPS: "UNHANDLED_CHILD_STEPS";
|
|
9
9
|
};
|
|
10
10
|
export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
|
11
|
+
/**
|
|
12
|
+
* Metadata about the context where an error occurred.
|
|
13
|
+
*/
|
|
14
|
+
export interface ErrorMetadata {
|
|
15
|
+
jobId?: string;
|
|
16
|
+
stepId?: string;
|
|
17
|
+
parentStepId?: string | null;
|
|
18
|
+
actionName?: string;
|
|
19
|
+
stepName?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Base class for all built-in errors in Duron.
|
|
23
|
+
* All errors include a cause property that can be serialized.
|
|
24
|
+
*/
|
|
11
25
|
export declare abstract class DuronError extends Error {
|
|
26
|
+
/**
|
|
27
|
+
* Error code for type checking without instanceof.
|
|
28
|
+
*/
|
|
12
29
|
readonly code: ErrorCode;
|
|
30
|
+
/**
|
|
31
|
+
* Whether this error should prevent retries.
|
|
32
|
+
*/
|
|
13
33
|
readonly nonRetriable: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The underlying cause of the error, if any.
|
|
36
|
+
*
|
|
37
|
+
* This will be serialized and stored in the database.
|
|
38
|
+
*/
|
|
14
39
|
readonly cause?: unknown;
|
|
40
|
+
/**
|
|
41
|
+
* Metadata about the context where the error occurred.
|
|
42
|
+
*/
|
|
43
|
+
metadata: ErrorMetadata;
|
|
15
44
|
constructor(message: string, options?: {
|
|
45
|
+
/**
|
|
46
|
+
* The underlying cause of the error, if any.
|
|
47
|
+
*
|
|
48
|
+
* This will be serialized and stored in the database.
|
|
49
|
+
*/
|
|
16
50
|
cause?: unknown;
|
|
51
|
+
/**
|
|
52
|
+
* Metadata about the context where the error occurred.
|
|
53
|
+
*/
|
|
54
|
+
metadata?: ErrorMetadata;
|
|
17
55
|
});
|
|
56
|
+
/**
|
|
57
|
+
* Set or update metadata about the context where the error occurred.
|
|
58
|
+
* Merges with existing metadata (new values override existing ones).
|
|
59
|
+
*
|
|
60
|
+
* @param metadata - The metadata to set or merge
|
|
61
|
+
* @returns this - Returns the error instance for chaining
|
|
62
|
+
*/
|
|
63
|
+
setMetadata(metadata: ErrorMetadata): this;
|
|
18
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Error thrown when attempting to execute a step that has already been executed.
|
|
67
|
+
*/
|
|
19
68
|
export declare class StepAlreadyExecutedError extends DuronError {
|
|
20
69
|
readonly code: "STEP_ALREADY_EXECUTED";
|
|
21
70
|
readonly nonRetriable = true;
|
|
71
|
+
/**
|
|
72
|
+
* Create a new StepAlreadyExecutedError.
|
|
73
|
+
*
|
|
74
|
+
* @param stepName - The name of the step that was already executed
|
|
75
|
+
* @param jobId - The ID of the job containing the step
|
|
76
|
+
* @param actionName - The name of the action containing the step
|
|
77
|
+
*/
|
|
22
78
|
constructor(stepName: string, jobId: string, actionName: string);
|
|
23
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* NonRetriableError indicates that a step should not be retried.
|
|
82
|
+
*
|
|
83
|
+
* If a step handler throws this error, the step will fail immediately
|
|
84
|
+
* without retrying, even if retry options are configured.
|
|
85
|
+
*/
|
|
24
86
|
export declare class NonRetriableError extends DuronError {
|
|
25
87
|
readonly code: ErrorCode;
|
|
26
88
|
readonly nonRetriable = true;
|
|
27
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Error thrown when an action exceeds its timeout.
|
|
92
|
+
*/
|
|
28
93
|
export declare class ActionTimeoutError extends DuronError {
|
|
29
94
|
readonly code: "ACTION_TIMEOUT";
|
|
30
95
|
readonly nonRetriable = true;
|
|
31
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Create a new ActionTimeoutError.
|
|
98
|
+
*
|
|
99
|
+
* @param actionName - The name of the action that timed out
|
|
100
|
+
* @param jobId - The ID of the job containing the action
|
|
101
|
+
* @param timeoutMs - The timeout value in milliseconds
|
|
102
|
+
* @param options - Optional error options including cause
|
|
103
|
+
*/
|
|
104
|
+
constructor(actionName: string, jobId: string, timeoutMs: number, options?: {
|
|
32
105
|
cause?: unknown;
|
|
33
106
|
});
|
|
34
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Error thrown when a step exceeds its timeout.
|
|
110
|
+
*/
|
|
35
111
|
export declare class StepTimeoutError extends DuronError {
|
|
36
112
|
readonly code: "STEP_TIMEOUT";
|
|
37
113
|
readonly nonRetriable = false;
|
|
114
|
+
/**
|
|
115
|
+
* Create a new StepTimeoutError.
|
|
116
|
+
*
|
|
117
|
+
* @param stepName - The name of the step that timed out
|
|
118
|
+
* @param jobId - The ID of the job containing the step
|
|
119
|
+
* @param timeoutMs - The timeout value in milliseconds
|
|
120
|
+
* @param options - Optional error options including cause and additional metadata
|
|
121
|
+
*/
|
|
38
122
|
constructor(stepName: string, jobId: string, timeoutMs: number, options?: {
|
|
39
123
|
cause?: unknown;
|
|
124
|
+
stepId?: string;
|
|
125
|
+
parentStepId?: string | null;
|
|
126
|
+
actionName?: string;
|
|
40
127
|
});
|
|
41
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Error thrown when an action is cancelled.
|
|
131
|
+
*/
|
|
42
132
|
export declare class ActionCancelError extends DuronError {
|
|
43
133
|
readonly code: "ACTION_CANCEL";
|
|
44
134
|
readonly nonRetriable = true;
|
|
135
|
+
/**
|
|
136
|
+
* Create a new ActionCancelError.
|
|
137
|
+
*
|
|
138
|
+
* @param actionName - The name of the action that was cancelled
|
|
139
|
+
* @param jobId - The ID of the job containing the action
|
|
140
|
+
* @param options - Optional error options including cause
|
|
141
|
+
*/
|
|
45
142
|
constructor(actionName: string, jobId: string, options?: {
|
|
46
143
|
cause?: unknown;
|
|
47
144
|
});
|
|
48
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Error thrown when a parent step completes with unhandled (non-awaited) child steps.
|
|
148
|
+
*
|
|
149
|
+
* This error indicates a bug in the action handler where child steps were started
|
|
150
|
+
* but not properly awaited. All child steps must be awaited before the parent returns.
|
|
151
|
+
*/
|
|
49
152
|
export declare class UnhandledChildStepsError extends NonRetriableError {
|
|
50
153
|
readonly code: "UNHANDLED_CHILD_STEPS";
|
|
51
|
-
|
|
154
|
+
/**
|
|
155
|
+
* The number of unhandled child steps.
|
|
156
|
+
*/
|
|
52
157
|
readonly pendingCount: number;
|
|
53
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Create a new UnhandledChildStepsError.
|
|
160
|
+
*
|
|
161
|
+
* @param stepName - The name of the parent step
|
|
162
|
+
* @param pendingCount - The number of unhandled child steps
|
|
163
|
+
* @param options - Optional metadata
|
|
164
|
+
*/
|
|
165
|
+
constructor(stepName: string, pendingCount: number, options?: {
|
|
166
|
+
stepId?: string;
|
|
167
|
+
parentStepId?: string | null;
|
|
168
|
+
jobId?: string;
|
|
169
|
+
actionName?: string;
|
|
170
|
+
});
|
|
54
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Checks if an error is a DuronError instance.
|
|
174
|
+
*/
|
|
55
175
|
export declare function isDuronError(error: unknown): error is DuronError;
|
|
176
|
+
/**
|
|
177
|
+
* Checks if an error is a NonRetriableError instance.
|
|
178
|
+
*/
|
|
56
179
|
export declare function isNonRetriableError(error: unknown): error is NonRetriableError;
|
|
180
|
+
/**
|
|
181
|
+
* Checks if an error is an UnhandledChildStepsError instance.
|
|
182
|
+
*/
|
|
57
183
|
export declare function isUnhandledChildStepsError(error: unknown): error is UnhandledChildStepsError;
|
|
184
|
+
/**
|
|
185
|
+
* Checks if an error is a timeout error (ActionTimeoutError or StepTimeoutError).
|
|
186
|
+
*/
|
|
58
187
|
export declare function isTimeoutError(error: unknown): error is ActionTimeoutError | StepTimeoutError;
|
|
188
|
+
/**
|
|
189
|
+
* Checks if an error is a cancel error (ActionCancelError or StepCancelError).
|
|
190
|
+
*/
|
|
59
191
|
export declare function isCancelError(error: unknown): error is ActionCancelError;
|
|
60
192
|
export type SerializableError = {
|
|
61
193
|
name: string;
|
|
62
194
|
message: string;
|
|
63
195
|
code?: ErrorCode;
|
|
64
196
|
nonRetriable?: boolean;
|
|
197
|
+
metadata?: ErrorMetadata;
|
|
65
198
|
cause?: unknown;
|
|
66
199
|
stack?: string;
|
|
67
200
|
};
|
|
201
|
+
/**
|
|
202
|
+
* Serializes an error for storage in the database.
|
|
203
|
+
* Handles DuronError instances specially to preserve their type information.
|
|
204
|
+
*/
|
|
68
205
|
export declare function serializeError(error: unknown): SerializableError;
|
|
69
206
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW;;;;;;;;CAQd,CAAA;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AE,MAAM,CAAA;QACf,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;QAC5B,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,UAAU,CAAC,EAAE,MAAM,CAAA;KACpB;CAgBJ;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAGhE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAE9E;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,wBAAwB,CAE5F;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,GAAG,gBAAgB,CAG7F;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAExE;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,EAAE,aAAa,CAAA;IACxB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,CA0ChE"}
|
package/dist/errors.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Error codes for type checking without instanceof
|
|
1
2
|
export const ERROR_CODES = {
|
|
2
3
|
DURON_ERROR: 'DURON_ERROR',
|
|
3
4
|
STEP_ALREADY_EXECUTED: 'STEP_ALREADY_EXECUTED',
|
|
@@ -7,87 +8,228 @@ export const ERROR_CODES = {
|
|
|
7
8
|
ACTION_CANCEL: 'ACTION_CANCEL',
|
|
8
9
|
UNHANDLED_CHILD_STEPS: 'UNHANDLED_CHILD_STEPS',
|
|
9
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Base class for all built-in errors in Duron.
|
|
13
|
+
* All errors include a cause property that can be serialized.
|
|
14
|
+
*/
|
|
10
15
|
export class DuronError extends Error {
|
|
16
|
+
/**
|
|
17
|
+
* Error code for type checking without instanceof.
|
|
18
|
+
*/
|
|
11
19
|
code = ERROR_CODES.DURON_ERROR;
|
|
20
|
+
/**
|
|
21
|
+
* Whether this error should prevent retries.
|
|
22
|
+
*/
|
|
12
23
|
nonRetriable = false;
|
|
24
|
+
/**
|
|
25
|
+
* The underlying cause of the error, if any.
|
|
26
|
+
*
|
|
27
|
+
* This will be serialized and stored in the database.
|
|
28
|
+
*/
|
|
13
29
|
cause;
|
|
30
|
+
/**
|
|
31
|
+
* Metadata about the context where the error occurred.
|
|
32
|
+
*/
|
|
33
|
+
metadata;
|
|
14
34
|
constructor(message, options) {
|
|
15
35
|
super(message);
|
|
16
36
|
this.cause = options?.cause;
|
|
37
|
+
this.metadata = options?.metadata ?? {};
|
|
38
|
+
// Set the name to the class name
|
|
17
39
|
this.name = this.constructor.name;
|
|
40
|
+
// Ensure stack trace points to the error location
|
|
18
41
|
if (Error.captureStackTrace) {
|
|
19
42
|
Error.captureStackTrace(this, this.constructor);
|
|
20
43
|
}
|
|
21
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Set or update metadata about the context where the error occurred.
|
|
47
|
+
* Merges with existing metadata (new values override existing ones).
|
|
48
|
+
*
|
|
49
|
+
* @param metadata - The metadata to set or merge
|
|
50
|
+
* @returns this - Returns the error instance for chaining
|
|
51
|
+
*/
|
|
52
|
+
setMetadata(metadata) {
|
|
53
|
+
this.metadata = { ...this.metadata, ...metadata };
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
22
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Error thrown when attempting to execute a step that has already been executed.
|
|
59
|
+
*/
|
|
23
60
|
export class StepAlreadyExecutedError extends DuronError {
|
|
24
61
|
code = ERROR_CODES.STEP_ALREADY_EXECUTED;
|
|
25
62
|
nonRetriable = true;
|
|
63
|
+
/**
|
|
64
|
+
* Create a new StepAlreadyExecutedError.
|
|
65
|
+
*
|
|
66
|
+
* @param stepName - The name of the step that was already executed
|
|
67
|
+
* @param jobId - The ID of the job containing the step
|
|
68
|
+
* @param actionName - The name of the action containing the step
|
|
69
|
+
*/
|
|
26
70
|
constructor(stepName, jobId, actionName) {
|
|
27
|
-
super(`Step "${stepName}" has already been executed for job "${jobId}" and action "${actionName}"
|
|
71
|
+
super(`Step "${stepName}" has already been executed for job "${jobId}" and action "${actionName}"`, {
|
|
72
|
+
metadata: { stepName, jobId, actionName },
|
|
73
|
+
});
|
|
28
74
|
}
|
|
29
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* NonRetriableError indicates that a step should not be retried.
|
|
78
|
+
*
|
|
79
|
+
* If a step handler throws this error, the step will fail immediately
|
|
80
|
+
* without retrying, even if retry options are configured.
|
|
81
|
+
*/
|
|
30
82
|
export class NonRetriableError extends DuronError {
|
|
31
83
|
code = ERROR_CODES.NON_RETRIABLE;
|
|
32
84
|
nonRetriable = true;
|
|
33
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Error thrown when an action exceeds its timeout.
|
|
88
|
+
*/
|
|
34
89
|
export class ActionTimeoutError extends DuronError {
|
|
35
90
|
code = ERROR_CODES.ACTION_TIMEOUT;
|
|
36
91
|
nonRetriable = true;
|
|
37
|
-
|
|
38
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Create a new ActionTimeoutError.
|
|
94
|
+
*
|
|
95
|
+
* @param actionName - The name of the action that timed out
|
|
96
|
+
* @param jobId - The ID of the job containing the action
|
|
97
|
+
* @param timeoutMs - The timeout value in milliseconds
|
|
98
|
+
* @param options - Optional error options including cause
|
|
99
|
+
*/
|
|
100
|
+
constructor(actionName, jobId, timeoutMs, options) {
|
|
101
|
+
super(`Action "${actionName}" in job "${jobId}" timed out after ${timeoutMs}ms`, {
|
|
102
|
+
cause: options?.cause,
|
|
103
|
+
metadata: { actionName, jobId },
|
|
104
|
+
});
|
|
39
105
|
}
|
|
40
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Error thrown when a step exceeds its timeout.
|
|
109
|
+
*/
|
|
41
110
|
export class StepTimeoutError extends DuronError {
|
|
42
111
|
code = ERROR_CODES.STEP_TIMEOUT;
|
|
43
112
|
nonRetriable = false;
|
|
113
|
+
/**
|
|
114
|
+
* Create a new StepTimeoutError.
|
|
115
|
+
*
|
|
116
|
+
* @param stepName - The name of the step that timed out
|
|
117
|
+
* @param jobId - The ID of the job containing the step
|
|
118
|
+
* @param timeoutMs - The timeout value in milliseconds
|
|
119
|
+
* @param options - Optional error options including cause and additional metadata
|
|
120
|
+
*/
|
|
44
121
|
constructor(stepName, jobId, timeoutMs, options) {
|
|
45
|
-
super(`Step "${stepName}" in job "${jobId}" timed out after ${timeoutMs}ms`,
|
|
122
|
+
super(`Step "${stepName}" in job "${jobId}" timed out after ${timeoutMs}ms`, {
|
|
123
|
+
cause: options?.cause,
|
|
124
|
+
metadata: {
|
|
125
|
+
stepName,
|
|
126
|
+
jobId,
|
|
127
|
+
stepId: options?.stepId,
|
|
128
|
+
parentStepId: options?.parentStepId,
|
|
129
|
+
actionName: options?.actionName,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
46
132
|
}
|
|
47
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Error thrown when an action is cancelled.
|
|
136
|
+
*/
|
|
48
137
|
export class ActionCancelError extends DuronError {
|
|
49
138
|
code = ERROR_CODES.ACTION_CANCEL;
|
|
50
139
|
nonRetriable = true;
|
|
140
|
+
/**
|
|
141
|
+
* Create a new ActionCancelError.
|
|
142
|
+
*
|
|
143
|
+
* @param actionName - The name of the action that was cancelled
|
|
144
|
+
* @param jobId - The ID of the job containing the action
|
|
145
|
+
* @param options - Optional error options including cause
|
|
146
|
+
*/
|
|
51
147
|
constructor(actionName, jobId, options) {
|
|
52
|
-
super(`Action "${actionName}" in job "${jobId}" was cancelled`,
|
|
148
|
+
super(`Action "${actionName}" in job "${jobId}" was cancelled`, {
|
|
149
|
+
cause: options?.cause,
|
|
150
|
+
metadata: { actionName, jobId },
|
|
151
|
+
});
|
|
53
152
|
}
|
|
54
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Error thrown when a parent step completes with unhandled (non-awaited) child steps.
|
|
156
|
+
*
|
|
157
|
+
* This error indicates a bug in the action handler where child steps were started
|
|
158
|
+
* but not properly awaited. All child steps must be awaited before the parent returns.
|
|
159
|
+
*/
|
|
55
160
|
export class UnhandledChildStepsError extends NonRetriableError {
|
|
56
161
|
code = ERROR_CODES.UNHANDLED_CHILD_STEPS;
|
|
57
|
-
|
|
162
|
+
/**
|
|
163
|
+
* The number of unhandled child steps.
|
|
164
|
+
*/
|
|
58
165
|
pendingCount;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
166
|
+
/**
|
|
167
|
+
* Create a new UnhandledChildStepsError.
|
|
168
|
+
*
|
|
169
|
+
* @param stepName - The name of the parent step
|
|
170
|
+
* @param pendingCount - The number of unhandled child steps
|
|
171
|
+
* @param options - Optional metadata
|
|
172
|
+
*/
|
|
173
|
+
constructor(stepName, pendingCount, options) {
|
|
174
|
+
super(`Parent step "${stepName}" completed with ${pendingCount} unhandled child step(s). All child steps must be awaited before the parent returns.`, {
|
|
175
|
+
metadata: {
|
|
176
|
+
stepName,
|
|
177
|
+
stepId: options?.stepId,
|
|
178
|
+
parentStepId: options?.parentStepId,
|
|
179
|
+
jobId: options?.jobId,
|
|
180
|
+
actionName: options?.actionName,
|
|
181
|
+
},
|
|
182
|
+
});
|
|
62
183
|
this.pendingCount = pendingCount;
|
|
63
184
|
}
|
|
64
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Checks if an error is a DuronError instance.
|
|
188
|
+
*/
|
|
65
189
|
export function isDuronError(error) {
|
|
66
190
|
const code = error?.code;
|
|
67
191
|
return code !== undefined && Object.values(ERROR_CODES).includes(code);
|
|
68
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Checks if an error is a NonRetriableError instance.
|
|
195
|
+
*/
|
|
69
196
|
export function isNonRetriableError(error) {
|
|
70
197
|
return error?.nonRetriable === true;
|
|
71
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Checks if an error is an UnhandledChildStepsError instance.
|
|
201
|
+
*/
|
|
72
202
|
export function isUnhandledChildStepsError(error) {
|
|
73
203
|
return error?.code === ERROR_CODES.UNHANDLED_CHILD_STEPS;
|
|
74
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Checks if an error is a timeout error (ActionTimeoutError or StepTimeoutError).
|
|
207
|
+
*/
|
|
75
208
|
export function isTimeoutError(error) {
|
|
76
209
|
const code = error?.code;
|
|
77
210
|
return code === ERROR_CODES.ACTION_TIMEOUT || code === ERROR_CODES.STEP_TIMEOUT;
|
|
78
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Checks if an error is a cancel error (ActionCancelError or StepCancelError).
|
|
214
|
+
*/
|
|
79
215
|
export function isCancelError(error) {
|
|
80
216
|
return error?.code === ERROR_CODES.ACTION_CANCEL;
|
|
81
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Serializes an error for storage in the database.
|
|
220
|
+
* Handles DuronError instances specially to preserve their type information.
|
|
221
|
+
*/
|
|
82
222
|
export function serializeError(error) {
|
|
83
223
|
const code = error?.code;
|
|
84
224
|
const nonRetriable = error?.nonRetriable;
|
|
225
|
+
const metadata = error?.metadata;
|
|
85
226
|
if (isTimeoutError(error)) {
|
|
86
227
|
return {
|
|
87
228
|
name: error.name,
|
|
88
229
|
message: error.message,
|
|
89
230
|
code,
|
|
90
231
|
nonRetriable,
|
|
232
|
+
metadata,
|
|
91
233
|
cause: error.cause,
|
|
92
234
|
stack: undefined,
|
|
93
235
|
};
|
|
@@ -98,6 +240,7 @@ export function serializeError(error) {
|
|
|
98
240
|
message: error.message,
|
|
99
241
|
code,
|
|
100
242
|
nonRetriable,
|
|
243
|
+
metadata,
|
|
101
244
|
cause: error.cause,
|
|
102
245
|
stack: error.stack,
|
|
103
246
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Action } from './action.js';
|
|
2
2
|
import { Client, type ClientOptions } from './client.js';
|
|
3
|
-
export { createStep, defineAction, type StepDefinition, type StepDefinitionHandlerContext, type StepDefinitionInput, } from './action.js';
|
|
3
|
+
export { createStep, defineAction, type StepDefinition, type StepDefinitionHandlerContext, type StepDefinitionInput, type StepNameContext, } from './action.js';
|
|
4
4
|
export * from './client.js';
|
|
5
5
|
export * from './constants.js';
|
|
6
6
|
export { NonRetriableError, UnhandledChildStepsError } from './errors.js';
|
|
7
7
|
export * from './server.js';
|
|
8
|
+
export type { TelemetryContext } from './step-manager.js';
|
|
8
9
|
export * from './telemetry/index.js';
|
|
9
10
|
export declare const duron: <TActions extends Record<string, Action<any, any, TVariables>>, TVariables = Record<string, unknown>>(options: ClientOptions<TActions, TVariables>) => Client<TActions, TVariables>;
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAExD,OAAO,EACL,UAAU,EACV,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAExD,OAAO,EACL,UAAU,EACV,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EACxB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAA;AACpB,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AACzE,cAAc,aAAa,CAAA;AAC3B,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACzD,cAAc,sBAAsB,CAAA;AAEpC,eAAO,MAAM,KAAK,GAChB,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,EAC7D,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAEpC,SAAS,aAAa,CAAC,QAAQ,EAAE,UAAU,CAAC,iCACA,CAAA"}
|