Comparing version 1.0.0-beta.4 to 1.0.0-beta.5
@@ -23,4 +23,4 @@ declare type Maybe<T> = T | null | undefined; | ||
}; | ||
declare type TypeFromShape<S extends ObjectShape, C> = { | ||
[K in keyof S]: S[K] extends ISchema<any, C> ? S[K]['__outputType'] : unknown; | ||
declare type TypeFromShape<S extends ObjectShape, _C> = { | ||
[K in keyof S]: S[K] extends ISchema<any, any> ? S[K]['__outputType'] : unknown; | ||
}; | ||
@@ -118,3 +118,3 @@ declare type DefaultFromShape<Shape extends ObjectShape> = { | ||
declare type SchemaSpec<TDefault> = { | ||
coarce: boolean; | ||
coerce: boolean; | ||
nullable: boolean; | ||
@@ -143,2 +143,11 @@ optional: boolean; | ||
} | ||
interface CastOptionalityOptions<C = {}> extends Omit<CastOptions<C>, 'assert'> { | ||
/** | ||
* Whether or not to throw TypeErrors if casting fails to produce a valid type. | ||
* defaults to `true`. The `'ignore-optionality'` options is provided as a migration | ||
* path from pre-v1 where `schema.nullable().required()` was allowed. When provided | ||
* cast will only throw for values that are the wrong type *not* including `null` and `undefined` | ||
*/ | ||
assert: 'ignore-optionality'; | ||
} | ||
declare type RunTest = (opts: TestOptions, panic: PanicCallback, next: NextCallback) => void; | ||
@@ -213,2 +222,3 @@ declare type TestRunOptions = { | ||
cast(value: any, options?: CastOptions<TContext>): this['__outputType']; | ||
cast(value: any, options: CastOptionalityOptions<TContext>): this['__outputType'] | null | undefined; | ||
protected _cast(rawValue: any, _options: CastOptions<TContext>): any; | ||
@@ -336,2 +346,3 @@ protected _validate(_value: any, options: InternalOptions<TContext> | undefined, panic: (err: Error, value: unknown) => void, next: (err: ValidationError[], value: unknown) => void): void; | ||
cast(value: any, options?: CastOptions<C>): T; | ||
cast(value: any, options: CastOptionalityOptions<C>): T | null | undefined; | ||
validate(value: any, options?: ValidateOptions<C>): Promise<T>; | ||
@@ -795,8 +806,8 @@ asNestedTest(config: NestedTestConfig): Test; | ||
declare type LazyBuilder<T, TContext = AnyObject, TDefault = any, TFlags extends Flags = any> = (value: any, options: ResolveOptions) => ISchema<T, TContext, TFlags, TDefault>; | ||
declare function create<T, TContext = AnyObject, TFlags extends Flags = any, TDefault = any>(builder: LazyBuilder<T, TContext, TDefault, TFlags>): Lazy<T, TContext, TDefault, TFlags>; | ||
declare function create<TSchema extends ISchema<any, TContext>, TContext = AnyObject>(builder: (value: any, options: ResolveOptions<TContext>) => TSchema): Lazy<InferType<TSchema>, TContext, any>; | ||
interface LazySpec { | ||
meta: Record<string, unknown> | undefined; | ||
optional: boolean; | ||
} | ||
declare class Lazy<T, TContext = AnyObject, TDefault = any, TFlags extends Flags = any> implements ISchema<T, TContext, TFlags, TDefault> { | ||
declare class Lazy<T, TContext = AnyObject, TFlags extends Flags = any> implements ISchema<T, TContext, TFlags, undefined> { | ||
private builder; | ||
@@ -808,9 +819,12 @@ type: "lazy"; | ||
readonly __flags: TFlags; | ||
readonly __default: TDefault; | ||
readonly __default: undefined; | ||
spec: LazySpec; | ||
constructor(builder: LazyBuilder<T, TContext, TDefault, TFlags>); | ||
clone(): Lazy<T, TContext, TDefault, TFlags>; | ||
constructor(builder: any); | ||
clone(spec?: Partial<LazySpec>): Lazy<T, TContext, TFlags>; | ||
private _resolve; | ||
resolve(options: ResolveOptions<TContext>): Schema<T, TContext, TDefault, TFlags>; | ||
private optionality; | ||
optional(): Lazy<T | undefined, TContext, TFlags>; | ||
resolve(options: ResolveOptions<TContext>): Schema<T, TContext, undefined, TFlags>; | ||
cast(value: any, options?: CastOptions<TContext>): T; | ||
cast(value: any, options?: CastOptionalityOptions<TContext>): T | null | undefined; | ||
asNestedTest(options: NestedTestConfig): RunTest; | ||
@@ -825,3 +839,3 @@ validate(value: any, options?: ValidateOptions<TContext>): Promise<T>; | ||
meta(): Record<string, unknown> | undefined; | ||
meta(obj: Record<string, unknown>): Lazy<T, TContext, TDefault, TFlags>; | ||
meta(obj: Record<string, unknown>): Lazy<T, TContext, TFlags>; | ||
} | ||
@@ -844,2 +858,2 @@ | ||
export { AnyObject, AnyObjectSchema, AnySchema, ArraySchema, InferType as Asserts, BooleanSchema, CreateErrorOptions, DateSchema, InferType, MixedOptions, MixedSchema, NumberSchema, ObjectSchema, Schema, StringSchema, TestConfig, TestContext, TestFunction, TestOptions, TupleSchema, TypeGuard, ValidationError, addMethod, create$2 as array, create$7 as bool, create$7 as boolean, create$4 as date, getIn, isSchema, create as lazy, create$8 as mixed, create$5 as number, create$3 as object, reach, create$9 as ref, setLocale, create$6 as string, create$1 as tuple }; | ||
export { AnyObject, AnyObjectSchema, AnySchema, ArraySchema, InferType as Asserts, BooleanSchema, CreateErrorOptions, DateSchema, InferType, LocaleObject, MixedOptions, MixedSchema, NumberSchema, ObjectSchema, Schema, SchemaDescription, SchemaFieldDescription, SchemaInnerTypeDescription, SchemaLazyDescription, SchemaObjectDescription, SchemaRefDescription, StringSchema, TestConfig, TestContext, TestFunction, TestOptions, TupleSchema, TypeGuard, ValidationError, addMethod, create$2 as array, create$7 as bool, create$7 as boolean, create$4 as date, getIn, isSchema, create as lazy, create$8 as mixed, create$5 as number, create$3 as object, reach, create$9 as ref, setLocale, create$6 as string, create$1 as tuple }; |
{ | ||
"name": "yup", | ||
"version": "1.0.0-beta.4", | ||
"version": "1.0.0-beta.5", | ||
"description": "Dead simple Object schema validation", | ||
"main": "index.js", | ||
"module": "index.esm.js", | ||
"main": "lib/index.js", | ||
"module": "lib/index.esm.js", | ||
"runkitExampleFilename": "./runkit-example.js", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -48,3 +48,3 @@ # Yup | ||
```ts | ||
// Attempts to coarce values to the correct type | ||
// Attempts to coerce values to the correct type | ||
const parsedUser = userSchema.cast({ | ||
@@ -231,3 +231,3 @@ name: 'jimmy', | ||
yup has robust support for assertions, or "tests", over input values. Tests check that inputs conform to some | ||
Yup has robust support for assertions, or "tests", over input values. Tests check that inputs conform to some | ||
criteria. Tests are distinct from transforms, in that they do not change or alter the input (or its type) | ||
@@ -259,3 +259,3 @@ and are usually reserved for checks that are hard, if not impossible, to represent in static types. | ||
> (in this case an optional string). It still may be `undefined` or `null` depending on your schema | ||
> in those cases, you may want to return `true` for absent values unless your transform, makes presence | ||
> in those cases, you may want to return `true` for absent values unless your transform makes presence | ||
> related assertions | ||
@@ -280,3 +280,3 @@ | ||
Yup schema produce, static TypeScript interfaces. Use `InferType` to extract that interface: | ||
Yup schema produce static TypeScript interfaces. Use `InferType` to extract that interface: | ||
@@ -302,4 +302,4 @@ ```ts | ||
a schema's default is used when casting produces an `undefined` output value. Because of this, | ||
setting a default affects the output type of the schema, effectively marking it as "defined()". | ||
A schema's default is used when casting produces an `undefined` output value. Because of this, | ||
setting a default affects the output type of the schema, essentially marking it as "defined()". | ||
@@ -318,3 +318,3 @@ ```ts | ||
In some cases, the TypeScript type already exists, and you want to ensure that | ||
In some cases a TypeScript type already exists, and you want to ensure that | ||
your schema produces a compatible type: | ||
@@ -378,4 +378,4 @@ | ||
We also recommend settings `strictFunctionTypes` to `false`, for functionally better types. Yes | ||
this reduces overall soundness, however TypeScript already disables this check | ||
anyway for methods and constructors (note from TS docs): | ||
this reduces overall soundness, however TypeScript already disables this check | ||
for methods and constructors (note from TS docs): | ||
@@ -719,3 +719,3 @@ > During development of this feature, we discovered a large number of inherently | ||
stripUnknown: boolean = false; | ||
// when `false` validations will be preformed shallowly | ||
// when `false` validations will be performed shallowly | ||
recursive: boolean = true; | ||
@@ -1098,7 +1098,9 @@ // External values that can be provided to validations and conditionals | ||
// or make it async by returning a promise | ||
let asyncJimmySchema = string().test( | ||
'is-jimmy', | ||
'${path} is not Jimmy', | ||
async (value, testContext) => (await fetch('/is-jimmy/' + value)).responseText === 'true', | ||
}); | ||
let asyncJimmySchema = string() | ||
.label('First name') | ||
.test( | ||
'is-jimmy', | ||
({ label }) => `${label} is not Jimmy`, // a message can also be a function | ||
async (value, testContext) => (await fetch('/is-jimmy/' + value)).responseText === 'true', | ||
); | ||
@@ -1414,3 +1416,3 @@ await schema.isValid('jimmy'); // => true | ||
Define an array schema. Arrays can be typed or not, When specifying the element type, `cast` and `isValid` | ||
will apply to the elements as well. Options passed into `isValid` are passed also passed to child schemas. | ||
will apply to the elements as well. Options passed into `isValid` are also passed to child schemas. | ||
@@ -1417,0 +1419,0 @@ Inherits from [`Schema`](#Schema). |
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
240647
5173
1648