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:
@@ -61,7 +61,8 @@ This is how the server adapter knows which events to forward to this spoke. With
|
||||
When `addEventListener(type, callback)` is called:
|
||||
|
||||
1. Register the local listener (standard `EventTarget` behavior)
|
||||
2. If this is the first listener for this topic (no previous listeners registered), send a `__subscribe` control event to the server:
|
||||
2. If `callback` is `null`, this is a no-op — no listener is registered and no `__subscribe` is sent
|
||||
3. If this is the first listener for this topic (no previous listeners registered), send a `__subscribe` control event to the server:
|
||||
|
||||
```json
|
||||
{ "type": "__subscribe", "id": "", "payload": { "topic": "call.responded:uuid-123" } }
|
||||
@@ -74,7 +75,9 @@ The `id` field is the empty string (`""`) for control events by convention. The
|
||||
When `removeEventListener(type, callback)` is called:
|
||||
|
||||
1. Remove the local listener (standard `EventTarget` behavior)
|
||||
2. If no listeners remain for this topic, send an `__unsubscribe` control event:
|
||||
2. If `callback` was never registered for this type, this is a no-op — no `__unsubscribe` is sent (the reference count wasn't incremented, so it shouldn't be decremented)
|
||||
3. If `callback` is `null`, remove all listeners for this type. If no listeners remain after removal, send `__unsubscribe`
|
||||
4. If this was the last registered listener for this topic, send an `__unsubscribe` control event:
|
||||
|
||||
```json
|
||||
{ "type": "__unsubscribe", "id": "", "payload": { "topic": "call.responded:uuid-123" } }
|
||||
|
||||
Reference in New Issue
Block a user