milkio 0.1.2 → 0.2.0
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/api-test/index.ts +65 -65
- package/c.ts +37 -35
- package/defines/define-api-test.ts +24 -17
- package/defines/define-api.ts +9 -9
- package/defines/define-command-handler.ts +41 -41
- package/defines/define-http-handler.ts +181 -181
- package/defines/define-middleware.ts +6 -6
- package/defines/define-use.ts +10 -10
- package/index.ts +22 -22
- package/kernel/context.ts +17 -17
- package/kernel/fail.ts +13 -13
- package/kernel/logger.ts +96 -96
- package/kernel/meta.ts +6 -6
- package/kernel/middleware.ts +32 -32
- package/kernel/milkio.ts +250 -224
- package/kernel/runtime.ts +9 -9
- package/kernel/validate.ts +9 -9
- package/package.json +1 -1
- package/scripts/gen-insignificant.ts +239 -239
- package/scripts/gen-significant.ts +118 -120
- package/utils/create-ulid.ts +3 -3
- package/utils/env-to-boolean.ts +5 -5
- package/utils/env-to-number.ts +2 -2
- package/utils/env-to-string.ts +2 -2
- package/utils/exec.ts +18 -18
- package/utils/handle-catch-error.ts +37 -37
- package/utils/header-to-plain-object.ts +7 -7
- package/utils/remove-dir.ts +19 -19
- package/utils/tson.ts +2 -2
- package/.co.toml +0 -2
package/kernel/milkio.ts
CHANGED
|
@@ -1,115 +1,125 @@
|
|
|
1
1
|
/* eslint-disable no-console, @typescript-eslint/no-invalid-void-type, @typescript-eslint/await-thenable, @typescript-eslint/ban-types, @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { type MiddlewareOptions, _middlewares, MiddlewareEvent } from "./middleware"
|
|
3
|
-
import schema from "../../../generated/api-schema"
|
|
4
|
-
import type { Context } from "../../../src/context"
|
|
5
|
-
import { failCode } from "../../../src/fail-code"
|
|
6
|
-
import type { MilkioContext } from "./context"
|
|
7
|
-
import { headerToPlainObject } from "../utils/header-to-plain-object"
|
|
8
|
-
import { type Mixin, type ExecuteId, type Fail, type FailEnumerates, loggerPushTags, loggerSubmit, runtime, TSON, type Logger, useLogger, reject } from ".."
|
|
9
|
-
import { hanldeCatchError } from "../utils/handle-catch-error"
|
|
10
|
-
import { createUlid } from "../utils/create-ulid"
|
|
11
|
-
import { _validate } from "./validate"
|
|
12
|
-
import { exit } from "node:process"
|
|
2
|
+
import { type MiddlewareOptions, _middlewares, MiddlewareEvent } from "./middleware";
|
|
3
|
+
import schema from "../../../generated/api-schema";
|
|
4
|
+
import type { Context } from "../../../src/context";
|
|
5
|
+
import { failCode } from "../../../src/fail-code";
|
|
6
|
+
import type { MilkioContext } from "./context";
|
|
7
|
+
import { headerToPlainObject } from "../utils/header-to-plain-object";
|
|
8
|
+
import { type Mixin, type ExecuteId, type Fail, type FailEnumerates, loggerPushTags, loggerSubmit, runtime, TSON, type Logger, useLogger, reject } from "..";
|
|
9
|
+
import { hanldeCatchError } from "../utils/handle-catch-error";
|
|
10
|
+
import { createUlid } from "../utils/create-ulid";
|
|
11
|
+
import { _validate } from "./validate";
|
|
12
|
+
import { exit } from "node:process";
|
|
13
13
|
|
|
14
14
|
export type MilkioAppOptions = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
/**
|
|
16
|
+
* bootstraps
|
|
17
|
+
* @description
|
|
18
|
+
* When Milkio is launched, all methods in this array will run **in parallel**.
|
|
19
|
+
*/
|
|
20
|
+
bootstraps?: () => Array<
|
|
21
|
+
/* This type is long, and its intention is to prevent someone from forgetting to add parentheses when adding bootstraps. Therefore, it allows all types except methods */ Promise<unknown> | void | string | number | boolean | null | undefined | Record<string | number | symbol, unknown> | Array<unknown>
|
|
22
|
+
>;
|
|
23
|
+
/**
|
|
24
|
+
* middlewares
|
|
25
|
+
* @description
|
|
26
|
+
* When Milkio is launched, the closer it is to the front of the array, the more it is on the outer layer of the "onion".
|
|
27
|
+
*/
|
|
28
|
+
middlewares?: () => Array<MiddlewareOptions>;
|
|
29
|
+
/**
|
|
30
|
+
* maxRunningTime (minutes)
|
|
31
|
+
* @description
|
|
32
|
+
* When the function runs for a long time, it is possible that the memory will continuously expand (not necessarily due to memory leaks, but also possibly due to having a large number of routes).
|
|
33
|
+
* Set the maximum running time (in minutes). When milkio's running time reaches this value, terminate the process and automatically restart it from outside (K8S or other means).
|
|
34
|
+
*/
|
|
35
|
+
enableMaxRunningTimeoutLimit?: number | null | undefined;
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
export async function createMilkioApp(MilkioAppOptions: MilkioAppOptions = {}) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
39
|
+
if (MilkioAppOptions.enableMaxRunningTimeoutLimit && MilkioAppOptions.enableMaxRunningTimeoutLimit >= 1) {
|
|
40
|
+
setTimeout(
|
|
41
|
+
() => {
|
|
42
|
+
throw new Error('Milkio reached the limit of "maxRunningTimeout" in the options and automatically exited.');
|
|
43
|
+
},
|
|
44
|
+
MilkioAppOptions.enableMaxRunningTimeoutLimit * 60 * 1000,
|
|
45
|
+
);
|
|
46
|
+
runtime.maxRunningTimeout.enable = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const MilkioApp = {
|
|
50
|
+
execute: _execute,
|
|
51
|
+
executeToJson: _executeToJson,
|
|
52
|
+
_executeCore,
|
|
53
|
+
_executeCoreToJson,
|
|
54
|
+
randParams: _randParams,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
if (MilkioAppOptions.bootstraps) {
|
|
58
|
+
await Promise.all(MilkioAppOptions.bootstraps());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (MilkioAppOptions.middlewares) {
|
|
62
|
+
MiddlewareEvent.define("bootstrap", (a, b) => a.index - b.index);
|
|
63
|
+
MiddlewareEvent.define("beforeExecute", (a, b) => a.index - b.index);
|
|
64
|
+
MiddlewareEvent.define("afterExecute", (a, b) => b.index - a.index);
|
|
65
|
+
MiddlewareEvent.define("afterHTTPRequest", (a, b) => a.index - b.index);
|
|
66
|
+
MiddlewareEvent.define("beforeHTTPResponse", (a, b) => b.index - a.index);
|
|
67
|
+
|
|
68
|
+
const middlewares = MilkioAppOptions.middlewares();
|
|
69
|
+
|
|
70
|
+
for (let index = 0; index < middlewares.length; index++) {
|
|
71
|
+
const middlewareOptions = middlewares[index];
|
|
72
|
+
for (const name in middlewareOptions) {
|
|
73
|
+
let middleware = _middlewares.get(name);
|
|
74
|
+
if (middleware === undefined) {
|
|
75
|
+
middleware = [];
|
|
76
|
+
_middlewares.set(name, middleware);
|
|
77
|
+
}
|
|
78
|
+
const id = createUlid();
|
|
79
|
+
middleware.push({ id, index, middleware: middlewareOptions[name] });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
MiddlewareEvent._sort();
|
|
83
|
+
|
|
84
|
+
await MiddlewareEvent.handle("bootstrap", [MilkioApp]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return MilkioApp;
|
|
83
88
|
}
|
|
84
89
|
|
|
85
|
-
async function _execute<Path extends keyof (typeof schema)["apiMethodsTypeSchema"], Result extends Awaited<ReturnType<(typeof schema)["apiMethodsTypeSchema"][Path]["api"]["action"]>>>(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
90
|
+
async function _execute<Path extends keyof (typeof schema)["apiMethodsTypeSchema"], Result extends Awaited<ReturnType<(typeof schema)["apiMethodsTypeSchema"][Path]["api"]["action"]>>>(
|
|
91
|
+
path: Path,
|
|
92
|
+
params: Parameters<(typeof schema)["apiMethodsTypeSchema"][Path]["api"]["action"]>[0] | string,
|
|
93
|
+
headersInit: Record<string, string> | Headers = {},
|
|
94
|
+
options?: ExecuteOptions,
|
|
95
|
+
): Promise<ExecuteResult<Result>> {
|
|
96
|
+
const executeId = (options?.executeId ?? createUlid()) as ExecuteId;
|
|
97
|
+
const logger = useLogger(executeId);
|
|
98
|
+
runtime.execute.executeIds.add(executeId);
|
|
99
|
+
|
|
100
|
+
loggerPushTags(executeId, {
|
|
101
|
+
from: "execute",
|
|
102
|
+
executeId,
|
|
103
|
+
params,
|
|
104
|
+
path,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const result: any = await _executeCore(path, params, headersInit, {
|
|
108
|
+
...options,
|
|
109
|
+
executeId,
|
|
110
|
+
logger,
|
|
111
|
+
onAfterHeaders: (headers) => {
|
|
112
|
+
loggerPushTags(executeId, {
|
|
113
|
+
headers: headerToPlainObject(headers),
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
loggerPushTags(executeId, { result });
|
|
119
|
+
await loggerSubmit(executeId);
|
|
120
|
+
runtime.execute.executeIds.delete(executeId);
|
|
121
|
+
|
|
122
|
+
return result;
|
|
113
123
|
}
|
|
114
124
|
|
|
115
125
|
/**
|
|
@@ -117,146 +127,162 @@ async function _execute<Path extends keyof (typeof schema)["apiMethodsTypeSchema
|
|
|
117
127
|
* It only does the most basic thing internally, which is calling the API. The external handling of functions such as making executeId, logging, middleware, etc., are all handled externally.
|
|
118
128
|
* Both execute and httpServer essentially call executeCore.
|
|
119
129
|
*/
|
|
120
|
-
async function _executeCore<Path extends keyof (typeof schema)["apiMethodsTypeSchema"], Result extends Awaited<ReturnType<(typeof schema)["apiMethodsTypeSchema"][Path]["api"]["action"]>>>(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
130
|
+
async function _executeCore<Path extends keyof (typeof schema)["apiMethodsTypeSchema"], Result extends Awaited<ReturnType<(typeof schema)["apiMethodsTypeSchema"][Path]["api"]["action"]>>>(
|
|
131
|
+
path: Path,
|
|
132
|
+
params: Parameters<(typeof schema)["apiMethodsTypeSchema"][Path]["api"]["action"]>[0] | string,
|
|
133
|
+
headersInit: Record<string, string> | Headers = {},
|
|
134
|
+
options: ExecuteCoreOptions,
|
|
135
|
+
): Promise<ExecuteResult<Result>> {
|
|
136
|
+
const executeId = options.executeId as ExecuteId;
|
|
137
|
+
|
|
138
|
+
params = TSON.decode(params);
|
|
139
|
+
|
|
140
|
+
if (!(path in schema.apiMethodsSchema)) {
|
|
141
|
+
const result = {
|
|
142
|
+
executeId,
|
|
143
|
+
success: false,
|
|
144
|
+
fail: {
|
|
145
|
+
code: "NOT_FOUND",
|
|
146
|
+
message: failCode.NOT_FOUND(),
|
|
147
|
+
data: undefined,
|
|
148
|
+
},
|
|
149
|
+
} satisfies ExecuteResult<Result>;
|
|
150
|
+
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
let headers: Headers;
|
|
155
|
+
if (!(headersInit instanceof Headers)) {
|
|
156
|
+
// @ts-ignore
|
|
157
|
+
headers = new Headers({
|
|
158
|
+
...headersInit,
|
|
159
|
+
});
|
|
160
|
+
} else {
|
|
161
|
+
headers = headersInit;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (options?.onAfterHeaders) {
|
|
165
|
+
await options.onAfterHeaders(headers);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const context: Context = {
|
|
169
|
+
executeId,
|
|
170
|
+
path,
|
|
171
|
+
headers,
|
|
172
|
+
logger: options.logger,
|
|
173
|
+
detail: options?.detail ?? {},
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
let result: { value: Result };
|
|
177
|
+
try {
|
|
178
|
+
// before execute middleware
|
|
179
|
+
await MiddlewareEvent.handle("beforeExecute", [context]);
|
|
180
|
+
|
|
181
|
+
let fn: any;
|
|
182
|
+
// check type
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
185
|
+
try {
|
|
186
|
+
fn = await schema.apiValidator.validate[path]();
|
|
187
|
+
} catch (error) {
|
|
188
|
+
throw reject("BUSINESS_FAIL", "This is the new API, which takes effect after restarting the server or saving any changes. It will be fixed in the future.");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
params = _validate(await fn.validateParams(params));
|
|
192
|
+
|
|
193
|
+
// execute api
|
|
194
|
+
let api: any;
|
|
195
|
+
if (apis.has(path)) api = apis.get(path);
|
|
196
|
+
else {
|
|
197
|
+
// @ts-ignore
|
|
198
|
+
api = schema.apiMethodsSchema[path]();
|
|
199
|
+
apis.set(path, api);
|
|
200
|
+
}
|
|
201
|
+
const apiModuleAwaited = await api.module;
|
|
202
|
+
|
|
203
|
+
const apiMethod = apiModuleAwaited.api.action;
|
|
204
|
+
|
|
205
|
+
// @ts-ignore
|
|
206
|
+
result = { value: await apiMethod(params, context) };
|
|
207
|
+
|
|
208
|
+
// after execute middleware
|
|
209
|
+
await MiddlewareEvent.handle("afterExecute", [context, result]);
|
|
210
|
+
} catch (error: any) {
|
|
211
|
+
const errorResult = hanldeCatchError(error, executeId);
|
|
212
|
+
|
|
213
|
+
return errorResult;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
executeId,
|
|
218
|
+
success: true,
|
|
219
|
+
data: result.value,
|
|
220
|
+
};
|
|
202
221
|
}
|
|
203
222
|
|
|
204
223
|
async function _executeToJson<Path extends keyof (typeof schema)["apiMethodsTypeSchema"]>(path: Path, params: Parameters<(typeof schema)["apiMethodsTypeSchema"][Path]["api"]["action"]>[0] | string, headersInit: Record<string, string> | Headers = {}, options?: ExecuteOptions): Promise<string> {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
224
|
+
const resultsRaw = await _execute(path, params, headersInit, options);
|
|
225
|
+
let fn: any;
|
|
226
|
+
try {
|
|
227
|
+
fn = await schema.apiValidator.validate[path]();
|
|
228
|
+
} catch (error) {
|
|
229
|
+
throw reject("BUSINESS_FAIL", "This is the new API, which takes effect after restarting the server or saving any changes. It will be fixed in the future.");
|
|
230
|
+
}
|
|
231
|
+
const results = await fn.validateResults(TSON.encode(resultsRaw));
|
|
232
|
+
return results;
|
|
210
233
|
}
|
|
211
234
|
|
|
212
235
|
async function _executeCoreToJson<Path extends keyof (typeof schema)["apiMethodsTypeSchema"]>(path: Path, params: Parameters<(typeof schema)["apiMethodsTypeSchema"][Path]["api"]["action"]>[0] | string, headersInit: Record<string, string> | Headers = {}, options: ExecuteCoreOptions): Promise<string> {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
236
|
+
const resultsRaw = await _executeCore(path, params, headersInit, options);
|
|
237
|
+
let fn: any;
|
|
238
|
+
try {
|
|
239
|
+
fn = await schema.apiValidator.validate[path]();
|
|
240
|
+
} catch (error) {
|
|
241
|
+
throw reject("BUSINESS_FAIL", "This is the new API, which takes effect after restarting the server or saving any changes. It will be fixed in the future.");
|
|
242
|
+
}
|
|
243
|
+
const results = await fn.validateResults(TSON.encode(resultsRaw));
|
|
244
|
+
return results;
|
|
218
245
|
}
|
|
219
246
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return await (await schema.apiValidator.validate[path]()).randParams()
|
|
247
|
+
export async function _randParams<Path extends keyof (typeof schema)["apiMethodsTypeSchema"]>(path: Path): Promise<Parameters<(typeof schema)["apiMethodsTypeSchema"][Path]["api"]["action"]>[0]> {
|
|
248
|
+
return await (await schema.apiValidator.validate[path]()).randParams();
|
|
223
249
|
}
|
|
224
250
|
|
|
225
|
-
const apis = new Map<string, any>()
|
|
251
|
+
const apis = new Map<string, any>();
|
|
226
252
|
|
|
227
253
|
export type ExecuteResult<Result> = ExecuteResultSuccess<Result> | ExecuteResultFail;
|
|
228
254
|
|
|
229
255
|
export type ExecuteResultSuccess<Result> = {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
256
|
+
executeId: ExecuteId;
|
|
257
|
+
success: true;
|
|
258
|
+
data: Result;
|
|
233
259
|
};
|
|
234
260
|
|
|
235
261
|
export type ExecuteResultFail<FailT extends Fail<keyof FailEnumerates> = Fail<keyof FailEnumerates>> = {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
262
|
+
executeId: ExecuteId;
|
|
263
|
+
success: false;
|
|
264
|
+
fail: FailT;
|
|
239
265
|
};
|
|
240
266
|
|
|
241
267
|
export type ExecuteOptions = {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
268
|
+
/**
|
|
269
|
+
* The executeId of the request
|
|
270
|
+
* executeId may be generated by the serverless provider, if not, a random string will be generated instead
|
|
271
|
+
*/
|
|
272
|
+
executeId?: string;
|
|
273
|
+
/**
|
|
274
|
+
* Additional information about the request
|
|
275
|
+
* These are usually only fully implemented when called by an HTTP server
|
|
276
|
+
* During testing or when calling between microservices, some or all of the values may be undefined
|
|
277
|
+
*/
|
|
278
|
+
detail?: MilkioContext["detail"];
|
|
253
279
|
};
|
|
254
280
|
|
|
255
281
|
export type ExecuteCoreOptions = Mixin<
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
>;
|
|
282
|
+
ExecuteOptions,
|
|
283
|
+
{
|
|
284
|
+
executeId: string;
|
|
285
|
+
logger: Logger;
|
|
286
|
+
onAfterHeaders?: (headers: Headers) => void | Promise<void>;
|
|
287
|
+
}
|
|
288
|
+
>;
|
package/kernel/runtime.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ExecuteId } from "..";
|
|
2
2
|
|
|
3
3
|
export const runtime = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
4
|
+
execute: {
|
|
5
|
+
executeIds: new Set<ExecuteId>(),
|
|
6
|
+
},
|
|
7
|
+
maxRunningTimeout: {
|
|
8
|
+
enable: false,
|
|
9
|
+
expectedEndedAt: 0,
|
|
10
|
+
},
|
|
11
|
+
};
|
package/kernel/validate.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
|
-
import type { IValidation } from "typia"
|
|
4
|
-
import { reject } from "../kernel/fail"
|
|
3
|
+
import type { IValidation } from "typia";
|
|
4
|
+
import { reject } from "../kernel/fail";
|
|
5
5
|
|
|
6
6
|
export function _validate(validator: IValidation.IFailure | IValidation.ISuccess): any {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
if (validator.success) return validator.data;
|
|
8
|
+
const error = validator.errors[0];
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
throw reject("TYPE_SAFE_ERROR", {
|
|
11
|
+
path: error.path,
|
|
12
|
+
expected: error.expected,
|
|
13
|
+
value: error.value,
|
|
14
|
+
});
|
|
15
15
|
}
|