zod-nest 2.1.2 → 2.1.3

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 CHANGED
@@ -531,11 +531,14 @@ See [`docs/recipes/custom-openapi-overrides.md`](docs/recipes/custom-openapi-ove
531
531
  | ------------------------- | ------ | ---------------- | -------------- | ----------------- | ------ | ------------------ |
532
532
  | `floor` | 4.4.0 | 11.0.1 | 11.0.1 | 11.0.0 | 7.6.0 | 0.2.0 |
533
533
  | `zod-latest` | latest | 11.0.1 | 11.0.1 | 11.0.0 | 7.6.0 | 0.2.0 |
534
+ | `zod-4.5` | 4.5.4 | 11.0.1 | 11.0.1 | 11.0.0 | 7.6.0 | 0.2.0 |
534
535
  | `nest-latest` | 4.4.0 | latest | latest | latest | 7.6.0 | 0.2.0 |
535
536
  | `rxjs-latest` | 4.4.0 | 11.0.1 | 11.0.1 | 11.0.0 | latest | 0.2.0 |
536
537
  | `reflect-metadata-latest` | 4.4.0 | 11.0.1 | 11.0.1 | 11.0.0 | 7.6.0 | latest |
537
538
  | `all-latest` | latest | latest | latest | latest | latest | latest |
538
539
 
540
+ One emission difference is visible across the supported `zod` range: from 4.5, a union of primitives — including `.nullable()` — emits `{ "type": ["string", "null"] }` where 4.4 emitted `{ "anyOf": [{ "type": "string" }, { "type": "null" }] }`. Both are valid OpenAPI 3.1 and validate identically; only the spelling changes. Everything else — `$ref` layout, composition `allOf`, input/output siblings, `paths` — is byte-identical across 4.4 and 4.5.
541
+
539
542
  Cell definitions live in [`.github/compat-matrix.json`](.github/compat-matrix.json). The CI workflow ([`.github/workflows/compat-matrix.yml`](.github/workflows/compat-matrix.yml)) runs on every push to `main` and weekly on Monday — when a cell fails, the workflow opens (or comments on) a GitHub issue labelled `compat-matrix-failure` so the regression is tracked outside the Actions UI. Editing the JSON is the formal way to extend or shrink supported ranges. Node is not matrixed — the `>=22` floor is enforced by `engines`.
540
543
 
541
544
  ## Migration from `nestjs-zod`
package/dist/index.js CHANGED
@@ -440,6 +440,60 @@ var rewriteRefs = /* @__PURE__ */ __name((node, selfRef) => {
440
440
  rewriteRefs(value, selfRef);
441
441
  }
442
442
  }, "rewriteRefs");
443
+ var refsIn = /* @__PURE__ */ __name(function* (node) {
444
+ if (Array.isArray(node)) {
445
+ for (const item of node) {
446
+ yield* refsIn(item);
447
+ }
448
+ return;
449
+ }
450
+ if (node === null || typeof node !== "object") {
451
+ return;
452
+ }
453
+ const obj = node;
454
+ if (typeof obj.$ref === "string") {
455
+ yield obj.$ref;
456
+ }
457
+ for (const value of Object.values(obj)) {
458
+ yield* refsIn(value);
459
+ }
460
+ }, "refsIn");
461
+ var rootDefId = /* @__PURE__ */ __name((raw) => {
462
+ const ref = raw.$ref;
463
+ if (typeof ref !== "string" || !ref.startsWith(DEFS_PREFIX)) {
464
+ return void 0;
465
+ }
466
+ return ref.slice(DEFS_PREFIX.length);
467
+ }, "rootDefId");
468
+ var isReferenced = /* @__PURE__ */ __name((defs, id) => {
469
+ const ownRef = `${DEFS_PREFIX}${id}`;
470
+ for (const ref of refsIn(defs)) {
471
+ if (ref === "#" || ref === ownRef) {
472
+ return true;
473
+ }
474
+ }
475
+ return false;
476
+ }, "isReferenced");
477
+ var liftRoot = /* @__PURE__ */ __name((raw, refs) => {
478
+ const id = rootDefId(raw);
479
+ if (id === void 0) {
480
+ return void 0;
481
+ }
482
+ const body = refs.get(id);
483
+ if (body === void 0 || isReferenced(raw.$defs, id)) {
484
+ return void 0;
485
+ }
486
+ refs.delete(id);
487
+ return body;
488
+ }, "liftRoot");
489
+ var stripEnvelope = /* @__PURE__ */ __name((raw) => {
490
+ const root = {
491
+ ...raw
492
+ };
493
+ delete root.$schema;
494
+ delete root.$defs;
495
+ return root;
496
+ }, "stripEnvelope");
443
497
  var postProcess = /* @__PURE__ */ __name((raw) => {
444
498
  const refs = /* @__PURE__ */ new Map();
445
499
  const rawDefs = raw.$defs;
@@ -448,11 +502,7 @@ var postProcess = /* @__PURE__ */ __name((raw) => {
448
502
  refs.set(id, body);
449
503
  }
450
504
  }
451
- const root = {
452
- ...raw
453
- };
454
- delete root.$schema;
455
- delete root.$defs;
505
+ const root = liftRoot(raw, refs) ?? stripEnvelope(raw);
456
506
  rewriteRefs(root, void 0);
457
507
  for (const [id, body] of refs) {
458
508
  rewriteRefs(body, `${COMPONENTS_SCHEMAS_PREFIX}${id}`);