@hestjs/core 0.1.0

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.
Files changed (134) hide show
  1. package/README.md +387 -0
  2. package/dist/application/application-factory.d.ts +15 -0
  3. package/dist/application/application-factory.d.ts.map +1 -0
  4. package/dist/application/application-factory.js +77 -0
  5. package/dist/application/application-factory.js.map +1 -0
  6. package/dist/application/hest-application.d.ts +40 -0
  7. package/dist/application/hest-application.d.ts.map +1 -0
  8. package/dist/application/hest-application.js +50 -0
  9. package/dist/application/hest-application.js.map +1 -0
  10. package/dist/application/index.d.ts +3 -0
  11. package/dist/application/index.d.ts.map +1 -0
  12. package/dist/application/index.js +3 -0
  13. package/dist/application/index.js.map +1 -0
  14. package/dist/container/container.d.ts +48 -0
  15. package/dist/container/container.d.ts.map +1 -0
  16. package/dist/container/container.js +77 -0
  17. package/dist/container/container.js.map +1 -0
  18. package/dist/container/index.d.ts +3 -0
  19. package/dist/container/index.d.ts.map +1 -0
  20. package/dist/container/index.js +3 -0
  21. package/dist/container/index.js.map +1 -0
  22. package/dist/container/injection-token.d.ts +14 -0
  23. package/dist/container/injection-token.d.ts.map +1 -0
  24. package/dist/container/injection-token.js +10 -0
  25. package/dist/container/injection-token.js.map +1 -0
  26. package/dist/decorators/controller.d.ts +14 -0
  27. package/dist/decorators/controller.d.ts.map +1 -0
  28. package/dist/decorators/controller.js +23 -0
  29. package/dist/decorators/controller.js.map +1 -0
  30. package/dist/decorators/index.d.ts +5 -0
  31. package/dist/decorators/index.d.ts.map +1 -0
  32. package/dist/decorators/index.js +5 -0
  33. package/dist/decorators/index.js.map +1 -0
  34. package/dist/decorators/injectable.d.ts +13 -0
  35. package/dist/decorators/injectable.d.ts.map +1 -0
  36. package/dist/decorators/injectable.js +20 -0
  37. package/dist/decorators/injectable.js.map +1 -0
  38. package/dist/decorators/module.d.ts +14 -0
  39. package/dist/decorators/module.d.ts.map +1 -0
  40. package/dist/decorators/module.js +16 -0
  41. package/dist/decorators/module.js.map +1 -0
  42. package/dist/decorators/route.d.ts +56 -0
  43. package/dist/decorators/route.d.ts.map +1 -0
  44. package/dist/decorators/route.js +94 -0
  45. package/dist/decorators/route.js.map +1 -0
  46. package/dist/exceptions/base-exception.d.ts +20 -0
  47. package/dist/exceptions/base-exception.d.ts.map +1 -0
  48. package/dist/exceptions/base-exception.js +38 -0
  49. package/dist/exceptions/base-exception.js.map +1 -0
  50. package/dist/exceptions/exception-filter.d.ts +39 -0
  51. package/dist/exceptions/exception-filter.d.ts.map +1 -0
  52. package/dist/exceptions/exception-filter.js +63 -0
  53. package/dist/exceptions/exception-filter.js.map +1 -0
  54. package/dist/exceptions/http-exception.d.ts +40 -0
  55. package/dist/exceptions/http-exception.d.ts.map +1 -0
  56. package/dist/exceptions/http-exception.js +77 -0
  57. package/dist/exceptions/http-exception.js.map +1 -0
  58. package/dist/exceptions/index.d.ts +4 -0
  59. package/dist/exceptions/index.d.ts.map +1 -0
  60. package/dist/exceptions/index.js +4 -0
  61. package/dist/exceptions/index.js.map +1 -0
  62. package/dist/index.d.ts +15 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +19 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/interceptors/index.d.ts +2 -0
  67. package/dist/interceptors/index.d.ts.map +1 -0
  68. package/dist/interceptors/index.js +2 -0
  69. package/dist/interceptors/index.js.map +1 -0
  70. package/dist/interceptors/interceptor.d.ts +82 -0
  71. package/dist/interceptors/interceptor.d.ts.map +1 -0
  72. package/dist/interceptors/interceptor.js +114 -0
  73. package/dist/interceptors/interceptor.js.map +1 -0
  74. package/dist/interfaces/application.d.ts +24 -0
  75. package/dist/interfaces/application.d.ts.map +1 -0
  76. package/dist/interfaces/application.js +2 -0
  77. package/dist/interfaces/application.js.map +1 -0
  78. package/dist/interfaces/index.d.ts +4 -0
  79. package/dist/interfaces/index.d.ts.map +1 -0
  80. package/dist/interfaces/index.js +4 -0
  81. package/dist/interfaces/index.js.map +1 -0
  82. package/dist/interfaces/metadata.d.ts +49 -0
  83. package/dist/interfaces/metadata.d.ts.map +1 -0
  84. package/dist/interfaces/metadata.js +2 -0
  85. package/dist/interfaces/metadata.js.map +1 -0
  86. package/dist/interfaces/router.d.ts +48 -0
  87. package/dist/interfaces/router.d.ts.map +1 -0
  88. package/dist/interfaces/router.js +2 -0
  89. package/dist/interfaces/router.js.map +1 -0
  90. package/dist/metadata/index.d.ts +3 -0
  91. package/dist/metadata/index.d.ts.map +1 -0
  92. package/dist/metadata/index.js +3 -0
  93. package/dist/metadata/index.js.map +1 -0
  94. package/dist/metadata/metadata-scanner.d.ts +59 -0
  95. package/dist/metadata/metadata-scanner.d.ts.map +1 -0
  96. package/dist/metadata/metadata-scanner.js +75 -0
  97. package/dist/metadata/metadata-scanner.js.map +1 -0
  98. package/dist/metadata/reflector.d.ts +50 -0
  99. package/dist/metadata/reflector.d.ts.map +1 -0
  100. package/dist/metadata/reflector.js +57 -0
  101. package/dist/metadata/reflector.js.map +1 -0
  102. package/dist/middlewares/index.d.ts +2 -0
  103. package/dist/middlewares/index.d.ts.map +1 -0
  104. package/dist/middlewares/index.js +2 -0
  105. package/dist/middlewares/index.js.map +1 -0
  106. package/dist/middlewares/middleware.d.ts +39 -0
  107. package/dist/middlewares/middleware.d.ts.map +1 -0
  108. package/dist/middlewares/middleware.js +71 -0
  109. package/dist/middlewares/middleware.js.map +1 -0
  110. package/dist/router/index.d.ts +3 -0
  111. package/dist/router/index.d.ts.map +1 -0
  112. package/dist/router/index.js +3 -0
  113. package/dist/router/index.js.map +1 -0
  114. package/dist/router/route-metadata.d.ts +41 -0
  115. package/dist/router/route-metadata.d.ts.map +1 -0
  116. package/dist/router/route-metadata.js +43 -0
  117. package/dist/router/route-metadata.js.map +1 -0
  118. package/dist/router/router-explorer.d.ts +52 -0
  119. package/dist/router/router-explorer.d.ts.map +1 -0
  120. package/dist/router/router-explorer.js +259 -0
  121. package/dist/router/router-explorer.js.map +1 -0
  122. package/dist/utils/constants.d.ts +33 -0
  123. package/dist/utils/constants.d.ts.map +1 -0
  124. package/dist/utils/constants.js +40 -0
  125. package/dist/utils/constants.js.map +1 -0
  126. package/dist/utils/helpers.d.ts +27 -0
  127. package/dist/utils/helpers.d.ts.map +1 -0
  128. package/dist/utils/helpers.js +54 -0
  129. package/dist/utils/helpers.js.map +1 -0
  130. package/dist/utils/index.d.ts +3 -0
  131. package/dist/utils/index.d.ts.map +1 -0
  132. package/dist/utils/index.js +3 -0
  133. package/dist/utils/index.js.map +1 -0
  134. package/package.json +64 -0
