@dudousxd/nestjs-codegen 0.4.1 → 0.5.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.
@@ -1,2 +1,2 @@
1
- export { l as ApiClientLayer, m as ApiHeaderContribution, n as ApiModuleDeps, C as CodegenExtension, o as EmittedFile, E as ExtensionContext, L as LeafModel, p as RequestModel, q as RequestShape, s as defineExtension, t as requestShape } from '../index-DA4uySjo.cjs';
1
+ export { l as ApiClientLayer, m as ApiHeaderContribution, n as ApiModuleDeps, C as CodegenExtension, o as EmittedFile, E as ExtensionContext, L as LeafModel, p as RequestModel, q as RequestShape, s as defineExtension, t as requestShape } from '../index-B0mS84Jj.cjs';
2
2
  import 'ts-morph';
@@ -1,2 +1,2 @@
1
- export { l as ApiClientLayer, m as ApiHeaderContribution, n as ApiModuleDeps, C as CodegenExtension, o as EmittedFile, E as ExtensionContext, L as LeafModel, p as RequestModel, q as RequestShape, s as defineExtension, t as requestShape } from '../index-DA4uySjo.js';
1
+ export { l as ApiClientLayer, m as ApiHeaderContribution, n as ApiModuleDeps, C as CodegenExtension, o as EmittedFile, E as ExtensionContext, L as LeafModel, p as RequestModel, q as RequestShape, s as defineExtension, t as requestShape } from '../index-B0mS84Jj.js';
2
2
  import 'ts-morph';
