---
title: Realtime API
description: Generated public TypeScript reference for @relkit/realtime.
search:
  exclude: true
sidebar:
  icon: braces
---

{/* Generated by apps/docs/scripts/generate.ts. Do not edit. */}

## Common APIs

- [defineChannel](/docs/api/realtime#definechannel)

For configuration and examples, read [realtime](/docs/modules/realtime), [access](/docs/modules/realtime/access), [react](/docs/modules/realtime/react).

## Frontend usage

[Subscribe to a channel](/docs/modules/realtime/react) shows the client side of this capability.

## Public imports

- `@relkit/realtime` — 75 exports
- `@relkit/realtime/operation-id` — 9 exports

## All exported APIs

Names link to their complete contracts. Re-exports share their original contract; legacy exports keep their separate identity. Examples link to the API's inline sample, a maintained repository usage, or the shared module walkthrough.

| API                                                                                                 | Kind  | Import from                                         | Example                                                                       |
| --------------------------------------------------------------------------------------------------- | ----- | --------------------------------------------------- | ----------------------------------------------------------------------------- |
| [AcquirePresenceLease](/docs/api/realtime#acquirepresencelease-type-alias)                          | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#acquirepresencelease-type-alias)             |
| [AppendChannelEvent](/docs/api/realtime#appendchannelevent-interface)                               | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#appendchannelevent-interface)                |
| [AppendReceiptLookup](/docs/api/realtime#appendreceiptlookup-type-alias)                            | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#appendreceiptlookup-type-alias)              |
| [ChannelCheckpoint](/docs/api/realtime#channelcheckpoint-interface)                                 | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channelcheckpoint-interface)                 |
| [ChannelClientPolicy](/docs/api/realtime#channelclientpolicy-type-alias)                            | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channelclientpolicy-type-alias)              |
| [ChannelDescriptor](/docs/api/realtime#channeldescriptor-type-alias)                                | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channeldescriptor-type-alias)                |
| [ChannelDescriptorAny](/docs/api/realtime#channeldescriptorany-type-alias)                          | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channeldescriptorany-type-alias)             |
| [ChannelDescriptorData](/docs/api/realtime#channeldescriptordata-type-alias)                        | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channeldescriptordata-type-alias)            |
| [ChannelEventPage](/docs/api/realtime#channeleventpage-interface)                                   | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channeleventpage-interface)                  |
| [ChannelEventRecord](/docs/api/realtime#channeleventrecord-interface)                               | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channeleventrecord-interface)                |
| [ChannelGrant](/docs/api/realtime#channelgrant-interface)                                           | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channelgrant-interface)                      |
| [ChannelGuard](/docs/api/realtime#channelguard-type-alias)                                          | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channelguard-type-alias)                     |
| [ChannelPresence](/docs/api/realtime#channelpresence-type-alias)                                    | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channelpresence-type-alias)                  |
| [ChannelReplay](/docs/api/realtime#channelreplay-interface)                                         | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channelreplay-interface)                     |
| [ChannelTriggerOptions](/docs/api/realtime#channeltriggeroptions-interface)                         | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channeltriggeroptions-interface)             |
| [ChannelValidationError](/docs/api/realtime#channelvalidationerror-class)                           | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#channelvalidationerror-class)                |
| [CountPresence](/docs/api/realtime#countpresence-interface)                                         | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#countpresence-interface)                     |
| [createOperationId](/docs/api/realtime#createoperationid)                                           | Value | `@relkit/realtime`, `@relkit/realtime/operation-id` | [API example](/docs/api/realtime#createoperationid)                           |
| [createOperationIdEffect](/docs/api/realtime#createoperationideffect)                               | Value | `@relkit/realtime`, `@relkit/realtime/operation-id` | [API example](/docs/api/realtime#createoperationideffect)                     |
| [createProviderRealtimeDispatcher](/docs/api/realtime#createproviderrealtimedispatcher)             | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#createproviderrealtimedispatcher)            |
| [createProviderRealtimeDispatcherEffect](/docs/api/realtime#createproviderrealtimedispatchereffect) | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#createproviderrealtimedispatchereffect)      |
| [currentRealtimeDispatcher](/docs/api/realtime#currentrealtimedispatcher)                           | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#currentrealtimedispatcher)                   |
| [currentRealtimeDispatcherEffect](/docs/api/realtime#currentrealtimedispatchereffect)               | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#currentrealtimedispatchereffect)             |
| [defineChannel](/docs/api/realtime#definechannel)                                                   | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#definechannel)                               |
| [defineChannelEffect](/docs/api/realtime#definechanneleffect)                                       | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#definechanneleffect)                         |
| [DefineChannelOptions](/docs/api/realtime#definechanneloptions-interface)                           | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#definechanneloptions-interface)              |
| [getChannelPresenceEffect](/docs/api/realtime#getchannelpresenceeffect)                             | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#getchannelpresenceeffect)                    |
| [isChannelDescriptor](/docs/api/realtime#ischanneldescriptor)                                       | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#ischanneldescriptor)                         |
| [isChannelDescriptorEffect](/docs/api/realtime#ischanneldescriptoreffect)                           | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#ischanneldescriptoreffect)                   |
| [limitsForEffect](/docs/api/realtime#limitsforeffect-1)                                             | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#limitsforeffect-1)                           |
| [LookupAppendReceipt](/docs/api/realtime#lookupappendreceipt-interface)                             | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#lookupappendreceipt-interface)               |
| [MemberPresence](/docs/api/realtime#memberpresence-interface)                                       | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#memberpresence-interface)                    |
| [MemberPresenceDescriptor](/docs/api/realtime#memberpresencedescriptor-interface)                   | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#memberpresencedescriptor-interface)          |
| [observeRealtime](/docs/api/realtime#observerealtime)                                               | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#observerealtime)                             |
| [OperationIdEntropy](/docs/api/realtime#operationidentropy-class)                                   | Value | `@relkit/realtime`, `@relkit/realtime/operation-id` | [API example](/docs/api/realtime#operationidentropy-class)                    |
| [OperationIdEntropyLive](/docs/api/realtime#operationidentropylive)                                 | Value | `@relkit/realtime`, `@relkit/realtime/operation-id` | [API example](/docs/api/realtime#operationidentropylive)                      |
| [OperationIdError](/docs/api/realtime#operationiderror-class)                                       | Value | `@relkit/realtime`, `@relkit/realtime/operation-id` | [API example](/docs/api/realtime#operationiderror-class)                      |
| [OperationIdFailure](/docs/api/realtime#operationidfailure-class)                                   | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#operationidfailure-class)                    |
| [operationIdTimestamp](/docs/api/realtime#operationidtimestamp)                                     | Value | `@relkit/realtime`, `@relkit/realtime/operation-id` | [API example](/docs/api/realtime#operationidtimestamp)                        |
| [operationIdTimestampEffect](/docs/api/realtime#operationidtimestampeffect)                         | Value | `@relkit/realtime`, `@relkit/realtime/operation-id` | [API example](/docs/api/realtime#operationidtimestampeffect)                  |
| [parseOperationId](/docs/api/realtime#parseoperationid)                                             | Value | `@relkit/realtime`, `@relkit/realtime/operation-id` | [API example](/docs/api/realtime#parseoperationid)                            |
| [parseOperationIdEffect](/docs/api/realtime#parseoperationideffect)                                 | Value | `@relkit/realtime`, `@relkit/realtime/operation-id` | [API example](/docs/api/realtime#parseoperationideffect)                      |
| [PresenceLeaseRequest](/docs/api/realtime#presenceleaserequest-interface)                           | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#presenceleaserequest-interface)              |
| [PresenceMember](/docs/api/realtime#presencemember-interface)                                       | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#presencemember-interface)                    |
| [PresenceSnapshot](/docs/api/realtime#presencesnapshot-type-alias)                                  | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#presencesnapshot-type-alias)                 |
| [ProviderRealtimeDispatcherOptions](/docs/api/realtime#providerrealtimedispatcheroptions-interface) | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#providerrealtimedispatcheroptions-interface) |
| [providerSourceLayer](/docs/api/realtime#providersourcelayer)                                       | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#providersourcelayer)                         |
| [ReadChannelEvents](/docs/api/realtime#readchannelevents-interface)                                 | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#readchannelevents-interface)                 |
| [ReadPresenceRequest](/docs/api/realtime#readpresencerequest-type-alias)                            | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#readpresencerequest-type-alias)              |
| [readProviderPresenceEffect](/docs/api/realtime#readproviderpresenceeffect)                         | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#readproviderpresenceeffect)                  |
| [RealtimeActionError](/docs/api/realtime#realtimeactionerror-class)                                 | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimeactionerror-class)                   |
| [RealtimeDispatcher](/docs/api/realtime#realtimedispatcher-interface)                               | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimedispatcher-interface)                |
| [RealtimeDispatcherError](/docs/api/realtime#realtimedispatchererror-class)                         | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimedispatchererror-class)               |
| [RealtimeDispatcherLive](/docs/api/realtime#realtimedispatcherlive)                                 | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimedispatcherlive)                      |
| [RealtimeDispatcherService](/docs/api/realtime#realtimedispatcherservice-class)                     | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimedispatcherservice-class)             |
| [RealtimeLimits](/docs/api/realtime#realtimelimits-interface)                                       | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimelimits-interface)                    |
| [RealtimeOperation](/docs/api/realtime#realtimeoperation-type-alias)                                | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimeoperation-type-alias)                |
| [RealtimeProvider](/docs/api/realtime#realtimeprovider-interface)                                   | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimeprovider-interface)                  |
| [RealtimeProviderError](/docs/api/realtime#realtimeprovidererror-class)                             | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimeprovidererror-class)                 |
| [RealtimeProviderSource](/docs/api/realtime#realtimeprovidersource-class)                           | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimeprovidersource-class)                |
| [RealtimeProviderSourceService](/docs/api/realtime#realtimeprovidersourceservice-interface)         | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimeprovidersourceservice-interface)     |
| [RealtimeScope](/docs/api/realtime#realtimescope-interface)                                         | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimescope-interface)                     |
| [RealtimeTelemetry](/docs/api/realtime#realtimetelemetry-class)                                     | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimetelemetry-class)                     |
| [RealtimeTelemetryLive](/docs/api/realtime#realtimetelemetrylive)                                   | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimetelemetrylive)                       |
| [RealtimeTelemetryService](/docs/api/realtime#realtimetelemetryservice-interface)                   | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#realtimetelemetryservice-interface)          |
| [ReleasePresenceLease](/docs/api/realtime#releasepresencelease-type-alias)                          | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#releasepresencelease-type-alias)             |
| [RenewPresenceLease](/docs/api/realtime#renewpresencelease-type-alias)                              | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#renewpresencelease-type-alias)               |
| [runWithRealtimeDispatcher](/docs/api/realtime#runwithrealtimedispatcher)                           | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#runwithrealtimedispatcher)                   |
| [runWithRealtimeDispatcherEffect](/docs/api/realtime#runwithrealtimedispatchereffect)               | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#runwithrealtimedispatchereffect)             |
| [setActiveRealtimeDispatcher](/docs/api/realtime#setactiverealtimedispatcher)                       | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#setactiverealtimedispatcher)                 |
| [setActiveRealtimeDispatcherEffect](/docs/api/realtime#setactiverealtimedispatchereffect)           | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#setactiverealtimedispatchereffect)           |
| [triggerChannelEffect](/docs/api/realtime#triggerchanneleffect)                                     | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#triggerchanneleffect)                        |
| [triggerProviderEffect](/docs/api/realtime#triggerprovidereffect)                                   | Value | `@relkit/realtime`                                  | [API example](/docs/api/realtime#triggerprovidereffect)                       |
| [TriggerReceipt](/docs/api/realtime#triggerreceipt-interface)                                       | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#triggerreceipt-interface)                    |
| [WaitForChannelEvents](/docs/api/realtime#waitforchannelevents-interface)                           | Type  | `@relkit/realtime`                                  | [API example](/docs/api/realtime#waitforchannelevents-interface)              |

## `channel-operations.ts`

### getChannelPresenceEffect

Reads a channel's presence snapshot in the Effect path.

**Example**

```ts
Effect.runPromise(getChannelPresenceEffect(channel, {}));
```

**Signature**

```ts
declare const getChannelPresenceEffect: (
  channel: ChannelDescriptorData,
  params: unknown,
) => Effect.Effect<
  PresenceSnapshot,
  ChannelValidationError | RealtimeDispatcherError | RealtimeProviderError,
  never
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-operations.ts#L85)

### runChannelPromise

Converts an Effect result to the legacy Promise rejection shape.

**Throws**

TypeError, Error, or the original provider rejection on failure.

**Example**

```ts
await runChannelPromise(triggerChannelEffect(channel, {}, "posted", "hello"));
```

**Signature**

```ts
declare const runChannelPromise: <A, E>(effect: Effect.Effect<A, E>) => Promise<A>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-operations.ts#L18)

### triggerChannelEffect

Validates and dispatches one channel event in the Effect path.

**Example**

```ts
Effect.runPromise(triggerChannelEffect(channel, {}, "posted", "hello"));
```

**Signature**

```ts
declare const triggerChannelEffect: (
  channel: ChannelDescriptorData,
  params: unknown,
  event: string,
  payload: unknown,
  options?: ChannelTriggerOptions | undefined,
) => Effect.Effect<
  TriggerReceipt,
  ChannelValidationError | RealtimeDispatcherError | RealtimeProviderError,
  never
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-operations.ts#L41)

## `channel-policy.ts`

### copyChannelClient

Copies a client policy.

**Throws**

TypeError for a malformed policy.

**Example**

```ts
copyChannelClient({ public: true });
```

**Signature**

```ts
declare const copyChannelClient: (value: unknown) => ChannelClientPolicy<ChannelGuard> | undefined;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-policy.ts#L56)

### copyChannelClientEffect

Copies an authored client policy into a descriptor value.

**Example**

```ts
Effect.runSync(copyChannelClientEffect({ public: true }));
```

**Signature**

```ts
declare const copyChannelClientEffect: (
  value: unknown,
) => Effect.Effect<
  { public: true; authorize?: never } | { authorize: ChannelGuard; public?: never } | undefined,
  ChannelValidationError,
  never
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-policy.ts#L21)

### copyChannelPresence

Copies a presence policy.

**Throws**

TypeError for malformed or unprotected member presence.

**Example**

```ts
copyChannelPresence("count", undefined);
```

**Signature**

```ts
declare const copyChannelPresence: (
  value: unknown,
  client: ChannelClientPolicy<ChannelGuard> | undefined,
) => ChannelPresence | undefined;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-policy.ts#L116)

### copyChannelPresenceEffect

Copies presence and checks member authorization.

**Example**

```ts
Effect.runSync(copyChannelPresenceEffect("count", undefined));
```

**Signature**

```ts
declare const copyChannelPresenceEffect: (
  value: unknown,
  client: ChannelClientPolicy<ChannelGuard> | undefined,
) => Effect.Effect<
  | "count"
  | {
      member: MemberPresenceDescriptor["member"];
      resolve: MemberPresenceDescriptor["resolve"];
      maxMembers: number;
    }
  | undefined,
  ChannelValidationError,
  never
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-policy.ts#L73)

### copyChannelReplay

Copies replay limits.

**Throws**

TypeError for invalid limits.

**Example**

```ts
copyChannelReplay({ retentionMs: 100, maxEvents: 10 });
```

**Signature**

```ts
declare const copyChannelReplay: (value: unknown) => ChannelReplay | undefined;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-policy.ts#L155)

### copyChannelReplayEffect

Copies replay limits into a descriptor value.

**Example**

```ts
Effect.runSync(copyChannelReplayEffect({ retentionMs: 100, maxEvents: 10 }));
```

**Signature**

```ts
declare const copyChannelReplayEffect: (
  value: unknown,
) => Effect.Effect<
  { retentionMs: number; maxEvents: number } | undefined,
  ChannelValidationError,
  never
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-policy.ts#L127)

## `channel-validation.ts`

### assertChannelSchema

Asserts a Standard Schema v1 validator.

**Throws**

TypeError for a malformed schema.

**Example**

```ts
assertChannelSchema(schema, "params");
```

**Signature**

```ts
declare const assertChannelSchema: (
  value: unknown,
  name: string,
) => asserts value is StandardSchemaV1;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-validation.ts#L84)

### assertChannelSchemaEffect

Validates a schema shape with a tagged error.

**Example**

```ts
Effect.runSync(assertChannelSchemaEffect(schema, "params"));
```

**Signature**

```ts
declare const assertChannelSchemaEffect: (
  value: unknown,
  name: string,
) => Effect.Effect<undefined, ChannelValidationError, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-validation.ts#L65)

### copyChannelEvents

Copies an event schema map.

**Throws**

TypeError for invalid names or schemas.

**Example**

```ts
copyChannelEvents({ changed: schema });
```

**Signature**

```ts
declare const copyChannelEvents: (value: unknown) => Readonly<Record<string, StandardSchemaV1>>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-validation.ts#L177)

### copyChannelEventsEffect

Copies and normalizes an authored event schema map.

**Example**

```ts
Effect.runSync(copyChannelEventsEffect({ changed: schema }));
```

**Signature**

```ts
declare const copyChannelEventsEffect: (
  value: unknown,
) => Effect.Effect<
  Readonly<Record<string, StandardSchemaV1<unknown, unknown>>>,
  ChannelValidationError,
  never
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-validation.ts#L145)

### isChannelSchema

Checks a Standard Schema v1 validator.

**Example**

```ts
isChannelSchema(schema);
```

**Signature**

```ts
declare const isChannelSchema: (value: unknown) => value is StandardSchemaV1;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-validation.ts#L56)

### isChannelSchemaEffect

Checks the Standard Schema v1 shape in the Effect path.

**Example**

```ts
Effect.runSync(isChannelSchemaEffect(schema));
```

**Signature**

```ts
declare const isChannelSchemaEffect: (value: unknown) => Effect.Effect<boolean, never, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-validation.ts#L41)

### isRecord

Checks whether a value is a non-array record.

**Example**

```ts
isRecord({});
```

**Signature**

```ts
declare const isRecord: (value: unknown) => value is Record<PropertyKey, unknown>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-validation.ts#L33)

### isRecordEffect

Checks an unknown value for the record shape in the Effect path.

**Example**

```ts
Effect.runSync(isRecordEffect({}));
```

**Signature**

```ts
declare const isRecordEffect: (value: unknown) => Effect.Effect<boolean, never, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-validation.ts#L22)

### runChannelValidation

Runs a validation effect while retaining the public TypeError contract.

**Throws**

TypeError for a tagged validation failure.

**Example**

```ts
runChannelValidation(copyChannelEventsEffect({ posted: schema }));
```

**Signature**

```ts
declare const runChannelValidation: <A>(effect: Effect.Effect<A, ChannelValidationError>) => A;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-validation.ts#L12)

### validateChannelValue

Validates a value through the Promise compatibility API.

**Throws**

TypeError when validation fails.

**Example**

```ts
await validateChannelValue(schema, value, "params");
```

**Signature**

```ts
declare const validateChannelValue: (
  schema: StandardSchemaV1,
  value: unknown,
  name: string,
) => Promise<unknown>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-validation.ts#L126)

### validateChannelValueEffect

Validates a value with a Standard Schema validator.

**Example**

```ts
Effect.runPromise(validateChannelValueEffect(schema, value, "params"));
```

**Signature**

```ts
declare const validateChannelValueEffect: (
  schema: StandardSchemaV1<unknown, unknown>,
  value: unknown,
  name: string,
) => Effect.Effect<unknown, ChannelValidationError, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel-validation.ts#L97)

## `channel.ts`

### defineChannel

Defines a typed channel for validated backend publication and observation.

**Throws**

TypeError for invalid channel options.

**Example**

```ts
import { defineChannel } from "@relkit/realtime";
import { z } from "@relkit/schema";
const alerts = defineChannel({
  id: "alerts",
  params: z.object({}),
  events: { posted: z.string() },
});
```

**Signature**

```ts
declare const defineChannel: <
  const Id extends string,
  const ParamsSchema extends StandardSchemaV1,
  const Events extends Readonly<Record<string, StandardSchemaV1>>,
  const Client extends ChannelClientPolicy<ChannelGuard<InferOutput<ParamsSchema>>> | undefined,
  const Presence extends ChannelPresence<InferOutput<ParamsSchema>> | undefined = undefined,
>(
  options: DefineChannelOptions<Id, ParamsSchema, Events, Client, Presence>,
) => ChannelDescriptor<Id, ParamsSchema, Events, Client, Presence>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.ts#L132)

Since v0.4.0

#### Backend and frontend example

**Backend** — these maintained files define the operation used by the frontend below.

```ts title="examples/commerce/src/services/announcements/channels/announcements.channel.ts"
/** Declares public posted-announcement events with five-minute replay retention and a thousand-event limit. */
import { defineChannel } from "@relkit/app/realtime";
import { z } from "@relkit/app/schema";

const announcements = defineChannel({
  id: "announcements.feed",
  params: z.object({}),
  events: { posted: z.object({ message: z.string(), postedAt: z.string() }) },
  client: { public: true },
  replay: { retentionMs: 300_000, maxEvents: 1_000 },
});

export default announcements;
```

**Frontend**

After [frontend setup and pulling the commerce contract](/guides/frontend/connect-react), render
this component under the provider. It subscribes to this declaration's `announcements.feed` channel:

```tsx title="src/Announcements.tsx"
"use client";

/** Combines the commerce announcement query with channel invalidation and reconnect recovery. */
import { useChannel, useRoute } from "@relkit/client/react";

/** Restores authoritative messages on publication, catch-up, and replay gaps.
 * @returns The current messages with query failure and channel status feedback. */
export function Announcements() {
  const messages = useRoute("GET /announcements", { input: {} });
  const channel = useChannel("announcements.feed", {
    params: {},
    on: {
      posted: () => {
        void messages.refetch();
      },
    },
    onCaughtUp: async () => {
      await messages.refetch();
    },
    onGap: async () => {
      await messages.refetch();
    },
  });

  if (messages.isError) return <p role="alert">{messages.error.message}</p>;
  return (
    <section>
      <p role="status">Channel: {channel.status}</p>
      {messages.isPending && <p>Loading messages…</p>}
      <ul>
        {messages.data?.messages.map((message, index) => (
          <li key={index}>{message}</li>
        ))}
      </ul>
    </section>
  );
}
```

`params: {}` selects the channel's empty partition schema. `posted` is a declared event, so its
callback is checked against the event map. The route query restores the authoritative messages
after updates, catch-up, or replay gaps. Backend `trigger()` publishes; the browser subscribes.

Reference: [`useChannel`](/docs/api/client#usechannel), [`useRealtime`](/docs/api/client#userealtime).
Continue with [subscription and recovery](/docs/modules/realtime/react).

### "./channel.types.js" (namespace export)

Re-exports all named exports from the "./channel.types.js" module.

**Signature**

```ts
export * from "./channel.types.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.ts#L31)

### defineChannelEffect

Constructs a typed channel descriptor through validated Effect operations.

**Example**

```ts
Effect.runSync(defineChannelEffect({ id: "news", params: schema, events: { posted: schema } }));
```

**Signature**

```ts
declare const defineChannelEffect: <
  const Id extends string,
  const ParamsSchema extends StandardSchemaV1,
  const Events extends Readonly<Record<string, StandardSchemaV1>>,
  const Client extends ChannelClientPolicy<ChannelGuard<InferOutput<ParamsSchema>>> | undefined,
  const Presence extends ChannelPresence<InferOutput<ParamsSchema>> | undefined = undefined,
>(
  options: DefineChannelOptions<Id, ParamsSchema, Events, Client, Presence>,
) => Effect.Effect<
  ChannelDescriptor<Id, ParamsSchema, Events, Client, Presence>,
  ChannelValidationError,
  never
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.ts#L38)

### getChannelPresenceEffect

**Signature**

```ts
declare const getChannelPresenceEffect: (
  channel: ChannelDescriptorData,
  params: unknown,
) => Effect.Effect<
  PresenceSnapshot,
  ChannelValidationError | RealtimeDispatcherError | RealtimeProviderError,
  never
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.ts#L32)

### isChannelDescriptor

Checks for a channel descriptor.

**Example**

```ts
isChannelDescriptor(channel);
```

**Signature**

```ts
declare const isChannelDescriptor: (value: unknown) => value is ChannelDescriptorAny;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.ts#L162)

### isChannelDescriptorEffect

Checks for a channel descriptor in the Effect path.

**Example**

```ts
Effect.runSync(isChannelDescriptorEffect(channel));
```

**Signature**

```ts
declare const isChannelDescriptorEffect: (value: unknown) => Effect.Effect<boolean, never, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.ts#L150)

### triggerChannelEffect

**Signature**

```ts
declare const triggerChannelEffect: (
  channel: ChannelDescriptorData,
  params: unknown,
  event: string,
  payload: unknown,
  options?: ChannelTriggerOptions | undefined,
) => Effect.Effect<
  TriggerReceipt,
  ChannelValidationError | RealtimeDispatcherError | RealtimeProviderError,
  never
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.ts#L32)

## `channel.types.ts`

### ChannelClientPolicy (type alias)

Public access or an authorization guard, exclusively.

**Example**

```ts
const policy: ChannelClientPolicy<ChannelGuard> = { public: true };
```

**Signature**

```ts
type ChannelClientPolicy<Guard> =
  | { readonly public: true; readonly authorize?: never }
  | { readonly authorize: Guard; readonly public?: never };
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.types.ts#L19)

### ChannelDescriptor (type alias)

A typed channel descriptor with backend publication methods.

**Example**

```ts
const channel: ChannelDescriptorAny = defineChannel(options);
```

**Signature**

```ts
type ChannelDescriptor<
  Id extends string,
  ParamsSchema extends StandardSchemaV1,
  Events extends Readonly<Record<string, StandardSchemaV1>>,
  Client extends ChannelClientPolicy<ChannelGuard<InferOutput<ParamsSchema>>> | undefined,
  Presence extends ChannelPresence<InferOutput<ParamsSchema>> | undefined,
> = DescriptorBase<"channel", Id> & {
  readonly params: ParamsSchema;
  readonly events: Events;
  readonly profile?: string;
  readonly client?: Client;
  readonly replay?: ChannelReplay;
  readonly presence?: Presence;
  /** Validates and publishes one event through the bound dispatcher.
   * @param params - Schema input for channel parameters.
   * @param event - One of the declared event names.
   * @param payload - Input for the selected event schema.
   * @param options - Optional idempotency key.
   * @returns A trigger receipt or validation/provider rejection.
   * @example await channel.trigger({ orderId: "o1" }, "changed", { status: "paid" });
   */
  readonly trigger: <Name extends Extract<keyof Events, string>>(
    params: InferInput<ParamsSchema>,
    event: Name,
    payload: InferInput<Events[Name]>,
    options?: { readonly idempotencyKey?: OperationId },
  ) => Promise<TriggerReceipt>;
} & ([Presence] extends [undefined]
    ? {}
    : {
        /** Reads validated presence through the bound dispatcher.
         * @param params - Schema input for channel parameters.
         * @returns Count or member presence, or a validation/provider rejection.
         * @example await channel.getPresence({ orderId: "o1" });
         */
        readonly getPresence: (
          params: InferInput<ParamsSchema>,
        ) => Promise<PresenceResult<Presence>>;
      });
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.types.ts#L49)

### ChannelDescriptorAny (type alias)

Erased descriptor type retained for existing public API consumers.

**Example**

```ts
const channel: ChannelDescriptorAny = registry.get("news");
```

**Signature**

```ts
type ChannelDescriptorAny = ChannelDescriptor<
  string,
  StandardSchemaV1,
  Readonly<Record<string, StandardSchemaV1>>,
  ChannelClientPolicy<ChannelGuard> | undefined,
  ChannelPresence | undefined
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.types.ts#L97)

### ChannelDescriptorData (type alias)

Descriptor data read by provider and transport boundaries.
Typed trigger methods remain on ChannelDescriptor; providers read only this data.

**Example**

```ts
const data: ChannelDescriptorData = defineChannel(options);
```

**Signature**

```ts
type ChannelDescriptorData = DescriptorBase<"channel", string> & {
  readonly params: StandardSchemaV1;
  readonly events: Readonly<Record<string, StandardSchemaV1>>;
  readonly profile?: string;
  readonly client?: ChannelClientPolicy<ChannelGuard>;
  readonly replay?: ChannelReplay;
  readonly presence?: ChannelPresence;
};
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.types.ts#L108)

### ChannelGuard (type alias)

Authorizes channel parameters against an application context.

**Example**

```ts
const allow: ChannelGuard = async () => true;
```

**Signature**

```ts
type ChannelGuard<Params = unknown, Context = unknown> = (
  params: Params,
  context: Context,
) => MaybePromise<boolean>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.types.ts#L12)

### ChannelPresence (type alias)

Count-only or protected member presence.

**Example**

```ts
const presence: ChannelPresence = "count";
```

**Signature**

```ts
type ChannelPresence<Params = unknown, Context = unknown> =
  "count" | MemberPresenceDescriptor<StandardSchemaV1, Params, Context>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.types.ts#L37)

### ChannelReplay (interface)

Retention settings copied into a channel descriptor.

**Example**

```ts
const replay: ChannelReplay = { retentionMs: 60000, maxEvents: 100 };
```

**Signature**

```ts
export interface ChannelReplay {
  readonly retentionMs: number;
  readonly maxEvents: number;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.types.ts#L42)

### DefineChannelOptions (interface)

Authored channel options before validation and normalization.

**Example**

```ts
const options: DefineChannelOptions<
  "news",
  typeof schema,
  { posted: typeof schema },
  undefined,
  undefined
> = {
  id: "news",
  params: schema,
  events: { posted: schema },
};
```

**Signature**

```ts
export interface DefineChannelOptions<
  Id extends string,
  ParamsSchema extends StandardSchemaV1,
  Events extends Readonly<Record<string, StandardSchemaV1>>,
  Client extends ChannelClientPolicy<ChannelGuard<InferOutput<ParamsSchema>>> | undefined,
  Presence extends ChannelPresence<InferOutput<ParamsSchema>> | undefined,
> extends DescriptorMetadata {
  readonly id: Id;
  readonly params: ParamsSchema;
  readonly events: Events;
  readonly profile?: string;
  readonly client?: Client;
  readonly replay?: ChannelReplay;
  readonly presence?: Presence;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.types.ts#L119)

### MemberPresenceDescriptor (interface)

Describes validated member presence for a protected channel.

**Example**

```ts
const presence: MemberPresenceDescriptor<typeof schema> = {
  member: schema,
  resolve: async () => ({ name: "Ada" }),
  maxMembers: 10,
};
```

**Signature**

```ts
export interface MemberPresenceDescriptor<
  MemberSchema extends StandardSchemaV1 = StandardSchemaV1,
  Params = unknown,
  Context = unknown,
> {
  readonly member: MemberSchema;
  readonly resolve: (params: Params, context: Context) => MaybePromise<InferInput<MemberSchema>>;
  readonly maxMembers: number;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/channel.types.ts#L25)

## `dispatch.ts`

### "./dispatch.types.js" (namespace export)

Re-exports all named exports from the "./dispatch.types.js" module.

**Signature**

```ts
export * from "./dispatch.types.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/dispatch.ts#L6)

### RealtimeDispatcherLive

Resolves the currently bound dispatcher when an Effect requests it.

**Example**

```ts
Effect.provide(currentRealtimeDispatcherEffect(), RealtimeDispatcherLive);
```

**Signature**

```ts
declare const RealtimeDispatcherLive: Layer.Layer<
  RealtimeDispatcherService,
  RealtimeDispatcherError,
  never
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/dispatch.ts#L19)

### RealtimeDispatcherService (class)

Injectable dispatcher for Effect-native channel operations.

**Example**

```ts
Effect.provide(currentRealtimeDispatcherEffect(), RealtimeDispatcherLive);
```

**Signature**

```ts
declare class RealtimeDispatcherService
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/dispatch.ts#L12)

### currentRealtimeDispatcher

Returns the dispatcher bound to the current generation.

**Throws**

Error when no dispatcher is active.

**Example**

```ts
currentRealtimeDispatcher();
```

**Signature**

```ts
declare const currentRealtimeDispatcher: () => RealtimeDispatcher;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/dispatch.ts#L138)

### currentRealtimeDispatcherEffect

Resolves the current dispatcher with a typed missing-binding error.

**Example**

```ts
Effect.runPromise(currentRealtimeDispatcherEffect());
```

**Signature**

```ts
declare const currentRealtimeDispatcherEffect: () => Effect.Effect<
  RealtimeDispatcher,
  RealtimeDispatcherError,
  never
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/dispatch.ts#L117)

### runWithRealtimeDispatcher

Executes an action under a dispatcher scope.

**Throws**

The action's synchronous error or an Effect runtime defect.

**Example**

```ts
runWithRealtimeDispatcher(dispatcher, () => channel.trigger({}, "posted", "hello"));
```

**Signature**

```ts
declare const runWithRealtimeDispatcher: <Value>(
  dispatcher: RealtimeDispatcher,
  action: () => Value,
) => Value;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/dispatch.ts#L93)

### runWithRealtimeDispatcherEffect

Runs an action with a dispatcher in async-local generation scope.

**Example**

```ts
Effect.runSync(runWithRealtimeDispatcherEffect(dispatcher, () => 1));
```

**Signature**

```ts
declare const runWithRealtimeDispatcherEffect: <Value>(
  dispatcher: RealtimeDispatcher,
  action: (signal: AbortSignal) => Value,
) => Effect.Effect<Awaited<Value>, RealtimeActionError, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/dispatch.ts#L65)

### setActiveRealtimeDispatcher

Sets the fallback dispatcher for code outside a generation scope.

**Example**

```ts
setActiveRealtimeDispatcher(dispatcher);
```

**Signature**

```ts
declare const setActiveRealtimeDispatcher: (dispatcher: RealtimeDispatcher | undefined) => void;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/dispatch.ts#L41)

### setActiveRealtimeDispatcherEffect

Changes the fallback dispatcher in the Effect path.

**Example**

```ts
Effect.runSync(setActiveRealtimeDispatcherEffect(dispatcher));
```

**Signature**

```ts
declare const setActiveRealtimeDispatcherEffect: (
  dispatcher: RealtimeDispatcher | undefined,
) => Effect.Effect<void, never, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/dispatch.ts#L30)

## `dispatch.types.ts`

### ChannelTriggerOptions (interface)

Options attached to a channel trigger request.

**Example**

```ts
const options: ChannelTriggerOptions = { idempotencyKey: id };
```

**Signature**

```ts
export interface ChannelTriggerOptions {
  readonly idempotencyKey?: OperationId;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/dispatch.types.ts#L7)

### RealtimeDispatcher (interface)

A generation-bound dispatcher for validated realtime operations.

**Example**

```ts
const dispatcher: RealtimeDispatcher = {
  trigger: async () => receipt,
  getPresence: async () => presence,
};
```

**Signature**

```ts
export interface RealtimeDispatcher {
  /** Publishes a validated event.
   * @param request - Channel, parameters, event, payload, and optional idempotency key.
   * @param signal - Optional cancellation signal for in-flight work.
   * @returns A trigger receipt or a provider rejection.
   * @example await dispatcher.trigger({ channel, params: {}, event: "posted", payload: "hello" });
   */
  readonly trigger: (
    request: {
      readonly channel: ChannelDescriptorData;
      readonly params: unknown;
      readonly event: string;
      readonly payload: unknown;
      readonly options?: ChannelTriggerOptions;
    },
    signal?: AbortSignal,
  ) => MaybePromise<TriggerReceipt>;
  /** Reads the current presence snapshot.
   * @param request - Channel and validated parameters.
   * @param signal - Optional cancellation signal for in-flight work.
   * @returns Presence snapshot or a provider rejection.
   * @example await dispatcher.getPresence({ channel, params: {} });
   */
  readonly getPresence: (
    request: {
      readonly channel: ChannelDescriptorData;
      readonly params: unknown;
    },
    signal?: AbortSignal,
  ) => MaybePromise<PresenceSnapshot>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/dispatch.types.ts#L13)

## `index.ts`

### "./channel.js" (namespace export)

Re-exports all named exports from the "./channel.js" module.

**Signature**

```ts
export * from "./channel.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/index.ts#L1)

### "./dispatch.js" (namespace export)

Re-exports all named exports from the "./dispatch.js" module.

**Signature**

```ts
export * from "./dispatch.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/index.ts#L4)

### "./operation-id.js" (namespace export)

Re-exports all named exports from the "./operation-id.js" module.

**Signature**

```ts
export * from "./operation-id.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/index.ts#L3)

### "./provider-dispatcher.js" (namespace export)

Re-exports all named exports from the "./provider-dispatcher.js" module.

**Signature**

```ts
export * from "./provider-dispatcher.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/index.ts#L6)

### "./provider.js" (namespace export)

Re-exports all named exports from the "./provider.js" module.

**Signature**

```ts
export * from "./provider.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/index.ts#L2)

### "./realtime-errors.js" (namespace export)

Re-exports all named exports from the "./realtime-errors.js" module.

**Signature**

```ts
export * from "./realtime-errors.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/index.ts#L7)

### "./realtime-observability.js" (namespace export)

Re-exports all named exports from the "./realtime-observability.js" module.

**Signature**

```ts
export * from "./realtime-observability.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/index.ts#L8)

### "./realtime-observability.types.js" (namespace export)

Re-exports all named exports from the "./realtime-observability.types.js" module.

**Signature**

```ts
export * from "./realtime-observability.types.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/index.ts#L9)

### "./types.js" (namespace export)

Re-exports all named exports from the "./types.js" module.

**Signature**

```ts
export * from "./types.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/index.ts#L5)

## `operation-id.ts`

### OperationIdEntropy (class)

Injectable random-byte service for operation ID generation.

**Example**

```ts
Effect.provide(createOperationIdEffect(0), OperationIdEntropyLive);
```

**Signature**

```ts
declare class OperationIdEntropy
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/operation-id.ts#L28)

### OperationIdEntropyLive

Cryptographic entropy for live UUIDv7 creation.

**Example**

```ts
Effect.provide(createOperationIdEffect(0), OperationIdEntropyLive);
```

**Signature**

```ts
declare const OperationIdEntropyLive: Layer.Layer<OperationIdEntropy, never, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/operation-id.ts#L35)

### OperationIdError (class)

Compatibility error for invalid or expired operation IDs.

**Example**

```ts
new OperationIdError("OPERATION_ID_INVALID", "Operation ID must be a UUIDv7.");
```

**Signature**

```ts
declare class OperationIdError { constructor(
    readonly code: "OPERATION_ID_INVALID" | "IDEMPOTENCY_WINDOW_EXPIRED",
    message: string,
  ) }
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/operation-id.ts#L10)

### createOperationId

Creates a UUIDv7 operation ID.

**Throws**

RangeError for an invalid timestamp.

**Example**

```ts
createOperationId(Date.now());
```

**Signature**

```ts
declare const createOperationId: (now?: number) => OperationId;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/operation-id.ts#L151)

### createOperationIdEffect

Creates a UUIDv7 ID using Effect Clock and injectable entropy.

**Example**

```ts
Effect.runSync(Effect.provide(createOperationIdEffect(0), OperationIdEntropyLive));
```

**Signature**

```ts
declare const createOperationIdEffect: (
  now: number | undefined,
) => Effect.Effect<OperationId, OperationIdFailure, OperationIdEntropy>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/operation-id.ts#L115)

### operationIdTimestamp

Extracts a UUIDv7 timestamp without validating the ID.

**Example**

```ts
operationIdTimestamp(id);
```

**Signature**

```ts
declare const operationIdTimestamp: (value: string) => number;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/operation-id.ts#L56)

### operationIdTimestampEffect

Extracts the first 48 timestamp bits without validating UUID syntax.

**Example**

```ts
Effect.runSync(operationIdTimestampEffect(id));
```

**Signature**

```ts
declare const operationIdTimestampEffect: (value: string) => Effect.Effect<number, never, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/operation-id.ts#L45)

### parseOperationId

Parses a UUIDv7 operation ID through the compatibility API.

**Throws**

OperationIdError for an invalid or expired ID.

**Example**

```ts
parseOperationId(id, { now: Date.now() });
```

**Signature**

```ts
declare const parseOperationId: (value: string, options?: ParseOperationIdOptions) => OperationId;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/operation-id.ts#L101)

### parseOperationIdEffect

Parses a UUIDv7 operation ID and enforces its receipt window.

**Example**

```ts
Effect.runSync(parseOperationIdEffect(id, { now: Date.now() }));
```

**Signature**

```ts
declare const parseOperationIdEffect: (
  value: string,
  options?: ParseOperationIdOptions | undefined,
) => Effect.Effect<OperationId, OperationIdFailure, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/operation-id.ts#L65)

## `operation-id.types.ts`

### OperationIdEntropyService (interface)

Injectable source of UUIDv7 random bytes.

**Example**

```ts
const source: OperationIdEntropyService = { bytes: () => Effect.succeed(new Uint8Array(16)) };
```

**Signature**

```ts
export interface OperationIdEntropyService {
  /** Produces sixteen independent bytes.
   * @returns An Effect of random bytes without a typed failure.
   * @example Effect.runSync(source.bytes());
   */
  readonly bytes: () => Effect.Effect<Uint8Array>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/operation-id.types.ts#L14)

### ParseOperationIdOptions (interface)

Optional receipt-window clock controls for ID parsing.

**Example**

```ts
const options: ParseOperationIdOptions = { now: Date.now(), receiptWindowMs: 60000 };
```

**Signature**

```ts
export interface ParseOperationIdOptions {
  readonly now?: number;
  readonly receiptWindowMs?: number;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/operation-id.types.ts#L6)

## `provider-dispatcher.ts`

### "./provider-dispatcher.types.js" (namespace export)

Re-exports all named exports from the "./provider-dispatcher.types.js" module.

**Signature**

```ts
export * from "./provider-dispatcher.types.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-dispatcher.ts#L13)

### RealtimeProviderSource (class)

Injectable profile-to-provider lookup.

**Example**

```ts
Effect.provide(triggerProviderEffect(options, request), providerSourceLayer(options));
```

**Signature**

```ts
declare class RealtimeProviderSource
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-dispatcher.ts#L18)

### createProviderRealtimeDispatcher

Creates a provider-backed realtime dispatcher.

**Throws**

An Effect runtime defect if construction cannot execute synchronously.

**Example**

```ts
const dispatcher = createProviderRealtimeDispatcher(options);
```

**Signature**

```ts
declare const createProviderRealtimeDispatcher: (
  options: ProviderRealtimeDispatcherOptions,
) => RealtimeDispatcher;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-dispatcher.ts#L195)

### createProviderRealtimeDispatcherEffect

Creates the compatibility dispatcher through the Effect path.

**Example**

```ts
Effect.runSync(createProviderRealtimeDispatcherEffect(options));
```

**Signature**

```ts
declare const createProviderRealtimeDispatcherEffect: (
  options: ProviderRealtimeDispatcherOptions,
) => Effect.Effect<RealtimeDispatcher, never, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-dispatcher.ts#L172)

### limitsForEffect

**Signature**

```ts
declare const limitsForEffect: (
  options: ProviderRealtimeDispatcherOptions,
) => Effect.Effect<RealtimeLimits, never, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-dispatcher.ts#L14)

### providerSourceLayer

Builds a provider resolver layer from authored dispatcher options.

**Example**

```ts
providerSourceLayer(options);
```

**Signature**

```ts
declare const providerSourceLayer: (
  options: ProviderRealtimeDispatcherOptions,
) => Layer.Layer<RealtimeProviderSource, never, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-dispatcher.ts#L27)

### readProviderPresenceEffect

Reads presence from a resolved provider.

**Example**

```ts
Effect.runPromise(
  Effect.provide(readProviderPresenceEffect(options, request), providerSourceLayer(options)),
);
```

**Signature**

```ts
declare const readProviderPresenceEffect: (
  options: ProviderRealtimeDispatcherOptions,
  request: { readonly channel: ChannelDescriptorData; readonly params: unknown },
) => Effect.Effect<PresenceSnapshot, RealtimeProviderError, RealtimeProviderSource>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-dispatcher.ts#L130)

### triggerProviderEffect

Sends a validated trigger to a resolved provider.

**Example**

```ts
Effect.runPromise(
  Effect.provide(triggerProviderEffect(options, request), providerSourceLayer(options)),
);
```

**Signature**

```ts
declare const triggerProviderEffect: (
  options: ProviderRealtimeDispatcherOptions,
  request: {
    readonly channel: ChannelDescriptorData;
    readonly params: unknown;
    readonly event: string;
    readonly payload: unknown;
    readonly options?: ChannelTriggerOptions;
  },
) => Effect.Effect<
  TriggerReceipt,
  RealtimeProviderError | OperationIdFailure,
  RealtimeProviderSource
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-dispatcher.ts#L66)

## `provider-dispatcher.types.ts`

### ProviderRealtimeDispatcherOptions (interface)

Configuration for a provider-backed generation dispatcher.

**Example**

```ts
const options: ProviderRealtimeDispatcherOptions = {
  applicationId: "app",
  environment: "dev",
  generationId: "g1",
  publicFingerprint: "p1",
  provider: async () => provider,
};
```

**Signature**

```ts
export interface ProviderRealtimeDispatcherOptions {
  readonly applicationId: string;
  readonly environment: string;
  readonly generationId: string;
  readonly publicFingerprint: string;
  /** Resolves a provider for one profile.
   * @param profile - Validated profile name.
   * @param signal - Optional cancellation signal for an in-flight lookup.
   * @returns A provider or lookup rejection.
   * @example await options.provider("default", controller.signal);
   */
  readonly provider: (
    profile: string,
    signal?: AbortSignal,
  ) => Promise<RealtimeProvider> | RealtimeProvider;
  readonly limits?: Partial<RealtimeLimits>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-dispatcher.types.ts#L8)

### RealtimeProviderSourceService (interface)

Injectable provider resolver used by Effect-native dispatcher operations.

**Example**

```ts
const source: RealtimeProviderSourceService = { resolve: () => Effect.succeed(provider) };
```

**Signature**

```ts
export interface RealtimeProviderSourceService {
  /** Resolves the provider configured for one profile.
   * @param profile - Validated profile name.
   * @returns An Effect of the provider or RealtimeProviderError.
   * @example Effect.runPromise(source.resolve("default"));
   */
  readonly resolve: (profile: string) => Effect.Effect<RealtimeProvider, RealtimeProviderError>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-dispatcher.types.ts#L29)

## `provider-encoding.ts`

### digestEffect

Hashes canonical JSON for partitions and idempotency.

**Example**

```ts
Effect.runSync(digestEffect({ id: "one" }));
```

**Signature**

```ts
declare const digestEffect: (value: unknown) => Effect.Effect<string, RealtimeProviderError, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-encoding.ts#L12)

### encodedBytesEffect

Measures an encoded event envelope.

**Example**

```ts
Effect.runSync(encodedBytesEffect({ event: "posted" }));
```

**Signature**

```ts
declare const encodedBytesEffect: (
  value: unknown,
) => Effect.Effect<number, RealtimeProviderError, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-encoding.ts#L26)

### providerScopeEffect

Computes the immutable portion of a provider scope.

**Example**

```ts
Effect.runSync(providerScopeEffect(options, "news", "default", {}));
```

**Signature**

```ts
declare const providerScopeEffect: (
  options: ProviderRealtimeDispatcherOptions,
  channelId: string,
  profile: string,
  params: unknown,
) => Effect.Effect<
  {
    applicationId: string;
    environment: string;
    channelId: string;
    partition: string;
    profile: string;
    policyEpoch: string;
    providerEpoch: string;
    identityScope: string;
    sessionEpoch: string;
  },
  RealtimeProviderError,
  never
>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-encoding.ts#L43)

## `provider-limits.ts`

### limitsForEffect

Computes effective provider limits in the Effect path.

**Example**

```ts
Effect.runSync(limitsForEffect(options));
```

**Signature**

```ts
declare const limitsForEffect: (
  options: ProviderRealtimeDispatcherOptions,
) => Effect.Effect<RealtimeLimits, never, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider-limits.ts#L11)

## `provider.ts`

### "./provider.types.js" (namespace export)

Re-exports all named exports from the "./provider.types.js" module.

**Signature**

```ts
export * from "./provider.types.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.ts#L1)

## `provider.types.ts`

### AcquirePresenceLease (type alias)

Initial lease request.

**Example**

```ts
const request: AcquirePresenceLease = lease;
```

**Signature**

```ts
type AcquirePresenceLease = PresenceLeaseRequest;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L102)

### AppendChannelEvent (interface)

Validated event append request including idempotency and retention settings.

**Example**

```ts
const append: AppendChannelEvent = {
  ...scope,
  event: "posted",
  payload: "hi",
  encodedBytes: 42,
  occurredAt: new Date().toISOString(),
  limits,
};
```

**Signature**

```ts
export interface AppendChannelEvent extends RealtimeScope {
  readonly operationId?: OperationId;
  readonly semanticDigest?: string;
  readonly event: string;
  readonly payload: unknown;
  readonly encodedBytes: number;
  readonly occurredAt: string;
  readonly receiptExpiresAt?: string;
  readonly retentionMs?: number;
  readonly maxEvents?: number;
  readonly limits: RealtimeLimits;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L24)

### AppendReceiptLookup (type alias)

Provider receipt lookup result.

**Example**

```ts
const result: AppendReceiptLookup = await provider.lookupAppendReceipt(lookup);
```

**Signature**

```ts
type AppendReceiptLookup = ReceiptLookup<TriggerReceipt>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L50)

### ChannelEventPage (interface)

Ordered provider replay page and its next checkpoint.

**Example**

```ts
const page: ChannelEventPage = await provider.readAfter(read);
```

**Signature**

```ts
export interface ChannelEventPage {
  readonly events: readonly ChannelEventRecord[];
  readonly checkpoint: ChannelCheckpoint;
  readonly hasMore: boolean;
  readonly gap?: "expired" | "foreign" | "future" | "policy" | "session" | "provider-reset";
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L64)

### LookupAppendReceipt (interface)

Provider lookup for an existing idempotent append receipt.

**Example**

```ts
const lookup: LookupAppendReceipt = {
  ...scope,
  operationId: id,
  semanticDigest: digest,
  receiptWindowMs: 60000,
  now: new Date().toISOString(),
};
```

**Signature**

```ts
export interface LookupAppendReceipt extends RealtimeScope {
  readonly operationId: OperationId;
  readonly semanticDigest: string;
  readonly receiptWindowMs: number;
  readonly now: string;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L40)

### PresenceLeaseRequest (interface)

Presence lease mutation request; providers own lease persistence.

**Example**

```ts
const lease: PresenceLeaseRequest = {
  ...scope,
  leaseId: "l1",
  connectionId: "c1",
  expiresAt: new Date().toISOString(),
  maxMembers: 10,
  maxConnections: 10,
};
```

**Signature**

```ts
export interface PresenceLeaseRequest extends RealtimeScope {
  readonly leaseId: string;
  readonly connectionId: string;
  readonly opaqueMemberId?: string;
  readonly memberInfo?: unknown;
  readonly expiresAt: string;
  readonly maxMembers: number;
  readonly maxConnections: number;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L83)

### ReadChannelEvents (interface)

Bounded replay page request.

**Example**

```ts
const read: ReadChannelEvents = { ...scope, limit: 10, maxEncodedBytes: 4096 };
```

**Signature**

```ts
export interface ReadChannelEvents extends RealtimeScope {
  readonly after?: ChannelCheckpoint;
  readonly limit: number;
  readonly maxEncodedBytes: number;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L55)

### ReadPresenceRequest (type alias)

Presence read with a bounded member count.

**Example**

```ts
const read: ReadPresenceRequest = { ...scope, maxMembers: 10 };
```

**Signature**

```ts
type ReadPresenceRequest = RealtimeScope & {
  readonly maxMembers: number;
};
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L96)

### RealtimeLimits (interface)

Provider-enforced bounds for event, connection, partition, and presence storage.

**Example**

```ts
const limits: RealtimeLimits = {
  maxEventBytes: 1024,
  maxRetainedBytes: 4096,
  maxPartitions: 10,
  maxConnections: 10,
  maxPresenceMembers: 10,
};
```

**Signature**

```ts
export interface RealtimeLimits {
  readonly maxEventBytes: number;
  readonly maxRetainedBytes: number;
  readonly maxPartitions: number;
  readonly maxConnections: number;
  readonly maxPresenceMembers: number;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L13)

### RealtimeProvider (interface)

Backend contract for ordered events, idempotency, and presence.
The caller owns aborting waitAfter; provider implementations own their internal resources.

**Example**

```ts
const epoch = await provider.getEpoch();
```

**Signature**

```ts
export interface RealtimeProvider {
  readonly capabilities: {
    readonly replay: "memory" | "retained";
    readonly presenceScope: "process" | "shared";
    readonly durability: "volatile" | "filesystem" | "redis-configured";
  };
  /** Reads the provider generation epoch.
   * @param signal - Optional cancellation signal for in-flight work.
   * @returns The epoch or a provider rejection.
   * @example await provider.getEpoch();
   */
  getEpoch(signal?: AbortSignal): Promise<string>;
  /** Appends a validated event.
   * @param request - Event and scope metadata.
   * @param signal - Optional cancellation signal; an implementation may already have committed an append when aborted.
   * @returns A receipt or a provider rejection.
   * @example await provider.append(append);
   */
  append(request: AppendChannelEvent, signal?: AbortSignal): Promise<TriggerReceipt>;
  /** Looks up an idempotent append receipt.
   * @param request - Receipt lookup key and time window.
   * @returns Existing receipt state or a provider rejection.
   * @example await provider.lookupAppendReceipt(lookup);
   */
  lookupAppendReceipt(request: LookupAppendReceipt): Promise<AppendReceiptLookup>;
  /** Reads an ordered, bounded event page.
   * @param request - Replay cursor and limits.
   * @returns A page or a provider rejection.
   * @example await provider.readAfter(read);
   */
  readAfter(request: ReadChannelEvents): Promise<ChannelEventPage>;
  /** Waits for events until a deadline or caller abort.
   * @param request - Cursor, deadline, and caller-owned abort signal.
   * @returns Completion or a provider rejection.
   * @example await provider.waitAfter(wait);
   */
  waitAfter(request: WaitForChannelEvents): Promise<void>;
  /** Reads current presence.
   * @param request - Scope and member limit.
   * @param signal - Optional cancellation signal for in-flight work.
   * @returns Presence snapshot or a provider rejection.
   * @example await provider.readPresence(read);
   */
  readPresence(request: ReadPresenceRequest, signal?: AbortSignal): Promise<PresenceSnapshot>;
  /** Acquires a presence lease.
   * @param request - Lease identity, expiry, and limits.
   * @returns Updated presence or a provider rejection.
   * @example await provider.acquirePresence(lease);
   */
  acquirePresence(request: AcquirePresenceLease): Promise<PresenceSnapshot>;
  /** Renews a presence lease.
   * @param request - Existing lease and next expiry.
   * @returns Updated presence or a provider rejection.
   * @example await provider.renewPresence(lease);
   */
  renewPresence(request: RenewPresenceLease): Promise<PresenceSnapshot>;
  /** Releases a presence lease.
   * @param request - Existing lease without expiry.
   * @returns Updated presence or a provider rejection.
   * @example await provider.releasePresence(release);
   */
  releasePresence(request: ReleasePresenceLease): Promise<PresenceSnapshot>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L116)

### ReleasePresenceLease (type alias)

Lease release request without an expiry.

**Example**

```ts
const request: ReleasePresenceLease = {
  ...scope,
  leaseId: "l1",
  connectionId: "c1",
  maxMembers: 10,
  maxConnections: 10,
};
```

**Signature**

```ts
type ReleasePresenceLease = Omit<PresenceLeaseRequest, "expiresAt">;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L110)

### RenewPresenceLease (type alias)

Existing lease renewal request.

**Example**

```ts
const request: RenewPresenceLease = lease;
```

**Signature**

```ts
type RenewPresenceLease = PresenceLeaseRequest;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L106)

### WaitForChannelEvents (interface)

Abortable long-poll request owned by its caller.

**Example**

```ts
const wait: WaitForChannelEvents = {
  ...scope,
  after: checkpoint,
  deadlineMs: Date.now() + 1000,
  signal: controller.signal,
};
```

**Signature**

```ts
export interface WaitForChannelEvents extends RealtimeScope {
  readonly after: ChannelCheckpoint;
  readonly deadlineMs: number;
  readonly signal: AbortSignal;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/provider.types.ts#L74)

## `realtime-errors.ts`

### ChannelValidationError (class)

Invalid authored channel data or an invalid channel operation.

**Example**

```ts
new ChannelValidationError({ operation: "channel.define", reason: "Missing events" });
```

**Signature**

```ts
declare class ChannelValidationError
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/realtime-errors.ts#L5)

### OperationIdFailure (class)

An operation ID is malformed or outside its receipt window.

**Example**

```ts
new OperationIdFailure({ code: "OPERATION_ID_INVALID", reason: "Invalid ID" });
```

**Signature**

```ts
declare class OperationIdFailure
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/realtime-errors.ts#L33)

### RealtimeActionError (class)

An action thrown while entering a dispatcher scope.

**Example**

```ts
new RealtimeActionError({ operation: "dispatch.runWith", cause: new Error("failed") });
```

**Signature**

```ts
declare class RealtimeActionError
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/realtime-errors.ts#L19)

### RealtimeDispatcherError (class)

A realtime dispatcher was required but none was bound.

**Example**

```ts
new RealtimeDispatcherError({
  operation: "dispatch.current",
  reason: "No realtime dispatcher is active.",
});
```

**Signature**

```ts
declare class RealtimeDispatcherError
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/realtime-errors.ts#L12)

### RealtimeProviderError (class)

A provider operation failed at the external adapter boundary.

**Example**

```ts
new RealtimeProviderError({ operation: "provider.trigger", cause: new Error("offline") });
```

**Signature**

```ts
declare class RealtimeProviderError
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/realtime-errors.ts#L26)

## `realtime-observability.ts`

### RealtimeTelemetry (class)

Injectable realtime telemetry boundary.

**Example**

```ts
Effect.provide(Effect.succeed(1), RealtimeTelemetryLive);
```

**Signature**

```ts
declare class RealtimeTelemetry
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/realtime-observability.ts#L9)

### RealtimeTelemetryLive

Live span and metric observer for realtime operations.

**Example**

```ts
Effect.provide(Effect.succeed(1), RealtimeTelemetryLive);
```

**Signature**

```ts
declare const RealtimeTelemetryLive: Layer.Layer<RealtimeTelemetry, never, never>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/realtime-observability.ts#L16)

### observeRealtime

Observes a realtime operation using the supplied test service or live metrics.

**Example**

```ts
observeRealtime("channel.define", Effect.succeed(undefined));
```

**Signature**

```ts
declare const observeRealtime: <A, E, R>(
  operation: RealtimeOperation,
  effect: Effect.Effect<A, E, R>,
) => Effect.Effect<A, E, R>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/realtime-observability.ts#L28)

## `realtime-observability.types.ts`

### RealtimeOperation (type alias)

Bounded names used for realtime spans and metrics.

**Example**

```ts
const operation: RealtimeOperation = "channel.define";
```

**Signature**

```ts
type RealtimeOperation =
  | "channel.define"
  | "channel.isDescriptor"
  | "channel.trigger"
  | "channel.getPresence"
  | "channel.copyClient"
  | "channel.copyPresence"
  | "channel.copyEvents"
  | "channel.copyReplay"
  | "channel.assertSchema"
  | "channel.isSchema"
  | "channel.validateValue"
  | "channel.isRecord"
  | "dispatch.setActive"
  | "dispatch.runWith"
  | "dispatch.current"
  | "operationId.parse"
  | "operationId.timestamp"
  | "operationId.create"
  | "provider.createDispatcher"
  | "provider.resolve"
  | "provider.trigger"
  | "provider.getPresence"
  | "provider.scope"
  | "provider.digest"
  | "provider.bytes"
  | "provider.limits";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/realtime-observability.types.ts#L5)

### RealtimeTelemetryService (interface)

Substitutable observer for realtime operation tests and application telemetry.

**Example**

```ts
const observer: RealtimeTelemetryService = { observe: (_name, effect) => effect };
```

**Signature**

```ts
export interface RealtimeTelemetryService {
  /** Surrounds an operation without changing its result.
   * @param operation - A stable, bounded operation name.
   * @param effect - The operation to observe.
   * @returns The same success and error channels with telemetry attached.
   * @example observer.observe("channel.define", Effect.succeed(undefined));
   */
  readonly observe: <A, E, R>(
    operation: RealtimeOperation,
    effect: Effect.Effect<A, E, R>,
  ) => Effect.Effect<A, E, R>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/realtime-observability.types.ts#L35)

## `types.ts`

### ChannelCheckpoint (interface)

Replay cursor bound to the provider, policy, and session epochs.

**Example**

```ts
const checkpoint: ChannelCheckpoint = {
  ...scope,
  sequence: "1",
  historyStart: "1",
  expiresAt: new Date().toISOString(),
};
```

**Signature**

```ts
export interface ChannelCheckpoint extends RealtimeScope {
  readonly sequence: string;
  readonly historyStart: string;
  readonly expiresAt: string;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/types.ts#L20)

### ChannelEventRecord (interface)

Stored channel event and checkpoint returned by replay.

**Example**

```ts
const record: ChannelEventRecord = {
  eventId: "e1",
  event: "posted",
  payload: "hi",
  checkpoint,
  encodedBytes: 20,
  createdAt: new Date().toISOString(),
};
```

**Signature**

```ts
export interface ChannelEventRecord {
  readonly eventId: string;
  readonly event: string;
  readonly payload: unknown;
  readonly checkpoint: ChannelCheckpoint;
  readonly encodedBytes: number;
  readonly createdAt: string;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/types.ts#L39)

### ChannelGrant (interface)

Authorized channel grant with a bounded replay window.

**Example**

```ts
const grant: ChannelGrant = {
  ...scope,
  grantId: "g",
  principalScope: "user",
  historyStart: "1",
  expiresAt: new Date().toISOString(),
};
```

**Signature**

```ts
export interface ChannelGrant extends RealtimeScope {
  readonly grantId: string;
  readonly principalScope: string;
  readonly historyStart: string;
  readonly expiresAt: string;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/types.ts#L29)

### CountPresence (interface)

Count-only presence snapshot and freshness state.

**Example**

```ts
const count: CountPresence = { connections: 1, status: "fresh", revision: "1", scope: "shared" };
```

**Signature**

```ts
export interface CountPresence {
  readonly connections: number | undefined;
  readonly status: "loading" | "fresh" | "stale" | "error";
  readonly revision: string | undefined;
  readonly scope: "process" | "shared";
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/types.ts#L64)

### MemberPresence (interface)

Presence snapshot with a bounded member list.

**Example**

```ts
const members: MemberPresence<string> = {
  connections: 1,
  status: "fresh",
  revision: "1",
  scope: "shared",
  memberCount: 1,
  members: [{ id: "opaque", info: "Ada" }],
  membersTruncated: false,
};
```

**Signature**

```ts
export interface MemberPresence<Member = unknown> extends CountPresence {
  readonly memberCount: number | undefined;
  readonly members: readonly PresenceMember<Member>[];
  readonly membersTruncated: boolean;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/types.ts#L82)

### PresenceMember (interface)

Member identity and validated application-visible information.

**Example**

```ts
const member: PresenceMember<string> = { id: "opaque", info: "Ada" };
```

**Signature**

```ts
export interface PresenceMember<Member = unknown> {
  readonly id: string;
  readonly info: Member;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/types.ts#L74)

### PresenceSnapshot (type alias)

Count-only or member presence returned by a provider.

**Example**

```ts
const snapshot: PresenceSnapshot = await provider.readPresence(read);
```

**Signature**

```ts
type PresenceSnapshot<Member = unknown> = CountPresence | MemberPresence<Member>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/types.ts#L91)

### RealtimeScope (interface)

Identity and partition coordinates shared by all realtime provider requests.

**Example**

```ts
const scope: RealtimeScope = {
  applicationId: "app",
  environment: "dev",
  channelId: "news",
  partition: "p",
  profile: "default",
  policyEpoch: "v1",
  providerEpoch: "e1",
  identityScope: "public",
  sessionEpoch: "s1",
};
```

**Signature**

```ts
export interface RealtimeScope extends ExpectedClientIdentity {
  readonly applicationId: string;
  readonly environment: string;
  readonly tenantScope?: string;
  readonly channelId: string;
  readonly partition: string;
  readonly profile: string;
  readonly policyEpoch: string;
  readonly providerEpoch: string;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/types.ts#L6)

### TriggerReceipt (interface)

Provider acknowledgement for an accepted channel event.

**Example**

```ts
const receipt: TriggerReceipt = await channel.trigger({}, "posted", "hi");
```

**Signature**

```ts
export interface TriggerReceipt {
  readonly accepted: true;
  readonly operationId?: OperationId;
  readonly eventId: string;
  readonly checkpoint: ChannelCheckpoint;
  readonly profile: string;
  readonly providerEpoch: string;
  readonly duplicate: boolean;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/realtime/src/types.ts#L51)
