@dudousxd/nestjs-codegen 0.7.0 → 0.8.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 +12 -0
- package/dist/cli/main.cjs +38 -14
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +38 -14
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +38 -14
- 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 +38 -14
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +22 -3
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +22 -3
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -296,6 +296,6 @@ interface FastDiscoveryOptions {
|
|
|
296
296
|
}
|
|
297
297
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
298
298
|
|
|
299
|
-
declare const VERSION = "0.
|
|
299
|
+
declare const VERSION = "0.8.0";
|
|
300
300
|
|
|
301
301
|
export { type ChainModuleRendererOptions, CodegenError, ConfigError, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, 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
|
@@ -296,6 +296,6 @@ interface FastDiscoveryOptions {
|
|
|
296
296
|
}
|
|
297
297
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
298
298
|
|
|
299
|
-
declare const VERSION = "0.
|
|
299
|
+
declare const VERSION = "0.8.0";
|
|
300
300
|
|
|
301
301
|
export { type ChainModuleRendererOptions, CodegenError, ConfigError, type FastDiscoveryOptions, type JsonSchema, type MocksEmitOptions, type OpenApiDocument, type OpenApiEmitOptions, type OpenApiInfo, RenderContext, RenderedModule, ResolvedConfig, RouteDescriptor, SchemaModule, SchemaNode, type TsTypeContext, UserConfig, VERSION, ValidationAdapter, 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
|
@@ -46,18 +46,23 @@ async function fileExists(filePath) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
async function importTs(filePath) {
|
|
49
|
-
|
|
49
|
+
const fileUrl = pathToFileURL(filePath).href;
|
|
50
50
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
return await import(fileUrl);
|
|
52
|
+
} catch (nativeError) {
|
|
53
|
+
let tsImport;
|
|
54
|
+
try {
|
|
55
|
+
const tsxEsm = await import("tsx/esm/api");
|
|
56
|
+
tsImport = tsxEsm.tsImport;
|
|
57
|
+
} catch {
|
|
58
|
+
throw new ConfigError(
|
|
59
|
+
"Failed to load config: `tsx` is required for loading TypeScript config files. Install it as a dev dependency: pnpm add -D tsx",
|
|
60
|
+
{ cause: nativeError }
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const parentURL = pathToFileURL(`${filePath}__parent__`).href;
|
|
64
|
+
return tsImport(fileUrl, { parentURL });
|
|
57
65
|
}
|
|
58
|
-
const parentURL = pathToFileURL(`${filePath}__parent__`).href;
|
|
59
|
-
const fileUrl = pathToFileURL(filePath).href;
|
|
60
|
-
return tsImport(fileUrl, { parentURL });
|
|
61
66
|
}
|
|
62
67
|
function resolveAbsolute(cwd, p) {
|
|
63
68
|
if (isAbsolute(p)) return p;
|
|
@@ -3520,14 +3525,33 @@ function extractQueryType(method, sourceFile, project) {
|
|
|
3520
3525
|
for (const param of method.getParameters()) {
|
|
3521
3526
|
const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
|
|
3522
3527
|
if (!queryDecorator) continue;
|
|
3523
|
-
|
|
3524
|
-
if (queryArgs.length > 0) continue;
|
|
3528
|
+
if (queryDecorator.getArguments().length > 0) continue;
|
|
3525
3529
|
const typeNode = param.getTypeNode();
|
|
3526
3530
|
if (typeNode) {
|
|
3527
3531
|
return resolveTypeNodeToString(typeNode, sourceFile, project, 3);
|
|
3528
3532
|
}
|
|
3529
3533
|
}
|
|
3530
|
-
|
|
3534
|
+
const entries = [];
|
|
3535
|
+
for (const param of method.getParameters()) {
|
|
3536
|
+
const queryDecorator = param.getDecorators().find((d) => d.getName() === "Query");
|
|
3537
|
+
if (!queryDecorator) continue;
|
|
3538
|
+
const queryArgs = queryDecorator.getArguments();
|
|
3539
|
+
const nameArg = queryArgs[0];
|
|
3540
|
+
if (!nameArg || !Node6.isStringLiteral(nameArg)) continue;
|
|
3541
|
+
const queryName = nameArg.getLiteralValue();
|
|
3542
|
+
const typeNode = param.getTypeNode();
|
|
3543
|
+
const queryType = typeNode ? resolveTypeNodeToString(typeNode, sourceFile, project, 3) : "string";
|
|
3544
|
+
entries.push(`${queryName}${isParamOptional(param) ? "?" : ""}: ${queryType}`);
|
|
3545
|
+
}
|
|
3546
|
+
return entries.length > 0 ? `{ ${entries.join("; ")} }` : null;
|
|
3547
|
+
}
|
|
3548
|
+
function isParamOptional(param) {
|
|
3549
|
+
if (param.hasQuestionToken() || param.hasInitializer()) return true;
|
|
3550
|
+
const typeNode = param.getTypeNode();
|
|
3551
|
+
if (typeNode && Node6.isUnionTypeNode(typeNode)) {
|
|
3552
|
+
return typeNode.getTypeNodes().some((t) => t.getKind() === SyntaxKind3.UndefinedKeyword);
|
|
3553
|
+
}
|
|
3554
|
+
return false;
|
|
3531
3555
|
}
|
|
3532
3556
|
function extractParamsType(method, sourceFile, project) {
|
|
3533
3557
|
const entries = [];
|
|
@@ -4548,7 +4572,7 @@ function createChainModuleRenderer(opts) {
|
|
|
4548
4572
|
}
|
|
4549
4573
|
|
|
4550
4574
|
// src/index.ts
|
|
4551
|
-
var VERSION = "0.
|
|
4575
|
+
var VERSION = "0.8.0";
|
|
4552
4576
|
export {
|
|
4553
4577
|
CodegenError,
|
|
4554
4578
|
ConfigError,
|