defineContentClientPlugin()

Author a client-side plugin that adds typed methods to the Content instance client.

defineContentClientPlugin(factory)

Defines a client-side plugin. Same shape as defineContentPlugin, but setup receives the client (with its resolved options: baseURL, basePath, fetch) instead of the Content instance plugin context, and is synchronous.

Parameters:

  • factory: (options?: TOptions) => { setup: (client: ContentClientWithOptions) => TMethods | void }.

Returns: a client plugin factory (...args) => ContentClientPlugin<TMethods> to pass to createContentClient({ plugins }).

plugin.ts
import { defineContentClientPlugin } from 'comark-content/client'

export default defineContentClientPlugin(() => ({
  setup(client) {
    return {
      searchSections: (q: string) =>
        client.options.fetch(`${client.options.basePath}/search-sections?q=${q}`),
    }
  },
}))

Import client plugins from comark-content/client; import Content plugins from comark-content.

Usage

Pair the client plugin with the defineContentPlugin that registers the matching section, so the two halves live in one place:

search-client.ts
import { defineContentClientPlugin } from 'comark-content/client'

export default defineContentClientPlugin(() => ({
  setup(client) {
    return {
      searchSections: (q: string) =>
        client.options.fetch(`${client.options.basePath}/search-sections?q=${q}`),
    }
  },
}))

Register it with createContentClient({ plugins }) to add the method to the client.