@contentful/rich-text-types
Version:
Type definitions and constants for the Contentful rich text field type.
61 lines (60 loc) • 2.35 kB
TypeScript
import type { Path } from './path.js';
import { ValidationError } from './types.js';
export declare class ObjectAssertion {
private readonly obj;
private readonly path;
private _errors;
constructor(obj: Record<string, any>, path: Path);
catch: (...errors: ValidationError[]) => void;
get errors(): ValidationError[];
/**
* Asserts the key exists in the object. You probably shouldn't call this
* function directly. Instead, use `$.object`, `$.number`, `$.string`, etc.
*/
exists: (key: string) => boolean;
/**
* Asserts the key exists in the object and its value is a plain object. if
* no key is provided, it asserts the object itself.
*/
object: (key?: string) => boolean;
/**
* Asserts the key exists in the object and its value is a string.
*/
string: (key: string) => boolean;
/**
* Asserts the key exists in the object and its value is a number.
*/
number: (key: string, optional?: boolean) => boolean;
/**
* Asserts the key exists in the object and its value is an array. You don't
* need to manually call this function before `$.each` or `$.maxLength`.
*/
array: (key: string) => boolean;
/**
* Asserts the value of the key is one of the expected values.
*/
enum: (key: string, expected: string[]) => boolean;
/**
* Asserts the array value of the object key is empty. If the value isn't an
* array, the function captures a type error and returns false.
*/
empty: (key: string) => boolean;
/**
* Asserts the length of the value of the object key is at least `min`. If the
* value isn't an array, the function captures a type error and returns false.
*/
minLength: (key: string, min: number) => boolean;
/**
* Asserts the object has no additional properties other than the ones
* specified
*/
noAdditionalProperties: (properties: string[]) => boolean;
/**
* Iterates over the value of the key and assert each item. If the value isn't
* an array, the function captures a type error and safely exits.
*
* To maintain compatibility with previous implementation, we stop early if we
* find any errors.
*/
each: (key: string, assert: (item: any, path: Path) => ValidationError[]) => void;
}