duron 0.3.0-beta.0 → 0.3.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/action.d.ts +21 -0
- package/dist/action.d.ts.map +1 -1
- package/dist/action.js +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/step-manager.d.ts.map +1 -1
- package/dist/step-manager.js +37 -0
- package/package.json +1 -1
- package/src/action.ts +158 -0
- package/src/index.ts +7 -1
- package/src/step-manager.ts +62 -0
package/dist/action.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface ActionHandlerContext<TInput extends z.ZodObject, TVariables = R
|
|
|
11
11
|
logger: Logger;
|
|
12
12
|
observe: ObserveContext;
|
|
13
13
|
step: <TResult>(name: string, cb: (ctx: StepHandlerContext) => Promise<TResult>, options?: z.input<typeof StepOptionsSchema>) => Promise<TResult>;
|
|
14
|
+
run: <TStepInput extends z.ZodObject, TResult>(stepDef: StepDefinition<TStepInput, TResult, TVariables>, input: z.input<TStepInput>, options?: Partial<z.input<typeof StepOptionsSchema>>) => Promise<TResult>;
|
|
14
15
|
}
|
|
15
16
|
export interface StepHandlerContext {
|
|
16
17
|
signal: AbortSignal;
|
|
@@ -19,6 +20,24 @@ export interface StepHandlerContext {
|
|
|
19
20
|
observe: ObserveContext;
|
|
20
21
|
step: <TResult>(name: string, cb: (ctx: StepHandlerContext) => Promise<TResult>, options?: z.input<typeof StepOptionsSchema>) => Promise<TResult>;
|
|
21
22
|
}
|
|
23
|
+
export interface StepDefinitionHandlerContext<TInput extends z.ZodObject, TVariables = Record<string, unknown>> extends StepHandlerContext {
|
|
24
|
+
input: z.infer<TInput>;
|
|
25
|
+
var: TVariables;
|
|
26
|
+
logger: Logger;
|
|
27
|
+
jobId: string;
|
|
28
|
+
run: <TStepInput extends z.ZodObject, TResult>(stepDef: StepDefinition<TStepInput, TResult, TVariables>, input: z.input<TStepInput>, options?: Partial<z.input<typeof StepOptionsSchema>>) => Promise<TResult>;
|
|
29
|
+
}
|
|
30
|
+
export interface StepDefinition<TInput extends z.ZodObject, TResult, TVariables = Record<string, unknown>> {
|
|
31
|
+
name: string | ((ctx: {
|
|
32
|
+
input: z.infer<TInput>;
|
|
33
|
+
}) => string);
|
|
34
|
+
input?: TInput;
|
|
35
|
+
retry?: z.input<typeof RetryOptionsSchema>;
|
|
36
|
+
expire?: number;
|
|
37
|
+
parallel?: boolean;
|
|
38
|
+
handler: (ctx: StepDefinitionHandlerContext<TInput, TVariables>) => Promise<TResult>;
|
|
39
|
+
__stepDefinition: true;
|
|
40
|
+
}
|
|
22
41
|
export interface ConcurrencyHandlerContext<TInput extends z.ZodObject, TVariables = Record<string, unknown>> {
|
|
23
42
|
input: z.infer<TInput>;
|
|
24
43
|
var: TVariables;
|
|
@@ -133,4 +152,6 @@ export declare const defineAction: <TVariables = Record<string, unknown>>() => <
|
|
|
133
152
|
concurrency?: ((ctx: ConcurrencyHandlerContext<TInput, TVariables>) => Promise<number>) | undefined;
|
|
134
153
|
} | undefined;
|
|
135
154
|
};
|
|
155
|
+
export type StepDefinitionInput<TInput extends z.ZodObject, TResult, TVariables = Record<string, unknown>> = Omit<StepDefinition<TInput, TResult, TVariables>, '__stepDefinition'>;
|
|
156
|
+
export declare const createStep: <TVariables = Record<string, unknown>>() => <TInput extends z.ZodObject, TResult>(def: StepDefinitionInput<TInput, TResult, TVariables>) => StepDefinition<TInput, TResult, TVariables>;
|
|
136
157
|
//# 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,cAAc,EAAE,MAAM,wBAAw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C,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
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Action } from './action.js';
|
|
2
2
|
import { Client, type ClientOptions } from './client.js';
|
|
3
|
-
export { defineAction } from './action.js';
|
|
3
|
+
export { createStep, defineAction, type StepDefinition, type StepDefinitionHandlerContext, type StepDefinitionInput, } from './action.js';
|
|
4
4
|
export * from './client.js';
|
|
5
5
|
export * from './constants.js';
|
|
6
6
|
export { NonRetriableError, UnhandledChildStepsError } from './errors.js';
|
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,
|
|
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,GACzB,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,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"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from './client.js';
|
|
2
|
-
export { defineAction } from './action.js';
|
|
2
|
+
export { createStep, defineAction, } from './action.js';
|
|
3
3
|
export * from './client.js';
|
|
4
4
|
export * from './constants.js';
|
|
5
5
|
export { NonRetriableError, UnhandledChildStepsError } from './errors.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step-manager.d.ts","sourceRoot":"","sources":["../src/step-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,EACL,KAAK,MAAM,EACX,KAAK,oBAAoB,
|
|
1
|
+
{"version":3,"file":"step-manager.d.ts","sourceRoot":"","sources":["../src/step-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,EACL,KAAK,MAAM,EACX,KAAK,oBAAoB,EAGzB,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,OAAO,EAAgC,MAAM,uBAAuB,CAAA;AAClF,OAAO,EAAoE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAWlH,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAIpF,MAAM,WAAW,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G,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,EAC9D,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,EAC3C,SAAS,EAAE,UAAU,EACrB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,cAAc,GAC7B,oBAAoB,CAAC,MAAM,EAAE,UAAU,CAAC;IAO3C,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc;IA6BlD,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAQlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAiT7B"}
|
package/dist/step-manager.js
CHANGED
|
@@ -304,6 +304,7 @@ class ActionContext {
|
|
|
304
304
|
}
|
|
305
305
|
this.#input = job.input ?? {};
|
|
306
306
|
this.step = this.step.bind(this);
|
|
307
|
+
this.run = this.run.bind(this);
|
|
307
308
|
}
|
|
308
309
|
get input() {
|
|
309
310
|
return this.#input;
|
|
@@ -337,4 +338,40 @@ class ActionContext {
|
|
|
337
338
|
parallel: parsedOptions.parallel,
|
|
338
339
|
});
|
|
339
340
|
}
|
|
341
|
+
async run(stepDef, input, options = {}) {
|
|
342
|
+
const validatedInput = stepDef.input
|
|
343
|
+
? stepDef.input.parse(input, {
|
|
344
|
+
error: () => 'Error parsing step input',
|
|
345
|
+
reportInput: true,
|
|
346
|
+
})
|
|
347
|
+
: input;
|
|
348
|
+
const stepName = typeof stepDef.name === 'function' ? stepDef.name({ input: validatedInput }) : stepDef.name;
|
|
349
|
+
const mergedOptions = {
|
|
350
|
+
...this.#action.steps,
|
|
351
|
+
...(stepDef.retry !== undefined && { retry: stepDef.retry }),
|
|
352
|
+
...(stepDef.expire !== undefined && { expire: stepDef.expire }),
|
|
353
|
+
...(stepDef.parallel !== undefined && { parallel: stepDef.parallel }),
|
|
354
|
+
...options,
|
|
355
|
+
};
|
|
356
|
+
const parsedOptions = StepOptionsSchema.parse(mergedOptions);
|
|
357
|
+
const wrappedCb = async (baseCtx) => {
|
|
358
|
+
const extendedCtx = {
|
|
359
|
+
...baseCtx,
|
|
360
|
+
input: validatedInput,
|
|
361
|
+
var: this.#variables,
|
|
362
|
+
logger: this.#logger,
|
|
363
|
+
jobId: this.#jobId,
|
|
364
|
+
run: this.run.bind(this),
|
|
365
|
+
};
|
|
366
|
+
return stepDef.handler(extendedCtx);
|
|
367
|
+
};
|
|
368
|
+
return this.#stepManager.push({
|
|
369
|
+
name: stepName,
|
|
370
|
+
cb: wrappedCb,
|
|
371
|
+
options: parsedOptions,
|
|
372
|
+
abortSignal: this.#abortSignal,
|
|
373
|
+
parentStepId: null,
|
|
374
|
+
parallel: parsedOptions.parallel,
|
|
375
|
+
});
|
|
376
|
+
}
|
|
340
377
|
}
|
package/package.json
CHANGED
package/src/action.ts
CHANGED
|
@@ -21,11 +21,33 @@ export interface ActionHandlerContext<TInput extends z.ZodObject, TVariables = R
|
|
|
21
21
|
*/
|
|
22
22
|
observe: ObserveContext
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Execute an inline step within the action.
|
|
26
|
+
*
|
|
27
|
+
* @param name - The name of the step (must be unique within the job)
|
|
28
|
+
* @param cb - The step handler callback
|
|
29
|
+
* @param options - Optional step configuration
|
|
30
|
+
* @returns Promise resolving to the step result
|
|
31
|
+
*/
|
|
24
32
|
step: <TResult>(
|
|
25
33
|
name: string,
|
|
26
34
|
cb: (ctx: StepHandlerContext) => Promise<TResult>,
|
|
27
35
|
options?: z.input<typeof StepOptionsSchema>,
|
|
28
36
|
) => Promise<TResult>
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Execute a reusable step definition created with createStep().
|
|
40
|
+
*
|
|
41
|
+
* @param stepDef - The step definition to execute
|
|
42
|
+
* @param input - The input data for the step (validated against the step's input schema)
|
|
43
|
+
* @param options - Optional step configuration overrides
|
|
44
|
+
* @returns Promise resolving to the step result
|
|
45
|
+
*/
|
|
46
|
+
run: <TStepInput extends z.ZodObject, TResult>(
|
|
47
|
+
stepDef: StepDefinition<TStepInput, TResult, TVariables>,
|
|
48
|
+
input: z.input<TStepInput>,
|
|
49
|
+
options?: Partial<z.input<typeof StepOptionsSchema>>,
|
|
50
|
+
) => Promise<TResult>
|
|
29
51
|
}
|
|
30
52
|
|
|
31
53
|
export interface StepHandlerContext {
|
|
@@ -71,6 +93,95 @@ export interface StepHandlerContext {
|
|
|
71
93
|
) => Promise<TResult>
|
|
72
94
|
}
|
|
73
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Extended context for step definition handlers.
|
|
98
|
+
* Includes all StepHandlerContext properties plus action-level context.
|
|
99
|
+
*/
|
|
100
|
+
export interface StepDefinitionHandlerContext<TInput extends z.ZodObject, TVariables = Record<string, unknown>>
|
|
101
|
+
extends StepHandlerContext {
|
|
102
|
+
/**
|
|
103
|
+
* The validated input for this step.
|
|
104
|
+
*/
|
|
105
|
+
input: z.infer<TInput>
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Variables shared across the action.
|
|
109
|
+
*/
|
|
110
|
+
var: TVariables
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Logger instance for this step.
|
|
114
|
+
*/
|
|
115
|
+
logger: Logger
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The job ID this step belongs to.
|
|
119
|
+
*/
|
|
120
|
+
jobId: string
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Execute a reusable step definition created with createStep().
|
|
124
|
+
* Allows nested step definitions to call other step definitions.
|
|
125
|
+
*
|
|
126
|
+
* @param stepDef - The step definition to execute
|
|
127
|
+
* @param input - The input data for the step (validated against the step's input schema)
|
|
128
|
+
* @param options - Optional step configuration overrides
|
|
129
|
+
* @returns Promise resolving to the step result
|
|
130
|
+
*/
|
|
131
|
+
run: <TStepInput extends z.ZodObject, TResult>(
|
|
132
|
+
stepDef: StepDefinition<TStepInput, TResult, TVariables>,
|
|
133
|
+
input: z.input<TStepInput>,
|
|
134
|
+
options?: Partial<z.input<typeof StepOptionsSchema>>,
|
|
135
|
+
) => Promise<TResult>
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* A reusable step definition created with createStep().
|
|
140
|
+
* Can be executed within an action handler using ctx.run().
|
|
141
|
+
*/
|
|
142
|
+
export interface StepDefinition<
|
|
143
|
+
TInput extends z.ZodObject,
|
|
144
|
+
TResult,
|
|
145
|
+
TVariables = Record<string, unknown>,
|
|
146
|
+
> {
|
|
147
|
+
/**
|
|
148
|
+
* The name of the step.
|
|
149
|
+
* Can be a static string or a function that generates the name from the input.
|
|
150
|
+
*/
|
|
151
|
+
name: string | ((ctx: { input: z.infer<TInput> }) => string)
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Zod schema for validating the step input.
|
|
155
|
+
*/
|
|
156
|
+
input?: TInput
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Retry configuration for this step.
|
|
160
|
+
*/
|
|
161
|
+
retry?: z.input<typeof RetryOptionsSchema>
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Timeout in milliseconds for this step.
|
|
165
|
+
*/
|
|
166
|
+
expire?: number
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Whether this step runs in parallel with siblings.
|
|
170
|
+
*/
|
|
171
|
+
parallel?: boolean
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The handler function that executes the step logic.
|
|
175
|
+
*/
|
|
176
|
+
handler: (ctx: StepDefinitionHandlerContext<TInput, TVariables>) => Promise<TResult>
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Internal marker to identify this as a step definition.
|
|
180
|
+
* @internal
|
|
181
|
+
*/
|
|
182
|
+
__stepDefinition: true
|
|
183
|
+
}
|
|
184
|
+
|
|
74
185
|
export interface ConcurrencyHandlerContext<TInput extends z.ZodObject, TVariables = Record<string, unknown>> {
|
|
75
186
|
input: z.infer<TInput>
|
|
76
187
|
var: TVariables
|
|
@@ -301,3 +412,50 @@ export const defineAction = <TVariables = Record<string, unknown>>() => {
|
|
|
301
412
|
})
|
|
302
413
|
}
|
|
303
414
|
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Input type for createStep() - the definition object before transformation.
|
|
418
|
+
*/
|
|
419
|
+
export type StepDefinitionInput<
|
|
420
|
+
TInput extends z.ZodObject,
|
|
421
|
+
TResult,
|
|
422
|
+
TVariables = Record<string, unknown>,
|
|
423
|
+
> = Omit<StepDefinition<TInput, TResult, TVariables>, '__stepDefinition'>
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Creates a reusable step definition that can be executed within action handlers.
|
|
427
|
+
*
|
|
428
|
+
* @template TVariables - Type of variables available to the step handler
|
|
429
|
+
* @returns A curried function that accepts the step definition and returns a StepDefinition
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```typescript
|
|
433
|
+
* const sendEmailStep = createStep<typeof variables>()({
|
|
434
|
+
* name: 'send-email',
|
|
435
|
+
* input: z.object({
|
|
436
|
+
* email: z.string().email(),
|
|
437
|
+
* body: z.string(),
|
|
438
|
+
* }),
|
|
439
|
+
* retry: { limit: 3 },
|
|
440
|
+
* expire: 60000,
|
|
441
|
+
* handler: async (ctx) => {
|
|
442
|
+
* // ctx.input is typed as { email: string, body: string }
|
|
443
|
+
* // ctx.var, ctx.logger, ctx.jobId are also available
|
|
444
|
+
* return { success: true }
|
|
445
|
+
* },
|
|
446
|
+
* })
|
|
447
|
+
*
|
|
448
|
+
* // In an action handler:
|
|
449
|
+
* const result = await ctx.run(sendEmailStep, { email: 'test@example.com', body: 'Hello' })
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
export const createStep = <TVariables = Record<string, unknown>>() => {
|
|
453
|
+
return <TInput extends z.ZodObject, TResult>(
|
|
454
|
+
def: StepDefinitionInput<TInput, TResult, TVariables>,
|
|
455
|
+
): StepDefinition<TInput, TResult, TVariables> => {
|
|
456
|
+
return {
|
|
457
|
+
...def,
|
|
458
|
+
__stepDefinition: true as const,
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { Action } from './action.js'
|
|
2
2
|
import { Client, type ClientOptions } from './client.js'
|
|
3
3
|
|
|
4
|
-
export {
|
|
4
|
+
export {
|
|
5
|
+
createStep,
|
|
6
|
+
defineAction,
|
|
7
|
+
type StepDefinition,
|
|
8
|
+
type StepDefinitionHandlerContext,
|
|
9
|
+
type StepDefinitionInput,
|
|
10
|
+
} from './action.js'
|
|
5
11
|
export * from './client.js'
|
|
6
12
|
export * from './constants.js'
|
|
7
13
|
export { NonRetriableError, UnhandledChildStepsError } from './errors.js'
|
package/src/step-manager.ts
CHANGED
|
@@ -5,6 +5,8 @@ import type { z } from 'zod'
|
|
|
5
5
|
import {
|
|
6
6
|
type Action,
|
|
7
7
|
type ActionHandlerContext,
|
|
8
|
+
type StepDefinition,
|
|
9
|
+
type StepDefinitionHandlerContext,
|
|
8
10
|
type StepHandlerContext,
|
|
9
11
|
type StepOptions,
|
|
10
12
|
StepOptionsSchema,
|
|
@@ -609,6 +611,7 @@ class ActionContext<TInput extends z.ZodObject, TOutput extends z.ZodObject, TVa
|
|
|
609
611
|
}
|
|
610
612
|
this.#input = job.input ?? {}
|
|
611
613
|
this.step = this.step.bind(this)
|
|
614
|
+
this.run = this.run.bind(this)
|
|
612
615
|
}
|
|
613
616
|
|
|
614
617
|
// ============================================================================
|
|
@@ -688,4 +691,63 @@ class ActionContext<TInput extends z.ZodObject, TOutput extends z.ZodObject, TVa
|
|
|
688
691
|
parallel: parsedOptions.parallel, // Pass parallel option
|
|
689
692
|
})
|
|
690
693
|
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Execute a reusable step definition created with createStep().
|
|
697
|
+
*
|
|
698
|
+
* @param stepDef - The step definition to execute
|
|
699
|
+
* @param input - The input data for the step (validated against the step's input schema)
|
|
700
|
+
* @param options - Optional step configuration overrides
|
|
701
|
+
* @returns Promise resolving to the step result
|
|
702
|
+
*/
|
|
703
|
+
async run<TStepInput extends z.ZodObject, TResult>(
|
|
704
|
+
stepDef: StepDefinition<TStepInput, TResult, TVariables>,
|
|
705
|
+
input: z.input<TStepInput>,
|
|
706
|
+
options: Partial<z.input<typeof StepOptionsSchema>> = {},
|
|
707
|
+
): Promise<TResult> {
|
|
708
|
+
// Validate input against the step's schema if provided
|
|
709
|
+
// After parsing, validatedInput is z.output<TStepInput> (same as z.infer<TStepInput>)
|
|
710
|
+
const validatedInput: z.infer<TStepInput> = stepDef.input
|
|
711
|
+
? stepDef.input.parse(input, {
|
|
712
|
+
error: () => 'Error parsing step input',
|
|
713
|
+
reportInput: true,
|
|
714
|
+
})
|
|
715
|
+
: (input as z.infer<TStepInput>)
|
|
716
|
+
|
|
717
|
+
// Resolve step name (static or dynamic)
|
|
718
|
+
const stepName = typeof stepDef.name === 'function' ? stepDef.name({ input: validatedInput }) : stepDef.name
|
|
719
|
+
|
|
720
|
+
// Merge options: action defaults -> step definition -> call-time overrides
|
|
721
|
+
const mergedOptions: z.input<typeof StepOptionsSchema> = {
|
|
722
|
+
...this.#action.steps,
|
|
723
|
+
...(stepDef.retry !== undefined && { retry: stepDef.retry }),
|
|
724
|
+
...(stepDef.expire !== undefined && { expire: stepDef.expire }),
|
|
725
|
+
...(stepDef.parallel !== undefined && { parallel: stepDef.parallel }),
|
|
726
|
+
...options,
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
const parsedOptions = StepOptionsSchema.parse(mergedOptions)
|
|
730
|
+
|
|
731
|
+
// Create a wrapper callback that provides the extended context
|
|
732
|
+
const wrappedCb = async (baseCtx: StepHandlerContext): Promise<TResult> => {
|
|
733
|
+
const extendedCtx: StepDefinitionHandlerContext<TStepInput, TVariables> = {
|
|
734
|
+
...baseCtx,
|
|
735
|
+
input: validatedInput,
|
|
736
|
+
var: this.#variables,
|
|
737
|
+
logger: this.#logger,
|
|
738
|
+
jobId: this.#jobId,
|
|
739
|
+
run: this.run.bind(this), // Allow nested step definitions to call ctx.run()
|
|
740
|
+
}
|
|
741
|
+
return stepDef.handler(extendedCtx)
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
return this.#stepManager.push({
|
|
745
|
+
name: stepName,
|
|
746
|
+
cb: wrappedCb,
|
|
747
|
+
options: parsedOptions,
|
|
748
|
+
abortSignal: this.#abortSignal,
|
|
749
|
+
parentStepId: null, // Root steps have no parent
|
|
750
|
+
parallel: parsedOptions.parallel,
|
|
751
|
+
})
|
|
752
|
+
}
|
|
691
753
|
}
|