Running Loops
Adapters
LoopStore interface
All persistence adapters must implement:
1getInstance(aggregateId: AggregateId): Promise<LoopInstance | null>2saveInstance(instance: LoopInstance): Promise<void>3getTransitionHistory(aggregateId: AggregateId): Promise<TransitionRecord[]>4saveTransitionRecord(record: TransitionRecord): Promise<void>5listOpenInstances(loopId: LoopId): Promise<LoopInstance[]>@loop-engine/adapter-memory
1import { memoryStore } from '@loop-engine/adapter-memory'2const store = memoryStore()Use for tests, local development, browser demos.
Data resets on process restart.
@loop-engine/adapter-postgres
1import { postgresStore, createSchema, createPool, runMigrations } from '@loop-engine/adapter-postgres'2 3const pool = createPool({ connectionString: process.env.DATABASE_URL })4await runMigrations(pool)5const store = postgresStore(pool)Schema creates:
loop_instancesaggregate_id,loop_id,current_state,status,started_at,updated_at,completed_at,correlation_id,metadata
loop_transitionsid,loop_id,aggregate_id,transition_id,from_state,to_state,actor,evidence,occurred_at,duration_ms
schema_migrations- migration-tracking table managed by
runMigrations
- migration-tracking table managed by
Additional exports: createSchema(pool) (legacy DDL helper; prefer runMigrations for incremental upgrades), plus Migration, MigrationRunResult, PoolOptions, PostgresStore types and error classification utilities.
Peer dependency: pg@^8.0.0.
Event bus adapters
@loop-engine/adapter-kafka
- Provides
kafkaEventBus(...) - Use for streaming and service-to-service fanout
- Peer dependency:
kafkajs@^2.0.0
@loop-engine/adapter-http
- Provides
httpEventBus(...) - Use for webhooks and low-friction integrations
subscribe()is intentionally unsupported (emit-only adapter)
Build a custom adapter
Implement LoopStore exactly and pass it to:
1createLoopSystem({ loops, store: myStore })