zod-nest 3.0.0 → 3.0.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/README.md +2 -11
- package/dist/index.js +56 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +23 -20
package/README.md
CHANGED
|
@@ -245,20 +245,11 @@ The id is what appears as the `components.schemas` key in the OpenAPI document a
|
|
|
245
245
|
|
|
246
246
|
```ts
|
|
247
247
|
// Preferred — on the schema, via Zod's metadata
|
|
248
|
-
const userSchema = z
|
|
249
|
-
.object({
|
|
250
|
-
/* ... */
|
|
251
|
-
})
|
|
252
|
-
.meta({ id: 'User' });
|
|
248
|
+
const userSchema = z.object({/* ... */}).meta({ id: 'User' });
|
|
253
249
|
class UserDto extends createZodDto(userSchema) {}
|
|
254
250
|
|
|
255
251
|
// Also valid — passed through createZodDto's options
|
|
256
|
-
class UserDto extends createZodDto(
|
|
257
|
-
z.object({
|
|
258
|
-
/* ... */
|
|
259
|
-
}),
|
|
260
|
-
{ id: 'User' },
|
|
261
|
-
) {}
|
|
252
|
+
class UserDto extends createZodDto(z.object({/* ... */}), { id: 'User' }) {}
|
|
262
253
|
```
|
|
263
254
|
|
|
264
255
|
Both produce the same OpenAPI output. `.meta({ id })` is preferred when the schema is hoisted into its own `const`, because the id stays with the schema — composition (`extend(parent, ...)`), shared input/output via `.meta({ id })` on the same schema reference, and any non-DTO use of the schema all pick up the same id without an extra hop through `createZodDto`'s options. Use the `createZodDto(schema, { id })` form when you don't own the schema (e.g. it comes from a third-party module) or when defining a small DTO with an inline schema, where chaining `.meta()` on the inline expression hurts readability.
|
package/dist/index.js
CHANGED
|
@@ -41,6 +41,18 @@ var readId = /* @__PURE__ */ __name((schema) => {
|
|
|
41
41
|
const id = meta.id;
|
|
42
42
|
return typeof id === "string" ? id : void 0;
|
|
43
43
|
}, "readId");
|
|
44
|
+
var resolveLazyTarget = /* @__PURE__ */ __name((getter) => {
|
|
45
|
+
try {
|
|
46
|
+
return [
|
|
47
|
+
getter()
|
|
48
|
+
];
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (error instanceof ReferenceError) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}, "resolveLazyTarget");
|
|
44
56
|
var collectChildren = /* @__PURE__ */ __name((schema) => {
|
|
45
57
|
const def = schema._zod.def;
|
|
46
58
|
if (def.type === "object") {
|
|
@@ -95,9 +107,7 @@ var collectChildren = /* @__PURE__ */ __name((schema) => {
|
|
|
95
107
|
];
|
|
96
108
|
}
|
|
97
109
|
if (def.type === "lazy") {
|
|
98
|
-
return
|
|
99
|
-
def.getter()
|
|
100
|
-
];
|
|
110
|
+
return resolveLazyTarget(() => def.getter());
|
|
101
111
|
}
|
|
102
112
|
if (INNER_TYPE_WRAPPERS.has(def.type)) {
|
|
103
113
|
return [
|
|
@@ -140,6 +150,7 @@ var createRegistry = /* @__PURE__ */ __name(() => {
|
|
|
140
150
|
const seen = /* @__PURE__ */ new Map();
|
|
141
151
|
const forceExposed = /* @__PURE__ */ new Set();
|
|
142
152
|
const anonymous = /* @__PURE__ */ new Set();
|
|
153
|
+
const pendingRoots = [];
|
|
143
154
|
const recordOnce = /* @__PURE__ */ __name((schema, id) => {
|
|
144
155
|
let set = seen.get(id);
|
|
145
156
|
if (set === void 0) {
|
|
@@ -152,6 +163,13 @@ var createRegistry = /* @__PURE__ */ __name(() => {
|
|
|
152
163
|
set.add(schema);
|
|
153
164
|
return true;
|
|
154
165
|
}, "recordOnce");
|
|
166
|
+
const flushPendingDiscovery = /* @__PURE__ */ __name(() => {
|
|
167
|
+
for (const root of pendingRoots.splice(0)) {
|
|
168
|
+
for (const [child, childId] of discoverDependents(root)) {
|
|
169
|
+
recordOnce(child, childId);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}, "flushPendingDiscovery");
|
|
155
173
|
return {
|
|
156
174
|
zodRegistry: zod.z.globalRegistry,
|
|
157
175
|
register: /* @__PURE__ */ __name((schema, id, flags) => {
|
|
@@ -177,15 +195,15 @@ var createRegistry = /* @__PURE__ */ __name(() => {
|
|
|
177
195
|
if (!recordOnce(schema, id)) {
|
|
178
196
|
return;
|
|
179
197
|
}
|
|
180
|
-
|
|
181
|
-
recordOnce(child, childId);
|
|
182
|
-
}
|
|
198
|
+
pendingRoots.push(schema);
|
|
183
199
|
}, "register"),
|
|
184
200
|
hasCollision: /* @__PURE__ */ __name((id) => {
|
|
201
|
+
flushPendingDiscovery();
|
|
185
202
|
const set = seen.get(id);
|
|
186
203
|
return set !== void 0 && set.size > 1;
|
|
187
204
|
}, "hasCollision"),
|
|
188
205
|
getCollisions: /* @__PURE__ */ __name(() => {
|
|
206
|
+
flushPendingDiscovery();
|
|
189
207
|
const out = /* @__PURE__ */ new Map();
|
|
190
208
|
for (const [id, set] of seen) {
|
|
191
209
|
if (set.size <= 1) {
|
|
@@ -195,9 +213,12 @@ var createRegistry = /* @__PURE__ */ __name(() => {
|
|
|
195
213
|
}
|
|
196
214
|
return out;
|
|
197
215
|
}, "getCollisions"),
|
|
198
|
-
ids: /* @__PURE__ */ __name(() =>
|
|
199
|
-
|
|
200
|
-
|
|
216
|
+
ids: /* @__PURE__ */ __name(() => {
|
|
217
|
+
flushPendingDiscovery();
|
|
218
|
+
return [
|
|
219
|
+
...seen.keys()
|
|
220
|
+
];
|
|
221
|
+
}, "ids"),
|
|
201
222
|
forceExposedIds: /* @__PURE__ */ __name(() => [
|
|
202
223
|
...forceExposed
|
|
203
224
|
], "forceExposedIds"),
|
|
@@ -1063,13 +1084,22 @@ var normalizeZodNestOptions = /* @__PURE__ */ __name((opts) => {
|
|
|
1063
1084
|
// src/pipes/validation.pipe.ts
|
|
1064
1085
|
function _ts_decorate(decorators, target, key, desc) {
|
|
1065
1086
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1066
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1067
|
-
|
|
1087
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1088
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1089
|
+
} else {
|
|
1090
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
1091
|
+
if (d = decorators[i]) {
|
|
1092
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1068
1096
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1069
1097
|
}
|
|
1070
1098
|
__name(_ts_decorate, "_ts_decorate");
|
|
1071
|
-
function _ts_metadata(
|
|
1072
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1099
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
1100
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1101
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
1102
|
+
}
|
|
1073
1103
|
}
|
|
1074
1104
|
__name(_ts_metadata, "_ts_metadata");
|
|
1075
1105
|
function _ts_param(paramIndex, decorator) {
|
|
@@ -1728,13 +1758,22 @@ var ZodCookies = /* @__PURE__ */ __name((schema, options) => {
|
|
|
1728
1758
|
}, "ZodCookies");
|
|
1729
1759
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
1730
1760
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1731
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1732
|
-
|
|
1761
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
1762
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1763
|
+
} else {
|
|
1764
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
1765
|
+
if (d = decorators[i]) {
|
|
1766
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1733
1770
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1734
1771
|
}
|
|
1735
1772
|
__name(_ts_decorate2, "_ts_decorate");
|
|
1736
|
-
function _ts_metadata2(
|
|
1737
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1773
|
+
function _ts_metadata2(metadataKey, metadataValue) {
|
|
1774
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
1775
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
1776
|
+
}
|
|
1738
1777
|
}
|
|
1739
1778
|
__name(_ts_metadata2, "_ts_metadata");
|
|
1740
1779
|
function _ts_param2(paramIndex, decorator) {
|