@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.
- package/.barrelsby.json +5 -0
- package/lib/esm/common/builder/PlatformBuilder.js +308 -0
- package/lib/esm/common/builder/PlatformBuilder.js.map +1 -0
- package/lib/esm/common/config/interfaces/PlatformJsonMapperSettings.js +2 -0
- package/lib/esm/common/config/interfaces/PlatformJsonMapperSettings.js.map +1 -0
- package/lib/esm/common/config/interfaces/PlatformMulterSettings.js +2 -0
- package/lib/esm/common/config/interfaces/PlatformMulterSettings.js.map +1 -0
- package/lib/esm/common/config/interfaces/PlatformRouterSettings.js +2 -0
- package/lib/esm/common/config/interfaces/PlatformRouterSettings.js.map +1 -0
- package/lib/esm/common/config/interfaces/PlatformStaticsSettings.js +2 -0
- package/lib/esm/common/config/interfaces/PlatformStaticsSettings.js.map +1 -0
- package/lib/esm/common/config/services/PlatformConfiguration.js +119 -0
- package/lib/esm/common/config/services/PlatformConfiguration.js.map +1 -0
- package/lib/esm/common/constants/routerOptions.js +2 -0
- package/lib/esm/common/constants/routerOptions.js.map +1 -0
- package/lib/esm/common/decorators/PlatformProvider.js +7 -0
- package/lib/esm/common/decorators/PlatformProvider.js.map +1 -0
- package/lib/esm/common/decorators/multer/multerFileSize.js +32 -0
- package/lib/esm/common/decorators/multer/multerFileSize.js.map +1 -0
- package/lib/esm/common/decorators/multer/multerOptions.js +50 -0
- package/lib/esm/common/decorators/multer/multerOptions.js.map +1 -0
- package/lib/esm/common/decorators/multer/multipartFile.js +75 -0
- package/lib/esm/common/decorators/multer/multipartFile.js.map +1 -0
- package/lib/esm/common/decorators/params/error.js +16 -0
- package/lib/esm/common/decorators/params/error.js.map +1 -0
- package/lib/esm/common/decorators/params/next.js +17 -0
- package/lib/esm/common/decorators/params/next.js.map +1 -0
- package/lib/esm/common/decorators/params/request.js +34 -0
- package/lib/esm/common/decorators/params/request.js.map +1 -0
- package/lib/esm/common/decorators/params/response.js +28 -0
- package/lib/esm/common/decorators/params/response.js.map +1 -0
- package/lib/esm/common/domain/AnyToPromiseWithCtx.js +21 -0
- package/lib/esm/common/domain/AnyToPromiseWithCtx.js.map +1 -0
- package/lib/esm/common/domain/EndpointMetadata.js +2 -0
- package/lib/esm/common/domain/EndpointMetadata.js.map +1 -0
- package/lib/esm/common/domain/PlatformContext.js +69 -0
- package/lib/esm/common/domain/PlatformContext.js.map +1 -0
- package/lib/esm/common/domain/PlatformRouteDetails.js +2 -0
- package/lib/esm/common/domain/PlatformRouteDetails.js.map +1 -0
- package/lib/esm/common/exports.js +5 -0
- package/lib/esm/common/exports.js.map +1 -0
- package/lib/esm/common/index.js +61 -0
- package/lib/esm/common/index.js.map +1 -0
- package/lib/esm/common/interfaces/AfterInit.js +2 -0
- package/lib/esm/common/interfaces/AfterInit.js.map +1 -0
- package/lib/esm/common/interfaces/AfterListen.js +2 -0
- package/lib/esm/common/interfaces/AfterListen.js.map +1 -0
- package/lib/esm/common/interfaces/AfterRoutesInit.js +2 -0
- package/lib/esm/common/interfaces/AfterRoutesInit.js.map +1 -0
- package/lib/esm/common/interfaces/BeforeInit.js +2 -0
- package/lib/esm/common/interfaces/BeforeInit.js.map +1 -0
- package/lib/esm/common/interfaces/BeforeListen.js +2 -0
- package/lib/esm/common/interfaces/BeforeListen.js.map +1 -0
- package/lib/esm/common/interfaces/BeforeRoutesInit.js +2 -0
- package/lib/esm/common/interfaces/BeforeRoutesInit.js.map +1 -0
- package/lib/esm/common/interfaces/HandlerType.js +14 -0
- package/lib/esm/common/interfaces/HandlerType.js.map +1 -0
- package/lib/esm/common/interfaces/IncomingEvent.js +2 -0
- package/lib/esm/common/interfaces/IncomingEvent.js.map +1 -0
- package/lib/esm/common/interfaces/OnReady.js +2 -0
- package/lib/esm/common/interfaces/OnReady.js.map +1 -0
- package/lib/esm/common/interfaces/OnRequest.js +2 -0
- package/lib/esm/common/interfaces/OnRequest.js.map +1 -0
- package/lib/esm/common/interfaces/OnResponse.js +2 -0
- package/lib/esm/common/interfaces/OnResponse.js.map +1 -0
- package/lib/esm/common/interfaces/OnRoutesInit.js +2 -0
- package/lib/esm/common/interfaces/OnRoutesInit.js.map +1 -0
- package/lib/esm/common/interfaces/PlatformRouteOptions.js +2 -0
- package/lib/esm/common/interfaces/PlatformRouteOptions.js.map +1 -0
- package/lib/esm/common/interfaces/ResponseErrorObject.js +2 -0
- package/lib/esm/common/interfaces/ResponseErrorObject.js.map +1 -0
- package/lib/esm/common/interfaces/Route.js +2 -0
- package/lib/esm/common/interfaces/Route.js.map +1 -0
- package/lib/esm/common/middlewares/PlatformAcceptMimesMiddleware.js +36 -0
- package/lib/esm/common/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
- package/lib/esm/common/middlewares/PlatformMulterMiddleware.js +66 -0
- package/lib/esm/common/middlewares/PlatformMulterMiddleware.js.map +1 -0
- package/lib/esm/common/services/Platform.js +73 -0
- package/lib/esm/common/services/Platform.js.map +1 -0
- package/lib/esm/common/services/PlatformAdapter.js +77 -0
- package/lib/esm/common/services/PlatformAdapter.js.map +1 -0
- package/lib/esm/common/services/PlatformApplication.js +41 -0
- package/lib/esm/common/services/PlatformApplication.js.map +1 -0
- package/lib/esm/common/services/PlatformHandler.js +130 -0
- package/lib/esm/common/services/PlatformHandler.js.map +1 -0
- package/lib/esm/common/services/PlatformMiddlewaresChain.js +57 -0
- package/lib/esm/common/services/PlatformMiddlewaresChain.js.map +1 -0
- package/lib/esm/common/services/PlatformRequest.js +141 -0
- package/lib/esm/common/services/PlatformRequest.js.map +1 -0
- package/lib/esm/common/services/PlatformResponse.js +306 -0
- package/lib/esm/common/services/PlatformResponse.js.map +1 -0
- package/lib/esm/common/utils/closeServer.js +4 -0
- package/lib/esm/common/utils/closeServer.js.map +1 -0
- package/lib/esm/common/utils/createContext.js +44 -0
- package/lib/esm/common/utils/createContext.js.map +1 -0
- package/lib/esm/common/utils/createHttpServer.js +13 -0
- package/lib/esm/common/utils/createHttpServer.js.map +1 -0
- package/lib/esm/common/utils/createHttpsServer.js +13 -0
- package/lib/esm/common/utils/createHttpsServer.js.map +1 -0
- package/lib/esm/common/utils/createInjector.js +41 -0
- package/lib/esm/common/utils/createInjector.js.map +1 -0
- package/lib/esm/common/utils/createServer.js +29 -0
- package/lib/esm/common/utils/createServer.js.map +1 -0
- package/lib/esm/common/utils/ensureContext.js +12 -0
- package/lib/esm/common/utils/ensureContext.js.map +1 -0
- package/lib/esm/common/utils/getConfiguration.js +32 -0
- package/lib/esm/common/utils/getConfiguration.js.map +1 -0
- package/lib/esm/common/utils/getStaticsOptions.js +17 -0
- package/lib/esm/common/utils/getStaticsOptions.js.map +1 -0
- package/lib/esm/common/utils/listenServer.js +10 -0
- package/lib/esm/common/utils/listenServer.js.map +1 -0
- package/lib/esm/common/utils/mapReturnedResponse.js +11 -0
- package/lib/esm/common/utils/mapReturnedResponse.js.map +1 -0
- package/lib/esm/common/utils/printRoutes.js +34 -0
- package/lib/esm/common/utils/printRoutes.js.map +1 -0
- package/lib/esm/common/utils/registerPlatformAdapter.js +7 -0
- package/lib/esm/common/utils/registerPlatformAdapter.js.map +1 -0
- package/lib/esm/common/utils/setResponseHeaders.js +25 -0
- package/lib/esm/common/utils/setResponseHeaders.js.map +1 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/testing/FakeAdapter.js +2 -0
- package/lib/esm/testing/FakeAdapter.js.map +1 -0
- package/lib/esm/testing/FakeResponse.js +55 -0
- package/lib/esm/testing/FakeResponse.js.map +1 -0
- package/lib/esm/testing/PlatformTest.js +131 -0
- package/lib/esm/testing/PlatformTest.js.map +1 -0
- package/lib/esm/testing/index.js +6 -0
- package/lib/esm/testing/index.js.map +1 -0
- package/lib/types/common/builder/PlatformBuilder.d.ts +100 -0
- package/lib/types/common/config/interfaces/PlatformJsonMapperSettings.d.ts +10 -0
- package/lib/types/common/config/interfaces/PlatformMulterSettings.d.ts +14 -0
- package/lib/types/common/config/interfaces/PlatformRouterSettings.d.ts +10 -0
- package/lib/types/common/config/interfaces/PlatformStaticsSettings.d.ts +17 -0
- package/lib/types/common/config/services/PlatformConfiguration.d.ts +78 -0
- package/lib/types/common/constants/routerOptions.d.ts +1 -0
- package/lib/types/common/decorators/PlatformProvider.d.ts +3 -0
- package/lib/types/common/decorators/multer/multerFileSize.d.ts +28 -0
- package/lib/types/common/decorators/multer/multerOptions.d.ts +43 -0
- package/lib/types/common/decorators/multer/multipartFile.d.ts +48 -0
- package/lib/types/common/decorators/params/error.d.ts +7 -0
- package/lib/types/common/decorators/params/next.d.ts +22 -0
- package/lib/types/common/decorators/params/request.d.ts +46 -0
- package/lib/types/common/decorators/params/response.d.ts +40 -0
- package/lib/types/common/domain/AnyToPromiseWithCtx.d.ts +10 -0
- package/lib/types/common/domain/EndpointMetadata.d.ts +1 -0
- package/lib/types/common/domain/PlatformContext.d.ts +80 -0
- package/lib/types/common/domain/PlatformRouteDetails.d.ts +7 -0
- package/lib/types/common/exports.d.ts +4 -0
- package/lib/types/common/index.d.ts +60 -0
- package/lib/types/common/interfaces/AfterInit.d.ts +3 -0
- package/lib/types/common/interfaces/AfterListen.d.ts +3 -0
- package/lib/types/common/interfaces/AfterRoutesInit.d.ts +3 -0
- package/lib/types/common/interfaces/BeforeInit.d.ts +3 -0
- package/lib/types/common/interfaces/BeforeListen.d.ts +3 -0
- package/lib/types/common/interfaces/BeforeRoutesInit.d.ts +3 -0
- package/lib/types/common/interfaces/HandlerType.d.ts +12 -0
- package/lib/types/common/interfaces/IncomingEvent.d.ts +6 -0
- package/lib/types/common/interfaces/OnReady.d.ts +3 -0
- package/lib/types/common/interfaces/OnRequest.d.ts +4 -0
- package/lib/types/common/interfaces/OnResponse.d.ts +4 -0
- package/lib/types/common/interfaces/OnRoutesInit.d.ts +3 -0
- package/lib/types/common/interfaces/PlatformRouteOptions.d.ts +15 -0
- package/lib/types/common/interfaces/ResponseErrorObject.d.ts +8 -0
- package/lib/types/common/interfaces/Route.d.ts +10 -0
- package/lib/types/common/middlewares/PlatformAcceptMimesMiddleware.d.ts +10 -0
- package/lib/types/common/middlewares/PlatformMulterMiddleware.d.ts +24 -0
- package/lib/types/common/services/Platform.d.ts +25 -0
- package/lib/types/common/services/PlatformAdapter.d.ts +89 -0
- package/lib/types/common/services/PlatformApplication.d.ts +29 -0
- package/lib/types/common/services/PlatformHandler.d.ts +39 -0
- package/lib/types/common/services/PlatformMiddlewaresChain.d.ts +17 -0
- package/lib/types/common/services/PlatformRequest.d.ts +111 -0
- package/lib/types/common/services/PlatformResponse.d.ts +175 -0
- package/lib/types/common/utils/closeServer.d.ts +7 -0
- package/lib/types/common/utils/createContext.d.ts +10 -0
- package/lib/types/common/utils/createHttpServer.d.ts +4 -0
- package/lib/types/common/utils/createHttpsServer.d.ts +4 -0
- package/lib/types/common/utils/createInjector.d.ts +8 -0
- package/lib/types/common/utils/createServer.d.ts +17 -0
- package/lib/types/common/utils/ensureContext.d.ts +2 -0
- package/lib/types/common/utils/getConfiguration.d.ts +2 -0
- package/lib/types/common/utils/getStaticsOptions.d.ts +5 -0
- package/lib/types/common/utils/listenServer.d.ts +8 -0
- package/lib/types/common/utils/mapReturnedResponse.d.ts +4 -0
- package/lib/types/common/utils/printRoutes.d.ts +2 -0
- package/lib/types/common/utils/registerPlatformAdapter.d.ts +3 -0
- package/lib/types/common/utils/setResponseHeaders.d.ts +5 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/testing/FakeAdapter.d.ts +1 -0
- package/lib/types/testing/FakeResponse.d.ts +22 -0
- package/lib/types/testing/PlatformTest.d.ts +61 -0
- package/lib/types/testing/index.d.ts +5 -0
- package/package.json +111 -0
- package/readme.md +226 -0
- package/vitest.config.mts +21 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerPlatformAdapter.js","sourceRoot":"","sources":["../../../../src/common/utils/registerPlatformAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAG9D,MAAM,UAAU,uBAAuB,CAAC,OAAmC;IACzE,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;IAC/B,eAAe,CAAC,OAAO,GAAG,OAAO,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ignore
|
|
3
|
+
*/
|
|
4
|
+
export function setResponseHeaders(ctx) {
|
|
5
|
+
const { response, endpoint } = ctx;
|
|
6
|
+
const { operation } = endpoint;
|
|
7
|
+
if (ctx.isDone()) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (!response.hasStatus()) {
|
|
11
|
+
// apply status only if the isn't already modified
|
|
12
|
+
response.status(operation.getStatus());
|
|
13
|
+
}
|
|
14
|
+
const statusCode = response.statusCode;
|
|
15
|
+
const headers = operation.getHeadersOf(statusCode);
|
|
16
|
+
Object.entries(headers).forEach(([key, item]) => {
|
|
17
|
+
if (!response.get(key) && item.example !== undefined) {
|
|
18
|
+
response.setHeader(key, String(item.example));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
if (operation.isRedirection(statusCode)) {
|
|
22
|
+
response.redirect(statusCode, response.get("location"));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=setResponseHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setResponseHeaders.js","sourceRoot":"","sources":["../../../../src/common/utils/setResponseHeaders.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAoB;IACrD,MAAM,EAAC,QAAQ,EAAE,QAAQ,EAAC,GAAG,GAAG,CAAC;IACjC,MAAM,EAAC,SAAS,EAAC,GAAG,QAAQ,CAAC;IAE7B,IAAI,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC;QACjB,OAAO;IACT,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC;QAC1B,kDAAkD;QAClD,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;IACvC,MAAM,OAAO,GAAG,SAAS,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IAEnD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAQ,EAAE,EAAE;QACrD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACrD,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,SAAS,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;QACxC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC"}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FakeAdapter.js","sourceRoot":"","sources":["../../../src/testing/FakeAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,uCAAuC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
export class FakeResponse extends EventEmitter {
|
|
3
|
+
constructor(opts = {}) {
|
|
4
|
+
super();
|
|
5
|
+
this.headers = {};
|
|
6
|
+
this.locals = {};
|
|
7
|
+
this.statusCode = 200;
|
|
8
|
+
Object.assign(this, opts);
|
|
9
|
+
}
|
|
10
|
+
status(code) {
|
|
11
|
+
this.statusCode = code;
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
contentType(content) {
|
|
15
|
+
this.set("content-type", content);
|
|
16
|
+
}
|
|
17
|
+
contentLength(content) {
|
|
18
|
+
this.set("content-length", content);
|
|
19
|
+
}
|
|
20
|
+
redirect(status, path) {
|
|
21
|
+
this.statusCode = status;
|
|
22
|
+
this.set("location", path);
|
|
23
|
+
}
|
|
24
|
+
location(path) {
|
|
25
|
+
this.set("location", path);
|
|
26
|
+
}
|
|
27
|
+
get(key) {
|
|
28
|
+
return this.headers[key.toLowerCase()];
|
|
29
|
+
}
|
|
30
|
+
getHeaders() {
|
|
31
|
+
return this.headers;
|
|
32
|
+
}
|
|
33
|
+
set(key, value) {
|
|
34
|
+
this.headers[key.toLowerCase()] = value;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
setHeader(key, value) {
|
|
38
|
+
this.headers[key.toLowerCase()] = value;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
send(data) {
|
|
42
|
+
this.data = data;
|
|
43
|
+
}
|
|
44
|
+
json(data) {
|
|
45
|
+
this.data = data;
|
|
46
|
+
}
|
|
47
|
+
write(chunk) {
|
|
48
|
+
this.emit("data", chunk);
|
|
49
|
+
}
|
|
50
|
+
end(data) {
|
|
51
|
+
data !== undefined && (this.data = data);
|
|
52
|
+
this.emit("end");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=FakeResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FakeResponse.js","sourceRoot":"","sources":["../../../src/testing/FakeResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa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AC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,IAAS;QACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,IAAS;QACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,KAAU;QACd,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED,GAAG,CAAC,IAAS;QACX,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;QAEzC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { DITest, hasInjector, injector } from "@tsed/di";
|
|
2
|
+
import accepts from "accepts";
|
|
3
|
+
import { PlatformBuilder } from "../common/builder/PlatformBuilder.js";
|
|
4
|
+
import { PlatformContext } from "../common/domain/PlatformContext.js";
|
|
5
|
+
import { PlatformApplication } from "../common/services/PlatformApplication.js";
|
|
6
|
+
import { createInjector } from "../common/utils/createInjector.js";
|
|
7
|
+
import { getConfiguration } from "../common/utils/getConfiguration.js";
|
|
8
|
+
import { FakeResponse } from "./FakeResponse.js";
|
|
9
|
+
/**
|
|
10
|
+
* @platform
|
|
11
|
+
*/
|
|
12
|
+
export class PlatformTest extends DITest {
|
|
13
|
+
static async create(settings = {}) {
|
|
14
|
+
PlatformTest.createInjector(getConfiguration(settings));
|
|
15
|
+
await DITest.createContainer();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a new injector with the right default services
|
|
19
|
+
*/
|
|
20
|
+
static createInjector(settings = {}) {
|
|
21
|
+
return createInjector({
|
|
22
|
+
settings: DITest.configure({ httpPort: false, httpsPort: false, ...settings })
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Load the server silently without listening port and configure it on test profile.
|
|
27
|
+
* @decorator
|
|
28
|
+
* @param mod
|
|
29
|
+
* @param listen
|
|
30
|
+
* @param settings
|
|
31
|
+
* @returns {Promise<void>}
|
|
32
|
+
*/
|
|
33
|
+
static bootstrap(mod, { listen, ...settings } = {}) {
|
|
34
|
+
return async function before() {
|
|
35
|
+
let instance;
|
|
36
|
+
const adapter = settings.platform || settings.adapter || PlatformTest.adapter;
|
|
37
|
+
/* istanbul ignore next */
|
|
38
|
+
if (!adapter) {
|
|
39
|
+
throw new Error("Platform adapter is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?");
|
|
40
|
+
}
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
settings = DITest.configure(settings);
|
|
43
|
+
settings.adapter = adapter;
|
|
44
|
+
const configuration = getConfiguration(settings, mod);
|
|
45
|
+
instance = await PlatformBuilder.build(mod, configuration).bootstrap();
|
|
46
|
+
await instance.listen(!!listen);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* It injects services into the test function where you can alter, spy on, and manipulate them.
|
|
51
|
+
*
|
|
52
|
+
* The inject function has two parameters
|
|
53
|
+
*
|
|
54
|
+
* * an array of Service dependency injection tokens,
|
|
55
|
+
* * a test function whose parameters correspond exactly to each item in the injection token array.
|
|
56
|
+
*
|
|
57
|
+
* @deprecated use PlatformTest.injector.invoke instead
|
|
58
|
+
* @param targets
|
|
59
|
+
* @param func
|
|
60
|
+
*/
|
|
61
|
+
static inject(targets, func) {
|
|
62
|
+
return async () => {
|
|
63
|
+
if (!hasInjector()) {
|
|
64
|
+
await PlatformTest.create();
|
|
65
|
+
}
|
|
66
|
+
const inj = injector();
|
|
67
|
+
const deps = [];
|
|
68
|
+
for (const target of targets) {
|
|
69
|
+
deps.push(inj.has(target) ? inj.get(target) : await inj.invoke(target));
|
|
70
|
+
}
|
|
71
|
+
return func(...deps);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Return the raw application (express or koa).
|
|
76
|
+
* Use this callback with SuperTest.
|
|
77
|
+
*
|
|
78
|
+
* ```typescript
|
|
79
|
+
* let request: SuperTest.Agent;
|
|
80
|
+
* beforeEach(PlatformTest.bootstrap(Server, {
|
|
81
|
+
* mount: {
|
|
82
|
+
* "/rest": [ProductsController]
|
|
83
|
+
* }
|
|
84
|
+
* }));
|
|
85
|
+
* beforeEach(() => {
|
|
86
|
+
* request = SuperTest(PlatformTest.callback());
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
static callback() {
|
|
91
|
+
return injector().get(PlatformApplication)?.callback();
|
|
92
|
+
}
|
|
93
|
+
static createRequest(options = {}) {
|
|
94
|
+
return {
|
|
95
|
+
headers: {},
|
|
96
|
+
method: "GET",
|
|
97
|
+
url: "/",
|
|
98
|
+
query: {},
|
|
99
|
+
get(key) {
|
|
100
|
+
return this.headers[key.toLowerCase()];
|
|
101
|
+
},
|
|
102
|
+
accepts(mime) {
|
|
103
|
+
return accepts(this).types([].concat(mime));
|
|
104
|
+
},
|
|
105
|
+
...options
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
static createResponse(options = {}) {
|
|
109
|
+
return new FakeResponse(options);
|
|
110
|
+
}
|
|
111
|
+
static createRequestContext(options = {}) {
|
|
112
|
+
const event = {
|
|
113
|
+
...options.event,
|
|
114
|
+
request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),
|
|
115
|
+
response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()
|
|
116
|
+
};
|
|
117
|
+
const $ctx = new PlatformContext({
|
|
118
|
+
id: "id",
|
|
119
|
+
injector: injector(),
|
|
120
|
+
logger: injector().logger,
|
|
121
|
+
url: "/",
|
|
122
|
+
...options,
|
|
123
|
+
event
|
|
124
|
+
});
|
|
125
|
+
if (options.endpoint) {
|
|
126
|
+
$ctx.endpoint = options.endpoint;
|
|
127
|
+
}
|
|
128
|
+
return $ctx;
|
|
129
|
+
}
|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,CAAC;YACrB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACnC,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { Type } from "@tsed/core";
|
|
3
|
+
import { InjectorService, ProviderOpts, TokenProvider } from "@tsed/di";
|
|
4
|
+
import { PlatformLayer } from "@tsed/platform-router";
|
|
5
|
+
import type { IncomingMessage, ServerResponse } from "http";
|
|
6
|
+
import { Platform } from "../services/Platform.js";
|
|
7
|
+
import { PlatformAdapter, PlatformBuilderSettings } from "../services/PlatformAdapter.js";
|
|
8
|
+
import { PlatformApplication } from "../services/PlatformApplication.js";
|
|
9
|
+
/**
|
|
10
|
+
* @platform
|
|
11
|
+
*/
|
|
12
|
+
export declare class PlatformBuilder<App = TsED.Application> {
|
|
13
|
+
#private;
|
|
14
|
+
static adapter: Type<PlatformAdapter<any>>;
|
|
15
|
+
readonly name: string;
|
|
16
|
+
protected startedAt: Date;
|
|
17
|
+
protected current: Date;
|
|
18
|
+
protected constructor(adapter: Type<PlatformAdapter<App>> | undefined, module: Type, settings: Partial<TsED.Configuration>);
|
|
19
|
+
get injector(): InjectorService;
|
|
20
|
+
get rootModule(): any;
|
|
21
|
+
get app(): PlatformApplication<App>;
|
|
22
|
+
get platform(): Platform;
|
|
23
|
+
get adapter(): PlatformAdapter<App>;
|
|
24
|
+
/**
|
|
25
|
+
* Return the settings configured by the decorator @@Configuration@@.
|
|
26
|
+
*
|
|
27
|
+
* ```typescript
|
|
28
|
+
* @Configuration({
|
|
29
|
+
* port: 8000,
|
|
30
|
+
* httpsPort: 8080,
|
|
31
|
+
* mount: {
|
|
32
|
+
* "/rest": "${rootDir}/controllers/**\/*.js"
|
|
33
|
+
* }
|
|
34
|
+
* })
|
|
35
|
+
* export class Server {
|
|
36
|
+
* $onInit(){
|
|
37
|
+
* console.log(this.settings); // {rootDir, port, httpsPort,...}
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @returns {PlatformConfiguration}
|
|
43
|
+
*/
|
|
44
|
+
get settings(): import("@tsed/di").DIConfiguration;
|
|
45
|
+
get logger(): import("@tsed/di").DILogger;
|
|
46
|
+
get disableBootstrapLog(): any;
|
|
47
|
+
static create<App = TsED.Application>(module: Type<any>, settings: PlatformBuilderSettings<App>): PlatformBuilder<App>;
|
|
48
|
+
static build<App = TsED.Application>(module: Type<any>, { adapter, ...settings }: PlatformBuilderSettings<App>): PlatformBuilder<App>;
|
|
49
|
+
/**
|
|
50
|
+
* Bootstrap a server application
|
|
51
|
+
* @param module
|
|
52
|
+
* @param settings
|
|
53
|
+
*/
|
|
54
|
+
static bootstrap<App = TsED.Application>(module: Type<any>, settings: PlatformBuilderSettings<App>): Promise<PlatformBuilder<App>>;
|
|
55
|
+
callback(): (req: IncomingMessage, res: ServerResponse) => void;
|
|
56
|
+
callback(req: IncomingMessage, res: ServerResponse): void;
|
|
57
|
+
log(...data: any[]): any;
|
|
58
|
+
/**
|
|
59
|
+
* Add classes decorated by @@Controller@@ to components container.
|
|
60
|
+
*
|
|
61
|
+
* ### Example
|
|
62
|
+
*
|
|
63
|
+
* ```typescript
|
|
64
|
+
* @Controller('/ctrl')
|
|
65
|
+
* class MyController{
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* platform.addControllers('/rest', [MyController])
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* ::: tip
|
|
72
|
+
* If the MyController class isn't decorated, the class will be ignored.
|
|
73
|
+
* :::
|
|
74
|
+
*
|
|
75
|
+
* @param {string} endpoint
|
|
76
|
+
* @param {any[]} controllers
|
|
77
|
+
*/
|
|
78
|
+
addControllers(endpoint: string, controllers: TokenProvider | TokenProvider[]): void;
|
|
79
|
+
runLifecycle(): Promise<this>;
|
|
80
|
+
loadInjector(): Promise<void>;
|
|
81
|
+
listen(network?: boolean): Promise<void>;
|
|
82
|
+
stop(): Promise<void>;
|
|
83
|
+
ready(): Promise<void>;
|
|
84
|
+
callHook(hook: string, ...args: any[]): Promise<void>;
|
|
85
|
+
loadStatics(hook: string): void;
|
|
86
|
+
useProvider(token: Type<any>, settings?: Partial<ProviderOpts>): this;
|
|
87
|
+
bootstrap(): Promise<this>;
|
|
88
|
+
protected mapRouters(): Promise<void>;
|
|
89
|
+
protected diff(): string;
|
|
90
|
+
/**
|
|
91
|
+
* Load middlewares from configuration for the given hook
|
|
92
|
+
* @param hook
|
|
93
|
+
* @protected
|
|
94
|
+
*/
|
|
95
|
+
protected loadMiddlewaresFor(hook: string): void;
|
|
96
|
+
protected createHttpServers(): void;
|
|
97
|
+
protected listenServers(): Promise<void>;
|
|
98
|
+
protected logRoutes(layers: PlatformLayer[]): Promise<void>;
|
|
99
|
+
protected mapTokenMiddlewares(): Promise<void>;
|
|
100
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JsonMapperGlobalOptions } from "@tsed/json-mapper";
|
|
2
|
+
export interface PlatformJsonMapperSettings extends JsonMapperGlobalOptions {
|
|
3
|
+
}
|
|
4
|
+
declare global {
|
|
5
|
+
namespace TsED {
|
|
6
|
+
interface Configuration extends Record<string, any> {
|
|
7
|
+
jsonMapper?: PlatformJsonMapperSettings;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type multer from "multer";
|
|
2
|
+
declare global {
|
|
3
|
+
namespace TsED {
|
|
4
|
+
type MulterFile = Express.Multer.File;
|
|
5
|
+
type MulterStorageEngine = multer.StorageEngine;
|
|
6
|
+
type MulterOptions = multer.Options;
|
|
7
|
+
type MulterField = multer.Field;
|
|
8
|
+
type Multer = multer.Multer;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export type PlatformMulter = TsED.Multer;
|
|
12
|
+
export type PlatformMulterSettings = TsED.MulterOptions;
|
|
13
|
+
export type PlatformMulterFile = TsED.MulterFile;
|
|
14
|
+
export type PlatformMulterField = TsED.MulterField;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
namespace TsED {
|
|
3
|
+
interface StaticsOptions {
|
|
4
|
+
root: string;
|
|
5
|
+
hook?: "$beforeRoutesInit" | "$afterRoutesInit";
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export interface PlatformStaticsOptions extends TsED.StaticsOptions {
|
|
11
|
+
root: string;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
export type PathOrStaticsOptions = string | PlatformStaticsOptions;
|
|
15
|
+
export interface PlatformStaticsSettings {
|
|
16
|
+
[endpoint: string]: PathOrStaticsOptions | PathOrStaticsOptions[];
|
|
17
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { getHostInfoFromPort } from "@tsed/core";
|
|
3
|
+
import { DIConfiguration, TokenProvider } from "@tsed/di";
|
|
4
|
+
import Https from "https";
|
|
5
|
+
import { PlatformJsonMapperSettings } from "../interfaces/PlatformJsonMapperSettings.js";
|
|
6
|
+
/**
|
|
7
|
+
* `PlatformConfiguration` contains all information about your Server configuration.
|
|
8
|
+
*/
|
|
9
|
+
export declare class PlatformConfiguration extends DIConfiguration {
|
|
10
|
+
constructor();
|
|
11
|
+
get port(): string | number | false;
|
|
12
|
+
set port(value: string | number | false);
|
|
13
|
+
get httpsOptions(): Https.ServerOptions;
|
|
14
|
+
set httpsOptions(value: Https.ServerOptions);
|
|
15
|
+
get httpPort(): string | number | false;
|
|
16
|
+
set httpPort(value: string | number | false);
|
|
17
|
+
get httpsPort(): string | number | false;
|
|
18
|
+
set httpsPort(value: string | number | false);
|
|
19
|
+
get mount(): Record<string, TokenProvider[]>;
|
|
20
|
+
set mount(value: Record<string, TokenProvider[]>);
|
|
21
|
+
get statics(): Record<string, (any | string)[]>;
|
|
22
|
+
set statics(value: Record<string, (any | string)[]>);
|
|
23
|
+
get acceptMimes(): string[];
|
|
24
|
+
set acceptMimes(value: string[]);
|
|
25
|
+
get jsonMapper(): Partial<PlatformJsonMapperSettings>;
|
|
26
|
+
set jsonMapper(options: Partial<PlatformJsonMapperSettings>);
|
|
27
|
+
get additionalProperties(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @returns {string|number}
|
|
31
|
+
*/
|
|
32
|
+
getHttpPort(): ReturnType<typeof getHostInfoFromPort>;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param settings
|
|
36
|
+
*/
|
|
37
|
+
setHttpPort(settings: {
|
|
38
|
+
address: string;
|
|
39
|
+
port: number;
|
|
40
|
+
}): void;
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @returns {string|number}
|
|
44
|
+
*/
|
|
45
|
+
getHttpsPort(): {
|
|
46
|
+
protocol: string;
|
|
47
|
+
address: string;
|
|
48
|
+
port: number;
|
|
49
|
+
toString(): string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param settings
|
|
54
|
+
*/
|
|
55
|
+
setHttpsPort(settings: {
|
|
56
|
+
address: string;
|
|
57
|
+
port: number;
|
|
58
|
+
}): void;
|
|
59
|
+
getBestHost(): {
|
|
60
|
+
protocol: string;
|
|
61
|
+
address: string;
|
|
62
|
+
port: number;
|
|
63
|
+
toString(): string;
|
|
64
|
+
} | {
|
|
65
|
+
toString(): string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
declare global {
|
|
69
|
+
namespace TsED {
|
|
70
|
+
interface Context {
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Here to allow extension on DIConfiguration base service
|
|
74
|
+
*/
|
|
75
|
+
interface DIConfiguration extends PlatformConfiguration {
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ROUTER_OPTIONS: unique symbol;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define file size limit.
|
|
3
|
+
*
|
|
4
|
+
* ```typescript
|
|
5
|
+
* import {Post} from "@tsed/schema";
|
|
6
|
+
* import {MulterOptions, MultipartFile} from "@tsed/platform-http";
|
|
7
|
+
* import {Controller} from "@tsed/di";
|
|
8
|
+
* import {Multer} from "@types/multer";
|
|
9
|
+
*
|
|
10
|
+
* type MulterFile = Express.Multer.File;
|
|
11
|
+
*
|
|
12
|
+
* @Controller('/')
|
|
13
|
+
* class MyCtrl {
|
|
14
|
+
* @Post('/file2')
|
|
15
|
+
* @MulterFileSize(1024) // (Ko). Applied for all fields
|
|
16
|
+
* private uploadFile(@MultipartFile("file1") file: MulterFile, @MultipartFile("file2") file2: MulterFile) {
|
|
17
|
+
*
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* > See the tutorial on the [multer configuration](/tutorials/multer.md).
|
|
23
|
+
* @param fileSize
|
|
24
|
+
* @returns {(target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor}
|
|
25
|
+
* @decorator
|
|
26
|
+
* @multer
|
|
27
|
+
*/
|
|
28
|
+
export declare function MulterFileSize(fileSize: number): MethodDecorator;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PlatformMulterSettings } from "../../config/interfaces/PlatformMulterSettings.js";
|
|
2
|
+
/**
|
|
3
|
+
* Define multer option for all MultipartFile
|
|
4
|
+
*
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import {PlatformMulterFile, MultipartFile, MulterOptions} from "@tsed/platform-http";
|
|
7
|
+
* import {Controller} from "@tsed/di";
|
|
8
|
+
* import {Post} from "@tsed/schema";
|
|
9
|
+
*
|
|
10
|
+
* @Controller('/')
|
|
11
|
+
* class MyCtrl {
|
|
12
|
+
* @Post('/file')
|
|
13
|
+
* private uploadFile(@MultipartFile("file1") file: PlatformMulterFile) {
|
|
14
|
+
*
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* @Post('/file')
|
|
18
|
+
* @MulterOptions({dest: "/other-dir"})
|
|
19
|
+
* private uploadFile(@MultipartFile("file1") file: PlatformMulterFile) {
|
|
20
|
+
*
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* @Post('/file2')
|
|
24
|
+
* @MulterOptions({dest: "/other-dir"})
|
|
25
|
+
* private uploadFile(@MultipartFile("file1") file: PlatformMulterFile, @MultipartFile("file2") file2: PlatformMulterFile) {
|
|
26
|
+
*
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* @Post('/files')
|
|
30
|
+
* private uploadFile(@MultipartFile("file1") files: PlatformMulterFile[]) {
|
|
31
|
+
*
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* See the tutorial on the [multer configuration](/tutorials/multer.md).
|
|
37
|
+
*
|
|
38
|
+
* @param {multer.Options} options
|
|
39
|
+
* @returns {(target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor}
|
|
40
|
+
* @decorator
|
|
41
|
+
* @multer
|
|
42
|
+
*/
|
|
43
|
+
export declare function MulterOptions(options: PlatformMulterSettings): MethodDecorator;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { PlatformMulterFile } from "../../config/interfaces/PlatformMulterSettings.js";
|
|
2
|
+
/**
|
|
3
|
+
* Define a parameter as Multipart file.
|
|
4
|
+
*
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import {Post} from "@tsed/schema";
|
|
7
|
+
* import {Controller, 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('/file')
|
|
16
|
+
* private uploadFile(@MultipartFile("file1") file: MulterFile) {
|
|
17
|
+
*
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* @Post('/file')
|
|
21
|
+
* @MulterOptions({dest: "/other-dir"})
|
|
22
|
+
* private uploadFile(@MultipartFile("file1") file: MulterFile) {
|
|
23
|
+
*
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* @Post('/file2')
|
|
27
|
+
* @MulterOptions({dest: "/other-dir"})
|
|
28
|
+
* private uploadFile(@MultipartFile("file1") file: MulterFile, @MultipartFile("file2") file2: MulterFile) {
|
|
29
|
+
*
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* @Post('/files')
|
|
33
|
+
* private uploadFile(@MultipartFile("file1") files: MulterFile[]) {
|
|
34
|
+
*
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* > See the tutorial on the [multer configuration](/tutorials/multer.md).
|
|
40
|
+
*
|
|
41
|
+
* @param name
|
|
42
|
+
* @param maxCount
|
|
43
|
+
* @returns Function
|
|
44
|
+
* @decorator
|
|
45
|
+
* @input
|
|
46
|
+
*/
|
|
47
|
+
export declare function MultipartFile(name: string, maxCount?: number): ParameterDecorator;
|
|
48
|
+
export type MultipartFile = PlatformMulterFile;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the Next function (for express application and middleware).
|
|
3
|
+
*
|
|
4
|
+
* @decorator
|
|
5
|
+
* @operation
|
|
6
|
+
* @input
|
|
7
|
+
*/
|
|
8
|
+
export declare function Next(): ParameterDecorator;
|
|
9
|
+
declare global {
|
|
10
|
+
namespace TsED {
|
|
11
|
+
interface NextFunction extends Function {
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get the Next function (for express application and middleware).
|
|
17
|
+
*
|
|
18
|
+
* @decorator
|
|
19
|
+
* @operation
|
|
20
|
+
* @input
|
|
21
|
+
*/
|
|
22
|
+
export type Next = TsED.NextFunction;
|