Skip to content

API reference / @chanx-js/server / core / TopicOptions

Interface: TopicOptions<Pattern, User, State> ​

Defined in: packages/server/src/topic.ts:62

Options for topic().

Extends ​

Type Parameters ​

Type ParameterDefault type
Pattern extends string-
User-
StateRecord<never, never>

Properties ​

authorize? ​

ts
optional authorize?: (subscription) => boolean | Promise<boolean>;

Defined in: packages/server/src/topic.ts:79

Decide whether this connection may subscribe.

Parameters ​

ParameterType
subscription{ conn: Connection<string, User>; params: PathParams<Pattern>; state: State; topic: string; }
subscription.connConnection<string, User>
subscription.paramsPathParams<Pattern>
subscription.stateState
subscription.topicstring

Returns ​

boolean | Promise<boolean>


description? ​

ts
optional description?: string;

Defined in: packages/server/src/topic.ts:73

The AsyncAPI channel's description.


layer? ​

ts
optional layer?: string;

Defined in: packages/server/src/topic.ts:75

The channel layer to publish on. Defaults to default.


name? ​

ts
optional name?: string;

Defined in: packages/server/src/topic.ts:71

Name of the topic's channel layer group namespace: two servers sharing a layer must agree on it. Defaults to RoomTopic for room:{...}.


onEventError? ​

ts
optional onEventError?: (error, event, ctx) => void | Promise<void>;

Defined in: packages/server/src/consumer.ts:172

An event handler threw. Default: log it; the client is told nothing.

Parameters ​

ParameterType
errorunknown
eventMessage
ctxTopicContext

Returns ​

void | Promise<void>

Inherited from ​

ErrorHooks.onEventError


onHandlerError? ​

ts
optional onHandlerError?: (error, message, ctx) => void | Promise<void>;

Defined in: packages/server/src/consumer.ts:170

A message handler threw. Default: log it, and an error frame naming the action.

Parameters ​

ParameterType
errorunknown
messageMessage
ctxTopicContext

Returns ​

void | Promise<void>

Inherited from ​

ErrorHooks.onHandlerError


onSubscribe? ​

ts
optional onSubscribe?: (ctx) => void | Promise<void>;

Defined in: packages/server/src/topic.ts:86

Once subscribed; what it sends is state, not a reply, so it carries no ref.

Parameters ​

ParameterType
ctxTopicContext<Pattern, User, Message<string, unknown>, State>

Returns ​

void | Promise<void>


onUnsubscribe? ​

ts
optional onUnsubscribe?: (ctx) => void | Promise<void>;

Defined in: packages/server/src/topic.ts:90

Before leaving, on unsubscribe and on disconnect.

Parameters ​

ParameterType
ctxTopicContext<Pattern, User, Message<string, unknown>, State>

Returns ​

void | Promise<void>


onValidationError? ​

ts
optional onValidationError?: (issues, ctx) => void | Promise<void>;

Defined in: packages/server/src/consumer.ts:168

A frame failed validation. Default: an error frame listing the issues.

Parameters ​

ParameterType
issuesValidationIssue[]
ctxTopicContext

Returns ​

void | Promise<void>

Inherited from ​

ErrorHooks.onValidationError


state? ​

ts
optional state?: (subscription) => State;

Defined in: packages/server/src/topic.ts:77

Per-subscription state, available as ctx.state; built before authorize.

Parameters ​

ParameterType
subscriptionSubscription<User>

Returns ​

State

MIT licensed