Socket
Socket
Sign inDemoInstall

superstruct

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

superstruct - npm Package Compare versions

Comparing version 0.10.13 to 0.11.0

115

Changelog.md

@@ -5,2 +5,117 @@ # Changelog

### `0.11.0` — November 20, 2020
###### NEW
**New `assign`, `pick`, and `omit` object utilities.** These utilities make composing object structs together possible, which should make re-using structs in your codebase easier.
```ts
// Combine two structs with `assign`:
const a = object({ id: number() })
const b = object({ name: string() })
const c = assign([a, b])
// Pick out specific properties with `pick`:
const a2 = pick(c, ['id'])
// Omit specific properties with `omit`:
const a3 = omit(c, ['name'])
```
**New `unknown` struct.** This is the same as the existing `any` struct, but it will ensure that in TypeScript the value is of the more restrictive `unknown` type so it encourages better type safety.
```ts
const Shape = type({
id: number(),
name: string(),
other: unknown(),
})
```
**New `integer`, `regexp`, and `func` structs.** These are just simple additions for common use cases of ensuring a value is an integer, a regular expression object (not a string!), or a function.
```ts
const Shape = type({
id: integer(),
matches: regexp(),
send: func(),
})
```
**New `max/min` refinements.** For refining `number` (or `integer`) or `date` structs to ensure they are greater than or less than a specific threshold. The third argument can indicate whether to make the threshold exclusive (instead of the default inclusive).
```ts
const Index = min(number(), 0)
const PastOrPresent = max(date(), new Date())
const Past = max(date(), new Date(), { exclusive: true })
```
**Even more information on errors.** Errors now expose the `error.refinement` property when the failure originated in a refinement validation. And they also now have an `error.key` property which is the key for the failure in the case of complex values like arrays/objects. (Previously the key was retrievable by checking `error.path`, but this will make the 90% case easier.)
###### BREAKING
**The `coerce` helper has been renamed to `create`.** This will hopefully make it more clear that it's fully coercing and validating a value against a struct, throwing errors if the value was invalid. This has caused confusion for people who though it would just coerce the value and return the unvalidated-but-coerced version.
```ts
// Previously
const user = coerce(data, User)
// Now
const user = create(data, User)
```
**The `struct`, `refinement` and `coercion` factories have been renamed.** This renaming is purely for keeping things slightly cleaner and easier to understand. The new names are `define`, `refine`, and `coerce`. Separating them slightly from the noun-based names used for the types themselves.
```ts
// Previously
const Email = struct('email', isEmail)
const Positive = refinement('positive', number(), n => n > 0)
const Trimmed = coercion(string(), s => s.trim()
// Now
const Email = define('email', isEmail)
const Positive = refine(number(), 'positive', n => n > 0)
const Trimmed = coerce(string(), s => s.trim())
```
_Note that the order of `refine` arguments has changed to be slightly more natural, and encourage scoped refinement names._
**The `length` refinement has been renamed to `size`.** This is to match with the expansion of it's abilities from purely strings and arrays to also now include numbers, maps, and sets. In addition you can also omit the `max` argument to specify an exact size:
```ts
// Previously
const Name = length(string(), 1, 100)
const MyArray = length(array(string()), 3, 3)
// Now
const Name = size(string(), 1, 100)
const MyArray = size(array(string()), 3)
const Id = size(integer(), 1, Infinity)
const MySet = size(set(), 1, 9)
```
**The `StructType` inferring helper has been renamed to `Infer`.** This just makes it slightly easier to read what's going on when you're inferring a type.
```ts
// Previously
type User = StructType<typeof User>
// Now
type User = Infer<typeof User>
```
**The `error.type` property has been standardized.** Previously it was a human-readable description that sort of incorporated the schema. Now it is simple the plain lowercase name of the struct in question, making it something you can use programmatically when formatting errors.
```ts
// Previously
'Array<string>'
'[string,number]'
'Map<string,number>'
// Now
'array'
'tuple'
'map'
```
### `0.10.0` — June 6, 2020

@@ -7,0 +122,0 @@

4

lib/error.d.ts

@@ -28,6 +28,6 @@ /**

branch: Array<any>;
failures: () => IterableIterator<Failure>;
failures: () => Array<Failure>;
[key: string]: any;
constructor(failure: Failure, iterable: Iterable<Failure>);
constructor(failure: Failure, moreFailures: IterableIterator<Failure>);
}
//# sourceMappingURL=error.d.ts.map
/**
* `Struct` objects encapsulate the schema for a specific data type (with
* optional coercion). You can then use the `assert`, `is` or `validate` helpers
* to validate unknown data against a struct.
* A `StructFailure` represents a single specific failure in validation.
*/
declare class Struct<T, S = any> {
type Failure = {
value: any;
key: string | number | undefined;
type: string;
schema: S;
coercer: (value: unknown) => unknown;
validator: (value: unknown, context: StructContext) => StructResult;
refiner: (value: T, context: StructContext) => StructResult;
constructor(props: {
type: Struct<T>["type"];
schema: S;
coercer?: Struct<T>["coercer"];
validator?: Struct<T>["validator"];
refiner?: Struct<T>["refiner"];
});
}
refinement: string | undefined;
message: string;
branch: Array<any>;
path: Array<string | number>;
};
/**
* `StructError` objects are thrown (or returned) by Superstruct when its
* validation fails. The error represents the first error encountered during
* validation. But they also have an `error.failures` property that holds
* information for all of the failures encountered.
* `StructError` objects are thrown (or returned) when validation fails.
*
* Validation logic is design to exit early for maximum performance. The error
* represents the first error encountered during validation. For more detail,
* the `error.failures` property is a generator function that can be run to
* continue validation and receive all the failures in the data.
*/
declare class StructError extends TypeError {
value: any;
key: string | number | undefined;
type: string;
refinement: string | undefined;
path: Array<number | string>;
branch: Array<any>;
failures: () => Array<StructFailure>;
failures: () => Array<Failure>;
[key: string]: any;
constructor(failure: StructFailure, moreFailures: IterableIterator<StructFailure>);
constructor(failure: Failure, moreFailures: IterableIterator<Failure>);
}
/**
* `Struct` objects encapsulate the validation logic for a specific type of
* values. Once constructed, you use the `assert`, `is` or `validate` helpers to
* validate unknown input data against the struct.
*/
declare class Struct<T = unknown, S = unknown> {
readonly TYPE: T;
type: string;
schema: S;
coercer: Coercer;
validator: Validator<T, S>;
refiner: Refiner<T, S>;
constructor(props: {
type: Struct<T, S>["type"];
schema: Struct<T, S>["schema"];
coercer?: Struct<T, S>["coercer"];
validator?: Struct<T, S>["validator"];
refiner?: Struct<T, S>["refiner"];
});
/**
* Assert that a value passes the struct's validation, throwing if it doesn't.
*/
assert(value: unknown): value is T;
/**
* Create a value with the struct's coercion logic, then validate it.
*/
create(value: unknown): T;
/**
* Check if a value passes the struct's validation.
*/
is(value: unknown): value is T;
/**
* Mask a value, coercing and validating it, but returning only the subset of
* properties defined by the struct's schema.
*/
mask(value: unknown): T;
/**
* Validate a value with the struct's validation logic, returning a tuple
* representing the result.
*
* You may optionally pass `true` for the `withCoercion` argument to coerce
* the value before attempting to validate it. If you do, the result will
* contain the coerced result when successful.
*/
validate(value: unknown, options?: {
coerce?: boolean;
}): [StructError, undefined] | [undefined, T];
}
/**
* A `StructContext` contains information about the current value being
* validated as well as helper functions for failures and recursive validating.
*/
type StructContext = {
type Context<T, S> = {
value: any;
type: string;
struct: Struct<T, S>;
branch: Array<any>;
path: Array<string | number>;
fail: (props?: Partial<StructFailure>) => StructFailure;
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => IterableIterator<StructFailure>;
fail: (props?: string | Partial<Failure>) => Failure;
check: <Y, Z>(value: any, struct: Struct<Y, Z>, parent?: any, key?: string | number) => IterableIterator<Failure>;
};
/**
* A `StructFailure` represents a single specific failure in validation.
* A type utility to extract the type from a `Struct` class.
*/
type StructFailure = {
value: StructContext["value"];
type: StructContext["type"];
branch: StructContext["branch"];
path: StructContext["path"];
[key: string]: any;
};
type Infer<T extends Struct<any, any>> = T["TYPE"];
/**
* A `StructResult` is returned from validation functions.
* A `Result` is returned from validation functions.
*/
type StructResult = boolean | Iterable<StructFailure>;
type Result = boolean | string | Iterable<Failure>;
/**
* A type utility to extract the type from a `Struct` class.
* A `Coercer` takes an unknown value and optionally coerces it.
*/
type StructType<T extends Struct<any>> = Parameters<T["refiner"]>[0];
type Coercer = (value: unknown) => unknown;
/**
* A `Validate` takes an unknown value and validates it.
*/
type Validator<T, S> = (value: unknown, context: Context<T, S>) => Result;
/**
* A `Refiner` takes a value of a known type and validates it against a further
* constraint.
*/
type Refiner<T, S> = (value: T, context: Context<T, S>) => Result;
/**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
declare function assert<T>(value: unknown, struct: Struct<T>): value is T;
declare function assert<T, S>(value: unknown, struct: Struct<T, S>): value is T;
/**
* Coerce a value with the coercion logic of `Struct` and validate it.
* Create a value with the coercion logic of `Struct` and validate it.
*/
declare function coerce<T>(value: unknown, struct: Struct<T>): T;
declare function create<T, S>(value: unknown, struct: Struct<T, S>): T;
/**
* Mask a value, returning only the subset of properties defined by a Struct.
*/
declare function mask<T, S>(value: unknown, struct: Struct<T, S>): T;
/**
* Check if a value passes a `Struct`.
*/
declare function is<T>(value: unknown, struct: Struct<T>): value is T;
declare function is<T, S>(value: unknown, struct: Struct<T, S>): value is T;
/**
* Validate a value against a `Struct`, returning an error if invalid.
*/
declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T];
declare function validate<T, S>(value: unknown, struct: Struct<T, S>, options?: {
coerce?: boolean;
}): [StructError, undefined] | [undefined, T];
/**
* Augment a `Struct` to add an additional coercion step to its input.
*
* This allows you to transform input data before validating it, to increase the
* likelihood that it passes validation—for example for default values, parsing
* different formats, etc.
*
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
declare function coercion<T>(struct: Struct<T>, coercer: Struct<T>["coercer"]): Struct<T>;
declare function coerce<T, S>(struct: Struct<T, S>, coercer: Struct<T, S>["coercer"]): Struct<T, S>;
/**
* Augment a struct to coerce a default value for missing values.
* Augment a struct to replace `undefined` values with a default.
*
* Note: You must use `coerce(value, Struct)` on the value before validating it
* to have the value defaulted!
* Note: You must use `coerce(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
declare function defaulted<T>(S: Struct<T>, fallback: any, strict?: true): Struct<T>;
declare function defaulted<T, S>(S: Struct<T, S>, fallback: any, options?: {
strict?: boolean;
}): Struct<T, S>;
/**
* Coerce a value to mask its properties to only that defined in the struct.
* Augment a struct to mask its input to only properties defined in the struct.
*
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
declare function masked<T extends {
[key: string]: any;
}, V extends Record<string, Struct<any>>>(S: Struct<T, V>): Struct<T>;
declare function masked<T, S>(struct: Struct<T, S>): Struct<T, S>;
/**
* Augment a string or array struct to constrain its length to zero.
* Ensure that a string, array, map, or set is empty.
*/
declare function empty<T extends string | any[]>(S: Struct<T>): Struct<T>;
declare function empty<T extends string | any[] | Map<any, any> | Set<any>>(struct: Struct<T>): Struct<T>;
/**
* Augment a string or array struct to constrain its length to being between a
* minimum and maximum size.
* Ensure that a number or date is below a threshold.
*/
declare function length<T extends string | any[]>(S: Struct<T>, min: number, max: number): Struct<T>;
declare function max<T extends number | Date>(struct: Struct<T>, threshold: T, options?: {
exclusive?: boolean;
}): Struct<T>;
/**
* Refine a string struct to match a specific regexp pattern.
* Ensure that a number or date is above a threshold.
*/
declare function pattern<T extends string>(S: Struct<T>, regexp: RegExp): Struct<T>;
declare function min<T extends number | Date>(struct: Struct<T>, threshold: T, options?: {
exclusive?: boolean;
}): Struct<T>;
/**
* Ensure that a string matches a regular expression.
*/
declare function pattern<T extends string>(struct: Struct<T>, regexp: RegExp): Struct<T>;
/**
* Ensure that a string, array, number, date, map, or set has a size (or length, or time) between `min` and `max`.
*/
declare function size<T extends string | number | Date | any[] | Map<any, any> | Set<any>>(struct: Struct<T>, min: number, max?: number): Struct<T>;
/**
* Augment a `Struct` to add an additional refinement to the validation.
*
* The refiner function is guaranteed to receive a value of the struct's type,
* because the struct's existing validation will already have passed. This
* allows you to layer additional validation on top of existing structs.
*/
declare function refinement<T>(struct: Struct<T>, type: string, refiner: Struct<T>["refiner"]): Struct<T>;
type StructRecord<T> = Record<string, Struct<T>>;
type StructTuple<T> = {
declare function refine<T, S>(struct: Struct<T, S>, name: string, refiner: Refiner<T, S>): Struct<T, S>;
/**
* Normalize properties of a type that allow `undefined` to make them optional.
*/
type Optionalize<S extends object> = OmitBy<S, undefined> & Partial<PickBy<S, undefined>>;
/**
* Omit properties from a type that extend from a specific type.
*/
type OmitBy<T, V> = Omit<T, {
[K in keyof T]: V extends Extract<T[K], V> ? K : never;
}[keyof T]>;
/**
* Pick properties from a type that extend from a specific type.
*/
type PickBy<T, V> = Pick<T, {
[K in keyof T]: V extends Extract<T[K], V> ? K : never;
}[keyof T]>;
/**
* Simplifies a type definition to its most basic representation.
*/
type Simplify<T> = T extends any[] | Date ? T : {
[Key in keyof T]: T[Key];
} & {};
/**
* Assign properties from one type to another, overwriting existing.
*/
type Assign<T, U> = Simplify<U & Omit<T, keyof U>>;
/**
* A schema for object structs.
*/
type ObjectSchema = Record<string, Struct<any, any>>;
/**
* Infer a type from an object struct schema.
*/
type ObjectType<S extends ObjectSchema> = Simplify<Optionalize<{
[K in keyof S]: Infer<S[K]>;
}>>;
/**
* Transform an object schema type to represent a partial.
*/
type PartialObjectSchema<S extends ObjectSchema> = {
[K in keyof S]: Struct<Infer<S[K]> | undefined>;
};
/**
* A schema for tuple structs.
*/
type TupleSchema<T> = {
[K in keyof T]: Struct<T[K]>;
};
/**
* Validate any value.
* Ensure that any value passes validation.
*/
declare function any(): Struct<any>;
declare function any(): Struct<any, null>;
/**
* Validate that an array of values of a specific type.
* Ensure that a value is an array and that its elements are of a specific type.
*
* Note: If you omit the element struct, the arrays elements will not be
* iterated at all. This can be helpful for cases where performance is critical,
* and it is preferred to using `array(any())`.
*/
declare function array(): Struct<unknown[]>;
declare function array<T>(Element: Struct<T>): Struct<T[], Struct<T>>;
declare function array<T extends Struct<any>>(Element: T): Struct<Infer<T>[], T>;
declare function array(): Struct<unknown[], undefined>;
/**
* Validate that boolean values.
* Ensure that a value is a boolean.
*/
declare function boolean(): Struct<boolean>;
declare function boolean(): Struct<boolean, null>;
/**
* Validate that `Date` values.
* Ensure that a value is a valid `Date`.
*

@@ -138,179 +265,214 @@ * Note: this also ensures that the value is *not* an invalid `Date` object,

*/
declare function date(): Struct<Date>;
declare function date(): Struct<Date, null>;
/**
* Validate that a value dynamically, determing which struct to use at runtime.
* Ensure that a value is one of a set of potential values.
*
* Note: after creating the struct, you can access the definition of the
* potential values as `struct.schema`.
*/
declare function dynamic<T>(fn: (value: unknown, ctx: StructContext) => Struct<T>): Struct<T>;
declare function enums<T extends number>(values: T[]): Struct<T, {
[K in T[][number]]: K;
}>;
declare function enums<T extends string>(values: T[]): Struct<T, {
[K in T[][number]]: K;
}>;
/**
* Validate that a value against a set of potential values.
* Ensure that a value is a function.
*/
declare function enums<T extends number>(values: T[]): Struct<T>;
declare function enums<T extends string>(values: T[]): Struct<T>;
declare function func(): Struct<Function, null>;
/**
* Validate that a value is a function.
* Ensure that a value is an instance of a specific class.
*/
declare function func(): Struct<Function>;
/**
* Validate that a value is an instance of a class.
*/
declare function instance<T extends {
new (...args: any): any;
}>(Class: T): Struct<InstanceType<T>>;
}>(Class: T): Struct<InstanceType<T>, null>;
/**
* Validate that a value matches all of a set of structs.
* Ensure that a value is an integer.
*/
declare function intersection<A>(Structs: StructTuple<[A]>): Struct<A>;
declare function intersection<A, B>(Structs: StructTuple<[A, B]>): Struct<A & B>;
declare function intersection<A, B, C>(Structs: StructTuple<[A, B, C]>): Struct<A & B & C>;
declare function intersection<A, B, C, D>(Structs: StructTuple<[A, B, C, D]>): Struct<A & B & C & D>;
declare function intersection<A, B, C, D, E>(Structs: StructTuple<[A, B, C, D, E]>): Struct<A & B & C & D & E>;
declare function intersection<A, B, C, D, E, F>(Structs: StructTuple<[A, B, C, D, E, F]>): Struct<A & B & C & D & E & F>;
declare function intersection<A, B, C, D, E, F, G>(Structs: StructTuple<[A, B, C, D, E, F, G]>): Struct<A & B & C & D & E & F & G>;
declare function intersection<A, B, C, D, E, F, G, H>(Structs: StructTuple<[A, B, C, D, E, F, G, H]>): Struct<A & B & C & D & E & F & G & H>;
declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I]>): Struct<A & B & C & D & E & F & G & H & I>;
declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J]>): Struct<A & B & C & D & E & F & G & H & I & J>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A & B & C & D & E & F & G & H & I & J & K>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q>;
declare function integer(): Struct<number, null>;
/**
* Validate a value lazily, by constructing the struct right before the first
* validation. This is useful for cases where you want to have self-referential
* structs for nested data structures.
* Ensure that a value matches all of a set of types.
*/
declare function lazy<T>(fn: () => Struct<T>): Struct<T>;
declare function intersection<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
declare function intersection<A, B>(Structs: TupleSchema<[A, B]>): Struct<A & B, null>;
declare function intersection<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<A & B & C, null>;
declare function intersection<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<A & B & C & D, null>;
declare function intersection<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<A & B & C & D & E, null>;
declare function intersection<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<A & B & C & D & E & F, null>;
declare function intersection<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<A & B & C & D & E & F & G, null>;
declare function intersection<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<A & B & C & D & E & F & G & H, null>;
declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<A & B & C & D & E & F & G & H & I, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<A & B & C & D & E & F & G & H & I & J, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A & B & C & D & E & F & G & H & I & J & K, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q, null>;
/**
* Validate that a value is a specific constant.
* Ensure that a value is an exact value, using `===` for comparison.
*/
declare function literal<T extends boolean>(constant: T): Struct<T>;
declare function literal<T extends number>(constant: T): Struct<T>;
declare function literal<T extends string>(constant: T): Struct<T>;
declare function literal<T>(constant: T): Struct<T>;
declare function literal<T extends boolean>(constant: T): Struct<T, null>;
declare function literal<T extends number>(constant: T): Struct<T, null>;
declare function literal<T extends string>(constant: T): Struct<T, null>;
declare function literal<T>(constant: T): Struct<T, null>;
/**
* Validate that a value is a map with specific key and value entries.
* Ensure that a value is a `Map` object, and that its keys and values are of
* specific types.
*/
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>>;
declare function map(): Struct<Map<unknown, unknown>, null>;
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>, null>;
/**
* Validate that a value always fails.
* Ensure that no value ever passes validation.
*/
declare function never(): Struct<never>;
declare function never(): Struct<never, null>;
/**
* Augment a struct to make it accept `null` values.
* Augment an existing struct to allow `null` values.
*/
declare function nullable<T>(S: Struct<T>): Struct<T | null>;
declare function nullable<T, S>(struct: Struct<T, S>): Struct<T | null, S>;
/**
* Validate that a value is a number.
* Ensure that a value is a number.
*/
declare function number(): Struct<number>;
declare function number(): Struct<number, null>;
/**
* Type helper to Flatten the Union of optional and required properties.
* Ensure that a value is an object, that is has a known set of properties,
* and that its properties are of specific types.
*
* Note: Unrecognized properties will fail validation.
*/
type Flatten<T> = T extends infer U ? {
[K in keyof U]: U[K];
} : never;
declare function object(): Struct<Record<string, unknown>, null>;
declare function object<S extends ObjectSchema>(schema: S): Struct<ObjectType<S>, S>;
/**
* Type helper to extract the optional keys of an object
* Augment a struct to allow `undefined` values.
*/
type OptionalKeys<T> = {
[K in keyof T]: undefined extends T[K] ? K : never;
}[keyof T];
declare function optional<T, S>(struct: Struct<T, S>): Struct<T | undefined, S>;
/**
* Type helper to extract the required keys of an object
* Ensure that a value is an object with keys and values of specific types, but
* without ensuring any specific shape of properties.
*
* Like TypeScript's `Record` utility.
*/
type RequiredKeys<T> = {
[K in keyof T]: undefined extends T[K] ? never : K;
}[keyof T];
declare function record<K extends string, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>, null>;
/**
* Type helper to create optional properties when the property value can be
* undefined (ie. when `optional()` is used to define a type)
* Ensure that a value is a `RegExp`.
*
* Note: this does not test the value against the regular expression! For that
* you need to use the `pattern()` refinement.
*/
type OptionalizeObject<T> = Flatten<{
[K in RequiredKeys<T>]: T[K];
} & {
[K in OptionalKeys<T>]?: T[K];
}>;
declare function regexp(): Struct<RegExp, null>;
/**
* Validate that an object with specific entry values.
* Ensure that a value is a `Set` object, and that its elements are of a
* specific type.
*/
declare function object<V extends StructRecord<any>>(): Struct<Record<string, unknown>>;
declare function object<V extends StructRecord<any>>(Structs: V): Struct<OptionalizeObject<{
[K in keyof V]: StructType<V[K]>;
}>, V>;
declare function set(): Struct<Set<unknown>, null>;
declare function set<T>(Element: Struct<T>): Struct<Set<T>, null>;
/**
* Augment a struct to make it optionally accept `undefined` values.
* Ensure that a value is a string.
*/
declare function optional<T>(S: Struct<T>): Struct<T | undefined>;
declare function string(): Struct<string, null>;
/**
* Validate that a partial object with specific entry values.
* Ensure that a value is a tuple of a specific length, and that each of its
* elements is of a specific type.
*/
declare function partial<T, V extends StructRecord<any>>(Structs: V | Struct<T, V>): Struct<{
[K in keyof V]?: StructType<V[K]>;
}>;
declare function tuple<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
declare function tuple<A, B>(Structs: TupleSchema<[A, B]>): Struct<[A, B], null>;
declare function tuple<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<[A, B, C], null>;
declare function tuple<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<[A, B, C, D], null>;
declare function tuple<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<[A, B, C, D, E], null>;
declare function tuple<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<[A, B, C, D, E, F], null>;
declare function tuple<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<[A, B, C, D, E, F, G], null>;
declare function tuple<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<[A, B, C, D, E, F, G, H], null>;
declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<[A, B, C, D, E, F, G, H, I], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<[A, B, C, D, E, F, G, H, I, J], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<[A, B, C, D, E, F, G, H, I, J, K], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q], null>;
/**
* Validate that a value is a record with specific key and
* value entries.
* Ensure that a value has a set of known properties of specific types.
*
* Note: Unrecognized properties are allowed and untouched. This is similar to
* how TypeScript's structural typing works.
*/
declare function record<K extends string | number, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>>;
declare function type<S extends ObjectSchema>(schema: S): Struct<ObjectType<S>, S>;
/**
* Validate that a set of values matches a specific type.
* Ensure that a value matches one of a set of types.
*/
declare function set<T>(Element: Struct<T>): Struct<Set<T>>;
declare function union<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
declare function union<A, B>(Structs: TupleSchema<[A, B]>): Struct<A | B, null>;
declare function union<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<A | B | C, null>;
declare function union<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<A | B | C | D, null>;
declare function union<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<A | B | C | D | E, null>;
declare function union<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<A | B | C | D | E | F, null>;
declare function union<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<A | B | C | D | E | F | G, null>;
declare function union<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<A | B | C | D | E | F | G | H, null>;
declare function union<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<A | B | C | D | E | F | G | H | I, null>;
declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<A | B | C | D | E | F | G | H | I | J, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A | B | C | D | E | F | G | H | I | J | K, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q, null>;
/**
* Validate that a value is a string.
* Ensure that any value passes validation, without widening its type to `any`.
*/
declare function string(): Struct<string>;
declare function unknown(): Struct<unknown, null>;
/**
* Define a `Struct` instance with a type and validation function.
* Create a new struct that combines the properties properties from multiple
* object structs.
*
* Like JavaScript's `Object.assign` utility.
*/
declare function struct<T>(name: string, validator: Struct<T>["validator"]): Struct<T, null>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>): Struct<ObjectType<Assign<A, B>>, Assign<A, B>>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>): Struct<ObjectType<Assign<Assign<A, B>, C>>, Assign<Assign<A, B>, C>>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>, D: Struct<ObjectType<D>, D>): Struct<ObjectType<Assign<Assign<Assign<A, B>, C>, D>>, Assign<Assign<Assign<A, B>, C>, D>>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema, E extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>, D: Struct<ObjectType<D>, D>, E: Struct<ObjectType<E>, E>): Struct<ObjectType<Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>, Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>;
/**
* Validate that a value is a tuple with entries of specific types.
* Define a new struct with a custom validation function.
*/
declare function tuple<A>(Structs: StructTuple<[A]>): Struct<A>;
declare function tuple<A, B>(Structs: StructTuple<[A, B]>): Struct<[A, B]>;
declare function tuple<A, B, C>(Structs: StructTuple<[A, B, C]>): Struct<[A, B, C]>;
declare function tuple<A, B, C, D>(Structs: StructTuple<[A, B, C, D]>): Struct<[A, B, C, D]>;
declare function tuple<A, B, C, D, E>(Structs: StructTuple<[A, B, C, D, E]>): Struct<[A, B, C, D, E]>;
declare function tuple<A, B, C, D, E, F>(Structs: StructTuple<[A, B, C, D, E, F]>): Struct<[A, B, C, D, E, F]>;
declare function tuple<A, B, C, D, E, F, G>(Structs: StructTuple<[A, B, C, D, E, F, G]>): Struct<[A, B, C, D, E, F, G]>;
declare function tuple<A, B, C, D, E, F, G, H>(Structs: StructTuple<[A, B, C, D, E, F, G, H]>): Struct<[A, B, C, D, E, F, G, H]>;
declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I]>): Struct<[A, B, C, D, E, F, G, H, I]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J]>): Struct<[A, B, C, D, E, F, G, H, I, J]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<[A, B, C, D, E, F, G, H, I, J, K]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>;
declare function define<T>(name: string, validator: Validator<T, null>): Struct<T, null>;
/**
* Validate that a value matches a specific strutural interface, like the
* structural typing that TypeScript uses.
* Create a struct with dynamic, runtime validation.
*
* The callback will receive the value currently being validated, and must
* return a struct object to validate it with. This can be useful to model
* validation logic that changes based on its input.
*/
declare function type<V extends StructRecord<any>>(Structs: V): Struct<{
[K in keyof V]: StructType<V[K]>;
}>;
declare function dynamic<T>(fn: (value: unknown, ctx: Context<T, null>) => Struct<T, any>): Struct<T, null>;
/**
* Validate that a value is one of a set of types.
* Create a struct with lazily evaluated validation.
*
* The first time validation is run with the struct, the callback will be called
* and must return a struct object to use. This is useful for cases where you
* want to have self-referential structs for nested data structures to avoid a
* circular definition problem.
*/
declare function union<A>(Structs: StructTuple<[A]>): Struct<A>;
declare function union<A, B>(Structs: StructTuple<[A, B]>): Struct<A | B>;
declare function union<A, B, C>(Structs: StructTuple<[A, B, C]>): Struct<A | B | C>;
declare function union<A, B, C, D>(Structs: StructTuple<[A, B, C, D]>): Struct<A | B | C | D>;
declare function union<A, B, C, D, E>(Structs: StructTuple<[A, B, C, D, E]>): Struct<A | B | C | D | E>;
declare function union<A, B, C, D, E, F>(Structs: StructTuple<[A, B, C, D, E, F]>): Struct<A | B | C | D | E | F>;
declare function union<A, B, C, D, E, F, G>(Structs: StructTuple<[A, B, C, D, E, F, G]>): Struct<A | B | C | D | E | F | G>;
declare function union<A, B, C, D, E, F, G, H>(Structs: StructTuple<[A, B, C, D, E, F, G, H]>): Struct<A | B | C | D | E | F | G | H>;
declare function union<A, B, C, D, E, F, G, H, I>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I]>): Struct<A | B | C | D | E | F | G | H | I>;
declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J]>): Struct<A | B | C | D | E | F | G | H | I | J>;
declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A | B | C | D | E | F | G | H | I | J | K>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q>;
export { coercion, defaulted, masked, empty, length, pattern, refinement, Struct, StructError, StructContext, StructFailure, StructResult, StructType, assert, coerce, is, validate, any, array, boolean, date, dynamic, enums, func, instance, intersection, lazy, literal, map, never, nullable, number, object, optional, partial, record, set, string, struct, tuple, type, union };
declare function lazy<T>(fn: () => Struct<T, any>): Struct<T, null>;
/**
* Create a new struct based on an existing object struct, but excluding
* specific properties.
*
* Like TypeScript's `Omit` utility.
*/
declare function omit<S extends ObjectSchema, K extends keyof S>(struct: Struct<ObjectType<S>, S>, keys: K[]): Struct<ObjectType<Omit<S, K>>, Omit<S, K>>;
/**
* Create a new struct based on an existing object struct, but with all of its
* properties allowed to be `undefined`.
*
* Like TypeScript's `Partial` utility.
*/
declare function partial<S extends ObjectSchema>(struct: Struct<ObjectType<S>, S> | S): Struct<ObjectType<PartialObjectSchema<S>>, PartialObjectSchema<S>>;
/**
* Create a new struct based on an existing object struct, but only including
* specific properties.
*
* Like TypeScript's `Pick` utility.
*/
declare function pick<S extends ObjectSchema, K extends keyof S>(struct: Struct<ObjectType<S>, S>, keys: K[]): Struct<ObjectType<Pick<S, K>>, Pick<S, K>>;
export { Failure, StructError, Struct, Context, Infer, Result, Coercer, Validator, Refiner, assert, create, mask, is, validate, coerce, defaulted, masked, empty, max, min, pattern, size, refine, any, array, boolean, date, enums, func, instance, integer, intersection, literal, map, never, nullable, number, object, optional, record, regexp, set, string, tuple, type, union, unknown, assign, define, dynamic, lazy, omit, partial, pick };

