milkio 0.0.37 → 0.1.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/kernel/milkio.ts +11 -3
- package/package.json +1 -1
package/kernel/milkio.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { type Mixin, type ExecuteId, type Fail, type FailEnumerates, loggerPushT
|
|
|
9
9
|
import { hanldeCatchError } from "../utils/handle-catch-error"
|
|
10
10
|
import { createUlid } from "../utils/create-ulid"
|
|
11
11
|
import { _validate } from "./validate"
|
|
12
|
+
import { exit } from "node:process"
|
|
12
13
|
|
|
13
14
|
export type MilkioAppOptions = {
|
|
14
15
|
/**
|
|
@@ -162,10 +163,13 @@ async function _executeCore<Path extends keyof (typeof schema)["apiMethodsTypeSc
|
|
|
162
163
|
// before execute middleware
|
|
163
164
|
await MiddlewareEvent.handle("beforeExecute", [context])
|
|
164
165
|
|
|
166
|
+
let fn: any
|
|
165
167
|
// check type
|
|
166
168
|
// @ts-ignore
|
|
167
169
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
168
|
-
|
|
170
|
+
try { fn = await schema.apiValidator.validate[path]() } catch (error) { exit(439913) }
|
|
171
|
+
|
|
172
|
+
params = _validate(await fn.validateParams(params))
|
|
169
173
|
|
|
170
174
|
// execute api
|
|
171
175
|
let api: any
|
|
@@ -199,13 +203,17 @@ async function _executeCore<Path extends keyof (typeof schema)["apiMethodsTypeSc
|
|
|
199
203
|
|
|
200
204
|
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> {
|
|
201
205
|
const resultsRaw = await _execute(path, params, headersInit, options)
|
|
202
|
-
|
|
206
|
+
let fn: any
|
|
207
|
+
try { fn = await schema.apiValidator.validate[path]() } catch (error) { exit(439913) }
|
|
208
|
+
const results = await fn.validateResults(TSON.encode(resultsRaw))
|
|
203
209
|
return results
|
|
204
210
|
}
|
|
205
211
|
|
|
206
212
|
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> {
|
|
207
213
|
const resultsRaw = await _executeCore(path, params, headersInit, options)
|
|
208
|
-
|
|
214
|
+
let fn: any
|
|
215
|
+
try { fn = await schema.apiValidator.validate[path]() } catch (error) { exit(439913) }
|
|
216
|
+
const results = await fn.validateResults(TSON.encode(resultsRaw))
|
|
209
217
|
return results
|
|
210
218
|
}
|
|
211
219
|
|