milkio 0.7.0-alpha.4 → 0.7.0-alpha.5
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 +16 -13
- package/kernel/execute.ts +2 -2
- package/package.json +1 -1
package/kernel/context.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type MilkioContext = {
|
|
|
11
11
|
* During testing or when calling between microservices, some or all of the values may be undefined
|
|
12
12
|
*/
|
|
13
13
|
detail: FrameworkHttpDetail;
|
|
14
|
-
|
|
14
|
+
step: Steps<{}>['step'];
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export type FrameworkHttpDetail = {
|
|
@@ -30,17 +30,20 @@ export type Steps<StageT extends Record<any, any>> = {
|
|
|
30
30
|
|
|
31
31
|
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>>>>>
|
|
32
32
|
|
|
33
|
-
export const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
export const createStep = () => {
|
|
34
|
+
const stepController = {
|
|
35
|
+
_steps: [] as Array<(stage: any) => Promise<any>>,
|
|
36
|
+
step(handler: (stage: any) => Promise<any>) {
|
|
37
|
+
this._steps.push(handler);
|
|
38
|
+
return this;
|
|
39
|
+
},
|
|
40
|
+
async run(handler: any) {
|
|
41
|
+
let stage = {};
|
|
42
|
+
for (const step of this._steps) {
|
|
43
|
+
stage = { ...stage, ...(await step(stage)) }
|
|
44
|
+
}
|
|
45
|
+
return await handler(stage);
|
|
43
46
|
}
|
|
44
|
-
return await handler(stage);
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
return stepController.step as any as Steps<{}>['step'];
|
|
49
|
+
};
|
package/kernel/execute.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Context } from "../../../src/context";
|
|
2
2
|
import { failCode } from "../../../src/fail-code";
|
|
3
3
|
import schema from "../../../generated/api-schema";
|
|
4
|
-
import { type ExecuteId, type ExecuteOptions, type ExecuteResult, createUlid, useLogger, runtime, loggerPushTags, headerToPlainObject, loggerSubmit, type ExecuteCoreOptions, TSON, MiddlewareEvent, reject, _validate, ExecuteStreamResult,
|
|
4
|
+
import { type ExecuteId, type ExecuteOptions, type ExecuteResult, createUlid, useLogger, runtime, loggerPushTags, headerToPlainObject, loggerSubmit, type ExecuteCoreOptions, TSON, MiddlewareEvent, reject, _validate, ExecuteStreamResult, createStep } from "..";
|
|
5
5
|
import { handleCatchError } from "../utils/handle-catch-error";
|
|
6
6
|
|
|
7
7
|
const apis = new Map<string, any>();
|
|
@@ -56,7 +56,7 @@ export async function _call(
|
|
|
56
56
|
headers,
|
|
57
57
|
logger: options.logger,
|
|
58
58
|
detail: options?.detail ?? {} as any,
|
|
59
|
-
|
|
59
|
+
step: createStep(),
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
let result: { value: unknown };
|