forrealtime

Realtime

The core class that owns your schema, Redis adapter, and history settings.

The Realtime class is the core of forrealtime. It owns your schema, Redis adapter, and history settings.

import { Realtime } from "forrealtime";

const realtime = new Realtime({
  schema,
  redis,
  history: {
    maxLength: 1000,
  },
});

Constructor options

OptionTypeDescription
schemaRecord<string, Record<string, ZodType>>Nested Zod schema defining event types
redisRedisAdapterRedis adapter instance
history.maxLengthnumberMaximum number of events to keep per stream
pluginsRealtimePlugin[]Plugins to extend the instance with additional methods

Schema shape

The schema is a two-level nested object. The top level is the namespace, the second level is the event name, and the value is a Zod type:

import z from "zod/v4";

const schema = {
  notification: {
    alert: z.string(),
    badge: z.number(),
  },
  chat: {
    message: z.object({
      text: z.string(),
      user: z.string(),
    }),
    typing: z.object({
      user: z.string(),
    }),
  },
};

On this page