@pogodisco/zephyr 1.2.7 → 1.2.8

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.
@@ -26,7 +26,11 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
26
26
  private frontier;
27
27
  private outputResolver?;
28
28
  constructor(name: string, registry: Reg, context: Context);
29
- step<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve: (ctx: {
29
+ step<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve?: Parameters<Reg[ActionName]>[0] extends undefined ? (ctx?: {
30
+ input: Input;
31
+ results: Results;
32
+ context: Context;
33
+ }) => undefined : (ctx: {
30
34
  input: Input;
31
35
  results: Results;
32
36
  context: Context;
@@ -36,7 +40,11 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
36
40
  ], Results & {
37
41
  [K in ID]: StepResult<Reg, ActionName>;
38
42
  }>;
39
- seq<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve: (ctx: {
43
+ seq<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve?: Parameters<Reg[ActionName]>[0] extends undefined ? (ctx?: {
44
+ input: Input;
45
+ results: Results;
46
+ context: Context;
47
+ }) => undefined : (ctx: {
40
48
  input: Input;
41
49
  results: Results;
42
50
  context: Context;
@@ -47,15 +55,18 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
47
55
  ...Steps,
48
56
  ...(Branches[number] extends WorkflowBuilder<Reg, any, any, infer S, any> ? S : never)
49
57
  ], Results & (Branches[number] extends WorkflowBuilder<Reg, any, any, any, infer R> ? UnionToIntersection<R> : {})>;
50
- join<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve: (ctx: {
58
+ join<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve?: Parameters<Reg[ActionName]>[0] extends undefined ? (ctx?: {
59
+ input: Input;
60
+ results: Results;
61
+ }) => undefined : (ctx: {
51
62
  input: Input;
52
63
  results: Results;
53
64
  }) => Parameters<Reg[ActionName]>[0]): WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K in ID]: Awaited<ReturnType<Reg[ActionName]>>; }, undefined>;
54
- subflow<Prefix extends string, SubInput, SubResults, SubSteps extends StepDef<Reg, any, any>[], SubOutput>(prefix: Prefix, workflow: WorkflowDef<Reg, SubInput, SubResults, SubSteps, SubOutput>, resolveInput: (ctx: {
65
+ subflow<Prefix extends string, SubInput, SubResults, SubSteps extends StepDef<Reg, any, any>[], SubOutput>(prefix: Prefix, workflow: WorkflowDef<Reg, SubInput, SubResults, SubSteps, SubOutput>, resolveInput?: (ctx: {
55
66
  input: Input;
56
67
  results: Results;
57
68
  context: Context;
58
- }) => SubInput): WorkflowBuilder<Reg, Input, Context, [
69
+ }) => [SubInput] extends [never] ? any : SubInput & Record<Exclude<keyof SubInput, keyof any>, never>): WorkflowBuilder<Reg, Input, Context, [
59
70
  ...Steps,
60
71
  ...SubSteps
61
72
  ], Results & {
@@ -560,7 +560,7 @@ export class WorkflowBuilder {
560
560
  this.steps.push({
561
561
  id,
562
562
  action,
563
- resolve,
563
+ resolve: resolve ?? (() => undefined),
564
564
  dependsOn: deps,
565
565
  });
566
566
  this.frontier = [id];
@@ -607,7 +607,8 @@ export class WorkflowBuilder {
607
607
  id: idMap.get(step.id),
608
608
  dependsOn: step.dependsOn.map((d) => idMap.get(d)),
609
609
  resolve: (ctx) => {
610
- const subInput = resolveInput(ctx);
610
+ const subInput = resolveInput ? resolveInput(ctx) : undefined;
611
+ // const subInput = resolveInput(ctx);
611
612
  return step.resolve({
612
613
  input: subInput,
613
614
  results: ctx.results,
@@ -627,9 +628,6 @@ export class WorkflowBuilder {
627
628
  this.outputResolver = fn;
628
629
  return this.build();
629
630
  }
630
- /* ------------------------------------------------ */
631
- /* Build */
632
- /* ------------------------------------------------ */
633
631
  build() {
634
632
  this.validateDependencies();
635
633
  return {
@@ -642,7 +640,6 @@ export class WorkflowBuilder {
642
640
  outputResolver: this.outputResolver,
643
641
  };
644
642
  }
645
- /* ------------------------------------------------ */
646
643
  validateDependencies() {
647
644
  const stepIds = new Set(this.steps.map((s) => s.id));
648
645
  for (const step of this.steps) {
@@ -132,10 +132,13 @@ export async function executeWorkflow(workflow, registry, input, middleware = []
132
132
  const ctx = { stepId, input, results, registry, extras, frame };
133
133
  const core = async () => {
134
134
  frame.attempts++;
135
- frame.input = step.resolve({ input, results });
135
+ frame.input = step.resolve?.({ input, results }) ?? undefined;
136
136
  try {
137
137
  const action = registry[step.action];
138
- const result = await action(frame.input);
138
+ const result = frame.input === undefined
139
+ ? await action()
140
+ : await action(frame.input);
141
+ // const result = await action(frame.input);
139
142
  frame.output = result;
140
143
  frame.end = Date.now();
141
144
  results[step.id] = result;
@@ -44,53 +44,3 @@ export function createModule({ registry, context, use, define, }) {
44
44
  ...own,
45
45
  };
46
46
  }
47
- // type MergeFlows<T extends any[]> = T extends [infer F, ...infer R]
48
- // ? F extends { flows: infer Fl }
49
- // ? MergeFlows<R> & Fl
50
- // : MergeFlows<R>
51
- // : {};
52
- //
53
- // type Module<
54
- // Reg extends ActionRegistry,
55
- // Context extends Record<string, any>,
56
- // Flows,
57
- // > = {
58
- // wf: ReturnType<typeof createWorkflow<Reg, Context>>;
59
- // flows: Flows;
60
- // };
61
- //
62
- // export function createModule<
63
- // Reg extends ActionRegistry,
64
- // Context extends Record<string, any>,
65
- // Flows extends Record<string, any>,
66
- // UseModules extends Module<any, any, any>[] = [],
67
- // >({
68
- // registry,
69
- // context,
70
- // use = [] as unknown as UseModules,
71
- // define,
72
- // }: {
73
- // registry: Reg;
74
- // context: Context;
75
- // use?: UseModules;
76
- // define?: (
77
- // wf: ReturnType<typeof createWorkflow<Reg, Context>>,
78
- // deps: MergeFlows<UseModules>,
79
- // ) => Flows;
80
- // }) {
81
- // const wf = createWorkflow(registry, context);
82
- //
83
- // const inherited = Object.assign({}, ...use.map((m) => m.flows));
84
- // const own = define ? define(wf, inherited as MergeFlows<UseModules>) : {};
85
- //
86
- // const flows = {
87
- // ...inherited,
88
- // ...own,
89
- // };
90
- //
91
- // return {
92
- // wf,
93
- // flows,
94
- // ...flows,
95
- // } as Module<Reg, Context, typeof flows>;
96
- // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pogodisco/zephyr",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },