@nestbridge/core 2.1.4 → 2.2.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/CHANGELOG.md +12 -0
- package/README.md +66 -3
- package/build/nestbridge.core.d.ts +49 -5
- package/build/nestbridge.core.js +373 -15
- package/build/nestbridge.core.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @nestbridge/core
|
|
2
2
|
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 98349c7: One client can now use controllers from several NestJS apps. `nestBridge()` accepts an array of options, one entry per app, and each entry takes its own `name`, `root`, `controllers`, `resolvers`, `baseURL`, `bootstrap`, `globalPrefix` and `versioning`. A named app writes its declarations to `<outputDir>/<name>/`, detects its own response wrapper and error body from its own bootstrap file, and tags every generated request with its `name` as the `service`. A single object still works as before.
|
|
8
|
+
|
|
9
|
+
The runtime picks each request's origin from `configureNestBridge({ services })`, then the origin the plugin registered for that app with the new `setNestBridgeServiceBaseURL(name, baseURL)`, then the global `setNestBridgeBaseURL()` value. `graphqlEndpoint` also accepts a record with one endpoint per app.
|
|
10
|
+
|
|
11
|
+
`@Controller({ path, version })` and `@Version(...)` are now read, and the global prefix (`setGlobalPrefix`, including `exclude`) and URI versioning (`enableVersioning`) are detected from the bootstrap file and composed into every request path with the new `detectGlobalPrefix`, `detectVersioning` and `applyApplicationRouting` from `@nestbridge/core`. A prefix or versioning setup that cannot be read statically is reported as an `unsupported-global-prefix` or `unsupported-versioning` diagnostic; the `globalPrefix` and `versioning` plugin options state the value explicitly, and `false` ignores it.
|
|
12
|
+
|
|
13
|
+
Upgrading: the global prefix and URI versioning are now part of every URL, so a prefix that was written into `baseURL` as a workaround would now be repeated. Keep `baseURL` to the origin, or set `globalPrefix: false` / `versioning: false`. A relative `root` now resolves against the bundler's root instead of `process.cwd()`. See `MIGRATION.md`.
|
|
14
|
+
|
|
3
15
|
## 2.1.4
|
|
4
16
|
|
|
5
17
|
No changes in this release.
|
package/README.md
CHANGED
|
@@ -29,10 +29,14 @@ yarn add @nestbridge/core
|
|
|
29
29
|
Parses each file, finds classes decorated with `@Controller(...)`, and
|
|
30
30
|
extracts a plain `ControllerDefinition` per controller — its base path, and
|
|
31
31
|
each `@Get`/`@Post`/`@Put`/`@Patch`/`@Delete` method's HTTP method, route
|
|
32
|
-
path, `@Param`/`@Query`/`@Body`/`@Headers` parameter mapping, and
|
|
32
|
+
path, `version`, `@Param`/`@Query`/`@Body`/`@Headers` parameter mapping, and
|
|
33
33
|
`responseKind` (`'json'`, `'observable'` for an `Observable<T>` return type, or
|
|
34
34
|
`'stream'` for `StreamableFile`), read from the method's declared return type.
|
|
35
|
-
|
|
35
|
+
Both `@Controller('path')` and `@Controller({ path, version })` are read, and
|
|
36
|
+
a method's `@Version(...)` replaces its controller's version. A method's
|
|
37
|
+
`version` is a string, `null` for `VERSION_NEUTRAL`, or `undefined` when the
|
|
38
|
+
route states none (an array of versions uses its first entry). Anything it
|
|
39
|
+
can't safely resolve statically (a non-literal route path or version, an
|
|
36
40
|
unsupported decorator) becomes a `NestBridgeDiagnostic` instead of a guess.
|
|
37
41
|
|
|
38
42
|
```ts
|
|
@@ -117,6 +121,59 @@ import { detectErrorResponseShape } from '@nestbridge/core';
|
|
|
117
121
|
const errorResponseShape = detectErrorResponseShape('src/main.ts');
|
|
118
122
|
```
|
|
119
123
|
|
|
124
|
+
### `detectGlobalPrefix(bootstrapFilePath)`
|
|
125
|
+
|
|
126
|
+
Statically reads the app's `setGlobalPrefix(...)` call in the bootstrap file.
|
|
127
|
+
It returns a `BootstrapDetection<GlobalPrefix>`: `{ value, diagnostics }`, where
|
|
128
|
+
`value` is `{ prefix, exclude }` — `exclude` lists the routes the prefix skips
|
|
129
|
+
(string paths, and `{ path, method: RequestMethod.X }` entries as
|
|
130
|
+
`{ path, httpMethod }`) — or `undefined` when the file never sets a prefix. A
|
|
131
|
+
call that is conditional or made more than once, a prefix that is not a string
|
|
132
|
+
literal, or an exclusion it cannot read yields an `unsupported-global-prefix`
|
|
133
|
+
diagnostic and no value.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { detectGlobalPrefix } from '@nestbridge/core';
|
|
137
|
+
|
|
138
|
+
const { value: globalPrefix, diagnostics } = detectGlobalPrefix('src/main.ts');
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### `detectVersioning(bootstrapFilePath)`
|
|
142
|
+
|
|
143
|
+
Statically reads the app's `enableVersioning(...)` call. It returns a
|
|
144
|
+
`BootstrapDetection<UriVersioning>` whose `value` is
|
|
145
|
+
`{ prefix, defaultVersion? }`: the version prefix (`'v'` unless the call sets
|
|
146
|
+
another string, or `false` for none, read as `''`) and the default version of
|
|
147
|
+
routes that state none. Only `VersioningType.URI` is URL-expressible; header
|
|
148
|
+
and media-type versioning, a conditional or repeated call, and non-literal
|
|
149
|
+
values yield an `unsupported-versioning` diagnostic and no value.
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
import { detectVersioning } from '@nestbridge/core';
|
|
153
|
+
|
|
154
|
+
const { value: versioning, diagnostics } = detectVersioning('src/main.ts');
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### `applyApplicationRouting(controllers, routing)`
|
|
158
|
+
|
|
159
|
+
Composes the application-level routing onto analyzed controllers, the way Nest
|
|
160
|
+
composes a route: `[global prefix][/<version prefix><version>][controller
|
|
161
|
+
path][method path]`. It returns new `ControllerDefinition`s whose methods'
|
|
162
|
+
`path` is the full request path; a prefix-excluded route skips the prefix but
|
|
163
|
+
keeps its version, and a `null` (`VERSION_NEUTRAL`) version adds no segment.
|
|
164
|
+
`routing` is an `ApplicationRouting` — `{ globalPrefix?, versioning? }`, the
|
|
165
|
+
two `value`s detected above, or any values you supply yourself.
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
import { analyzeControllers, applyApplicationRouting } from '@nestbridge/core';
|
|
169
|
+
|
|
170
|
+
const { controllers } = analyzeControllers(files);
|
|
171
|
+
const routed = applyApplicationRouting(controllers, {
|
|
172
|
+
globalPrefix: { prefix: 'api', exclude: [{ path: 'health' }] },
|
|
173
|
+
versioning: { prefix: 'v', defaultVersion: '1' },
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
120
177
|
### `generateErrorBodyDeclaration(errorBodyTypeSource)`
|
|
121
178
|
|
|
122
179
|
Turns the `errorBodyTypeSource` from `detectErrorResponseShape` into the text
|
|
@@ -139,6 +196,11 @@ import { formatDiagnostic, NestBridgeDiagnosticError } from '@nestbridge/core';
|
|
|
139
196
|
string (file, position, message). `NestBridgeDiagnosticError` wraps one or
|
|
140
197
|
more diagnostics as a thrown `Error`.
|
|
141
198
|
|
|
199
|
+
A diagnostic's `code` is one of `unsupported-route` (a non-literal route path or
|
|
200
|
+
version), `unsupported-parameter`, `unsupported-argument`,
|
|
201
|
+
`unsupported-return-type`, `circular-type`, `unsupported-global-prefix` and
|
|
202
|
+
`unsupported-versioning`.
|
|
203
|
+
|
|
142
204
|
### Types
|
|
143
205
|
|
|
144
206
|
`ControllerAnalysisResult`, `ControllerDefinition`,
|
|
@@ -147,7 +209,8 @@ more diagnostics as a thrown `Error`.
|
|
|
147
209
|
`ResolverMethodDefinition`, `ResolverArgumentDefinition`, `SelectionField`,
|
|
148
210
|
`GraphqlOperationKind`, `ResponseKind`, `NestBridgeDiagnostic`,
|
|
149
211
|
`NestBridgeDiagnosticCode`, `ResponseWrapperDetection`,
|
|
150
|
-
`ErrorResponseShapeDetection
|
|
212
|
+
`ErrorResponseShapeDetection`, `BootstrapDetection`, `GlobalPrefix`,
|
|
213
|
+
`GlobalPrefixExclusion`, `UriVersioning`, `ApplicationRouting`.
|
|
151
214
|
|
|
152
215
|
## License
|
|
153
216
|
|
|
@@ -1,5 +1,32 @@
|
|
|
1
|
+
//#region src/models/http-method.d.ts
|
|
2
|
+
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/models/global-prefix-exclusion.d.ts
|
|
5
|
+
interface GlobalPrefixExclusion {
|
|
6
|
+
path: string;
|
|
7
|
+
httpMethod?: HttpMethod;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/models/global-prefix.d.ts
|
|
11
|
+
interface GlobalPrefix {
|
|
12
|
+
prefix: string;
|
|
13
|
+
exclude: GlobalPrefixExclusion[];
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/models/uri-versioning.d.ts
|
|
17
|
+
interface UriVersioning {
|
|
18
|
+
prefix: string;
|
|
19
|
+
defaultVersion?: string;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/models/application-routing.d.ts
|
|
23
|
+
interface ApplicationRouting {
|
|
24
|
+
globalPrefix?: GlobalPrefix;
|
|
25
|
+
versioning?: UriVersioning;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
1
28
|
//#region src/diagnostics/nestbridge-diagnostic.d.ts
|
|
2
|
-
type NestBridgeDiagnosticCode = "unsupported-route" | "unsupported-parameter" | "unsupported-argument" | "unsupported-return-type" | "circular-type";
|
|
29
|
+
type NestBridgeDiagnosticCode = "unsupported-route" | "unsupported-parameter" | "unsupported-argument" | "unsupported-return-type" | "circular-type" | "unsupported-global-prefix" | "unsupported-versioning";
|
|
3
30
|
interface NestBridgeDiagnostic {
|
|
4
31
|
code: NestBridgeDiagnosticCode;
|
|
5
32
|
title: string;
|
|
@@ -13,6 +40,12 @@ interface NestBridgeDiagnostic {
|
|
|
13
40
|
column: number;
|
|
14
41
|
}
|
|
15
42
|
//#endregion
|
|
43
|
+
//#region src/models/bootstrap-detection.d.ts
|
|
44
|
+
interface BootstrapDetection<T> {
|
|
45
|
+
value: T | undefined;
|
|
46
|
+
diagnostics: NestBridgeDiagnostic[];
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
16
49
|
//#region src/diagnostics/format-diagnostic.d.ts
|
|
17
50
|
export declare const formatDiagnostic: (diagnostic: NestBridgeDiagnostic) => string;
|
|
18
51
|
//#endregion
|
|
@@ -42,9 +75,6 @@ type ControllerParameterDefinition = (ControllerParameterBase & {
|
|
|
42
75
|
name: string;
|
|
43
76
|
});
|
|
44
77
|
//#endregion
|
|
45
|
-
//#region src/models/http-method.d.ts
|
|
46
|
-
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
47
|
-
//#endregion
|
|
48
78
|
//#region src/models/response-kind.d.ts
|
|
49
79
|
type ResponseKind = "json" | "observable" | "stream";
|
|
50
80
|
//#endregion
|
|
@@ -53,6 +83,11 @@ interface ControllerMethodDefinition {
|
|
|
53
83
|
name: string;
|
|
54
84
|
httpMethod: HttpMethod;
|
|
55
85
|
path: string;
|
|
86
|
+
/**
|
|
87
|
+
* `undefined` means the route states no version, so the application default version applies;
|
|
88
|
+
* `null` is `VERSION_NEUTRAL`, which never adds a version to the URL.
|
|
89
|
+
*/
|
|
90
|
+
version?: string | null;
|
|
56
91
|
parameters: ControllerParameterDefinition[];
|
|
57
92
|
responseKind: ResponseKind;
|
|
58
93
|
line: number;
|
|
@@ -130,9 +165,15 @@ export declare const analyzeControllers: (filePaths: readonly string[]) => Contr
|
|
|
130
165
|
//#region src/analysis/analyze-resolvers.d.ts
|
|
131
166
|
export declare const analyzeResolvers: (filePaths: readonly string[]) => ResolverAnalysisResult;
|
|
132
167
|
//#endregion
|
|
168
|
+
//#region src/analysis/apply-application-routing.d.ts
|
|
169
|
+
export declare const applyApplicationRouting: (controllers: readonly ControllerDefinition[], routing: ApplicationRouting) => ControllerDefinition[];
|
|
170
|
+
//#endregion
|
|
133
171
|
//#region src/analysis/detect-error-response-shape.d.ts
|
|
134
172
|
export declare const detectErrorResponseShape: (bootstrapFilePath: string) => ErrorResponseShapeDetection | undefined;
|
|
135
173
|
//#endregion
|
|
174
|
+
//#region src/analysis/detect-global-prefix.d.ts
|
|
175
|
+
export declare const detectGlobalPrefix: (bootstrapFilePath: string) => BootstrapDetection<GlobalPrefix>;
|
|
176
|
+
//#endregion
|
|
136
177
|
//#region src/analysis/detect-response-wrapper.d.ts
|
|
137
178
|
/**
|
|
138
179
|
* Interceptors registered first wrap those registered after them, so the
|
|
@@ -141,6 +182,9 @@ export declare const detectErrorResponseShape: (bootstrapFilePath: string) => Er
|
|
|
141
182
|
*/
|
|
142
183
|
export declare const detectResponseWrapper: (bootstrapFilePath: string) => ResponseWrapperDetection | undefined;
|
|
143
184
|
//#endregion
|
|
185
|
+
//#region src/analysis/detect-versioning.d.ts
|
|
186
|
+
export declare const detectVersioning: (bootstrapFilePath: string) => BootstrapDetection<UriVersioning>;
|
|
187
|
+
//#endregion
|
|
144
188
|
//#region src/declarations/generate-controller-declaration.d.ts
|
|
145
189
|
interface ClientDeclarationSource {
|
|
146
190
|
name: string;
|
|
@@ -158,5 +202,5 @@ export declare const generateErrorBodyDeclaration: (errorBodyTypeSource: string)
|
|
|
158
202
|
//#region src/version.d.ts
|
|
159
203
|
export declare const VERSION: string;
|
|
160
204
|
//#endregion
|
|
161
|
-
export type { ControllerAnalysisResult, ControllerDefinition, ControllerMethodDefinition, ControllerParameterDefinition, ErrorResponseShapeDetection, GraphqlOperationKind, HttpMethod, NestBridgeDiagnostic, NestBridgeDiagnosticCode, ParameterSourceKind, ResolverAnalysisResult, ResolverArgumentDefinition, ResolverDefinition, ResolverMethodDefinition, ResponseKind, ResponseWrapperDetection, SelectionField };
|
|
205
|
+
export type { ApplicationRouting, BootstrapDetection, ControllerAnalysisResult, ControllerDefinition, ControllerMethodDefinition, ControllerParameterDefinition, ErrorResponseShapeDetection, GlobalPrefix, GlobalPrefixExclusion, GraphqlOperationKind, HttpMethod, NestBridgeDiagnostic, NestBridgeDiagnosticCode, ParameterSourceKind, ResolverAnalysisResult, ResolverArgumentDefinition, ResolverDefinition, ResolverMethodDefinition, ResponseKind, ResponseWrapperDetection, SelectionField, UriVersioning };
|
|
162
206
|
//# sourceMappingURL=nestbridge.core.d.ts.map
|