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

CategoryAPIPurpose
Databasectx.query(sql, params)Raw SQL queries
ctx.db<T>()Typed Kysely query builder
Pub/Subctx.pubsub.publish(event, payload)Publish ephemeral events
Queuesctx.queue.enqueue(name, payload, opts?)Enqueue durable background jobs
Key-Valuectx.kv.get/set/delete/listKey-value storage
Collectionsctx.collection.find/insert/update/deleteSchemaless JSON documents
Streamsctx.stream.append/readAppend-only event streams
Workflowsctx.workflow.start/get/signalWorkflow management
Actionsctx.action(name, args)Call other registered actions
Secretsctx.secret(name)Access preloaded secrets
Loggingctx.log.debug/info/warn/errorStructured logging
Metricsctx.metric(name, value, labels)Record metrics
Tracingctx.trace(name)Distributed tracing spans