@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/nest/index.cjs
CHANGED
|
@@ -42,7 +42,10 @@ __export(nest_exports, {
|
|
|
42
42
|
CODEGEN_MODULE_OPTIONS: () => CODEGEN_MODULE_OPTIONS,
|
|
43
43
|
NestjsCodegenModule: () => NestjsCodegenModule,
|
|
44
44
|
NestjsCodegenService: () => NestjsCodegenService,
|
|
45
|
-
|
|
45
|
+
QueryList: () => QueryList,
|
|
46
|
+
resolveQueryList: () => resolveQueryList,
|
|
47
|
+
shouldRun: () => shouldRun,
|
|
48
|
+
toStringList: () => toStringList
|
|
46
49
|
});
|
|
47
50
|
module.exports = __toCommonJS(nest_exports);
|
|
48
51
|
|
|
@@ -738,6 +741,9 @@ function buildErrorType(c) {
|
|
|
738
741
|
}
|
|
739
742
|
return c.contractSource.error ?? "unknown";
|
|
740
743
|
}
|
|
744
|
+
function filterFieldLiterals(fields) {
|
|
745
|
+
return fields?.length ? fields.map((f) => JSON.stringify(f)) : [];
|
|
746
|
+
}
|
|
741
747
|
function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
742
748
|
const pad = " ".repeat(indent);
|
|
743
749
|
const lines = [];
|
|
@@ -764,7 +770,8 @@ function emitRouterTypeBlock(tree, indent, outDir, serialization) {
|
|
|
764
770
|
const params = buildParamsType(c.params);
|
|
765
771
|
const safeMethod = JSON.stringify(method);
|
|
766
772
|
const safeUrl = JSON.stringify(c.path);
|
|
767
|
-
const
|
|
773
|
+
const filterLiterals = filterFieldLiterals(c.contractSource.filterFields);
|
|
774
|
+
const filterFields = filterLiterals.length ? filterLiterals.join(" | ") : "never";
|
|
768
775
|
const stream = c.contractSource.stream ? "true" : "false";
|
|
769
776
|
const binary = c.contractSource.binaryResponse ? "true" : "false";
|
|
770
777
|
lines.push(
|
|
@@ -804,6 +811,7 @@ function buildRequestModel(c) {
|
|
|
804
811
|
const TA = buildRouterTypeAccess(c.name);
|
|
805
812
|
const withParams = hasPathParams(c.params);
|
|
806
813
|
const { isGet, isQuery, hasBody, hasQuery } = requestShape(c.route);
|
|
814
|
+
const filterLiterals = filterFieldLiterals(c.contractSource.filterFields);
|
|
807
815
|
const fields = [];
|
|
808
816
|
if (withParams) fields.push(`params: ${TA}['params']`);
|
|
809
817
|
if (hasQuery) fields.push(`query?: ${TA}['query']`);
|
|
@@ -833,7 +841,12 @@ function buildRequestModel(c) {
|
|
|
833
841
|
// (`[name]` rather than `[name, undefined]`) so the bare `.queryKey()` is a
|
|
834
842
|
// clean prefix that partial-matches every parametrized variant — making it
|
|
835
843
|
// directly usable for `invalidateQueries`.
|
|
836
|
-
queryKeyExpr: `(input === undefined ? [${flat}] as const : [${flat}, input] as const)
|
|
844
|
+
queryKeyExpr: `(input === undefined ? [${flat}] as const : [${flat}, input] as const)`,
|
|
845
|
+
// Runtime counterpart to the type-level `filterFields` union: the same
|
|
846
|
+
// discovered field list, emitted as a literal `[...] as const` so apps can
|
|
847
|
+
// validate a dynamic/user-supplied field string with `isFilterField(...)`
|
|
848
|
+
// instead of casting. Omitted for routes with no filter.
|
|
849
|
+
...filterLiterals.length ? { filterFieldsExpr: `[${filterLiterals.join(", ")}] as const` } : {}
|
|
837
850
|
};
|
|
838
851
|
}
|
|
839
852
|
function renderFetcherRequest(req, binaryResponse) {
|
|
@@ -868,9 +881,24 @@ function emitReqHelper() {
|
|
|
868
881
|
""
|
|
869
882
|
];
|
|
870
883
|
}
|
|
884
|
+
function emitFilterFieldGuard() {
|
|
885
|
+
return [
|
|
886
|
+
"/** 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. */",
|
|
887
|
+
"export function isFilterField<const K extends string>(",
|
|
888
|
+
" fields: readonly K[],",
|
|
889
|
+
" value: string,",
|
|
890
|
+
"): value is K {",
|
|
891
|
+
" return (fields as readonly string[]).includes(value);",
|
|
892
|
+
"}",
|
|
893
|
+
""
|
|
894
|
+
];
|
|
895
|
+
}
|
|
871
896
|
function renderLeaf(pad, objKey, req, requestExpr, members, streamExpr) {
|
|
872
897
|
const lines = [`${pad}${objKey}: (input?: ${req.inputType}) => ({`];
|
|
873
898
|
lines.push(`${pad} ...__req<${req.responseType}>(() => ${requestExpr}),`);
|
|
899
|
+
if (req.filterFieldsExpr) {
|
|
900
|
+
lines.push(`${pad} filterFields: ${req.filterFieldsExpr},`);
|
|
901
|
+
}
|
|
874
902
|
if (streamExpr) {
|
|
875
903
|
lines.push(`${pad} stream: () => ${streamExpr},`);
|
|
876
904
|
}
|
|
@@ -1142,6 +1170,9 @@ function buildApiFile(routes, outDir, opts = {}) {
|
|
|
1142
1170
|
lines.push("};");
|
|
1143
1171
|
lines.push("");
|
|
1144
1172
|
lines.push(...emitReqHelper());
|
|
1173
|
+
if (contracted.some((r) => r.contract?.contractSource.filterFields?.length)) {
|
|
1174
|
+
lines.push(...emitFilterFieldGuard());
|
|
1175
|
+
}
|
|
1145
1176
|
lines.push("export function createApi(fetcher: Fetcher) {");
|
|
1146
1177
|
lines.push(" return {");
|
|
1147
1178
|
lines.push(
|
|
@@ -4643,7 +4674,7 @@ async function watch(config, onChange, options = {}) {
|
|
|
4643
4674
|
}
|
|
4644
4675
|
|
|
4645
4676
|
// src/index.ts
|
|
4646
|
-
var VERSION = "0.
|
|
4677
|
+
var VERSION = "0.15.0";
|
|
4647
4678
|
|
|
4648
4679
|
// src/generate-manifest.ts
|
|
4649
4680
|
var MANIFEST_FILE = ".codegen-manifest.json";
|
|
@@ -4843,11 +4874,27 @@ var NestjsCodegenModule = class {
|
|
|
4843
4874
|
NestjsCodegenModule = __decorateClass([
|
|
4844
4875
|
(0, import_common.Module)({})
|
|
4845
4876
|
], NestjsCodegenModule);
|
|
4877
|
+
|
|
4878
|
+
// src/nest/query-list.ts
|
|
4879
|
+
var import_common2 = require("@nestjs/common");
|
|
4880
|
+
function toStringList(raw) {
|
|
4881
|
+
if (raw === void 0 || raw === null) return [];
|
|
4882
|
+
const arr = Array.isArray(raw) ? raw : String(raw).split(",");
|
|
4883
|
+
return arr.map((entry) => String(entry).trim()).filter((entry) => entry.length > 0);
|
|
4884
|
+
}
|
|
4885
|
+
function resolveQueryList(key, ctx) {
|
|
4886
|
+
const request = ctx.switchToHttp().getRequest();
|
|
4887
|
+
return toStringList(key ? request.query?.[key] : void 0);
|
|
4888
|
+
}
|
|
4889
|
+
var QueryList = (0, import_common2.createParamDecorator)(resolveQueryList);
|
|
4846
4890
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4847
4891
|
0 && (module.exports = {
|
|
4848
4892
|
CODEGEN_MODULE_OPTIONS,
|
|
4849
4893
|
NestjsCodegenModule,
|
|
4850
4894
|
NestjsCodegenService,
|
|
4851
|
-
|
|
4895
|
+
QueryList,
|
|
4896
|
+
resolveQueryList,
|
|
4897
|
+
shouldRun,
|
|
4898
|
+
toStringList
|
|
4852
4899
|
});
|
|
4853
4900
|
//# sourceMappingURL=index.cjs.map
|