@tsed/platform-http 8.0.0-beta.10

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 (196) hide show
  1. package/.barrelsby.json +5 -0
  2. package/lib/esm/common/builder/PlatformBuilder.js +308 -0
  3. package/lib/esm/common/builder/PlatformBuilder.js.map +1 -0
  4. package/lib/esm/common/config/interfaces/PlatformJsonMapperSettings.js +2 -0
  5. package/lib/esm/common/config/interfaces/PlatformJsonMapperSettings.js.map +1 -0
  6. package/lib/esm/common/config/interfaces/PlatformMulterSettings.js +2 -0
  7. package/lib/esm/common/config/interfaces/PlatformMulterSettings.js.map +1 -0
  8. package/lib/esm/common/config/interfaces/PlatformRouterSettings.js +2 -0
  9. package/lib/esm/common/config/interfaces/PlatformRouterSettings.js.map +1 -0
  10. package/lib/esm/common/config/interfaces/PlatformStaticsSettings.js +2 -0
  11. package/lib/esm/common/config/interfaces/PlatformStaticsSettings.js.map +1 -0
  12. package/lib/esm/common/config/services/PlatformConfiguration.js +119 -0
  13. package/lib/esm/common/config/services/PlatformConfiguration.js.map +1 -0
  14. package/lib/esm/common/constants/routerOptions.js +2 -0
  15. package/lib/esm/common/constants/routerOptions.js.map +1 -0
  16. package/lib/esm/common/decorators/PlatformProvider.js +7 -0
  17. package/lib/esm/common/decorators/PlatformProvider.js.map +1 -0
  18. package/lib/esm/common/decorators/multer/multerFileSize.js +32 -0
  19. package/lib/esm/common/decorators/multer/multerFileSize.js.map +1 -0
  20. package/lib/esm/common/decorators/multer/multerOptions.js +50 -0
  21. package/lib/esm/common/decorators/multer/multerOptions.js.map +1 -0
  22. package/lib/esm/common/decorators/multer/multipartFile.js +75 -0
  23. package/lib/esm/common/decorators/multer/multipartFile.js.map +1 -0
  24. package/lib/esm/common/decorators/params/error.js +16 -0
  25. package/lib/esm/common/decorators/params/error.js.map +1 -0
  26. package/lib/esm/common/decorators/params/next.js +17 -0
  27. package/lib/esm/common/decorators/params/next.js.map +1 -0
  28. package/lib/esm/common/decorators/params/request.js +34 -0
  29. package/lib/esm/common/decorators/params/request.js.map +1 -0
  30. package/lib/esm/common/decorators/params/response.js +28 -0
  31. package/lib/esm/common/decorators/params/response.js.map +1 -0
  32. package/lib/esm/common/domain/AnyToPromiseWithCtx.js +21 -0
  33. package/lib/esm/common/domain/AnyToPromiseWithCtx.js.map +1 -0
  34. package/lib/esm/common/domain/EndpointMetadata.js +2 -0
  35. package/lib/esm/common/domain/EndpointMetadata.js.map +1 -0
  36. package/lib/esm/common/domain/PlatformContext.js +69 -0
  37. package/lib/esm/common/domain/PlatformContext.js.map +1 -0
  38. package/lib/esm/common/domain/PlatformRouteDetails.js +2 -0
  39. package/lib/esm/common/domain/PlatformRouteDetails.js.map +1 -0
  40. package/lib/esm/common/exports.js +5 -0
  41. package/lib/esm/common/exports.js.map +1 -0
  42. package/lib/esm/common/index.js +61 -0
  43. package/lib/esm/common/index.js.map +1 -0
  44. package/lib/esm/common/interfaces/AfterInit.js +2 -0
  45. package/lib/esm/common/interfaces/AfterInit.js.map +1 -0
  46. package/lib/esm/common/interfaces/AfterListen.js +2 -0
  47. package/lib/esm/common/interfaces/AfterListen.js.map +1 -0
  48. package/lib/esm/common/interfaces/AfterRoutesInit.js +2 -0
  49. package/lib/esm/common/interfaces/AfterRoutesInit.js.map +1 -0
  50. package/lib/esm/common/interfaces/BeforeInit.js +2 -0
  51. package/lib/esm/common/interfaces/BeforeInit.js.map +1 -0
  52. package/lib/esm/common/interfaces/BeforeListen.js +2 -0
  53. package/lib/esm/common/interfaces/BeforeListen.js.map +1 -0
  54. package/lib/esm/common/interfaces/BeforeRoutesInit.js +2 -0
  55. package/lib/esm/common/interfaces/BeforeRoutesInit.js.map +1 -0
  56. package/lib/esm/common/interfaces/HandlerType.js +14 -0
  57. package/lib/esm/common/interfaces/HandlerType.js.map +1 -0
  58. package/lib/esm/common/interfaces/IncomingEvent.js +2 -0
  59. package/lib/esm/common/interfaces/IncomingEvent.js.map +1 -0
  60. package/lib/esm/common/interfaces/OnReady.js +2 -0
  61. package/lib/esm/common/interfaces/OnReady.js.map +1 -0
  62. package/lib/esm/common/interfaces/OnRequest.js +2 -0
  63. package/lib/esm/common/interfaces/OnRequest.js.map +1 -0
  64. package/lib/esm/common/interfaces/OnResponse.js +2 -0
  65. package/lib/esm/common/interfaces/OnResponse.js.map +1 -0
  66. package/lib/esm/common/interfaces/OnRoutesInit.js +2 -0
  67. package/lib/esm/common/interfaces/OnRoutesInit.js.map +1 -0
  68. package/lib/esm/common/interfaces/PlatformRouteOptions.js +2 -0
  69. package/lib/esm/common/interfaces/PlatformRouteOptions.js.map +1 -0
  70. package/lib/esm/common/interfaces/ResponseErrorObject.js +2 -0
  71. package/lib/esm/common/interfaces/ResponseErrorObject.js.map +1 -0
  72. package/lib/esm/common/interfaces/Route.js +2 -0
  73. package/lib/esm/common/interfaces/Route.js.map +1 -0
  74. package/lib/esm/common/middlewares/PlatformAcceptMimesMiddleware.js +36 -0
  75. package/lib/esm/common/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
  76. package/lib/esm/common/middlewares/PlatformMulterMiddleware.js +66 -0
  77. package/lib/esm/common/middlewares/PlatformMulterMiddleware.js.map +1 -0
  78. package/lib/esm/common/services/Platform.js +73 -0
  79. package/lib/esm/common/services/Platform.js.map +1 -0
  80. package/lib/esm/common/services/PlatformAdapter.js +77 -0
  81. package/lib/esm/common/services/PlatformAdapter.js.map +1 -0
  82. package/lib/esm/common/services/PlatformApplication.js +41 -0
  83. package/lib/esm/common/services/PlatformApplication.js.map +1 -0
  84. package/lib/esm/common/services/PlatformHandler.js +130 -0
  85. package/lib/esm/common/services/PlatformHandler.js.map +1 -0
  86. package/lib/esm/common/services/PlatformMiddlewaresChain.js +57 -0
  87. package/lib/esm/common/services/PlatformMiddlewaresChain.js.map +1 -0
  88. package/lib/esm/common/services/PlatformRequest.js +141 -0
  89. package/lib/esm/common/services/PlatformRequest.js.map +1 -0
  90. package/lib/esm/common/services/PlatformResponse.js +306 -0
  91. package/lib/esm/common/services/PlatformResponse.js.map +1 -0
  92. package/lib/esm/common/utils/closeServer.js +4 -0
  93. package/lib/esm/common/utils/closeServer.js.map +1 -0
  94. package/lib/esm/common/utils/createContext.js +44 -0
  95. package/lib/esm/common/utils/createContext.js.map +1 -0
  96. package/lib/esm/common/utils/createHttpServer.js +13 -0
  97. package/lib/esm/common/utils/createHttpServer.js.map +1 -0
  98. package/lib/esm/common/utils/createHttpsServer.js +13 -0
  99. package/lib/esm/common/utils/createHttpsServer.js.map +1 -0
  100. package/lib/esm/common/utils/createInjector.js +41 -0
  101. package/lib/esm/common/utils/createInjector.js.map +1 -0
  102. package/lib/esm/common/utils/createServer.js +29 -0
  103. package/lib/esm/common/utils/createServer.js.map +1 -0
  104. package/lib/esm/common/utils/ensureContext.js +12 -0
  105. package/lib/esm/common/utils/ensureContext.js.map +1 -0
  106. package/lib/esm/common/utils/getConfiguration.js +32 -0
  107. package/lib/esm/common/utils/getConfiguration.js.map +1 -0
  108. package/lib/esm/common/utils/getStaticsOptions.js +17 -0
  109. package/lib/esm/common/utils/getStaticsOptions.js.map +1 -0
  110. package/lib/esm/common/utils/listenServer.js +10 -0
  111. package/lib/esm/common/utils/listenServer.js.map +1 -0
  112. package/lib/esm/common/utils/mapReturnedResponse.js +11 -0
  113. package/lib/esm/common/utils/mapReturnedResponse.js.map +1 -0
  114. package/lib/esm/common/utils/printRoutes.js +34 -0
  115. package/lib/esm/common/utils/printRoutes.js.map +1 -0
  116. package/lib/esm/common/utils/registerPlatformAdapter.js +7 -0
  117. package/lib/esm/common/utils/registerPlatformAdapter.js.map +1 -0
  118. package/lib/esm/common/utils/setResponseHeaders.js +25 -0
  119. package/lib/esm/common/utils/setResponseHeaders.js.map +1 -0
  120. package/lib/esm/index.js +3 -0
  121. package/lib/esm/index.js.map +1 -0
  122. package/lib/esm/testing/FakeAdapter.js +2 -0
  123. package/lib/esm/testing/FakeAdapter.js.map +1 -0
  124. package/lib/esm/testing/FakeResponse.js +55 -0
  125. package/lib/esm/testing/FakeResponse.js.map +1 -0
  126. package/lib/esm/testing/PlatformTest.js +131 -0
  127. package/lib/esm/testing/PlatformTest.js.map +1 -0
  128. package/lib/esm/testing/index.js +6 -0
  129. package/lib/esm/testing/index.js.map +1 -0
  130. package/lib/types/common/builder/PlatformBuilder.d.ts +100 -0
  131. package/lib/types/common/config/interfaces/PlatformJsonMapperSettings.d.ts +10 -0
  132. package/lib/types/common/config/interfaces/PlatformMulterSettings.d.ts +14 -0
  133. package/lib/types/common/config/interfaces/PlatformRouterSettings.d.ts +10 -0
  134. package/lib/types/common/config/interfaces/PlatformStaticsSettings.d.ts +17 -0
  135. package/lib/types/common/config/services/PlatformConfiguration.d.ts +78 -0
  136. package/lib/types/common/constants/routerOptions.d.ts +1 -0
  137. package/lib/types/common/decorators/PlatformProvider.d.ts +3 -0
  138. package/lib/types/common/decorators/multer/multerFileSize.d.ts +28 -0
  139. package/lib/types/common/decorators/multer/multerOptions.d.ts +43 -0
  140. package/lib/types/common/decorators/multer/multipartFile.d.ts +48 -0
  141. package/lib/types/common/decorators/params/error.d.ts +7 -0
  142. package/lib/types/common/decorators/params/next.d.ts +22 -0
  143. package/lib/types/common/decorators/params/request.d.ts +46 -0
  144. package/lib/types/common/decorators/params/response.d.ts +40 -0
  145. package/lib/types/common/domain/AnyToPromiseWithCtx.d.ts +10 -0
  146. package/lib/types/common/domain/EndpointMetadata.d.ts +1 -0
  147. package/lib/types/common/domain/PlatformContext.d.ts +80 -0
  148. package/lib/types/common/domain/PlatformRouteDetails.d.ts +7 -0
  149. package/lib/types/common/exports.d.ts +4 -0
  150. package/lib/types/common/index.d.ts +60 -0
  151. package/lib/types/common/interfaces/AfterInit.d.ts +3 -0
  152. package/lib/types/common/interfaces/AfterListen.d.ts +3 -0
  153. package/lib/types/common/interfaces/AfterRoutesInit.d.ts +3 -0
  154. package/lib/types/common/interfaces/BeforeInit.d.ts +3 -0
  155. package/lib/types/common/interfaces/BeforeListen.d.ts +3 -0
  156. package/lib/types/common/interfaces/BeforeRoutesInit.d.ts +3 -0
  157. package/lib/types/common/interfaces/HandlerType.d.ts +12 -0
  158. package/lib/types/common/interfaces/IncomingEvent.d.ts +6 -0
  159. package/lib/types/common/interfaces/OnReady.d.ts +3 -0
  160. package/lib/types/common/interfaces/OnRequest.d.ts +4 -0
  161. package/lib/types/common/interfaces/OnResponse.d.ts +4 -0
  162. package/lib/types/common/interfaces/OnRoutesInit.d.ts +3 -0
  163. package/lib/types/common/interfaces/PlatformRouteOptions.d.ts +15 -0
  164. package/lib/types/common/interfaces/ResponseErrorObject.d.ts +8 -0
  165. package/lib/types/common/interfaces/Route.d.ts +10 -0
  166. package/lib/types/common/middlewares/PlatformAcceptMimesMiddleware.d.ts +10 -0
  167. package/lib/types/common/middlewares/PlatformMulterMiddleware.d.ts +24 -0
  168. package/lib/types/common/services/Platform.d.ts +25 -0
  169. package/lib/types/common/services/PlatformAdapter.d.ts +89 -0
  170. package/lib/types/common/services/PlatformApplication.d.ts +29 -0
  171. package/lib/types/common/services/PlatformHandler.d.ts +39 -0
  172. package/lib/types/common/services/PlatformMiddlewaresChain.d.ts +17 -0
  173. package/lib/types/common/services/PlatformRequest.d.ts +111 -0
  174. package/lib/types/common/services/PlatformResponse.d.ts +175 -0
  175. package/lib/types/common/utils/closeServer.d.ts +7 -0
  176. package/lib/types/common/utils/createContext.d.ts +10 -0
  177. package/lib/types/common/utils/createHttpServer.d.ts +4 -0
  178. package/lib/types/common/utils/createHttpsServer.d.ts +4 -0
  179. package/lib/types/common/utils/createInjector.d.ts +8 -0
  180. package/lib/types/common/utils/createServer.d.ts +17 -0
  181. package/lib/types/common/utils/ensureContext.d.ts +2 -0
  182. package/lib/types/common/utils/getConfiguration.d.ts +2 -0
  183. package/lib/types/common/utils/getStaticsOptions.d.ts +5 -0
  184. package/lib/types/common/utils/listenServer.d.ts +8 -0
  185. package/lib/types/common/utils/mapReturnedResponse.d.ts +4 -0
  186. package/lib/types/common/utils/printRoutes.d.ts +2 -0
  187. package/lib/types/common/utils/registerPlatformAdapter.d.ts +3 -0
  188. package/lib/types/common/utils/setResponseHeaders.d.ts +5 -0
  189. package/lib/types/index.d.ts +2 -0
  190. package/lib/types/testing/FakeAdapter.d.ts +1 -0
  191. package/lib/types/testing/FakeResponse.d.ts +22 -0
  192. package/lib/types/testing/PlatformTest.d.ts +61 -0
  193. package/lib/types/testing/index.d.ts +5 -0
  194. package/package.json +111 -0
  195. package/readme.md +226 -0
  196. package/vitest.config.mts +21 -0
