@dudousxd/nestjs-codegen 0.4.1 → 0.5.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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as SchemaModule, c as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext } from './index-DA4uySjo.cjs';
2
- export { A as AdapterUsage, d as ContractDescriptor, e as ContractSource, f as ControllerRef, N as NumberCheck, g as RenderContext, h as RenderedModule, i as ScopeConfig, j as StringCheck, T as TypeRef, k as ValidationOption, r as resolveAdapter } from './index-DA4uySjo.cjs';
1
+ import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as SchemaModule, c as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext } from './index-B0mS84Jj.cjs';
2
+ export { A as AdapterUsage, d as ContractDescriptor, e as ContractSource, f as ControllerRef, N as NumberCheck, g as RenderContext, h as RenderedModule, i as ScopeConfig, j as StringCheck, T as TypeRef, k as ValidationOption, r as resolveAdapter } from './index-B0mS84Jj.cjs';
3
3
  import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
4
4
 
5
5
  declare function defineConfig(c: UserConfig): UserConfig;
@@ -154,6 +154,106 @@ declare function emitApi(routes: RouteDescriptor[], outDir: string, opts?: ApiEm
154
154
  */
155
155
  declare function emitRoutes(routes: RouteDescriptor[], outDir: string): Promise<void>;
156
156
 
157
+ /**
158
+ * Converts the neutral {@link SchemaNode} / {@link SchemaModule} IR into a
159
+ * JSON Schema object compatible with the OpenAPI 3.1 schema dialect (which *is*
160
+ * JSON Schema 2020-12). This is the shared lowering used by both the OpenAPI 3.1
161
+ * exporter (`emit/emit-openapi.ts`) and the MSW+faker mock generator
162
+ * (`emit/emit-msw.ts`) — they consume the same JSON Schema so the spec and the
163
+ * mocks can never disagree about a route's shape.
164
+ *
165
+ * Design notes:
166
+ * - `enum` literals and `literal.raw` are verbatim TS source texts (quote style
167
+ * preserved, produced by ts-morph `getText()`), e.g. `'active'`, `42`, `true`,
168
+ * `null`. They are parsed back into real JSON values by {@link parseLiteral}.
169
+ * - Named schemas (the `named` map of a `SchemaModule`) are lowered into
170
+ * `components/schemas` and referenced via `$ref`, so recursion (`lazyRef`) and
171
+ * sharing produce real `$ref` cycles rather than infinite inlining.
172
+ * - `optional` only affects an *object field's* membership in `required`; a bare
173
+ * optional widens the type with `null` (the closest JSON Schema analog).
174
+ */
175
+
176
+ /** A minimal JSON Schema object (OpenAPI 3.1 dialect). Open-ended on purpose. */
177
+ type JsonSchema = {
178
+ type?: string | string[];
179
+ format?: string;
180
+ enum?: unknown[];
181
+ const?: unknown;
182
+ items?: JsonSchema;
183
+ properties?: Record<string, JsonSchema>;
184
+ required?: string[];
185
+ additionalProperties?: boolean | JsonSchema;
186
+ oneOf?: JsonSchema[];
187
+ anyOf?: JsonSchema[];
188
+ discriminator?: {
189
+ propertyName: string;
190
+ };
191
+ $ref?: string;
192
+ description?: string;
193
+ nullable?: boolean;
194
+ [key: string]: unknown;
195
+ };
196
+ interface JsonSchemaContext {
197
+ /** Prefix for `$ref` targets. Default `'#/components/schemas/'`. */
198
+ refPrefix: string;
199
+ }
200
+ /** Convert a single {@link SchemaNode} to a JSON Schema object. */
201
+ declare function schemaNodeToJsonSchema(node: SchemaNode, ctx?: JsonSchemaContext): JsonSchema;
202
+ /**
203
+ * Lower an entire {@link SchemaModule} to a `{ root, named }` pair of JSON
204
+ * Schemas. The `named` map becomes `components/schemas` entries; `root` is the
205
+ * route-level schema that references them via `$ref`.
206
+ */
207
+ declare function schemaModuleToJsonSchema(mod: SchemaModule, ctx?: JsonSchemaContext): {
208
+ root: JsonSchema;
209
+ named: Record<string, JsonSchema>;
210
+ };
211
+
212
+ interface OpenApiInfo {
213
+ title?: string;
214
+ version?: string;
215
+ description?: string;
216
+ }
217
+ interface OpenApiEmitOptions {
218
+ info?: OpenApiInfo;
219
+ /** Output file name within `outDir`. Default `'openapi.json'`. */
220
+ fileName?: string;
221
+ }
222
+ interface OpenApiDocument {
223
+ openapi: '3.1.0';
224
+ info: {
225
+ title: string;
226
+ version: string;
227
+ description?: string;
228
+ };
229
+ paths: Record<string, Record<string, unknown>>;
230
+ components: {
231
+ schemas: Record<string, JsonSchema>;
232
+ };
233
+ }
234
+ /** Build the OpenAPI 3.1 document object from the route set. Pure (no I/O). */
235
+ declare function buildOpenApiSpec(routes: RouteDescriptor[], opts?: OpenApiEmitOptions): OpenApiDocument;
236
+ /** Emit `openapi.json` into `outDir` for all contracted routes. */
237
+ declare function emitOpenApi(routes: RouteDescriptor[], outDir: string, opts?: OpenApiEmitOptions): Promise<void>;
238
+
239
+ interface MocksEmitOptions {
240
+ /** Output file name within `outDir`. Default `'mocks.ts'`. */
241
+ fileName?: string;
242
+ /** Deterministic seed. Default `1`. */
243
+ seed?: number;
244
+ /** Base URL prepended to handler paths. Default `''`. */
245
+ baseUrl?: string;
246
+ }
247
+ /** Build the `mocks.ts` source text. Pure (no I/O). */
248
+ declare function buildMocksFile(routes: RouteDescriptor[], opts?: MocksEmitOptions): string;
249
+ /** Emit `mocks.ts` into `outDir`. */
250
+ declare function emitMocks(routes: RouteDescriptor[], outDir: string, opts?: MocksEmitOptions): Promise<void>;
251
+
252
+ /**
253
+ * Static AST-based contract discovery using ts-morph.
254
+ * Cold start ~100-500 ms.
255
+ */
256
+
157
257
  interface FastDiscoveryOptions {
158
258
  /** Absolute path to the project root. */
159
259
  cwd: string;
@@ -164,6 +264,6 @@ interface FastDiscoveryOptions {
164
264
  }
165
265
  declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
166
266
 
167
- declare const VERSION = "0.4.1";
267
+ declare const VERSION = "0.5.1";
168
268
 
169
- export { CodegenError, ConfigError, type FastDiscoveryOptions, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, defineConfig, discoverContractsFast, emitApi, emitForms, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, watch };
269
+ export { CodegenError, ConfigError, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, buildMocksFile, buildOpenApiSpec, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, watch };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as SchemaModule, c as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext } from './index-DA4uySjo.js';
2
- export { A as AdapterUsage, d as ContractDescriptor, e as ContractSource, f as ControllerRef, N as NumberCheck, g as RenderContext, h as RenderedModule, i as ScopeConfig, j as StringCheck, T as TypeRef, k as ValidationOption, r as resolveAdapter } from './index-DA4uySjo.js';
1
+ import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as SchemaModule, c as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext } from './index-B0mS84Jj.js';
2
+ export { A as AdapterUsage, d as ContractDescriptor, e as ContractSource, f as ControllerRef, N as NumberCheck, g as RenderContext, h as RenderedModule, i as ScopeConfig, j as StringCheck, T as TypeRef, k as ValidationOption, r as resolveAdapter } from './index-B0mS84Jj.js';
3
3
  import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