@@ -0,0 +1,77 @@
1
+ import "reflect-metadata";
2
+ import { container as tsyringeContainer, } from "tsyringe";
3
+ import { METADATA_KEYS, Scope } from "../utils/constants";
4
+ /**
5
+ * HestJS DI 容器封装
6
+ */
7
+ export class Container {
8
+ static instance;
9
+ container;
10
+ constructor() {
11
+ this.container = tsyringeContainer.createChildContainer();
12
+ }
13
+ /**
14
+ * 获取容器单例
15
+ */
16
+ static getInstance() {
17
+ if (!Container.instance) {
18
+ Container.instance = new Container();
19
+ }
20
+ return Container.instance;
21
+ }
22
+ /**
23
+ * 注册服务
24
+ */
25
+ register(token, provider) {
26
+ const metadata = Reflect.getMetadata(METADATA_KEYS.INJECTABLE, provider) || {};
27
+ switch (metadata.scope) {
28
+ case Scope.SINGLETON:
29
+ this.container.registerSingleton(token, provider);
30
+ break;
31
+ case Scope.TRANSIENT:
32
+ this.container.register(token, { useClass: provider });
33
+ break;
34
+ default:
35
+ this.container.registerSingleton(token, provider);
36
+ }
37
+ }
38
+ /**
39
+ * 注册实例
40
+ */
41
+ registerInstance(token, instance) {
42
+ this.container.registerInstance(token, instance);
43
+ }
44
+ /**
45
+ * 解析服务
46
+ */
47
+ resolve(token) {
48
+ return this.container.resolve(token);
49
+ }
50
+ /**
51
+ * 检查是否已注册
52
+ */
53
+ isRegistered(token) {
54
+ return this.container.isRegistered(token);
55
+ }
56
+ /**
57
+ * 清空容器
58
+ */
59
+ clear() {
60
+ this.container.clearInstances();
61
+ }
62
+ /**
63
+ * 创建子容器
64
+ */
65
+ createChild() {
66
+ const child = new Container();
67
+ child.container = this.container.createChildContainer();
68
+ return child;
69
+ }
70
+ /**
71
+ * 获取底层容器实例
72
+ */
73
+ getContainer() {
74
+ return this.container;
75
+ }
76
+ }
77
+ //# sourceMappingURL=container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/container/container.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAGL,SAAS,IAAI,iBAAiB,GAC/B,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAS1D;;GAEG;AACH,MAAM,OAAO,SAAS;IACZ,MAAM,CAAC,QAAQ,CAAY;IAC3B,SAAS,CAAsB;IAEvC;QACE,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC,oBAAoB,EAAE,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YACxB,SAAS,CAAC,QAAQ,GAAG,IAAI,SAAS,EAAE,CAAC;QACvC,CAAC;QACD,OAAO,SAAS,CAAC,QAAQ,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,QAAQ,CAAI,KAAwB,EAAE,QAAa;QACjD,MAAM,QAAQ,GACZ,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEhE,QAAQ,QAAQ,CAAC,KAAK,EAAE,CAAC;YACvB,KAAK,KAAK,CAAC,SAAS;gBAClB,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;gBAClD,MAAM;YACR,KAAK,KAAK,CAAC,SAAS;gBAClB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;gBACvD,MAAM;YACR;gBACE,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,gBAAgB,CAAI,KAAwB,EAAE,QAAW;QACvD,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED;;OAEG;IACH,OAAO,CAAI,KAAwB;QACjC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,YAAY,CAAI,KAAwB;QACtC,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,WAAW;QACT,MAAM,KAAK,GAAG,IAAI,SAAS,EAAE,CAAC;QAC9B,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,oBAAoB,EAAE,CAAC;QACxD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export * from './container';
2
+ export * from './injection-token';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/container/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './container';
2
+ export * from './injection-token';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 注入令牌类型
3
+ */
4
+ export type InjectionToken<T = any> = string | symbol | Function | (abstract new (...args: any[]) => T);
5
+ /**
6
+ * 预定义的注入令牌
7
+ */
8
+ export declare const INJECTION_TOKENS: {
9
+ readonly HTTP_ADAPTER: symbol;
10
+ readonly APPLICATION: symbol;
11
+ readonly LOGGER: symbol;
12
+ readonly CONFIG: symbol;
13
+ };
14
+ //# sourceMappingURL=injection-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injection-token.d.ts","sourceRoot":"","sources":["../../src/container/injection-token.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,GAAG,IAC9B,MAAM,GACN,MAAM,GACN,QAAQ,GACR,CAAC,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;CAKnB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 预定义的注入令牌
3
+ */
4
+ export const INJECTION_TOKENS = {
5
+ HTTP_ADAPTER: Symbol("HttpAdapter"),
6
+ APPLICATION: Symbol("HestApplication"),
7
+ LOGGER: Symbol("Logger"),
8
+ CONFIG: Symbol("Config"),
9
+ };
10
+ //# sourceMappingURL=injection-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injection-token.js","sourceRoot":"","sources":["../../src/container/injection-token.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,YAAY,EAAE,MAAM,CAAC,aAAa,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC,iBAAiB,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC;CAChB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import "reflect-metadata";
2
+ declare global {
3
+ namespace Reflect {
4
+ function defineMetadata(key: any, value: any, target: any, propertyKey?: string | symbol): void;
5
+ function hasMetadata(key: any, target: any, propertyKey?: string | symbol): boolean;
6
+ function getMetadata(key: any, target: any, propertyKey?: string | symbol): any;
7
+ }
8
+ }
9
+ /**
10
+ * 控制器装饰器
11
+ * @param path 控制器路径前缀
12
+ */
13
+ export declare function Controller(path?: string): ClassDecorator;
14
+ //# sourceMappingURL=controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/decorators/controller.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAM1B,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,SAAS,cAAc,CACrB,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,GAAG,EACV,MAAM,EAAE,GAAG,EACX,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAC5B,IAAI,CAAC;QACR,SAAS,WAAW,CAClB,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,GAAG,EACX,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAC5B,OAAO,CAAC;QACX,SAAS,WAAW,CAClB,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,GAAG,EACX,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAC5B,GAAG,CAAC;KACR;CACF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,SAAK,GAAG,cAAc,CAsBpD"}
@@ -0,0 +1,23 @@
1
+ import "reflect-metadata";
2
+ import { injectable } from "tsyringe";
3
+ import { METADATA_KEYS } from "../utils/constants";
4
+ /**
5
+ * 控制器装饰器
6
+ * @param path 控制器路径前缀
7
+ */
8
+ export function Controller(path = "") {
9
+ return (target) => {
10
+ const metadata = {
11
+ path: path.startsWith("/") ? path : `/${path}`,
12
+ };
13
+ Reflect.defineMetadata(METADATA_KEYS.CONTROLLER, metadata, target);
14
+ // 确保类可以被注入
15
+ if (!Reflect.hasMetadata(METADATA_KEYS.INJECTABLE, target)) {
16
+ Reflect.defineMetadata(METADATA_KEYS.INJECTABLE, { scope: "singleton" }, target);
17
+ }
18
+ // 自动应用 TSyringe 的 injectable 装饰器
19
+ injectable()(target);
20
+ return target;
21
+ };
22
+ }
23
+ //# sourceMappingURL=controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/decorators/controller.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAwBnD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,IAAI,GAAG,EAAE;IAClC,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,MAAM,QAAQ,GAAuB;YACnC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE;SAC/C,CAAC;QAEF,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAEnE,WAAW;QACX,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC;YAC3D,OAAO,CAAC,cAAc,CACpB,aAAa,CAAC,UAAU,EACxB,EAAE,KAAK,EAAE,WAAW,EAAE,EACtB,MAAM,CACP,CAAC;QACJ,CAAC;QAED,iCAAiC;QACjC,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC;QAErB,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./controller";
2
+ export * from "./injectable";
3
+ export * from "./module";
4
+ export * from "./route";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./controller";
2
+ export * from "./injectable";
3
+ export * from "./module";
4
+ export * from "./route";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,13 @@
1
+ import 'reflect-metadata';
2
+ import type { InjectableMetadata } from '../interfaces/metadata';
3
+ declare global {
4
+ namespace Reflect {
5
+ function defineMetadata(key: any, value: any, target: any, propertyKey?: string | symbol): void;
6
+ }
7
+ }
8
+ /**
9
+ * 可注入装饰器
10
+ * @param options 注入选项
11
+ */
12
+ export declare function Injectable(options?: InjectableMetadata): ClassDecorator;
13
+ //# sourceMappingURL=injectable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectable.d.ts","sourceRoot":"","sources":["../../src/decorators/injectable.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAGjE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,SAAS,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;KACjG;CACF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,kBAAuB,GAAG,cAAc,CAa3E"}
@@ -0,0 +1,20 @@
1
+ import 'reflect-metadata';
2
+ import { autoInjectable } from 'tsyringe';
3
+ import { METADATA_KEYS, Scope } from '../utils/constants';
4
+ /**
5
+ * 可注入装饰器
6
+ * @param options 注入选项
7
+ */
8
+ export function Injectable(options = {}) {
9
+ return (target) => {
10
+ const metadata = {
11
+ scope: options.scope || Scope.SINGLETON,
12
+ };
13
+ Reflect.defineMetadata(METADATA_KEYS.INJECTABLE, metadata, target);
14
+ // 使用 autoInjectable 来自动解析依赖
15
+ // 这样就不需要手动 @Inject 装饰器了
16
+ autoInjectable()(target);
17
+ return target;
18
+ };
19
+ }
20
+ //# sourceMappingURL=injectable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../src/decorators/injectable.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAU1D;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,UAA8B,EAAE;IACzD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,MAAM,QAAQ,GAAuB;YACnC,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS;SACxC,CAAC;QAEF,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAEnE,4BAA4B;QAC5B,wBAAwB;QACxB,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC;QACzB,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import 'reflect-metadata';
2
+ import type { ModuleMetadata } from '../interfaces/metadata';
3
+ declare global {
4
+ namespace Reflect {
5
+ function defineMetadata(key: any, value: any, target: any, propertyKey?: string | symbol): void;
6
+ function hasMetadata(key: any, target: any, propertyKey?: string | symbol): boolean;
7
+ }
8
+ }
9
+ /**
10
+ * 模块装饰器
11
+ * @param metadata 模块元数据
12
+ */
13
+ export declare function Module(metadata: ModuleMetadata): ClassDecorator;
14
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/decorators/module.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,SAAS,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;QAChG,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;KACrF;CACF;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,cAAc,GAAG,cAAc,CAS/D"}
@@ -0,0 +1,16 @@
1
+ import 'reflect-metadata';
2
+ import { METADATA_KEYS } from '../utils/constants';
3
+ /**
4
+ * 模块装饰器
5
+ * @param metadata 模块元数据
6
+ */
7
+ export function Module(metadata) {
8
+ return (target) => {
9
+ Reflect.defineMetadata(METADATA_KEYS.MODULE, metadata, target);
10
+ // 确保模块可以被注入
11
+ if (!Reflect.hasMetadata(METADATA_KEYS.INJECTABLE, target)) {
12
+ Reflect.defineMetadata(METADATA_KEYS.INJECTABLE, { scope: 'singleton' }, target);
13
+ }
14
+ };
15
+ }
16
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/decorators/module.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAWnD;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,QAAwB;IAC7C,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE/D,YAAY;QACZ,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC;YAC3D,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,MAAM,CAAC,CAAC;QACnF,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,56 @@
1
+ import 'reflect-metadata';
2
+ declare global {
3
+ namespace Reflect {
4
+ function defineMetadata(key: any, value: any, target: any, propertyKey?: string | symbol): void;
5
+ function getMetadata(key: any, target: any, propertyKey?: string | symbol): any;
6
+ }
7
+ }
8
+ /**
9
+ * GET 请求装饰器
10
+ */
11
+ export declare const Get: (path?: string) => (target: any, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => PropertyDescriptor;
12
+ /**
13
+ * POST 请求装饰器
14
+ */
15
+ export declare const Post: (path?: string) => (target: any, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => PropertyDescriptor;
16
+ /**
17
+ * PUT 请求装饰器
18
+ */
19
+ export declare const Put: (path?: string) => (target: any, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => PropertyDescriptor;
20
+ /**
21
+ * DELETE 请求装饰器
22
+ */
23
+ export declare const Delete: (path?: string) => (target: any, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => PropertyDescriptor;
24
+ /**
25
+ * PATCH 请求装饰器
26
+ */
27
+ export declare const Patch: (path?: string) => (target: any, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => PropertyDescriptor;
28
+ /**
29
+ * 请求体参数装饰器
30
+ */
31
+ export declare const Body: (key?: string) => (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
32
+ /**
33
+ * 路径参数装饰器
34
+ */
35
+ export declare const Param: (key?: string) => (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
36
+ /**
37
+ * 查询参数装饰器
38
+ */
39
+ export declare const Query: (key?: string) => (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
40
+ /**
41
+ * 请求头参数装饰器
42
+ */
43
+ export declare const Header: (key?: string) => (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
44
+ /**
45
+ * 完整请求对象装饰器
46
+ */
47
+ export declare const Req: (key?: string) => (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
48
+ /**
49
+ * 响应对象装饰器
50
+ */
51
+ export declare const Res: (key?: string) => (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
52
+ /**
53
+ * 上下文装饰器 - 获取完整的 Hono Context
54
+ */
55
+ export declare const Context: (key?: string) => (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
56
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/decorators/route.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAK1B,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,SAAS,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;QAChG,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KACjF;CACF;AA6BD;;GAEG;AACH,eAAO,MAAM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MAAM,GAAG,SA1CA,MAAM,MACV,QAAQ,GAAG,EAAE,aAAa,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,gBAAgB,MAAM,SAyC/B,CAAC;AAE3D;;GAEG;AACH,eAAO,MAAM,GAAG,SA/CA,MAAM,MACV,QAAQ,GAAG,EAAE,aAAa,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,gBAAgB,MAAM,SA8C9B,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,OAAO,SApDJ,MAAM,MACV,QAAQ,GAAG,EAAE,aAAa,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,gBAAgB,MAAM,SAmD3B,CAAC"}
@@ -0,0 +1,94 @@
1
+ import 'reflect-metadata';
2
+ import { METADATA_KEYS, HttpMethod, ParamType } from '../utils/constants';
3
+ /**
4
+ * 创建路由装饰器
5
+ */
6
+ function createRouteDecorator(method) {
7
+ return (path = '') => {
8
+ return (target, propertyKey, descriptor) => {
9
+ const metadata = {
10
+ method,
11
+ path: path.startsWith('/') ? path : `/${path}`,
12
+ methodName: String(propertyKey),
13
+ };
14
+ const existingRoutes = Reflect.getMetadata(METADATA_KEYS.ROUTE, target.constructor) || [];
15
+ existingRoutes.push(metadata);
16
+ Reflect.defineMetadata(METADATA_KEYS.ROUTE, existingRoutes, target.constructor);
17
+ return descriptor || {
18
+ value: target[propertyKey],
19
+ writable: true,
20
+ enumerable: true,
21
+ configurable: true,
22
+ };
23
+ };
24
+ };
25
+ }
26
+ /**
27
+ * GET 请求装饰器
28
+ */
29
+ export const Get = createRouteDecorator(HttpMethod.GET);
30
+ /**
31
+ * POST 请求装饰器
32
+ */
33
+ export const Post = createRouteDecorator(HttpMethod.POST);
34
+ /**
35
+ * PUT 请求装饰器
36
+ */
37
+ export const Put = createRouteDecorator(HttpMethod.PUT);
38
+ /**
39
+ * DELETE 请求装饰器
40
+ */
41
+ export const Delete = createRouteDecorator(HttpMethod.DELETE);
42
+ /**
43
+ * PATCH 请求装饰器
44
+ */
45
+ export const Patch = createRouteDecorator(HttpMethod.PATCH);
46
+ /**
47
+ * 创建参数装饰器
48
+ */
49
+ function createParamDecorator(type) {
50
+ return (key) => {
51
+ return (target, propertyKey, parameterIndex) => {
52
+ if (!propertyKey)
53
+ return;
54
+ const metadata = {
55
+ index: parameterIndex,
56
+ type,
57
+ key,
58
+ };
59
+ const paramKey = `${METADATA_KEYS.PARAM.toString()}_${String(propertyKey)}`;
60
+ const existingParams = Reflect.getMetadata(paramKey, target.constructor) || [];
61
+ existingParams.push(metadata);
62
+ Reflect.defineMetadata(paramKey, existingParams, target.constructor);
63
+ };
64
+ };
65
+ }
66
+ /**
67
+ * 请求体参数装饰器
68
+ */
69
+ export const Body = createParamDecorator(ParamType.BODY);
70
+ /**
71
+ * 路径参数装饰器
72
+ */
73
+ export const Param = createParamDecorator(ParamType.PARAM);
74
+ /**
75
+ * 查询参数装饰器
76
+ */
77
+ export const Query = createParamDecorator(ParamType.QUERY);
78
+ /**
79
+ * 请求头参数装饰器
80
+ */
81
+ export const Header = createParamDecorator(ParamType.HEADER);
82
+ /**
83
+ * 完整请求对象装饰器
84
+ */
85
+ export const Req = createParamDecorator(ParamType.REQUEST);
86
+ /**
87
+ * 响应对象装饰器
88
+ */
89
+ export const Res = createParamDecorator(ParamType.RESPONSE);
90
+ /**
91
+ * 上下文装饰器 - 获取完整的 Hono Context
92
+ */
93
+ export const Context = createParamDecorator(ParamType.CONTEXT);
94
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/decorators/route.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAW1E;;GAEG;AACH,SAAS,oBAAoB,CAAC,MAAkB;IAC9C,OAAO,CAAC,IAAI,GAAG,EAAE,EAAE,EAAE;QACnB,OAAO,CAAC,MAAW,EAAE,WAA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AAoB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { ContentfulStatusCode } from 'hono/utils/http-status';
2
+ /**
3
+ * 基础异常类
4
+ */
5
+ export declare abstract class BaseException extends Error {
6
+ readonly status: ContentfulStatusCode;
7
+ readonly error: string;
8
+ readonly timestamp: Date;
9
+ readonly path?: string;
10
+ constructor(message: string, status?: ContentfulStatusCode, error?: string);
11
+ /**
12
+ * 获取异常响应对象
13
+ */
14
+ getResponse(): Record<string, any>;
15
+ /**
16
+ * 设置请求路径
17
+ */
18
+ setPath(path: string): this;
19
+ }
20
+ //# sourceMappingURL=base-exception.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/base-exception.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE;;GAEG;AACH,8BAAsB,aAAc,SAAQ,KAAK;aAM7B,MAAM,EAAE,oBAAoB;aAC5B,KAAK,EAAE,MAAM;IAN/B,SAAgB,SAAS,EAAE,IAAI,CAAC;IAChC,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;gBAG5B,OAAO,EAAE,MAAM,EACC,MAAM,GAAE,oBAA0B,EAClC,KAAK,GAAE,MAAgC;IAUzD;;OAEG;IACH,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAUlC;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAI5B"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * 基础异常类
3
+ */
4
+ export class BaseException extends Error {
5
+ status;
6
+ error;
7
+ timestamp;
8
+ path;
9
+ constructor(message, status = 500, error = 'Internal Server Error') {
10
+ super(message);
11
+ this.status = status;
12
+ this.error = error;
13
+ this.name = this.constructor.name;
14
+ this.timestamp = new Date();
15
+ // 确保异常堆栈正确
16
+ Error.captureStackTrace(this, this.constructor);
17
+ }
18
+ /**
19
+ * 获取异常响应对象
20
+ */
21
+ getResponse() {
22
+ return {
23
+ statusCode: this.status,
24
+ message: this.message,
25
+ error: this.error,
26
+ timestamp: this.timestamp.toISOString(),
27
+ path: this.path,
28
+ };
29
+ }
30
+ /**
31
+ * 设置请求路径
32
+ */
33
+ setPath(path) {
34
+ this.path = path;
35
+ return this;
36
+ }
37
+ }
38
+ //# sourceMappingURL=base-exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-exception.js","sourceRoot":"","sources":["../../src/exceptions/base-exception.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAgB,aAAc,SAAQ,KAAK;IAM7B;IACA;IANF,SAAS,CAAO;IAChB,IAAI,CAAU;IAE9B,YACE,OAAe,EACC,SAA+B,GAAG,EAClC,QAAgB,uBAAuB;QAEvD,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,WAAM,GAAN,MAAM,CAA4B;QAClC,UAAK,GAAL,KAAK,CAAkC;QAGvD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAE5B,WAAW;QACX,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,MAAM;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;YACvC,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,IAAY;QACjB,IAAY,CAAC,IAAI,GAAG,IAAI,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,39 @@
1
+ import type { Context } from "hono";
2
+ import { HttpException } from "./http-exception";
3
+ /**
4
+ * 异常过滤器接口
5
+ */
6
+ export interface ExceptionFilter<T = any> {
7
+ catch(exception: T, host: ArgumentsHost): any;
8
+ }
9
+ /**
10
+ * 参数宿主接口
11
+ */
12
+ export interface ArgumentsHost {
13
+ getContext(): Context;
14
+ getRequest(): any;
15
+ getResponse(): any;
16
+ }
17
+ /**
18
+ * 默认参数宿主实现
19
+ */
20
+ export declare class DefaultArgumentsHost implements ArgumentsHost {
21
+ private readonly context;
22
+ constructor(context: Context);
23
+ getContext(): Context;
24
+ getRequest(): any;
25
+ getResponse(): any;
26
+ }
27
+ /**
28
+ * 默认全局异常过滤器
29
+ */
30
+ export declare class DefaultExceptionFilter implements ExceptionFilter {
31
+ catch(exception: any, host: ArgumentsHost): any;
32
+ }
33
+ /**
34
+ * HTTP 异常过滤器
35
+ */
36
+ export declare class HttpExceptionFilter implements ExceptionFilter<HttpException> {
37
+ catch(exception: HttpException, host: ArgumentsHost): any;
38
+ }
39
+ //# sourceMappingURL=exception-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exception-filter.d.ts","sourceRoot":"","sources":["../../src/exceptions/exception-filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,GAAG;IACtC,KAAK,CAAC,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,GAAG,GAAG,CAAC;CAC/C;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,UAAU,IAAI,OAAO,CAAC;IACtB,UAAU,IAAI,GAAG,CAAC;IAClB,WAAW,IAAI,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,oBAAqB,YAAW,aAAa;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,OAAO;IAE7C,UAAU,IAAI,OAAO;IAIrB,UAAU,IAAI,GAAG;IAIjB,WAAW,IAAI,GAAG;CAGnB;AAED;;GAEG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IAC5D,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,GAAG,GAAG;CA0BhD;AAED;;GAEG;AACH,qBAAa,mBAAoB,YAAW,eAAe,CAAC,aAAa,CAAC;IACxE,KAAK,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,aAAa,GAAG,GAAG;CAY1D"}
@@ -0,0 +1,63 @@
1
+ import { BaseException } from "./base-exception";
2
+ /**
3
+ * 默认参数宿主实现
4
+ */
5
+ export class DefaultArgumentsHost {
6
+ context;
7
+ constructor(context) {
8
+ this.context = context;
9
+ }
10
+ getContext() {
11
+ return this.context;
12
+ }
13
+ getRequest() {
14
+ return this.context.req;
15
+ }
16
+ getResponse() {
17
+ return this.context;
18
+ }
19
+ }
20
+ /**
21
+ * 默认全局异常过滤器
22
+ */
23
+ export class DefaultExceptionFilter {
24
+ catch(exception, host) {
25
+ const ctx = host.getContext();
26
+ const request = host.getRequest();
27
+ let status = 500;
28
+ let response = {
29
+ statusCode: 500,
30
+ message: "Internal server error",
31
+ timestamp: new Date().toISOString(),
32
+ path: request.url,
33
+ };
34
+ if (exception instanceof BaseException) {
35
+ status = exception.status;
36
+ response = exception.getResponse();
37
+ response.path = request.url;
38
+ }
39
+ else if (exception instanceof Error) {
40
+ response.message = exception.message;
41
+ response.stack = exception.stack;
42
+ }
43
+ // 记录错误日志
44
+ console.error(`Exception caught: ${exception.message}`, exception.stack);
45
+ return ctx.json(response, status);
46
+ }
47
+ }
48
+ /**
49
+ * HTTP 异常过滤器
50
+ */
51
+ export class HttpExceptionFilter {
52
+ catch(exception, host) {
53
+ const ctx = host.getContext();
54
+ const request = host.getRequest();
55
+ const status = exception.status;
56
+ const response = {
57
+ ...exception.getResponse(),
58
+ path: request.url,
59
+ };
60
+ return ctx.json(response, status);
61
+ }
62
+ }
63
+ //# sourceMappingURL=exception-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exception-filter.js","sourceRoot":"","sources":["../../src/exceptions/exception-filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAmBjD;;GAEG;AACH,MAAM,OAAO,oBAAoB;IACF;IAA7B,YAA6B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAEjD,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;IAC1B,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,sBAAsB;IACjC,KAAK,CAAC,SAAc,EAAE,IAAmB;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAElC,IAAI,MAAM,GAAG,GAAG,CAAC;QACjB,IAAI,QAAQ,GAAQ;YAClB,UAAU,EAAE,GAAG;YACf,OAAO,EAAE,uBAAuB;YAChC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,IAAI,EAAE,OAAO,CAAC,GAAG;SAClB,CAAC;QAEF,IAAI,SAAS,YAAY,aAAa,EAAE,CAAC;YACvC,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;YAC1B,QAAQ,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;YACnC,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;QAC9B,CAAC;aAAM,IAAI,SAAS,YAAY,KAAK,EAAE,CAAC;YACtC,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC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