arri-validate
Advanced tools
Comparing version 0.42.2 to 0.43.0
@@ -1,3 +0,3 @@ | ||
import { A as ASchemaOptions, a as ASchema, b as AArraySchema, c as AScalarSchema, d as AObjectSchema, e as ADiscriminatorSchema, I as InferType, R as ResolveObject, f as AStringEnumSchema, g as AObjectSchemaOptions, h as InferObjectOutput, V as ValidationData, i as ARecordSchema, j as ARefSchema, S as SafeResult, k as coerce, l as errors, m as InferSubType, p as parse, s as safeCoerce, n as safeParse, o as serialize, v as validate, q as SchemaValidator, r as SchemaMetadata, t as SCHEMA_METADATA } from './shared/arri-validate.b7c77149.js'; | ||
export { K as InferObjectRawType, M as MaybeNullable, D as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, x as ValidationError, w as ValueError, E as isAAraySchema, G as isADiscriminatorSchema, J as isAObjectSchema, H as isARecordSchema, O as isARefSchema, C as isAScalarSchema, z as isASchema, F as isAStringEnumSchema, L as isObject, y as isValidationError, u as sanitizeJson } from './shared/arri-validate.b7c77149.js'; | ||
import { A as ASchemaOptions, a as ASchema, b as AArraySchema, c as AScalarSchema, d as AObjectSchema, e as ADiscriminatorSchema, I as InferType, R as ResolveObject, f as AStringEnumSchema, g as InferObjectOutput, h as AObjectSchemaOptions, V as ValidationData, i as ARecordSchema, j as ARefSchema, S as SafeResult, k as coerce, l as errors, m as InferSubType, p as parse, s as safeCoerce, n as safeParse, o as serialize, v as validate, q as SchemaValidator, r as SchemaMetadata, t as SCHEMA_METADATA } from './shared/arri-validate.0f3a59a1.js'; | ||
export { K as InferObjectRawType, M as MaybeNullable, D as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, x as ValidationError, w as ValueError, E as isAAraySchema, G as isADiscriminatorSchema, J as isAObjectSchema, H as isARecordSchema, O as isARefSchema, C as isAScalarSchema, z as isASchema, F as isAStringEnumSchema, L as isObject, y as isValidationError, u as sanitizeJson } from './shared/arri-validate.0f3a59a1.js'; | ||
import { Schema } from 'jtd-utils'; | ||
@@ -54,2 +54,3 @@ | ||
*/ | ||
declare function discriminator<TDiscriminatorKey extends string, TMapping extends Record<string, AObjectSchema<any>>>(id: string, discriminator: TDiscriminatorKey, mapping: TMapping): ADiscriminatorSchema<InferDiscriminatorType<TDiscriminatorKey, TMapping, JoinedDiscriminator<TDiscriminatorKey, TMapping>>>; | ||
declare function discriminator<TDiscriminatorKey extends string, TMapping extends Record<string, AObjectSchema<any>>>(discriminator: TDiscriminatorKey, mapping: TMapping, opts?: ASchemaOptions): ADiscriminatorSchema<InferDiscriminatorType<TDiscriminatorKey, TMapping, JoinedDiscriminator<TDiscriminatorKey, TMapping>>>; | ||
@@ -127,3 +128,3 @@ type JoinedDiscriminator<TUnionKey extends string, TInput extends Record<string, AObjectSchema<any>>> = { | ||
* @example | ||
* const Schema = a.object({ | ||
* const Schema = a.object('Schema', { | ||
* foo: a.string(), | ||
@@ -135,2 +136,3 @@ * bar: a.number() | ||
*/ | ||
declare function object<TInput extends Record<any, ASchema> = any, TAdditionalProps extends boolean = false>(id: string, input: TInput): AObjectSchema<InferObjectOutput<TInput, TAdditionalProps>, TAdditionalProps>; | ||
declare function object<TInput extends Record<any, ASchema> = any, TAdditionalProps extends boolean = false>(input: TInput, opts?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchema<InferObjectOutput<TInput, TAdditionalProps>, TAdditionalProps>; | ||
@@ -188,3 +190,22 @@ declare function parseObjectSchema<T>(schema: AObjectSchema<T>, input: unknown, data: ValidationData, coerce?: boolean): T | undefined; | ||
declare function recursive<T>(callback: (self: ARefSchema<T>) => AObjectSchema<T> | ADiscriminatorSchema<T>, options?: ASchemaOptions): AObjectSchema<T> | ADiscriminatorSchema<T>; | ||
type RecursiveCallback<T> = (self: ARefSchema<T>) => AObjectSchema<T> | ADiscriminatorSchema<T>; | ||
/** | ||
* @example | ||
* ```ts | ||
* type BinaryTree = { | ||
* left: BinaryTree | null; | ||
* right: BinaryTree | null; | ||
* } | ||
* | ||
* const BinaryTree = a.recursive<BinaryTree>( | ||
* "BinaryTree", | ||
* (self) => a.object({ | ||
* left: a.nullable(self), | ||
* right: a.nullable(self), | ||
* }) | ||
* ); | ||
* ``` | ||
*/ | ||
declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>): AObjectSchema<T> | ADiscriminatorSchema<T>; | ||
declare function recursive<T = any>(callback: RecursiveCallback<T>, options?: ASchemaOptions): AObjectSchema<T> | ADiscriminatorSchema<T>; | ||
@@ -191,0 +212,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import { d as AObjectSchema, e as ADiscriminatorSchema, a as ASchema } from './shared/arri-validate.b7c77149.js'; | ||
import { d as AObjectSchema, e as ADiscriminatorSchema, a as ASchema } from './shared/arri-validate.0f3a59a1.js'; | ||
import 'jtd-utils'; | ||
@@ -3,0 +3,0 @@ |
{ | ||
"name": "arri-validate", | ||
"version": "0.42.2", | ||
"version": "0.43.0", | ||
"type": "module", | ||
@@ -27,3 +27,3 @@ "license": "MIT", | ||
"uncrypto": "^0.1.3", | ||
"jtd-utils": "0.42.2" | ||
"jtd-utils": "0.43.0" | ||
}, | ||
@@ -30,0 +30,0 @@ "devDependencies": { |
@@ -736,2 +736,3 @@ # Arri Validate | ||
```ts | ||
// metadata object | ||
const BookSchema = a.object( | ||
@@ -805,2 +806,35 @@ { | ||
### ID Shorthand | ||
Because IDs are really important for producing consise type names. Arri validate also provides a shorthand for defining IDs of objects, discriminators, and recursive types. | ||
```ts | ||
// ID will be set to "Book" | ||
const BookSchema = a.object("Book", { | ||
title: a.string(), | ||
author: a.string(), | ||
publishDate: a.timestamp(), | ||
}); | ||
// ID will be set to "Message" | ||
const MessageSchema = a.discriminator("Message", "type", { | ||
TEXT: a.object({ | ||
userId: a.string(), | ||
content: a.string(), | ||
}), | ||
IMAGE: a.object({ | ||
userId: a.string(), | ||
imageUrl: a.string(), | ||
}), | ||
}); | ||
// ID will be set to "BTree" | ||
const BinaryTreeSchema = a.recursive("BTree", (self) => | ||
a.object({ | ||
left: a.nullable(self), | ||
right: a.nullable(self), | ||
}), | ||
); | ||
``` | ||
## Benchmarks | ||
@@ -807,0 +841,0 @@ |
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
460835
11000
982
+ Addedjtd-utils@0.43.0(transitive)
- Removedjtd-utils@0.42.2(transitive)
Updatedjtd-utils@0.43.0