Fix critical publish() bug, address review findings
CRITICAL: createPubSub.publish() was dispatching CustomEvent with
just the event type (e.g. 'call.responded') instead of the composite
topic string ('call.responded:uuid-123'). This broke all adapters
that rely on topic-scoped dispatch — Redis subscribe/publish
channels didn't match, and WS server fan-out routing would fail.
Fixed to dispatch with the full type:id composite.
Other fixes:
- Add __ prefix runtime guard in publish() (reserved for control)
- Add Redis barrel re-export to src/index.ts (ADR-002 compliance)
- Clarify WS server: adapter's onclose calls removeConnection
internally; user doesn't need to
- WS client: document null callback no-op, removeEventListener
edge cases (unregistered callback, null callback)
- WS server: document dispatchEvent always returns true
- Redis spec: document in-flight message edge case after unsubscribe
- Worker adapter: rename createMainThreadEventTarget to
createWorkerThreadEventTarget, createWorkerEventTarget to
createWorkerHostEventTarget (fix inverted naming)
- api-surface.md: add PubSub.publish() section documenting the
type:id composite and __ guard
This commit is contained in:
@@ -69,8 +69,14 @@ export function createPubSub<TEventMap extends PubSubEventMap>(
|
||||
id: string,
|
||||
payload: TEventMap[TType],
|
||||
) {
|
||||
if (type.startsWith("__")) {
|
||||
throw new Error(
|
||||
`Event types starting with "__" are reserved for adapter control messages. Received: "${type}"`,
|
||||
);
|
||||
}
|
||||
const envelope: EventEnvelope<TType, TEventMap[TType]> = { type, id, payload };
|
||||
const event = new CustomEvent(type, { detail: envelope }) as PubSubEvent<
|
||||
const topic = `${type}:${id}`;
|
||||
const event = new CustomEvent(topic, { detail: envelope }) as PubSubEvent<
|
||||
TEventMap,
|
||||
TType
|
||||
>;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export { createPubSub, type PubSub, type PubSubConfig, type PubSubEvent, type PubSubEventTarget, type PubSubEventMap } from "./create_pubsub.js";
|
||||
export { type EventEnvelope, type TypedEvent, type TypedEventTarget, type TypedEventListener, type TypedEventListenerObject, type TypedEventListenerOrEventListenerObject } from "./types.js";
|
||||
export { filter, map, pipe, take, reduce, toArray, batch, dedupe, window, flat, groupBy, chain, join } from "./operators.js";
|
||||
export { Repeater, RepeaterOverflowError, type Push, type Stop, type RepeaterExecutor, type RepeaterBuffer } from "./repeater.js";
|
||||
export { Repeater, RepeaterOverflowError, type Push, type Stop, type RepeaterExecutor, type RepeaterBuffer } from "./repeater.js";
|
||||
export { createRedisEventTarget, type CreateRedisEventTargetArgs } from "./event-target-redis.js";
|
||||
Reference in New Issue
Block a user