zod-nest 0.12.0 → 1.0.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/README.md CHANGED
@@ -431,7 +431,7 @@ A compact, link-out index. Type signatures and detailed semantics live in the co
431
431
  - `ZodNestModule.forRoot(options?)`, `ZodNestModuleOptions`, `DEFAULT_REDACT_KEYS`, `DEFAULT_MAX_LOGGED_VALUE_BYTES`, `ZOD_NEST_OPTIONS`
432
432
 
433
433
  **Schema engine** — single-schema mode and extension points
434
- - `toOpenApi(schema, opts)`, `createRegistry()`, `defaultRegistry`, `ZodNestRegistry`, `Override`, `OverrideContext`, `ZodNestError`, `ZodNestUnrepresentableError`, `extend`, `getLineage`, `LineageEntry`
434
+ - `toOpenApi(schema, opts)`, `createRegistry()`, `defaultRegistry`, `ZodNestRegistry`, `Override`, `OverrideContext`, `overrideJSONSchema(schema, fragment)`, `ZodNestError`, `ZodNestUnrepresentableError`, `extend`, `getLineage`, `LineageEntry`
435
435
 
436
436
  ## Documentation
437
437
 
@@ -450,16 +450,18 @@ A compact, link-out index. Type signatures and detailed semantics live in the co
450
450
 
451
451
  ## Compatibility matrix
452
452
 
453
- `zod-nest` declares broad peer-dep ranges in `package.json`: `zod >= 4.4.0`, `@nestjs/common >= 10`, `@nestjs/core >= 10`, `@nestjs/swagger >= 8`, `rxjs >= 7`, Node `>= 22`. CI validates those claims by running the full test suite against the cells below; a red cell is a real blocker.
453
+ `zod-nest` declares explicit min + max peer-dep ranges in `package.json`: `zod >=4.4.0 <5.0.0`, `@nestjs/common >=11.0.1 <12.0.0`, `@nestjs/core >=11.0.1 <12.0.0`, `@nestjs/swagger >=11.0.0 <12.0.0`, `rxjs >=7.1.0 <8.0.0`, `reflect-metadata >=0.2.0 <0.3.0`, Node `>=22`. CI validates those claims by running the full test suite against the cells below; a red cell is a real blocker. Upper bounds are deliberate — a new peer major has to land in a real PR with a `/check-upstream-updates` audit before consumers can install it against this library.
454
454
 
455
- | Cell | `zod` | `@nestjs/common` | `@nestjs/core` | `@nestjs/swagger` |
456
- |---|---|---|---|---|
457
- | `floor` | 4.4.0 | 10.0.0 | 10.0.0 | 8.0.0 |
458
- | `zod-latest` | latest | 10.0.0 | 10.0.0 | 8.0.0 |
459
- | `nest-latest` | 4.4.0 | latest | latest | latest |
460
- | `all-latest` | latest | latest | latest | latest |
455
+ | Cell | `zod` | `@nestjs/common` | `@nestjs/core` | `@nestjs/swagger` | `rxjs` | `reflect-metadata` |
456
+ |---|---|---|---|---|---|---|
457
+ | `floor` | 4.4.0 | 11.0.1 | 11.0.1 | 11.0.0 | 7.1.0 | 0.2.0 |
458
+ | `zod-latest` | latest | 11.0.1 | 11.0.1 | 11.0.0 | 7.1.0 | 0.2.0 |
459
+ | `nest-latest` | 4.4.0 | latest | latest | latest | 7.1.0 | 0.2.0 |
460
+ | `rxjs-latest` | 4.4.0 | 11.0.1 | 11.0.1 | 11.0.0 | latest | 0.2.0 |
461
+ | `reflect-metadata-latest` | 4.4.0 | 11.0.1 | 11.0.1 | 11.0.0 | 7.1.0 | latest |
462
+ | `all-latest` | latest | latest | latest | latest | latest | latest |
461
463
 
