createActions
createActions<
TUser>(config):object
Defined in: packages/actions/src/create-actions.ts:106
Creates a scoped action factory bound to a shared context provider.
Returns two functions — createAction and composeActions — that share the
same getContext callback. This ensures every action in the application resolves
its database, user, and grants consistently.
Type Parameters
Section titled “Type Parameters”TUser = any
The shape of the authenticated user object.
Parameters
Section titled “Parameters”config
Section titled “config”ActionsConfig<TUser>
The ActionsConfig providing the getContext callback.
Returns
Section titled “Returns”An object with createAction and composeActions functions.
composeActions()
Section titled “composeActions()”composeActions: <
TActions>(actions) =>ComposedActions<TActions>
Combines multiple action definitions into a single
route handler that dispatches by the _action discriminator field.
The returned ComposedActions object provides a unified .action handler,
a .loader() wrapper that checks permissions for all actions at once,
and a .client descriptor covering every action name.
Type Parameters
Section titled “Type Parameters”TActions
Section titled “TActions”TActions extends Record<string, ActionDefinition<any, any, any>>
A record mapping action names to their definitions.
Parameters
Section titled “Parameters”actions
Section titled “actions”TActions
An object of named action definitions to compose.
Returns
Section titled “Returns”ComposedActions<TActions>
A ComposedActions object with combined handler, loader, and client descriptor.
Example
Section titled “Example”const composed = composeActions({ deletePost, publishPost, unpublishPost,});
export const action = composed.action;export const loader = composed.loader(async ({ request, params }) => { return { post: await getPost(params.slug) };});createAction()
Section titled “createAction()”createAction: <
TInput,TResult>(operationsFn) =>ActionDefinition<TInput,TResult,TUser>
Defines a single permission-aware action.
Takes an OperationsFn that builds a database Operation from
the parsed input and action context. Returns an ActionDefinition
with .action, .loader(), .client, and .buildOperation facets.
Type Parameters
Section titled “Type Parameters”TInput
Section titled “TInput”TInput
The expected input shape for this action.
TResult
Section titled “TResult”TResult
The return type of the action handler.
Parameters
Section titled “Parameters”operationsFn
Section titled “operationsFn”OperationsFn<TInput, TResult, TUser>
A function that builds the database operation for this action.
Returns
Section titled “Returns”ActionDefinition<TInput, TResult, TUser>
An ActionDefinition with action handler, loader wrapper, client descriptor, and build method.
Example
Section titled “Example”const deletePost = createAction<{ postId: string }, Response>( (db, input, ctx) => compose( [db.delete(posts).where(eq(posts.id, input.postId))], async (runDelete) => { await runDelete({}); return redirect("/"); }, ),);
export const action = deletePost.action;Example
Section titled “Example”import { createActions } from "@cfast/actions";
export const { createAction, composeActions } = createActions({ getContext: async ({ request }) => { const ctx = await requireAuthContext(request); const db = createCfDb(env.DB, ctx); return { db, user: ctx.user, grants: ctx.grants }; },});