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