Skip to Content
sock8 is still in very early development. The API is unstable and subject to change.
Channel DSLDefining Channels

Defining Channels

Sock8 channels are defined statically using TypeScript and Zod schemas.

You define the paths, parameters, and message shapes for your realtime system up front.
This enables full type-safety, autocompletion, and runtime validation across client and server.


Basic Channel Definition

Each channel path maps to a Zod schema that describes the messages allowed on that channel.

There are two supported styles:

Tuple form

'notifications': [ z.object({ title: z.string(), body: z.string(), }), ]
  • The array’s first element is the message schema.
  • The second (optional) element is channel configuration (advanced, usually omitted).

Object form

'notifications': { schema: z.object({ title: z.string(), body: z.string(), }), }
  • This is exactly equivalent to the tuple form.
  • Some teams prefer the object style because it is easier to extend later.

Parameterized Channels

You can define dynamic segments inside the channel path by wrapping them in {}.

'chat.{roomId}.messages': [ z.object({ sender: z.string(), text: z.string(), }), ]

At compile-time, TypeScript will require you to provide the roomId parameter whenever you access or use this channel.

At runtime, Sock8 will also validate that the parameters are correct before resolving the subscription.

Parameterized channels allow you to scope realtime interactions cleanly — per user, per room, per organization, etc.


Channel Types

ConceptDescription
Static channelNo parameters. Path is fixed.
Parameterized channelHas {param} segments that must be provided at both compile-time and runtime.
Message schemaZod schema describing the structure of each published message.
Optional configurationAdvanced per-channel options (covered later).

Example: Multiple Channels

export const appChannels = channels({ notifications: [ z.object({ title: z.string(), body: z.string(), }), ], 'chat.{roomId}.messages': [ z.object({ sender: z.string(), text: z.string(), }), ], metrics: [ z.object({ cpu: z.number(), memory: z.number(), }), ], } satisfies ChannelTreeDefinition);
Last updated on