koatty_router 1.9.0 → 1.9.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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.9.2](https://github.com/koatty/koatty_router/compare/v1.9.1...v1.9.2) (2024-03-15)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * controller方法执行结果错误对象拦截 ([1536793](https://github.com/koatty/koatty_router/commit/1536793e89c5af2aa2114c71eef4c155b627da01))
11
+
12
+ ### [1.9.1](https://github.com/koatty/koatty_router/compare/v1.9.0...v1.9.1) (2024-03-15)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * injectParamMetaData参数传递错误 ([c2f91c4](https://github.com/koatty/koatty_router/commit/c2f91c4d825c5ba573f56360f3113636d58a3dd3))
18
+
5
19
  ## [1.9.0](https://github.com/koatty/koatty_router/compare/v1.9.0-2...v1.9.0) (2024-01-16)
6
20
 
7
21
  ## [1.9.0-2](https://github.com/koatty/koatty_router/compare/v1.9.0-1...v1.9.0-2) (2024-01-15)
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2024-01-16 08:30:50
3
+ * @Date: 2024-03-15 11:22:50
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2024-01-16 08:30:38
3
+ * @Date: 2024-03-15 11:22:37
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -212,7 +212,7 @@ const HeadMapping = (path = "/", routerOptions = {}) => {
212
212
  * @Usage:
213
213
  * @Author: richen
214
214
  * @Date: 2023-12-09 12:02:29
215
- * @LastEditTime: 2024-01-16 08:27:06
215
+ * @LastEditTime: 2024-03-15 11:12:12
216
216
  * @License: BSD (3-Clause)
217
217
  * @Copyright (c): <richenlin(at)gmail.com>
218
218
  */
@@ -240,6 +240,9 @@ async function Handler(app, ctx, ctl, method, ctlParams) {
240
240
  }
241
241
  // method
242
242
  const res = await ctl[method](...args);
243
+ if (Helper.Helper.isError(res)) {
244
+ throw res;
245
+ }
243
246
  ctx.body = ctx.body || res;
244
247
  }
245
248
  /**
@@ -282,55 +285,55 @@ function injectRouter(app, target, instance) {
282
285
  *
283
286
  * @param {Koatty} app
284
287
  * @param {*} target
285
- * @param {*} [instance]
288
+ * @param {*} [options]
286
289
  * @returns {*}
287
290
  */
288
- function injectParamMetaData(app, target, instance, options) {
291
+ function injectParamMetaData(app, target, options) {
289
292
  var _a, _b;
290
- instance = instance || target.prototype;
293
+ // const instance = target.prototype;
291
294
  const metaDatas = koatty_container.RecursiveGetMetadata(koatty_container.TAGGED_PARAM, target);
292
295
  const validMetaDatas = koatty_container.RecursiveGetMetadata(koatty_validation.PARAM_RULE_KEY, target);
293
296
  const validatedMetaDatas = koatty_container.RecursiveGetMetadata(koatty_validation.PARAM_CHECK_KEY, target);
294
297
  const argsMetaObj = {};
295
298
  for (const meta in metaDatas) {
296
299
  // 实例方法带规则形参必须小于等于原型形参(如果不存在验证规则,则小于)
297
- if (instance[meta] && instance[meta].length <= metaDatas[meta].length) {
298
- koatty_logger.DefaultLogger.Debug(`Register inject param key ${koatty_container.IOCContainer.getIdentifier(target)}: ${Helper.Helper.toString(meta)} => value: ${JSON.stringify(metaDatas[meta])}`);
299
- // cover to obj
300
- const data = ((_a = metaDatas[meta]) !== null && _a !== void 0 ? _a : []).sort((a, b) => a.index - b.index);
301
- const validData = (_b = validMetaDatas[meta]) !== null && _b !== void 0 ? _b : [];
302
- data.forEach((v) => {
303
- var _a;
304
- validData.forEach((it) => {
305
- if (v.index === it.index && it.name === v.name) {
306
- v.validRule = it.rule;
307
- v.validOpt = it.options;
308
- }
309
- });
310
- if (v.type) {
311
- v.type = v.isDto ? v.type : (v.type).toLowerCase();
300
+ // if (instance[meta] && instance[meta].length <= metaDatas[meta].length) {
301
+ koatty_logger.DefaultLogger.Debug(`Register inject param key ${koatty_container.IOCContainer.getIdentifier(target)}: ${Helper.Helper.toString(meta)} => value: ${JSON.stringify(metaDatas[meta])}`);
302
+ // cover to obj
303
+ const data = ((_a = metaDatas[meta]) !== null && _a !== void 0 ? _a : []).sort((a, b) => a.index - b.index);
304
+ const validData = (_b = validMetaDatas[meta]) !== null && _b !== void 0 ? _b : [];
305
+ data.forEach((v) => {
306
+ var _a;
307
+ validData.forEach((it) => {
308
+ if (v.index === it.index && it.name === v.name) {
309
+ v.validRule = it.rule;
310
+ v.validOpt = it.options;
312
311
  }
313
- v.dtoCheck = !!(((_a = validatedMetaDatas[meta]) === null || _a === void 0 ? void 0 : _a.dtoCheck));
314
- if (v.isDto) {
315
- v.clazz = koatty_container.IOCContainer.getClass(v.type, "COMPONENT");
316
- if (!v.clazz) {
317
- throw Error(`Failed to obtain the class ${v.type},
312
+ });
313
+ if (v.type) {
314
+ v.type = v.isDto ? v.type : (v.type).toLowerCase();
315
+ }
316
+ v.dtoCheck = !!(((_a = validatedMetaDatas[meta]) === null || _a === void 0 ? void 0 : _a.dtoCheck));
317
+ if (v.isDto) {
318
+ v.clazz = koatty_container.IOCContainer.getClass(v.type, "COMPONENT");
319
+ if (!v.clazz) {
320
+ throw Error(`Failed to obtain the class ${v.type},
318
321
  because the class is not registered in the container.`);
319
- }
320
- if (v.dtoCheck) {
321
- v.dtoRule = koatty_container.getOriginMetadata(koatty_validation.PARAM_TYPE_KEY, v.clazz);
322
- Reflect.defineProperty(v.clazz.prototype, "_typeDef", {
323
- enumerable: true,
324
- configurable: false,
325
- writable: false,
326
- value: v.dtoRule,
327
- });
328
- }
329
322
  }
330
- v.options = options;
331
- });
332
- argsMetaObj[meta] = data;
333
- }
323
+ if (v.dtoCheck) {
324
+ v.dtoRule = koatty_container.getOriginMetadata(koatty_validation.PARAM_TYPE_KEY, v.clazz);
325
+ Reflect.defineProperty(v.clazz.prototype, "_typeDef", {
326
+ enumerable: true,
327
+ configurable: false,
328
+ writable: false,
329
+ value: v.dtoRule,
330
+ });
331
+ }
332
+ }
333
+ v.options = options;
334
+ });
335
+ argsMetaObj[meta] = data;
336
+ // }
334
337
  }
335
338
  return argsMetaObj;
336
339
  }
@@ -711,7 +714,7 @@ async function parseXml(ctx, opts) {
711
714
  * @Usage:
712
715
  * @Author: richen
713
716
  * @Date: 2021-06-29 14:10:30
714
- * @LastEditTime: 2024-01-16 00:30:29
717
+ * @LastEditTime: 2024-01-16 22:49:46
715
718
  */
716
719
  class GrpcRouter {
717
720
  constructor(app, options) {
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2024-01-16 08:30:38
3
+ * @Date: 2024-03-15 11:22:37
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -192,7 +192,7 @@ const HeadMapping = (path = "/", routerOptions = {}) => {
192
192
  * @Usage:
193
193
  * @Author: richen
194
194
  * @Date: 2023-12-09 12:02:29
195
- * @LastEditTime: 2024-01-16 08:27:06
195
+ * @LastEditTime: 2024-03-15 11:12:12
196
196
  * @License: BSD (3-Clause)
197
197
  * @Copyright (c): <richenlin(at)gmail.com>
198
198
  */
@@ -220,6 +220,9 @@ async function Handler(app, ctx, ctl, method, ctlParams) {
220
220
  }
221
221
  // method
222
222
  const res = await ctl[method](...args);
223
+ if (Helper$1.isError(res)) {
224
+ throw res;
225
+ }
223
226
  ctx.body = ctx.body || res;
224
227
  }
225
228
  /**
@@ -262,55 +265,55 @@ function injectRouter(app, target, instance) {
262
265
  *
263
266
  * @param {Koatty} app
264
267
  * @param {*} target
265
- * @param {*} [instance]
268
+ * @param {*} [options]
266
269
  * @returns {*}
267
270
  */
268
- function injectParamMetaData(app, target, instance, options) {
271
+ function injectParamMetaData(app, target, options) {
269
272
  var _a, _b;
270
- instance = instance || target.prototype;
273
+ // const instance = target.prototype;
271
274
  const metaDatas = RecursiveGetMetadata(TAGGED_PARAM, target);
272
275
  const validMetaDatas = RecursiveGetMetadata(PARAM_RULE_KEY, target);
273
276
  const validatedMetaDatas = RecursiveGetMetadata(PARAM_CHECK_KEY, target);
274
277
  const argsMetaObj = {};
275
278
  for (const meta in metaDatas) {
276
279
  // 实例方法带规则形参必须小于等于原型形参(如果不存在验证规则,则小于)
277
- if (instance[meta] && instance[meta].length <= metaDatas[meta].length) {
278
- DefaultLogger.Debug(`Register inject param key ${IOCContainer.getIdentifier(target)}: ${Helper$1.toString(meta)} => value: ${JSON.stringify(metaDatas[meta])}`);
279
- // cover to obj
280
- const data = ((_a = metaDatas[meta]) !== null && _a !== void 0 ? _a : []).sort((a, b) => a.index - b.index);
281
- const validData = (_b = validMetaDatas[meta]) !== null && _b !== void 0 ? _b : [];
282
- data.forEach((v) => {
283
- var _a;
284
- validData.forEach((it) => {
285
- if (v.index === it.index && it.name === v.name) {
286
- v.validRule = it.rule;
287
- v.validOpt = it.options;
288
- }
289
- });
290
- if (v.type) {
291
- v.type = v.isDto ? v.type : (v.type).toLowerCase();
280
+ // if (instance[meta] && instance[meta].length <= metaDatas[meta].length) {
281
+ DefaultLogger.Debug(`Register inject param key ${IOCContainer.getIdentifier(target)}: ${Helper$1.toString(meta)} => value: ${JSON.stringify(metaDatas[meta])}`);
282
+ // cover to obj
283
+ const data = ((_a = metaDatas[meta]) !== null && _a !== void 0 ? _a : []).sort((a, b) => a.index - b.index);
284
+ const validData = (_b = validMetaDatas[meta]) !== null && _b !== void 0 ? _b : [];
285
+ data.forEach((v) => {
286
+ var _a;
287
+ validData.forEach((it) => {
288
+ if (v.index === it.index && it.name === v.name) {
289
+ v.validRule = it.rule;
290
+ v.validOpt = it.options;
292
291
  }
293
- v.dtoCheck = !!(((_a = validatedMetaDatas[meta]) === null || _a === void 0 ? void 0 : _a.dtoCheck));
294
- if (v.isDto) {
295
- v.clazz = IOCContainer.getClass(v.type, "COMPONENT");
296
- if (!v.clazz) {
297
- throw Error(`Failed to obtain the class ${v.type},
292
+ });
293
+ if (v.type) {
294
+ v.type = v.isDto ? v.type : (v.type).toLowerCase();
295
+ }
296
+ v.dtoCheck = !!(((_a = validatedMetaDatas[meta]) === null || _a === void 0 ? void 0 : _a.dtoCheck));
297
+ if (v.isDto) {
298
+ v.clazz = IOCContainer.getClass(v.type, "COMPONENT");
299
+ if (!v.clazz) {
300
+ throw Error(`Failed to obtain the class ${v.type},
298
301
  because the class is not registered in the container.`);
299
- }
300
- if (v.dtoCheck) {
301
- v.dtoRule = getOriginMetadata(PARAM_TYPE_KEY, v.clazz);
302
- Reflect.defineProperty(v.clazz.prototype, "_typeDef", {
303
- enumerable: true,
304
- configurable: false,
305
- writable: false,
306
- value: v.dtoRule,
307
- });
308
- }
309
302
  }
310
- v.options = options;
311
- });
312
- argsMetaObj[meta] = data;
313
- }
303
+ if (v.dtoCheck) {
304
+ v.dtoRule = getOriginMetadata(PARAM_TYPE_KEY, v.clazz);
305
+ Reflect.defineProperty(v.clazz.prototype, "_typeDef", {
306
+ enumerable: true,
307
+ configurable: false,
308
+ writable: false,
309
+ value: v.dtoRule,
310
+ });
311
+ }
312
+ }
313
+ v.options = options;
314
+ });
315
+ argsMetaObj[meta] = data;
316
+ // }
314
317
  }
315
318
  return argsMetaObj;
316
319
  }
@@ -691,7 +694,7 @@ async function parseXml(ctx, opts) {
691
694
  * @Usage:
692
695
  * @Author: richen
693
696
  * @Date: 2021-06-29 14:10:30
694
- * @LastEditTime: 2024-01-16 00:30:29
697
+ * @LastEditTime: 2024-01-16 22:49:46
695
698
  */
696
699
  class GrpcRouter {
697
700
  constructor(app, options) {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty_router",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "Koatty routing component, adapt to http1/2, websocket, gRPC.",
5
5
  "scripts": {
6
6
  "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty_router",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "Koatty routing component, adapt to http1/2, websocket, gRPC.",
5
5
  "scripts": {
6
6
  "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",