@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.
@@ -1,6 +1,6 @@
1
1
  import * as _nestjs_common from '@nestjs/common';
2
2
  import { DynamicModule, OnApplicationBootstrap, OnModuleDestroy, ExecutionContext } from '@nestjs/common';
3
- import { U as UserConfig } from '../index-BsptKWwz.cjs';
3
+ import { U as UserConfig } from '../index-Ce3YnfwS.cjs';
4
4
  import 'ts-morph';
5
5
 
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import * as _nestjs_common from '@nestjs/common';
2
2
  import { DynamicModule, OnApplicationBootstrap, OnModuleDestroy, ExecutionContext } from '@nestjs/common';
3
- import { U as UserConfig } from '../index-BsptKWwz.js';
3
+ import { U as UserConfig } from '../index-Ce3YnfwS.js';
4
4
  import 'ts-morph';
5
5
 
6
6
  /**
@@ -1109,12 +1109,19 @@ function classifyFromColumnDecorator(prop, sourceFile, project) {
1109
1109
  return { kind: "string" };
1110
1110
  }
1111
1111
  }
1112
- const typeProp = arg.getProperty("type");
1113
- if (typeProp && Node3.isPropertyAssignment(typeProp)) {
1112
+ for (const key of ["columnType", "type"]) {
1113
+ const typeProp = arg.getProperty(key);
1114
+ if (!typeProp || !Node3.isPropertyAssignment(typeProp)) continue;
1114
1115
  const init = typeProp.getInitializer();
1115
- if (init && Node3.isStringLiteral(init)) {
1116
+ if (!init) continue;
1117
+ if (Node3.isStringLiteral(init)) {
1116
1118
  const kind = classifyTypeKeyword(init.getLiteralValue());
1117
1119
  if (kind) return { kind };
1120
+ continue;
1121
+ }
1122
+ if (Node3.isIdentifier(init)) {
1123
+ const kind = classifyTypeKeyword(init.getText());
1124
+ if (kind) return { kind };
1118
1125
  }
1119
1126
  }
1120
1127
  }
@@ -1126,12 +1133,18 @@ function classifyFromColumnDecorator(prop, sourceFile, project) {
1126
1133
  function classifyFieldType(prop, sourceFile, project) {
1127
1134
  let nullable = prop.hasQuestionToken();
1128
1135
  const typeNode = prop.getTypeNode();
1136
+ const fromDecorator = classifyFromColumnDecorator(prop, sourceFile, project);
1129
1137
  if (typeNode) {
1130
1138
  const r = classifyTypeNode(typeNode, sourceFile, project);
1131
1139
  if (r.nullable) nullable = true;
1132
- if (r.kind !== "unknown") return markNullable(r, nullable);
1140
+ if (r.kind !== "unknown") {
1141
+ const conflicts = fromDecorator !== null && fromDecorator.kind !== "unknown" && fromDecorator.kind !== r.kind;
1142
+ if (conflicts) {
1143
+ return markNullable({ ...fromDecorator, valueKind: r.kind }, nullable);
1144
+ }
1145
+ return markNullable(r, nullable);
1146
+ }
1133
1147
  }
1134
- const fromDecorator = classifyFromColumnDecorator(prop, sourceFile, project);
1135
1148
  if (fromDecorator) {
1136
1149
  return markNullable(fromDecorator, nullable || fromDecorator.nullable === true);
1137
1150
  }
@@ -1139,6 +1152,7 @@ function classifyFieldType(prop, sourceFile, project) {
1139
1152
  }
1140
1153
  function toFilterFieldType(name, r) {
1141
1154
  const ft = { name, kind: r.kind };
1155
+ if (r.valueKind && r.valueKind !== r.kind) ft.valueKind = r.valueKind;
1142
1156
  if (r.enumValues && r.enumValues.length > 0) ft.enumValues = r.enumValues;
1143
1157
  if (r.nullable) ft.nullable = true;
1144
1158
  if (r.numericEnum) ft.numericEnum = true;
@@ -1245,6 +1259,32 @@ function resolveFactoryStaticClass(node) {
1245
1259
  if (!Node4.isIdentifier(inner)) return void 0;
1246
1260
  return inner.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node4.isClassDeclaration(n));
1247
1261
  }
1262
+ function resolveBaseClass(cls) {
1263
+ const heritage = cls.getExtends()?.getExpression();
1264
+ if (!heritage) return void 0;
1265
+ const call = resolveHeritageCall(heritage);
1266
+ if (call) {
1267
+ const factoryDecl = resolveFactoryDeclaration(call);
1268
+ return factoryDecl ? resolveReturnedClass(factoryDecl) : void 0;
1269
+ }
1270
+ const expr = unwrapExpression(heritage);
1271
+ if (!Node4.isIdentifier(expr)) return void 0;
1272
+ return expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node4.isClassDeclaration(n));
1273
+ }
1274
+ function collectMethodsThroughChain(returnedClass) {
1275
+ const byName = /* @__PURE__ */ new Map();
1276
+ const seen = /* @__PURE__ */ new Set();
1277
+ let current = returnedClass;
1278
+ while (current && !seen.has(current)) {
1279
+ seen.add(current);
1280
+ for (const method of current.getMethods()) {
1281
+ const name = method.getName();
1282
+ if (!byName.has(name)) byName.set(name, method);
1283
+ }
1284
+ current = resolveBaseClass(current);
1285
+ }
1286
+ return [...byName.values()];
1287
+ }
1248
1288
  function resolveInheritedMethods(cls) {
1249
1289
  const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
1250
1290
  if (!expr) return void 0;
@@ -1284,7 +1324,7 @@ function resolveInheritedMethods(cls) {
1284
1324
  }
1285
1325
  }
