← @mortar-kit/core

Contentinterface

import { Content } from '@mortar-kit/core'

interface Content extends ContentSource

Reading and writing documents: what the admin needs.

Properties

list: (collection: string, options?: ListOptions) => Promise<DocSummary[]>

Documents of a collection, without their bodies.

get: (collection: string, ref: DocRef) => Promise<Doc<Record<string, unknown>> | null>

One document, or null if there is none.

track?: () => void

Called before each brick load, where reads are tracked: read a signal here to make every load run again when it changes (the admin preview does, after each save).

readonly collections?: readonly AnyCollection[]

The collections it serves (createContent sets it), for createContentServer to find each one's canWrite.

save: (collection: string, doc: unknown) => Promise<SaveResult>

Validates a document (from an untrusted client) and stores it. Problems are returned, not thrown. Renaming its slug moves it. Writes through one Content run one at a time.

remove: (collection: string, id: string) => Promise<RemoveResult>

Deletes a document by id, unless other documents reference it (then they are returned).

move?: (collection: string, id: string, index: number) => Promise<void>

Moves a document of an orderable collection to index (from 0) in its manual order; an index past either end moves it to that end. Throws for a collection that isn't orderable, a bad index or an unknown id. Optional for custom implementations: without it the admin shows no reorder controls.

runAction?: (ref: EntryRef, form: FormData | URLSearchParams, options?: RunActionOptions) => Promise<unknown>

Runs the action of the brick behind an entry with a posted form: reads the document by id, finds the entry, and calls the action with the entry's stored (normalized) data. Resolves to what the action returns; throws when the reference names no entry with an action. Call it from the app's one server function for brick forms (a plain form post arrives as URLSearchParams, which becomes FormData; the reference and form come from the browser: both are untrusted, which is why the data doesn't travel with them). Optional for custom implementations.

assets?: Assets

Uploaded files; only when content has a blob store.