Comparing version 1.2.0 to 1.3.0
@@ -19,3 +19,6 @@ import { Get } from 'type-fest'; | ||
type Params = Record<string, unknown>; | ||
declare class ValidationError extends Error { | ||
declare class ValidationError implements Error { | ||
name: string; | ||
message: string; | ||
stack?: string | undefined; | ||
value: any; | ||
@@ -29,3 +32,4 @@ path?: string; | ||
static isError(err: any): err is ValidationError; | ||
constructor(errorOrErrors: string | ValidationError | readonly ValidationError[], value?: any, field?: string, type?: string); | ||
constructor(errorOrErrors: string | ValidationError | readonly ValidationError[], value?: any, field?: string, type?: string, disableStack?: boolean); | ||
[Symbol.toStringTag]: string; | ||
} | ||
@@ -40,2 +44,3 @@ | ||
type?: string; | ||
disableStackTrace?: boolean; | ||
}; | ||
@@ -91,5 +96,9 @@ type TestContext<TContext = {}> = { | ||
recursive?: boolean; | ||
disableStackTrace?: boolean; | ||
label?: string | undefined; | ||
meta?: any; | ||
meta?: SchemaMetadata; | ||
}; | ||
interface CustomSchemaMetadata { | ||
} | ||
type SchemaMetadata = keyof CustomSchemaMetadata extends never ? Record<PropertyKey, any> : CustomSchemaMetadata; | ||
type SchemaOptions<TType, TDefault> = { | ||
@@ -139,3 +148,3 @@ type: string; | ||
label?: string; | ||
meta: object | undefined; | ||
meta?: SchemaMetadata; | ||
} | ||
@@ -146,3 +155,3 @@ type SchemaFieldDescription = SchemaDescription | SchemaRefDescription | SchemaObjectDescription | SchemaInnerTypeDescription | SchemaLazyDescription; | ||
label?: string; | ||
meta: object | undefined; | ||
meta?: SchemaMetadata; | ||
oneOf: unknown[]; | ||
@@ -180,4 +189,4 @@ notOneOf: unknown[]; | ||
label(label: string): this; | ||
meta(): Record<string, unknown> | undefined; | ||
meta(obj: Record<string, unknown>): this; | ||
meta(): SchemaMetadata | undefined; | ||
meta(obj: SchemaMetadata): this; | ||
withMutation<T>(fn: (schema: this) => T): T; | ||
@@ -377,2 +386,6 @@ concat(schema: this): this; | ||
/** | ||
* When true ValidationError instance won't include stack trace information. Default - false | ||
*/ | ||
disableStackTrace?: boolean; | ||
/** | ||
* Any context needed for validating schema conditions (see: when()) | ||
@@ -541,2 +554,5 @@ */ | ||
} | ||
interface TupleLocale { | ||
notType?: Message; | ||
} | ||
interface BooleanLocale { | ||
@@ -553,2 +569,3 @@ isValue?: Message; | ||
array?: ArrayLocale; | ||
tuple?: TupleLocale; | ||
} | ||
@@ -871,2 +888,2 @@ declare const _default: LocaleObject; | ||
export { AnyObject, AnyObjectSchema, AnySchema, ArraySchema, InferType as Asserts, BooleanSchema, CastOptions, CreateErrorOptions, DateSchema, DefaultFromShape, DefaultThunk, Defined, Flags, ISchema, InferType, LocaleObject, MakePartial, Maybe, Message, MixedOptions, MixedSchema, TypeGuard as MixedTypeGuard, NotNull, NumberSchema, ObjectSchema, ObjectShape, Optionals, Schema, SchemaDescription, SchemaFieldDescription, SchemaInnerTypeDescription, SchemaLazyDescription, SchemaObjectDescription, SchemaRefDescription, SetFlag, StringSchema, TestConfig, TestContext, TestFunction, TestOptions, ToggleDefault, TupleSchema, TypeFromShape, UnsetFlag, ValidateOptions, ValidationError, addMethod, create$2 as array, create$7 as bool, create$7 as boolean, create$4 as date, _default as defaultLocale, getIn, isSchema, create as lazy, create$8 as mixed, create$5 as number, create$3 as object, printValue, reach, create$9 as ref, setLocale, create$6 as string, create$1 as tuple }; | ||
export { AnyObject, AnyObjectSchema, AnySchema, ArraySchema, InferType as Asserts, BooleanSchema, CastOptions, CreateErrorOptions, CustomSchemaMetadata, DateSchema, DefaultFromShape, DefaultThunk, Defined, Flags, ISchema, InferType, Lazy, LocaleObject, MakePartial, Maybe, Message, MixedOptions, MixedSchema, TypeGuard as MixedTypeGuard, NotNull, NumberSchema, ObjectSchema, ObjectShape, Optionals, Reference, Schema, SchemaDescription, SchemaFieldDescription, SchemaInnerTypeDescription, SchemaLazyDescription, SchemaMetadata, SchemaObjectDescription, SchemaRefDescription, SetFlag, StringSchema, TestConfig, TestContext, TestFunction, TestOptions, ToggleDefault, TupleSchema, TypeFromShape, UnsetFlag, ValidateOptions, ValidationError, addMethod, create$2 as array, create$7 as bool, create$7 as boolean, create$4 as date, _default as defaultLocale, getIn, isSchema, create as lazy, create$8 as mixed, create$5 as number, create$3 as object, printValue, reach, create$9 as ref, setLocale, create$6 as string, create$1 as tuple }; |
{ | ||
"name": "yup", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Dead simple Object schema validation", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -98,3 +98,3 @@ # Yup | ||
- [`Schema.label(label: string): Schema`](#schemalabellabel-string-schema) | ||
- [`Schema.meta(metadata: object): Schema`](#schemametametadata-object-schema) | ||
- [`Schema.meta(metadata: SchemaMetadata): Schema`](#schemametametadata-schemametadata-schema) | ||
- [`Schema.describe(options?: ResolveOptions): SchemaDescription`](#schemadescribeoptions-resolveoptions-schemadescription) | ||
@@ -354,3 +354,3 @@ - [`Schema.concat(schema: Schema): Schema`](#schemaconcatschema-schema-schema) | ||
age: number().optional(), | ||
sex: string<'male' | 'female' | 'other'>().nullable().defined(); | ||
sex: string<'male' | 'female' | 'other'>().nullable().defined(), | ||
}); | ||
@@ -636,7 +636,27 @@ | ||
#### `Schema.meta(metadata: object): Schema` | ||
#### `Schema.meta(metadata: SchemaMetadata): Schema` | ||
Adds to a metadata object, useful for storing data with a schema, that doesn't belong | ||
the cast object itself. | ||
to the cast object itself. | ||
A custom `SchemaMetadata` interface can be defined through | ||
[merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-interfaces) | ||
with the `CustomSchemaMetadata` interface. Start by creating a `yup.d.ts` file | ||
in your package and creating your desired `CustomSchemaMetadata` interface: | ||
```ts | ||
// yup.d.ts | ||
import 'yup'; | ||
declare module 'yup' { | ||
// Define your desired `SchemaMetadata` interface by merging the | ||
// `CustomSchemaMetadata` interface. | ||
export interface CustomSchemaMetadata { | ||
placeholderText?: string | ||
tooltipText?: string | ||
// … | ||
} | ||
} | ||
``` | ||
#### `Schema.describe(options?: ResolveOptions): SchemaDescription` | ||
@@ -643,0 +663,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
247503
5371
1723