milkio 1.0.0-alpha.0 β†’ 1.0.0-alpha.2

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/context/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type $types, type Logger } from "..";
1
+ import { type MilkioHttpRequest, type MilkioHttpResponse, type $types, type Logger } from "..";
2
2
 
3
3
  export interface $context {
4
4
  executeId: string;
@@ -15,4 +15,6 @@ export type ContextHttp<ParamsParsed> = {
15
15
  string: string;
16
16
  parsed: ParamsParsed;
17
17
  };
18
+ request: MilkioHttpRequest;
19
+ response: MilkioHttpResponse;
18
20
  };
package/execute/index.ts CHANGED
@@ -38,7 +38,6 @@ export const __initExecuter = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
38
38
  headers = options.headers;
39
39
  }
40
40
  let params: Record<any, unknown>;
41
- if (runtime.port.develop === "disabled") throw reject("NOT_DEVELOP_MODE", "This feature must be in developer mode to use. Usually entering developer mode requires using a cookbook to start milkio and accessing it through localhost.");
42
41
  if (options.paramsType === "raw") {
43
42
  params = options.params;
44
43
  if (typeof params === "undefined") params = {};
@@ -55,13 +54,14 @@ export const __initExecuter = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
55
54
  }
56
55
  if (typeof params !== "object" || Array.isArray(params)) throw reject("PARAMS_TYPE_NOT_SUPPORTED", { expected: "json" });
57
56
  if ("$milkioGenerateParams" in params && params.$milkioGenerateParams === "enable") {
57
+ if (runtime.port.develop === "disabled") throw reject("NOT_DEVELOP_MODE", "This feature must be in developer mode to use. Usually entering developer mode requires using a cookbook to start milkio and accessing it through localhost.");
58
58
  delete params.$milkioGenerateParams;
59
59
  let paramsRand = routeSchema.randomParams();
60
60
  if (paramsRand === undefined || paramsRand === null) paramsRand = {};
61
61
  params = { ...paramsRand, ...params };
62
62
  options.createdLogger.debug("[milkio]", "πŸͺ„ generate params:", options.path, TSON.stringify(params));
63
63
  }
64
- if (options.mixinContext?.detail?.params?.string) options.mixinContext.detail.params.parsed = params; // listen γ§γƒ‘γƒΌγ‚Ήγ—γŸγƒ‘γƒ©γƒ‘γƒΌγ‚Ώγ‚’ζΈ‘γ™
64
+ if (options.mixinContext?.http?.params?.string) options.mixinContext.http.params.parsed = params; // listen γ§γƒ‘γƒΌγ‚Ήγ—γŸγƒ‘γƒ©γƒ‘γƒΌγ‚Ώγ‚’ζΈ‘γ™
65
65
  const context = {
66
66
  ...(options.mixinContext ? options.mixinContext : {}),
67
67
  path: options.path,
package/listener/index.ts CHANGED
@@ -56,7 +56,7 @@ export const __initListener = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
56
56
  };
57
57
 
58
58
  try {
59
- const detail = (await (async () => {
59
+ const http = (await (async () => {
60
60
  const url = new URL(request.url);
61
61
  let pathArray = url.pathname.substring(1).split("/");
62
62
  if (runtime.ignorePathLevel !== undefined && runtime.ignorePathLevel !== 0) pathArray = pathArray.slice(runtime.ignorePathLevel);
@@ -69,25 +69,27 @@ export const __initListener = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
69
69
 
70
70
  return {
71
71
  url,
72
- path: { string: pathString as keyof $types["generated"]["routeSchema"]["$types"], array: pathArray },
73
72
  ip,
73
+ path: { string: pathString as keyof $types["generated"]["routeSchema"]["$types"], array: pathArray },
74
74
  params,
75
+ request,
76
+ response,
75
77
  } as ContextHttp<undefined>;
76
78
  })())!;
77
79
 
78
80
  if (!request.headers.get("Accept")?.startsWith("text/event-stream")) {
79
81
  // action
80
- const routeSchema = generated.routeSchema.routes.get(detail.path.string);
81
- if (routeSchema === undefined) throw reject("NOT_FOUND", { path: detail.path.string as string });
82
+ const routeSchema = generated.routeSchema.routes.get(http.path.string);
83
+ if (routeSchema === undefined) throw reject("NOT_FOUND", { path: http.path.string as string });
82
84
  if (routeSchema.type !== "action") throw reject("UNACCEPTABLE", { expected: "stream", message: `Not acceptable, the Accept in the request header should be "text/event-stream". If you are using the "@milkio/stargate" package, please add \`type: "stream"\` to the execute options.` });
83
85
 
84
86
  const executed = await executer.__call(routeSchema, {
85
87
  createdExecuteId: executeId,
86
88
  createdLogger: logger,
87
- path: detail.path.string as string,
89
+ path: http.path.string as string,
88
90
  headers: request.headers as Headers,
89
- mixinContext: { detail },
90
- params: detail.params.string,
91
+ mixinContext: { http },
92
+ params: http.params.string,
91
93
  paramsType: "string",
92
94
  });
93
95
 
@@ -97,17 +99,17 @@ export const __initListener = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
97
99
  return new Response(response.body, response);
98
100
  } else {
99
101
  // stream
100
- const routeSchema = generated.routeSchema.routes.get(detail.path.string);
101
- if (routeSchema === undefined) throw reject("NOT_FOUND", { path: detail.path.string as string });
102
+ const routeSchema = generated.routeSchema.routes.get(http.path.string);
103
+ if (routeSchema === undefined) throw reject("NOT_FOUND", { path: http.path.string as string });
102
104
  if (routeSchema.type !== "stream") throw reject("UNACCEPTABLE", { expected: "stream", message: `Not acceptable, the Accept in the request header should be "application/json". If you are using the "@milkio/stargate" package, please remove \`type: "stream"\` to the execute options.` });
103
105
 
104
106
  const executed = await executer.__call(routeSchema, {
105
107
  createdExecuteId: executeId,
106
108
  createdLogger: logger,
107
- path: detail.path.string as string,
109
+ path: http.path.string as string,
108
110
  headers: request.headers as Headers,
109
- mixinContext: { detail },
110
- params: detail.params.string,
111
+ mixinContext: { http },
112
+ params: http.params.string,
111
113
  paramsType: "string",
112
114
  });
113
115
  let stream: ReadableStream;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "milkio",
3
3
  "type": "module",
4
4
  "module": "index.ts",
5
- "version": "1.0.0-alpha.0",
5
+ "version": "1.0.0-alpha.2",
6
6
  "peerDependencies": {
7
7
  "typescript": "^5.4.2"
8
8
  },