@@ -73,9 +73,17 @@ type SchemaNode = {
73
73
  } | {
74
74
  kind: 'literal';
75
75
  raw: string;
76
- } | {
76
+ }
77
+ /**
78
+ * A union of schemas. When `discriminator` is set (the shared literal property
79
+ * name, e.g. `'kind'`), this is a *discriminated* union: adapters that support
80
+ * it emit a fast tagged-union form (zod `discriminatedUnion`, valibot `variant`).
81
+ * Plain unions leave `discriminator` undefined.
82
+ */
83
+ | {
77
84
  kind: 'union';
78
85
  options: SchemaNode[];
86
+ discriminator?: string;
79
87
  } | {
80
88
  kind: 'object';
81
89
  fields: Array<{
@@ -259,6 +267,38 @@ interface UserConfig {
259
267
  /** Module specifier for the `z` import. Default: `'zod'`. */
260
268
  zodImport?: string;
261
269
  };
270
+ /**
271
+ * OpenAPI 3.1 spec export (`openapi.json`). Opt-in: omit (or `enabled: false`)
272
+ * to skip. Lowers the discovered routes + validation IR into a valid OpenAPI
273
+ * 3.1 document for ecosystem interop (consume/publish a spec).
274
+ */
275
+ openapi?: {
276
+ /** Emit `openapi.json`. Default: `false`. */
277
+ enabled?: boolean;
278
+ /** Output file name within `outDir`. Default: `'openapi.json'`. */
279
+ fileName?: string;
280
+ /** `info.title`. Default: `'NestJS API'`. */
281
+ title?: string;
282
+ /** `info.version`. Default: `'1.0.0'`. */
283
+ version?: string;
284
+ /** `info.description`. */
285
+ description?: string;
286
+ };
287
+ /**
288
+ * MSW + faker mock handler generation (`mocks.ts`). Opt-in: omit (or
289
+ * `enabled: false`) to skip. Generates Mock Service Worker handlers that return
290
+ * faker-style data matching each route's response schema.
291
+ */
292
+ mocks?: {
293
+ /** Emit `mocks.ts`. Default: `false`. */
294
+ enabled?: boolean;
295
+ /** Output file name within `outDir`. Default: `'mocks.ts'`. */
296
+ fileName?: string;
297
+ /** Deterministic seed for generated mock data. Default: `1`. */
298
+ seed?: number;
299
+ /** Base URL prepended to handler paths. Default: `''` (relative paths). */
300
+ baseUrl?: string;
301
+ };
262
302
  }
263
303
  interface ScopeConfig {
264
304
  glob: string;
@@ -288,6 +328,19 @@ interface ResolvedFormsConfig {
288
328
  watch: string;
289
329
  zodImport: string;
290
330
  }
331
+ interface ResolvedOpenApiConfig {
332
+ enabled: boolean;
333
+ fileName: string;
334
+ title: string;
335
+ version: string;
336
+ description: string | null;
337
+ }
338
+ interface ResolvedMocksConfig {
339
+ enabled: boolean;
340
+ fileName: string;
341
+ seed: number;
342
+ baseUrl: string;
343
+ }
291
344
  interface ResolvedConfig {
292
345
  extensions: CodegenExtension[];
293
346
  validation: ValidationAdapter;
@@ -300,6 +353,8 @@ interface ResolvedConfig {
300
353
  importPath: string;
301
354
  } | null;
302
355
  forms: ResolvedFormsConfig;
356
+ openapi: ResolvedOpenApiConfig;
357
+ mocks: ResolvedMocksConfig;
303
358
  }
304
359
 
305
360
  interface TypeRef {
@@ -346,9 +401,19 @@ interface ContractSource {
346
401
  query: string | null;
347
402
  body: string | null;
348
403
  response: string;
404
+ /**
405
+ * The route's error response body type, as a TS type-source string. Discovered
406
+ * from a `defineContract({ error })` zod schema, or an `@ApiResponse({ status,
407
+ * type })` decorator whose `status` is a 4xx/5xx code. Absent/null means the
408
+ * error body is untyped and resolves to `unknown` in `Route.Error<K>` (never
409
+ * `never` — an HTTP error always carries some body).
410
+ */
411
+ error?: string | null;
349
412
  queryRef?: TypeRef | null;
350
413
  bodyRef?: TypeRef | null;
351
414
  responseRef?: TypeRef | null;
415
+ /** Importable named ref for the error type (parallel to {@link responseRef}). */
416
+ errorRef?: TypeRef | null;
352
417
  filterFields?: string[] | null;
353
418
  filterFieldTypes?: FilterFieldType[] | null;
354
419
  filterSource?: 'body' | 'query' | null;
@@ -372,6 +437,23 @@ interface ContractSource {
372
437
  bodySchema?: SchemaModule | null;
373
438
  /** Neutral validation IR for the query (class-validator DTO only). */
374
439
  querySchema?: SchemaModule | null;
440
+ /**
441
+ * Neutral validation IR for the success RESPONSE body, when it can be derived
442
+ * from a class-validator-decorated response DTO. Consumed by the OpenAPI export
443
+ * (richer `responses` schemas) and the MSW+faker mock generator (schema-shaped
444
+ * mock data). Optional/additive: when absent the response degrades to the TS
445
+ * type string (`response`) and mocks fall back to a permissive shape.
446
+ */
447
+ responseSchema?: SchemaModule | null;
448
+ /**
449
+ * True when the route is a server-sent-events / streaming endpoint: it carries
450
+ * a `@Sse()` decorator, or its handler returns `Observable<T>` /
451
+ * `AsyncIterable<T>` / `AsyncGenerator<T>`. When set, `response` (and
452
+ * `responseRef`) describe the streamed ELEMENT type `T` (NestJS `MessageEvent<T>`
453
+ * wrappers are unwrapped to `T`), and the client surfaces the route as an
454
+ * `AsyncIterable<T>` stream rather than a single awaited value.
455
+ */
456
+ stream?: boolean;
375
457
  }
376
458
  interface ContractDescriptor {
377
459
  contractSource: ContractSource;
@@ -73,9 +73,17 @@ type SchemaNode = {
73
73
  } | {
74
74
  kind: 'literal';
75
75
  raw: string;
76
- } | {
76
+ }
77
+ /**
78
+ * A union of schemas. When `discriminator` is set (the shared literal property
79
+ * name, e.g. `'kind'`), this is a *discriminated* union: adapters that support
80
+ * it emit a fast tagged-union form (zod `discriminatedUnion`, valibot `variant`).
81
+ * Plain unions leave `discriminator` undefined.
82
+ */
83
+ | {
77
84
  kind: 'union';
78
85
  options: SchemaNode[];
86
+ discriminator?: string;
79
87
  } | {
80
88
  kind: 'object';
81
89
  fields: Array<{
@@ -259,6 +267,38 @@ interface UserConfig {
259
267
  /** Module specifier for the `z` import. Default: `'zod'`. */
260
268
  zodImport?: string;
261
269
  };
270
+ /**
271
+ * OpenAPI 3.1 spec export (`openapi.json`). Opt-in: omit (or `enabled: false`)
272
+ * to skip. Lowers the discovered routes + validation IR into a valid OpenAPI
273
+ * 3.1 document for ecosystem interop (consume/publish a spec).
274
+ */
275
+ openapi?: {
276
+ /** Emit `openapi.json`. Default: `false`. */
277
+ enabled?: boolean;
278
+ /** Output file name within `outDir`. Default: `'openapi.json'`. */
279
+ fileName?: string;
280
+ /** `info.title`. Default: `'NestJS API'`. */
281
+ title?: string;
282
+ /** `info.version`. Default: `'1.0.0'`. */
283
+ version?: string;
284
+ /** `info.description`. */
285
+ description?: string;
286
+ };
287
+ /**
288
+ * MSW + faker mock handler generation (`mocks.ts`). Opt-in: omit (or
289
+ * `enabled: false`) to skip. Generates Mock Service Worker handlers that return
290
+ * faker-style data matching each route's response schema.
291
+ */
292
+ mocks?: {
293
+ /** Emit `mocks.ts`. Default: `false`. */
294
+ enabled?: boolean;
295
+ /** Output file name within `outDir`. Default: `'mocks.ts'`. */
296
+ fileName?: string;
297
+ /** Deterministic seed for generated mock data. Default: `1`. */
298
+ seed?: number;
299
+ /** Base URL prepended to handler paths. Default: `''` (relative paths). */
300
+ baseUrl?: string;
301
+ };
262
302
  }
263
303
  interface ScopeConfig {
264
304
  glob: string;
@@ -288,6 +328,19 @@ interface ResolvedFormsConfig {
288
328
  watch: string;
289
329
  zodImport: string;
290
330
  }
331
+ interface ResolvedOpenApiConfig {
332
+ enabled: boolean;
333
+ fileName: string;
334
+ title: string;
335
+ version: string;
336
+ description: string | null;
337
+ }
338
+ interface ResolvedMocksConfig {
339
+ enabled: boolean;
340
+ fileName: string;
341
+ seed: number;
342
+ baseUrl: string;
343
+ }
291
344
  interface ResolvedConfig {
292
345
  extensions: CodegenExtension[];
293
346
  validation: ValidationAdapter;
@@ -300,6 +353,8 @@ interface ResolvedConfig {
300
353
  importPath: string;
301
354
  } | null;
302
355
  forms: ResolvedFormsConfig;
356
+ openapi: ResolvedOpenApiConfig;
357
+ mocks: ResolvedMocksConfig;
303
358
  }
304
359
 
305
360
  interface TypeRef {
@@ -346,9 +401,19 @@ interface ContractSource {
346
401
  query: string | null;
347
402
  body: string | null;
348
403
  response: string;
404
+ /**
405
+ * The route's error response body type, as a TS type-source string. Discovered
406
+ * from a `defineContract({ error })` zod schema, or an `@ApiResponse({ status,
407
+ * type })` decorator whose `status` is a 4xx/5xx code. Absent/null means the
408
+ * error body is untyped and resolves to `unknown` in `Route.Error<K>` (never
409
+ * `never` — an HTTP error always carries some body).
410
+ */
411
+ error?: string | null;
349
412
  queryRef?: TypeRef | null;
350
413
  bodyRef?: TypeRef | null;
351
414
  responseRef?: TypeRef | null;
415
+ /** Importable named ref for the error type (parallel to {@link responseRef}). */
416
+ errorRef?: TypeRef | null;
352
417
  filterFields?: string[] | null;
353
418
  filterFieldTypes?: FilterFieldType[] | null;
354
419
  filterSource?: 'body' | 'query' | null;
@@ -372,6 +437,23 @@ interface ContractSource {
372
437
  bodySchema?: SchemaModule | null;
373
438
  /** Neutral validation IR for the query (class-validator DTO only). */
374
439
  querySchema?: SchemaModule | null;
440
+ /**
441
+ * Neutral validation IR for the success RESPONSE body, when it can be derived
442
+ * from a class-validator-decorated response DTO. Consumed by the OpenAPI export
443
+ * (richer `responses` schemas) and the MSW+faker mock generator (schema-shaped
444
+ * mock data). Optional/additive: when absent the response degrades to the TS
445
+ * type string (`response`) and mocks fall back to a permissive shape.
446
+ */
447
+ responseSchema?: SchemaModule | null;
448
+ /**
449
+ * True when the route is a server-sent-events / streaming endpoint: it carries
450
+ * a `@Sse()` decorator, or its handler returns `Observable<T>` /
451
+ * `AsyncIterable<T>` / `AsyncGenerator<T>`. When set, `response` (and
452
+ * `responseRef`) describe the streamed ELEMENT type `T` (NestJS `MessageEvent<T>`
453
+ * wrappers are unwrapped to `T`), and the client surfaces the route as an
454
+ * `AsyncIterable<T>` stream rather than a single awaited value.
455
+ */
456
+ stream?: boolean;
375
457
  }
376
458
  interface ContractDescriptor {
377
459
  contractSource: ContractSource;