Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.2
@@ -1,4 +0,4 @@ | ||
import type { AnyObject, InternalOptions, Callback, Message, Maybe, Optionals } from './types'; | ||
import type { AnyObject, InternalOptions, Callback, Message, Maybe } from './types'; | ||
import type Reference from './Reference'; | ||
import { Asserts, Config, Defined, NotNull, SetFlag, Thunk, ToggleDefault, TypeOf } from './util/types'; | ||
import { Asserts, Config, Defined, NotNull, SetFlag, Thunk, ToggleDefault } from './util/types'; | ||
import BaseSchema, { AnySchema, SchemaInnerTypeDescription, SchemaSpec } from './schema'; | ||
@@ -8,7 +8,7 @@ import Lazy from './Lazy'; | ||
export declare type RejectorFn = (value: any, index: number, array: any[]) => boolean; | ||
export declare function create<C extends AnyObject = AnyObject, T extends AnySchema | Lazy<any, any> = AnySchema>(type?: T): ArraySchema<T, Config<C, "">, TypeOf<T>[] | undefined>; | ||
export declare function create<C extends AnyObject = AnyObject, T extends AnySchema | Lazy<any, any> = AnySchema>(type?: T): ArraySchema<T, Config<C, "">, Asserts<T>[] | undefined>; | ||
export declare namespace create { | ||
var prototype: ArraySchema<any, any, any>; | ||
} | ||
export default class ArraySchema<T extends AnySchema | Lazy<any, any>, C extends Config<any, any> = Config, TIn extends Maybe<TypeOf<T>[]> = TypeOf<T>[] | undefined> extends BaseSchema<TIn, Asserts<T>[] | Optionals<TIn>, C> { | ||
export default class ArraySchema<T extends AnySchema | Lazy<any, any>, C extends Config<any, any> = Config, TIn extends Maybe<Asserts<T>[]> = Asserts<T>[] | undefined> extends BaseSchema<TIn, C> { | ||
innerType?: T; | ||
@@ -37,3 +37,3 @@ constructor(type?: T); | ||
} | ||
export default interface ArraySchema<T extends AnySchema | Lazy<any, any>, C extends Config<any, any> = Config, TIn extends Maybe<TypeOf<T>[]> = TypeOf<T>[] | undefined> extends BaseSchema<TIn, Asserts<T>[] | Optionals<TIn>, C> { | ||
export default interface ArraySchema<T extends AnySchema | Lazy<any, any>, C extends Config<any, any> = Config, TIn extends Maybe<Asserts<T>[]> = Asserts<T>[] | undefined> extends BaseSchema<TIn, C> { | ||
default<D extends Maybe<TIn>>(def: Thunk<D>): ArraySchema<T, ToggleDefault<C, D>, TIn>; | ||
@@ -40,0 +40,0 @@ defined(msg?: Message): ArraySchema<T, C, Defined<TIn>>; |
@@ -12,3 +12,3 @@ import BaseSchema from './schema'; | ||
} | ||
export default class BooleanSchema<TType extends Maybe<boolean> = boolean | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default class BooleanSchema<TType extends Maybe<boolean> = boolean | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
constructor(); | ||
@@ -19,3 +19,3 @@ protected _typeCheck(v: any): v is NonNullable<TType>; | ||
} | ||
export default interface BooleanSchema<TType extends Maybe<boolean>, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default interface BooleanSchema<TType extends Maybe<boolean>, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
default<D extends Maybe<TType>>(def: Thunk<D>): BooleanSchema<TType, ToggleDefault<TConfig, D>>; | ||
@@ -22,0 +22,0 @@ concat<TOther extends BooleanSchema<any, any>>(schema: TOther): TOther; |
@@ -15,3 +15,3 @@ import Ref from './Reference'; | ||
} | ||
export default class DateSchema<TType extends Maybe<Date> = Date | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default class DateSchema<TType extends Maybe<Date> = Date | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
static INVALID_DATE: Date; | ||
@@ -28,3 +28,3 @@ constructor(); | ||
} | ||
export default interface DateSchema<TType extends Maybe<Date>, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default interface DateSchema<TType extends Maybe<Date>, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
default<D extends Maybe<TType>>(def: Thunk<D>): DateSchema<TType, ToggleDefault<TConfig, D>>; | ||
@@ -31,0 +31,0 @@ concat<TOther extends DateSchema<any, any>>(schema: TOther): TOther; |
@@ -19,5 +19,5 @@ import MixedSchema, { create as mixedCreate } from './mixed'; | ||
declare type ObjectSchemaOf<T extends AnyObject> = ObjectSchema<{ | ||
[k in keyof T]-?: T[k] extends Array<infer E> ? ArraySchema<SchemaOf<E>> : T[k] extends AnyObject ? ObjectSchemaOf<T[k]> : BaseSchema<T[k], T[k], Config>; | ||
[k in keyof T]-?: T[k] extends Array<infer E> ? ArraySchema<SchemaOf<E>> : T[k] extends AnyObject ? ObjectSchemaOf<T[k]> : BaseSchema<T[k], Config>; | ||
}>; | ||
declare type SchemaOf<T> = T extends Array<infer E> ? ArraySchema<SchemaOf<E>> : T extends AnyObject ? ObjectSchemaOf<T> : BaseSchema<T, T, Config>; | ||
declare type SchemaOf<T> = T extends Array<infer E> ? ArraySchema<SchemaOf<E>> : T extends AnyObject ? ObjectSchemaOf<T> : BaseSchema<T, Config>; | ||
export declare type AnyObjectSchema = ObjectSchema<any, any, any>; | ||
@@ -24,0 +24,0 @@ export type { SchemaOf, TypeOf, Asserts, Asserts as InferType, AnySchema }; |
import { Maybe, Message, Optionals } from './types'; | ||
import type { Config, Defined, Thunk, ToggleDefault } from './util/types'; | ||
import BaseSchema from './schema'; | ||
export declare class MixedSchema<TType = any, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export declare class MixedSchema<TType = any, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
default<D extends Maybe<TType>>(def: Thunk<D>): MixedSchema<TType, ToggleDefault<TConfig, D>>; | ||
concat<IT, IC extends Config<any, any>>(schema: MixedSchema<IT, IC>): MixedSchema<NonNullable<TType> | IT, TConfig & IC>; | ||
concat<IT, IC extends Config<any, any>>(schema: BaseSchema<IT, any, IC>): MixedSchema<NonNullable<TType> | Optionals<IT>, TConfig & IC>; | ||
concat<IT, IC extends Config<any, any>>(schema: BaseSchema<IT, IC>): MixedSchema<NonNullable<TType> | Optionals<IT>, TConfig & IC>; | ||
concat(schema: this): this; | ||
@@ -9,0 +9,0 @@ defined(msg?: Message): MixedSchema<Defined<TType>, TConfig>; |
@@ -13,3 +13,3 @@ import type { AnyObject, Maybe, Message } from './types'; | ||
} | ||
export default class NumberSchema<TType extends Maybe<number> = number | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default class NumberSchema<TType extends Maybe<number> = number | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
constructor(); | ||
@@ -39,3 +39,3 @@ protected _typeCheck(value: any): value is NonNullable<TType>; | ||
} | ||
export default interface NumberSchema<TType extends Maybe<number> = number | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default interface NumberSchema<TType extends Maybe<number> = number | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
strip(): NumberSchema<TType, SetFlag<TConfig, 's'>>; | ||
@@ -42,0 +42,0 @@ default<D extends Maybe<TType>>(def: Thunk<D>): NumberSchema<TType, ToggleDefault<TConfig, D>>; |
@@ -23,3 +23,5 @@ import { InternalOptions, Callback, Maybe, Optionals, Preserve, Message } from './types'; | ||
[K in keyof S]: FieldType<S[K], '__outputType'>; | ||
}>; | ||
}> & { | ||
[k: string]: any; | ||
}; | ||
export declare type PartialSchema<S extends ObjectShape> = { | ||
@@ -34,3 +36,3 @@ [K in keyof S]: S[K] extends BaseSchema ? ReturnType<S[K]['optional']> : S[K]; | ||
}; | ||
export default class ObjectSchema<TShape extends ObjectShape, TConfig extends Config<any, any> = Config<AnyObject, 'd'>, TIn extends Maybe<TypeOfShape<TShape>> = TypeOfShape<TShape> | undefined> extends BaseSchema<TIn, AssertsShape<TShape> | Optionals<TIn>, TConfig> { | ||
export default class ObjectSchema<TShape extends ObjectShape, TConfig extends Config<any, any> = Config<AnyObject, 'd'>, TIn extends Maybe<AssertsShape<TShape>> = AssertsShape<TShape> | undefined> extends BaseSchema<TIn, TConfig> { | ||
fields: TShape; | ||
@@ -46,3 +48,3 @@ spec: ObjectSchemaSpec; | ||
clone(spec?: ObjectSchemaSpec): this; | ||
concat<TOther extends ObjectSchema<any, any, any>>(schema: TOther): TOther extends ObjectSchema<infer S, infer C, infer IType> ? ObjectSchema<TShape & S, TConfig & C, TypeOfShape<TShape & S> | Optionals<IType>> : never; | ||
concat<TOther extends ObjectSchema<any, any, any>>(schema: TOther): TOther extends ObjectSchema<infer S, infer C, infer IType> ? ObjectSchema<TShape & S, TConfig & C, AssertsShape<TShape & S> | Optionals<IType>> : never; | ||
concat(schema: this): this; | ||
@@ -52,7 +54,7 @@ protected _getDefault(): any; | ||
private setFields; | ||
shape<TNextShape extends ObjectShape>(additions: TNextShape, excludes?: [string, string][]): ObjectSchema<Assign<TShape, TNextShape>, TConfig, Extract<TIn, null | undefined> | TypeOfShape<Assign<TShape, TNextShape>>>; | ||
partial(): ObjectSchema<PartialSchema<TShape>, TConfig, Extract<TIn, null | undefined> | TypeOfShape<PartialSchema<TShape>>>; | ||
deepPartial(): ObjectSchema<DeepPartialSchema<TShape>, TConfig, Optionals<TIn> | undefined | TypeOfShape<DeepPartialSchema<TShape>>>; | ||
pick<TKey extends keyof TShape>(keys: TKey[]): ObjectSchema<Pick<TShape, TKey>, TConfig, Extract<TIn, null | undefined> | TypeOfShape<Pick<TShape, TKey>>>; | ||
omit<TKey extends keyof TShape>(keys: TKey[]): ObjectSchema<Pick<TShape, Exclude<keyof TShape, TKey>>, TConfig, Extract<TIn, null | undefined> | TypeOfShape<Pick<TShape, Exclude<keyof TShape, TKey>>>>; | ||
shape<TNextShape extends ObjectShape>(additions: TNextShape, excludes?: [string, string][]): ObjectSchema<Assign<TShape, TNextShape>, TConfig, Extract<TIn, null | undefined> | AssertsShape<Assign<TShape, TNextShape>>>; | ||
partial(): ObjectSchema<PartialSchema<TShape>, TConfig, Extract<TIn, null | undefined> | AssertsShape<PartialSchema<TShape>>>; | ||
deepPartial(): ObjectSchema<DeepPartialSchema<TShape>, TConfig, Optionals<TIn> | undefined | AssertsShape<DeepPartialSchema<TShape>>>; | ||
pick<TKey extends keyof TShape>(keys: TKey[]): ObjectSchema<Pick<TShape, TKey>, TConfig, Extract<TIn, null | undefined> | AssertsShape<Pick<TShape, TKey>>>; | ||
omit<TKey extends keyof TShape>(keys: TKey[]): ObjectSchema<Pick<TShape, Exclude<keyof TShape, TKey>>, TConfig, Extract<TIn, null | undefined> | AssertsShape<Pick<TShape, Exclude<keyof TShape, TKey>>>>; | ||
from(from: string, to: keyof TShape, alias?: boolean): this; | ||
@@ -67,7 +69,7 @@ noUnknown(noAllow?: boolean, message?: Message<any>): this; | ||
} | ||
export declare function create<TShape extends ObjectShape = {}>(spec?: TShape): ObjectSchema<TShape, Config<Record<string, any>, "d">, TypeOfShape<TShape> | undefined>; | ||
export declare function create<TShape extends ObjectShape = {}>(spec?: TShape): ObjectSchema<TShape, Config<Record<string, any>, "d">, AssertsShape<TShape> | undefined>; | ||
export declare namespace create { | ||
var prototype: ObjectSchema<any, any, any>; | ||
} | ||
export default interface ObjectSchema<TShape extends ObjectShape, TConfig extends Config<any, any> = Config<AnyObject, 'd'>, TIn extends Maybe<TypeOfShape<TShape>> = TypeOfShape<TShape> | undefined> extends BaseSchema<TIn, AssertsShape<TShape> | Optionals<TIn>, TConfig> { | ||
export default interface ObjectSchema<TShape extends ObjectShape, TConfig extends Config<any, any> = Config<AnyObject, 'd'>, TIn extends Maybe<AssertsShape<TShape>> = AssertsShape<TShape> | undefined> extends BaseSchema<TIn, TConfig> { | ||
default<D extends Maybe<AnyObject>>(def: Thunk<D>): ObjectSchema<TShape, ToggleDefault<TConfig, D>, TIn>; | ||
@@ -74,0 +76,0 @@ defined(msg?: Message): ObjectSchema<TShape, TConfig, Defined<TIn>>; |
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
import snakeCase from 'lodash/snakeCase'; | ||
import camelCase from 'lodash/camelCase'; // @ts-ignore | ||
// @ts-ignore | ||
import { getter, normalizePath, join } from 'property-expr'; | ||
import { camelCase, snakeCase } from 'tiny-case'; | ||
import { object as locale } from './locale'; | ||
@@ -8,0 +7,0 @@ import sortFields from './util/sortFields'; |
@@ -8,3 +8,3 @@ import { ConditionOptions, ResolveOptions } from './Condition'; | ||
export { Config }; | ||
export declare type ConfigOf<T> = T extends AnySchema<any, any, infer C> ? C : never; | ||
export declare type ConfigOf<T> = T extends AnySchema<any, infer C> ? C : never; | ||
export declare type ContextOf<T> = ConfigOf<T>['context']; | ||
@@ -29,3 +29,3 @@ export declare type FlagsOf<T> = T extends AnySchema ? T['__flags'] : never; | ||
}; | ||
export declare type AnySchema<TType = any, TOut = any, C extends Config = any> = BaseSchema<TType, TOut, C>; | ||
export declare type AnySchema<TType = any, C extends Config = any> = BaseSchema<TType, C>; | ||
export interface CastOptions<C = {}> { | ||
@@ -68,6 +68,6 @@ parent?: any; | ||
} | ||
export default abstract class BaseSchema<TType = any, TOut = TType, TConfig extends Config<any, any> = Config> { | ||
export default abstract class BaseSchema<TType = any, TConfig extends Config<any, any> = Config> { | ||
readonly type: string; | ||
readonly __type: TType; | ||
readonly __outputType: ResolveFlags<TOut, TConfig['flags']>; | ||
readonly __outputType: ResolveFlags<TType, TConfig['flags']>; | ||
readonly __flags: TConfig['flags']; | ||
@@ -151,3 +151,3 @@ readonly __isYupSchema__: boolean; | ||
}>): this; | ||
strip(strip?: boolean): BaseSchema<TType, TOut, SetFlag<TConfig, 's'>>; | ||
strip(strip?: boolean): BaseSchema<TType, SetFlag<TConfig, 's'>>; | ||
/** | ||
@@ -160,3 +160,3 @@ * Return a serialized description of the schema including validations, flags, types etc. | ||
} | ||
export default interface BaseSchema<TType = any, TOut = TType, TConfig extends Config<any, any> = Config> { | ||
export default interface BaseSchema<TType = any, TConfig extends Config<any, any> = Config> { | ||
validateAt(path: string, value: any, options?: ValidateOptions<TConfig['context']>): Promise<any>; | ||
@@ -163,0 +163,0 @@ validateSyncAt(path: string, value: any, options?: ValidateOptions<TConfig['context']>): any; |
@@ -22,3 +22,3 @@ import { MixedLocale } from './locale'; | ||
export { create }; | ||
export default class StringSchema<TType extends Maybe<string> = string | undefined, TConfig extends AnyConfig = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default class StringSchema<TType extends Maybe<string> = string | undefined, TConfig extends AnyConfig = Config> extends BaseSchema<TType, TConfig> { | ||
constructor(); | ||
@@ -51,3 +51,3 @@ protected _typeCheck(value: any): value is NonNullable<TType>; | ||
} | ||
export default interface StringSchema<TType extends Maybe<string> = string | undefined, TConfig extends AnyConfig = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default interface StringSchema<TType extends Maybe<string> = string | undefined, TConfig extends AnyConfig = Config> extends BaseSchema<TType, TConfig> { | ||
default<D extends Maybe<TType>>(def: Thunk<D>): StringSchema<TType, ToggleDefault<TConfig, D>>; | ||
@@ -54,0 +54,0 @@ oneOf<U extends TType>(arrayOfValues: ReadonlyArray<U | Reference>, message?: MixedLocale['oneOf']): StringSchema<U | Optionals<TType>, TConfig>; |
@@ -45,3 +45,3 @@ import ValidationError from '../ValidationError'; | ||
}): { | ||
<TSchema extends AnySchema<any, any, any> = AnySchema<any, any, any>>({ value, path, label, options, originalValue, sync, ...rest }: TestOptions<TSchema>, cb: Callback): void; | ||
<TSchema extends AnySchema<any, any> = AnySchema<any, any>>({ value, path, label, options, originalValue, sync, ...rest }: TestOptions<TSchema>, cb: Callback): void; | ||
OPTIONS: { | ||
@@ -48,0 +48,0 @@ name?: string | undefined; |
@@ -1,4 +0,4 @@ | ||
import type { AnyObject, InternalOptions, Callback, Message, Maybe, Optionals } from './types'; | ||
import type { AnyObject, InternalOptions, Callback, Message, Maybe } from './types'; | ||
import type Reference from './Reference'; | ||
import { Asserts, Config, Defined, NotNull, SetFlag, Thunk, ToggleDefault, TypeOf } from './util/types'; | ||
import { Asserts, Config, Defined, NotNull, SetFlag, Thunk, ToggleDefault } from './util/types'; | ||
import BaseSchema, { AnySchema, SchemaInnerTypeDescription, SchemaSpec } from './schema'; | ||
@@ -8,7 +8,7 @@ import Lazy from './Lazy'; | ||
export declare type RejectorFn = (value: any, index: number, array: any[]) => boolean; | ||
export declare function create<C extends AnyObject = AnyObject, T extends AnySchema | Lazy<any, any> = AnySchema>(type?: T): ArraySchema<T, Config<C, "">, TypeOf<T>[] | undefined>; | ||
export declare function create<C extends AnyObject = AnyObject, T extends AnySchema | Lazy<any, any> = AnySchema>(type?: T): ArraySchema<T, Config<C, "">, Asserts<T>[] | undefined>; | ||
export declare namespace create { | ||
var prototype: ArraySchema<any, any, any>; | ||
} | ||
export default class ArraySchema<T extends AnySchema | Lazy<any, any>, C extends Config<any, any> = Config, TIn extends Maybe<TypeOf<T>[]> = TypeOf<T>[] | undefined> extends BaseSchema<TIn, Asserts<T>[] | Optionals<TIn>, C> { | ||
export default class ArraySchema<T extends AnySchema | Lazy<any, any>, C extends Config<any, any> = Config, TIn extends Maybe<Asserts<T>[]> = Asserts<T>[] | undefined> extends BaseSchema<TIn, C> { | ||
innerType?: T; | ||
@@ -37,3 +37,3 @@ constructor(type?: T); | ||
} | ||
export default interface ArraySchema<T extends AnySchema | Lazy<any, any>, C extends Config<any, any> = Config, TIn extends Maybe<TypeOf<T>[]> = TypeOf<T>[] | undefined> extends BaseSchema<TIn, Asserts<T>[] | Optionals<TIn>, C> { | ||
export default interface ArraySchema<T extends AnySchema | Lazy<any, any>, C extends Config<any, any> = Config, TIn extends Maybe<Asserts<T>[]> = Asserts<T>[] | undefined> extends BaseSchema<TIn, C> { | ||
default<D extends Maybe<TIn>>(def: Thunk<D>): ArraySchema<T, ToggleDefault<C, D>, TIn>; | ||
@@ -40,0 +40,0 @@ defined(msg?: Message): ArraySchema<T, C, Defined<TIn>>; |
@@ -12,3 +12,3 @@ import BaseSchema from './schema'; | ||
} | ||
export default class BooleanSchema<TType extends Maybe<boolean> = boolean | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default class BooleanSchema<TType extends Maybe<boolean> = boolean | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
constructor(); | ||
@@ -19,3 +19,3 @@ protected _typeCheck(v: any): v is NonNullable<TType>; | ||
} | ||
export default interface BooleanSchema<TType extends Maybe<boolean>, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default interface BooleanSchema<TType extends Maybe<boolean>, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
default<D extends Maybe<TType>>(def: Thunk<D>): BooleanSchema<TType, ToggleDefault<TConfig, D>>; | ||
@@ -22,0 +22,0 @@ concat<TOther extends BooleanSchema<any, any>>(schema: TOther): TOther; |
@@ -15,3 +15,3 @@ import Ref from './Reference'; | ||
} | ||
export default class DateSchema<TType extends Maybe<Date> = Date | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default class DateSchema<TType extends Maybe<Date> = Date | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
static INVALID_DATE: Date; | ||
@@ -28,3 +28,3 @@ constructor(); | ||
} | ||
export default interface DateSchema<TType extends Maybe<Date>, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default interface DateSchema<TType extends Maybe<Date>, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
default<D extends Maybe<TType>>(def: Thunk<D>): DateSchema<TType, ToggleDefault<TConfig, D>>; | ||
@@ -31,0 +31,0 @@ concat<TOther extends DateSchema<any, any>>(schema: TOther): TOther; |
@@ -19,5 +19,5 @@ import MixedSchema, { create as mixedCreate } from './mixed'; | ||
declare type ObjectSchemaOf<T extends AnyObject> = ObjectSchema<{ | ||
[k in keyof T]-?: T[k] extends Array<infer E> ? ArraySchema<SchemaOf<E>> : T[k] extends AnyObject ? ObjectSchemaOf<T[k]> : BaseSchema<T[k], T[k], Config>; | ||
[k in keyof T]-?: T[k] extends Array<infer E> ? ArraySchema<SchemaOf<E>> : T[k] extends AnyObject ? ObjectSchemaOf<T[k]> : BaseSchema<T[k], Config>; | ||
}>; | ||
declare type SchemaOf<T> = T extends Array<infer E> ? ArraySchema<SchemaOf<E>> : T extends AnyObject ? ObjectSchemaOf<T> : BaseSchema<T, T, Config>; | ||
declare type SchemaOf<T> = T extends Array<infer E> ? ArraySchema<SchemaOf<E>> : T extends AnyObject ? ObjectSchemaOf<T> : BaseSchema<T, Config>; | ||
export declare type AnyObjectSchema = ObjectSchema<any, any, any>; | ||
@@ -24,0 +24,0 @@ export type { SchemaOf, TypeOf, Asserts, Asserts as InferType, AnySchema }; |
import { Maybe, Message, Optionals } from './types'; | ||
import type { Config, Defined, Thunk, ToggleDefault } from './util/types'; | ||
import BaseSchema from './schema'; | ||
export declare class MixedSchema<TType = any, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export declare class MixedSchema<TType = any, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
default<D extends Maybe<TType>>(def: Thunk<D>): MixedSchema<TType, ToggleDefault<TConfig, D>>; | ||
concat<IT, IC extends Config<any, any>>(schema: MixedSchema<IT, IC>): MixedSchema<NonNullable<TType> | IT, TConfig & IC>; | ||
concat<IT, IC extends Config<any, any>>(schema: BaseSchema<IT, any, IC>): MixedSchema<NonNullable<TType> | Optionals<IT>, TConfig & IC>; | ||
concat<IT, IC extends Config<any, any>>(schema: BaseSchema<IT, IC>): MixedSchema<NonNullable<TType> | Optionals<IT>, TConfig & IC>; | ||
concat(schema: this): this; | ||
@@ -9,0 +9,0 @@ defined(msg?: Message): MixedSchema<Defined<TType>, TConfig>; |
@@ -13,3 +13,3 @@ import type { AnyObject, Maybe, Message } from './types'; | ||
} | ||
export default class NumberSchema<TType extends Maybe<number> = number | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default class NumberSchema<TType extends Maybe<number> = number | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
constructor(); | ||
@@ -39,3 +39,3 @@ protected _typeCheck(value: any): value is NonNullable<TType>; | ||
} | ||
export default interface NumberSchema<TType extends Maybe<number> = number | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default interface NumberSchema<TType extends Maybe<number> = number | undefined, TConfig extends Config<any, any> = Config> extends BaseSchema<TType, TConfig> { | ||
strip(): NumberSchema<TType, SetFlag<TConfig, 's'>>; | ||
@@ -42,0 +42,0 @@ default<D extends Maybe<TType>>(def: Thunk<D>): NumberSchema<TType, ToggleDefault<TConfig, D>>; |
@@ -23,3 +23,5 @@ import { InternalOptions, Callback, Maybe, Optionals, Preserve, Message } from './types'; | ||
[K in keyof S]: FieldType<S[K], '__outputType'>; | ||
}>; | ||
}> & { | ||
[k: string]: any; | ||
}; | ||
export declare type PartialSchema<S extends ObjectShape> = { | ||
@@ -34,3 +36,3 @@ [K in keyof S]: S[K] extends BaseSchema ? ReturnType<S[K]['optional']> : S[K]; | ||
}; | ||
export default class ObjectSchema<TShape extends ObjectShape, TConfig extends Config<any, any> = Config<AnyObject, 'd'>, TIn extends Maybe<TypeOfShape<TShape>> = TypeOfShape<TShape> | undefined> extends BaseSchema<TIn, AssertsShape<TShape> | Optionals<TIn>, TConfig> { | ||
export default class ObjectSchema<TShape extends ObjectShape, TConfig extends Config<any, any> = Config<AnyObject, 'd'>, TIn extends Maybe<AssertsShape<TShape>> = AssertsShape<TShape> | undefined> extends BaseSchema<TIn, TConfig> { | ||
fields: TShape; | ||
@@ -46,3 +48,3 @@ spec: ObjectSchemaSpec; | ||
clone(spec?: ObjectSchemaSpec): this; | ||
concat<TOther extends ObjectSchema<any, any, any>>(schema: TOther): TOther extends ObjectSchema<infer S, infer C, infer IType> ? ObjectSchema<TShape & S, TConfig & C, TypeOfShape<TShape & S> | Optionals<IType>> : never; | ||
concat<TOther extends ObjectSchema<any, any, any>>(schema: TOther): TOther extends ObjectSchema<infer S, infer C, infer IType> ? ObjectSchema<TShape & S, TConfig & C, AssertsShape<TShape & S> | Optionals<IType>> : never; | ||
concat(schema: this): this; | ||
@@ -52,7 +54,7 @@ protected _getDefault(): any; | ||
private setFields; | ||
shape<TNextShape extends ObjectShape>(additions: TNextShape, excludes?: [string, string][]): ObjectSchema<Assign<TShape, TNextShape>, TConfig, Extract<TIn, null | undefined> | TypeOfShape<Assign<TShape, TNextShape>>>; | ||
partial(): ObjectSchema<PartialSchema<TShape>, TConfig, Extract<TIn, null | undefined> | TypeOfShape<PartialSchema<TShape>>>; | ||
deepPartial(): ObjectSchema<DeepPartialSchema<TShape>, TConfig, Optionals<TIn> | undefined | TypeOfShape<DeepPartialSchema<TShape>>>; | ||
pick<TKey extends keyof TShape>(keys: TKey[]): ObjectSchema<Pick<TShape, TKey>, TConfig, Extract<TIn, null | undefined> | TypeOfShape<Pick<TShape, TKey>>>; | ||
omit<TKey extends keyof TShape>(keys: TKey[]): ObjectSchema<Pick<TShape, Exclude<keyof TShape, TKey>>, TConfig, Extract<TIn, null | undefined> | TypeOfShape<Pick<TShape, Exclude<keyof TShape, TKey>>>>; | ||
shape<TNextShape extends ObjectShape>(additions: TNextShape, excludes?: [string, string][]): ObjectSchema<Assign<TShape, TNextShape>, TConfig, Extract<TIn, null | undefined> | AssertsShape<Assign<TShape, TNextShape>>>; | ||
partial(): ObjectSchema<PartialSchema<TShape>, TConfig, Extract<TIn, null | undefined> | AssertsShape<PartialSchema<TShape>>>; | ||
deepPartial(): ObjectSchema<DeepPartialSchema<TShape>, TConfig, Optionals<TIn> | undefined | AssertsShape<DeepPartialSchema<TShape>>>; | ||
pick<TKey extends keyof TShape>(keys: TKey[]): ObjectSchema<Pick<TShape, TKey>, TConfig, Extract<TIn, null | undefined> | AssertsShape<Pick<TShape, TKey>>>; | ||
omit<TKey extends keyof TShape>(keys: TKey[]): ObjectSchema<Pick<TShape, Exclude<keyof TShape, TKey>>, TConfig, Extract<TIn, null | undefined> | AssertsShape<Pick<TShape, Exclude<keyof TShape, TKey>>>>; | ||
from(from: string, to: keyof TShape, alias?: boolean): this; | ||
@@ -67,7 +69,7 @@ noUnknown(noAllow?: boolean, message?: Message<any>): this; | ||
} | ||
export declare function create<TShape extends ObjectShape = {}>(spec?: TShape): ObjectSchema<TShape, Config<Record<string, any>, "d">, TypeOfShape<TShape> | undefined>; | ||
export declare function create<TShape extends ObjectShape = {}>(spec?: TShape): ObjectSchema<TShape, Config<Record<string, any>, "d">, AssertsShape<TShape> | undefined>; | ||
export declare namespace create { | ||
var prototype: ObjectSchema<any, any, any>; | ||
} | ||
export default interface ObjectSchema<TShape extends ObjectShape, TConfig extends Config<any, any> = Config<AnyObject, 'd'>, TIn extends Maybe<TypeOfShape<TShape>> = TypeOfShape<TShape> | undefined> extends BaseSchema<TIn, AssertsShape<TShape> | Optionals<TIn>, TConfig> { | ||
export default interface ObjectSchema<TShape extends ObjectShape, TConfig extends Config<any, any> = Config<AnyObject, 'd'>, TIn extends Maybe<AssertsShape<TShape>> = AssertsShape<TShape> | undefined> extends BaseSchema<TIn, TConfig> { | ||
default<D extends Maybe<AnyObject>>(def: Thunk<D>): ObjectSchema<TShape, ToggleDefault<TConfig, D>, TIn>; | ||
@@ -74,0 +76,0 @@ defined(msg?: Message): ObjectSchema<TShape, TConfig, Defined<TIn>>; |
@@ -9,8 +9,6 @@ "use strict"; | ||
var _snakeCase = _interopRequireDefault(require("lodash/snakeCase")); | ||
var _propertyExpr = require("property-expr"); | ||
var _camelCase = _interopRequireDefault(require("lodash/camelCase")); | ||
var _tinyCase = require("tiny-case"); | ||
var _propertyExpr = require("property-expr"); | ||
var _locale = require("./locale"); | ||
@@ -387,11 +385,11 @@ | ||
camelCase() { | ||
return this.transformKeys(_camelCase.default); | ||
return this.transformKeys(_tinyCase.camelCase); | ||
} | ||
snakeCase() { | ||
return this.transformKeys(_snakeCase.default); | ||
return this.transformKeys(_tinyCase.snakeCase); | ||
} | ||
constantCase() { | ||
return this.transformKeys(key => (0, _snakeCase.default)(key).toUpperCase()); | ||
return this.transformKeys(key => (0, _tinyCase.snakeCase)(key).toUpperCase()); | ||
} | ||
@@ -398,0 +396,0 @@ |
@@ -8,3 +8,3 @@ import { ConditionOptions, ResolveOptions } from './Condition'; | ||
export { Config }; | ||
export declare type ConfigOf<T> = T extends AnySchema<any, any, infer C> ? C : never; | ||
export declare type ConfigOf<T> = T extends AnySchema<any, infer C> ? C : never; | ||
export declare type ContextOf<T> = ConfigOf<T>['context']; | ||
@@ -29,3 +29,3 @@ export declare type FlagsOf<T> = T extends AnySchema ? T['__flags'] : never; | ||
}; | ||
export declare type AnySchema<TType = any, TOut = any, C extends Config = any> = BaseSchema<TType, TOut, C>; | ||
export declare type AnySchema<TType = any, C extends Config = any> = BaseSchema<TType, C>; | ||
export interface CastOptions<C = {}> { | ||
@@ -68,6 +68,6 @@ parent?: any; | ||
} | ||
export default abstract class BaseSchema<TType = any, TOut = TType, TConfig extends Config<any, any> = Config> { | ||
export default abstract class BaseSchema<TType = any, TConfig extends Config<any, any> = Config> { | ||
readonly type: string; | ||
readonly __type: TType; | ||
readonly __outputType: ResolveFlags<TOut, TConfig['flags']>; | ||
readonly __outputType: ResolveFlags<TType, TConfig['flags']>; | ||
readonly __flags: TConfig['flags']; | ||
@@ -151,3 +151,3 @@ readonly __isYupSchema__: boolean; | ||
}>): this; | ||
strip(strip?: boolean): BaseSchema<TType, TOut, SetFlag<TConfig, 's'>>; | ||
strip(strip?: boolean): BaseSchema<TType, SetFlag<TConfig, 's'>>; | ||
/** | ||
@@ -160,3 +160,3 @@ * Return a serialized description of the schema including validations, flags, types etc. | ||
} | ||
export default interface BaseSchema<TType = any, TOut = TType, TConfig extends Config<any, any> = Config> { | ||
export default interface BaseSchema<TType = any, TConfig extends Config<any, any> = Config> { | ||
validateAt(path: string, value: any, options?: ValidateOptions<TConfig['context']>): Promise<any>; | ||
@@ -163,0 +163,0 @@ validateSyncAt(path: string, value: any, options?: ValidateOptions<TConfig['context']>): any; |
@@ -22,3 +22,3 @@ import { MixedLocale } from './locale'; | ||
export { create }; | ||
export default class StringSchema<TType extends Maybe<string> = string | undefined, TConfig extends AnyConfig = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default class StringSchema<TType extends Maybe<string> = string | undefined, TConfig extends AnyConfig = Config> extends BaseSchema<TType, TConfig> { | ||
constructor(); | ||
@@ -51,3 +51,3 @@ protected _typeCheck(value: any): value is NonNullable<TType>; | ||
} | ||
export default interface StringSchema<TType extends Maybe<string> = string | undefined, TConfig extends AnyConfig = Config> extends BaseSchema<TType, TType, TConfig> { | ||
export default interface StringSchema<TType extends Maybe<string> = string | undefined, TConfig extends AnyConfig = Config> extends BaseSchema<TType, TConfig> { | ||
default<D extends Maybe<TType>>(def: Thunk<D>): StringSchema<TType, ToggleDefault<TConfig, D>>; | ||
@@ -54,0 +54,0 @@ oneOf<U extends TType>(arrayOfValues: ReadonlyArray<U | Reference>, message?: MixedLocale['oneOf']): StringSchema<U | Optionals<TType>, TConfig>; |
@@ -45,3 +45,3 @@ import ValidationError from '../ValidationError'; | ||
}): { | ||
<TSchema extends AnySchema<any, any, any> = AnySchema<any, any, any>>({ value, path, label, options, originalValue, sync, ...rest }: TestOptions<TSchema>, cb: Callback): void; | ||
<TSchema extends AnySchema<any, any> = AnySchema<any, any>>({ value, path, label, options, originalValue, sync, ...rest }: TestOptions<TSchema>, cb: Callback): void; | ||
OPTIONS: { | ||
@@ -48,0 +48,0 @@ name?: string | undefined; |
{ | ||
"name": "yup", | ||
"version": "1.0.0-alpha.1", | ||
"version": "1.0.0-alpha.2", | ||
"description": "Dead simple Object schema validation", | ||
@@ -76,2 +76,3 @@ "main": "lib/index.js", | ||
"@babel/preset-typescript": "^7.12.7", | ||
"@typescript-eslint/eslint-plugin": "^4.9.1", | ||
"@typescript-eslint/parser": "^4.9.1", | ||
@@ -112,8 +113,5 @@ "babel-core": "^7.0.0-bridge.0", | ||
"@babel/runtime": "^7.12.5", | ||
"@types/lodash": "^4.14.165", | ||
"@typescript-eslint/eslint-plugin": "^4.9.1", | ||
"lodash": "^4.17.20", | ||
"lodash-es": "^4.17.11", | ||
"nanoclone": "^0.2.1", | ||
"property-expr": "^2.0.4", | ||
"tiny-case": "^1.0.2", | ||
"toposort": "^2.0.2" | ||
@@ -120,0 +118,0 @@ }, |
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
5
6123
305921
40
+ Addedtiny-case@^1.0.2
+ Addedtiny-case@1.0.3(transitive)
- Removed@types/lodash@^4.14.165
- Removedlodash@^4.17.20
- Removedlodash-es@^4.17.11
- Removed@babel/code-frame@7.12.11(transitive)
- Removed@babel/helper-validator-identifier@7.25.9(transitive)
- Removed@babel/highlight@7.25.9(transitive)
- Removed@eslint/eslintrc@0.4.3(transitive)
- Removed@humanwhocodes/config-array@0.5.0(transitive)
- Removed@humanwhocodes/object-schema@1.2.1(transitive)
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removed@types/json-schema@7.0.15(transitive)
- Removed@types/lodash@4.17.13(transitive)
- Removed@typescript-eslint/eslint-plugin@4.33.0(transitive)
- Removed@typescript-eslint/experimental-utils@4.33.0(transitive)
- Removed@typescript-eslint/parser@4.33.0(transitive)
- Removed@typescript-eslint/scope-manager@4.33.0(transitive)
- Removed@typescript-eslint/types@4.33.0(transitive)
- Removed@typescript-eslint/typescript-estree@4.33.0(transitive)
- Removed@typescript-eslint/visitor-keys@4.33.0(transitive)
- Removedacorn@7.4.1(transitive)
- Removedacorn-jsx@5.3.2(transitive)
- Removedajv@6.12.68.17.1(transitive)
- Removedansi-colors@4.1.3(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@3.2.14.3.0(transitive)
- Removedargparse@1.0.10(transitive)
- Removedarray-union@2.1.0(transitive)
- Removedastral-regex@2.0.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbraces@3.0.3(transitive)
- Removedcallsites@3.1.0(transitive)
- Removedchalk@2.4.24.1.2(transitive)
- Removedcolor-convert@1.9.32.0.1(transitive)
- Removedcolor-name@1.1.31.1.4(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedcross-spawn@7.0.5(transitive)
- Removeddebug@4.3.7(transitive)
- Removeddeep-is@0.1.4(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removeddoctrine@3.0.0(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedenquirer@2.4.1(transitive)
- Removedescape-string-regexp@1.0.54.0.0(transitive)
- Removedeslint@7.32.0(transitive)
- Removedeslint-scope@5.1.1(transitive)
- Removedeslint-utils@2.1.03.0.0(transitive)
- Removedeslint-visitor-keys@1.3.02.1.0(transitive)
- Removedespree@7.3.1(transitive)
- Removedesprima@4.0.1(transitive)
- Removedesquery@1.6.0(transitive)
- Removedesrecurse@4.3.0(transitive)
- Removedestraverse@4.3.05.3.0(transitive)
- Removedesutils@2.0.3(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-glob@3.3.2(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfast-levenshtein@2.0.6(transitive)
- Removedfast-uri@3.0.3(transitive)
- Removedfastq@1.17.1(transitive)
- Removedfile-entry-cache@6.0.1(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedflat-cache@3.2.0(transitive)
- Removedflatted@3.3.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfunctional-red-black-tree@1.0.1(transitive)
- Removedglob@7.2.3(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedglobals@13.24.0(transitive)
- Removedglobby@11.1.0(transitive)
- Removedhas-flag@3.0.04.0.0(transitive)
- Removedignore@4.0.65.3.2(transitive)
- Removedimport-fresh@3.3.0(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedjson-buffer@3.0.1(transitive)
- Removedjson-schema-traverse@0.4.11.0.0(transitive)
- Removedjson-stable-stringify-without-jsonify@1.0.1(transitive)
- Removedkeyv@4.5.4(transitive)
- Removedlevn@0.4.1(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlodash-es@4.17.21(transitive)
- Removedlodash.merge@4.6.2(transitive)
- Removedlodash.truncate@4.4.2(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedms@2.1.3(transitive)
- Removednatural-compare@1.4.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedoptionator@0.9.4(transitive)
- Removedparent-module@1.0.1(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-key@3.1.1(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedprelude-ls@1.2.1(transitive)
- Removedprogress@2.0.3(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedregexpp@3.2.0(transitive)
- Removedrequire-from-string@2.0.2(transitive)
- Removedresolve-from@4.0.0(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrimraf@3.0.2(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedsemver@7.6.3(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedslash@3.0.0(transitive)
- Removedslice-ansi@4.0.0(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedstrip-json-comments@3.1.1(transitive)
- Removedsupports-color@5.5.07.2.0(transitive)
- Removedtable@6.8.2(transitive)
- Removedtext-table@0.2.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedtslib@1.14.1(transitive)
- Removedtsutils@3.21.0(transitive)
- Removedtype-check@0.4.0(transitive)
- Removedtype-fest@0.20.2(transitive)
- Removedtypescript@5.6.3(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedv8-compile-cache@2.4.0(transitive)
- Removedwhich@2.0.2(transitive)
- Removedword-wrap@1.2.5(transitive)
- Removedwrappy@1.0.2(transitive)