@nestbridge/core 3.0.0 → 3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @nestbridge/core
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 531bf3e: Declare the response shape of any interceptor in an optional `nestbridge.d.ts` or `nestbridge-env.d.ts` at the server `root` (equivalent names, both can be used together), and keep the types of the interceptors around an unsupported one.
8
+
9
+ Export one generic type alias per interceptor, named after the interceptor class (`export type ZodSerializerInterceptor<T> = T;`). `T` is the value coming from inside; an alias with no type parameter is a fixed shape that discards what is inside it. A matching alias wins over local analysis, the package shape-neutral rule and the unsupported diagnostic, and the interceptor is matched by its exported class name even when imported under another name. Only exported `type` aliases with zero or one type parameter are accepted; anything else exported from a file, `declare global` and `declare module` are reported as the new `invalid-interceptor-declaration` diagnostic. NestBridge writes `<outputDir>/<package name>/interceptors.d.ts`, re-exporting every alias with one line per file, and the controller declarations import the aliases they use from it. A name exported by both files is reported and used from neither. Creating, editing or deleting either file regenerates the declarations in watch mode.
10
+
11
+ An unsupported interceptor still reports its diagnostic, but it now contributes `unknown` to its route instead of turning the whole route into `AbortablePromise<unknown>`: the interceptors outside it still apply, so a declared `TransformInterceptor<T> = { data: T; meta: ... }` outside an unsupported interceptor gives `{ data: unknown; meta: ... }`. A route whose outermost result is `unknown` stays `AbortablePromise<unknown>`, and so does a route with a registration that cannot be placed in the chain (a spread `APP_INTERCEPTOR` provider, a `@UseInterceptors` argument that is not a class or `new X()`).
12
+
13
+ `@nestbridge/core` adds `analyzeControllers` option `interceptorDeclarationFilePaths`, the result field `interceptorDeclarations`, `generateInterceptorsDeclaration` (takes the declarations and the output path), the `INTERCEPTOR_DECLARATION_FILE_NAMES` constant and an optional `declaredInterceptors` list on `ResponseWrapperDetection`; `generateControllerDeclaration` takes an options argument with `interceptorsDeclarationFilePath`.
14
+
15
+ ### Patch Changes
16
+
17
+ - 531bf3e: Interceptors that come from a package are now treated as shape-neutral instead of failing the build with `unsupported-interceptor`.
18
+
19
+ An interceptor class whose import resolves into `node_modules`, or to a declaration or JavaScript file, such as `ZodSerializerInterceptor` from `nestjs-zod` or Nest's own `ClassSerializerInterceptor` and `CacheInterceptor`, produces no diagnostic and leaves the route's type as it would be without it, in every registration form (`APP_INTERCEPTOR`, `useGlobalInterceptors(new X(...))`, `@UseInterceptors`). A package interceptor that really does change the response shape is not reflected in the types. Local interceptors and workspace libraries that resolve to TypeScript source are analyzed as before, and an import that does not resolve is still reported.
20
+
3
21
  ## 3.0.0
4
22
 
5
23
  ### Minor Changes
