@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/dist/cli/main.js CHANGED
@@ -1485,12 +1485,19 @@ function classifyFromColumnDecorator(prop, sourceFile, project) {
1485
1485
  return { kind: "string" };
1486
1486
  }
1487
1487
  }
1488
- const typeProp = arg.getProperty("type");
1489
- if (typeProp && Node4.isPropertyAssignment(typeProp)) {
1488
+ for (const key of ["columnType", "type"]) {
1489
+ const typeProp = arg.getProperty(key);
1490
+ if (!typeProp || !Node4.isPropertyAssignment(typeProp)) continue;
1490
1491
  const init = typeProp.getInitializer();
1491
- if (init && Node4.isStringLiteral(init)) {
1492
+ if (!init) continue;
1493
+ if (Node4.isStringLiteral(init)) {
1492
1494
  const kind = classifyTypeKeyword(init.getLiteralValue());
1493
1495
  if (kind) return { kind };
1496
+ continue;
1497
+ }
1498
+ if (Node4.isIdentifier(init)) {
1499
+ const kind = classifyTypeKeyword(init.getText());
1500
+ if (kind) return { kind };
1494
1501
  }
1495
1502
  }
1496
1503
  }
@@ -1502,12 +1509,18 @@ function classifyFromColumnDecorator(prop, sourceFile, project) {
1502
1509
  function classifyFieldType(prop, sourceFile, project) {
1503
1510
  let nullable = prop.hasQuestionToken();
1504
1511
  const typeNode = prop.getTypeNode();
1512
+ const fromDecorator = classifyFromColumnDecorator(prop, sourceFile, project);
1505
1513
  if (typeNode) {
1506
1514
  const r = classifyTypeNode(typeNode, sourceFile, project);
1507
1515
  if (r.nullable) nullable = true;
1508
- if (r.kind !== "unknown") return markNullable(r, nullable);
1516
+ if (r.kind !== "unknown") {
1517
+ const conflicts = fromDecorator !== null && fromDecorator.kind !== "unknown" && fromDecorator.kind !== r.kind;
1518
+ if (conflicts) {
1519
+ return markNullable({ ...fromDecorator, valueKind: r.kind }, nullable);
1520
+ }
1521
+ return markNullable(r, nullable);
1522
+ }
1509
1523
  }
1510
- const fromDecorator = classifyFromColumnDecorator(prop, sourceFile, project);
1511
1524
  if (fromDecorator) {
1512
1525
  return markNullable(fromDecorator, nullable || fromDecorator.nullable === true);
1513
1526
  }
@@ -1515,6 +1528,7 @@ function classifyFieldType(prop, sourceFile, project) {
1515
1528
  }
1516
1529
  function toFilterFieldType(name, r) {
1517
1530
  const ft = { name, kind: r.kind };
1531
+ if (r.valueKind && r.valueKind !== r.kind) ft.valueKind = r.valueKind;
1518
1532
  if (r.enumValues && r.enumValues.length > 0) ft.enumValues = r.enumValues;
1519
1533
  if (r.nullable) ft.nullable = true;
1520
1534
  if (r.numericEnum) ft.numericEnum = true;
@@ -1621,6 +1635,32 @@ function resolveFactoryStaticClass(node) {
1621
1635
  if (!Node5.isIdentifier(inner)) return void 0;
1622
1636
  return inner.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node5.isClassDeclaration(n));
1623
1637
  }
1638
+ function resolveBaseClass(cls) {
1639
+ const heritage = cls.getExtends()?.getExpression();
1640
+ if (!heritage) return void 0;
1641
+ const call = resolveHeritageCall(heritage);
1642
+ if (call) {
1643
+ const factoryDecl = resolveFactoryDeclaration(call);
1644
+ return factoryDecl ? resolveReturnedClass(factoryDecl) : void 0;
1645
+ }
1646
+ const expr = unwrapExpression(heritage);
1647
+ if (!Node5.isIdentifier(expr)) return void 0;
1648
+ return expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node5.isClassDeclaration(n));
1649
+ }
1650
+ function collectMethodsThroughChain(returnedClass) {
1651
+ const byName = /* @__PURE__ */ new Map();
1652
+ const seen = /* @__PURE__ */ new Set();
1653
+ let current = returnedClass;
1654
+ while (current && !seen.has(current)) {
1655
+ seen.add(current);
1656
+ for (const method of current.getMethods()) {
1657
+ const name = method.getName();
1658
+ if (!byName.has(name)) byName.set(name, method);
1659
+ }
1660
+ current = resolveBaseClass(current);
1661
+ }
1662
+ return [...byName.values()];
1663
+ }
1624
1664
  function resolveInheritedMethods(cls) {
1625
1665
  const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
1626
1666
  if (!expr) return void 0;
@@ -1660,7 +1700,7 @@ function resolveInheritedMethods(cls) {
1660
1700
  }
1661
1701
  }
1662
1702
  return {
1663
- methods: returnedClass.getMethods(),
1703
+ methods: collectMethodsThroughChain(returnedClass),
1664
1704
  // The DECLARATION's name, not the call-site text: consumers look the factory
1665
1705
  // back up by name inside `factoryFilePath`, which a qualified
1666
1706
  // `tables.createTableController` would never match. For a bare identifier
@@ -3034,7 +3074,7 @@ function extractDtoRoute(args) {
3034
3074
  const methodName = method.getName();
3035
3075
  const classAs = readAsDecorator(cls, `class ${className}`);
3036
3076
  const methodAs = readAsDecorator(method, `${className}.${methodName}`);
3037
- const dtoContract = extractDtoContract(method, sourceFile, project, mixin, cls);
3077
+ const dtoContract = extractDtoContract(method, method.getSourceFile(), project, mixin, cls);
3038
3078
  const mixinResponse = mixin ? resolveInstantiatedReturnType(cls, methodName) : void 0;
3039
3079
  return buildRoute({
3040
3080
  className,
@@ -3320,7 +3360,7 @@ function kindToTs(kind, enumValues, numericEnum) {
3320
3360
  }
3321
3361
  function emitFieldTypesLiteral(fts) {
3322
3362
  const entries = fts.map((f) => {
3323
- let t = f.typeRef ? f.typeRef.name : kindToTs(f.kind, f.enumValues, f.numericEnum);
3363
+ let t = f.typeRef ? f.typeRef.name : kindToTs(f.valueKind ?? f.kind, f.enumValues, f.numericEnum);
3324
3364
  if (f.nullable) t = `${t} | null`;
3325
3365
  return `${JSON.stringify(f.name)}: ${t}`;
3326
3366
  });
@@ -5241,7 +5281,7 @@ async function watch(config, onChange, options = {}) {
5241
5281
  }
5242
5282
 
5243
5283
  // src/index.ts
5244
- var VERSION = "0.23.0";
5284
+ var VERSION = "0.25.0";
5245
5285
 
5246
5286
  // src/cli/codegen.ts
5247
5287
  async function runCodegen(opts = {}) {