milkio 1.0.0-alpha.0 β 1.0.0-alpha.1
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 +3 -1
- package/execute/index.ts +1 -1
- package/listener/index.ts +14 -12
- package/package.json +1 -1
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
|
@@ -61,7 +61,7 @@ export const __initExecuter = <MilkioRuntime extends MilkioRuntimeInit<MilkioRun
|
|
|
61
61
|
params = { ...paramsRand, ...params };
|
|
62
62
|
options.createdLogger.debug("[milkio]", "πͺ generate params:", options.path, TSON.stringify(params));
|
|
63
63
|
}
|
|
64
|
-
if (options.mixinContext?.
|
|
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
|
|
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(
|
|
81
|
-
if (routeSchema === undefined) throw reject("NOT_FOUND", { path:
|
|
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:
|
|
89
|
+
path: http.path.string as string,
|
|
88
90
|
headers: request.headers as Headers,
|
|
89
|
-
mixinContext: {
|
|
90
|
-
params:
|
|
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(
|
|
101
|
-
if (routeSchema === undefined) throw reject("NOT_FOUND", { path:
|
|
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:
|
|
109
|
+
path: http.path.string as string,
|
|
108
110
|
headers: request.headers as Headers,
|
|
109
|
-
mixinContext: {
|
|
110
|
-
params:
|
|
111
|
+
mixinContext: { http },
|
|
112
|
+
params: http.params.string,
|
|
111
113
|
paramsType: "string",
|
|
112
114
|
});
|
|
113
115
|
let stream: ReadableStream;
|