@tsed/platform-middlewares 6.88.1 → 6.92.0
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/{constants → cjs/constants}/index.d.ts +0 -0
- package/lib/cjs/constants/index.js +34 -0
- package/lib/cjs/constants/index.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/authOptions.d.ts +0 -0
- package/lib/cjs/decorators/authOptions.js +58 -0
- package/lib/cjs/decorators/authOptions.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/middleware.d.ts +0 -0
- package/lib/cjs/decorators/middleware.js +17 -0
- package/lib/cjs/decorators/middleware.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/use.d.ts +0 -0
- package/lib/cjs/decorators/use.js +43 -0
- package/lib/cjs/decorators/use.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/useAfter.d.ts +0 -0
- package/lib/cjs/decorators/useAfter.js +46 -0
- package/lib/cjs/decorators/useAfter.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/useAuth.d.ts +0 -0
- package/lib/cjs/decorators/useAuth.js +45 -0
- package/lib/cjs/decorators/useAuth.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/useBefore.d.ts +0 -0
- package/lib/cjs/decorators/useBefore.js +45 -0
- package/lib/cjs/decorators/useBefore.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/useBeforeEach.d.ts +0 -0
- package/lib/cjs/decorators/useBeforeEach.js +40 -0
- package/lib/cjs/decorators/useBeforeEach.js.map +1 -0
- package/lib/{domain → cjs/domain}/MiddlewareMethods.d.ts +0 -0
- package/lib/cjs/domain/MiddlewareMethods.js +3 -0
- package/lib/cjs/domain/MiddlewareMethods.js.map +1 -0
- package/lib/{domain → cjs/domain}/PlatformMiddlewareSettings.d.ts +0 -0
- package/lib/cjs/domain/PlatformMiddlewareSettings.js +3 -0
- package/lib/cjs/domain/PlatformMiddlewareSettings.js.map +1 -0
- package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- package/lib/cjs/index.js +17 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/{utils → cjs/utils}/getMiddlewaresForHook.d.ts +0 -0
- package/lib/cjs/utils/getMiddlewaresForHook.js +26 -0
- package/lib/cjs/utils/getMiddlewaresForHook.js.map +1 -0
- package/lib/{utils → cjs/utils}/mapUseOptions.d.ts +0 -0
- package/lib/cjs/utils/mapUseOptions.js +26 -0
- package/lib/cjs/utils/mapUseOptions.js.map +1 -0
- package/lib/esm/constants/index.js +31 -0
- package/lib/esm/constants/index.js.map +1 -0
- package/lib/esm/decorators/authOptions.js +54 -0
- package/lib/esm/decorators/authOptions.js.map +1 -0
- package/lib/esm/decorators/middleware.js +13 -0
- package/lib/esm/decorators/middleware.js.map +1 -0
- package/lib/esm/decorators/use.js +39 -0
- package/lib/esm/decorators/use.js.map +1 -0
- package/lib/esm/decorators/useAfter.js +42 -0
- package/lib/esm/decorators/useAfter.js.map +1 -0
- package/lib/esm/decorators/useAuth.js +41 -0
- package/lib/esm/decorators/useAuth.js.map +1 -0
- package/lib/esm/decorators/useBefore.js +41 -0
- package/lib/esm/decorators/useBefore.js.map +1 -0
- package/lib/esm/decorators/useBeforeEach.js +36 -0
- package/lib/esm/decorators/useBeforeEach.js.map +1 -0
- package/lib/esm/domain/MiddlewareMethods.js +2 -0
- package/lib/esm/domain/MiddlewareMethods.js.map +1 -0
- package/lib/esm/domain/PlatformMiddlewareSettings.js +2 -0
- package/lib/esm/domain/PlatformMiddlewareSettings.js.map +1 -0
- package/lib/esm/index.js +14 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/utils/getMiddlewaresForHook.js +22 -0
- package/lib/esm/utils/getMiddlewaresForHook.js.map +1 -0
- package/lib/esm/utils/mapUseOptions.js +22 -0
- package/lib/esm/utils/mapUseOptions.js.map +1 -0
- package/lib/types/constants/index.d.ts +1 -0
- package/lib/types/decorators/authOptions.d.ts +42 -0
- package/lib/types/decorators/middleware.d.ts +7 -0
- package/lib/types/decorators/use.d.ts +22 -0
- package/lib/types/decorators/useAfter.d.ts +21 -0
- package/lib/types/decorators/useAuth.d.ts +23 -0
- package/lib/types/decorators/useBefore.d.ts +21 -0
- package/lib/types/decorators/useBeforeEach.d.ts +21 -0
- package/lib/types/domain/MiddlewareMethods.d.ts +8 -0
- package/lib/types/domain/PlatformMiddlewareSettings.d.ts +17 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/utils/getMiddlewaresForHook.d.ts +2 -0
- package/lib/types/utils/mapUseOptions.d.ts +5 -0
- package/package.json +16 -12
- package/tsconfig.compile.esm.json +23 -0
- package/lib/index.js +0 -326
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -319
- package/lib/index.modern.js.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Injectable, ProviderType } from "@tsed/di";
|
|
2
|
+
/**
|
|
3
|
+
* Register a new Middleware class.
|
|
4
|
+
*
|
|
5
|
+
* @decorator
|
|
6
|
+
* @classDecorator
|
|
7
|
+
*/
|
|
8
|
+
export function Middleware() {
|
|
9
|
+
return Injectable({
|
|
10
|
+
type: ProviderType.MIDDLEWARE
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/decorators/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,YAAY,EAAC,MAAM,UAAU,CAAC;AAElD;;;;;GAKG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,UAAU,CAAC;QAChB,IAAI,EAAE,YAAY,CAAC,UAAU;KAC9B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {Injectable, ProviderType} from \"@tsed/di\";\n\n/**\n * Register a new Middleware class.\n *\n * @decorator\n * @classDecorator\n */\nexport function Middleware(): ClassDecorator {\n return Injectable({\n type: ProviderType.MIDDLEWARE\n });\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DecoratorTypes, UnsupportedDecoratorType } from "@tsed/core";
|
|
2
|
+
import { JsonEntityFn, Route } from "@tsed/schema";
|
|
3
|
+
/**
|
|
4
|
+
* Mounts the specified middleware function or functions at the specified path: the middleware function is executed when
|
|
5
|
+
* the base of the requested path matches `path.
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @Controller('/')
|
|
9
|
+
* @Use(Middleware1)
|
|
10
|
+
* export class Ctrl {
|
|
11
|
+
*
|
|
12
|
+
* @Get('/')
|
|
13
|
+
* @Use(Middleware2)
|
|
14
|
+
* get() { }
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @returns {Function}
|
|
20
|
+
* @param args
|
|
21
|
+
* @decorator
|
|
22
|
+
* @operation
|
|
23
|
+
*/
|
|
24
|
+
export function Use(...args) {
|
|
25
|
+
return JsonEntityFn((entity, parameters) => {
|
|
26
|
+
switch (entity.decoratorType) {
|
|
27
|
+
case DecoratorTypes.METHOD:
|
|
28
|
+
return Route(...args);
|
|
29
|
+
case DecoratorTypes.CLASS:
|
|
30
|
+
entity.store.merge("middlewares", {
|
|
31
|
+
use: args
|
|
32
|
+
});
|
|
33
|
+
break;
|
|
34
|
+
default:
|
|
35
|
+
throw new UnsupportedDecoratorType(Use, parameters);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=use.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use.js","sourceRoot":"","sources":["../../../src/decorators/use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAC,YAAY,EAAmC,KAAK,EAAC,MAAM,cAAc,CAAC;AAGlF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,GAAG,CAAC,GAAG,IAAW;IAChC,OAAO,YAAY,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;QACzC,QAAQ,MAAM,CAAC,aAAa,EAAE;YAC5B,KAAK,cAAc,CAAC,MAAM;gBACxB,OAAO,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAExB,KAAK,cAAc,CAAC,KAAK;gBACvB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,EAAE;oBAChC,GAAG,EAAE,IAAI;iBACV,CAAC,CAAC;gBACH,MAAM;YAER;gBACE,MAAM,IAAI,wBAAwB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;SACvD;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {DecoratorTypes, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {JsonEntityFn, OperationMethods, OperationPath, Route} from \"@tsed/schema\";\nimport {mapUseOptions} from \"../utils/mapUseOptions\";\n\n/**\n * Mounts the specified middleware function or functions at the specified path: the middleware function is executed when\n * the base of the requested path matches `path.\n *\n * ```typescript\n * @Controller('/')\n * @Use(Middleware1)\n * export class Ctrl {\n *\n * @Get('/')\n * @Use(Middleware2)\n * get() { }\n * }\n *\n * ```\n *\n * @returns {Function}\n * @param args\n * @decorator\n * @operation\n */\nexport function Use(...args: any[]): Function {\n return JsonEntityFn((entity, parameters) => {\n switch (entity.decoratorType) {\n case DecoratorTypes.METHOD:\n return Route(...args);\n\n case DecoratorTypes.CLASS:\n entity.store.merge(\"middlewares\", {\n use: args\n });\n break;\n\n default:\n throw new UnsupportedDecoratorType(Use, parameters);\n }\n });\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DecoratorTypes, UnsupportedDecoratorType } from "@tsed/core";
|
|
2
|
+
import { JsonEntityFn } from "@tsed/schema";
|
|
3
|
+
/**
|
|
4
|
+
* Mounts the specified middleware function or functions at the specified path: the middleware function is executed when
|
|
5
|
+
* the base of the requested path matches `path.
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @Controller('/')
|
|
9
|
+
* @UseAfter(Middleware1)
|
|
10
|
+
* export class Ctrl {
|
|
11
|
+
*
|
|
12
|
+
* @Get('/')
|
|
13
|
+
* @UseAfter(Middleware2)
|
|
14
|
+
* get() { }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @returns {function(any, any, any): *}
|
|
19
|
+
* @param args
|
|
20
|
+
* @decorator
|
|
21
|
+
* @operation
|
|
22
|
+
*/
|
|
23
|
+
export function UseAfter(...args) {
|
|
24
|
+
return JsonEntityFn((entity, parameters) => {
|
|
25
|
+
switch (entity.decoratorType) {
|
|
26
|
+
case DecoratorTypes.METHOD:
|
|
27
|
+
const endpoint = entity;
|
|
28
|
+
endpoint.afterMiddlewares = args.concat(endpoint.afterMiddlewares);
|
|
29
|
+
break;
|
|
30
|
+
case DecoratorTypes.CLASS:
|
|
31
|
+
const middlewares = entity.store.get("middlewares") || {};
|
|
32
|
+
entity.store.set("middlewares", {
|
|
33
|
+
...middlewares,
|
|
34
|
+
useAfter: [...args, ...(middlewares.useAfter || [])]
|
|
35
|
+
});
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
throw new UnsupportedDecoratorType(UseAfter, parameters);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=useAfter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAfter.js","sourceRoot":"","sources":["../../../src/decorators/useAfter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAG,IAAW;IACrC,OAAO,YAAY,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;QACzC,QAAQ,MAAM,CAAC,aAAa,EAAE;YAC5B,KAAK,cAAc,CAAC,MAAM;gBACxB,MAAM,QAAQ,GAAG,MAAM,CAAC;gBACxB,QAAQ,CAAC,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;gBAEnE,MAAM;YAER,KAAK,cAAc,CAAC,KAAK;gBACvB,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;gBAE1D,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE;oBAC9B,GAAG,WAAW;oBACd,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,WAAW,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;iBACrD,CAAC,CAAC;gBACH,MAAM;YAER;gBACE,MAAM,IAAI,wBAAwB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;SAC5D;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {DecoratorTypes, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {JsonEntityFn} from \"@tsed/schema\";\n\n/**\n * Mounts the specified middleware function or functions at the specified path: the middleware function is executed when\n * the base of the requested path matches `path.\n *\n * ```typescript\n * @Controller('/')\n * @UseAfter(Middleware1)\n * export class Ctrl {\n *\n * @Get('/')\n * @UseAfter(Middleware2)\n * get() { }\n * }\n * ```\n *\n * @returns {function(any, any, any): *}\n * @param args\n * @decorator\n * @operation\n */\nexport function UseAfter(...args: any[]): Function {\n return JsonEntityFn((entity, parameters) => {\n switch (entity.decoratorType) {\n case DecoratorTypes.METHOD:\n const endpoint = entity;\n endpoint.afterMiddlewares = args.concat(endpoint.afterMiddlewares);\n\n break;\n\n case DecoratorTypes.CLASS:\n const middlewares = entity.store.get(\"middlewares\") || {};\n\n entity.store.set(\"middlewares\", {\n ...middlewares,\n useAfter: [...args, ...(middlewares.useAfter || [])]\n });\n break;\n\n default:\n throw new UnsupportedDecoratorType(UseAfter, parameters);\n }\n });\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { decorateMethodsOf, decoratorTypeOf, DecoratorTypes, StoreFn, UnsupportedDecoratorType, useDecorators } from "@tsed/core";
|
|
2
|
+
import { AuthOptions } from "./authOptions";
|
|
3
|
+
import { UseBefore } from "./useBefore";
|
|
4
|
+
/**
|
|
5
|
+
* Use custom authentication strategy on your endpoint.
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @Controller('/mypath')
|
|
9
|
+
* @UseAuth(MyAuthStrategy)
|
|
10
|
+
* class MyCtrl {
|
|
11
|
+
*
|
|
12
|
+
* @Get('/')
|
|
13
|
+
* @UseAuth(MyAuthStrategy, {role: 'admin'})
|
|
14
|
+
* public getResource(){}
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param guardAuth {Type<any>} A middleware which implement a custom auth strategy
|
|
19
|
+
* @param options {Object} Object passed to the customer auth strategy
|
|
20
|
+
* @returns {Function}
|
|
21
|
+
* @decorator
|
|
22
|
+
* @operation
|
|
23
|
+
*/
|
|
24
|
+
export function UseAuth(guardAuth, options = {}) {
|
|
25
|
+
return (...args) => {
|
|
26
|
+
switch (decoratorTypeOf(args)) {
|
|
27
|
+
case DecoratorTypes.METHOD:
|
|
28
|
+
return useDecorators(StoreFn((store) => {
|
|
29
|
+
if (!store.has(guardAuth)) {
|
|
30
|
+
return UseBefore(guardAuth);
|
|
31
|
+
}
|
|
32
|
+
}), AuthOptions(guardAuth, options))(...args);
|
|
33
|
+
case DecoratorTypes.CLASS:
|
|
34
|
+
decorateMethodsOf(args[0], UseAuth(guardAuth, options));
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
throw new UnsupportedDecoratorType(UseAuth, args);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=useAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuth.js","sourceRoot":"","sources":["../../../src/decorators/useAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAEjB,eAAe,EACf,cAAc,EAEd,OAAO,EAEP,wBAAwB,EACxB,aAAa,EACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAC,WAAW,EAAe,MAAM,eAAe,CAAC;AACxD,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,OAAO,CAAC,SAAoB,EAAE,UAAwB,EAAE;IACtE,OAAO,CAAI,GAAG,IAAyB,EAAqC,EAAE;QAC5E,QAAQ,eAAe,CAAC,IAAI,CAAC,EAAE;YAC7B,KAAK,cAAc,CAAC,MAAM;gBACxB,OAAO,aAAa,CAClB,OAAO,CAAC,CAAC,KAAY,EAAE,EAAE;oBACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;wBACzB,OAAO,SAAS,CAAC,SAAS,CAAC,CAAC;qBAC7B;gBACH,CAAC,CAAC,EACF,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAChC,CAAC,GAAG,IAAI,CAAC,CAAC;YAEb,KAAK,cAAc,CAAC,KAAK;gBACvB,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;gBACxD,MAAM;YAER;gBACE,MAAM,IAAI,wBAAwB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;SACrD;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n decorateMethodsOf,\n DecoratorParameters,\n decoratorTypeOf,\n DecoratorTypes,\n Store,\n StoreFn,\n Type,\n UnsupportedDecoratorType,\n useDecorators\n} from \"@tsed/core\";\nimport {AuthOptions, IAuthOptions} from \"./authOptions\";\nimport {UseBefore} from \"./useBefore\";\n\n/**\n * Use custom authentication strategy on your endpoint.\n *\n * ```typescript\n * @Controller('/mypath')\n * @UseAuth(MyAuthStrategy)\n * class MyCtrl {\n *\n * @Get('/')\n * @UseAuth(MyAuthStrategy, {role: 'admin'})\n * public getResource(){}\n * }\n * ```\n *\n * @param guardAuth {Type<any>} A middleware which implement a custom auth strategy\n * @param options {Object} Object passed to the customer auth strategy\n * @returns {Function}\n * @decorator\n * @operation\n */\nexport function UseAuth(guardAuth: Type<any>, options: IAuthOptions = {}): Function {\n return <T>(...args: DecoratorParameters): TypedPropertyDescriptor<T> | void => {\n switch (decoratorTypeOf(args)) {\n case DecoratorTypes.METHOD:\n return useDecorators(\n StoreFn((store: Store) => {\n if (!store.has(guardAuth)) {\n return UseBefore(guardAuth);\n }\n }),\n AuthOptions(guardAuth, options)\n )(...args);\n\n case DecoratorTypes.CLASS:\n decorateMethodsOf(args[0], UseAuth(guardAuth, options));\n break;\n\n default:\n throw new UnsupportedDecoratorType(UseAuth, args);\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DecoratorTypes, UnsupportedDecoratorType } from "@tsed/core";
|
|
2
|
+
import { JsonEntityFn } from "@tsed/schema";
|
|
3
|
+
/**
|
|
4
|
+
* Mounts the specified middleware function or functions at the specified path: the middleware function is executed when
|
|
5
|
+
* the base of the requested path matches `path.
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @Controller('/')
|
|
9
|
+
* @UseBefore(Middleware1) // called only one time before all endpoint
|
|
10
|
+
* export class Ctrl {
|
|
11
|
+
*
|
|
12
|
+
* @Get('/')
|
|
13
|
+
* @UseBefore(Middleware2)
|
|
14
|
+
* get() { }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @returns {function(any, any, any): *}
|
|
19
|
+
* @param args
|
|
20
|
+
* @decorator
|
|
21
|
+
* @operation
|
|
22
|
+
*/
|
|
23
|
+
export function UseBefore(...args) {
|
|
24
|
+
return JsonEntityFn((entity, parameters) => {
|
|
25
|
+
switch (entity.decoratorType) {
|
|
26
|
+
case DecoratorTypes.METHOD:
|
|
27
|
+
entity.beforeMiddlewares = args.concat(entity.beforeMiddlewares);
|
|
28
|
+
break;
|
|
29
|
+
case DecoratorTypes.CLASS:
|
|
30
|
+
const middlewares = entity.store.get("middlewares") || {};
|
|
31
|
+
entity.store.set("middlewares", {
|
|
32
|
+
...middlewares,
|
|
33
|
+
useBefore: [...args, ...(middlewares.useBefore || [])]
|
|
34
|
+
});
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
throw new UnsupportedDecoratorType(UseBefore, parameters);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=useBefore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBefore.js","sourceRoot":"","sources":["../../../src/decorators/useBefore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,SAAS,CAAC,GAAG,IAAW;IACtC,OAAO,YAAY,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;QACzC,QAAQ,MAAM,CAAC,aAAa,EAAE;YAC5B,KAAK,cAAc,CAAC,MAAM;gBACxB,MAAM,CAAC,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;gBAEjE,MAAM;YAER,KAAK,cAAc,CAAC,KAAK;gBACvB,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;gBAE1D,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE;oBAC9B,GAAG,WAAW;oBACd,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,WAAW,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;iBACvD,CAAC,CAAC;gBACH,MAAM;YAER;gBACE,MAAM,IAAI,wBAAwB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;SAC7D;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {DecoratorTypes, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {JsonEntityFn} from \"@tsed/schema\";\n\n/**\n * Mounts the specified middleware function or functions at the specified path: the middleware function is executed when\n * the base of the requested path matches `path.\n *\n * ```typescript\n * @Controller('/')\n * @UseBefore(Middleware1) // called only one time before all endpoint\n * export class Ctrl {\n *\n * @Get('/')\n * @UseBefore(Middleware2)\n * get() { }\n * }\n * ```\n *\n * @returns {function(any, any, any): *}\n * @param args\n * @decorator\n * @operation\n */\nexport function UseBefore(...args: any[]): Function {\n return JsonEntityFn((entity, parameters) => {\n switch (entity.decoratorType) {\n case DecoratorTypes.METHOD:\n entity.beforeMiddlewares = args.concat(entity.beforeMiddlewares);\n\n break;\n\n case DecoratorTypes.CLASS:\n const middlewares = entity.store.get(\"middlewares\") || {};\n\n entity.store.set(\"middlewares\", {\n ...middlewares,\n useBefore: [...args, ...(middlewares.useBefore || [])]\n });\n break;\n\n default:\n throw new UnsupportedDecoratorType(UseBefore, parameters);\n }\n });\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { decorateMethodsOf, decoratorTypeOf, DecoratorTypes, UnsupportedDecoratorType } from "@tsed/core";
|
|
2
|
+
import { UseBefore } from "./useBefore";
|
|
3
|
+
/**
|
|
4
|
+
* Mounts the specified middleware function or functions at the specified path: the middleware function is executed when
|
|
5
|
+
* the base of the requested path matches `path.
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @Controller('/')
|
|
9
|
+
* @UseBeforeEach(Middleware1) // Called before each endpoint
|
|
10
|
+
* export class Ctrl {
|
|
11
|
+
*
|
|
12
|
+
* @Get('/')
|
|
13
|
+
* get() { }
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @returns {Function}
|
|
19
|
+
* @param args
|
|
20
|
+
* @decorator
|
|
21
|
+
* @operation
|
|
22
|
+
*/
|
|
23
|
+
export function UseBeforeEach(...args) {
|
|
24
|
+
return (...decoratorArgs) => {
|
|
25
|
+
switch (decoratorTypeOf(decoratorArgs)) {
|
|
26
|
+
case DecoratorTypes.METHOD:
|
|
27
|
+
return UseBefore(...args)(...decoratorArgs);
|
|
28
|
+
case DecoratorTypes.CLASS:
|
|
29
|
+
decorateMethodsOf(decoratorArgs[0], UseBefore(...args));
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
throw new UnsupportedDecoratorType(UseBeforeEach, decoratorArgs);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=useBeforeEach.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBeforeEach.js","sourceRoot":"","sources":["../../../src/decorators/useBeforeEach.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAuB,eAAe,EAAE,cAAc,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;AAC7H,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,aAAa,CAAC,GAAG,IAAW;IAC1C,OAAO,CAAI,GAAG,aAAkC,EAAqC,EAAE;QACrF,QAAQ,eAAe,CAAC,aAAa,CAAC,EAAE;YACtC,KAAK,cAAc,CAAC,MAAM;gBACxB,OAAO,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC;YAE9C,KAAK,cAAc,CAAC,KAAK;gBACvB,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;gBACxD,MAAM;YAER;gBACE,MAAM,IAAI,wBAAwB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;SACpE;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {decorateMethodsOf, DecoratorParameters, decoratorTypeOf, DecoratorTypes, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {UseBefore} from \"./useBefore\";\n\n/**\n * Mounts the specified middleware function or functions at the specified path: the middleware function is executed when\n * the base of the requested path matches `path.\n *\n * ```typescript\n * @Controller('/')\n * @UseBeforeEach(Middleware1) // Called before each endpoint\n * export class Ctrl {\n *\n * @Get('/')\n * get() { }\n * }\n *\n * ```\n *\n * @returns {Function}\n * @param args\n * @decorator\n * @operation\n */\nexport function UseBeforeEach(...args: any[]): Function {\n return <T>(...decoratorArgs: DecoratorParameters): TypedPropertyDescriptor<T> | void => {\n switch (decoratorTypeOf(decoratorArgs)) {\n case DecoratorTypes.METHOD:\n return UseBefore(...args)(...decoratorArgs);\n\n case DecoratorTypes.CLASS:\n decorateMethodsOf(decoratorArgs[0], UseBefore(...args));\n break;\n\n default:\n throw new UnsupportedDecoratorType(UseBeforeEach, decoratorArgs);\n }\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareMethods.js","sourceRoot":"","sources":["../../../src/domain/MiddlewareMethods.ts"],"names":[],"mappings":"","sourcesContent":["export interface MiddlewareMethods {\n use(...args: any[]): void | any | Promise<any>;\n}\n\n/**\n * @deprecated Since v6. Use MiddlewareMethods instead\n */\nexport interface IMiddleware extends MiddlewareMethods {}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformMiddlewareSettings.js","sourceRoot":"","sources":["../../../src/domain/PlatformMiddlewareSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {Env, Type} from \"@tsed/core\";\n\nexport type PlatformMiddlewareLoadingOptions = {env?: Env; use: Function | Type<any>; hook?: string};\nexport type PlatformMiddlewareSettings = Function | Type<any> | PlatformMiddlewareLoadingOptions | any;\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n /**\n * Load middlewares on the $beforeRoutesInit hook (or on the specified hook event name).\n */\n middlewares: PlatformMiddlewareSettings[];\n }\n }\n}\n"]}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// decorators
|
|
2
|
+
export * from "./decorators/middleware";
|
|
3
|
+
export * from "./decorators/authOptions";
|
|
4
|
+
export * from "./decorators/use";
|
|
5
|
+
export * from "./decorators/useAfter";
|
|
6
|
+
export * from "./decorators/useAuth";
|
|
7
|
+
export * from "./decorators/useBefore";
|
|
8
|
+
export * from "./decorators/useBeforeEach";
|
|
9
|
+
// domain
|
|
10
|
+
export * from "./domain/MiddlewareMethods";
|
|
11
|
+
export * from "./domain/PlatformMiddlewareSettings";
|
|
12
|
+
// utils
|
|
13
|
+
export * from "./utils/getMiddlewaresForHook";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAE3C,SAAS;AACT,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AAEpD,QAAQ;AACR,cAAc,+BAA+B,CAAC","sourcesContent":["// decorators\nexport * from \"./decorators/middleware\";\nexport * from \"./decorators/authOptions\";\nexport * from \"./decorators/use\";\nexport * from \"./decorators/useAfter\";\nexport * from \"./decorators/useAuth\";\nexport * from \"./decorators/useBefore\";\nexport * from \"./decorators/useBeforeEach\";\n\n// domain\nexport * from \"./domain/MiddlewareMethods\";\nexport * from \"./domain/PlatformMiddlewareSettings\";\n\n// utils\nexport * from \"./utils/getMiddlewaresForHook\";\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isFunction } from "@tsed/core";
|
|
2
|
+
export function getMiddlewaresForHook(hook, settings, defaultHook = "") {
|
|
3
|
+
const { env, middlewares = [] } = settings;
|
|
4
|
+
return middlewares
|
|
5
|
+
.map((middleware) => {
|
|
6
|
+
return isFunction(middleware)
|
|
7
|
+
? {
|
|
8
|
+
env,
|
|
9
|
+
hook: defaultHook,
|
|
10
|
+
use: middleware
|
|
11
|
+
}
|
|
12
|
+
: {
|
|
13
|
+
env,
|
|
14
|
+
hook: defaultHook,
|
|
15
|
+
...middleware
|
|
16
|
+
};
|
|
17
|
+
})
|
|
18
|
+
.filter((options) => {
|
|
19
|
+
return options.use && options.env === env && options.hook === hook;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=getMiddlewaresForHook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMiddlewaresForHook.js","sourceRoot":"","sources":["../../../src/utils/getMiddlewaresForHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAGtC,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,QAA4B,EAAE,WAAW,GAAG,EAAE;IAChG,MAAM,EAAC,GAAG,EAAE,WAAW,GAAG,EAAE,EAAC,GAAG,QAAQ,CAAC;IAEzC,OAAO,WAAW;SACf,GAAG,CAAmC,CAAC,UAAU,EAAE,EAAE;QACpD,OAAO,UAAU,CAAC,UAAU,CAAC;YAC3B,CAAC,CAAC;gBACE,GAAG;gBACH,IAAI,EAAE,WAAW;gBACjB,GAAG,EAAE,UAAU;aAChB;YACH,CAAC,CAAC;gBACE,GAAG;gBACH,IAAI,EAAE,WAAW;gBACjB,GAAG,UAAU;aACd,CAAC;IACR,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QAClB,OAAO,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,KAAK,GAAG,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC;IACrE,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import {isFunction} from \"@tsed/core\";\nimport {PlatformMiddlewareLoadingOptions} from \"../domain/PlatformMiddlewareSettings\";\n\nexport function getMiddlewaresForHook(hook: string, settings: TsED.Configuration, defaultHook = \"\") {\n const {env, middlewares = []} = settings;\n\n return middlewares\n .map<PlatformMiddlewareLoadingOptions>((middleware) => {\n return isFunction(middleware)\n ? {\n env,\n hook: defaultHook,\n use: middleware\n }\n : {\n env,\n hook: defaultHook,\n ...middleware\n };\n })\n .filter((options) => {\n return options.use && options.env === env && options.hook === hook;\n });\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { HTTP_METHODS } from "../constants";
|
|
2
|
+
export function mapUseOptions(args) {
|
|
3
|
+
let method = undefined;
|
|
4
|
+
let path = undefined;
|
|
5
|
+
const middlewares = args.filter((arg) => {
|
|
6
|
+
if (typeof arg === "string" && HTTP_METHODS.includes(arg)) {
|
|
7
|
+
method = arg;
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (typeof arg === "string" || arg instanceof RegExp) {
|
|
11
|
+
path = arg ? arg : "/";
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return !!arg;
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
path,
|
|
18
|
+
method,
|
|
19
|
+
middlewares
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=mapUseOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapUseOptions.js","sourceRoot":"","sources":["../../../src/utils/mapUseOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAE1C,MAAM,UAAU,aAAa,CAAC,IAAW;IACvC,IAAI,MAAM,GAAuB,SAAS,CAAC;IAC3C,IAAI,IAAI,GAAgC,SAAS,CAAC;IAElD,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAQ,EAAE,EAAE;QAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACzD,MAAM,GAAG,GAAG,CAAC;YAEb,OAAO,KAAK,CAAC;SACd;QAED,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,YAAY,MAAM,EAAE;YACpD,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YAEvB,OAAO,KAAK,CAAC;SACd;QAED,OAAO,CAAC,CAAC,GAAG,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,IAAI;QACJ,MAAM;QACN,WAAW;KACZ,CAAC;AACJ,CAAC","sourcesContent":["import {HTTP_METHODS} from \"../constants\";\n\nexport function mapUseOptions(args: any[]) {\n let method: string | undefined = undefined;\n let path: string | RegExp | undefined = undefined;\n\n const middlewares = args.filter((arg: any) => {\n if (typeof arg === \"string\" && HTTP_METHODS.includes(arg)) {\n method = arg;\n\n return false;\n }\n\n if (typeof arg === \"string\" || arg instanceof RegExp) {\n path = arg ? arg : \"/\";\n\n return false;\n }\n\n return !!arg;\n });\n\n return {\n path,\n method,\n middlewares\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const HTTP_METHODS: string[];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
export interface IAuthOptions {
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Since v6. Use @Returns from @tsed/schema
|
|
5
|
+
*/
|
|
6
|
+
responses?: {
|
|
7
|
+
[statusCode: string]: {
|
|
8
|
+
description: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Since v6. Use @Security from @tsed/schema
|
|
13
|
+
*/
|
|
14
|
+
security?: {
|
|
15
|
+
[securityName: string]: string[];
|
|
16
|
+
}[] | {
|
|
17
|
+
[securityName: string]: string[];
|
|
18
|
+
};
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Change authentication options.
|
|
23
|
+
*
|
|
24
|
+
* ```typescript
|
|
25
|
+
* @Controller('/mypath')
|
|
26
|
+
* @UseAuth(MyAuthStrategy, {role: ''})
|
|
27
|
+
* class MyCtrl {
|
|
28
|
+
*
|
|
29
|
+
* @Get('/')
|
|
30
|
+
* @AuthOptions(MyAuthStrategy, {role: 'admin'})
|
|
31
|
+
* public getResource(){}
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param guardAuth
|
|
36
|
+
* @param options {Object} Object passed to the customer auth strategy
|
|
37
|
+
* @returns {Function}
|
|
38
|
+
* @decorator
|
|
39
|
+
* @decorator
|
|
40
|
+
* @operation
|
|
41
|
+
*/
|
|
42
|
+
export declare function AuthOptions(guardAuth: Type<any>, options?: IAuthOptions): Function;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mounts the specified middleware function or functions at the specified path: the middleware function is executed when
|
|
3
|
+
* the base of the requested path matches `path.
|
|
4
|
+
*
|
|
5
|
+
* ```typescript
|
|
6
|
+
* @Controller('/')
|
|
7
|
+
* @Use(Middleware1)
|
|
8
|
+
* export class Ctrl {
|
|
9
|
+
*
|
|
10
|
+
* @Get('/')
|
|
11
|
+
* @Use(Middleware2)
|
|
12
|
+
* get() { }
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @returns {Function}
|
|
18
|
+
* @param args
|
|
19
|
+
* @decorator
|
|
20
|
+
* @operation
|
|
21
|
+
*/
|
|
22
|
+
export declare function Use(...args: any[]): Function;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mounts the specified middleware function or functions at the specified path: the middleware function is executed when
|
|
3
|
+
* the base of the requested path matches `path.
|
|
4
|
+
*
|
|
5
|
+
* ```typescript
|
|
6
|
+
* @Controller('/')
|
|
7
|
+
* @UseAfter(Middleware1)
|
|
8
|
+
* export class Ctrl {
|
|
9
|
+
*
|
|
10
|
+
* @Get('/')
|
|
11
|
+
* @UseAfter(Middleware2)
|
|
12
|
+
* get() { }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @returns {function(any, any, any): *}
|
|
17
|
+
* @param args
|
|
18
|
+
* @decorator
|
|
19
|
+
* @operation
|
|
20
|
+
*/
|
|
21
|
+
export declare function UseAfter(...args: any[]): Function;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
import { IAuthOptions } from "./authOptions";
|
|
3
|
+
/**
|
|
4
|
+
* Use custom authentication strategy on your endpoint.
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* @Controller('/mypath')
|
|
8
|
+
* @UseAuth(MyAuthStrategy)
|
|
9
|
+
* class MyCtrl {
|
|
10
|
+
*
|
|
11
|
+
* @Get('/')
|
|
12
|
+
* @UseAuth(MyAuthStrategy, {role: 'admin'})
|
|
13
|
+
* public getResource(){}
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param guardAuth {Type<any>} A middleware which implement a custom auth strategy
|
|
18
|
+
* @param options {Object} Object passed to the customer auth strategy
|
|
19
|
+
* @returns {Function}
|
|
20
|
+
* @decorator
|
|
21
|
+
* @operation
|
|
22
|
+
*/
|
|
23
|
+
export declare function UseAuth(guardAuth: Type<any>, options?: IAuthOptions): Function;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mounts the specified middleware function or functions at the specified path: the middleware function is executed when
|
|
3
|
+
* the base of the requested path matches `path.
|
|
4
|
+
*
|
|
5
|
+
* ```typescript
|
|
6
|
+
* @Controller('/')
|
|
7
|
+
* @UseBefore(Middleware1) // called only one time before all endpoint
|
|
8
|
+
* export class Ctrl {
|
|
9
|
+
*
|
|
10
|
+
* @Get('/')
|
|
11
|
+
* @UseBefore(Middleware2)
|
|
12
|
+
* get() { }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @returns {function(any, any, any): *}
|
|
17
|
+
* @param args
|
|
18
|
+
* @decorator
|
|
19
|
+
* @operation
|
|
20
|
+
*/
|
|
21
|
+
export declare function UseBefore(...args: any[]): Function;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mounts the specified middleware function or functions at the specified path: the middleware function is executed when
|
|
3
|
+
* the base of the requested path matches `path.
|
|
4
|
+
*
|
|
5
|
+
* ```typescript
|
|
6
|
+
* @Controller('/')
|
|
7
|
+
* @UseBeforeEach(Middleware1) // Called before each endpoint
|
|
8
|
+
* export class Ctrl {
|
|
9
|
+
*
|
|
10
|
+
* @Get('/')
|
|
11
|
+
* get() { }
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @returns {Function}
|
|
17
|
+
* @param args
|
|
18
|
+
* @decorator
|
|
19
|
+
* @operation
|
|
20
|
+
*/
|
|
21
|
+
export declare function UseBeforeEach(...args: any[]): Function;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Env, Type } from "@tsed/core";
|
|
2
|
+
export declare type PlatformMiddlewareLoadingOptions = {
|
|
3
|
+
env?: Env;
|
|
4
|
+
use: Function | Type<any>;
|
|
5
|
+
hook?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare type PlatformMiddlewareSettings = Function | Type<any> | PlatformMiddlewareLoadingOptions | any;
|
|
8
|
+
declare global {
|
|
9
|
+
namespace TsED {
|
|
10
|
+
interface Configuration {
|
|
11
|
+
/**
|
|
12
|
+
* Load middlewares on the $beforeRoutesInit hook (or on the specified hook event name).
|
|
13
|
+
*/
|
|
14
|
+
middlewares: PlatformMiddlewareSettings[];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./decorators/middleware";
|
|
2
|
+
export * from "./decorators/authOptions";
|
|
3
|
+
export * from "./decorators/use";
|
|
4
|
+
export * from "./decorators/useAfter";
|
|
5
|
+
export * from "./decorators/useAuth";
|
|
6
|
+
export * from "./decorators/useBefore";
|
|
7
|
+
export * from "./decorators/useBeforeEach";
|
|
8
|
+
export * from "./domain/MiddlewareMethods";
|
|
9
|
+
export * from "./domain/PlatformMiddlewareSettings";
|
|
10
|
+
export * from "./utils/getMiddlewaresForHook";
|
package/package.json
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-middlewares",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.92.0",
|
|
4
4
|
"description": "Middlewares module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
|
-
"main": "./lib/index.js",
|
|
8
|
-
"typings": "./lib/index.d.ts",
|
|
7
|
+
"main": "./lib/cjs/index.js",
|
|
8
|
+
"typings": "./lib/types/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"import": "./lib/esm/index.js",
|
|
12
|
+
"require": "./lib/cjs/index.js",
|
|
13
|
+
"default": "./lib/esm/index.js"
|
|
12
14
|
},
|
|
13
15
|
"scripts": {
|
|
14
|
-
"build": "
|
|
16
|
+
"build": "yarn run build:esm && yarn run build:cjs",
|
|
17
|
+
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
18
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json"
|
|
15
19
|
},
|
|
16
20
|
"dependencies": {
|
|
17
21
|
"tslib": "2.2.0"
|
|
18
22
|
},
|
|
19
23
|
"devDependencies": {
|
|
20
|
-
"@tsed/core": "6.
|
|
21
|
-
"@tsed/di": "6.
|
|
22
|
-
"@tsed/schema": "6.
|
|
24
|
+
"@tsed/core": "6.92.0",
|
|
25
|
+
"@tsed/di": "6.92.0",
|
|
26
|
+
"@tsed/schema": "6.92.0"
|
|
23
27
|
},
|
|
24
28
|
"peerDependencies": {
|
|
25
|
-
"@tsed/core": "^6.
|
|
26
|
-
"@tsed/di": "^6.
|
|
27
|
-
"@tsed/schema": "^6.
|
|
29
|
+
"@tsed/core": "^6.92.0",
|
|
30
|
+
"@tsed/di": "^6.92.0",
|
|
31
|
+
"@tsed/schema": "^6.92.0"
|
|
28
32
|
},
|
|
29
33
|
"repository": "https://github.com/tsedio/tsed",
|
|
30
34
|
"bugs": {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.compile.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"outDir": "./lib/esm",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationDir": "./lib/types"
|
|
10
|
+
},
|
|
11
|
+
"exclude": [
|
|
12
|
+
"node_modules",
|
|
13
|
+
"test",
|
|
14
|
+
"lib",
|
|
15
|
+
"benchmark",
|
|
16
|
+
"coverage",
|
|
17
|
+
"spec",
|
|
18
|
+
"**/*.benchmark.ts",
|
|
19
|
+
"**/*.spec.ts",
|
|
20
|
+
"keys",
|
|
21
|
+
"jest.config.js"
|
|
22
|
+
]
|
|
23
|
+
}
|