@orpc/zod 0.0.0-next.f356b86 → 0.0.0-next.f437dcb
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 +7 -5
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +3 -3
- package/dist/zod4/index.d.mts +8 -8
- package/dist/zod4/index.d.ts +8 -8
- package/dist/zod4/index.mjs +14 -13
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
31
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
32
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
-
-
|
|
33
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
34
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
34
35
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
36
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
37
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -38,7 +39,6 @@
|
|
|
38
39
|
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
40
|
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
41
|
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
-
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
42
42
|
|
|
43
43
|
## Documentation
|
|
44
44
|
|
|
@@ -50,9 +50,11 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
50
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
51
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
52
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
53
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
53
54
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
54
55
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
55
56
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
57
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
56
58
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
57
59
|
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
58
60
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
@@ -72,7 +74,7 @@ More schemas that [Zod](https://zod.dev/) doesn't support yet, and provides `Zod
|
|
|
72
74
|
|
|
73
75
|
```ts
|
|
74
76
|
import { oz } from '@orpc/zod'
|
|
75
|
-
import { z } from 'zod'
|
|
77
|
+
import { z } from 'zod/v3'
|
|
76
78
|
|
|
77
79
|
const Example = z.object({
|
|
78
80
|
url: oz.url(),
|
|
@@ -86,7 +88,7 @@ const Example = z.object({
|
|
|
86
88
|
|
|
87
89
|
```ts
|
|
88
90
|
import { OpenAPIGenerator } from '@orpc/openapi'
|
|
89
|
-
import { ZodToJsonSchemaConverter } from '@orpc/zod'
|
|
91
|
+
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
|
|
90
92
|
|
|
91
93
|
const openAPIGenerator = new OpenAPIGenerator({
|
|
92
94
|
schemaConverters: [new ZodToJsonSchemaConverter()],
|
|
@@ -111,7 +113,7 @@ const specFromRouter = await openAPIGenerator.generate(router, {
|
|
|
111
113
|
|
|
112
114
|
```ts
|
|
113
115
|
import { oz } from '@orpc/zod'
|
|
114
|
-
import
|
|
116
|
+
import * as z from 'zod'
|
|
115
117
|
|
|
116
118
|
const InputSchema = oz.openapi(
|
|
117
119
|
z.object({
|
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,4 +1,4 @@
|
|
|
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
4
|
import { JsonSchemaXNativeType } from '@orpc/json-schema';
|
|
@@ -129,7 +129,7 @@ class ZodSmartCoercionPlugin {
|
|
|
129
129
|
options.clientInterceptors ??= [];
|
|
130
130
|
options.clientInterceptors.unshift((options2) => {
|
|
131
131
|
const inputSchema = options2.procedure["~orpc"].inputSchema;
|
|
132
|
-
if (!inputSchema || inputSchema["~standard"].vendor !== "zod") {
|
|
132
|
+
if (!inputSchema || inputSchema["~standard"].vendor !== "zod" || "_zod" in inputSchema) {
|
|
133
133
|
return options2.next();
|
|
134
134
|
}
|
|
135
135
|
const coercedInput = zodCoerceInternal(inputSchema, options2.input);
|
|
@@ -401,7 +401,7 @@ class ZodToJsonSchemaConverter {
|
|
|
401
401
|
this.anyJsonSchema = options.anyJsonSchema ?? {};
|
|
402
402
|
}
|
|
403
403
|
condition(schema) {
|
|
404
|
-
return schema !== void 0 && schema["~standard"].vendor === "zod";
|
|
404
|
+
return schema !== void 0 && schema["~standard"].vendor === "zod" && !("_zod" in schema);
|
|
405
405
|
}
|
|
406
406
|
convert(schema, options, lazyDepth = 0, isHandledCustomJSONSchema = false, isHandledZodDescription = false, structureDepth = 0) {
|
|
407
407
|
const def = schema._def;
|
package/dist/zod4/index.d.mts
CHANGED
|
@@ -14,7 +14,7 @@ declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> impl
|
|
|
14
14
|
init(options: StandardHandlerOptions<TContext>): void;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
interface
|
|
17
|
+
interface ZodToJsonSchemaConverterOptions {
|
|
18
18
|
/**
|
|
19
19
|
* Max depth of lazy type.
|
|
20
20
|
*
|
|
@@ -59,7 +59,7 @@ interface experimental_ZodToJsonSchemaOptions {
|
|
|
59
59
|
jsonSchema: Exclude<JSONSchema, boolean>
|
|
60
60
|
]>[];
|
|
61
61
|
}
|
|
62
|
-
declare class
|
|
62
|
+
declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
|
|
63
63
|
#private;
|
|
64
64
|
private readonly maxLazyDepth;
|
|
65
65
|
private readonly maxStructureDepth;
|
|
@@ -67,7 +67,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
|
|
|
67
67
|
private readonly unsupportedJsonSchema;
|
|
68
68
|
private readonly undefinedJsonSchema;
|
|
69
69
|
private readonly interceptors;
|
|
70
|
-
constructor(options?:
|
|
70
|
+
constructor(options?: ZodToJsonSchemaConverterOptions);
|
|
71
71
|
condition(schema: AnySchema | undefined): boolean;
|
|
72
72
|
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
|
|
73
73
|
}
|
|
@@ -89,7 +89,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
|
|
|
89
89
|
* })
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
|
-
declare const
|
|
92
|
+
declare const JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
93
93
|
$anchor?: string;
|
|
94
94
|
$comment?: string;
|
|
95
95
|
$defs?: Record<string, JSONSchema>;
|
|
@@ -168,7 +168,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
|
168
168
|
* })
|
|
169
169
|
* ```
|
|
170
170
|
*/
|
|
171
|
-
declare const
|
|
171
|
+
declare const JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
172
172
|
$anchor?: string;
|
|
173
173
|
$comment?: string;
|
|
174
174
|
$defs?: Record<string, JSONSchema>;
|
|
@@ -247,7 +247,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<
|
|
|
247
247
|
* })
|
|
248
248
|
* ```
|
|
249
249
|
*/
|
|
250
|
-
declare const
|
|
250
|
+
declare const JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
251
251
|
$anchor?: string;
|
|
252
252
|
$comment?: string;
|
|
253
253
|
$defs?: Record<string, JSONSchema>;
|
|
@@ -310,5 +310,5 @@ declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry
|
|
|
310
310
|
writeOnly?: boolean;
|
|
311
311
|
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
|
312
312
|
|
|
313
|
-
export {
|
|
314
|
-
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
|
@@ -14,7 +14,7 @@ declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> impl
|
|
|
14
14
|
init(options: StandardHandlerOptions<TContext>): void;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
interface
|
|
17
|
+
interface ZodToJsonSchemaConverterOptions {
|
|
18
18
|
/**
|
|
19
19
|
* Max depth of lazy type.
|
|
20
20
|
*
|
|
@@ -59,7 +59,7 @@ interface experimental_ZodToJsonSchemaOptions {
|
|
|
59
59
|
jsonSchema: Exclude<JSONSchema, boolean>
|
|
60
60
|
]>[];
|
|
61
61
|
}
|
|
62
|
-
declare class
|
|
62
|
+
declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
|
|
63
63
|
#private;
|
|
64
64
|
private readonly maxLazyDepth;
|
|
65
65
|
private readonly maxStructureDepth;
|
|
@@ -67,7 +67,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
|
|
|
67
67
|
private readonly unsupportedJsonSchema;
|
|
68
68
|
private readonly undefinedJsonSchema;
|
|
69
69
|
private readonly interceptors;
|
|
70
|
-
constructor(options?:
|
|
70
|
+
constructor(options?: ZodToJsonSchemaConverterOptions);
|
|
71
71
|
condition(schema: AnySchema | undefined): boolean;
|
|
72
72
|
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
|
|
73
73
|
}
|
|
@@ -89,7 +89,7 @@ declare class experimental_ZodToJsonSchemaConverter implements ConditionalSchema
|
|
|
89
89
|
* })
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
|
-
declare const
|
|
92
|
+
declare const JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
93
93
|
$anchor?: string;
|
|
94
94
|
$comment?: string;
|
|
95
95
|
$defs?: Record<string, JSONSchema>;
|
|
@@ -168,7 +168,7 @@ declare const experimental_JSON_SCHEMA_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
|
168
168
|
* })
|
|
169
169
|
* ```
|
|
170
170
|
*/
|
|
171
|
-
declare const
|
|
171
|
+
declare const JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
172
172
|
$anchor?: string;
|
|
173
173
|
$comment?: string;
|
|
174
174
|
$defs?: Record<string, JSONSchema>;
|
|
@@ -247,7 +247,7 @@ declare const experimental_JSON_SCHEMA_INPUT_REGISTRY: zod_v4_core.$ZodRegistry<
|
|
|
247
247
|
* })
|
|
248
248
|
* ```
|
|
249
249
|
*/
|
|
250
|
-
declare const
|
|
250
|
+
declare const JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry<{
|
|
251
251
|
$anchor?: string;
|
|
252
252
|
$comment?: string;
|
|
253
253
|
$defs?: Record<string, JSONSchema>;
|
|
@@ -310,5 +310,5 @@ declare const experimental_JSON_SCHEMA_OUTPUT_REGISTRY: zod_v4_core.$ZodRegistry
|
|
|
310
310
|
writeOnly?: boolean;
|
|
311
311
|
}, zod_v4_core.$ZodType<unknown, unknown, zod_v4_core.$ZodTypeInternals<unknown, unknown>>>;
|
|
312
312
|
|
|
313
|
-
export {
|
|
314
|
-
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
|
@@ -8,7 +8,7 @@ class experimental_ZodSmartCoercionPlugin {
|
|
|
8
8
|
options.clientInterceptors ??= [];
|
|
9
9
|
options.clientInterceptors.unshift((options2) => {
|
|
10
10
|
const inputSchema = options2.procedure["~orpc"].inputSchema;
|
|
11
|
-
if (!inputSchema || inputSchema["~standard"].vendor !== "zod") {
|
|
11
|
+
if (!inputSchema || inputSchema["~standard"].vendor !== "zod" || !("_zod" in inputSchema)) {
|
|
12
12
|
return options2.next();
|
|
13
13
|
}
|
|
14
14
|
const coercedInput = this.#coerce(inputSchema, options2.input);
|
|
@@ -269,11 +269,11 @@ class experimental_ZodSmartCoercionPlugin {
|
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
const
|
|
273
|
-
const
|
|
274
|
-
const
|
|
272
|
+
const JSON_SCHEMA_REGISTRY = registry();
|
|
273
|
+
const JSON_SCHEMA_INPUT_REGISTRY = registry();
|
|
274
|
+
const JSON_SCHEMA_OUTPUT_REGISTRY = registry();
|
|
275
275
|
|
|
276
|
-
class
|
|
276
|
+
class ZodToJsonSchemaConverter {
|
|
277
277
|
maxLazyDepth;
|
|
278
278
|
maxStructureDepth;
|
|
279
279
|
anyJsonSchema;
|
|
@@ -289,7 +289,7 @@ class experimental_ZodToJsonSchemaConverter {
|
|
|
289
289
|
this.interceptors = options.interceptors ?? [];
|
|
290
290
|
}
|
|
291
291
|
condition(schema) {
|
|
292
|
-
return schema !== void 0 && schema["~standard"].vendor === "zod";
|
|
292
|
+
return schema !== void 0 && schema["~standard"].vendor === "zod" && "_zod" in schema;
|
|
293
293
|
}
|
|
294
294
|
convert(schema, options) {
|
|
295
295
|
return this.#convert(schema, options, 0, 0);
|
|
@@ -627,18 +627,19 @@ class experimental_ZodToJsonSchemaConverter {
|
|
|
627
627
|
);
|
|
628
628
|
}
|
|
629
629
|
#getCustomJsonSchema(schema, options) {
|
|
630
|
-
if (options.strategy === "input" &&
|
|
631
|
-
return
|
|
630
|
+
if (options.strategy === "input" && JSON_SCHEMA_INPUT_REGISTRY.has(schema)) {
|
|
631
|
+
return JSON_SCHEMA_INPUT_REGISTRY.get(schema);
|
|
632
632
|
}
|
|
633
|
-
if (options.strategy === "output" &&
|
|
634
|
-
return
|
|
633
|
+
if (options.strategy === "output" && JSON_SCHEMA_OUTPUT_REGISTRY.has(schema)) {
|
|
634
|
+
return JSON_SCHEMA_OUTPUT_REGISTRY.get(schema);
|
|
635
635
|
}
|
|
636
|
-
if (
|
|
637
|
-
return
|
|
636
|
+
if (JSON_SCHEMA_REGISTRY.has(schema)) {
|
|
637
|
+
return JSON_SCHEMA_REGISTRY.get(schema);
|
|
638
638
|
}
|
|
639
639
|
const global = globalRegistry.get(schema);
|
|
640
640
|
if (global) {
|
|
641
641
|
return {
|
|
642
|
+
title: global.title,
|
|
642
643
|
description: global.description,
|
|
643
644
|
examples: Array.isArray(global.examples) ? global.examples : void 0
|
|
644
645
|
};
|
|
@@ -676,4 +677,4 @@ class experimental_ZodToJsonSchemaConverter {
|
|
|
676
677
|
}
|
|
677
678
|
}
|
|
678
679
|
|
|
679
|
-
export {
|
|
680
|
+
export { JSON_SCHEMA_INPUT_REGISTRY, JSON_SCHEMA_OUTPUT_REGISTRY, JSON_SCHEMA_REGISTRY, ZodToJsonSchemaConverter, experimental_ZodSmartCoercionPlugin };
|
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.
|
|
4
|
+
"version": "0.0.0-next.f437dcb",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -29,20 +29,19 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"zod": ">=3.
|
|
33
|
-
"@orpc/contract": "0.0.0-next.
|
|
34
|
-
"@orpc/server": "0.0.0-next.
|
|
32
|
+
"zod": ">=3.25.0",
|
|
33
|
+
"@orpc/contract": "0.0.0-next.f437dcb",
|
|
34
|
+
"@orpc/server": "0.0.0-next.f437dcb"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"escape-string-regexp": "^5.0.0",
|
|
38
38
|
"wildcard-match": "^5.1.3",
|
|
39
|
-
"@orpc/
|
|
40
|
-
"@orpc/
|
|
41
|
-
"@orpc/
|
|
39
|
+
"@orpc/shared": "0.0.0-next.f437dcb",
|
|
40
|
+
"@orpc/json-schema": "0.0.0-next.f437dcb",
|
|
41
|
+
"@orpc/openapi": "0.0.0-next.f437dcb"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"zod": "^
|
|
45
|
-
"zod-to-json-schema": "^3.24.6"
|
|
44
|
+
"zod": "^4.1.3"
|
|
46
45
|
},
|
|
47
46
|
"scripts": {
|
|
48
47
|
"build": "unbuild",
|