462
- 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 + rxjs are not currently matrixed (Node floor `22` is enforced by `engines`; rxjs has been stable enough not to need cells yet).
464
+ 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`.
463
465
 
464
466
  ## Migration from `nestjs-zod`
465
467
 
package/dist/index.d.mts CHANGED
@@ -79,6 +79,28 @@ declare const extend: <P extends z.ZodObject, S extends z.ZodObject>(parent: P,
79
79
  */
80
80
  declare const getLineage: (schema: z.ZodType) => LineageEntry | undefined;
81
81
 
82
+ /**
83
+ * Register a fixed JSON Schema fragment for a specific Zod schema instance.
84
+ *
85
+ * Designed for shapes JSON Schema can't model directly — `z.custom<T>()` and
86
+ * `z.instanceof(...)` (e.g. multipart `File` fields) — which Zod emits as `{}`,
87
+ * tripping `ZodNestUnrepresentableError` in strict mode. After registration
88
+ * the engine writes the supplied fragment in-place wherever that schema
89
+ * instance is emitted (single-schema `toOpenApi`, bulk emission, nested
90
+ * inside `z.object({...})`, anywhere).
91
+ *
92
+ * Idempotent: subsequent calls for the same schema overwrite the prior
93
+ * registration (last-write-wins).
94
+ *
95
+ * @example
96
+ * const FileSchema = z.instanceof(File);
97
+ * overrideJSONSchema(FileSchema, { type: 'string', format: 'binary' });
98
+ *
99
+ * class UploadDto extends createZodDto(z.object({ file: FileSchema })) {}
100
+ * // OpenAPI doc emits `properties.file = { type: 'string', format: 'binary' }`
101
+ */
102
+ declare const overrideJSONSchema: (schema: z.ZodType, jsonSchema: SchemaObject) => void;
103
+
82
104
  interface ToOpenApiOptions {
83
105
  io: 'input' | 'output';
84
106
  registry: ZodNestRegistry;
@@ -527,4 +549,4 @@ declare class ZodNestDocumentError extends ZodNestError {
527
549
  constructor(code: ZodNestDocumentErrorCode, message: string, details?: Record<string, unknown>);
528
550
  }
529
551
 
530
- export { type ApplyZodNestOptions, COMPONENTS_SCHEMAS_PREFIX, type CreateSerializationException, type CreateValidationException, type CreateZodDtoOptions, DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, type Io, type LineageEntry, type NormalizedZodNestOptions, type Override, type OverrideContext, type ResponseStatusInput, type ResponseStatusWildcard, type ResponseVariant, type ResponseVariantKind, type SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, type ZodDto, type ZodDtoMarker, ZodNestDocumentError, type ZodNestDocumentErrorCode, ZodNestError, ZodNestModule, type ZodNestModuleOptions, type ZodNestRegistry, ZodNestUnrepresentableError, ZodResponse, type ZodResponseDescription, type ZodResponseOptions, type ZodResponseType, ZodSerializationException, ZodSerializerInterceptor, ZodValidationException, ZodValidationPipe, type ZodValidationPipeArg, type ZodValidationPipeOptions, applyZodNest, createRegistry, createZodDto, defaultRegistry, defaultStatusFor, extend, getLineage, isZodDto, isZodDtoMarker, makeZodDtoMarker, resolveEffectiveStatus, toOpenApi };
552
+ export { type ApplyZodNestOptions, COMPONENTS_SCHEMAS_PREFIX, type CreateSerializationException, type CreateValidationException, type CreateZodDtoOptions, DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, type Io, type LineageEntry, type NormalizedZodNestOptions, type Override, type OverrideContext, type ResponseStatusInput, type ResponseStatusWildcard, type ResponseVariant, type ResponseVariantKind, type SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, type ZodDto, type ZodDtoMarker, ZodNestDocumentError, type ZodNestDocumentErrorCode, ZodNestError, ZodNestModule, type ZodNestModuleOptions, type ZodNestRegistry, ZodNestUnrepresentableError, ZodResponse, type ZodResponseDescription, type ZodResponseOptions, type ZodResponseType, ZodSerializationException, ZodSerializerInterceptor, ZodValidationException, ZodValidationPipe, type ZodValidationPipeArg, type ZodValidationPipeOptions, applyZodNest, createRegistry, createZodDto, defaultRegistry, defaultStatusFor, extend, getLineage, isZodDto, isZodDtoMarker, makeZodDtoMarker, overrideJSONSchema, resolveEffectiveStatus, toOpenApi };
package/dist/index.d.ts CHANGED
@@ -79,6 +79,28 @@ declare const extend: <P extends z.ZodObject, S extends z.ZodObject>(parent: P,
79
79
  */
80
80
  declare const getLineage: (schema: z.ZodType) => LineageEntry | undefined;
81
81
 
82
+ /**
83
+ * Register a fixed JSON Schema fragment for a specific Zod schema instance.
84
+ *
85
+ * Designed for shapes JSON Schema can't model directly — `z.custom<T>()` and
86
+ * `z.instanceof(...)` (e.g. multipart `File` fields) — which Zod emits as `{}`,
87
+ * tripping `ZodNestUnrepresentableError` in strict mode. After registration
88
+ * the engine writes the supplied fragment in-place wherever that schema
89
+ * instance is emitted (single-schema `toOpenApi`, bulk emission, nested
90
+ * inside `z.object({...})`, anywhere).
91
+ *
92
+ * Idempotent: subsequent calls for the same schema overwrite the prior
93
+ * registration (last-write-wins).
94
+ *
95
+ * @example
96
+ * const FileSchema = z.instanceof(File);
97
+ * overrideJSONSchema(FileSchema, { type: 'string', format: 'binary' });
98
+ *
99
+ * class UploadDto extends createZodDto(z.object({ file: FileSchema })) {}
100
+ * // OpenAPI doc emits `properties.file = { type: 'string', format: 'binary' }`
101
+ */
102
+ declare const overrideJSONSchema: (schema: z.ZodType, jsonSchema: SchemaObject) => void;
103
+
82
104
  interface ToOpenApiOptions {
83
105
  io: 'input' | 'output';
84
106
  registry: ZodNestRegistry;
@@ -527,4 +549,4 @@ declare class ZodNestDocumentError extends ZodNestError {
527
549
  constructor(code: ZodNestDocumentErrorCode, message: string, details?: Record<string, unknown>);
528
550
  }
529
551
 
530
- export { type ApplyZodNestOptions, COMPONENTS_SCHEMAS_PREFIX, type CreateSerializationException, type CreateValidationException, type CreateZodDtoOptions, DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, type Io, type LineageEntry, type NormalizedZodNestOptions, type Override, type OverrideContext, type ResponseStatusInput, type ResponseStatusWildcard, type ResponseVariant, type ResponseVariantKind, type SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, type ZodDto, type ZodDtoMarker, ZodNestDocumentError, type ZodNestDocumentErrorCode, ZodNestError, ZodNestModule, type ZodNestModuleOptions, type ZodNestRegistry, ZodNestUnrepresentableError, ZodResponse, type ZodResponseDescription, type ZodResponseOptions, type ZodResponseType, ZodSerializationException, ZodSerializerInterceptor, ZodValidationException, ZodValidationPipe, type ZodValidationPipeArg, type ZodValidationPipeOptions, applyZodNest, createRegistry, createZodDto, defaultRegistry, defaultStatusFor, extend, getLineage, isZodDto, isZodDtoMarker, makeZodDtoMarker, resolveEffectiveStatus, toOpenApi };
552
+ export { type ApplyZodNestOptions, COMPONENTS_SCHEMAS_PREFIX, type CreateSerializationException, type CreateValidationException, type CreateZodDtoOptions, DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, type Io, type LineageEntry, type NormalizedZodNestOptions, type Override, type OverrideContext, type ResponseStatusInput, type ResponseStatusWildcard, type ResponseVariant, type ResponseVariantKind, type SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, type ZodDto, type ZodDtoMarker, ZodNestDocumentError, type ZodNestDocumentErrorCode, ZodNestError, ZodNestModule, type ZodNestModuleOptions, type ZodNestRegistry, ZodNestUnrepresentableError, ZodResponse, type ZodResponseDescription, type ZodResponseOptions, type ZodResponseType, ZodSerializationException, ZodSerializerInterceptor, ZodValidationException, ZodValidationPipe, type ZodValidationPipeArg, type ZodValidationPipeOptions, applyZodNest, createRegistry, createZodDto, defaultRegistry, defaultStatusFor, extend, getLineage, isZodDto, isZodDtoMarker, makeZodDtoMarker, overrideJSONSchema, resolveEffectiveStatus, toOpenApi };
package/dist/index.js CHANGED
@@ -104,6 +104,22 @@ var createCompositionOverride = /* @__PURE__ */ __name((opts) => {
104
104
  };
105
105
  }, "createCompositionOverride");
106
106
 
107
+ // src/schema/custom-override.ts
108
+ var customOverrideMap = /* @__PURE__ */ new WeakMap();
109
+ var overrideJSONSchema = /* @__PURE__ */ __name((schema, jsonSchema) => {
110
+ customOverrideMap.set(schema, jsonSchema);
111
+ }, "overrideJSONSchema");
112
+ var customOverride = /* @__PURE__ */ __name(({ zodSchema, jsonSchema }) => {
113
+ const fragment = customOverrideMap.get(zodSchema);
114
+ if (fragment === void 0) {
115
+ return;
116
+ }
117
+ for (const key of Object.keys(jsonSchema)) {
118
+ Reflect.deleteProperty(jsonSchema, key);
119
+ }
120
+ Object.assign(jsonSchema, fragment);
121
+ }, "customOverride");
122
+
107
123
  // src/schema/errors.ts
108
124
  var ZodNestError = class extends Error {
109
125
  static {
@@ -232,7 +248,7 @@ var buildToJsonSchemaOptions = /* @__PURE__ */ __name((params) => {
232
248
  buildRef: params.uri ?? DEFAULT_BUILD_REF,
233
249
  registry: params.registry
234
250
  });
235
- const merged = combine(primitiveOverride, compositionOverride, params.override);
251
+ const merged = combine(primitiveOverride, compositionOverride, customOverride, params.override);
236
252
  const unrepresentableHits = [];
237
253
  const wrapped = /* @__PURE__ */ __name((ctx) => {
238
254
  merged(ctx);
@@ -1482,6 +1498,7 @@ exports.getLineage = getLineage;
1482
1498
  exports.isZodDto = isZodDto;
1483
1499
  exports.isZodDtoMarker = isZodDtoMarker;
1484
1500
  exports.makeZodDtoMarker = makeZodDtoMarker;
1501
+ exports.overrideJSONSchema = overrideJSONSchema;
1485
1502
  exports.resolveEffectiveStatus = resolveEffectiveStatus;
1486
1503
  exports.toOpenApi = toOpenApi;
1487
1504
  //# sourceMappingURL=index.js.map