2023-06-03 08:27:44 +00:00
|
|
|
## API Report File for "@tldraw/validate"
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
|
|
|
// @public
|
|
|
|
const any: Validator<any>;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
const array: Validator<unknown[]>;
|
|
|
|
|
|
|
|
// @public
|
2023-06-12 14:04:14 +00:00
|
|
|
function arrayOf<T>(itemValidator: Validatable<T>): ArrayOfValidator<T>;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
class ArrayOfValidator<T> extends Validator<T[]> {
|
2023-06-12 14:04:14 +00:00
|
|
|
constructor(itemValidator: Validatable<T>);
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
2023-06-12 14:04:14 +00:00
|
|
|
readonly itemValidator: Validatable<T>;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
|
|
|
lengthGreaterThan1(): Validator<T[]>;
|
|
|
|
// (undocumented)
|
|
|
|
nonEmpty(): Validator<T[]>;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public
|
|
|
|
const bigint: Validator<bigint>;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
const boolean: Validator<boolean>;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
const boxModel: ObjectValidator<{
|
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
w: number;
|
|
|
|
h: number;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
// @public
|
2023-06-12 14:04:14 +00:00
|
|
|
function dict<Key extends string, Value>(keyValidator: Validatable<Key>, valueValidator: Validatable<Value>): DictValidator<Key, Value>;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
class DictValidator<Key extends string, Value> extends Validator<Record<Key, Value>> {
|
2023-06-12 14:04:14 +00:00
|
|
|
constructor(keyValidator: Validatable<Key>, valueValidator: Validatable<Value>);
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
2023-06-12 14:04:14 +00:00
|
|
|
readonly keyValidator: Validatable<Key>;
|
2023-04-25 11:01:25 +00:00
|
|
|
// (undocumented)
|
2023-06-12 14:04:14 +00:00
|
|
|
readonly valueValidator: Validatable<Value>;
|
2023-04-25 11:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @public
|
|
|
|
const integer: Validator<number>;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
function literal<T extends boolean | number | string>(expectedValue: T): Validator<T>;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
function model<T extends {
|
|
|
|
readonly id: string;
|
2023-06-12 14:04:14 +00:00
|
|
|
}>(name: string, validator: Validatable<T>): Validator<T>;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public
|
|
|
|
const nonZeroInteger: Validator<number>;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
const nonZeroNumber: Validator<number>;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
const number: Validator<number>;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
function object<Shape extends object>(config: {
|
2023-06-12 14:04:14 +00:00
|
|
|
readonly [K in keyof Shape]: Validatable<Shape[K]>;
|
2023-04-25 11:01:25 +00:00
|
|
|
}): ObjectValidator<Shape>;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
class ObjectValidator<Shape extends object> extends Validator<Shape> {
|
|
|
|
constructor(config: {
|
2023-06-12 14:04:14 +00:00
|
|
|
readonly [K in keyof Shape]: Validatable<Shape[K]>;
|
2023-04-25 11:01:25 +00:00
|
|
|
}, shouldAllowUnknownProperties?: boolean);
|
|
|
|
// (undocumented)
|
|
|
|
allowUnknownProperties(): ObjectValidator<Shape>;
|
|
|
|
// (undocumented)
|
|
|
|
readonly config: {
|
2023-06-12 14:04:14 +00:00
|
|
|
readonly [K in keyof Shape]: Validatable<Shape[K]>;
|
2023-04-25 11:01:25 +00:00
|
|
|
};
|
|
|
|
extend<Extension extends Record<string, unknown>>(extension: {
|
2023-06-12 14:04:14 +00:00
|
|
|
readonly [K in keyof Extension]: Validatable<Extension[K]>;
|
2023-04-25 11:01:25 +00:00
|
|
|
}): ObjectValidator<Shape & Extension>;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
const point: ObjectValidator<{
|
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
z: number | undefined;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
const positiveInteger: Validator<number>;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
const positiveNumber: Validator<number>;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
function setEnum<T>(values: ReadonlySet<T>): Validator<T>;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
const string: Validator<string>;
|
|
|
|
|
|
|
|
declare namespace T {
|
|
|
|
export {
|
|
|
|
literal,
|
|
|
|
arrayOf,
|
|
|
|
object,
|
|
|
|
dict,
|
|
|
|
union,
|
|
|
|
model,
|
|
|
|
setEnum,
|
|
|
|
ValidatorFn,
|
2023-06-12 14:04:14 +00:00
|
|
|
Validatable,
|
2023-04-25 11:01:25 +00:00
|
|
|
ValidationError,
|
|
|
|
TypeOf,
|
|
|
|
Validator,
|
|
|
|
ArrayOfValidator,
|
|
|
|
ObjectValidator,
|
|
|
|
UnionValidator,
|
|
|
|
DictValidator,
|
|
|
|
unknown,
|
|
|
|
any,
|
|
|
|
string,
|
|
|
|
number,
|
|
|
|
positiveNumber,
|
|
|
|
nonZeroNumber,
|
|
|
|
integer,
|
|
|
|
positiveInteger,
|
|
|
|
nonZeroInteger,
|
|
|
|
boolean,
|
|
|
|
bigint,
|
|
|
|
array,
|
|
|
|
unknownObject,
|
|
|
|
point,
|
|
|
|
boxModel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export { T }
|
|
|
|
|
|
|
|
// @public (undocumented)
|
2023-06-12 14:04:14 +00:00
|
|
|
type TypeOf<V extends Validatable<unknown>> = V extends Validatable<infer T> ? T : never;
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// @public
|
|
|
|
function union<Key extends string, Config extends UnionValidatorConfig<Key, Config>>(key: Key, config: Config): UnionValidator<Key, Config>;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
class UnionValidator<Key extends string, Config extends UnionValidatorConfig<Key, Config>, UnknownValue = never> extends Validator<TypeOf<Config[keyof Config]> | UnknownValue> {
|
|
|
|
constructor(key: Key, config: Config, unknownValueValidation: (value: object, variant: string) => UnknownValue);
|
|
|
|
// (undocumented)
|
|
|
|
validateUnknownVariants<Unknown>(unknownValueValidation: (value: object, variant: string) => Unknown): UnionValidator<Key, Config, Unknown>;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public
|
|
|
|
const unknown: Validator<unknown>;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
const unknownObject: Validator<Record<string, unknown>>;
|
|
|
|
|
2023-06-12 14:04:14 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
type Validatable<T> = {
|
|
|
|
validate: (value: unknown) => T;
|
|
|
|
};
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
class ValidationError extends Error {
|
|
|
|
constructor(rawMessage: string, path?: ReadonlyArray<number | string>);
|
|
|
|
// (undocumented)
|
|
|
|
name: string;
|
|
|
|
// (undocumented)
|
|
|
|
readonly path: ReadonlyArray<number | string>;
|
|
|
|
// (undocumented)
|
|
|
|
readonly rawMessage: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public (undocumented)
|
2023-06-12 14:04:14 +00:00
|
|
|
class Validator<T> implements Validatable<T> {
|
2023-04-25 11:01:25 +00:00
|
|
|
constructor(validationFn: ValidatorFn<T>);
|
|
|
|
check(name: string, checkFn: (value: T) => void): Validator<T>;
|
|
|
|
// (undocumented)
|
|
|
|
check(checkFn: (value: T) => void): Validator<T>;
|
|
|
|
nullable(): Validator<null | T>;
|
|
|
|
optional(): Validator<T | undefined>;
|
|
|
|
refine<U>(otherValidationFn: (value: T) => U): Validator<U>;
|
|
|
|
validate(value: unknown): T;
|
|
|
|
// (undocumented)
|
|
|
|
readonly validationFn: ValidatorFn<T>;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
type ValidatorFn<T> = (value: unknown) => T;
|
|
|
|
|
|
|
|
// (No @packageDocumentation comment for this package)
|
|
|
|
|
|
|
|
```
|