@bram-dc/fastify-type-provider-zod 3.0.0 → 3.1.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
@@ -1,7 +1,7 @@
1
1
  # Fastify Type Provider Zod
2
2
 
3
- [![NPM Version](https://img.shields.io/npm/v/fastify-type-provider-zod.svg)](https://npmjs.org/package/fastify-type-provider-zod)
4
- [![NPM Downloads](https://img.shields.io/npm/dm/fastify-type-provider-zod.svg)](https://npmjs.org/package/fastify-type-provider-zod)
3
+ [![NPM Version](https://img.shields.io/npm/v/@bram-dc/fastify-type-provider-zod.svg)](https://www.npmjs.com/package/@bram-dc/fastify-type-provider-zod)
4
+ [![NPM Downloads](https://img.shields.io/npm/dm/@bram-dc/fastify-type-provider-zod.svg)](https://www.npmjs.com/package/@bram-dc/fastify-type-provider-zod)
5
5
  [![Build Status](https://github.com//bram-dc/fastify-type-provider-zod/workflows/CI/badge.svg)](https://github.com/bram-dc/fastify-type-provider-zod/actions)
6
6
 
7
7
  ## How to use?
package/dist/index.d.ts CHANGED
@@ -41,6 +41,13 @@ export declare const jsonSchemaTransform: ({ schema, url }: {
41
41
  url: string;
42
42
  };
43
43
  export declare const ZodValidatorCompiler: FastifySchemaCompiler<z.ZodAny>;
44
+ type ReplacerFunction = (this: any, key: string, value: any) => any;
45
+ type ZodSerializerCompilerOptions = {
46
+ replacer?: ReplacerFunction;
47
+ };
48
+ export declare const createZodSerializerCompiler: (options: ZodSerializerCompilerOptions) => FastifySerializerCompiler<z.ZodAny | {
49
+ properties: z.ZodAny;
50
+ }>;
44
51
  export declare const ZodSerializerCompiler: FastifySerializerCompiler<z.ZodAny | {
45
52
  properties: z.ZodAny;
46
53
  }>;
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createJsonSchemaTransformObject = exports.ZodSerializerCompiler = exports.ZodValidatorCompiler = exports.jsonSchemaTransform = exports.createJsonSchemaTransform = exports.InvalidSchemaError = exports.ResponseValidationError = void 0;
6
+ exports.createJsonSchemaTransformObject = exports.ZodSerializerCompiler = exports.createZodSerializerCompiler = exports.ZodValidatorCompiler = exports.jsonSchemaTransform = exports.createJsonSchemaTransform = exports.InvalidSchemaError = exports.ResponseValidationError = void 0;
7
7
  const error_1 = __importDefault(require("@fastify/error"));
8
8
  const zod_to_json_schema_1 = require("zod-to-json-schema");
9
9
  const defaultSkipList = [
@@ -97,15 +97,16 @@ const resolveSchema = (maybeSchema) => {
97
97
  }
98
98
  throw new exports.InvalidSchemaError(JSON.stringify(maybeSchema));
99
99
  };
100
- const ZodSerializerCompiler = ({ schema: maybeSchema }) => (data) => {
100
+ const createZodSerializerCompiler = (options) => ({ schema: maybeSchema }) => (data) => {
101
101
  const schema = resolveSchema(maybeSchema);
102
102
  const result = schema.safeParse(data);
103
103
  if (result.success) {
104
- return JSON.stringify(result.data);
104
+ return JSON.stringify(result.data, options.replacer);
105
105
  }
106
106
  throw new exports.ResponseValidationError({ cause: result.error });
107
107
  };
108
- exports.ZodSerializerCompiler = ZodSerializerCompiler;
108
+ exports.createZodSerializerCompiler = createZodSerializerCompiler;
109
+ exports.ZodSerializerCompiler = (0, exports.createZodSerializerCompiler)({});
109
110
  const createJsonSchemaTransformObject = ({ schemas: zodSchemas }) => (input) => {
110
111
  if ("swaggerObject" in input) {
111
112
  console.warn("This package currently does not support component references for Swagger 2.0");
package/package.json CHANGED
@@ -1,63 +1,62 @@
1
- {
2
- "name": "@bram-dc/fastify-type-provider-zod",
3
- "private": false,
4
- "version": "3.0.0",
5
- "description": "Zod Type Provider for Fastify@5",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "files": [
9
- "README.md",
10
- "LICENSE",
11
- "dist"
12
- ],
13
- "scripts": {
14
- "build": "tsc",
15
- "test": "npm run build && npm run typescript && vitest",
16
- "lint": "eslint .",
17
- "lint:fix": "eslint --fix .",
18
- "typescript": "tsd",
19
- "prepublishOnly": "npm run build"
20
- },
21
- "peerDependencies": {
22
- "fastify": "^5.0.0",
23
- "zod": "^3.23.8"
24
- },
25
- "repository": {
26
- "url": "https://github.com/bram-dc/fastify-type-provider-zod"
27
- },
28
- "keywords": [
29
- "fastify",
30
- "zod",
31
- "type",
32
- "provider"
33
- ],
34
- "author": "turkerd",
35
- "license": "MIT",
36
- "bugs": {
37
- "url": "https://github.com/bram-dc/fastify-type-provider-zod/issues"
38
- },
39
- "homepage": "https://github.com/bram-dc/fastify-type-provider-zod",
40
- "dependencies": {
41
- "@fastify/error": "^4.0.0",
42
- "zod-to-json-schema": "^3.23.3"
43
- },
44
- "devDependencies": {
45
- "@fastify/swagger": "^9.0.0",
46
- "@fastify/swagger-ui": "^5.0.1",
47
- "@stylistic/eslint-plugin": "^2.8.0",
48
- "@types/node": "^22.5.5",
49
- "eslint": "^9.10.0",
50
- "fastify": "^5.0.0",
51
- "fastify-plugin": "^5.0.0",
52
- "oas-validator": "^5.0.8",
53
- "openapi-types": "^12.1.3",
54
- "tsd": "^0.31.2",
55
- "typescript": "^5.6.2",
56
- "typescript-eslint": "^8.6.0",
57
- "vitest": "^2.1.1",
58
- "zod": "^3.23.8"
59
- },
60
- "tsd": {
61
- "directory": "types"
62
- }
63
- }
1
+ {
2
+ "name": "@bram-dc/fastify-type-provider-zod",
3
+ "version": "3.1.0",
4
+ "description": "Zod Type Provider for Fastify@5",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "README.md",
9
+ "LICENSE",
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "test": "npm run build && npm run typescript && vitest",
15
+ "lint": "eslint .",
16
+ "lint:fix": "eslint --fix .",
17
+ "typescript": "tsd",
18
+ "prepublishOnly": "npm run build"
19
+ },
20
+ "peerDependencies": {
21
+ "fastify": "^5.0.0",
22
+ "zod": "^3.23.8"
23
+ },
24
+ "repository": {
25
+ "url": "https://github.com/bram-dc/fastify-type-provider-zod"
26
+ },
27
+ "keywords": [
28
+ "fastify",
29
+ "zod",
30
+ "type",
31
+ "provider"
32
+ ],
33
+ "author": "turkerd",
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/bram-dc/fastify-type-provider-zod/issues"
37
+ },
38
+ "homepage": "https://github.com/bram-dc/fastify-type-provider-zod",
39
+ "dependencies": {
40
+ "@fastify/error": "^4.0.0",
41
+ "zod-to-json-schema": "^3.23.3"
42
+ },
43
+ "devDependencies": {
44
+ "@fastify/swagger": "^9.0.0",
45
+ "@fastify/swagger-ui": "^5.0.1",
46
+ "@stylistic/eslint-plugin": "^2.8.0",
47
+ "@types/node": "^22.5.5",
48
+ "eslint": "^9.10.0",
49
+ "fastify": "^5.0.0",
50
+ "fastify-plugin": "^5.0.0",
51
+ "oas-validator": "^5.0.8",
52
+ "openapi-types": "^12.1.3",
53
+ "tsd": "^0.31.2",
54
+ "typescript": "^5.6.2",
55
+ "typescript-eslint": "^8.6.0",
56
+ "vitest": "^2.1.1",
57
+ "zod": "^3.23.8"
58
+ },
59
+ "tsd": {
60
+ "directory": "types"
61
+ }
62
+ }