@pogodisco/zephyr 1.3.7 → 1.3.9

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/utils.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { ActionRegistry } from "./types.js";
2
+ import { WorkflowDef } from "./workflow-composer.js";
1
3
  type AnyFn = (...args: any[]) => any;
2
4
  /**
3
5
  * For generic actions - preserves the generic parameter
@@ -7,4 +9,9 @@ export declare function genericAction<F extends AnyFn>(fn: F): <T>() => ((...arg
7
9
  * For fixed actions
8
10
  */
9
11
  export declare function fixedAction<F extends AnyFn>(fn: F): () => ((...args: Parameters<F>) => ReturnType<F>);
12
+ export declare function createRunner<Reg extends ActionRegistry>(registry: Reg): <W extends WorkflowDef<Reg, any, any, any, any>>(workflow: W, input: W extends WorkflowDef<Reg, infer I, any, any, any> ? I : never, observers?: any[]) => Promise<{
13
+ output: W extends WorkflowDef<Reg, any, any, any, infer O> ? O : never;
14
+ results: W extends WorkflowDef<Reg, any, infer R, any, any> ? R : never;
15
+ extras: Record<string, any>;
16
+ }>;
10
17
  export {};
package/dist/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { executeWorkflow } from "./workflow-executor.js";
1
2
  /**
2
3
  * For generic actions - preserves the generic parameter
3
4
  */
@@ -15,3 +16,8 @@ export function fixedAction(fn) {
15
16
  return fn;
16
17
  };
17
18
  }
19
+ export function createRunner(registry) {
20
+ return async (workflow, input, observers) => {
21
+ return executeWorkflow(workflow, registry, input, observers ?? []);
22
+ };
23
+ }
@@ -1,10 +1,4 @@
1
1
  import { ActionParams, ActionRegistry, ActionReturn } from "./types.js";
2
- type StepBuilderResult<WB, ID extends string, Default> = WB & {
3
- as<Override>(): OverrideStepResult<WB, ID, Override>;
4
- };
5
- type OverrideStepResult<WB, ID extends string, Override> = WB extends WorkflowBuilder<infer Reg, infer Input, infer Context, infer Steps, infer Results, infer Output> ? WorkflowBuilder<Reg, Input, Context, Steps, Omit<Results, ID> & {
6
- [K in ID]: Override;
7
- }, Output> : never;
8
2
  type NormalizedCall = {
9
3
  kind: "none";
10
4
  } | {
@@ -78,28 +72,31 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
78
72
  input: Input;
79
73
  results: Results;
80
74
  context: Context;
81
- } & CallHelpers<Reg, ActionName>) => ResolveOut, dependsOn?: string[], options?: {}): StepBuilderResult<WorkflowBuilder<Reg, Input, Context, [
75
+ } & CallHelpers<Reg, ActionName>) => ResolveOut, dependsOn?: string[], options?: {}): WorkflowBuilder<Reg, Input, Context, [
82
76
  ...Steps,
83
77
  StepDef<Reg, ID, ActionName>
84
78
  ], Results & {
85
79
  [K in ID]: StepResultFromResolve<Reg, ActionName, ResolveOut>;
86
- }, Output>, ID, StepResultFromResolve<Reg, ActionName, ResolveOut>>;
87
- seq<ID extends string, ActionName extends keyof Reg & string, ResolveOut extends ResolvedStepInput = ResolvedStepInput>(id: ID, action: ActionName, resolve?: (ctx: {
80
+ }>;
81
+ seq<ID extends string = string, ActionName extends keyof Reg & string = any, ResolveOut extends ResolvedStepInput = ResolvedStepInput>(id: ID, action: ActionName, resolve?: (ctx: {
88
82
  input: Input;
89
83
  results: Results;
90
84
  context: Context;
91
- } & CallHelpers<Reg, ActionName>) => ResolveOut, options?: {}): StepBuilderResult<WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K in ID]: StepResultFromResolve<Reg, ActionName, ResolveOut>; }, Output>, ID, StepResultFromResolve<Reg, ActionName, ResolveOut>>;
85
+ } & CallHelpers<Reg, ActionName>) => ResolveOut, options?: {}): WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K in ID]: StepResultFromResolve<Reg, ActionName, ResolveOut>; }, undefined>;
86
+ as<NewType>(): WorkflowBuilder<Reg, Input, Context, Steps, Steps extends [...infer Rest, infer Last] ? Last extends StepDef<Reg, infer ID, any> ? Omit<Results, ID> & {
87
+ [K in ID]: NewType;
88
+ } : Results : Results, Output>;
92
89
  parallel<Branches extends WorkflowBuilder<Reg, Input, Context, any, any>[]>(...branches: {
93
90
  [K in keyof Branches]: (builder: WorkflowBuilder<Reg, Input, Context, [], Results>) => Branches[K];
94
91
  }): WorkflowBuilder<Reg, Input, Context, [
95
92
  ...Steps,
96
93
  ...(Branches[number] extends WorkflowBuilder<Reg, any, any, infer S, any> ? S : never)
97
94
  ], Results & (Branches[number] extends WorkflowBuilder<Reg, any, any, any, infer R> ? UnionToIntersection<R> : {})>;
