Skip to main content

Type Alias: DocumentLoader

DocumentLoader = (route) => DocumentVersion | null | Promise<DocumentVersion | null>

Defined in: config.types.ts:26

Reads the document version a route compiles from. Every command that touches a route calls it once, before anything is validated.

Parameters

route

string

The route argument as typed on the command line — /pricing, /guides/[city]. It is unvalidated at this point: compile judges the route, and it does so after this returns, so a loader that finds nothing for a malformed route answers null rather than raising about the shape.

Returns

DocumentVersion | null | Promise<DocumentVersion | null>

The version to compile, or null for a route with no document. Either a value or a promise of one — the CLI awaits both. null exits 2, with no document for <route>, which is what keeps "nothing is authored here" distinct from a load that broke.

Throws

Whatever reading the document raises. It reaches the terminal as the refusal, so a message naming what could not be read is the one a consumer sees.

Example

const document: DocumentLoader = async (route) => (await db.draftFor(route)) ?? null;