// Documentation
TypeScript SDK reference.
The @cosmonapse/sdk surface - the idiomatic TypeScript port of the same protocol. Verified against packages/ts-sdk.
TS · 07
Synapse - transport adapters
A Synapse is the message bus. The TS port ships MemorySynapse (single process), DevSynapse (the cosmo:// dev broker), NatsSynapse, and KafkaSynapse. Map a URL with synapseFromUrl() / connectSynapse() (mirroring Python), or construct an adapter directly and pass it to the Dendrite.
interface
SynapseThe contract every adapter implements. The caller builds, connects, and closes it; the Dendrite only uses it.
synapse.ts
interface Synapse { connect(): Promise<void>; close(): Promise<void>; publish(subject: string, signal: Signal): Promise<void>; subscribe(subject: string, handler: MessageHandler, opts?: SubscribeOptions): Promise<Subscription>; request(subject: string, signal: Signal, opts?: RequestOptions): Promise<Signal>; } // Build from a URL (mirrors Python's synapse_from_url / connect_synapse): import { synapseFromUrl, connectSynapse } from "@cosmonapse/sdk"; const dev = synapseFromUrl("cosmo://127.0.0.1:7070"); // DevSynapse (built, not connected) const nats = synapseFromUrl("nats://nats:4222"); // NatsSynapse const kafka = synapseFromUrl("kafka://broker:9092"); // KafkaSynapse const syn = await connectSynapse("cosmo://127.0.0.1:7070"); // build + connect // memory:// has no URL - it is process-local, so build it directly: const mem = new MemorySynapse();
| Class | Use when |
|---|---|
| MemorySynapse | Tests and single-process apps. No external deps. |
| DevSynapse | Single-host dev against cosmo synapse start memory. URL scheme cosmo://. |
| NatsSynapse | Cross-process / cluster. Lazily imports nats; construct with new NatsSynapse({ url }) or nats:// URL. |
| KafkaSynapse | Kafka deployments. Lazily imports kafkajs; URL scheme kafka://. |
Have a feature in mind?
The protocol, SDKs, and CLI are still pre-1.0. If something here is missing, ambiguous, or wrong - open an issue and propose a change. Every breaking change is debated in DECISIONS.md first.