@pogodisco/zephyr 1.5.3 → 1.5.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.
package/dist/utils.js
CHANGED
|
@@ -25,7 +25,7 @@ export declare class PipeBuilder<Current, Reg extends ActionRegistry, Services e
|
|
|
25
25
|
action<A extends keyof Reg & string>(action: A, resolve: (ctx: {
|
|
26
26
|
current: Current;
|
|
27
27
|
results: Results;
|
|
28
|
-
} & CallHelpers<Reg, A>) => NormalizedCall): PipeBuilder<ActionReturn<Reg, A>, Reg, Services, Results, [
|
|
28
|
+
} & Results & CallHelpers<Reg, A>) => NormalizedCall): PipeBuilder<ActionReturn<Reg, A>, Reg, Services, Results, [
|
|
29
29
|
...Steps,
|
|
30
30
|
{
|
|
31
31
|
type: "action";
|
|
@@ -35,7 +35,7 @@ export declare class PipeBuilder<Current, Reg extends ActionRegistry, Services e
|
|
|
35
35
|
service<SK extends keyof Services & string, MK extends keyof Services[SK] & string>(id: string, service: SK, method: MK, resolve: (ctx: {
|
|
36
36
|
current: Current;
|
|
37
37
|
results: Results;
|
|
38
|
-
} & {
|
|
38
|
+
} & Results & {
|
|
39
39
|
args: (...args: ServiceParams<Services, SK, MK>) => {
|
|
40
40
|
kind: "positional";
|
|
41
41
|
args: ServiceParams<Services, SK, MK>;
|
|
@@ -47,16 +47,6 @@ export declare class PipeBuilder<Current, Reg extends ActionRegistry, Services e
|
|
|
47
47
|
none: () => {
|
|
48
48
|
kind: "none";
|
|
49
49
|
};
|
|
50
|
-
loop: (items: {
|
|
51
|
-
kind: "positional";
|
|
52
|
-
args: ServiceParams<Services, SK, MK>;
|
|
53
|
-
}[] | {
|
|
54
|
-
kind: "object";
|
|
55
|
-
args: ServiceParams<Services, SK, MK>[0];
|
|
56
|
-
}[]) => {
|
|
57
|
-
kind: "loop";
|
|
58
|
-
items: typeof items;
|
|
59
|
-
};
|
|
60
50
|
}) => NormalizedCall): PipeBuilder<ServiceReturn<Services, SK, MK>, Reg, Services, Results, [
|
|
61
51
|
...Steps,
|
|
62
52
|
{
|
|
@@ -57,7 +57,7 @@ Input = unknown, Steps extends StepDef<Reg, any, any>[] = [], Results = {}, Outp
|
|
|
57
57
|
step<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve?: (ctx: {
|
|
58
58
|
input: Input;
|
|
59
59
|
results: Results;
|
|
60
|
-
} & CallHelpers<Reg, ActionName>) => NormalizedCall, dependsOn?: string[], options?: StepOptions<Input, Results>): WorkflowBuilder<Reg, Services, WFReg, Input, [
|
|
60
|
+
} & Results & CallHelpers<Reg, ActionName>) => NormalizedCall, dependsOn?: string[], options?: StepOptions<Input, Results>): WorkflowBuilder<Reg, Services, WFReg, Input, [
|
|
61
61
|
...Steps,
|
|
62
62
|
StepDef<Reg, ID, ActionName>
|
|
63
63
|
], Simplify<Results & {
|
|
@@ -66,11 +66,11 @@ Input = unknown, Steps extends StepDef<Reg, any, any>[] = [], Results = {}, Outp
|
|
|
66
66
|
seq<ID extends string = string, ActionName extends keyof Reg & string = any>(id: ID, action: ActionName, resolve?: (ctx: {
|
|
67
67
|
input: Input;
|
|
68
68
|
results: Results;
|
|
69
|
-
} & CallHelpers<Reg, ActionName>) => NormalizedCall, options?: StepOptions<Input, Results>): WorkflowBuilder<Reg, Services, WFReg, Input, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K_1 in ID]: ActionReturn<Reg, ActionName>; } extends infer T ? { [K in keyof T]: T[K]; } : never, undefined>;
|
|
69
|
+
} & Results & CallHelpers<Reg, ActionName>) => NormalizedCall, options?: StepOptions<Input, Results>): WorkflowBuilder<Reg, Services, WFReg, Input, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K_1 in ID]: ActionReturn<Reg, ActionName>; } extends infer T ? { [K in keyof T]: T[K]; } : never, undefined>;
|
|
70
70
|
service<ID extends string, SK extends keyof Services & string, MK extends keyof Services[SK] & string>(id: ID, service: SK, method: MK, resolve?: (ctx: {
|
|
71
71
|
input: Input;
|
|
72
72
|
results: Results;
|
|
73
|
-
} & {
|
|
73
|
+
} & Results & {
|
|
74
74
|
args: (...args: ServiceParams<Services, SK, MK>) => {
|
|
75
75
|
kind: "positional";
|
|
76
76
|
args: ServiceParams<Services, SK, MK>;
|
|
@@ -106,22 +106,24 @@ Input = unknown, Steps extends StepDef<Reg, any, any>[] = [], Results = {}, Outp
|
|
|
106
106
|
join<ID extends string = string, ActionName extends keyof Reg & string = any>(id: ID, action: ActionName, resolve?: (ctx: {
|
|
107
107
|
input: Input;
|
|
108
108
|
results: Results;
|
|
109
|
-
} & CallHelpers<Reg, ActionName>) => NormalizedCall, options?: StepOptions<Input, Results>): WorkflowBuilder<Reg, Services, WFReg, Input, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K_1 in ID]: ActionReturn<Reg, ActionName>; } extends infer T ? { [K in keyof T]: T[K]; } : never, undefined>;
|
|
109
|
+
} & Results & CallHelpers<Reg, ActionName>) => NormalizedCall, options?: StepOptions<Input, Results>): WorkflowBuilder<Reg, Services, WFReg, Input, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K_1 in ID]: ActionReturn<Reg, ActionName>; } extends infer T ? { [K in keyof T]: T[K]; } : never, undefined>;
|
|
110
110
|
subflow<Prefix extends string, K extends keyof WFReg & string>(prefix: Prefix, workflowKey: K, resolveInput: (ctx: {
|
|
111
111
|
input: Input;
|
|
112
112
|
results: Results;
|
|
113
113
|
}) => WorkflowInput<WFReg[K]>, options?: StepOptions<Input, Results>): WorkflowBuilder<Reg, Services, WFReg, Input, Steps, Results & {
|
|
114
114
|
[P in Prefix]: WorkflowOutput<WFReg[K]>;
|
|
115
115
|
}>;
|
|
116
|
+
private _subflow;
|
|
117
|
+
sub: this["subflow"];
|
|
116
118
|
when(predicate: (ctx: {
|
|
117
119
|
input: Input;
|
|
118
120
|
results: Results;
|
|
119
|
-
}) => boolean): WorkflowBuilder<Reg, Services, WFReg, Input, Steps, Results, Output>;
|
|
121
|
+
} & Results) => boolean): WorkflowBuilder<Reg, Services, WFReg, Input, Steps, Results, Output>;
|
|
120
122
|
endWhen(): this;
|
|
121
123
|
output<Output>(fn: (ctx: {
|
|
122
124
|
input: Input;
|
|
123
125
|
results: Results;
|
|
124
|
-
}) => Output): WorkflowDef<Reg, Input, Results, Steps, Output>;
|
|
126
|
+
} & Results) => Output): WorkflowDef<Reg, Input, Results, Steps, Output>;
|
|
125
127
|
build(): WorkflowDef<Reg, Input, Results, Steps>;
|
|
126
128
|
private validateDependencies;
|
|
127
129
|
private getEndSteps;
|
|
@@ -11,6 +11,8 @@ export class WorkflowBuilder {
|
|
|
11
11
|
this.name = name;
|
|
12
12
|
this.steps = [];
|
|
13
13
|
this.frontier = [];
|
|
14
|
+
this._subflow = this.subflow.bind(this);
|
|
15
|
+
this.sub = ((...args) => this._subflow(...args));
|
|
14
16
|
}
|
|
15
17
|
step(id, action, resolve, dependsOn, options) {
|
|
16
18
|
const deps = dependsOn ?? [...this.frontier];
|
|
@@ -14,6 +14,24 @@ async function withTimeout(promise, ms) {
|
|
|
14
14
|
new Promise((_, reject) => setTimeout(() => reject(new Error("Timeout")), ms)),
|
|
15
15
|
]);
|
|
16
16
|
}
|
|
17
|
+
function createStepCtx(input, results) {
|
|
18
|
+
const helpers = createCallHelpers();
|
|
19
|
+
return new Proxy({
|
|
20
|
+
input,
|
|
21
|
+
results,
|
|
22
|
+
...helpers,
|
|
23
|
+
}, {
|
|
24
|
+
get(target, prop) {
|
|
25
|
+
// 1. explicit keys first
|
|
26
|
+
if (prop in target)
|
|
27
|
+
return target[prop];
|
|
28
|
+
// 2. fallback to results
|
|
29
|
+
if (prop in results)
|
|
30
|
+
return results[prop];
|
|
31
|
+
return undefined;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
17
35
|
// Helper to run action with retry support
|
|
18
36
|
async function runWithRetry(actionFn, stepOptions) {
|
|
19
37
|
const maxRetries = stepOptions?.retry ?? 0;
|
|
@@ -100,11 +118,13 @@ export async function executeWorkflow({ workflow, actionRegistry, services, inpu
|
|
|
100
118
|
extras,
|
|
101
119
|
frame,
|
|
102
120
|
};
|
|
103
|
-
const stepCtx =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
121
|
+
const stepCtx = createStepCtx(input, results);
|
|
122
|
+
// const stepCtx = {
|
|
123
|
+
// input,
|
|
124
|
+
// results,
|
|
125
|
+
//
|
|
126
|
+
// ...createCallHelpers(),
|
|
127
|
+
// };
|
|
108
128
|
const resolvedArgs = step.resolve?.(stepCtx);
|
|
109
129
|
frame.input = resolvedArgs;
|
|
110
130
|
const core = async () => {
|
|
@@ -219,11 +239,9 @@ export async function executeWorkflow({ workflow, actionRegistry, services, inpu
|
|
|
219
239
|
if (completed !== workflow.steps.length) {
|
|
220
240
|
throw new Error("Workflow execution failed (cycle or missing dependency)");
|
|
221
241
|
}
|
|
242
|
+
const outputCtx = createStepCtx(input, results);
|
|
222
243
|
const output = workflow.outputResolver
|
|
223
|
-
? workflow.outputResolver(
|
|
224
|
-
input,
|
|
225
|
-
results,
|
|
226
|
-
})
|
|
244
|
+
? workflow.outputResolver(outputCtx)
|
|
227
245
|
: results;
|
|
228
246
|
return {
|
|
229
247
|
// results: results as WorkflowResults<WR[K]>,
|