package/README.md CHANGED
@@ -52,8 +52,12 @@ interceptors that apply to it (global `APP_INTERCEPTOR` providers, then
52
52
  `useGlobalInterceptors(...)` in the bootstrap file, then the controller's and
53
53
  the method's `@UseInterceptors`, outermost first). A method no interceptor
54
54
  reshapes has no `responseWrapper`. An interceptor that cannot be read gives an
55
- `unsupported-interceptor` diagnostic, once per interceptor, and its methods get
56
- a `responseWrapper` of `unknown`. `interceptorFiles` lists the files that took
55
+ `unsupported-interceptor` diagnostic, once per interceptor, and it contributes
56
+ `unknown` to the chain (so a route whose outermost interceptor is unsupported gets a
57
+ `responseWrapper` of `unknown`). Interceptors named by an exported type alias in
58
+ the files given as `interceptorDeclarationFilePaths` (`nestbridge.d.ts` and
59
+ `nestbridge-env.d.ts`, read in that order) use that
60
+ alias instead, and the result lists them as `interceptorDeclarations`. `interceptorFiles` lists the files that took
57
61
  part in that detection, so a watcher knows what to re-analyze. Message handlers
58
62
  and GraphQL resolvers are not wrapped yet. See the [repository
59
63
  README](../../README.md#auto-detected-response-shaping-interceptors) for the
@@ -26,7 +26,7 @@ interface ApplicationRouting {
26
26
  }
27
27
  //#endregion
28
28
  //#region src/diagnostics/nestbridge-diagnostic.d.ts
29
- type NestBridgeDiagnosticCode = "unsupported-route" | "unsupported-parameter" | "unsupported-argument" | "unsupported-return-type" | "circular-type" | "unsupported-global-prefix" | "unsupported-versioning" | "unsupported-message-pattern" | "unsupported-interceptor";
29
+ type NestBridgeDiagnosticCode = "unsupported-route" | "unsupported-parameter" | "unsupported-argument" | "unsupported-return-type" | "circular-type" | "unsupported-global-prefix" | "unsupported-versioning" | "unsupported-message-pattern" | "unsupported-interceptor" | "invalid-interceptor-declaration";
30
30
  interface NestBridgeDiagnostic {
31
31
  code: NestBridgeDiagnosticCode;
32
32
  title: string;
@@ -59,6 +59,12 @@ interface ControllerAnalysisOptions {
59
59
  * from it. Without it, only `@UseInterceptors()` on controllers and routes is analyzed.
60
60
  */
61
61
  bootstrapFilePath?: string;
62
+ /**
63
+ * The server's interceptor declaration files (`INTERCEPTOR_DECLARATION_FILE_NAMES` under its
64
+ * root), in reading order. They declare the response shape of interceptors by name. Each one is
65
+ * read when it exists; a missing file changes nothing.
66
+ */
67
+ interceptorDeclarationFilePaths?: readonly string[];
62
68
  }
63
69
  //#endregion
64
70
  //#region src/diagnostics/format-diagnostic.d.ts
@@ -100,6 +106,11 @@ type ResponseKind = "json" | "observable" | "stream";
100
106
  */
101
107
  interface ResponseWrapperDetection {
102
108
  wrappedResultTypeSource: string;
109
+ /**
110
+ * The interceptor declarations the source refers to, each as `DECLARED_INTERCEPTOR_PREFIX`
111
+ * followed by its name. Absent when the source refers to none.
112
+ */
113
+ declaredInterceptors?: readonly string[];
103
114
  }
104
115
  //#endregion
105
116
  //#region src/models/controller-method-definition.d.ts
@@ -160,6 +171,18 @@ interface ControllerDefinition {
160
171
  messageHandlers: MessageHandlerDefinition[];
161
172
  }
162
173
  //#endregion
174
+ //#region src/models/interceptor-declaration.d.ts
175
+ /**
176
+ * An exported type alias of one of the server's interceptor declaration files, named after an interceptor class.
177
+ * `typeParameterCount` is 1 when the alias receives the inner shape as `T`, and 0 when it is a
178
+ * fixed shape that ignores what is inside it.
179
+ */
180
+ interface InterceptorDeclaration {
181
+ name: string;
182
+ filePath: string;
183
+ typeParameterCount: 0 | 1;
184
+ }
185
+ //#endregion
163
186
  //#region src/models/controller-analysis-result.d.ts
164
187
  interface ControllerAnalysisResult {
165
188
  controllers: ControllerDefinition[];
@@ -170,6 +193,8 @@ interface ControllerAnalysisResult {
170
193
  * classes. A change to any of them can change the declared response types.
171
194
  */
172
195
  interceptorFiles: string[];
196
+ /** The valid exported aliases of the interceptor declarations file, in source order. */
197
+ interceptorDeclarations: InterceptorDeclaration[];
173
198
  }
174
199
  //#endregion
175
200
  //#region src/models/error-response-shape-detection.d.ts
@@ -236,6 +261,18 @@ export declare const detectGlobalPrefix: (bootstrapFilePath: string) => Bootstra
236
261
  //#region src/analysis/detect-versioning.d.ts
237
262
  export declare const detectVersioning: (bootstrapFilePath: string) => BootstrapDetection<UriVersioning>;
238
263
  //#endregion
264
+ //#region src/analysis/interceptor-declaration-file-names.d.ts
265
+ export declare const INTERCEPTOR_DECLARATION_FILE_NAMES: readonly ["nestbridge.d.ts", "nestbridge-env.d.ts"];
266
+ //#endregion
267
+ //#region src/declarations/controller-declaration-options.d.ts
268
+ interface ControllerDeclarationOptions {
269
+ /**
270
+ * The generated `interceptors.d.ts` the declared interceptor aliases are imported from. Needed
271
+ * only by controllers whose routes use a declared interceptor.
272
+ */
273
+ interceptorsDeclarationFilePath?: string;
274
+ }
275
+ //#endregion
239
276
  //#region src/declarations/generate-controller-declaration.d.ts
240
277
  interface ClientDeclarationParameter {
241
278
  index: number;
@@ -255,13 +292,20 @@ interface ClientDeclarationSource {
255
292
  methods: readonly ClientDeclarationMethod[];
256
293
  messageHandlers?: readonly ClientDeclarationMessageHandler[];
257
294
  }
258
- export declare const generateControllerDeclaration: (controller: ClientDeclarationSource, outputFilePath: string) => string;
295
+ export declare const generateControllerDeclaration: (controller: ClientDeclarationSource, outputFilePath: string, options?: ControllerDeclarationOptions) => string;
259
296
  //#endregion
260
297
  //#region src/declarations/generate-error-body-declaration.d.ts
261
298
  export declare const generateErrorBodyDeclaration: (errorBodyTypeSource: string) => string;
262
299
  //#endregion
300
+ //#region src/declarations/generate-interceptors-declaration.d.ts
301
+ /**
302
+ * One re-export line per declaration file, in the order the files were read. A file that
303
+ * contributes no alias gets no line.
304
+ */
305
+ export declare const generateInterceptorsDeclaration: (declarations: readonly InterceptorDeclaration[], outputFilePath: string) => string;
306
+ //#endregion
263
307
  //#region src/version.d.ts
264
308
  export declare const VERSION: string;
265
309
  //#endregion
266
- export type { ApplicationRouting, BootstrapDetection, ControllerAnalysisOptions, ControllerAnalysisResult, ControllerDefinition, ControllerMethodDefinition, ControllerParameterDefinition, ErrorResponseShapeDetection, GlobalPrefix, GlobalPrefixExclusion, GraphqlOperationKind, HttpMethod, MessageHandlerDefinition, MessageKind, MessagePattern, NestBridgeDiagnostic, NestBridgeDiagnosticCode, ParameterSourceKind, ResolverAnalysisResult, ResolverArgumentDefinition, ResolverDefinition, ResolverMethodDefinition, ResponseKind, ResponseWrapperDetection, SelectionField, UriVersioning };
310
+ export type { ApplicationRouting, BootstrapDetection, ControllerAnalysisOptions, ControllerAnalysisResult, ControllerDeclarationOptions, ControllerDefinition, ControllerMethodDefinition, ControllerParameterDefinition, ErrorResponseShapeDetection, GlobalPrefix, GlobalPrefixExclusion, GraphqlOperationKind, HttpMethod, InterceptorDeclaration, MessageHandlerDefinition, MessageKind, MessagePattern, NestBridgeDiagnostic, NestBridgeDiagnosticCode, ParameterSourceKind, ResolverAnalysisResult, ResolverArgumentDefinition, ResolverDefinition, ResolverMethodDefinition, ResponseKind, ResponseWrapperDetection, SelectionField, UriVersioning };
267
311
  //# sourceMappingURL=nestbridge.core.d.ts.map