UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

34 lines (33 loc) 1.54 kB
import type { Data, Database } from "../util/data.js"; import type { Item } from "../util/item.js"; import type { Validators } from "../util/validate.js"; import { DataSchema } from "./DataSchema.js"; import type { KeySchema } from "./KeySchema.js"; import { type OptionalSchema } from "./OptionalSchema.js"; import type { SchemaOptions } from "./Schema.js"; /** Allowed options for `ItemSchema` */ export interface ItemSchemaOptions<T extends Data> extends SchemaOptions { readonly id?: KeySchema | undefined; readonly props: Validators<T>; readonly value?: Partial<Item<T>> | undefined; } /** Validate an item object. */ export declare class ItemSchema<T extends Data> extends DataSchema<Item<T>> { constructor({ id, props, ...options }: ItemSchemaOptions<T>); } /** Set of named item schemas. */ export type ItemSchemas<T extends Database> = { [K in keyof T]: DataSchema<Item<T[K]>>; }; /** * Valid item object with specifed properties. * - An `Item` is a `Data` object with a string `.id` prop. * - Optional validator for `.id` must be a `KeySchema` and defaults to `KEY`. */ export declare const ITEM: <T extends Data>(props: Validators<T> | DataSchema<T>, id?: KeySchema) => ItemSchema<Item<T>>; /** * Valid item object or `null`. * - An `Item` is a `Data` object with a string `.id` prop. * - Optional validator for `.id` must be a `KeySchema` and defaults to `KEY`. */ export declare const OPTIONAL_ITEM: <T extends Data>(props: Validators<T> | DataSchema<T>, id?: KeySchema) => OptionalSchema<Item<T>>;