@@ -0,0 +1,5 @@
1
+ {
2
+ "directory": ["./src/common", "./src/testing"],
3
+ "exclude": ["**/__mock__", "**/__mocks__", "**/*.spec.ts", "**/getConfiguration.ts", "FakeResponse.ts"],
4
+ "delete": true
5
+ }
@@ -0,0 +1,308 @@
1
+ import { isClass, isFunction, isString, nameOf } from "@tsed/core";
2
+ import { colors, setLoggerConfiguration } from "@tsed/di";
3
+ import { getMiddlewaresForHook } from "@tsed/platform-middlewares";
4
+ import { Platform } from "../services/Platform.js";
5
+ import { PlatformAdapter } from "../services/PlatformAdapter.js";
6
+ import { PlatformApplication } from "../services/PlatformApplication.js";
7
+ import { closeServer } from "../utils/closeServer.js";
8
+ import { createInjector } from "../utils/createInjector.js";
9
+ import { getConfiguration } from "../utils/getConfiguration.js";
10
+ import { getStaticsOptions } from "../utils/getStaticsOptions.js";
11
+ import { printRoutes } from "../utils/printRoutes.js";
12
+ /**
13
+ * @platform
14
+ */
15
+ export class PlatformBuilder {
16
+ #injector;
17
+ #rootModule;
18
+ #adapter;
19
+ #promise;
20
+ #servers;
21
+ #listeners;
22
+ constructor(adapter, module, settings) {
23
+ this.name = "";
24
+ this.startedAt = new Date();
25
+ this.current = new Date();
26
+ this.#listeners = [];
27
+ this.#rootModule = module;
28
+ const configuration = getConfiguration(settings, module);
29
+ const adapterKlass = adapter || PlatformBuilder.adapter;
30
+ configuration.PLATFORM_NAME = adapterKlass.NAME;
31
+ this.name = adapterKlass.NAME;
32
+ this.#injector = createInjector({
33
+ adapter: adapterKlass,
34
+ settings: configuration
35
+ });
36
+ this.log(`Loading ${adapterKlass.NAME.toUpperCase()} platform adapter...`);
37
+ this.#adapter = this.#injector.get(PlatformAdapter);
38
+ this.createHttpServers();
39
+ this.log("Injector created...");
40
+ }
41
+ get injector() {
42
+ return this.#injector;
43
+ }
44
+ get rootModule() {
45
+ return this.#injector.get(this.#rootModule);
46
+ }
47
+ get app() {
48
+ return this.injector.get(PlatformApplication);
49
+ }
50
+ get platform() {
51
+ return this.injector.get(Platform);
52
+ }
53
+ get adapter() {
54
+ return this.#adapter;
55
+ }
56
+ /**
57
+ * Return the settings configured by the decorator @@Configuration@@.
58
+ *
59
+ * ```typescript
60
+ * @Configuration({
61
+ * port: 8000,
62
+ * httpsPort: 8080,
63
+ * mount: {
64
+ * "/rest": "${rootDir}/controllers/**\/*.js"
65
+ * }
66
+ * })
67
+ * export class Server {
68
+ * $onInit(){
69
+ * console.log(this.settings); // {rootDir, port, httpsPort,...}
70
+ * }
71
+ * }
72
+ * ```
73
+ *
74
+ * @returns {PlatformConfiguration}
75
+ */
76
+ get settings() {
77
+ return this.injector.settings;
78
+ }
79
+ get logger() {
80
+ return this.injector.logger;
81
+ }
82
+ get disableBootstrapLog() {
83
+ return this.settings.get("logger.disableBootstrapLog");
84
+ }
85
+ static create(module, settings) {
86
+ return this.build(module, {
87
+ httpsPort: false,
88
+ httpPort: false,
89
+ ...settings
90
+ });
91
+ }
92
+ static build(module, { adapter, ...settings }) {
93
+ return new PlatformBuilder(adapter, module, settings);
94
+ }
95
+ /**
96
+ * Bootstrap a server application
97
+ * @param module
98
+ * @param settings
99
+ */
100
+ static bootstrap(module, settings) {
101
+ return this.build(module, settings).bootstrap();
102
+ }
103
+ callback(...args) {
104
+ return this.adapter.app.callback(...args);
105
+ }
106
+ log(...data) {
107
+ return !this.disableBootstrapLog && this.logger.info(...data, this.diff());
108
+ }
109
+ /**
110
+ * Add classes decorated by @@Controller@@ to components container.
111
+ *
112
+ * ### Example
113
+ *
114
+ * ```typescript
115
+ * @Controller('/ctrl')
116
+ * class MyController{
117
+ * }
118
+ *
119
+ * platform.addControllers('/rest', [MyController])
120
+ * ```
121
+ *
122
+ * ::: tip
123
+ * If the MyController class isn't decorated, the class will be ignored.
124
+ * :::
125
+ *
126
+ * @param {string} endpoint
127
+ * @param {any[]} controllers
128
+ */
129
+ addControllers(endpoint, controllers) {
130
+ [].concat(controllers).forEach((token) => {
131
+ this.settings.routes.push({ token, route: endpoint });
132
+ });
133
+ }
134
+ async runLifecycle() {
135
+ // init adapter (Express, Koa, etc...)
136
+ await this.#adapter.onInit();
137
+ setLoggerConfiguration(this.injector);
138
+ // create the middleware mapping to be executed to the expected hook
139
+ await this.mapTokenMiddlewares();
140
+ await this.loadInjector();
141
+ // add the context middleware to the application
142
+ this.log("Mount app context");
143
+ this.#adapter.useContext();
144
+ // init routes (controllers, middlewares, etc...)
145
+ this.log("Load routes");
146
+ await this.#adapter.beforeLoadRoutes();
147
+ if (this.rootModule.$beforeRoutesInit) {
148
+ await this.rootModule.$beforeRoutesInit();
149
+ // remove method to avoid multiple call and preserve hook order
150
+ this.rootModule.$beforeRoutesInit = () => { };
151
+ }
152
+ // Hooks execution (adding middlewares, controllers, services, etc...)
153
+ await this.loadStatics("$beforeRoutesInit");
154
+ await this.callHook("$beforeRoutesInit");
155
+ const routes = this.injector.settings.get("routes");
156
+ this.platform.addRoutes(routes);
157
+ await this.callHook("$onRoutesInit");
158
+ await this.loadStatics("$afterRoutesInit");
159
+ await this.callHook("$afterRoutesInit");
160
+ await this.#adapter.afterLoadRoutes();
161
+ // map routers are loaded after all hooks because it contains all added middlewares/controllers in the virtual Ts.ED layers
162
+ // This step will convert all Ts.ED layers to the platform layer (Express or Koa)
163
+ await this.mapRouters();
164
+ // Server is bootstrapped and ready to listen
165
+ return this;
166
+ }
167
+ async loadInjector() {
168
+ const { injector } = this;
169
+ this.log("Build providers");
170
+ await injector.loadModule(this.#rootModule);
171
+ this.log("Settings and injector loaded...");
172
+ await this.callHook("$afterInit");
173
+ }
174
+ async listen(network = true) {
175
+ if (!this.#promise) {
176
+ await this.bootstrap();
177
+ }
178
+ await this.callHook("$beforeListen");
179
+ if (network) {
180
+ await this.listenServers();
181
+ }
182
+ await this.callHook("$afterListen");
183
+ await this.ready();
184
+ }
185
+ async stop() {
186
+ await this.callHook("$onDestroy");
187
+ await this.injector.destroy();
188
+ this.#listeners.map(closeServer);
189
+ }
190
+ async ready() {
191
+ const { startedAt } = this;
192
+ await this.callHook("$onReady");
193
+ await this.injector.emit("$onServerReady");
194
+ this.log(`Started in ${new Date().getTime() - startedAt.getTime()} ms`);
195
+ }
196
+ async callHook(hook, ...args) {
197
+ const { injector } = this;
198
+ if (!this.disableBootstrapLog) {
199
+ injector.logger.debug(`\x1B[1mCall hook ${hook}\x1B[22m`);
200
+ }
201
+ // Load middlewares for the given hook
202
+ this.loadMiddlewaresFor(hook);
203
+ // call hooks added by providers
204
+ await injector.emit(hook, ...args);
205
+ }
206
+ loadStatics(hook) {
207
+ const statics = this.settings.get("statics");
208
+ getStaticsOptions(statics).forEach(({ path, options }) => {
209
+ if (options.hook === hook) {
210
+ this.platform.app.statics(path, options);
211
+ }
212
+ });
213
+ }
214
+ useProvider(token, settings) {
215
+ this.injector.addProvider(token, settings);
216
+ return this;
217
+ }
218
+ bootstrap() {
219
+ this.#promise = this.#promise || this.runLifecycle();
220
+ return this.#promise;
221
+ }
222
+ mapRouters() {
223
+ const layers = this.platform.getLayers();
224
+ this.#adapter.mapLayers(layers);
225
+ const rawBody = this.settings.get("rawBody") ||
226
+ layers.some(({ handlers }) => {
227
+ return handlers.some((handler) => handler.opts?.paramsTypes?.RAW_BODY);
228
+ });
229
+ this.settings.set("rawBody", rawBody);
230
+ return this.logRoutes(layers.filter((layer) => layer.isProvider()));
231
+ }
232
+ diff() {
233
+ const ms = colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);
234
+ this.current = new Date();
235
+ return ms;
236
+ }
237
+ /**
238
+ * Load middlewares from configuration for the given hook
239
+ * @param hook
240
+ * @protected
241
+ */
242
+ loadMiddlewaresFor(hook) {
243
+ return getMiddlewaresForHook(hook, this.settings, "$beforeRoutesInit").forEach(({ use }) => {
244
+ this.app.use(use);
245
+ });
246
+ }
247
+ createHttpServers() {
248
+ this.#servers = this.#adapter.getServers();
249
+ }
250
+ async listenServers() {
251
+ this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));
252
+ }
253
+ async logRoutes(layers) {
254
+ const { logger } = this;
255
+ this.log("Routes mounted...");
256
+ if (!this.settings.get("logger.disableRoutesSummary") && !this.disableBootstrapLog) {
257
+ const routes = layers.map((layer) => {
258
+ return {
259
+ url: layer.path,
260
+ method: layer.method,
261
+ name: layer.opts.name || `${layer.provider.className}.constructor()`,
262
+ className: layer.opts.className || layer.provider.className,
263
+ methodClassName: layer.opts.methodClassName || ""
264
+ };
265
+ });
266
+ logger.info(printRoutes(await this.injector.alterAsync("$logRoutes", routes)));
267
+ }
268
+ }
269
+ async mapTokenMiddlewares() {
270
+ let middlewares = this.injector.settings.get("middlewares", []);
271
+ const { env } = this.injector.settings;
272
+ const defaultHook = "$beforeRoutesInit";
273
+ const promises = middlewares.map(async (middleware) => {
274
+ if (isFunction(middleware)) {
275
+ return {
276
+ env,
277
+ hook: defaultHook,
278
+ use: middleware
279
+ };
280
+ }
281
+ if (isString(middleware)) {
282
+ middleware = { env, use: middleware, hook: defaultHook };
283
+ }
284
+ let { use, options } = middleware;
285
+ if (isString(use)) {
286
+ if (["text-parser", "raw-parser", "json-parser", "urlencoded-parser"].includes(use)) {
287
+ use = this.adapter.bodyParser(use.replace("-parser", ""), options);
288
+ }
289
+ else {
290
+ const mod = await import(use);
291
+ use = (mod.default || mod)(options);
292
+ }
293
+ }
294
+ if (isClass(use) && ["$beforeInit", "$onInit", "$afterInit"].includes(middleware.hook)) {
295
+ throw new Error(`Ts.ED Middleware "${nameOf(use)}" middleware cannot be added on ${middleware.hook} hook. Use one of this hooks instead: $beforeRoutesInit, $onRoutesInit, $afterRoutesInit, $beforeListen, $afterListen, $onReady`);
296
+ }
297
+ return {
298
+ env,
299
+ hook: defaultHook,
300
+ ...middleware,
301
+ use
302
+ };
303
+ });
304
+ middlewares = await Promise.all(promises);
305
+ this.injector.settings.set("middlewares", middlewares.filter((middleware) => middleware.use));
306
+ }
307
+ }
308
+ //# sourceMappingURL=PlatformBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../../src/common/builder/PlatformBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAO,MAAM,YAAY,CAAC;AACvE,OAAO,EAAC,MAAM,EAAiC,sBAAsB,EAAgB,MAAM,UAAU,CAAC;AACtG,OAAO,EAAC,qBAAqB,EAAmC,MAAM,4BAA4B,CAAC;AAUnG,OAAO,EAAC,QAAQ,EAAC,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAC,eAAe,EAA0B,MAAM,gCAAgC,CAAC;AACxF,OAAO,EAAC,mBAAmB,EAAC,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAC,iBAAiB,EAAC,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,eAAe;IAMjB,SAAS,CAAkB;IAC3B,WAAW,CAAY;IACvB,QAAQ,CAAuB;IACxC,QAAQ,CAAgB;IACxB,QAAQ,CAAuB;IAC/B,UAAU,CAA0D;IAEpE,YAAsB,OAA+C,EAAE,MAAY,EAAE,QAAqC;QAVjH,SAAI,GAAW,EAA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YACH,CAAC;YAED,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAK,CAAC,EAAE,CAAC;gBACxF,MAAM,IAAI,KAAK,CACb,qBAAqB,MAAM,CAAC,GAAG,CAAC,mCAC9B,UAAU,CAAC,IACb,iIAAiI,CAClI,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,GAAG;gBACH,IAAI,EAAE,WAAW;gBACjB,GAAG,UAAU;gBACb,GAAG;aACJ,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,WAAW,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAE1C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CACxB,aAAa,EACb,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CACnD,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PlatformJsonMapperSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformJsonMapperSettings.js","sourceRoot":"","sources":["../../../../../src/common/config/interfaces/PlatformJsonMapperSettings.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PlatformMulterSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformMulterSettings.js","sourceRoot":"","sources":["../../../../../src/common/config/interfaces/PlatformMulterSettings.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PlatformRouterSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformRouterSettings.js","sourceRoot":"","sources":["../../../../../src/common/config/interfaces/PlatformRouterSettings.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PlatformStaticsSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformStaticsSettings.js","sourceRoot":"","sources":["../../../../../src/common/config/interfaces/PlatformStaticsSettings.ts"],"names":[],"mappings":""}
@@ -0,0 +1,119 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { getHostInfoFromPort, isBoolean } from "@tsed/core";
3
+ import { DIConfiguration, Injectable, ProviderScope } from "@tsed/di";
4
+ import { JsonMapperSettings } from "@tsed/json-mapper";
5
+ const rootDir = process.cwd();
6
+ /**
7
+ * `PlatformConfiguration` contains all information about your Server configuration.
8
+ */
9
+ let PlatformConfiguration = class PlatformConfiguration extends DIConfiguration {
10
+ constructor() {
11
+ super({ rootDir });
12
+ }
13
+ get port() {
14
+ return this.httpPort;
15
+ }
16
+ set port(value) {
17
+ this.httpPort = value;
18
+ }
19
+ get httpsOptions() {
20
+ return this.getRaw("httpsOptions");
21
+ }
22
+ set httpsOptions(value) {
23
+ this.setRaw("httpsOptions", value);
24
+ }
25
+ get httpPort() {
26
+ return this.getRaw("httpPort");
27
+ }
28
+ set httpPort(value) {
29
+ this.setRaw("httpPort", value);
30
+ }
31
+ get httpsPort() {
32
+ return this.getRaw("httpsPort");
33
+ }
34
+ set httpsPort(value) {
35
+ this.setRaw("httpsPort", value);
36
+ }
37
+ get mount() {
38
+ return this.get("mount");
39
+ }
40
+ set mount(value) {
41
+ this.setRaw("mount", value);
42
+ }
43
+ get statics() {
44
+ return this.getRaw("statics") || this.getRaw("serveStatic") || {};
45
+ }
46
+ set statics(value) {
47
+ this.setRaw("statics", value);
48
+ }
49
+ get acceptMimes() {
50
+ return this.getRaw("acceptMimes");
51
+ }
52
+ set acceptMimes(value) {
53
+ this.setRaw("acceptMimes", value || []);
54
+ }
55
+ get jsonMapper() {
56
+ return {
57
+ ...JsonMapperSettings
58
+ };
59
+ }
60
+ set jsonMapper(options) {
61
+ JsonMapperSettings.strictGroups = Boolean(options.strictGroups);
62
+ JsonMapperSettings.disableUnsecureConstructor = Boolean(options.disableUnsecureConstructor);
63
+ JsonMapperSettings.additionalProperties = Boolean(isBoolean(options.additionalProperties) ? options.additionalProperties : options.additionalProperties === "accept");
64
+ }
65
+ get additionalProperties() {
66
+ return this.get("converter.additionalProperties") === "accept";
67
+ }
68
+ /**
69
+ *
70
+ * @returns {string|number}
71
+ */
72
+ getHttpPort() {
73
+ return getHostInfoFromPort("http", this.getRaw("httpPort"));
74
+ }
75
+ /**
76
+ *
77
+ * @param settings
78
+ */
79
+ setHttpPort(settings) {
80
+ this.setRaw("httpPort", `${settings.address}:${settings.port}`);
81
+ }
82
+ /**
83
+ *
84
+ * @returns {string|number}
85
+ */
86
+ getHttpsPort() {
87
+ return getHostInfoFromPort("https", this.getRaw("httpsPort"));
88
+ }
89
+ /**
90
+ *
91
+ * @param settings
92
+ */
93
+ setHttpsPort(settings) {
94
+ this.setRaw("httpsPort", `${settings.address}:${settings.port}`);
95
+ }
96
+ getBestHost() {
97
+ const { httpsPort, httpPort } = this;
98
+ if (httpsPort) {
99
+ return this.getHttpsPort();
100
+ }
101
+ if (httpPort) {
102
+ return this.getHttpPort();
103
+ }
104
+ return {
105
+ toString() {
106
+ return "/";
107
+ }
108
+ };
109
+ }
110
+ };
111
+ PlatformConfiguration = __decorate([
112
+ Injectable({
113
+ scope: ProviderScope.SINGLETON,
114
+ global: true
115
+ }),
116
+ __metadata("design:paramtypes", [])
117
+ ], PlatformConfiguration);
118
+ export { PlatformConfiguration };
119
+ //# sourceMappingURL=PlatformConfiguration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformConfiguration.js","sourceRoot":"","sources":["../../../../../src/common/config/services/PlatformConfiguration.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,mBAAmB,EAAE,SAAS,EAAC,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAE,UAAU,EAAE,aAAa,EAAgB,MAAM,UAAU,CAAC;AACnF,OAAO,EAAC,kBAAkB,EAAC,MA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,WAAW,CAAC,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACH,YAAY,CAAC,QAAyC;QACpD,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,WAAW;QACT,MAAM,EAAC,SAAS,EAAE,QAAQ,EAAC,GAAG,IAAI,CAAC;QAEnC,IAAI,SAAS,EAAE,CAAC;YACd,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC;QAC7B,CAAC;QAED,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;QAC5B,CAAC;QAED,OAAO;YACL,QAAQ;gBACN,OAAO,GAAG,CAAC;YACb,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAhIY,qBAAqB;IAJjC,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,MAAM,EAAE,IAAI;KACb,CAAC;;GACW,qBAAqB,CAgIjC"}
@@ -0,0 +1,2 @@
1
+ export const ROUTER_OPTIONS = Symbol.for("ROUTER_OPTIONS");
2
+ //# sourceMappingURL=routerOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routerOptions.js","sourceRoot":"","sources":["../../../../src/common/constants/routerOptions.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { registerPlatformAdapter } from "../utils/registerPlatformAdapter.js";
2
+ export function PlatformProvider() {
3
+ return (klass) => {
4
+ registerPlatformAdapter(klass);
5
+ };
6
+ }
7
+ //# sourceMappingURL=PlatformProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformProvider.js","sourceRoot":"","sources":["../../../../src/common/decorators/PlatformProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,uBAAuB,EAAC,MAAM,qCAAqC,CAAC;AAE5E,MAAM,UAAU,gBAAgB;IAC9B,OAAO,CAAC,KAA4B,EAAE,EAAE;QACtC,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { MulterOptions } from "./multerOptions.js";
2
+ /**
3
+ * Define file size limit.
4
+ *
5
+ * ```typescript
6
+ * import {Post} from "@tsed/schema";
7
+ * import {MulterOptions, MultipartFile} from "@tsed/platform-http";
8
+ * import {Controller} from "@tsed/di";
9
+ * import {Multer} from "@types/multer";
10
+ *
11
+ * type MulterFile = Express.Multer.File;
12
+ *
13
+ * @Controller('/')
14
+ * class MyCtrl {
15
+ * @Post('/file2')
16
+ * @MulterFileSize(1024) // (Ko). Applied for all fields
17
+ * private uploadFile(@MultipartFile("file1") file: MulterFile, @MultipartFile("file2") file2: MulterFile) {
18
+ *
19
+ * }
20
+ * }
21
+ * ```
22
+ *
23
+ * > See the tutorial on the [multer configuration](/tutorials/multer.md).
24
+ * @param fileSize
25
+ * @returns {(target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor}
26
+ * @decorator
27
+ * @multer
28
+ */
29
+ export function MulterFileSize(fileSize) {
30
+ return MulterOptions({ limits: { fileSize } });
31
+ }
32
+ //# sourceMappingURL=multerFileSize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multerFileSize.js","sourceRoot":"","sources":["../../../../../src/common/decorators/multer/multerFileSize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,OAAO,aAAa,CAAC,EAAC,MAAM,EAAE,EAAC,QAAQ,EAAC,EAAC,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { StoreMerge } from "@tsed/core";
2
+ import { PlatformMulterMiddleware } from "../../middlewares/PlatformMulterMiddleware.js";
3
+ /**
4
+ * Define multer option for all MultipartFile
5
+ *
6
+ * ```typescript
7
+ * import {PlatformMulterFile, MultipartFile, MulterOptions} from "@tsed/platform-http";
8
+ * import {Controller} from "@tsed/di";
9
+ * import {Post} from "@tsed/schema";
10
+ *
11
+ * @Controller('/')
12
+ * class MyCtrl {
13
+ * @Post('/file')
14
+ * private uploadFile(@MultipartFile("file1") file: PlatformMulterFile) {
15
+ *
16
+ * }
17
+ *
18
+ * @Post('/file')
19
+ * @MulterOptions({dest: "/other-dir"})
20
+ * private uploadFile(@MultipartFile("file1") file: PlatformMulterFile) {
21
+ *
22
+ * }
23
+ *
24
+ * @Post('/file2')
25
+ * @MulterOptions({dest: "/other-dir"})
26
+ * private uploadFile(@MultipartFile("file1") file: PlatformMulterFile, @MultipartFile("file2") file2: PlatformMulterFile) {
27
+ *
28
+ * }
29
+ *
30
+ * @Post('/files')
31
+ * private uploadFile(@MultipartFile("file1") files: PlatformMulterFile[]) {
32
+ *
33
+ * }
34
+ * }
35
+ * ```
36
+ *
37
+ * See the tutorial on the [multer configuration](/tutorials/multer.md).
38
+ *
39
+ * @param {multer.Options} options
40
+ * @returns {(target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor}
41
+ * @decorator
42
+ * @multer
43
+ */
44
+ export function MulterOptions(options) {
45
+ return (target, propertyKey, descriptor) => {
46
+ StoreMerge(PlatformMulterMiddleware, { options })(target, propertyKey, descriptor);
47
+ return descriptor;
48
+ };
49
+ }
50
+ //# sourceMappingURL=multerOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multerOptions.js","sourceRoot":"","sources":["../../../../../src/common/decorators/multer/multerOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAGtC,OAAO,EAAC,wBAAwB,EAAC,MAAM,+CAA+C,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,aAAa,CAAC,OAA+B;IAC3D,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAE;QAC1E,UAAU,CAAC,wBAAwB,EAAE,EAAC,OAAO,EAAC,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAEjF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}