@orpc/zod 0.0.0-next.cc4cb21 → 0.0.0-next.cc8802c

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
3
3
  </div>
4
4
 
5
5
  <h1></h1>
@@ -0,0 +1,82 @@
1
+ import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
2
+ import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod';
3
+ import { Context } from '@orpc/server';
4
+ import { HandlerPlugin } from '@orpc/server/plugins';
5
+ import { StandardHandlerOptions } from '@orpc/server/standard';
6
+ import { AnySchema } from '@orpc/contract';
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>;
37
+
38
+ declare class ZodSmartCoercionPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
39
+ init(options: StandardHandlerOptions<TContext>): void;
40
+ }
41
+
42
+ interface ZodToJsonSchemaOptions {
43
+ /**
44
+ * Max depth of lazy type, if it exceeds.
45
+ *
46
+ * Used `{}` when reach max depth
47
+ *
48
+ * @default 3
49
+ */
50
+ maxLazyDepth?: number;
51
+ /**
52
+ * The schema to be used when the Zod schema is unsupported.
53
+ *
54
+ * @default { not: {} }
55
+ */
56
+ unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
57
+ /**
58
+ * The schema to be used to represent the any | unknown type.
59
+ *
60
+ * @default { }
61
+ */
62
+ anyJsonSchema?: Exclude<JSONSchema, boolean>;
63
+ }
64
+ declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
65
+ #private;
66
+ private readonly maxLazyDepth;
67
+ private readonly unsupportedJsonSchema;
68
+ private readonly anyJsonSchema;
69
+ constructor(options?: ZodToJsonSchemaOptions);
70
+ condition(schema: AnySchema | undefined): boolean;
71
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
72
+ }
73
+
74
+ declare const oz: {
75
+ file: typeof file;
76
+ blob: typeof blob;
77
+ url: typeof url;
78
+ regexp: typeof regexp;
79
+ openapi: typeof customJsonSchema;
80
+ };
81
+
82
+ export { type CustomParams, type CustomZodDef, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, type ZodToJsonSchemaOptions, blob, composeParams, customJsonSchema, file, getCustomJsonSchema, getCustomZodDef, oz, regexp, setCustomZodDef, url };
@@ -0,0 +1,82 @@
1
+ import { JSONSchema, ConditionalSchemaConverter, SchemaConvertOptions } from '@orpc/openapi';
2
+ import { ZodTypeAny, input, output, ZodTypeDef, CustomErrorParams, ZodType, ZodEffects } from 'zod';
3
+ import { Context } from '@orpc/server';
4
+ import { HandlerPlugin } from '@orpc/server/plugins';
5
+ import { StandardHandlerOptions } from '@orpc/server/standard';
6
+ import { AnySchema } from '@orpc/contract';
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>;
37
+
38
+ declare class ZodSmartCoercionPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
39
+ init(options: StandardHandlerOptions<TContext>): void;
40
+ }
41
+
42
+ interface ZodToJsonSchemaOptions {
43
+ /**
44
+ * Max depth of lazy type, if it exceeds.
45
+ *
46
+ * Used `{}` when reach max depth
47
+ *
48
+ * @default 3
49
+ */
50
+ maxLazyDepth?: number;
51
+ /**
52
+ * The schema to be used when the Zod schema is unsupported.
53
+ *
54
+ * @default { not: {} }
55
+ */
56
+ unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
57
+ /**
58
+ * The schema to be used to represent the any | unknown type.
59
+ *
60
+ * @default { }
61
+ */
62
+ anyJsonSchema?: Exclude<JSONSchema, boolean>;
63
+ }
64
+ declare class ZodToJsonSchemaConverter implements ConditionalSchemaConverter {
65
+ #private;
66
+ private readonly maxLazyDepth;
67
+ private readonly unsupportedJsonSchema;
68
+ private readonly anyJsonSchema;
69
+ constructor(options?: ZodToJsonSchemaOptions);
70
+ condition(schema: AnySchema | undefined): boolean;
71
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions, lazyDepth?: number, isHandledCustomJSONSchema?: boolean, isHandledZodDescription?: boolean): [required: boolean, jsonSchema: Exclude<JSONSchema, boolean>];
72
+ }
73
+
74
+ declare const oz: {
75
+ file: typeof file;
76
+ blob: typeof blob;
77
+ url: typeof url;
78
+ regexp: typeof regexp;
79
+ openapi: typeof customJsonSchema;
80
+ };
81
+
82
+ export { type CustomParams, type CustomZodDef, ZodSmartCoercionPlugin, ZodToJsonSchemaConverter, type ZodToJsonSchemaOptions, blob, composeParams, customJsonSchema, file, getCustomJsonSchema, getCustomZodDef, oz, regexp, setCustomZodDef, url };