Files
skills/docs/api-stack/api/api-plugin-campaigns/src/context/context.md
2026-05-29 08:20:56 +01:00

2.4 KiB

context

(no submodules)

Purpose

The context module owns the Hono ContextVariableMap declaration-merge augmentation applied by @suaveplan/api-plugin-campaigns. Importing the module for its side effects (which the package root barrel does automatically) adds the typed slots the plugin's route handlers read with c.get(...), eliminating the as any casts that pile up in untyped Hono middleware chains.

In Chunk A the only slot the plugin commits to is eventBus, because that is the only context entry the no-op onInit placeholder would set if it had a body. Chunks B and C will extend the declaration with the repository handles (campaignRepository, campaignSuppressionStore, deliveryEventStore) once those classes exist; consumers do not need to re-import this module to pick the extensions up.

Features

  • Pure declaration-merge — zero runtime cost, zero bundle size.
  • Re-exports an empty value (export {}) so the module participates in ES-module side-effect ordering without polluting the consumer's namespace.
  • Slot type drawn from @suaveplan/types so the augmentation does not drag in the api-plugin-campaigns implementation surface.

Usage: Basic

import { Hono } from "hono";
import "@suaveplan/api-plugin-campaigns"; // also pulls this module via the root barrel

const app = new Hono();
app.get("/", (c) => {
    const bus = c.get("eventBus");
    bus.emit("campaign.read", { id: "x" });
    return c.text("ok");
});

Usage: Advanced

import "@suaveplan/api-plugin-campaigns/plugin/plugin"; // ensures the augmentation
import type { ContextVariableMap } from "hono";

type EventBus = ContextVariableMap["eventBus"];

API Reference

  • Adds eventBus: EventBusLike to Hono ContextVariableMap.
  • No runtime exports.

Implementation Notes

Module augmentations must live in a file with at least one export statement to be picked up as a module rather than a script. The empty export {} at the bottom is the standard idiom; removing it would silently demote the file to a script and the declare module "hono" block would stop applying.

Chunks B and C augment the same ContextVariableMap interface from their own context modules, relying on TypeScript declaration merging to union the slots together. That means agents working on later chunks never edit this file — they add new files with their own declare module "hono" blocks.