@nestbridge/core 2.0.3 → 2.1.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/README.md +48 -1
- package/build/nestbridge.core.d.ts +162 -0
- package/build/nestbridge.core.js +1249 -0
- package/build/nestbridge.core.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -77,6 +77,52 @@ import { generateControllerDeclaration } from '@nestbridge/core';
|
|
|
77
77
|
const source = generateControllerDeclaration(controller, outputPath);
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
### `detectResponseWrapper(bootstrapFilePath)`
|
|
81
|
+
|
|
82
|
+
Statically detects `app.useGlobalInterceptors(...)` registrations in the
|
|
83
|
+
bootstrap file whose `intercept()` method reshapes every response through a
|
|
84
|
+
single recognized `next.handle().pipe(map(...))` call, composing multiple
|
|
85
|
+
chained interceptors in registration order, and returns the resulting
|
|
86
|
+
wrapped-response type source. Returns `undefined` when no interceptor is
|
|
87
|
+
registered, or the shape isn't exactly recognized — see the [repository
|
|
88
|
+
README](../../README.md#auto-detected-global-response-wrapper) for the full
|
|
89
|
+
rules.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { detectResponseWrapper } from '@nestbridge/core';
|
|
93
|
+
|
|
94
|
+
const responseWrapper = detectResponseWrapper('src/main.ts');
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### `detectErrorResponseShape(bootstrapFilePath)`
|
|
98
|
+
|
|
99
|
+
Statically detects a single global `@Catch(...)` exception filter —
|
|
100
|
+
registered via `app.useGlobalFilters(...)` or an `APP_FILTER` provider on the
|
|
101
|
+
root module — whose `catch()` method reshapes the error through a single
|
|
102
|
+
recognized `.json(...)`/`.send(...)` call, and returns the resulting error
|
|
103
|
+
body type source. Returns `undefined` when no filter is registered, or the
|
|
104
|
+
shape isn't exactly recognized — see the [repository
|
|
105
|
+
README](../../README.md#auto-detected-exception-filter-error-body) for the
|
|
106
|
+
full rules.
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { detectErrorResponseShape } from '@nestbridge/core';
|
|
110
|
+
|
|
111
|
+
const errorResponseShape = detectErrorResponseShape('src/main.ts');
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### `generateErrorBodyDeclaration(errorBodyTypeSource)`
|
|
115
|
+
|
|
116
|
+
Turns the `errorBodyTypeSource` from `detectErrorResponseShape` into the text
|
|
117
|
+
of the fixed `nestbridge-error-body.d.ts` declaration file, exporting a
|
|
118
|
+
`NestBridgeErrorBody` type.
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { generateErrorBodyDeclaration } from '@nestbridge/core';
|
|
122
|
+
|
|
123
|
+
const source = generateErrorBodyDeclaration(errorResponseShape.errorBodyTypeSource);
|
|
124
|
+
```
|
|
125
|
+
|
|
80
126
|
### Diagnostics
|
|
81
127
|
|
|
82
128
|
```ts
|
|
@@ -93,7 +139,8 @@ more diagnostics as a thrown `Error`.
|
|
|
93
139
|
`ControllerParameterDefinition`, `HttpMethod`, `ParameterSourceKind`,
|
|
94
140
|
`ResolverDefinition`, `ResolverMethodDefinition`,
|
|
95
141
|
`ResolverArgumentDefinition`, `SelectionField`, `GraphqlOperationKind`,
|
|
96
|
-
`NestBridgeDiagnostic`, `NestBridgeDiagnosticCode
|
|
142
|
+
`NestBridgeDiagnostic`, `NestBridgeDiagnosticCode`, `ResponseWrapperDetection`,
|
|
143
|
+
`ErrorResponseShapeDetection`.
|
|
97
144
|
|
|
98
145
|
## License
|
|
99
146
|
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
//#region src/diagnostics/nestbridge-diagnostic.d.ts
|
|
2
|
+
type NestBridgeDiagnosticCode = "unsupported-route" | "unsupported-parameter" | "unsupported-argument" | "unsupported-return-type" | "circular-type";
|
|
3
|
+
interface NestBridgeDiagnostic {
|
|
4
|
+
code: NestBridgeDiagnosticCode;
|
|
5
|
+
title: string;
|
|
6
|
+
controllerName: string;
|
|
7
|
+
memberName: string;
|
|
8
|
+
detail: string;
|
|
9
|
+
found?: string;
|
|
10
|
+
expected?: string;
|
|
11
|
+
filePath: string;
|
|
12
|
+
line: number;
|
|
13
|
+
column: number;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/diagnostics/format-diagnostic.d.ts
|
|
17
|
+
export declare const formatDiagnostic: (diagnostic: NestBridgeDiagnostic) => string;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/diagnostics/nestbridge-diagnostic-error.d.ts
|
|
20
|
+
export declare class NestBridgeDiagnosticError extends Error {
|
|
21
|
+
readonly diagnostic: NestBridgeDiagnostic;
|
|
22
|
+
constructor(diagnostic: NestBridgeDiagnostic);
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/models/controller-parameter-definition.d.ts
|
|
26
|
+
type ParameterSourceKind = "param" | "query" | "body" | "header";
|
|
27
|
+
interface ControllerParameterBase {
|
|
28
|
+
index: number;
|
|
29
|
+
parameterName: string;
|
|
30
|
+
}
|
|
31
|
+
type ControllerParameterDefinition = (ControllerParameterBase & {
|
|
32
|
+
kind: "param";
|
|
33
|
+
name: string;
|
|
34
|
+
}) | (ControllerParameterBase & {
|
|
35
|
+
kind: "query";
|
|
36
|
+
name?: string;
|
|
37
|
+
}) | (ControllerParameterBase & {
|
|
38
|
+
kind: "body";
|
|
39
|
+
name?: string;
|
|
40
|
+
}) | (ControllerParameterBase & {
|
|
41
|
+
kind: "header";
|
|
42
|
+
name: string;
|
|
43
|
+
});
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/models/http-method.d.ts
|
|
46
|
+
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/models/response-kind.d.ts
|
|
49
|
+
type ResponseKind = "json" | "observable" | "stream";
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/models/controller-method-definition.d.ts
|
|
52
|
+
interface ControllerMethodDefinition {
|
|
53
|
+
name: string;
|
|
54
|
+
httpMethod: HttpMethod;
|
|
55
|
+
path: string;
|
|
56
|
+
parameters: ControllerParameterDefinition[];
|
|
57
|
+
responseKind: ResponseKind;
|
|
58
|
+
line: number;
|
|
59
|
+
column: number;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/models/controller-definition.d.ts
|
|
63
|
+
interface ControllerDefinition {
|
|
64
|
+
name: string;
|
|
65
|
+
path: string;
|
|
66
|
+
sourceFile: string;
|
|
67
|
+
methods: ControllerMethodDefinition[];
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/models/controller-analysis-result.d.ts
|
|
71
|
+
interface ControllerAnalysisResult {
|
|
72
|
+
controllers: ControllerDefinition[];
|
|
73
|
+
diagnostics: NestBridgeDiagnostic[];
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/models/error-response-shape-detection.d.ts
|
|
77
|
+
interface ErrorResponseShapeDetection {
|
|
78
|
+
errorBodyTypeSource: string;
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/models/graphql-operation-kind.d.ts
|
|
82
|
+
type GraphqlOperationKind = "query" | "mutation";
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/models/resolver-argument-definition.d.ts
|
|
85
|
+
interface ResolverArgumentDefinition {
|
|
86
|
+
index: number;
|
|
87
|
+
parameterName: string;
|
|
88
|
+
name: string;
|
|
89
|
+
graphqlType: string;
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/models/selection-field.d.ts
|
|
93
|
+
interface SelectionField {
|
|
94
|
+
name: string;
|
|
95
|
+
children?: SelectionField[];
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/models/resolver-method-definition.d.ts
|
|
99
|
+
interface ResolverMethodDefinition {
|
|
100
|
+
name: string;
|
|
101
|
+
operationKind: GraphqlOperationKind;
|
|
102
|
+
operationName: string;
|
|
103
|
+
arguments: ResolverArgumentDefinition[];
|
|
104
|
+
selection: SelectionField[];
|
|
105
|
+
line: number;
|
|
106
|
+
column: number;
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/models/resolver-definition.d.ts
|
|
110
|
+
interface ResolverDefinition {
|
|
111
|
+
name: string;
|
|
112
|
+
sourceFile: string;
|
|
113
|
+
methods: ResolverMethodDefinition[];
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/models/resolver-analysis-result.d.ts
|
|
117
|
+
interface ResolverAnalysisResult {
|
|
118
|
+
resolvers: ResolverDefinition[];
|
|
119
|
+
diagnostics: NestBridgeDiagnostic[];
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/models/response-wrapper-detection.d.ts
|
|
123
|
+
interface ResponseWrapperDetection {
|
|
124
|
+
wrappedResultTypeSource: string;
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/analysis/analyze-controllers.d.ts
|
|
128
|
+
export declare const analyzeControllers: (filePaths: readonly string[]) => ControllerAnalysisResult;
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/analysis/analyze-resolvers.d.ts
|
|
131
|
+
export declare const analyzeResolvers: (filePaths: readonly string[]) => ResolverAnalysisResult;
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/analysis/detect-error-response-shape.d.ts
|
|
134
|
+
export declare const detectErrorResponseShape: (bootstrapFilePath: string) => ErrorResponseShapeDetection | undefined;
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/analysis/detect-response-wrapper.d.ts
|
|
137
|
+
/**
|
|
138
|
+
* Interceptors registered first wrap those registered after them, so the
|
|
139
|
+
* composed type is built from the last-registered interceptor (closest to the
|
|
140
|
+
* raw handler result) outward to the first-registered one.
|
|
141
|
+
*/
|
|
142
|
+
export declare const detectResponseWrapper: (bootstrapFilePath: string) => ResponseWrapperDetection | undefined;
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/declarations/generate-controller-declaration.d.ts
|
|
145
|
+
interface ClientDeclarationSource {
|
|
146
|
+
name: string;
|
|
147
|
+
sourceFile: string;
|
|
148
|
+
methods: readonly {
|
|
149
|
+
name: string;
|
|
150
|
+
responseKind?: ResponseKind;
|
|
151
|
+
}[];
|
|
152
|
+
}
|
|
153
|
+
export declare const generateControllerDeclaration: (controller: ClientDeclarationSource, outputFilePath: string, responseWrapper?: ResponseWrapperDetection) => string;
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/declarations/generate-error-body-declaration.d.ts
|
|
156
|
+
export declare const generateErrorBodyDeclaration: (errorBodyTypeSource: string) => string;
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/version.d.ts
|
|
159
|
+
export declare const VERSION: string;
|
|
160
|
+
//#endregion
|
|
161
|
+
export type { ControllerAnalysisResult, ControllerDefinition, ControllerMethodDefinition, ControllerParameterDefinition, ErrorResponseShapeDetection, GraphqlOperationKind, HttpMethod, NestBridgeDiagnostic, NestBridgeDiagnosticCode, ParameterSourceKind, ResolverAnalysisResult, ResolverArgumentDefinition, ResolverDefinition, ResolverMethodDefinition, ResponseKind, ResponseWrapperDetection, SelectionField };
|
|
162
|
+
//# sourceMappingURL=nestbridge.core.d.ts.map
|