@@ -1,5 +0,7 @@

export * from './coercions';
export * from './refinements';
export * from './error';
export * from './struct';
export * from './types';
export * from './structs/coercions';
export * from './structs/refinements';
export * from './structs/types';
export * from './structs/utilities';
//# sourceMappingURL=index.d.ts.map
/**
* `Struct` objects encapsulate the schema for a specific data type (with
* optional coercion). You can then use the `assert`, `is` or `validate` helpers
* to validate unknown data against a struct.
* A `StructFailure` represents a single specific failure in validation.
*/
declare class Struct<T, S = any> {
type Failure = {
value: any;
key: string | number | undefined;
type: string;
schema: S;
coercer: (value: unknown) => unknown;
validator: (value: unknown, context: StructContext) => StructResult;
refiner: (value: T, context: StructContext) => StructResult;
constructor(props: {
type: Struct<T>["type"];
schema: S;
coercer?: Struct<T>["coercer"];
validator?: Struct<T>["validator"];
refiner?: Struct<T>["refiner"];
});
}
refinement: string | undefined;
message: string;
branch: Array<any>;
path: Array<string | number>;
};
/**
* `StructError` objects are thrown (or returned) by Superstruct when its
* validation fails. The error represents the first error encountered during
* validation. But they also have an `error.failures` property that holds
* information for all of the failures encountered.
* `StructError` objects are thrown (or returned) when validation fails.
*
* Validation logic is design to exit early for maximum performance. The error
* represents the first error encountered during validation. For more detail,
* the `error.failures` property is a generator function that can be run to
* continue validation and receive all the failures in the data.
*/
declare class StructError extends TypeError {
value: any;
key: string | number | undefined;
type: string;
refinement: string | undefined;
path: Array<number | string>;
branch: Array<any>;
failures: () => Array<StructFailure>;
failures: () => Array<Failure>;
[key: string]: any;
constructor(failure: StructFailure, moreFailures: IterableIterator<StructFailure>);
constructor(failure: Failure, moreFailures: IterableIterator<Failure>);
}
/**
* `Struct` objects encapsulate the validation logic for a specific type of
* values. Once constructed, you use the `assert`, `is` or `validate` helpers to
* validate unknown input data against the struct.
*/
declare class Struct<T = unknown, S = unknown> {
readonly TYPE: T;
type: string;
schema: S;
coercer: Coercer;
validator: Validator<T, S>;
refiner: Refiner<T, S>;
constructor(props: {
type: Struct<T, S>["type"];
schema: Struct<T, S>["schema"];
coercer?: Struct<T, S>["coercer"];
validator?: Struct<T, S>["validator"];
refiner?: Struct<T, S>["refiner"];
});
/**
* Assert that a value passes the struct's validation, throwing if it doesn't.
*/
assert(value: unknown): value is T;
/**
* Create a value with the struct's coercion logic, then validate it.
*/
create(value: unknown): T;
/**
* Check if a value passes the struct's validation.
*/
is(value: unknown): value is T;
/**
* Mask a value, coercing and validating it, but returning only the subset of
* properties defined by the struct's schema.
*/
mask(value: unknown): T;
/**
* Validate a value with the struct's validation logic, returning a tuple
* representing the result.
*
* You may optionally pass `true` for the `withCoercion` argument to coerce
* the value before attempting to validate it. If you do, the result will
* contain the coerced result when successful.
*/
validate(value: unknown, options?: {
coerce?: boolean;
}): [StructError, undefined] | [undefined, T];
}
/**
* A `StructContext` contains information about the current value being
* validated as well as helper functions for failures and recursive validating.
*/
type StructContext = {
type Context<T, S> = {
value: any;
type: string;
struct: Struct<T, S>;
branch: Array<any>;
path: Array<string | number>;
fail: (props?: Partial<StructFailure>) => StructFailure;
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => IterableIterator<StructFailure>;
fail: (props?: string | Partial<Failure>) => Failure;
check: <Y, Z>(value: any, struct: Struct<Y, Z>, parent?: any, key?: string | number) => IterableIterator<Failure>;
};
/**
* A `StructFailure` represents a single specific failure in validation.
* A type utility to extract the type from a `Struct` class.
*/
type StructFailure = {
value: StructContext["value"];
type: StructContext["type"];
branch: StructContext["branch"];
path: StructContext["path"];
[key: string]: any;
};
type Infer<T extends Struct<any, any>> = T["TYPE"];
/**
* A `StructResult` is returned from validation functions.
* A `Result` is returned from validation functions.
*/
type StructResult = boolean | Iterable<StructFailure>;
type Result = boolean | string | Iterable<Failure>;
/**
* A type utility to extract the type from a `Struct` class.
* A `Coercer` takes an unknown value and optionally coerces it.
*/
type StructType<T extends Struct<any>> = Parameters<T["refiner"]>[0];
type Coercer = (value: unknown) => unknown;
/**
* A `Validate` takes an unknown value and validates it.
*/
type Validator<T, S> = (value: unknown, context: Context<T, S>) => Result;
/**
* A `Refiner` takes a value of a known type and validates it against a further
* constraint.
*/
type Refiner<T, S> = (value: T, context: Context<T, S>) => Result;
/**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
declare function assert<T>(value: unknown, struct: Struct<T>): value is T;
declare function assert<T, S>(value: unknown, struct: Struct<T, S>): value is T;
/**
* Coerce a value with the coercion logic of `Struct` and validate it.
* Create a value with the coercion logic of `Struct` and validate it.
*/
declare function coerce<T>(value: unknown, struct: Struct<T>): T;
declare function create<T, S>(value: unknown, struct: Struct<T, S>): T;
/**
* Mask a value, returning only the subset of properties defined by a Struct.
*/
declare function mask<T, S>(value: unknown, struct: Struct<T, S>): T;
/**
* Check if a value passes a `Struct`.
*/
declare function is<T>(value: unknown, struct: Struct<T>): value is T;
declare function is<T, S>(value: unknown, struct: Struct<T, S>): value is T;
/**
* Validate a value against a `Struct`, returning an error if invalid.
*/
declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T];
declare function validate<T, S>(value: unknown, struct: Struct<T, S>, options?: {
coerce?: boolean;
}): [StructError, undefined] | [undefined, T];
/**
* Augment a `Struct` to add an additional coercion step to its input.
*
* This allows you to transform input data before validating it, to increase the
* likelihood that it passes validation—for example for default values, parsing
* different formats, etc.
*
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
declare function coercion<T>(struct: Struct<T>, coercer: Struct<T>["coercer"]): Struct<T>;
declare function coerce<T, S>(struct: Struct<T, S>, coercer: Struct<T, S>["coercer"]): Struct<T, S>;
/**
* Augment a struct to coerce a default value for missing values.
* Augment a struct to replace `undefined` values with a default.
*
* Note: You must use `coerce(value, Struct)` on the value before validating it
* to have the value defaulted!
* Note: You must use `coerce(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
declare function defaulted<T>(S: Struct<T>, fallback: any, strict?: true): Struct<T>;
declare function defaulted<T, S>(S: Struct<T, S>, fallback: any, options?: {
strict?: boolean;
}): Struct<T, S>;
/**
* Coerce a value to mask its properties to only that defined in the struct.
* Augment a struct to mask its input to only properties defined in the struct.
*
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
declare function masked<T extends {
[key: string]: any;
}, V extends Record<string, Struct<any>>>(S: Struct<T, V>): Struct<T>;
declare function masked<T, S>(struct: Struct<T, S>): Struct<T, S>;
/**
* Augment a string or array struct to constrain its length to zero.
* Ensure that a string, array, map, or set is empty.
*/
declare function empty<T extends string | any[]>(S: Struct<T>): Struct<T>;
declare function empty<T extends string | any[] | Map<any, any> | Set<any>>(struct: Struct<T>): Struct<T>;
/**
* Augment a string or array struct to constrain its length to being between a
* minimum and maximum size.
* Ensure that a number or date is below a threshold.
*/
declare function length<T extends string | any[]>(S: Struct<T>, min: number, max: number): Struct<T>;
declare function max<T extends number | Date>(struct: Struct<T>, threshold: T, options?: {
exclusive?: boolean;
}): Struct<T>;
/**
* Refine a string struct to match a specific regexp pattern.
* Ensure that a number or date is above a threshold.
*/
declare function pattern<T extends string>(S: Struct<T>, regexp: RegExp): Struct<T>;
declare function min<T extends number | Date>(struct: Struct<T>, threshold: T, options?: {
exclusive?: boolean;
}): Struct<T>;
/**
* Ensure that a string matches a regular expression.
*/
declare function pattern<T extends string>(struct: Struct<T>, regexp: RegExp): Struct<T>;
/**
* Ensure that a string, array, number, date, map, or set has a size (or length, or time) between `min` and `max`.
*/
declare function size<T extends string | number | Date | any[] | Map<any, any> | Set<any>>(struct: Struct<T>, min: number, max?: number): Struct<T>;
/**
* Augment a `Struct` to add an additional refinement to the validation.
*
* The refiner function is guaranteed to receive a value of the struct's type,
* because the struct's existing validation will already have passed. This
* allows you to layer additional validation on top of existing structs.
*/
declare function refinement<T>(struct: Struct<T>, type: string, refiner: Struct<T>["refiner"]): Struct<T>;
type StructRecord<T> = Record<string, Struct<T>>;
type StructTuple<T> = {
declare function refine<T, S>(struct: Struct<T, S>, name: string, refiner: Refiner<T, S>): Struct<T, S>;
/**
* Normalize properties of a type that allow `undefined` to make them optional.
*/
type Optionalize<S extends object> = OmitBy<S, undefined> & Partial<PickBy<S, undefined>>;
/**
* Omit properties from a type that extend from a specific type.
*/
type OmitBy<T, V> = Omit<T, {
[K in keyof T]: V extends Extract<T[K], V> ? K : never;
}[keyof T]>;
/**
* Pick properties from a type that extend from a specific type.
*/
type PickBy<T, V> = Pick<T, {
[K in keyof T]: V extends Extract<T[K], V> ? K : never;
}[keyof T]>;
/**
* Simplifies a type definition to its most basic representation.
*/
type Simplify<T> = T extends any[] | Date ? T : {
[Key in keyof T]: T[Key];
} & {};
/**
* Assign properties from one type to another, overwriting existing.
*/
type Assign<T, U> = Simplify<U & Omit<T, keyof U>>;
/**
* A schema for object structs.
*/
type ObjectSchema = Record<string, Struct<any, any>>;
/**
* Infer a type from an object struct schema.
*/
type ObjectType<S extends ObjectSchema> = Simplify<Optionalize<{
[K in keyof S]: Infer<S[K]>;
}>>;
/**
* Transform an object schema type to represent a partial.
*/
type PartialObjectSchema<S extends ObjectSchema> = {
[K in keyof S]: Struct<Infer<S[K]> | undefined>;
};
/**
* A schema for tuple structs.
*/
type TupleSchema<T> = {
[K in keyof T]: Struct<T[K]>;
};
/**
* Validate any value.
* Ensure that any value passes validation.
*/
declare function any(): Struct<any>;
declare function any(): Struct<any, null>;
/**
* Validate that an array of values of a specific type.
* Ensure that a value is an array and that its elements are of a specific type.
*
* Note: If you omit the element struct, the arrays elements will not be
* iterated at all. This can be helpful for cases where performance is critical,
* and it is preferred to using `array(any())`.
*/
declare function array(): Struct<unknown[]>;
declare function array<T>(Element: Struct<T>): Struct<T[], Struct<T>>;
declare function array<T extends Struct<any>>(Element: T): Struct<Infer<T>[], T>;
declare function array(): Struct<unknown[], undefined>;
/**
* Validate that boolean values.
* Ensure that a value is a boolean.
*/
declare function boolean(): Struct<boolean>;
declare function boolean(): Struct<boolean, null>;
/**
* Validate that `Date` values.
* Ensure that a value is a valid `Date`.
*

@@ -138,179 +265,214 @@ * Note: this also ensures that the value is *not* an invalid `Date` object,

*/
declare function date(): Struct<Date>;
declare function date(): Struct<Date, null>;
/**
* Validate that a value dynamically, determing which struct to use at runtime.
* Ensure that a value is one of a set of potential values.
*
* Note: after creating the struct, you can access the definition of the
* potential values as `struct.schema`.
*/
declare function dynamic<T>(fn: (value: unknown, ctx: StructContext) => Struct<T>): Struct<T>;
declare function enums<T extends number>(values: T[]): Struct<T, {
[K in T[][number]]: K;
}>;
declare function enums<T extends string>(values: T[]): Struct<T, {
[K in T[][number]]: K;
}>;
/**
* Validate that a value against a set of potential values.
* Ensure that a value is a function.
*/
declare function enums<T extends number>(values: T[]): Struct<T>;
declare function enums<T extends string>(values: T[]): Struct<T>;
declare function func(): Struct<Function, null>;
/**
* Validate that a value is a function.
* Ensure that a value is an instance of a specific class.
*/
declare function func(): Struct<Function>;
/**
* Validate that a value is an instance of a class.
*/
declare function instance<T extends {
new (...args: any): any;
}>(Class: T): Struct<InstanceType<T>>;
}>(Class: T): Struct<InstanceType<T>, null>;
/**
* Validate that a value matches all of a set of structs.
* Ensure that a value is an integer.
*/
declare function intersection<A>(Structs: StructTuple<[A]>): Struct<A>;
declare function intersection<A, B>(Structs: StructTuple<[A, B]>): Struct<A & B>;
declare function intersection<A, B, C>(Structs: StructTuple<[A, B, C]>): Struct<A & B & C>;
declare function intersection<A, B, C, D>(Structs: StructTuple<[A, B, C, D]>): Struct<A & B & C & D>;
declare function intersection<A, B, C, D, E>(Structs: StructTuple<[A, B, C, D, E]>): Struct<A & B & C & D & E>;
declare function intersection<A, B, C, D, E, F>(Structs: StructTuple<[A, B, C, D, E, F]>): Struct<A & B & C & D & E & F>;
declare function intersection<A, B, C, D, E, F, G>(Structs: StructTuple<[A, B, C, D, E, F, G]>): Struct<A & B & C & D & E & F & G>;
declare function intersection<A, B, C, D, E, F, G, H>(Structs: StructTuple<[A, B, C, D, E, F, G, H]>): Struct<A & B & C & D & E & F & G & H>;
declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I]>): Struct<A & B & C & D & E & F & G & H & I>;
declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J]>): Struct<A & B & C & D & E & F & G & H & I & J>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A & B & C & D & E & F & G & H & I & J & K>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q>;
declare function integer(): Struct<number, null>;
/**
* Validate a value lazily, by constructing the struct right before the first
* validation. This is useful for cases where you want to have self-referential
* structs for nested data structures.
* Ensure that a value matches all of a set of types.
*/
declare function lazy<T>(fn: () => Struct<T>): Struct<T>;
declare function intersection<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
declare function intersection<A, B>(Structs: TupleSchema<[A, B]>): Struct<A & B, null>;
declare function intersection<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<A & B & C, null>;
declare function intersection<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<A & B & C & D, null>;
declare function intersection<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<A & B & C & D & E, null>;
declare function intersection<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<A & B & C & D & E & F, null>;
declare function intersection<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<A & B & C & D & E & F & G, null>;
declare function intersection<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<A & B & C & D & E & F & G & H, null>;
declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<A & B & C & D & E & F & G & H & I, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<A & B & C & D & E & F & G & H & I & J, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A & B & C & D & E & F & G & H & I & J & K, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q, null>;
/**
* Validate that a value is a specific constant.
* Ensure that a value is an exact value, using `===` for comparison.
*/
declare function literal<T extends boolean>(constant: T): Struct<T>;
declare function literal<T extends number>(constant: T): Struct<T>;
declare function literal<T extends string>(constant: T): Struct<T>;
declare function literal<T>(constant: T): Struct<T>;
declare function literal<T extends boolean>(constant: T): Struct<T, null>;
declare function literal<T extends number>(constant: T): Struct<T, null>;
declare function literal<T extends string>(constant: T): Struct<T, null>;
declare function literal<T>(constant: T): Struct<T, null>;
/**
* Validate that a value is a map with specific key and value entries.
* Ensure that a value is a `Map` object, and that its keys and values are of
* specific types.
*/
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>>;
declare function map(): Struct<Map<unknown, unknown>, null>;
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>, null>;
/**
* Validate that a value always fails.
* Ensure that no value ever passes validation.
*/
declare function never(): Struct<never>;
declare function never(): Struct<never, null>;
/**
* Augment a struct to make it accept `null` values.
* Augment an existing struct to allow `null` values.
*/
declare function nullable<T>(S: Struct<T>): Struct<T | null>;
declare function nullable<T, S>(struct: Struct<T, S>): Struct<T | null, S>;
/**
* Validate that a value is a number.
* Ensure that a value is a number.
*/
declare function number(): Struct<number>;
declare function number(): Struct<number, null>;
/**
* Type helper to Flatten the Union of optional and required properties.
* Ensure that a value is an object, that is has a known set of properties,
* and that its properties are of specific types.
*
* Note: Unrecognized properties will fail validation.
*/
type Flatten<T> = T extends infer U ? {
[K in keyof U]: U[K];
} : never;
declare function object(): Struct<Record<string, unknown>, null>;
declare function object<S extends ObjectSchema>(schema: S): Struct<ObjectType<S>, S>;
/**
* Type helper to extract the optional keys of an object
* Augment a struct to allow `undefined` values.
*/
type OptionalKeys<T> = {
[K in keyof T]: undefined extends T[K] ? K : never;
}[keyof T];
declare function optional<T, S>(struct: Struct<T, S>): Struct<T | undefined, S>;
/**
* Type helper to extract the required keys of an object
* Ensure that a value is an object with keys and values of specific types, but
* without ensuring any specific shape of properties.
*
* Like TypeScript's `Record` utility.
*/
type RequiredKeys<T> = {
[K in keyof T]: undefined extends T[K] ? never : K;
}[keyof T];
declare function record<K extends string, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>, null>;
/**
* Type helper to create optional properties when the property value can be
* undefined (ie. when `optional()` is used to define a type)
* Ensure that a value is a `RegExp`.
*
* Note: this does not test the value against the regular expression! For that
* you need to use the `pattern()` refinement.
*/
type OptionalizeObject<T> = Flatten<{
[K in RequiredKeys<T>]: T[K];
} & {
[K in OptionalKeys<T>]?: T[K];
}>;
declare function regexp(): Struct<RegExp, null>;
/**
* Validate that an object with specific entry values.
* Ensure that a value is a `Set` object, and that its elements are of a
* specific type.
*/
declare function object<V extends StructRecord<any>>(): Struct<Record<string, unknown>>;
declare function object<V extends StructRecord<any>>(Structs: V): Struct<OptionalizeObject<{
[K in keyof V]: StructType<V[K]>;
}>, V>;
declare function set(): Struct<Set<unknown>, null>;
declare function set<T>(Element: Struct<T>): Struct<Set<T>, null>;
/**
* Augment a struct to make it optionally accept `undefined` values.
* Ensure that a value is a string.
*/
declare function optional<T>(S: Struct<T>): Struct<T | undefined>;
declare function string(): Struct<string, null>;
/**
* Validate that a partial object with specific entry values.
* Ensure that a value is a tuple of a specific length, and that each of its
* elements is of a specific type.
*/
declare function partial<T, V extends StructRecord<any>>(Structs: V | Struct<T, V>): Struct<{
[K in keyof V]?: StructType<V[K]>;
}>;
declare function tuple<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
declare function tuple<A, B>(Structs: TupleSchema<[A, B]>): Struct<[A, B], null>;
declare function tuple<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<[A, B, C], null>;
declare function tuple<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<[A, B, C, D], null>;
declare function tuple<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<[A, B, C, D, E], null>;
declare function tuple<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<[A, B, C, D, E, F], null>;
declare function tuple<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<[A, B, C, D, E, F, G], null>;
declare function tuple<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<[A, B, C, D, E, F, G, H], null>;
declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<[A, B, C, D, E, F, G, H, I], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<[A, B, C, D, E, F, G, H, I, J], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<[A, B, C, D, E, F, G, H, I, J, K], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q], null>;
/**
* Validate that a value is a record with specific key and
* value entries.
* Ensure that a value has a set of known properties of specific types.
*
* Note: Unrecognized properties are allowed and untouched. This is similar to
* how TypeScript's structural typing works.
*/
declare function record<K extends string | number, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>>;
declare function type<S extends ObjectSchema>(schema: S): Struct<ObjectType<S>, S>;
/**
* Validate that a set of values matches a specific type.
* Ensure that a value matches one of a set of types.
*/
declare function set<T>(Element: Struct<T>): Struct<Set<T>>;
declare function union<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
declare function union<A, B>(Structs: TupleSchema<[A, B]>): Struct<A | B, null>;
declare function union<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<A | B | C, null>;
declare function union<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<A | B | C | D, null>;
declare function union<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<A | B | C | D | E, null>;
declare function union<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<A | B | C | D | E | F, null>;
declare function union<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<A | B | C | D | E | F | G, null>;
declare function union<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<A | B | C | D | E | F | G | H, null>;
declare function union<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<A | B | C | D | E | F | G | H | I, null>;
declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<A | B | C | D | E | F | G | H | I | J, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A | B | C | D | E | F | G | H | I | J | K, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q, null>;
/**
* Validate that a value is a string.
* Ensure that any value passes validation, without widening its type to `any`.
*/
declare function string(): Struct<string>;
declare function unknown(): Struct<unknown, null>;
/**
* Define a `Struct` instance with a type and validation function.
* Create a new struct that combines the properties properties from multiple
* object structs.
*
* Like JavaScript's `Object.assign` utility.
*/
declare function struct<T>(name: string, validator: Struct<T>["validator"]): Struct<T, null>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>): Struct<ObjectType<Assign<A, B>>, Assign<A, B>>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>): Struct<ObjectType<Assign<Assign<A, B>, C>>, Assign<Assign<A, B>, C>>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>, D: Struct<ObjectType<D>, D>): Struct<ObjectType<Assign<Assign<Assign<A, B>, C>, D>>, Assign<Assign<Assign<A, B>, C>, D>>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema, E extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>, D: Struct<ObjectType<D>, D>, E: Struct<ObjectType<E>, E>): Struct<ObjectType<Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>, Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>;
/**
* Validate that a value is a tuple with entries of specific types.
* Define a new struct with a custom validation function.
*/
declare function tuple<A>(Structs: StructTuple<[A]>): Struct<A>;
declare function tuple<A, B>(Structs: StructTuple<[A, B]>): Struct<[A, B]>;
declare function tuple<A, B, C>(Structs: StructTuple<[A, B, C]>): Struct<[A, B, C]>;
declare function tuple<A, B, C, D>(Structs: StructTuple<[A, B, C, D]>): Struct<[A, B, C, D]>;
declare function tuple<A, B, C, D, E>(Structs: StructTuple<[A, B, C, D, E]>): Struct<[A, B, C, D, E]>;
declare function tuple<A, B, C, D, E, F>(Structs: StructTuple<[A, B, C, D, E, F]>): Struct<[A, B, C, D, E, F]>;
declare function tuple<A, B, C, D, E, F, G>(Structs: StructTuple<[A, B, C, D, E, F, G]>): Struct<[A, B, C, D, E, F, G]>;
declare function tuple<A, B, C, D, E, F, G, H>(Structs: StructTuple<[A, B, C, D, E, F, G, H]>): Struct<[A, B, C, D, E, F, G, H]>;
declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I]>): Struct<[A, B, C, D, E, F, G, H, I]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J]>): Struct<[A, B, C, D, E, F, G, H, I, J]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<[A, B, C, D, E, F, G, H, I, J, K]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>;
declare function define<T>(name: string, validator: Validator<T, null>): Struct<T, null>;
/**
* Validate that a value matches a specific strutural interface, like the
* structural typing that TypeScript uses.
* Create a struct with dynamic, runtime validation.
*
* The callback will receive the value currently being validated, and must
* return a struct object to validate it with. This can be useful to model
* validation logic that changes based on its input.
*/
declare function type<V extends StructRecord<any>>(Structs: V): Struct<{
[K in keyof V]: StructType<V[K]>;
}>;
declare function dynamic<T>(fn: (value: unknown, ctx: Context<T, null>) => Struct<T, any>): Struct<T, null>;
/**
* Validate that a value is one of a set of types.
* Create a struct with lazily evaluated validation.
*
* The first time validation is run with the struct, the callback will be called
* and must return a struct object to use. This is useful for cases where you
* want to have self-referential structs for nested data structures to avoid a
* circular definition problem.
*/
declare function union<A>(Structs: StructTuple<[A]>): Struct<A>;
declare function union<A, B>(Structs: StructTuple<[A, B]>): Struct<A | B>;
declare function union<A, B, C>(Structs: StructTuple<[A, B, C]>): Struct<A | B | C>;
declare function union<A, B, C, D>(Structs: StructTuple<[A, B, C, D]>): Struct<A | B | C | D>;
declare function union<A, B, C, D, E>(Structs: StructTuple<[A, B, C, D, E]>): Struct<A | B | C | D | E>;
declare function union<A, B, C, D, E, F>(Structs: StructTuple<[A, B, C, D, E, F]>): Struct<A | B | C | D | E | F>;
declare function union<A, B, C, D, E, F, G>(Structs: StructTuple<[A, B, C, D, E, F, G]>): Struct<A | B | C | D | E | F | G>;
declare function union<A, B, C, D, E, F, G, H>(Structs: StructTuple<[A, B, C, D, E, F, G, H]>): Struct<A | B | C | D | E | F | G | H>;
declare function union<A, B, C, D, E, F, G, H, I>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I]>): Struct<A | B | C | D | E | F | G | H | I>;
declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J]>): Struct<A | B | C | D | E | F | G | H | I | J>;
declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A | B | C | D | E | F | G | H | I | J | K>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q>;
export { coercion, defaulted, masked, empty, length, pattern, refinement, Struct, StructError, StructContext, StructFailure, StructResult, StructType, assert, coerce, is, validate, any, array, boolean, date, dynamic, enums, func, instance, intersection, lazy, literal, map, never, nullable, number, object, optional, partial, record, set, string, struct, tuple, type, union };
declare function lazy<T>(fn: () => Struct<T, any>): Struct<T, null>;
/**
* Create a new struct based on an existing object struct, but excluding
* specific properties.
*
* Like TypeScript's `Omit` utility.
*/
declare function omit<S extends ObjectSchema, K extends keyof S>(struct: Struct<ObjectType<S>, S>, keys: K[]): Struct<ObjectType<Omit<S, K>>, Omit<S, K>>;
/**
* Create a new struct based on an existing object struct, but with all of its
* properties allowed to be `undefined`.
*
* Like TypeScript's `Partial` utility.
*/
declare function partial<S extends ObjectSchema>(struct: Struct<ObjectType<S>, S> | S): Struct<ObjectType<PartialObjectSchema<S>>, PartialObjectSchema<S>>;
/**
* Create a new struct based on an existing object struct, but only including
* specific properties.
*
* Like TypeScript's `Pick` utility.
*/
declare function pick<S extends ObjectSchema, K extends keyof S>(struct: Struct<ObjectType<S>, S>, keys: K[]): Struct<ObjectType<Pick<S, K>>, Pick<S, K>>;
export { Failure, StructError, Struct, Context, Infer, Result, Coercer, Validator, Refiner, assert, create, mask, is, validate, coerce, defaulted, masked, empty, max, min, pattern, size, refine, any, array, boolean, date, enums, func, instance, integer, intersection, literal, map, never, nullable, number, object, optional, record, regexp, set, string, tuple, type, union, unknown, assign, define, dynamic, lazy, omit, partial, pick };

