From e4450c8417624b71d779cb4f41692538f9165e10 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sat, 2 Sep 2023 19:12:47 -0400 Subject: first commit --- node_modules/@sapphire/shapeshift/dist/index.d.ts | 715 ++++++++++++++++++++++ 1 file changed, 715 insertions(+) create mode 100644 node_modules/@sapphire/shapeshift/dist/index.d.ts (limited to 'node_modules/@sapphire/shapeshift/dist/index.d.ts') diff --git a/node_modules/@sapphire/shapeshift/dist/index.d.ts b/node_modules/@sapphire/shapeshift/dist/index.d.ts new file mode 100644 index 0000000..748451d --- /dev/null +++ b/node_modules/@sapphire/shapeshift/dist/index.d.ts @@ -0,0 +1,715 @@ +import { InspectOptionsStylized } from 'util'; + +declare class Result { + readonly success: boolean; + readonly value?: T; + readonly error?: E; + private constructor(); + isOk(): this is { + success: true; + value: T; + }; + isErr(): this is { + success: false; + error: E; + }; + unwrap(): T; + static ok(value: T): Result; + static err(error: E): Result; +} + +type ArrayConstraintName = `s.array(T).${'unique' | `length${'LessThan' | 'LessThanOrEqual' | 'GreaterThan' | 'GreaterThanOrEqual' | 'Equal' | 'NotEqual' | 'Range' | 'RangeInclusive' | 'RangeExclusive'}`}`; +declare function arrayLengthLessThan(value: number): IConstraint; +declare function arrayLengthLessThanOrEqual(value: number): IConstraint; +declare function arrayLengthGreaterThan(value: number): IConstraint; +declare function arrayLengthGreaterThanOrEqual(value: number): IConstraint; +declare function arrayLengthEqual(value: number): IConstraint; +declare function arrayLengthNotEqual(value: number): IConstraint; +declare function arrayLengthRange(start: number, endBefore: number): IConstraint; +declare function arrayLengthRangeInclusive(start: number, end: number): IConstraint; +declare function arrayLengthRangeExclusive(startAfter: number, endBefore: number): IConstraint; + +type BigIntConstraintName = `s.bigint.${'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'notEqual' | 'divisibleBy'}`; +declare function bigintLessThan(value: bigint): IConstraint; +declare function bigintLessThanOrEqual(value: bigint): IConstraint; +declare function bigintGreaterThan(value: bigint): IConstraint; +declare function bigintGreaterThanOrEqual(value: bigint): IConstraint; +declare function bigintEqual(value: bigint): IConstraint; +declare function bigintNotEqual(value: bigint): IConstraint; +declare function bigintDivisibleBy(divider: bigint): IConstraint; + +type BooleanConstraintName = `s.boolean.${boolean}`; +declare const booleanTrue: IConstraint; +declare const booleanFalse: IConstraint; + +type DateConstraintName = `s.date.${'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'notEqual' | 'valid' | 'invalid'}`; +declare function dateLessThan(value: Date): IConstraint; +declare function dateLessThanOrEqual(value: Date): IConstraint; +declare function dateGreaterThan(value: Date): IConstraint; +declare function dateGreaterThanOrEqual(value: Date): IConstraint; +declare function dateEqual(value: Date): IConstraint; +declare function dateNotEqual(value: Date): IConstraint; +declare const dateInvalid: IConstraint; +declare const dateValid: IConstraint; + +type NumberConstraintName = `s.number.${'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'equal(NaN)' | 'notEqual' | 'notEqual(NaN)' | 'int' | 'safeInt' | 'finite' | 'divisibleBy'}`; +declare function numberLessThan(value: number): IConstraint; +declare function numberLessThanOrEqual(value: number): IConstraint; +declare function numberGreaterThan(value: number): IConstraint; +declare function numberGreaterThanOrEqual(value: number): IConstraint; +declare function numberEqual(value: number): IConstraint; +declare function numberNotEqual(value: number): IConstraint; +declare const numberInt: IConstraint; +declare const numberSafeInt: IConstraint; +declare const numberFinite: IConstraint; +declare const numberNaN: IConstraint; +declare const numberNotNaN: IConstraint; +declare function numberDivisibleBy(divider: number): IConstraint; + +declare const customInspectSymbol: unique symbol; +declare const customInspectSymbolStackLess: unique symbol; +declare abstract class BaseError extends Error { + protected [customInspectSymbol](depth: number, options: InspectOptionsStylized): string; + protected abstract [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string; +} + +declare class CombinedError extends BaseError { + readonly errors: readonly BaseError[]; + constructor(errors: readonly BaseError[]); + protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string; +} + +declare class ValidationError extends BaseError { + readonly validator: string; + readonly given: unknown; + constructor(validator: string, message: string, given: unknown); + toJSON(): { + name: string; + validator: string; + given: unknown; + }; + protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string; +} + +declare class ExpectedValidationError extends ValidationError { + readonly expected: T; + constructor(validator: string, message: string, given: unknown, expected: T); + toJSON(): { + name: string; + validator: string; + given: unknown; + expected: T; + }; + protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string; +} + +declare class MissingPropertyError extends BaseError { + readonly property: PropertyKey; + constructor(property: PropertyKey); + toJSON(): { + name: string; + property: PropertyKey; + }; + protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string; +} + +declare class MultiplePossibilitiesConstraintError extends BaseConstraintError { + readonly expected: readonly string[]; + constructor(constraint: ConstraintErrorNames, message: string, given: T, expected: readonly string[]); + toJSON(): { + name: string; + constraint: ConstraintErrorNames; + given: T; + expected: readonly string[]; + }; + protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string; +} + +declare class UnknownEnumValueError extends BaseError { + readonly value: string | number; + readonly enumKeys: string[]; + readonly enumMappings: Map; + constructor(value: string | number, keys: string[], enumMappings: Map); + toJSON(): { + name: string; + value: string | number; + enumKeys: string[]; + enumMappings: [string | number, string | number][]; + }; + protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string; +} + +declare class UnknownPropertyError extends BaseError { + readonly property: PropertyKey; + readonly value: unknown; + constructor(property: PropertyKey, value: unknown); + toJSON(): { + name: string; + property: PropertyKey; + value: unknown; + }; + protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string; +} + +declare class BigIntValidator extends BaseValidator { + lessThan(number: bigint): this; + lessThanOrEqual(number: bigint): this; + greaterThan(number: bigint): this; + greaterThanOrEqual(number: bigint): this; + equal(number: N): BigIntValidator; + notEqual(number: bigint): this; + get positive(): this; + get negative(): this; + divisibleBy(number: bigint): this; + get abs(): this; + intN(bits: number): this; + uintN(bits: number): this; + protected handle(value: unknown): Result; +} + +declare class BooleanValidator extends BaseValidator { + get true(): BooleanValidator; + get false(): BooleanValidator; + equal(value: R): BooleanValidator; + notEqual(value: R): BooleanValidator; + protected handle(value: unknown): Result; +} + +declare class DateValidator extends BaseValidator { + lessThan(date: Date | number | string): this; + lessThanOrEqual(date: Date | number | string): this; + greaterThan(date: Date | number | string): this; + greaterThanOrEqual(date: Date | number | string): this; + equal(date: Date | number | string): this; + notEqual(date: Date | number | string): this; + get valid(): this; + get invalid(): this; + protected handle(value: unknown): Result; +} + +declare class DefaultValidator extends BaseValidator { + private readonly validator; + private defaultValue; + constructor(validator: BaseValidator, value: T | (() => T), constraints?: readonly IConstraint[]); + default(value: Exclude | (() => Exclude)): DefaultValidator>; + protected handle(value: unknown): Result; + protected clone(): this; +} + +declare class InstanceValidator extends BaseValidator { + readonly expected: Constructor; + constructor(expected: Constructor, constraints?: readonly IConstraint[]); + protected handle(value: unknown): Result>>; + protected clone(): this; +} + +declare class LiteralValidator extends BaseValidator { + readonly expected: T; + constructor(literal: T, constraints?: readonly IConstraint[]); + protected handle(value: unknown): Result>; + protected clone(): this; +} + +declare class CombinedPropertyError extends BaseError { + readonly errors: [PropertyKey, BaseError][]; + constructor(errors: [PropertyKey, BaseError][]); + protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string; + private static formatProperty; +} + +declare class MapValidator extends BaseValidator> { + private readonly keyValidator; + private readonly valueValidator; + constructor(keyValidator: BaseValidator, valueValidator: BaseValidator, constraints?: readonly IConstraint>[]); + protected clone(): this; + protected handle(value: unknown): Result, ValidationError | CombinedPropertyError>; +} + +declare class NativeEnumValidator extends BaseValidator { + readonly enumShape: T; + readonly hasNumericElements: boolean; + private readonly enumKeys; + private readonly enumMapping; + constructor(enumShape: T); + protected handle(value: unknown): Result; + protected clone(): this; +} +interface NativeEnumLike { + [key: string]: string | number; + [key: number]: string; +} + +declare class NeverValidator extends BaseValidator { + protected handle(value: unknown): Result; +} + +declare class NullishValidator extends BaseValidator { + protected handle(value: unknown): Result; +} + +declare class NumberValidator extends BaseValidator { + lessThan(number: number): this; + lessThanOrEqual(number: number): this; + greaterThan(number: number): this; + greaterThanOrEqual(number: number): this; + equal(number: N): NumberValidator; + notEqual(number: number): this; + get int(): this; + get safeInt(): this; + get finite(): this; + get positive(): this; + get negative(): this; + divisibleBy(divider: number): this; + get abs(): this; + get sign(): this; + get trunc(): this; + get floor(): this; + get fround(): this; + get round(): this; + get ceil(): this; + protected handle(value: unknown): Result; +} + +declare class ObjectValidator> extends BaseValidator { + readonly shape: MappedObjectValidator; + readonly strategy: ObjectValidatorStrategy; + private readonly keys; + private readonly handleStrategy; + private readonly requiredKeys; + private readonly possiblyUndefinedKeys; + private readonly possiblyUndefinedKeysWithDefaults; + constructor(shape: MappedObjectValidator, strategy?: ObjectValidatorStrategy, constraints?: readonly IConstraint[]); + get strict(): this; + get ignore(): this; + get passthrough(): this; + get partial(): ObjectValidator<{ + [Key in keyof I]?: I[Key]; + }>; + get required(): ObjectValidator<{ + [Key in keyof I]-?: I[Key]; + }>; + extend(schema: ObjectValidator | MappedObjectValidator): ObjectValidator; + pick(keys: readonly K[]): ObjectValidator<{ + [Key in keyof Pick]: I[Key]; + }>; + omit(keys: readonly K[]): ObjectValidator<{ + [Key in keyof Omit]: I[Key]; + }>; + protected handle(value: unknown): Result; + protected clone(): this; + private handleIgnoreStrategy; + private handleStrictStrategy; + private handlePassthroughStrategy; +} +declare enum ObjectValidatorStrategy { + Ignore = 0, + Strict = 1, + Passthrough = 2 +} + +declare class PassthroughValidator extends BaseValidator { + protected handle(value: unknown): Result; +} + +declare class RecordValidator extends BaseValidator> { + private readonly validator; + constructor(validator: BaseValidator, constraints?: readonly IConstraint>[]); + protected clone(): this; + protected handle(value: unknown): Result, ValidationError | CombinedPropertyError>; +} + +declare class SetValidator extends BaseValidator> { + private readonly validator; + constructor(validator: BaseValidator, constraints?: readonly IConstraint>[]); + protected clone(): this; + protected handle(values: unknown): Result, ValidationError | CombinedError>; +} + +type StringConstraintName = `s.string.${`length${'LessThan' | 'LessThanOrEqual' | 'GreaterThan' | 'GreaterThanOrEqual' | 'Equal' | 'NotEqual'}` | 'regex' | 'url' | 'uuid' | 'email' | `ip${'v4' | 'v6' | ''}` | 'date' | 'phone'}`; +type StringProtocol = `${string}:`; +type StringDomain = `${string}.${string}`; +interface UrlOptions { + allowedProtocols?: StringProtocol[]; + allowedDomains?: StringDomain[]; +} +type UUIDVersion = 1 | 3 | 4 | 5; +interface StringUuidOptions { + version?: UUIDVersion | `${UUIDVersion}-${UUIDVersion}` | null; + nullable?: boolean; +} +declare function stringLengthLessThan(length: number): IConstraint; +declare function stringLengthLessThanOrEqual(length: number): IConstraint; +declare function stringLengthGreaterThan(length: number): IConstraint; +declare function stringLengthGreaterThanOrEqual(length: number): IConstraint; +declare function stringLengthEqual(length: number): IConstraint; +declare function stringLengthNotEqual(length: number): IConstraint; +declare function stringEmail(): IConstraint; +declare function stringUrl(options?: UrlOptions): IConstraint; +declare function stringIp(version?: 4 | 6): IConstraint; +declare function stringRegex(regex: RegExp): IConstraint; +declare function stringUuid({ version, nullable }?: StringUuidOptions): IConstraint; + +declare class StringValidator extends BaseValidator { + lengthLessThan(length: number): this; + lengthLessThanOrEqual(length: number): this; + lengthGreaterThan(length: number): this; + lengthGreaterThanOrEqual(length: number): this; + lengthEqual(length: number): this; + lengthNotEqual(length: number): this; + get email(): this; + url(options?: UrlOptions): this; + uuid(options?: StringUuidOptions): this; + regex(regex: RegExp): this; + get date(): this; + get ipv4(): this; + get ipv6(): this; + ip(version?: 4 | 6): this; + phone(): this; + protected handle(value: unknown): Result; +} + +declare class TupleValidator extends BaseValidator<[...T]> { + private readonly validators; + constructor(validators: BaseValidator<[...T]>[], constraints?: readonly IConstraint<[...T]>[]); + protected clone(): this; + protected handle(values: unknown): Result<[...T], ValidationError | CombinedPropertyError>; +} + +type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array; +declare const TypedArrays: { + readonly Int8Array: (x: unknown) => x is Int8Array; + readonly Uint8Array: (x: unknown) => x is Uint8Array; + readonly Uint8ClampedArray: (x: unknown) => x is Uint8ClampedArray; + readonly Int16Array: (x: unknown) => x is Int16Array; + readonly Uint16Array: (x: unknown) => x is Uint16Array; + readonly Int32Array: (x: unknown) => x is Int32Array; + readonly Uint32Array: (x: unknown) => x is Uint32Array; + readonly Float32Array: (x: unknown) => x is Float32Array; + readonly Float64Array: (x: unknown) => x is Float64Array; + readonly BigInt64Array: (x: unknown) => x is BigInt64Array; + readonly BigUint64Array: (x: unknown) => x is BigUint64Array; + readonly TypedArray: (x: unknown) => x is TypedArray; +}; +type TypedArrayName = keyof typeof TypedArrays; + +declare class TypedArrayValidator extends BaseValidator { + private readonly type; + constructor(type: TypedArrayName, constraints?: readonly IConstraint[]); + byteLengthLessThan(length: number): this; + byteLengthLessThanOrEqual(length: number): this; + byteLengthGreaterThan(length: number): this; + byteLengthGreaterThanOrEqual(length: number): this; + byteLengthEqual(length: number): this; + byteLengthNotEqual(length: number): this; + byteLengthRange(start: number, endBefore: number): this; + byteLengthRangeInclusive(startAt: number, endAt: number): this; + byteLengthRangeExclusive(startAfter: number, endBefore: number): this; + lengthLessThan(length: number): this; + lengthLessThanOrEqual(length: number): this; + lengthGreaterThan(length: number): this; + lengthGreaterThanOrEqual(length: number): this; + lengthEqual(length: number): this; + lengthNotEqual(length: number): this; + lengthRange(start: number, endBefore: number): this; + lengthRangeInclusive(startAt: number, endAt: number): this; + lengthRangeExclusive(startAfter: number, endBefore: number): this; + protected clone(): this; + protected handle(value: unknown): Result; +} + +declare class UnionValidator extends BaseValidator { + private validators; + constructor(validators: readonly BaseValidator[], constraints?: readonly IConstraint[]); + get optional(): UnionValidator; + get required(): UnionValidator>; + get nullable(): UnionValidator; + get nullish(): UnionValidator; + or(...predicates: readonly BaseValidator[]): UnionValidator; + protected clone(): this; + protected handle(value: unknown): Result; +} + +type ObjectConstraintName = `s.object(T.when)`; +type WhenKey = PropertyKey | PropertyKey[]; +interface WhenOptions, Key extends WhenKey> { + is?: boolean | ((value: Key extends Array ? any[] : any) => boolean); + then: (predicate: T) => T; + otherwise?: (predicate: T) => T; +} + +declare class ExpectedConstraintError extends BaseConstraintError { + readonly expected: string; + constructor(constraint: ConstraintErrorNames, message: string, given: T, expected: string); + toJSON(): { + name: string; + constraint: ConstraintErrorNames; + given: T; + expected: string; + }; + protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string; +} + +type TypedArrayConstraintName = `s.typedArray(T).${'byteLength' | 'length'}${'LessThan' | 'LessThanOrEqual' | 'GreaterThan' | 'GreaterThanOrEqual' | 'Equal' | 'NotEqual' | 'Range' | 'RangeInclusive' | 'RangeExclusive'}`; +declare function typedArrayByteLengthLessThan(value: number): IConstraint; +declare function typedArrayByteLengthLessThanOrEqual(value: number): IConstraint; +declare function typedArrayByteLengthGreaterThan(value: number): IConstraint; +declare function typedArrayByteLengthGreaterThanOrEqual(value: number): IConstraint; +declare function typedArrayByteLengthEqual(value: number): IConstraint; +declare function typedArrayByteLengthNotEqual(value: number): IConstraint; +declare function typedArrayByteLengthRange(start: number, endBefore: number): IConstraint; +declare function typedArrayByteLengthRangeInclusive(start: number, end: number): { + run(input: T): Result | Result>; +}; +declare function typedArrayByteLengthRangeExclusive(startAfter: number, endBefore: number): IConstraint; +declare function typedArrayLengthLessThan(value: number): IConstraint; +declare function typedArrayLengthLessThanOrEqual(value: number): IConstraint; +declare function typedArrayLengthGreaterThan(value: number): IConstraint; +declare function typedArrayLengthGreaterThanOrEqual(value: number): IConstraint; +declare function typedArrayLengthEqual(value: number): IConstraint; +declare function typedArrayLengthNotEqual(value: number): IConstraint; +declare function typedArrayLengthRange(start: number, endBefore: number): IConstraint; +declare function typedArrayLengthRangeInclusive(start: number, end: number): IConstraint; +declare function typedArrayLengthRangeExclusive(startAfter: number, endBefore: number): IConstraint; + +type ConstraintErrorNames = TypedArrayConstraintName | ArrayConstraintName | BigIntConstraintName | BooleanConstraintName | DateConstraintName | NumberConstraintName | ObjectConstraintName | StringConstraintName; +declare abstract class BaseConstraintError extends BaseError { + readonly constraint: ConstraintErrorNames; + readonly given: T; + constructor(constraint: ConstraintErrorNames, message: string, given: T); +} + +interface IConstraint { + run(input: Input, parent?: any): Result>; +} + +declare class ArrayValidator extends BaseValidator { + private readonly validator; + constructor(validator: BaseValidator, constraints?: readonly IConstraint[]); + lengthLessThan(length: N): ArrayValidator]>>>; + lengthLessThanOrEqual(length: N): ArrayValidator]>>; + lengthGreaterThan(length: N): ArrayValidator<[...Tuple, I, ...T]>; + lengthGreaterThanOrEqual(length: N): ArrayValidator<[...Tuple, ...T]>; + lengthEqual(length: N): ArrayValidator<[...Tuple]>; + lengthNotEqual(length: number): ArrayValidator<[...T]>; + lengthRange(start: S, endBefore: E): ArrayValidator]>>, ExpandSmallerTuples]>>>>; + lengthRangeInclusive(startAt: S, endAt: E): ArrayValidator]>, ExpandSmallerTuples]>>>>; + lengthRangeExclusive(startAfter: S, endBefore: E): ArrayValidator]>>, ExpandSmallerTuples<[...Tuple]>>>; + get unique(): this; + protected clone(): this; + protected handle(values: unknown): Result; +} + +declare abstract class BaseValidator { + description?: string; + protected parent?: object; + protected constraints: readonly IConstraint[]; + protected isValidationEnabled: boolean | (() => boolean) | null; + constructor(constraints?: readonly IConstraint[]); + setParent(parent: object): this; + get optional(): UnionValidator; + get nullable(): UnionValidator; + get nullish(): UnionValidator; + get array(): ArrayValidator; + get set(): SetValidator; + or(...predicates: readonly BaseValidator[]): UnionValidator; + transform(cb: (value: T) => T): this; + transform(cb: (value: T) => O): BaseValidator; + reshape(cb: (input: T) => Result): this; + reshape, O = InferResultType>(cb: (input: T) => R): BaseValidator; + default(value: Exclude | (() => Exclude)): DefaultValidator>; + when = this>(key: Key, options: WhenOptions): this; + describe(description: string): this; + run(value: unknown): Result; + parse(value: unknown): R; + is(value: unknown): value is R; + /** + * Sets if the validator should also run constraints or just do basic checks. + * @param isValidationEnabled Whether this validator should be enabled or disabled. You can pass boolean or a function returning boolean which will be called just before parsing. + * Set to `null` to go off of the global configuration. + */ + setValidationEnabled(isValidationEnabled: boolean | (() => boolean) | null): this; + getValidationEnabled(): boolean | null; + protected get shouldRunConstraints(): boolean; + protected clone(): this; + protected abstract handle(value: unknown): Result; + protected addConstraint(constraint: IConstraint): this; +} +type ValidatorError = ValidationError | CombinedError | CombinedPropertyError | UnknownEnumValueError; + +type Constructor = (new (...args: readonly any[]) => T) | (abstract new (...args: readonly any[]) => T); +type Type = V extends BaseValidator ? T : never; +/** + * @deprecated Use `object` instead. + */ +type NonNullObject = {} & object; +/** + * @deprecated This type is no longer used and will be removed in the next major version. + */ +type PickDefined = { + [K in keyof T as undefined extends T[K] ? never : K]: T[K]; +}; +/** + * @deprecated This type is no longer used and will be removed in the next major version. + */ +type PickUndefinedMakeOptional = { + [K in keyof T as undefined extends T[K] ? K : never]+?: Exclude; +}; +type FilterDefinedKeys = Exclude<{ + [TKey in keyof TObj]: undefined extends TObj[TKey] ? never : TKey; +}[keyof TObj], undefined>; +type UndefinedToOptional = Pick> & { + [k in keyof Omit>]?: Exclude; +}; +type MappedObjectValidator = { + [key in keyof T]: BaseValidator; +}; +/** + * An alias of {@link ObjectValidator} with a name more common among object validation libraries. + * This is the type of a schema after using `s.object({ ... })` + * @example + * ```typescript + * import { s, SchemaOf } from '@sapphire/shapeshift'; + * + * interface IIngredient { + * ingredientId: string | undefined; + * name: string | undefined; + * } + * + * interface IInstruction { + * instructionId: string | undefined; + * message: string | undefined; + * } + * + * interface IRecipe { + * recipeId: string | undefined; + * title: string; + * description: string; + * instructions: IInstruction[]; + * ingredients: IIngredient[]; + * } + * + * type InstructionSchemaType = SchemaOf; + * // Expected Type: ObjectValidator + * + * type IngredientSchemaType = SchemaOf; + * // Expected Type: ObjectValidator + * + * type RecipeSchemaType = SchemaOf; + * // Expected Type: ObjectValidator + * + * const instructionSchema: InstructionSchemaType = s.object({ + * instructionId: s.string.optional, + * message: s.string + * }); + * + * const ingredientSchema: IngredientSchemaType = s.object({ + * ingredientId: s.string.optional, + * name: s.string + * }); + * + * const recipeSchema: RecipeSchemaType = s.object({ + * recipeId: s.string.optional, + * title: s.string, + * description: s.string, + * instructions: s.array(instructionSchema), + * ingredients: s.array(ingredientSchema) + * }); + * ``` + */ +type SchemaOf = ObjectValidator; +/** + * Infers the type of a schema object given `typeof schema`. + * The schema has to extend {@link ObjectValidator}. + * @example + * ```typescript + * import { InferType, s } from '@sapphire/shapeshift'; + * + * const schema = s.object({ + * foo: s.string, + * bar: s.number, + * baz: s.boolean, + * qux: s.bigint, + * quux: s.date + * }); + * + * type Inferredtype = InferType; + * // Expected type: + * // type Inferredtype = { + * // foo: string; + * // bar: number; + * // baz: boolean; + * // qux: bigint; + * // quux: Date; + * // }; + * ``` + */ +type InferType> = T extends ObjectValidator ? U : never; +type InferResultType> = T extends Result ? U : never; +type UnwrapTuple = T extends [infer Head, ...infer Tail] ? [Unwrap, ...UnwrapTuple] : []; +type Unwrap = T extends BaseValidator ? V : never; +type UnshiftTuple = T extends [T[0], ...infer Tail] ? Tail : never; +type ExpandSmallerTuples = T extends [T[0], ...infer Tail] ? T | ExpandSmallerTuples : []; +type Shift> = ((...args: A) => void) extends (...args: [A[0], ...infer R]) => void ? R : never; +type GrowExpRev, N extends number, P extends Array>> = A['length'] extends N ? A : GrowExpRev<[...A, ...P[0]][N] extends undefined ? [...A, ...P[0]] : A, N, Shift

