@tsed/platform-middlewares 7.79.4 → 7.80.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.
@@ -0,0 +1 @@
1
+ export declare const HTTP_METHODS: string[];
@@ -0,0 +1,23 @@
1
+ import { Type } from "@tsed/core";
2
+ /**
3
+ * Change authentication options.
4
+ *
5
+ * ```typescript
6
+ * @Controller('/mypath')
7
+ * @UseAuth(MyAuthStrategy, {role: ''})
8
+ * class MyCtrl {
9
+ *
10
+ * @Get('/')
11
+ * @AuthOptions(MyAuthStrategy, {role: 'admin'})
12
+ * public getResource(){}
13
+ * }
14
+ * ```
15
+ *
16
+ * @param guardAuth
17
+ * @param options {Object} Object passed to the customer auth strategy
18
+ * @returns {Function}
19
+ * @decorator
20
+ * @decorator
21
+ * @operation
22
+ */
23
+ export declare function AuthOptions(guardAuth: Type<any>, options?: Record<string, unknown>): Function;
@@ -0,0 +1,8 @@
1
+ import { ProviderOpts } from "@tsed/di";
2
+ /**
3
+ * Register a new Middleware class.
4
+ *
5
+ * @decorator
6
+ * @classDecorator
7
+ */
8
+ export declare function Middleware(opts?: Partial<Omit<ProviderOpts, "type">>): ClassDecorator;
@@ -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,22 @@
1
+ import { Type } from "@tsed/core";
2
+ /**
3
+ * Use custom authentication strategy on your endpoint.
4
+ *
5
+ * ```typescript
6
+ * @Controller('/mypath')
7
+ * @UseAuth(MyAuthStrategy)
8
+ * class MyCtrl {
9
+ *
10
+ * @Get('/')
11
+ * @UseAuth(MyAuthStrategy, {role: 'admin'})
12
+ * public getResource(){}
13
+ * }
14
+ * ```
15
+ *
16
+ * @param guardAuth {Type<any>} A middleware which implement a custom auth strategy
17
+ * @param options {Object} Object passed to the customer auth strategy
18
+ * @returns {Function}
19
+ * @decorator
20
+ * @operation
21
+ */
22
+ export declare function UseAuth(guardAuth: Type<any>, options?: Record<string, unknown>): 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,3 @@
1
+ export interface MiddlewareMethods {
2
+ use(...args: any[]): void | any | Promise<any>;
3
+ }
@@ -0,0 +1,18 @@
1
+ import { Env, Type } from "@tsed/core";
2
+ export type PlatformMiddlewareLoadingOptions = {
3
+ env?: Env;
4
+ use: Function | Type<any> | string;
5
+ hook?: string;
6
+ options?: any;
7
+ };
8
+ export type PlatformMiddlewareSettings = Function | Type<any> | PlatformMiddlewareLoadingOptions | string | any;
9
+ declare global {
10
+ namespace TsED {
11
+ interface Configuration {
12
+ /**
13
+ * Load middlewares on the $beforeRoutesInit hook (or on the specified hook event name).
14
+ */
15
+ middlewares: PlatformMiddlewareSettings[];
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @file Automatically generated by @tsed/barrels.
3
+ */
4
+ export * from "./constants/constants.js";
5
+ export * from "./decorators/authOptions.js";
6
+ export * from "./decorators/middleware.js";
7
+ export * from "./decorators/use.js";
8
+ export * from "./decorators/useAfter.js";
9
+ export * from "./decorators/useAuth.js";
10
+ export * from "./decorators/useBefore.js";
11
+ export * from "./decorators/useBeforeEach.js";
12
+ export * from "./domain/MiddlewareMethods.js";
13
+ export * from "./domain/PlatformMiddlewareSettings.js";
14
+ export * from "./utils/getMiddlewaresForHook.js";
@@ -0,0 +1,3 @@
1
+ import { DIConfiguration } from "@tsed/di";
2
+ import { PlatformMiddlewareLoadingOptions } from "../domain/PlatformMiddlewareSettings.js";
3
+ export declare function getMiddlewaresForHook(hook: string, settings: DIConfiguration, defaultHook?: string): PlatformMiddlewareLoadingOptions[];
package/package.json CHANGED
@@ -1,39 +1,43 @@
1
1
  {
2
2
  "name": "@tsed/platform-middlewares",
3
- "version": "7.79.4",
4
3
  "description": "Middlewares module for Ts.ED Framework",
4
+ "type": "commonjs",
5
+ "version": "7.80.0",
5
6
  "source": "./src/index.ts",
6
7
  "main": "./lib/cjs/index.js",
7
8
  "module": "./lib/esm/index.js",
8
9
  "typings": "./lib/types/index.d.ts",
9
10
  "exports": {
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"
11
+ ".": {
12
+ "types": "./lib/types/index.d.ts",
13
+ "import": "./lib/esm/index.js",
14
+ "default": "./lib/cjs/index.js"
15
+ }
14
16
  },
15
17
  "scripts": {
16
18
  "build": "yarn barrels && yarn build:ts",
17
19
  "barrels": "barrels",
18
- "test": "jest --max-workers=2 && jest-coverage-thresholds-bumper",
19
- "build:ts": "tsc --build tsconfig.json && tsc --build tsconfig.esm.json"
20
+ "test": "vitest run",
21
+ "build:ts": "tsc --build tsconfig.json",
22
+ "test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
20
23
  },
21
24
  "dependencies": {
22
25
  "tslib": "2.6.1"
23
26
  },
24
27
  "devDependencies": {
25
- "@tsed/barrels": "7.79.4",
26
- "@tsed/core": "7.79.4",
27
- "@tsed/di": "7.79.4",
28
- "@tsed/schema": "7.79.4",
29
- "@tsed/typescript": "7.79.4",
28
+ "@tsed/barrels": "7.80.0",
29
+ "@tsed/core": "7.80.0",
30
+ "@tsed/di": "7.80.0",
31
+ "@tsed/schema": "7.80.0",
32
+ "@tsed/typescript": "7.80.0",
30
33
  "eslint": "^8.57.0",
31
- "jest": "^29.7.0"
34
+ "typescript": "4.9.5",
35
+ "vitest": "2.0.4"
32
36
  },
33
37
  "peerDependencies": {
34
- "@tsed/core": "7.79.4",
35
- "@tsed/di": "7.79.4",
36
- "@tsed/schema": "7.79.4"
38
+ "@tsed/core": "7.80.0",
39
+ "@tsed/di": "7.80.0",
40
+ "@tsed/schema": "7.80.0"
37
41
  },
38
42
  "peerDependenciesMeta": {
39
43
  "@tsed/core": {
@@ -0,0 +1,21 @@
1
+ // @ts-ignore
2
+ import {presets} from "@tsed/vitest/presets";
3
+ import {defineConfig} from "vitest/config";
4
+
5
+ export default defineConfig(
6
+ {
7
+ ...presets,
8
+ test: {
9
+ ...presets.test,
10
+ coverage: {
11
+ ...presets.test.coverage,
12
+ thresholds: {
13
+ statements: 0,
14
+ branches: 0,
15
+ functions: 0,
16
+ lines: 0
17
+ }
18
+ }
19
+ }
20
+ }
21
+ );
package/jest.config.js DELETED
@@ -1,14 +0,0 @@
1
- // For a detailed explanation regarding each configuration property, visit:
2
- // https://jestjs.io/docs/en/configuration.html
3
-
4
- module.exports = {
5
- ...require("@tsed/jest-config"),
6
- coverageThreshold: {
7
- global: {
8
- statements: 100,
9
- branches: 100,
10
- functions: 100,
11
- lines: 100
12
- }
13
- }
14
- };
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
package/tsconfig.esm.json DELETED
@@ -1,39 +0,0 @@
1
- {
2
- "extends": "@tsed/typescript/tsconfig.node.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "module": "ES2020",
6
- "rootDir": "src",
7
- "outDir": "./lib/esm",
8
- "declaration": true,
9
- "declarationDir": "./lib/types",
10
- "composite": true,
11
- "noEmit": false
12
- },
13
- "include": ["src", "src/**/*.json"],
14
- "exclude": [
15
- "node_modules",
16
- "test",
17
- "lib",
18
- "benchmark",
19
- "coverage",
20
- "spec",
21
- "**/*.benchmark.ts",
22
- "**/*.spec.ts",
23
- "keys",
24
- "jest.config.js",
25
- "**/__mock__/**",
26
- "webpack.config.js"
27
- ],
28
- "references": [
29
- {
30
- "path": "../../core"
31
- },
32
- {
33
- "path": "../../di"
34
- },
35
- {
36
- "path": "../../specs/schema"
37
- }
38
- ]
39
- }