@orpc/zod 0.0.0-next.ef3ba82 → 0.0.0-next.f16d90e

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/zod",
3
3
  "type": "module",
4
- "version": "0.0.0-next.ef3ba82",
4
+ "version": "0.0.0-next.f16d90e",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,25 +15,36 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs",
20
+ "default": "./dist/index.mjs"
21
21
  },
22
- "./🔒/*": {
23
- "types": "./dist/src/*.d.ts"
22
+ "./zod4": {
23
+ "types": "./dist/zod4/index.d.mts",
24
+ "import": "./dist/zod4/index.mjs",
25
+ "default": "./dist/zod4/index.mjs"
24
26
  }
25
27
  },
26
28
  "files": [
27
- "!dist/*.tsbuildinfo",
28
29
  "dist"
29
30
  ],
31
+ "peerDependencies": {
32
+ "zod": ">=3.24.2",
33
+ "@orpc/contract": "0.0.0-next.f16d90e",
34
+ "@orpc/server": "0.0.0-next.f16d90e"
35
+ },
30
36
  "dependencies": {
31
- "json-schema-typed": "^8.0.1",
37
+ "escape-string-regexp": "^5.0.0",
32
38
  "wildcard-match": "^5.1.3",
33
- "zod": "^3.23.8"
39
+ "@orpc/openapi": "0.0.0-next.f16d90e",
40
+ "@orpc/shared": "0.0.0-next.f16d90e"
41
+ },
42
+ "devDependencies": {
43
+ "zod": "^3.25.11",
44
+ "zod-to-json-schema": "^3.24.5"
34
45
  },
35
46
  "scripts": {
36
- "build": "tsup --clean --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
47
+ "build": "unbuild",
37
48
  "build:watch": "pnpm run build --watch",
38
49
  "type:check": "tsc -b"
39
50
  }
