@dudousxd/nestjs-codegen 0.17.1 → 0.18.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 +48 -0
- package/dist/cli/main.cjs +228 -174
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +222 -168
- 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-DCF9QSPY.d.cts → index-Dyf4ttwU.d.cts} +24 -1
- package/dist/{index-DCF9QSPY.d.ts → index-Dyf4ttwU.d.ts} +24 -1
- package/dist/index.cjs +228 -174
- 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 +222 -168
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +228 -174
- 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 +222 -168
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/nest/index.d.cts
CHANGED
|
@@ -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-
|
|
3
|
+
import { U as UserConfig } from '../index-Dyf4ttwU.cjs';
|
|
4
4
|
import 'ts-morph';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/nest/index.d.ts
CHANGED
|
@@ -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-
|
|
3
|
+
import { U as UserConfig } from '../index-Dyf4ttwU.js';
|
|
4
4
|
import 'ts-morph';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/nest/index.js
CHANGED
|
@@ -2257,7 +2257,7 @@ import {
|
|
|
2257
2257
|
|
|
2258
2258
|
// src/discovery/dto-type-resolver.ts
|
|
2259
2259
|
import {
|
|
2260
|
-
Node as
|
|
2260
|
+
Node as Node7,
|
|
2261
2261
|
SyntaxKind as SyntaxKind3
|
|
2262
2262
|
} from "ts-morph";
|
|
2263
2263
|
|
|
@@ -3020,7 +3020,7 @@ function inSchemaFromDecorator(decorator) {
|
|
|
3020
3020
|
|
|
3021
3021
|
// src/discovery/filter-for.ts
|
|
3022
3022
|
import {
|
|
3023
|
-
Node as
|
|
3023
|
+
Node as Node6
|
|
3024
3024
|
} from "ts-morph";
|
|
3025
3025
|
|
|
3026
3026
|
// src/discovery/filter-field-types.ts
|
|
@@ -3243,15 +3243,161 @@ function toFilterFieldType(name, r) {
|
|
|
3243
3243
|
return ft;
|
|
3244
3244
|
}
|
|
3245
3245
|
|
|
3246
|
+
// src/discovery/heritage.ts
|
|
3247
|
+
import { Node as Node5, Project as Project3 } from "ts-morph";
|
|
3248
|
+
function resolveHeritageCall(node) {
|
|
3249
|
+
if (!node) return void 0;
|
|
3250
|
+
const expr = unwrapExpression(node);
|
|
3251
|
+
if (Node5.isCallExpression(expr)) return expr;
|
|
3252
|
+
if (!Node5.isIdentifier(expr)) return void 0;
|
|
3253
|
+
const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find(
|
|
3254
|
+
(n) => n !== void 0 && Node5.isVariableDeclaration(n)
|
|
3255
|
+
);
|
|
3256
|
+
const init = decl?.getInitializer();
|
|
3257
|
+
if (!init) return void 0;
|
|
3258
|
+
const unwrapped = unwrapExpression(init);
|
|
3259
|
+
return Node5.isCallExpression(unwrapped) ? unwrapped : void 0;
|
|
3260
|
+
}
|
|
3261
|
+
function unwrapExpression(node) {
|
|
3262
|
+
let current = node;
|
|
3263
|
+
while (Node5.isAsExpression(current) || Node5.isSatisfiesExpression(current) || Node5.isParenthesizedExpression(current) || Node5.isTypeAssertion(current)) {
|
|
3264
|
+
current = current.getExpression();
|
|
3265
|
+
}
|
|
3266
|
+
return current;
|
|
3267
|
+
}
|
|
3268
|
+
function resolveReturnedClass(factoryDecl) {
|
|
3269
|
+
const body = factoryDecl.getBody();
|
|
3270
|
+
if (!body) return void 0;
|
|
3271
|
+
const returns = body.getDescendants().filter((n) => Node5.isReturnStatement(n));
|
|
3272
|
+
for (const ret of returns) {
|
|
3273
|
+
const expr = ret.getExpression();
|
|
3274
|
+
if (!expr) continue;
|
|
3275
|
+
const inner = unwrapExpression(expr);
|
|
3276
|
+
if (Node5.isClassExpression(inner)) {
|
|
3277
|
+
return inner;
|
|
3278
|
+
}
|
|
3279
|
+
if (Node5.isIdentifier(inner)) {
|
|
3280
|
+
const name = inner.getText();
|
|
3281
|
+
const decl = body.getDescendants().find((n) => Node5.isClassDeclaration(n) && n.getName() === name);
|
|
3282
|
+
if (decl) return decl;
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
return void 0;
|
|
3286
|
+
}
|
|
3287
|
+
function resolveFactoryDeclaration(call) {
|
|
3288
|
+
const callee = call.getExpression();
|
|
3289
|
+
if (!Node5.isIdentifier(callee)) return void 0;
|
|
3290
|
+
return callee.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => Node5.isFunctionDeclaration(n));
|
|
3291
|
+
}
|
|
3292
|
+
function resolveFactoryStaticClass(node) {
|
|
3293
|
+
if (!Node5.isPropertyAccessExpression(node)) return void 0;
|
|
3294
|
+
const call = resolveHeritageCall(node.getExpression());
|
|
3295
|
+
if (!call) return void 0;
|
|
3296
|
+
const factoryDecl = resolveFactoryDeclaration(call);
|
|
3297
|
+
if (!factoryDecl) return void 0;
|
|
3298
|
+
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
3299
|
+
if (!returnedClass) return void 0;
|
|
3300
|
+
const staticProp = returnedClass.getStaticProperties().find((p) => p.getName() === node.getName());
|
|
3301
|
+
if (!staticProp || !Node5.isPropertyDeclaration(staticProp)) return void 0;
|
|
3302
|
+
const init = staticProp.getInitializer();
|
|
3303
|
+
if (!init) return void 0;
|
|
3304
|
+
const inner = unwrapExpression(init);
|
|
3305
|
+
if (Node5.isClassExpression(inner)) return inner;
|
|
3306
|
+
if (!Node5.isIdentifier(inner)) return void 0;
|
|
3307
|
+
return inner.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node5.isClassDeclaration(n));
|
|
3308
|
+
}
|
|
3309
|
+
function resolveInheritedMethods(cls) {
|
|
3310
|
+
const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
|
|
3311
|
+
if (!expr) return void 0;
|
|
3312
|
+
const callee = expr.getExpression();
|
|
3313
|
+
if (!Node5.isIdentifier(callee)) return void 0;
|
|
3314
|
+
const factoryDecl = resolveFactoryDeclaration(expr);
|
|
3315
|
+
if (!factoryDecl) return void 0;
|
|
3316
|
+
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
3317
|
+
if (!returnedClass) return void 0;
|
|
3318
|
+
const classArgs = [];
|
|
3319
|
+
const namedClassArgs = {};
|
|
3320
|
+
for (const arg of expr.getArguments()) {
|
|
3321
|
+
const positional = resolveClassReference(arg);
|
|
3322
|
+
if (positional) {
|
|
3323
|
+
classArgs.push(positional);
|
|
3324
|
+
continue;
|
|
3325
|
+
}
|
|
3326
|
+
if (!Node5.isObjectLiteralExpression(arg)) continue;
|
|
3327
|
+
for (const prop of arg.getProperties()) {
|
|
3328
|
+
const named = resolvePropertyClassReference(prop);
|
|
3329
|
+
if (!named) continue;
|
|
3330
|
+
namedClassArgs[named.key] ??= named.ref;
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
return {
|
|
3334
|
+
methods: returnedClass.getMethods(),
|
|
3335
|
+
factoryName: callee.getText(),
|
|
3336
|
+
factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
|
|
3337
|
+
classArgs,
|
|
3338
|
+
namedClassArgs
|
|
3339
|
+
};
|
|
3340
|
+
}
|
|
3341
|
+
function resolveClassReference(node) {
|
|
3342
|
+
const expr = unwrapExpression(node);
|
|
3343
|
+
if (!Node5.isIdentifier(expr)) return void 0;
|
|
3344
|
+
const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node5.isClassDeclaration(n));
|
|
3345
|
+
if (!decl) return void 0;
|
|
3346
|
+
return {
|
|
3347
|
+
name: decl.getName() ?? expr.getText(),
|
|
3348
|
+
filePath: decl.getSourceFile().getFilePath()
|
|
3349
|
+
};
|
|
3350
|
+
}
|
|
3351
|
+
function resolvePropertyClassReference(prop) {
|
|
3352
|
+
if (Node5.isShorthandPropertyAssignment(prop)) {
|
|
3353
|
+
const ref2 = resolveClassReference(prop.getNameNode());
|
|
3354
|
+
return ref2 ? { key: prop.getName(), ref: ref2 } : void 0;
|
|
3355
|
+
}
|
|
3356
|
+
if (!Node5.isPropertyAssignment(prop)) return void 0;
|
|
3357
|
+
const init = prop.getInitializer();
|
|
3358
|
+
if (!init) return void 0;
|
|
3359
|
+
const ref = resolveClassReference(init);
|
|
3360
|
+
if (!ref) return void 0;
|
|
3361
|
+
const nameNode = prop.getNameNode();
|
|
3362
|
+
const key = Node5.isStringLiteral(nameNode) ? nameNode.getLiteralValue() : prop.getName();
|
|
3363
|
+
return { key, ref };
|
|
3364
|
+
}
|
|
3365
|
+
var mixinTypeProject;
|
|
3366
|
+
function getMixinTypeProject() {
|
|
3367
|
+
mixinTypeProject ??= new Project3({
|
|
3368
|
+
skipAddingFilesFromTsConfig: true,
|
|
3369
|
+
compilerOptions: { strict: true }
|
|
3370
|
+
});
|
|
3371
|
+
return mixinTypeProject;
|
|
3372
|
+
}
|
|
3373
|
+
function clearMixinTypeProject() {
|
|
3374
|
+
mixinTypeProject = void 0;
|
|
3375
|
+
}
|
|
3376
|
+
function resolveInstantiatedReturnType(cls, methodName) {
|
|
3377
|
+
const filePath = cls.getSourceFile().getFilePath();
|
|
3378
|
+
const className = cls.getName();
|
|
3379
|
+
if (!className) return void 0;
|
|
3380
|
+
const project = getMixinTypeProject();
|
|
3381
|
+
const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPathIfExists(filePath);
|
|
3382
|
+
const typedCls = sourceFile?.getClass(className);
|
|
3383
|
+
if (!typedCls) return void 0;
|
|
3384
|
+
const prop = typedCls.getType().getProperty(methodName);
|
|
3385
|
+
if (!prop) return void 0;
|
|
3386
|
+
const returnType = prop.getTypeAtLocation(typedCls).getCallSignatures()[0]?.getReturnType();
|
|
3387
|
+
if (!returnType) return void 0;
|
|
3388
|
+
const unwrapped = returnType.getSymbol()?.getName() === "Promise" ? returnType.getTypeArguments()[0] ?? returnType : returnType;
|
|
3389
|
+
return unwrapped.getText(typedCls);
|
|
3390
|
+
}
|
|
3391
|
+
|
|
3246
3392
|
// src/discovery/filter-for.ts
|
|
3247
3393
|
function resolveMixinEntityClass(mixin, project) {
|
|
3248
|
-
const entityArg = mixin?.classArgs[0];
|
|
3394
|
+
const entityArg = mixin?.namedClassArgs?.entity ?? mixin?.classArgs[0];
|
|
3249
3395
|
if (!entityArg) return void 0;
|
|
3250
3396
|
const file = project.getSourceFile(entityArg.filePath) ?? project.addSourceFileAtPathIfExists(entityArg.filePath);
|
|
3251
3397
|
return file?.getClass(entityArg.name);
|
|
3252
3398
|
}
|
|
3253
3399
|
function classifyFilterForHint(typeInit) {
|
|
3254
|
-
if (
|
|
3400
|
+
if (Node6.isStringLiteral(typeInit)) {
|
|
3255
3401
|
switch (typeInit.getLiteralValue()) {
|
|
3256
3402
|
case "string":
|
|
3257
3403
|
return { kind: "string" };
|
|
@@ -3265,10 +3411,10 @@ function classifyFilterForHint(typeInit) {
|
|
|
3265
3411
|
return null;
|
|
3266
3412
|
}
|
|
3267
3413
|
}
|
|
3268
|
-
if (
|
|
3414
|
+
if (Node6.isArrayLiteralExpression(typeInit)) {
|
|
3269
3415
|
const values = [];
|
|
3270
3416
|
for (const el of typeInit.getElements()) {
|
|
3271
|
-
if (!
|
|
3417
|
+
if (!Node6.isStringLiteral(el)) return null;
|
|
3272
3418
|
values.push(el.getLiteralValue());
|
|
3273
3419
|
}
|
|
3274
3420
|
if (values.length === 0) return null;
|
|
@@ -3303,11 +3449,11 @@ function extractFilterForHints(classDecl, project) {
|
|
|
3303
3449
|
if (!filterForDec) continue;
|
|
3304
3450
|
const args = filterForDec.getArguments();
|
|
3305
3451
|
const keyArg = args[0];
|
|
3306
|
-
const inputKey = keyArg &&
|
|
3452
|
+
const inputKey = keyArg && Node6.isStringLiteral(keyArg) ? keyArg.getLiteralValue() : method.getName();
|
|
3307
3453
|
const optsArg = args[1];
|
|
3308
|
-
if (optsArg &&
|
|
3454
|
+
if (optsArg && Node6.isObjectLiteralExpression(optsArg)) {
|
|
3309
3455
|
const typeProp = optsArg.getProperty("type");
|
|
3310
|
-
if (typeProp &&
|
|
3456
|
+
if (typeProp && Node6.isPropertyAssignment(typeProp)) {
|
|
3311
3457
|
const typeInit = typeProp.getInitializer();
|
|
3312
3458
|
if (typeInit) {
|
|
3313
3459
|
const classified = classifyFilterForHint(typeInit);
|
|
@@ -3332,21 +3478,23 @@ function extractApplyFilterInfo(method, sourceFile, project, mixin) {
|
|
|
3332
3478
|
const args = filterDecorator.getArguments();
|
|
3333
3479
|
if (args.length === 0) continue;
|
|
3334
3480
|
const filterClassArg = args[0];
|
|
3335
|
-
if (!filterClassArg
|
|
3481
|
+
if (!filterClassArg) continue;
|
|
3482
|
+
const factoryStaticClass = resolveFactoryStaticClass(filterClassArg);
|
|
3483
|
+
if (!factoryStaticClass && !Node6.isIdentifier(filterClassArg)) continue;
|
|
3336
3484
|
let source = "query";
|
|
3337
3485
|
const optionsArg = args[1];
|
|
3338
|
-
if (optionsArg &&
|
|
3486
|
+
if (optionsArg && Node6.isObjectLiteralExpression(optionsArg)) {
|
|
3339
3487
|
const sourceProp = optionsArg.getProperty("source");
|
|
3340
|
-
if (sourceProp &&
|
|
3488
|
+
if (sourceProp && Node6.isPropertyAssignment(sourceProp)) {
|
|
3341
3489
|
const init = sourceProp.getInitializer();
|
|
3342
|
-
if (init &&
|
|
3490
|
+
if (init && Node6.isStringLiteral(init) && init.getLiteralValue() === "body") {
|
|
3343
3491
|
source = "body";
|
|
3344
3492
|
}
|
|
3345
3493
|
}
|
|
3346
3494
|
}
|
|
3347
3495
|
const filterClassName = filterClassArg.getText();
|
|
3348
|
-
const resolved = findType(filterClassName, declFile, project);
|
|
3349
|
-
const classDecl = resolved?.kind === "class" ? resolved.decl : resolveLocalClassDeclaration(filterClassArg);
|
|
3496
|
+
const resolved = factoryStaticClass ? void 0 : findType(filterClassName, declFile, project);
|
|
3497
|
+
const classDecl = factoryStaticClass ?? (resolved?.kind === "class" ? resolved.decl : resolveLocalClassDeclaration(filterClassArg));
|
|
3350
3498
|
if (classDecl) {
|
|
3351
3499
|
let fieldTypes = extractClassPropertyTypes(classDecl, project);
|
|
3352
3500
|
if (fieldTypes.length === 0) {
|
|
@@ -3402,22 +3550,22 @@ function resolveRelationEntity(prop, sourceFile, project) {
|
|
|
3402
3550
|
const args = dec.getArguments();
|
|
3403
3551
|
if (args.length === 0) continue;
|
|
3404
3552
|
const arg = args[0];
|
|
3405
|
-
if (
|
|
3553
|
+
if (Node6.isObjectLiteralExpression(arg)) {
|
|
3406
3554
|
const entityProp = arg.getProperty("entity");
|
|
3407
|
-
if (entityProp &&
|
|
3555
|
+
if (entityProp && Node6.isPropertyAssignment(entityProp)) {
|
|
3408
3556
|
const init = entityProp.getInitializer();
|
|
3409
|
-
if (init &&
|
|
3557
|
+
if (init && Node6.isArrowFunction(init)) {
|
|
3410
3558
|
const body = init.getBody();
|
|
3411
|
-
if (
|
|
3559
|
+
if (Node6.isIdentifier(body)) {
|
|
3412
3560
|
const resolved = findType(body.getText(), prop.getSourceFile(), project);
|
|
3413
3561
|
if (resolved?.kind === "class") return resolved.decl;
|
|
3414
3562
|
}
|
|
3415
3563
|
}
|
|
3416
3564
|
}
|
|
3417
3565
|
}
|
|
3418
|
-
if (
|
|
3566
|
+
if (Node6.isArrowFunction(arg)) {
|
|
3419
3567
|
const body = arg.getBody();
|
|
3420
|
-
if (
|
|
3568
|
+
if (Node6.isIdentifier(body)) {
|
|
3421
3569
|
const resolved = findType(body.getText(), prop.getSourceFile(), project);
|
|
3422
3570
|
if (resolved?.kind === "class") return resolved.decl;
|
|
3423
3571
|
}
|
|
@@ -3436,15 +3584,15 @@ function extractClassPropertyTypes(classDecl, project) {
|
|
|
3436
3584
|
return fields;
|
|
3437
3585
|
}
|
|
3438
3586
|
function resolveLocalClassDeclaration(identifier) {
|
|
3439
|
-
if (!
|
|
3440
|
-
return identifier.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 &&
|
|
3587
|
+
if (!Node6.isIdentifier(identifier)) return void 0;
|
|
3588
|
+
return identifier.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => n !== void 0 && Node6.isClassDeclaration(n));
|
|
3441
3589
|
}
|
|
3442
3590
|
function resolveDeclaredEntity(optionsArg, filterClass, project) {
|
|
3443
|
-
if (!
|
|
3591
|
+
if (!Node6.isObjectLiteralExpression(optionsArg)) return void 0;
|
|
3444
3592
|
const entityProp = optionsArg.getProperty("entity");
|
|
3445
|
-
if (!entityProp || !
|
|
3593
|
+
if (!entityProp || !Node6.isPropertyAssignment(entityProp)) return void 0;
|
|
3446
3594
|
const entityInit = entityProp.getInitializer();
|
|
3447
|
-
if (!entityInit || !
|
|
3595
|
+
if (!entityInit || !Node6.isIdentifier(entityInit)) return void 0;
|
|
3448
3596
|
const resolved = findType(entityInit.getText(), filterClass.getSourceFile(), project);
|
|
3449
3597
|
if (!resolved || resolved.kind !== "class") return void 0;
|
|
3450
3598
|
return resolved.decl;
|
|
@@ -3455,7 +3603,7 @@ function extractFilterableEntityFields(filterClass, project, entityOverride) {
|
|
|
3455
3603
|
const args = filterableDecorator.getArguments();
|
|
3456
3604
|
if (args.length === 0) return [];
|
|
3457
3605
|
const optionsArg = args[0];
|
|
3458
|
-
if (!
|
|
3606
|
+
if (!Node6.isObjectLiteralExpression(optionsArg)) return [];
|
|
3459
3607
|
const entityDecl = entityOverride ?? resolveDeclaredEntity(optionsArg, filterClass, project);
|
|
3460
3608
|
if (!entityDecl) return [];
|
|
3461
3609
|
const fields = collectEntityFields(
|
|
@@ -3468,17 +3616,17 @@ function extractFilterableEntityFields(filterClass, project, entityOverride) {
|
|
|
3468
3616
|
const relationsDecorator = filterClass.getDecorators().find((d) => d.getName() === "Relations");
|
|
3469
3617
|
if (relationsDecorator) {
|
|
3470
3618
|
const relArgs = relationsDecorator.getArguments();
|
|
3471
|
-
if (relArgs.length > 0 &&
|
|
3619
|
+
if (relArgs.length > 0 && Node6.isObjectLiteralExpression(relArgs[0])) {
|
|
3472
3620
|
for (const relProp of relArgs[0].getProperties()) {
|
|
3473
|
-
if (!
|
|
3621
|
+
if (!Node6.isPropertyAssignment(relProp)) continue;
|
|
3474
3622
|
const relInit = relProp.getInitializer();
|
|
3475
|
-
if (!relInit || !
|
|
3623
|
+
if (!relInit || !Node6.isObjectLiteralExpression(relInit)) continue;
|
|
3476
3624
|
const keysProp = relInit.getProperty("keys");
|
|
3477
|
-
if (!keysProp || !
|
|
3625
|
+
if (!keysProp || !Node6.isPropertyAssignment(keysProp)) continue;
|
|
3478
3626
|
const keysInit = keysProp.getInitializer();
|
|
3479
|
-
if (!keysInit || !
|
|
3627
|
+
if (!keysInit || !Node6.isArrayLiteralExpression(keysInit)) continue;
|
|
3480
3628
|
for (const el of keysInit.getElements()) {
|
|
3481
|
-
if (
|
|
3629
|
+
if (Node6.isStringLiteral(el)) {
|
|
3482
3630
|
fields.push(toFilterFieldType(el.getLiteralValue(), { kind: "unknown" }));
|
|
3483
3631
|
}
|
|
3484
3632
|
}
|
|
@@ -3519,22 +3667,22 @@ var PASSTHROUGH_UTILITY = /* @__PURE__ */ new Set([
|
|
|
3519
3667
|
]);
|
|
3520
3668
|
function resolveTypeNodeToString(typeNode, sourceFile, project, depth, subst = /* @__PURE__ */ new Map()) {
|
|
3521
3669
|
if (depth <= 0) return "unknown";
|
|
3522
|
-
if (
|
|
3670
|
+
if (Node7.isArrayTypeNode(typeNode)) {
|
|
3523
3671
|
const elementType = typeNode.getElementTypeNode();
|
|
3524
3672
|
return `Array<${resolveTypeNodeToString(elementType, sourceFile, project, depth, subst)}>`;
|
|
3525
3673
|
}
|
|
3526
|
-
if (
|
|
3674
|
+
if (Node7.isUnionTypeNode(typeNode)) {
|
|
3527
3675
|
return typeNode.getTypeNodes().map((t) => resolveTypeNodeToString(t, sourceFile, project, depth, subst)).join(" | ");
|
|
3528
3676
|
}
|
|
3529
|
-
if (
|
|
3677
|
+
if (Node7.isIntersectionTypeNode(typeNode)) {
|
|
3530
3678
|
return typeNode.getTypeNodes().map((t) => resolveTypeNodeToString(t, sourceFile, project, depth, subst)).join(" & ");
|
|
3531
3679
|
}
|
|
3532
|
-
if (
|
|
3680
|
+
if (Node7.isParenthesizedTypeNode(typeNode)) {
|
|
3533
3681
|
return `(${resolveTypeNodeToString(typeNode.getTypeNode(), sourceFile, project, depth, subst)})`;
|
|
3534
3682
|
}
|
|
3535
|
-
if (
|
|
3683
|
+
if (Node7.isTypeReference(typeNode)) {
|
|
3536
3684
|
const typeName = typeNode.getTypeName();
|
|
3537
|
-
const name =
|
|
3685
|
+
const name = Node7.isIdentifier(typeName) ? typeName.getText() : typeNode.getText();
|
|
3538
3686
|
const bound = subst.get(name);
|
|
3539
3687
|
if (bound !== void 0) return bound;
|
|
3540
3688
|
if (name === "string" || name === "number" || name === "boolean") return name;
|
|
@@ -3557,10 +3705,10 @@ function resolveTypeNodeToString(typeNode, sourceFile, project, depth, subst = /
|
|
|
3557
3705
|
dbg("unresolvable type:", name, "in", sourceFile.getFilePath());
|
|
3558
3706
|
return "unknown";
|
|
3559
3707
|
}
|
|
3560
|
-
if (
|
|
3708
|
+
if (Node7.isTypeLiteral(typeNode)) {
|
|
3561
3709
|
const members = [];
|
|
3562
3710
|
for (const member of typeNode.getMembers()) {
|
|
3563
|
-
if (
|
|
3711
|
+
if (Node7.isPropertySignature(member)) {
|
|
3564
3712
|
const memberTypeNode = member.getTypeNode();
|
|
3565
3713
|
const memberType = memberTypeNode ? resolveTypeNodeToString(memberTypeNode, sourceFile, project, depth, subst) : "unknown";
|
|
3566
3714
|
members.push(`${member.getName()}${member.hasQuestionToken() ? "?" : ""}: ${memberType}`);
|
|
@@ -3660,7 +3808,7 @@ function extractQueryType(method, sourceFile, project) {
|
|
|
3660
3808
|
if (!queryDecorator) continue;
|
|
3661
3809
|
const queryArgs = queryDecorator.getArguments();
|
|
3662
3810
|
const nameArg = queryArgs[0];
|
|
3663
|
-
if (!nameArg || !
|
|
3811
|
+
if (!nameArg || !Node7.isStringLiteral(nameArg)) continue;
|
|
3664
3812
|
const queryName = nameArg.getLiteralValue();
|
|
3665
3813
|
const typeNode = param.getTypeNode();
|
|
3666
3814
|
const queryType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
|
|
@@ -3671,7 +3819,7 @@ function extractQueryType(method, sourceFile, project) {
|
|
|
3671
3819
|
function isParamOptional(param) {
|
|
3672
3820
|
if (param.hasQuestionToken() || param.hasInitializer()) return true;
|
|
3673
3821
|
const typeNode = param.getTypeNode();
|
|
3674
|
-
if (typeNode &&
|
|
3822
|
+
if (typeNode && Node7.isUnionTypeNode(typeNode)) {
|
|
3675
3823
|
return typeNode.getTypeNodes().some((t) => t.getKind() === SyntaxKind3.UndefinedKeyword);
|
|
3676
3824
|
}
|
|
3677
3825
|
return false;
|
|
@@ -3684,7 +3832,7 @@ function extractParamsType(method, sourceFile, project) {
|
|
|
3684
3832
|
const paramArgs = paramDecorator.getArguments();
|
|
3685
3833
|
if (paramArgs.length === 0) continue;
|
|
3686
3834
|
const nameArg = paramArgs[0];
|
|
3687
|
-
if (!
|
|
3835
|
+
if (!Node7.isStringLiteral(nameArg)) continue;
|
|
3688
3836
|
const paramName = nameArg.getLiteralValue();
|
|
3689
3837
|
const typeNode = param.getTypeNode();
|
|
3690
3838
|
const paramType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
|
|
@@ -3705,28 +3853,28 @@ function extractUploadedFiles(method) {
|
|
|
3705
3853
|
for (const decorator of method.getDecorators()) {
|
|
3706
3854
|
if (decorator.getName() !== "UseInterceptors") continue;
|
|
3707
3855
|
for (const arg of decorator.getArguments()) {
|
|
3708
|
-
if (!
|
|
3856
|
+
if (!Node7.isCallExpression(arg)) continue;
|
|
3709
3857
|
const interceptor = arg.getExpression().getText();
|
|
3710
3858
|
const callArgs = arg.getArguments();
|
|
3711
3859
|
const firstArg2 = callArgs[0];
|
|
3712
3860
|
if (interceptor === "FileInterceptor") {
|
|
3713
|
-
if (firstArg2 &&
|
|
3861
|
+
if (firstArg2 && Node7.isStringLiteral(firstArg2)) {
|
|
3714
3862
|
entries.push(`${firstArg2.getLiteralValue()}: ${FILE}`);
|
|
3715
3863
|
multipart = true;
|
|
3716
3864
|
}
|
|
3717
3865
|
} else if (interceptor === "FilesInterceptor") {
|
|
3718
|
-
if (firstArg2 &&
|
|
3866
|
+
if (firstArg2 && Node7.isStringLiteral(firstArg2)) {
|
|
3719
3867
|
entries.push(`${firstArg2.getLiteralValue()}: Array<${FILE}>`);
|
|
3720
3868
|
multipart = true;
|
|
3721
3869
|
}
|
|
3722
3870
|
} else if (interceptor === "FileFieldsInterceptor") {
|
|
3723
|
-
if (firstArg2 &&
|
|
3871
|
+
if (firstArg2 && Node7.isArrayLiteralExpression(firstArg2)) {
|
|
3724
3872
|
for (const el of firstArg2.getElements()) {
|
|
3725
|
-
if (!
|
|
3873
|
+
if (!Node7.isObjectLiteralExpression(el)) continue;
|
|
3726
3874
|
const nameProp = el.getProperty("name");
|
|
3727
|
-
if (nameProp &&
|
|
3875
|
+
if (nameProp && Node7.isPropertyAssignment(nameProp)) {
|
|
3728
3876
|
const init = nameProp.getInitializer();
|
|
3729
|
-
if (init &&
|
|
3877
|
+
if (init && Node7.isStringLiteral(init)) {
|
|
3730
3878
|
entries.push(`${init.getLiteralValue()}: Array<${FILE}>`);
|
|
3731
3879
|
}
|
|
3732
3880
|
}
|
|
@@ -3746,13 +3894,13 @@ function extractResponseType(method, sourceFile, project) {
|
|
|
3746
3894
|
if (apiResponseDecorator) {
|
|
3747
3895
|
const args = apiResponseDecorator.getArguments();
|
|
3748
3896
|
const optsArg = args[0];
|
|
3749
|
-
if (optsArg &&
|
|
3897
|
+
if (optsArg && Node7.isObjectLiteralExpression(optsArg)) {
|
|
3750
3898
|
for (const prop of optsArg.getProperties()) {
|
|
3751
|
-
if (!
|
|
3899
|
+
if (!Node7.isPropertyAssignment(prop)) continue;
|
|
3752
3900
|
if (prop.getName() !== "type") continue;
|
|
3753
3901
|
const val = prop.getInitializer();
|
|
3754
3902
|
if (!val) continue;
|
|
3755
|
-
if (
|
|
3903
|
+
if (Node7.isArrayLiteralExpression(val)) {
|
|
3756
3904
|
const elements = val.getElements();
|
|
3757
3905
|
const firstEl = elements[0];
|
|
3758
3906
|
if (elements.length > 0 && firstEl !== void 0) {
|
|
@@ -3773,24 +3921,24 @@ function extractResponseType(method, sourceFile, project) {
|
|
|
3773
3921
|
}
|
|
3774
3922
|
function apiResponseStatus(decorator) {
|
|
3775
3923
|
const optsArg = decorator.getArguments()[0];
|
|
3776
|
-
if (!optsArg || !
|
|
3924
|
+
if (!optsArg || !Node7.isObjectLiteralExpression(optsArg)) return null;
|
|
3777
3925
|
for (const prop of optsArg.getProperties()) {
|
|
3778
|
-
if (!
|
|
3926
|
+
if (!Node7.isPropertyAssignment(prop)) continue;
|
|
3779
3927
|
if (prop.getName() !== "status") continue;
|
|
3780
3928
|
const val = prop.getInitializer();
|
|
3781
|
-
if (val &&
|
|
3929
|
+
if (val && Node7.isNumericLiteral(val)) return Number(val.getLiteralValue());
|
|
3782
3930
|
}
|
|
3783
3931
|
return null;
|
|
3784
3932
|
}
|
|
3785
3933
|
function apiResponseTypeNode(decorator) {
|
|
3786
3934
|
const optsArg = decorator.getArguments()[0];
|
|
3787
|
-
if (!optsArg || !
|
|
3935
|
+
if (!optsArg || !Node7.isObjectLiteralExpression(optsArg)) return null;
|
|
3788
3936
|
for (const prop of optsArg.getProperties()) {
|
|
3789
|
-
if (!
|
|
3937
|
+
if (!Node7.isPropertyAssignment(prop)) continue;
|
|
3790
3938
|
if (prop.getName() !== "type") continue;
|
|
3791
3939
|
const val = prop.getInitializer();
|
|
3792
3940
|
if (!val) return null;
|
|
3793
|
-
if (
|
|
3941
|
+
if (Node7.isArrayLiteralExpression(val)) {
|
|
3794
3942
|
const first = val.getElements()[0];
|
|
3795
3943
|
return first ? { node: first, isArray: true } : null;
|
|
3796
3944
|
}
|
|
@@ -3808,7 +3956,7 @@ function extractErrorType(method, sourceFile, project) {
|
|
|
3808
3956
|
const inner = resolveIdentifierToClassType(typeInfo.node, sourceFile, project, 3);
|
|
3809
3957
|
const type = typeInfo.isArray ? `Array<${inner}>` : inner;
|
|
3810
3958
|
let ref = null;
|
|
3811
|
-
if (
|
|
3959
|
+
if (Node7.isIdentifier(typeInfo.node)) {
|
|
3812
3960
|
const name = typeInfo.node.getText();
|
|
3813
3961
|
const localDecl = sourceFile.getInterface(name) || sourceFile.getClass(name) || sourceFile.getTypeAlias(name);
|
|
3814
3962
|
if (localDecl?.isExported()) {
|
|
@@ -3825,7 +3973,7 @@ function extractErrorType(method, sourceFile, project) {
|
|
|
3825
3973
|
return null;
|
|
3826
3974
|
}
|
|
3827
3975
|
function resolveIdentifierToClassType(node, sourceFile, project, depth) {
|
|
3828
|
-
if (!
|
|
3976
|
+
if (!Node7.isIdentifier(node)) return "unknown";
|
|
3829
3977
|
const name = node.getText();
|
|
3830
3978
|
const resolved = findType(name, sourceFile, project);
|
|
3831
3979
|
if (resolved) {
|
|
@@ -3845,9 +3993,9 @@ var STREAM_ENVELOPES = /* @__PURE__ */ new Set(["MessageEvent", "MessageEventLik
|
|
|
3845
3993
|
var BINARY_RESPONSE_TYPES = /* @__PURE__ */ new Set(["StreamableFile", "Buffer"]);
|
|
3846
3994
|
function detectBinaryResponse(method) {
|
|
3847
3995
|
const node = unwrapNamedContainer(method.getReturnTypeNode(), /* @__PURE__ */ new Set(["Promise"]));
|
|
3848
|
-
if (!node || !
|
|
3996
|
+
if (!node || !Node7.isTypeReference(node)) return false;
|
|
3849
3997
|
const typeName = node.getTypeName();
|
|
3850
|
-
const name =
|
|
3998
|
+
const name = Node7.isIdentifier(typeName) ? typeName.getText() : "";
|
|
3851
3999
|
return BINARY_RESPONSE_TYPES.has(name);
|
|
3852
4000
|
}
|
|
3853
4001
|
function detectStreamElement(method) {
|
|
@@ -3862,9 +4010,9 @@ function detectStreamElement(method) {
|
|
|
3862
4010
|
return null;
|
|
3863
4011
|
}
|
|
3864
4012
|
function streamContainerElement(node) {
|
|
3865
|
-
if (!node || !
|
|
4013
|
+
if (!node || !Node7.isTypeReference(node)) return null;
|
|
3866
4014
|
const typeName = node.getTypeName();
|
|
3867
|
-
const name =
|
|
4015
|
+
const name = Node7.isIdentifier(typeName) ? typeName.getText() : "";
|
|
3868
4016
|
if (STREAM_CONTAINERS.has(name) || STREAM_CONTAINERS_GENERATOR.has(name)) {
|
|
3869
4017
|
return node.getTypeArguments()[0] ?? null;
|
|
3870
4018
|
}
|
|
@@ -3874,9 +4022,9 @@ function hasAsQueryDecorator(method) {
|
|
|
3874
4022
|
return method.getDecorators().some((d) => d.getName() === "AsQuery");
|
|
3875
4023
|
}
|
|
3876
4024
|
function unwrapNamedContainer(node, names) {
|
|
3877
|
-
if (!node || !
|
|
4025
|
+
if (!node || !Node7.isTypeReference(node)) return node;
|
|
3878
4026
|
const typeName = node.getTypeName();
|
|
3879
|
-
const name =
|
|
4027
|
+
const name = Node7.isIdentifier(typeName) ? typeName.getText() : "";
|
|
3880
4028
|
if (names.has(name)) {
|
|
3881
4029
|
return node.getTypeArguments()[0] ?? node;
|
|
3882
4030
|
}
|
|
@@ -3922,11 +4070,11 @@ function extractDtoContract(method, sourceFile, project, mixin) {
|
|
|
3922
4070
|
if (apiResp) {
|
|
3923
4071
|
const args = apiResp.getArguments();
|
|
3924
4072
|
const optsArg = args[0];
|
|
3925
|
-
if (optsArg &&
|
|
4073
|
+
if (optsArg && Node7.isObjectLiteralExpression(optsArg)) {
|
|
3926
4074
|
for (const prop of optsArg.getProperties()) {
|
|
3927
|
-
if (
|
|
4075
|
+
if (Node7.isPropertyAssignment(prop) && prop.getName() === "type") {
|
|
3928
4076
|
const val = prop.getInitializer();
|
|
3929
|
-
if (val &&
|
|
4077
|
+
if (val && Node7.isIdentifier(val)) {
|
|
3930
4078
|
const name = val.getText();
|
|
3931
4079
|
const localDecl = sourceFile.getInterface(name) || sourceFile.getClass(name) || sourceFile.getTypeAlias(name);
|
|
3932
4080
|
if (localDecl?.isExported()) {
|
|
@@ -3994,101 +4142,6 @@ function resolveParamClass(method, decoratorName, sourceFile, project) {
|
|
|
3994
4142
|
return null;
|
|
3995
4143
|
}
|
|
3996
4144
|
|
|
3997
|
-
// src/discovery/heritage.ts
|
|
3998
|
-
import { Node as Node7, Project as Project3 } from "ts-morph";
|
|
3999
|
-
function resolveHeritageCall(node) {
|
|
4000
|
-
if (!node) return void 0;
|
|
4001
|
-
const expr = unwrapExpression(node);
|
|
4002
|
-
if (Node7.isCallExpression(expr)) return expr;
|
|
4003
|
-
if (!Node7.isIdentifier(expr)) return void 0;
|
|
4004
|
-
const decl = expr.getDefinitions().map((d) => d.getDeclarationNode()).find(
|
|
4005
|
-
(n) => n !== void 0 && Node7.isVariableDeclaration(n)
|
|
4006
|
-
);
|
|
4007
|
-
const init = decl?.getInitializer();
|
|
4008
|
-
if (!init) return void 0;
|
|
4009
|
-
const unwrapped = unwrapExpression(init);
|
|
4010
|
-
return Node7.isCallExpression(unwrapped) ? unwrapped : void 0;
|
|
4011
|
-
}
|
|
4012
|
-
function unwrapExpression(node) {
|
|
4013
|
-
let current = node;
|
|
4014
|
-
while (Node7.isAsExpression(current) || Node7.isSatisfiesExpression(current) || Node7.isParenthesizedExpression(current) || Node7.isTypeAssertion(current)) {
|
|
4015
|
-
current = current.getExpression();
|
|
4016
|
-
}
|
|
4017
|
-
return current;
|
|
4018
|
-
}
|
|
4019
|
-
function resolveReturnedClass(factoryDecl) {
|
|
4020
|
-
const body = factoryDecl.getBody();
|
|
4021
|
-
if (!body) return void 0;
|
|
4022
|
-
const returns = body.getDescendants().filter((n) => Node7.isReturnStatement(n));
|
|
4023
|
-
for (const ret of returns) {
|
|
4024
|
-
const expr = ret.getExpression();
|
|
4025
|
-
if (!expr) continue;
|
|
4026
|
-
const inner = unwrapExpression(expr);
|
|
4027
|
-
if (Node7.isClassExpression(inner)) {
|
|
4028
|
-
return inner;
|
|
4029
|
-
}
|
|
4030
|
-
if (Node7.isIdentifier(inner)) {
|
|
4031
|
-
const name = inner.getText();
|
|
4032
|
-
const decl = body.getDescendants().find((n) => Node7.isClassDeclaration(n) && n.getName() === name);
|
|
4033
|
-
if (decl) return decl;
|
|
4034
|
-
}
|
|
4035
|
-
}
|
|
4036
|
-
return void 0;
|
|
4037
|
-
}
|
|
4038
|
-
function resolveInheritedMethods(cls) {
|
|
4039
|
-
const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
|
|
4040
|
-
if (!expr) return void 0;
|
|
4041
|
-
const callee = expr.getExpression();
|
|
4042
|
-
if (!Node7.isIdentifier(callee)) return void 0;
|
|
4043
|
-
const factoryDecl = callee.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => Node7.isFunctionDeclaration(n));
|
|
4044
|
-
if (!factoryDecl) return void 0;
|
|
4045
|
-
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
4046
|
-
if (!returnedClass) return void 0;
|
|
4047
|
-
const classArgs = [];
|
|
4048
|
-
for (const arg of expr.getArguments()) {
|
|
4049
|
-
if (!Node7.isIdentifier(arg)) continue;
|
|
4050
|
-
const decl = arg.getDefinitions().map((d) => d.getDeclarationNode()).find((n) => Node7.isClassDeclaration(n));
|
|
4051
|
-
if (decl) {
|
|
4052
|
-
classArgs.push({
|
|
4053
|
-
name: decl.getName() ?? arg.getText(),
|
|
4054
|
-
filePath: decl.getSourceFile().getFilePath()
|
|
4055
|
-
});
|
|
4056
|
-
}
|
|
4057
|
-
}
|
|
4058
|
-
return {
|
|
4059
|
-
methods: returnedClass.getMethods(),
|
|
4060
|
-
factoryName: callee.getText(),
|
|
4061
|
-
factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
|
|
4062
|
-
classArgs
|
|
4063
|
-
};
|
|
4064
|
-
}
|
|
4065
|
-
var mixinTypeProject;
|
|
4066
|
-
function getMixinTypeProject() {
|
|
4067
|
-
mixinTypeProject ??= new Project3({
|
|
4068
|
-
skipAddingFilesFromTsConfig: true,
|
|
4069
|
-
compilerOptions: { strict: true }
|
|
4070
|
-
});
|
|
4071
|
-
return mixinTypeProject;
|
|
4072
|
-
}
|
|
4073
|
-
function clearMixinTypeProject() {
|
|
4074
|
-
mixinTypeProject = void 0;
|
|
4075
|
-
}
|
|
4076
|
-
function resolveInstantiatedReturnType(cls, methodName) {
|
|
4077
|
-
const filePath = cls.getSourceFile().getFilePath();
|
|
4078
|
-
const className = cls.getName();
|
|
4079
|
-
if (!className) return void 0;
|
|
4080
|
-
const project = getMixinTypeProject();
|
|
4081
|
-
const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPathIfExists(filePath);
|
|
4082
|
-
const typedCls = sourceFile?.getClass(className);
|
|
4083
|
-
if (!typedCls) return void 0;
|
|
4084
|
-
const prop = typedCls.getType().getProperty(methodName);
|
|
4085
|
-
if (!prop) return void 0;
|
|
4086
|
-
const returnType = prop.getTypeAtLocation(typedCls).getCallSignatures()[0]?.getReturnType();
|
|
4087
|
-
if (!returnType) return void 0;
|
|
4088
|
-
const unwrapped = returnType.getSymbol()?.getName() === "Promise" ? returnType.getTypeArguments()[0] ?? returnType : returnType;
|
|
4089
|
-
return unwrapped.getText(typedCls);
|
|
4090
|
-
}
|
|
4091
|
-
|
|
4092
4145
|
// src/discovery/zod-ast-to-ts.ts
|
|
4093
4146
|
import { Node as Node8, SyntaxKind as SyntaxKind4 } from "ts-morph";
|
|
4094
4147
|
function zodAstToTs(node) {
|
|
@@ -4571,7 +4624,8 @@ function extractFromSourceFile(sourceFile, project) {
|
|
|
4571
4624
|
const mixinBinding = inherited ? {
|
|
4572
4625
|
factoryName: inherited.factoryName,
|
|
4573
4626
|
factoryFilePath: inherited.factoryFilePath,
|
|
4574
|
-
classArgs: inherited.classArgs
|
|
4627
|
+
classArgs: inherited.classArgs,
|
|
4628
|
+
namedClassArgs: inherited.namedClassArgs
|
|
4575
4629
|
} : void 0;
|
|
4576
4630
|
const ownMethods = cls.getMethods();
|
|
4577
4631
|
const ownNames = new Set(ownMethods.map((m) => m.getName()));
|
|
@@ -4803,7 +4857,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
4803
4857
|
}
|
|
4804
4858
|
|
|
4805
4859
|
// src/index.ts
|
|
4806
|
-
var VERSION = "0.
|
|
4860
|
+
var VERSION = "0.18.0";
|
|
4807
4861
|
|
|
4808
4862
|
// src/generate-manifest.ts
|
|
4809
4863
|
var MANIFEST_FILE = ".codegen-manifest.json";
|