duron 0.3.0-beta.3 → 0.3.0-beta.4

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.
@@ -40,7 +40,7 @@ export declare class StepManager {
40
40
  #private;
41
41
  constructor(options: StepManagerOptions);
42
42
  setJobSpan(span: Span): void;
43
- setRunFn(runFn: StepHandlerContext['run']): void;
43
+ setRunFnFactory(factory: (parentStepId: string | null, abortSignal: AbortSignal) => StepHandlerContext['run']): void;
44
44
  createActionContext<TInput extends z.ZodObject, TOutput extends z.ZodObject, TVariables = Record<string, unknown>>(job: {
45
45
  id: string;
46
46
  input: z.infer<TInput>;
@@ -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,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,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAC7C,OAAO,EAAE,WAAW,CAAA;IACpB,WAAW,EAAE,WAAW,CAAA;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,EAAE,OAAO,CAAA;CAClB;AAMD,qBAAa,SAAS;;gBAYR,OAAO,E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AM,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;CAkT7B"}
@@ -50,7 +50,7 @@ export class StepManager {
50
50
  #historySteps = new Set();
51
51
  #stepSpans = new Map();
52
52
  #jobSpan = null;
53
- #runFn = null;
53
+ #runFnFactory = null;
54
54
  constructor(options) {
55
55
  this.#jobId = options.jobId;
56
56
  this.#actionName = options.actionName;
@@ -68,8 +68,8 @@ export class StepManager {
68
68
  setJobSpan(span) {
69
69
  this.#jobSpan = span;
70
70
  }
71
- setRunFn(runFn) {
72
- this.#runFn = runFn;
71
+ setRunFnFactory(factory) {
72
+ this.#runFnFactory = factory;
73
73
  }
74
74
  createActionContext(job, action, variables, abortSignal, logger, observeContext) {
75
75
  return new ActionContext(this, job, action, variables, abortSignal, logger, observeContext);
@@ -181,7 +181,7 @@ export class StepManager {
181
181
  });
182
182
  return childPromise;
183
183
  },
184
- run: this.#runFn,
184
+ run: this.#runFnFactory(step.id, childSignal),
185
185
  };
186
186
  try {
187
187
  const abortPromise = waitForAbort(stepSignal);
@@ -310,7 +310,9 @@ class ActionContext {
310
310
  this.#input = job.input ?? {};
311
311
  this.step = this.step.bind(this);
312
312
  this.run = this.run.bind(this);
313
- this.#stepManager.setRunFn(this.run);
313
+ this.#stepManager.setRunFnFactory((parentStepId, abortSignal) => {
314
+ return (stepDef, input, options) => this.#runInternal(stepDef, input, options, parentStepId, abortSignal);
315
+ });
314
316
  }
315
317
  get input() {
316
318
  return this.#input;
@@ -345,6 +347,9 @@ class ActionContext {
345
347
  });
346
348
  }
347
349
  async run(stepDef, input, options = {}) {
350
+ return this.#runInternal(stepDef, input, options, null, this.#abortSignal);
351
+ }
352
+ async #runInternal(stepDef, input, options = {}, parentStepId, abortSignal) {
348
353
  const validatedInput = stepDef.input
349
354
  ? stepDef.input.parse(input, {
350
355
  error: () => 'Error parsing step input',
@@ -367,7 +372,6 @@ class ActionContext {
367
372
  var: this.#variables,
368
373
  logger: this.#logger,
369
374
  jobId: this.#jobId,
370
- run: this.run.bind(this),
371
375
  };
372
376
  return stepDef.handler(extendedCtx);
373
377
  };
@@ -375,8 +379,8 @@ class ActionContext {
375
379
  name: stepName,
376
380
  cb: wrappedCb,
377
381
  options: parsedOptions,
378
- abortSignal: this.#abortSignal,
379
- parentStepId: null,
382
+ abortSignal,
383
+ parentStepId,
380
384
  parallel: parsedOptions.parallel,
381
385
  });
382
386
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "duron",
3
- "version": "0.3.0-beta.3",
3
+ "version": "0.3.0-beta.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -154,8 +154,8 @@ export class StepManager {
154
154
  #stepSpans = new Map<string, Span>()
155
155
  // Store the job span for creating step spans
156
156
  #jobSpan: Span | null = null
157
- // Store the run function for executing step definitions from inline steps
158
- #runFn: StepHandlerContext['run'] | null = null
157
+ // Factory function to create run functions with the correct parent step ID and abort signal
158
+ #runFnFactory: ((parentStepId: string | null, abortSignal: AbortSignal) => StepHandlerContext['run']) | null = null
159
159
 
160
160
  // ============================================================================
161
161
  // Constructor
@@ -190,11 +190,13 @@ export class StepManager {
190
190
  }
191
191
 
192
192
  /**
193
- * Set the run function for executing step definitions from inline steps.
193
+ * Set the run function factory for executing step definitions from inline steps.
194
194
  * Called from ActionContext after it's initialized.
195
+ *
196
+ * @param factory - A function that creates run functions with the correct parent step ID and abort signal
195
197
  */
196
- setRunFn(runFn: StepHandlerContext['run']): void {
197
- this.#runFn = runFn
198
+ setRunFnFactory(factory: (parentStepId: string | null, abortSignal: AbortSignal) => StepHandlerContext['run']): void {
199
+ this.#runFnFactory = factory
198
200
  }
199
201
 
200
202
  // ============================================================================
@@ -436,7 +438,7 @@ export class StepManager {
436
438
 
437
439
  return childPromise
438
440
  },
439
- run: this.#runFn!,
441
+ run: this.#runFnFactory!(step.id, childSignal),
440
442
  }
441
443
 
442
444
  try {
@@ -623,8 +625,10 @@ class ActionContext<TInput extends z.ZodObject, TOutput extends z.ZodObject, TVa
623
625
  this.#input = job.input ?? {}
624
626
  this.step = this.step.bind(this)
625
627
  this.run = this.run.bind(this)
626
- // Set the run function on the step manager so inline steps can call step definitions
627
- this.#stepManager.setRunFn(this.run)
628
+ // Set the run function factory so inline steps can call step definitions with correct parent
629
+ this.#stepManager.setRunFnFactory((parentStepId, abortSignal) => {
630
+ return (stepDef, input, options) => this.#runInternal(stepDef, input, options, parentStepId, abortSignal)
631
+ })
628
632
  }
629
633
 
630
634
  // ============================================================================
@@ -707,6 +711,7 @@ class ActionContext<TInput extends z.ZodObject, TOutput extends z.ZodObject, TVa
707
711
 
708
712
  /**
709
713
  * Execute a reusable step definition created with createStep().
714
+ * This is the public method called from action handlers.
710
715
  *
711
716
  * @param stepDef - The step definition to execute
712
717
  * @param input - The input data for the step (validated against the step's input schema)
@@ -717,6 +722,20 @@ class ActionContext<TInput extends z.ZodObject, TOutput extends z.ZodObject, TVa
717
722
  stepDef: StepDefinition<TStepInput, TResult, TVariables>,
718
723
  input: z.input<TStepInput>,
719
724
  options: Partial<z.input<typeof StepOptionsSchema>> = {},
725
+ ): Promise<TResult> {
726
+ return this.#runInternal(stepDef, input, options, null, this.#abortSignal)
727
+ }
728
+
729
+ /**
730
+ * Internal method to execute a step definition with explicit parent step ID and abort signal.
731
+ * Used by both the public run method and the run functions passed to step contexts.
732
+ */
733
+ async #runInternal<TStepInput extends z.ZodObject, TResult>(
734
+ stepDef: StepDefinition<TStepInput, TResult, TVariables>,
735
+ input: z.input<TStepInput>,
736
+ options: Partial<z.input<typeof StepOptionsSchema>> = {},
737
+ parentStepId: string | null,
738
+ abortSignal: AbortSignal,
720
739
  ): Promise<TResult> {
721
740
  // Validate input against the step's schema if provided
722
741
  // After parsing, validatedInput is z.output<TStepInput> (same as z.infer<TStepInput>)
@@ -749,7 +768,6 @@ class ActionContext<TInput extends z.ZodObject, TOutput extends z.ZodObject, TVa
749
768
  var: this.#variables,
750
769
  logger: this.#logger,
751
770
  jobId: this.#jobId,
752
- run: this.run.bind(this), // Allow nested step definitions to call ctx.run()
753
771
  }
754
772
  return stepDef.handler(extendedCtx)
755
773
  }
@@ -758,8 +776,8 @@ class ActionContext<TInput extends z.ZodObject, TOutput extends z.ZodObject, TVa
758
776
  name: stepName,
759
777
  cb: wrappedCb,
760
778
  options: parsedOptions,
761
- abortSignal: this.#abortSignal,
762
- parentStepId: null, // Root steps have no parent
779
+ abortSignal,
780
+ parentStepId,
763
781
  parallel: parsedOptions.parallel,
764
782
  })
765
783
  }