@dudousxd/nestjs-codegen 0.14.2 → 0.15.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 +7 -0
- package/dist/cli/main.cjs +31 -3
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +31 -3
- package/dist/cli/main.js.map +1 -1
- package/dist/extension/index.cjs.map +1 -1
- package/dist/extension/index.d.cts +1 -1
- package/dist/extension/index.d.ts +1 -1
- package/dist/extension/index.js.map +1 -1
- package/dist/{index-DT8SgPxp.d.cts → index-CjIDPMsV.d.cts} +7 -0
- package/dist/{index-DT8SgPxp.d.ts → index-CjIDPMsV.d.ts} +7 -0
- package/dist/index.cjs +31 -3
- 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 +31 -3
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +52 -5
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.d.cts +56 -3
- package/dist/nest/index.d.ts +56 -3
- package/dist/nest/index.js +48 -4
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-
|
|
2
|
-
export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-
|
|
1
|
+
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-CjIDPMsV.cjs';
|
|
2
|
+
export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-CjIDPMsV.cjs';
|
|
3
3
|
import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
|
|
4
4
|
|
|
5
5
|
declare function defineConfig(c: UserConfig): UserConfig;
|
|
@@ -373,6 +373,6 @@ interface FastDiscoveryOptions {
|
|
|
373
373
|
}
|
|
374
374
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
375
375
|
|
|
376
|
-
declare const VERSION = "0.
|
|
376
|
+
declare const VERSION = "0.15.0";
|
|
377
377
|
|
|
378
378
|
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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-
|
|
2
|
-
export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-
|
|
1
|
+
import { U as UserConfig, R as ResolvedConfig, a as RouteDescriptor, S as SchemaNode, b as RenderContext, c as SchemaModule, d as RenderedModule, e as ResolvedFormsConfig, V as ValidationAdapter, C as CodegenExtension, E as ExtensionContext, f as SerializationMode } from './index-CjIDPMsV.js';
|
|
2
|
+
export { A as AdapterUsage, g as ContractDescriptor, h as ContractSource, i as ControllerRef, N as NumberCheck, j as ScopeConfig, k as StringCheck, T as TypeRef, l as ValidationOption, r as resolveAdapter } from './index-CjIDPMsV.js';
|
|
3
3
|
import { ClassDeclaration, SourceFile, Project } from 'ts-morph';
|
|
4
4
|
|
|
5
5
|
declare function defineConfig(c: UserConfig): UserConfig;
|
|
@@ -373,6 +373,6 @@ interface FastDiscoveryOptions {
|
|
|
373
373
|
}
|
|
374
374
|
declare function discoverContractsFast(opts: FastDiscoveryOptions): Promise<RouteDescriptor[]>;
|
|
375
375
|
|
|
376
|
-
declare const VERSION = "0.
|
|
376
|
+
declare const VERSION = "0.15.0";
|
|
377
377
|
|
|
378
378
|
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
|
@@ -746,6 +746,9 @@ function buildErrorType(c) {
|
|
|
746
746
|
}
|
|
747
747
|
return c.contractSource.error ?? "unknown";
|
|
748
748
|
}
|
|
749
|
+
function filterFieldLiterals(fields) {
|
|
750
|
+
return fields?.length ? fields.map((f) => JSON.stringify(f)) : [];
|
|
751
|
+
}
|
|
749
752
|
function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
750
753
|
const pad = " ".repeat(indent);
|
|
751
754
|
const lines = [];
|
|
@@ -772,7 +775,8 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
|
772
775
|
const params = buildParamsType(c.params);
|
|
773
776
|
const safeMethod = JSON.stringify(method);
|
|
774
777
|
const safeUrl = JSON.stringify(c.path);
|
|
775
|
-
const
|
|
778
|
+
const filterLiterals = filterFieldLiterals(c.contractSource.filterFields);
|
|
779
|
+
const filterFields = filterLiterals.length ? filterLiterals.join(" | ") : "never";
|
|
776
780
|
const stream = c.contractSource.stream ? "true" : "false";
|
|
777
781
|
const binary = c.contractSource.binaryResponse ? "true" : "false";
|
|
778
782
|
lines.push(
|
|
@@ -812,6 +816,7 @@ function buildRequestModel(c) {
|
|
|
812
816
|
const TA = buildRouterTypeAccess(c.name);
|
|
813
817
|
const withParams = hasPathParams(c.params);
|
|
814
818
|
const { isGet, isQuery, hasBody, hasQuery } = requestShape(c.route);
|
|
819
|
+
const filterLiterals = filterFieldLiterals(c.contractSource.filterFields);
|
|
815
820
|
const fields = [];
|
|
816
821
|
if (withParams) fields.push(`params: ${TA}['params']`);
|
|
817
822
|
if (hasQuery) fields.push(`query?: ${TA}['query']`);
|
|
@@ -841,7 +846,12 @@ function buildRequestModel(c) {
|
|
|
841
846
|
// (`[name]` rather than `[name, undefined]`) so the bare `.queryKey()` is a
|
|
842
847
|
// clean prefix that partial-matches every parametrized variant — making it
|
|
843
848
|
// directly usable for `invalidateQueries`.
|
|
844
|
-
queryKeyExpr: `(input === undefined ? [${flat}] as const : [${flat}, input] as const)
|
|
849
|
+
queryKeyExpr: `(input === undefined ? [${flat}] as const : [${flat}, input] as const)`,
|
|
850
|
+
// Runtime counterpart to the type-level `filterFields` union: the same
|
|
851
|
+
// discovered field list, emitted as a literal `[...] as const` so apps can
|
|
852
|
+
// validate a dynamic/user-supplied field string with `isFilterField(...)`
|
|
853
|
+
// instead of casting. Omitted for routes with no filter.
|
|
854
|
+
...filterLiterals.length ? { filterFieldsExpr: `[${filterLiterals.join(", ")}] as const` } : {}
|
|
845
855
|
};
|
|
846
856
|
}
|
|
847
857
|
function renderFetcherRequest(req, binaryResponse) {
|
|
@@ -876,9 +886,24 @@ function emitReqHelper() {
|
|
|
876
886
|
""
|
|
877
887
|
];
|
|
878
888
|
}
|
|
889
|
+
function emitFilterFieldGuard() {
|
|
890
|
+
return [
|
|
891
|
+
"/** Runtime guard: narrows `value` to one of the leaf's `filterFields` (a `readonly K[] as const`), so a dynamic field string can be passed to `.where()` without a cast. */",
|
|
892
|
+
"export function isFilterField<const K extends string>(",
|
|
893
|
+
" fields: readonly K[],",
|
|
894
|
+
" value: string,",
|
|
895
|
+
"): value is K {",
|
|
896
|
+
" return (fields as readonly string[]).includes(value);",
|
|
897
|
+
"}",
|
|
898
|
+
""
|
|
899
|
+
];
|
|
900
|
+
}
|
|
879
901
|
function renderLeaf(pad, objKey, req, requestExpr, members, streamExpr) {
|
|
880
902
|
const lines = [`${pad}${objKey}: (input?: ${req.inputType}) => ({`];
|
|
881
903
|
lines.push(`${pad} ...__req<${req.responseType}>(() => ${requestExpr}),`);
|
|
904
|
+
if (req.filterFieldsExpr) {
|
|
905
|
+
lines.push(`${pad} filterFields: ${req.filterFieldsExpr},`);
|
|
906
|
+
}
|
|
882
907
|
if (streamExpr) {
|
|
883
908
|
lines.push(`${pad} stream: () => ${streamExpr},`);
|
|
884
909
|
}
|
|
@@ -1150,6 +1175,9 @@ function buildApiFile(routes, outDir, opts = {}) {
|
|
|
1150
1175
|
lines.push("};");
|
|
1151
1176
|
lines.push("");
|
|
1152
1177
|
lines.push(...emitReqHelper());
|
|
1178
|
+
if (contracted.some((r) => r.contract?.contractSource.filterFields?.length)) {
|
|
1179
|
+
lines.push(...emitFilterFieldGuard());
|
|
1180
|
+
}
|
|
1153
1181
|
lines.push("export function createApi(fetcher: Fetcher) {");
|
|
1154
1182
|
lines.push(" return {");
|
|
1155
1183
|
lines.push(
|
|
@@ -4906,7 +4934,7 @@ function createChainModuleRenderer(opts) {
|
|
|
4906
4934
|
}
|
|
4907
4935
|
|
|
4908
4936
|
// src/index.ts
|
|
4909
|
-
var VERSION = "0.
|
|
4937
|
+
var VERSION = "0.15.0";
|
|
4910
4938
|
export {
|
|
4911
4939
|
CodegenError,
|
|
4912
4940
|
ConfigError,
|