Spec constructors
Workpool component example
The Workpool component pools actions and mutations with configurable parallelism and retries. It requires you to define Convex functions that it can reference—such as the action to run and anonComplete callback. This walkthrough shows how to integrate those functions into Confect.
Install the component
convex/convex.config.ts:
convex/convex.config.ts
Write the Convex functions
Write standard Convex functions using the Convex API and place them in yourconfect/ directory. By convention, they go adjacent to their corresponding spec and impl files—for example, workpool.ts alongside workpool.spec.ts and workpool.impl.ts. The component reference comes from Confect’s generated components registry.
confect/workpool.ts
Define the spec
Use theconvex* spec constructors and pass each Convex function’s type as a type argument. Confect extracts argument and return types from the Convex RegisteredQuery, RegisteredMutation, or RegisteredAction type so that refs are fully typed.
confect/workpool.spec.ts
Import the Convex functions as type-only imports (
import type). The spec
is shared between the server and client, so a runtime import here would leak
the function implementation to the client bundle.confect codegen to pick up the new spec.
Implement the functions
For plain Convex functions, the impl is the Convex function value itself. Pass each one directly toFunctionImpl.make.
confect/workpool.impl.ts
confect codegen to pick up the new impl.
Call plain functions from the client
Plain Convex functions are available through refs just like Confect functions.Mixing Confect and plain functions
A single group can contain both Confect functions (with Effect schemas) and plain Convex functions. Each function’s spec constructor determines how it is registered and called.confect/notes.spec.ts