>; +type GrowExp, N extends number, P extends Array>> = [...A, ...A][N] extends undefined ? GrowExp<[...A, ...A], N, [A, ...P]> : GrowExpRev; +type Tuple = N extends number ? number extends N ? Array : N extends 0 ? [] : N extends 1 ? [T] : GrowExp<[T], N, [[]]> : never; + +declare class LazyValidator, R = Unwrap> extends BaseValidator { + private readonly validator; + constructor(validator: (value: unknown) => T, constraints?: readonly IConstraint[]); + protected clone(): this; + protected handle(values: unknown): Result; +} + +declare class Shapes { + get string(): StringValidator; + get number(): NumberValidator; + get bigint(): BigIntValidator; + get boolean(): BooleanValidator; + get date(): DateValidator; + object(shape: MappedObjectValidator): ObjectValidator>; + get undefined(): BaseValidator; + get null(): BaseValidator; + get nullish(): NullishValidator; + get any(): PassthroughValidator; + get unknown(): PassthroughValidator; + get never(): NeverValidator; + enum(...values: readonly T[]): UnionValidator; + nativeEnum(enumShape: T): NativeEnumValidator; + literal(value: T): BaseValidator; + instance(expected: Constructor): InstanceValidator; + union[]]>(...validators: [...T]): UnionValidator>; + array(validator: BaseValidator): ArrayValidator; + array(validator: BaseValidator): ArrayValidator; + typedArray(type?: TypedArrayName): TypedArrayValidator; + get int8Array(): TypedArrayValidator; + get uint8Array(): TypedArrayValidator; + get uint8ClampedArray(): TypedArrayValidator; + get int16Array(): TypedArrayValidator; + get uint16Array(): TypedArrayValidator; + get int32Array(): TypedArrayValidator; + get uint32Array(): TypedArrayValidator; + get float32Array(): TypedArrayValidator; + get float64Array(): TypedArrayValidator; + get bigInt64Array(): TypedArrayValidator; + get bigUint64Array(): TypedArrayValidator; + tuple[]]>(validators: [...T]): TupleValidator>; + set(validator: BaseValidator): SetValidator; + record(validator: BaseValidator): RecordValidator; + map(keyValidator: BaseValidator, valueValidator: BaseValidator): MapValidator; + lazy>(validator: (value: unknown) => T): LazyValidator>; +} + +/** + * Sets whether validators should run on the input, or if the input should be passed through. + * @param enabled Whether validation should be done on inputs + */ +declare function setGlobalValidationEnabled(enabled: boolean): void; +/** + * @returns Whether validation is enabled + */ +declare function getGlobalValidationEnabled(): boolean; + +declare const s: Shapes; + +export { ArrayConstraintName, ArrayValidator, BaseConstraintError, BaseError, BaseValidator, BigIntConstraintName, BigIntValidator, BooleanConstraintName, BooleanValidator, CombinedError, CombinedPropertyError, ConstraintErrorNames, Constructor, DateConstraintName, DateValidator, DefaultValidator, ExpandSmallerTuples, ExpectedConstraintError, ExpectedValidationError, GrowExp, GrowExpRev, IConstraint, InferResultType, InferType, InstanceValidator, LiteralValidator, MapValidator, MappedObjectValidator, MissingPropertyError, MultiplePossibilitiesConstraintError, NativeEnumLike, NativeEnumValidator, NeverValidator, NonNullObject, NullishValidator, NumberConstraintName, NumberValidator, ObjectValidator, ObjectValidatorStrategy, PassthroughValidator, PickDefined, PickUndefinedMakeOptional, RecordValidator, Result, SchemaOf, SetValidator, Shapes, Shift, StringConstraintName, StringDomain, StringProtocol, StringUuidOptions, StringValidator, Tuple, TupleValidator, Type, TypedArrayConstraintName, TypedArrayValidator, UUIDVersion, UndefinedToOptional, UnionValidator, UnknownEnumValueError, UnknownPropertyError, UnshiftTuple, Unwrap, UnwrapTuple, UrlOptions, ValidationError, ValidatorError, arrayLengthEqual, arrayLengthGreaterThan, arrayLengthGreaterThanOrEqual, arrayLengthLessThan, arrayLengthLessThanOrEqual, arrayLengthNotEqual, arrayLengthRange, arrayLengthRangeExclusive, arrayLengthRangeInclusive, bigintDivisibleBy, bigintEqual, bigintGreaterThan, bigintGreaterThanOrEqual, bigintLessThan, bigintLessThanOrEqual, bigintNotEqual, booleanFalse, booleanTrue, customInspectSymbol, customInspectSymbolStackLess, dateEqual, dateGreaterThan, dateGreaterThanOrEqual, dateInvalid, dateLessThan, dateLessThanOrEqual, dateNotEqual, dateValid, getGlobalValidationEnabled, numberDivisibleBy, numberEqual, numberFinite, numberGreaterThan, numberGreaterThanOrEqual, numberInt, numberLessThan, numberLessThanOrEqual, numberNaN, numberNotEqual, numberNotNaN, numberSafeInt, s, setGlobalValidationEnabled, stringEmail, stringIp, stringLengthEqual, stringLengthGreaterThan, stringLengthGreaterThanOrEqual, stringLengthLessThan, stringLengthLessThanOrEqual, stringLengthNotEqual, stringRegex, stringUrl, stringUuid, typedArrayByteLengthEqual, typedArrayByteLengthGreaterThan, typedArrayByteLengthGreaterThanOrEqual, typedArrayByteLengthLessThan, typedArrayByteLengthLessThanOrEqual, typedArrayByteLengthNotEqual, typedArrayByteLengthRange, typedArrayByteLengthRangeExclusive, typedArrayByteLengthRangeInclusive, typedArrayLengthEqual, typedArrayLengthGreaterThan, typedArrayLengthGreaterThanOrEqual, typedArrayLengthLessThan, typedArrayLengthLessThanOrEqual, typedArrayLengthNotEqual, typedArrayLengthRange, typedArrayLengthRangeExclusive, typedArrayLengthRangeInclusive }; -- cgit v1.2.3