milkio 0.0.37 → 0.1.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/kernel/milkio.ts +12 -4
- package/package.json +1 -1
package/kernel/milkio.ts
CHANGED
|
@@ -5,10 +5,11 @@ import type { Context } from "../../../src/context"
|
|
|
5
5
|
import { failCode } from "../../../src/fail-code"
|
|
6
6
|
import type { MilkioContext } from "./context"
|
|
7
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 } from ".."
|
|
8
|
+
import { type Mixin, type ExecuteId, type Fail, type FailEnumerates, loggerPushTags, loggerSubmit, runtime, TSON, type Logger, useLogger, reject } from ".."
|
|
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) { throw reject('BUSINESS_FAIL', 'This is the new API, which takes effect after restarting the server or saving any changes.') }
|
|
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) { throw reject('BUSINESS_FAIL', 'This is the new API, which takes effect after restarting the server or saving any changes.') }
|
|
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) { throw reject('BUSINESS_FAIL', 'This is the new API, which takes effect after restarting the server or saving any changes.') }
|
|
216
|
+
const results = await fn.validateResults(TSON.encode(resultsRaw))
|
|
209
217
|
return results
|
|
210
218
|
}
|
|
211
219
|
|