@dudousxd/nestjs-codegen 0.5.1 → 0.6.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 +14 -0
- package/dist/cli/main.cjs +24 -18
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +24 -18
- package/dist/cli/main.js.map +1 -1
- package/dist/extension/index.d.cts +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/{index-B0mS84Jj.d.cts → index-_qRai4M3.d.cts} +1 -1
- package/dist/{index-B0mS84Jj.d.ts → index-_qRai4M3.d.ts} +1 -1
- package/dist/index.cjs +64 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -4
- package/dist/index.d.ts +29 -4
- package/dist/index.js +61 -18
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +23 -17
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.d.cts +1 -1
- package/dist/nest/index.d.ts +1 -1
- package/dist/nest/index.js +23 -17
- package/dist/nest/index.js.map +1 -1
- package/package.json +2 -2
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
|
|
2
|
-
export { A as AdapterUsage,
|
|
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.
|
|
292
|
+
declare const VERSION = "0.6.0";
|
|
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
|
|
2
|
-
export { A as AdapterUsage,
|
|
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.
|
|
292
|
+
declare const VERSION = "0.6.0";
|
|
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
|
@@ -2254,7 +2254,6 @@ function resolveImportedType(name, sourceFile, project) {
|
|
|
2254
2254
|
if (!namedImport) continue;
|
|
2255
2255
|
const moduleSpecifier = importDecl.getModuleSpecifierValue();
|
|
2256
2256
|
const candidates = resolveModuleSpecifier(moduleSpecifier, sourceFile, project);
|
|
2257
|
-
if (candidates.length === 0) continue;
|
|
2258
2257
|
for (const candidate of candidates) {
|
|
2259
2258
|
let importedFile = project.getSourceFile(candidate);
|
|
2260
2259
|
if (!importedFile) {
|
|
@@ -2269,9 +2268,25 @@ function resolveImportedType(name, sourceFile, project) {
|
|
|
2269
2268
|
const viaReExport = resolveReExportedType(name, importedFile, project, /* @__PURE__ */ new Set());
|
|
2270
2269
|
if (viaReExport) return viaReExport;
|
|
2271
2270
|
}
|
|
2271
|
+
if (candidates.length === 0) {
|
|
2272
|
+
const viaCompiler = resolveBareSpecifierType(name, importDecl, project);
|
|
2273
|
+
if (viaCompiler) return viaCompiler;
|
|
2274
|
+
}
|
|
2272
2275
|
}
|
|
2273
2276
|
return resolveReExportedType(name, sourceFile, project, /* @__PURE__ */ new Set());
|
|
2274
2277
|
}
|
|
2278
|
+
function resolveBareSpecifierType(name, importDecl, project) {
|
|
2279
|
+
let target;
|
|
2280
|
+
try {
|
|
2281
|
+
target = importDecl.getModuleSpecifierSourceFile();
|
|
2282
|
+
} catch {
|
|
2283
|
+
return null;
|
|
2284
|
+
}
|
|
2285
|
+
if (!target) return null;
|
|
2286
|
+
const direct = findTypeInFile(name, target);
|
|
2287
|
+
if (direct) return direct;
|
|
2288
|
+
return resolveReExportedType(name, target, project, /* @__PURE__ */ new Set());
|
|
2289
|
+
}
|
|
2275
2290
|
function resolveReExportedType(name, file, project, seen) {
|
|
2276
2291
|
const filePath = file.getFilePath();
|
|
2277
2292
|
if (seen.has(filePath)) return null;
|
|
@@ -2555,37 +2570,28 @@ function buildProperty(prop, classFile, ctx) {
|
|
|
2555
2570
|
const typeNode = prop.getTypeNode();
|
|
2556
2571
|
const typeText = typeNode?.getText() ?? "unknown";
|
|
2557
2572
|
const isArrayType = !!typeNode && Node3.isArrayTypeNode(typeNode);
|
|
2573
|
+
const asField = (child) => applyPresence(
|
|
2574
|
+
has("IsArray") || isArrayType ? { kind: "array", element: child } : child,
|
|
2575
|
+
decorators
|
|
2576
|
+
);
|
|
2558
2577
|
const discriminator = resolveDiscriminator(dec("Type"));
|
|
2559
2578
|
if (discriminator) {
|
|
2560
2579
|
const options = discriminator.subTypes.map(
|
|
2561
2580
|
(name) => buildNestedReference(name, classFile, ctx)
|
|
2562
2581
|
);
|
|
2563
|
-
|
|
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);
|
|
2582
|
+
return asField({ kind: "union", options, discriminator: discriminator.property });
|
|
2571
2583
|
}
|
|
2572
2584
|
const propTypeParam = singularClassName(typeText);
|
|
2573
2585
|
if (propTypeParam && ctx.typeBindings.has(propTypeParam)) {
|
|
2574
2586
|
const bound = ctx.typeBindings.get(propTypeParam);
|
|
2575
|
-
|
|
2576
|
-
const wrapArray = has("IsArray") || isArrayType;
|
|
2577
|
-
const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
|
|
2578
|
-
return applyPresence(node2, decorators);
|
|
2587
|
+
return asField(buildNestedReference(bound, classFile, ctx));
|
|
2579
2588
|
}
|
|
2580
2589
|
const typeRefName = resolveTypeFactoryName(dec("Type"));
|
|
2581
2590
|
if (has("ValidateNested") || typeRefName) {
|
|
2582
2591
|
const typeArgs = genericTypeArgNames(typeNode);
|
|
2583
2592
|
const childName = typeRefName ?? singularClassName(typeText);
|
|
2584
2593
|
if (childName) {
|
|
2585
|
-
|
|
2586
|
-
const wrapArray = has("IsArray") || isArrayType;
|
|
2587
|
-
const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
|
|
2588
|
-
return applyPresence(node2, decorators);
|
|
2594
|
+
return asField(buildNestedReference(childName, classFile, ctx, typeArgs));
|
|
2589
2595
|
}
|
|
2590
2596
|
}
|
|
2591
2597
|
let base = baseFromType(typeText, isArrayType);
|
|
@@ -4494,8 +4500,42 @@ function renderTsType(node, ctx) {
|
|
|
4494
4500
|
}
|
|
4495
4501
|
}
|
|
4496
4502
|
|
|
4503
|
+
// src/adapters/chain-module.ts
|
|
4504
|
+
function typeNameFor(schemaName) {
|
|
4505
|
+
return schemaName.replace(/Schema(_\d+)?$/, "$1");
|
|
4506
|
+
}
|
|
4507
|
+
function toObjectKey2(name) {
|
|
4508
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) ? name : JSON.stringify(name);
|
|
4509
|
+
}
|
|
4510
|
+
function createChainModuleRenderer(opts) {
|
|
4511
|
+
const { render, recursiveAnnotation } = opts;
|
|
4512
|
+
return (mod) => {
|
|
4513
|
+
const ctx = { named: mod.named };
|
|
4514
|
+
const recursive = mod.recursive ?? /* @__PURE__ */ new Set();
|
|
4515
|
+
const tctx = { named: mod.named, recursive, typeNameFor };
|
|
4516
|
+
const namedNestedSchemas = /* @__PURE__ */ new Map();
|
|
4517
|
+
const namedTypeAliases = /* @__PURE__ */ new Map();
|
|
4518
|
+
const namedAnnotations = /* @__PURE__ */ new Map();
|
|
4519
|
+
for (const [name, node] of mod.named) {
|
|
4520
|
+
namedNestedSchemas.set(name, render(node, ctx));
|
|
4521
|
+
if (recursive.has(name)) {
|
|
4522
|
+
const typeName = typeNameFor(name);
|
|
4523
|
+
namedTypeAliases.set(name, `type ${typeName} = ${renderTsType(node, tctx)}`);
|
|
4524
|
+
namedAnnotations.set(name, recursiveAnnotation(typeName));
|
|
4525
|
+
}
|
|
4526
|
+
}
|
|
4527
|
+
return {
|
|
4528
|
+
schemaText: render(mod.root, ctx),
|
|
4529
|
+
namedNestedSchemas,
|
|
4530
|
+
namedTypeAliases,
|
|
4531
|
+
namedAnnotations,
|
|
4532
|
+
warnings: mod.warnings
|
|
4533
|
+
};
|
|
4534
|
+
};
|
|
4535
|
+
}
|
|
4536
|
+
|
|
4497
4537
|
// src/index.ts
|
|
4498
|
-
var VERSION = "0.
|
|
4538
|
+
var VERSION = "0.6.0";
|
|
4499
4539
|
export {
|
|
4500
4540
|
CodegenError,
|
|
4501
4541
|
ConfigError,
|
|
@@ -4503,6 +4543,7 @@ export {
|
|
|
4503
4543
|
acquireLock,
|
|
4504
4544
|
buildMocksFile,
|
|
4505
4545
|
buildOpenApiSpec,
|
|
4546
|
+
createChainModuleRenderer,
|
|
4506
4547
|
defineConfig,
|
|
4507
4548
|
discoverContractsFast,
|
|
4508
4549
|
emitApi,
|
|
@@ -4518,6 +4559,8 @@ export {
|
|
|
4518
4559
|
resolveConfig,
|
|
4519
4560
|
schemaModuleToJsonSchema,
|
|
4520
4561
|
schemaNodeToJsonSchema,
|
|
4562
|
+
toObjectKey2 as toObjectKey,
|
|
4563
|
+
typeNameFor,
|
|
4521
4564
|
watch
|
|
4522
4565
|
};
|
|
4523
4566
|
//# sourceMappingURL=index.js.map
|