@orpc/zod 0.0.0-next.b683b88 β 0.0.0-next.b6b8746
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 +125 -16
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +52 -21
- package/dist/zod4/index.d.mts +11 -8
- package/dist/zod4/index.d.ts +11 -8
- package/dist/zod4/index.mjs +56 -26
- package/package.json +11 -12
package/README.md
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<image align="center" src="https://orpc.
|
|
2
|
+
<image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" />
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<h1></h1>
|
|
6
6
|
|
|
7
7
|
<div align="center">
|
|
8
|
-
<a href="https://codecov.io/gh/
|
|
9
|
-
<img alt="codecov" src="https://codecov.io/gh/
|
|
8
|
+
<a href="https://codecov.io/gh/middleapi/orpc">
|
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
|
|
10
10
|
</a>
|
|
11
11
|
<a href="https://www.npmjs.com/package/@orpc/zod">
|
|
12
12
|
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fzod?logo=npm" />
|
|
13
13
|
</a>
|
|
14
|
-
<a href="https://github.com/
|
|
15
|
-
<img alt="MIT License" src="https://img.shields.io/github/license/
|
|
14
|
+
<a href="https://github.com/middleapi/orpc/blob/main/LICENSE">
|
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/middleapi/orpc?logo=open-source-initiative" />
|
|
16
16
|
</a>
|
|
17
17
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
18
|
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
19
|
</a>
|
|
20
|
+
<a href="https://deepwiki.com/middleapi/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
20
23
|
</div>
|
|
21
24
|
|
|
22
25
|
<h3 align="center">Typesafe APIs Made Simple πͺ</h3>
|
|
@@ -30,7 +33,8 @@
|
|
|
30
33
|
- **π End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
34
|
- **π First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
35
|
- **π Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
-
-
|
|
36
|
+
- **π First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
37
|
+
- **βοΈ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
34
38
|
- **π Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
39
|
- **π Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
40
|
- **ποΈ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -38,11 +42,10 @@
|
|
|
38
42
|
- **π‘ SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
43
|
- **π Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
44
|
- **π Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
-
- **π‘οΈ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
42
45
|
|
|
43
46
|
## Documentation
|
|
44
47
|
|
|
45
|
-
You can find the full documentation [here](https://orpc.
|
|
48
|
+
You can find the full documentation [here](https://orpc.dev).
|
|
46
49
|
|
|
47
50
|
## Packages
|
|
48
51
|
|
|
@@ -50,9 +53,11 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
50
53
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
51
54
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
55
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
56
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
53
57
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
54
58
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
55
59
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
60
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
56
61
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
57
62
|
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
58
63
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
@@ -72,7 +77,7 @@ More schemas that [Zod](https://zod.dev/) doesn't support yet, and provides `Zod
|
|
|
72
77
|
|
|
73
78
|
```ts
|
|
74
79
|
import { oz } from '@orpc/zod'
|
|
75
|
-
import { z } from 'zod'
|
|
80
|
+
import { z } from 'zod/v3'
|
|
76
81
|
|
|
77
82
|
const Example = z.object({
|
|
78
83
|
url: oz.url(),
|
|
@@ -86,7 +91,7 @@ const Example = z.object({
|
|
|
86
91
|
|
|
87
92
|
```ts
|
|
88
93
|
import { OpenAPIGenerator } from '@orpc/openapi'
|
|
89
|
-
import { ZodToJsonSchemaConverter } from '@orpc/zod'
|
|
94
|
+
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
|
|
90
95
|
|
|
91
96
|
const openAPIGenerator = new OpenAPIGenerator({
|
|
92
97
|
schemaConverters: [new ZodToJsonSchemaConverter()],
|
|
@@ -111,7 +116,7 @@ const specFromRouter = await openAPIGenerator.generate(router, {
|
|
|
111
116
|
|
|
112
117
|
```ts
|
|
113
118
|
import { oz } from '@orpc/zod'
|
|
114
|
-
import
|
|
119
|
+
import * as z from 'zod'
|
|
115
120
|
|
|
116
121
|
const InputSchema = oz.openapi(
|
|
117
122
|
z.object({
|
|
@@ -129,12 +134,116 @@ const InputSchema = oz.openapi(
|
|
|
129
134
|
|
|
130
135
|
## Sponsors
|
|
131
136
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
137
|
+
If you find oRPC valuable and would like to support its development, you can do so here: [GitHub Sponsors](https://github.com/sponsors/dinwwwh).
|
|
138
|
+
|
|
139
|
+
### π Platinum Sponsor
|
|
140
|
+
|
|
141
|
+
<table>
|
|
142
|
+
<tr>
|
|
143
|
+
<td align="center"><a href="https://screenshotone.com/?ref=orpc" target="_blank" rel="noopener" title="ScreenshotOne.com"><img src="https://avatars.githubusercontent.com/u/97035603?v=4" width="279" alt="ScreenshotOne.com"/><br />ScreenshotOne.com</a></td>
|
|
144
|
+
</tr>
|
|
145
|
+
</table>
|
|
146
|
+
|
|
147
|
+
### π₯ Silver Sponsor
|
|
148
|
+
|
|
149
|
+
<table>
|
|
150
|
+
<tr>
|
|
151
|
+
<td align="center"><a href="https://misskey.io/?ref=orpc" target="_blank" rel="noopener" title="ζδΈγγ"><img src="https://avatars.githubusercontent.com/u/37681609?u=0dd4c7e4ba937cbb52b068c55914b1d8164dc0c7&v=4" width="209" alt="ζδΈγγ"/><br />ζδΈγγ</a></td>
|
|
152
|
+
<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="209" alt="christ12938"/><br />christ12938</a></td>
|
|
153
|
+
</tr>
|
|
154
|
+
</table>
|
|
155
|
+
|
|
156
|
+
### Generous Sponsors
|
|
157
|
+
|
|
158
|
+
<table>
|
|
159
|
+
<tr>
|
|
160
|
+
<td align="center"><a href="https://github.com/ln-markets?ref=orpc" target="_blank" rel="noopener" title="LN Markets"><img src="https://avatars.githubusercontent.com/u/70597625?v=4" width="167" alt="LN Markets"/><br />LN Markets</a></td>
|
|
161
|
+
</tr>
|
|
162
|
+
</table>
|
|
163
|
+
|
|
164
|
+
### Sponsors
|
|
165
|
+
|
|
166
|
+
<table>
|
|
167
|
+
<tr>
|
|
168
|
+
<td align="center"><a href="https://github.com/hrmcdonald?ref=orpc" target="_blank" rel="noopener" title="Reece McDonald"><img src="https://avatars.githubusercontent.com/u/39349270?v=4" width="139" alt="Reece McDonald"/><br />Reece McDonald</a></td>
|
|
169
|
+
<td align="center"><a href="https://github.com/nicognaW?ref=orpc" target="_blank" rel="noopener" title="nk"><img src="https://avatars.githubusercontent.com/u/66731869?u=4699bda3a9092d3ec34fbd959450767bcc8b8b6d&v=4" width="139" alt="nk"/><br />nk</a></td>
|
|
170
|
+
<td align="center"><a href="https://github.com/supastarter?ref=orpc" target="_blank" rel="noopener" title="supastarter"><img src="https://avatars.githubusercontent.com/u/110960143?v=4" width="139" alt="supastarter"/><br />supastarter</a></td>
|
|
171
|
+
<td align="center"><a href="https://github.com/divmgl?ref=orpc" target="_blank" rel="noopener" title="Dexter Miguel"><img src="https://avatars.githubusercontent.com/u/5452298?u=645993204be8696c085ecf0d228c3062efe2ed65&v=4" width="139" alt="Dexter Miguel"/><br />Dexter Miguel</a></td>
|
|
172
|
+
<td align="center"><a href="https://github.com/herrfugbaum?ref=orpc" target="_blank" rel="noopener" title="herrfugbaum"><img src="https://avatars.githubusercontent.com/u/12859776?u=644dc1666d0220bc0468eb0de3c56b919f635b16&v=4" width="139" alt="herrfugbaum"/><br />herrfugbaum</a></td>
|
|
173
|
+
<td align="center"><a href="https://github.com/ryota-murakami?ref=orpc" target="_blank" rel="noopener" title="Ryota Murakami"><img src="https://avatars.githubusercontent.com/u/5501268?u=599389e03340734325726ca3f8f423c021d47d7f&v=4" width="139" alt="Ryota Murakami"/><br />Ryota Murakami</a></td>
|
|
174
|
+
</tr>
|
|
175
|
+
<tr>
|
|
176
|
+
<td align="center"><a href="https://github.com/dcramer?ref=orpc" target="_blank" rel="noopener" title="David Cramer"><img src="https://avatars.githubusercontent.com/u/23610?v=4" width="139" alt="David Cramer"/><br />David Cramer</a></td>
|
|
177
|
+
<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>
|
|
178
|
+
<td align="center"><a href="https://github.com/happyboy2022?ref=orpc" target="_blank" rel="noopener" title="happyboy"><img src="https://avatars.githubusercontent.com/u/103669586?u=65b49c4b893ed3703909fbb3a7a22313f3f9c121&v=4" width="139" alt="happyboy"/><br />happyboy</a></td>
|
|
179
|
+
<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>
|
|
180
|
+
<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>
|
|
181
|
+
<td align="center"><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="139" alt="Andrew Peters"/><br />Andrew Peters</a></td>
|
|
182
|
+
</tr>
|
|
183
|
+
<tr>
|
|
184
|
+
<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>
|
|
185
|
+
<td align="center"><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="139" alt="Peter Adam"/><br />Peter Adam</a></td>
|
|
186
|
+
<td align="center"><a href="https://github.com/yukimotochern?ref=orpc" target="_blank" rel="noopener" title="Chen, Zhi-Yuan"><img src="https://avatars.githubusercontent.com/u/20896173?u=945c33fc21725e4d566a0d02afc54b136ca1d67a&v=4" width="139" alt="Chen, Zhi-Yuan"/><br />Chen, Zhi-Yuan</a></td>
|
|
187
|
+
<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>
|
|
188
|
+
</tr>
|
|
189
|
+
</table>
|
|
190
|
+
|
|
191
|
+
### Backers
|
|
192
|
+
|
|
193
|
+
<table>
|
|
194
|
+
<tr>
|
|
195
|
+
<td align="center"><a href="https://github.com/rhinodavid?ref=orpc" target="_blank" rel="noopener" title="David Walsh"><img src="https://avatars.githubusercontent.com/u/5778036?u=b5521f07d2f88c3db2a0dae62b5f2f8357214af0&v=4" width="119" alt="David Walsh"/><br />David Walsh</a></td>
|
|
196
|
+
<td align="center"><a href="https://github.com/Robbe95?ref=orpc" target="_blank" rel="noopener" title="Robbe Vaes"><img src="https://avatars.githubusercontent.com/u/44748019?u=e0232402c045ad4eac7cbd217f1f47e083103b89&v=4" width="119" alt="Robbe Vaes"/><br />Robbe Vaes</a></td>
|
|
197
|
+
<td align="center"><a href="https://github.com/aidansunbury?ref=orpc" target="_blank" rel="noopener" title="Aidan Sunbury"><img src="https://avatars.githubusercontent.com/u/64103161?v=4" width="119" alt="Aidan Sunbury"/><br />Aidan Sunbury</a></td>
|
|
198
|
+
<td align="center"><a href="https://github.com/soonoo?ref=orpc" target="_blank" rel="noopener" title="soonoo"><img src="https://avatars.githubusercontent.com/u/5436405?u=5d0b4aa955c87e30e6bda7f0cccae5402da99528&v=4" width="119" alt="soonoo"/><br />soonoo</a></td>
|
|
199
|
+
<td align="center"><a href="https://github.com/kporten?ref=orpc" target="_blank" rel="noopener" title="Kevin Porten"><img src="https://avatars.githubusercontent.com/u/1839345?u=dc2263d5cfe0d927ce1a0be04a1d55dd6b55405c&v=4" width="119" alt="Kevin Porten"/><br />Kevin Porten</a></td>
|
|
200
|
+
<td align="center"><a href="https://github.com/pumpkinlink?ref=orpc" target="_blank" rel="noopener" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&v=4" width="119" alt="Denis"/><br />Denis</a></td>
|
|
201
|
+
<td align="center"><a href="https://github.com/christopher-kapic?ref=orpc" target="_blank" rel="noopener" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&v=4" width="119" alt="Christopher Kapic"/><br />Christopher Kapic</a></td>
|
|
202
|
+
</tr>
|
|
203
|
+
<tr>
|
|
204
|
+
<td align="center"><a href="https://github.com/thomasballinger?ref=orpc" target="_blank" rel="noopener" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&v=4" width="119" alt="Tom Ballinger"/><br />Tom Ballinger</a></td>
|
|
205
|
+
<td align="center"><a href="https://github.com/SSam0419?ref=orpc" target="_blank" rel="noopener" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&v=4" width="119" alt="Sam"/><br />Sam</a></td>
|
|
206
|
+
<td align="center"><a href="https://github.com/Titoine?ref=orpc" target="_blank" rel="noopener" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&v=4" width="119" alt="Titoine"/><br />Titoine</a></td>
|
|
207
|
+
<td align="center"><a href="https://github.com/Mnigos?ref=orpc" target="_blank" rel="noopener" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&v=4" width="119" alt="Igor Makowski"/><br />Igor Makowski</a></td>
|
|
208
|
+
<td align="center"><a href="https://github.com/steelbrain?ref=orpc" target="_blank" rel="noopener" title="Anees Iqbal"><img src="https://avatars.githubusercontent.com/u/4278113?u=22b80b5399eed68ac76cd58b02961b0481f1db11&v=4" width="119" alt="Anees Iqbal"/><br />Anees Iqbal</a></td>
|
|
209
|
+
<td align="center"><a href="https://github.com/hanayashiki?ref=orpc" target="_blank" rel="noopener" title="wang chenyu"><img src="https://avatars.githubusercontent.com/u/26056783?u=98c5ceda64b19874ed2a31515467332ea991e590&v=4" width="119" alt="wang chenyu"/><br />wang chenyu</a></td>
|
|
210
|
+
<td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="119" alt="Alex"/><br />Alex</a></td>
|
|
211
|
+
</tr>
|
|
212
|
+
</table>
|
|
213
|
+
|
|
214
|
+
### Past Sponsors
|
|
215
|
+
|
|
216
|
+
<p>
|
|
217
|
+
<a href="https://github.com/MrMaxie?ref=orpc" target="_blank" rel="noopener" title="Maxie"><img src="https://avatars.githubusercontent.com/u/3857836?u=5e6b57973d4385d655663ffdd836e487856f2984&v=4" width="32" height="32" alt="Maxie" /></a>
|
|
218
|
+
<a href="https://github.com/Stijn-Timmer?ref=orpc" target="_blank" rel="noopener" title="Stijn Timmer"><img src="https://avatars.githubusercontent.com/u/100147665?u=106b2c18e9c98a61861b4ee7fc100f5b9906a6c9&v=4" width="32" height="32" alt="Stijn Timmer" /></a>
|
|
219
|
+
<a href="https://github.com/u1-liquid?ref=orpc" target="_blank" rel="noopener" title="γγγγγ¨γΌγ«γ
"><img src="https://avatars.githubusercontent.com/u/17376330?u=de3353804be889f009f7e0a1582daf04d0ab292d&v=4" width="32" height="32" alt="γγγγγ¨γΌγ«γ
" /></a>
|
|
220
|
+
<a href="https://github.com/zuplo?ref=orpc" target="_blank" rel="noopener" title="Zuplo"><img src="https://avatars.githubusercontent.com/u/85497839?v=4" width="32" height="32" alt="Zuplo" /></a>
|
|
221
|
+
<a href="https://github.com/motopods?ref=orpc" target="_blank" rel="noopener" title="motopods"><img src="https://avatars.githubusercontent.com/u/58200641?u=18833983d65b481ae90a4adec2373064ec58bcf3&v=4" width="32" height="32" alt="motopods" /></a>
|
|
222
|
+
<a href="https://github.com/franciscohermida?ref=orpc" target="_blank" rel="noopener" title="Francisco Hermida"><img src="https://avatars.githubusercontent.com/u/483242?u=bbcbc80eb9d8781ff401f7dafc3b59cd7bea0561&v=4" width="32" height="32" alt="Francisco Hermida" /></a>
|
|
223
|
+
<a href="https://github.com/theoludwig?ref=orpc" target="_blank" rel="noopener" title="ThΓ©o LUDWIG"><img src="https://avatars.githubusercontent.com/u/25207499?u=a6a9653725a2f574c07893748806668e0598cdbe&v=4" width="32" height="32" alt="ThΓ©o LUDWIG" /></a>
|
|
224
|
+
<a href="https://github.com/abhay-ramesh?ref=orpc" target="_blank" rel="noopener" title="Abhay Ramesh"><img src="https://avatars.githubusercontent.com/u/66196314?u=c5c2b0327b26606c2efcfaf17046ab18c3d25c57&v=4" width="32" height="32" alt="Abhay Ramesh" /></a>
|
|
225
|
+
<a href="https://github.com/shr-ink?ref=orpc" target="_blank" rel="noopener" title="shr.ink oΓΌ"><img src="https://avatars.githubusercontent.com/u/139700438?v=4" width="32" height="32" alt="shr.ink oΓΌ" /></a>
|
|
226
|
+
<a href="https://github.com/johngerome?ref=orpc" target="_blank" rel="noopener" title="0x4e32"><img src="https://avatars.githubusercontent.com/u/2002000?u=24e8dd943cfc862aa284d858a023532c75071ade&v=4" width="32" height="32" alt="0x4e32" /></a>
|
|
227
|
+
<a href="https://github.com/yzuyr?ref=orpc" target="_blank" rel="noopener" title="Ryuz"><img src="https://avatars.githubusercontent.com/u/196539378?u=d38374588d219b6748b16406982f6559411466d4&v=4" width="32" height="32" alt="Ryuz" /></a>
|
|
228
|
+
<a href="https://github.com/YiCChi?ref=orpc" target="_blank" rel="noopener" title="yicchi"><img src="https://avatars.githubusercontent.com/u/86967274?u=6c2756f09fe15dd94d572f560e979cd157982852&v=4" width="32" height="32" alt="yicchi" /></a>
|
|
229
|
+
<a href="https://github.com/cloudycotton?ref=orpc" target="_blank" rel="noopener" title="Saksham"><img src="https://avatars.githubusercontent.com/u/168998965?u=9b9634a5aed66a51c1b880663272725b00b92b14&v=4" width="32" height="32" alt="Saksham" /></a>
|
|
230
|
+
<a href="https://github.com/hrynevychroman?ref=orpc" target="_blank" rel="noopener" title="Roman Hrynevych"><img src="https://avatars.githubusercontent.com/u/82209198?u=1a1d111ab3d589855b9cc8a7fefb1b5c6a4fbbaf&v=4" width="32" height="32" alt="Roman Hrynevych" /></a>
|
|
231
|
+
<a href="https://github.com/rokitgg?ref=orpc" target="_blank" rel="noopener" title="rokitg"><img src="https://avatars.githubusercontent.com/u/125133357?u=06c74aefaa2236b06a2e5fba5a5c612339f45912&v=4" width="32" height="32" alt="rokitg" /></a>
|
|
232
|
+
<a href="https://github.com/omarkhatibgg?ref=orpc" target="_blank" rel="noopener" title="Omar Khatib"><img src="https://avatars.githubusercontent.com/u/9054278?u=afbba7331b85c51b8eee4130f5fd31b1017dc919&v=4" width="32" height="32" alt="Omar Khatib" /></a>
|
|
233
|
+
<a href="https://github.com/YuSabo90002?ref=orpc" target="_blank" rel="noopener" title="Yu-Sabo"><img src="https://avatars.githubusercontent.com/u/13120582?v=4" width="32" height="32" alt="Yu-Sabo" /></a>
|
|
234
|
+
<a href="https://github.com/bapspatil?ref=orpc" target="_blank" rel="noopener" title="Bapusaheb Patil"><img src="https://avatars.githubusercontent.com/u/16699418?v=4" width="32" height="32" alt="Bapusaheb Patil" /></a>
|
|
235
|
+
<a href="https://github.com/ripgrim?ref=orpc" target="_blank" rel="noopener" title="grim"><img src="https://avatars.githubusercontent.com/u/75869731?u=b17c42ec2309552fdb822a86b25a2f99146a4d72&v=4" width="32" height="32" alt="grim" /></a>
|
|
236
|
+
<a href="https://github.com/nelsonlaidev?ref=orpc" target="_blank" rel="noopener" title="Nelson Lai"><img src="https://avatars.githubusercontent.com/u/75498339?u=2fc0e0b95dd184c5ffb744df977cb15a18b60672&v=4" width="32" height="32" alt="Nelson Lai" /></a>
|
|
237
|
+
<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>
|
|
238
|
+
<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>
|
|
239
|
+
<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>
|
|
240
|
+
<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>
|
|
241
|
+
<a href="https://github.com/NovakAnton?ref=orpc" target="_blank" rel="noopener" title="Novak Antonijevic"><img src="https://avatars.githubusercontent.com/u/157126729?u=ae49fa22292d55c0434ff0ca008206155b18663b&v=4" width="32" height="32" alt="Novak Antonijevic" /></a>
|
|
242
|
+
<a href="https://github.com/laduniestu?ref=orpc" target="_blank" rel="noopener" title="Laduni Estu Syalwa"><img src="https://avatars.githubusercontent.com/u/44757637?u=a2fc1ea8f7d827a96721176f79d30592d1c48059&v=4" width="32" height="32" alt="Laduni Estu Syalwa" /></a>
|
|
243
|
+
<a href="https://github.com/illarionvk?ref=orpc" target="_blank" rel="noopener" title="Illarion Koperski"><img src="https://avatars.githubusercontent.com/u/5012724?u=7cfa13652f7ac5fb3c56d880e3eb3fbe40c3ea34&v=4" width="32" height="32" alt="Illarion Koperski" /></a>
|
|
244
|
+
<a href="https://github.com/Scrumplex?ref=orpc" target="_blank" rel="noopener" title="Sefa Eyeoglu"><img src="https://avatars.githubusercontent.com/u/11587657?u=ab503582165c0bbff0cca47ce31c9450bb1553c9&v=4" width="32" height="32" alt="Sefa Eyeoglu" /></a>
|
|
136
245
|
</p>
|
|
137
246
|
|
|
138
247
|
## License
|
|
139
248
|
|
|
140
|
-
Distributed under the MIT License. See [LICENSE](https://github.com/
|
|
249
|
+
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,5 +1,5 @@
|
|
|
1
1
|
import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
|
|
2
|
-
import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod';
|
|
2
|
+
import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod/v3';
|
|
3
3
|
import { Context } from '@orpc/server';
|
|
4
4
|
import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
5
5
|
import { AnySchema } from '@orpc/contract';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
|
|
2
|
-
import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod';
|
|
2
|
+
import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod/v3';
|
|
3
3
|
import { Context } from '@orpc/server';
|
|
4
4
|
import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
5
5
|
import { AnySchema } from '@orpc/contract';
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { custom, ZodFirstPartyTypeKind } from 'zod';
|
|
1
|
+
import { custom, ZodFirstPartyTypeKind } from 'zod/v3';
|
|
2
2
|
import wcmatch from 'wildcard-match';
|
|
3
3
|
import { isObject, guard, toArray } from '@orpc/shared';
|
|
4
|
+
import { JsonSchemaXNativeType } from '@orpc/json-schema';
|
|
4
5
|
import { JSONSchemaFormat } from '@orpc/openapi';
|
|
5
6
|
import escapeStringRegexp from 'escape-string-regexp';
|
|
6
7
|
|
|
@@ -128,7 +129,7 @@ class ZodSmartCoercionPlugin {
|
|
|
128
129
|
options.clientInterceptors ??= [];
|
|
129
130
|
options.clientInterceptors.unshift((options2) => {
|
|
130
131
|
const inputSchema = options2.procedure["~orpc"].inputSchema;
|
|
131
|
-
if (!inputSchema || inputSchema["~standard"].vendor !== "zod") {
|
|
132
|
+
if (!inputSchema || inputSchema["~standard"].vendor !== "zod" || "_zod" in inputSchema) {
|
|
132
133
|
return options2.next();
|
|
133
134
|
}
|
|
134
135
|
const coercedInput = zodCoerceInternal(inputSchema, options2.input);
|
|
@@ -400,7 +401,7 @@ class ZodToJsonSchemaConverter {
|
|
|
400
401
|
this.anyJsonSchema = options.anyJsonSchema ?? {};
|
|
401
402
|
}
|
|
402
403
|
condition(schema) {
|
|
403
|
-
return schema !== void 0 && schema["~standard"].vendor === "zod";
|
|
404
|
+
return schema !== void 0 && schema["~standard"].vendor === "zod" && !("_zod" in schema);
|
|
404
405
|
}
|
|
405
406
|
convert(schema, options, lazyDepth = 0, isHandledCustomJSONSchema = false, isHandledZodDescription = false, structureDepth = 0) {
|
|
406
407
|
const def = schema._def;
|
|
@@ -563,7 +564,11 @@ class ZodToJsonSchemaConverter {
|
|
|
563
564
|
return [true, json];
|
|
564
565
|
}
|
|
565
566
|
case ZodFirstPartyTypeKind.ZodBigInt: {
|
|
566
|
-
const json = {
|
|
567
|
+
const json = {
|
|
568
|
+
"type": "string",
|
|
569
|
+
"pattern": "^-?[0-9]+$",
|
|
570
|
+
"x-native-type": JsonSchemaXNativeType.BigInt
|
|
571
|
+
};
|
|
567
572
|
return [true, json];
|
|
568
573
|
}
|
|
569
574
|
case ZodFirstPartyTypeKind.ZodNaN: {
|
|
@@ -573,7 +578,11 @@ class ZodToJsonSchemaConverter {
|
|
|
573
578
|
return [true, { type: "boolean" }];
|
|
574
579
|
}
|
|
575
580
|
case ZodFirstPartyTypeKind.ZodDate: {
|
|
576
|
-
const schema2 = {
|
|
581
|
+
const schema2 = {
|
|
582
|
+
"type": "string",
|
|
583
|
+
"format": JSONSchemaFormat.DateTime,
|
|
584
|
+
"x-native-type": JsonSchemaXNativeType.Date
|
|
585
|
+
};
|
|
577
586
|
return [true, schema2];
|
|
578
587
|
}
|
|
579
588
|
case ZodFirstPartyTypeKind.ZodNull: {
|
|
@@ -596,11 +605,20 @@ class ZodToJsonSchemaConverter {
|
|
|
596
605
|
}
|
|
597
606
|
case ZodFirstPartyTypeKind.ZodEnum: {
|
|
598
607
|
const schema_ = schema;
|
|
599
|
-
|
|
608
|
+
const values = schema_._def.values;
|
|
609
|
+
const json = { enum: values, type: "string" };
|
|
610
|
+
return [true, json];
|
|
600
611
|
}
|
|
601
612
|
case ZodFirstPartyTypeKind.ZodNativeEnum: {
|
|
602
613
|
const schema_ = schema;
|
|
603
|
-
|
|
614
|
+
const values = getEnumValues(schema_._def.values);
|
|
615
|
+
const json = { enum: values };
|
|
616
|
+
if (values.every((v) => typeof v === "string")) {
|
|
617
|
+
json.type = "string";
|
|
618
|
+
} else if (values.every((v) => Number.isFinite(v))) {
|
|
619
|
+
json.type = "number";
|
|
620
|
+
}
|
|
621
|
+
return [true, json];
|
|
604
622
|
}
|
|
605
623
|
case ZodFirstPartyTypeKind.ZodArray: {
|
|
606
624
|
const schema_ = schema;
|
|
@@ -681,7 +699,11 @@ class ZodToJsonSchemaConverter {
|
|
|
681
699
|
}
|
|
682
700
|
case ZodFirstPartyTypeKind.ZodSet: {
|
|
683
701
|
const schema_ = schema;
|
|
684
|
-
const json = {
|
|
702
|
+
const json = {
|
|
703
|
+
"type": "array",
|
|
704
|
+
"uniqueItems": true,
|
|
705
|
+
"x-native-type": JsonSchemaXNativeType.Set
|
|
706
|
+
};
|
|
685
707
|
const [itemRequired, itemJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false, structureDepth + 1);
|
|
686
708
|
json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
|
|
687
709
|
return [true, json];
|
|
@@ -690,9 +712,9 @@ class ZodToJsonSchemaConverter {
|
|
|
690
712
|
const schema_ = schema;
|
|
691
713
|
const [keyRequired, keyJson] = this.convert(schema_._def.keyType, options, lazyDepth, false, false, structureDepth + 1);
|
|
692
714
|
const [valueRequired, valueJson] = this.convert(schema_._def.valueType, options, lazyDepth, false, false, structureDepth + 1);
|
|
693
|
-
|
|
694
|
-
type: "array",
|
|
695
|
-
items: {
|
|
715
|
+
const json = {
|
|
716
|
+
"type": "array",
|
|
717
|
+
"items": {
|
|
696
718
|
type: "array",
|
|
697
719
|
prefixItems: [
|
|
698
720
|
this.#toArrayItemJsonSchema(keyRequired, keyJson, options.strategy),
|
|
@@ -700,8 +722,10 @@ class ZodToJsonSchemaConverter {
|
|
|
700
722
|
],
|
|
701
723
|
maxItems: 2,
|
|
702
724
|
minItems: 2
|
|
703
|
-
}
|
|
704
|
-
|
|
725
|
+
},
|
|
726
|
+
"x-native-type": JsonSchemaXNativeType.Map
|
|
727
|
+
};
|
|
728
|
+
return [true, json];
|
|
705
729
|
}
|
|
706
730
|
case ZodFirstPartyTypeKind.ZodUnion:
|
|
707
731
|
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
|
|
@@ -709,7 +733,7 @@ class ZodToJsonSchemaConverter {
|
|
|
709
733
|
const anyOf = [];
|
|
710
734
|
let required = true;
|
|
711
735
|
for (const item of schema_._def.options) {
|
|
712
|
-
const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth);
|
|
736
|
+
const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth + 1);
|
|
713
737
|
if (!itemRequired) {
|
|
714
738
|
required = false;
|
|
715
739
|
if (itemJson !== this.unsupportedJsonSchema) {
|
|
@@ -719,9 +743,6 @@ class ZodToJsonSchemaConverter {
|
|
|
719
743
|
anyOf.push(itemJson);
|
|
720
744
|
}
|
|
721
745
|
}
|
|
722
|
-
if (anyOf.length === 1) {
|
|
723
|
-
return [required, anyOf[0]];
|
|
724
|
-
}
|
|
725
746
|
return [required, { anyOf }];
|
|
726
747
|
}
|
|
727
748
|
case ZodFirstPartyTypeKind.ZodIntersection: {
|
|
@@ -729,7 +750,7 @@ class ZodToJsonSchemaConverter {
|
|
|
729
750
|
const allOf = [];
|
|
730
751
|
let required = false;
|
|
731
752
|
for (const item of [schema_._def.left, schema_._def.right]) {
|
|
732
|
-
const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth);
|
|
753
|
+
const [itemRequired, itemJson] = this.convert(item, options, lazyDepth, false, false, structureDepth + 1);
|
|
733
754
|
allOf.push(itemJson);
|
|
734
755
|
if (itemRequired) {
|
|
735
756
|
required = true;
|
|
@@ -808,12 +829,17 @@ class ZodToJsonSchemaConverter {
|
|
|
808
829
|
}
|
|
809
830
|
case "regexp": {
|
|
810
831
|
return {
|
|
811
|
-
type: "string",
|
|
812
|
-
pattern: "^\\/(.*)\\/([a-z]*)$"
|
|
832
|
+
"type": "string",
|
|
833
|
+
"pattern": "^\\/(.*)\\/([a-z]*)$",
|
|
834
|
+
"x-native-type": JsonSchemaXNativeType.RegExp
|
|
813
835
|
};
|
|
814
836
|
}
|
|
815
837
|
case "url": {
|
|
816
|
-
return {
|
|
838
|
+
return {
|
|
839
|
+
"type": "string",
|
|
840
|
+
"format": JSONSchemaFormat.URI,
|
|
841
|
+
"x-native-type": JsonSchemaXNativeType.Url
|
|
842
|
+
};
|
|
817
843
|
}
|
|
818
844
|
}
|
|
819
845
|
}
|
|
@@ -827,6 +853,11 @@ class ZodToJsonSchemaConverter {
|
|
|
827
853
|
return strategy === "input" ? { anyOf: [schema, this.unsupportedJsonSchema] } : { anyOf: [schema, { type: "null" }] };
|
|
828
854
|
}
|
|
829
855
|
}
|
|
856
|
+
function getEnumValues(entries) {
|
|
857
|
+
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
858
|
+
const values = Object.entries(entries).filter(([k, _]) => !numericValues.includes(+k)).map(([_, v]) => v);
|
|
859
|
+
return values;
|
|
860
|
+
}
|
|
830
861
|
|
|
831
862
|
const oz = {
|
|
832
863
|
file,
|
package/dist/zod4/index.d.mts
CHANGED
|
@@ -6,12 +6,15 @@ import { Interceptor } from '@orpc/shared';
|
|
|
6
6
|
import * as zod_v4_core from 'zod/v4/core';
|
|
7
7
|
import { $ZodType, $input, $output } from 'zod/v4/core';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use [Smart Coercion Plugin](https://orpc.dev/docs/openapi/plugins/smart-coercion) instead.
|
|
11
|
+
*/
|
|
9
12
|
declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
|
|
10
13
|
#private;
|
|
11
14
|
init(options: StandardHandlerOptions<TContext>): void;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
interface
|
|
17
|
+
interface ZodToJsonSchemaConverterOptions {
|
|
15
18
|
/**
|
|
16
19
|
* Max depth of lazy type.
|
|
17
20
|
*
|
|
@@ -56,7 +59,7 @@ interface experimental_ZodToJsonSchemaOptions {
|
|
|
56
59
|
jsonSchema: Exclude<JSONSchema, boolean>
|
|
57
60
|
]>[];
|
|
58
61
|
}
|
|
59
|
-
declare class
|
|
62
|
+
declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
|
|
60
63
|
#private;
|
|
61
64
|
private readonly maxLazyDepth;
|
|
62
65
|
private readonly maxStructureDepth;
|
|
@@ -64,7 +67,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
|
|
|
64
67
|
private readonly unsupportedJsonSchema;
|
|
65
68
|
private readonly undefinedJsonSchema;
|
|
66
69
|
private readonly interceptors;
|
|
67
|
-
constructor(options?:
|
|
70
|
+
constructor(options?: ZodToJsonSchemaConverterOptions);
|
|
68
71
|
condition(schema: AnySchema | undefined): boolean;
|
|
69
72
|
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
|
|
70
73
|
}
|
|
@@ -86,7 +89,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
|
|
|
86
89
|
* })
|
|
87
90
|
* ```
|
|
88
91
|
*/
|
|
89
|
-
declare const
|
|
92
|
+
declare const JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
90
93
|
$anchor?: string;
|
|
91
94
|
$comment?: string;
|
|
92
95
|
$defs?: Record<string, JSONSchema>;
|
|
@@ -165,7 +168,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
|
165
168
|
* })
|
|
166
169
|
* ```
|
|
167
170
|
*/
|
|
168
|
-
declare const
|
|
171
|
+
declare const JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
169
172
|
$anchor?: string;
|
|
170
173
|
$comment?: string;
|
|
171
174
|
$defs?: Record<string, JSONSchema>;
|
|
@@ -244,7 +247,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<
|
|
|
244
247
|
* })
|
|
245
248
|
* ```
|
|
246
249
|
*/
|
|
247
|
-
declare const
|
|
250
|
+
declare const JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
248
251
|
$anchor?: string;
|
|
249
252
|
$comment?: string;
|
|
250
253
|
$defs?: Record<string, JSONSchema>;
|
|
@@ -307,5 +310,5 @@ declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry
|
|
|
307
310
|
writeOnly?: boolean;
|
|
308
311
|
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
|
309
312
|
|
|
310
|
-
export {
|
|
311
|
-
export type {
|
|
313
|
+
export { JSON_SCHEMA_INPUT_REGISTRY, JSON_SCHEMA_OUTPUT_REGISTRY, JSON_SCHEMA_REGISTRY, ZodToJsonSchemaConverter, experimental_ZodSmartCoercionPlugin };
|
|
314
|
+
export type { ZodToJsonSchemaConverterOptions };
|
package/dist/zod4/index.d.ts
CHANGED
|
@@ -6,12 +6,15 @@ import { Interceptor } from '@orpc/shared';
|
|
|
6
6
|
import * as zod_v4_core from 'zod/v4/core';
|
|
7
7
|
import { $ZodType, $input, $output } from 'zod/v4/core';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use [Smart Coercion Plugin](https://orpc.dev/docs/openapi/plugins/smart-coercion) instead.
|
|
11
|
+
*/
|
|
9
12
|
declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
|
|
10
13
|
#private;
|
|
11
14
|
init(options: StandardHandlerOptions<TContext>): void;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
interface
|
|
17
|
+
interface ZodToJsonSchemaConverterOptions {
|
|
15
18
|
/**
|
|
16
19
|
* Max depth of lazy type.
|
|
17
20
|
*
|
|
@@ -56,7 +59,7 @@ interface experimental_ZodToJsonSchemaOptions {
|
|
|
56
59
|
jsonSchema: Exclude<JSONSchema, boolean>
|
|
57
60
|
]>[];
|
|
58
61
|
}
|
|
59
|
-
declare class
|
|
62
|
+
declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
|
|
60
63
|
#private;
|
|
61
64
|
private readonly maxLazyDepth;
|
|
62
65
|
private readonly maxStructureDepth;
|
|
@@ -64,7 +67,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
|
|
|
64
67
|
private readonly unsupportedJsonSchema;
|
|
65
68
|
private readonly undefinedJsonSchema;
|
|
66
69
|
private readonly interceptors;
|
|
67
|
-
constructor(options?:
|
|
70
|
+
constructor(options?: ZodToJsonSchemaConverterOptions);
|
|
68
71
|
condition(schema: AnySchema | undefined): boolean;
|
|
69
72
|
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
|
|
70
73
|
}
|
|
@@ -86,7 +89,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
|
|
|
86
89
|
* })
|
|
87
90
|
* ```
|
|
88
91
|
*/
|
|
89
|
-
declare const
|
|
92
|
+
declare const JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
90
93
|
$anchor?: string;
|
|
91
94
|
$comment?: string;
|
|
92
95
|
$defs?: Record<string, JSONSchema>;
|
|
@@ -165,7 +168,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
|
165
168
|
* })
|
|
166
169
|
* ```
|
|
167
170
|
*/
|
|
168
|
-
declare const
|
|
171
|
+
declare const JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
169
172
|
$anchor?: string;
|
|
170
173
|
$comment?: string;
|
|
171
174
|
$defs?: Record<string, JSONSchema>;
|
|
@@ -244,7 +247,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<
|
|
|
244
247
|
* })
|
|
245
248
|
* ```
|
|
246
249
|
*/
|
|
247
|
-
declare const
|
|
250
|
+
declare const JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
248
251
|
$anchor?: string;
|
|
249
252
|
$comment?: string;
|
|
250
253
|
$defs?: Record<string, JSONSchema>;
|
|
@@ -307,5 +310,5 @@ declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry
|
|
|
307
310
|
writeOnly?: boolean;
|
|
308
311
|
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
|
309
312
|
|
|
310
|
-
export {
|
|
311
|
-
export type {
|
|
313
|
+
export { JSON_SCHEMA_INPUT_REGISTRY, JSON_SCHEMA_OUTPUT_REGISTRY, JSON_SCHEMA_REGISTRY, ZodToJsonSchemaConverter, experimental_ZodSmartCoercionPlugin };
|
|
314
|
+
export type { ZodToJsonSchemaConverterOptions };
|
package/dist/zod4/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isObject, guard, intercept, toArray } from '@orpc/shared';
|
|
2
|
+
import { JsonSchemaXNativeType } from '@orpc/json-schema';
|
|
2
3
|
import { JSONSchemaFormat, JSONSchemaContentEncoding } from '@orpc/openapi';
|
|
3
4
|
import { registry, globalRegistry } from 'zod/v4/core';
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ class experimental_ZodSmartCoercionPlugin {
|
|
|
7
8
|
options.clientInterceptors ??= [];
|
|
8
9
|
options.clientInterceptors.unshift((options2) => {
|
|
9
10
|
const inputSchema = options2.procedure["~orpc"].inputSchema;
|
|
10
|
-
if (!inputSchema || inputSchema["~standard"].vendor !== "zod") {
|
|
11
|
+
if (!inputSchema || inputSchema["~standard"].vendor !== "zod" || !("_zod" in inputSchema)) {
|
|
11
12
|
return options2.next();
|
|
12
13
|
}
|
|
13
14
|
const coercedInput = this.#coerce(inputSchema, options2.input);
|
|
@@ -268,11 +269,11 @@ class experimental_ZodSmartCoercionPlugin {
|
|
|
268
269
|
}
|
|
269
270
|
}
|
|
270
271
|
|
|
271
|
-
const
|
|
272
|
-
const
|
|
273
|
-
const
|
|
272
|
+
const JSON_SCHEMA_REGISTRY = registry();
|
|
273
|
+
const JSON_SCHEMA_INPUT_REGISTRY = registry();
|
|
274
|
+
const JSON_SCHEMA_OUTPUT_REGISTRY = registry();
|
|
274
275
|
|
|
275
|
-
class
|
|
276
|
+
class ZodToJsonSchemaConverter {
|
|
276
277
|
maxLazyDepth;
|
|
277
278
|
maxStructureDepth;
|
|
278
279
|
anyJsonSchema;
|
|
@@ -288,7 +289,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
|
288
289
|
this.interceptors = options.interceptors ?? [];
|
|
289
290
|
}
|
|
290
291
|
condition(schema) {
|
|
291
|
-
return schema !== void 0 && schema["~standard"].vendor === "zod";
|
|
292
|
+
return schema !== void 0 && schema["~standard"].vendor === "zod" && "_zod" in schema;
|
|
292
293
|
}
|
|
293
294
|
convert(schema, options) {
|
|
294
295
|
return this.#convert(schema, options, 0, 0);
|
|
@@ -376,10 +377,18 @@ class experimental_ZodToJsonSchemaConverter {
|
|
|
376
377
|
return [true, { type: "boolean" }];
|
|
377
378
|
}
|
|
378
379
|
case "bigint": {
|
|
379
|
-
return [true, {
|
|
380
|
+
return [true, {
|
|
381
|
+
"type": "string",
|
|
382
|
+
"pattern": "^-?[0-9]+$",
|
|
383
|
+
"x-native-type": JsonSchemaXNativeType.BigInt
|
|
384
|
+
}];
|
|
380
385
|
}
|
|
381
386
|
case "date": {
|
|
382
|
-
return [true, {
|
|
387
|
+
return [true, {
|
|
388
|
+
"type": "string",
|
|
389
|
+
"format": JSONSchemaFormat.DateTime,
|
|
390
|
+
"x-native-type": JsonSchemaXNativeType.Date
|
|
391
|
+
}];
|
|
383
392
|
}
|
|
384
393
|
case "null": {
|
|
385
394
|
return [true, { type: "null" }];
|
|
@@ -437,7 +446,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
|
437
446
|
const anyOf = [];
|
|
438
447
|
let required = true;
|
|
439
448
|
for (const item of union._zod.def.options) {
|
|
440
|
-
const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2, structureDepth);
|
|
449
|
+
const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2, structureDepth + 1);
|
|
441
450
|
if (!itemRequired) {
|
|
442
451
|
required = false;
|
|
443
452
|
}
|
|
@@ -451,14 +460,14 @@ class experimental_ZodToJsonSchemaConverter {
|
|
|
451
460
|
}
|
|
452
461
|
}
|
|
453
462
|
}
|
|
454
|
-
return [required,
|
|
463
|
+
return [required, { anyOf }];
|
|
455
464
|
}
|
|
456
465
|
case "intersection": {
|
|
457
466
|
const intersection = schema2;
|
|
458
467
|
const json = { allOf: [] };
|
|
459
468
|
let required = false;
|
|
460
469
|
for (const item of [intersection._zod.def.left, intersection._zod.def.right]) {
|
|
461
|
-
const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2, structureDepth);
|
|
470
|
+
const [itemRequired, itemJson] = this.#convert(item, options2, lazyDepth2, structureDepth + 1);
|
|
462
471
|
json.allOf.push(itemJson);
|
|
463
472
|
if (itemRequired) {
|
|
464
473
|
required = true;
|
|
@@ -494,8 +503,8 @@ class experimental_ZodToJsonSchemaConverter {
|
|
|
494
503
|
case "map": {
|
|
495
504
|
const map = schema2;
|
|
496
505
|
return [true, {
|
|
497
|
-
type: "array",
|
|
498
|
-
items: {
|
|
506
|
+
"type": "array",
|
|
507
|
+
"items": {
|
|
499
508
|
type: "array",
|
|
500
509
|
prefixItems: [
|
|
501
510
|
this.#handleArrayItemJsonSchema(this.#convert(map._zod.def.keyType, options2, lazyDepth2, structureDepth + 1), options2),
|
|
@@ -503,20 +512,29 @@ class experimental_ZodToJsonSchemaConverter {
|
|
|
503
512
|
],
|
|
504
513
|
maxItems: 2,
|
|
505
514
|
minItems: 2
|
|
506
|
-
}
|
|
515
|
+
},
|
|
516
|
+
"x-native-type": JsonSchemaXNativeType.Map
|
|
507
517
|
}];
|
|
508
518
|
}
|
|
509
519
|
case "set": {
|
|
510
520
|
const set = schema2;
|
|
511
521
|
return [true, {
|
|
512
|
-
type: "array",
|
|
513
|
-
uniqueItems: true,
|
|
514
|
-
items: this.#handleArrayItemJsonSchema(this.#convert(set._zod.def.valueType, options2, lazyDepth2, structureDepth + 1), options2)
|
|
522
|
+
"type": "array",
|
|
523
|
+
"uniqueItems": true,
|
|
524
|
+
"items": this.#handleArrayItemJsonSchema(this.#convert(set._zod.def.valueType, options2, lazyDepth2, structureDepth + 1), options2),
|
|
525
|
+
"x-native-type": JsonSchemaXNativeType.Set
|
|
515
526
|
}];
|
|
516
527
|
}
|
|
517
528
|
case "enum": {
|
|
518
529
|
const enum_ = schema2;
|
|
519
|
-
|
|
530
|
+
const values = getEnumValues(enum_._zod.def.entries);
|
|
531
|
+
const json = { enum: values };
|
|
532
|
+
if (values.every((v) => typeof v === "string")) {
|
|
533
|
+
json.type = "string";
|
|
534
|
+
} else if (values.every((v) => Number.isFinite(v))) {
|
|
535
|
+
json.type = "number";
|
|
536
|
+
}
|
|
537
|
+
return [true, json];
|
|
520
538
|
}
|
|
521
539
|
case "literal": {
|
|
522
540
|
const literal = schema2;
|
|
@@ -580,7 +598,13 @@ class experimental_ZodToJsonSchemaConverter {
|
|
|
580
598
|
}
|
|
581
599
|
case "pipe": {
|
|
582
600
|
const pipe = schema2;
|
|
583
|
-
return this.#convert(
|
|
601
|
+
return this.#convert(
|
|
602
|
+
// prefer out schema when in schema is preprocess/transform
|
|
603
|
+
options2.strategy === "input" && pipe._zod.def.in._zod.def.type !== "transform" ? pipe._zod.def.in : pipe._zod.def.out,
|
|
604
|
+
options2,
|
|
605
|
+
lazyDepth2,
|
|
606
|
+
structureDepth
|
|
607
|
+
);
|
|
584
608
|
}
|
|
585
609
|
case "readonly": {
|
|
586
610
|
const readonly_ = schema2;
|
|
@@ -616,18 +640,19 @@ class experimental_ZodToJsonSchemaConverter {
|
|
|
616
640
|
);
|
|
617
641
|
}
|
|
618
642
|
#getCustomJsonSchema(schema, options) {
|
|
619
|
-
if (options.strategy === "input" &&
|
|
620
|
-
return
|
|
643
|
+
if (options.strategy === "input" && JSON_SCHEMA_INPUT_REGISTRY.has(schema)) {
|
|
644
|
+
return JSON_SCHEMA_INPUT_REGISTRY.get(schema);
|
|
621
645
|
}
|
|
622
|
-
if (options.strategy === "output" &&
|
|
623
|
-
return
|
|
646
|
+
if (options.strategy === "output" && JSON_SCHEMA_OUTPUT_REGISTRY.has(schema)) {
|
|
647
|
+
return JSON_SCHEMA_OUTPUT_REGISTRY.get(schema);
|
|
624
648
|
}
|
|
625
|
-
if (
|
|
626
|
-
return
|
|
649
|
+
if (JSON_SCHEMA_REGISTRY.has(schema)) {
|
|
650
|
+
return JSON_SCHEMA_REGISTRY.get(schema);
|
|
627
651
|
}
|
|
628
652
|
const global = globalRegistry.get(schema);
|
|
629
653
|
if (global) {
|
|
630
654
|
return {
|
|
655
|
+
title: global.title,
|
|
631
656
|
description: global.description,
|
|
632
657
|
examples: Array.isArray(global.examples) ? global.examples : void 0
|
|
633
658
|
};
|
|
@@ -664,5 +689,10 @@ class experimental_ZodToJsonSchemaConverter {
|
|
|
664
689
|
return Object.values(JSONSchemaContentEncoding).includes(contentEncoding) ? contentEncoding : void 0;
|
|
665
690
|
}
|
|
666
691
|
}
|
|
692
|
+
function getEnumValues(entries) {
|
|
693
|
+
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
694
|
+
const values = Object.entries(entries).filter(([k, _]) => !numericValues.includes(+k)).map(([_, v]) => v);
|
|
695
|
+
return values;
|
|
696
|
+
}
|
|
667
697
|
|
|
668
|
-
export {
|
|
698
|
+
export { JSON_SCHEMA_INPUT_REGISTRY, JSON_SCHEMA_OUTPUT_REGISTRY, JSON_SCHEMA_REGISTRY, ZodToJsonSchemaConverter, experimental_ZodSmartCoercionPlugin };
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/zod",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.b6b8746",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"homepage": "https://orpc.
|
|
6
|
+
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/
|
|
9
|
+
"url": "git+https://github.com/middleapi/orpc.git",
|
|
10
10
|
"directory": "packages/zod"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
|
-
"unnoq",
|
|
14
13
|
"orpc"
|
|
15
14
|
],
|
|
16
15
|
"exports": {
|
|
@@ -29,19 +28,19 @@
|
|
|
29
28
|
"dist"
|
|
30
29
|
],
|
|
31
30
|
"peerDependencies": {
|
|
32
|
-
"zod": ">=3.
|
|
33
|
-
"@orpc/contract": "0.0.0-next.
|
|
34
|
-
"@orpc/server": "0.0.0-next.
|
|
31
|
+
"zod": ">=3.25.0",
|
|
32
|
+
"@orpc/contract": "0.0.0-next.b6b8746",
|
|
33
|
+
"@orpc/server": "0.0.0-next.b6b8746"
|
|
35
34
|
},
|
|
36
35
|
"dependencies": {
|
|
37
36
|
"escape-string-regexp": "^5.0.0",
|
|
38
|
-
"wildcard-match": "^5.1.
|
|
39
|
-
"@orpc/
|
|
40
|
-
"@orpc/
|
|
37
|
+
"wildcard-match": "^5.1.4",
|
|
38
|
+
"@orpc/openapi": "0.0.0-next.b6b8746",
|
|
39
|
+
"@orpc/shared": "0.0.0-next.b6b8746",
|
|
40
|
+
"@orpc/json-schema": "0.0.0-next.b6b8746"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"zod": "^3.
|
|
44
|
-
"zod-to-json-schema": "^3.24.5"
|
|
43
|
+
"zod": "^4.3.6"
|
|
45
44
|
},
|
|
46
45
|
"scripts": {
|
|
47
46
|
"build": "unbuild",
|