@orpc/zod 1.14.9 → 1.14.11
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 +52 -112
- package/dist/index.d.mts +251 -86
- package/dist/index.d.ts +251 -86
- package/dist/index.mjs +78 -849
- package/package.json +8 -17
- package/dist/zod4/index.d.mts +0 -314
- package/dist/zod4/index.d.ts +0 -314
- package/dist/zod4/index.mjs +0 -698
package/README.md
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
<
|
|
2
|
-
<image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" />
|
|
3
|
-
</div>
|
|
4
|
-
|
|
5
|
-
<h1></h1>
|
|
1
|
+
<h1 align="center">oRPC - Typesafe APIs Made Simple 🪄</h1>
|
|
6
2
|
|
|
7
3
|
<div align="center">
|
|
8
4
|
<a href="https://codecov.io/gh/middleapi/orpc">
|
|
9
|
-
<img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/
|
|
5
|
+
<img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
|
|
10
6
|
</a>
|
|
11
7
|
<a href="https://www.npmjs.com/package/@orpc/zod">
|
|
12
8
|
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fzod?logo=npm" />
|
|
13
9
|
</a>
|
|
14
|
-
<a href="https://
|
|
10
|
+
<a href="https://app.codspeed.io/middleapi/orpc?utm_source=badge">
|
|
11
|
+
<img alt="CodSpeed" src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" />
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://github.com/middleapi/orpc/blob/main/LICENSE">
|
|
15
14
|
<img alt="MIT License" src="https://img.shields.io/github/license/middleapi/orpc?logo=open-source-initiative" />
|
|
16
15
|
</a>
|
|
17
16
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
@@ -22,119 +21,53 @@
|
|
|
22
21
|
</a>
|
|
23
22
|
</div>
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
## Documentation
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
You can read the documentation [here](https://orpc.dev).
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
## Packages
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
**Core**
|
|
32
31
|
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
38
|
-
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
39
|
-
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
40
|
-
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
41
|
-
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
42
|
-
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
43
|
-
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
44
|
-
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
32
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Define API contract as the single source of truth.
|
|
33
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build APIs or implement contracts.
|
|
34
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume APIs with end-to-end type safety.
|
|
35
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Add OpenAPI compatibility to APIs.
|
|
45
36
|
|
|
46
|
-
|
|
37
|
+
**Schema validation**
|
|
47
38
|
|
|
48
|
-
|
|
39
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): Integrate with [Zod](https://zod.dev/).
|
|
40
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): Integrate with [Valibot](https://valibot.dev/).
|
|
41
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): Integrate with [ArkType](https://arktype.io/).
|
|
49
42
|
|
|
50
|
-
|
|
43
|
+
**Built-in features**
|
|
44
|
+
|
|
45
|
+
- [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher): Pub/Sub with memory, Redis, and Upstash adapters.
|
|
46
|
+
- [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit): Rate limiting with memory, Redis, and Upstash adapters.
|
|
47
|
+
- [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema): Smart coercion for OpenAPI requests.
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
- [@orpc/
|
|
55
|
-
- [@orpc/
|
|
56
|
-
- [@orpc/
|
|
57
|
-
- [@orpc/
|
|
58
|
-
- [@orpc/
|
|
59
|
-
- [@orpc/
|
|
60
|
-
- [@orpc/
|
|
61
|
-
- [@orpc/
|
|
62
|
-
- [@orpc/
|
|
63
|
-
- [@orpc/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
### More Schemas
|
|
72
|
-
|
|
73
|
-
- `oz.url`: Zod schema for [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) instance.
|
|
74
|
-
- `oz.blob`: Zod schema for [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) instance.
|
|
75
|
-
- `oz.file`: Zod schema for [File](https://developer.mozilla.org/en-US/docs/Web/API/File) instance.
|
|
76
|
-
- `oz.regexp`: Zod schema for [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instance.
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
import { oz } from '@orpc/zod'
|
|
80
|
-
import { z } from 'zod/v3'
|
|
81
|
-
|
|
82
|
-
const Example = z.object({
|
|
83
|
-
url: oz.url(),
|
|
84
|
-
blob: oz.blob(),
|
|
85
|
-
file: oz.file().type('image/png'),
|
|
86
|
-
regexp: oz.regexp(),
|
|
87
|
-
})
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### Generate OpenAPI Spec
|
|
91
|
-
|
|
92
|
-
```ts
|
|
93
|
-
import { OpenAPIGenerator } from '@orpc/openapi'
|
|
94
|
-
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
|
|
95
|
-
|
|
96
|
-
const openAPIGenerator = new OpenAPIGenerator({
|
|
97
|
-
schemaConverters: [new ZodToJsonSchemaConverter()],
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
const specFromContract = await openAPIGenerator.generate(contract, {
|
|
101
|
-
info: {
|
|
102
|
-
title: 'My App',
|
|
103
|
-
version: '0.0.0',
|
|
104
|
-
},
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
const specFromRouter = await openAPIGenerator.generate(router, {
|
|
108
|
-
info: {
|
|
109
|
-
title: 'My App',
|
|
110
|
-
version: '0.0.0',
|
|
111
|
-
},
|
|
112
|
-
})
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### Extending the Specification
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
import { oz } from '@orpc/zod'
|
|
119
|
-
import * as z from 'zod'
|
|
120
|
-
|
|
121
|
-
const InputSchema = oz.openapi(
|
|
122
|
-
z.object({
|
|
123
|
-
name: z.string(),
|
|
124
|
-
}),
|
|
125
|
-
{
|
|
126
|
-
examples: [
|
|
127
|
-
{ name: 'Earth' },
|
|
128
|
-
{ name: 'Mars' },
|
|
129
|
-
],
|
|
130
|
-
// additional options...
|
|
131
|
-
}
|
|
132
|
-
)
|
|
133
|
-
```
|
|
49
|
+
**Framework & ecosystem integrations**
|
|
50
|
+
|
|
51
|
+
- [@orpc/next](https://www.npmjs.com/package/@orpc/next): Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data).
|
|
52
|
+
- [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk): Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools.
|
|
53
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): Integrate with [TanStack Query](https://tanstack.com/query/latest).
|
|
54
|
+
- [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada): Integrate with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
55
|
+
- [@orpc/swr](https://www.npmjs.com/package/@orpc/swr): Integrate with [SWR](https://swr.vercel.app/).
|
|
56
|
+
- [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect): Integrate with [Effect](https://effect.website/).
|
|
57
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Implement your contract with [NestJS](https://nestjs.com/).
|
|
58
|
+
- [@orpc/bun](https://www.npmjs.com/package/@orpc/bun): Adapters for [Bun's Redis](https://bun.sh/).
|
|
59
|
+
- [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare): Adapters for [Cloudflare's RateLimit and Durable Objects](https://developers.cloudflare.com/workers/).
|
|
60
|
+
- [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc): Reuse existing [tRPC](https://trpc.io/) routers within oRPC.
|
|
61
|
+
|
|
62
|
+
**Observability**
|
|
63
|
+
|
|
64
|
+
- [@orpc/opentelemetry](https://www.npmjs.com/package/@orpc/opentelemetry): Integrate with [OpenTelemetry](https://opentelemetry.io/) for distributed tracing.
|
|
65
|
+
- [@orpc/pino](https://www.npmjs.com/package/@orpc/pino): Integrate with [Pino](https://getpino.io/) for logging.
|
|
66
|
+
- [@orpc/evlog](https://www.npmjs.com/package/@orpc/evlog): Integrate with [Evlog](https://evlog.dev/) for logging.
|
|
134
67
|
|
|
135
68
|
## Sponsors
|
|
136
69
|
|
|
137
|
-
|
|
70
|
+
Like what we build over at [middleapi](https://github.com/middleapi)? You can help keep it going here: [GitHub Sponsors](https://github.com/sponsors/dinwwwh). Every bit helps! 🚀
|
|
138
71
|
|
|
139
72
|
### 🏆 Platinum Sponsor
|
|
140
73
|
|
|
@@ -176,11 +109,10 @@ If you find oRPC valuable and would like to support its development, you can do
|
|
|
176
109
|
<td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&v=4" width="139" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td>
|
|
177
110
|
<td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&v=4" width="139" alt="Valerii Strilets"/><br />Valerii Strilets</a></td>
|
|
178
111
|
<td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&v=4" width="139" alt="Kyle Mistele"/><br />Kyle Mistele</a></td>
|
|
179
|
-
<td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&v=4" width="139" alt="Ryan Vogel"/><br />Ryan Vogel</a></td>
|
|
180
112
|
<td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td>
|
|
113
|
+
<td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
181
114
|
</tr>
|
|
182
115
|
<tr>
|
|
183
|
-
<td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
184
116
|
<td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="139" alt="shota"/><br />shota</a></td>
|
|
185
117
|
</tr>
|
|
186
118
|
</table>
|
|
@@ -240,6 +172,7 @@ If you find oRPC valuable and would like to support its development, you can do
|
|
|
240
172
|
<a href="https://github.com/nguyenlc1993?ref=orpc" target="_blank" rel="noopener" title="Lê Cao Nguyên"><img src="https://avatars.githubusercontent.com/u/13871971?u=83c8b69d9e35b589c4e1f066cc113b1d9461386f&v=4" width="32" height="32" alt="Lê Cao Nguyên" /></a>
|
|
241
173
|
<a href="https://github.com/wobsoriano?ref=orpc" target="_blank" rel="noopener" title="Robert Soriano"><img src="https://avatars.githubusercontent.com/u/13049130?u=6d72104182e7c9ed25934815313fb69107332111&v=4" width="32" height="32" alt="Robert Soriano" /></a>
|
|
242
174
|
<a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="32" height="32" alt="Andrew Peters" /></a>
|
|
175
|
+
<a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&v=4" width="32" height="32" alt="Ryan Vogel" /></a>
|
|
243
176
|
<a href="https://github.com/SKostyukovich?ref=orpc" target="_blank" rel="noopener" title="SKostyukovich"><img src="https://avatars.githubusercontent.com/u/10700067?v=4" width="32" height="32" alt="SKostyukovich" /></a>
|
|
244
177
|
<a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&v=4" width="32" height="32" alt="Peter Adam" /></a>
|
|
245
178
|
<a href="https://github.com/FabworksHQ?ref=orpc" target="_blank" rel="noopener" title="Fabworks"><img src="https://avatars.githubusercontent.com/u/160179500?v=4" width="32" height="32" alt="Fabworks" /></a>
|
|
@@ -254,6 +187,13 @@ If you find oRPC valuable and would like to support its development, you can do
|
|
|
254
187
|
<a href="https://github.com/plancraft?ref=orpc" target="_blank" rel="noopener" title="plancraft"><img src="https://avatars.githubusercontent.com/u/46482287?v=4" width="32" height="32" alt="plancraft" /></a>
|
|
255
188
|
</p>
|
|
256
189
|
|
|
190
|
+
## References
|
|
191
|
+
|
|
192
|
+
oRPC is inspired by existing solutions that prioritize type safety and developer experience. Special acknowledgments to:
|
|
193
|
+
|
|
194
|
+
- [tRPC](https://trpc.io): For pioneering the concept of end-to-end type-safe RPC and influencing the development of type-safe APIs.
|
|
195
|
+
- [ts-rest](https://ts-rest.com): For its emphasis on contract-first development and OpenAPI integration, which have greatly inspired oRPC's feature set.
|
|
196
|
+
|
|
257
197
|
## License
|
|
258
198
|
|
|
259
|
-
Distributed under the MIT License. See [LICENSE](https://github.com/middleapi/orpc/blob/
|
|
199
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/middleapi/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,91 +1,256 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { AnySchema } from '@orpc/contract';
|
|
1
|
+
import { JsonSchemaConverter, AnySchema, JsonSchemaConverterDirection, JsonSchema } from '@orpc/json-schema';
|
|
2
|
+
import * as zod_v4_core from 'zod/v4/core';
|
|
3
|
+
import { ToJSONSchemaParams, $input, $output } from 'zod/v4/core';
|
|
4
|
+
import * as json_schema_typed from 'json-schema-typed';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
strategy: 'input' | 'output' | 'both';
|
|
9
|
-
}): Exclude<JSONSchema, boolean> | undefined;
|
|
10
|
-
declare function customJsonSchema<T extends ZodTypeAny, TStrategy extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema<TStrategy extends 'input' ? input<T> : TStrategy extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
|
|
11
|
-
strategy?: TStrategy;
|
|
12
|
-
}): T;
|
|
13
|
-
|
|
14
|
-
type CustomParams = CustomErrorParams & {
|
|
15
|
-
fatal?: boolean;
|
|
16
|
-
};
|
|
17
|
-
type CustomZodDef = {
|
|
18
|
-
type: 'blob' | 'regexp' | 'url';
|
|
19
|
-
} | {
|
|
20
|
-
type: 'file';
|
|
21
|
-
mimeType?: string;
|
|
22
|
-
};
|
|
23
|
-
declare function setCustomZodDef<T extends ZodTypeDef>(def: T, custom: CustomZodDef): void;
|
|
24
|
-
declare function getCustomZodDef(def: ZodTypeDef): CustomZodDef | undefined;
|
|
25
|
-
declare function composeParams<T = unknown>(defaultMessage: (input: T) => string, params: undefined | string | CustomParams | ((input: T) => CustomParams)): (input: T) => CustomParams;
|
|
26
|
-
|
|
27
|
-
declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Blob, ZodTypeDef, Blob>;
|
|
28
|
-
|
|
29
|
-
declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<File, ZodTypeDef, File> & {
|
|
30
|
-
type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<File, ZodTypeDef, File>, File, File>;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
declare function regexp(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<RegExp, ZodTypeDef, RegExp>;
|
|
34
|
-
|
|
35
|
-
declare function url(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<URL, ZodTypeDef, URL>;
|
|
36
|
-
|
|
37
|
-
declare class ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
|
|
38
|
-
init(options: StandardHandlerOptions<TContext>): void;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface ZodToJsonSchemaOptions {
|
|
42
|
-
/**
|
|
43
|
-
* Max depth of lazy type
|
|
44
|
-
*
|
|
45
|
-
* Used `{}` when exceed max depth
|
|
46
|
-
*
|
|
47
|
-
* @default 3
|
|
48
|
-
*/
|
|
49
|
-
maxLazyDepth?: number;
|
|
50
|
-
/**
|
|
51
|
-
* Max depth of nested types
|
|
52
|
-
*
|
|
53
|
-
* Used anyJsonSchema (`{}`) when exceed max depth
|
|
54
|
-
*
|
|
55
|
-
* @default 10
|
|
56
|
-
*/
|
|
57
|
-
maxStructureDepth?: number;
|
|
58
|
-
/**
|
|
59
|
-
* The schema to be used to represent the any | unknown type.
|
|
60
|
-
*
|
|
61
|
-
* @default { }
|
|
62
|
-
*/
|
|
63
|
-
anyJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
64
|
-
/**
|
|
65
|
-
* The schema to be used when the Zod schema is unsupported.
|
|
66
|
-
*
|
|
67
|
-
* @default { not: {} }
|
|
68
|
-
*/
|
|
69
|
-
unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
6
|
+
interface ZodToJsonSchemaConverterOptions extends Omit<ToJSONSchemaParams, 'target' | 'io'> {
|
|
70
7
|
}
|
|
71
|
-
declare class ZodToJsonSchemaConverter implements
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
private
|
|
77
|
-
|
|
78
|
-
condition(schema: AnySchema | undefined): boolean;
|
|
79
|
-
convert(schema: AnySchema | undefined, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean, structureDepth?: number): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
|
|
8
|
+
declare class ZodToJsonSchemaConverter implements JsonSchemaConverter {
|
|
9
|
+
private readonly options;
|
|
10
|
+
constructor(options?: ZodToJsonSchemaConverterOptions);
|
|
11
|
+
condition(schema: AnySchema | undefined, _direction: JsonSchemaConverterDirection): boolean;
|
|
12
|
+
convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
|
|
13
|
+
private convertZod;
|
|
14
|
+
private getCustomJsonSchema;
|
|
80
15
|
}
|
|
81
16
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Zod registry for customizing generated JSON schema, can use both for .input and .output
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { JSON_SCHEMA_REGISTRY } from '@orpc/zod'
|
|
23
|
+
*
|
|
24
|
+
* const user = z.object({
|
|
25
|
+
* name: z.string(),
|
|
26
|
+
* age: z.number(),
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* JSON_SCHEMA_REGISTRY.add(user, {
|
|
30
|
+
* examples: [{ name: 'John', age: 20 }],
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare const JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
35
|
+
$anchor?: string;
|
|
36
|
+
$comment?: string;
|
|
37
|
+
$defs?: Record<string, json_schema_typed.JSONSchema>;
|
|
38
|
+
$dynamicAnchor?: string;
|
|
39
|
+
$dynamicRef?: string;
|
|
40
|
+
$id?: string;
|
|
41
|
+
$ref?: string;
|
|
42
|
+
$schema?: string;
|
|
43
|
+
$vocabulary?: Record<string, string>;
|
|
44
|
+
additionalItems?: json_schema_typed.JSONSchema;
|
|
45
|
+
additionalProperties?: json_schema_typed.JSONSchema;
|
|
46
|
+
allOf?: (json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
|
|
47
|
+
anyOf?: (json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
|
|
48
|
+
const?: typeof $input | typeof $output | undefined;
|
|
49
|
+
contains?: json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
50
|
+
contentEncoding?: "7bit" | "8bit" | "base64" | "binary" | "ietf-token" | "quoted-printable" | "x-token";
|
|
51
|
+
contentMediaType?: string;
|
|
52
|
+
contentSchema?: json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
53
|
+
default?: typeof $input | typeof $output | undefined;
|
|
54
|
+
definitions?: Record<string, json_schema_typed.JSONSchema>;
|
|
55
|
+
dependencies?: Record<string, (string[] | readonly string[]) | json_schema_typed.JSONSchema>;
|
|
56
|
+
dependentRequired?: Record<string, string[] | readonly string[]>;
|
|
57
|
+
dependentSchemas?: Record<string, json_schema_typed.JSONSchema>;
|
|
58
|
+
deprecated?: boolean;
|
|
59
|
+
description?: string;
|
|
60
|
+
else?: json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
61
|
+
enum?: ((typeof $input | typeof $output)[] | readonly (typeof $input | typeof $output)[]) | undefined;
|
|
62
|
+
examples?: ((typeof $input | typeof $output)[] | readonly (typeof $input | typeof $output)[]) | undefined;
|
|
63
|
+
exclusiveMaximum?: number;
|
|
64
|
+
exclusiveMinimum?: number;
|
|
65
|
+
format?: string;
|
|
66
|
+
if?: json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
67
|
+
items?: json_schema_typed.JSONSchema;
|
|
68
|
+
maxContains?: number;
|
|
69
|
+
maximum?: number;
|
|
70
|
+
maxItems?: number;
|
|
71
|
+
maxLength?: number;
|
|
72
|
+
maxProperties?: number;
|
|
73
|
+
minContains?: number;
|
|
74
|
+
minimum?: number;
|
|
75
|
+
minItems?: number;
|
|
76
|
+
minLength?: number;
|
|
77
|
+
minProperties?: number;
|
|
78
|
+
multipleOf?: number;
|
|
79
|
+
not?: json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
80
|
+
oneOf?: (json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
|
|
81
|
+
pattern?: string;
|
|
82
|
+
patternProperties?: Record<string, json_schema_typed.JSONSchema>;
|
|
83
|
+
prefixItems?: (json_schema_typed.JSONSchema<any, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<any, json_schema_typed.JSONSchema.TypeValue>[]) | json_schema_typed.JSONSchema;
|
|
84
|
+
properties?: Record<string, json_schema_typed.JSONSchema>;
|
|
85
|
+
propertyNames?: json_schema_typed.JSONSchema;
|
|
86
|
+
readOnly?: boolean;
|
|
87
|
+
required?: string[] | readonly string[];
|
|
88
|
+
then?: json_schema_typed.JSONSchema<typeof $input | typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
89
|
+
title?: string;
|
|
90
|
+
type?: json_schema_typed.JSONSchema.TypeValue | undefined;
|
|
91
|
+
unevaluatedItems?: json_schema_typed.JSONSchema;
|
|
92
|
+
unevaluatedProperties?: json_schema_typed.JSONSchema;
|
|
93
|
+
uniqueItems?: boolean;
|
|
94
|
+
writeOnly?: boolean;
|
|
95
|
+
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
|
96
|
+
/**
|
|
97
|
+
* Zod registry for customizing generated JSON schema, only useful for .input
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { JSON_SCHEMA_INPUT_REGISTRY } from '@orpc/zod'
|
|
102
|
+
*
|
|
103
|
+
* const user = z.object({
|
|
104
|
+
* name: z.string(),
|
|
105
|
+
* age: z.string().transform(v => Number(v)),
|
|
106
|
+
* })
|
|
107
|
+
*
|
|
108
|
+
* JSON_SCHEMA_INPUT_REGISTRY.add(user, {
|
|
109
|
+
* examples: [{ name: 'John', age: "20" }],
|
|
110
|
+
* })
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare const JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
114
|
+
$anchor?: string;
|
|
115
|
+
$comment?: string;
|
|
116
|
+
$defs?: Record<string, json_schema_typed.JSONSchema>;
|
|
117
|
+
$dynamicAnchor?: string;
|
|
118
|
+
$dynamicRef?: string;
|
|
119
|
+
$id?: string;
|
|
120
|
+
$ref?: string;
|
|
121
|
+
$schema?: string;
|
|
122
|
+
$vocabulary?: Record<string, string>;
|
|
123
|
+
additionalItems?: json_schema_typed.JSONSchema;
|
|
124
|
+
additionalProperties?: json_schema_typed.JSONSchema;
|
|
125
|
+
allOf?: (json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
|
|
126
|
+
anyOf?: (json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
|
|
127
|
+
const?: typeof $input | undefined;
|
|
128
|
+
contains?: json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
129
|
+
contentEncoding?: "7bit" | "8bit" | "base64" | "binary" | "ietf-token" | "quoted-printable" | "x-token";
|
|
130
|
+
contentMediaType?: string;
|
|
131
|
+
contentSchema?: json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
132
|
+
default?: typeof $input | undefined;
|
|
133
|
+
definitions?: Record<string, json_schema_typed.JSONSchema>;
|
|
134
|
+
dependencies?: Record<string, (string[] | readonly string[]) | json_schema_typed.JSONSchema>;
|
|
135
|
+
dependentRequired?: Record<string, string[] | readonly string[]>;
|
|
136
|
+
dependentSchemas?: Record<string, json_schema_typed.JSONSchema>;
|
|
137
|
+
deprecated?: boolean;
|
|
138
|
+
description?: string;
|
|
139
|
+
else?: json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
140
|
+
enum?: ((typeof $input)[] | readonly (typeof $input)[]) | undefined;
|
|
141
|
+
examples?: ((typeof $input)[] | readonly (typeof $input)[]) | undefined;
|
|
142
|
+
exclusiveMaximum?: number;
|
|
143
|
+
exclusiveMinimum?: number;
|
|
144
|
+
format?: string;
|
|
145
|
+
if?: json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
146
|
+
items?: json_schema_typed.JSONSchema;
|
|
147
|
+
maxContains?: number;
|
|
148
|
+
maximum?: number;
|
|
149
|
+
maxItems?: number;
|
|
150
|
+
maxLength?: number;
|
|
151
|
+
maxProperties?: number;
|
|
152
|
+
minContains?: number;
|
|
153
|
+
minimum?: number;
|
|
154
|
+
minItems?: number;
|
|
155
|
+
minLength?: number;
|
|
156
|
+
minProperties?: number;
|
|
157
|
+
multipleOf?: number;
|
|
158
|
+
not?: json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
159
|
+
oneOf?: (json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
|
|
160
|
+
pattern?: string;
|
|
161
|
+
patternProperties?: Record<string, json_schema_typed.JSONSchema>;
|
|
162
|
+
prefixItems?: (json_schema_typed.JSONSchema<any, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<any, json_schema_typed.JSONSchema.TypeValue>[]) | json_schema_typed.JSONSchema;
|
|
163
|
+
properties?: Record<string, json_schema_typed.JSONSchema>;
|
|
164
|
+
propertyNames?: json_schema_typed.JSONSchema;
|
|
165
|
+
readOnly?: boolean;
|
|
166
|
+
required?: string[] | readonly string[];
|
|
167
|
+
then?: json_schema_typed.JSONSchema<typeof $input, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
168
|
+
title?: string;
|
|
169
|
+
type?: json_schema_typed.JSONSchema.TypeValue | undefined;
|
|
170
|
+
unevaluatedItems?: json_schema_typed.JSONSchema;
|
|
171
|
+
unevaluatedProperties?: json_schema_typed.JSONSchema;
|
|
172
|
+
uniqueItems?: boolean;
|
|
173
|
+
writeOnly?: boolean;
|
|
174
|
+
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
|
175
|
+
/**
|
|
176
|
+
* Zod registry for customizing generated JSON schema, only useful for .output
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* import { JSON_SCHEMA_OUTPUT_REGISTRY } from '@orpc/zod'
|
|
181
|
+
*
|
|
182
|
+
* const user = z.object({
|
|
183
|
+
* name: z.string(),
|
|
184
|
+
* age: z.string().transform(v => Number(v)),
|
|
185
|
+
* })
|
|
186
|
+
*
|
|
187
|
+
* JSON_SCHEMA_OUTPUT_REGISTRY.add(user, {
|
|
188
|
+
* examples: [{ name: 'John', age: 20 }],
|
|
189
|
+
* })
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
declare const JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
193
|
+
$anchor?: string;
|
|
194
|
+
$comment?: string;
|
|
195
|
+
$defs?: Record<string, json_schema_typed.JSONSchema>;
|
|
196
|
+
$dynamicAnchor?: string;
|
|
197
|
+
$dynamicRef?: string;
|
|
198
|
+
$id?: string;
|
|
199
|
+
$ref?: string;
|
|
200
|
+
$schema?: string;
|
|
201
|
+
$vocabulary?: Record<string, string>;
|
|
202
|
+
additionalItems?: json_schema_typed.JSONSchema;
|
|
203
|
+
additionalProperties?: json_schema_typed.JSONSchema;
|
|
204
|
+
allOf?: (json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
|
|
205
|
+
anyOf?: (json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
|
|
206
|
+
const?: typeof $output | undefined;
|
|
207
|
+
contains?: json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
208
|
+
contentEncoding?: "7bit" | "8bit" | "base64" | "binary" | "ietf-token" | "quoted-printable" | "x-token";
|
|
209
|
+
contentMediaType?: string;
|
|
210
|
+
contentSchema?: json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
211
|
+
default?: typeof $output | undefined;
|
|
212
|
+
definitions?: Record<string, json_schema_typed.JSONSchema>;
|
|
213
|
+
dependencies?: Record<string, (string[] | readonly string[]) | json_schema_typed.JSONSchema>;
|
|
214
|
+
dependentRequired?: Record<string, string[] | readonly string[]>;
|
|
215
|
+
dependentSchemas?: Record<string, json_schema_typed.JSONSchema>;
|
|
216
|
+
deprecated?: boolean;
|
|
217
|
+
description?: string;
|
|
218
|
+
else?: json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
219
|
+
enum?: ((typeof $output)[] | readonly (typeof $output)[]) | undefined;
|
|
220
|
+
examples?: ((typeof $output)[] | readonly (typeof $output)[]) | undefined;
|
|
221
|
+
exclusiveMaximum?: number;
|
|
222
|
+
exclusiveMinimum?: number;
|
|
223
|
+
format?: string;
|
|
224
|
+
if?: json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
225
|
+
items?: json_schema_typed.JSONSchema;
|
|
226
|
+
maxContains?: number;
|
|
227
|
+
maximum?: number;
|
|
228
|
+
maxItems?: number;
|
|
229
|
+
maxLength?: number;
|
|
230
|
+
maxProperties?: number;
|
|
231
|
+
minContains?: number;
|
|
232
|
+
minimum?: number;
|
|
233
|
+
minItems?: number;
|
|
234
|
+
minLength?: number;
|
|
235
|
+
minProperties?: number;
|
|
236
|
+
multipleOf?: number;
|
|
237
|
+
not?: json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
238
|
+
oneOf?: (json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue>[]) | undefined;
|
|
239
|
+
pattern?: string;
|
|
240
|
+
patternProperties?: Record<string, json_schema_typed.JSONSchema>;
|
|
241
|
+
prefixItems?: (json_schema_typed.JSONSchema<any, json_schema_typed.JSONSchema.TypeValue>[] | readonly json_schema_typed.JSONSchema<any, json_schema_typed.JSONSchema.TypeValue>[]) | json_schema_typed.JSONSchema;
|
|
242
|
+
properties?: Record<string, json_schema_typed.JSONSchema>;
|
|
243
|
+
propertyNames?: json_schema_typed.JSONSchema;
|
|
244
|
+
readOnly?: boolean;
|
|
245
|
+
required?: string[] | readonly string[];
|
|
246
|
+
then?: json_schema_typed.JSONSchema<typeof $output, json_schema_typed.JSONSchema.TypeValue> | undefined;
|
|
247
|
+
title?: string;
|
|
248
|
+
type?: json_schema_typed.JSONSchema.TypeValue | undefined;
|
|
249
|
+
unevaluatedItems?: json_schema_typed.JSONSchema;
|
|
250
|
+
unevaluatedProperties?: json_schema_typed.JSONSchema;
|
|
251
|
+
uniqueItems?: boolean;
|
|
252
|
+
writeOnly?: boolean;
|
|
253
|
+
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
|
89
254
|
|
|
90
|
-
export {
|
|
91
|
-
export type {
|
|
255
|
+
export { JSON_SCHEMA_INPUT_REGISTRY, JSON_SCHEMA_OUTPUT_REGISTRY, JSON_SCHEMA_REGISTRY, ZodToJsonSchemaConverter };
|
|
256
|
+
export type { ZodToJsonSchemaConverterOptions };
|