Repository: discordjs/discord.js
File: packages/brokers/src/brokers/Broker.ts (TypeScript)

Code before:
export const DefaultBrokerOptions = {
	encode: (data): Buffer => {
		const encoded = encode(data);
		return Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength);
	},
	decode: (data): unknown => decode(data),
} as const satisfies Required<BaseBrokerOptions>;

export type ToEventMap<
	TRecord extends Record<string, any>,
	TResponses extends Record<keyof TRecord, any> | undefined = undefined,
> = {
	[TKey in keyof TRecord]: [
		event: TResponses extends Record<keyof TRecord, any>
			? { ack(): Promise<void>; reply(data: TResponses[TKey]): Promise<void> }
			: { ack(): Promise<void> } & { data: TRecord[TKey] },
	];
} & { [K: string]: any };

export interface IBaseBroker<TEvents extends Record<string, any>> {
	/**
	 * Subscribes to the given events, grouping them by the given group name
	 */
	subscribe(events: (keyof TEvents)[]): Promise<void>;
	/**
	 * Unsubscribes from the given events - it's required to pass the same group name as when subscribing for proper cleanup
	 */
	unsubscribe(events: (keyof TEvents)[]): Promise<void>;
}

export interface IPubSubBroker<TEvents extends Record<string, any>>
	extends IBaseBroker<TEvents>,
		AsyncEventEmitter<ToEventMap<TEvents>> {
	/**
	 * Publishes an event
	 */
	publish<Event extends keyof TEvents>(event: Event, data: TEvents[Event]): Promise<void>;
}

export interface IRPCBroker<TEvents extends Record<string, any>, TResponses extends Record<keyof TEvents, any>>
	extends IBaseBroker<TEvents>,
		AsyncEventEmitter<ToEventMap<TEvents, TResponses>> {
	/**
	 * Makes an RPC call
	 */
	call<Event extends keyof TEvents>(
		event: Event,
		data: TEvents[Event],
		timeoutDuration?: number,
	): Promise<TResponses[Event]>;
}

Review comment (suggestion):
```suggestion
	 * Unsubscribes from the given events
```

Code after:
export const DefaultBrokerOptions = {
	encode: (data): Buffer => {
		const encoded = encode(data);
		return Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength);
	},
	decode: (data): unknown => decode(data),
} as const satisfies Required<BaseBrokerOptions>;

export type ToEventMap<
	TRecord extends Record<string, any>,
	TResponses extends Record<keyof TRecord, any> | undefined = undefined,
> = {
	[TKey in keyof TRecord]: [
		event: TResponses extends Record<keyof TRecord, any>
			? { ack(): Promise<void>; reply(data: TResponses[TKey]): Promise<void> }
			: { ack(): Promise<void> } & { data: TRecord[TKey] },
	];
} & { [K: string]: any };

export interface IBaseBroker<TEvents extends Record<string, any>> {
	/**
	 * Subscribes to the given events
	 */
	subscribe(events: (keyof TEvents)[]): Promise<void>;
	/**
	 * Unsubscribes from the given events
	 */
	unsubscribe(events: (keyof TEvents)[]): Promise<void>;
}

export interface IPubSubBroker<TEvents extends Record<string, any>>
	extends IBaseBroker<TEvents>,
		AsyncEventEmitter<ToEventMap<TEvents>> {
	/**
	 * Publishes an event
	 */
	publish<Event extends keyof TEvents>(event: Event, data: TEvents[Event]): Promise<void>;
}

export interface IRPCBroker<TEvents extends Record<string, any>, TResponses extends Record<keyof TEvents, any>>
	extends IBaseBroker<TEvents>,
		AsyncEventEmitter<ToEventMap<TEvents, TResponses>> {
	/**
	 * Makes an RPC call
	 */
	call<Event extends keyof TEvents>(
		event: Event,
		data: TEvents[Event],
		timeoutDuration?: number,
	): Promise<TResponses[Event]>;
}