@tsed/platform-middlewares 7.0.0-alpha.1 → 7.0.0-beta.3

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 (71) hide show
  1. package/lib/cjs/constants/index.js +34 -0
  2. package/lib/cjs/constants/index.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 +17 -0
  22. package/lib/cjs/index.js.map +1 -0
  23. package/lib/cjs/utils/getMiddlewaresForHook.js +26 -0
  24. package/lib/cjs/utils/getMiddlewaresForHook.js.map +1 -0
  25. package/lib/cjs/utils/mapUseOptions.js +26 -0
  26. package/lib/cjs/utils/mapUseOptions.js.map +1 -0
  27. package/lib/esm/constants/index.js +31 -0
  28. package/lib/esm/constants/index.js.map +1 -0
  29. package/lib/esm/decorators/authOptions.js +40 -0
  30. package/lib/esm/decorators/authOptions.js.map +1 -0
  31. package/lib/esm/decorators/middleware.js +13 -0
  32. package/lib/esm/decorators/middleware.js.map +1 -0
  33. package/lib/esm/decorators/use.js +39 -0
  34. package/lib/esm/decorators/use.js.map +1 -0
  35. package/lib/esm/decorators/useAfter.js +42 -0
  36. package/lib/esm/decorators/useAfter.js.map +1 -0
  37. package/lib/esm/decorators/useAuth.js +41 -0
  38. package/lib/esm/decorators/useAuth.js.map +1 -0
  39. package/lib/esm/decorators/useBefore.js +41 -0
  40. package/lib/esm/decorators/useBefore.js.map +1 -0
  41. package/lib/esm/decorators/useBeforeEach.js +36 -0
  42. package/lib/esm/decorators/useBeforeEach.js.map +1 -0
  43. package/lib/esm/domain/MiddlewareMethods.js +2 -0
  44. package/lib/esm/domain/MiddlewareMethods.js.map +1 -0
  45. package/lib/esm/domain/PlatformMiddlewareSettings.js +2 -0
  46. package/lib/esm/domain/PlatformMiddlewareSettings.js.map +1 -0
  47. package/lib/esm/index.js +14 -0
  48. package/lib/esm/index.js.map +1 -0
  49. package/lib/esm/utils/getMiddlewaresForHook.js +22 -0
  50. package/lib/esm/utils/getMiddlewaresForHook.js.map +1 -0
  51. package/lib/esm/utils/mapUseOptions.js +22 -0
  52. package/lib/esm/utils/mapUseOptions.js.map +1 -0
  53. package/lib/{constants → types/constants}/index.d.ts +0 -0
  54. package/lib/{decorators → types/decorators}/authOptions.d.ts +0 -0
  55. package/lib/{decorators → types/decorators}/middleware.d.ts +0 -0
  56. package/lib/{decorators → types/decorators}/use.d.ts +0 -0
  57. package/lib/{decorators → types/decorators}/useAfter.d.ts +0 -0
  58. package/lib/{decorators → types/decorators}/useAuth.d.ts +0 -0
  59. package/lib/{decorators → types/decorators}/useBefore.d.ts +0 -0
  60. package/lib/{decorators → types/decorators}/useBeforeEach.d.ts +0 -0
  61. package/lib/{domain → types/domain}/MiddlewareMethods.d.ts +0 -0
  62. package/lib/{domain → types/domain}/PlatformMiddlewareSettings.d.ts +0 -0
  63. package/lib/{index.d.ts → types/index.d.ts} +0 -0
  64. package/lib/{utils → types/utils}/getMiddlewaresForHook.d.ts +0 -0
  65. package/lib/{utils → types/utils}/mapUseOptions.d.ts +0 -0
  66. package/package.json +17 -13
  67. package/tsconfig.compile.esm.json +23 -0
  68. package/lib/index.js +0 -333
  69. package/lib/index.js.map +0 -1
  70. package/lib/index.modern.js +0 -326
  71. package/lib/index.modern.js.map +0 -1
@@ -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,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,OAAO,CAAC,SAAoB,EAAE,UAAmC,EAAE;IACjF,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} 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,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,2 @@
1
+ export {};
2
+ //# 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,2 @@
1
+ export {};
2
+ //# 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,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"]}
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,36 +1,40 @@
1
1
  {
2
2
  "name": "@tsed/platform-middlewares",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-beta.3",
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
- "require": "./lib/index.js",
11
- "default": "./lib/index.modern.js"
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": "microbundle --target node --no-compress --format modern,cjs --tsconfig ./tsconfig.compile.json"
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": "7.0.0-alpha.1",
21
- "@tsed/di": "7.0.0-alpha.1",
22
- "@tsed/schema": "7.0.0-alpha.1"
24
+ "@tsed/core": "7.0.0-beta.3",
25
+ "@tsed/di": "7.0.0-beta.3",
26
+ "@tsed/schema": "7.0.0-beta.3"
23
27
  },
24
28
  "peerDependencies": {
25
- "@tsed/core": "^7.0.0-alpha.1",
26
- "@tsed/di": "^7.0.0-alpha.1",
27
- "@tsed/schema": "^7.0.0-alpha.1"
29
+ "@tsed/core": "^7.0.0-beta.3",
30
+ "@tsed/di": "^7.0.0-beta.3",
31
+ "@tsed/schema": "^7.0.0-beta.3"
28
32
  },
29
33
  "repository": "https://github.com/tsedio/tsed",
30
34
  "bugs": {
31
35
  "url": "https://github.com/tsedio/tsed/issues"
32
36
  },
33
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/platform/platform-middlewares",
37
+ "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/platform/platform-middlewares",
34
38
  "author": "Romain Lenzotti",
35
39
  "license": "MIT"
36
40
  }
@@ -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
+ }