@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.
@@ -1132,12 +1132,19 @@ function classifyFromColumnDecorator(prop, sourceFile, project) {
1132
1132
  return { kind: "string" };
1133
1133
  }
1134
1134
  }
1135
- const typeProp = arg.getProperty("type");
1136
- if (typeProp && import_ts_morph3.Node.isPropertyAssignment(typeProp)) {
1135
+ for (const key of ["columnType", "type"]) {
1136
+ const typeProp = arg.getProperty(key);
1137
+ if (!typeProp || !import_ts_morph3.Node.isPropertyAssignment(typeProp)) continue;
1137
1138
  const init = typeProp.getInitializer();
1138
- if (init && import_ts_morph3.Node.isStringLiteral(init)) {
1139
+ if (!init) continue;
1140
+ if (import_ts_morph3.Node.isStringLiteral(init)) {
1139
1141
  const kind = classifyTypeKeyword(init.getLiteralValue());
1140
1142
  if (kind) return { kind };
1143
+ continue;
1144
+ }
1145
+ if (import_ts_morph3.Node.isIdentifier(init)) {
1146
+ const kind = classifyTypeKeyword(init.getText());
1147
+ if (kind) return { kind };
1141
1148
  }
1142
1149
  }
1143
1150
  }
@@ -1149,12 +1156,18 @@ function classifyFromColumnDecorator(prop, sourceFile, project) {
1149
1156
  function classifyFieldType(prop, sourceFile, project) {
1150
1157
  let nullable = prop.hasQuestionToken();
1151
1158
  const typeNode = prop.getTypeNode();
1159
+ const fromDecorator = classifyFromColumnDecorator(prop, sourceFile, project);
1152
1160
  if (typeNode) {
1153
1161
  const r = classifyTypeNode(typeNode, sourceFile, project);
1154
1162
  if (r.nullable) nullable = true;
1155
- if (r.kind !== "unknown") return markNullable(r, nullable);
1163
+ if (r.kind !== "unknown") {
1164
+ const conflicts = fromDecorator !== null && fromDecorator.kind !== "unknown" && fromDecorator.kind !== r.kind;
1165
+ if (conflicts) {
1166
+ return markNullable({ ...fromDecorator, valueKind: r.kind }, nullable);
1167
+ }
1168
+ return markNullable(r, nullable);
1169
+ }
1156
1170
  }
1157
- const fromDecorator = classifyFromColumnDecorator(prop, sourceFile, project);
1158
1171
  if (fromDecorator) {
1159
1172
  return markNullable(fromDecorator, nullable || fromDecorator.nullable === true);
1160
1173
  }
@@ -1162,6 +1175,7 @@ function classifyFieldType(prop, sourceFile, project) {
1162
1175
  }
1163
1176
  function toFilterFieldType(name, r) {
1164
1177
  const ft = { name, kind: r.kind };
1178
+ if (r.valueKind && r.valueKind !== r.kind) ft.valueKind = r.valueKind;
1165
1179
  if (r.enumValues && r.enumValues.length > 0) ft.enumValues = r.enumValues;
1166
1180
  if (r.nullable) ft.nullable = true;
1167
1181
  if (r.numericEnum) ft.numericEnum = true;
@@ -1268,6 +1282,32 @@ function resolveFactoryStaticClass(node) {
1268
1282
  if (!import_ts_morph4.Node.isIdentifier(inner)) return void 0;
1269
1283
  return inner.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && import_ts_morph4.Node.isClassDeclaration(n));
1270
1284
  }
1285
+ function resolveBaseClass(cls) {
1286
+ const heritage = cls.getExtends()?.getExpression();
1287
+ if (!heritage) return void 0;
1288
+ const call = resolveHeritageCall(heritage);
1289
+ if (call) {
1290
+ const factoryDecl = resolveFactoryDeclaration(call);
1291
+ return factoryDecl ? resolveReturnedClass(factoryDecl) : void 0;
1292
+ }
1293
+ const expr = unwrapExpression(heritage);
1294
+ if (!import_ts_morph4.Node.isIdentifier(expr)) return void 0;
1295
+ return expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && import_ts_morph4.Node.isClassDeclaration(n));
1296
+ }
1297
+ function collectMethodsThroughChain(returnedClass) {
1298
+ const byName = /* @__PURE__ */ new Map();
1299
+ const seen = /* @__PURE__ */ new Set();
1300
+ let current = returnedClass;
1301
+ while (current && !seen.has(current)) {
1302
+ seen.add(current);
1303
+ for (const method of current.getMethods()) {
1304
+ const name = method.getName();
1305
+ if (!byName.has(name)) byName.set(name, method);
1306
+ }
1307
+ current = resolveBaseClass(current);
1308
+ }
1309
+ return [...byName.values()];
1310
+ }
1271
1311
  function resolveInheritedMethods(cls) {
1272
1312
  const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
1273
1313
  if (!expr) return void 0;
@@ -1307,7 +1347,7 @@ function resolveInheritedMethods(cls) {
1307
1347
  }
1308
1348
  }
1309
1349
  return {
1310
- methods: returnedClass.getMethods(),
1350
+ methods: collectMethodsThroughChain(returnedClass),
1311
1351
  // The DECLARATION's name, not the call-site text: consumers look the factory
1312
1352
  // back up by name inside `factoryFilePath`, which a qualified
1313
1353
  // `tables.createTableController` would never match. For a bare identifier
@@ -2661,7 +2701,7 @@ function extractDtoRoute(args) {
2661
2701
  const methodName = method.getName();
2662
2702
  const classAs = readAsDecorator(cls, `class ${className}`);
2663
2703
  const methodAs = readAsDecorator(method, `${className}.${methodName}`);
2664
- const dtoContract = extractDtoContract(method, sourceFile, project, mixin, cls);
2704
+ const dtoContract = extractDtoContract(method, method.getSourceFile(), project, mixin, cls);
2665
2705
  const mixinResponse = mixin ? resolveInstantiatedReturnType(cls, methodName) : void 0;
2666
2706
  return buildRoute({
2667
2707
  className,
@@ -3282,7 +3322,7 @@ function kindToTs(kind, enumValues, numericEnum) {
3282
3322
  }
3283
3323
  function emitFieldTypesLiteral(fts) {
3284
3324
  const entries = fts.map((f) => {
3285
- let t = f.typeRef ? f.typeRef.name : kindToTs(f.kind, f.enumValues, f.numericEnum);
3325
+ let t = f.typeRef ? f.typeRef.name : kindToTs(f.valueKind ?? f.kind, f.enumValues, f.numericEnum);
3286
3326
  if (f.nullable) t = `${t} | null`;
3287
3327
  return `${JSON.stringify(f.name)}: ${t}`;
3288
3328
  });
@@ -5045,7 +5085,7 @@ async function watch(config, onChange, options = {}) {
5045
5085
  }
5046
5086
 
5047
5087
  // src/index.ts
5048
- var VERSION = "0.23.0";
5088
+ var VERSION = "0.25.0";
5049
5089
 
5050
5090
  // src/generate-manifest.ts
5051
5091
  var MANIFEST_FILE = ".codegen-manifest.json";