@orpc/zod
Advanced tools
Comparing version 0.0.0-next-20241120100614 to 0.0.0-next-20241126131150
import type { JSONSchema } from 'json-schema-typed/draft-2020-12'; | ||
import { type CustomErrorParams, type ZodEffects, type ZodType, type ZodTypeAny, type ZodTypeDef, type input, type output } from 'zod'; | ||
import { type CustomErrorParams, type input, type output, type ZodEffects, type ZodType, type ZodTypeAny, type ZodTypeDef } from 'zod'; | ||
export type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL'; | ||
@@ -13,3 +13,3 @@ type CustomParams = CustomErrorParams & { | ||
export declare function file(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & { | ||
type(mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodEffects<ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, InstanceType<typeof File>, InstanceType<typeof File>>; | ||
type: (mimeType: string, params?: string | CustomParams | ((input: unknown) => CustomParams)) => ZodEffects<ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, InstanceType<typeof File>, InstanceType<typeof File>>; | ||
}; | ||
@@ -16,0 +16,0 @@ export declare function blob(params?: string | CustomParams | ((input: unknown) => CustomParams)): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>>; |
{ | ||
"name": "@orpc/zod", | ||
"type": "module", | ||
"version": "0.0.0-next-20241120100614", | ||
"version": "0.0.0-next-20241126131150", | ||
"author": { | ||
@@ -11,7 +11,7 @@ "name": "unnoq", | ||
"license": "MIT", | ||
"homepage": "https://github.com/unnoq/unnoq", | ||
"homepage": "https://github.com/unnoq/orpc", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/unnoq/unnoq.git", | ||
"directory": "examples/typescript-vite-package" | ||
"url": "https://github.com/unnoq/orpc.git", | ||
"directory": "packages/zod" | ||
}, | ||
@@ -18,0 +18,0 @@ "keywords": [ |
@@ -7,3 +7,6 @@ /// <reference lib="dom" /> | ||
import { | ||
custom, | ||
type CustomErrorParams, | ||
type input, | ||
type output, | ||
type ZodEffects, | ||
@@ -13,5 +16,2 @@ type ZodType, | ||
type ZodTypeDef, | ||
custom, | ||
type input, | ||
type output, | ||
} from 'zod' | ||
@@ -69,4 +69,4 @@ | ||
return (val) => { | ||
const defaultMessage = | ||
typeof options.defaultMessage === 'function' | ||
const defaultMessage | ||
= typeof options.defaultMessage === 'function' | ||
? options.defaultMessage(val) | ||
@@ -104,6 +104,6 @@ : options.defaultMessage | ||
): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & { | ||
type( | ||
type: ( | ||
mimeType: string, | ||
params?: string | CustomParams | ((input: unknown) => CustomParams), | ||
): ZodEffects< | ||
) => ZodEffects< | ||
ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>, | ||
@@ -115,3 +115,3 @@ InstanceType<typeof File>, | ||
const schema = custom<InstanceType<typeof File>>( | ||
(val) => val instanceof File, | ||
val => val instanceof File, | ||
composeParams({ params, defaultMessage: 'Input is not a file' }), | ||
@@ -127,3 +127,3 @@ ) | ||
mimeType: string, | ||
params: string | CustomParams | ((input: unknown) => CustomParams), | ||
params?: string | CustomParams | ((input: unknown) => CustomParams), | ||
) => { | ||
@@ -133,6 +133,6 @@ const isMatch = wcmatch(mimeType) | ||
const refinedSchema = schema.refine( | ||
(val) => isMatch(val.type.split(';')[0]!), | ||
val => isMatch(val.type.split(';')[0]!), | ||
composeParams<InstanceType<typeof File>>({ | ||
params, | ||
defaultMessage: (val) => | ||
defaultMessage: val => | ||
`Expected a file of type ${mimeType} but got a file of type ${val.type || 'unknown'}`, | ||
@@ -156,3 +156,3 @@ }), | ||
const schema = custom<InstanceType<typeof Blob>>( | ||
(val) => val instanceof Blob, | ||
val => val instanceof Blob, | ||
composeParams({ params, defaultMessage: 'Input is not a blob' }), | ||
@@ -172,3 +172,3 @@ ) | ||
const schema = custom<Date>( | ||
(val) => val instanceof Date && Number.isNaN(val.getTime()), | ||
val => val instanceof Date && Number.isNaN(val.getTime()), | ||
composeParams({ params, defaultMessage: 'Input is not an invalid date' }), | ||
@@ -188,3 +188,3 @@ ) | ||
const schema = custom<RegExp>( | ||
(val) => val instanceof RegExp, | ||
val => val instanceof RegExp, | ||
composeParams({ params: options, defaultMessage: 'Input is not a regexp' }), | ||
@@ -202,3 +202,3 @@ ) | ||
const schema = custom<URL>( | ||
(val) => val instanceof URL, | ||
val => val instanceof URL, | ||
composeParams({ params: options, defaultMessage: 'Input is not a URL' }), | ||
@@ -233,4 +233,4 @@ ) | ||
const SYMBOL = | ||
options?.mode === 'input' | ||
const SYMBOL | ||
= options?.mode === 'input' | ||
? CUSTOM_JSON_SCHEMA_INPUT_SYMBOL | ||
@@ -237,0 +237,0 @@ : options?.mode === 'output' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
43770