@dudousxd/nestjs-codegen 0.18.0 → 0.19.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 +50 -0
- package/dist/cli/main.cjs +64 -9
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +64 -9
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +64 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +64 -9
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +64 -9
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +64 -9
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -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.19.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
|
@@ -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.19.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
|
@@ -3480,10 +3480,46 @@ function resolveReturnedClass(factoryDecl) {
|
|
|
3480
3480
|
}
|
|
3481
3481
|
return void 0;
|
|
3482
3482
|
}
|
|
3483
|
+
function factoryCalleeName(call) {
|
|
3484
|
+
const callee = unwrapExpression(call.getExpression());
|
|
3485
|
+
if (Node5.isIdentifier(callee)) return callee;
|
|
3486
|
+
if (Node5.isPropertyAccessExpression(callee)) {
|
|
3487
|
+
const name = callee.getNameNode();
|
|
3488
|
+
return Node5.isIdentifier(name) ? name : void 0;
|
|
3489
|
+
}
|
|
3490
|
+
return void 0;
|
|
3491
|
+
}
|
|
3483
3492
|
function resolveFactoryDeclaration(call) {
|
|
3484
|
-
const
|
|
3485
|
-
|
|
3486
|
-
|
|
3493
|
+
const name = factoryCalleeName(call);
|
|
3494
|
+
return name ? resolveFactoryFromName(name, /* @__PURE__ */ new Set()) : void 0;
|
|
3495
|
+
}
|
|
3496
|
+
function resolveFactoryFromName(name, seen) {
|
|
3497
|
+
if (seen.has(name)) return void 0;
|
|
3498
|
+
seen.add(name);
|
|
3499
|
+
const decls = name.getDefinitions().map((d) => d.getDeclarationNode()).filter((n) => n !== void 0);
|
|
3500
|
+
for (const decl of decls) {
|
|
3501
|
+
if (Node5.isFunctionDeclaration(decl) || Node5.isMethodDeclaration(decl)) return decl;
|
|
3502
|
+
if (Node5.isPropertyAssignment(decl)) {
|
|
3503
|
+
const init = decl.getInitializer();
|
|
3504
|
+
const inner = init ? unwrapExpression(init) : void 0;
|
|
3505
|
+
if (inner && Node5.isIdentifier(inner)) {
|
|
3506
|
+
const resolved = resolveFactoryFromName(inner, seen);
|
|
3507
|
+
if (resolved) return resolved;
|
|
3508
|
+
}
|
|
3509
|
+
continue;
|
|
3510
|
+
}
|
|
3511
|
+
if (Node5.isShorthandPropertyAssignment(decl)) {
|
|
3512
|
+
const nameNode = decl.getNameNode();
|
|
3513
|
+
const resolved = Node5.isIdentifier(nameNode) ? resolveFactoryFromName(nameNode, seen) : void 0;
|
|
3514
|
+
if (resolved) return resolved;
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
return void 0;
|
|
3518
|
+
}
|
|
3519
|
+
function warnUnresolvedFactory(cls, calleeText, reason) {
|
|
3520
|
+
console.warn(
|
|
3521
|
+
`[nestjs-codegen/fast] ${cls.getName() ?? "<anonymous class>"} in ${cls.getSourceFile().getFilePath()} extends ${calleeText}(...) but ${reason} \u2014 it contributes NO routes to the generated client. Resolvable factory callees: a name (\`factory(...)\`), a namespace or object property (\`ns.factory(...)\`), or a static method (\`Factory.create(...)\`), each resolving to a function or method declaration that returns a class.`
|
|
3522
|
+
);
|
|
3487
3523
|
}
|
|
3488
3524
|
function resolveFactoryStaticClass(node) {
|
|
3489
3525
|
if (!Node5.isPropertyAccessExpression(node)) return void 0;
|
|
@@ -3505,12 +3541,26 @@ function resolveFactoryStaticClass(node) {
|
|
|
3505
3541
|
function resolveInheritedMethods(cls) {
|
|
3506
3542
|
const expr = resolveHeritageCall(cls.getExtends()?.getExpression());
|
|
3507
3543
|
if (!expr) return void 0;
|
|
3508
|
-
const
|
|
3509
|
-
|
|
3544
|
+
const isController = cls.getDecorator("Controller") !== void 0;
|
|
3545
|
+
const calleeText = expr.getExpression().getText();
|
|
3510
3546
|
const factoryDecl = resolveFactoryDeclaration(expr);
|
|
3511
|
-
if (!factoryDecl)
|
|
3547
|
+
if (!factoryDecl) {
|
|
3548
|
+
if (isController) {
|
|
3549
|
+
warnUnresolvedFactory(
|
|
3550
|
+
cls,
|
|
3551
|
+
calleeText,
|
|
3552
|
+
factoryCalleeName(expr) ? "its callee does not resolve to a function or method declaration" : "its callee is not a name that can be resolved statically"
|
|
3553
|
+
);
|
|
3554
|
+
}
|
|
3555
|
+
return void 0;
|
|
3556
|
+
}
|
|
3512
3557
|
const returnedClass = resolveReturnedClass(factoryDecl);
|
|
3513
|
-
if (!returnedClass)
|
|
3558
|
+
if (!returnedClass) {
|
|
3559
|
+
if (isController) {
|
|
3560
|
+
warnUnresolvedFactory(cls, calleeText, "that factory does not return a class declaration");
|
|
3561
|
+
}
|
|
3562
|
+
return void 0;
|
|
3563
|
+
}
|
|
3514
3564
|
const classArgs = [];
|
|
3515
3565
|
const namedClassArgs = {};
|
|
3516
3566
|
for (const arg of expr.getArguments()) {
|
|
@@ -3528,7 +3578,12 @@ function resolveInheritedMethods(cls) {
|
|
|
3528
3578
|
}
|
|
3529
3579
|
return {
|
|
3530
3580
|
methods: returnedClass.getMethods(),
|
|
3531
|
-
|
|
3581
|
+
// The DECLARATION's name, not the call-site text: consumers look the factory
|
|
3582
|
+
// back up by name inside `factoryFilePath`, which a qualified
|
|
3583
|
+
// `tables.createTableController` would never match. For a bare identifier
|
|
3584
|
+
// the two coincide (bar an import alias, where the declaration name is the
|
|
3585
|
+
// one that resolves anyway).
|
|
3586
|
+
factoryName: factoryDecl.getName() ?? calleeText,
|
|
3532
3587
|
factoryFilePath: factoryDecl.getSourceFile().getFilePath(),
|
|
3533
3588
|
classArgs,
|
|
3534
3589
|
namedClassArgs
|
|
@@ -5155,7 +5210,7 @@ function createChainModuleRenderer(opts) {
|
|
|
5155
5210
|
}
|
|
5156
5211
|
|
|
5157
5212
|
// src/index.ts
|
|
5158
|
-
var VERSION = "0.
|
|
5213
|
+
var VERSION = "0.19.0";
|
|
5159
5214
|
export {
|
|
5160
5215
|
CodegenError,
|
|
5161
5216
|
ConfigError,
|