@pogodisco/zephyr 1.3.11 → 1.3.12
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/workflow-composer.d.ts +14 -15
- package/dist/workflow-composer.js +16 -7
- package/dist/workflow-module.d.ts +4 -2
- package/dist/workflow-module.js +15 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionParams, ActionRegistry, ActionReturn } from "./types.js";
|
|
1
|
+
import { ActionParams, ActionRegistry, ActionReturn, Simplify } from "./types.js";
|
|
2
2
|
type NormalizedCall = {
|
|
3
3
|
kind: "none";
|
|
4
4
|
} | {
|
|
@@ -74,7 +74,11 @@ type StepOptions<Input, Results, Context> = {
|
|
|
74
74
|
label?: string;
|
|
75
75
|
meta?: Record<string, any>;
|
|
76
76
|
};
|
|
77
|
-
type
|
|
77
|
+
type MergeBranchResults<Branches extends readonly any[], Acc> = Branches extends readonly [infer Head, ...infer Tail] ? MergeBranchResults<Tail, Acc & (Head extends WorkflowBuilder<any, any, any, any, infer R> ? R : {})> : Acc;
|
|
78
|
+
type MergeBranchSteps<Branches extends readonly any[], Acc extends any[]> = Branches extends readonly [infer Head, ...infer Tail] ? MergeBranchSteps<Tail, [
|
|
79
|
+
...Acc,
|
|
80
|
+
...(Head extends WorkflowBuilder<any, any, any, infer S, any> ? S : [])
|
|
81
|
+
]> : Acc;
|
|
78
82
|
export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown, Context extends Record<string, any> = {}, Steps extends StepDef<Reg, any, any>[] = [], Results = {}, Output = undefined> {
|
|
79
83
|
private name;
|
|
80
84
|
private registry;
|
|
@@ -92,30 +96,25 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
|
|
|
92
96
|
} & CallHelpers<Reg, ActionName>) => ResolveOut, dependsOn?: string[], options?: StepOptions<Input, Results, Context>): WorkflowBuilder<Reg, Input, Context, [
|
|
93
97
|
...Steps,
|
|
94
98
|
StepDef<Reg, ID, ActionName>
|
|
95
|
-
], Results & {
|
|
99
|
+
], Simplify<Results & {
|
|
96
100
|
[K in ID]: StepResultFromResolve<Reg, ActionName, ResolveOut>;
|
|
97
|
-
}
|
|
101
|
+
}>>;
|
|
98
102
|
seq<ID extends string = string, ActionName extends keyof Reg & string = any, ResolveOut extends ResolvedStepInput = ResolvedStepInput>(id: ID, action: ActionName, resolve?: (ctx: {
|
|
99
103
|
input: Input;
|
|
100
104
|
results: Results;
|
|
101
105
|
context: Context;
|
|
102
|
-
} & CallHelpers<Reg, ActionName>) => ResolveOut, options?: StepOptions<Input, Results, Context>): WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [
|
|
103
|
-
as<NewType>(): WorkflowBuilder<Reg, Input, Context, Steps, Steps extends [...infer Rest, infer Last] ? Last extends StepDef<Reg, infer ID, any> ? Omit<Results, ID> & {
|
|
106
|
+
} & CallHelpers<Reg, ActionName>) => ResolveOut, options?: StepOptions<Input, Results, Context>): WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K_1 in ID]: StepResultFromResolve<Reg, ActionName, ResolveOut>; } extends infer T ? { [K in keyof T]: T[K]; } : never, undefined>;
|
|
107
|
+
as<NewType>(): WorkflowBuilder<Reg, Input, Context, Steps, Steps extends [...infer Rest, infer Last] ? Last extends StepDef<Reg, infer ID, any> ? Simplify<Omit<Results, ID> & {
|
|
104
108
|
[K in ID]: NewType;
|
|
105
|
-
} : Results : Results, Output>;
|
|
106
|
-
parallel<Branches extends WorkflowBuilder<Reg, Input, Context, any, any>[]>(...branches: {
|
|
109
|
+
}> : Results : Results, Output>;
|
|
110
|
+
parallel<Branches extends readonly WorkflowBuilder<Reg, Input, Context, any, any>[]>(...branches: {
|
|
107
111
|
[K in keyof Branches]: (builder: WorkflowBuilder<Reg, Input, Context, [], Results>) => Branches[K];
|
|
108
|
-
}): WorkflowBuilder<Reg, Input, Context,
|
|
109
|
-
...Steps,
|
|
110
|
-
...(Branches[number] extends WorkflowBuilder<Reg, any, any, infer S, any> ? S : never)
|
|
111
|
-
], Results & UnionToIntersection<{
|
|
112
|
-
[K in keyof Branches]: Branches[K] extends WorkflowBuilder<Reg, any, any, any, infer R> ? R : never;
|
|
113
|
-
}[number]>>;
|
|
112
|
+
}): WorkflowBuilder<Reg, Input, Context, MergeBranchSteps<Branches, Steps>, Simplify<MergeBranchResults<Branches, Results>>>;
|
|
114
113
|
join<ID extends string = string, ActionName extends keyof Reg & string = any, ResolveOut extends ResolvedStepInput = ResolvedStepInput>(id: ID, action: ActionName, resolve?: (ctx: {
|
|
115
114
|
input: Input;
|
|
116
115
|
results: Results;
|
|
117
116
|
context: Context;
|
|
118
|
-
} & CallHelpers<Reg, ActionName>) => ResolveOut, options?: StepOptions<Input, Results, Context>): WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [
|
|
117
|
+
} & CallHelpers<Reg, ActionName>) => ResolveOut, options?: StepOptions<Input, Results, Context>): WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K_1 in ID]: StepResultFromResolve<Reg, ActionName, ResolveOut>; } extends infer T ? { [K in keyof T]: T[K]; } : never, undefined>;
|
|
119
118
|
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: {
|
|
120
119
|
input: Input;
|
|
121
120
|
results: Results;
|
|
@@ -37,9 +37,6 @@ export class WorkflowBuilder {
|
|
|
37
37
|
as() {
|
|
38
38
|
return this;
|
|
39
39
|
}
|
|
40
|
-
/* ------------------------------------------------ */
|
|
41
|
-
/* Parallel branches */
|
|
42
|
-
/* ------------------------------------------------ */
|
|
43
40
|
// parallel<Branches extends WorkflowBuilder<Reg, Input, Context, any, any>[]>(
|
|
44
41
|
// ...branches: {
|
|
45
42
|
// [K in keyof Branches]: (
|
|
@@ -56,10 +53,22 @@ export class WorkflowBuilder {
|
|
|
56
53
|
// ? S
|
|
57
54
|
// : never),
|
|
58
55
|
// ],
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
56
|
+
// Simplify<
|
|
57
|
+
// Results &
|
|
58
|
+
// UnionToIntersection<
|
|
59
|
+
// {
|
|
60
|
+
// [K in keyof Branches]: Branches[K] extends WorkflowBuilder<
|
|
61
|
+
// Reg,
|
|
62
|
+
// any,
|
|
63
|
+
// any,
|
|
64
|
+
// any,
|
|
65
|
+
// infer R
|
|
66
|
+
// >
|
|
67
|
+
// ? R
|
|
68
|
+
// : never;
|
|
69
|
+
// }[number]
|
|
70
|
+
// >
|
|
71
|
+
// >
|
|
63
72
|
// > {
|
|
64
73
|
// const parentFrontier = [...this.frontier];
|
|
65
74
|
// const branchEnds: string[] = [];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionRegistry } from "./types.js";
|
|
1
|
+
import { ActionRegistry, Simplify } from "./types.js";
|
|
2
2
|
import { createWorkflow, WorkflowDef } from "./workflow-composer.js";
|
|
3
3
|
type AnyWorkflow = WorkflowDef<any, any, any, any, any>;
|
|
4
4
|
type ModuleShape = Record<string, AnyWorkflow>;
|
|
@@ -14,7 +14,9 @@ export type ModuleContext<Reg extends ActionRegistry, Context extends Record<str
|
|
|
14
14
|
context: Context;
|
|
15
15
|
}) => T) => T;
|
|
16
16
|
};
|
|
17
|
-
export declare function createModule<Reg extends ActionRegistry, Context extends Record<string, any>, Use extends ModuleShape[] = [], Deps extends ModuleShape =
|
|
17
|
+
export declare function createModule<Reg extends ActionRegistry, Context extends Record<string, any>, Use extends ModuleShape[] = [], Deps extends ModuleShape = Simplify<{
|
|
18
|
+
[K in keyof UnionToIntersectionOrEmpty<Use[number]>]: AnyWorkflow;
|
|
19
|
+
}>, Own extends ModuleShape = {}>({ registry, context, use, define, }: {
|
|
18
20
|
registry: Reg;
|
|
19
21
|
context: Context;
|
|
20
22
|
use?: [...Use];
|
package/dist/workflow-module.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import { createWorkflow, } from "./workflow-composer.js";
|
|
2
|
+
function mergeModules(mods) {
|
|
3
|
+
const seen = new Set();
|
|
4
|
+
const result = {};
|
|
5
|
+
for (const mod of mods) {
|
|
6
|
+
for (const key in mod) {
|
|
7
|
+
if (!seen.has(key)) {
|
|
8
|
+
seen.add(key);
|
|
9
|
+
result[key] = mod[key];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
2
15
|
export function createModule({ registry, context, use, define, }) {
|
|
3
16
|
const wf = createWorkflow(registry, context);
|
|
4
|
-
const deps = (use ? Object.assign({}, ...use) : {});
|
|
17
|
+
// const deps = (use ? Object.assign({}, ...use) : {}) as Deps;
|
|
18
|
+
const deps = (use ? mergeModules(use) : {});
|
|
5
19
|
const moduleCtx = {
|
|
6
20
|
wf,
|
|
7
21
|
deps,
|