compose
compose<
TResult>(operations,executor):Operation<TResult>
Defined in: packages/db/src/compose.ts:47
Merges multiple Operations into a single operation with combined, deduplicated permissions and an executor function for controlling data flow.
compose() itself does not check permissions — it only merges them. Each sub-operation’s
.run() still performs its own permission check when the executor calls it. This enables
data dependencies between operations (e.g., using an insert result’s ID in an audit log).
Type Parameters
Section titled “Type Parameters”TResult
Section titled “TResult”TResult
The return type of the executor function.
Parameters
Section titled “Parameters”operations
Section titled “operations”Operation<unknown>[]
The operations to compose. Their permissions are merged and deduplicated.
executor
Section titled “executor”(…runs) => TResult | Promise<TResult>
A function that receives a run function for each operation (in order).
You control execution order, data flow between operations, and the return value.
Returns
Section titled “Returns”Operation<TResult>
A single Operation with combined permissions.
Example
Section titled “Example”import { compose } from "@cfast/db";
const publishWorkflow = compose( [updatePost, insertAuditLog], async (doUpdate, doAudit) => { const updated = await doUpdate({}); await doAudit({}); return { published: true }; },);
// Inspect combined permissionspublishWorkflow.permissions;// => [{ action: "update", table: "posts" }, { action: "create", table: "audit_logs" }]
// Execute all sub-operationsawait publishWorkflow.run({});