@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 +2 -2
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5 -4
- package/package.json +62 -63
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Fastify Type Provider Zod
|
|
2
2
|
|
|
3
|
-
[](https://npmjs.
|
|
4
|
-
[](https://npmjs.
|
|
3
|
+
[](https://www.npmjs.com/package/@bram-dc/fastify-type-provider-zod)
|
|
4
|
+
[](https://www.npmjs.com/package/@bram-dc/fastify-type-provider-zod)
|
|
5
5
|
[](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
|
|
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.
|
|
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
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"lint": "eslint .",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"@fastify/swagger": "^
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"fastify": "^5.0.0",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"typescript": "^
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|