@dudousxd/nestjs-codegen 0.23.0 → 0.25.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 +34 -0
- package/dist/cli/main.cjs +49 -9
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +49 -9
- 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-BsptKWwz.d.cts → index-Ce3YnfwS.d.cts} +19 -0
- package/dist/{index-BsptKWwz.d.ts → index-Ce3YnfwS.d.ts} +19 -0
- package/dist/index.cjs +49 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +49 -9
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +49 -9
- 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 +49 -9
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
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 RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-
|
|
2
|
-
export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-
|
|
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, f as SerializationMode } from './index-Ce3YnfwS.cjs';
|
|
2
|
+
export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-Ce3YnfwS.cjs';
|
|
3
3
|
import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
|
|
4
4
|
|
|
5
5
|
declare function defineConfig(c: UserConfig): UserConfig;
|
|
@@ -382,6 +382,6 @@ interface FastDiscoveryOptions {
|
|
|
382
382
|
}
|
|
383
383
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
384
384
|
|
|
385
|
-
declare const VERSION = "0.
|
|
385
|
+
declare const VERSION = "0.25.0";
|
|
386
386
|
|
|
387
387
|
export { type ChainModuleRendererOptions, CodegenError, type CodegenManifest, ConfigError, DriftGuardError, type EntryPoint, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type WatchOptions, 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 RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-
|
|
2
|
-
export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-
|
|
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, f as SerializationMode } from './index-Ce3YnfwS.js';
|
|
2
|
+
export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-Ce3YnfwS.js';
|
|
3
3
|
import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
|
|
4
4
|
|
|
5
5
|
declare function defineConfig(c: UserConfig): UserConfig;
|
|
@@ -382,6 +382,6 @@ interface FastDiscoveryOptions {
|
|
|
382
382
|
}
|
|
383
383
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
384
384
|
|
|
385
|
-
declare const VERSION = "0.
|
|
385
|
+
declare const VERSION = "0.25.0";
|
|
386
386
|
|
|
387
387
|
export { type ChainModuleRendererOptions, CodegenError, type CodegenManifest, ConfigError, DriftGuardError, type EntryPoint, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, type WatchOptions, 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
|
@@ -1490,12 +1490,19 @@ function classifyFromColumnDecorator(prop, sourceFile, project) {
|
|
|
1490
1490
|
return { kind: "string" };
|
|
1491
1491
|
}
|
|
1492
1492
|
}
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1493
|
+
for (const key of ["columnType", "type"]) {
|
|
1494
|
+
const typeProp = arg.getProperty(key);
|
|
1495
|
+
if (!typeProp || !Node4.isPropertyAssignment(typeProp)) continue;
|
|
1495
1496
|
const init = typeProp.getInitializer();
|
|
1496
|
-
if (init
|
|
1497
|
+
if (!init) continue;
|
|
1498
|
+
if (Node4.isStringLiteral(init)) {
|
|
1497
1499
|
const kind = classifyTypeKeyword(init.getLiteralValue());
|
|
1498
1500
|
if (kind) return { kind };
|
|
1501
|
+
continue;
|
|
1502
|
+
}
|
|
1503
|
+
if (Node4.isIdentifier(init)) {
|
|
1504
|
+
const kind = classifyTypeKeyword(init.getText());
|
|
1505
|
+
if (kind) return { kind };
|
|
1499
1506
|
}
|
|
1500
1507
|
}
|
|
1501
1508
|
}
|
|
@@ -1507,12 +1514,18 @@ function classifyFromColumnDecorator(prop, sourceFile, project) {
|
|
|
1507
1514
|
function classifyFieldType(prop, sourceFile, project) {
|
|
1508
1515
|
let nullable = prop.hasQuestionToken();
|
|
1509
1516
|
const typeNode = prop.getTypeNode();
|
|
1517
|
+
const fromDecorator = classifyFromColumnDecorator(prop, sourceFile, project);
|
|
1510
1518
|
if (typeNode) {
|
|
1511
1519
|
const r = classifyTypeNode(typeNode, sourceFile, project);
|
|
1512
1520
|
if (r.nullable) nullable = true;
|
|
1513
|
-
if (r.kind !== "unknown")
|
|
1521
|
+
if (r.kind !== "unknown") {
|
|
1522
|
+
const conflicts = fromDecorator !== null && fromDecorator.kind !== "unknown" && fromDecorator.kind !== r.kind;
|
|
1523
|
+
if (conflicts) {
|
|
1524
|
+
return markNullable({ ...fromDecorator, valueKind: r.kind }, nullable);
|
|
1525
|
+
}
|
|
1526
|
+
return markNullable(r, nullable);
|
|
1527
|
+
}
|
|
1514
1528
|
}
|
|
1515
|
-
const fromDecorator = classifyFromColumnDecorator(prop, sourceFile, project);
|
|
1516
1529
|
if (fromDecorator) {
|
|
1517
1530
|
return markNullable(fromDecorator, nullable || fromDecorator.nullable === true);
|
|
1518
1531
|
}
|
|
@@ -1520,6 +1533,7 @@ function classifyFieldType(prop, sourceFile, project) {
|
|
|
1520
1533
|
}
|
|
1521
1534
|
function toFilterFieldType(name, r) {
|
|
1522
1535
|
const ft = { name, kind: r.kind };
|
|
1536
|
+
if (r.valueKind && r.valueKind !== r.kind) ft.valueKind = r.valueKind;
|
|
1523
1537
|
if (r.enumValues && r.enumValues.length > 0) ft.enumValues = r.enumValues;
|
|
1524
1538
|
if (r.nullable) ft.nullable = true;
|
|
1525
1539
|
if (r.numericEnum) ft.numericEnum = true;
|
|
@@ -1626,6 +1640,32 @@ function resolveFactoryStaticClass(node) {
|
|
|
1626
1640
|
if (!Node5.isIdentifier(inner)) return void 0;
|
|
1627
1641
|
return inner.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node5.isClassDeclaration(n));
|
|
1628
1642
|
}
|
|
1643
|
+
function resolveBaseClass(cls) {
|
|
1644
|
+
const heritage = cls.getExtends()?.getExpression();
|
|
1645
|
+
if (!heritage) return void 0;
|
|
1646
|
+
const call = resolveHeritageCall(heritage);
|
|
1647
|
+
if (call) {
|
|
1648
|
+
const factoryDecl = resolveFactoryDeclaration(call);
|
|
1649
|
+
return factoryDecl ? resolveReturnedClass(factoryDecl) : void 0;
|
|
1650
|
+
}
|
|
1651
|
+
const expr = unwrapExpression(heritage);
|
|
1652
|
+
if (!Node5.isIdentifier(expr)) return void 0;
|
|
1653
|
+
return expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node5.isClassDeclaration(n));
|
|
1654
|
+
}
|
|
1655
|
+
function collectMethodsThroughChain(returnedClass) {
|
|
1656
|
+
const byName = /* @__PURE__ */ new Map();
|
|
1657
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1658
|
+
let current = returnedClass;
|
|
1659
|
+
while (current && !seen.has(current)) {
|
|
1660
|
+
seen.add(current);
|
|
1661
|
+
for (const method of current.getMethods()) {
|
|
1662
|
+
const name = method.getName();
|
|
1663
|
+
if (!byName.has(name)) byName.set(name, method);
|
|
1664
|
+
}
|
|
1665
|
+
current = resolveBaseClass(current);
|
|
1666
|
+
}
|
|
1667
|
+
return [...byName.values()];
|
|
1668
|
+
}
|
|
1629
1669
|
function resolveInheritedMethods(cls) {
|
|
1630
1670
|
const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
|
|
1631
1671
|
if (!expr) return void 0;
|
|
@@ -1665,7 +1705,7 @@ function resolveInheritedMethods(cls) {
|
|
|
1665
1705
|
}
|
|
1666
1706
|
}
|
|
1667
1707
|
return {
|
|
1668
|
-
methods: returnedClass
|
|
1708
|
+
methods: collectMethodsThroughChain(returnedClass),
|
|
1669
1709
|
// The DECLARATION's name, not the call-site text: consumers look the factory
|
|
1670
1710
|
// back up by name inside `factoryFilePath`, which a qualified
|
|
1671
1711
|
// `tables.createTableController` would never match. For a bare identifier
|
|
@@ -3039,7 +3079,7 @@ function extractDtoRoute(args) {
|
|
|
3039
3079
|
const methodName = method.getName();
|
|
3040
3080
|
const classAs = readAsDecorator(cls, `class ${className}`);
|
|
3041
3081
|
const methodAs = readAsDecorator(method, `${className}.${methodName}`);
|
|
3042
|
-
const dtoContract = extractDtoContract(method,
|
|
3082
|
+
const dtoContract = extractDtoContract(method, method.getSourceFile(), project, mixin, cls);
|
|
3043
3083
|
const mixinResponse = mixin ? resolveInstantiatedReturnType(cls, methodName) : void 0;
|
|
3044
3084
|
return buildRoute({
|
|
3045
3085
|
className,
|
|
@@ -3325,7 +3365,7 @@ function kindToTs(kind, enumValues, numericEnum) {
|
|
|
3325
3365
|
}
|
|
3326
3366
|
function emitFieldTypesLiteral(fts) {
|
|
3327
3367
|
const entries = fts.map((f) => {
|
|
3328
|
-
let t = f.typeRef ? f.typeRef.name : kindToTs(f.kind, f.enumValues, f.numericEnum);
|
|
3368
|
+
let t = f.typeRef ? f.typeRef.name : kindToTs(f.valueKind ?? f.kind, f.enumValues, f.numericEnum);
|
|
3329
3369
|
if (f.nullable) t = `${t} | null`;
|
|
3330
3370
|
return `${JSON.stringify(f.name)}: ${t}`;
|
|
3331
3371
|
});
|
|
@@ -5332,7 +5372,7 @@ function createChainModuleRenderer(opts) {
|
|
|
5332
5372
|
}
|
|
5333
5373
|
|
|
5334
5374
|
// src/index.ts
|
|
5335
|
-
var VERSION = "0.
|
|
5375
|
+
var VERSION = "0.25.0";
|
|
5336
5376
|
export {
|
|
5337
5377
|
CodegenError,
|
|
5338
5378
|
ConfigError,
|