@tsed/platform-router 7.79.4 → 7.80.1
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/types-esm/domain/PlatformHandlerMetadata.d.ts +40 -0
- package/lib/types-esm/domain/PlatformHandlerType.d.ts +10 -0
- package/lib/types-esm/domain/PlatformLayer.d.ts +44 -0
- package/lib/types-esm/domain/PlatformRouter.d.ts +29 -0
- package/lib/types-esm/domain/PlatformRouters.d.ts +21 -0
- package/lib/types-esm/domain/SinglePathType.d.ts +1 -0
- package/lib/types-esm/index.d.ts +11 -0
- package/lib/types-esm/utils/formatMethod.d.ts +1 -0
- package/lib/types-esm/utils/useContextHandler.d.ts +18 -0
- package/package.json +26 -22
- package/vitest.config.mts +21 -0
- package/jest.config.js +0 -20
- package/lib/cjs/package.json +0 -3
- package/lib/esm/package.json +0 -3
- package/tsconfig.esm.json +0 -48
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DIContext, InjectorService, Provider, ProviderScope, TokenProvider } from "@tsed/di";
|
|
2
|
+
import { JsonParameterStore } from "@tsed/schema";
|
|
3
|
+
import { PlatformHandlerType } from "./PlatformHandlerType.js";
|
|
4
|
+
import { SinglePathType } from "./SinglePathType.js";
|
|
5
|
+
export interface PlatformHandlerMetadataOpts extends Record<string, any> {
|
|
6
|
+
token?: TokenProvider;
|
|
7
|
+
}
|
|
8
|
+
export interface PlatformHandlerMetadataProps {
|
|
9
|
+
provider?: Provider;
|
|
10
|
+
handler?: any;
|
|
11
|
+
opts?: PlatformHandlerMetadataOpts;
|
|
12
|
+
propertyKey?: string | symbol;
|
|
13
|
+
type?: PlatformHandlerType;
|
|
14
|
+
}
|
|
15
|
+
export declare class PlatformHandlerMetadata {
|
|
16
|
+
#private;
|
|
17
|
+
path: SinglePathType;
|
|
18
|
+
readonly provider?: Provider;
|
|
19
|
+
readonly propertyKey: string | symbol;
|
|
20
|
+
readonly type: PlatformHandlerType;
|
|
21
|
+
readonly hasNextFunction: boolean;
|
|
22
|
+
readonly opts: PlatformHandlerMetadataOpts;
|
|
23
|
+
compiledHandler: ($ctx: DIContext) => any;
|
|
24
|
+
constructor(props: PlatformHandlerMetadataProps);
|
|
25
|
+
get target(): any;
|
|
26
|
+
get token(): any;
|
|
27
|
+
get handler(): any;
|
|
28
|
+
get scope(): ProviderScope;
|
|
29
|
+
get hasErrorParam(): boolean;
|
|
30
|
+
get store(): import("@tsed/schema").JsonMethodStore;
|
|
31
|
+
static from(injector: InjectorService, input: any, opts?: PlatformHandlerMetadataOpts): PlatformHandlerMetadata;
|
|
32
|
+
getParams(): JsonParameterStore[];
|
|
33
|
+
hasParamType(paramType: any): boolean;
|
|
34
|
+
isInjectable(): boolean;
|
|
35
|
+
isRawFn(): boolean;
|
|
36
|
+
isEndpoint(): boolean;
|
|
37
|
+
isCtxFn(): boolean;
|
|
38
|
+
isResponseFn(): boolean;
|
|
39
|
+
toString(): string;
|
|
40
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare enum PlatformHandlerType {
|
|
2
|
+
CUSTOM = "custom",
|
|
3
|
+
ENDPOINT = "endpoint",
|
|
4
|
+
MIDDLEWARE = "middleware",
|
|
5
|
+
ERR_MIDDLEWARE = "err:middleware",
|
|
6
|
+
CTX_FN = "context",
|
|
7
|
+
RESPONSE_FN = "response",
|
|
8
|
+
RAW_FN = "raw:middleware",
|
|
9
|
+
RAW_ERR_FN = "raw:err:middleware"
|
|
10
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
import { Provider } from "@tsed/di";
|
|
3
|
+
import type { PlatformParamsCallback } from "@tsed/platform-params";
|
|
4
|
+
import { PlatformHandlerMetadata } from "./PlatformHandlerMetadata.js";
|
|
5
|
+
import type { PlatformRouter } from "./PlatformRouter.js";
|
|
6
|
+
import { SinglePathType } from "./SinglePathType.js";
|
|
7
|
+
export interface PlatformLayerOptions extends Record<string, any> {
|
|
8
|
+
token?: Type<any>;
|
|
9
|
+
}
|
|
10
|
+
export interface PlatformLayerProps {
|
|
11
|
+
parent: PlatformLayer;
|
|
12
|
+
provider: Provider;
|
|
13
|
+
path: SinglePathType;
|
|
14
|
+
basePath: SinglePathType;
|
|
15
|
+
method: string;
|
|
16
|
+
handlers: any[];
|
|
17
|
+
router: PlatformRouter;
|
|
18
|
+
opts: PlatformLayerOptions;
|
|
19
|
+
}
|
|
20
|
+
export declare class PlatformLayer {
|
|
21
|
+
#private;
|
|
22
|
+
provider: Provider;
|
|
23
|
+
path: SinglePathType;
|
|
24
|
+
method: string;
|
|
25
|
+
handlers: PlatformHandlerMetadata[];
|
|
26
|
+
router?: PlatformRouter;
|
|
27
|
+
opts: PlatformLayerOptions;
|
|
28
|
+
layers: PlatformLayer[];
|
|
29
|
+
parent?: PlatformLayer;
|
|
30
|
+
basePath: SinglePathType;
|
|
31
|
+
constructor(props?: Partial<PlatformLayerProps>);
|
|
32
|
+
set(args: PlatformParamsCallback[]): void;
|
|
33
|
+
getArgs(): (SinglePathType | PlatformParamsCallback<import("@tsed/di").DIContext>)[];
|
|
34
|
+
isProvider(): boolean;
|
|
35
|
+
inspect(): {
|
|
36
|
+
basePath: string;
|
|
37
|
+
path: SinglePathType;
|
|
38
|
+
method: string;
|
|
39
|
+
handlers: string[];
|
|
40
|
+
opts: {};
|
|
41
|
+
};
|
|
42
|
+
getBasePath(): string;
|
|
43
|
+
setLayers(layers: PlatformLayer[]): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { InjectorService, Provider } from "@tsed/di";
|
|
2
|
+
import { PlatformLayer, PlatformLayerOptions } from "./PlatformLayer.js";
|
|
3
|
+
import { SinglePathType } from "./SinglePathType.js";
|
|
4
|
+
export declare class PlatformRouter {
|
|
5
|
+
#private;
|
|
6
|
+
protected readonly injector: InjectorService;
|
|
7
|
+
readonly layers: PlatformLayer[];
|
|
8
|
+
provider: Provider;
|
|
9
|
+
constructor(injector: InjectorService);
|
|
10
|
+
use(...handlers: any[]): this;
|
|
11
|
+
addRoute(method: string, path: SinglePathType, handlers: any[], opts?: PlatformLayerOptions): this;
|
|
12
|
+
all(path: SinglePathType, ...handlers: any[]): this;
|
|
13
|
+
get(path: SinglePathType, ...handlers: any[]): this;
|
|
14
|
+
post(path: SinglePathType, ...handlers: any[]): this;
|
|
15
|
+
put(path: SinglePathType, ...handlers: any[]): this;
|
|
16
|
+
delete(path: SinglePathType, ...handlers: any[]): this;
|
|
17
|
+
patch(path: SinglePathType, ...handlers: any[]): this;
|
|
18
|
+
head(path: SinglePathType, ...handlers: any[]): this;
|
|
19
|
+
options(path: SinglePathType, ...handlers: any[]): this;
|
|
20
|
+
statics(path: string, options: any): this;
|
|
21
|
+
inspect(): {
|
|
22
|
+
handlers: any[];
|
|
23
|
+
path: any;
|
|
24
|
+
basePath: string;
|
|
25
|
+
method: string;
|
|
26
|
+
opts: {};
|
|
27
|
+
}[];
|
|
28
|
+
isBuilt(): boolean;
|
|
29
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Hooks, Type } from "@tsed/core";
|
|
2
|
+
import { InjectorService, TokenProvider } from "@tsed/di";
|
|
3
|
+
import { JsonMethodStore } from "@tsed/schema";
|
|
4
|
+
import { PlatformLayer } from "./PlatformLayer.js";
|
|
5
|
+
import { PlatformRouter } from "./PlatformRouter.js";
|
|
6
|
+
export interface AlterEndpointHandlersArg {
|
|
7
|
+
before: (Type<any> | Function)[];
|
|
8
|
+
endpoint: JsonMethodStore;
|
|
9
|
+
after: (Type<any> | Function)[];
|
|
10
|
+
}
|
|
11
|
+
export declare class PlatformRouters {
|
|
12
|
+
protected readonly injector: InjectorService;
|
|
13
|
+
readonly hooks: Hooks;
|
|
14
|
+
readonly allowedVerbs: import("@tsed/schema").OperationVerbs[];
|
|
15
|
+
constructor(injector: InjectorService);
|
|
16
|
+
prebuild(): void;
|
|
17
|
+
from(token: TokenProvider, parentMiddlewares?: any[]): PlatformRouter;
|
|
18
|
+
getLayers(router: PlatformRouter): PlatformLayer[];
|
|
19
|
+
private sortHandlers;
|
|
20
|
+
private flatMapLayers;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SinglePathType = string | RegExp;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by @tsed/barrels.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./domain/PlatformHandlerMetadata.js";
|
|
5
|
+
export * from "./domain/PlatformHandlerType.js";
|
|
6
|
+
export * from "./domain/PlatformLayer.js";
|
|
7
|
+
export * from "./domain/PlatformRouter.js";
|
|
8
|
+
export * from "./domain/PlatformRouters.js";
|
|
9
|
+
export * from "./domain/SinglePathType.js";
|
|
10
|
+
export * from "./utils/formatMethod.js";
|
|
11
|
+
export * from "./utils/useContextHandler.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatMethod(method: string | undefined): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DIContext } from "@tsed/di";
|
|
2
|
+
import { PlatformHandlerType } from "../domain/PlatformHandlerType.js";
|
|
3
|
+
export type PlatformContextHandler<Context = DIContext> = ($ctx: Context) => any | Promise<any>;
|
|
4
|
+
/**
|
|
5
|
+
* Create Ts.ED context handler
|
|
6
|
+
* @param fn
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
9
|
+
export declare function useContextHandler(fn: PlatformContextHandler & {
|
|
10
|
+
type?: PlatformHandlerType;
|
|
11
|
+
}): PlatformContextHandler<DIContext> & {
|
|
12
|
+
type?: PlatformHandlerType | undefined;
|
|
13
|
+
};
|
|
14
|
+
export declare function useResponseHandler(fn: PlatformContextHandler & {
|
|
15
|
+
type?: PlatformHandlerType;
|
|
16
|
+
}): PlatformContextHandler<DIContext> & {
|
|
17
|
+
type?: PlatformHandlerType | undefined;
|
|
18
|
+
};
|
package/package.json
CHANGED
|
@@ -1,45 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-router",
|
|
3
|
-
"version": "7.79.4",
|
|
4
3
|
"description": "Router",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"version": "7.80.1",
|
|
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
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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": "
|
|
19
|
-
"build:ts": "tsc --build tsconfig.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.
|
|
26
|
-
"@tsed/core": "7.
|
|
27
|
-
"@tsed/di": "7.
|
|
28
|
-
"@tsed/exceptions": "7.
|
|
29
|
-
"@tsed/json-mapper": "7.
|
|
30
|
-
"@tsed/platform-params": "7.
|
|
31
|
-
"@tsed/schema": "7.
|
|
32
|
-
"@tsed/typescript": "7.
|
|
28
|
+
"@tsed/barrels": "7.80.1",
|
|
29
|
+
"@tsed/core": "7.80.1",
|
|
30
|
+
"@tsed/di": "7.80.1",
|
|
31
|
+
"@tsed/exceptions": "7.80.1",
|
|
32
|
+
"@tsed/json-mapper": "7.80.1",
|
|
33
|
+
"@tsed/platform-params": "7.80.1",
|
|
34
|
+
"@tsed/schema": "7.80.1",
|
|
35
|
+
"@tsed/typescript": "7.80.1",
|
|
33
36
|
"eslint": "^8.57.0",
|
|
34
|
-
"
|
|
37
|
+
"typescript": "4.9.5",
|
|
38
|
+
"vitest": "2.0.4"
|
|
35
39
|
},
|
|
36
40
|
"peerDependencies": {
|
|
37
|
-
"@tsed/core": "7.
|
|
38
|
-
"@tsed/di": "7.
|
|
39
|
-
"@tsed/exceptions": "7.
|
|
40
|
-
"@tsed/json-mapper": "7.
|
|
41
|
-
"@tsed/platform-params": "7.
|
|
42
|
-
"@tsed/schema": "7.
|
|
41
|
+
"@tsed/core": "7.80.1",
|
|
42
|
+
"@tsed/di": "7.80.1",
|
|
43
|
+
"@tsed/exceptions": "7.80.1",
|
|
44
|
+
"@tsed/json-mapper": "7.80.1",
|
|
45
|
+
"@tsed/platform-params": "7.80.1",
|
|
46
|
+
"@tsed/schema": "7.80.1"
|
|
43
47
|
},
|
|
44
48
|
"peerDependenciesMeta": {
|
|
45
49
|
"@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,20 +0,0 @@
|
|
|
1
|
-
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
-
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
-
const config = require("@tsed/jest-config");
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
...config,
|
|
7
|
-
roots: ["<rootDir>/src", "<rootDir>/test"],
|
|
8
|
-
moduleNameMapper: {
|
|
9
|
-
...config.moduleNameMapper,
|
|
10
|
-
"@tsed/platform-router": "<rootDir>/src/index.ts"
|
|
11
|
-
},
|
|
12
|
-
coverageThreshold: {
|
|
13
|
-
global: {
|
|
14
|
-
statements: 100,
|
|
15
|
-
branches: 93.28,
|
|
16
|
-
functions: 100,
|
|
17
|
-
lines: 100
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
};
|
package/lib/cjs/package.json
DELETED
package/lib/esm/package.json
DELETED
package/tsconfig.esm.json
DELETED
|
@@ -1,48 +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/exceptions"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"path": "../../specs/json-mapper"
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"path": "../platform-params"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"path": "../../specs/schema"
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
}
|