@tsed/common 7.0.0-beta.12 → 7.0.0-beta.13

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 (175) hide show
  1. package/jest.config.js +14 -0
  2. package/lib/cjs/builder/PlatformBuilder.js +65 -55
  3. package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
  4. package/lib/cjs/builder/PlatformControllerBuilder.js +1 -1
  5. package/lib/cjs/builder/PlatformControllerBuilder.js.map +1 -1
  6. package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -1
  7. package/lib/cjs/config/services/PlatformConfiguration.js +0 -70
  8. package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -1
  9. package/lib/cjs/domain/AnyToPromiseWithCtx.js +4 -3
  10. package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -1
  11. package/lib/cjs/domain/ControllerProvider.js +1 -0
  12. package/lib/cjs/domain/ControllerProvider.js.map +1 -1
  13. package/lib/cjs/domain/HandlerMetadata.js +10 -5
  14. package/lib/cjs/domain/HandlerMetadata.js.map +1 -1
  15. package/lib/cjs/domain/PlatformContext.js +54 -31
  16. package/lib/cjs/domain/PlatformContext.js.map +1 -1
  17. package/lib/cjs/domain/PlatformRouteDetails.js +5 -1
  18. package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -1
  19. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +2 -1
  20. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -1
  21. package/lib/cjs/middlewares/PlatformMulterMiddleware.js +2 -0
  22. package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -1
  23. package/lib/cjs/services/FakeAdapter.js +1 -3
  24. package/lib/cjs/services/FakeAdapter.js.map +1 -1
  25. package/lib/cjs/services/Platform.js +4 -2
  26. package/lib/cjs/services/Platform.js.map +1 -1
  27. package/lib/cjs/services/PlatformAdapter.js +12 -0
  28. package/lib/cjs/services/PlatformAdapter.js.map +1 -1
  29. package/lib/cjs/services/PlatformApplication.js +2 -0
  30. package/lib/cjs/services/PlatformApplication.js.map +1 -1
  31. package/lib/cjs/services/PlatformHandler.js +7 -4
  32. package/lib/cjs/services/PlatformHandler.js.map +1 -1
  33. package/lib/cjs/services/PlatformMiddlewaresChain.js +3 -1
  34. package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -1
  35. package/lib/cjs/services/PlatformRequest.js +16 -11
  36. package/lib/cjs/services/PlatformRequest.js.map +1 -1
  37. package/lib/cjs/services/PlatformResponse.js +15 -11
  38. package/lib/cjs/services/PlatformResponse.js.map +1 -1
  39. package/lib/cjs/services/PlatformRouter.js +7 -1
  40. package/lib/cjs/services/PlatformRouter.js.map +1 -1
  41. package/lib/cjs/services/PlatformTest.js +20 -8
  42. package/lib/cjs/services/PlatformTest.js.map +1 -1
  43. package/lib/cjs/utils/createContext.js +28 -13
  44. package/lib/cjs/utils/createContext.js.map +1 -1
  45. package/lib/cjs/utils/createHttpServer.js +3 -3
  46. package/lib/cjs/utils/createHttpServer.js.map +1 -1
  47. package/lib/cjs/utils/createHttpsServer.js +3 -3
  48. package/lib/cjs/utils/createHttpsServer.js.map +1 -1
  49. package/lib/cjs/utils/createInjector.js +6 -6
  50. package/lib/cjs/utils/createInjector.js.map +1 -1
  51. package/lib/cjs/utils/getConfiguration.js +2 -12
  52. package/lib/cjs/utils/getConfiguration.js.map +1 -1
  53. package/lib/cjs/utils/setResponseHeaders.js +7 -13
  54. package/lib/cjs/utils/setResponseHeaders.js.map +1 -1
  55. package/lib/esm/builder/PlatformBuilder.js +42 -55
  56. package/lib/esm/builder/PlatformBuilder.js.map +1 -1
  57. package/lib/esm/builder/PlatformControllerBuilder.js +1 -1
  58. package/lib/esm/builder/PlatformControllerBuilder.js.map +1 -1
  59. package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -1
  60. package/lib/esm/config/services/PlatformConfiguration.js +0 -70
  61. package/lib/esm/config/services/PlatformConfiguration.js.map +1 -1
  62. package/lib/esm/domain/AnyToPromiseWithCtx.js +4 -3
  63. package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -1
  64. package/lib/esm/domain/ControllerProvider.js +1 -0
  65. package/lib/esm/domain/ControllerProvider.js.map +1 -1
  66. package/lib/esm/domain/HandlerMetadata.js +10 -5
  67. package/lib/esm/domain/HandlerMetadata.js.map +1 -1
  68. package/lib/esm/domain/PlatformContext.js +54 -31
  69. package/lib/esm/domain/PlatformContext.js.map +1 -1
  70. package/lib/esm/domain/PlatformRouteDetails.js +5 -1
  71. package/lib/esm/domain/PlatformRouteDetails.js.map +1 -1
  72. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js +2 -1
  73. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -1
  74. package/lib/esm/middlewares/PlatformMulterMiddleware.js +2 -0
  75. package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -1
  76. package/lib/esm/services/FakeAdapter.js +1 -3
  77. package/lib/esm/services/FakeAdapter.js.map +1 -1
  78. package/lib/esm/services/Platform.js +4 -2
  79. package/lib/esm/services/Platform.js.map +1 -1
  80. package/lib/esm/services/PlatformAdapter.js +12 -0
  81. package/lib/esm/services/PlatformAdapter.js.map +1 -1
  82. package/lib/esm/services/PlatformApplication.js +2 -0
  83. package/lib/esm/services/PlatformApplication.js.map +1 -1
  84. package/lib/esm/services/PlatformHandler.js +8 -5
  85. package/lib/esm/services/PlatformHandler.js.map +1 -1
  86. package/lib/esm/services/PlatformMiddlewaresChain.js +3 -1
  87. package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -1
  88. package/lib/esm/services/PlatformRequest.js +16 -11
  89. package/lib/esm/services/PlatformRequest.js.map +1 -1
  90. package/lib/esm/services/PlatformResponse.js +15 -11
  91. package/lib/esm/services/PlatformResponse.js.map +1 -1
  92. package/lib/esm/services/PlatformRouter.js +7 -1
  93. package/lib/esm/services/PlatformRouter.js.map +1 -1
  94. package/lib/esm/services/PlatformTest.js +20 -8
  95. package/lib/esm/services/PlatformTest.js.map +1 -1
  96. package/lib/esm/utils/createContext.js +26 -12
  97. package/lib/esm/utils/createContext.js.map +1 -1
  98. package/lib/esm/utils/createHttpServer.js +3 -3
  99. package/lib/esm/utils/createHttpServer.js.map +1 -1
  100. package/lib/esm/utils/createHttpsServer.js +3 -3
  101. package/lib/esm/utils/createHttpsServer.js.map +1 -1
  102. package/lib/esm/utils/createInjector.js +7 -7
  103. package/lib/esm/utils/createInjector.js.map +1 -1
  104. package/lib/esm/utils/getConfiguration.js +4 -14
  105. package/lib/esm/utils/getConfiguration.js.map +1 -1
  106. package/lib/esm/utils/setResponseHeaders.js +7 -13
  107. package/lib/esm/utils/setResponseHeaders.js.map +1 -1
  108. package/lib/types/builder/PlatformBuilder.d.ts +4 -5
  109. package/lib/types/config/interfaces/PlatformLoggerSettings.d.ts +2 -43
  110. package/lib/types/config/services/PlatformConfiguration.d.ts +1 -22
  111. package/lib/types/domain/PlatformContext.d.ts +20 -14
  112. package/lib/types/domain/PlatformRouteDetails.d.ts +1 -7
  113. package/lib/types/services/PlatformRequest.d.ts +11 -8
  114. package/lib/types/services/PlatformResponse.d.ts +8 -9
  115. package/lib/types/services/PlatformTest.d.ts +2 -2
  116. package/lib/types/utils/createContext.d.ts +4 -1
  117. package/lib/types/utils/createHttpsServer.d.ts +1 -0
  118. package/lib/types/utils/createInjector.d.ts +1 -1
  119. package/lib/types/utils/listenServer.d.ts +2 -0
  120. package/package.json +22 -21
  121. package/lib/cjs/middlewares/__mock__/FakeCtrl.js +0 -12
  122. package/lib/cjs/middlewares/__mock__/FakeCtrl.js.map +0 -1
  123. package/lib/cjs/utils/__mock__/Test1.js +0 -8
  124. package/lib/cjs/utils/__mock__/Test1.js.map +0 -1
  125. package/lib/cjs/utils/__mock__/Test2.js +0 -8
  126. package/lib/cjs/utils/__mock__/Test2.js.map +0 -1
  127. package/lib/cjs/utils/__mock__/controllers/rest/TestCtrl.js +0 -12
  128. package/lib/cjs/utils/__mock__/controllers/rest/TestCtrl.js.map +0 -1
  129. package/lib/cjs/utils/__mock__/module1/Module1.js +0 -19
  130. package/lib/cjs/utils/__mock__/module1/Module1.js.map +0 -1
  131. package/lib/cjs/utils/__mock__/module1/controllers/M1Ctrl1.js +0 -17
  132. package/lib/cjs/utils/__mock__/module1/controllers/M1Ctrl1.js.map +0 -1
  133. package/lib/cjs/utils/__mock__/module1/services/M1Service.js +0 -17
  134. package/lib/cjs/utils/__mock__/module1/services/M1Service.js.map +0 -1
  135. package/lib/cjs/utils/__mock__/module1/submodule/SubModule.js +0 -15
  136. package/lib/cjs/utils/__mock__/module1/submodule/SubModule.js.map +0 -1
  137. package/lib/cjs/utils/__mock__/module1/submodule/SubService.js +0 -12
  138. package/lib/cjs/utils/__mock__/module1/submodule/SubService.js.map +0 -1
  139. package/lib/cjs/utils/__mock__/module2/Module2.js +0 -18
  140. package/lib/cjs/utils/__mock__/module2/Module2.js.map +0 -1
  141. package/lib/cjs/utils/__mock__/module2/controllers/M2Ctrl.js +0 -12
  142. package/lib/cjs/utils/__mock__/module2/controllers/M2Ctrl.js.map +0 -1
  143. package/lib/esm/middlewares/__mock__/FakeCtrl.js +0 -9
  144. package/lib/esm/middlewares/__mock__/FakeCtrl.js.map +0 -1
  145. package/lib/esm/utils/__mock__/Test1.js +0 -4
  146. package/lib/esm/utils/__mock__/Test1.js.map +0 -1
  147. package/lib/esm/utils/__mock__/Test2.js +0 -4
  148. package/lib/esm/utils/__mock__/Test2.js.map +0 -1
  149. package/lib/esm/utils/__mock__/controllers/rest/TestCtrl.js +0 -9
  150. package/lib/esm/utils/__mock__/controllers/rest/TestCtrl.js.map +0 -1
  151. package/lib/esm/utils/__mock__/module1/Module1.js +0 -16
  152. package/lib/esm/utils/__mock__/module1/Module1.js.map +0 -1
  153. package/lib/esm/utils/__mock__/module1/controllers/M1Ctrl1.js +0 -14
  154. package/lib/esm/utils/__mock__/module1/controllers/M1Ctrl1.js.map +0 -1
  155. package/lib/esm/utils/__mock__/module1/services/M1Service.js +0 -14
  156. package/lib/esm/utils/__mock__/module1/services/M1Service.js.map +0 -1
  157. package/lib/esm/utils/__mock__/module1/submodule/SubModule.js +0 -12
  158. package/lib/esm/utils/__mock__/module1/submodule/SubModule.js.map +0 -1
  159. package/lib/esm/utils/__mock__/module1/submodule/SubService.js +0 -9
  160. package/lib/esm/utils/__mock__/module1/submodule/SubService.js.map +0 -1
  161. package/lib/esm/utils/__mock__/module2/Module2.js +0 -15
  162. package/lib/esm/utils/__mock__/module2/Module2.js.map +0 -1
  163. package/lib/esm/utils/__mock__/module2/controllers/M2Ctrl.js +0 -9
  164. package/lib/esm/utils/__mock__/module2/controllers/M2Ctrl.js.map +0 -1
  165. package/lib/types/middlewares/__mock__/FakeCtrl.d.ts +0 -2
  166. package/lib/types/utils/__mock__/Test1.d.ts +0 -3
  167. package/lib/types/utils/__mock__/Test2.d.ts +0 -3
  168. package/lib/types/utils/__mock__/controllers/rest/TestCtrl.d.ts +0 -2
  169. package/lib/types/utils/__mock__/module1/Module1.d.ts +0 -2
  170. package/lib/types/utils/__mock__/module1/controllers/M1Ctrl1.d.ts +0 -5
  171. package/lib/types/utils/__mock__/module1/services/M1Service.d.ts +0 -5
  172. package/lib/types/utils/__mock__/module1/submodule/SubModule.d.ts +0 -2
  173. package/lib/types/utils/__mock__/module1/submodule/SubService.d.ts +0 -2
  174. package/lib/types/utils/__mock__/module2/Module2.d.ts +0 -2
  175. package/lib/types/utils/__mock__/module2/controllers/M2Ctrl.d.ts +0 -2
@@ -7,10 +7,16 @@ const platform_params_1 = require("@tsed/platform-params");
7
7
  const schema_1 = require("@tsed/schema");
8
8
  const HandlerType_1 = require("../interfaces/HandlerType");
