Context Overview
The ChimpbaseContext API available to all handlers.
Every handler in Chimpbase — actions, subscriptions, workers, cron jobs, and workflow steps — receives a ChimpbaseContext as its first argument. The context provides access to all runtime capabilities.
Context API at a Glance
| Category | API | Purpose |
|---|---|---|
| Database | ctx.query(sql, params) | Raw SQL queries |
ctx.db<T>() | Typed Kysely query builder | |
| Pub/Sub | ctx.pubsub.publish(event, payload) | Publish ephemeral events |
| Queues | ctx.queue.enqueue(name, payload, opts?) | Enqueue durable background jobs |
| Key-Value | ctx.kv.get/set/delete/list | Key-value storage |
| Collections | ctx.collection.find/insert/update/delete | Schemaless JSON documents |
| Streams | ctx.stream.append/read | Append-only event streams |
| Workflows | ctx.workflow.start/get/signal | Workflow management |
| Actions | ctx.action(name, args) | Call other registered actions |
| Secrets | ctx.secret(name) | Access preloaded secrets |
| Logging | ctx.log.debug/info/warn/error | Structured logging |
| Metrics | ctx.metric(name, value, labels) | Record metrics |
| Tracing | ctx.trace(name) | Distributed tracing spans |