content.hooks

A Hookable bus for content-change events.

content.hooks

A Hookable event bus for content-change events. Subscribe with content.hooks.hook(name, callback); the events are typed as ContentHooks.

Type: Hookable<ContentHooks>

HookSignatureFired when
watch:file:update(source, key, file) => voidA watched file is created or changed.
watch:file:remove(source, key) => voidA watched file is deleted.
file:parsed(ctx) => void | Promise<void>After a file extension parser assembles a ContentFile. Handlers may mutate or null . See FileParsedContext.
typegen:field(ctx) => void | Promise<void>While generating source types; plugins may override ctx.type and register imports via ctx.imports. See TypegenFieldContext.
file:upsert(source, key, file) => voidupdate() or a get() parse upserts an entry.
file:remove(source, key) => voidremove() drops an entry.
file:bulk:load(source, items) => voidA source's entries are bulk-loaded (e.g. snapshot hydration).

file:parsed

Fired at the end of parserRegistry.process() after a file extension parser assembles a ContentFile. Handlers receive a FileParsedContext and may mutate ctx.file or set it to null to reject the document.

The markdown-fields plugin transforms x-content markdown fields here — in frontmatter, JSON, YAML, and any other parsed file.data. The schema-validation plugin validates against the source schema — behavior controlled by mode.

typegen:field

Fired while generateSourceTypes() walks each source schema. Handlers receive a TypegenFieldContext: override ctx.type for semantic fields and call ctx.imports.add(from, ...names) for extra type imports.

Usage

hooks.ts
content.hooks.hook('file:upsert', (source, key, file) => {
  // re-index, revalidate, push the change over a socket, ...
})