@orpc/zod 0.46.0 → 0.47.0
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/dist/index.d.mts +49 -56
- package/dist/index.d.ts +49 -56
- package/dist/index.mjs +702 -793
- package/package.json +9 -8
package/dist/index.d.mts
CHANGED
@@ -1,89 +1,82 @@
|
|
1
|
+
import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
|
2
|
+
import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod';
|
1
3
|
import { Context } from '@orpc/server';
|
2
4
|
import { Plugin } from '@orpc/server/plugins';
|
3
5
|
import { StandardHandlerOptions } from '@orpc/server/standard';
|
4
6
|
import { Schema } from '@orpc/contract';
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
declare function getCustomJsonSchema(def: ZodTypeDef, options: {
|
9
|
+
strategy: 'input' | 'output' | 'both';
|
10
|
+
}): Exclude<JSONSchema, boolean> | undefined;
|
11
|
+
declare function customJsonSchema<T extends ZodTypeAny, TStrategy extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema<TStrategy extends 'input' ? input<T> : TStrategy extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
|
12
|
+
strategy?: TStrategy;
|
13
|
+
}): T;
|
14
|
+
|
15
|
+
type CustomParams = CustomErrorParams & {
|
16
|
+
fatal?: boolean;
|
17
|
+
};
|
18
|
+
type CustomZodDef = {
|
19
|
+
type: 'blob' | 'regexp' | 'url';
|
20
|
+
} | {
|
21
|
+
type: 'file';
|
22
|
+
mimeType?: string;
|
23
|
+
};
|
24
|
+
declare function setCustomZodDef<T extends ZodTypeDef>(def: T, custom: CustomZodDef): void;
|
25
|
+
declare function getCustomZodDef(def: ZodTypeDef): CustomZodDef | undefined;
|
26
|
+
declare function composeParams<T = unknown>(defaultMessage: (input: T) => string, params: undefined | string | CustomParams | ((input: T) => CustomParams)): (input: T) => CustomParams;
|
27
|
+
|
28
|
+
declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Blob, ZodTypeDef, Blob>;
|
29
|
+
|
30
|
+
declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<File, ZodTypeDef, File> & {
|
31
|
+
type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<File, ZodTypeDef, File>, File, File>;
|
32
|
+
};
|
33
|
+
|
34
|
+
declare function regexp(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<RegExp, ZodTypeDef, RegExp>;
|
35
|
+
|
36
|
+
declare function url(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<URL, ZodTypeDef, URL>;
|
9
37
|
|
10
38
|
declare class ZodSmartCoercionPlugin<TContext extends Context> implements Plugin<TContext> {
|
11
39
|
init(options: StandardHandlerOptions<TContext>): void;
|
12
40
|
}
|
13
41
|
|
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
42
|
interface ZodToJsonSchemaOptions {
|
22
43
|
/**
|
23
44
|
* Max depth of lazy type, if it exceeds.
|
24
45
|
*
|
25
46
|
* Used `{}` when reach max depth
|
26
47
|
*
|
27
|
-
* @default
|
48
|
+
* @default 3
|
28
49
|
*/
|
29
50
|
maxLazyDepth?: number;
|
30
51
|
/**
|
31
|
-
* The
|
52
|
+
* The schema to be used when the Zod schema is unsupported.
|
32
53
|
*
|
33
|
-
* @
|
54
|
+
* @default { not: {} }
|
34
55
|
*/
|
35
|
-
|
56
|
+
unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
|
36
57
|
/**
|
37
|
-
* The
|
58
|
+
* The schema to be used to represent the any | unknown type.
|
38
59
|
*
|
39
|
-
* @default
|
60
|
+
* @default { }
|
40
61
|
*/
|
41
|
-
|
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;
|
62
|
+
anyJsonSchema?: Exclude<JSONSchema, boolean>;
|
54
63
|
}
|
55
|
-
declare
|
56
|
-
|
64
|
+
declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
|
65
|
+
#private;
|
66
|
+
private readonly maxLazyDepth;
|
67
|
+
private readonly unsupportedJsonSchema;
|
68
|
+
private readonly anyJsonSchema;
|
69
|
+
constructor(options?: ZodToJsonSchemaOptions);
|
57
70
|
condition(schema: Schema): boolean;
|
58
|
-
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema
|
71
|
+
convert(schema: Schema, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
|
59
72
|
}
|
60
73
|
|
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
74
|
declare const oz: {
|
81
|
-
openapi: typeof openapi;
|
82
75
|
file: typeof file;
|
83
76
|
blob: typeof blob;
|
84
|
-
invalidDate: typeof invalidDate;
|
85
|
-
regexp: typeof regexp;
|
86
77
|
url: typeof url;
|
78
|
+
regexp: typeof regexp;
|
79
|
+
openapi: typeof customJsonSchema;
|
87
80
|
};
|
88
81
|
|
89
|
-
export { type
|
82
|
+
export { type CustomParams, type CustomZodDef, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, type ZodToJsonSchemaOptions, blob, composeParams, customJsonSchema, file, getCustomJsonSchema, getCustomZodDef, oz, regexp, setCustomZodDef, url };
|
package/dist/index.d.ts
CHANGED
@@ -1,89 +1,82 @@
|
|
1
|
+
import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
|
2
|
+
import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod';
|
1
3
|
import { Context } from '@orpc/server';
|
2
4
|
import { Plugin } from '@orpc/server/plugins';
|
3
5
|
import { StandardHandlerOptions } from '@orpc/server/standard';
|
4
6
|
import { Schema } from '@orpc/contract';
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
declare function getCustomJsonSchema(def: ZodTypeDef, options: {
|
9
|
+
strategy: 'input' | 'output' | 'both';
|
10
|
+
}): Exclude<JSONSchema, boolean> | undefined;
|
11
|
+
declare function customJsonSchema<T extends ZodTypeAny, TStrategy extends 'input' | 'output' | 'both' = 'both'>(schema: T, custom: Exclude<JSONSchema<TStrategy extends 'input' ? input<T> : TStrategy extends 'output' ? output<T> : input<T> & output<T>>, boolean>, options?: {
|
12
|
+
strategy?: TStrategy;
|
13
|
+
}): T;
|
14
|
+
|
15
|
+
type CustomParams = CustomErrorParams & {
|
16
|
+
fatal?: boolean;
|
17
|
+
};
|
18
|
+
type CustomZodDef = {
|
19
|
+
type: 'blob' | 'regexp' | 'url';
|
20
|
+
} | {
|
21
|
+
type: 'file';
|
22
|
+
mimeType?: string;
|
23
|
+
};
|
24
|
+
declare function setCustomZodDef<T extends ZodTypeDef>(def: T, custom: CustomZodDef): void;
|
25
|
+
declare function getCustomZodDef(def: ZodTypeDef): CustomZodDef | undefined;
|
26
|
+
declare function composeParams<T = unknown>(defaultMessage: (input: T) => string, params: undefined | string | CustomParams | ((input: T) => CustomParams)): (input: T) => CustomParams;
|
27
|
+
|
28
|
+
declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<Blob, ZodTypeDef, Blob>;
|
29
|
+
|
30
|
+
declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<File, ZodTypeDef, File> & {
|
31
|
+
type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<File, ZodTypeDef, File>, File, File>;
|
32
|
+
};
|
33
|
+
|
34
|
+
declare function regexp(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<RegExp, ZodTypeDef, RegExp>;
|
35
|
+
|
36
|
+
declare function url(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<URL, ZodTypeDef, URL>;
|
9
37
|
|
10
38
|
declare class ZodSmartCoercionPlugin<TContext extends Context> implements Plugin<TContext> {
|
11
39
|
init(options: StandardHandlerOptions<TContext>): void;
|
12
40
|
}
|
13
41
|
|
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
42
|
interface ZodToJsonSchemaOptions {
|
22
43
|
/**
|
23
44
|
* Max depth of lazy type, if it exceeds.
|
24
45
|
*
|
25
46
|
* Used `{}` when reach max depth
|
26
47
|
*
|
27
|
-
* @default
|
48
|
+
* @default 3
|
28
49
|
*/
|
29
50
|
maxLazyDepth?: number;
|
30
51
|
/**
|
31
|
-
* The
|
52
|
+
* The schema to be used when the Zod schema is unsupported.
|
32
53
|
*
|
33
|
-
* @
|
54
|
+
* @default { not: {} }
|
34
55
|
*/
|
35
|
-
|
56
|
+
unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
|
36
57
|
/**
|
37
|
-
* The
|
58
|
+
* The schema to be used to represent the any | unknown type.
|
38
59
|
*
|
39
|
-
* @default
|
60
|
+
* @default { }
|
40
61
|
*/
|
41
|
-
|
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;
|
62
|
+
anyJsonSchema?: Exclude<JSONSchema, boolean>;
|
54
63
|
}
|
55
|
-
declare
|
56
|
-
|
64
|
+
declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
|
65
|
+
#private;
|
66
|
+
private readonly maxLazyDepth;
|
67
|
+
private readonly unsupportedJsonSchema;
|
68
|
+
private readonly anyJsonSchema;
|
69
|
+
constructor(options?: ZodToJsonSchemaOptions);
|
57
70
|
condition(schema: Schema): boolean;
|
58
|
-
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema
|
71
|
+
convert(schema: Schema, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
|
59
72
|
}
|
60
73
|
|
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
74
|
declare const oz: {
|
81
|
-
openapi: typeof openapi;
|
82
75
|
file: typeof file;
|
83
76
|
blob: typeof blob;
|
84
|
-
invalidDate: typeof invalidDate;
|
85
|
-
regexp: typeof regexp;
|
86
77
|
url: typeof url;
|
78
|
+
regexp: typeof regexp;
|
79
|
+
openapi: typeof customJsonSchema;
|
87
80
|
};
|
88
81
|
|
89
|
-
export { type
|
82
|
+
export { type CustomParams, type CustomZodDef, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, type ZodToJsonSchemaOptions, blob, composeParams, customJsonSchema, file, getCustomJsonSchema, getCustomZodDef, oz, regexp, setCustomZodDef, url };
|