@tsed/platform-middlewares 7.0.0-alpha.1 → 7.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 (70) hide show
  1. package/lib/cjs/constants/constants.js +34 -0
  2. package/lib/cjs/constants/constants.js.map +1 -0
  3. package/lib/cjs/decorators/authOptions.js +44 -0
  4. package/lib/cjs/decorators/authOptions.js.map +1 -0
  5. package/lib/cjs/decorators/middleware.js +17 -0
  6. package/lib/cjs/decorators/middleware.js.map +1 -0
  7. package/lib/cjs/decorators/use.js +43 -0
  8. package/lib/cjs/decorators/use.js.map +1 -0
  9. package/lib/cjs/decorators/useAfter.js +46 -0
  10. package/lib/cjs/decorators/useAfter.js.map +1 -0
  11. package/lib/cjs/decorators/useAuth.js +45 -0
  12. package/lib/cjs/decorators/useAuth.js.map +1 -0
  13. package/lib/cjs/decorators/useBefore.js +45 -0
  14. package/lib/cjs/decorators/useBefore.js.map +1 -0
  15. package/lib/cjs/decorators/useBeforeEach.js +40 -0
  16. package/lib/cjs/decorators/useBeforeEach.js.map +1 -0
  17. package/lib/cjs/domain/MiddlewareMethods.js +3 -0
  18. package/lib/cjs/domain/MiddlewareMethods.js.map +1 -0
  19. package/lib/cjs/domain/PlatformMiddlewareSettings.js +3 -0
  20. package/lib/cjs/domain/PlatformMiddlewareSettings.js.map +1 -0
  21. package/lib/cjs/index.js +18 -0
  22. package/lib/cjs/index.js.map +1 -0
  23. package/lib/cjs/package.json +3 -0
  24. package/lib/cjs/utils/getMiddlewaresForHook.js +26 -0
  25. package/lib/cjs/utils/getMiddlewaresForHook.js.map +1 -0
  26. package/lib/esm/constants/constants.js +31 -0
  27. package/lib/esm/constants/constants.js.map +1 -0
  28. package/lib/esm/decorators/authOptions.js +40 -0
  29. package/lib/esm/decorators/authOptions.js.map +1 -0
  30. package/lib/esm/decorators/middleware.js +13 -0
  31. package/lib/esm/decorators/middleware.js.map +1 -0
  32. package/lib/esm/decorators/use.js +39 -0
  33. package/lib/esm/decorators/use.js.map +1 -0
  34. package/lib/esm/decorators/useAfter.js +42 -0
  35. package/lib/esm/decorators/useAfter.js.map +1 -0
  36. package/lib/esm/decorators/useAuth.js +41 -0
  37. package/lib/esm/decorators/useAuth.js.map +1 -0
  38. package/lib/esm/decorators/useBefore.js +41 -0
  39. package/lib/esm/decorators/useBefore.js.map +1 -0
  40. package/lib/esm/decorators/useBeforeEach.js +36 -0
  41. package/lib/esm/decorators/useBeforeEach.js.map +1 -0
  42. package/lib/esm/domain/MiddlewareMethods.js +2 -0
  43. package/lib/esm/domain/MiddlewareMethods.js.map +1 -0
  44. package/lib/esm/domain/PlatformMiddlewareSettings.js +2 -0
  45. package/lib/esm/domain/PlatformMiddlewareSettings.js.map +1 -0
  46. package/lib/esm/index.js +15 -0
  47. package/lib/esm/index.js.map +1 -0
  48. package/lib/esm/package.json +3 -0
  49. package/lib/esm/utils/getMiddlewaresForHook.js +22 -0
  50. package/lib/esm/utils/getMiddlewaresForHook.js.map +1 -0
  51. package/lib/{constants/index.d.ts → types/constants/constants.d.ts} +0 -0
  52. package/lib/{decorators → types/decorators}/authOptions.d.ts +0 -0
  53. package/lib/{decorators → types/decorators}/middleware.d.ts +0 -0
  54. package/lib/{decorators → types/decorators}/use.d.ts +0 -0
  55. package/lib/{decorators → types/decorators}/useAfter.d.ts +0 -0
  56. package/lib/{decorators → types/decorators}/useAuth.d.ts +0 -0
  57. package/lib/{decorators → types/decorators}/useBefore.d.ts +0 -0
  58. package/lib/{decorators → types/decorators}/useBeforeEach.d.ts +0 -0
  59. package/lib/{domain → types/domain}/MiddlewareMethods.d.ts +0 -0
  60. package/lib/{domain → types/domain}/PlatformMiddlewareSettings.d.ts +0 -0
  61. package/lib/{index.d.ts → types/index.d.ts} +5 -1
  62. package/lib/{utils → types/utils}/getMiddlewaresForHook.d.ts +0 -0
  63. package/package.json +31 -14
  64. package/readme.md +1 -2
  65. package/tsconfig.compile.esm.json +12 -0
  66. package/lib/index.js +0 -333
  67. package/lib/index.js.map +0 -1
  68. package/lib/index.modern.js +0 -326
  69. package/lib/index.modern.js.map +0 -1
  70. package/lib/utils/mapUseOptions.d.ts +0 -5
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HTTP_METHODS = void 0;
4
+ exports.HTTP_METHODS = [
5
+ "all",
6
+ "checkout",
7
+ "connect",
8
+ "copy",
9
+ "delete",
10
+ "get",
11
+ "head",
12
+ "lock",
13
+ "merge",
14
+ "mkactivity",
15
+ "mkcol",
16
+ "move",
17
+ "m-search",
18
+ "notify",
19
+ "options",
20
+ "param",
21
+ "patch",
22
+ "post",
23
+ "propfind",
24
+ "propatch",
25
+ "purge",
26
+ "put",
27
+ "report",
28
+ "search",
29
+ "subscribe",
30
+ "trace",
31
+ "unlock",
32
+ "unsuscribe"
33
+ ];
34
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG;IAC1B,KAAK;IACL,UAAU;IACV,SAAS;IACT,MAAM;IACN,QAAQ;IACR,KAAK;IACL,MAAM;IACN,MAAM;IACN,OAAO;IACP,YAAY;IACZ,OAAO;IACP,MAAM;IACN,UAAU;IACV,QAAQ;IACR,SAAS;IACT,OAAO;IACP,OAAO;IACP,MAAM;IACN,UAAU;IACV,UAAU;IACV,OAAO;IACP,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,WAAW;IACX,OAAO;IACP,QAAQ;IACR,YAAY;CACb,CAAC","sourcesContent":["export const HTTP_METHODS = [\n \"all\",\n \"checkout\",\n \"connect\",\n \"copy\",\n \"delete\",\n \"get\",\n \"head\",\n \"lock\",\n \"merge\",\n \"mkactivity\",\n \"mkcol\",\n \"move\",\n \"m-search\",\n \"notify\",\n \"options\",\n \"param\",\n \"patch\",\n \"post\",\n \"propfind\",\n \"propatch\",\n \"purge\",\n \"put\",\n \"report\",\n \"search\",\n \"subscribe\",\n \"trace\",\n \"unlock\",\n \"unsuscribe\"\n];\n"]}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthOptions = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const schema_1 = require("@tsed/schema");
6
+ /**
7
+ * Change authentication options.
8
+ *
9
+ * ```typescript
10
+ * @Controller('/mypath')
11
+ * @UseAuth(MyAuthStrategy, {role: ''})
12
+ * class MyCtrl {
13
+ *
14
+ * @Get('/')
15
+ * @AuthOptions(MyAuthStrategy, {role: 'admin'})
16
+ * public getResource(){}
17
+ * }
18
+ * ```
19
+ *
20
+ * @param guardAuth
21
+ * @param options {Object} Object passed to the customer auth strategy
22
+ * @returns {Function}
23
+ * @decorator
24
+ * @decorator
25
+ * @operation
26
+ */
27
+ function AuthOptions(guardAuth, options = {}) {
28
+ return (...args) => {
29
+ switch ((0, core_1.decoratorTypeOf)(args)) {
30
+ case core_1.DecoratorTypes.METHOD:
31
+ return (0, schema_1.JsonEntityFn)((entity) => {
32
+ const store = entity.store;
33
+ store.merge(guardAuth, options, true);
34
+ })(...args);
35
+ case core_1.DecoratorTypes.CLASS:
36
+ (0, core_1.decorateMethodsOf)(args[0], AuthOptions(guardAuth, options));
37
+ break;
38
+ default:
39
+ throw new core_1.UnsupportedDecoratorType(AuthOptions, args);
40
+ }
41
+ };
42
+ }
43
+ exports.AuthOptions = AuthOptions;
44
+ //# sourceMappingURL=authOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authOptions.js","sourceRoot":"","sources":["../../../src/decorators/authOptions.ts"],"names":[],"mappings":";;;AAAA,qCAQoB;AACpB,yCAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,WAAW,CAAC,SAAoB,EAAE,UAAmC,EAAE;IACrF,OAAO,CAAI,GAAG,IAAyB,EAAqC,EAAE;QAC5E,QAAQ,IAAA,sBAAe,EAAC,IAAI,CAAC,EAAE;YAC7B,KAAK,qBAAc,CAAC,MAAM;gBACxB,OAAO,IAAA,qBAAY,EAAC,CAAC,MAAM,EAAE,EAAE;oBAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;oBAE3B,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;gBACxC,CAAC,CAAC,CAAC,GAAI,IAAkC,CAAC,CAAC;YAE7C,KAAK,qBAAc,CAAC,KAAK;gBACvB,IAAA,wBAAiB,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;gBAC5D,MAAM;YAER;gBACE,MAAM,IAAI,+BAAwB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;SACzD;IACH,CAAC,CAAC;AACJ,CAAC;AAlBD,kCAkBC","sourcesContent":["import {\n decorateMethodsOf,\n DecoratorMethodParameters,\n DecoratorParameters,\n decoratorTypeOf,\n DecoratorTypes,\n Type,\n UnsupportedDecoratorType\n} from \"@tsed/core\";\nimport {JsonEntityFn} from \"@tsed/schema\";\n\n/**\n * Change authentication options.\n *\n * ```typescript\n * @Controller('/mypath')\n * @UseAuth(MyAuthStrategy, {role: ''})\n * class MyCtrl {\n *\n * @Get('/')\n * @AuthOptions(MyAuthStrategy, {role: 'admin'})\n * public getResource(){}\n * }\n * ```\n *\n * @param guardAuth\n * @param options {Object} Object passed to the customer auth strategy\n * @returns {Function}\n * @decorator\n * @decorator\n * @operation\n */\nexport function AuthOptions(guardAuth: Type<any>, options: Record<string, unknown> = {}): Function {\n return <T>(...args: DecoratorParameters): TypedPropertyDescriptor<T> | void => {\n switch (decoratorTypeOf(args)) {\n case DecoratorTypes.METHOD:\n return JsonEntityFn((entity) => {\n const store = entity.store;\n\n store.merge(guardAuth, options, true);\n })(...(args as DecoratorMethodParameters));\n\n case DecoratorTypes.CLASS:\n decorateMethodsOf(args[0], AuthOptions(guardAuth, options));\n break;\n\n default:\n throw new UnsupportedDecoratorType(AuthOptions, args);\n }\n };\n}\n"]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Middleware = void 0;
4
+ const di_1 = require("@tsed/di");
5
+ /**
6
+ * Register a new Middleware class.
7
+ *
8
+ * @decorator
9
+ * @classDecorator
10
+ */
11
+ function Middleware() {
12
+ return (0, di_1.Injectable)({
13
+ type: di_1.ProviderType.MIDDLEWARE
14
+ });
15
+ }
16
+ exports.Middleware = Middleware;
17
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/decorators/middleware.ts"],"names":[],"mappings":";;;AAAA,iCAAkD;AAElD;;;;;GAKG;AACH,SAAgB,UAAU;IACxB,OAAO,IAAA,eAAU,EAAC;QAChB,IAAI,EAAE,iBAAY,CAAC,UAAU;KAC9B,CAAC,CAAC;AACL,CAAC;AAJD,gCAIC","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,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Use = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const schema_1 = require("@tsed/schema");
6
+ /**
7
+ * Mounts the specified middleware function or functions at the specified path: the middleware function is executed when
8
+ * the base of the requested path matches `path.
9
+ *
10
+ * ```typescript
11
+ * @Controller('/')
12
+ * @Use(Middleware1)
13
+ * export class Ctrl {
14
+ *
15
+ * @Get('/')
16
+ * @Use(Middleware2)
17
+ * get() { }
18
+ * }
19
+ *
20
+ * ```
21
+ *
22
+ * @returns {Function}
23
+ * @param args
24
+ * @decorator
25
+ * @operation
26
+ */
27
+ function Use(...args) {
28
+ return (0, schema_1.JsonEntityFn)((entity, parameters) => {
29
+ switch (entity.decoratorType) {
30
+ case core_1.DecoratorTypes.METHOD:
31
+ return (0, schema_1.Route)(...args);
32
+ case core_1.DecoratorTypes.CLASS:
33
+ entity.store.merge("middlewares", {
34
+ use: args
35
+ });
36
+ break;
37
+ default:
38
+ throw new core_1.UnsupportedDecoratorType(Use, parameters);
39
+ }
40
+ });
41
+ }
42
+ exports.Use = Use;
43
+ //# sourceMappingURL=use.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use.js","sourceRoot":"","sources":["../../../src/decorators/use.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,yCAAiD;AAEjD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,GAAG,CAAC,GAAG,IAAW;IAChC,OAAO,IAAA,qBAAY,EAAC,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;QACzC,QAAQ,MAAM,CAAC,aAAa,EAAE;YAC5B,KAAK,qBAAc,CAAC,MAAM;gBACxB,OAAO,IAAA,cAAK,EAAC,GAAG,IAAI,CAAC,CAAC;YAExB,KAAK,qBAAc,CAAC,KAAK;gBACvB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,EAAE;oBAChC,GAAG,EAAE,IAAI;iBACV,CAAC,CAAC;gBACH,MAAM;YAER;gBACE,MAAM,IAAI,+BAAwB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;SACvD;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAhBD,kBAgBC","sourcesContent":["import {DecoratorTypes, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {JsonEntityFn, Route} 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 * @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,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UseAfter = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const schema_1 = require("@tsed/schema");
6
+ /**
7
+ * Mounts the specified middleware function or functions at the specified path: the middleware function is executed when
8
+ * the base of the requested path matches `path.
9
+ *
10
+ * ```typescript
11
+ * @Controller('/')
12
+ * @UseAfter(Middleware1)
13
+ * export class Ctrl {
14
+ *
15
+ * @Get('/')
16
+ * @UseAfter(Middleware2)
17
+ * get() { }
18
+ * }
19
+ * ```
20
+ *
21
+ * @returns {function(any, any, any): *}
22
+ * @param args
23
+ * @decorator
24
+ * @operation
25
+ */
26
+ function UseAfter(...args) {
27
+ return (0, schema_1.JsonEntityFn)((entity, parameters) => {
28
+ switch (entity.decoratorType) {
29
+ case core_1.DecoratorTypes.METHOD:
30
+ const endpoint = entity;
31
+ endpoint.afterMiddlewares = args.concat(endpoint.afterMiddlewares);
32
+ break;
33
+ case core_1.DecoratorTypes.CLASS:
34
+ const middlewares = entity.store.get("middlewares") || {};
35
+ entity.store.set("middlewares", {
36
+ ...middlewares,
37
+ useAfter: [...args, ...(middlewares.useAfter || [])]
38
+ });
39
+ break;
40
+ default:
41
+ throw new core_1.UnsupportedDecoratorType(UseAfter, parameters);
42
+ }
43
+ });
44
+ }
45
+ exports.UseAfter = UseAfter;
46
+ //# sourceMappingURL=useAfter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAfter.js","sourceRoot":"","sources":["../../../src/decorators/useAfter.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,yCAA0C;AAE1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,QAAQ,CAAC,GAAG,IAAW;IACrC,OAAO,IAAA,qBAAY,EAAC,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;QACzC,QAAQ,MAAM,CAAC,aAAa,EAAE;YAC5B,KAAK,qBAAc,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,qBAAc,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,+BAAwB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;SAC5D;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAtBD,4BAsBC","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,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UseAuth = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const authOptions_1 = require("./authOptions");
6
+ const useBefore_1 = require("./useBefore");
7
+ /**
8
+ * Use custom authentication strategy on your endpoint.
9
+ *
10
+ * ```typescript
11
+ * @Controller('/mypath')
12
+ * @UseAuth(MyAuthStrategy)
13
+ * class MyCtrl {
14
+ *
15
+ * @Get('/')
16
+ * @UseAuth(MyAuthStrategy, {role: 'admin'})
17
+ * public getResource(){}
18
+ * }
19
+ * ```
20
+ *
21
+ * @param guardAuth {Type<any>} A middleware which implement a custom auth strategy
22
+ * @param options {Object} Object passed to the customer auth strategy
23
+ * @returns {Function}
24
+ * @decorator
25
+ * @operation
26
+ */
27
+ function UseAuth(guardAuth, options = {}) {
28
+ return (...args) => {
29
+ switch ((0, core_1.decoratorTypeOf)(args)) {
30
+ case core_1.DecoratorTypes.METHOD:
31
+ return (0, core_1.useDecorators)((0, core_1.StoreFn)((store) => {
32
+ if (!store.has(guardAuth)) {
33
+ return (0, useBefore_1.UseBefore)(guardAuth);
34
+ }
35
+ }), (0, authOptions_1.AuthOptions)(guardAuth, options))(...args);
36
+ case core_1.DecoratorTypes.CLASS:
37
+ (0, core_1.decorateMethodsOf)(args[0], UseAuth(guardAuth, options));
38
+ break;
39
+ default:
40
+ throw new core_1.UnsupportedDecoratorType(UseAuth, args);
41
+ }
42
+ };
43
+ }
44
+ exports.UseAuth = UseAuth;
45
+ //# sourceMappingURL=useAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuth.js","sourceRoot":"","sources":["../../../src/decorators/useAuth.ts"],"names":[],"mappings":";;;AAAA,qCAUoB;AACpB,+CAA0C;AAC1C,2CAAsC;AAEtC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,OAAO,CAAC,SAAoB,EAAE,UAAmC,EAAE;IACjF,OAAO,CAAI,GAAG,IAAyB,EAAqC,EAAE;QAC5E,QAAQ,IAAA,sBAAe,EAAC,IAAI,CAAC,EAAE;YAC7B,KAAK,qBAAc,CAAC,MAAM;gBACxB,OAAO,IAAA,oBAAa,EAClB,IAAA,cAAO,EAAC,CAAC,KAAY,EAAE,EAAE;oBACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;wBACzB,OAAO,IAAA,qBAAS,EAAC,SAAS,CAAC,CAAC;qBAC7B;gBACH,CAAC,CAAC,EACF,IAAA,yBAAW,EAAC,SAAS,EAAE,OAAO,CAAC,CAChC,CAAC,GAAG,IAAI,CAAC,CAAC;YAEb,KAAK,qBAAc,CAAC,KAAK;gBACvB,IAAA,wBAAiB,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;gBACxD,MAAM;YAER;gBACE,MAAM,IAAI,+BAAwB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;SACrD;IACH,CAAC,CAAC;AACJ,CAAC;AArBD,0BAqBC","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} 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: Record<string, unknown> = {}): 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,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UseBefore = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const schema_1 = require("@tsed/schema");
6
+ /**
7
+ * Mounts the specified middleware function or functions at the specified path: the middleware function is executed when
8
+ * the base of the requested path matches `path.
9
+ *
10
+ * ```typescript
11
+ * @Controller('/')
12
+ * @UseBefore(Middleware1) // called only one time before all endpoint
13
+ * export class Ctrl {
14
+ *
15
+ * @Get('/')
16
+ * @UseBefore(Middleware2)
17
+ * get() { }
18
+ * }
19
+ * ```
20
+ *
21
+ * @returns {function(any, any, any): *}
22
+ * @param args
23
+ * @decorator
24
+ * @operation
25
+ */
26
+ function UseBefore(...args) {
27
+ return (0, schema_1.JsonEntityFn)((entity, parameters) => {
28
+ switch (entity.decoratorType) {
29
+ case core_1.DecoratorTypes.METHOD:
30
+ entity.beforeMiddlewares = args.concat(entity.beforeMiddlewares);
31
+ break;
32
+ case core_1.DecoratorTypes.CLASS:
33
+ const middlewares = entity.store.get("middlewares") || {};
34
+ entity.store.set("middlewares", {
35
+ ...middlewares,
36
+ useBefore: [...args, ...(middlewares.useBefore || [])]
37
+ });
38
+ break;
39
+ default:
40
+ throw new core_1.UnsupportedDecoratorType(UseBefore, parameters);
41
+ }
42
+ });
43
+ }
44
+ exports.UseBefore = UseBefore;
45
+ //# sourceMappingURL=useBefore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBefore.js","sourceRoot":"","sources":["../../../src/decorators/useBefore.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,yCAA0C;AAE1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,SAAS,CAAC,GAAG,IAAW;IACtC,OAAO,IAAA,qBAAY,EAAC,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;QACzC,QAAQ,MAAM,CAAC,aAAa,EAAE;YAC5B,KAAK,qBAAc,CAAC,MAAM;gBACxB,MAAM,CAAC,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;gBAEjE,MAAM;YAER,KAAK,qBAAc,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,+BAAwB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;SAC7D;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AArBD,8BAqBC","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,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UseBeforeEach = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const useBefore_1 = require("./useBefore");
6
+ /**
7
+ * Mounts the specified middleware function or functions at the specified path: the middleware function is executed when
8
+ * the base of the requested path matches `path.
9
+ *
10
+ * ```typescript
11
+ * @Controller('/')
12
+ * @UseBeforeEach(Middleware1) // Called before each endpoint
13
+ * export class Ctrl {
14
+ *
15
+ * @Get('/')
16
+ * get() { }
17
+ * }
18
+ *
19
+ * ```
20
+ *
21
+ * @returns {Function}
22
+ * @param args
23
+ * @decorator
24
+ * @operation
25
+ */
26
+ function UseBeforeEach(...args) {
27
+ return (...decoratorArgs) => {
28
+ switch ((0, core_1.decoratorTypeOf)(decoratorArgs)) {
29
+ case core_1.DecoratorTypes.METHOD:
30
+ return (0, useBefore_1.UseBefore)(...args)(...decoratorArgs);
31
+ case core_1.DecoratorTypes.CLASS:
32
+ (0, core_1.decorateMethodsOf)(decoratorArgs[0], (0, useBefore_1.UseBefore)(...args));
33
+ break;
34
+ default:
35
+ throw new core_1.UnsupportedDecoratorType(UseBeforeEach, decoratorArgs);
36
+ }
37
+ };
38
+ }
39
+ exports.UseBeforeEach = UseBeforeEach;
40
+ //# sourceMappingURL=useBeforeEach.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBeforeEach.js","sourceRoot":"","sources":["../../../src/decorators/useBeforeEach.ts"],"names":[],"mappings":";;;AAAA,qCAA6H;AAC7H,2CAAsC;AAEtC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,aAAa,CAAC,GAAG,IAAW;IAC1C,OAAO,CAAI,GAAG,aAAkC,EAAqC,EAAE;QACrF,QAAQ,IAAA,sBAAe,EAAC,aAAa,CAAC,EAAE;YACtC,KAAK,qBAAc,CAAC,MAAM;gBACxB,OAAO,IAAA,qBAAS,EAAC,GAAG,IAAI,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC;YAE9C,KAAK,qBAAc,CAAC,KAAK;gBACvB,IAAA,wBAAiB,EAAC,aAAa,CAAC,CAAC,CAAC,EAAE,IAAA,qBAAS,EAAC,GAAG,IAAI,CAAC,CAAC,CAAC;gBACxD,MAAM;YAER;gBACE,MAAM,IAAI,+BAAwB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;SACpE;IACH,CAAC,CAAC;AACJ,CAAC;AAdD,sCAcC","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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=MiddlewareMethods.js.map
@@ -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"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=PlatformMiddlewareSettings.js.map
@@ -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"]}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ /**
3
+ * @file Automatically generated by barrelsby.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const tslib_1 = require("tslib");
7
+ tslib_1.__exportStar(require("./constants/constants"), exports);
8
+ tslib_1.__exportStar(require("./decorators/authOptions"), exports);
9
+ tslib_1.__exportStar(require("./decorators/middleware"), exports);
10
+ tslib_1.__exportStar(require("./decorators/use"), exports);
11
+ tslib_1.__exportStar(require("./decorators/useAfter"), exports);
12
+ tslib_1.__exportStar(require("./decorators/useAuth"), exports);
13
+ tslib_1.__exportStar(require("./decorators/useBefore"), exports);
14
+ tslib_1.__exportStar(require("./decorators/useBeforeEach"), exports);
15
+ tslib_1.__exportStar(require("./domain/MiddlewareMethods"), exports);
16
+ tslib_1.__exportStar(require("./domain/PlatformMiddlewareSettings"), exports);
17
+ tslib_1.__exportStar(require("./utils/getMiddlewaresForHook"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAsC;AACtC,mEAAyC;AACzC,kEAAwC;AACxC,2DAAiC;AACjC,gEAAsC;AACtC,+DAAqC;AACrC,iEAAuC;AACvC,qEAA2C;AAC3C,qEAA2C;AAC3C,8EAAoD;AACpD,wEAA8C","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/authOptions\";\nexport * from \"./decorators/middleware\";\nexport * from \"./decorators/use\";\nexport * from \"./decorators/useAfter\";\nexport * from \"./decorators/useAuth\";\nexport * from \"./decorators/useBefore\";\nexport * from \"./decorators/useBeforeEach\";\nexport * from \"./domain/MiddlewareMethods\";\nexport * from \"./domain/PlatformMiddlewareSettings\";\nexport * from \"./utils/getMiddlewaresForHook\";\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMiddlewaresForHook = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ function getMiddlewaresForHook(hook, settings, defaultHook = "") {
6
+ const { env, middlewares = [] } = settings;
7
+ return middlewares
8
+ .map((middleware) => {
9
+ return (0, core_1.isFunction)(middleware)
10
+ ? {
11
+ env,
12
+ hook: defaultHook,
13
+ use: middleware
14
+ }
15
+ : {
16
+ env,
17
+ hook: defaultHook,
18
+ ...middleware
19
+ };
20
+ })
21
+ .filter((options) => {
22
+ return options.use && options.env === env && options.hook === hook;
23
+ });
24
+ }
25
+ exports.getMiddlewaresForHook = getMiddlewaresForHook;
26
+ //# sourceMappingURL=getMiddlewaresForHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getMiddlewaresForHook.js","sourceRoot":"","sources":["../../../src/utils/getMiddlewaresForHook.ts"],"names":[],"mappings":";;;AAAA,qCAAsC;AAGtC,SAAgB,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,IAAA,iBAAU,EAAC,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;AApBD,sDAoBC","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,31 @@
1
+ export const HTTP_METHODS = [
2
+ "all",
3
+ "checkout",
4
+ "connect",
5
+ "copy",
6
+ "delete",
7
+ "get",
8
+ "head",
9
+ "lock",
10
+ "merge",
11
+ "mkactivity",
12
+ "mkcol",
13
+ "move",
14
+ "m-search",
15
+ "notify",
16
+ "options",
17
+ "param",
18
+ "patch",
19
+ "post",
20
+ "propfind",
21
+ "propatch",
22
+ "purge",
23
+ "put",
24
+ "report",
25
+ "search",
26
+ "subscribe",
27
+ "trace",
28
+ "unlock",
29
+ "unsuscribe"
30
+ ];
31
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,KAAK;IACL,UAAU;IACV,SAAS;IACT,MAAM;IACN,QAAQ;IACR,KAAK;IACL,MAAM;IACN,MAAM;IACN,OAAO;IACP,YAAY;IACZ,OAAO;IACP,MAAM;IACN,UAAU;IACV,QAAQ;IACR,SAAS;IACT,OAAO;IACP,OAAO;IACP,MAAM;IACN,UAAU;IACV,UAAU;IACV,OAAO;IACP,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,WAAW;IACX,OAAO;IACP,QAAQ;IACR,YAAY;CACb,CAAC","sourcesContent":["export const HTTP_METHODS = [\n \"all\",\n \"checkout\",\n \"connect\",\n \"copy\",\n \"delete\",\n \"get\",\n \"head\",\n \"lock\",\n \"merge\",\n \"mkactivity\",\n \"mkcol\",\n \"move\",\n \"m-search\",\n \"notify\",\n \"options\",\n \"param\",\n \"patch\",\n \"post\",\n \"propfind\",\n \"propatch\",\n \"purge\",\n \"put\",\n \"report\",\n \"search\",\n \"subscribe\",\n \"trace\",\n \"unlock\",\n \"unsuscribe\"\n];\n"]}
@@ -0,0 +1,40 @@
1
+ import { decorateMethodsOf, decoratorTypeOf, DecoratorTypes, UnsupportedDecoratorType } from "@tsed/core";
2
+ import { JsonEntityFn } from "@tsed/schema";
3
+ /**
4
+ * Change authentication options.
5
+ *
6
+ * ```typescript
7
+ * @Controller('/mypath')
8
+ * @UseAuth(MyAuthStrategy, {role: ''})
9
+ * class MyCtrl {
10
+ *
11
+ * @Get('/')
12
+ * @AuthOptions(MyAuthStrategy, {role: 'admin'})
13
+ * public getResource(){}
14
+ * }
15
+ * ```
16
+ *
17
+ * @param guardAuth
18
+ * @param options {Object} Object passed to the customer auth strategy
19
+ * @returns {Function}
20
+ * @decorator
21
+ * @decorator
22
+ * @operation
23
+ */
24
+ export function AuthOptions(guardAuth, options = {}) {
25
+ return (...args) => {
26
+ switch (decoratorTypeOf(args)) {
27
+ case DecoratorTypes.METHOD:
28
+ return JsonEntityFn((entity) => {
29
+ const store = entity.store;
30
+ store.merge(guardAuth, options, true);
31
+ })(...args);
32
+ case DecoratorTypes.CLASS:
33
+ decorateMethodsOf(args[0], AuthOptions(guardAuth, options));
34
+ break;
35
+ default:
36
+ throw new UnsupportedDecoratorType(AuthOptions, args);
37
+ }
38
+ };
39
+ }
40
+ //# sourceMappingURL=authOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authOptions.js","sourceRoot":"","sources":["../../../src/decorators/authOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAGjB,eAAe,EACf,cAAc,EAEd,wBAAwB,EACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,WAAW,CAAC,SAAoB,EAAE,UAAmC,EAAE;IACrF,OAAO,CAAI,GAAG,IAAyB,EAAqC,EAAE;QAC5E,QAAQ,eAAe,CAAC,IAAI,CAAC,EAAE;YAC7B,KAAK,cAAc,CAAC,MAAM;gBACxB,OAAO,YAAY,CAAC,CAAC,MAAM,EAAE,EAAE;oBAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;oBAE3B,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;gBACxC,CAAC,CAAC,CAAC,GAAI,IAAkC,CAAC,CAAC;YAE7C,KAAK,cAAc,CAAC,KAAK;gBACvB,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;gBAC5D,MAAM;YAER;gBACE,MAAM,IAAI,wBAAwB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;SACzD;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n decorateMethodsOf,\n DecoratorMethodParameters,\n DecoratorParameters,\n decoratorTypeOf,\n DecoratorTypes,\n Type,\n UnsupportedDecoratorType\n} from \"@tsed/core\";\nimport {JsonEntityFn} from \"@tsed/schema\";\n\n/**\n * Change authentication options.\n *\n * ```typescript\n * @Controller('/mypath')\n * @UseAuth(MyAuthStrategy, {role: ''})\n * class MyCtrl {\n *\n * @Get('/')\n * @AuthOptions(MyAuthStrategy, {role: 'admin'})\n * public getResource(){}\n * }\n * ```\n *\n * @param guardAuth\n * @param options {Object} Object passed to the customer auth strategy\n * @returns {Function}\n * @decorator\n * @decorator\n * @operation\n */\nexport function AuthOptions(guardAuth: Type<any>, options: Record<string, unknown> = {}): Function {\n return <T>(...args: DecoratorParameters): TypedPropertyDescriptor<T> | void => {\n switch (decoratorTypeOf(args)) {\n case DecoratorTypes.METHOD:\n return JsonEntityFn((entity) => {\n const store = entity.store;\n\n store.merge(guardAuth, options, true);\n })(...(args as DecoratorMethodParameters));\n\n case DecoratorTypes.CLASS:\n decorateMethodsOf(args[0], AuthOptions(guardAuth, options));\n break;\n\n default:\n throw new UnsupportedDecoratorType(AuthOptions, args);\n }\n };\n}\n"]}
@@ -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,EAAE,KAAK,EAAC,MAAM,cAAc,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;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, Route} 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 * @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