---
title: "Plugin types"
description: "The plugin-contract and plugin option and method types exported by comark-content."
canonical_url: "https://content.comark.dev/reference/types/plugins"
---
# Plugin types

> The plugin-contract and plugin option and method types exported by comark-content.

The types describing the Content instance and client plugin contracts, plus the option and method bags each plugin contributes.

Every export is re-exported from the main `comark-content` entry point:

```ts
import type {
  ContentPlugin,
  ContentPluginContext,
  ContentClientPlugin,
} from 'comark-content'
```

## `ContentPlugin`

The interface a plugin implements: a `name` and a synchronous `setup` hook. `setup` runs at construction and must return its methods directly; an async `setup` isn't awaited, so do deferred work in a hook or on first use.

```ts
interface ContentPlugin<Methods extends Record<string, any> = Record<string, never>> {
  name?: string
  setup?: (content: ContentPluginContext) => Methods | void
}
```

## `ContentPluginContext`

The `content` handle passed to a plugin's `setup`: the manifest, cache, hooks, and registration helpers.

```ts
interface ContentPluginContext {
  options: ContentOptions
  name: string                      // the instance name
  hooks: Hookable<ContentHooks>
  cache: Cache
  readonly __manifest__: Manifest   // the live index — synchronous, plugin-only
  logger: Logger
  onError: OnErrorMode
  perf: Perf                        // no-op unless a tracing plugin installed a recorder
  setPerf: (recorder: Perf) => void // install the recorder behind content.perf (first wins)
  init: (opts?: { partial?: boolean; ignoreCache?: boolean }) => Promise<void>
  stat: (key: string) => ContentListFile | undefined
  getSource: (name?: string) => Source | undefined
  snapshot: () => Promise<ParsedSnapshot>
  addParser: (extensions: `.${string}`[], parse: Parser) => void
  addListingFields: (extensions: `.${string}`[], fields: string[]) => void
  addServeHandler: (path: string, handler: (request: Request) => Promise<Response>) => void
  update: (file: ContentFile) => Promise<void>
  ingest: (file: ContentFile) => Promise<void>
  remove: (key: string) => Promise<void>
}
```

The `defineContentPlugin` helper handles the generics for you:

```ts
export default defineContentPlugin<Options, Methods>((options) => ({
  setup(content) { /* ... */ return methodsToMerge },
}))
```

## `ContentClientPlugin`

The interface a client plugin implements. Build one with [`defineContentClientPlugin`](https://content.comark.dev/reference/plugins/define-content-client-plugin).

```ts
interface ContentClientPlugin<Methods extends Record<string, any> = Record<string, never>> {
  setup?: (client: ContentClientWithOptions) => Methods | void
}
```

## Plugin option and method types

Per-plugin option and method bags, each documented in full on its feature page.

| Type                                                                                              | Used by                                                                                                                                                      |
| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `SqlQueryOptions`                                                                                 | [`sqlQuery()`](https://content.comark.dev/plugins/built-in/sql-query)                                                                                        |
| `SqliteFullTextSearchOptions`, `SqliteFullTextSearchMethods`, `SqliteFullTextSearchClientMethods` | [full-text search](https://content.comark.dev/plugins/built-in/full-text-search)                                                                             |
| `MediaOptions`, `MediaMethods`                                                                    | the [`media`](https://content.comark.dev/plugins/built-in/media) plugin                                                                                      |
| `JsonPluginOptions`                                                                               | the [`json`](https://content.comark.dev/plugins/built-in/json) plugin                                                                                        |
| `YamlPluginOptions`                                                                               | the [`yaml`](https://content.comark.dev/plugins/built-in/yaml) plugin                                                                                        |
| `MarkdownPluginOptions`                                                                           | the built-in [`markdown`](https://content.comark.dev/plugins/built-in/markdown) parser                                                                       |
| `FileParsedContext`                                                                               | [`file:parsed`](https://content.comark.dev/reference/content/hooks#fileparsed) hook context                                                                  |
| `TypegenFieldContext`, `GenerateSourceTypesOptions`, `WriteSourceTypesOptions`                    | [type generation](https://content.comark.dev/reference/types/typegen) and [`typegen:field`](https://content.comark.dev/reference/content/hooks#typegenfield) |
| `ComarkViteOptions`                                                                               | the [`comark-content/vite`](https://content.comark.dev/examples/vite/vue) plugin                                                                             |
| `MergePluginMethods<P>`                                                                           | Intersection of the method maps contributed by Content plugins.                                                                                              |
| `MergeClientPluginMethods<P>`                                                                     | Intersection of the method maps contributed by client plugins.                                                                                               |


## Sitemap

See the full [sitemap](https://content.comark.dev/sitemap.md) for all pages.
