definePlugin
Call Signature
Section titled “Call Signature”definePlugin<
TName,TProvides,TClient>(config):CfastPlugin<TName,Awaited<TProvides>,unknown,TClient>
Defined in: packages/core/src/define-plugin.ts:39
Defines a cfast plugin for use with createApp().use().
Has two call signatures:
- Direct form (no dependencies):
definePlugin({ name, setup, ... })— types are fully inferred. - Curried form (with dependencies):
definePlugin<TRequires>()({ name, setup, ... })— specifyTRequiresexplicitly sosetup(ctx)receives typed prior-plugin context.
Type Parameters
Section titled “Type Parameters”TName extends string
TProvides
Section titled “TProvides”TProvides
TClient
Section titled “TClient”TClient = unknown
Parameters
Section titled “Parameters”config
Section titled “config”Plugin configuration with name, setup, and optional Provider/client.
client?
Section titled “client?”TClient
TName
Provider?
Section titled “Provider?”ComponentType<{ children: ReactNode; }>
(ctx) => TProvides | Promise<TProvides>
Returns
Section titled “Returns”CfastPlugin<TName, Awaited<TProvides>, unknown, TClient>
A CfastPlugin instance ready to pass to app.use().
Example
Section titled “Example”// Leaf plugin (no dependencies)const analyticsPlugin = definePlugin({ name: 'analytics', setup(ctx) { return { track: (event: string) => {} }; },});
// Plugin with dependencies (curried)import type { AuthPluginProvides } from '@cfast/auth';const dbPlugin = definePlugin<AuthPluginProvides>()({ name: 'db', setup(ctx) { ctx.auth.user; // typed from AuthPluginProvides return { client: createDb({}) }; },});Call Signature
Section titled “Call Signature”definePlugin<
TRequires>(): <TName,TProvides,TClient>(config) =>CfastPlugin<TName,Awaited<TProvides>,TRequires,TClient>
Defined in: packages/core/src/define-plugin.ts:51
Defines a cfast plugin for use with createApp().use().
Has two call signatures:
- Direct form (no dependencies):
definePlugin({ name, setup, ... })— types are fully inferred. - Curried form (with dependencies):
definePlugin<TRequires>()({ name, setup, ... })— specifyTRequiresexplicitly sosetup(ctx)receives typed prior-plugin context.
Type Parameters
Section titled “Type Parameters”TRequires
Section titled “TRequires”TRequires
Returns
Section titled “Returns”A CfastPlugin instance ready to pass to app.use().
<
TName,TProvides,TClient>(config):CfastPlugin<TName,Awaited<TProvides>,TRequires,TClient>
Type Parameters
Section titled “Type Parameters”TName extends string
TProvides
Section titled “TProvides”TProvides
TClient
Section titled “TClient”TClient = unknown
Parameters
Section titled “Parameters”config
Section titled “config”client?
Section titled “client?”TClient
TName
Provider?
Section titled “Provider?”ComponentType<{ children: ReactNode; }>
(ctx) => TProvides | Promise<TProvides>
Returns
Section titled “Returns”CfastPlugin<TName, Awaited<TProvides>, TRequires, TClient>
Example
Section titled “Example”// Leaf plugin (no dependencies)const analyticsPlugin = definePlugin({ name: 'analytics', setup(ctx) { return { track: (event: string) => {} }; },});
// Plugin with dependencies (curried)import type { AuthPluginProvides } from '@cfast/auth';const dbPlugin = definePlugin<AuthPluginProvides>()({ name: 'db', setup(ctx) { ctx.auth.user; // typed from AuthPluginProvides return { client: createDb({}) }; },});