1286
1326
  return {
1287
- methods: returnedClass.getMethods(),
1327
+ methods: collectMethodsThroughChain(returnedClass),
1288
1328
  // The DECLARATION's name, not the call-site text: consumers look the factory
1289
1329
  // back up by name inside `factoryFilePath`, which a qualified
1290
1330
  // `tables.createTableController` would never match. For a bare identifier
@@ -2638,7 +2678,7 @@ function extractDtoRoute(args) {
2638
2678
  const methodName = method.getName();
2639
2679
  const classAs = readAsDecorator(cls, `class ${className}`);
2640
2680
  const methodAs = readAsDecorator(method, `${className}.${methodName}`);
2641
- const dtoContract = extractDtoContract(method, sourceFile, project, mixin, cls);
2681
+ const dtoContract = extractDtoContract(method, method.getSourceFile(), project, mixin, cls);
2642
2682
  const mixinResponse = mixin ? resolveInstantiatedReturnType(cls, methodName) : void 0;
2643
2683
  return buildRoute({
2644
2684
  className,
@@ -3259,7 +3299,7 @@ function kindToTs(kind, enumValues, numericEnum) {
3259
3299
  }
3260
3300
  function emitFieldTypesLiteral(fts) {
3261
3301
  const entries = fts.map((f) => {
3262
- let t = f.typeRef ? f.typeRef.name : kindToTs(f.kind, f.enumValues, f.numericEnum);
3302
+ let t = f.typeRef ? f.typeRef.name : kindToTs(f.valueKind ?? f.kind, f.enumValues, f.numericEnum);
3263
3303
  if (f.nullable) t = `${t} | null`;
3264
3304
  return `${JSON.stringify(f.name)}: ${t}`;
3265
3305
  });
@@ -5022,7 +5062,7 @@ async function watch(config, onChange, options = {}) {
5022
5062
  }
5023
5063
 
5024
5064
  // src/index.ts
5025
- var VERSION = "0.23.0";
5065
+ var VERSION = "0.25.0";
5026
5066
 
5027
5067
  // src/generate-manifest.ts
5028
5068
  var MANIFEST_FILE = ".codegen-manifest.json";