@tsed/common 8.0.0-alpha.5 → 8.0.0-alpha.6

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 (205) hide show
  1. package/lib/esm/services/PlatformTest.js.map +1 -1
  2. package/lib/types/builder/PlatformBuilder.d.ts +1 -1
  3. package/lib/types/config/services/PlatformConfiguration.d.ts +1 -1
  4. package/lib/types/domain/PlatformContext.d.ts +1 -1
  5. package/lib/types/interfaces/IncomingEvent.d.ts +1 -1
  6. package/lib/types/services/FakeResponse.d.ts +1 -1
  7. package/lib/types/services/PlatformAdapter.d.ts +1 -1
  8. package/lib/types/services/PlatformApplication.d.ts +1 -1
  9. package/lib/types/services/PlatformRequest.d.ts +1 -1
  10. package/lib/types/services/PlatformResponse.d.ts +2 -2
  11. package/lib/types/services/PlatformTest.d.ts +1 -1
  12. package/lib/types/utils/closeServer.d.ts +3 -3
  13. package/lib/types/utils/createHttpServer.d.ts +1 -1
  14. package/lib/types/utils/createHttpsServer.d.ts +1 -1
  15. package/lib/types/utils/createServer.d.ts +3 -3
  16. package/lib/types/utils/listenServer.d.ts +3 -3
  17. package/package.json +19 -20
  18. package/lib/cjs/builder/PlatformBuilder.js +0 -341
  19. package/lib/cjs/builder/PlatformBuilder.js.map +0 -1
  20. package/lib/cjs/config/interfaces/PlatformJsonMapperSettings.js +0 -3
  21. package/lib/cjs/config/interfaces/PlatformJsonMapperSettings.js.map +0 -1
  22. package/lib/cjs/config/interfaces/PlatformMulterSettings.js +0 -3
  23. package/lib/cjs/config/interfaces/PlatformMulterSettings.js.map +0 -1
  24. package/lib/cjs/config/interfaces/PlatformRouterSettings.js +0 -3
  25. package/lib/cjs/config/interfaces/PlatformRouterSettings.js.map +0 -1
  26. package/lib/cjs/config/interfaces/PlatformStaticsSettings.js +0 -3
  27. package/lib/cjs/config/interfaces/PlatformStaticsSettings.js.map +0 -1
  28. package/lib/cjs/config/services/PlatformConfiguration.js +0 -122
  29. package/lib/cjs/config/services/PlatformConfiguration.js.map +0 -1
  30. package/lib/cjs/constants/routerOptions.js +0 -5
  31. package/lib/cjs/constants/routerOptions.js.map +0 -1
  32. package/lib/cjs/decorators/PlatformProvider.js +0 -11
  33. package/lib/cjs/decorators/PlatformProvider.js.map +0 -1
  34. package/lib/cjs/decorators/multer/multerFileSize.js +0 -35
  35. package/lib/cjs/decorators/multer/multerFileSize.js.map +0 -1
  36. package/lib/cjs/decorators/multer/multerOptions.js +0 -52
  37. package/lib/cjs/decorators/multer/multerOptions.js.map +0 -1
  38. package/lib/cjs/decorators/multer/multipartFile.js +0 -78
  39. package/lib/cjs/decorators/multer/multipartFile.js.map +0 -1
  40. package/lib/cjs/decorators/params/error.js +0 -20
  41. package/lib/cjs/decorators/params/error.js.map +0 -1
  42. package/lib/cjs/decorators/params/next.js +0 -21
  43. package/lib/cjs/decorators/params/next.js.map +0 -1
  44. package/lib/cjs/decorators/params/request.js +0 -39
  45. package/lib/cjs/decorators/params/request.js.map +0 -1
  46. package/lib/cjs/decorators/params/response.js +0 -33
  47. package/lib/cjs/decorators/params/response.js.map +0 -1
  48. package/lib/cjs/domain/AnyToPromiseWithCtx.js +0 -25
  49. package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +0 -1
  50. package/lib/cjs/domain/EndpointMetadata.js +0 -6
  51. package/lib/cjs/domain/EndpointMetadata.js.map +0 -1
  52. package/lib/cjs/domain/PlatformContext.js +0 -73
  53. package/lib/cjs/domain/PlatformContext.js.map +0 -1
  54. package/lib/cjs/domain/PlatformRouteDetails.js +0 -3
  55. package/lib/cjs/domain/PlatformRouteDetails.js.map +0 -1
  56. package/lib/cjs/exports.js +0 -30
  57. package/lib/cjs/exports.js.map +0 -1
  58. package/lib/cjs/index.js +0 -67
  59. package/lib/cjs/index.js.map +0 -1
  60. package/lib/cjs/interfaces/AfterInit.js +0 -3
  61. package/lib/cjs/interfaces/AfterInit.js.map +0 -1
  62. package/lib/cjs/interfaces/AfterListen.js +0 -3
  63. package/lib/cjs/interfaces/AfterListen.js.map +0 -1
  64. package/lib/cjs/interfaces/AfterRoutesInit.js +0 -3
  65. package/lib/cjs/interfaces/AfterRoutesInit.js.map +0 -1
  66. package/lib/cjs/interfaces/BeforeInit.js +0 -3
  67. package/lib/cjs/interfaces/BeforeInit.js.map +0 -1
  68. package/lib/cjs/interfaces/BeforeListen.js +0 -3
  69. package/lib/cjs/interfaces/BeforeListen.js.map +0 -1
  70. package/lib/cjs/interfaces/BeforeRoutesInit.js +0 -3
  71. package/lib/cjs/interfaces/BeforeRoutesInit.js.map +0 -1
  72. package/lib/cjs/interfaces/HandlerType.js +0 -17
  73. package/lib/cjs/interfaces/HandlerType.js.map +0 -1
  74. package/lib/cjs/interfaces/IncomingEvent.js +0 -3
  75. package/lib/cjs/interfaces/IncomingEvent.js.map +0 -1
  76. package/lib/cjs/interfaces/OnReady.js +0 -3
  77. package/lib/cjs/interfaces/OnReady.js.map +0 -1
  78. package/lib/cjs/interfaces/OnRequest.js +0 -3
  79. package/lib/cjs/interfaces/OnRequest.js.map +0 -1
  80. package/lib/cjs/interfaces/OnResponse.js +0 -3
  81. package/lib/cjs/interfaces/OnResponse.js.map +0 -1
  82. package/lib/cjs/interfaces/OnRoutesInit.js +0 -3
  83. package/lib/cjs/interfaces/OnRoutesInit.js.map +0 -1
  84. package/lib/cjs/interfaces/PlatformRouteOptions.js +0 -3
  85. package/lib/cjs/interfaces/PlatformRouteOptions.js.map +0 -1
  86. package/lib/cjs/interfaces/ResponseErrorObject.js +0 -3
  87. package/lib/cjs/interfaces/ResponseErrorObject.js.map +0 -1
  88. package/lib/cjs/interfaces/Route.js +0 -3
  89. package/lib/cjs/interfaces/Route.js.map +0 -1
  90. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +0 -39
  91. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +0 -1
  92. package/lib/cjs/middlewares/PlatformMulterMiddleware.js +0 -70
  93. package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +0 -1
  94. package/lib/cjs/package.json +0 -3
  95. package/lib/cjs/services/FakeAdapter.js +0 -6
  96. package/lib/cjs/services/FakeAdapter.js.map +0 -1
  97. package/lib/cjs/services/FakeResponse.js +0 -59
  98. package/lib/cjs/services/FakeResponse.js.map +0 -1
  99. package/lib/cjs/services/Platform.js +0 -76
  100. package/lib/cjs/services/Platform.js.map +0 -1
  101. package/lib/cjs/services/PlatformAdapter.js +0 -82
  102. package/lib/cjs/services/PlatformAdapter.js.map +0 -1
  103. package/lib/cjs/services/PlatformApplication.js +0 -44
  104. package/lib/cjs/services/PlatformApplication.js.map +0 -1
  105. package/lib/cjs/services/PlatformHandler.js +0 -133
  106. package/lib/cjs/services/PlatformHandler.js.map +0 -1
  107. package/lib/cjs/services/PlatformMiddlewaresChain.js +0 -60
  108. package/lib/cjs/services/PlatformMiddlewaresChain.js.map +0 -1
  109. package/lib/cjs/services/PlatformRequest.js +0 -144
  110. package/lib/cjs/services/PlatformRequest.js.map +0 -1
  111. package/lib/cjs/services/PlatformResponse.js +0 -309
  112. package/lib/cjs/services/PlatformResponse.js.map +0 -1
  113. package/lib/cjs/services/PlatformTest.js +0 -142
  114. package/lib/cjs/services/PlatformTest.js.map +0 -1
  115. package/lib/cjs/utils/closeServer.js +0 -8
  116. package/lib/cjs/utils/closeServer.js.map +0 -1
  117. package/lib/cjs/utils/createContext.js +0 -49
  118. package/lib/cjs/utils/createContext.js.map +0 -1
  119. package/lib/cjs/utils/createHttpServer.js +0 -18
  120. package/lib/cjs/utils/createHttpServer.js.map +0 -1
  121. package/lib/cjs/utils/createHttpsServer.js +0 -18
  122. package/lib/cjs/utils/createHttpsServer.js.map +0 -1
  123. package/lib/cjs/utils/createInjector.js +0 -45
  124. package/lib/cjs/utils/createInjector.js.map +0 -1
  125. package/lib/cjs/utils/createServer.js +0 -33
  126. package/lib/cjs/utils/createServer.js.map +0 -1
  127. package/lib/cjs/utils/ensureContext.js +0 -16
  128. package/lib/cjs/utils/ensureContext.js.map +0 -1
  129. package/lib/cjs/utils/getConfiguration.js +0 -36
  130. package/lib/cjs/utils/getConfiguration.js.map +0 -1
  131. package/lib/cjs/utils/getStaticsOptions.js +0 -21
  132. package/lib/cjs/utils/getStaticsOptions.js.map +0 -1
  133. package/lib/cjs/utils/listenServer.js +0 -14
  134. package/lib/cjs/utils/listenServer.js.map +0 -1
  135. package/lib/cjs/utils/mapReturnedResponse.js +0 -15
  136. package/lib/cjs/utils/mapReturnedResponse.js.map +0 -1
  137. package/lib/cjs/utils/printRoutes.js +0 -38
  138. package/lib/cjs/utils/printRoutes.js.map +0 -1
  139. package/lib/cjs/utils/registerPlatformAdapter.js +0 -11
  140. package/lib/cjs/utils/registerPlatformAdapter.js.map +0 -1
  141. package/lib/cjs/utils/setResponseHeaders.js +0 -29
  142. package/lib/cjs/utils/setResponseHeaders.js.map +0 -1
  143. package/lib/esm/package.json +0 -3
  144. package/lib/types-esm/builder/PlatformBuilder.d.ts +0 -100
  145. package/lib/types-esm/config/interfaces/PlatformJsonMapperSettings.d.ts +0 -10
  146. package/lib/types-esm/config/interfaces/PlatformMulterSettings.d.ts +0 -14
  147. package/lib/types-esm/config/interfaces/PlatformRouterSettings.d.ts +0 -10
  148. package/lib/types-esm/config/interfaces/PlatformStaticsSettings.d.ts +0 -17
  149. package/lib/types-esm/config/services/PlatformConfiguration.d.ts +0 -67
  150. package/lib/types-esm/constants/routerOptions.d.ts +0 -1
  151. package/lib/types-esm/decorators/PlatformProvider.d.ts +0 -3
  152. package/lib/types-esm/decorators/multer/multerFileSize.d.ts +0 -27
  153. package/lib/types-esm/decorators/multer/multerOptions.d.ts +0 -41
  154. package/lib/types-esm/decorators/multer/multipartFile.d.ts +0 -47
  155. package/lib/types-esm/decorators/params/error.d.ts +0 -7
  156. package/lib/types-esm/decorators/params/next.d.ts +0 -22
  157. package/lib/types-esm/decorators/params/request.d.ts +0 -46
  158. package/lib/types-esm/decorators/params/response.d.ts +0 -40
  159. package/lib/types-esm/domain/AnyToPromiseWithCtx.d.ts +0 -10
  160. package/lib/types-esm/domain/EndpointMetadata.d.ts +0 -1
  161. package/lib/types-esm/domain/PlatformContext.d.ts +0 -80
  162. package/lib/types-esm/domain/PlatformRouteDetails.d.ts +0 -7
  163. package/lib/types-esm/exports.d.ts +0 -11
  164. package/lib/types-esm/index.d.ts +0 -63
  165. package/lib/types-esm/interfaces/AfterInit.d.ts +0 -3
  166. package/lib/types-esm/interfaces/AfterListen.d.ts +0 -3
  167. package/lib/types-esm/interfaces/AfterRoutesInit.d.ts +0 -3
  168. package/lib/types-esm/interfaces/BeforeInit.d.ts +0 -3
  169. package/lib/types-esm/interfaces/BeforeListen.d.ts +0 -3
  170. package/lib/types-esm/interfaces/BeforeRoutesInit.d.ts +0 -3
  171. package/lib/types-esm/interfaces/HandlerType.d.ts +0 -12
  172. package/lib/types-esm/interfaces/IncomingEvent.d.ts +0 -6
  173. package/lib/types-esm/interfaces/OnReady.d.ts +0 -3
  174. package/lib/types-esm/interfaces/OnRequest.d.ts +0 -4
  175. package/lib/types-esm/interfaces/OnResponse.d.ts +0 -4
  176. package/lib/types-esm/interfaces/OnRoutesInit.d.ts +0 -3
  177. package/lib/types-esm/interfaces/PlatformRouteOptions.d.ts +0 -15
  178. package/lib/types-esm/interfaces/ResponseErrorObject.d.ts +0 -8
  179. package/lib/types-esm/interfaces/Route.d.ts +0 -10
  180. package/lib/types-esm/middlewares/PlatformAcceptMimesMiddleware.d.ts +0 -10
  181. package/lib/types-esm/middlewares/PlatformMulterMiddleware.d.ts +0 -24
  182. package/lib/types-esm/services/FakeAdapter.d.ts +0 -1
  183. package/lib/types-esm/services/FakeResponse.d.ts +0 -22
  184. package/lib/types-esm/services/Platform.d.ts +0 -25
  185. package/lib/types-esm/services/PlatformAdapter.d.ts +0 -89
  186. package/lib/types-esm/services/PlatformApplication.d.ts +0 -29
  187. package/lib/types-esm/services/PlatformHandler.d.ts +0 -39
  188. package/lib/types-esm/services/PlatformMiddlewaresChain.d.ts +0 -17
  189. package/lib/types-esm/services/PlatformRequest.d.ts +0 -111
  190. package/lib/types-esm/services/PlatformResponse.d.ts +0 -174
  191. package/lib/types-esm/services/PlatformTest.d.ts +0 -60
  192. package/lib/types-esm/utils/closeServer.d.ts +0 -7
  193. package/lib/types-esm/utils/createContext.d.ts +0 -10
  194. package/lib/types-esm/utils/createHttpServer.d.ts +0 -4
  195. package/lib/types-esm/utils/createHttpsServer.d.ts +0 -4
  196. package/lib/types-esm/utils/createInjector.d.ts +0 -9
  197. package/lib/types-esm/utils/createServer.d.ts +0 -17
  198. package/lib/types-esm/utils/ensureContext.d.ts +0 -2
  199. package/lib/types-esm/utils/getConfiguration.d.ts +0 -2
  200. package/lib/types-esm/utils/getStaticsOptions.d.ts +0 -5
  201. package/lib/types-esm/utils/listenServer.d.ts +0 -8
  202. package/lib/types-esm/utils/mapReturnedResponse.d.ts +0 -4
  203. package/lib/types-esm/utils/printRoutes.d.ts +0 -2
  204. package/lib/types-esm/utils/registerPlatformAdapter.d.ts +0 -3
  205. package/lib/types-esm/utils/setResponseHeaders.d.ts +0 -5
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformApplication.ts"],"names":[],"mappings":";;;;AAAA,iCAAoE;AACpE,2DAAqD;AAGrD,6DAAqD;AASrD;;;;GAIG;AAKI,IAAM,mBAAmB,GAAzB,MAAM,mBAA4C,SAAQ,gCAAc;IAI7E,YACS,OAA6B,EAC7B,QAAyB;QAEhC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAHT,YAAO,GAAP,OAAO,CAAsB;QAC7B,aAAQ,GAAR,QAAQ,CAAiB;QAGhC,MAAM,EAAC,GAAG,EAAE,QAAQ,EAAC,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;QAE5C,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;QAClB,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,OAA+B;QACpC,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAID,QAAQ,CAAC,GAAqB,EAAE,GAAoB;QAClD,IAAI,GAAG,IAAI,GAAG,EAAE;YACd,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;SAClC;QAED,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;CACF,CAAA;AAhCY,mBAAmB;IAJ/B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,KAAK,EAAE,qBAAqB;KAC7B,CAAC;6CAMkB,oCAAe;QACd,oBAAe;GANvB,mBAAmB,CAgC/B;AAhCY,kDAAmB"}
@@ -1,133 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformHandler = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@tsed/core");
6
- const di_1 = require("@tsed/di");
7
- const platform_exceptions_1 = require("@tsed/platform-exceptions");
8
- const platform_params_1 = require("@tsed/platform-params");
9
- const platform_response_filter_1 = require("@tsed/platform-response-filter");
10
- const platform_router_1 = require("@tsed/platform-router");
11
- const AnyToPromiseWithCtx_js_1 = require("../domain/AnyToPromiseWithCtx.js");
12
- const setResponseHeaders_js_1 = require("../utils/setResponseHeaders.js");
13
- const PlatformApplication_js_1 = require("./PlatformApplication.js");
14
- const PlatformMiddlewaresChain_js_1 = require("./PlatformMiddlewaresChain.js");
15
- /**
16
- * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).
17
- * @platform
18
- */
19
- let PlatformHandler = class PlatformHandler {
20
- constructor(platformRouters) {
21
- this.platformRouters = platformRouters;
22
- // configure the router module
23
- platformRouters.hooks
24
- .on("alterEndpointHandlers", (handlers, operationRoute) => {
25
- handlers = this.platformMiddlewaresChain.get(handlers, operationRoute);
26
- handlers.after.push((0, platform_router_1.useResponseHandler)(this.flush.bind(this)));
27
- return handlers;
28
- })
29
- .on("alterHandler", (handlerMetadata) => {
30
- const handler = handlerMetadata.isInjectable() ? this.createHandler(handlerMetadata) : handlerMetadata.handler;
31
- return this.platformApplication.adapter.mapHandler(handler, handlerMetadata);
32
- });
33
- }
34
- createHandler(handlerMetadata) {
35
- const handler = this.platformParams.compileHandler(handlerMetadata);
36
- return ($ctx) => {
37
- $ctx.handlerMetadata = handlerMetadata;
38
- return this.onRequest(handler, $ctx);
39
- };
40
- }
41
- /**
42
- * @param provider
43
- * @param propertyKey
44
- */
45
- createCustomHandler(provider, propertyKey) {
46
- const metadata = new platform_router_1.PlatformHandlerMetadata({
47
- provider,
48
- type: platform_router_1.PlatformHandlerType.CUSTOM,
49
- propertyKey
50
- });
51
- return this.createHandler(metadata);
52
- }
53
- /**
54
- * Call handler when a request his handle
55
- */
56
- async onRequest(handler, $ctx) {
57
- const { handlerMetadata } = $ctx;
58
- if (handlerMetadata.type === platform_router_1.PlatformHandlerType.CTX_FN) {
59
- return handler({ $ctx });
60
- }
61
- const resolver = new AnyToPromiseWithCtx_js_1.AnyToPromiseWithCtx($ctx);
62
- const response = await resolver.call(handler);
63
- // Note: restore previous handler metadata (for OIDC)
64
- $ctx.handlerMetadata = handlerMetadata;
65
- if (response.state === core_1.AnyToPromiseStatus.RESOLVED && !$ctx.isDone()) {
66
- return this.onResponse(response, $ctx);
67
- }
68
- }
69
- onResponse({ status, data, headers }, $ctx) {
70
- if (status) {
71
- $ctx.response.status(status);
72
- }
73
- if (headers) {
74
- $ctx.response.setHeaders(headers);
75
- }
76
- if (data !== undefined) {
77
- $ctx.data = data;
78
- }
79
- $ctx.error = null;
80
- // set headers each times that an endpoint is called
81
- if ($ctx.handlerMetadata.isEndpoint()) {
82
- (0, setResponseHeaders_js_1.setResponseHeaders)($ctx);
83
- }
84
- }
85
- /**
86
- * Send the response to the consumer.
87
- * @protected
88
- * @param $ctx
89
- */
90
- async flush($ctx) {
91
- if (!$ctx.error) {
92
- $ctx.error = await (0, core_1.catchAsyncError)(async () => {
93
- const { response } = $ctx;
94
- if (!$ctx.isDone()) {
95
- let data = await this.responseFilter.serialize($ctx.data, $ctx);
96
- data = await this.responseFilter.transform(data, $ctx);
97
- response.body(data);
98
- }
99
- });
100
- }
101
- if ($ctx.error) {
102
- this.platformExceptions.catch($ctx.error, $ctx);
103
- }
104
- }
105
- };
106
- tslib_1.__decorate([
107
- (0, di_1.Inject)(),
108
- tslib_1.__metadata("design:type", platform_response_filter_1.PlatformResponseFilter)
109
- ], PlatformHandler.prototype, "responseFilter", void 0);
110
- tslib_1.__decorate([
111
- (0, di_1.Inject)(),
112
- tslib_1.__metadata("design:type", platform_params_1.PlatformParams)
113
- ], PlatformHandler.prototype, "platformParams", void 0);
114
- tslib_1.__decorate([
115
- (0, di_1.Inject)(),
116
- tslib_1.__metadata("design:type", platform_exceptions_1.PlatformExceptions)
117
- ], PlatformHandler.prototype, "platformExceptions", void 0);
118
- tslib_1.__decorate([
119
- (0, di_1.Inject)(),
120
- tslib_1.__metadata("design:type", PlatformApplication_js_1.PlatformApplication)
121
- ], PlatformHandler.prototype, "platformApplication", void 0);
122
- tslib_1.__decorate([
123
- (0, di_1.Inject)(),
124
- tslib_1.__metadata("design:type", PlatformMiddlewaresChain_js_1.PlatformMiddlewaresChain)
125
- ], PlatformHandler.prototype, "platformMiddlewaresChain", void 0);
126
- PlatformHandler = tslib_1.__decorate([
127
- (0, di_1.Injectable)({
128
- scope: di_1.ProviderScope.SINGLETON
129
- }),
130
- tslib_1.__metadata("design:paramtypes", [platform_router_1.PlatformRouters])
131
- ], PlatformHandler);
132
- exports.PlatformHandler = PlatformHandler;
133
- //# sourceMappingURL=PlatformHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformHandler.ts"],"names":[],"m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iCAAe;GAhB3C,eAAe,CAyH3B;AAzHY,0CAAe"}
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformMiddlewaresChain = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@tsed/core");
6
- const di_1 = require("@tsed/di");
7
- const platform_params_1 = require("@tsed/platform-params");
8
- const schema_1 = require("@tsed/schema");
9
- const PlatformAcceptMimesMiddleware_js_1 = require("../middlewares/PlatformAcceptMimesMiddleware.js");
10
- const PlatformMulterMiddleware_js_1 = require("../middlewares/PlatformMulterMiddleware.js");
11
- const PlatformAdapter_js_1 = require("../services/PlatformAdapter.js");
12
- let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
13
- get(handlers, operationRoute) {
14
- const { ACCEPT_MIMES, FILE } = this.getParamTypes(handlers, operationRoute);
15
- return {
16
- ...handlers,
17
- before: [ACCEPT_MIMES && PlatformAcceptMimesMiddleware_js_1.PlatformAcceptMimesMiddleware, ...handlers.before, FILE && PlatformMulterMiddleware_js_1.PlatformMulterMiddleware].filter(Boolean)
18
- };
19
- }
20
- hasAcceptMimes(operationRoute) {
21
- return operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;
22
- }
23
- getParamTypes(middlewares, operationRoute) {
24
- return middlewares.before
25
- .concat(middlewares.after)
26
- .filter(core_1.isClass)
27
- .reduce((paramTypes, token) => {
28
- const entity = schema_1.JsonEntityStore.fromMethod(token, "use");
29
- if (entity.decoratorType === "method") {
30
- const { FILE, RAW_BODY, BODY } = entity.getParamTypes();
31
- paramTypes.FILE = paramTypes.FILE || FILE;
32
- paramTypes.RAW_BODY = paramTypes.RAW_BODY || RAW_BODY;
33
- paramTypes.BODY = paramTypes.BODY || BODY;
34
- }
35
- return paramTypes;
36
- }, {
37
- ACCEPT_MIMES: this.hasAcceptMimes(operationRoute),
38
- FILE: operationRoute.has(platform_params_1.ParamTypes.FILES),
39
- RAW_BODY: operationRoute.has(platform_params_1.ParamTypes.RAW_BODY),
40
- BODY: operationRoute.has(platform_params_1.ParamTypes.BODY) || operationRoute.method === "ALL"
41
- });
42
- }
43
- };
44
- tslib_1.__decorate([
45
- (0, di_1.Constant)("acceptMimes", []),
46
- tslib_1.__metadata("design:type", Array)
47
- ], PlatformMiddlewaresChain.prototype, "acceptMimes", void 0);
48
- tslib_1.__decorate([
49
- (0, di_1.Inject)(PlatformAdapter_js_1.PlatformAdapter),
50
- tslib_1.__metadata("design:type", PlatformAdapter_js_1.PlatformAdapter)
51
- ], PlatformMiddlewaresChain.prototype, "adapter", void 0);
52
- tslib_1.__decorate([
53
- (0, di_1.Inject)(di_1.InjectorService),
54
- tslib_1.__metadata("design:type", di_1.InjectorService)
55
- ], PlatformMiddlewaresChain.prototype, "injector", void 0);
56
- PlatformMiddlewaresChain = tslib_1.__decorate([
57
- (0, di_1.Injectable)()
58
- ], PlatformMiddlewaresChain);
59
- exports.PlatformMiddlewaresChain = PlatformMiddlewaresChain;
60
- //# sourceMappingURL=PlatformMiddlewaresChain.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformMiddlewaresChain.js","sourceRoot":"","sources":["../../../src/services/PlatformMiddlewaresChain.ts"],"names":[],"mappings":";;;;AAAA,qCAAmC;AACnC,iCAAsF;AACtF,2DAAiD;AAEjD,yCAAiE;AACjE,sGAA8F;AAC9F,4FAAoF;AACpF,uEAA+D;AAGxD,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAUnC,GAAG,CAAC,QAAkC,EAAE,cAAkC;QACxE,MAAM,EAAC,YAAY,EAAE,IAAI,EAAC,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAE1E,OAAO;YACL,GAAG,QAAQ;YACX,MAAM,EAAE,CAAC,YAAY,IAAI,gEAA6B,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,IAAI,IAAI,sDAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAU;SACvI,CAAC;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WAAM,EAAC,oCAAe,CAAC;sCACL,oCAAe;yDAAC;AAEnC;IAAC,IAAA,WAAM,EAAC,oBAAe,CAAC;sCACJ,oBAAe;0DAAC;AARzB,wBAAwB;IADpC,IAAA,eAAU,GAAE;GACA,wBAAwB,CAgDpC;AAhDY,4DAAwB"}
@@ -1,144 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformRequest = void 0;
4
- const tslib_1 = require("tslib");
5
- const di_1 = require("@tsed/di");
6
- /**
7
- * Platform Request abstraction layer.
8
- * @platform
9
- */
10
- let PlatformRequest = class PlatformRequest {
11
- constructor($ctx) {
12
- this.$ctx = $ctx;
13
- }
14
- /**
15
- * The current @@PlatformResponse@@.
16
- */
17
- get response() {
18
- return this.$ctx.response;
19
- }
20
- get raw() {
21
- return this.$ctx.event.request;
22
- }
23
- get secure() {
24
- return this.raw.secure;
25
- }
26
- get host() {
27
- return this.get("host");
28
- }
29
- get protocol() {
30
- return this.raw.protocol;
31
- }
32
- /**
33
- * Get the url of the request.
34
- *
35
- * Is equivalent of `express.response.originalUrl || express.response.url`.
36
- */
37
- get url() {
38
- return this.raw.originalUrl || this.raw.url;
39
- }
40
- get headers() {
41
- return this.raw.headers;
42
- }
43
- get method() {
44
- return this.raw.method;
45
- }
46
- /**
47
- * Contains key-value pairs of data submitted in the request body. By default, it is `undefined`, and is populated when you use
48
- * `body-parsing` middleware such as `express.json()` or `express.urlencoded()`.
49
- */
50
- get body() {
51
- return this.raw.body;
52
- }
53
- get rawBody() {
54
- return this.raw.rawBody || this.raw.body;
55
- }
56
- /**
57
- * When using `cookie-parser` middleware, this property is an object that contains cookies sent by the request.
58
- * If the request contains no cookies, it defaults to `{}`.
59
- */
60
- get cookies() {
61
- return this.raw.cookies;
62
- }
63
- /**
64
- * This property is an object containing properties mapped to the named route `parameters`.
65
- * For example, if you have the route `/user/:name`, then the `name` property is available as `req.params.name`.
66
- * This object defaults to `{}`.
67
- */
68
- get params() {
69
- return this.raw.params;
70
- }
71
- /**
72
- * This property is an object containing a property for each query string parameter in the route.
73
- * When query parser is set to disabled, it is an empty object `{}`, otherwise it is the result of the configured query parser.
74
- */
75
- get query() {
76
- return this.raw.query;
77
- }
78
- /**
79
- * This property is an object containing a property for each session attributes set by any code.
80
- * It requires to install a middleware like express-session to work.
81
- */
82
- get session() {
83
- return this.raw.session;
84
- }
85
- get files() {
86
- return this.raw.files;
87
- }
88
- get route() {
89
- return this.$ctx.handlerMetadata?.path;
90
- }
91
- /**
92
- * Return the original request framework instance
93
- */
94
- get request() {
95
- return this.getRequest();
96
- }
97
- /**
98
- * Return the original request node.js instance
99
- */
100
- get req() {
101
- return this.getReq();
102
- }
103
- /**
104
- * Returns the HTTP request header specified by field. The match is case-insensitive.
105
- *
106
- * ```typescript
107
- * request.get('Content-Type') // => "text/plain"
108
- * ```
109
- *
110
- * @param name
111
- */
112
- get(name) {
113
- return this.raw.get(name);
114
- }
115
- getHeader(name) {
116
- return this.get(name);
117
- }
118
- accepts(mime) {
119
- // @ts-ignore
120
- return this.raw.accepts(mime);
121
- }
122
- isAborted() {
123
- return this.raw.aborted;
124
- }
125
- /**
126
- * Return the Framework response object (express, koa, etc...)
127
- */
128
- getRequest() {
129
- return this.raw;
130
- }
131
- /**
132
- * Return the Node.js response object
133
- */
134
- getReq() {
135
- return this.$ctx.event.request;
136
- }
137
- };
138
- PlatformRequest = tslib_1.__decorate([
139
- (0, di_1.Injectable)(),
140
- (0, di_1.Scope)(di_1.ProviderScope.INSTANCE),
141
- tslib_1.__metadata("design:paramtypes", [Function])
142
- ], PlatformRequest);
143
- exports.PlatformRequest = PlatformRequest;
144
- //# sourceMappingURL=PlatformRequest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformRequest.ts"],"names":[],"mappings":";;;;AAAA,iCAA0D;AAc1D;;;GAGG;AAGI,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,YA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;;;OAGG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,OAAc,CAAC;IACjC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;IACxB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,SAAS,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAaD,OAAO,CAAC,IAAwB;QAC9B,aAAa;QACb,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,GAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IACjC,CAAC;CACF,CAAA;AAhKY,eAAe;IAF3B,IAAA,eAAU,GAAE;IACZ,IAAA,UAAK,EAAC,kBAAa,CAAC,QAAQ,CAAC;;GACjB,eAAe,CAgK3B;AAhKY,0CAAe"}
@@ -1,309 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformResponse = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@tsed/core");
6
- const di_1 = require("@tsed/di");
7
- const schema_1 = require("@tsed/schema");
8
- const encodeurl_1 = tslib_1.__importDefault(require("encodeurl"));
9
- /**
10
- * Platform Response abstraction layer.
11
- * @platform
12
- */
13
- let PlatformResponse = class PlatformResponse {
14
- constructor($ctx) {
15
- this.$ctx = $ctx;
16
- }
17
- /**
18
- * The current @@PlatformRequest@@.
19
- */
20
- get request() {
21
- return this.$ctx.request;
22
- }
23
- get raw() {
24
- return this.$ctx.event.response;
25
- }
26
- /**
27
- * Get the current statusCode
28
- */
29
- get statusCode() {
30
- return this.raw.statusCode;
31
- }
32
- /**
33
- * An object that contains response local variables scoped to the request, and therefore available only to the view(s) rendered during that request / response cycle (if any). Otherwise, this property is identical to app.locals.
34
- *
35
- * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.
36
- */
37
- get locals() {
38
- return this.raw.locals;
39
- }
40
- /**
41
- * Return the original response framework instance
42
- */
43
- get response() {
44
- return this.getResponse();
45
- }
46
- /**
47
- * Return the original response node.js instance
48
- */
49
- get res() {
50
- return this.getRes();
51
- }
52
- /**
53
- * Returns the HTTP response header specified by field. The match is case-insensitive.
54
- *
55
- * ```typescript
56
- * response.get('Content-Type') // => "text/plain"
57
- * ```
58
- *
59
- * @param name
60
- */
61
- get(name) {
62
- return this.raw.get(name);
63
- }
64
- getHeaders() {
65
- return this.raw.getHeaders();
66
- }
67
- /**
68
- * Return the Framework response object (express, koa, etc...)
69
- */
70
- getResponse() {
71
- return this.raw;
72
- }
73
- /**
74
- * Return the Node.js response object
75
- */
76
- getRes() {
77
- return this.raw;
78
- }
79
- hasStatus() {
80
- return this.statusCode !== 200;
81
- }
82
- /**
83
- * Sets the HTTP status for the response.
84
- *
85
- * @param status
86
- */
87
- status(status) {
88
- this.raw.status(status);
89
- return this;
90
- }
91
- /**
92
- * Set header `field` to `val`, or pass
93
- * an object of header fields.
94
- *
95
- * Examples:
96
- * ```typescript
97
- * response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
98
- * ```
99
- *
100
- * Aliased as `res.header()`.
101
- */
102
- setHeaders(headers) {
103
- // apply headers
104
- Object.entries(headers).forEach(([key, item]) => {
105
- this.setHeader(key, item);
106
- });
107
- return this;
108
- }
109
- setHeader(key, item) {
110
- this.raw.set(key, this.formatHeader(key, item));
111
- return this;
112
- }
113
- /**
114
- * Set `Content-Type` response header with `type` through `mime.lookup()`
115
- * when it does not contain "/", or set the Content-Type to `type` otherwise.
116
- *
117
- * Examples:
118
- *
119
- * res.type('.html');
120
- * res.type('html');
121
- * res.type('json');
122
- * res.type('application/json');
123
- * res.type('png');
124
- */
125
- contentType(contentType) {
126
- this.raw.contentType(contentType);
127
- return this;
128
- }
129
- contentLength(length) {
130
- this.setHeader("Content-Length", length);
131
- return this;
132
- }
133
- getContentLength() {
134
- if (this.get("Content-Length")) {
135
- return parseInt(this.get("Content-Length"), 10) || 0;
136
- }
137
- }
138
- getContentType() {
139
- return (this.get("Content-Type") || "").split(";")[0];
140
- }
141
- /**
142
- * Sets the HTTP response Content-Disposition header field to “attachment”.
143
- * If a filename is given, then it sets the Content-Type based on the extension name via res.type(), and sets the Content-Disposition “filename=” parameter.
144
- *
145
- * ```typescript
146
- * res.attachment()
147
- * // Content-Disposition: attachment
148
- *
149
- * res.attachment('path/to/logo.png')
150
- * // Content-Disposition: attachment; filename="logo.png"
151
- * // Content-Type: image/png
152
- * ```
153
- *
154
- * @param filename
155
- */
156
- attachment(filename) {
157
- this.raw.attachment(filename);
158
- return this;
159
- }
160
- /**
161
- * Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an [HTTP status code](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).
162
- * If not specified, status defaults to `302 Found`.
163
- *
164
- * @param status
165
- * @param url
166
- */
167
- redirect(status, url) {
168
- status = status || 302;
169
- this.location(url);
170
- // Set location header
171
- url = this.get("Location");
172
- const txt = `${(0, schema_1.getStatusMessage)(status)}. Redirecting to ${url}`;
173
- this.status(status);
174
- if (this.request.method === "HEAD") {
175
- this.end();
176
- }
177
- else {
178
- this.setHeader("Content-Length", Buffer.byteLength(txt)).end(txt);
179
- }
180
- return this;
181
- }
182
- /**
183
- * Sets the response Location HTTP header to the specified path parameter.
184
- *
185
- * @param location
186
- */
187
- location(location) {
188
- this.setHeader("Location", location);
189
- return this;
190
- }
191
- /**
192
- * Stream the given data.
193
- *
194
- * @param data
195
- */
196
- stream(data) {
197
- data.pipe(this.raw);
198
- return this;
199
- }
200
- /**
201
- * Renders a view and sends the rendered HTML string to the client.
202
- *
203
- * @param path
204
- * @param options
205
- */
206
- async render(path, options = {}) {
207
- const { PlatformViews } = await Promise.resolve().then(() => tslib_1.__importStar(require("@tsed/platform-views")));
208
- const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);
209
- return platformViews.render(path, {
210
- ...this.locals,
211
- ...options
212
- });
213
- }
214
- /**
215
- * Send any data to your consumer.
216
- *
217
- * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
218
- * It chooses the better way to send the data.
219
- *
220
- * @param data
221
- */
222
- body(data) {
223
- this.data = data;
224
- if (data === undefined) {
225
- this.end();
226
- return this;
227
- }
228
- if ((0, core_1.isStream)(data)) {
229
- this.stream(data);
230
- return this;
231
- }
232
- if (Buffer.isBuffer(data)) {
233
- this.buffer(data);
234
- return this;
235
- }
236
- if ((0, core_1.isBoolean)(data) || (0, core_1.isNumber)(data) || (0, core_1.isString)(data) || data === null) {
237
- this.end(data);
238
- return this;
239
- }
240
- this.json(data);
241
- return this;
242
- }
243
- getBody() {
244
- return this.data;
245
- }
246
- /**
247
- * Add a listener to handler the end of the request/response.
248
- * @param cb
249
- */
250
- onEnd(cb) {
251
- const res = this.getRes();
252
- res.on("finish", cb);
253
- return this;
254
- }
255
- isDone() {
256
- if (this.$ctx.isFinished()) {
257
- return true;
258
- }
259
- const res = this.getRes();
260
- return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);
261
- }
262
- isHeadersSent() {
263
- return this.getRes().headersSent;
264
- }
265
- cookie(name, value, opts) {
266
- if (value === null) {
267
- this.raw.clearCookie(name);
268
- return this;
269
- }
270
- this.raw.cookie(name, value, opts);
271
- const cookie = this.raw.get("set-cookie");
272
- if (!(0, core_1.isArray)(value)) {
273
- this.raw.set("set-cookie", [].concat(cookie));
274
- }
275
- return this;
276
- }
277
- formatHeader(key, item) {
278
- if (key.toLowerCase() === "location") {
279
- // "back" is an alias for the referrer
280
- if (item === "back") {
281
- item = this.request.get("Referrer") || "/";
282
- }
283
- item = (0, encodeurl_1.default)(String(item));
284
- }
285
- return item;
286
- }
287
- json(data) {
288
- this.raw.json(data);
289
- return this;
290
- }
291
- buffer(data) {
292
- if (!this.getContentType()) {
293
- this.contentType("application/octet-stream");
294
- }
295
- this.contentLength(data.length);
296
- this.end(data);
297
- }
298
- end(data) {
299
- // data = await this.$ctx.injector.alter("$onResponse", data, this.$ctx);
300
- this.raw.send(data);
301
- }
302
- };
303
- PlatformResponse = tslib_1.__decorate([
304
- (0, di_1.Injectable)(),
305
- (0, di_1.Scope)(di_1.ProviderScope.INSTANCE),
306
- tslib_1.__metadata("design:paramtypes", [Function])
307
- ], PlatformResponse);
308
- exports.PlatformResponse = PlatformResponse;
309
- //# sourceMappingURL=PlatformResponse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformResponse.ts"],"names":[],"mappings":";;;;AAAA,qCAA4E;AAC5E,iCAA0D;AAC1D,yCAA8C;AAC9C,kEAAkC;AAwBlC;;;GAGG;AAGI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAG3B,YAAqB,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;IAAG,CAAC;IAE9C;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IAC3B,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,K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