Skip to main content
Version: v10.0.0

collection

Creates a collection from a Standard Schema, such as a Zod, Valibot or ArkType schema, or from rowType<Row>() .


Import
import { collection } from "@hyper-fetch/db"

Usage​

const Post = collection(PostSchema, { key: "id", version: "updatedAt" });
const Draft = collection(rowType<Draft>(), { key: "id" });

Parameters​

collection<Schema, KeyField>(schema: Schema, options: CollectionOptions<InferSchemaOutput<Schema>, KeyField>)
Parameters
NameTypeDescription
schema
Schema
options
CollectionOptions<InferSchemaOutput<Schema>, KeyField>

Returns​

class Collection<Row, Input, KeyField, Loaders, Mutations> {
constructor(config: CollectionConfig) {};
config: CollectionConfig;
__types: { input: Input; key: KeyField; loaders: Loaders; mutations: Mutations; row: Row };
ingest<Req, Mapped, Type>(request: Req, options?: IngestOptions<Req, Mapped, Type>) => IsIngestRow<Row, KeyField, (Inferred<Type, insert> & IngestType), Inferred<Mapped, DefaultRows<Req>>> extends true ? Collection<Row, Input, KeyField, Loaders, Mutations> : RowMismatch<Inferred<Mapped, DefaultRows<Req>>, Row>;
load<Req, Mapped, Where, Order, Cursor, Limit, ByKey, ByKeys, LoaderNotation>(request: Req, options?: LoaderOptions<Row, NonNullable<Row[KeyField]>, Req, Mapped, Where, Order, Cursor, Limit, ByKey, ByKeys, LoaderNotation>) => IsExactRow<Inferred<Mapped, DefaultRows<Req>>, Row> extends true ? Collection<Row, Input, KeyField, Loaders | DescribeLoader<Row, Where, Order, Cursor, Limit, ByKey, ByKeys, LoaderNotation>, Mutations> : RowMismatch<Inferred<Mapped, DefaultRows<Req>>, Row>;
mutate<InsertReq, UpdateReq, DeleteReq, InsertMapped, UpdateMapped, InsertSuccess, UpdateSuccess>(mutations: { delete?: DeleteMutation<Row, KeyField, DeleteReq>; insert?: InsertMutation<Row, InsertReq, InsertMapped, InsertSuccess>; update?: UpdateMutation<Row, KeyField, UpdateReq, UpdateMapped, UpdateSuccess> }) => [IsWriteHandled<InsertReq, IsExactRow<Inferred<InsertMapped, ExtractResponseType<InsertReq>>, Row>, InsertSuccess>, IsWriteHandled<UpdateReq, IsPartialRow<Inferred<UpdateMapped, ExtractResponseType<UpdateReq>>, Row, KeyField>, UpdateSuccess>] extends [true, true] ? Collection<Row, Input, KeyField, Loaders, Mutations & (IsGiven<InsertReq> extends true ? { insert: Input } : {}) & (IsGiven<UpdateReq> extends true ? { update: PayloadChanges<Row, UpdateReq> } : {}) & (IsGiven<DeleteReq> extends true ? { delete: true } : {})> : RowMismatch<ExtractResponseType<InsertReq> | ExtractResponseType<UpdateReq>, Row>;
normalize<TargetRow, Mapped>(target: { __types?: { row: TargetRow }; config: CollectionConfig }, extract: (row: Row) => readonly Mapped[]) => ([Mapped] extends [never] ? true : IsExactRow<Mapped, TargetRow>) extends true ? Collection<Row, Input, KeyField, Loaders, Mutations> : RowMismatch<Mapped, TargetRow>;
resource<Node, Item, Mapped, Filters, Cursor, InsertSuccess, UpdateSuccess, ListOption>(node: Node, options: ResourceOptions<Row, Node, Item, Mapped, Filters, Cursor, InsertSuccess, UpdateSuccess> & { list?: ListOption }) => IsResourceValid<Row, KeyField, Node, Item, Mapped, (ListOption extends false ? false : true), InsertSuccess, UpdateSuccess> extends true ? Collection<Row, Input, KeyField, Loaders | ResourceLoaders<Row, Node, Item, Filters, Cursor, (ListOption extends false ? false : true)>, Mutations & (Node extends { $post: RequestInstance } ? { insert: Input } : {}) & ([UpdateRequestOf<Node, Item>] extends [never] ? {} : { update: Partial<Row> }) & (ItemNode<Node, Item> extends { $delete: RequestInstance } ? { delete: true } : {})> : RowMismatch<unknown, Row>;
sync<Listener, Type, Mapped>(listener: Listener, options: SyncOptions<Row, KeyField, Listener, Type, Mapped>) => IsSyncRow<Row, KeyField, Type, Inferred<Mapped, SyncMessage<Listener>>> extends true ? Collection<Row, Input, KeyField, Loaders, Mutations> : RowMismatch<Inferred<Mapped, SyncMessage<Listener>>, Row>;
syncChanges<Listener, Mapped>(listener: Listener, options: SyncChangesOptions<Row, KeyField, Listener, Mapped>) => ([Mapped] extends [never] ? true : IsExactRow<Mapped, Row>) extends true ? Collection<Row, Input, KeyField, Loaders, Mutations> : RowMismatch<Mapped, Row>;
}
Collection<InferSchemaOutput<Schema>, InferSchemaInput<Schema>, KeyField>