milkio 0.7.0-alpha.4 → 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 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;
@@ -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
- steps: Steps<{}>;
14
+ step: Steps<{}>['step'];
15
15
  };
16
16
 
17
17
  export type FrameworkHttpDetail = {
@@ -25,22 +25,31 @@ 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>>>>>
32
33
 
33
- export const createSteps = () => ({
34
- _steps: [],
35
- step(handler: (stage: any) => Promise<any>) {
36
- this.steps.push(handler);
37
- return this;
38
- },
39
- async run(handler: any) {
40
- let stage = {};
41
- for (const step of this._steps) {
42
- stage = { ...stage, ...(await step(stage)) }
34
+ export const createStep = () => {
35
+ const stepController = {
36
+ _steps: [] as Array<(stage: any) => Promise<any>>,
37
+ step(handler: (stage: any) => Promise<any>) {
38
+ stepController._steps.push(handler);
39
+ return stepController;
40
+ },
41
+ async run() {
42
+ let stage = {};
43
+ for (const step of stepController._steps) {
44
+ stage = { ...stage, ...(await step(stage)) }
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;
43
52
  }
44
- return await handler(stage);
45
53
  }
46
- }) as any as Steps<{}>;
54
+ return stepController.step as any as Steps<{}>['step'];
55
+ };
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, createSteps } from "..";
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
- steps: createSteps(),
59
+ step: createStep(),
60
60
  };
61
61
 
62
62
  let result: { value: unknown };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "milkio",
3
3
  "type": "module",
4
4
  "module": "index.ts",
5
- "version": "0.7.0-alpha.4",
5
+ "version": "0.7.0-alpha.6",
6
6
  "peerDependencies": {
7
7
  "typescript": "^5.4.2"
8
8
  },
package/types.ts CHANGED
@@ -99,4 +99,8 @@ export type ToEmptyObject<T> = T extends undefined | null | never
99
99
  ? {}
100
100
  : T extends object
101
101
  ? T
102
- : {};
102
+ : {};
103
+
104
+ type Remove$<T> = {
105
+ [K in keyof T as K extends `$${string}` ? never : K]: T[K];
106
+ };