ActionsConfig
ActionsConfig<
TUser,TServices> =object
Defined in: packages/actions/src/types.ts:164
Configuration for the createActions factory.
Provides a getContext callback that resolves the per-request
ActionContext (database, user, grants) for every action
invocation, plus an optional services bag that is injected into
every action’s context as ctx.services.
getContext is allowed to return an ActionContext without the
services field (the backward-compatible shape) — the factory will
fill it in with the registered services (or an empty object) so that
every handler can always rely on ctx.services being defined.
Examples
Section titled “Examples”const config: ActionsConfig<AppUser> = { getContext: async ({ request }) => { const ctx = await requireAuthContext(request); const db = createCfDb(env.DB, ctx); return { db, user: ctx.user, grants: ctx.grants }; },};const { createAction } = createActions<AppUser, { nutritionApi: NutritionApi }>({ getContext: async ({ request }) => { ... }, services: { nutritionApi: createNutritionApi(env.NUTRITION_API_KEY) },});
const lookupFood = createAction((db, input, ctx) => ({ permissions: [], run: async () => ctx.services.nutritionApi.lookup(input.name),}));Type Parameters
Section titled “Type Parameters”TUser
The shape of the authenticated user object.
TServices
Section titled “TServices”TServices extends ActionServices = ActionServices
The shape of the registered services map.
Properties
Section titled “Properties”getContext()
Section titled “getContext()”getContext: (
args) =>Promise<Omit<ActionContext<TUser,TServices>,"services"> &object>
Defined in: packages/actions/src/types.ts:173
Resolves the per-request action context from the route handler arguments.
The returned context does not need to include services — the factory
merges the registered services config in automatically. This keeps
the callback ergonomic for the common case (auth + DB only) while
still letting advanced users return a fully-formed context.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<Omit<ActionContext<TUser, TServices>, "services"> & object>
services?
Section titled “services?”
optionalservices:TServices
Defined in: packages/actions/src/types.ts:182
External services made available to every action handler as
ctx.services. Registering services here keeps handlers free of
module-level imports of third-party APIs and makes it trivial to
mock them in tests. Defaults to {} when omitted.