9
9
  class HandlerMetadata {
10
+ target;
11
+ token;
12
+ propertyKey;
13
+ injectable = false;
14
+ type = HandlerType_1.HandlerType.RAW_FN;
15
+ hasNextFunction = false;
16
+ routeOptions;
17
+ scope;
18
+ handler;
10
19
  constructor(options) {
11
- this.injectable = false;
12
- this.type = HandlerType_1.HandlerType.RAW_FN;
13
- this.hasNextFunction = false;
14
20
  const { target, token, propertyKey, type, scope, routeOptions } = options;
15
21
  this.type = type || target.type || HandlerType_1.HandlerType.RAW_FN;
16
22
  this.scope = scope || di_1.ProviderScope.SINGLETON;
@@ -46,8 +52,7 @@ class HandlerMetadata {
46
52
  return this.getParams().findIndex((p) => p.paramType === paramType) > -1;
47
53
  }
48
54
  isFinal() {
49
- var _a;
50
- return ((_a = this.routeOptions) === null || _a === void 0 ? void 0 : _a.isFinal) || false;
55
+ return this.routeOptions?.isFinal || false;
51
56
  }
52
57
  toString() {
53
58
  return [this.target && (0, core_1.nameOf)(this.target), this.propertyKey].filter(Boolean).join(".");
@@ -1 +1 @@
1
- {"version":3,"file":"HandlerMetadata.js","sourceRoot":"","sources":["../../../src/domain/HandlerMetadata.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AACxC,iCAAuC;AACvC,2DAAiD;AACjD,yCAAgD;AAChD,2DAAsD;AAYtD,MAAa,eAAe;IAY1B,YAAY,OAA+B;QARlC,eAAU,GAAY,KAAK,CAAC;QAC5B,SAAI,GAAgB,yBAAW,CAAC,MAAM,CAAC;QACvC,oBAAe,GAAY,KAAK,CAAC;QAOxC,MAAM,EAAC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAC,GAAG,OAAO,CAAC;QAExE,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,IAAI,IAAI,yBAAW,CAAC,MAAM,CAAC;QACtD,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,kBAAa,CAAC,SAAS,CAAC;QAC9C,IAAI,CAAC,YAAY,GAAG,YAAY,IAAI,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAErE,IAAI,WAAW,EAAE;YACf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AI,CAAC,YAAY,0CAAE,OAAO,KAAI,KAAK,CAAC;IAC7C,CAAC;IAED,QAAQ;QACN,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,IAAA,aAAM,EAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1F,CAAC;CACF;AA9DD,0CA8DC","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {ProviderScope} from \"@tsed/di\";\nimport {ParamTypes} from \"@tsed/platform-params\";\nimport {JsonParameterStore} from \"@tsed/schema\";\nimport {HandlerType} from \"../interfaces/HandlerType\";\nimport {PlatformRouteOptions, PlatformRouteWithoutHandlers} from \"../interfaces/PlatformRouteOptions\";\n\nexport interface HandlerMetadataOptions {\n target: (Type<any> | Function) & {type?: HandlerType};\n routeOptions?: PlatformRouteWithoutHandlers;\n token?: Type<any>;\n propertyKey?: string | symbol;\n scope?: ProviderScope;\n type?: HandlerType;\n}\n\nexport class HandlerMetadata {\n readonly target: any;\n readonly token: Type<any>;\n readonly propertyKey: string | symbol;\n readonly injectable: boolean = false;\n readonly type: HandlerType = HandlerType.RAW_FN;\n readonly hasNextFunction: boolean = false;\n readonly routeOptions: Partial<PlatformRouteOptions>;\n readonly scope: ProviderScope;\n\n handler: any;\n\n constructor(options: HandlerMetadataOptions) {\n const {target, token, propertyKey, type, scope, routeOptions} = options;\n\n this.type = type || target.type || HandlerType.RAW_FN;\n this.scope = scope || ProviderScope.SINGLETON;\n this.routeOptions = routeOptions || {};\n const handler = propertyKey ? target.prototype[propertyKey] : target;\n\n if (propertyKey) {\n this.target = target;\n this.token = token!;\n this.propertyKey = propertyKey;\n this.hasNextFunction = this.hasParamType(ParamTypes.NEXT_FN);\n\n if (this.hasParamType(ParamTypes.ERR)) {\n this.type = HandlerType.ERR_MIDDLEWARE;\n }\n\n this.injectable = JsonParameterStore.getParams(target as any, propertyKey).length > 0;\n } else {\n this.handler = handler;\n }\n\n if (!this.injectable) {\n if (handler.length === 4) {\n this.type = HandlerType.RAW_ERR_FN;\n }\n this.hasNextFunction = handler.length >= 3;\n }\n }\n\n get hasErrorParam() {\n return this.type === HandlerType.ERR_MIDDLEWARE || this.type === HandlerType.RAW_ERR_FN;\n }\n\n public getParams() {\n return JsonParameterStore.getParams(this.target, this.propertyKey) || [];\n }\n\n public hasParamType(paramType: any): boolean {\n return this.getParams().findIndex((p) => p.paramType === paramType) > -1;\n }\n\n public isFinal() {\n return this.routeOptions?.isFinal || false;\n }\n\n toString() {\n return [this.target && nameOf(this.target), this.propertyKey].filter(Boolean).join(\".\");\n }\n}\n"]}
1
+ {"version":3,"file":"HandlerMetadata.js","sourceRoot":"","sources":["../../../src/domain/HandlerMetadata.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AACxC,iCAAuC;AACvC,2DAAiD;AACjD,yCAAgD;AAChD,2DAAsD;AAYtD,MAAa,eAAe;IACjB,MAAM,CAAM;IACZ,KAAK,CAAY;IACjB,WAAW,CAAkB;IAC7B,UAAU,GAAY,KAAK,CAAC;IAC5B,IAAI,GAAgB,yBAAW,CAAC,MAAM,CAAC;IACvC,eAAe,GAAY,KAAK,CAAC;IACjC,YAAY,CAAgC;IAC5C,KAAK,CAAgB;IAE9B,OAAO,CAAM;IAEb,YAAY,OAA+B;QACzC,MAAM,EAAC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAC,GAAG,OAAO,CAAC;QAExE,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,IAAI,IAAI,yBAAW,CAAC,MAAM,CAAC;QACtD,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,kBAAa,CAAC,SAAS,CAAC;QAC9C,IAAI,CAAC,YAAY,GAAG,YAAY,IAAI,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,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AAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3E,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,YAAY,EAAE,OAAO,IAAI,KAAK,CAAC;IAC7C,CAAC;IAED,QAAQ;QACN,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,IAAA,aAAM,EAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1F,CAAC;CACF;AA9DD,0CA8DC","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {ProviderScope} from \"@tsed/di\";\nimport {ParamTypes} from \"@tsed/platform-params\";\nimport {JsonParameterStore} from \"@tsed/schema\";\nimport {HandlerType} from \"../interfaces/HandlerType\";\nimport {PlatformRouteOptions, PlatformRouteWithoutHandlers} from \"../interfaces/PlatformRouteOptions\";\n\nexport interface HandlerMetadataOptions {\n target: (Type<any> | Function) & {type?: HandlerType};\n routeOptions?: PlatformRouteWithoutHandlers;\n token?: Type<any>;\n propertyKey?: string | symbol;\n scope?: ProviderScope;\n type?: HandlerType;\n}\n\nexport class HandlerMetadata {\n readonly target: any;\n readonly token: Type<any>;\n readonly propertyKey: string | symbol;\n readonly injectable: boolean = false;\n readonly type: HandlerType = HandlerType.RAW_FN;\n readonly hasNextFunction: boolean = false;\n readonly routeOptions: Partial<PlatformRouteOptions>;\n readonly scope: ProviderScope;\n\n handler: any;\n\n constructor(options: HandlerMetadataOptions) {\n const {target, token, propertyKey, type, scope, routeOptions} = options;\n\n this.type = type || target.type || HandlerType.RAW_FN;\n this.scope = scope || ProviderScope.SINGLETON;\n this.routeOptions = routeOptions || {};\n const handler = propertyKey ? target.prototype[propertyKey] : target;\n\n if (propertyKey) {\n this.target = target;\n this.token = token!;\n this.propertyKey = propertyKey;\n this.hasNextFunction = this.hasParamType(ParamTypes.NEXT_FN);\n\n if (this.hasParamType(ParamTypes.ERR)) {\n this.type = HandlerType.ERR_MIDDLEWARE;\n }\n\n this.injectable = JsonParameterStore.getParams(target as any, propertyKey).length > 0;\n } else {\n this.handler = handler;\n }\n\n if (!this.injectable) {\n if (handler.length === 4) {\n this.type = HandlerType.RAW_ERR_FN;\n }\n this.hasNextFunction = handler.length >= 3;\n }\n }\n\n get hasErrorParam() {\n return this.type === HandlerType.ERR_MIDDLEWARE || this.type === HandlerType.RAW_ERR_FN;\n }\n\n public getParams() {\n return JsonParameterStore.getParams(this.target, this.propertyKey) || [];\n }\n\n public hasParamType(paramType: any): boolean {\n return this.getParams().findIndex((p) => p.paramType === paramType) > -1;\n }\n\n public isFinal() {\n return this.routeOptions?.isFinal || false;\n }\n\n toString() {\n return [this.target && nameOf(this.target), this.propertyKey].filter(Boolean).join(\".\");\n }\n}\n"]}
@@ -2,32 +2,52 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlatformContext = void 0;
4
4
  const di_1 = require("@tsed/di");
5
+ const schema_1 = require("@tsed/schema");
5
6
  const PlatformApplication_1 = require("../services/PlatformApplication");
6
7
  const PlatformRequest_1 = require("../services/PlatformRequest");
7
8
  const PlatformResponse_1 = require("../services/PlatformResponse");
8
9
  class PlatformContext extends di_1.DIContext {
9
- constructor({ event, endpoint, ignoreUrlPatterns = [], ResponseKlass = PlatformResponse_1.PlatformResponse, RequestKlass = PlatformRequest_1.PlatformRequest, ...options }) {
10
- super({
11
- ...options,
12
- ignoreLog: () => {
13
- return this.ignoreUrlPatterns.find((reg) => !!this.url.match(reg));
14
- }
15
- });
16
- this.ignoreUrlPatterns = [];
17
- endpoint && (this.endpoint = endpoint);
18
- this.ignoreUrlPatterns = ignoreUrlPatterns.map((pattern) => typeof pattern === "string" ? new RegExp(pattern, "gi") : pattern);
19
- this.response = new ResponseKlass(event, this);
20
- this.request = new RequestKlass(event, this);
21
- this.response.request = this.request;
22
- this.request.response = this.response;
10
+ event;
11
+ /**
12
+ * The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty.
13
+ */
14
+ data;
15
+ /**
16
+ * The error caught by the current handler
17
+ */
18
+ error;
19
+ /**
20
+ * The current @@PlatformResponse@@.
21
+ */
22
+ response;
23
+ /**
24
+ * The current @@PlatformRequest@@.
25
+ */
26
+ request;
27
+ ignoreUrlPatterns = [];
28
+ #isDestroyed = false;
29
+ constructor(options) {
30
+ super(options);
31
+ options.endpoint && (this.endpoint = options.endpoint);
32
+ this.event = options.event;
33
+ this.response = new (options.ResponseKlass || PlatformResponse_1.PlatformResponse)(this);
34
+ this.request = new (options.RequestKlass || PlatformRequest_1.PlatformRequest)(this);
23
35
  this.request.request.$ctx = this;
24
36
  this.request.request.id = this.id;
25
- this.logger.url = this.url;
26
37
  this.container.set(PlatformResponse_1.PlatformResponse, this.response);
27
38
  this.container.set(PlatformRequest_1.PlatformRequest, this.request);
28
39
  this.container.set(PlatformContext, this);
29
40
  this.response.setHeader("x-request-id", this.id);
30
41
  }
42
+ /**
43
+ * The current @@EndpointMetadata@@ resolved by Ts.ED during the request.
44
+ */
45
+ get endpoint() {
46
+ return this.get(schema_1.EndpointMetadata);
47
+ }
48
+ set endpoint(endpoint) {
49
+ this.set(schema_1.EndpointMetadata, endpoint);
50
+ }
31
51
  get url() {
32
52
  return this.request.url;
33
53
  }
@@ -35,27 +55,27 @@ class PlatformContext extends di_1.DIContext {
35
55
  return this.injector.get(PlatformApplication_1.PlatformApplication);
36
56
  }
37
57
  async destroy() {
38
- var _a, _b;
39
58
  await super.destroy();
40
- (_b = (_a = this.request) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? true : delete _b.$ctx;
59
+ this.upgrade({
60
+ response: {
61
+ isDone: true,
62
+ statusCode: this.statusCode
63
+ },
64
+ request: {
65
+ method: this.method,
66
+ url: this.url,
67
+ headers: this.headers,
68
+ body: this.body,
69
+ query: this.query,
70
+ params: this.params
71
+ }
72
+ });
41
73
  this.response.destroy();
42
74
  this.request.destroy();
43
- // @ts-ignore
44
- delete this.endpoint;
45
- // @ts-ignore
46
- delete this.response;
47
- // @ts-ignore
48
- delete this.request;
75
+ this.#isDestroyed = true;
49
76
  }
50
77
  isDone() {
51
- var _a, _b;
52
- if (!this.request || !this.response) {
53
- return true;
54
- }
55
- if ((_a = this.request) === null || _a === void 0 ? void 0 : _a.isAborted()) {
56
- return true;
57
- }
58
- return (_b = this.response) === null || _b === void 0 ? void 0 : _b.isDone();
78
+ return this.request?.isAborted() || this.response?.isDone() || this.#isDestroyed;
59
79
  }
60
80
  /**
61
81
  * Return the framework request instance (Express, Koa, etc...)
@@ -87,6 +107,9 @@ class PlatformContext extends di_1.DIContext {
87
107
  getApp() {
88
108
  return this.app.getApp();
89
109
  }
110
+ upgrade(event) {
111
+ this.event = event;
112
+ }
90
113
  }
91
114
  exports.PlatformContext = PlatformContext;
92
115
  //# sourceMappingURL=PlatformContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformContext.js","sourceRoot":"","sources":["../../../src/domain/PlatformContext.ts"],"names":[],"mappings":";;;AAAA,iCAAqE;AAGrE,yEAAoE;AACpE,iEAA4D;AAC5D,mEAA8D;AAiB9D,MAAa,eAAgB,SAAQ,cAAS;IAoB5C,YAAY,EACV,KAAK,EACL,QAAQ,EACR,iBAAiB,GAAG,EAAE,EACtB,aAAa,GAAG,mCAAgB,EAChC,YAAY,GAAG,iCAAe,EAC9B,GAAG,OAAO,EACa;QACvB,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,SAAS,EAAE,GAAG,EAAE;gBACd,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YACrE,CAAC;SACF,CAAC,CAAC;QAfG,sBAAiB,GAAa,EAAE,CAAC;QAiBvC,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;QAEvC,IAA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IAED,KAAK,CAAC,OAAO;;QACX,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QAEf,MAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,OAAO,+CAAE,IAAI,CAAC;QAEnC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAEvB,aAAa;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC;QACrB,aAAa;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC;QACrB,aAAa;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,MAAM;;QACJ,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YACnC,OAAO,IAAI,CAAC;SACb;QAED,IAAI,MAAA,IAAI,CAAC,OAAO,0CAAE,SAAS,EAAE,EAAE;YAC7B,OAAO,IAAI,CAAC;SACb;QAED,OAAO,MAAA,IAAI,CAAC,QAAQ,0CAAE,MAAM,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAO,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAO,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,EAAS,CAAC;IAClC,CAAC;CACF;AAhID,0CAgIC","sourcesContent":["import {ContextMethods, DIContext, DIContextOptions} from \"@tsed/di\";\nimport {IncomingMessage, ServerResponse} from \"http\";\nimport {EndpointMetadata} from \"@tsed/schema\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\n\ndeclare global {\n namespace TsED {\n export interface Context extends PlatformContext {}\n }\n}\n\nexport interface PlatformContextOptions extends DIContextOptions {\n event: {\n response?: ServerResponse;\n request?: IncomingMessage;\n };\n ignoreUrlPatterns?: any[];\n endpoint?: EndpointMetadata;\n}\n\nexport class PlatformContext extends DIContext implements ContextMethods {\n /**\n * The current @@EndpointMetadata@@ resolved by Ts.ED during the request.\n */\n public endpoint: EndpointMetadata;\n /**\n * The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty.\n */\n public data: any;\n /**\n * The current @@PlatformResponse@@.\n */\n public response: PlatformResponse;\n /**\n * The current @@PlatformRequest@@.\n */\n public request: PlatformRequest;\n\n private ignoreUrlPatterns: RegExp[] = [];\n\n constructor({\n event,\n endpoint,\n ignoreUrlPatterns = [],\n ResponseKlass = PlatformResponse,\n RequestKlass = PlatformRequest,\n ...options\n }: PlatformContextOptions) {\n super({\n ...options,\n ignoreLog: () => {\n return this.ignoreUrlPatterns.find((reg) => !!this.url.match(reg));\n }\n });\n\n endpoint && (this.endpoint = endpoint);\n\n this.ignoreUrlPatterns = ignoreUrlPatterns.map((pattern: string | RegExp) =>\n typeof pattern === \"string\" ? new RegExp(pattern, \"gi\") : pattern\n );\n\n this.response = new ResponseKlass(event, this);\n this.request = new RequestKlass(event, this);\n\n this.response.request = this.request;\n this.request.response = this.response;\n\n this.request.request.$ctx = this;\n this.request.request.id = this.id;\n this.logger.url = this.url;\n\n this.container.set(PlatformResponse, this.response);\n this.container.set(PlatformRequest, this.request);\n this.container.set(PlatformContext, this);\n\n this.response.setHeader(\"x-request-id\", this.id);\n }\n\n get url() {\n return this.request.url;\n }\n\n get app() {\n return this.injector.get<PlatformApplication>(PlatformApplication)!;\n }\n\n async destroy() {\n await super.destroy();\n\n delete this.request?.request?.$ctx;\n\n this.response.destroy();\n this.request.destroy();\n\n // @ts-ignore\n delete this.endpoint;\n // @ts-ignore\n delete this.response;\n // @ts-ignore\n delete this.request;\n }\n\n isDone() {\n if (!this.request || !this.response) {\n return true;\n }\n\n if (this.request?.isAborted()) {\n return true;\n }\n\n return this.response?.isDone();\n }\n\n /**\n * Return the framework request instance (Express, Koa, etc...)\n */\n getRequest<Req = any>(): Req {\n return this.request.getRequest<Req>();\n }\n\n /**\n * Return the framework response instance (Express, Koa, etc...)\n */\n getResponse<Res = any>(): Res {\n return this.response.getResponse<Res>();\n }\n\n /**\n * Get Node.js request\n */\n getReq(): IncomingMessage {\n return this.request.getReq();\n }\n\n /**\n * Get Node.js response\n */\n getRes(): ServerResponse {\n return this.response.getRes();\n }\n\n /**\n * Return the original application instance.\n */\n getApp<T = any>(): T {\n return this.app.getApp() as any;\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformContext.js","sourceRoot":"","sources":["../../../src/domain/PlatformContext.ts"],"names":[],"mappings":";;;AAAA,iCAAqE;AACrE,yCAA8C;AAG9C,yEAAoE;AACpE,iEAA4D;AAC5D,mEAA8D;AAc9D,MAAa,eACX,SAAQ,cAAS;IAGV,KAAK,CAAgB;IAC5B;;OAEG;IACI,IAAI,CAAM;IACjB;;OAEG;IACI,KAAK,CAAW;IACvB;;OAEG;IACM,QAAQ,CAAO;IACxB;;OAEG;IACM,OAAO,CAAO;IAEf,iBAAiB,GAAa,EAAE,CAAC;IACzC,YAAY,GAAY,KAAK,CAAC;IAE9B,YAAY,OAA+B;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,OAAO,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QAEvD,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,IAAI,mCAAgB,CAAC,CAAC,IAAI,CA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AAE,IAAI,CAAC,GAAG;gBACb,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB;SACK,CAAC,CAAC;QAEV,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,IAAI,CAAC,YAAY,CAAC;IACnF,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAO,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAO,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,EAAS,CAAC;IAClC,CAAC;IAED,OAAO,CAAC,KAAoB;QAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AA/HD,0CA+HC","sourcesContent":["import {ContextMethods, DIContext, DIContextOptions} from \"@tsed/di\";\nimport {EndpointMetadata} from \"@tsed/schema\";\nimport {IncomingMessage, ServerResponse} from \"http\";\nimport {IncomingEvent} from \"../interfaces/IncomingEvent\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\n\ndeclare global {\n namespace TsED {\n export interface Context extends PlatformContext {}\n }\n}\n\nexport interface PlatformContextOptions extends DIContextOptions {\n event: IncomingEvent;\n ignoreUrlPatterns?: any[];\n endpoint?: EndpointMetadata;\n}\n\nexport class PlatformContext<PReq extends PlatformRequest = PlatformRequest, PRes extends PlatformResponse = PlatformResponse>\n extends DIContext\n implements ContextMethods\n{\n public event: IncomingEvent;\n /**\n * The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty.\n */\n public data: any;\n /**\n * The error caught by the current handler\n */\n public error?: unknown;\n /**\n * The current @@PlatformResponse@@.\n */\n readonly response: PRes;\n /**\n * The current @@PlatformRequest@@.\n */\n readonly request: PReq;\n\n private ignoreUrlPatterns: RegExp[] = [];\n #isDestroyed: boolean = false;\n\n constructor(options: PlatformContextOptions) {\n super(options);\n\n options.endpoint && (this.endpoint = options.endpoint);\n\n this.event = options.event;\n this.response = new (options.ResponseKlass || PlatformResponse)(this);\n this.request = new (options.RequestKlass || PlatformRequest)(this);\n\n this.request.request.$ctx = this;\n this.request.request.id = this.id;\n this.container.set(PlatformResponse, this.response);\n this.container.set(PlatformRequest, this.request);\n this.container.set(PlatformContext, this);\n\n this.response.setHeader(\"x-request-id\", this.id);\n }\n\n /**\n * The current @@EndpointMetadata@@ resolved by Ts.ED during the request.\n */\n get endpoint(): EndpointMetadata {\n return this.get(EndpointMetadata);\n }\n\n set endpoint(endpoint: EndpointMetadata) {\n this.set(EndpointMetadata, endpoint);\n }\n\n get url() {\n return this.request.url;\n }\n\n get app() {\n return this.injector.get<PlatformApplication>(PlatformApplication)!;\n }\n\n async destroy() {\n await super.destroy();\n\n this.upgrade({\n response: {\n isDone: true,\n statusCode: this.statusCode\n },\n request: {\n method: this.method,\n url: this.url,\n headers: this.headers,\n body: this.body,\n query: this.query,\n params: this.params\n }\n } as any);\n\n this.response.destroy();\n this.request.destroy();\n this.#isDestroyed = true;\n }\n\n isDone() {\n return this.request?.isAborted() || this.response?.isDone() || this.#isDestroyed;\n }\n\n /**\n * Return the framework request instance (Express, Koa, etc...)\n */\n getRequest<Req = any>(): Req {\n return this.request.getRequest<Req>();\n }\n\n /**\n * Return the framework response instance (Express, Koa, etc...)\n */\n getResponse<Res = any>(): Res {\n return this.response.getResponse<Res>();\n }\n\n /**\n * Get Node.js request\n */\n getReq(): IncomingMessage {\n return this.request.getReq();\n }\n\n /**\n * Get Node.js response\n */\n getRes(): ServerResponse {\n return this.response.getRes();\n }\n\n /**\n * Return the original application instance.\n */\n getApp<T = any>(): T {\n return this.app.getApp() as any;\n }\n\n upgrade(event: IncomingEvent) {\n this.event = event;\n }\n}\n"]}
@@ -4,9 +4,13 @@ exports.PlatformRouteDetails = void 0;
4
4
  const platform_params_1 = require("@tsed/platform-params");
5
5
  const schema_1 = require("@tsed/schema");
6
6
  class PlatformRouteDetails extends schema_1.JsonOperationRoute {
7
- constructor(options = {}) {
7
+ rawBody;
8
+ provider;
9
+ constructor(options) {
8
10
  super(options);
9
11
  this.rawBody = !!this.endpoint.parameters.find((param) => param.paramType === platform_params_1.ParamTypes.RAW_BODY);
12
+ // TMP FIX
13
+ this.endpoint.set("route", this.url);
10
14
  }
11
15
  toJSON() {
12
16
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformRouteDetails.js","sourceRoot":"","sources":["../../../src/domain/PlatformRouteDetails.ts"],"names":[],"mappings":";;;AAAA,2DAAiD;AACjD,yCAAkE;AAUlE,MAAa,oBAAqB,SAAQ,2BAAoC;IAI5E,YAAY,UAAyC,EAAE;QACrD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,4BAAU,CAAC,QAAQ,CAAC,CAAC;IACrG,CAAC;IAED,MAAM;QACJ,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;CACF;AApBD,oDAoBC","sourcesContent":["import {ParamTypes} from \"@tsed/platform-params\";\nimport {EndpointMetadata, JsonOperationRoute} from \"@tsed/schema\";\nimport {ControllerProvider} from \"./ControllerProvider\";\n\nexport interface PlatformRouterDetailsOptions {\n provider: ControllerProvider;\n endpoint: EndpointMetadata;\n method: string;\n url: string;\n}\n\nexport class PlatformRouteDetails extends JsonOperationRoute<EndpointMetadata> {\n readonly rawBody: boolean;\n readonly provider: ControllerProvider;\n\n constructor(options: Partial<PlatformRouteDetails> = {}) {\n super(options);\n this.rawBody = !!this.endpoint.parameters.find((param) => param.paramType === ParamTypes.RAW_BODY);\n }\n\n toJSON() {\n return {\n method: this.method,\n name: this.name,\n url: this.url,\n className: this.className,\n methodClassName: this.methodClassName,\n parameters: this.parameters,\n rawBody: this.rawBody\n };\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformRouteDetails.js","sourceRoot":"","sources":["../../../src/domain/PlatformRouteDetails.ts"],"names":[],"mappings":";;;AAAA,2DAAiD;AACjD,yCAAkE;AAGlE,MAAa,oBAAqB,SAAQ,2BAAoC;IACnE,OAAO,CAAU;IACjB,QAAQ,CAAqB;IAEtC,YAAY,OAAsC;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,4BAAU,CAAC,QAAQ,CAAC,CAAC;QAEnG,UAAU;QACV,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;IAED,MAAM;QACJ,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;CACF;AAvBD,oDAuBC","sourcesContent":["import {ParamTypes} from \"@tsed/platform-params\";\nimport {EndpointMetadata, JsonOperationRoute} from \"@tsed/schema\";\nimport {ControllerProvider} from \"./ControllerProvider\";\n\nexport class PlatformRouteDetails extends JsonOperationRoute<EndpointMetadata> {\n readonly rawBody: boolean;\n readonly provider: ControllerProvider;\n\n constructor(options: Partial<PlatformRouteDetails>) {\n super(options);\n this.rawBody = !!this.endpoint.parameters.find((param) => param.paramType === ParamTypes.RAW_BODY);\n\n // TMP FIX\n this.endpoint.set(\"route\", this.url);\n }\n\n toJSON() {\n return {\n method: this.method,\n name: this.name,\n url: this.url,\n className: this.className,\n methodClassName: this.methodClassName,\n parameters: this.parameters,\n rawBody: this.rawBody\n };\n }\n}\n"]}
@@ -12,9 +12,10 @@ const platform_params_1 = require("@tsed/platform-params");
12
12
  * @platform
13
13
  */
14
14
  let PlatformAcceptMimesMiddleware = class PlatformAcceptMimesMiddleware {
15
+ acceptMimes;
15
16
  use(ctx) {
16
17
  const { endpoint, request } = ctx;
17
- const mimes = (0, core_1.uniq)(((endpoint === null || endpoint === void 0 ? void 0 : endpoint.get("acceptMimes")) || []).concat(this.acceptMimes));
18
+ const mimes = (0, core_1.uniq)((endpoint?.get("acceptMimes") || []).concat(this.acceptMimes));
18
19
  if (mimes.length && !request.accepts(mimes)) {
19
20
  throw new exceptions_1.NotAcceptable(mimes.join(", "));
20
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformAcceptMimesMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PlatformAcceptMimesMiddleware.ts"],"names":[],"mappings":";;;;AAAA,qCAAgC;AAChC,iCAAkC;AAClC,iDAA+C;AAC/C,qEAAyE;AACzE,2DAA8C;AAE9C;;;GAGG;AAEH,IAAa,6BAA6B,GAA1C,MAAa,6BAA6B;IAIjC,GAAG,CAAY,GAAY;QAChC,MAAM,EAAC,QAAQ,EAAE,OAAO,EAAC,GAAG,GAAG,CAAC;QAChC,MAAM,KAAK,GAAG,IAAA,WAAI,EAAC,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,GAAG,CAAC,aAAa,CAAC,KAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;QAElF,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC3C,MAAM,IAAI,0BAAa,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;SAC3C;IACH,CAAC;CACF,CAAA;AAVC;IADC,IAAA,aAAQ,EAAC,aAAa,EAAE,EAAE,CAAC;;kEACN;AAEtB;IAAY,mBAAA,IAAA,yBAAO,GAAE,CAAA;;;;wDAOpB;AAXU,6BAA6B;IADzC,IAAA,iCAAU,GAAE;GACA,6BAA6B,CAYzC;AAZY,sEAA6B","sourcesContent":["import {uniq} from \"@tsed/core\";\nimport {Constant} from \"@tsed/di\";\nimport {NotAcceptable} from \"@tsed/exceptions\";\nimport {Middleware, MiddlewareMethods} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/platform-params\";\n\n/**\n * @middleware\n * @platform\n */\n@Middleware()\nexport class PlatformAcceptMimesMiddleware implements MiddlewareMethods {\n @Constant(\"acceptMimes\", [])\n acceptMimes: string[];\n\n public use(@Context() ctx: Context): void {\n const {endpoint, request} = ctx;\n const mimes = uniq((endpoint?.get(\"acceptMimes\") || []).concat(this.acceptMimes));\n\n if (mimes.length && !request.accepts(mimes)) {\n throw new NotAcceptable(mimes.join(\", \"));\n }\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformAcceptMimesMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PlatformAcceptMimesMiddleware.ts"],"names":[],"mappings":";;;;AAAA,qCAAgC;AAChC,iCAAkC;AAClC,iDAA+C;AAC/C,qEAAyE;AACzE,2DAA8C;AAE9C;;;GAGG;AAEH,IAAa,6BAA6B,GAA1C,MAAa,6BAA6B;IAExC,WAAW,CAAW;IAEf,GAAG,CAAY,GAAY;QAChC,MAAM,EAAC,QAAQ,EAAE,OAAO,EAAC,GAAG,GAAG,CAAC;QAChC,MAAM,KAAK,GAAG,IAAA,WAAI,EAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;QAElF,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC3C,MAAM,IAAI,0BAAa,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;SAC3C;IACH,CAAC;CACF,CAAA;AAVC;IADC,IAAA,aAAQ,EAAC,aAAa,EAAE,EAAE,CAAC;;kEACN;AAEtB;IAAY,mBAAA,IAAA,yBAAO,GAAE,CAAA;;;;wDAOpB;AAXU,6BAA6B;IADzC,IAAA,iCAAU,GAAE;GACA,6BAA6B,CAYzC;AAZY,sEAA6B","sourcesContent":["import {uniq} from \"@tsed/core\";\nimport {Constant} from \"@tsed/di\";\nimport {NotAcceptable} from \"@tsed/exceptions\";\nimport {Middleware, MiddlewareMethods} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/platform-params\";\n\n/**\n * @middleware\n * @platform\n */\n@Middleware()\nexport class PlatformAcceptMimesMiddleware implements MiddlewareMethods {\n @Constant(\"acceptMimes\", [])\n acceptMimes: string[];\n\n public use(@Context() ctx: Context): void {\n const {endpoint, request} = ctx;\n const mimes = uniq((endpoint?.get(\"acceptMimes\") || []).concat(this.acceptMimes));\n\n if (mimes.length && !request.accepts(mimes)) {\n throw new NotAcceptable(mimes.join(\", \"));\n }\n }\n}\n"]}
@@ -20,6 +20,8 @@ exports.MulterException = MulterException;
20
20
  * @middleware
21
21
  */
22
22
  let PlatformMulterMiddleware = PlatformMulterMiddleware_1 = class PlatformMulterMiddleware {
23
+ settings;
24
+ app;
23
25
  async use(ctx) {
24
26
  try {
25
27
  const { fields, options = {} } = ctx.endpoint.get(PlatformMulterMiddleware_1);
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformMulterMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PlatformMulterMiddleware.ts"],"names":[],"mappings":";;;;;AACA,iCAAiD;AACjD,iDAA4C;AAC5C,qEAAyE;AACzE,2DAA8C;AAE9C,yEAAoE;AAOpE,MAAa,eAAgB,SAAQ,uBAAU;IAC7C,YAAY,EAAe;QACzB,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;IACtB,CAAC;CACF;AAND,0CAMC;AAED;;GAEG;AAEH,IAAa,wBAAwB,gCAArC,MAAa,wBAAwB;IAOnC,KAAK,CAAC,GAAG,CAAY,GAAY;QAC/B,IAAI;YACF,MAAM,EAAC,MAAM,EAAE,OAAO,GAAG,EAAE,EAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,0BAAwB,CAAC,CAAC;YAC1E,MAAM,QAAQ,GAA2B;gBACvC,GAAG,IAAI,CAAC,QAAQ;gBAChB,GAAG,OAAO;aACX,CAAC;YAEF,0BAA0B;YAC1B,IAAI,QAAQ,CAAC,OAAO,EAAE;gBACpB,OAAO,QAAQ,CAAC,IAAI,CAAC;aACtB;YAED,MAAM,UAAU,GAAQ,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC,CAAC;YAEnF,OAAO,MAAM,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;SAC9D;QAAC,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,CAAC,IAAI,EAAE;gBACX,MAAM,IAAI,eAAe,CAAC,EAAE,CAAC,CAAC;aAC/B;YAED,MAAM,EAAE,CAAC;SACV;IACH,CAAC;IAES,SAAS,CAAC,IAAwB;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAC,EAAE,EAAE,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAC,CAAC,CAAC,CAAC;IACnE,CAAC;CACF,CAAA;AAjCC;IADC,IAAA,UAAK,EAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,4EAA4E;;;0DACtD;AAG3C;IADC,IAAA,WAAM,GAAE;sCACM,yCAAmB;qDAAC;AAEnC;IAAW,mBAAA,IAAA,yBAAO,GAAE,CAAA;;;;mDAuBnB;AA9BU,wBAAwB;IADpC,IAAA,iCAAU,GAAE;GACA,wBAAwB,CAmCpC;AAnCY,4DAAwB","sourcesContent":["import type {MulterError} from \"multer\";\nimport {Constant, Inject, Value} from \"@tsed/di\";\nimport {BadRequest} from \"@tsed/exceptions\";\nimport {Middleware, MiddlewareMethods} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/platform-params\";\nimport {PlatformMulterField, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {PlatformConfiguration} from \"../config/services/PlatformConfiguration\";\n\nexport interface MulterInputOptions {\n fields: PlatformMulterField[];\n}\n\nexport class MulterException extends BadRequest {\n constructor(er: MulterError) {\n super(er.message);\n this.origin = er;\n this.name = er.code;\n }\n}\n\n/**\n * @middleware\n */\n@Middleware()\nexport class PlatformMulterMiddleware implements MiddlewareMethods {\n @Value(\"multer\", {}) // NOTE: don't use constant to getting multer configuration. See issue #1840\n protected settings: PlatformMulterSettings;\n\n @Inject()\n protected app: PlatformApplication;\n\n async use(@Context() ctx: Context) {\n try {\n const {fields, options = {}} = ctx.endpoint.get(PlatformMulterMiddleware);\n const settings: PlatformMulterSettings = {\n ...this.settings,\n ...options\n };\n\n /* istanbul ignore next */\n if (settings.storage) {\n delete settings.dest;\n }\n\n const middleware: any = this.app.multer(settings).fields(this.getFields({fields}));\n\n return await middleware(ctx.getRequest(), ctx.getResponse());\n } catch (er) {\n if (er.code) {\n throw new MulterException(er);\n }\n\n throw er;\n }\n }\n\n protected getFields(conf: MulterInputOptions) {\n return conf.fields.map(({name, maxCount}) => ({name, maxCount}));\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformMulterMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PlatformMulterMiddleware.ts"],"names":[],"mappings":";;;;;AACA,iCAAiD;AACjD,iDAA4C;AAC5C,qEAAyE;AACzE,2DAA8C;AAE9C,yEAAoE;AAMpE,MAAa,eAAgB,SAAQ,uBAAU;IAC7C,YAAY,EAAe;QACzB,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;IACtB,CAAC;CACF;AAND,0CAMC;AAED;;GAEG;AAEH,IAAa,wBAAwB,gCAArC,MAAa,wBAAwB;IAEzB,QAAQ,CAAyB;IAGjC,GAAG,CAAsB;IAEnC,KAAK,CAAC,GAAG,CAAY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multer\";\nimport {Constant, Inject, Value} from \"@tsed/di\";\nimport {BadRequest} from \"@tsed/exceptions\";\nimport {Middleware, MiddlewareMethods} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/platform-params\";\nimport {PlatformMulterField, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\n\nexport interface MulterInputOptions {\n fields: PlatformMulterField[];\n}\n\nexport class MulterException extends BadRequest {\n constructor(er: MulterError) {\n super(er.message);\n this.origin = er;\n this.name = er.code;\n }\n}\n\n/**\n * @middleware\n */\n@Middleware()\nexport class PlatformMulterMiddleware implements MiddlewareMethods {\n @Value(\"multer\", {}) // NOTE: don't use constant to getting multer configuration. See issue #1840\n protected settings: PlatformMulterSettings;\n\n @Inject()\n protected app: PlatformApplication;\n\n async use(@Context() ctx: Context) {\n try {\n const {fields, options = {}} = ctx.endpoint.get(PlatformMulterMiddleware);\n const settings: PlatformMulterSettings = {\n ...this.settings,\n ...options\n };\n\n /* istanbul ignore next */\n if (settings.storage) {\n delete settings.dest;\n }\n\n const middleware: any = this.app.multer(settings).fields(this.getFields({fields}));\n\n return await middleware(ctx.getRequest(), ctx.getResponse());\n } catch (er) {\n if (er.code) {\n throw new MulterException(er);\n }\n\n throw er;\n }\n }\n\n protected getFields(conf: MulterInputOptions) {\n return conf.fields.map(({name, maxCount}) => ({name, maxCount}));\n }\n}\n"]}
@@ -2,9 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FakeAdapter = void 0;
4
4
  class FakeAdapter {
5
- constructor() {
6
- this.providers = [];
7
- }
5
+ providers = [];
8
6
  static createFakeRawDriver() {
9
7
  // istanbul ignore next
10
8
  function FakeRawDriver() { }
@@ -1 +1 @@
1
- {"version":3,"file":"FakeAdapter.js","sourceRoot":"","sources":["../../../src/services/FakeAdapter.ts"],"names":[],"mappings":";;;AAKA,MAAa,WAAW;IAAxB;QACE,cAAS,GAAmB,EAAE,CAAC;IAuDjC,CAAC;IArDC,MAAM,CAAC,mBAAmB;QACxB,uBAAuB;QACvB,SAAS,aAAa,KAAI,CAAC;QAE3B,uBAAuB;QACvB,SAAS,GAAG;YACV,OAAO,IAAI,CAAC;QACd,CAAC;QAED,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,KAAK,GAAG,GAAG,CAAC;QAC1B,aAAa,CAAC,IAAI,GAAG,GAAG,CAAC;QACzB,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,IAAI,GAAG,GAAG,CAAC;QACzB,aAAa,CAAC,MAAM,GAAG,GAAG,CAAC;QAC3B,aAAa,CAAC,OAAO,GAAG,GAAG,CAAC;QAE5B,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,GAAG;QACD,MAAM,GAAG,GAAG,WAAW,CAAC,mBAAmB,EAAE,CAAC;QAC9C,OAAO;YACL,GAAG;YACH,QAAQ;gBACN,OAAO,GAAG,CAAC;YACb,CAAC;SACF,CAAC;IACJ,CAAC;IAED,SAAS,CAAC,OAA+B;QACvC,OAAO,EAAS,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,aAAkB;QACvB,MAAM,MAAM,GAAG,WAAW,CAAC,mBAAmB,EAAE,CAAC;QACjD,OAAO;YACL,MAAM;YACN,QAAQ;gBACN,OAAO,MAAM,CAAC;YAChB,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,QAAgB,EAAE,OAA+B;QACvD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,UAAU,CAAC,IAAY;QACrB,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC;CACF;AAxDD,kCAwDC","sourcesContent":["import {ProviderOpts} from \"@tsed/di\";\nimport {PlatformAdapter} from \"./PlatformAdapter\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\n\nexport class FakeAdapter implements PlatformAdapter<any, any> {\n providers: ProviderOpts[] = [];\n\n static createFakeRawDriver() {\n // istanbul ignore next\n function FakeRawDriver() {}\n\n // istanbul ignore next\n function use() {\n return this;\n }\n\n FakeRawDriver.use = use;\n FakeRawDriver.all = use;\n FakeRawDriver.get = use;\n FakeRawDriver.patch = use;\n FakeRawDriver.post = use;\n FakeRawDriver.put = use;\n FakeRawDriver.head = use;\n FakeRawDriver.delete = use;\n FakeRawDriver.options = use;\n\n return FakeRawDriver;\n }\n\n app(): {app: any; callback(): any} {\n const app = FakeAdapter.createFakeRawDriver();\n return {\n app,\n callback() {\n return app;\n }\n };\n }\n\n multipart(options: PlatformMulterSettings): PlatformMulter {\n return {} as any;\n }\n\n router(routerOptions: any): {router: any; callback(): any} {\n const router = FakeAdapter.createFakeRawDriver();\n return {\n router,\n callback() {\n return router;\n }\n };\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions): any {\n return {};\n }\n\n bodyParser(type: string): any {\n return () => {};\n }\n}\n"]}
1
+ {"version":3,"file":"FakeAdapter.js","sourceRoot":"","sources":["../../../src/services/FakeAdapter.ts"],"names":[],"mappings":";;;AAKA,MAAa,WAAW;IACtB,SAAS,GAAmB,EAAE,CAAC;IAE/B,MAAM,CAAC,mBAAmB;QACxB,uBAAuB;QACvB,SAAS,aAAa,KAAI,CAAC;QAE3B,uBAAuB;QACvB,SAAS,GAAG;YACV,OAAO,IAAI,CAAC;QACd,CAAC;QAED,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,KAAK,GAAG,GAAG,CAAC;QAC1B,aAAa,CAAC,IAAI,GAAG,GAAG,CAAC;QACzB,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,IAAI,GAAG,GAAG,CAAC;QACzB,aAAa,CAAC,MAAM,GAAG,GAAG,CAAC;QAC3B,aAAa,CAAC,OAAO,GAAG,GAAG,CAAC;QAE5B,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,GAAG;QACD,MAAM,GAAG,GAAG,WAAW,CAAC,mBAAmB,EAAE,CAAC;QAC9C,OAAO;YACL,GAAG;YACH,QAAQ;gBACN,OAAO,GAAG,CAAC;YACb,CAAC;SACF,CAAC;IACJ,CAAC;IAED,SAAS,CAAC,OAA+B;QACvC,OAAO,EAAS,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,aAAkB;QACvB,MAAM,MAAM,GAAG,WAAW,CAAC,mBAAmB,EAAE,CAAC;QACjD,OAAO;YACL,MAAM;YACN,QAAQ;gBACN,OAAO,MAAM,CAAC;YAChB,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,QAAgB,EAAE,OAA+B;QACvD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,UAAU,CAAC,IAAY;QACrB,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC;CACF;AAxDD,kCAwDC","sourcesContent":["import {ProviderOpts} from \"@tsed/di\";\nimport {PlatformAdapter} from \"./PlatformAdapter\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\n\nexport class FakeAdapter implements PlatformAdapter<any, any> {\n providers: ProviderOpts[] = [];\n\n static createFakeRawDriver() {\n // istanbul ignore next\n function FakeRawDriver() {}\n\n // istanbul ignore next\n function use() {\n return this;\n }\n\n FakeRawDriver.use = use;\n FakeRawDriver.all = use;\n FakeRawDriver.get = use;\n FakeRawDriver.patch = use;\n FakeRawDriver.post = use;\n FakeRawDriver.put = use;\n FakeRawDriver.head = use;\n FakeRawDriver.delete = use;\n FakeRawDriver.options = use;\n\n return FakeRawDriver;\n }\n\n app(): {app: any; callback(): any} {\n const app = FakeAdapter.createFakeRawDriver();\n return {\n app,\n callback() {\n return app;\n }\n };\n }\n\n multipart(options: PlatformMulterSettings): PlatformMulter {\n return {} as any;\n }\n\n router(routerOptions: any): {router: any; callback(): any} {\n const router = FakeAdapter.createFakeRawDriver();\n return {\n router,\n callback() {\n return router;\n }\n };\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions): any {\n return {};\n }\n\n bodyParser(type: string): any {\n return () => {};\n }\n}\n"]}
@@ -14,11 +14,13 @@ const PlatformMiddlewaresChain_1 = require("./PlatformMiddlewaresChain");
14
14
  * @platform
15
15
  */
16
16
  let Platform = class Platform {
17
+ injector;
18
+ platformApplication;
19
+ _routes = [];
20
+ _controllers = [];
17
21
  constructor(injector, platformApplication) {
18
22
  this.injector = injector;
19
23
  this.platformApplication = platformApplication;
20
- this._routes = [];
21
- this._controllers = [];
22
24
  this.createRouters();
23
25
  }
24
26
  get app() {
@@ -1 +1 @@
1
- {"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../../src/services/Platform.ts"],"names":[],"mappings":";;;;AACA,iCAAiG;AACjG,yCAAoH;AACpH,oFAA0F;AAE1F,yEAAoE;AAEpE,+DAA0D;AAC1D,yEAAoE;AAEpE;;;;GAIG;AAKH,IAAa,QAAQ,GAArB,MAAa,QAAQ;IAInB,YAAqB,QAAyB,EAAW,mBAAwC;QAA5E,aAAQ,GAAR,QAAQ,CAAiB;QAAW,wBAAmB,GAAnB,mBAAmB,CAAqB;QAHzF,YAAO,GAA2B,EAAE,CAAC;QACrC,iBAAY,GAAsB,EAAE,CAAC;QAG3C,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,SAAS,CAAC,MAAe;QAC9B,MAAM,C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AI,CAAC,iBAAiB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC;QAC1E,CAAC,EAAE,EAAE,CAAC;aACL,MAAM,CAAC;YACN;gBACE,KAAK,EAAE,QAAQ;gBACf,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAuB;aACjE;SACF,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACK,gBAAgB;QACtB,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,QAAQ,CAAC,YAAY,CAAC,iBAAY,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,QAA4B,EAAE,EAAE;YAClF,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;gBACzB,OAAO,IAAA,uCAAW,EAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;aACxC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA3HY,QAAQ;IAJpB,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,mDAAwB,CAAC;KACpC,CAAC;6CAK+B,oBAAe,EAAgC,yCAAmB;GAJtF,QAAQ,CA2HpB;AA3HY,4BAAQ","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {Injectable, InjectorService, ProviderScope, ProviderType, TokenProvider} from \"@tsed/di\";\nimport {concatPath, EndpointMetadata, getJsonEntityStore, getOperationsRoutes, JsonEntityStore} from \"@tsed/schema\";\nimport {buildRouter, createRouter, getRouter} from \"../builder/PlatformControllerBuilder\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {PlatformRouteDetails} from \"../domain/PlatformRouteDetails\";\nimport {Route, RouteController} from \"../interfaces/Route\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {PlatformMiddlewaresChain} from \"./PlatformMiddlewaresChain\";\n\n/**\n * `Platform` is used to provide all routes collected by annotation `@Controller`.\n *\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [PlatformMiddlewaresChain]\n})\nexport class Platform {\n private _routes: PlatformRouteDetails[] = [];\n private _controllers: RouteController[] = [];\n\n constructor(readonly injector: InjectorService, readonly platformApplication: PlatformApplication) {\n this.createRouters();\n }\n\n get app() {\n return this.platformApplication;\n }\n\n get routes(): PlatformRouteDetails[] {\n return this._routes;\n }\n\n public addRoutes(routes: Route[]) {\n routes.forEach((routeSettings) => {\n this.addRoute(routeSettings.route, routeSettings.token);\n });\n }\n\n public addRoute(basePath: string, token: TokenProvider) {\n const {injector} = this;\n const provider = injector.getProvider(token) as ControllerProvider;\n\n if (!provider || provider.hasParent()) {\n return;\n }\n\n this._controllers.push(...this.getAllControllers(basePath, token));\n\n const ctrlPath = concatPath(basePath, JsonEntityStore.from(provider.token).path);\n\n this.app.use(ctrlPath, ...[].concat(getRouter(injector, provider).callback()));\n\n this._routes = getOperationsRoutes<EndpointMetadata>(provider.token, {\n withChildren: true,\n basePath\n }).reduce((routes, operationRoute) => {\n if (injector.hasProvider(token)) {\n const provider = injector.getProvider(operationRoute.token) as ControllerProvider;\n const route = new PlatformRouteDetails({\n ...operationRoute,\n provider\n });\n\n routes = routes.concat(route);\n }\n\n return routes;\n }, this._routes);\n\n return this;\n }\n\n /**\n * Get all routes built by TsExpressDecorators and mounted on Express application.\n * @returns {PlatformRouteDetails[]}\n */\n public getRoutes(): PlatformRouteDetails[] {\n return this._routes;\n }\n\n /**\n * Get all controllers mounted on the application.\n * @returns {RouteController[]}\n */\n public getMountedControllers(): RouteController[] {\n return this._controllers;\n }\n\n protected $onInit() {\n this.buildControllers();\n }\n\n /**\n * Create routers from the collected controllers.\n * @private\n */\n private createRouters() {\n const {injector} = this;\n\n injector.getProviders(ProviderType.CONTROLLER).map((provider: ControllerProvider) => {\n createRouter(injector, provider);\n });\n }\n\n /**\n * Get all router controllers from the controller token.\n * @private\n */\n private getAllControllers(basePath: string, token: Type<any> | any): RouteController[] {\n const store: JsonEntityStore = token.isStore ? token : getJsonEntityStore(token);\n const ctrlPath = concatPath(basePath, JsonEntityStore.from(token).path);\n const children = store.get<Type[]>(\"childrenControllers\", []);\n\n return children\n .reduce<RouteController[]>((controllers, token) => {\n const childBasePath = concatPath(basePath, store.path);\n return controllers.concat(this.getAllControllers(childBasePath, token));\n }, [])\n .concat([\n {\n route: ctrlPath,\n provider: this.injector.getProvider(token) as ControllerProvider\n }\n ]);\n }\n\n /**\n * Create controllers from DI\n * @private\n */\n private buildControllers() {\n const {injector} = this;\n\n injector.getProviders(ProviderType.CONTROLLER).map((provider: ControllerProvider) => {\n if (!provider.hasParent()) {\n return buildRouter(injector, provider);\n }\n });\n }\n}\n"]}
1
+ {"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../../src/services/Platform.ts"],"names":[],"mappings":";;;;AACA,iCAAiG;AACjG,yCAAoH;AACpH,oFAA0F;AAE1F,yEAAoE;AAEpE,+DAA0D;AAC1D,yEAAoE;AAEpE;;;;GAIG;AAKH,IAAa,QAAQ,GAArB,MAAa,QAAQ;IAIE;IAAoC;IAHjD,OAAO,GAA2B,EAAE,CAAC;IACrC,YAAY,GAAsB,EAAE,CAAC;IAE7C,YAAqB,QAAyB,EAAW,mBAAwC;QAA5E,aAAQ,GAAR,QAAQ,CAAiB;QAAW,wBAAmB,GAAnB,mBAAmB,CAAqB;QAC/F,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,SAAS,CAAC,MAAe;QAC9B,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE;YAC/B,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,QAAQ,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CAAC,WAAW,CAAC,KAAK,CAAuB;aACjE;SACF,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACK,gBAAgB;QACtB,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,QAAQ,CAAC,YAAY,CAAC,iBAAY,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,QAA4B,EAAE,EAAE;YAClF,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;gBACzB,OAAO,IAAA,uCAAW,EAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;aACxC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA3HY,QAAQ;IAJpB,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,mDAAwB,CAAC;KACpC,CAAC;6CAK+B,oBAAe,EAAgC,yCAAmB;GAJtF,QAAQ,CA2HpB;AA3HY,4BAAQ","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {Injectable, InjectorService, ProviderScope, ProviderType, TokenProvider} from \"@tsed/di\";\nimport {concatPath, EndpointMetadata, getJsonEntityStore, getOperationsRoutes, JsonEntityStore} from \"@tsed/schema\";\nimport {buildRouter, createRouter, getRouter} from \"../builder/PlatformControllerBuilder\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {PlatformRouteDetails} from \"../domain/PlatformRouteDetails\";\nimport {Route, RouteController} from \"../interfaces/Route\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {PlatformMiddlewaresChain} from \"./PlatformMiddlewaresChain\";\n\n/**\n * `Platform` is used to provide all routes collected by annotation `@Controller`.\n *\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [PlatformMiddlewaresChain]\n})\nexport class Platform {\n private _routes: PlatformRouteDetails[] = [];\n private _controllers: RouteController[] = [];\n\n constructor(readonly injector: InjectorService, readonly platformApplication: PlatformApplication) {\n this.createRouters();\n }\n\n get app() {\n return this.platformApplication;\n }\n\n get routes(): PlatformRouteDetails[] {\n return this._routes;\n }\n\n public addRoutes(routes: Route[]) {\n routes.forEach((routeSettings) => {\n this.addRoute(routeSettings.route, routeSettings.token);\n });\n }\n\n public addRoute(basePath: string, token: TokenProvider) {\n const {injector} = this;\n const provider = injector.getProvider(token) as ControllerProvider;\n\n if (!provider || provider.hasParent()) {\n return;\n }\n\n this._controllers.push(...this.getAllControllers(basePath, token));\n\n const ctrlPath = concatPath(basePath, JsonEntityStore.from(provider.token).path);\n\n this.app.use(ctrlPath, ...[].concat(getRouter(injector, provider).callback()));\n\n this._routes = getOperationsRoutes<EndpointMetadata>(provider.token, {\n withChildren: true,\n basePath\n }).reduce((routes, operationRoute) => {\n if (injector.hasProvider(token)) {\n const provider = injector.getProvider(operationRoute.token) as ControllerProvider;\n const route = new PlatformRouteDetails({\n ...operationRoute,\n provider\n });\n\n routes = routes.concat(route);\n }\n\n return routes;\n }, this._routes);\n\n return this;\n }\n\n /**\n * Get all routes built by TsExpressDecorators and mounted on Express application.\n * @returns {PlatformRouteDetails[]}\n */\n public getRoutes(): PlatformRouteDetails[] {\n return this._routes;\n }\n\n /**\n * Get all controllers mounted on the application.\n * @returns {RouteController[]}\n */\n public getMountedControllers(): RouteController[] {\n return this._controllers;\n }\n\n protected $onInit() {\n this.buildControllers();\n }\n\n /**\n * Create routers from the collected controllers.\n * @private\n */\n private createRouters() {\n const {injector} = this;\n\n injector.getProviders(ProviderType.CONTROLLER).map((provider: ControllerProvider) => {\n createRouter(injector, provider);\n });\n }\n\n /**\n * Get all router controllers from the controller token.\n * @private\n */\n private getAllControllers(basePath: string, token: Type<any> | any): RouteController[] {\n const store: JsonEntityStore = token.isStore ? token : getJsonEntityStore(token);\n const ctrlPath = concatPath(basePath, JsonEntityStore.from(token).path);\n const children = store.get<Type[]>(\"childrenControllers\", []);\n\n return children\n .reduce<RouteController[]>((controllers, token) => {\n const childBasePath = concatPath(basePath, store.path);\n return controllers.concat(this.getAllControllers(childBasePath, token));\n }, [])\n .concat([\n {\n route: ctrlPath,\n provider: this.injector.getProvider(token) as ControllerProvider\n }\n ]);\n }\n\n /**\n * Create controllers from DI\n * @private\n */\n private buildControllers() {\n const {injector} = this;\n\n injector.getProviders(ProviderType.CONTROLLER).map((provider: ControllerProvider) => {\n if (!provider.hasParent()) {\n return buildRouter(injector, provider);\n }\n });\n }\n}\n"]}
@@ -4,6 +4,18 @@ exports.PlatformAdapter = void 0;
4
4
  const di_1 = require("@tsed/di");
5
5
  const FakeAdapter_1 = require("./FakeAdapter");
6
6
  class PlatformAdapter {
7
+ /**
8
+ * Load providers in top priority
9
+ */
10
+ providers;
11
+ /**
12
+ * Called after the injector instantiation
13
+ */
14
+ onInit;
15
+ beforeLoadRoutes;
16
+ afterLoadRoutes;
17
+ useRouter;
18
+ useContext;
7
19
  }
8
20
  exports.PlatformAdapter = PlatformAdapter;
9
21
  (0, di_1.registerProvider)({
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformAdapter.js","sourceRoot":"","sources":["../../../src/services/PlatformAdapter.ts"],"names":[],"mappings":";;;AACA,iCAAyE;AAIzE,+CAA0C;AAE1C,MAAsB,eAAe;CAoCpC;AApCD,0CAoCC;AAMD,IAAA,qBAAgB,EAAC;IACf,OAAO,EAAE,eAAe;IACxB,IAAI,EAAE,CAAC,oBAAe,CAAC;IACvB,QAAQ,EAAE,yBAAW;CACtB,CAAC,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {InjectorService, ProviderOpts, registerProvider} from \"@tsed/di\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {RouterOptions} from \"express\";\nimport {FakeAdapter} from \"./FakeAdapter\";\n\nexport abstract class PlatformAdapter<App = TsED.Application, Router = TsED.Router> {\n /**\n * Load providers in top priority\n */\n providers: ProviderOpts[];\n /**\n * Called after the injector instantiation\n */\n onInit?: () => any;\n beforeLoadRoutes?: () => Promise<any>;\n afterLoadRoutes?: () => Promise<any>;\n useRouter?: () => any;\n useContext?: () => any;\n\n abstract app(): {app: App; callback(): any};\n\n abstract router(routerOptions?: Partial<RouterOptions>): {router: Router; callback(): any};\n /**\n * Return the statics middlewares\n * @param endpoint\n * @param options\n */\n abstract statics(endpoint: string, options: PlatformStaticsOptions): any;\n\n /**\n * Return the multipart middleware\n * @param options\n */\n abstract multipart(options: PlatformMulterSettings): PlatformMulter;\n\n /**\n * Return the body parser for the given\n * @param type\n * @param opts\n */\n abstract bodyParser(type: string, opts?: Record<string, any>): any;\n}\n\nexport interface PlatformBuilderSettings<App = TsED.Application, Router = TsED.Router> extends Partial<TsED.Configuration> {\n adapter?: Type<PlatformAdapter<App, Router>>;\n}\n\nregisterProvider({\n provide: PlatformAdapter,\n deps: [InjectorService],\n useClass: FakeAdapter\n});\n"]}
1
+ {"version":3,"file":"PlatformAdapter.js","sourceRoot":"","sources":["../../../src/services/PlatformAdapter.ts"],"names":[],"mappings":";;;AACA,iCAAyE;AAIzE,+CAA0C;AAE1C,MAAsB,eAAe;IACnC;;OAEG;IACH,SAAS,CAAiB;IAC1B;;OAEG;IACH,MAAM,CAAa;IACnB,gBAAgB,CAAsB;IACtC,eAAe,CAAsB;IACrC,SAAS,CAAa;IACtB,UAAU,CAAa;CAwBxB;AApCD,0CAoCC;AAMD,IAAA,qBAAgB,EAAC;IACf,OAAO,EAAE,eAAe;IACxB,IAAI,EAAE,CAAC,oBAAe,CAAC;IACvB,QAAQ,EAAE,yBAAW;CACtB,CAAC,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {InjectorService, ProviderOpts, registerProvider} from \"@tsed/di\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {RouterOptions} from \"express\";\nimport {FakeAdapter} from \"./FakeAdapter\";\n\nexport abstract class PlatformAdapter<App = TsED.Application, Router = TsED.Router> {\n /**\n * Load providers in top priority\n */\n providers: ProviderOpts[];\n /**\n * Called after the injector instantiation\n */\n onInit?: () => any;\n beforeLoadRoutes?: () => Promise<any>;\n afterLoadRoutes?: () => Promise<any>;\n useRouter?: () => any;\n useContext?: () => any;\n\n abstract app(): {app: App; callback(): any};\n\n abstract router(routerOptions?: Partial<RouterOptions>): {router: Router; callback(): any};\n /**\n * Return the statics middlewares\n * @param endpoint\n * @param options\n */\n abstract statics(endpoint: string, options: PlatformStaticsOptions): any;\n\n /**\n * Return the multipart middleware\n * @param options\n */\n abstract multipart(options: PlatformMulterSettings): PlatformMulter;\n\n /**\n * Return the body parser for the given\n * @param type\n * @param opts\n */\n abstract bodyParser(type: string, opts?: Record<string, any>): any;\n}\n\nexport interface PlatformBuilderSettings<App = TsED.Application, Router = TsED.Router> extends Partial<TsED.Configuration> {\n adapter?: Type<PlatformAdapter<App, Router>>;\n}\n\nregisterProvider({\n provide: PlatformAdapter,\n deps: [InjectorService],\n useClass: FakeAdapter\n});\n"]}
@@ -12,6 +12,8 @@ const PlatformAdapter_1 = require("./PlatformAdapter");
12
12
  * @platform
13
13
  */
14
14
  let PlatformApplication = class PlatformApplication extends PlatformRouter_1.PlatformRouter {
15
+ raw;
16
+ rawApp;
15
17
  constructor(platformHandler, adapter) {
16
18
  super(platformHandler, adapter);
17
19
  const { app, callback } = adapter.app();
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformApplication.ts"],"names":[],"mappings":";;;;AAAA,iCAAmD;AACnD,uDAAkD;AAClD,qDAAgD;AAChD,uDAAkD;AASlD;;;;GAIG;AAIH,IAAa,mBAAmB,GAAhC,MAAa,mBAAkE,SAAQ,+BAA2B;IAKhH,YAAY,eAAgC,EAAE,OAAqC;QACjF,KAAK,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAChC,MAAM,EAAC,GAAG,EAAE,QAAQ,EAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAEtC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF,CAAA;AAhBY,mBAAmB;IAH/B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;KAC/B,CAAC;6CAM6B,iCAAe,EAAW,iCAAe;GAL3D,mBAAmB,CAgB/B;AAhBY,kDAAmB","sourcesContent":["import {Injectable, ProviderScope} from \"@tsed/di\";\nimport {PlatformHandler} from \"./PlatformHandler\";\nimport {PlatformRouter} from \"./PlatformRouter\";\nimport {PlatformAdapter} from \"./PlatformAdapter\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Application {}\n }\n}\n\n/**\n * `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.\n *\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON\n})\nexport class PlatformApplication<App = TsED.Application, Router = TsED.Router> extends PlatformRouter<App, Router> {\n raw: App;\n rawApp: App;\n declare rawRouter: Router;\n\n constructor(platformHandler: PlatformHandler, adapter: PlatformAdapter<App, Router>) {\n super(platformHandler, adapter);\n const {app, callback} = adapter.app();\n\n this.rawApp = this.raw = app;\n this.callback = callback;\n }\n\n getApp(): App {\n return this.raw;\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformApplication.ts"],"names":[],"mappings":";;;;AAAA,iCAAmD;AACnD,uDAAkD;AAClD,qDAAgD;AAChD,uDAAkD;AASlD;;;;GAIG;AAIH,IAAa,mBAAmB,GAAhC,MAAa,mBAAkE,SAAQ,+BAA2B;IAChH,GAAG,CAAM;IACT,MAAM,CAAM;IAGZ,YAAY,eAAgC,EAAE,OAAqC;QACjF,KAAK,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAChC,MAAM,EAAC,GAAG,EAAE,QAAQ,EAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAEtC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF,CAAA;AAhBY,mBAAmB;IAH/B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;KAC/B,CAAC;6CAM6B,iCAAe,EAAW,iCAAe;GAL3D,mBAAmB,CAgB/B;AAhBY,kDAAmB","sourcesContent":["import {Injectable, ProviderScope} from \"@tsed/di\";\nimport {PlatformHandler} from \"./PlatformHandler\";\nimport {PlatformRouter} from \"./PlatformRouter\";\nimport {PlatformAdapter} from \"./PlatformAdapter\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Application {}\n }\n}\n\n/**\n * `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.\n *\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON\n})\nexport class PlatformApplication<App = TsED.Application, Router = TsED.Router> extends PlatformRouter<App, Router> {\n raw: App;\n rawApp: App;\n declare rawRouter: Router;\n\n constructor(platformHandler: PlatformHandler, adapter: PlatformAdapter<App, Router>) {\n super(platformHandler, adapter);\n const {app, callback} = adapter.app();\n\n this.rawApp = this.raw = app;\n this.callback = callback;\n }\n\n getApp(): App {\n return this.raw;\n }\n}\n"]}
@@ -17,6 +17,9 @@ const setResponseHeaders_1 = require("../utils/setResponseHeaders");
17
17
  * @platform
18
18
  */
19
19
  let PlatformHandler = class PlatformHandler {
20
+ injector;
21
+ params;
22
+ responseFilter;
20
23
  constructor(injector, params) {
21
24
  this.injector = injector;
22
25
  this.params = params;
@@ -105,8 +108,8 @@ let PlatformHandler = class PlatformHandler {
105
108
  });
106
109
  return;
107
110
  }
108
- const resolver = new AnyToPromiseWithCtx_1.AnyToPromiseWithCtx({ $ctx, err });
109
- return (0, di_1.runInContext)($ctx, async () => {
111
+ return $ctx.runInContext(async () => {
112
+ const resolver = new AnyToPromiseWithCtx_1.AnyToPromiseWithCtx({ $ctx, err });
110
113
  try {
111
114
  const { state, data, status, headers } = await resolver.call(handler);
112
115
  if (state === core_1.AnyToPromiseStatus.RESOLVED) {
@@ -143,7 +146,7 @@ let PlatformHandler = class PlatformHandler {
143
146
  message: `An error was caught after the headers were sent to the client. The error comes from the handler: ${metadata.toString()}`,
144
147
  stack: er.stack,
145
148
  origin: er,
146
- request_id: $ctx === null || $ctx === void 0 ? void 0 : $ctx.id
149
+ request_id: $ctx?.id
147
150
  });
148
151
  return;
149
152
  }
@@ -158,7 +161,7 @@ let PlatformHandler = class PlatformHandler {
158
161
  async onSuccess(data, requestOptions) {
159
162
  const { metadata, $ctx, next } = requestOptions;
160
163
  // istanbul ignore next
161
- if ($ctx === null || $ctx === void 0 ? void 0 : $ctx.isDone()) {
164
+ if ($ctx?.isDone()) {
162
165
  return;
163
166
  }
164
167
  // set headers each times that an endpoint is called
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformHandler.ts"],"names":[],"mappings":";;;;AAAA,qCAAoE;AACpE,iCAAoG;AACpG,yCAAkC;AAClC,2DAAiF;AACjF,6EAAsE;AAEtE,uEAAkE;AAClE,+DAA0D;AAE1D,2DAAsD;AAEtD,0EAAqE;AACrE,oEAA+D;AAY/D;;;GAGG;AAIH,IAAa,eAAe,GAA5B,MAAa,eAAe;IAI1B,YAAsB,QAAyB,EAAY,MAAsB;QAA3D,aAAQ,GAAR,QAAQ,CAAiB;QAAY,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IAErF;;;;OAIG;IACH,aAAa,CAAC,KAA+C,EAAE,UAAwC,EAAE;QACvG,OAAO,IAAI,CAAC,g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CAAC;SACzB;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAE9C,OAAO,KAAK,EAAE,OAAY,EAAE,QAAa,EAAE,IAAS,EAAE,EAAE;YACtD,OAAO,OAAO,CAAC;gBACb,IAAI;gBACJ,IAAI,EAAE,OAAO,CAAC,IAAI;aACnB,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACO,UAAU,CAAC,GAAoB;QACvC,OAAO,IAAA,uCAAkB,EAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAES,IAAI,CAAC,cAAgC;QAC7C,MAAM,EAAC,IAAI,EAAE,IAAI,EAAC,GAAG,cAAc,CAAC;QAEpC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;IACnD,CAAC;IAES,cAAc,CAAC,QAAyB;QAChD,OAAO,KAAK,EAAE,KAAgC,EAAE,EAAE,CAChD;YACE,QAAQ,CAAC,aAAa,IAAI,KAAK,CAAC,GAAG;YACnC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO;YAC1B,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ;YAC5B,QAAQ,CAAC,eAAe,IAAI,KAAK,CAAC,IAAI;SACvC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;CACF,CAAA;AAlPC;IADC,IAAA,WAAM,GAAE;sCACiB,iDAAsB;uDAAC;AAFtC,eAAe;IAH3B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;KAC/B,CAAC;6CAKgC,oBAAe,EAAoB,gCAAc;GAJtE,eAAe,CAoP3B;AApPY,0CAAe","sourcesContent":["import {AnyToPromiseStatus, isFunction, isStream} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider, ProviderScope, runInContext} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {ArgScope, HandlerWithScope, PlatformParams} from \"@tsed/platform-params\";\nimport {PlatformResponseFilter} from \"@tsed/platform-response-filter\";\nimport {EndpointMetadata} from \"@tsed/schema\";\nimport {AnyToPromiseWithCtx} from \"../domain/AnyToPromiseWithCtx\";\nimport {HandlerMetadata} from \"../domain/HandlerMetadata\";\nimport {PlatformContext} from \"../domain/PlatformContext\";\nimport {HandlerType} from \"../interfaces/HandlerType\";\nimport {PlatformRouteWithoutHandlers} from \"../interfaces/PlatformRouteOptions\";\nimport {createHandlerMetadata} from \"../utils/createHandlerMetadata\";\nimport {setResponseHeaders} from \"../utils/setResponseHeaders\";\n\nexport interface OnRequestOptions {\n $ctx: PlatformContext;\n metadata: HandlerMetadata;\n handler: HandlerWithScope;\n next?: any;\n err?: any;\n\n [key: string]: any;\n}\n\n/**\n * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON\n})\nexport class PlatformHandler {\n @Inject()\n protected responseFilter: PlatformResponseFilter;\n\n constructor(protected injector: InjectorService, protected params: PlatformParams) {}\n\n /**\n * Create a native middleware based on the given metadata and return an instance of AnyToPromiseWithCtx\n * @param input\n * @param options\n */\n createHandler(input: EndpointMetadata | HandlerMetadata | any, options: PlatformRouteWithoutHandlers = {}) {\n return this.createRawHandler(createHandlerMetadata(this.injector, input, options));\n }\n\n /**\n * Create injectable handler from the given provider\n * @param provider\n * @param propertyKey\n */\n createCustomHandler(provider: Provider, propertyKey: string) {\n const handler = this.compileHandler(\n new HandlerMetadata({\n token: provider.provide,\n target: provider.useClass,\n type: HandlerType.CUSTOM,\n scope: provider.scope,\n propertyKey\n })\n );\n\n return async ($ctx: PlatformContext, next?: any) =>\n handler({\n $ctx,\n next\n });\n }\n\n /**\n * Send the response to the consumer.\n * @param data\n * @param ctx\n * @protected\n */\n async flush(data: any, ctx: PlatformContext) {\n const {response} = ctx;\n\n if (!response.isDone()) {\n data = await this.responseFilter.serialize(data, ctx);\n data = await this.responseFilter.transform(data, ctx);\n response.body(data);\n }\n }\n\n compileHandler(metadata: HandlerMetadata) {\n if (metadata.type === HandlerType.CTX_FN) {\n return async (scope: Record<string, any>) => {\n // @ts-ignore\n return this.onCtxRequest({\n ...scope,\n handler: () => metadata.handler(scope.$ctx),\n metadata\n });\n };\n }\n\n const promise = this.params.compileHandler<PlatformContext>({\n token: metadata.token,\n propertyKey: metadata.propertyKey,\n getCustomArgs: metadata.injectable ? undefined : this.getDefaultArgs(metadata)\n });\n\n return async (scope: Record<string, any>) => {\n const handler = await promise;\n // @ts-ignore\n return this.onRequest({\n ...scope,\n handler,\n metadata\n });\n };\n }\n\n protected async onCtxRequest(requestOptions: OnRequestOptions): Promise<any> {\n await requestOptions.handler(requestOptions);\n\n return this.next(requestOptions);\n }\n\n /**\n * Call handler when a request his handle\n * @param requestOptions\n */\n protected async onRequest(requestOptions: OnRequestOptions): Promise<any> {\n const {$ctx, metadata, err, handler} = requestOptions;\n // istanbul ignore next\n if (!$ctx || $ctx.isDone()) {\n $log.error({\n name: \"HEADERS_SENT\",\n message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${metadata.toString()}`\n });\n return;\n }\n\n const resolver = new AnyToPromiseWithCtx({$ctx, err});\n\n return runInContext($ctx, async () => {\n try {\n const {state, data, status, headers} = await resolver.call(handler);\n\n if (state === AnyToPromiseStatus.RESOLVED) {\n if (status) {\n $ctx.response.status(status);\n }\n\n if (headers) {\n $ctx.response.setHeaders(headers);\n }\n\n if (data !== undefined) {\n $ctx.data = data;\n }\n\n // Can be canceled by the handler itself\n return await this.onSuccess($ctx.data, requestOptions);\n }\n } catch (er) {\n return this.onError(er, requestOptions);\n }\n });\n }\n\n protected async onError(er: Error, requestOptions: OnRequestOptions) {\n const {next, $ctx, metadata} = requestOptions;\n\n if ($ctx) {\n $ctx.data = er;\n }\n\n if (!next) {\n throw er;\n }\n\n // istanbul ignore next\n if (!$ctx || $ctx.isDone()) {\n $log.warn({\n name: \"HEADERS_SENT\",\n message: `An error was caught after the headers were sent to the client. The error comes from the handler: ${metadata.toString()}`,\n stack: er.stack,\n origin: er,\n request_id: $ctx?.id\n });\n\n return;\n }\n\n return next(er);\n }\n\n /**\n * Manage success scenario\n * @param data\n * @param requestOptions\n * @protected\n */\n protected async onSuccess(data: any, requestOptions: OnRequestOptions) {\n const {metadata, $ctx, next} = requestOptions;\n\n // istanbul ignore next\n if ($ctx?.isDone()) {\n return;\n }\n\n // set headers each times that an endpoint is called\n if (metadata.type === HandlerType.ENDPOINT) {\n this.setHeaders($ctx);\n }\n\n // call returned middleware\n if (isFunction(data) && !isStream(data)) {\n return this.callReturnedMiddleware(data, $ctx, next);\n }\n\n if (metadata.isFinal()) {\n return this.flush(data, $ctx);\n }\n\n return this.next(requestOptions);\n }\n\n /**\n * Call the returned middleware by the handler.\n * @param middleware\n * @param ctx\n * @param next\n * @protected\n */\n protected callReturnedMiddleware(middleware: any, ctx: PlatformContext, next: any) {\n return middleware(ctx.getRequest(), ctx.getResponse(), next);\n }\n\n /**\n * create Raw handler\n * @param metadata\n */\n protected createRawHandler(metadata: HandlerMetadata) {\n if ([HandlerType.RAW_ERR_FN, HandlerType.RAW_FN].includes(metadata.type)) {\n return metadata.handler;\n }\n\n const handler = this.compileHandler(metadata);\n\n return async (request: any, response: any, next: any) => {\n return handler({\n next,\n $ctx: request.$ctx\n });\n };\n }\n\n /**\n * Set response headers\n * @param ctx\n * @protected\n */\n protected setHeaders(ctx: PlatformContext) {\n return setResponseHeaders(ctx);\n }\n\n protected next(requestOptions: OnRequestOptions) {\n const {$ctx, next} = requestOptions;\n\n return !$ctx.response.isDone() && next && next();\n }\n\n protected getDefaultArgs(metadata: HandlerMetadata) {\n return async (scope: ArgScope<PlatformContext>) =>\n [\n metadata.hasErrorParam && scope.err,\n scope.$ctx.request.request,\n scope.$ctx.response.response,\n metadata.hasNextFunction && scope.next\n ].filter(Boolean);\n }\n}\n"]}
1
+ {"version":3,"file":"Pl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C,eAAe,IAAI,KAAK,CAAC,IAAI;SACvC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;CACF,CAAA;AAlPC;IADC,IAAA,WAAM,GAAE;sCACiB,iDAAsB;uDAAC;AAFtC,eAAe;IAH3B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;KAC/B,CAAC;6CAKgC,oBAAe,EAAoB,gCAAc;GAJtE,eAAe,CAoP3B;AApPY,0CAAe","sourcesContent":["import {AnyToPromiseStatus, isFunction, isStream} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider, ProviderScope} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {ArgScope, HandlerWithScope, PlatformParams} from \"@tsed/platform-params\";\nimport {PlatformResponseFilter} from \"@tsed/platform-response-filter\";\nimport {EndpointMetadata} from \"@tsed/schema\";\nimport {AnyToPromiseWithCtx} from \"../domain/AnyToPromiseWithCtx\";\nimport {HandlerMetadata} from \"../domain/HandlerMetadata\";\nimport {PlatformContext} from \"../domain/PlatformContext\";\nimport {HandlerType} from \"../interfaces/HandlerType\";\nimport {PlatformRouteWithoutHandlers} from \"../interfaces/PlatformRouteOptions\";\nimport {createHandlerMetadata} from \"../utils/createHandlerMetadata\";\nimport {setResponseHeaders} from \"../utils/setResponseHeaders\";\n\nexport interface OnRequestOptions {\n $ctx: PlatformContext;\n metadata: HandlerMetadata;\n handler: HandlerWithScope;\n next?: any;\n err?: any;\n\n [key: string]: any;\n}\n\n/**\n * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON\n})\nexport class PlatformHandler {\n @Inject()\n protected responseFilter: PlatformResponseFilter;\n\n constructor(protected injector: InjectorService, protected params: PlatformParams) {}\n\n /**\n * Create a native middleware based on the given metadata and return an instance of AnyToPromiseWithCtx\n * @param input\n * @param options\n */\n createHandler(input: EndpointMetadata | HandlerMetadata | any, options: PlatformRouteWithoutHandlers = {}) {\n return this.createRawHandler(createHandlerMetadata(this.injector, input, options));\n }\n\n /**\n * Create injectable handler from the given provider\n * @param provider\n * @param propertyKey\n */\n createCustomHandler(provider: Provider, propertyKey: string) {\n const handler = this.compileHandler(\n new HandlerMetadata({\n token: provider.provide,\n target: provider.useClass,\n type: HandlerType.CUSTOM,\n scope: provider.scope,\n propertyKey\n })\n );\n\n return async ($ctx: PlatformContext, next?: any) =>\n handler({\n $ctx,\n next\n });\n }\n\n /**\n * Send the response to the consumer.\n * @param data\n * @param ctx\n * @protected\n */\n async flush(data: any, ctx: PlatformContext) {\n const {response} = ctx;\n\n if (!response.isDone()) {\n data = await this.responseFilter.serialize(data, ctx);\n data = await this.responseFilter.transform(data, ctx);\n response.body(data);\n }\n }\n\n compileHandler(metadata: HandlerMetadata) {\n if (metadata.type === HandlerType.CTX_FN) {\n return async (scope: Record<string, any>) => {\n // @ts-ignore\n return this.onCtxRequest({\n ...scope,\n handler: () => metadata.handler(scope.$ctx),\n metadata\n });\n };\n }\n\n const promise = this.params.compileHandler<PlatformContext>({\n token: metadata.token,\n propertyKey: metadata.propertyKey,\n getCustomArgs: metadata.injectable ? undefined : this.getDefaultArgs(metadata)\n });\n\n return async (scope: Record<string, any>) => {\n const handler = await promise;\n // @ts-ignore\n return this.onRequest({\n ...scope,\n handler,\n metadata\n });\n };\n }\n\n protected async onCtxRequest(requestOptions: OnRequestOptions): Promise<any> {\n await requestOptions.handler(requestOptions);\n\n return this.next(requestOptions);\n }\n\n /**\n * Call handler when a request his handle\n * @param requestOptions\n */\n protected async onRequest(requestOptions: OnRequestOptions): Promise<any> {\n const {$ctx, metadata, err, handler} = requestOptions;\n // istanbul ignore next\n if (!$ctx || $ctx.isDone()) {\n $log.error({\n name: \"HEADERS_SENT\",\n message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${metadata.toString()}`\n });\n return;\n }\n\n return $ctx.runInContext(async () => {\n const resolver = new AnyToPromiseWithCtx({$ctx, err});\n\n try {\n const {state, data, status, headers} = await resolver.call(handler);\n\n if (state === AnyToPromiseStatus.RESOLVED) {\n if (status) {\n $ctx.response.status(status);\n }\n\n if (headers) {\n $ctx.response.setHeaders(headers);\n }\n\n if (data !== undefined) {\n $ctx.data = data;\n }\n\n // Can be canceled by the handler itself\n return await this.onSuccess($ctx.data, requestOptions);\n }\n } catch (er) {\n return this.onError(er, requestOptions);\n }\n });\n }\n\n protected async onError(er: Error, requestOptions: OnRequestOptions) {\n const {next, $ctx, metadata} = requestOptions;\n\n if ($ctx) {\n $ctx.data = er;\n }\n\n if (!next) {\n throw er;\n }\n\n // istanbul ignore next\n if (!$ctx || $ctx.isDone()) {\n $log.warn({\n name: \"HEADERS_SENT\",\n message: `An error was caught after the headers were sent to the client. The error comes from the handler: ${metadata.toString()}`,\n stack: er.stack,\n origin: er,\n request_id: $ctx?.id\n });\n\n return;\n }\n\n return next(er);\n }\n\n /**\n * Manage success scenario\n * @param data\n * @param requestOptions\n * @protected\n */\n protected async onSuccess(data: any, requestOptions: OnRequestOptions) {\n const {metadata, $ctx, next} = requestOptions;\n\n // istanbul ignore next\n if ($ctx?.isDone()) {\n return;\n }\n\n // set headers each times that an endpoint is called\n if (metadata.type === HandlerType.ENDPOINT) {\n this.setHeaders($ctx);\n }\n\n // call returned middleware\n if (isFunction(data) && !isStream(data)) {\n return this.callReturnedMiddleware(data, $ctx, next);\n }\n\n if (metadata.isFinal()) {\n return this.flush(data, $ctx);\n }\n\n return this.next(requestOptions);\n }\n\n /**\n * Call the returned middleware by the handler.\n * @param middleware\n * @param ctx\n * @param next\n * @protected\n */\n protected callReturnedMiddleware(middleware: any, ctx: PlatformContext, next: any) {\n return middleware(ctx.getRequest(), ctx.getResponse(), next);\n }\n\n /**\n * create Raw handler\n * @param metadata\n */\n protected createRawHandler(metadata: HandlerMetadata) {\n if ([HandlerType.RAW_ERR_FN, HandlerType.RAW_FN].includes(metadata.type)) {\n return metadata.handler;\n }\n\n const handler = this.compileHandler(metadata);\n\n return async (request: any, response: any, next: any) => {\n return handler({\n next,\n $ctx: request.$ctx\n });\n };\n }\n\n /**\n * Set response headers\n * @param ctx\n * @protected\n */\n protected setHeaders(ctx: PlatformContext) {\n return setResponseHeaders(ctx);\n }\n\n protected next(requestOptions: OnRequestOptions) {\n const {$ctx, next} = requestOptions;\n\n return !$ctx.response.isDone() && next && next();\n }\n\n protected getDefaultArgs(metadata: HandlerMetadata) {\n return async (scope: ArgScope<PlatformContext>) =>\n [\n metadata.hasErrorParam && scope.err,\n scope.$ctx.request.request,\n scope.$ctx.response.response,\n metadata.hasNextFunction && scope.next\n ].filter(Boolean);\n }\n}\n"]}
@@ -12,6 +12,8 @@ const useCtxHandler_1 = require("../utils/useCtxHandler");
12
12
  const PlatformAdapter_1 = require("../services/PlatformAdapter");
13
13
  const core_1 = require("@tsed/core");
14
14
  let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
15
+ acceptMimes;
16
+ adapter;
15
17
  get(provider, operationRoute, parentMiddlewares = []) {
16
18
  const { endpoint } = operationRoute;
17
19
  const { beforeMiddlewares, middlewares: mldwrs, afterMiddlewares } = endpoint;
@@ -56,7 +58,7 @@ let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
56
58
  ACCEPT_MIMES: this.hasAcceptMimes(operationRoute),
57
59
  FILE: operationRoute.has(platform_params_1.ParamTypes.FILES),
58
60
  RAW_BODY: operationRoute.has(platform_params_1.ParamTypes.RAW_BODY),
59
- BODY: operationRoute.has(platform_params_1.ParamTypes.BODY)
61
+ BODY: operationRoute.has(platform_params_1.ParamTypes.BODY) || operationRoute.method === "ALL"
60
62
  });
61
63
  }
62
64
  };
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformMiddlewaresChain.js","sourceRoot":"","sources":["../../../src/services/PlatformMiddlewaresChain.ts"],"names":[],"mappings":";;;;AAAA,iCAAsD;AACtD,2DAAiD;AACjD,yCAAiE;AAEjE,kFAA6E;AAC7E,gGAA2F;AAC3F,sFAAiF;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,CAmEpC;AAnEY,4DAAwB","sourcesContent":["import {Constant, Inject, Injectable} from \"@tsed/di\";\nimport {ParamTypes} from \"@tsed/platform-params\";\nimport {JsonEntityStore, JsonOperationRoute} from \"@tsed/schema\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {bindEndpointMiddleware} from \"../middlewares/bindEndpointMiddleware\";\nimport {PlatformAcceptMimesMiddleware} from \"../middlewares/PlatformAcceptMimesMiddleware\";\nimport {PlatformMulterMiddleware} from \"../middlewares/PlatformMulterMiddleware\";\nimport {useCtxHandler} from \"../utils/useCtxHandler\";\nimport {PlatformAdapter} from \"../services/PlatformAdapter\";\nimport {isClass} from \"@tsed/core\";\n\n@Injectable()\nexport class PlatformMiddlewaresChain {\n @Constant(\"acceptMimes\", [])\n protected acceptMimes: string[];\n\n @Inject()\n protected adapter: PlatformAdapter;\n\n get(provider: ControllerProvider, operationRoute: JsonOperationRoute, parentMiddlewares: any[] = []) {\n const {endpoint} = operationRoute;\n const {beforeMiddlewares, middlewares: mldwrs, afterMiddlewares} = endpoint;\n\n const {\n middlewares: {useBefore, use, useAfter}\n } = provider;\n\n const allMiddlewares = [\n ...parentMiddlewares,\n ...useBefore,\n ...beforeMiddlewares,\n ...use,\n ...mldwrs,\n endpoint,\n ...afterMiddlewares,\n ...useAfter\n ];\n\n const {ACCEPT_MIMES, FILE, RAW_BODY, BODY} = this.getParamTypes(allMiddlewares, operationRoute);\n\n return [\n useCtxHandler(bindEndpointMiddleware(endpoint)),\n ACCEPT_MIMES && PlatformAcceptMimesMiddleware,\n FILE && PlatformMulterMiddleware,\n !FILE && RAW_BODY && this.adapter.bodyParser(\"raw\"),\n !FILE && !RAW_BODY && BODY && this.adapter.bodyParser(\"json\"),\n !FILE && !RAW_BODY && BODY && this.adapter.bodyParser(\"urlencoded\"),\n ...allMiddlewares\n ].filter(Boolean);\n }\n\n protected hasAcceptMimes(operationRoute: JsonOperationRoute) {\n return operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;\n }\n\n protected getParamTypes(middlewares: any[], operationRoute: JsonOperationRoute) {\n return middlewares.filter(isClass).reduce(\n (paramTypes, token) => {\n if (token !== operationRoute.endpoint) {\n const entity = JsonEntityStore.fromMethod(token, \"use\");\n\n if (entity.decoratorType === \"method\") {\n const {FILE, RAW_BODY, BODY} = entity.getParamTypes();\n paramTypes.FILE = paramTypes.FILE || FILE;\n paramTypes.RAW_BODY = paramTypes.RAW_BODY || RAW_BODY;\n paramTypes.BODY = paramTypes.BODY || BODY;\n }\n }\n\n return paramTypes;\n },\n {\n ACCEPT_MIMES: this.hasAcceptMimes(operationRoute),\n FILE: operationRoute.has(ParamTypes.FILES),\n RAW_BODY: operationRoute.has(ParamTypes.RAW_BODY),\n BODY: operationRoute.has(ParamTypes.BODY)\n }\n );\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformMiddlewaresChain.js","sourceRoot":"","sources":["../../../src/services/PlatformMiddlewaresChain.ts"],"names":[],"mappings":";;;;AAAA,iCAAsD;AACtD,2DAAiD;AACjD,yCAAiE;AAEjE,kFAA6E;AAC7E,gGAA2F;AAC3F,sFAAiF;AACjF,0DAAqD;AACrD,iEAA4D;AAC5D,qCAAmC;AAGnC,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IAEzB,WAAW,CAAW;IAGtB,OAAO,CAAkB;IAEnC,GAAG,CAAC,QAA4B,EAAE,cAAkC,EAAE,oBAA2B,EAAE;QACjG,MAAM,EAAC,QAAQ,EAAC,GAAG,cAAc,CAAC;QAClC,MAAM,EAAC,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB,EAAC,GAAG,QAAQ,CAAC;QAE5E,MAAM,EACJ,WAAW,EAAE,EAAC,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAC,EACxC,GAAG,QAAQ,CAAC;QAEb,MAAM,cAAc,GAAG;YACrB,GAAG,iBAAiB;YACpB,GAAG,SAAS;YACZ,GAAG,iBAAiB;YACpB,GAAG,GAAG;YACN,GAAG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EAAE,CAAC;oBACtD,UAAU,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,IAAI,IAAI,CAAC;oBAC1C,UAAU,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ,IAAI,QAAQ,CAAC;oBACtD,UAAU,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,IAAI,IAAI,CAAC;iBAC3C;aACF;YAED,OAAO,UAAU,CAAC;QACpB,CAAC,EACD;YACE,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC;YACjD,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC,4BAAU,CAAC,KAAK,CAAC;YAC1C,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC,4BAAU,CAAC,QAAQ,CAAC;YACjD,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC,4BAAU,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,MAAM,KAAK,KAAK;SAC7E,CACF,CAAC;IACJ,CAAC;CACF,CAAA;AAjEC;IADC,IAAA,aAAQ,EAAC,aAAa,EAAE,EAAE,CAAC;;6DACI;AAGhC;IADC,IAAA,WAAM,GAAE;sCACU,iCAAe;yDAAC;AALxB,wBAAwB;IADpC,IAAA,eAAU,GAAE;GACA,wBAAwB,CAmEpC;AAnEY,4DAAwB","sourcesContent":["import {Constant, Inject, Injectable} from \"@tsed/di\";\nimport {ParamTypes} from \"@tsed/platform-params\";\nimport {JsonEntityStore, JsonOperationRoute} from \"@tsed/schema\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {bindEndpointMiddleware} from \"../middlewares/bindEndpointMiddleware\";\nimport {PlatformAcceptMimesMiddleware} from \"../middlewares/PlatformAcceptMimesMiddleware\";\nimport {PlatformMulterMiddleware} from \"../middlewares/PlatformMulterMiddleware\";\nimport {useCtxHandler} from \"../utils/useCtxHandler\";\nimport {PlatformAdapter} from \"../services/PlatformAdapter\";\nimport {isClass} from \"@tsed/core\";\n\n@Injectable()\nexport class PlatformMiddlewaresChain {\n @Constant(\"acceptMimes\", [])\n protected acceptMimes: string[];\n\n @Inject()\n protected adapter: PlatformAdapter;\n\n get(provider: ControllerProvider, operationRoute: JsonOperationRoute, parentMiddlewares: any[] = []) {\n const {endpoint} = operationRoute;\n const {beforeMiddlewares, middlewares: mldwrs, afterMiddlewares} = endpoint;\n\n const {\n middlewares: {useBefore, use, useAfter}\n } = provider;\n\n const allMiddlewares = [\n ...parentMiddlewares,\n ...useBefore,\n ...beforeMiddlewares,\n ...use,\n ...mldwrs,\n endpoint,\n ...afterMiddlewares,\n ...useAfter\n ];\n\n const {ACCEPT_MIMES, FILE, RAW_BODY, BODY} = this.getParamTypes(allMiddlewares, operationRoute);\n\n return [\n useCtxHandler(bindEndpointMiddleware(endpoint)),\n ACCEPT_MIMES && PlatformAcceptMimesMiddleware,\n FILE && PlatformMulterMiddleware,\n !FILE && RAW_BODY && this.adapter.bodyParser(\"raw\"),\n !FILE && !RAW_BODY && BODY && this.adapter.bodyParser(\"json\"),\n !FILE && !RAW_BODY && BODY && this.adapter.bodyParser(\"urlencoded\"),\n ...allMiddlewares\n ].filter(Boolean);\n }\n\n protected hasAcceptMimes(operationRoute: JsonOperationRoute) {\n return operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;\n }\n\n protected getParamTypes(middlewares: any[], operationRoute: JsonOperationRoute) {\n return middlewares.filter(isClass).reduce(\n (paramTypes, token) => {\n if (token !== operationRoute.endpoint) {\n const entity = JsonEntityStore.fromMethod(token, \"use\");\n\n if (entity.decoratorType === \"method\") {\n const {FILE, RAW_BODY, BODY} = entity.getParamTypes();\n paramTypes.FILE = paramTypes.FILE || FILE;\n paramTypes.RAW_BODY = paramTypes.RAW_BODY || RAW_BODY;\n paramTypes.BODY = paramTypes.BODY || BODY;\n }\n }\n\n return paramTypes;\n },\n {\n ACCEPT_MIMES: this.hasAcceptMimes(operationRoute),\n FILE: operationRoute.has(ParamTypes.FILES),\n RAW_BODY: operationRoute.has(ParamTypes.RAW_BODY),\n BODY: operationRoute.has(ParamTypes.BODY) || operationRoute.method === \"ALL\"\n }\n );\n }\n}\n"]}