← @mortar-kit/core

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: string
readonly label: string
readonly fields: F
readonly body: boolean
readonly title: keyof F & string | undefined
readonly sort: Required<SortOrder>
readonly orderable: boolean

Whether documents are in a manual order (see CollectionDefinition.orderable).

readonly reservedSlugs: readonly string[]
readonly url: string | undefined

The document path pattern (see CollectionDefinition.url).

readonly home: string | undefined

The slug of the document at the pattern's prefix (see CollectionDefinition.home).

readonly canWrite: ((write: CollectionWrite<F>) => boolean | Promise<boolean>) | undefined

Who may change its documents (see CollectionDefinition.canWrite).

urlOf: (doc: { slug: string }) => string | undefined

A document's path on the site, from url; undefined without one.

titleOf: (doc: { slug: string; fields: Record<string, unknown> }) => string

A 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.