milkio 0.7.0-alpha.5 → 0.7.0-alpha.6
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/kernel/context.ts +13 -7
- package/package.json +1 -1
- package/types.ts +5 -1
package/kernel/context.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExecuteId, Logger, MilkioHttpResponse, Mixin, ToEmptyObject } from "..";
|
|
1
|
+
import type { ExecuteId, Logger, MilkioHttpResponse, Mixin, ToEmptyObject, Remove$ } from "..";
|
|
2
2
|
|
|
3
3
|
export type MilkioContext = {
|
|
4
4
|
path: string;
|
|
@@ -25,7 +25,8 @@ export type FrameworkHttpDetail = {
|
|
|
25
25
|
|
|
26
26
|
export type Steps<StageT extends Record<any, any>> = {
|
|
27
27
|
step: StepFunction<StageT>,
|
|
28
|
-
run: <HandlerT extends (stage: StageT) => Record<any, any> | Promise<Record<any, any>>>(handler: HandlerT) => Promise<Awaited<ReturnType<HandlerT>>>,
|
|
28
|
+
// run: <HandlerT extends (stage: StageT) => Record<any, any> | Promise<Record<any, any>>>(handler: HandlerT) => Promise<Awaited<ReturnType<HandlerT>>>,
|
|
29
|
+
run: () => Promise<Remove$<StageT>>
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
type StepFunction<StageT extends Record<any, any>> = <HandlerT extends ((stage: Readonly<StageT>) => Record<any, any> | Promise<Record<any, any>>) >(handler: HandlerT) => Steps<Mixin<StageT, ToEmptyObject<Awaited<ReturnType<HandlerT>>>>>
|
|
@@ -34,15 +35,20 @@ export const createStep = () => {
|
|
|
34
35
|
const stepController = {
|
|
35
36
|
_steps: [] as Array<(stage: any) => Promise<any>>,
|
|
36
37
|
step(handler: (stage: any) => Promise<any>) {
|
|
37
|
-
|
|
38
|
-
return
|
|
38
|
+
stepController._steps.push(handler);
|
|
39
|
+
return stepController;
|
|
39
40
|
},
|
|
40
|
-
async run(
|
|
41
|
+
async run() {
|
|
41
42
|
let stage = {};
|
|
42
|
-
for (const step of
|
|
43
|
+
for (const step of stepController._steps) {
|
|
43
44
|
stage = { ...stage, ...(await step(stage)) }
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
let result: Record<any, any> = {};
|
|
47
|
+
for (const key in stage) {
|
|
48
|
+
const value = (stage as any)[key];
|
|
49
|
+
if (!key.startsWith('$')) result[key] = value;
|
|
50
|
+
}
|
|
51
|
+
return stage;
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
54
|
return stepController.step as any as Steps<{}>['step'];
|
package/package.json
CHANGED