Collectioninterface
import { Collection } from '@mortar-kit/core'
interface Collection<F extends Fields = Fields> extends SchemaOps<F>A registered collection. Its SchemaOps apply to a document's fields (keys outside the schema are kept).
Properties
defaults: () => InferFields<F>Fresh default data.
validate: (data: unknown) => ValidateResult<InferFields<F>>Validates (and fills defaults into) unknown data.
normalize: (data: unknown) => InferFields<F>Coerces unknown data into the schema's shape for rendering: missing fields get defaults, and fields of the wrong type are replaced by their default. Values that are the right type but break a rule (an empty required text) are kept, so a preview shows what the editor typed.
readonly name: stringreadonly label: stringreadonly fields: Freadonly body: booleanreadonly title: keyof F & string | undefinedreadonly sort: Required<SortOrder>readonly orderable: booleanWhether documents are in a manual order (see
CollectionDefinition.orderable).readonly reservedSlugs: readonly string[]readonly url: string | undefinedThe document path pattern (see
CollectionDefinition.url).readonly home: string | undefinedThe slug of the document at the pattern's prefix (see
CollectionDefinition.home).readonly canWrite: ((write: CollectionWrite<F>) => boolean | Promise<boolean>) | undefinedWho may change its documents (see
CollectionDefinition.canWrite).urlOf: (doc: { slug: string }) => string | undefinedA document's path on the site, from
url; undefined without one.titleOf: (doc: { slug: string; fields: Record<string, unknown> }) => stringA document's label in lists: its title field, or its slug when that is empty or there is no title field.
create: (slug: string) => Doc<InferFields<F>>A new, unsaved document with a fresh id and default fields. Call it from event handlers, not during render.