dilswer
Version:
Blazingly fast data validation library with TypeScript integration.
75 lines (74 loc) • 2.63 kB
TypeScript
import type { DataTypeKind, Metadata } from "./type-types";
import { Path } from "../validation-algorithms/path";
export declare const DataTypeSymbol: unique symbol;
export declare const MetadataSymbol: unique symbol;
export declare const BasicDataTypes: {
readonly Unknown: "unknown";
readonly String: "string";
readonly Number: "number";
readonly Int: "integer";
readonly Boolean: "boolean";
readonly Symbol: "symbol";
readonly Function: "function";
readonly Null: "null";
readonly Undefined: "undefined";
readonly StringNumeral: "stringnumeral";
readonly StringInt: "stringinteger";
};
export declare class TypeMetadata<T extends BaseType, M extends Metadata = Metadata> {
type: T;
container: M;
constructor(type: T, container: M);
/**
* Retrieves the metadata of a DataType, like title, description
* or examples.
*
* Metadata must be explicitly set on the DataType, otherwise it
* will be an empty object.
*/
get<Extra>(): Omit<M, "extra"> & {
extra?: Extra;
};
/**
* Sets a metadata `description` property. This property can be
* later read by `getMetadata` and is also used by
* `toJsonSchema` to generate a JSON Schema.
*/
description(description: string): T;
/**
* Sets a metadata `title` property. This property can be later
* read by `getMetadata` and is also used by `toJsonSchema` to
* generate a JSON Schema.
*/
title(name: string): T;
/**
* Sets a metadata `format` property. This property can be
* later read by `getMetadata` and is also used by
* `toJsonSchema` to generate a JSON Schema.
*/
format(format: string): T;
/**
* Sets the extra metadata. The extra metadata can be anything.
* This metadata is not used by Dilswer, but can be by the
* Dilswer consumer.
*/
extra(extra: Record<any, any>): T;
}
export declare abstract class BaseType {
protected [MetadataSymbol]: Metadata;
protected [DataTypeSymbol]: boolean;
readonly kind: DataTypeKind;
private compiledValidatorRef;
protected copy<T extends BaseType>(this: T): T;
meta: TypeMetadata<this, Metadata>;
/**
* Compiles a fast validator to be used via interfaces that support the Standard Schema
* (through the `~standard` property.)
*
* Compiled validator is much faster than default, but provides less informations in
* case of validation failure.
*/
compile(): this;
abstract ["~matches"](value: any): boolean;
abstract ["~validate"](path: Path, value: any): void;
}