@dudousxd/nestjs-codegen 0.5.1 → 0.5.2
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 +6 -0
- package/dist/cli/main.cjs +8 -17
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +8 -17
- 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-B0mS84Jj.d.cts → index-_qRai4M3.d.cts} +1 -1
- package/dist/{index-B0mS84Jj.d.ts → index-_qRai4M3.d.ts} +1 -1
- package/dist/index.cjs +48 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -4
- package/dist/index.d.ts +29 -4
- package/dist/index.js +45 -17
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +7 -16
- 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 +7 -16
- package/dist/nest/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { l as ApiClientLayer, m as ApiHeaderContribution, n as ApiModuleDeps, C as CodegenExtension, o as EmittedFile, E as ExtensionContext, L as LeafModel, p as RequestModel, q as RequestShape, s as defineExtension, t as requestShape } from '../index-
|
|
1
|
+
export { l as ApiClientLayer, m as ApiHeaderContribution, n as ApiModuleDeps, C as CodegenExtension, o as EmittedFile, E as ExtensionContext, L as LeafModel, p as RequestModel, q as RequestShape, s as defineExtension, t as requestShape } from '../index-_qRai4M3.cjs';
|
|
2
2
|
import 'ts-morph';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { l as ApiClientLayer, m as ApiHeaderContribution, n as ApiModuleDeps, C as CodegenExtension, o as EmittedFile, E as ExtensionContext, L as LeafModel, p as RequestModel, q as RequestShape, s as defineExtension, t as requestShape } from '../index-
|
|
1
|
+
export { l as ApiClientLayer, m as ApiHeaderContribution, n as ApiModuleDeps, C as CodegenExtension, o as EmittedFile, E as ExtensionContext, L as LeafModel, p as RequestModel, q as RequestShape, s as defineExtension, t as requestShape } from '../index-_qRai4M3.js';
|
|
2
2
|
import 'ts-morph';
|
|
@@ -631,4 +631,4 @@ declare function requestShape(route: RouteDescriptor): RequestShape;
|
|
|
631
631
|
/** Identity helper for authoring extensions with full type inference. */
|
|
632
632
|
declare function defineExtension(ext: CodegenExtension): CodegenExtension;
|
|
633
633
|
|
|
634
|
-
export { type AdapterUsage as A, type CodegenExtension as C, type ExtensionContext as E, type LeafModel as L, type NumberCheck as N, type ResolvedConfig as R, type SchemaNode as S, type TypeRef as T, type UserConfig as U, type ValidationAdapter as V, type RouteDescriptor as a, type
|
|
634
|
+
export { type AdapterUsage as A, type CodegenExtension as C, type ExtensionContext as E, type LeafModel as L, type NumberCheck as N, type ResolvedConfig as R, type SchemaNode as S, type TypeRef as T, type UserConfig as U, type ValidationAdapter as V, type RouteDescriptor as a, type RenderContext as b, type SchemaModule as c, type RenderedModule as d, type ResolvedFormsConfig as e, type ContractDescriptor as f, type ContractSource as g, type ControllerRef as h, type ScopeConfig as i, type StringCheck as j, type ValidationOption as k, type ApiClientLayer as l, type ApiHeaderContribution as m, type ApiModuleDeps as n, type EmittedFile as o, type RequestModel as p, type RequestShape as q, resolveAdapter as r, defineExtension as s, requestShape as t };
|
|
@@ -631,4 +631,4 @@ declare function requestShape(route: RouteDescriptor): RequestShape;
|
|
|
631
631
|
/** Identity helper for authoring extensions with full type inference. */
|
|
632
632
|
declare function defineExtension(ext: CodegenExtension): CodegenExtension;
|
|
633
633
|
|
|
634
|
-
export { type AdapterUsage as A, type CodegenExtension as C, type ExtensionContext as E, type LeafModel as L, type NumberCheck as N, type ResolvedConfig as R, type SchemaNode as S, type TypeRef as T, type UserConfig as U, type ValidationAdapter as V, type RouteDescriptor as a, type
|
|
634
|
+
export { type AdapterUsage as A, type CodegenExtension as C, type ExtensionContext as E, type LeafModel as L, type NumberCheck as N, type ResolvedConfig as R, type SchemaNode as S, type TypeRef as T, type UserConfig as U, type ValidationAdapter as V, type RouteDescriptor as a, type RenderContext as b, type SchemaModule as c, type RenderedModule as d, type ResolvedFormsConfig as e, type ContractDescriptor as f, type ContractSource as g, type ControllerRef as h, type ScopeConfig as i, type StringCheck as j, type ValidationOption as k, type ApiClientLayer as l, type ApiHeaderContribution as m, type ApiModuleDeps as n, type EmittedFile as o, type RequestModel as p, type RequestShape as q, resolveAdapter as r, defineExtension as s, requestShape as t };
|
package/dist/index.cjs
CHANGED
|
@@ -36,6 +36,7 @@ __export(src_exports, {
|
|
|
36
36
|
acquireLock: () => acquireLock,
|
|
37
37
|
buildMocksFile: () => buildMocksFile,
|
|
38
38
|
buildOpenApiSpec: () => buildOpenApiSpec,
|
|
39
|
+
createChainModuleRenderer: () => createChainModuleRenderer,
|
|
39
40
|
defineConfig: () => defineConfig,
|
|
40
41
|
discoverContractsFast: () => discoverContractsFast,
|
|
41
42
|
emitApi: () => emitApi,
|
|
@@ -51,6 +52,8 @@ __export(src_exports, {
|
|
|
51
52
|
resolveConfig: () => resolveConfig,
|
|
52
53
|
schemaModuleToJsonSchema: () => schemaModuleToJsonSchema,
|
|
53
54
|
schemaNodeToJsonSchema: () => schemaNodeToJsonSchema,
|
|
55
|
+
toObjectKey: () => toObjectKey2,
|
|
56
|
+
typeNameFor: () => typeNameFor,
|
|
54
57
|
watch: () => watch
|
|
55
58
|
});
|
|
56
59
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -2602,37 +2605,28 @@ function buildProperty(prop, classFile, ctx) {
|
|
|
2602
2605
|
const typeNode = prop.getTypeNode();
|
|
2603
2606
|
const typeText = typeNode?.getText() ?? "unknown";
|
|
2604
2607
|
const isArrayType = !!typeNode && import_ts_morph4.Node.isArrayTypeNode(typeNode);
|
|
2608
|
+
const asField = (child) => applyPresence(
|
|
2609
|
+
has("IsArray") || isArrayType ? { kind: "array", element: child } : child,
|
|
2610
|
+
decorators
|
|
2611
|
+
);
|
|
2605
2612
|
const discriminator = resolveDiscriminator(dec("Type"));
|
|
2606
2613
|
if (discriminator) {
|
|
2607
2614
|
const options = discriminator.subTypes.map(
|
|
2608
2615
|
(name) => buildNestedReference(name, classFile, ctx)
|
|
2609
2616
|
);
|
|
2610
|
-
|
|
2611
|
-
kind: "union",
|
|
2612
|
-
options,
|
|
2613
|
-
discriminator: discriminator.property
|
|
2614
|
-
};
|
|
2615
|
-
const wrapArray = has("IsArray") || isArrayType;
|
|
2616
|
-
const node2 = wrapArray ? { kind: "array", element: unionNode } : unionNode;
|
|
2617
|
-
return applyPresence(node2, decorators);
|
|
2617
|
+
return asField({ kind: "union", options, discriminator: discriminator.property });
|
|
2618
2618
|
}
|
|
2619
2619
|
const propTypeParam = singularClassName(typeText);
|
|
2620
2620
|
if (propTypeParam && ctx.typeBindings.has(propTypeParam)) {
|
|
2621
2621
|
const bound = ctx.typeBindings.get(propTypeParam);
|
|
2622
|
-
|
|
2623
|
-
const wrapArray = has("IsArray") || isArrayType;
|
|
2624
|
-
const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
|
|
2625
|
-
return applyPresence(node2, decorators);
|
|
2622
|
+
return asField(buildNestedReference(bound, classFile, ctx));
|
|
2626
2623
|
}
|
|
2627
2624
|
const typeRefName = resolveTypeFactoryName(dec("Type"));
|
|
2628
2625
|
if (has("ValidateNested") || typeRefName) {
|
|
2629
2626
|
const typeArgs = genericTypeArgNames(typeNode);
|
|
2630
2627
|
const childName = typeRefName ?? singularClassName(typeText);
|
|
2631
2628
|
if (childName) {
|
|
2632
|
-
|
|
2633
|
-
const wrapArray = has("IsArray") || isArrayType;
|
|
2634
|
-
const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
|
|
2635
|
-
return applyPresence(node2, decorators);
|
|
2629
|
+
return asField(buildNestedReference(childName, classFile, ctx, typeArgs));
|
|
2636
2630
|
}
|
|
2637
2631
|
}
|
|
2638
2632
|
let base = baseFromType(typeText, isArrayType);
|
|
@@ -4536,8 +4530,42 @@ function renderTsType(node, ctx) {
|
|
|
4536
4530
|
}
|
|
4537
4531
|
}
|
|
4538
4532
|
|
|
4533
|
+
// src/adapters/chain-module.ts
|
|
4534
|
+
function typeNameFor(schemaName) {
|
|
4535
|
+
return schemaName.replace(/Schema(_\d+)?$/, "$1");
|
|
4536
|
+
}
|
|
4537
|
+
function toObjectKey2(name) {
|
|
4538
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) ? name : JSON.stringify(name);
|
|
4539
|
+
}
|
|
4540
|
+
function createChainModuleRenderer(opts) {
|
|
4541
|
+
const { render, recursiveAnnotation } = opts;
|
|
4542
|
+
return (mod) => {
|
|
4543
|
+
const ctx = { named: mod.named };
|
|
4544
|
+
const recursive = mod.recursive ?? /* @__PURE__ */ new Set();
|
|
4545
|
+
const tctx = { named: mod.named, recursive, typeNameFor };
|
|
4546
|
+
const namedNestedSchemas = /* @__PURE__ */ new Map();
|
|
4547
|
+
const namedTypeAliases = /* @__PURE__ */ new Map();
|
|
4548
|
+
const namedAnnotations = /* @__PURE__ */ new Map();
|
|
4549
|
+
for (const [name, node] of mod.named) {
|
|
4550
|
+
namedNestedSchemas.set(name, render(node, ctx));
|
|
4551
|
+
if (recursive.has(name)) {
|
|
4552
|
+
const typeName = typeNameFor(name);
|
|
4553
|
+
namedTypeAliases.set(name, `type ${typeName} = ${renderTsType(node, tctx)}`);
|
|
4554
|
+
namedAnnotations.set(name, recursiveAnnotation(typeName));
|
|
4555
|
+
}
|
|
4556
|
+
}
|
|
4557
|
+
return {
|
|
4558
|
+
schemaText: render(mod.root, ctx),
|
|
4559
|
+
namedNestedSchemas,
|
|
4560
|
+
namedTypeAliases,
|
|
4561
|
+
namedAnnotations,
|
|
4562
|
+
warnings: mod.warnings
|
|
4563
|
+
};
|
|
4564
|
+
};
|
|
4565
|
+
}
|
|
4566
|
+
|
|
4539
4567
|
// src/index.ts
|
|
4540
|
-
var VERSION = "0.5.
|
|
4568
|
+
var VERSION = "0.5.2";
|
|
4541
4569
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4542
4570
|
0 && (module.exports = {
|
|
4543
4571
|
CodegenError,
|
|
@@ -4546,6 +4574,7 @@ var VERSION = "0.5.1";
|
|
|
4546
4574
|
acquireLock,
|
|
4547
4575
|
buildMocksFile,
|
|
4548
4576
|
buildOpenApiSpec,
|
|
4577
|
+
createChainModuleRenderer,
|
|
4549
4578
|
defineConfig,
|
|
4550
4579
|
discoverContractsFast,
|
|
4551
4580
|
emitApi,
|
|
@@ -4561,6 +4590,8 @@ var VERSION = "0.5.1";
|
|
|
4561
4590
|
resolveConfig,
|
|
4562
4591
|
schemaModuleToJsonSchema,
|
|
4563
4592
|
schemaNodeToJsonSchema,
|
|
4593
|
+
toObjectKey,
|
|
4594
|
+
typeNameFor,
|
|
4564
4595
|
watch
|
|
4565
4596
|
});
|
|
4566
4597
|
//# sourceMappingURL=index.cjs.map
|