package/dist/index.js DELETED
@@ -1,147 +0,0 @@
1
- // src/index.ts
2
- import wcmatch from "wildcard-match";
3
- import {
4
- custom
5
- } from "zod";
6
- var customZodTypeSymbol = Symbol("customZodTypeSymbol");
7
- var customZodFileMimeTypeSymbol = Symbol("customZodFileMimeTypeSymbol");
8
- var CUSTOM_JSON_SCHEMA_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA");
9
- var CUSTOM_JSON_SCHEMA_INPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_INPUT");
10
- var CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_OUTPUT");
11
- function getCustomZodType(def) {
12
- return customZodTypeSymbol in def ? def[customZodTypeSymbol] : void 0;
13
- }
14
- function getCustomZodFileMimeType(def) {
15
- return customZodFileMimeTypeSymbol in def ? def[customZodFileMimeTypeSymbol] : void 0;
16
- }
17
- function getCustomJSONSchema(def, options) {
18
- if (options?.mode === "input" && CUSTOM_JSON_SCHEMA_INPUT_SYMBOL in def) {
19
- return def[CUSTOM_JSON_SCHEMA_INPUT_SYMBOL];
20
- }
21
- if (options?.mode === "output" && CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL in def) {
22
- return def[CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL];
23
- }
24
- if (CUSTOM_JSON_SCHEMA_SYMBOL in def) {
25
- return def[CUSTOM_JSON_SCHEMA_SYMBOL];
26
- }
27
- return void 0;
28
- }
29
- function composeParams(options) {
30
- return (val) => {
31
- const defaultMessage = typeof options.defaultMessage === "function" ? options.defaultMessage(val) : options.defaultMessage;
32
- if (!options.params) {
33
- return {
34
- message: defaultMessage
35
- };
36
- }
37
- if (typeof options.params === "function") {
38
- return {
39
- message: defaultMessage,
40
- ...options.params(val)
41
- };
42
- }
43
- if (typeof options.params === "object") {
44
- return {
45
- message: defaultMessage,
46
- ...options.params
47
- };
48
- }
49
- return {
50
- message: options.params
51
- };
52
- };
53
- }
54
- function file(params) {
55
- const schema = custom(
56
- (val) => val instanceof File,
57
- composeParams({ params, defaultMessage: "Input is not a file" })
58
- );
59
- Object.assign(schema._def, {
60
- [customZodTypeSymbol]: "File"
61
- });
62
- return Object.assign(schema, {
63
- type: (mimeType, params2) => {
64
- const isMatch = wcmatch(mimeType);
65
- const refinedSchema = schema.refine(
66
- (val) => isMatch(val.type.split(";")[0]),
67
- composeParams({
68
- params: params2,
69
- defaultMessage: (val) => `Expected a file of type ${mimeType} but got a file of type ${val.type || "unknown"}`
70
- })
71
- );
72
- Object.assign(refinedSchema._def, {
73
- [customZodTypeSymbol]: "File",
74
- [customZodFileMimeTypeSymbol]: mimeType
75
- });
76
- return refinedSchema;
77
- }
78
- });
79
- }
80
- function blob(params) {
81
- const schema = custom(
82
- (val) => val instanceof Blob,
83
- composeParams({ params, defaultMessage: "Input is not a blob" })
84
- );
85
- Object.assign(schema._def, {
86
- [customZodTypeSymbol]: "Blob"
87
- });
88
- return schema;
89
- }
90
- function invalidDate(params) {
91
- const schema = custom(
92
- (val) => val instanceof Date && Number.isNaN(val.getTime()),
93
- composeParams({ params, defaultMessage: "Input is not an invalid date" })
94
- );
95
- Object.assign(schema._def, {
96
- [customZodTypeSymbol]: "Invalid Date"
97
- });
98
- return schema;
99
- }
100
- function regexp(options) {
101
- const schema = custom(
102
- (val) => val instanceof RegExp,
103
- composeParams({ params: options, defaultMessage: "Input is not a regexp" })
104
- );
105
- Object.assign(schema._def, {
106
- [customZodTypeSymbol]: "RegExp"
107
- });
108
- return schema;
109
- }
110
- function url(options) {
111
- const schema = custom(
112
- (val) => val instanceof URL,
113
- composeParams({ params: options, defaultMessage: "Input is not a URL" })
114
- );
115
- Object.assign(schema._def, {
116
- [customZodTypeSymbol]: "URL"
117
- });
118
- return schema;
119
- }
120
- function openapi(schema, custom2, options) {
121
- const newSchema = schema.refine(() => true);
122
- const SYMBOL = options?.mode === "input" ? CUSTOM_JSON_SCHEMA_INPUT_SYMBOL : options?.mode === "output" ? CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL : CUSTOM_JSON_SCHEMA_SYMBOL;
123
- Object.assign(newSchema._def, {
124
- [SYMBOL]: custom2
125
- });
126
- return newSchema;
127
- }
128
- var oz = {
129
- openapi,
130
- file,
131
- blob,
132
- invalidDate,
133
- regexp,
134
- url
135
- };
136
- export {
137
- blob,
138
- file,
139
- getCustomJSONSchema,
140
- getCustomZodFileMimeType,
141
- getCustomZodType,
142
- invalidDate,
143
- openapi,
144
- oz,
145
- regexp,
146
- url
147
- };
@@ -1,30 +0,0 @@
1
- import type { JSONSchema } from 'json-schema-typed/draft-2020-12';
2
- import { type CustomErrorParams, type input, type output, type ZodEffects, type ZodType, type ZodTypeAny, type ZodTypeDef } from 'zod';
3
- export type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL';
4
- type CustomParams = CustomErrorParams & {
5
- fatal?: boolean;
6
- };
7
- export declare function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined;
8
- export declare function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined;
9
- export declare function getCustomJSONSchema(def: ZodTypeDef, options?: {
10
- mode?: 'input' | 'output';
11
- }): Exclude<JSONSchema, boolean> | undefined;
12
- export declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {
13
- type: (mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)) => ZodEffects<ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, InstanceType<typeof File>, InstanceType<typeof File>>;
14
- };
15
- export declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>>;
16
- export declare function invalidDate(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Date, ZodTypeDef, Date>;
17
- export declare function regexp(options?: CustomParams): ZodType<RegExp, ZodTypeDef, RegExp>;
18
- export declare function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL>;
19
- export declare function openapi<T extends ZodTypeAny, TMode extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema<TMode extends 'input' ? input<T> : TMode extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
20
- mode: TMode;
21
- }): ReturnType<T['refine']>;
22
- export declare const oz: {
23
- openapi: typeof openapi;
24
- file: typeof file;
25
- blob: typeof blob;
26
- invalidDate: typeof invalidDate;
27
- regexp: typeof regexp;
28
- url: typeof url;
29
- };
30
- export {};