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/action.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from 'pino';
|
|
2
2
|
import * as z from 'zod';
|
|
3
|
-
import type {
|
|
3
|
+
import type { TelemetryContext } from './step-manager.js';
|
|
4
4
|
export type RetryOptions = z.infer<typeof RetryOptionsSchema>;
|
|
5
5
|
export type StepOptions = z.infer<typeof StepOptionsSchema>;
|
|
6
6
|
export interface ActionHandlerContext<TInput extends z.ZodObject, TVariables = Record<string, unknown>> {
|
|
@@ -9,40 +9,387 @@ export interface ActionHandlerContext<TInput extends z.ZodObject, TVariables = R
|
|
|
9
9
|
groupKey: string;
|
|
10
10
|
var: TVariables;
|
|
11
11
|
logger: Logger;
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Telemetry context for recording metrics and span data.
|
|
14
|
+
* Provides access to OpenTelemetry APIs for recording traces and metrics.
|
|
15
|
+
*/
|
|
16
|
+
telemetry: TelemetryContext;
|
|
17
|
+
/**
|
|
18
|
+
* Execute an inline step within the action.
|
|
19
|
+
*
|
|
20
|
+
* @param name - The name of the step (must be unique within the job)
|
|
21
|
+
* @param cb - The step handler callback
|
|
22
|
+
* @param options - Optional step configuration
|
|
23
|
+
* @returns Promise resolving to the step result
|
|
24
|
+
*/
|
|
13
25
|
step: <TResult>(name: string, cb: (ctx: StepHandlerContext) => Promise<TResult>, options?: z.input<typeof StepOptionsSchema>) => Promise<TResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Execute a reusable step definition created with createStep().
|
|
28
|
+
*
|
|
29
|
+
* @param stepDef - The step definition to execute
|
|
30
|
+
* @param input - The input data for the step (validated against the step's input schema)
|
|
31
|
+
* @param options - Optional step configuration overrides
|
|
32
|
+
* @returns Promise resolving to the step result
|
|
33
|
+
*/
|
|
14
34
|
run: <TStepInput extends z.ZodObject, TResult>(stepDef: StepDefinition<TStepInput, TResult, TVariables>, input: z.input<TStepInput>, options?: Partial<z.input<typeof StepOptionsSchema>>) => Promise<TResult>;
|
|
15
35
|
}
|
|
16
36
|
export interface StepHandlerContext {
|
|
37
|
+
/**
|
|
38
|
+
* The abort signal for this step.
|
|
39
|
+
* This signal will be aborted when:
|
|
40
|
+
* - The action is cancelled
|
|
41
|
+
* - The parent step times out
|
|
42
|
+
* - This step times out
|
|
43
|
+
*/
|
|
17
44
|
signal: AbortSignal;
|
|
45
|
+
/**
|
|
46
|
+
* The unique ID of this step.
|
|
47
|
+
*/
|
|
18
48
|
stepId: string;
|
|
49
|
+
/**
|
|
50
|
+
* The ID of the parent step, or null if this is a root step.
|
|
51
|
+
*/
|
|
19
52
|
parentStepId: string | null;
|
|
20
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Telemetry context for recording metrics and span data.
|
|
55
|
+
* Provides access to OpenTelemetry APIs for recording traces and metrics.
|
|
56
|
+
*/
|
|
57
|
+
telemetry: TelemetryContext;
|
|
58
|
+
/**
|
|
59
|
+
* Create a nested child step.
|
|
60
|
+
* Child steps inherit the abort signal chain from their parent.
|
|
61
|
+
* All child steps MUST be awaited before the parent step returns.
|
|
62
|
+
*
|
|
63
|
+
* @param name - The name of the child step (must be unique within the job)
|
|
64
|
+
* @param cb - The step handler callback
|
|
65
|
+
* @param options - Optional step configuration
|
|
66
|
+
* @returns Promise resolving to the step result
|
|
67
|
+
*/
|
|
21
68
|
step: <TResult>(name: string, cb: (ctx: StepHandlerContext) => Promise<TResult>, options?: z.input<typeof StepOptionsSchema>) => Promise<TResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Execute a reusable step definition created with createStep().
|
|
71
|
+
* Allows inline steps to call step definitions.
|
|
72
|
+
*
|
|
73
|
+
* @param stepDef - The step definition to execute
|
|
74
|
+
* @param input - The input data for the step (validated against the step's input schema)
|
|
75
|
+
* @param options - Optional step configuration overrides
|
|
76
|
+
* @returns Promise resolving to the step result
|
|
77
|
+
*/
|
|
22
78
|
run: <TStepInput extends z.ZodObject, TResult>(stepDef: StepDefinition<TStepInput, TResult, any>, input: z.input<TStepInput>, options?: Partial<z.input<typeof StepOptionsSchema>>) => Promise<TResult>;
|
|
23
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Extended context for step definition handlers.
|
|
82
|
+
* Includes all StepHandlerContext properties plus action-level context.
|
|
83
|
+
*/
|
|
24
84
|
export interface StepDefinitionHandlerContext<TInput extends z.ZodObject, TVariables = Record<string, unknown>> extends StepHandlerContext {
|
|
85
|
+
/**
|
|
86
|
+
* The validated input for this step.
|
|
87
|
+
*/
|
|
25
88
|
input: z.infer<TInput>;
|
|
89
|
+
/**
|
|
90
|
+
* Variables shared across the action.
|
|
91
|
+
*/
|
|
26
92
|
var: TVariables;
|
|
93
|
+
/**
|
|
94
|
+
* Logger instance for this step.
|
|
95
|
+
*/
|
|
27
96
|
logger: Logger;
|
|
97
|
+
/**
|
|
98
|
+
* The job ID this step belongs to.
|
|
99
|
+
*/
|
|
28
100
|
jobId: string;
|
|
29
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* A reusable step definition created with createStep().
|
|
104
|
+
* Can be executed within an action handler using ctx.run().
|
|
105
|
+
*/
|
|
30
106
|
export interface StepDefinition<TInput extends z.ZodObject, TResult, TVariables = Record<string, unknown>> {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
107
|
+
/**
|
|
108
|
+
* The name of the step.
|
|
109
|
+
* Can be a static string or a function that generates the name from the context.
|
|
110
|
+
* The function receives a context object with input, variables, jobId, and parentStepId.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* name: (ctx) => `process-user-${ctx.input.userId}`
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* name: (ctx) => `step-${ctx.var.environment}-${ctx.jobId.slice(0, 8)}`
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
name: string | ((ctx: StepNameContext<TInput, TVariables>) => string);
|
|
123
|
+
/**
|
|
124
|
+
* Zod schema for validating the step input.
|
|
125
|
+
*/
|
|
34
126
|
input?: TInput;
|
|
127
|
+
/**
|
|
128
|
+
* Retry configuration for this step.
|
|
129
|
+
*/
|
|
35
130
|
retry?: z.input<typeof RetryOptionsSchema>;
|
|
131
|
+
/**
|
|
132
|
+
* Timeout in milliseconds for this step.
|
|
133
|
+
*/
|
|
36
134
|
expire?: number;
|
|
135
|
+
/**
|
|
136
|
+
* Whether this step runs in parallel with siblings.
|
|
137
|
+
*/
|
|
37
138
|
parallel?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* The handler function that executes the step logic.
|
|
141
|
+
*/
|
|
38
142
|
handler: (ctx: StepDefinitionHandlerContext<TInput, TVariables>) => Promise<TResult>;
|
|
143
|
+
/**
|
|
144
|
+
* Internal marker to identify this as a step definition.
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
39
147
|
__stepDefinition: true;
|
|
40
148
|
}
|
|
41
149
|
export interface ConcurrencyHandlerContext<TInput extends z.ZodObject, TVariables = Record<string, unknown>> {
|
|
42
150
|
input: z.infer<TInput>;
|
|
43
151
|
var: TVariables;
|
|
44
152
|
}
|
|
45
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Context available when generating dynamic step names.
|
|
155
|
+
* Provides access to input, variables, job ID, and parent step ID.
|
|
156
|
+
*/
|
|
157
|
+
export interface StepNameContext<TInput extends z.ZodObject, TVariables = Record<string, unknown>> {
|
|
158
|
+
/**
|
|
159
|
+
* The validated input for this step.
|
|
160
|
+
*/
|
|
161
|
+
input: z.infer<TInput>;
|
|
162
|
+
/**
|
|
163
|
+
* Variables shared across the action.
|
|
164
|
+
*/
|
|
165
|
+
var: TVariables;
|
|
166
|
+
/**
|
|
167
|
+
* The job ID this step belongs to.
|
|
168
|
+
*/
|
|
169
|
+
jobId: string;
|
|
170
|
+
/**
|
|
171
|
+
* The ID of the parent step, or null if this is a root step.
|
|
172
|
+
*/
|
|
173
|
+
parentStepId: string | null;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Retry configuration options for actions and steps.
|
|
177
|
+
* Controls how failed operations are retried with exponential backoff.
|
|
178
|
+
*/
|
|
179
|
+
export interface RetryOptionsInput {
|
|
180
|
+
/**
|
|
181
|
+
* Maximum number of retry attempts.
|
|
182
|
+
* Set to 0 to disable retries.
|
|
183
|
+
*
|
|
184
|
+
* @default 4
|
|
185
|
+
*/
|
|
186
|
+
limit?: number;
|
|
187
|
+
/**
|
|
188
|
+
* Exponential backoff factor.
|
|
189
|
+
* The delay between retries is calculated as: `minTimeout * (factor ^ attemptNumber)`
|
|
190
|
+
*
|
|
191
|
+
* @default 2
|
|
192
|
+
*/
|
|
193
|
+
factor?: number;
|
|
194
|
+
/**
|
|
195
|
+
* Minimum delay in milliseconds before the first retry.
|
|
196
|
+
* This is the base delay that gets multiplied by the factor.
|
|
197
|
+
*
|
|
198
|
+
* @default 1000
|
|
199
|
+
*/
|
|
200
|
+
minTimeout?: number;
|
|
201
|
+
/**
|
|
202
|
+
* Maximum delay in milliseconds between retries.
|
|
203
|
+
* The calculated delay will be capped at this value to prevent
|
|
204
|
+
* excessively long wait times.
|
|
205
|
+
*
|
|
206
|
+
* @default 30000
|
|
207
|
+
*/
|
|
208
|
+
maxTimeout?: number;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Configuration options for steps within an action.
|
|
212
|
+
* Controls concurrency, retries, and timeouts for step execution.
|
|
213
|
+
*/
|
|
214
|
+
export interface StepsConfigInput {
|
|
215
|
+
/**
|
|
216
|
+
* Maximum number of steps that can run concurrently within this action.
|
|
217
|
+
* Higher values allow more parallelism but may increase resource usage.
|
|
218
|
+
*
|
|
219
|
+
* @default 100
|
|
220
|
+
*/
|
|
221
|
+
concurrency?: number;
|
|
222
|
+
/**
|
|
223
|
+
* Retry configuration for steps.
|
|
224
|
+
* These settings apply to all steps unless overridden at the step level.
|
|
225
|
+
*
|
|
226
|
+
* @default { limit: 4, factor: 2, minTimeout: 1000, maxTimeout: 30000 }
|
|
227
|
+
*/
|
|
228
|
+
retry?: RetryOptionsInput;
|
|
229
|
+
/**
|
|
230
|
+
* Timeout in milliseconds for each step.
|
|
231
|
+
* Steps that exceed this timeout will be cancelled and may be retried.
|
|
232
|
+
*
|
|
233
|
+
* @default 300000 (5 minutes)
|
|
234
|
+
*/
|
|
235
|
+
expire?: number;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Group configuration for concurrency control.
|
|
239
|
+
* Allows grouping jobs by key and controlling concurrency per group.
|
|
240
|
+
*/
|
|
241
|
+
export interface GroupsConfigInput<TInput extends z.ZodObject, TVariables = Record<string, unknown>> {
|
|
242
|
+
/**
|
|
243
|
+
* Function to determine the group key for a job.
|
|
244
|
+
* Jobs with the same group key will respect the group concurrency limit.
|
|
245
|
+
* Use this to limit concurrent processing of related jobs (e.g., per user, per tenant).
|
|
246
|
+
*
|
|
247
|
+
* If not provided, all jobs for this action will use the '@default' group key.
|
|
248
|
+
*
|
|
249
|
+
* @param ctx - Context containing the validated input and variables
|
|
250
|
+
* @returns Promise resolving to the group key string
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* groupKey: async (ctx) => `user:${ctx.input.userId}`
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
groupKey?: (ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<string>;
|
|
258
|
+
/**
|
|
259
|
+
* Function to dynamically determine the concurrency limit for a job's group.
|
|
260
|
+
* The concurrency limit is stored with each job and used during fetch operations.
|
|
261
|
+
* This allows different groups to have different concurrency limits.
|
|
262
|
+
*
|
|
263
|
+
* If not provided, uses the global `groupConcurrencyLimit` from the client options.
|
|
264
|
+
*
|
|
265
|
+
* @param ctx - Context containing the validated input and variables
|
|
266
|
+
* @returns Promise resolving to the concurrency limit number
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```typescript
|
|
270
|
+
* concurrency: async (ctx) => ctx.input.priority === 'high' ? 10 : 2
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
concurrency?: (ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<number>;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Definition for creating a Duron action.
|
|
277
|
+
* Actions are type-safe, durable job handlers with built-in retry logic,
|
|
278
|
+
* step-based execution, and concurrency control.
|
|
279
|
+
*
|
|
280
|
+
* @template TInput - Zod schema type for validating the action input
|
|
281
|
+
* @template TOutput - Zod schema type for validating the action output
|
|
282
|
+
* @template TVariables - Type of variables available to the action handler
|
|
283
|
+
*/
|
|
284
|
+
export interface ActionDefinitionInput<TInput extends z.ZodObject, TOutput extends z.ZodObject, TVariables = Record<string, unknown>> {
|
|
285
|
+
/**
|
|
286
|
+
* Unique name for this action.
|
|
287
|
+
* Used as the queue name and must be unique across all actions registered with a client.
|
|
288
|
+
* This name is used for job routing, logging, and dashboard display.
|
|
289
|
+
*
|
|
290
|
+
* @example 'send-email', 'process-payment', 'sync-user-data'
|
|
291
|
+
*/
|
|
292
|
+
name: string;
|
|
293
|
+
/**
|
|
294
|
+
* Optional version string for the action.
|
|
295
|
+
* Used to track changes to the action and included in the checksum calculation.
|
|
296
|
+
* Changing the version will cause existing jobs to be treated as having a different checksum.
|
|
297
|
+
*
|
|
298
|
+
* @example '1.0.0', '2024-01-15', 'v2'
|
|
299
|
+
*/
|
|
300
|
+
version?: string;
|
|
301
|
+
/**
|
|
302
|
+
* Zod schema for validating the action input.
|
|
303
|
+
* If provided, input will be validated before the handler is called.
|
|
304
|
+
* Invalid input will throw a validation error and the job will fail.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* input: z.object({
|
|
309
|
+
* email: z.string().email(),
|
|
310
|
+
* subject: z.string().min(1),
|
|
311
|
+
* })
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
input?: TInput;
|
|
315
|
+
/**
|
|
316
|
+
* Zod schema for validating the action output.
|
|
317
|
+
* If provided, output will be validated after the handler completes.
|
|
318
|
+
* Invalid output will cause the job to fail.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```typescript
|
|
322
|
+
* output: z.object({
|
|
323
|
+
* success: z.boolean(),
|
|
324
|
+
* messageId: z.string().optional(),
|
|
325
|
+
* })
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
output?: TOutput;
|
|
329
|
+
/**
|
|
330
|
+
* Group configuration for concurrency control.
|
|
331
|
+
* Allows grouping jobs by a dynamic key and controlling concurrency per group.
|
|
332
|
+
* Useful for rate limiting per user, tenant, or resource.
|
|
333
|
+
*/
|
|
334
|
+
groups?: GroupsConfigInput<TInput, TVariables>;
|
|
335
|
+
/**
|
|
336
|
+
* Configuration for steps within this action.
|
|
337
|
+
* Steps are retryable units of work that can be executed within the action handler.
|
|
338
|
+
* These settings apply to all steps unless overridden at the step level.
|
|
339
|
+
*
|
|
340
|
+
* @default { concurrency: 100, retry: { limit: 4, factor: 2, minTimeout: 1000, maxTimeout: 30000 }, expire: 300000 }
|
|
341
|
+
*/
|
|
342
|
+
steps?: StepsConfigInput;
|
|
343
|
+
/**
|
|
344
|
+
* Maximum number of jobs for this action that can run concurrently across all workers.
|
|
345
|
+
* This limit is enforced per action, regardless of group.
|
|
346
|
+
*
|
|
347
|
+
* @default 100
|
|
348
|
+
*/
|
|
349
|
+
concurrency?: number;
|
|
350
|
+
/**
|
|
351
|
+
* Timeout in milliseconds for the entire action.
|
|
352
|
+
* Jobs that exceed this timeout will be cancelled.
|
|
353
|
+
* Make sure this is greater than the expected total execution time including all steps.
|
|
354
|
+
*
|
|
355
|
+
* @default 900000 (15 minutes)
|
|
356
|
+
*/
|
|
357
|
+
expire?: number;
|
|
358
|
+
/**
|
|
359
|
+
* Function to generate a dynamic description for the job.
|
|
360
|
+
* The description is calculated at job creation time and stored in the database.
|
|
361
|
+
* Use this to provide context about what the specific job instance is doing.
|
|
362
|
+
*
|
|
363
|
+
* @param ctx - Context containing the validated input and variables
|
|
364
|
+
* @returns Promise resolving to the description string
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* ```typescript
|
|
368
|
+
* description: async (ctx) => `Send email to ${ctx.input.email}`
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
description?: (ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<string>;
|
|
372
|
+
/**
|
|
373
|
+
* The handler function that executes the action logic.
|
|
374
|
+
* Receives a context object with validated input, variables, logger, and step functions.
|
|
375
|
+
* Must return a Promise that resolves to the action output (matching the output schema if provided).
|
|
376
|
+
*
|
|
377
|
+
* @param ctx - Action handler context with input, variables, and step functions
|
|
378
|
+
* @returns Promise resolving to the action output
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```typescript
|
|
382
|
+
* handler: async (ctx) => {
|
|
383
|
+
* const result = await ctx.step('send', async () => {
|
|
384
|
+
* return await sendEmail(ctx.input.email, ctx.input.subject)
|
|
385
|
+
* })
|
|
386
|
+
* return { success: true, messageId: result.id }
|
|
387
|
+
* }
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
handler: (ctx: ActionHandlerContext<TInput, TVariables>) => Promise<z.infer<TOutput>>;
|
|
391
|
+
}
|
|
392
|
+
export type ActionDefinition<TInput extends z.ZodObject, TOutput extends z.ZodObject, TVariables = Record<string, unknown>> = ActionDefinitionInput<TInput, TOutput, TVariables>;
|
|
46
393
|
export type Action<TInput extends z.ZodObject, TOutput extends z.ZodObject, TVariables = Record<string, unknown>> = z.infer<ReturnType<typeof createActionDefinitionSchema<TInput, TOutput, TVariables>>>;
|
|
47
394
|
export declare const RetryOptionsSchema: z.ZodDefault<z.ZodObject<{
|
|
48
395
|
limit: z.ZodDefault<z.ZodNumber>;
|
|
@@ -81,6 +428,7 @@ export declare function createActionDefinitionSchema<TInput extends z.ZodObject,
|
|
|
81
428
|
}, z.core.$strip>>;
|
|
82
429
|
concurrency: z.ZodDefault<z.ZodNumber>;
|
|
83
430
|
expire: z.ZodDefault<z.ZodNumber>;
|
|
431
|
+
description: z.ZodOptional<z.ZodCustom<(ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<string>, (ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<string>>>;
|
|
84
432
|
handler: z.ZodCustom<(ctx: ActionHandlerContext<TInput, TVariables>) => Promise<z.infer<TOutput>>, (ctx: ActionHandlerContext<TInput, TVariables>) => Promise<z.infer<TOutput>>>;
|
|
85
433
|
}, z.core.$strip>, z.ZodTransform<{
|
|
86
434
|
checksum: string;
|
|
@@ -105,6 +453,7 @@ export declare function createActionDefinitionSchema<TInput extends z.ZodObject,
|
|
|
105
453
|
groupKey?: ((ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<string>) | undefined;
|
|
106
454
|
concurrency?: ((ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<number>) | undefined;
|
|
107
455
|
} | undefined;
|
|
456
|
+
description?: ((ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<string>) | undefined;
|
|
108
457
|
}, {
|
|
109
458
|
name: string;
|
|
110
459
|
steps: {
|
|
@@ -127,6 +476,7 @@ export declare function createActionDefinitionSchema<TInput extends z.ZodObject,
|
|
|
127
476
|
groupKey?: ((ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<string>) | undefined;
|
|
128
477
|
concurrency?: ((ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<number>) | undefined;
|
|
129
478
|
} | undefined;
|
|
479
|
+
description?: ((ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<string>) | undefined;
|
|
130
480
|
}>>;
|
|
131
481
|
export declare const defineAction: <TVariables = Record<string, unknown>>() => <TInput extends z.ZodObject, TOutput extends z.ZodObject>(def: ActionDefinition<TInput, TOutput, TVariables>) => {
|
|
132
482
|
checksum: string;
|
|
@@ -151,7 +501,38 @@ export declare const defineAction: <TVariables = Record<string, unknown>>() => <
|
|
|
151
501
|
groupKey?: ((ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<string>) | undefined;
|
|
152
502
|
concurrency?: ((ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<number>) | undefined;
|
|
153
503
|
} | undefined;
|
|
504
|
+
description?: ((ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<string>) | undefined;
|
|
154
505
|
};
|
|
506
|
+
/**
|
|
507
|
+
* Input type for createStep() - the definition object before transformation.
|
|
508
|
+
*/
|
|
155
509
|
export type StepDefinitionInput<TInput extends z.ZodObject, TResult, TVariables = Record<string, unknown>> = Omit<StepDefinition<TInput, TResult, TVariables>, '__stepDefinition'>;
|
|
510
|
+
/**
|
|
511
|
+
* Creates a reusable step definition that can be executed within action handlers.
|
|
512
|
+
*
|
|
513
|
+
* @template TVariables - Type of variables available to the step handler
|
|
514
|
+
* @returns A curried function that accepts the step definition and returns a StepDefinition
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```typescript
|
|
518
|
+
* const sendEmailStep = createStep<typeof variables>()({
|
|
519
|
+
* name: 'send-email',
|
|
520
|
+
* input: z.object({
|
|
521
|
+
* email: z.string().email(),
|
|
522
|
+
* body: z.string(),
|
|
523
|
+
* }),
|
|
524
|
+
* retry: { limit: 3 },
|
|
525
|
+
* expire: 60000,
|
|
526
|
+
* handler: async (ctx) => {
|
|
527
|
+
* // ctx.input is typed as { email: string, body: string }
|
|
528
|
+
* // ctx.var, ctx.logger, ctx.jobId are also available
|
|
529
|
+
* return { success: true }
|
|
530
|
+
* },
|
|
531
|
+
* })
|
|
532
|
+
*
|
|
533
|
+
* // In an action handler:
|
|
534
|
+
* const result = await ctx.run(sendEmailStep, { email: 'test@example.com', body: 'Hello' })
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
156
537
|
export declare const createStep: <TVariables = Record<string, unknown>>() => <TInput extends z.ZodObject, TResult>(def: StepDefinitionInput<TInput, TResult, TVariables>) => StepDefinition<TInput, TResult, TVariables>;
|
|
157
538
|
//# sourceMappingURL=action.d.ts.map
|
package/dist/action.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../src/action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../src/action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAGzD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAE7D,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAE3D,MAAM,WAAW,oBAAoB,CAAC,MAAM,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACpG,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,UAAU,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IAEd;;;OAGG;IACH,SAAS,EAAE,gBAAgB,CAAA;IAE3B;;;;;;;OA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AAM,SAAS,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,IAAI,CAC/G,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,EAC3C,kBAAkB,CACnB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QACrD,MAAM,SAAS,CAAC,CAAC,SAAS,EAAE,OAAO,EACzC,KAAK,mBAAmB,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,KACpD,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAM9C,CAAA"}
|
package/dist/action.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
2
|
import generateChecksum from './utils/checksum.js';
|
|
3
|
+
const _checkActionDef = true;
|
|
3
4
|
export const RetryOptionsSchema = z
|
|
4
5
|
.object({
|
|
5
6
|
limit: z.number().default(4),
|
|
@@ -7,21 +8,17 @@ export const RetryOptionsSchema = z
|
|
|
7
8
|
minTimeout: z.number().default(1000),
|
|
8
9
|
maxTimeout: z.number().default(30000),
|
|
9
10
|
})
|
|
10
|
-
.default({ limit: 4, factor: 2, minTimeout: 1000, maxTimeout: 30000 })
|
|
11
|
-
.describe('The retry options');
|
|
11
|
+
.default({ limit: 4, factor: 2, minTimeout: 1000, maxTimeout: 30000 });
|
|
12
12
|
export const StepOptionsSchema = z.object({
|
|
13
13
|
retry: RetryOptionsSchema,
|
|
14
|
-
expire: z
|
|
15
|
-
|
|
16
|
-
.default(5 * 60 * 1000)
|
|
17
|
-
.describe('The expire time for the step (milliseconds)'),
|
|
18
|
-
parallel: z.boolean().default(false).describe('Whether this step runs in parallel (independent from siblings)'),
|
|
14
|
+
expire: z.number().default(5 * 60 * 1000),
|
|
15
|
+
parallel: z.boolean().default(false),
|
|
19
16
|
});
|
|
20
17
|
export function createActionDefinitionSchema() {
|
|
21
18
|
return z
|
|
22
19
|
.object({
|
|
23
|
-
name: z.string()
|
|
24
|
-
version: z.string().
|
|
20
|
+
name: z.string(),
|
|
21
|
+
version: z.string().optional(),
|
|
25
22
|
input: z
|
|
26
23
|
.custom((val) => {
|
|
27
24
|
return !val || ('_zod' in val && 'type' in val && val.type === 'object');
|
|
@@ -48,28 +45,25 @@ export function createActionDefinitionSchema() {
|
|
|
48
45
|
.optional(),
|
|
49
46
|
steps: z
|
|
50
47
|
.object({
|
|
51
|
-
concurrency: z.number().default(100)
|
|
52
|
-
retry: RetryOptionsSchema
|
|
53
|
-
expire: z
|
|
54
|
-
.number()
|
|
55
|
-
.default(5 * 60 * 1000)
|
|
56
|
-
.describe('How long a step can run for (milliseconds)'),
|
|
48
|
+
concurrency: z.number().default(100),
|
|
49
|
+
retry: RetryOptionsSchema,
|
|
50
|
+
expire: z.number().default(5 * 60 * 1000),
|
|
57
51
|
})
|
|
58
52
|
.default({
|
|
59
53
|
concurrency: 100,
|
|
60
54
|
retry: { limit: 4, factor: 2, minTimeout: 1000, maxTimeout: 30000 },
|
|
61
55
|
expire: 5 * 60 * 1000,
|
|
62
56
|
}),
|
|
63
|
-
concurrency: z.number().default(100)
|
|
64
|
-
expire: z
|
|
65
|
-
|
|
66
|
-
.default(15 * 60 * 1000)
|
|
67
|
-
.describe('How long a job can run for (milliseconds)'),
|
|
68
|
-
handler: z
|
|
57
|
+
concurrency: z.number().default(100),
|
|
58
|
+
expire: z.number().default(15 * 60 * 1000),
|
|
59
|
+
description: z
|
|
69
60
|
.custom((val) => {
|
|
70
|
-
return val instanceof Function;
|
|
61
|
+
return !val || val instanceof Function;
|
|
71
62
|
})
|
|
72
|
-
.
|
|
63
|
+
.optional(),
|
|
64
|
+
handler: z.custom((val) => {
|
|
65
|
+
return val instanceof Function;
|
|
66
|
+
}),
|
|
73
67
|
})
|
|
74
68
|
.transform((def) => {
|
|
75
69
|
const checksum = [def.name, def.version, def.handler.toString()].filter(Boolean).join(':');
|
|
@@ -86,6 +80,33 @@ export const defineAction = () => {
|
|
|
86
80
|
});
|
|
87
81
|
};
|
|
88
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* Creates a reusable step definition that can be executed within action handlers.
|
|
85
|
+
*
|
|
86
|
+
* @template TVariables - Type of variables available to the step handler
|
|
87
|
+
* @returns A curried function that accepts the step definition and returns a StepDefinition
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const sendEmailStep = createStep<typeof variables>()({
|
|
92
|
+
* name: 'send-email',
|
|
93
|
+
* input: z.object({
|
|
94
|
+
* email: z.string().email(),
|
|
95
|
+
* body: z.string(),
|
|
96
|
+
* }),
|
|
97
|
+
* retry: { limit: 3 },
|
|
98
|
+
* expire: 60000,
|
|
99
|
+
* handler: async (ctx) => {
|
|
100
|
+
* // ctx.input is typed as { email: string, body: string }
|
|
101
|
+
* // ctx.var, ctx.logger, ctx.jobId are also available
|
|
102
|
+
* return { success: true }
|
|
103
|
+
* },
|
|
104
|
+
* })
|
|
105
|
+
*
|
|
106
|
+
* // In an action handler:
|
|
107
|
+
* const result = await ctx.run(sendEmailStep, { email: 'test@example.com', body: 'Hello' })
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
89
110
|
export const createStep = () => {
|
|
90
111
|
return (def) => {
|
|
91
112
|
return {
|