98
- join<ID extends string, ActionName extends keyof Reg & string, ResolveOut extends ResolvedStepInput = ResolvedStepInput>(id: ID, action: ActionName, resolve?: (ctx: {
95
+ join<ID extends string = string, ActionName extends keyof Reg & string = any, ResolveOut extends ResolvedStepInput = ResolvedStepInput>(id: ID, action: ActionName, resolve?: (ctx: {
99
96
  input: Input;
100
97
  results: Results;
101
98
  context: Context;
102
- } & CallHelpers<Reg, ActionName>) => ResolveOut, options?: {}): StepBuilderResult<WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K in ID]: StepResultFromResolve<Reg, ActionName, ResolveOut>; }, Output>, ID, StepResultFromResolve<Reg, ActionName, ResolveOut>>;
99
+ } & CallHelpers<Reg, ActionName>) => ResolveOut, options?: {}): WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K in ID]: StepResultFromResolve<Reg, ActionName, ResolveOut>; }, undefined>;
103
100
  subflow<Prefix extends string, SubSteps extends StepDef<Reg, any, any>[], WF extends WorkflowDef<Reg, any, any, SubSteps, any>>(prefix: Prefix, workflow: WF, resolveInput: WorkflowInput<WF> extends undefined ? ((ctx: {
104
101
  input: Input;
105
102
  results: Results;
@@ -373,50 +373,6 @@ export class WorkflowBuilder {
373
373
  this.steps = [];
374
374
  this.frontier = [];
375
375
  }
376
- /* ------------------------------------------------ */
377
- /* Base Step */
378
- /* ------------------------------------------------ */
379
- // step<
380
- // ID extends string,
381
- // ActionName extends keyof Reg & string,
382
- // ResolveOut extends ResolvedStepInput = ResolvedStepInput,
383
- // >(
384
- // id: ID,
385
- // action: ActionName,
386
- // resolve?: (
387
- // ctx: {
388
- // input: Input;
389
- // results: Results;
390
- // context: Context;
391
- // } & CallHelpers<Reg, ActionName>,
392
- // ) => ResolveOut,
393
- // dependsOn?: string[],
394
- // options?: {},
395
- // ): WorkflowBuilder<
396
- // Reg,
397
- // Input,
398
- // Context,
399
- // [...Steps, StepDef<Reg, ID, ActionName>],
400
- // Results & { [K in ID]: StepResultFromResolve<Reg, ActionName, ResolveOut> }
401
- // > {
402
- // const deps = dependsOn ?? [...this.frontier];
403
- //
404
- // this.steps.push({
405
- // id,
406
- // action,
407
- // resolve: resolve ?? (() => ({ kind: "none" })),
408
- // dependsOn: deps,
409
- // });
410
- //
411
- // this.frontier = [id];
412
- //
413
- // // with Override
414
- //
415
- // return this as any;
416
- // }
417
- /* ------------------------------------------------ */
418
- /* Base Step */
419
- /* ------------------------------------------------ */
420
376
  step(id, action, resolve, dependsOn, options) {
421
377
  const deps = dependsOn ?? [...this.frontier];
422
378
  this.steps.push({
@@ -426,13 +382,7 @@ export class WorkflowBuilder {
426
382
  dependsOn: deps,
427
383
  });
428
384
  this.frontier = [id];
429
- // with Override
430
- const next = this;
431
- next.as = () => {
432
- return next;
433
- };
434
- return next;
435
- // return this as any;
385
+ return this;
436
386
  }
437
387
  /* ------------------------------------------------ */
438
388
  /* Sequential shortcut */
@@ -441,6 +391,12 @@ export class WorkflowBuilder {
441
391
  return this.step(id, action, resolve, undefined, options);
442
392
  }
443
393
  /* ------------------------------------------------ */
394
+ /* Override the result of the last step */
395
+ /* ------------------------------------------------ */
396
+ as() {
397
+ return this;
398
+ }
399
+ /* ------------------------------------------------ */
444
400
  /* Parallel branches */
445
401
  /* ------------------------------------------------ */
446
402
  parallel(...branches) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pogodisco/zephyr",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },