@orpc/zod 0.0.0-next.ccd4e42 → 0.0.0-next.cd121e3
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 +132 -0
- package/dist/index.d.mts +89 -0
- package/dist/index.d.ts +89 -0
- package/dist/{index.js → index.mjs} +76 -142
- package/package.json +12 -12
- package/dist/src/coercer.d.ts +0 -6
- package/dist/src/converter.d.ts +0 -50
- package/dist/src/index.d.ts +0 -4
- package/dist/src/schemas.d.ts +0 -31
package/README.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
<div align="center">
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
|
3
|
+
</div>
|
4
|
+
|
5
|
+
<h1></h1>
|
6
|
+
|
7
|
+
<div align="center">
|
8
|
+
<a href="https://codecov.io/gh/unnoq/orpc">
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
|
10
|
+
</a>
|
11
|
+
<a href="https://www.npmjs.com/package/@orpc/zod">
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fzod?logo=npm" />
|
13
|
+
</a>
|
14
|
+
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
|
16
|
+
</a>
|
17
|
+
<a href="https://discord.gg/TXEbwRBvQn">
|
18
|
+
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
19
|
+
</a>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
23
|
+
|
24
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
|
25
|
+
|
26
|
+
---
|
27
|
+
|
28
|
+
## Highlights
|
29
|
+
|
30
|
+
- **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
|
31
|
+
- **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
|
32
|
+
- **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
|
33
|
+
- **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
|
34
|
+
- **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
|
35
|
+
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
|
36
|
+
- **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
|
37
|
+
- **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
|
38
|
+
- **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
|
39
|
+
- **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
|
40
|
+
- **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
|
41
|
+
- **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
|
42
|
+
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
43
|
+
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
44
|
+
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
45
|
+
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
46
|
+
|
47
|
+
## Documentation
|
48
|
+
|
49
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
50
|
+
|
51
|
+
## Packages
|
52
|
+
|
53
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
54
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
55
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
56
|
+
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
57
|
+
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
58
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
59
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
60
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
61
|
+
|
62
|
+
## `@orpc/zod`
|
63
|
+
|
64
|
+
More schemas that [Zod](https://zod.dev/) doesn't support yet, and provides `ZodToJsonSchemaConverter` for generating OpenAPI specs.
|
65
|
+
|
66
|
+
### More Schemas
|
67
|
+
|
68
|
+
- `oz.url`: Zod schema for [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) instance.
|
69
|
+
- `oz.blob`: Zod schema for [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) instance.
|
70
|
+
- `oz.file`: Zod schema for [File](https://developer.mozilla.org/en-US/docs/Web/API/File) instance.
|
71
|
+
- `oz.regexp`: Zod schema for [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instance.
|
72
|
+
|
73
|
+
```ts
|
74
|
+
import { oz } from '@orpc/zod'
|
75
|
+
import { z } from 'zod'
|
76
|
+
|
77
|
+
const Example = z.object({
|
78
|
+
url: oz.url(),
|
79
|
+
blob: oz.blob(),
|
80
|
+
file: oz.file().type('image/png'),
|
81
|
+
regexp: oz.regexp(),
|
82
|
+
})
|
83
|
+
```
|
84
|
+
|
85
|
+
### Generate OpenAPI Spec
|
86
|
+
|
87
|
+
```ts
|
88
|
+
import { OpenAPIGenerator } from '@orpc/openapi'
|
89
|
+
import { ZodToJsonSchemaConverter } from '@orpc/zod'
|
90
|
+
|
91
|
+
const openAPIGenerator = new OpenAPIGenerator({
|
92
|
+
schemaConverters: [new ZodToJsonSchemaConverter()],
|
93
|
+
})
|
94
|
+
|
95
|
+
const specFromContract = await openAPIGenerator.generate(contract, {
|
96
|
+
info: {
|
97
|
+
title: 'My App',
|
98
|
+
version: '0.0.0',
|
99
|
+
},
|
100
|
+
})
|
101
|
+
|
102
|
+
const specFromRouter = await openAPIGenerator.generate(router, {
|
103
|
+
info: {
|
104
|
+
title: 'My App',
|
105
|
+
version: '0.0.0',
|
106
|
+
},
|
107
|
+
})
|
108
|
+
```
|
109
|
+
|
110
|
+
### Extending the Specification
|
111
|
+
|
112
|
+
```ts
|
113
|
+
import { oz } from '@orpc/zod'
|
114
|
+
import { z } from 'zod'
|
115
|
+
|
116
|
+
const InputSchema = oz.openapi(
|
117
|
+
z.object({
|
118
|
+
name: z.string(),
|
119
|
+
}),
|
120
|
+
{
|
121
|
+
examples: [
|
122
|
+
{ name: 'Earth' },
|
123
|
+
{ name: 'Mars' },
|
124
|
+
],
|
125
|
+
// additional options...
|
126
|
+
}
|
127
|
+
)
|
128
|
+
```
|
129
|
+
|
130
|
+
## License
|
131
|
+
|
132
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
import { Context } from '@orpc/server';
|
2
|
+
import { Plugin } from '@orpc/server/plugins';
|
3
|
+
import { StandardHandlerOptions } from '@orpc/server/standard';
|
4
|
+
import { Schema } from '@orpc/contract';
|
5
|
+
import { JSONSchema, SchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
|
6
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
7
|
+
import { JSONSchema as JSONSchema$1 } from 'json-schema-typed/draft-2020-12';
|
8
|
+
import { ZodTypeDef, CustomErrorParams, ZodType, ZodEffects, ZodTypeAny, input, output } from 'zod';
|
9
|
+
|
10
|
+
declare class ZodSmartCoercionPlugin<TContext extends Context> implements Plugin<TContext> {
|
11
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
12
|
+
}
|
13
|
+
|
14
|
+
declare const NON_LOGIC_KEYWORDS: ("default" | "$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly" | "contentEncoding" | "contentMediaType")[];
|
15
|
+
declare const UNSUPPORTED_JSON_SCHEMA: {
|
16
|
+
not: {};
|
17
|
+
};
|
18
|
+
declare const UNDEFINED_JSON_SCHEMA: {
|
19
|
+
const: string;
|
20
|
+
};
|
21
|
+
interface ZodToJsonSchemaOptions {
|
22
|
+
/**
|
23
|
+
* Max depth of lazy type, if it exceeds.
|
24
|
+
*
|
25
|
+
* Used `{}` when reach max depth
|
26
|
+
*
|
27
|
+
* @default 5
|
28
|
+
*/
|
29
|
+
maxLazyDepth?: number;
|
30
|
+
/**
|
31
|
+
* The length used to track the depth of lazy type
|
32
|
+
*
|
33
|
+
* @internal
|
34
|
+
*/
|
35
|
+
lazyDepth?: number;
|
36
|
+
/**
|
37
|
+
* The expected json schema for input or output zod schema
|
38
|
+
*
|
39
|
+
* @default input
|
40
|
+
*/
|
41
|
+
mode?: 'input' | 'output';
|
42
|
+
/**
|
43
|
+
* Track if current level schema is handled custom json schema to prevent recursive
|
44
|
+
*
|
45
|
+
* @internal
|
46
|
+
*/
|
47
|
+
isHandledCustomJSONSchema?: boolean;
|
48
|
+
/**
|
49
|
+
* Track if current level schema is handled zod description to prevent recursive
|
50
|
+
*
|
51
|
+
* @internal
|
52
|
+
*/
|
53
|
+
isHandledZodDescription?: boolean;
|
54
|
+
}
|
55
|
+
declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema.JSONSchema, boolean>;
|
56
|
+
declare class ZodToJsonSchemaConverter implements SchemaConverter {
|
57
|
+
condition(schema: Schema): boolean;
|
58
|
+
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
|
59
|
+
}
|
60
|
+
|
61
|
+
type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL';
|
62
|
+
type CustomParams = CustomErrorParams & {
|
63
|
+
fatal?: boolean;
|
64
|
+
};
|
65
|
+
declare function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined;
|
66
|
+
declare function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined;
|
67
|
+
declare function getCustomJSONSchema(def: ZodTypeDef, options?: {
|
68
|
+
mode?: 'input' | 'output';
|
69
|
+
}): Exclude<JSONSchema$1, boolean> | undefined;
|
70
|
+
declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {
|
71
|
+
type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, InstanceType<typeof File>, InstanceType<typeof File>>;
|
72
|
+
};
|
73
|
+
declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>>;
|
74
|
+
declare function invalidDate(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Date, ZodTypeDef, Date>;
|
75
|
+
declare function regexp(options?: CustomParams): ZodType<RegExp, ZodTypeDef, RegExp>;
|
76
|
+
declare function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL>;
|
77
|
+
declare function openapi<T extends ZodTypeAny, TMode extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema$1<TMode extends 'input' ? input<T> : TMode extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
|
78
|
+
mode: TMode;
|
79
|
+
}): ReturnType<T['refine']>;
|
80
|
+
declare const oz: {
|
81
|
+
openapi: typeof openapi;
|
82
|
+
file: typeof file;
|
83
|
+
blob: typeof blob;
|
84
|
+
invalidDate: typeof invalidDate;
|
85
|
+
regexp: typeof regexp;
|
86
|
+
url: typeof url;
|
87
|
+
};
|
88
|
+
|
89
|
+
export { type CustomZodType, NON_LOGIC_KEYWORDS, UNDEFINED_JSON_SCHEMA, UNSUPPORTED_JSON_SCHEMA, ZodSmartCoercionPlugin as ZodAutoCoercePlugin, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, type ZodToJsonSchemaOptions, blob, file, getCustomJSONSchema, getCustomZodFileMimeType, getCustomZodType, invalidDate, openapi, oz, regexp, url, zodToJsonSchema };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
import { Context } from '@orpc/server';
|
2
|
+
import { Plugin } from '@orpc/server/plugins';
|
3
|
+
import { StandardHandlerOptions } from '@orpc/server/standard';
|
4
|
+
import { Schema } from '@orpc/contract';
|
5
|
+
import { JSONSchema, SchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
|
6
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
7
|
+
import { JSONSchema as JSONSchema$1 } from 'json-schema-typed/draft-2020-12';
|
8
|
+
import { ZodTypeDef, CustomErrorParams, ZodType, ZodEffects, ZodTypeAny, input, output } from 'zod';
|
9
|
+
|
10
|
+
declare class ZodSmartCoercionPlugin<TContext extends Context> implements Plugin<TContext> {
|
11
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
12
|
+
}
|
13
|
+
|
14
|
+
declare const NON_LOGIC_KEYWORDS: ("default" | "$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly" | "contentEncoding" | "contentMediaType")[];
|
15
|
+
declare const UNSUPPORTED_JSON_SCHEMA: {
|
16
|
+
not: {};
|
17
|
+
};
|
18
|
+
declare const UNDEFINED_JSON_SCHEMA: {
|
19
|
+
const: string;
|
20
|
+
};
|
21
|
+
interface ZodToJsonSchemaOptions {
|
22
|
+
/**
|
23
|
+
* Max depth of lazy type, if it exceeds.
|
24
|
+
*
|
25
|
+
* Used `{}` when reach max depth
|
26
|
+
*
|
27
|
+
* @default 5
|
28
|
+
*/
|
29
|
+
maxLazyDepth?: number;
|
30
|
+
/**
|
31
|
+
* The length used to track the depth of lazy type
|
32
|
+
*
|
33
|
+
* @internal
|
34
|
+
*/
|
35
|
+
lazyDepth?: number;
|
36
|
+
/**
|
37
|
+
* The expected json schema for input or output zod schema
|
38
|
+
*
|
39
|
+
* @default input
|
40
|
+
*/
|
41
|
+
mode?: 'input' | 'output';
|
42
|
+
/**
|
43
|
+
* Track if current level schema is handled custom json schema to prevent recursive
|
44
|
+
*
|
45
|
+
* @internal
|
46
|
+
*/
|
47
|
+
isHandledCustomJSONSchema?: boolean;
|
48
|
+
/**
|
49
|
+
* Track if current level schema is handled zod description to prevent recursive
|
50
|
+
*
|
51
|
+
* @internal
|
52
|
+
*/
|
53
|
+
isHandledZodDescription?: boolean;
|
54
|
+
}
|
55
|
+
declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema.JSONSchema, boolean>;
|
56
|
+
declare class ZodToJsonSchemaConverter implements SchemaConverter {
|
57
|
+
condition(schema: Schema): boolean;
|
58
|
+
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
|
59
|
+
}
|
60
|
+
|
61
|
+
type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL';
|
62
|
+
type CustomParams = CustomErrorParams & {
|
63
|
+
fatal?: boolean;
|
64
|
+
};
|
65
|
+
declare function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined;
|
66
|
+
declare function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined;
|
67
|
+
declare function getCustomJSONSchema(def: ZodTypeDef, options?: {
|
68
|
+
mode?: 'input' | 'output';
|
69
|
+
}): Exclude<JSONSchema$1, boolean> | undefined;
|
70
|
+
declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {
|
71
|
+
type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, InstanceType<typeof File>, InstanceType<typeof File>>;
|
72
|
+
};
|
73
|
+
declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>>;
|
74
|
+
declare function invalidDate(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Date, ZodTypeDef, Date>;
|
75
|
+
declare function regexp(options?: CustomParams): ZodType<RegExp, ZodTypeDef, RegExp>;
|
76
|
+
declare function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL>;
|
77
|
+
declare function openapi<T extends ZodTypeAny, TMode extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema$1<TMode extends 'input' ? input<T> : TMode extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
|
78
|
+
mode: TMode;
|
79
|
+
}): ReturnType<T['refine']>;
|
80
|
+
declare const oz: {
|
81
|
+
openapi: typeof openapi;
|
82
|
+
file: typeof file;
|
83
|
+
blob: typeof blob;
|
84
|
+
invalidDate: typeof invalidDate;
|
85
|
+
regexp: typeof regexp;
|
86
|
+
url: typeof url;
|
87
|
+
};
|
88
|
+
|
89
|
+
export { type CustomZodType, NON_LOGIC_KEYWORDS, UNDEFINED_JSON_SCHEMA, UNSUPPORTED_JSON_SCHEMA, ZodSmartCoercionPlugin as ZodAutoCoercePlugin, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, type ZodToJsonSchemaOptions, blob, file, getCustomJSONSchema, getCustomZodFileMimeType, getCustomZodType, invalidDate, openapi, oz, regexp, url, zodToJsonSchema };
|
@@ -1,46 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
}
|
5
|
-
|
6
|
-
|
7
|
-
function isPlainObject(payload) {
|
8
|
-
if (getType(payload) !== "Object")
|
9
|
-
return false;
|
10
|
-
const prototype = Object.getPrototypeOf(payload);
|
11
|
-
return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
|
12
|
-
}
|
13
|
-
|
14
|
-
// ../../node_modules/.pnpm/radash@12.1.0/node_modules/radash/dist/esm/async.mjs
|
15
|
-
var guard = (func, shouldGuard) => {
|
16
|
-
const _guard = (err) => {
|
17
|
-
if (shouldGuard && !shouldGuard(err))
|
18
|
-
throw err;
|
19
|
-
return void 0;
|
20
|
-
};
|
21
|
-
const isPromise2 = (result) => result instanceof Promise;
|
22
|
-
try {
|
23
|
-
const result = func();
|
24
|
-
return isPromise2(result) ? result.catch(_guard) : result;
|
25
|
-
} catch (err) {
|
26
|
-
return _guard(err);
|
27
|
-
}
|
28
|
-
};
|
1
|
+
import { guard, isObject } from '@orpc/shared';
|
2
|
+
import { getCustomZodType as getCustomZodType$1 } from '@orpc/zod';
|
3
|
+
import { ZodFirstPartyTypeKind, custom } from 'zod';
|
4
|
+
import { JSONSchemaFormat } from '@orpc/openapi';
|
5
|
+
import escapeStringRegexp from 'escape-string-regexp';
|
6
|
+
import wcmatch from 'wildcard-match';
|
29
7
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
return coerced;
|
8
|
+
class ZodSmartCoercionPlugin {
|
9
|
+
init(options) {
|
10
|
+
options.clientInterceptors ??= [];
|
11
|
+
options.clientInterceptors.unshift((options2) => {
|
12
|
+
const inputSchema = options2.procedure["~orpc"].inputSchema;
|
13
|
+
if (!inputSchema || inputSchema["~standard"].vendor !== "zod") {
|
14
|
+
return options2.next();
|
15
|
+
}
|
16
|
+
const coercedInput = zodCoerceInternal(inputSchema, options2.input, { bracketNotation: true });
|
17
|
+
return options2.next({ ...options2, input: coercedInput });
|
18
|
+
});
|
42
19
|
}
|
43
|
-
}
|
20
|
+
}
|
44
21
|
function zodCoerceInternal(schema, value, options) {
|
45
22
|
const isRoot = options?.isRoot ?? true;
|
46
23
|
const options_ = { ...options, isRoot: false };
|
@@ -51,7 +28,7 @@ function zodCoerceInternal(schema, value, options) {
|
|
51
28
|
}
|
52
29
|
return zodCoerceInternal(schema, value, options_);
|
53
30
|
}
|
54
|
-
const customType = getCustomZodType(schema._def);
|
31
|
+
const customType = getCustomZodType$1(schema._def);
|
55
32
|
if (customType === "Invalid Date") {
|
56
33
|
if (typeof value === "string" && value.toLocaleLowerCase() === "invalid date") {
|
57
34
|
return /* @__PURE__ */ new Date("Invalid Date");
|
@@ -66,9 +43,9 @@ function zodCoerceInternal(schema, value, options) {
|
|
66
43
|
}
|
67
44
|
} else if (customType === "URL") {
|
68
45
|
if (typeof value === "string") {
|
69
|
-
const
|
70
|
-
if (
|
71
|
-
return
|
46
|
+
const url = guard(() => new URL(value));
|
47
|
+
if (url !== void 0) {
|
48
|
+
return url;
|
72
49
|
}
|
73
50
|
}
|
74
51
|
}
|
@@ -125,7 +102,7 @@ function zodCoerceInternal(schema, value, options) {
|
|
125
102
|
if (value === void 0) {
|
126
103
|
return [];
|
127
104
|
}
|
128
|
-
if (
|
105
|
+
if (isObject(value) && Object.keys(value).every((k) => /^[1-9]\d*$/.test(k) || k === "0")) {
|
129
106
|
const indexes = Object.keys(value).map((k) => Number(k)).sort((a, b) => a - b);
|
130
107
|
const arr = Array.from({ length: (indexes.at(-1) ?? -1) + 1 });
|
131
108
|
for (const i of indexes) {
|
@@ -136,7 +113,7 @@ function zodCoerceInternal(schema, value, options) {
|
|
136
113
|
}
|
137
114
|
} else if (typeName === ZodFirstPartyTypeKind.ZodObject) {
|
138
115
|
const schema_ = schema;
|
139
|
-
if (
|
116
|
+
if (isObject(value)) {
|
140
117
|
const newObj = {};
|
141
118
|
const keys = /* @__PURE__ */ new Set([
|
142
119
|
...Object.keys(value),
|
@@ -174,7 +151,7 @@ function zodCoerceInternal(schema, value, options) {
|
|
174
151
|
if (value === void 0) {
|
175
152
|
return /* @__PURE__ */ new Set();
|
176
153
|
}
|
177
|
-
if (
|
154
|
+
if (isObject(value) && Object.keys(value).every((k) => /^[1-9]\d*$/.test(k) || k === "0")) {
|
178
155
|
const indexes = Object.keys(value).map((k) => Number(k)).sort((a, b) => a - b);
|
179
156
|
const arr = Array.from({ length: (indexes.at(-1) ?? -1) + 1 });
|
180
157
|
for (const i of indexes) {
|
@@ -197,9 +174,9 @@ function zodCoerceInternal(schema, value, options) {
|
|
197
174
|
if (value === void 0) {
|
198
175
|
return /* @__PURE__ */ new Map();
|
199
176
|
}
|
200
|
-
if (
|
177
|
+
if (isObject(value)) {
|
201
178
|
const arr = Array.from({ length: Object.keys(value).length }).fill(void 0).map(
|
202
|
-
(_, i) =>
|
179
|
+
(_, i) => isObject(value[i]) && Object.keys(value[i]).length === 2 && "0" in value[i] && "1" in value[i] ? [value[i]["0"], value[i]["1"]] : void 0
|
203
180
|
);
|
204
181
|
if (arr.every((v) => !!v)) {
|
205
182
|
return new Map(
|
@@ -213,7 +190,7 @@ function zodCoerceInternal(schema, value, options) {
|
|
213
190
|
}
|
214
191
|
} else if (typeName === ZodFirstPartyTypeKind.ZodRecord) {
|
215
192
|
const schema_ = schema;
|
216
|
-
if (
|
193
|
+
if (isObject(value)) {
|
217
194
|
const newObj = {};
|
218
195
|
for (const [k, v] of Object.entries(value)) {
|
219
196
|
const key = zodCoerceInternal(schema_._def.keyType, k, options_);
|
@@ -334,38 +311,15 @@ function zodCoerceInternal(schema, value, options) {
|
|
334
311
|
}
|
335
312
|
}
|
336
313
|
}
|
337
|
-
} else
|
338
|
-
const _expected = typeName;
|
339
|
-
}
|
314
|
+
} else ;
|
340
315
|
return value;
|
341
316
|
}
|
342
317
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
if (typeof string !== "string") {
|
349
|
-
throw new TypeError("Expected a string");
|
350
|
-
}
|
351
|
-
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
352
|
-
}
|
353
|
-
|
354
|
-
// src/converter.ts
|
355
|
-
import {
|
356
|
-
ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2
|
357
|
-
} from "zod";
|
358
|
-
|
359
|
-
// src/schemas.ts
|
360
|
-
import wcmatch from "wildcard-match";
|
361
|
-
import {
|
362
|
-
custom
|
363
|
-
} from "zod";
|
364
|
-
var customZodTypeSymbol = Symbol("customZodTypeSymbol");
|
365
|
-
var customZodFileMimeTypeSymbol = Symbol("customZodFileMimeTypeSymbol");
|
366
|
-
var CUSTOM_JSON_SCHEMA_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA");
|
367
|
-
var CUSTOM_JSON_SCHEMA_INPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_INPUT");
|
368
|
-
var CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_OUTPUT");
|
318
|
+
const customZodTypeSymbol = Symbol("customZodTypeSymbol");
|
319
|
+
const customZodFileMimeTypeSymbol = Symbol("customZodFileMimeTypeSymbol");
|
320
|
+
const CUSTOM_JSON_SCHEMA_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA");
|
321
|
+
const CUSTOM_JSON_SCHEMA_INPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_INPUT");
|
322
|
+
const CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_OUTPUT");
|
369
323
|
function getCustomZodType(def) {
|
370
324
|
return customZodTypeSymbol in def ? def[customZodTypeSymbol] : void 0;
|
371
325
|
}
|
@@ -483,7 +437,7 @@ function openapi(schema, custom2, options) {
|
|
483
437
|
});
|
484
438
|
return newSchema;
|
485
439
|
}
|
486
|
-
|
440
|
+
const oz = {
|
487
441
|
openapi,
|
488
442
|
file,
|
489
443
|
blob,
|
@@ -492,8 +446,7 @@ var oz = {
|
|
492
446
|
url
|
493
447
|
};
|
494
448
|
|
495
|
-
|
496
|
-
var NON_LOGIC_KEYWORDS = [
|
449
|
+
const NON_LOGIC_KEYWORDS = [
|
497
450
|
// Core Documentation Keywords
|
498
451
|
"$anchor",
|
499
452
|
"$comment",
|
@@ -520,8 +473,8 @@ var NON_LOGIC_KEYWORDS = [
|
|
520
473
|
"$dynamicAnchor",
|
521
474
|
"$dynamicRef"
|
522
475
|
];
|
523
|
-
|
524
|
-
|
476
|
+
const UNSUPPORTED_JSON_SCHEMA = { not: {} };
|
477
|
+
const UNDEFINED_JSON_SCHEMA = { const: "undefined" };
|
525
478
|
function zodToJsonSchema(schema, options) {
|
526
479
|
if (schema["~standard"].vendor !== "zod") {
|
527
480
|
console.warn(`Generate JSON schema not support ${schema["~standard"].vendor} yet`);
|
@@ -574,10 +527,9 @@ function zodToJsonSchema(schema, options) {
|
|
574
527
|
return { type: "string", format: JSONSchemaFormat.URI };
|
575
528
|
}
|
576
529
|
}
|
577
|
-
const _expectedCustomType = customType;
|
578
530
|
const typeName = schema__._def.typeName;
|
579
531
|
switch (typeName) {
|
580
|
-
case
|
532
|
+
case ZodFirstPartyTypeKind.ZodString: {
|
581
533
|
const schema_ = schema__;
|
582
534
|
const json = { type: "string" };
|
583
535
|
for (const check of schema_._def.checks) {
|
@@ -653,13 +605,13 @@ function zodToJsonSchema(schema, options) {
|
|
653
605
|
json.pattern = "^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$";
|
654
606
|
break;
|
655
607
|
default: {
|
656
|
-
|
608
|
+
check.kind;
|
657
609
|
}
|
658
610
|
}
|
659
611
|
}
|
660
612
|
return json;
|
661
613
|
}
|
662
|
-
case
|
614
|
+
case ZodFirstPartyTypeKind.ZodNumber: {
|
663
615
|
const schema_ = schema__;
|
664
616
|
const json = { type: "number" };
|
665
617
|
for (const check of schema_._def.checks) {
|
@@ -677,50 +629,50 @@ function zodToJsonSchema(schema, options) {
|
|
677
629
|
json.multipleOf = check.value;
|
678
630
|
break;
|
679
631
|
default: {
|
680
|
-
|
632
|
+
check.kind;
|
681
633
|
}
|
682
634
|
}
|
683
635
|
}
|
684
636
|
return json;
|
685
637
|
}
|
686
|
-
case
|
638
|
+
case ZodFirstPartyTypeKind.ZodNaN: {
|
687
639
|
return { const: "NaN" };
|
688
640
|
}
|
689
|
-
case
|
641
|
+
case ZodFirstPartyTypeKind.ZodBigInt: {
|
690
642
|
const json = { type: "string", pattern: "^-?[0-9]+$" };
|
691
643
|
return json;
|
692
644
|
}
|
693
|
-
case
|
645
|
+
case ZodFirstPartyTypeKind.ZodBoolean: {
|
694
646
|
return { type: "boolean" };
|
695
647
|
}
|
696
|
-
case
|
648
|
+
case ZodFirstPartyTypeKind.ZodDate: {
|
697
649
|
const schema2 = { type: "string", format: JSONSchemaFormat.Date };
|
698
650
|
return schema2;
|
699
651
|
}
|
700
|
-
case
|
652
|
+
case ZodFirstPartyTypeKind.ZodNull: {
|
701
653
|
return { type: "null" };
|
702
654
|
}
|
703
|
-
case
|
704
|
-
case
|
655
|
+
case ZodFirstPartyTypeKind.ZodVoid:
|
656
|
+
case ZodFirstPartyTypeKind.ZodUndefined: {
|
705
657
|
return UNDEFINED_JSON_SCHEMA;
|
706
658
|
}
|
707
|
-
case
|
659
|
+
case ZodFirstPartyTypeKind.ZodLiteral: {
|
708
660
|
const schema_ = schema__;
|
709
661
|
return { const: schema_._def.value };
|
710
662
|
}
|
711
|
-
case
|
663
|
+
case ZodFirstPartyTypeKind.ZodEnum: {
|
712
664
|
const schema_ = schema__;
|
713
665
|
return {
|
714
666
|
enum: schema_._def.values
|
715
667
|
};
|
716
668
|
}
|
717
|
-
case
|
669
|
+
case ZodFirstPartyTypeKind.ZodNativeEnum: {
|
718
670
|
const schema_ = schema__;
|
719
671
|
return {
|
720
672
|
enum: Object.values(schema_._def.values)
|
721
673
|
};
|
722
674
|
}
|
723
|
-
case
|
675
|
+
case ZodFirstPartyTypeKind.ZodArray: {
|
724
676
|
const schema_ = schema__;
|
725
677
|
const def = schema_._def;
|
726
678
|
const json = { type: "array" };
|
@@ -737,7 +689,7 @@ function zodToJsonSchema(schema, options) {
|
|
737
689
|
}
|
738
690
|
return json;
|
739
691
|
}
|
740
|
-
case
|
692
|
+
case ZodFirstPartyTypeKind.ZodTuple: {
|
741
693
|
const schema_ = schema__;
|
742
694
|
const prefixItems = [];
|
743
695
|
const json = { type: "array" };
|
@@ -755,7 +707,7 @@ function zodToJsonSchema(schema, options) {
|
|
755
707
|
}
|
756
708
|
return json;
|
757
709
|
}
|
758
|
-
case
|
710
|
+
case ZodFirstPartyTypeKind.ZodObject: {
|
759
711
|
const schema_ = schema__;
|
760
712
|
const json = { type: "object" };
|
761
713
|
const properties = {};
|
@@ -791,7 +743,7 @@ function zodToJsonSchema(schema, options) {
|
|
791
743
|
}
|
792
744
|
return json;
|
793
745
|
}
|
794
|
-
case
|
746
|
+
case ZodFirstPartyTypeKind.ZodRecord: {
|
795
747
|
const schema_ = schema__;
|
796
748
|
const json = { type: "object" };
|
797
749
|
json.additionalProperties = zodToJsonSchema(
|
@@ -800,14 +752,14 @@ function zodToJsonSchema(schema, options) {
|
|
800
752
|
);
|
801
753
|
return json;
|
802
754
|
}
|
803
|
-
case
|
755
|
+
case ZodFirstPartyTypeKind.ZodSet: {
|
804
756
|
const schema_ = schema__;
|
805
757
|
return {
|
806
758
|
type: "array",
|
807
759
|
items: zodToJsonSchema(schema_._def.valueType, childOptions)
|
808
760
|
};
|
809
761
|
}
|
810
|
-
case
|
762
|
+
case ZodFirstPartyTypeKind.ZodMap: {
|
811
763
|
const schema_ = schema__;
|
812
764
|
return {
|
813
765
|
type: "array",
|
@@ -822,8 +774,8 @@ function zodToJsonSchema(schema, options) {
|
|
822
774
|
}
|
823
775
|
};
|
824
776
|
}
|
825
|
-
case
|
826
|
-
case
|
777
|
+
case ZodFirstPartyTypeKind.ZodUnion:
|
778
|
+
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
|
827
779
|
const schema_ = schema__;
|
828
780
|
const anyOf = [];
|
829
781
|
for (const s of schema_._def.options) {
|
@@ -831,7 +783,7 @@ function zodToJsonSchema(schema, options) {
|
|
831
783
|
}
|
832
784
|
return { anyOf };
|
833
785
|
}
|
834
|
-
case
|
786
|
+
case ZodFirstPartyTypeKind.ZodIntersection: {
|
835
787
|
const schema_ = schema__;
|
836
788
|
const allOf = [];
|
837
789
|
for (const s of [schema_._def.left, schema_._def.right]) {
|
@@ -839,7 +791,7 @@ function zodToJsonSchema(schema, options) {
|
|
839
791
|
}
|
840
792
|
return { allOf };
|
841
793
|
}
|
842
|
-
case
|
794
|
+
case ZodFirstPartyTypeKind.ZodLazy: {
|
843
795
|
const schema_ = schema__;
|
844
796
|
const maxLazyDepth = childOptions?.maxLazyDepth ?? 5;
|
845
797
|
const lazyDepth = childOptions?.lazyDepth ?? 0;
|
@@ -851,49 +803,49 @@ function zodToJsonSchema(schema, options) {
|
|
851
803
|
lazyDepth: lazyDepth + 1
|
852
804
|
});
|
853
805
|
}
|
854
|
-
case
|
855
|
-
case
|
806
|
+
case ZodFirstPartyTypeKind.ZodUnknown:
|
807
|
+
case ZodFirstPartyTypeKind.ZodAny:
|
856
808
|
case void 0: {
|
857
809
|
return {};
|
858
810
|
}
|
859
|
-
case
|
811
|
+
case ZodFirstPartyTypeKind.ZodOptional: {
|
860
812
|
const schema_ = schema__;
|
861
813
|
const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
|
862
814
|
return {
|
863
815
|
anyOf: [UNDEFINED_JSON_SCHEMA, inner]
|
864
816
|
};
|
865
817
|
}
|
866
|
-
case
|
818
|
+
case ZodFirstPartyTypeKind.ZodReadonly: {
|
867
819
|
const schema_ = schema__;
|
868
820
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
869
821
|
}
|
870
|
-
case
|
822
|
+
case ZodFirstPartyTypeKind.ZodDefault: {
|
871
823
|
const schema_ = schema__;
|
872
824
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
873
825
|
}
|
874
|
-
case
|
826
|
+
case ZodFirstPartyTypeKind.ZodEffects: {
|
875
827
|
const schema_ = schema__;
|
876
828
|
if (schema_._def.effect.type === "transform" && childOptions?.mode === "output") {
|
877
829
|
return {};
|
878
830
|
}
|
879
831
|
return zodToJsonSchema(schema_._def.schema, childOptions);
|
880
832
|
}
|
881
|
-
case
|
833
|
+
case ZodFirstPartyTypeKind.ZodCatch: {
|
882
834
|
const schema_ = schema__;
|
883
835
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
884
836
|
}
|
885
|
-
case
|
837
|
+
case ZodFirstPartyTypeKind.ZodBranded: {
|
886
838
|
const schema_ = schema__;
|
887
839
|
return zodToJsonSchema(schema_._def.type, childOptions);
|
888
840
|
}
|
889
|
-
case
|
841
|
+
case ZodFirstPartyTypeKind.ZodPipeline: {
|
890
842
|
const schema_ = schema__;
|
891
843
|
return zodToJsonSchema(
|
892
844
|
childOptions?.mode === "output" ? schema_._def.out : schema_._def.in,
|
893
845
|
childOptions
|
894
846
|
);
|
895
847
|
}
|
896
|
-
case
|
848
|
+
case ZodFirstPartyTypeKind.ZodNullable: {
|
897
849
|
const schema_ = schema__;
|
898
850
|
const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
|
899
851
|
return {
|
@@ -901,7 +853,6 @@ function zodToJsonSchema(schema, options) {
|
|
901
853
|
};
|
902
854
|
}
|
903
855
|
}
|
904
|
-
const _expected = typeName;
|
905
856
|
return UNSUPPORTED_JSON_SCHEMA;
|
906
857
|
}
|
907
858
|
function extractJSONSchema(schema, check, matches = []) {
|
@@ -944,7 +895,7 @@ function extractJSONSchema(schema, check, matches = []) {
|
|
944
895
|
}
|
945
896
|
return { schema, matches };
|
946
897
|
}
|
947
|
-
|
898
|
+
class ZodToJsonSchemaConverter {
|
948
899
|
condition(schema) {
|
949
900
|
return Boolean(schema && schema["~standard"].vendor === "zod");
|
950
901
|
}
|
@@ -952,23 +903,6 @@ var ZodToJsonSchemaConverter = class {
|
|
952
903
|
const jsonSchema = schema;
|
953
904
|
return zodToJsonSchema(jsonSchema, { mode: options.strategy });
|
954
905
|
}
|
955
|
-
}
|
956
|
-
|
957
|
-
|
958
|
-
UNDEFINED_JSON_SCHEMA,
|
959
|
-
UNSUPPORTED_JSON_SCHEMA,
|
960
|
-
ZodCoercer,
|
961
|
-
ZodToJsonSchemaConverter,
|
962
|
-
blob,
|
963
|
-
file,
|
964
|
-
getCustomJSONSchema,
|
965
|
-
getCustomZodFileMimeType,
|
966
|
-
getCustomZodType,
|
967
|
-
invalidDate,
|
968
|
-
openapi,
|
969
|
-
oz,
|
970
|
-
regexp,
|
971
|
-
url,
|
972
|
-
zodToJsonSchema
|
973
|
-
};
|
974
|
-
//# sourceMappingURL=index.js.map
|
906
|
+
}
|
907
|
+
|
908
|
+
export { NON_LOGIC_KEYWORDS, UNDEFINED_JSON_SCHEMA, UNSUPPORTED_JSON_SCHEMA, ZodSmartCoercionPlugin as ZodAutoCoercePlugin, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, blob, file, getCustomJSONSchema, getCustomZodFileMimeType, getCustomZodType, invalidDate, openapi, oz, regexp, url, zodToJsonSchema };
|
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.cd121e3",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -15,29 +15,29 @@
|
|
15
15
|
],
|
16
16
|
"exports": {
|
17
17
|
".": {
|
18
|
-
"types": "./dist/
|
19
|
-
"import": "./dist/index.
|
20
|
-
"default": "./dist/index.
|
21
|
-
},
|
22
|
-
"./🔒/*": {
|
23
|
-
"types": "./dist/src/*.d.ts"
|
18
|
+
"types": "./dist/index.d.mts",
|
19
|
+
"import": "./dist/index.mjs",
|
20
|
+
"default": "./dist/index.mjs"
|
24
21
|
}
|
25
22
|
},
|
26
23
|
"files": [
|
27
|
-
"!**/*.map",
|
28
|
-
"!**/*.tsbuildinfo",
|
29
24
|
"dist"
|
30
25
|
],
|
31
26
|
"peerDependencies": {
|
32
|
-
"@orpc/
|
27
|
+
"@orpc/contract": "0.0.0-next.cd121e3",
|
28
|
+
"@orpc/openapi": "0.0.0-next.cd121e3",
|
29
|
+
"@orpc/server": "0.0.0-next.cd121e3"
|
33
30
|
},
|
34
31
|
"dependencies": {
|
32
|
+
"@standard-schema/spec": "^1.0.0",
|
33
|
+
"escape-string-regexp": "^5.0.0",
|
35
34
|
"json-schema-typed": "^8.0.1",
|
36
35
|
"wildcard-match": "^5.1.3",
|
37
|
-
"zod": "^3.24.1"
|
36
|
+
"zod": "^3.24.1",
|
37
|
+
"@orpc/shared": "0.0.0-next.cd121e3"
|
38
38
|
},
|
39
39
|
"scripts": {
|
40
|
-
"build": "
|
40
|
+
"build": "unbuild",
|
41
41
|
"build:watch": "pnpm run build --watch",
|
42
42
|
"type:check": "tsc -b"
|
43
43
|
}
|
package/dist/src/coercer.d.ts
DELETED
package/dist/src/converter.d.ts
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
import type { Schema } from '@orpc/contract';
|
2
|
-
import type { JSONSchema, SchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
|
3
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
4
|
-
export declare const NON_LOGIC_KEYWORDS: ("$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "contentEncoding" | "contentMediaType" | "default" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly")[];
|
5
|
-
export declare const UNSUPPORTED_JSON_SCHEMA: {
|
6
|
-
not: {};
|
7
|
-
};
|
8
|
-
export declare const UNDEFINED_JSON_SCHEMA: {
|
9
|
-
const: string;
|
10
|
-
};
|
11
|
-
export interface ZodToJsonSchemaOptions {
|
12
|
-
/**
|
13
|
-
* Max depth of lazy type, if it exceeds.
|
14
|
-
*
|
15
|
-
* Used `{}` when reach max depth
|
16
|
-
*
|
17
|
-
* @default 5
|
18
|
-
*/
|
19
|
-
maxLazyDepth?: number;
|
20
|
-
/**
|
21
|
-
* The length used to track the depth of lazy type
|
22
|
-
*
|
23
|
-
* @internal
|
24
|
-
*/
|
25
|
-
lazyDepth?: number;
|
26
|
-
/**
|
27
|
-
* The expected json schema for input or output zod schema
|
28
|
-
*
|
29
|
-
* @default input
|
30
|
-
*/
|
31
|
-
mode?: 'input' | 'output';
|
32
|
-
/**
|
33
|
-
* Track if current level schema is handled custom json schema to prevent recursive
|
34
|
-
*
|
35
|
-
* @internal
|
36
|
-
*/
|
37
|
-
isHandledCustomJSONSchema?: boolean;
|
38
|
-
/**
|
39
|
-
* Track if current level schema is handled zod description to prevent recursive
|
40
|
-
*
|
41
|
-
* @internal
|
42
|
-
*/
|
43
|
-
isHandledZodDescription?: boolean;
|
44
|
-
}
|
45
|
-
export declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema.JSONSchema, boolean>;
|
46
|
-
export declare class ZodToJsonSchemaConverter implements SchemaConverter {
|
47
|
-
condition(schema: Schema): boolean;
|
48
|
-
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
|
49
|
-
}
|
50
|
-
//# sourceMappingURL=converter.d.ts.map
|
package/dist/src/index.d.ts
DELETED
package/dist/src/schemas.d.ts
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
import type { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
2
|
-
import { type CustomErrorParams, type input, type output, type ZodEffects, type ZodType, type ZodTypeAny, type ZodTypeDef } from 'zod';
|
3
|
-
export type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL';
|
4
|
-
type CustomParams = CustomErrorParams & {
|
5
|
-
fatal?: boolean;
|
6
|
-
};
|
7
|
-
export declare function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined;
|
8
|
-
export declare function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined;
|
9
|
-
export declare function getCustomJSONSchema(def: ZodTypeDef, options?: {
|
10
|
-
mode?: 'input' | 'output';
|
11
|
-
}): Exclude<JSONSchema, boolean> | undefined;
|
12
|
-
export declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {
|
13
|
-
type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, InstanceType<typeof File>, InstanceType<typeof File>>;
|
14
|
-
};
|
15
|
-
export declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>>;
|
16
|
-
export declare function invalidDate(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Date, ZodTypeDef, Date>;
|
17
|
-
export declare function regexp(options?: CustomParams): ZodType<RegExp, ZodTypeDef, RegExp>;
|
18
|
-
export declare function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL>;
|
19
|
-
export declare function openapi<T extends ZodTypeAny, TMode extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema<TMode extends 'input' ? input<T> : TMode extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
|
20
|
-
mode: TMode;
|
21
|
-
}): ReturnType<T['refine']>;
|
22
|
-
export declare const oz: {
|
23
|
-
openapi: typeof openapi;
|
24
|
-
file: typeof file;
|
25
|
-
blob: typeof blob;
|
26
|
-
invalidDate: typeof invalidDate;
|
27
|
-
regexp: typeof regexp;
|
28
|
-
url: typeof url;
|
29
|
-
};
|
30
|
-
export {};
|
31
|
-
//# sourceMappingURL=schemas.d.ts.map
|