@dudousxd/nestjs-codegen 0.5.1 → 0.5.2

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-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';
1
+ import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext } from './index-_qRai4M3.cjs';
2
+ export { A as AdapterUsage, f as ContractDescriptor, g as ContractSource, h as ControllerRef, N as NumberCheck, i as ScopeConfig, j as StringCheck, T as TypeRef, k as ValidationOption, r as resolveAdapter } from './index-_qRai4M3.cjs';
3
3
  import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
4
4
 
5
5
  declare function defineConfig(c: UserConfig): UserConfig;
@@ -98,6 +98,31 @@ interface TsTypeContext {
98
98
  }
99
99
  declare function renderTsType(node: SchemaNode, ctx: TsTypeContext): string;
100
100
 
101
+ /** Schema const name → hoisted TS type-alias name (`ColumnFilterSchema` → `ColumnFilter`). */
102
+ declare function typeNameFor(schemaName: string): string;
103
+ /** Valid JS identifier → bare key, else quoted. */
104
+ declare function toObjectKey(name: string): string;
105
+ interface ChainModuleRendererOptions {
106
+ /** The adapter's node renderer (used for both the root and each hoisted named schema). */
107
+ render(node: SchemaNode, ctx: RenderContext): string;
108
+ /**
109
+ * Const type annotation for a recursive schema, e.g. `z.ZodType<ColumnFilter>`
110
+ * or `v.GenericSchema<ColumnFilter>`, emitted as `const <name>: <annotation> = ...`
111
+ * to break the implicit-any self-reference cycle.
112
+ */
113
+ recursiveAnnotation(typeName: string): string;
114
+ }
115
+ /**
116
+ * Builds the `renderModule` for a method-chain / pipe-style adapter (zod, valibot):
117
+ * render the root and every hoisted named schema, and for each recursive schema emit
118
+ * a structural `type` alias plus a const annotation. The only thing these adapters
119
+ * differ on is the annotation text, supplied via {@link ChainModuleRendererOptions.recursiveAnnotation};
120
+ * everything else (the alias-name derivation, the recursive-set handling, the
121
+ * `renderTsType` lowering) is identical. arktype does not use this — its module
122
+ * rendering degrades mutually-recursive cycles and emits no type aliases.
123
+ */
124
+ declare function createChainModuleRenderer(opts: ChainModuleRendererOptions): (mod: SchemaModule) => RenderedModule;
125
+
101
126
  /**
102
127
  * Pure-AST translation of class-validator-decorated DTO classes into the neutral
103
128
  * {@link SchemaModule} IR. Reads decorator names + literal args via ts-morph — it
@@ -264,6 +289,6 @@ interface FastDiscoveryOptions {
264
289
  }
265
290
  declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
266
291
 
267
- declare const VERSION = "0.5.1";
292
+ declare const VERSION = "0.5.2";
268
293
 
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 };
294
+ export { type ChainModuleRendererOptions, CodegenError, ConfigError, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, buildMocksFile, buildOpenApiSpec, createChainModuleRenderer, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, toObjectKey, typeNameFor, 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-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';
1
+ import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext } from './index-_qRai4M3.js';
2
+ export { A as AdapterUsage, f as ContractDescriptor, g as ContractSource, h as ControllerRef, N as NumberCheck, i as ScopeConfig, j as StringCheck, T as TypeRef, k as ValidationOption, r as resolveAdapter } from './index-_qRai4M3.js';
3
3
  import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
4
4
 
5
5
  declare function defineConfig(c: UserConfig): UserConfig;
@@ -98,6 +98,31 @@ interface TsTypeContext {
98
98
  }
99
99
  declare function renderTsType(node: SchemaNode, ctx: TsTypeContext): string;
100
100
 
101
+ /** Schema const name → hoisted TS type-alias name (`ColumnFilterSchema` → `ColumnFilter`). */
102
+ declare function typeNameFor(schemaName: string): string;
103
+ /** Valid JS identifier → bare key, else quoted. */
104
+ declare function toObjectKey(name: string): string;
105
+ interface ChainModuleRendererOptions {
106
+ /** The adapter's node renderer (used for both the root and each hoisted named schema). */
107
+ render(node: SchemaNode, ctx: RenderContext): string;
108
+ /**
109
+ * Const type annotation for a recursive schema, e.g. `z.ZodType<ColumnFilter>`
110
+ * or `v.GenericSchema<ColumnFilter>`, emitted as `const <name>: <annotation> = ...`
111
+ * to break the implicit-any self-reference cycle.
112
+ */
113
+ recursiveAnnotation(typeName: string): string;
114
+ }
115
+ /**
116
+ * Builds the `renderModule` for a method-chain / pipe-style adapter (zod, valibot):
117
+ * render the root and every hoisted named schema, and for each recursive schema emit
118
+ * a structural `type` alias plus a const annotation. The only thing these adapters
119
+ * differ on is the annotation text, supplied via {@link ChainModuleRendererOptions.recursiveAnnotation};
120
+ * everything else (the alias-name derivation, the recursive-set handling, the
121
+ * `renderTsType` lowering) is identical. arktype does not use this — its module
122
+ * rendering degrades mutually-recursive cycles and emits no type aliases.
123
+ */
124
+ declare function createChainModuleRenderer(opts: ChainModuleRendererOptions): (mod: SchemaModule) => RenderedModule;
125
+
101
126
  /**
102
127
  * Pure-AST translation of class-validator-decorated DTO classes into the neutral
103
128
  * {@link SchemaModule} IR. Reads decorator names + literal args via ts-morph — it
@@ -264,6 +289,6 @@ interface FastDiscoveryOptions {
264
289
  }
265
290
  declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
266
291
 
267
- declare const VERSION = "0.5.1";
292
+ declare const VERSION = "0.5.2";
268
293
 
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 };
294
+ export { type ChainModuleRendererOptions, CodegenError, ConfigError, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type Watcher, acquireLock, buildMocksFile, buildOpenApiSpec, createChainModuleRenderer, defineConfig, discoverContractsFast, emitApi, emitForms, emitMocks, emitOpenApi, emitRoutes, extractSchemaFromDto, generate, loadConfig, renderTsType, resolveConfig, schemaModuleToJsonSchema, schemaNodeToJsonSchema, toObjectKey, typeNameFor, watch };
package/dist/index.js CHANGED
@@ -2555,37 +2555,28 @@ function buildProperty(prop, classFile, ctx) {
2555
2555
  const typeNode = prop.getTypeNode();
2556
2556
  const typeText = typeNode?.getText() ?? "unknown";
2557
2557
  const isArrayType = !!typeNode && Node3.isArrayTypeNode(typeNode);
2558
+ const asField = (child) => applyPresence(
2559
+ has("IsArray") || isArrayType ? { kind: "array", element: child } : child,
2560
+ decorators
2561
+ );
2558
2562
  const discriminator = resolveDiscriminator(dec("Type"));
2559
2563
  if (discriminator) {
2560
2564
  const options = discriminator.subTypes.map(
2561
2565
  (name) => buildNestedReference(name, classFile, ctx)
2562
2566
  );
2563
- const unionNode = {
2564
- kind: "union",
2565
- options,
2566
- discriminator: discriminator.property
2567
- };
2568
- const wrapArray = has("IsArray") || isArrayType;
2569
- const node2 = wrapArray ? { kind: "array", element: unionNode } : unionNode;
2570
- return applyPresence(node2, decorators);
2567
+ return asField({ kind: "union", options, discriminator: discriminator.property });
2571
2568
  }
2572
2569
  const propTypeParam = singularClassName(typeText);
2573
2570
  if (propTypeParam && ctx.typeBindings.has(propTypeParam)) {
2574
2571
  const bound = ctx.typeBindings.get(propTypeParam);
2575
- const childNode = buildNestedReference(bound, classFile, ctx);
2576
- const wrapArray = has("IsArray") || isArrayType;
2577
- const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
2578
- return applyPresence(node2, decorators);
2572
+ return asField(buildNestedReference(bound, classFile, ctx));
2579
2573
  }
2580
2574
  const typeRefName = resolveTypeFactoryName(dec("Type"));
2581
2575
  if (has("ValidateNested") || typeRefName) {
2582
2576
  const typeArgs = genericTypeArgNames(typeNode);
2583
2577
  const childName = typeRefName ?? singularClassName(typeText);
2584
2578
  if (childName) {
2585
- const childNode = buildNestedReference(childName, classFile, ctx, typeArgs);
2586
- const wrapArray = has("IsArray") || isArrayType;
2587
- const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
2588
- return applyPresence(node2, decorators);
2579
+ return asField(buildNestedReference(childName, classFile, ctx, typeArgs));
2589
2580
  }
2590
2581
  }
2591
2582
  let base = baseFromType(typeText, isArrayType);
@@ -4494,8 +4485,42 @@ function renderTsType(node, ctx) {
4494
4485
  }
4495
4486
  }
4496
4487
 
4488
+ // src/adapters/chain-module.ts
4489
+ function typeNameFor(schemaName) {
4490
+ return schemaName.replace(/Schema(_\d+)?$/, "$1");
4491
+ }
4492
+ function toObjectKey2(name) {
4493
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) ? name : JSON.stringify(name);
4494
+ }
4495
+ function createChainModuleRenderer(opts) {
4496
+ const { render, recursiveAnnotation } = opts;
4497
+ return (mod) => {
4498
+ const ctx = { named: mod.named };
4499
+ const recursive = mod.recursive ?? /* @__PURE__ */ new Set();
4500
+ const tctx = { named: mod.named, recursive, typeNameFor };
4501
+ const namedNestedSchemas = /* @__PURE__ */ new Map();
4502
+ const namedTypeAliases = /* @__PURE__ */ new Map();
4503
+ const namedAnnotations = /* @__PURE__ */ new Map();
4504
+ for (const [name, node] of mod.named) {
4505
+ namedNestedSchemas.set(name, render(node, ctx));
4506
+ if (recursive.has(name)) {
4507
+ const typeName = typeNameFor(name);
4508
+ namedTypeAliases.set(name, `type ${typeName} = ${renderTsType(node, tctx)}`);
4509
+ namedAnnotations.set(name, recursiveAnnotation(typeName));
4510
+ }
4511
+ }
4512
+ return {
4513
+ schemaText: render(mod.root, ctx),
4514
+ namedNestedSchemas,
4515
+ namedTypeAliases,
4516
+ namedAnnotations,
4517
+ warnings: mod.warnings
4518
+ };
4519
+ };
4520
+ }
4521
+
4497
4522
  // src/index.ts
4498
- var VERSION = "0.5.1";
4523
+ var VERSION = "0.5.2";
4499
4524
  export {
4500
4525
  CodegenError,
4501
4526
  ConfigError,
@@ -4503,6 +4528,7 @@ export {
4503
4528
  acquireLock,
4504
4529
  buildMocksFile,
4505
4530
  buildOpenApiSpec,
4531
+ createChainModuleRenderer,
4506
4532
  defineConfig,
4507
4533
  discoverContractsFast,
4508
4534
  emitApi,
@@ -4518,6 +4544,8 @@ export {
4518
4544
  resolveConfig,
4519
4545
  schemaModuleToJsonSchema,
4520
4546
  schemaNodeToJsonSchema,
4547
+ toObjectKey2 as toObjectKey,
4548
+ typeNameFor,
4521
4549
  watch
4522
4550
  };
4523
4551
  //# sourceMappingURL=index.js.map