@tsed/di 6.72.2 → 6.73.2
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/lib/decorators/controller.d.ts +43 -0
- package/lib/decorators/index.d.ts +1 -0
- package/lib/index.js +64 -4
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +65 -6
- package/lib/index.modern.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
import { IProvider } from "../interfaces/IProvider";
|
|
3
|
+
export declare type PathType = string | RegExp | (string | RegExp)[];
|
|
4
|
+
export interface ControllerMiddlewares {
|
|
5
|
+
useBefore: any[];
|
|
6
|
+
use: any[];
|
|
7
|
+
useAfter: any[];
|
|
8
|
+
}
|
|
9
|
+
export interface ControllerOptions extends Partial<IProvider<any>> {
|
|
10
|
+
path?: PathType;
|
|
11
|
+
children?: Type<any>[];
|
|
12
|
+
routerOptions?: any;
|
|
13
|
+
middlewares?: Partial<ControllerMiddlewares>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Declare a new controller with his Rest path. His methods annotated will be collected to build the routing list.
|
|
17
|
+
* This routing listing will be built with the `express.Router` object.
|
|
18
|
+
*
|
|
19
|
+
* ::: tip
|
|
20
|
+
* See [Controllers](/docs/controllers.md) section for more details
|
|
21
|
+
* :::
|
|
22
|
+
*
|
|
23
|
+
* ```typescript
|
|
24
|
+
* @Controller("/calendars")
|
|
25
|
+
* export provide CalendarCtrl {
|
|
26
|
+
*
|
|
27
|
+
* @Get("/:id")
|
|
28
|
+
* public get(
|
|
29
|
+
* @Req() request: Req,
|
|
30
|
+
* @Res() response: Res,
|
|
31
|
+
* @Next() next: Next
|
|
32
|
+
* ): void {
|
|
33
|
+
*
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @param options
|
|
39
|
+
* @controller
|
|
40
|
+
* @decorator
|
|
41
|
+
* @classDecorator
|
|
42
|
+
*/
|
|
43
|
+
export declare function Controller(options: PathType | ControllerOptions): ClassDecorator;
|
package/lib/index.js
CHANGED
|
@@ -600,7 +600,7 @@ class ContextLogger {
|
|
|
600
600
|
|
|
601
601
|
}
|
|
602
602
|
|
|
603
|
-
const _excluded$
|
|
603
|
+
const _excluded$2 = ["id", "injector", "logger", "ignoreLog"];
|
|
604
604
|
class DIContext extends Map {
|
|
605
605
|
constructor(_ref) {
|
|
606
606
|
let {
|
|
@@ -609,7 +609,7 @@ class DIContext extends Map {
|
|
|
609
609
|
logger,
|
|
610
610
|
ignoreLog
|
|
611
611
|
} = _ref,
|
|
612
|
-
options = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
612
|
+
options = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
613
613
|
|
|
614
614
|
super();
|
|
615
615
|
/**
|
|
@@ -1086,7 +1086,7 @@ function Configuration(configuration = {}) {
|
|
|
1086
1086
|
};
|
|
1087
1087
|
}
|
|
1088
1088
|
|
|
1089
|
-
const _excluded = ["scopes", "imports", "resolvers", "deps", "scope"];
|
|
1089
|
+
const _excluded$1 = ["scopes", "imports", "resolvers", "deps", "scope"];
|
|
1090
1090
|
/**
|
|
1091
1091
|
* Declare a new Ts.ED module
|
|
1092
1092
|
*
|
|
@@ -1105,7 +1105,7 @@ function Module(options = {}) {
|
|
|
1105
1105
|
resolvers,
|
|
1106
1106
|
deps
|
|
1107
1107
|
} = options,
|
|
1108
|
-
configuration = _objectWithoutPropertiesLoose(options, _excluded);
|
|
1108
|
+
configuration = _objectWithoutPropertiesLoose(options, _excluded$1);
|
|
1109
1109
|
|
|
1110
1110
|
return core.useDecorators(Configuration(configuration), Injectable({
|
|
1111
1111
|
type: exports.ProviderType.MODULE,
|
|
@@ -1226,6 +1226,65 @@ function UseOpts(options) {
|
|
|
1226
1226
|
};
|
|
1227
1227
|
}
|
|
1228
1228
|
|
|
1229
|
+
const _excluded = ["children"];
|
|
1230
|
+
|
|
1231
|
+
function mapOptions(options) {
|
|
1232
|
+
if (typeof options === "string" || options instanceof RegExp || core.isArrayOrArrayClass(options)) {
|
|
1233
|
+
return {
|
|
1234
|
+
path: options
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
return options;
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Declare a new controller with his Rest path. His methods annotated will be collected to build the routing list.
|
|
1242
|
+
* This routing listing will be built with the `express.Router` object.
|
|
1243
|
+
*
|
|
1244
|
+
* ::: tip
|
|
1245
|
+
* See [Controllers](/docs/controllers.md) section for more details
|
|
1246
|
+
* :::
|
|
1247
|
+
*
|
|
1248
|
+
* ```typescript
|
|
1249
|
+
* @Controller("/calendars")
|
|
1250
|
+
* export provide CalendarCtrl {
|
|
1251
|
+
*
|
|
1252
|
+
* @Get("/:id")
|
|
1253
|
+
* public get(
|
|
1254
|
+
* @Req() request: Req,
|
|
1255
|
+
* @Res() response: Res,
|
|
1256
|
+
* @Next() next: Next
|
|
1257
|
+
* ): void {
|
|
1258
|
+
*
|
|
1259
|
+
* }
|
|
1260
|
+
* }
|
|
1261
|
+
* ```
|
|
1262
|
+
*
|
|
1263
|
+
* @param options
|
|
1264
|
+
* @controller
|
|
1265
|
+
* @decorator
|
|
1266
|
+
* @classDecorator
|
|
1267
|
+
*/
|
|
1268
|
+
|
|
1269
|
+
|
|
1270
|
+
function Controller(options) {
|
|
1271
|
+
const _mapOptions = mapOptions(options),
|
|
1272
|
+
{
|
|
1273
|
+
children = []
|
|
1274
|
+
} = _mapOptions,
|
|
1275
|
+
opts = _objectWithoutPropertiesLoose(_mapOptions, _excluded);
|
|
1276
|
+
|
|
1277
|
+
return target => {
|
|
1278
|
+
registerController(_extends({
|
|
1279
|
+
provide: target
|
|
1280
|
+
}, opts));
|
|
1281
|
+
core.Store.from(target).set("childrenControllers", children);
|
|
1282
|
+
children.forEach(childToken => {
|
|
1283
|
+
core.Store.from(childToken).set("parentController", target);
|
|
1284
|
+
});
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1229
1288
|
class InjectionError extends Error {
|
|
1230
1289
|
constructor(token, origin) {
|
|
1231
1290
|
super(core.isString(origin) ? origin : "");
|
|
@@ -2238,6 +2297,7 @@ exports.Configuration = Configuration;
|
|
|
2238
2297
|
exports.Constant = Constant;
|
|
2239
2298
|
exports.Container = Container;
|
|
2240
2299
|
exports.ContextLogger = ContextLogger;
|
|
2300
|
+
exports.Controller = Controller;
|
|
2241
2301
|
exports.DIConfiguration = DIConfiguration;
|
|
2242
2302
|
exports.DIContext = DIContext;
|
|
2243
2303
|
exports.DITest = DITest;
|