@@ -87,12 +87,69 @@ function _defineProperty(obj, key, value) {

/**
* Convert a validation result to an iterable of failures.
* A `StructFailure` represents a single specific failure in validation.
*/
function* toFailures(result, context) {
if (result === true) ; else if (result === false) {
yield context.fail();
} else {
yield* result;
/**
* `StructError` objects are thrown (or returned) when validation fails.
*
* Validation logic is design to exit early for maximum performance. The error
* represents the first error encountered during validation. For more detail,
* the `error.failures` property is a generator function that can be run to
* continue validation and receive all the failures in the data.
*/
class StructError extends TypeError {
constructor(failure, moreFailures) {
const {
path,
value,
key,
type,
message,
refinement,
branch
} = failure,
rest = _objectWithoutProperties(failure, ["path", "value", "key", "type", "message", "refinement", "branch"]);
let failures;
const msg = path.length === 0 ? message : `At path: ${path.join('.')} -- ${message}`;
super(msg);
Object.assign(this, rest);
this.name = this.constructor.name;
this.value = value;
this.key = key;
this.type = type;
this.refinement = refinement;
this.path = path;
this.branch = branch;
this.failures = () => {
if (!failures) {
failures = [failure, ...moreFailures];
}
return failures;
};
}
}
/**
* Check if a value is a plain object.
*/
function isPlainObject(value) {
if (Object.prototype.toString.call(value) !== '[object Object]') {
return false;
}
const prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.prototype;
}
/**
* Return a value as a printable string.
*/
function print(value, ticks) {
const string = typeof value === 'string' ? JSON.stringify(value) : `${value}`;
return ticks ? `${ticks}${string}${ticks}` : string;
}
/**
* Shifts (removes and returns) the first value from the `input` iterator.

@@ -102,3 +159,3 @@ * Like `Array.prototype.shift()` but for an `Iterator`.

function iteratorShift(input) {
function shiftIterator(input) {
const {

@@ -110,9 +167,108 @@ done,

}
/**
* Convert a validation result to an iterable of failures.
*/
function* toFailures(result, context) {
if (typeof result === 'string') {
yield context.fail({
message: result
});
} else if (result === true) {
return;
} else if (result === false) {
yield context.fail();
} else {
yield* result;
}
}
/**
* `Struct` objects encapsulate the schema for a specific data type (with
* optional coercion). You can then use the `assert`, `is` or `validate` helpers
* to validate unknown data against a struct.
* Augment a `Struct` to add an additional coercion step to its input.
*
* This allows you to transform input data before validating it, to increase the
* likelihood that it passes validation—for example for default values, parsing
* different formats, etc.
*
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
function coerce(struct, coercer) {
const fn = struct.coercer;
return new Struct(_objectSpread2(_objectSpread2({}, struct), {}, {
coercer: value => {
return fn(coercer(value));
}
}));
}
/**
* Augment a struct to replace `undefined` values with a default.
*
* Note: You must use `coerce(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
function defaulted(S, fallback, options = {}) {
const {
strict
} = options;
return coerce(S, x => {
const f = typeof fallback === 'function' ? fallback() : fallback;
if (x === undefined) {
return f;
}
if (!strict && isPlainObject(x) && isPlainObject(f)) {
const ret = _objectSpread2({}, x);
let changed = false;
for (const key in f) {
if (ret[key] === undefined) {
ret[key] = f[key];
changed = true;
}
}
if (changed) {
return ret;
}
}
return x;
});
}
/**
* Augment a struct to mask its input to only properties defined in the struct.
*
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
function masked(struct) {
return coerce(struct, x => {
if (typeof struct.schema !== 'object' || struct.schema == null || typeof x !== 'object' || x == null) {
return x;
} else {
const ret = {};
for (const key in struct.schema) {
if (key in x) {
ret[key] = x[key];
}
}
return ret;
}
});
}
/**
* `Struct` objects encapsulate the validation logic for a specific type of
* values. Once constructed, you use the `assert`, `is` or `validate` helpers to
* validate unknown input data against the struct.
*/
class Struct {

@@ -133,43 +289,49 @@ constructor(props) {

}
/**
* Assert that a value passes the struct's validation, throwing if it doesn't.
*/
}
/**
* `StructError` objects are thrown (or returned) by Superstruct when its
* validation fails. The error represents the first error encountered during
* validation. But they also have an `error.failures` property that holds
* information for all of the failures encountered.
*/
class StructError extends TypeError {
constructor(failure, moreFailures) {
const {
path,
value,
type,
branch
} = failure,
rest = _objectWithoutProperties(failure, ["path", "value", "type", "branch"]);
assert(value) {
return assert(value, this);
}
/**
* Create a value with the struct's coercion logic, then validate it.
*/
const message = `Expected a value of type \`${type}\`${path.length ? ` for \`${path.join('.')}\`` : ''} but received \`${JSON.stringify(value)}\`.`;
let failuresResult;
function failures() {
if (!failuresResult) {
failuresResult = [failure, ...moreFailures];
}
create(value) {
return create(value, this);
}
/**
* Check if a value passes the struct's validation.
*/
return failuresResult;
}
super(message);
this.value = value;
Object.assign(this, rest);
this.type = type;
this.path = path;
this.branch = branch;
this.failures = failures;
this.stack = new Error().stack;
this.__proto__ = StructError.prototype;
is(value) {
return is(value, this);
}
/**
* Mask a value, coercing and validating it, but returning only the subset of
* properties defined by the struct's schema.
*/
mask(value) {
return mask(value, this);
}
/**
* Validate a value with the struct's validation logic, returning a tuple
* representing the result.
*
* You may optionally pass `true` for the `withCoercion` argument to coerce
* the value before attempting to validate it. If you do, the result will
* contain the coerced result when successful.
*/
validate(value, options = {}) {
return validate(value, this, options);
}
}

@@ -188,6 +350,6 @@ /**

/**
* Coerce a value with the coercion logic of `Struct` and validate it.
* Create a value with the coercion logic of `Struct` and validate it.
*/
function coerce(value, struct) {
function create(value, struct) {
const ret = struct.coercer(value);

@@ -198,2 +360,11 @@ assert(ret, struct);

/**
* Mask a value, returning only the subset of properties defined by a Struct.
*/
function mask(value, struct) {
const M = masked(struct);
const ret = create(value, M);
return ret;
}
/**
* Check if a value passes a `Struct`.

@@ -210,4 +381,4 @@ */

function validate(value, struct, coercing = false) {
if (coercing) {
function validate(value, struct, options = {}) {
if (options.coerce) {
value = struct.coercer(value);

@@ -217,3 +388,3 @@ }

const failures = check(value, struct);
const failure = iteratorShift(failures);
const failure = shiftIterator(failures);

@@ -232,24 +403,42 @@ if (failure) {

function* check(value, struct, path = [], branch = []) {
const {
type
} = struct;
const ctx = {
value,
type,
struct,
branch,
path,
check(v, s, parent, key) {
const p = parent !== undefined ? [...path, key] : path;
const b = parent !== undefined ? [...branch, parent] : branch;
return check(v, s, p, b);
},
fail(props = {}) {
return _objectSpread2({
if (typeof props === 'string') {
props = {
message: props
};
}
const {
type
} = struct;
let {
message,
refinement
} = props;
if (!message) {
message = `Expected a value of type \`${type}\`${refinement ? ` with refinement \`${refinement}\`` : ''}${path.length ? ` for \`${path.join('.')}\`` : ''}, but received: \`${print(value)}\``;
}
return _objectSpread2(_objectSpread2({}, props), {}, {
value,
type,
refinement,
message,
key: path[path.length - 1],
path,
branch: [...branch, value]
}, props);
},
check(v, s, parent, key) {
const p = parent !== undefined ? [...path, key] : path;
const b = parent !== undefined ? [...branch, parent] : branch;
return check(v, s, p, b);
});
}

@@ -259,3 +448,3 @@

const failures = toFailures(struct.validator(value, ctx), ctx);
const failure = iteratorShift(failures);
const failure = shiftIterator(failures);

@@ -271,138 +460,218 @@ if (failure) {

/**
* Augment a `Struct` to add an additional coercion step to its input.
* Ensure that a string, array, map, or set is empty.
*/
function coercion(struct, coercer) {
const fn = struct.coercer;
return new Struct(_objectSpread2(_objectSpread2({}, struct), {}, {
coercer: value => {
return fn(coercer(value));
function empty(struct) {
const expected = `Expected an empty ${struct.type}`;
return refine(struct, 'empty', value => {
if (value instanceof Map || value instanceof Set) {
const {
size
} = value;
return size === 0 || `${expected} but received one with a size of \`${size}\``;
} else {
const {
length
} = value;
return length === 0 || `${expected} but received one with a length of \`${length}\``;
}
}));
});
}
/**
* Augment a struct to coerce a default value for missing values.
*
* Note: You must use `coerce(value, Struct)` on the value before validating it
* to have the value defaulted!
* Ensure that a number or date is below a threshold.
*/
function defaulted(S, fallback, strict) {
return coercion(S, x => {
const f = typeof fallback === 'function' ? fallback() : fallback;
function max(struct, threshold, options = {}) {
const {
exclusive
} = options;
return refine(struct, 'max', value => {
return exclusive ? value < threshold : value <= threshold || `Expected a ${struct.type} greater than ${exclusive ? '' : 'or equal to '}${threshold} but received \`${value}\``;
});
}
/**
* Ensure that a number or date is above a threshold.
*/
if (x === undefined) {
return f;
}
function min(struct, threshold, options = {}) {
const {
exclusive
} = options;
return refine(struct, 'min', value => {
return exclusive ? value > threshold : value >= threshold || `Expected a ${struct.type} greater than ${exclusive ? '' : 'or equal to '}${threshold} but received \`${value}\``;
});
}
/**
* Ensure that a string matches a regular expression.
*/
if (strict !== true && isPlainObject(x) && isPlainObject(f)) {
const ret = _objectSpread2({}, x);
function pattern(struct, regexp) {
return refine(struct, 'pattern', value => {
return regexp.test(value) || `Expected a ${struct.type} matching \`/${regexp.source}/\` but received "${value}"`;
});
}
/**
* Ensure that a string, array, number, date, map, or set has a size (or length, or time) between `min` and `max`.
*/
let changed = false;
for (const key in f) {
if (ret[key] === undefined) {
ret[key] = f[key];
changed = true;
}
}
if (changed) {
return ret;
}
function size(struct, min, max = min) {
const expected = `Expected a ${struct.type}`;
const of = min === max ? `of \`${min}\`` : `between \`${min}\` and \`${max}\``;
return refine(struct, 'size', value => {
if (typeof value === 'number' || value instanceof Date) {
return min <= value && value <= max || `${expected} ${of} but received \`${value}\``;
} else if (value instanceof Map || value instanceof Set) {
const {
size
} = value;
return min <= size && size <= max || `${expected} with a size ${of} but received one with a size of \`${size}\``;
} else {
const {
length
} = value;
return min <= length && length <= max || `${expected} with a length ${of} but received one with a length of \`${length}\``;
}
return x;
});
}
/**
* Coerce a value to mask its properties to only that defined in the struct.
* Augment a `Struct` to add an additional refinement to the validation.
*
* The refiner function is guaranteed to receive a value of the struct's type,
* because the struct's existing validation will already have passed. This
* allows you to layer additional validation on top of existing structs.
*/
function masked(S) {
return coercion(S, x => {
if (!isPlainObject(x)) {
return x;
function refine(struct, name, refiner) {
const fn = struct.refiner;
return new Struct(_objectSpread2(_objectSpread2({}, struct), {}, {
*refiner(value, ctx) {
yield* toFailures(fn(value, ctx), ctx);
for (const failure of toFailures(refiner(value, ctx), ctx)) {
yield _objectSpread2(_objectSpread2({}, failure), {}, {
refinement: name
});
}
}
const ret = {};
}));
}
for (const key in S.schema) {
ret[key] = x[key];
}
function assign(...Structs) {
const schemas = Structs.map(s => s.schema);
const schema = Object.assign({}, ...schemas);
return object(schema);
}
/**
* Define a new struct with a custom validation function.
*/
return ret;
function define(name, validator) {
return new Struct({
type: name,
schema: null,
validator
});
}
/**
* Check if a value is a plain object.
* Create a struct with dynamic, runtime validation.
*
* The callback will receive the value currently being validated, and must
* return a struct object to validate it with. This can be useful to model
* validation logic that changes based on its input.
*/
function isPlainObject(value) {
if (Object.prototype.toString.call(value) !== '[object Object]') {
return false;
}
const prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.prototype;
function dynamic(fn) {
return define('dynamic', (value, ctx) => {
return ctx.check(value, fn(value, ctx));
});
}
/**
* Augment a string or array struct to constrain its length to zero.
* Create a struct with lazily evaluated validation.
*
* The first time validation is run with the struct, the callback will be called
* and must return a struct object to use. This is useful for cases where you
* want to have self-referential structs for nested data structures to avoid a
* circular definition problem.
*/
function empty(S) {
return refinement(S, `${S.type} & Empty`, value => {
return value.length === 0;
function lazy(fn) {
let s;
return define('lazy', (value, ctx) => {
if (!s) {
s = fn();
}
return ctx.check(value, s);
});
}
/**
* Augment a string or array struct to constrain its length to being between a
* minimum and maximum size.
* Create a new struct based on an existing object struct, but excluding
* specific properties.
*
* Like TypeScript's `Omit` utility.
*/
function length(S, min, max) {
return refinement(S, `${S.type} & Length<${min},${max}>`, value => {
return min < value.length && value.length < max;
});
function omit(struct, keys) {
const {
schema
} = struct;
const subschema = _objectSpread2({}, schema);
for (const key of keys) {
delete subschema[key];
}
return object(subschema);
}
/**
* Refine a string struct to match a specific regexp pattern.
* Create a new struct based on an existing object struct, but with all of its
* properties allowed to be `undefined`.
*
* Like TypeScript's `Partial` utility.
*/
function pattern(S, regexp) {
return refinement(S, `${S.type} & Pattern<${regexp.source}>`, value => {
return regexp.test(value);
});
function partial(struct) {
const schema = struct instanceof Struct ? _objectSpread2({}, struct.schema) : _objectSpread2({}, struct);
for (const key in schema) {
schema[key] = optional(schema[key]);
}
return object(schema);
}
/**
* Augment a `Struct` to add an additional refinement to the validation.
* Create a new struct based on an existing object struct, but only including
* specific properties.
*
* Like TypeScript's `Pick` utility.
*/
function refinement(struct, type, refiner) {
const fn = struct.refiner;
return new Struct(_objectSpread2(_objectSpread2({}, struct), {}, {
type,
function pick(struct, keys) {
const {
schema
} = struct;
const subschema = {};
*refiner(value, fail) {
yield* toFailures(fn(value, fail), fail);
yield* toFailures(refiner(value, fail), fail);
}
for (const key of keys) {
subschema[key] = schema[key];
}
}));
return object(subschema);
}
/**
* Validate any value.
* Ensure that any value passes validation.
*/
function any() {
return struct('any', () => true);
return define('any', () => true);
}
function array(Element) {
return new Struct({
type: `Array<${Element ? Element.type : 'unknown'}>`,
type: 'array',
schema: Element,
coercer: value => {
return Element && Array.isArray(value) ? value.map(v => coerce(v, Element)) : value;
return Element && Array.isArray(value) ? value.map(v => Element.coercer(v)) : value;
},

@@ -412,7 +681,4 @@

if (!Array.isArray(value)) {
yield ctx.fail();
return;
}
if (Element) {
yield ctx.fail(`Expected an array value, but received: ${print(value)}`);
} else if (Element) {
for (const [i, v] of value.entries()) {

@@ -427,7 +693,7 @@ yield* ctx.check(v, Element, value, i);

/**
* Validate that boolean values.
* Ensure that a value is a boolean.
*/
function boolean() {
return struct('boolean', value => {
return define('boolean', value => {
return typeof value === 'boolean';

@@ -437,3 +703,3 @@ });

/**
* Validate that `Date` values.
* Ensure that a value is a valid `Date`.
*

@@ -445,40 +711,51 @@ * Note: this also ensures that the value is *not* an invalid `Date` object,

function date() {
return struct('Date', value => {
return value instanceof Date && !isNaN(value.getTime());
return define('date', value => {
return value instanceof Date && !isNaN(value.getTime()) || `Expected a valid \`Date\` object, but received: ${print(value)}`;
});
}
/**
* Validate that a value dynamically, determing which struct to use at runtime.
*/
function enums(values) {
const schema = {};
const description = values.map(v => print(v)).join();
function dynamic(fn) {
return struct('Dynamic<...>', (value, ctx) => {
return ctx.check(value, fn(value, ctx));
for (const key of values) {
schema[key] = key;
}
return new Struct({
type: 'enums',
schema,
validator: value => {
return values.includes(value) || `Expected one of \`${description}\`, but received: ${print(value)}`;
}
});
}
function enums(values) {
return struct(`Enum<${values.map(toLiteralString)}>`, value => {
return values.includes(value);
});
}
/**
* Validate that a value is a function.
* Ensure that a value is a function.
*/
function func() {
return struct('Function', value => {
return typeof value === 'function';
return define('func', value => {
return typeof value === 'function' || `Expected a function, but received: ${print(value)}`;
});
}
/**
* Validate that a value is an instance of a class.
* Ensure that a value is an instance of a specific class.
*/
function instance(Class) {
return struct(`InstanceOf<${Class.name}>`, value => {
return value instanceof Class;
return define('instance', value => {
return value instanceof Class || `Expected a \`${Class.name}\` instance, but received: ${print(value)}`;
});
}
/**
* Ensure that a value is an integer.
*/
function integer() {
return define('integer', value => {
return typeof value === 'number' && !isNaN(value) && Number.isInteger(value) || `Expected an integer, but received: ${print(value)}`;
});
}
function intersection(Structs) {
return struct(Structs.map(s => s.type).join(' & '), function* (value, ctx) {
return define('intersection', function* (value, ctx) {
for (const S of Structs) {

@@ -489,84 +766,70 @@ yield* ctx.check(value, S);

}
/**
* Validate a value lazily, by constructing the struct right before the first
* validation. This is useful for cases where you want to have self-referential
* structs for nested data structures.
*/
function lazy(fn) {
let S;
return struct('Lazy<...>', (value, ctx) => {
if (!S) {
S = fn();
}
return ctx.check(value, S);
});
}
function literal(constant) {
return struct(`Literal<${toLiteralString(constant)}>`, value => {
return value === constant;
const description = print(constant);
return define('literal', value => {
return value === constant || `Expected the literal \`${description}\`, but received: ${print(value)}`;
});
}
/**
* Validate that a value is a map with specific key and value entries.
*/
function map(Key, Value) {
return struct(`Map<${Key.type},${Value.type}>`, function* (value, ctx) {
return define('map', function* (value, ctx) {
if (!(value instanceof Map)) {
yield ctx.fail();
return;
yield ctx.fail(`Expected a \`Map\` object, but received: ${print(value)}`);
} else if (Key && Value) {
for (const [k, v] of value.entries()) {
yield* ctx.check(k, Key, value, k);
yield* ctx.check(v, Value, value, k);
}
}
for (const [k, v] of value.entries()) {
yield* ctx.check(k, Key, value, k);
yield* ctx.check(v, Value, value, k);
}
});
}
/**
* Validate that a value always fails.
* Ensure that no value ever passes validation.
*/
function never() {
return struct('never', () => false);
return define('never', () => false);
}
/**
* Augment a struct to make it accept `null` values.
* Augment an existing struct to allow `null` values.
*/
function nullable(S) {
return new Struct({
type: `${S.type} | null`,
schema: S.schema,
function nullable(struct) {
const {
refiner
} = struct;
return new Struct(_objectSpread2(_objectSpread2({}, struct), {}, {
validator: (value, ctx) => {
return value === null || ctx.check(value, S);
return value === null || ctx.check(value, struct);
},
refiner: function* (value, ctx) {
if (value != null) {
const c = _objectSpread2(_objectSpread2({}, ctx), {}, {
struct
});
yield* toFailures(refiner(value, c), c);
}
}
});
}));
}
/**
* Validate that a value is a number.
* Ensure that a value is a number.
*/
function number() {
return struct(`number`, value => {
return typeof value === 'number' && !isNaN(value);
return define('number', value => {
return typeof value === 'number' && !isNaN(value) || `Expected a number, but received: ${print(value)}`;
});
}
function object(Structs) {
const knowns = Structs ? Object.keys(Structs) : [];
function object(schema) {
const knowns = schema ? Object.keys(schema) : [];
const Never = never();
return new Struct({
type: Structs ? `Object<{${knowns.join(',')}}>` : 'Object',
schema: Structs ? Structs : null,
coercer: Structs ? createObjectCoercer(Structs) : x => x,
type: 'object',
schema: schema ? schema : null,
*validator(value, ctx) {
if (typeof value !== 'object' || value == null) {
yield ctx.fail();
return;
}
if (Structs) {
yield ctx.fail(`Expected an object, but received: ${print(value)}`);
} else if (schema) {
const unknowns = new Set(Object.keys(value));

@@ -576,3 +839,3 @@

unknowns.delete(key);
const Value = Structs[key];
const Value = schema[key];
const v = value[key];

@@ -587,41 +850,10 @@ yield* ctx.check(v, Value, value, key);

}
}
},
});
}
/**
* Augment a struct to make it optionally accept `undefined` values.
*/
function optional(S) {
return new Struct({
type: `${S.type}?`,
schema: S.schema,
validator: (value, ctx) => {
return value === undefined || ctx.check(value, S);
}
});
}
/**
* Validate that a partial object with specific entry values.
*/
function partial(Structs) {
if (Structs instanceof Struct) {
Structs = Structs.schema;
}
const knowns = Object.keys(Structs);
const Never = never();
return new Struct({
type: `Partial<{${knowns.join(',')}}>`,
schema: Structs,
coercer: createObjectCoercer(Structs),
*validator(value, ctx) {
if (typeof value !== 'object' || value == null) {
yield ctx.fail();
return;
coercer: value => {
if (!schema || typeof value !== 'object' || value == null) {
return value;
}
const ret = {};
const unknowns = new Set(Object.keys(value));

@@ -631,171 +863,162 @@

unknowns.delete(key);
if (!(key in value)) {
continue;
}
const Value = Structs[key];
const Value = schema[key];
const v = value[key];
yield* ctx.check(v, Value, value, key);
ret[key] = Value.coercer(v);
}
for (const key of unknowns) {
const v = value[key];
yield* ctx.check(v, Never, value, key);
ret[key] = value[key];
}
return ret;
}
});
}
/**
* Validate that a value is a record with specific key and
* value entries.
* Augment a struct to allow `undefined` values.
*/
function optional(struct) {
const {
refiner
} = struct;
return new Struct(_objectSpread2(_objectSpread2({}, struct), {}, {
validator: (value, ctx) => {
return value === undefined || ctx.check(value, struct);
},
refiner: function* (value, ctx) {
if (value != null) {
const c = _objectSpread2(_objectSpread2({}, ctx), {}, {
struct
});
yield* toFailures(refiner(value, c), c);
}
}
}));
}
/**
* Ensure that a value is an object with keys and values of specific types, but
* without ensuring any specific shape of properties.
*
* Like TypeScript's `Record` utility.
*/
function record(Key, Value) {
return struct(`Record<${Key.type},${Value.type}>`, function* (value, ctx) {
return define('record', function* (value, ctx) {
if (typeof value !== 'object' || value == null) {
yield ctx.fail();
return;
yield ctx.fail(`Expected an object, but received: ${print(value)}`);
} else {
for (const k in value) {
const v = value[k];
yield* ctx.check(k, Key, value, k);
yield* ctx.check(v, Value, value, k);
}
}
for (const k in value) {
const v = value[k];
yield* ctx.check(k, Key, value, k);
yield* ctx.check(v, Value, value, k);
}
});
}
/**
* Validate that a set of values matches a specific type.
* Ensure that a value is a `RegExp`.
*
* Note: this does not test the value against the regular expression! For that
* you need to use the `pattern()` refinement.
*/
function regexp() {
return define('regexp', value => {
return value instanceof RegExp;
});
}
function set(Element) {
return struct(`Set<${Element.type}>`, (value, ctx) => {
return define('set', function* (value, ctx) {
if (!(value instanceof Set)) {
return false;
}
for (const val of value) {
const [failure] = ctx.check(val, Element);
if (failure) {
return false;
yield ctx.fail(`Expected a \`Set\` object, but received: ${print(value)}`);
} else if (Element) {
for (const val of value) {
yield* ctx.check(val, Element, value, val);
}
}
return true;
});
}
/**
* Validate that a value is a string.
* Ensure that a value is a string.
*/
function string() {
return struct('string', value => {
return typeof value === 'string';
return define('string', value => {
return typeof value === 'string' || `Expected a string, but received: ${print(value)}`;
});
}
/**
* Define a `Struct` instance with a type and validation function.
*/
function struct(name, validator) {
return new Struct({
type: name,
validator,
schema: null
});
}
function tuple(Elements) {
const Never = never();
return struct(`[${Elements.map(s => s.type).join(',')}]`, function* (value, ctx) {
return define('tuple', function* (value, ctx) {
if (!Array.isArray(value)) {
yield ctx.fail();
return;
}
yield ctx.fail(`Expected an array, but received: ${print(value)}`);
} else {
for (const [index, Element] of Elements.entries()) {
const v = value[index];
yield* ctx.check(v, Element, value, index);
}
for (const [index, Element] of Elements.entries()) {
const v = value[index];
yield* ctx.check(v, Element, value, index);
if (value.length > Elements.length) {
const index = Elements.length;
const v = value[index];
yield* ctx.check(v, Never, value, index);
}
}
if (value.length > Elements.length) {
const index = Elements.length;
const v = value[index];
yield* ctx.check(v, Never, value, index);
}
});
}
/**
* Validate that a value matches a specific strutural interface, like the
* structural typing that TypeScript uses.
* Ensure that a value has a set of known properties of specific types.
*
* Note: Unrecognized properties are allowed and untouched. This is similar to
* how TypeScript's structural typing works.
*/
function type(Structs) {
const keys = Object.keys(Structs);
return struct(`Type<{${keys.join(',')}}>`, function* (value, ctx) {
if (typeof value !== 'object' || value == null) {
yield ctx.fail();
return;
function type(schema) {
const keys = Object.keys(schema);
return new Struct({
type: 'type',
schema,
validator: function* (value, ctx) {
if (typeof value !== 'object' || value == null) {
yield ctx.fail(`Expected an object, but received: ${print(value)}`);
} else {
for (const key of keys) {
const Value = schema[key];
const v = value[key];
yield* ctx.check(v, Value, value, key);
}
}
}
for (const key of keys) {
const Value = Structs[key];
const v = value[key];
yield* ctx.check(v, Value, value, key);
}
});
}
function union(Structs) {
return struct(`${Structs.map(s => s.type).join(' | ')}`, function* (value, ctx) {
const description = Structs.map(s => s.type).join(' | ');
return define('union', function* (value, ctx) {
const failures = [];
for (const S of Structs) {
const [...failures] = ctx.check(value, S);
const [...array] = ctx.check(value, S);
if (failures.length === 0) {
if (array.length === 0) {
return;
} else {
failures.push(...array);
}
}
yield ctx.fail();
yield ctx.fail(`Expected the value to satisfy a union of \`${description}\`, but received: ${print(value)}`);
yield* failures;
});
}
/**
* Convert a value to a literal string.
* Ensure that any value passes validation, without widening its type to `any`.
*/
function toLiteralString(value) {
return typeof value === 'string' ? `"${value.replace(/"/g, '"')}"` : `${value}`;
function unknown() {
return define('unknown', () => true);
}
/**
* Coerce the values of an object-like struct.
*/
function createObjectCoercer(Structs) {
const knowns = Object.keys(Structs);
return value => {
if (typeof value !== 'object' || value == null) {
return value;
}
const ret = {};
const unknowns = new Set(Object.keys(value));
for (const key of knowns) {
unknowns.delete(key);
const Value = Structs[key];
const v = value[key];
ret[key] = coerce(v, Value);
}
for (const key of unknowns) {
ret[key] = value[key];
}
return ret;
};
}
export { Struct, StructError, any, array, assert, boolean, coerce, coercion, date, defaulted, dynamic, empty, enums, func, instance, intersection, is, lazy, length, literal, map, masked, never, nullable, number, object, optional, partial, pattern, record, refinement, set, string, struct, tuple, type, union, validate };
export { Struct, StructError, any, array, assert, assign, boolean, coerce, create, date, defaulted, define, dynamic, empty, enums, func, instance, integer, intersection, is, lazy, literal, map, mask, masked, max, min, never, nullable, number, object, omit, optional, partial, pattern, pick, record, refine, regexp, set, size, string, tuple, type, union, unknown, validate };
//# sourceMappingURL=index.es.js.map

@@ -0,81 +1,105 @@

import { StructError, Failure } from './error';
/**
* `Struct` objects encapsulate the schema for a specific data type (with
* optional coercion). You can then use the `assert`, `is` or `validate` helpers
* to validate unknown data against a struct.
* `Struct` objects encapsulate the validation logic for a specific type of
* values. Once constructed, you use the `assert`, `is` or `validate` helpers to
* validate unknown input data against the struct.
*/
export declare class Struct<T, S = any> {
export declare class Struct<T = unknown, S = unknown> {
readonly TYPE: T;
type: string;
schema: S;
coercer: (value: unknown) => unknown;
validator: (value: unknown, context: StructContext) => StructResult;
refiner: (value: T, context: StructContext) => StructResult;
coercer: Coercer;
validator: Validator<T, S>;
refiner: Refiner<T, S>;
constructor(props: {
type: Struct<T>['type'];
schema: S;
coercer?: Struct<T>['coercer'];
validator?: Struct<T>['validator'];
refiner?: Struct<T>['refiner'];
type: Struct<T, S>['type'];
schema: Struct<T, S>['schema'];
coercer?: Struct<T, S>['coercer'];
validator?: Struct<T, S>['validator'];
refiner?: Struct<T, S>['refiner'];
});
/**
* Assert that a value passes the struct's validation, throwing if it doesn't.
*/
assert(value: unknown): asserts value is T;
/**
* Create a value with the struct's coercion logic, then validate it.
*/
create(value: unknown): T;
/**
* Check if a value passes the struct's validation.
*/
is(value: unknown): value is T;
/**
* Mask a value, coercing and validating it, but returning only the subset of
* properties defined by the struct's schema.
*/
mask(value: unknown): T;
/**
* Validate a value with the struct's validation logic, returning a tuple
* representing the result.
*
* You may optionally pass `true` for the `withCoercion` argument to coerce
* the value before attempting to validate it. If you do, the result will
* contain the coerced result when successful.
*/
validate(value: unknown, options?: {
coerce?: boolean;
}): [StructError, undefined] | [undefined, T];
}
/**
* `StructError` objects are thrown (or returned) by Superstruct when its
* validation fails. The error represents the first error encountered during
* validation. But they also have an `error.failures` property that holds
* information for all of the failures encountered.
*/
export declare class StructError extends TypeError {
value: any;
type: string;
path: Array<number | string>;
branch: Array<any>;
failures: () => Array<StructFailure>;
[key: string]: any;
constructor(failure: StructFailure, moreFailures: IterableIterator<StructFailure>);
}
/**
* A `StructContext` contains information about the current value being
* validated as well as helper functions for failures and recursive validating.
*/
export declare type StructContext = {
export declare type Context<T, S> = {
value: any;
type: string;
struct: Struct<T, S>;
branch: Array<any>;
path: Array<string | number>;
fail: (props?: Partial<StructFailure>) => StructFailure;
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => IterableIterator<StructFailure>;
fail: (props?: string | Partial<Failure>) => Failure;
check: <Y, Z>(value: any, struct: Struct<Y, Z>, parent?: any, key?: string | number) => IterableIterator<Failure>;
};
/**
* A `StructFailure` represents a single specific failure in validation.
* A type utility to extract the type from a `Struct` class.
*/
export declare type StructFailure = {
value: StructContext['value'];
type: StructContext['type'];
branch: StructContext['branch'];
path: StructContext['path'];
[key: string]: any;
};
export declare type Infer<T extends Struct<any, any>> = T['TYPE'];
/**
* A `StructResult` is returned from validation functions.
* A `Result` is returned from validation functions.
*/
export declare type StructResult = boolean | Iterable<StructFailure>;
export declare type Result = boolean | string | Iterable<Failure>;
/**
* A type utility to extract the type from a `Struct` class.
* A `Coercer` takes an unknown value and optionally coerces it.
*/
export declare type StructType<T extends Struct<any>> = Parameters<T['refiner']>[0];
export declare type Coercer = (value: unknown) => unknown;
/**
* A `Validate` takes an unknown value and validates it.
*/
export declare type Validator<T, S> = (value: unknown, context: Context<T, S>) => Result;
/**
* A `Refiner` takes a value of a known type and validates it against a further
* constraint.
*/
export declare type Refiner<T, S> = (value: T, context: Context<T, S>) => Result;
/**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
export declare function assert<T>(value: unknown, struct: Struct<T>): asserts value is T;
export declare function assert<T, S>(value: unknown, struct: Struct<T, S>): asserts value is T;
/**
* Coerce a value with the coercion logic of `Struct` and validate it.
* Create a value with the coercion logic of `Struct` and validate it.
*/
export declare function coerce<T>(value: unknown, struct: Struct<T>): T;
export declare function create<T, S>(value: unknown, struct: Struct<T, S>): T;
/**
* Mask a value, returning only the subset of properties defined by a Struct.
*/
export declare function mask<T, S>(value: unknown, struct: Struct<T, S>): T;
/**
* Check if a value passes a `Struct`.
*/
export declare function is<T>(value: unknown, struct: Struct<T>): value is T;
export declare function is<T, S>(value: unknown, struct: Struct<T, S>): value is T;
/**
* Validate a value against a `Struct`, returning an error if invalid.
*/
export declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T];
export declare function validate<T, S>(value: unknown, struct: Struct<T, S>, options?: {
coerce?: boolean;
}): [StructError, undefined] | [undefined, T];
//# sourceMappingURL=struct.d.ts.map
import { Struct } from '../struct';
import { ObjectSchema, ObjectType } from '../utils';
/**

@@ -10,6 +9,6 @@ * Augment a `Struct` to add an additional coercion step to its input.

*
* Note: You must use `coerce(value, Struct)` on the value to have the coercion
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
export declare function coercion<T, S>(struct: Struct<T, S>, coercer: Struct<T, S>['coercer']): Struct<T, S>;
export declare function coerce<T, S>(struct: Struct<T, S>, coercer: Struct<T, S>['coercer']): Struct<T, S>;
/**

@@ -21,10 +20,12 @@ * Augment a struct to replace `undefined` values with a default.

*/
export declare function defaulted<T, S>(S: Struct<T, S>, fallback: any, strict?: true): Struct<T, S>;
export declare function defaulted<T, S>(S: Struct<T, S>, fallback: any, options?: {
strict?: boolean;
}): Struct<T, S>;
/**
* Augment a struct to mask its input to only properties defined in the struct.
*
* Note: You must use `coerce(value, Struct)` on the value to have the coercion
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
export declare function masked<S extends ObjectSchema>(struct: Struct<ObjectType<S>, S>): Struct<ObjectType<S>, S>;
export declare function masked<T, S>(struct: Struct<T, S>): Struct<T, S>;
//# sourceMappingURL=coercions.d.ts.map
import { Struct, Refiner } from '../struct';
/**
* Ensure that a string or array has a length of zero.
* Ensure that a string, array, map, or set is empty.
*/
export declare function empty<T extends string | any[]>(struct: Struct<T>): Struct<T>;
export declare function empty<T extends string | any[] | Map<any, any> | Set<any>>(struct: Struct<T>): Struct<T>;
/**
* Ensure that a string or array has a length between `min` and `max`.
* Ensure that a number or date is below a threshold.
*/
export declare function length<T extends string | any[]>(struct: Struct<T>, min: number, max: number): Struct<T>;
export declare function max<T extends number | Date>(struct: Struct<T>, threshold: T, options?: {
exclusive?: boolean;
}): Struct<T>;
/**
* Ensure that a number is negative (not zero).
* Ensure that a number or date is above a threshold.
*/
export declare function negative<T extends number>(struct: Struct<T>): Struct<T>;
export declare function min<T extends number | Date>(struct: Struct<T>, threshold: T, options?: {
exclusive?: boolean;
}): Struct<T>;
/**
* Ensure that a number is non-negative (includes zero).
*/
export declare function nonnegative<T extends number>(struct: Struct<T>): Struct<T>;
/**
* Ensure that a number is non-positive (includes zero).
*/
export declare function nonpositive<T extends number>(struct: Struct<T>): Struct<T>;
/**
* Ensure that a string matches a regular expression.

@@ -27,5 +23,5 @@ */

/**
* Ensure that a number is positive (not zero).
* Ensure that a string, array, number, date, map, or set has a size (or length, or time) between `min` and `max`.
*/
export declare function positive<T extends number>(struct: Struct<T>): Struct<T>;
export declare function size<T extends string | number | Date | any[] | Map<any, any> | Set<any>>(struct: Struct<T>, min: number, max?: number): Struct<T>;
/**

@@ -38,3 +34,3 @@ * Augment a `Struct` to add an additional refinement to the validation.

*/
export declare function refinement<T, S>(name: string, struct: Struct<T, S>, refiner: Refiner<T, S>): Struct<T, S>;
export declare function refine<T, S>(struct: Struct<T, S>, name: string, refiner: Refiner<T, S>): Struct<T, S>;
//# sourceMappingURL=refinements.d.ts.map

@@ -131,9 +131,2 @@ import { Infer, Struct } from '../struct';

/**
* Ensure that a value has a set of known properties of specific types.
*
* Note: Unrecognized properties are allowed and untouched. This is similar to
* how TypeScript's structural typing works.
*/
export declare function shape<S extends ObjectSchema>(schema: S): Struct<ObjectType<S>, S>;
/**
* Ensure that a value is a string.

@@ -164,2 +157,9 @@ */

/**
* Ensure that a value has a set of known properties of specific types.
*
* Note: Unrecognized properties are allowed and untouched. This is similar to
* how TypeScript's structural typing works.
*/
export declare function type<S extends ObjectSchema>(schema: S): Struct<ObjectType<S>, S>;
/**
* Ensure that a value matches one of a set of types.

@@ -166,0 +166,0 @@ */

@@ -9,7 +9,11 @@ import { Struct, Context, Validator } from '../struct';

*/
export declare function assign<A extends ObjectSchema, B extends ObjectSchema>(Structs: [Struct<ObjectType<A>, A>, Struct<ObjectType<B>, B>]): Struct<ObjectType<Assign<A, B>>, Assign<A, B>>;
export declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema>(Structs: [Struct<ObjectType<A>, A>, Struct<ObjectType<B>, B>, Struct<ObjectType<C>, C>]): Struct<ObjectType<Assign<Assign<A, B>, C>>, Assign<Assign<A, B>, C>>;
export declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema>(Structs: [Struct<ObjectType<A>, A>, Struct<ObjectType<B>, B>, Struct<ObjectType<C>, C>, Struct<ObjectType<D>, D>]): Struct<ObjectType<Assign<Assign<Assign<A, B>, C>, D>>, Assign<Assign<Assign<A, B>, C>, D>>;
export declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema, E extends ObjectSchema>(Structs: [Struct<ObjectType<A>, A>, Struct<ObjectType<B>, B>, Struct<ObjectType<C>, C>, Struct<ObjectType<D>, D>, Struct<ObjectType<E>, E>]): Struct<ObjectType<Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>, Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>;
export declare function assign<A extends ObjectSchema, B extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>): Struct<ObjectType<Assign<A, B>>, Assign<A, B>>;
export declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>): Struct<ObjectType<Assign<Assign<A, B>, C>>, Assign<Assign<A, B>, C>>;
export declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>, D: Struct<ObjectType<D>, D>): Struct<ObjectType<Assign<Assign<Assign<A, B>, C>, D>>, Assign<Assign<Assign<A, B>, C>, D>>;
export declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema, E extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>, D: Struct<ObjectType<D>, D>, E: Struct<ObjectType<E>, E>): Struct<ObjectType<Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>, Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>;
/**
* Define a new struct with a custom validation function.
*/
export declare function define<T>(name: string, validator: Validator<T, null>): Struct<T, null>;
/**
* Create a struct with dynamic, runtime validation.

@@ -52,6 +56,2 @@ *

export declare function pick<S extends ObjectSchema, K extends keyof S>(struct: Struct<ObjectType<S>, S>, keys: K[]): Struct<ObjectType<Pick<S, K>>, Pick<S, K>>;
/**
* Create a new struct with a custom validation function.
*/
export declare function struct<T>(name: string, validator: Validator<T, null>): Struct<T, null>;
//# sourceMappingURL=utilities.d.ts.map

@@ -1,10 +0,13 @@

import { Struct, StructResult, StructFailure, StructContext } from './struct';
export declare type StructRecord<T> = Record<string, Struct<T>>;
export declare type StructTuple<T> = {
[K in keyof T]: Struct<T[K]>;
import { Struct, Infer, Result, Context } from './struct';
import { Failure } from './error';
/**
* Check if a value is a plain object.
*/
export declare function isPlainObject(value: unknown): value is {
[key: string]: any;
};
/**
* Convert a validation result to an iterable of failures.
* Return a value as a printable string.
*/
export declare function toFailures(result: StructResult, context: StructContext): IterableIterator<StructFailure>;
export declare function print(value: any, ticks?: string): string;
/**

@@ -14,3 +17,55 @@ * Shifts (removes and returns) the first value from the `input` iterator.

*/
export declare function iteratorShift<T>(input: Iterator<T>): T | undefined;
export declare function shiftIterator<T>(input: Iterator<T>): T | undefined;
/**
* Convert a validation result to an iterable of failures.
*/
export declare function toFailures<T, S>(result: Result, context: Context<T, S>): IterableIterator<Failure>;
/**
* Normalize properties of a type that allow `undefined` to make them optional.
*/
export declare type Optionalize<S extends object> = OmitBy<S, undefined> & Partial<PickBy<S, undefined>>;
/**
* Omit properties from a type that extend from a specific type.
*/
export declare type OmitBy<T, V> = Omit<T, {
[K in keyof T]: V extends Extract<T[K], V> ? K : never;
}[keyof T]>;
/**
* Pick properties from a type that extend from a specific type.
*/
export declare type PickBy<T, V> = Pick<T, {
[K in keyof T]: V extends Extract<T[K], V> ? K : never;
}[keyof T]>;
/**
* Simplifies a type definition to its most basic representation.
*/
export declare type Simplify<T> = T extends any[] | Date ? T : {
[Key in keyof T]: T[Key];
} & {};
/**
* Assign properties from one type to another, overwriting existing.
*/
export declare type Assign<T, U> = Simplify<U & Omit<T, keyof U>>;
/**
* A schema for object structs.
*/
export declare type ObjectSchema = Record<string, Struct<any, any>>;
/**
* Infer a type from an object struct schema.
*/
export declare type ObjectType<S extends ObjectSchema> = Simplify<Optionalize<{
[K in keyof S]: Infer<S[K]>;
}>>;
/**
* Transform an object schema type to represent a partial.
*/
export declare type PartialObjectSchema<S extends ObjectSchema> = {
[K in keyof S]: Struct<Infer<S[K]> | undefined>;
};
/**
* A schema for tuple structs.
*/
export declare type TupleSchema<T> = {
[K in keyof T]: Struct<T[K]>;
};
//# sourceMappingURL=utils.d.ts.map
{
"name": "superstruct",
"type": "module",
"description": "A simple, expressive way to validate data in JavaScript.",
"version": "0.10.13",
"description": "A simple and composable way to validate data in JavaScript (and TypeScript).",
"version": "0.11.0",
"license": "MIT",

@@ -12,2 +12,3 @@ "repository": "git://github.com/ianstormtaylor/superstruct.git",

"module": "./lib/index.es.js",
"sideEffects": false,
"files": [

@@ -53,3 +54,3 @@ "umd",

"scripts": {
"build": "yarn build:es && yarn build:cjs && yarn build:max && yarn build:min && yarn build:types",
"build": "yarn build:types && yarn build:es && yarn build:cjs && yarn build:max && yarn build:min",
"build:cjs": "rollup --config ./config/rollup-cjs.js",

@@ -56,0 +57,0 @@ "build:es": "rollup --config ./config/rollup.js",

@@ -7,3 +7,3 @@ <p align="center">

A simple and composable way <br/>
to validate data in JavaScript.
to validate data in JavaScript (and TypeScript).
</p>

@@ -23,14 +23,8 @@ <br/>

<p align="center">
<a href="https://travis-ci.org/ianstormtaylor/superstruct">
<img src="https://travis-ci.org/ianstormtaylor/superstruct.svg?branch=master">
</a>
<a href="https://unpkg.com/superstruct/umd/superstruct.min.js">
<img src="http://img.badgesize.io/https://unpkg.com/superstruct/umd/superstruct.min.js?compression=gzip&amp;label=size&amp;maxAge=300">
<img src="https://badgen.net/bundlephobia/minzip/superstruct?color=green&label=size">
</a>
<a href="./package.json">
<img src="https://img.shields.io/npm/v/superstruct.svg?maxAge=300&label=version&colorB=007ec6&maxAge=300">
<img src="https://badgen.net/npm/v/superstruct?color=blue&label=version">
</a>
<a href="./License.md">
<img src="https://img.shields.io/npm/l/slate.svg?maxAge=300">
</a>
</p>

@@ -37,0 +31,0 @@

/**
* `Struct` objects encapsulate the schema for a specific data type (with
* optional coercion). You can then use the `assert`, `is` or `validate` helpers
* to validate unknown data against a struct.
* A `StructFailure` represents a single specific failure in validation.
*/
declare class Struct<T, S = any> {
type Failure = {
value: any;
key: string | number | undefined;
type: string;
schema: S;
coercer: (value: unknown) => unknown;
validator: (value: unknown, context: StructContext) => StructResult;
refiner: (value: T, context: StructContext) => StructResult;
constructor(props: {
type: Struct<T>["type"];
schema: S;
coercer?: Struct<T>["coercer"];
validator?: Struct<T>["validator"];
refiner?: Struct<T>["refiner"];
});
}
refinement: string | undefined;
message: string;
branch: Array<any>;
path: Array<string | number>;
};
/**
* `StructError` objects are thrown (or returned) by Superstruct when its
* validation fails. The error represents the first error encountered during
* validation. But they also have an `error.failures` property that holds
* information for all of the failures encountered.
* `StructError` objects are thrown (or returned) when validation fails.
*
* Validation logic is design to exit early for maximum performance. The error
* represents the first error encountered during validation. For more detail,
* the `error.failures` property is a generator function that can be run to
* continue validation and receive all the failures in the data.
*/
declare class StructError extends TypeError {
value: any;
key: string | number | undefined;
type: string;
refinement: string | undefined;
path: Array<number | string>;
branch: Array<any>;
failures: () => Array<StructFailure>;
failures: () => Array<Failure>;
[key: string]: any;
constructor(failure: StructFailure, moreFailures: IterableIterator<StructFailure>);
constructor(failure: Failure, moreFailures: IterableIterator<Failure>);
}
/**
* `Struct` objects encapsulate the validation logic for a specific type of
* values. Once constructed, you use the `assert`, `is` or `validate` helpers to
* validate unknown input data against the struct.
*/
declare class Struct<T = unknown, S = unknown> {
readonly TYPE: T;
type: string;
schema: S;
coercer: Coercer;
validator: Validator<T, S>;
refiner: Refiner<T, S>;
constructor(props: {
type: Struct<T, S>["type"];
schema: Struct<T, S>["schema"];
coercer?: Struct<T, S>["coercer"];
validator?: Struct<T, S>["validator"];
refiner?: Struct<T, S>["refiner"];
});
/**
* Assert that a value passes the struct's validation, throwing if it doesn't.
*/
assert(value: unknown): value is T;
/**
* Create a value with the struct's coercion logic, then validate it.
*/
create(value: unknown): T;
/**
* Check if a value passes the struct's validation.
*/
is(value: unknown): value is T;
/**
* Mask a value, coercing and validating it, but returning only the subset of
* properties defined by the struct's schema.
*/
mask(value: unknown): T;
/**
* Validate a value with the struct's validation logic, returning a tuple
* representing the result.
*
* You may optionally pass `true` for the `withCoercion` argument to coerce
* the value before attempting to validate it. If you do, the result will
* contain the coerced result when successful.
*/
validate(value: unknown, options?: {
coerce?: boolean;
}): [StructError, undefined] | [undefined, T];
}
/**
* A `StructContext` contains information about the current value being
* validated as well as helper functions for failures and recursive validating.
*/
type StructContext = {
type Context<T, S> = {
value: any;
type: string;
struct: Struct<T, S>;
branch: Array<any>;
path: Array<string | number>;
fail: (props?: Partial<StructFailure>) => StructFailure;
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => IterableIterator<StructFailure>;
fail: (props?: string | Partial<Failure>) => Failure;
check: <Y, Z>(value: any, struct: Struct<Y, Z>, parent?: any, key?: string | number) => IterableIterator<Failure>;
};
/**
* A `StructFailure` represents a single specific failure in validation.
* A type utility to extract the type from a `Struct` class.
*/
type StructFailure = {
value: StructContext["value"];
type: StructContext["type"];
branch: StructContext["branch"];
path: StructContext["path"];
[key: string]: any;
};
type Infer<T extends Struct<any, any>> = T["TYPE"];
/**
* A `StructResult` is returned from validation functions.
* A `Result` is returned from validation functions.
*/
type StructResult = boolean | Iterable<StructFailure>;
type Result = boolean | string | Iterable<Failure>;
/**
* A type utility to extract the type from a `Struct` class.
* A `Coercer` takes an unknown value and optionally coerces it.
*/
type StructType<T extends Struct<any>> = Parameters<T["refiner"]>[0];
type Coercer = (value: unknown) => unknown;
/**
* A `Validate` takes an unknown value and validates it.
*/
type Validator<T, S> = (value: unknown, context: Context<T, S>) => Result;
/**
* A `Refiner` takes a value of a known type and validates it against a further
* constraint.
*/
type Refiner<T, S> = (value: T, context: Context<T, S>) => Result;
/**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
declare function assert<T>(value: unknown, struct: Struct<T>): value is T;
declare function assert<T, S>(value: unknown, struct: Struct<T, S>): value is T;
/**
* Coerce a value with the coercion logic of `Struct` and validate it.
* Create a value with the coercion logic of `Struct` and validate it.
*/
declare function coerce<T>(value: unknown, struct: Struct<T>): T;
declare function create<T, S>(value: unknown, struct: Struct<T, S>): T;
/**
* Mask a value, returning only the subset of properties defined by a Struct.
*/
declare function mask<T, S>(value: unknown, struct: Struct<T, S>): T;
/**
* Check if a value passes a `Struct`.
*/
declare function is<T>(value: unknown, struct: Struct<T>): value is T;
declare function is<T, S>(value: unknown, struct: Struct<T, S>): value is T;
/**
* Validate a value against a `Struct`, returning an error if invalid.
*/
declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T];
declare function validate<T, S>(value: unknown, struct: Struct<T, S>, options?: {
coerce?: boolean;
}): [StructError, undefined] | [undefined, T];
/**
* Augment a `Struct` to add an additional coercion step to its input.
*
* This allows you to transform input data before validating it, to increase the
* likelihood that it passes validation—for example for default values, parsing
* different formats, etc.
*
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
declare function coercion<T>(struct: Struct<T>, coercer: Struct<T>["coercer"]): Struct<T>;
declare function coerce<T, S>(struct: Struct<T, S>, coercer: Struct<T, S>["coercer"]): Struct<T, S>;
/**
* Augment a struct to coerce a default value for missing values.
* Augment a struct to replace `undefined` values with a default.
*
* Note: You must use `coerce(value, Struct)` on the value before validating it
* to have the value defaulted!
* Note: You must use `coerce(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
declare function defaulted<T>(S: Struct<T>, fallback: any, strict?: true): Struct<T>;
declare function defaulted<T, S>(S: Struct<T, S>, fallback: any, options?: {
strict?: boolean;
}): Struct<T, S>;
/**
* Coerce a value to mask its properties to only that defined in the struct.
* Augment a struct to mask its input to only properties defined in the struct.
*
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
declare function masked<T extends {
[key: string]: any;
}, V extends Record<string, Struct<any>>>(S: Struct<T, V>): Struct<T>;
declare function masked<T, S>(struct: Struct<T, S>): Struct<T, S>;
/**
* Augment a string or array struct to constrain its length to zero.
* Ensure that a string, array, map, or set is empty.
*/
declare function empty<T extends string | any[]>(S: Struct<T>): Struct<T>;
declare function empty<T extends string | any[] | Map<any, any> | Set<any>>(struct: Struct<T>): Struct<T>;
/**
* Augment a string or array struct to constrain its length to being between a
* minimum and maximum size.
* Ensure that a number or date is below a threshold.
*/
declare function length<T extends string | any[]>(S: Struct<T>, min: number, max: number): Struct<T>;
declare function max<T extends number | Date>(struct: Struct<T>, threshold: T, options?: {
exclusive?: boolean;
}): Struct<T>;
/**
* Refine a string struct to match a specific regexp pattern.
* Ensure that a number or date is above a threshold.
*/
declare function pattern<T extends string>(S: Struct<T>, regexp: RegExp): Struct<T>;
declare function min<T extends number | Date>(struct: Struct<T>, threshold: T, options?: {
exclusive?: boolean;
}): Struct<T>;
/**
* Ensure that a string matches a regular expression.
*/
declare function pattern<T extends string>(struct: Struct<T>, regexp: RegExp): Struct<T>;
/**
* Ensure that a string, array, number, date, map, or set has a size (or length, or time) between `min` and `max`.
*/
declare function size<T extends string | number | Date | any[] | Map<any, any> | Set<any>>(struct: Struct<T>, min: number, max?: number): Struct<T>;
/**
* Augment a `Struct` to add an additional refinement to the validation.
*
* The refiner function is guaranteed to receive a value of the struct's type,
* because the struct's existing validation will already have passed. This
* allows you to layer additional validation on top of existing structs.
*/
declare function refinement<T>(struct: Struct<T>, type: string, refiner: Struct<T>["refiner"]): Struct<T>;
type StructRecord<T> = Record<string, Struct<T>>;
type StructTuple<T> = {
declare function refine<T, S>(struct: Struct<T, S>, name: string, refiner: Refiner<T, S>): Struct<T, S>;
/**
* Normalize properties of a type that allow `undefined` to make them optional.
*/
type Optionalize<S extends object> = OmitBy<S, undefined> & Partial<PickBy<S, undefined>>;
/**
* Omit properties from a type that extend from a specific type.
*/
type OmitBy<T, V> = Omit<T, {
[K in keyof T]: V extends Extract<T[K], V> ? K : never;
}[keyof T]>;
/**
* Pick properties from a type that extend from a specific type.
*/
type PickBy<T, V> = Pick<T, {
[K in keyof T]: V extends Extract<T[K], V> ? K : never;
}[keyof T]>;
/**
* Simplifies a type definition to its most basic representation.
*/
type Simplify<T> = T extends any[] | Date ? T : {
[Key in keyof T]: T[Key];
} & {};
/**
* Assign properties from one type to another, overwriting existing.
*/
type Assign<T, U> = Simplify<U & Omit<T, keyof U>>;
/**
* A schema for object structs.
*/
type ObjectSchema = Record<string, Struct<any, any>>;
/**
* Infer a type from an object struct schema.
*/
type ObjectType<S extends ObjectSchema> = Simplify<Optionalize<{
[K in keyof S]: Infer<S[K]>;
}>>;
/**
* Transform an object schema type to represent a partial.
*/
type PartialObjectSchema<S extends ObjectSchema> = {
[K in keyof S]: Struct<Infer<S[K]> | undefined>;
};
/**
* A schema for tuple structs.
*/
type TupleSchema<T> = {
[K in keyof T]: Struct<T[K]>;
};
/**
* Validate any value.
* Ensure that any value passes validation.
*/
declare function any(): Struct<any>;
declare function any(): Struct<any, null>;
/**
* Validate that an array of values of a specific type.
* Ensure that a value is an array and that its elements are of a specific type.
*
* Note: If you omit the element struct, the arrays elements will not be
* iterated at all. This can be helpful for cases where performance is critical,
* and it is preferred to using `array(any())`.
*/
declare function array(): Struct<unknown[]>;
declare function array<T>(Element: Struct<T>): Struct<T[], Struct<T>>;
declare function array<T extends Struct<any>>(Element: T): Struct<Infer<T>[], T>;
declare function array(): Struct<unknown[], undefined>;
/**
* Validate that boolean values.
* Ensure that a value is a boolean.
*/
declare function boolean(): Struct<boolean>;
declare function boolean(): Struct<boolean, null>;
/**
* Validate that `Date` values.
* Ensure that a value is a valid `Date`.
*

@@ -138,179 +265,214 @@ * Note: this also ensures that the value is *not* an invalid `Date` object,

*/
declare function date(): Struct<Date>;
declare function date(): Struct<Date, null>;
/**
* Validate that a value dynamically, determing which struct to use at runtime.
* Ensure that a value is one of a set of potential values.
*
* Note: after creating the struct, you can access the definition of the
* potential values as `struct.schema`.
*/
declare function dynamic<T>(fn: (value: unknown, ctx: StructContext) => Struct<T>): Struct<T>;
declare function enums<T extends number>(values: T[]): Struct<T, {
[K in T[][number]]: K;
}>;
declare function enums<T extends string>(values: T[]): Struct<T, {
[K in T[][number]]: K;
}>;
/**
* Validate that a value against a set of potential values.
* Ensure that a value is a function.
*/
declare function enums<T extends number>(values: T[]): Struct<T>;
declare function enums<T extends string>(values: T[]): Struct<T>;
declare function func(): Struct<Function, null>;
/**
* Validate that a value is a function.
* Ensure that a value is an instance of a specific class.
*/
declare function func(): Struct<Function>;
/**
* Validate that a value is an instance of a class.
*/
declare function instance<T extends {
new (...args: any): any;
}>(Class: T): Struct<InstanceType<T>>;
}>(Class: T): Struct<InstanceType<T>, null>;
/**
* Validate that a value matches all of a set of structs.
* Ensure that a value is an integer.
*/
declare function intersection<A>(Structs: StructTuple<[A]>): Struct<A>;
declare function intersection<A, B>(Structs: StructTuple<[A, B]>): Struct<A & B>;
declare function intersection<A, B, C>(Structs: StructTuple<[A, B, C]>): Struct<A & B & C>;
declare function intersection<A, B, C, D>(Structs: StructTuple<[A, B, C, D]>): Struct<A & B & C & D>;
declare function intersection<A, B, C, D, E>(Structs: StructTuple<[A, B, C, D, E]>): Struct<A & B & C & D & E>;
declare function intersection<A, B, C, D, E, F>(Structs: StructTuple<[A, B, C, D, E, F]>): Struct<A & B & C & D & E & F>;
declare function intersection<A, B, C, D, E, F, G>(Structs: StructTuple<[A, B, C, D, E, F, G]>): Struct<A & B & C & D & E & F & G>;
declare function intersection<A, B, C, D, E, F, G, H>(Structs: StructTuple<[A, B, C, D, E, F, G, H]>): Struct<A & B & C & D & E & F & G & H>;
declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I]>): Struct<A & B & C & D & E & F & G & H & I>;
declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J]>): Struct<A & B & C & D & E & F & G & H & I & J>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A & B & C & D & E & F & G & H & I & J & K>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q>;
declare function integer(): Struct<number, null>;
/**
* Validate a value lazily, by constructing the struct right before the first
* validation. This is useful for cases where you want to have self-referential
* structs for nested data structures.
* Ensure that a value matches all of a set of types.
*/
declare function lazy<T>(fn: () => Struct<T>): Struct<T>;
declare function intersection<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
declare function intersection<A, B>(Structs: TupleSchema<[A, B]>): Struct<A & B, null>;
declare function intersection<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<A & B & C, null>;
declare function intersection<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<A & B & C & D, null>;
declare function intersection<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<A & B & C & D & E, null>;
declare function intersection<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<A & B & C & D & E & F, null>;
declare function intersection<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<A & B & C & D & E & F & G, null>;
declare function intersection<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<A & B & C & D & E & F & G & H, null>;
declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<A & B & C & D & E & F & G & H & I, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<A & B & C & D & E & F & G & H & I & J, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A & B & C & D & E & F & G & H & I & J & K, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q, null>;
/**
* Validate that a value is a specific constant.
* Ensure that a value is an exact value, using `===` for comparison.
*/
declare function literal<T extends boolean>(constant: T): Struct<T>;
declare function literal<T extends number>(constant: T): Struct<T>;
declare function literal<T extends string>(constant: T): Struct<T>;
declare function literal<T>(constant: T): Struct<T>;
declare function literal<T extends boolean>(constant: T): Struct<T, null>;
declare function literal<T extends number>(constant: T): Struct<T, null>;
declare function literal<T extends string>(constant: T): Struct<T, null>;
declare function literal<T>(constant: T): Struct<T, null>;
/**
* Validate that a value is a map with specific key and value entries.
* Ensure that a value is a `Map` object, and that its keys and values are of
* specific types.
*/
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>>;
declare function map(): Struct<Map<unknown, unknown>, null>;
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>, null>;
/**
* Validate that a value always fails.
* Ensure that no value ever passes validation.
*/
declare function never(): Struct<never>;
declare function never(): Struct<never, null>;
/**
* Augment a struct to make it accept `null` values.
* Augment an existing struct to allow `null` values.
*/
declare function nullable<T>(S: Struct<T>): Struct<T | null>;
declare function nullable<T, S>(struct: Struct<T, S>): Struct<T | null, S>;
/**
* Validate that a value is a number.
* Ensure that a value is a number.
*/
declare function number(): Struct<number>;
declare function number(): Struct<number, null>;
/**
* Type helper to Flatten the Union of optional and required properties.
* Ensure that a value is an object, that is has a known set of properties,
* and that its properties are of specific types.
*
* Note: Unrecognized properties will fail validation.
*/
type Flatten<T> = T extends infer U ? {
[K in keyof U]: U[K];
} : never;
declare function object(): Struct<Record<string, unknown>, null>;
declare function object<S extends ObjectSchema>(schema: S): Struct<ObjectType<S>, S>;
/**
* Type helper to extract the optional keys of an object
* Augment a struct to allow `undefined` values.
*/
type OptionalKeys<T> = {
[K in keyof T]: undefined extends T[K] ? K : never;
}[keyof T];
declare function optional<T, S>(struct: Struct<T, S>): Struct<T | undefined, S>;
/**
* Type helper to extract the required keys of an object
* Ensure that a value is an object with keys and values of specific types, but
* without ensuring any specific shape of properties.
*
* Like TypeScript's `Record` utility.
*/
type RequiredKeys<T> = {
[K in keyof T]: undefined extends T[K] ? never : K;
}[keyof T];
declare function record<K extends string, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>, null>;
/**
* Type helper to create optional properties when the property value can be
* undefined (ie. when `optional()` is used to define a type)
* Ensure that a value is a `RegExp`.
*
* Note: this does not test the value against the regular expression! For that
* you need to use the `pattern()` refinement.
*/
type OptionalizeObject<T> = Flatten<{
[K in RequiredKeys<T>]: T[K];
} & {
[K in OptionalKeys<T>]?: T[K];
}>;
declare function regexp(): Struct<RegExp, null>;
/**
* Validate that an object with specific entry values.
* Ensure that a value is a `Set` object, and that its elements are of a
* specific type.
*/
declare function object<V extends StructRecord<any>>(): Struct<Record<string, unknown>>;
declare function object<V extends StructRecord<any>>(Structs: V): Struct<OptionalizeObject<{
[K in keyof V]: StructType<V[K]>;
}>, V>;
declare function set(): Struct<Set<unknown>, null>;
declare function set<T>(Element: Struct<T>): Struct<Set<T>, null>;
/**
* Augment a struct to make it optionally accept `undefined` values.
* Ensure that a value is a string.
*/
declare function optional<T>(S: Struct<T>): Struct<T | undefined>;
declare function string(): Struct<string, null>;
/**
* Validate that a partial object with specific entry values.
* Ensure that a value is a tuple of a specific length, and that each of its
* elements is of a specific type.
*/
declare function partial<T, V extends StructRecord<any>>(Structs: V | Struct<T, V>): Struct<{
[K in keyof V]?: StructType<V[K]>;
}>;
declare function tuple<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
declare function tuple<A, B>(Structs: TupleSchema<[A, B]>): Struct<[A, B], null>;
declare function tuple<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<[A, B, C], null>;
declare function tuple<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<[A, B, C, D], null>;
declare function tuple<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<[A, B, C, D, E], null>;
declare function tuple<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<[A, B, C, D, E, F], null>;
declare function tuple<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<[A, B, C, D, E, F, G], null>;
declare function tuple<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<[A, B, C, D, E, F, G, H], null>;
declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<[A, B, C, D, E, F, G, H, I], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<[A, B, C, D, E, F, G, H, I, J], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<[A, B, C, D, E, F, G, H, I, J, K], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q], null>;
/**
* Validate that a value is a record with specific key and
* value entries.
* Ensure that a value has a set of known properties of specific types.
*
* Note: Unrecognized properties are allowed and untouched. This is similar to
* how TypeScript's structural typing works.
*/
declare function record<K extends string | number, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>>;
declare function type<S extends ObjectSchema>(schema: S): Struct<ObjectType<S>, S>;
/**
* Validate that a set of values matches a specific type.
* Ensure that a value matches one of a set of types.
*/
declare function set<T>(Element: Struct<T>): Struct<Set<T>>;
declare function union<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
declare function union<A, B>(Structs: TupleSchema<[A, B]>): Struct<A | B, null>;
declare function union<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<A | B | C, null>;
declare function union<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<A | B | C | D, null>;
declare function union<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<A | B | C | D | E, null>;
declare function union<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<A | B | C | D | E | F, null>;
declare function union<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<A | B | C | D | E | F | G, null>;
declare function union<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<A | B | C | D | E | F | G | H, null>;
declare function union<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<A | B | C | D | E | F | G | H | I, null>;
declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<A | B | C | D | E | F | G | H | I | J, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A | B | C | D | E | F | G | H | I | J | K, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q, null>;
/**
* Validate that a value is a string.
* Ensure that any value passes validation, without widening its type to `any`.
*/
declare function string(): Struct<string>;
declare function unknown(): Struct<unknown, null>;
/**
* Define a `Struct` instance with a type and validation function.
* Create a new struct that combines the properties properties from multiple
* object structs.
*
* Like JavaScript's `Object.assign` utility.
*/
declare function struct<T>(name: string, validator: Struct<T>["validator"]): Struct<T, null>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>): Struct<ObjectType<Assign<A, B>>, Assign<A, B>>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>): Struct<ObjectType<Assign<Assign<A, B>, C>>, Assign<Assign<A, B>, C>>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>, D: Struct<ObjectType<D>, D>): Struct<ObjectType<Assign<Assign<Assign<A, B>, C>, D>>, Assign<Assign<Assign<A, B>, C>, D>>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema, E extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>, D: Struct<ObjectType<D>, D>, E: Struct<ObjectType<E>, E>): Struct<ObjectType<Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>, Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>;
/**
* Validate that a value is a tuple with entries of specific types.
* Define a new struct with a custom validation function.
*/
declare function tuple<A>(Structs: StructTuple<[A]>): Struct<A>;
declare function tuple<A, B>(Structs: StructTuple<[A, B]>): Struct<[A, B]>;
declare function tuple<A, B, C>(Structs: StructTuple<[A, B, C]>): Struct<[A, B, C]>;
declare function tuple<A, B, C, D>(Structs: StructTuple<[A, B, C, D]>): Struct<[A, B, C, D]>;
declare function tuple<A, B, C, D, E>(Structs: StructTuple<[A, B, C, D, E]>): Struct<[A, B, C, D, E]>;
declare function tuple<A, B, C, D, E, F>(Structs: StructTuple<[A, B, C, D, E, F]>): Struct<[A, B, C, D, E, F]>;
declare function tuple<A, B, C, D, E, F, G>(Structs: StructTuple<[A, B, C, D, E, F, G]>): Struct<[A, B, C, D, E, F, G]>;
declare function tuple<A, B, C, D, E, F, G, H>(Structs: StructTuple<[A, B, C, D, E, F, G, H]>): Struct<[A, B, C, D, E, F, G, H]>;
declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I]>): Struct<[A, B, C, D, E, F, G, H, I]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J]>): Struct<[A, B, C, D, E, F, G, H, I, J]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<[A, B, C, D, E, F, G, H, I, J, K]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>;
declare function define<T>(name: string, validator: Validator<T, null>): Struct<T, null>;
/**
* Validate that a value matches a specific strutural interface, like the
* structural typing that TypeScript uses.
* Create a struct with dynamic, runtime validation.
*
* The callback will receive the value currently being validated, and must
* return a struct object to validate it with. This can be useful to model
* validation logic that changes based on its input.
*/
declare function type<V extends StructRecord<any>>(Structs: V): Struct<{
[K in keyof V]: StructType<V[K]>;
}>;
declare function dynamic<T>(fn: (value: unknown, ctx: Context<T, null>) => Struct<T, any>): Struct<T, null>;
/**
* Validate that a value is one of a set of types.
* Create a struct with lazily evaluated validation.
*
* The first time validation is run with the struct, the callback will be called
* and must return a struct object to use. This is useful for cases where you
* want to have self-referential structs for nested data structures to avoid a
* circular definition problem.
*/
declare function union<A>(Structs: StructTuple<[A]>): Struct<A>;
declare function union<A, B>(Structs: StructTuple<[A, B]>): Struct<A | B>;
declare function union<A, B, C>(Structs: StructTuple<[A, B, C]>): Struct<A | B | C>;
declare function union<A, B, C, D>(Structs: StructTuple<[A, B, C, D]>): Struct<A | B | C | D>;
declare function union<A, B, C, D, E>(Structs: StructTuple<[A, B, C, D, E]>): Struct<A | B | C | D | E>;
declare function union<A, B, C, D, E, F>(Structs: StructTuple<[A, B, C, D, E, F]>): Struct<A | B | C | D | E | F>;
declare function union<A, B, C, D, E, F, G>(Structs: StructTuple<[A, B, C, D, E, F, G]>): Struct<A | B | C | D | E | F | G>;
declare function union<A, B, C, D, E, F, G, H>(Structs: StructTuple<[A, B, C, D, E, F, G, H]>): Struct<A | B | C | D | E | F | G | H>;
declare function union<A, B, C, D, E, F, G, H, I>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I]>): Struct<A | B | C | D | E | F | G | H | I>;
declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J]>): Struct<A | B | C | D | E | F | G | H | I | J>;
declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A | B | C | D | E | F | G | H | I | J | K>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q>;
export { coercion, defaulted, masked, empty, length, pattern, refinement, Struct, StructError, StructContext, StructFailure, StructResult, StructType, assert, coerce, is, validate, any, array, boolean, date, dynamic, enums, func, instance, intersection, lazy, literal, map, never, nullable, number, object, optional, partial, record, set, string, struct, tuple, type, union };
declare function lazy<T>(fn: () => Struct<T, any>): Struct<T, null>;
/**
* Create a new struct based on an existing object struct, but excluding
* specific properties.
*
* Like TypeScript's `Omit` utility.
*/
declare function omit<S extends ObjectSchema, K extends keyof S>(struct: Struct<ObjectType<S>, S>, keys: K[]): Struct<ObjectType<Omit<S, K>>, Omit<S, K>>;
/**
* Create a new struct based on an existing object struct, but with all of its
* properties allowed to be `undefined`.
*
* Like TypeScript's `Partial` utility.
*/
declare function partial<S extends ObjectSchema>(struct: Struct<ObjectType<S>, S> | S): Struct<ObjectType<PartialObjectSchema<S>>, PartialObjectSchema<S>>;
/**
* Create a new struct based on an existing object struct, but only including
* specific properties.
*
* Like TypeScript's `Pick` utility.
*/
declare function pick<S extends ObjectSchema, K extends keyof S>(struct: Struct<ObjectType<S>, S>, keys: K[]): Struct<ObjectType<Pick<S, K>>, Pick<S, K>>;
export { Failure, StructError, Struct, Context, Infer, Result, Coercer, Validator, Refiner, assert, create, mask, is, validate, coerce, defaulted, masked, empty, max, min, pattern, size, refine, any, array, boolean, date, enums, func, instance, integer, intersection, literal, map, never, nullable, number, object, optional, record, regexp, set, string, tuple, type, union, unknown, assign, define, dynamic, lazy, omit, partial, pick };

@@ -93,12 +93,69 @@ (function (global, factory) {

/**
* Convert a validation result to an iterable of failures.
* A `StructFailure` represents a single specific failure in validation.
*/
function* toFailures(result, context) {
if (result === true) ; else if (result === false) {
yield context.fail();
} else {
yield* result;
/**
* `StructError` objects are thrown (or returned) when validation fails.
*
* Validation logic is design to exit early for maximum performance. The error
* represents the first error encountered during validation. For more detail,
* the `error.failures` property is a generator function that can be run to
* continue validation and receive all the failures in the data.
*/
class StructError extends TypeError {
constructor(failure, moreFailures) {
const {
path,
value,
key,
type,
message,
refinement,
branch
} = failure,
rest = _objectWithoutProperties(failure, ["path", "value", "key", "type", "message", "refinement", "branch"]);
let failures;
const msg = path.length === 0 ? message : `At path: ${path.join('.')} -- ${message}`;
super(msg);
Object.assign(this, rest);
this.name = this.constructor.name;
this.value = value;
this.key = key;
this.type = type;
this.refinement = refinement;
this.path = path;
this.branch = branch;
this.failures = () => {
if (!failures) {
failures = [failure, ...moreFailures];
}
return failures;
};
}
}
/**
* Check if a value is a plain object.
*/
function isPlainObject(value) {
if (Object.prototype.toString.call(value) !== '[object Object]') {
return false;
}
const prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.prototype;
}
/**
* Return a value as a printable string.
*/
function print(value, ticks) {
const string = typeof value === 'string' ? JSON.stringify(value) : `${value}`;
return ticks ? `${ticks}${string}${ticks}` : string;
}
/**
* Shifts (removes and returns) the first value from the `input` iterator.

@@ -108,3 +165,3 @@ * Like `Array.prototype.shift()` but for an `Iterator`.

function iteratorShift(input) {
function shiftIterator(input) {
const {

@@ -116,9 +173,108 @@ done,

}
/**
* Convert a validation result to an iterable of failures.
*/
function* toFailures(result, context) {
if (typeof result === 'string') {
yield context.fail({
message: result
});
} else if (result === true) {
return;
} else if (result === false) {
yield context.fail();
} else {
yield* result;
}
}
/**
* `Struct` objects encapsulate the schema for a specific data type (with
* optional coercion). You can then use the `assert`, `is` or `validate` helpers
* to validate unknown data against a struct.
* Augment a `Struct` to add an additional coercion step to its input.
*
* This allows you to transform input data before validating it, to increase the
* likelihood that it passes validation—for example for default values, parsing
* different formats, etc.
*
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
function coerce(struct, coercer) {
const fn = struct.coercer;
return new Struct(_objectSpread2(_objectSpread2({}, struct), {}, {
coercer: value => {
return fn(coercer(value));
}
}));
}
/**
* Augment a struct to replace `undefined` values with a default.
*
* Note: You must use `coerce(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
function defaulted(S, fallback, options = {}) {
const {
strict
} = options;
return coerce(S, x => {
const f = typeof fallback === 'function' ? fallback() : fallback;
if (x === undefined) {
return f;
}
if (!strict && isPlainObject(x) && isPlainObject(f)) {
const ret = _objectSpread2({}, x);
let changed = false;
for (const key in f) {
if (ret[key] === undefined) {
ret[key] = f[key];
changed = true;
}
}
if (changed) {
return ret;
}
}
return x;
});
}
/**
* Augment a struct to mask its input to only properties defined in the struct.
*
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
function masked(struct) {
return coerce(struct, x => {
if (typeof struct.schema !== 'object' || struct.schema == null || typeof x !== 'object' || x == null) {
return x;
} else {
const ret = {};
for (const key in struct.schema) {
if (key in x) {
ret[key] = x[key];
}
}
return ret;
}
});
}
/**
* `Struct` objects encapsulate the validation logic for a specific type of
* values. Once constructed, you use the `assert`, `is` or `validate` helpers to
* validate unknown input data against the struct.
*/
class Struct {

@@ -139,43 +295,49 @@ constructor(props) {

}
/**
* Assert that a value passes the struct's validation, throwing if it doesn't.
*/
}
/**
* `StructError` objects are thrown (or returned) by Superstruct when its
* validation fails. The error represents the first error encountered during
* validation. But they also have an `error.failures` property that holds
* information for all of the failures encountered.
*/
class StructError extends TypeError {
constructor(failure, moreFailures) {
const {
path,
value,
type,
branch
} = failure,
rest = _objectWithoutProperties(failure, ["path", "value", "type", "branch"]);
assert(value) {
return assert(value, this);
}
/**
* Create a value with the struct's coercion logic, then validate it.
*/
const message = `Expected a value of type \`${type}\`${path.length ? ` for \`${path.join('.')}\`` : ''} but received \`${JSON.stringify(value)}\`.`;
let failuresResult;
function failures() {
if (!failuresResult) {
failuresResult = [failure, ...moreFailures];
}
create(value) {
return create(value, this);
}
/**
* Check if a value passes the struct's validation.
*/
return failuresResult;
}
super(message);
this.value = value;
Object.assign(this, rest);
this.type = type;
this.path = path;
this.branch = branch;
this.failures = failures;
this.stack = new Error().stack;
this.__proto__ = StructError.prototype;
is(value) {
return is(value, this);
}
/**
* Mask a value, coercing and validating it, but returning only the subset of
* properties defined by the struct's schema.
*/
mask(value) {
return mask(value, this);
}
/**
* Validate a value with the struct's validation logic, returning a tuple
* representing the result.
*
* You may optionally pass `true` for the `withCoercion` argument to coerce
* the value before attempting to validate it. If you do, the result will
* contain the coerced result when successful.
*/
validate(value, options = {}) {
return validate(value, this, options);
}
}

@@ -194,6 +356,6 @@ /**

/**
* Coerce a value with the coercion logic of `Struct` and validate it.
* Create a value with the coercion logic of `Struct` and validate it.
*/
function coerce(value, struct) {
function create(value, struct) {
const ret = struct.coercer(value);

@@ -204,2 +366,11 @@ assert(ret, struct);

/**
* Mask a value, returning only the subset of properties defined by a Struct.
*/
function mask(value, struct) {
const M = masked(struct);
const ret = create(value, M);
return ret;
}
/**
* Check if a value passes a `Struct`.

@@ -216,4 +387,4 @@ */

function validate(value, struct, coercing = false) {
if (coercing) {
function validate(value, struct, options = {}) {
if (options.coerce) {
value = struct.coercer(value);

@@ -223,3 +394,3 @@ }

const failures = check(value, struct);
const failure = iteratorShift(failures);
const failure = shiftIterator(failures);

@@ -238,24 +409,42 @@ if (failure) {

function* check(value, struct, path = [], branch = []) {
const {
type
} = struct;
const ctx = {
value,
type,
struct,
branch,
path,
check(v, s, parent, key) {
const p = parent !== undefined ? [...path, key] : path;
const b = parent !== undefined ? [...branch, parent] : branch;
return check(v, s, p, b);
},
fail(props = {}) {
return _objectSpread2({
if (typeof props === 'string') {
props = {
message: props
};
}
const {
type
} = struct;
let {
message,
refinement
} = props;
if (!message) {
message = `Expected a value of type \`${type}\`${refinement ? ` with refinement \`${refinement}\`` : ''}${path.length ? ` for \`${path.join('.')}\`` : ''}, but received: \`${print(value)}\``;
}
return _objectSpread2(_objectSpread2({}, props), {}, {
value,
type,
refinement,
message,
key: path[path.length - 1],
path,
branch: [...branch, value]
}, props);
},
check(v, s, parent, key) {
const p = parent !== undefined ? [...path, key] : path;
const b = parent !== undefined ? [...branch, parent] : branch;
return check(v, s, p, b);
});
}

@@ -265,3 +454,3 @@

const failures = toFailures(struct.validator(value, ctx), ctx);
const failure = iteratorShift(failures);
const failure = shiftIterator(failures);

@@ -277,138 +466,218 @@ if (failure) {

/**
* Augment a `Struct` to add an additional coercion step to its input.
* Ensure that a string, array, map, or set is empty.
*/
function coercion(struct, coercer) {
const fn = struct.coercer;
return new Struct(_objectSpread2(_objectSpread2({}, struct), {}, {
coercer: value => {
return fn(coercer(value));
function empty(struct) {
const expected = `Expected an empty ${struct.type}`;
return refine(struct, 'empty', value => {
if (value instanceof Map || value instanceof Set) {
const {
size
} = value;
return size === 0 || `${expected} but received one with a size of \`${size}\``;
} else {
const {
length
} = value;
return length === 0 || `${expected} but received one with a length of \`${length}\``;
}
}));
});
}
/**
* Augment a struct to coerce a default value for missing values.
*
* Note: You must use `coerce(value, Struct)` on the value before validating it
* to have the value defaulted!
* Ensure that a number or date is below a threshold.
*/
function defaulted(S, fallback, strict) {
return coercion(S, x => {
const f = typeof fallback === 'function' ? fallback() : fallback;
function max(struct, threshold, options = {}) {
const {
exclusive
} = options;
return refine(struct, 'max', value => {
return exclusive ? value < threshold : value <= threshold || `Expected a ${struct.type} greater than ${exclusive ? '' : 'or equal to '}${threshold} but received \`${value}\``;
});
}
/**
* Ensure that a number or date is above a threshold.
*/
if (x === undefined) {
return f;
}
function min(struct, threshold, options = {}) {
const {
exclusive
} = options;
return refine(struct, 'min', value => {
return exclusive ? value > threshold : value >= threshold || `Expected a ${struct.type} greater than ${exclusive ? '' : 'or equal to '}${threshold} but received \`${value}\``;
});
}
/**
* Ensure that a string matches a regular expression.
*/
if (strict !== true && isPlainObject(x) && isPlainObject(f)) {
const ret = _objectSpread2({}, x);
function pattern(struct, regexp) {
return refine(struct, 'pattern', value => {
return regexp.test(value) || `Expected a ${struct.type} matching \`/${regexp.source}/\` but received "${value}"`;
});
}
/**
* Ensure that a string, array, number, date, map, or set has a size (or length, or time) between `min` and `max`.
*/
let changed = false;
for (const key in f) {
if (ret[key] === undefined) {
ret[key] = f[key];
changed = true;
}
}
if (changed) {
return ret;
}
function size(struct, min, max = min) {
const expected = `Expected a ${struct.type}`;
const of = min === max ? `of \`${min}\`` : `between \`${min}\` and \`${max}\``;
return refine(struct, 'size', value => {
if (typeof value === 'number' || value instanceof Date) {
return min <= value && value <= max || `${expected} ${of} but received \`${value}\``;
} else if (value instanceof Map || value instanceof Set) {
const {
size
} = value;
return min <= size && size <= max || `${expected} with a size ${of} but received one with a size of \`${size}\``;
} else {
const {
length
} = value;
return min <= length && length <= max || `${expected} with a length ${of} but received one with a length of \`${length}\``;
}
return x;
});
}
/**
* Coerce a value to mask its properties to only that defined in the struct.
* Augment a `Struct` to add an additional refinement to the validation.
*
* The refiner function is guaranteed to receive a value of the struct's type,
* because the struct's existing validation will already have passed. This
* allows you to layer additional validation on top of existing structs.
*/
function masked(S) {
return coercion(S, x => {
if (!isPlainObject(x)) {
return x;
function refine(struct, name, refiner) {
const fn = struct.refiner;
return new Struct(_objectSpread2(_objectSpread2({}, struct), {}, {
*refiner(value, ctx) {
yield* toFailures(fn(value, ctx), ctx);
for (const failure of toFailures(refiner(value, ctx), ctx)) {
yield _objectSpread2(_objectSpread2({}, failure), {}, {
refinement: name
});
}
}
const ret = {};
}));
}
for (const key in S.schema) {
ret[key] = x[key];
}
function assign(...Structs) {
const schemas = Structs.map(s => s.schema);
const schema = Object.assign({}, ...schemas);
return object(schema);
}
/**
* Define a new struct with a custom validation function.
*/
return ret;
function define(name, validator) {
return new Struct({
type: name,
schema: null,
validator
});
}
/**
* Check if a value is a plain object.
* Create a struct with dynamic, runtime validation.
*
* The callback will receive the value currently being validated, and must
* return a struct object to validate it with. This can be useful to model
* validation logic that changes based on its input.
*/
function isPlainObject(value) {
if (Object.prototype.toString.call(value) !== '[object Object]') {
return false;
}
const prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.prototype;
function dynamic(fn) {
return define('dynamic', (value, ctx) => {
return ctx.check(value, fn(value, ctx));
});
}
/**
* Augment a string or array struct to constrain its length to zero.
* Create a struct with lazily evaluated validation.
*
* The first time validation is run with the struct, the callback will be called
* and must return a struct object to use. This is useful for cases where you
* want to have self-referential structs for nested data structures to avoid a
* circular definition problem.
*/
function empty(S) {
return refinement(S, `${S.type} & Empty`, value => {
return value.length === 0;
function lazy(fn) {
let s;
return define('lazy', (value, ctx) => {
if (!s) {
s = fn();
}
return ctx.check(value, s);
});
}
/**
* Augment a string or array struct to constrain its length to being between a
* minimum and maximum size.
* Create a new struct based on an existing object struct, but excluding
* specific properties.
*
* Like TypeScript's `Omit` utility.
*/
function length(S, min, max) {
return refinement(S, `${S.type} & Length<${min},${max}>`, value => {
return min < value.length && value.length < max;
});
function omit(struct, keys) {
const {
schema
} = struct;
const subschema = _objectSpread2({}, schema);
for (const key of keys) {
delete subschema[key];
}
return object(subschema);
}
/**
* Refine a string struct to match a specific regexp pattern.
* Create a new struct based on an existing object struct, but with all of its
* properties allowed to be `undefined`.
*
* Like TypeScript's `Partial` utility.
*/
function pattern(S, regexp) {
return refinement(S, `${S.type} & Pattern<${regexp.source}>`, value => {
return regexp.test(value);
});
function partial(struct) {
const schema = struct instanceof Struct ? _objectSpread2({}, struct.schema) : _objectSpread2({}, struct);
for (const key in schema) {
schema[key] = optional(schema[key]);
}
return object(schema);
}
/**
* Augment a `Struct` to add an additional refinement to the validation.
* Create a new struct based on an existing object struct, but only including
* specific properties.
*
* Like TypeScript's `Pick` utility.
*/
function refinement(struct, type, refiner) {
const fn = struct.refiner;
return new Struct(_objectSpread2(_objectSpread2({}, struct), {}, {
type,
function pick(struct, keys) {
const {
schema
} = struct;
const subschema = {};
*refiner(value, fail) {
yield* toFailures(fn(value, fail), fail);
yield* toFailures(refiner(value, fail), fail);
}
for (const key of keys) {
subschema[key] = schema[key];
}
}));
return object(subschema);
}
/**
* Validate any value.
* Ensure that any value passes validation.
*/
function any() {
return struct('any', () => true);
return define('any', () => true);
}
function array(Element) {
return new Struct({
type: `Array<${Element ? Element.type : 'unknown'}>`,
type: 'array',
schema: Element,
coercer: value => {
return Element && Array.isArray(value) ? value.map(v => coerce(v, Element)) : value;
return Element && Array.isArray(value) ? value.map(v => Element.coercer(v)) : value;
},

@@ -418,7 +687,4 @@

if (!Array.isArray(value)) {
yield ctx.fail();
return;
}
if (Element) {
yield ctx.fail(`Expected an array value, but received: ${print(value)}`);
} else if (Element) {
for (const [i, v] of value.entries()) {

@@ -433,7 +699,7 @@ yield* ctx.check(v, Element, value, i);

/**
* Validate that boolean values.
* Ensure that a value is a boolean.
*/
function boolean() {
return struct('boolean', value => {
return define('boolean', value => {
return typeof value === 'boolean';

@@ -443,3 +709,3 @@ });

/**
* Validate that `Date` values.
* Ensure that a value is a valid `Date`.
*

@@ -451,40 +717,51 @@ * Note: this also ensures that the value is *not* an invalid `Date` object,

function date() {
return struct('Date', value => {
return value instanceof Date && !isNaN(value.getTime());
return define('date', value => {
return value instanceof Date && !isNaN(value.getTime()) || `Expected a valid \`Date\` object, but received: ${print(value)}`;
});
}
/**
* Validate that a value dynamically, determing which struct to use at runtime.
*/
function enums(values) {
const schema = {};
const description = values.map(v => print(v)).join();
function dynamic(fn) {
return struct('Dynamic<...>', (value, ctx) => {
return ctx.check(value, fn(value, ctx));
for (const key of values) {
schema[key] = key;
}
return new Struct({
type: 'enums',
schema,
validator: value => {
return values.includes(value) || `Expected one of \`${description}\`, but received: ${print(value)}`;
}
});
}
function enums(values) {
return struct(`Enum<${values.map(toLiteralString)}>`, value => {
return values.includes(value);
});
}
/**
* Validate that a value is a function.
* Ensure that a value is a function.
*/
function func() {
return struct('Function', value => {
return typeof value === 'function';
return define('func', value => {
return typeof value === 'function' || `Expected a function, but received: ${print(value)}`;
});
}
/**
* Validate that a value is an instance of a class.
* Ensure that a value is an instance of a specific class.
*/
function instance(Class) {
return struct(`InstanceOf<${Class.name}>`, value => {
return value instanceof Class;
return define('instance', value => {
return value instanceof Class || `Expected a \`${Class.name}\` instance, but received: ${print(value)}`;
});
}
/**
* Ensure that a value is an integer.
*/
function integer() {
return define('integer', value => {
return typeof value === 'number' && !isNaN(value) && Number.isInteger(value) || `Expected an integer, but received: ${print(value)}`;
});
}
function intersection(Structs) {
return struct(Structs.map(s => s.type).join(' & '), function* (value, ctx) {
return define('intersection', function* (value, ctx) {
for (const S of Structs) {

@@ -495,84 +772,70 @@ yield* ctx.check(value, S);

}
/**
* Validate a value lazily, by constructing the struct right before the first
* validation. This is useful for cases where you want to have self-referential
* structs for nested data structures.
*/
function lazy(fn) {
let S;
return struct('Lazy<...>', (value, ctx) => {
if (!S) {
S = fn();
}
return ctx.check(value, S);
});
}
function literal(constant) {
return struct(`Literal<${toLiteralString(constant)}>`, value => {
return value === constant;
const description = print(constant);
return define('literal', value => {
return value === constant || `Expected the literal \`${description}\`, but received: ${print(value)}`;
});
}
/**
* Validate that a value is a map with specific key and value entries.
*/
function map(Key, Value) {
return struct(`Map<${Key.type},${Value.type}>`, function* (value, ctx) {
return define('map', function* (value, ctx) {
if (!(value instanceof Map)) {
yield ctx.fail();
return;
yield ctx.fail(`Expected a \`Map\` object, but received: ${print(value)}`);
} else if (Key && Value) {
for (const [k, v] of value.entries()) {
yield* ctx.check(k, Key, value, k);
yield* ctx.check(v, Value, value, k);
}
}
for (const [k, v] of value.entries()) {
yield* ctx.check(k, Key, value, k);
yield* ctx.check(v, Value, value, k);
}
});
}
/**
* Validate that a value always fails.
* Ensure that no value ever passes validation.
*/
function never() {
return struct('never', () => false);
return define('never', () => false);
}
/**
* Augment a struct to make it accept `null` values.
* Augment an existing struct to allow `null` values.
*/
function nullable(S) {
return new Struct({
type: `${S.type} | null`,
schema: S.schema,
function nullable(struct) {
const {
refiner
} = struct;
return new Struct(_objectSpread2(_objectSpread2({}, struct), {}, {
validator: (value, ctx) => {
return value === null || ctx.check(value, S);
return value === null || ctx.check(value, struct);
},
refiner: function* (value, ctx) {
if (value != null) {
const c = _objectSpread2(_objectSpread2({}, ctx), {}, {
struct
});
yield* toFailures(refiner(value, c), c);
}
}
});
}));
}
/**
* Validate that a value is a number.
* Ensure that a value is a number.
*/
function number() {
return struct(`number`, value => {
return typeof value === 'number' && !isNaN(value);
return define('number', value => {
return typeof value === 'number' && !isNaN(value) || `Expected a number, but received: ${print(value)}`;
});
}
function object(Structs) {
const knowns = Structs ? Object.keys(Structs) : [];
function object(schema) {
const knowns = schema ? Object.keys(schema) : [];
const Never = never();
return new Struct({
type: Structs ? `Object<{${knowns.join(',')}}>` : 'Object',
schema: Structs ? Structs : null,
coercer: Structs ? createObjectCoercer(Structs) : x => x,
type: 'object',
schema: schema ? schema : null,
*validator(value, ctx) {
if (typeof value !== 'object' || value == null) {
yield ctx.fail();
return;
}
if (Structs) {
yield ctx.fail(`Expected an object, but received: ${print(value)}`);
} else if (schema) {
const unknowns = new Set(Object.keys(value));

@@ -582,3 +845,3 @@

unknowns.delete(key);
const Value = Structs[key];
const Value = schema[key];
const v = value[key];

@@ -593,41 +856,10 @@ yield* ctx.check(v, Value, value, key);

}
}
},
});
}
/**
* Augment a struct to make it optionally accept `undefined` values.
*/
function optional(S) {
return new Struct({
type: `${S.type}?`,
schema: S.schema,
validator: (value, ctx) => {
return value === undefined || ctx.check(value, S);
}
});
}
/**
* Validate that a partial object with specific entry values.
*/
function partial(Structs) {
if (Structs instanceof Struct) {
Structs = Structs.schema;
}
const knowns = Object.keys(Structs);
const Never = never();
return new Struct({
type: `Partial<{${knowns.join(',')}}>`,
schema: Structs,
coercer: createObjectCoercer(Structs),
*validator(value, ctx) {
if (typeof value !== 'object' || value == null) {
yield ctx.fail();
return;
coercer: value => {
if (!schema || typeof value !== 'object' || value == null) {
return value;
}
const ret = {};
const unknowns = new Set(Object.keys(value));

@@ -637,170 +869,161 @@

unknowns.delete(key);
if (!(key in value)) {
continue;
}
const Value = Structs[key];
const Value = schema[key];
const v = value[key];
yield* ctx.check(v, Value, value, key);
ret[key] = Value.coercer(v);
}
for (const key of unknowns) {
const v = value[key];
yield* ctx.check(v, Never, value, key);
ret[key] = value[key];
}
return ret;
}
});
}
/**
* Validate that a value is a record with specific key and
* value entries.
* Augment a struct to allow `undefined` values.
*/
function optional(struct) {
const {
refiner
} = struct;
return new Struct(_objectSpread2(_objectSpread2({}, struct), {}, {
validator: (value, ctx) => {
return value === undefined || ctx.check(value, struct);
},
refiner: function* (value, ctx) {
if (value != null) {
const c = _objectSpread2(_objectSpread2({}, ctx), {}, {
struct
});
yield* toFailures(refiner(value, c), c);
}
}
}));
}
/**
* Ensure that a value is an object with keys and values of specific types, but
* without ensuring any specific shape of properties.
*
* Like TypeScript's `Record` utility.
*/
function record(Key, Value) {
return struct(`Record<${Key.type},${Value.type}>`, function* (value, ctx) {
return define('record', function* (value, ctx) {
if (typeof value !== 'object' || value == null) {
yield ctx.fail();
return;
yield ctx.fail(`Expected an object, but received: ${print(value)}`);
} else {
for (const k in value) {
const v = value[k];
yield* ctx.check(k, Key, value, k);
yield* ctx.check(v, Value, value, k);
}
}
for (const k in value) {
const v = value[k];
yield* ctx.check(k, Key, value, k);
yield* ctx.check(v, Value, value, k);
}
});
}
/**
* Validate that a set of values matches a specific type.
* Ensure that a value is a `RegExp`.
*
* Note: this does not test the value against the regular expression! For that
* you need to use the `pattern()` refinement.
*/
function regexp() {
return define('regexp', value => {
return value instanceof RegExp;
});
}
function set(Element) {
return struct(`Set<${Element.type}>`, (value, ctx) => {
return define('set', function* (value, ctx) {
if (!(value instanceof Set)) {
return false;
}
for (const val of value) {
const [failure] = ctx.check(val, Element);
if (failure) {
return false;
yield ctx.fail(`Expected a \`Set\` object, but received: ${print(value)}`);
} else if (Element) {
for (const val of value) {
yield* ctx.check(val, Element, value, val);
}
}
return true;
});
}
/**
* Validate that a value is a string.
* Ensure that a value is a string.
*/
function string() {
return struct('string', value => {
return typeof value === 'string';
return define('string', value => {
return typeof value === 'string' || `Expected a string, but received: ${print(value)}`;
});
}
/**
* Define a `Struct` instance with a type and validation function.
*/
function struct(name, validator) {
return new Struct({
type: name,
validator,
schema: null
});
}
function tuple(Elements) {
const Never = never();
return struct(`[${Elements.map(s => s.type).join(',')}]`, function* (value, ctx) {
return define('tuple', function* (value, ctx) {
if (!Array.isArray(value)) {
yield ctx.fail();
return;
}
yield ctx.fail(`Expected an array, but received: ${print(value)}`);
} else {
for (const [index, Element] of Elements.entries()) {
const v = value[index];
yield* ctx.check(v, Element, value, index);
}
for (const [index, Element] of Elements.entries()) {
const v = value[index];
yield* ctx.check(v, Element, value, index);
if (value.length > Elements.length) {
const index = Elements.length;
const v = value[index];
yield* ctx.check(v, Never, value, index);
}
}
if (value.length > Elements.length) {
const index = Elements.length;
const v = value[index];
yield* ctx.check(v, Never, value, index);
}
});
}
/**
* Validate that a value matches a specific strutural interface, like the
* structural typing that TypeScript uses.
* Ensure that a value has a set of known properties of specific types.
*
* Note: Unrecognized properties are allowed and untouched. This is similar to
* how TypeScript's structural typing works.
*/
function type(Structs) {
const keys = Object.keys(Structs);
return struct(`Type<{${keys.join(',')}}>`, function* (value, ctx) {
if (typeof value !== 'object' || value == null) {
yield ctx.fail();
return;
function type(schema) {
const keys = Object.keys(schema);
return new Struct({
type: 'type',
schema,
validator: function* (value, ctx) {
if (typeof value !== 'object' || value == null) {
yield ctx.fail(`Expected an object, but received: ${print(value)}`);
} else {
for (const key of keys) {
const Value = schema[key];
const v = value[key];
yield* ctx.check(v, Value, value, key);
}
}
}
for (const key of keys) {
const Value = Structs[key];
const v = value[key];
yield* ctx.check(v, Value, value, key);
}
});
}
function union(Structs) {
return struct(`${Structs.map(s => s.type).join(' | ')}`, function* (value, ctx) {
const description = Structs.map(s => s.type).join(' | ');
return define('union', function* (value, ctx) {
const failures = [];
for (const S of Structs) {
const [...failures] = ctx.check(value, S);
const [...array] = ctx.check(value, S);
if (failures.length === 0) {
if (array.length === 0) {
return;
} else {
failures.push(...array);
}
}
yield ctx.fail();
yield ctx.fail(`Expected the value to satisfy a union of \`${description}\`, but received: ${print(value)}`);
yield* failures;
});
}
/**
* Convert a value to a literal string.
* Ensure that any value passes validation, without widening its type to `any`.
*/
function toLiteralString(value) {
return typeof value === 'string' ? `"${value.replace(/"/g, '"')}"` : `${value}`;
function unknown() {
return define('unknown', () => true);
}
/**
* Coerce the values of an object-like struct.
*/
function createObjectCoercer(Structs) {
const knowns = Object.keys(Structs);
return value => {
if (typeof value !== 'object' || value == null) {
return value;
}
const ret = {};
const unknowns = new Set(Object.keys(value));
for (const key of knowns) {
unknowns.delete(key);
const Value = Structs[key];
const v = value[key];
ret[key] = coerce(v, Value);
}
for (const key of unknowns) {
ret[key] = value[key];
}
return ret;
};
}
exports.Struct = Struct;

@@ -811,7 +1034,9 @@ exports.StructError = StructError;

exports.assert = assert;
exports.assign = assign;
exports.boolean = boolean;
exports.coerce = coerce;
exports.coercion = coercion;
exports.create = create;
exports.date = date;
exports.defaulted = defaulted;
exports.define = define;
exports.dynamic = dynamic;

@@ -822,9 +1047,12 @@ exports.empty = empty;

exports.instance = instance;
exports.integer = integer;
exports.intersection = intersection;
exports.is = is;
exports.lazy = lazy;
exports.length = length;
exports.literal = literal;
exports.map = map;
exports.mask = mask;
exports.masked = masked;
exports.max = max;
exports.min = min;
exports.never = never;

@@ -834,13 +1062,17 @@ exports.nullable = nullable;

exports.object = object;
exports.omit = omit;
exports.optional = optional;
exports.partial = partial;
exports.pattern = pattern;
exports.pick = pick;
exports.record = record;
exports.refinement = refinement;
exports.refine = refine;
exports.regexp = regexp;
exports.set = set;
exports.size = size;
exports.string = string;
exports.struct = struct;
exports.tuple = tuple;
exports.type = type;
exports.union = union;
exports.unknown = unknown;
exports.validate = validate;

@@ -847,0 +1079,0 @@

/**
* `Struct` objects encapsulate the schema for a specific data type (with
* optional coercion). You can then use the `assert`, `is` or `validate` helpers
* to validate unknown data against a struct.
* A `StructFailure` represents a single specific failure in validation.
*/
declare class Struct<T, S = any> {
type Failure = {
value: any;
key: string | number | undefined;
type: string;
schema: S;
coercer: (value: unknown) => unknown;
validator: (value: unknown, context: StructContext) => StructResult;
refiner: (value: T, context: StructContext) => StructResult;
constructor(props: {
type: Struct<T>["type"];
schema: S;
coercer?: Struct<T>["coercer"];
validator?: Struct<T>["validator"];
refiner?: Struct<T>["refiner"];
});
}
refinement: string | undefined;
message: string;
branch: Array<any>;
path: Array<string | number>;
};
/**
* `StructError` objects are thrown (or returned) by Superstruct when its
* validation fails. The error represents the first error encountered during
* validation. But they also have an `error.failures` property that holds
* information for all of the failures encountered.
* `StructError` objects are thrown (or returned) when validation fails.
*
* Validation logic is design to exit early for maximum performance. The error
* represents the first error encountered during validation. For more detail,
* the `error.failures` property is a generator function that can be run to
* continue validation and receive all the failures in the data.
*/
declare class StructError extends TypeError {
value: any;
key: string | number | undefined;
type: string;
refinement: string | undefined;
path: Array<number | string>;
branch: Array<any>;
failures: () => Array<StructFailure>;
failures: () => Array<Failure>;
[key: string]: any;
constructor(failure: StructFailure, moreFailures: IterableIterator<StructFailure>);
constructor(failure: Failure, moreFailures: IterableIterator<Failure>);
}
/**
* `Struct` objects encapsulate the validation logic for a specific type of
* values. Once constructed, you use the `assert`, `is` or `validate` helpers to
* validate unknown input data against the struct.
*/
declare class Struct<T = unknown, S = unknown> {
readonly TYPE: T;
type: string;
schema: S;
coercer: Coercer;
validator: Validator<T, S>;
refiner: Refiner<T, S>;
constructor(props: {
type: Struct<T, S>["type"];
schema: Struct<T, S>["schema"];
coercer?: Struct<T, S>["coercer"];
validator?: Struct<T, S>["validator"];
refiner?: Struct<T, S>["refiner"];
});
/**
* Assert that a value passes the struct's validation, throwing if it doesn't.
*/
assert(value: unknown): value is T;
/**
* Create a value with the struct's coercion logic, then validate it.
*/
create(value: unknown): T;
/**
* Check if a value passes the struct's validation.
*/
is(value: unknown): value is T;
/**
* Mask a value, coercing and validating it, but returning only the subset of
* properties defined by the struct's schema.
*/
mask(value: unknown): T;
/**
* Validate a value with the struct's validation logic, returning a tuple
* representing the result.
*
* You may optionally pass `true` for the `withCoercion` argument to coerce
* the value before attempting to validate it. If you do, the result will
* contain the coerced result when successful.
*/
validate(value: unknown, options?: {
coerce?: boolean;
}): [StructError, undefined] | [undefined, T];
}
/**
* A `StructContext` contains information about the current value being
* validated as well as helper functions for failures and recursive validating.
*/
type StructContext = {
type Context<T, S> = {
value: any;
type: string;
struct: Struct<T, S>;
branch: Array<any>;
path: Array<string | number>;
fail: (props?: Partial<StructFailure>) => StructFailure;
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => IterableIterator<StructFailure>;
fail: (props?: string | Partial<Failure>) => Failure;
check: <Y, Z>(value: any, struct: Struct<Y, Z>, parent?: any, key?: string | number) => IterableIterator<Failure>;
};
/**
* A `StructFailure` represents a single specific failure in validation.
* A type utility to extract the type from a `Struct` class.
*/
type StructFailure = {
value: StructContext["value"];
type: StructContext["type"];
branch: StructContext["branch"];
path: StructContext["path"];
[key: string]: any;
};
type Infer<T extends Struct<any, any>> = T["TYPE"];
/**
* A `StructResult` is returned from validation functions.
* A `Result` is returned from validation functions.
*/
type StructResult = boolean | Iterable<StructFailure>;
type Result = boolean | string | Iterable<Failure>;
/**
* A type utility to extract the type from a `Struct` class.
* A `Coercer` takes an unknown value and optionally coerces it.
*/
type StructType<T extends Struct<any>> = Parameters<T["refiner"]>[0];
type Coercer = (value: unknown) => unknown;
/**
* A `Validate` takes an unknown value and validates it.
*/
type Validator<T, S> = (value: unknown, context: Context<T, S>) => Result;
/**
* A `Refiner` takes a value of a known type and validates it against a further
* constraint.
*/
type Refiner<T, S> = (value: T, context: Context<T, S>) => Result;
/**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
declare function assert<T>(value: unknown, struct: Struct<T>): value is T;
declare function assert<T, S>(value: unknown, struct: Struct<T, S>): value is T;
/**
* Coerce a value with the coercion logic of `Struct` and validate it.
* Create a value with the coercion logic of `Struct` and validate it.
*/
declare function coerce<T>(value: unknown, struct: Struct<T>): T;
declare function create<T, S>(value: unknown, struct: Struct<T, S>): T;
/**
* Mask a value, returning only the subset of properties defined by a Struct.
*/
declare function mask<T, S>(value: unknown, struct: Struct<T, S>): T;
/**
* Check if a value passes a `Struct`.
*/
declare function is<T>(value: unknown, struct: Struct<T>): value is T;
declare function is<T, S>(value: unknown, struct: Struct<T, S>): value is T;
/**
* Validate a value against a `Struct`, returning an error if invalid.
*/
declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T];
declare function validate<T, S>(value: unknown, struct: Struct<T, S>, options?: {
coerce?: boolean;
}): [StructError, undefined] | [undefined, T];
/**
* Augment a `Struct` to add an additional coercion step to its input.
*
* This allows you to transform input data before validating it, to increase the
* likelihood that it passes validation—for example for default values, parsing
* different formats, etc.
*
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
declare function coercion<T>(struct: Struct<T>, coercer: Struct<T>["coercer"]): Struct<T>;
declare function coerce<T, S>(struct: Struct<T, S>, coercer: Struct<T, S>["coercer"]): Struct<T, S>;
/**
* Augment a struct to coerce a default value for missing values.
* Augment a struct to replace `undefined` values with a default.
*
* Note: You must use `coerce(value, Struct)` on the value before validating it
* to have the value defaulted!
* Note: You must use `coerce(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
declare function defaulted<T>(S: Struct<T>, fallback: any, strict?: true): Struct<T>;
declare function defaulted<T, S>(S: Struct<T, S>, fallback: any, options?: {
strict?: boolean;
}): Struct<T, S>;
/**
* Coerce a value to mask its properties to only that defined in the struct.
* Augment a struct to mask its input to only properties defined in the struct.
*
* Note: You must use `create(value, Struct)` on the value to have the coercion
* take effect! Using simply `assert()` or `is()` will not use coercion.
*/
declare function masked<T extends {
[key: string]: any;
}, V extends Record<string, Struct<any>>>(S: Struct<T, V>): Struct<T>;
declare function masked<T, S>(struct: Struct<T, S>): Struct<T, S>;
/**
* Augment a string or array struct to constrain its length to zero.
* Ensure that a string, array, map, or set is empty.
*/
declare function empty<T extends string | any[]>(S: Struct<T>): Struct<T>;
declare function empty<T extends string | any[] | Map<any, any> | Set<any>>(struct: Struct<T>): Struct<T>;
/**
* Augment a string or array struct to constrain its length to being between a
* minimum and maximum size.
* Ensure that a number or date is below a threshold.
*/
declare function length<T extends string | any[]>(S: Struct<T>, min: number, max: number): Struct<T>;
declare function max<T extends number | Date>(struct: Struct<T>, threshold: T, options?: {
exclusive?: boolean;
}): Struct<T>;
/**
* Refine a string struct to match a specific regexp pattern.
* Ensure that a number or date is above a threshold.
*/
declare function pattern<T extends string>(S: Struct<T>, regexp: RegExp): Struct<T>;
declare function min<T extends number | Date>(struct: Struct<T>, threshold: T, options?: {
exclusive?: boolean;
}): Struct<T>;
/**
* Ensure that a string matches a regular expression.
*/
declare function pattern<T extends string>(struct: Struct<T>, regexp: RegExp): Struct<T>;
/**
* Ensure that a string, array, number, date, map, or set has a size (or length, or time) between `min` and `max`.
*/
declare function size<T extends string | number | Date | any[] | Map<any, any> | Set<any>>(struct: Struct<T>, min: number, max?: number): Struct<T>;
/**
* Augment a `Struct` to add an additional refinement to the validation.
*
* The refiner function is guaranteed to receive a value of the struct's type,
* because the struct's existing validation will already have passed. This
* allows you to layer additional validation on top of existing structs.
*/
declare function refinement<T>(struct: Struct<T>, type: string, refiner: Struct<T>["refiner"]): Struct<T>;
type StructRecord<T> = Record<string, Struct<T>>;
type StructTuple<T> = {
declare function refine<T, S>(struct: Struct<T, S>, name: string, refiner: Refiner<T, S>): Struct<T, S>;
/**
* Normalize properties of a type that allow `undefined` to make them optional.
*/
type Optionalize<S extends object> = OmitBy<S, undefined> & Partial<PickBy<S, undefined>>;
/**
* Omit properties from a type that extend from a specific type.
*/
type OmitBy<T, V> = Omit<T, {
[K in keyof T]: V extends Extract<T[K], V> ? K : never;
}[keyof T]>;
/**
* Pick properties from a type that extend from a specific type.
*/
type PickBy<T, V> = Pick<T, {
[K in keyof T]: V extends Extract<T[K], V> ? K : never;
}[keyof T]>;
/**
* Simplifies a type definition to its most basic representation.
*/
type Simplify<T> = T extends any[] | Date ? T : {
[Key in keyof T]: T[Key];
} & {};
/**
* Assign properties from one type to another, overwriting existing.
*/
type Assign<T, U> = Simplify<U & Omit<T, keyof U>>;
/**
* A schema for object structs.
*/
type ObjectSchema = Record<string, Struct<any, any>>;
/**
* Infer a type from an object struct schema.
*/
type ObjectType<S extends ObjectSchema> = Simplify<Optionalize<{
[K in keyof S]: Infer<S[K]>;
}>>;
/**
* Transform an object schema type to represent a partial.
*/
type PartialObjectSchema<S extends ObjectSchema> = {
[K in keyof S]: Struct<Infer<S[K]> | undefined>;
};
/**
* A schema for tuple structs.
*/
type TupleSchema<T> = {
[K in keyof T]: Struct<T[K]>;
};
/**
* Validate any value.
* Ensure that any value passes validation.
*/
declare function any(): Struct<any>;
declare function any(): Struct<any, null>;
/**
* Validate that an array of values of a specific type.
* Ensure that a value is an array and that its elements are of a specific type.
*
* Note: If you omit the element struct, the arrays elements will not be
* iterated at all. This can be helpful for cases where performance is critical,
* and it is preferred to using `array(any())`.
*/
declare function array(): Struct<unknown[]>;
declare function array<T>(Element: Struct<T>): Struct<T[], Struct<T>>;
declare function array<T extends Struct<any>>(Element: T): Struct<Infer<T>[], T>;
declare function array(): Struct<unknown[], undefined>;
/**
* Validate that boolean values.
* Ensure that a value is a boolean.
*/
declare function boolean(): Struct<boolean>;
declare function boolean(): Struct<boolean, null>;
/**
* Validate that `Date` values.
* Ensure that a value is a valid `Date`.
*

@@ -138,179 +265,214 @@ * Note: this also ensures that the value is *not* an invalid `Date` object,

*/
declare function date(): Struct<Date>;
declare function date(): Struct<Date, null>;
/**
* Validate that a value dynamically, determing which struct to use at runtime.
* Ensure that a value is one of a set of potential values.
*
* Note: after creating the struct, you can access the definition of the
* potential values as `struct.schema`.
*/
declare function dynamic<T>(fn: (value: unknown, ctx: StructContext) => Struct<T>): Struct<T>;
declare function enums<T extends number>(values: T[]): Struct<T, {
[K in T[][number]]: K;
}>;
declare function enums<T extends string>(values: T[]): Struct<T, {
[K in T[][number]]: K;
}>;
/**
* Validate that a value against a set of potential values.
* Ensure that a value is a function.
*/
declare function enums<T extends number>(values: T[]): Struct<T>;
declare function enums<T extends string>(values: T[]): Struct<T>;
declare function func(): Struct<Function, null>;
/**
* Validate that a value is a function.
* Ensure that a value is an instance of a specific class.
*/
declare function func(): Struct<Function>;
/**
* Validate that a value is an instance of a class.
*/
declare function instance<T extends {
new (...args: any): any;
}>(Class: T): Struct<InstanceType<T>>;
}>(Class: T): Struct<InstanceType<T>, null>;
/**
* Validate that a value matches all of a set of structs.
* Ensure that a value is an integer.
*/
declare function intersection<A>(Structs: StructTuple<[A]>): Struct<A>;
declare function intersection<A, B>(Structs: StructTuple<[A, B]>): Struct<A & B>;
declare function intersection<A, B, C>(Structs: StructTuple<[A, B, C]>): Struct<A & B & C>;
declare function intersection<A, B, C, D>(Structs: StructTuple<[A, B, C, D]>): Struct<A & B & C & D>;
declare function intersection<A, B, C, D, E>(Structs: StructTuple<[A, B, C, D, E]>): Struct<A & B & C & D & E>;
declare function intersection<A, B, C, D, E, F>(Structs: StructTuple<[A, B, C, D, E, F]>): Struct<A & B & C & D & E & F>;
declare function intersection<A, B, C, D, E, F, G>(Structs: StructTuple<[A, B, C, D, E, F, G]>): Struct<A & B & C & D & E & F & G>;
declare function intersection<A, B, C, D, E, F, G, H>(Structs: StructTuple<[A, B, C, D, E, F, G, H]>): Struct<A & B & C & D & E & F & G & H>;
declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I]>): Struct<A & B & C & D & E & F & G & H & I>;
declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J]>): Struct<A & B & C & D & E & F & G & H & I & J>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A & B & C & D & E & F & G & H & I & J & K>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q>;
declare function integer(): Struct<number, null>;
/**
* Validate a value lazily, by constructing the struct right before the first
* validation. This is useful for cases where you want to have self-referential
* structs for nested data structures.
* Ensure that a value matches all of a set of types.
*/
declare function lazy<T>(fn: () => Struct<T>): Struct<T>;
declare function intersection<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
declare function intersection<A, B>(Structs: TupleSchema<[A, B]>): Struct<A & B, null>;
declare function intersection<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<A & B & C, null>;
declare function intersection<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<A & B & C & D, null>;
declare function intersection<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<A & B & C & D & E, null>;
declare function intersection<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<A & B & C & D & E & F, null>;
declare function intersection<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<A & B & C & D & E & F & G, null>;
declare function intersection<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<A & B & C & D & E & F & G & H, null>;
declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<A & B & C & D & E & F & G & H & I, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<A & B & C & D & E & F & G & H & I & J, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A & B & C & D & E & F & G & H & I & J & K, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q, null>;
/**
* Validate that a value is a specific constant.
* Ensure that a value is an exact value, using `===` for comparison.
*/
declare function literal<T extends boolean>(constant: T): Struct<T>;
declare function literal<T extends number>(constant: T): Struct<T>;
declare function literal<T extends string>(constant: T): Struct<T>;
declare function literal<T>(constant: T): Struct<T>;
declare function literal<T extends boolean>(constant: T): Struct<T, null>;
declare function literal<T extends number>(constant: T): Struct<T, null>;
declare function literal<T extends string>(constant: T): Struct<T, null>;
declare function literal<T>(constant: T): Struct<T, null>;
/**
* Validate that a value is a map with specific key and value entries.
* Ensure that a value is a `Map` object, and that its keys and values are of
* specific types.
*/
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>>;
declare function map(): Struct<Map<unknown, unknown>, null>;
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>, null>;
/**
* Validate that a value always fails.
* Ensure that no value ever passes validation.
*/
declare function never(): Struct<never>;
declare function never(): Struct<never, null>;
/**
* Augment a struct to make it accept `null` values.
* Augment an existing struct to allow `null` values.
*/
declare function nullable<T>(S: Struct<T>): Struct<T | null>;
declare function nullable<T, S>(struct: Struct<T, S>): Struct<T | null, S>;
/**
* Validate that a value is a number.
* Ensure that a value is a number.
*/
declare function number(): Struct<number>;
declare function number(): Struct<number, null>;
/**
* Type helper to Flatten the Union of optional and required properties.
* Ensure that a value is an object, that is has a known set of properties,
* and that its properties are of specific types.
*
* Note: Unrecognized properties will fail validation.
*/
type Flatten<T> = T extends infer U ? {
[K in keyof U]: U[K];
} : never;
declare function object(): Struct<Record<string, unknown>, null>;
declare function object<S extends ObjectSchema>(schema: S): Struct<ObjectType<S>, S>;
/**
* Type helper to extract the optional keys of an object
* Augment a struct to allow `undefined` values.
*/
type OptionalKeys<T> = {
[K in keyof T]: undefined extends T[K] ? K : never;
}[keyof T];
declare function optional<T, S>(struct: Struct<T, S>): Struct<T | undefined, S>;
/**
* Type helper to extract the required keys of an object
* Ensure that a value is an object with keys and values of specific types, but
* without ensuring any specific shape of properties.
*
* Like TypeScript's `Record` utility.
*/
type RequiredKeys<T> = {
[K in keyof T]: undefined extends T[K] ? never : K;
}[keyof T];
declare function record<K extends string, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>, null>;
/**
* Type helper to create optional properties when the property value can be
* undefined (ie. when `optional()` is used to define a type)
* Ensure that a value is a `RegExp`.
*
* Note: this does not test the value against the regular expression! For that
* you need to use the `pattern()` refinement.
*/
type OptionalizeObject<T> = Flatten<{
[K in RequiredKeys<T>]: T[K];
} & {
[K in OptionalKeys<T>]?: T[K];
}>;
declare function regexp(): Struct<RegExp, null>;
/**
* Validate that an object with specific entry values.
* Ensure that a value is a `Set` object, and that its elements are of a
* specific type.
*/
declare function object<V extends StructRecord<any>>(): Struct<Record<string, unknown>>;
declare function object<V extends StructRecord<any>>(Structs: V): Struct<OptionalizeObject<{
[K in keyof V]: StructType<V[K]>;
}>, V>;
declare function set(): Struct<Set<unknown>, null>;
declare function set<T>(Element: Struct<T>): Struct<Set<T>, null>;
/**
* Augment a struct to make it optionally accept `undefined` values.
* Ensure that a value is a string.
*/
declare function optional<T>(S: Struct<T>): Struct<T | undefined>;
declare function string(): Struct<string, null>;
/**
* Validate that a partial object with specific entry values.
* Ensure that a value is a tuple of a specific length, and that each of its
* elements is of a specific type.
*/
declare function partial<T, V extends StructRecord<any>>(Structs: V | Struct<T, V>): Struct<{
[K in keyof V]?: StructType<V[K]>;
}>;
declare function tuple<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
declare function tuple<A, B>(Structs: TupleSchema<[A, B]>): Struct<[A, B], null>;
declare function tuple<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<[A, B, C], null>;
declare function tuple<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<[A, B, C, D], null>;
declare function tuple<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<[A, B, C, D, E], null>;
declare function tuple<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<[A, B, C, D, E, F], null>;
declare function tuple<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<[A, B, C, D, E, F, G], null>;
declare function tuple<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<[A, B, C, D, E, F, G, H], null>;
declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<[A, B, C, D, E, F, G, H, I], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<[A, B, C, D, E, F, G, H, I, J], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<[A, B, C, D, E, F, G, H, I, J, K], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q], null>;
/**
* Validate that a value is a record with specific key and
* value entries.
* Ensure that a value has a set of known properties of specific types.
*
* Note: Unrecognized properties are allowed and untouched. This is similar to
* how TypeScript's structural typing works.
*/
declare function record<K extends string | number, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>>;
declare function type<S extends ObjectSchema>(schema: S): Struct<ObjectType<S>, S>;
/**
* Validate that a set of values matches a specific type.
* Ensure that a value matches one of a set of types.
*/
declare function set<T>(Element: Struct<T>): Struct<Set<T>>;
declare function union<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
declare function union<A, B>(Structs: TupleSchema<[A, B]>): Struct<A | B, null>;
declare function union<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<A | B | C, null>;
declare function union<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<A | B | C | D, null>;
declare function union<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<A | B | C | D | E, null>;
declare function union<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<A | B | C | D | E | F, null>;
declare function union<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<A | B | C | D | E | F | G, null>;
declare function union<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<A | B | C | D | E | F | G | H, null>;
declare function union<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<A | B | C | D | E | F | G | H | I, null>;
declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<A | B | C | D | E | F | G | H | I | J, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A | B | C | D | E | F | G | H | I | J | K, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q, null>;
/**
* Validate that a value is a string.
* Ensure that any value passes validation, without widening its type to `any`.
*/
declare function string(): Struct<string>;
declare function unknown(): Struct<unknown, null>;
/**
* Define a `Struct` instance with a type and validation function.
* Create a new struct that combines the properties properties from multiple
* object structs.
*
* Like JavaScript's `Object.assign` utility.
*/
declare function struct<T>(name: string, validator: Struct<T>["validator"]): Struct<T, null>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>): Struct<ObjectType<Assign<A, B>>, Assign<A, B>>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>): Struct<ObjectType<Assign<Assign<A, B>, C>>, Assign<Assign<A, B>, C>>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>, D: Struct<ObjectType<D>, D>): Struct<ObjectType<Assign<Assign<Assign<A, B>, C>, D>>, Assign<Assign<Assign<A, B>, C>, D>>;
declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema, E extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>, D: Struct<ObjectType<D>, D>, E: Struct<ObjectType<E>, E>): Struct<ObjectType<Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>, Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>;
/**
* Validate that a value is a tuple with entries of specific types.
* Define a new struct with a custom validation function.
*/
declare function tuple<A>(Structs: StructTuple<[A]>): Struct<A>;
declare function tuple<A, B>(Structs: StructTuple<[A, B]>): Struct<[A, B]>;
declare function tuple<A, B, C>(Structs: StructTuple<[A, B, C]>): Struct<[A, B, C]>;
declare function tuple<A, B, C, D>(Structs: StructTuple<[A, B, C, D]>): Struct<[A, B, C, D]>;
declare function tuple<A, B, C, D, E>(Structs: StructTuple<[A, B, C, D, E]>): Struct<[A, B, C, D, E]>;
declare function tuple<A, B, C, D, E, F>(Structs: StructTuple<[A, B, C, D, E, F]>): Struct<[A, B, C, D, E, F]>;
declare function tuple<A, B, C, D, E, F, G>(Structs: StructTuple<[A, B, C, D, E, F, G]>): Struct<[A, B, C, D, E, F, G]>;
declare function tuple<A, B, C, D, E, F, G, H>(Structs: StructTuple<[A, B, C, D, E, F, G, H]>): Struct<[A, B, C, D, E, F, G, H]>;
declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I]>): Struct<[A, B, C, D, E, F, G, H, I]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J]>): Struct<[A, B, C, D, E, F, G, H, I, J]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<[A, B, C, D, E, F, G, H, I, J, K]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>;
declare function define<T>(name: string, validator: Validator<T, null>): Struct<T, null>;
/**
* Validate that a value matches a specific strutural interface, like the
* structural typing that TypeScript uses.
* Create a struct with dynamic, runtime validation.
*
* The callback will receive the value currently being validated, and must
* return a struct object to validate it with. This can be useful to model
* validation logic that changes based on its input.
*/
declare function type<V extends StructRecord<any>>(Structs: V): Struct<{
[K in keyof V]: StructType<V[K]>;
}>;
declare function dynamic<T>(fn: (value: unknown, ctx: Context<T, null>) => Struct<T, any>): Struct<T, null>;
/**
* Validate that a value is one of a set of types.
* Create a struct with lazily evaluated validation.
*
* The first time validation is run with the struct, the callback will be called
* and must return a struct object to use. This is useful for cases where you
* want to have self-referential structs for nested data structures to avoid a
* circular definition problem.
*/
declare function union<A>(Structs: StructTuple<[A]>): Struct<A>;
declare function union<A, B>(Structs: StructTuple<[A, B]>): Struct<A | B>;
declare function union<A, B, C>(Structs: StructTuple<[A, B, C]>): Struct<A | B | C>;
declare function union<A, B, C, D>(Structs: StructTuple<[A, B, C, D]>): Struct<A | B | C | D>;
declare function union<A, B, C, D, E>(Structs: StructTuple<[A, B, C, D, E]>): Struct<A | B | C | D | E>;
declare function union<A, B, C, D, E, F>(Structs: StructTuple<[A, B, C, D, E, F]>): Struct<A | B | C | D | E | F>;
declare function union<A, B, C, D, E, F, G>(Structs: StructTuple<[A, B, C, D, E, F, G]>): Struct<A | B | C | D | E | F | G>;
declare function union<A, B, C, D, E, F, G, H>(Structs: StructTuple<[A, B, C, D, E, F, G, H]>): Struct<A | B | C | D | E | F | G | H>;
declare function union<A, B, C, D, E, F, G, H, I>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I]>): Struct<A | B | C | D | E | F | G | H | I>;
declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J]>): Struct<A | B | C | D | E | F | G | H | I | J>;
declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A | B | C | D | E | F | G | H | I | J | K>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q>;
export { coercion, defaulted, masked, empty, length, pattern, refinement, Struct, StructError, StructContext, StructFailure, StructResult, StructType, assert, coerce, is, validate, any, array, boolean, date, dynamic, enums, func, instance, intersection, lazy, literal, map, never, nullable, number, object, optional, partial, record, set, string, struct, tuple, type, union };
declare function lazy<T>(fn: () => Struct<T, any>): Struct<T, null>;
/**
* Create a new struct based on an existing object struct, but excluding
* specific properties.
*
* Like TypeScript's `Omit` utility.
*/
declare function omit<S extends ObjectSchema, K extends keyof S>(struct: Struct<ObjectType<S>, S>, keys: K[]): Struct<ObjectType<Omit<S, K>>, Omit<S, K>>;
/**
* Create a new struct based on an existing object struct, but with all of its
* properties allowed to be `undefined`.
*
* Like TypeScript's `Partial` utility.
*/
declare function partial<S extends ObjectSchema>(struct: Struct<ObjectType<S>, S> | S): Struct<ObjectType<PartialObjectSchema<S>>, PartialObjectSchema<S>>;
/**
* Create a new struct based on an existing object struct, but only including
* specific properties.
*
* Like TypeScript's `Pick` utility.
*/
declare function pick<S extends ObjectSchema, K extends keyof S>(struct: Struct<ObjectType<S>, S>, keys: K[]): Struct<ObjectType<Pick<S, K>>, Pick<S, K>>;
export { Failure, StructError, Struct, Context, Infer, Result, Coercer, Validator, Refiner, assert, create, mask, is, validate, coerce, defaulted, masked, empty, max, min, pattern, size, refine, any, array, boolean, date, enums, func, instance, integer, intersection, literal, map, never, nullable, number, object, optional, record, regexp, set, string, tuple, type, union, unknown, assign, define, dynamic, lazy, omit, partial, pick };

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Superstruct={})}(this,(function(e){"use strict";function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var n=1;n<arguments.length;n++){var a=null!=arguments[n]?arguments[n]:{};n%2?r(Object(a),!0).forEach((function(r){t(e,r,a[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):r(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function o(e,t,r){return(o=c()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var a=new(Function.bind.apply(e,n));return r&&u(a,r.prototype),a}).apply(null,arguments)}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return o(e,arguments,a(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,e)})(e)}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function s(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return f(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?f(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}var l=regeneratorRuntime.mark(p);function p(e,t){return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(!0!==e){r.next=3;break}r.next=9;break;case 3:if(!1!==e){r.next=8;break}return r.next=6,t.fail();case 6:r.next=9;break;case 8:return r.delegateYield(e,"t0",9);case 9:case"end":return r.stop()}}),l)}function d(e){var t=e.next(),r=t.done,n=t.value;return r?void 0:n}var b=regeneratorRuntime.mark(k),y=function(e){var t=e.type,r=e.schema,n=e.coercer,a=void 0===n?function(e){return e}:n,u=e.validator,c=void 0===u?function(){return[]}:u,o=e.refiner,i=void 0===o?function(){return[]}:o;this.type=t,this.schema=r,this.coercer=a,this.validator=c,this.refiner=i},v=function(e){var t,r;function n(t,r){var a,u,c=t.path,o=t.value,i=t.type,f=t.branch,s=function(e,t){if(null==e)return{};var r,n,a={},u=Object.keys(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(t,["path","value","type","branch"]),l="Expected a value of type `"+i+"`"+(c.length?" for `"+c.join(".")+"`":"")+" but received `"+JSON.stringify(o)+"`.";return(a=e.call(this,l)||this).value=o,Object.assign(function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(a),s),a.type=i,a.path=c,a.branch=f,a.failures=function(){return u||(u=[t].concat(r)),u},a.stack=(new Error).stack,a.__proto__=n.prototype,a}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r,n}(i(TypeError));function h(e,t){var r=g(e,t);if(r[0])throw r[0]}function m(e,t){var r=t.coercer(e);return h(r,t),r}function g(e,t,r){void 0===r&&(r=!1),r&&(e=t.coercer(e));var n=k(e,t),a=d(n);return a?[new v(a,n),void 0]:[void 0,e]}function k(e,t,r,a){var u,c,o,i;return regeneratorRuntime.wrap((function(f){for(;;)switch(f.prev=f.next){case 0:if(void 0===r&&(r=[]),void 0===a&&(a=[]),u=t.type,c={value:e,type:u,branch:a,path:r,fail:function(t){return void 0===t&&(t={}),n({value:e,type:u,path:r,branch:[].concat(a,[e])},t)},check:function(e,t,n,u){return k(e,t,void 0!==n?[].concat(r,[u]):r,void 0!==n?[].concat(a,[n]):a)}},o=p(t.validator(e,c),c),!(i=d(o))){f.next=12;break}return f.next=9,i;case 9:return f.delegateYield(o,"t0",10);case 10:f.next=13;break;case 12:return f.delegateYield(p(t.refiner(e,c),c),"t1",13);case 13:case"end":return f.stop()}}),b)}function x(e,t){var r=e.coercer;return new y(n(n({},e),{},{coercer:function(e){return r(t(e))}}))}function w(e){if("[object Object]"!==Object.prototype.toString.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function j(e,t,r){var a=e.refiner;return new y(n(n({},e),{},{type:t,refiner:regeneratorRuntime.mark((function e(t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(p(a(t,n),n),"t0",1);case 1:return e.delegateYield(p(r(t,n),n),"t1",2);case 2:case"end":return e.stop()}}),e)}))}))}function O(){return R("never",(function(){return!1}))}function R(e,t){return new y({type:e,validator:t,schema:null})}function S(e){return"string"==typeof e?'"'+e.replace(/"/g,'"')+'"':""+e}function P(e){var t=Object.keys(e);return function(r){if("object"!=typeof r||null==r)return r;for(var n,a={},u=new Set(Object.keys(r)),c=s(t);!(n=c()).done;){var o=n.value;u.delete(o);var i=e[o],f=r[o];a[o]=m(f,i)}for(var l,p=s(u);!(l=p()).done;){var d=l.value;a[d]=r[d]}return a}}e.Struct=y,e.StructError=v,e.any=function(){return R("any",(function(){return!0}))},e.array=function(e){return new y({type:"Array<"+(e?e.type:"unknown")+">",schema:e,coercer:function(t){return e&&Array.isArray(t)?t.map((function(t){return m(t,e)})):t},validator:regeneratorRuntime.mark((function t(r,n){var a,u,c,o,i;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(Array.isArray(r)){t.next=4;break}return t.next=3,n.fail();case 3:return t.abrupt("return");case 4:if(!e){t.next=11;break}a=s(r.entries());case 6:if((u=a()).done){t.next=11;break}return c=u.value,o=c[0],i=c[1],t.delegateYield(n.check(i,e,r,o),"t0",9);case 9:t.next=6;break;case 11:case"end":return t.stop()}}),t)}))})},e.assert=h,e.boolean=function(){return R("boolean",(function(e){return"boolean"==typeof e}))},e.coerce=m,e.coercion=x,e.date=function(){return R("Date",(function(e){return e instanceof Date&&!isNaN(e.getTime())}))},e.defaulted=function(e,t,r){return x(e,(function(e){var a="function"==typeof t?t():t;if(void 0===e)return a;if(!0!==r&&w(e)&&w(a)){var u=n({},e),c=!1;for(var o in a)void 0===u[o]&&(u[o]=a[o],c=!0);if(c)return u}return e}))},e.dynamic=function(e){return R("Dynamic<...>",(function(t,r){return r.check(t,e(t,r))}))},e.empty=function(e){return j(e,e.type+" & Empty",(function(e){return 0===e.length}))},e.enums=function(e){return R("Enum<"+e.map(S)+">",(function(t){return e.includes(t)}))},e.func=function(){return R("Function",(function(e){return"function"==typeof e}))},e.instance=function(e){return R("InstanceOf<"+e.name+">",(function(t){return t instanceof e}))},e.intersection=function(e){return R(e.map((function(e){return e.type})).join(" & "),regeneratorRuntime.mark((function t(r,n){var a,u,c;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a=s(e);case 1:if((u=a()).done){t.next=6;break}return c=u.value,t.delegateYield(n.check(r,c),"t0",4);case 4:t.next=1;break;case 6:case"end":return t.stop()}}),t)})))},e.is=function(e,t){return!g(e,t)[0]},e.lazy=function(e){var t;return R("Lazy<...>",(function(r,n){return t||(t=e()),n.check(r,t)}))},e.length=function(e,t,r){return j(e,e.type+" & Length<"+t+","+r+">",(function(e){return t<e.length&&e.length<r}))},e.literal=function(e){return R("Literal<"+S(e)+">",(function(t){return t===e}))},e.map=function(e,t){return R("Map<"+e.type+","+t.type+">",regeneratorRuntime.mark((function r(n,a){var u,c,o,i,f;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(n instanceof Map){r.next=4;break}return r.next=3,a.fail();case 3:return r.abrupt("return");case 4:u=s(n.entries());case 5:if((c=u()).done){r.next=11;break}return o=c.value,i=o[0],f=o[1],r.delegateYield(a.check(i,e,n,i),"t0",8);case 8:return r.delegateYield(a.check(f,t,n,i),"t1",9);case 9:r.next=5;break;case 11:case"end":return r.stop()}}),r)})))},e.masked=function(e){return x(e,(function(t){if(!w(t))return t;var r={};for(var n in e.schema)r[n]=t[n];return r}))},e.never=O,e.nullable=function(e){return new y({type:e.type+" | null",schema:e.schema,validator:function(t,r){return null===t||r.check(t,e)}})},e.number=function(){return R("number",(function(e){return"number"==typeof e&&!isNaN(e)}))},e.object=function(e){var t=e?Object.keys(e):[],r=O();return new y({type:e?"Object<{"+t.join(",")+"}>":"Object",schema:e||null,coercer:e?P(e):function(e){return e},validator:regeneratorRuntime.mark((function n(a,u){var c,o,i,f,l,p,d,b,y,v;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("object"==typeof a&&null!=a){n.next=4;break}return n.next=3,u.fail();case 3:return n.abrupt("return");case 4:if(!e){n.next=22;break}c=new Set(Object.keys(a)),o=s(t);case 7:if((i=o()).done){n.next=15;break}return f=i.value,c.delete(f),l=e[f],p=a[f],n.delegateYield(u.check(p,l,a,f),"t0",13);case 13:n.next=7;break;case 15:d=s(c);case 16:if((b=d()).done){n.next=22;break}return y=b.value,v=a[y],n.delegateYield(u.check(v,r,a,y),"t1",20);case 20:n.next=16;break;case 22:case"end":return n.stop()}}),n)}))})},e.optional=function(e){return new y({type:e.type+"?",schema:e.schema,validator:function(t,r){return void 0===t||r.check(t,e)}})},e.partial=function(e){e instanceof y&&(e=e.schema);var t=Object.keys(e),r=O();return new y({type:"Partial<{"+t.join(",")+"}>",schema:e,coercer:P(e),validator:regeneratorRuntime.mark((function n(a,u){var c,o,i,f,l,p,d,b,y,v;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("object"==typeof a&&null!=a){n.next=4;break}return n.next=3,u.fail();case 3:return n.abrupt("return");case 4:c=new Set(Object.keys(a)),o=s(t);case 6:if((i=o()).done){n.next=16;break}if(f=i.value,c.delete(f),f in a){n.next=11;break}return n.abrupt("continue",14);case 11:return l=e[f],p=a[f],n.delegateYield(u.check(p,l,a,f),"t0",14);case 14:n.next=6;break;case 16:d=s(c);case 17:if((b=d()).done){n.next=23;break}return y=b.value,v=a[y],n.delegateYield(u.check(v,r,a,y),"t1",21);case 21:n.next=17;break;case 23:case"end":return n.stop()}}),n)}))})},e.pattern=function(e,t){return j(e,e.type+" & Pattern<"+t.source+">",(function(e){return t.test(e)}))},e.record=function(e,t){return R("Record<"+e.type+","+t.type+">",regeneratorRuntime.mark((function r(n,a){var u,c;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if("object"==typeof n&&null!=n){r.next=4;break}return r.next=3,a.fail();case 3:return r.abrupt("return");case 4:r.t0=regeneratorRuntime.keys(n);case 5:if((r.t1=r.t0()).done){r.next=12;break}return u=r.t1.value,c=n[u],r.delegateYield(a.check(u,e,n,u),"t2",9);case 9:return r.delegateYield(a.check(c,t,n,u),"t3",10);case 10:r.next=5;break;case 12:case"end":return r.stop()}}),r)})))},e.refinement=j,e.set=function(e){return R("Set<"+e.type+">",(function(t,r){if(!(t instanceof Set))return!1;for(var n,a=s(t);!(n=a()).done;){var u=n.value;if(r.check(u,e)[0])return!1}return!0}))},e.string=function(){return R("string",(function(e){return"string"==typeof e}))},e.struct=R,e.tuple=function(e){var t=O();return R("["+e.map((function(e){return e.type})).join(",")+"]",regeneratorRuntime.mark((function r(n,a){var u,c,o,i,f,l,p,d;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(Array.isArray(n)){r.next=4;break}return r.next=3,a.fail();case 3:return r.abrupt("return");case 4:u=s(e.entries());case 5:if((c=u()).done){r.next=11;break}return o=c.value,i=o[0],f=o[1],l=n[i],r.delegateYield(a.check(l,f,n,i),"t0",9);case 9:r.next=5;break;case 11:if(!(n.length>e.length)){r.next=15;break}return p=e.length,d=n[p],r.delegateYield(a.check(d,t,n,p),"t1",15);case 15:case"end":return r.stop()}}),r)})))},e.type=function(e){var t=Object.keys(e);return R("Type<{"+t.join(",")+"}>",regeneratorRuntime.mark((function r(n,a){var u,c,o,i,f;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if("object"==typeof n&&null!=n){r.next=4;break}return r.next=3,a.fail();case 3:return r.abrupt("return");case 4:u=s(t);case 5:if((c=u()).done){r.next=12;break}return o=c.value,i=e[o],f=n[o],r.delegateYield(a.check(f,i,n,o),"t0",10);case 10:r.next=5;break;case 12:case"end":return r.stop()}}),r)})))},e.union=function(e){return R(""+e.map((function(e){return e.type})).join(" | "),regeneratorRuntime.mark((function t(r,n){var a,u,c,o;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a=s(e);case 1:if((u=a()).done){t.next=8;break}if(c=u.value,o=n.check(r,c),0!==o.slice(0).length){t.next=6;break}return t.abrupt("return");case 6:t.next=1;break;case 8:return t.next=10,n.fail();case 10:case"end":return t.stop()}}),t)})))},e.validate=g,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Superstruct={})}(this,(function(e){"use strict";function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var n=1;n<arguments.length;n++){var a=null!=arguments[n]?arguments[n]:{};n%2?r(Object(a),!0).forEach((function(r){t(e,r,a[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):r(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function u(e,t,r){return(u=i()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var a=new(Function.bind.apply(e,n));return r&&c(a,r.prototype),a}).apply(null,arguments)}function o(e){var t="function"==typeof Map?new Map:void 0;return(o=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return u(e,arguments,a(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,e)})(e)}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function s(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return f(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?f(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}var l=function(e){var t,r;function n(t,r){var n,a,c=t.path,i=t.value,u=t.key,o=t.type,f=t.message,s=t.refinement,l=t.branch,p=function(e,t){if(null==e)return{};var r,n,a={},c=Object.keys(e);for(n=0;n<c.length;n++)r=c[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(t,["path","value","key","type","message","refinement","branch"]),d=0===c.length?f:"At path: "+c.join(".")+" -- "+f;return n=e.call(this,d)||this,Object.assign(function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(n),p),n.name=n.constructor.name,n.value=i,n.key=u,n.type=o,n.refinement=s,n.path=c,n.branch=l,n.failures=function(){return a||(a=[t].concat(r)),a},n}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r,n}(o(TypeError)),p=regeneratorRuntime.mark(y);function d(e){if("[object Object]"!==Object.prototype.toString.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function v(e,t){var r="string"==typeof e?JSON.stringify(e):""+e;return t?""+t+r+t:r}function b(e){var t=e.next(),r=t.done,n=t.value;return r?void 0:n}function y(e,t){return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if("string"!=typeof e){r.next=5;break}return r.next=3,t.fail({message:e});case 3:r.next=15;break;case 5:if(!0!==e){r.next=9;break}return r.abrupt("return");case 9:if(!1!==e){r.next=14;break}return r.next=12,t.fail();case 12:r.next=15;break;case 14:return r.delegateYield(e,"t0",15);case 15:case"end":return r.stop()}}),p)}function m(e,t){var r=e.coercer;return new x(n(n({},e),{},{coercer:function(e){return r(t(e))}}))}function h(e){return m(e,(function(t){if("object"!=typeof e.schema||null==e.schema||"object"!=typeof t||null==t)return t;var r={};for(var n in e.schema)n in t&&(r[n]=t[n]);return r}))}var g=regeneratorRuntime.mark(E),x=function(){function e(e){var t=e.type,r=e.schema,n=e.coercer,a=void 0===n?function(e){return e}:n,c=e.validator,i=void 0===c?function(){return[]}:c,u=e.refiner,o=void 0===u?function(){return[]}:u;this.type=t,this.schema=r,this.coercer=a,this.validator=i,this.refiner=o}var t=e.prototype;return t.assert=function(e){return k(e,this)},t.create=function(e){return w(e,this)},t.is=function(e){return O(e,this)},t.mask=function(e){return j(e,this)},t.validate=function(e,t){return void 0===t&&(t={}),R(e,this,t)},e}();function k(e,t){var r=R(e,t);if(r[0])throw r[0]}function w(e,t){var r=t.coercer(e);return k(r,t),r}function j(e,t){return w(e,h(t))}function O(e,t){return!R(e,t)[0]}function R(e,t,r){void 0===r&&(r={}),r.coerce&&(e=t.coercer(e));var n=E(e,t),a=b(n);return a?[new l(a,n),void 0]:[void 0,e]}function E(e,t,r,a){var c,i,u;return regeneratorRuntime.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(void 0===r&&(r=[]),void 0===a&&(a=[]),c={value:e,struct:t,branch:a,path:r,check:function(e,t,n,c){return E(e,t,void 0!==n?[].concat(r,[c]):r,void 0!==n?[].concat(a,[n]):a)},fail:function(c){void 0===c&&(c={}),"string"==typeof c&&(c={message:c});var i=t.type,u=c,o=u.message,f=u.refinement;return o||(o="Expected a value of type `"+i+"`"+(f?" with refinement `"+f+"`":"")+(r.length?" for `"+r.join(".")+"`":"")+", but received: `"+v(e)+"`"),n(n({},c),{},{value:e,type:i,refinement:f,message:o,key:r[r.length-1],path:r,branch:[].concat(a,[e])})}},i=y(t.validator(e,c),c),!(u=b(i))){o.next=11;break}return o.next=8,u;case 8:return o.delegateYield(i,"t0",9);case 9:o.next=12;break;case 11:return o.delegateYield(y(t.refiner(e,c),c),"t1",12);case 12:case"end":return o.stop()}}),g)}function S(e,t,r){var a=e.refiner;return new x(n(n({},e),{},{refiner:regeneratorRuntime.mark((function e(c,i){var u,o,f;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(y(a(c,i),i),"t0",1);case 1:u=s(y(r(c,i),i));case 2:if((o=u()).done){e.next=8;break}return f=o.value,e.next=6,n(n({},f),{},{refinement:t});case 6:e.next=2;break;case 8:case"end":return e.stop()}}),e)}))}))}function Y(e,t){return new x({type:e,schema:null,validator:t})}function P(){return Y("never",(function(){return!1}))}function A(e){var t=e?Object.keys(e):[],r=P();return new x({type:"object",schema:e||null,validator:regeneratorRuntime.mark((function n(a,c){var i,u,o,f,l,p,d,b,y,m;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("object"==typeof a&&null!=a){n.next=5;break}return n.next=3,c.fail("Expected an object, but received: "+v(a));case 3:n.next=23;break;case 5:if(!e){n.next=23;break}i=new Set(Object.keys(a)),u=s(t);case 8:if((o=u()).done){n.next=16;break}return f=o.value,i.delete(f),l=e[f],p=a[f],n.delegateYield(c.check(p,l,a,f),"t0",14);case 14:n.next=8;break;case 16:d=s(i);case 17:if((b=d()).done){n.next=23;break}return y=b.value,m=a[y],n.delegateYield(c.check(m,r,a,y),"t1",21);case 21:n.next=17;break;case 23:case"end":return n.stop()}}),n)})),coercer:function(r){if(!e||"object"!=typeof r||null==r)return r;for(var n,a={},c=new Set(Object.keys(r)),i=s(t);!(n=i()).done;){var u=n.value;c.delete(u);var o=e[u],f=r[u];a[u]=o.coercer(f)}for(var l,p=s(c);!(l=p()).done;){var d=l.value;a[d]=r[d]}return a}})}function _(e){var t=e.refiner;return new x(n(n({},e),{},{validator:function(t,r){return void 0===t||r.check(t,e)},refiner:function(e){var t=regeneratorRuntime.mark(r);function r(r,n){var a=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(e.apply(this,a),"t0",1);case 1:return t.abrupt("return",t.t0);case 2:case"end":return t.stop()}}),t,this)}return r.toString=function(){return e.toString()},r}(regeneratorRuntime.mark((function r(a,c){var i;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(null==a){r.next=3;break}return i=n(n({},c),{},{struct:e}),r.delegateYield(y(t(a,i),i),"t0",3);case 3:case"end":return r.stop()}}),r)})))}))}e.Struct=x,e.StructError=l,e.any=function(){return Y("any",(function(){return!0}))},e.array=function(e){return new x({type:"array",schema:e,coercer:function(t){return e&&Array.isArray(t)?t.map((function(t){return e.coercer(t)})):t},validator:regeneratorRuntime.mark((function t(r,n){var a,c,i,u,o;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(Array.isArray(r)){t.next=5;break}return t.next=3,n.fail("Expected an array value, but received: "+v(r));case 3:t.next=12;break;case 5:if(!e){t.next=12;break}a=s(r.entries());case 7:if((c=a()).done){t.next=12;break}return i=c.value,u=i[0],o=i[1],t.delegateYield(n.check(o,e,r,u),"t0",10);case 10:t.next=7;break;case 12:case"end":return t.stop()}}),t)}))})},e.assert=k,e.assign=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=t.map((function(e){return e.schema})),a=Object.assign.apply(Object,[{}].concat(n));return A(a)},e.boolean=function(){return Y("boolean",(function(e){return"boolean"==typeof e}))},e.coerce=m,e.create=w,e.date=function(){return Y("date",(function(e){return e instanceof Date&&!isNaN(e.getTime())||"Expected a valid `Date` object, but received: "+v(e)}))},e.defaulted=function(e,t,r){void 0===r&&(r={});var a=r.strict;return m(e,(function(e){var r="function"==typeof t?t():t;if(void 0===e)return r;if(!a&&d(e)&&d(r)){var c=n({},e),i=!1;for(var u in r)void 0===c[u]&&(c[u]=r[u],i=!0);if(i)return c}return e}))},e.define=Y,e.dynamic=function(e){return Y("dynamic",(function(t,r){return r.check(t,e(t,r))}))},e.empty=function(e){var t="Expected an empty "+e.type;return S(e,"empty",(function(e){if(e instanceof Map||e instanceof Set){var r=e.size;return 0===r||t+" but received one with a size of `"+r+"`"}var n=e.length;return 0===n||t+" but received one with a length of `"+n+"`"}))},e.enums=function(e){for(var t,r={},n=e.map((function(e){return v(e)})).join(),a=s(e);!(t=a()).done;){var c=t.value;r[c]=c}return new x({type:"enums",schema:r,validator:function(t){return e.includes(t)||"Expected one of `"+n+"`, but received: "+v(t)}})},e.func=function(){return Y("func",(function(e){return"function"==typeof e||"Expected a function, but received: "+v(e)}))},e.instance=function(e){return Y("instance",(function(t){return t instanceof e||"Expected a `"+e.name+"` instance, but received: "+v(t)}))},e.integer=function(){return Y("integer",(function(e){return"number"==typeof e&&!isNaN(e)&&Number.isInteger(e)||"Expected an integer, but received: "+v(e)}))},e.intersection=function(e){return Y("intersection",regeneratorRuntime.mark((function t(r,n){var a,c,i;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a=s(e);case 1:if((c=a()).done){t.next=6;break}return i=c.value,t.delegateYield(n.check(r,i),"t0",4);case 4:t.next=1;break;case 6:case"end":return t.stop()}}),t)})))},e.is=O,e.lazy=function(e){var t;return Y("lazy",(function(r,n){return t||(t=e()),n.check(r,t)}))},e.literal=function(e){var t=v(e);return Y("literal",(function(r){return r===e||"Expected the literal `"+t+"`, but received: "+v(r)}))},e.map=function(e,t){return Y("map",regeneratorRuntime.mark((function r(n,a){var c,i,u,o,f;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(n instanceof Map){r.next=5;break}return r.next=3,a.fail("Expected a `Map` object, but received: "+v(n));case 3:r.next=13;break;case 5:if(!e||!t){r.next=13;break}c=s(n.entries());case 7:if((i=c()).done){r.next=13;break}return u=i.value,o=u[0],f=u[1],r.delegateYield(a.check(o,e,n,o),"t0",10);case 10:return r.delegateYield(a.check(f,t,n,o),"t1",11);case 11:r.next=7;break;case 13:case"end":return r.stop()}}),r)})))},e.mask=j,e.masked=h,e.max=function(e,t,r){void 0===r&&(r={});var n=r.exclusive;return S(e,"max",(function(r){return n?r<t:r<=t||"Expected a "+e.type+" greater than "+(n?"":"or equal to ")+t+" but received `"+r+"`"}))},e.min=function(e,t,r){void 0===r&&(r={});var n=r.exclusive;return S(e,"min",(function(r){return n?r>t:r>=t||"Expected a "+e.type+" greater than "+(n?"":"or equal to ")+t+" but received `"+r+"`"}))},e.never=P,e.nullable=function(e){var t=e.refiner;return new x(n(n({},e),{},{validator:function(t,r){return null===t||r.check(t,e)},refiner:regeneratorRuntime.mark((function r(a,c){var i;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(null==a){r.next=3;break}return i=n(n({},c),{},{struct:e}),r.delegateYield(y(t(a,i),i),"t0",3);case 3:case"end":return r.stop()}}),r)}))}))},e.number=function(){return Y("number",(function(e){return"number"==typeof e&&!isNaN(e)||"Expected a number, but received: "+v(e)}))},e.object=A,e.omit=function(e,t){for(var r,a=n({},e.schema),c=s(t);!(r=c()).done;){delete a[r.value]}return A(a)},e.optional=_,e.partial=function(e){var t=n({},e instanceof x?e.schema:e);for(var r in t)t[r]=_(t[r]);return A(t)},e.pattern=function(e,t){return S(e,"pattern",(function(r){return t.test(r)||"Expected a "+e.type+" matching `/"+t.source+'/` but received "'+r+'"'}))},e.pick=function(e,t){for(var r,n=e.schema,a={},c=s(t);!(r=c()).done;){var i=r.value;a[i]=n[i]}return A(a)},e.record=function(e,t){return Y("record",regeneratorRuntime.mark((function r(n,a){var c,i;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if("object"==typeof n&&null!=n){r.next=5;break}return r.next=3,a.fail("Expected an object, but received: "+v(n));case 3:r.next=13;break;case 5:r.t0=regeneratorRuntime.keys(n);case 6:if((r.t1=r.t0()).done){r.next=13;break}return c=r.t1.value,i=n[c],r.delegateYield(a.check(c,e,n,c),"t2",10);case 10:return r.delegateYield(a.check(i,t,n,c),"t3",11);case 11:r.next=6;break;case 13:case"end":return r.stop()}}),r)})))},e.refine=S,e.regexp=function(){return Y("regexp",(function(e){return e instanceof RegExp}))},e.set=function(e){return Y("set",regeneratorRuntime.mark((function t(r,n){var a,c,i;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r instanceof Set){t.next=5;break}return t.next=3,n.fail("Expected a `Set` object, but received: "+v(r));case 3:t.next=12;break;case 5:if(!e){t.next=12;break}a=s(r);case 7:if((c=a()).done){t.next=12;break}return i=c.value,t.delegateYield(n.check(i,e,r,i),"t0",10);case 10:t.next=7;break;case 12:case"end":return t.stop()}}),t)})))},e.size=function(e,t,r){void 0===r&&(r=t);var n="Expected a "+e.type,a=t===r?"of `"+t+"`":"between `"+t+"` and `"+r+"`";return S(e,"size",(function(e){if("number"==typeof e||e instanceof Date)return t<=e&&e<=r||n+" "+a+" but received `"+e+"`";if(e instanceof Map||e instanceof Set){var c=e.size;return t<=c&&c<=r||n+" with a size "+a+" but received one with a size of `"+c+"`"}var i=e.length;return t<=i&&i<=r||n+" with a length "+a+" but received one with a length of `"+i+"`"}))},e.string=function(){return Y("string",(function(e){return"string"==typeof e||"Expected a string, but received: "+v(e)}))},e.tuple=function(e){var t=P();return Y("tuple",regeneratorRuntime.mark((function r(n,a){var c,i,u,o,f,l,p,d;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(Array.isArray(n)){r.next=5;break}return r.next=3,a.fail("Expected an array, but received: "+v(n));case 3:r.next=16;break;case 5:c=s(e.entries());case 6:if((i=c()).done){r.next=12;break}return u=i.value,o=u[0],f=u[1],l=n[o],r.delegateYield(a.check(l,f,n,o),"t0",10);case 10:r.next=6;break;case 12:if(!(n.length>e.length)){r.next=16;break}return p=e.length,d=n[p],r.delegateYield(a.check(d,t,n,p),"t1",16);case 16:case"end":return r.stop()}}),r)})))},e.type=function(e){var t=Object.keys(e);return new x({type:"type",schema:e,validator:regeneratorRuntime.mark((function r(n,a){var c,i,u,o,f;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if("object"==typeof n&&null!=n){r.next=5;break}return r.next=3,a.fail("Expected an object, but received: "+v(n));case 3:r.next=13;break;case 5:c=s(t);case 6:if((i=c()).done){r.next=13;break}return u=i.value,o=e[u],f=n[u],r.delegateYield(a.check(f,o,n,u),"t0",11);case 11:r.next=6;break;case 13:case"end":return r.stop()}}),r)}))})},e.union=function(e){var t=e.map((function(e){return e.type})).join(" | ");return Y("union",regeneratorRuntime.mark((function r(n,a){var c,i,u,o,f,l;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:c=[],i=s(e);case 2:if((u=i()).done){r.next=12;break}if(o=u.value,f=a.check(n,o),0!==(l=f.slice(0)).length){r.next=9;break}return r.abrupt("return");case 9:c.push.apply(c,l);case 10:r.next=2;break;case 12:return r.next=14,a.fail("Expected the value to satisfy a union of `"+t+"`, but received: "+v(n));case 14:return r.delegateYield(c,"t0",15);case 15:case"end":return r.stop()}}),r)})))},e.unknown=function(){return Y("unknown",(function(){return!0}))},e.validate=R,Object.defineProperty(e,"__esModule",{value:!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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc