AuditEffectPower Scenario

Use an effect scenario to show how a power can do side effects without rewriting the main value

Scenario

You want to record an event:

  • a message arrived
  • an action was triggered

but you do not want to:

  • transform the value
  • block the flow

That is a clean effect use case.

Example

import { Power, type PowerHooks } from "@downcity/city/power";

class AuditEffectPower extends Power {
  readonly name = "audit_effect";
  readonly title = "Audit Effect";
  readonly description = "Writes one audit line for every observed event.";

  readonly hooks: PowerHooks = {
    effect: {
      "audit.observe": [
        async ({ value, power }) => {
          console.log(`[${power}] observed`, value);
        },
      ],
    },
  };
}

// City has registered audit_effect and bound it to entry's Agent/Workspace.
await city.powers.scope({ agent_id: agent.id, workspace_id: workspace.id }).effect("audit.observe", {
  event: "incoming_message",
  session_id: "sess_001",
});

Why this is not a pipeline

Because you do not care about returning a new value. The side effect is the whole point.