milkio 0.0.36 → 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.
@@ -37,6 +37,10 @@ export function defineCommandHandler(app: MilkioApp, options: CommandOptions = {
37
37
  if (options.notFoundHandler) await options.notFoundHandler({ ...params, name: argv.length === 2 ? 'default' : argv[2] })
38
38
  return
39
39
  }
40
+ if (result.fail.code !== 'INTERNAL_SERVER_ERROR') {
41
+ console.log(result.fail.message)
42
+ return
43
+ }
40
44
  }
41
45
  }
42
46
 
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
- params = _validate(await (await schema.apiValidator.validate[path]()).validateParams(params))
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
- const results = await (await schema.apiValidator.validate[path]()).validateResults(TSON.encode(resultsRaw))
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
- const results = await (await schema.apiValidator.validate[path]()).validateResults(TSON.encode(resultsRaw))
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
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "milkio",
3
3
  "type": "module",
4
4
  "module": "index.ts",
5
- "version": "0.0.36",
5
+ "version": "0.1.1",
6
6
  "peerDependencies": {
7
7
  "typescript": "^5.4.2"
8
8
  },