zod-nest 1.1.0 → 1.1.1

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/dist/index.js CHANGED
@@ -120,6 +120,7 @@ var overrideJSONSchema = /* @__PURE__ */ __name((schema, arg) => {
120
120
  output: arg
121
121
  });
122
122
  }, "overrideJSONSchema");
123
+ var peekRegistration = /* @__PURE__ */ __name((schema) => customOverrideMap.get(schema), "peekRegistration");
123
124
  var createCustomOverride = /* @__PURE__ */ __name((io) => {
124
125
  return ({ zodSchema, jsonSchema }) => {
125
126
  const record = customOverrideMap.get(zodSchema);
@@ -259,6 +260,18 @@ var isStrictlyUnrepresentable = /* @__PURE__ */ __name((jsonSchema, zodSchema) =
259
260
  }
260
261
  return Object.keys(jsonSchema).length === 0;
261
262
  }, "isStrictlyUnrepresentable");
263
+ var markPipeCoverage = /* @__PURE__ */ __name((schema, io, covered) => {
264
+ const def = schema._zod.def;
265
+ if (def.type !== "pipe" || def.in === void 0 || def.out === void 0) {
266
+ return;
267
+ }
268
+ const target = io === "output" ? def.out : def.in._zod.traits.has("$ZodTransform") ? def.out : def.in;
269
+ if (covered.has(target)) {
270
+ return;
271
+ }
272
+ covered.add(target);
273
+ markPipeCoverage(target, io, covered);
274
+ }, "markPipeCoverage");
262
275
  var buildToJsonSchemaOptions = /* @__PURE__ */ __name((params) => {
263
276
  const strict = params.strict ?? true;
264
277
  const compositionOverride = createCompositionOverride({
@@ -268,8 +281,15 @@ var buildToJsonSchemaOptions = /* @__PURE__ */ __name((params) => {
268
281
  const customOverride = createCustomOverride(params.io);
269
282
  const merged = combine(primitiveOverride, compositionOverride, customOverride, params.override);
270
283
  const unrepresentableHits = [];
284
+ const coveredByPipe = /* @__PURE__ */ new WeakSet();
271
285
  const wrapped = /* @__PURE__ */ __name((ctx) => {
272
286
  merged(ctx);
287
+ if (ctx.zodSchema._zod.def.type === "pipe") {
288
+ const record = peekRegistration(ctx.zodSchema);
289
+ if (record !== void 0 && record[params.io] !== void 0) {
290
+ markPipeCoverage(ctx.zodSchema, params.io, coveredByPipe);
291
+ }
292
+ }
273
293
  if (!strict || !isStrictlyUnrepresentable(ctx.jsonSchema, ctx.zodSchema)) {
274
294
  return;
275
295
  }
@@ -277,7 +297,8 @@ var buildToJsonSchemaOptions = /* @__PURE__ */ __name((params) => {
277
297
  path: [
278
298
  ...ctx.path
279
299
  ],
280
- zodType: ctx.zodSchema._zod.def.type
300
+ zodType: ctx.zodSchema._zod.def.type,
301
+ zodSchema: ctx.zodSchema
281
302
  });
282
303
  }, "wrapped");
283
304
  const options = {
@@ -295,7 +316,7 @@ var buildToJsonSchemaOptions = /* @__PURE__ */ __name((params) => {
295
316
  return {
296
317
  options,
297
318
  consumeUnrepresentable: /* @__PURE__ */ __name(() => {
298
- const firstHit = unrepresentableHits[0];
319
+ const firstHit = unrepresentableHits.find((hit) => !coveredByPipe.has(hit.zodSchema));
299
320
  if (firstHit !== void 0) {
300
321
  throw new ZodNestUnrepresentableError(firstHit.path, firstHit.zodType);
301
322
  }