4
4
 
5
5
  declare function defineConfig(c: UserConfig): UserConfig;
@@ -154,6 +154,106 @@ declare function emitApi(routes: RouteDescriptor[], outDir: string, opts?: ApiEm
154
154
  */
155
155
  declare function emitRoutes(routes: RouteDescriptor[], outDir: string): Promise<void>;
156
156
 
157
+ /**
158
+ * Converts the neutral {@link SchemaNode} / {@link SchemaModule} IR into a
159
+ * JSON Schema object compatible with the OpenAPI 3.1 schema dialect (which *is*
160
+ * JSON Schema 2020-12). This is the shared lowering used by both the OpenAPI 3.1
161
+ * exporter (`emit/emit-openapi.ts`) and the MSW+faker mock generator
162
+ * (`emit/emit-msw.ts`) — they consume the same JSON Schema so the spec and the
163
+ * mocks can never disagree about a route's shape.
164
+ *
165
+ * Design notes:
166
+ * - `enum` literals and `literal.raw` are verbatim TS source texts (quote style
167
+ * preserved, produced by ts-morph `getText()`), e.g. `'active'`, `42`, `true`,
168
+ * `null`. They are parsed back into real JSON values by {@link parseLiteral}.
169
+ * - Named schemas (the `named` map of a `SchemaModule`) are lowered into
170
+ * `components/schemas` and referenced via `$ref`, so recursion (`lazyRef`) and
171
+ * sharing produce real `$ref` cycles rather than infinite inlining.
172
+ * - `optional` only affects an *object field's* membership in `required`; a bare
173
+ * optional widens the type with `null` (the closest JSON Schema analog).
174
+ */
175
+
176
+ /** A minimal JSON Schema object (OpenAPI 3.1 dialect). Open-ended on purpose. */
177
+ type JsonSchema = {
178
+ type?: string | string[];
179
+ format?: string;
180
+ enum?: unknown[];
181
+ const?: unknown;
182
+ items?: JsonSchema;
183
+ properties?: Record<string, JsonSchema>;
184
+ required?: string[];
185
+ additionalProperties?: boolean | JsonSchema;
186
+ oneOf?: JsonSchema[];
187
+ anyOf?: JsonSchema[];
188
+ discriminator?: {
189
+ propertyName: string;
190
+ };
191
+ $ref?: string;
192
+ description?: string;
193
+ nullable?: boolean;
194
+ [key: string]: unknown;
195
+ };
196
+ interface JsonSchemaContext {
197
+ /** Prefix for `$ref` targets. Default `'#/components/schemas/'`. */
198
+ refPrefix: string;
199
+ }
200
+ /** Convert a single {@link SchemaNode} to a JSON Schema object. */
201
+ declare function schemaNodeToJsonSchema(node: SchemaNode, ctx?: JsonSchemaContext): JsonSchema;
202
+ /**
203
+ * Lower an entire {@link SchemaModule} to a `{ root, named }` pair of JSON
204
+ * Schemas. The `named` map becomes `components/schemas` entries; `root` is the
205
+ * route-level schema that references them via `$ref`.
206
+ */
207
+ declare function schemaModuleToJsonSchema(mod: SchemaModule, ctx?: JsonSchemaContext): {
208
+ root: JsonSchema;
209
+ named: Record<string, JsonSchema>;
210
+ };
211
+
212
+ interface OpenApiInfo {
213
+ title?: string;
214
+ version?: string;
215
+ description?: string;
216
+ }
217
+ interface OpenApiEmitOptions {
218
+ info?: OpenApiInfo;
219
+ /** Output file name within `outDir`. Default `'openapi.json'`. */
220
+ fileName?: string;
221
+ }
222
+ interface OpenApiDocument {
223
+ openapi: '3.1.0';
224
+ info: {
225
+ title: string;
226
+ version: string;
227
+ description?: string;
228
+ };
229
+ paths: Record<string, Record<string, unknown>>;
230
+ components: {
231
+ schemas: Record<string, JsonSchema>;
232
+ };
233
+ }
234
+ /** Build the OpenAPI 3.1 document object from the route set. Pure (no I/O). */
235
+ declare function buildOpenApiSpec(routes: RouteDescriptor[], opts?: OpenApiEmitOptions): OpenApiDocument;
236
+ /** Emit `openapi.json` into `outDir` for all contracted routes. */
237
+ declare function emitOpenApi(routes: RouteDescriptor[], outDir: string, opts?: OpenApiEmitOptions): Promise<void>;
238
+
239
+ interface MocksEmitOptions {
240
+ /** Output file name within `outDir`. Default `'mocks.ts'`. */
241
+ fileName?: string;
242
+ /** Deterministic seed. Default `1`. */
243
+ seed?: number;
244
+ /** Base URL prepended to handler paths. Default `''`. */
245
+ baseUrl?: string;
246
+ }
247
+ /** Build the `mocks.ts` source text. Pure (no I/O). */
248
+ declare function buildMocksFile(routes: RouteDescriptor[], opts?: MocksEmitOptions): string;
249
+ /** Emit `mocks.ts` into `outDir`. */
250
+ declare function emitMocks(routes: RouteDescriptor[], outDir: string, opts?: MocksEmitOptions): Promise<void>;
251
+
252
+ /**
253
+ * Static AST-based contract discovery using ts-morph.
254
+ * Cold start ~100-500 ms.
255
+ */
256
+
157
257
  interface FastDiscoveryOptions {
158
258
  /** Absolute path to the project root. */
159
259
  cwd: string;
@@ -164,6 +264,6 @@ interface FastDiscoveryOptions {
164
264
  }
165
265
  declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
166
266
 
167
- declare const VERSION = "0.4.1";
267
+ declare const VERSION = "0.5.1";
168
268
 
169
- export { CodegenError, ConfigError, type FastDiscoveryOptions, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, defineConfig, discoverContractsFast, emitApi, emitForms, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, watch };
269
+ export { CodegenError, ConfigError, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, buildMocksFile, buildOpenApiSpec, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, watch };