@studyportals/ws-client 0.1.1-beta.1 → 0.1.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { eventBus } from './event-bus';
2
2
  export type { EventBus } from './event-bus';
3
3
  export { WebSocketManager } from './websocket-manager';
4
- export type { WsEventMap, WsIdentifiedPayload, CampaignSavingPayload, WebSocketManagerConfig, IncomingMessage, ServerEventKey, ServerMessage, ServerMessageParsed, } from './types';
5
- export { wsIdentifiedPayloadSchema, campaignSavingPayloadSchema, incomingMessageSchema, serverMessageSchema, } from './types';
4
+ export type { WsEventMap, WsIdentifiedPayload, CampaignSavingPayload, WebSocketManagerConfig, ServerEventKey, ServerMessage, ServerMessageParsed, } from './types';
5
+ export { wsIdentifiedPayloadSchema, campaignSavingPayloadSchema, serverMessageSchema, } from './types';
6
6
  export type { IWebSocketTransport } from './transport.interface';
7
7
  export { RealWebSocketTransport } from './transports/real.transport';
8
8
  export { MockWebSocketTransport } from './transports/mock.transport';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export { eventBus } from './event-bus';
3
3
  // Manager
4
4
  export { WebSocketManager } from './websocket-manager';
5
5
  // Zod validators (useful for consumers and tests)
6
- export { wsIdentifiedPayloadSchema, campaignSavingPayloadSchema, incomingMessageSchema, serverMessageSchema, } from './types';
6
+ export { wsIdentifiedPayloadSchema, campaignSavingPayloadSchema, serverMessageSchema, } from './types';
7
7
  // Transport implementations
8
8
  export { RealWebSocketTransport } from './transports/real.transport';
9
9
  export { MockWebSocketTransport } from './transports/mock.transport';
@@ -4,7 +4,5 @@ export { wsIdentifiedPayloadSchema } from './ws-identified';
4
4
  export type { CampaignSavingPayload } from './campaign-saving';
5
5
  export { campaignSavingPayloadSchema } from './campaign-saving';
6
6
  export type { WebSocketManagerConfig } from './ws-manager-config';
7
- export type { IncomingMessage } from './ws-message';
8
- export { incomingMessageSchema } from './ws-message';
9
7
  export type { ServerEventKey, ServerMessage, ServerMessageParsed } from './server-message';
10
8
  export { serverMessageSchema } from './server-message';
@@ -1,4 +1,3 @@
1
1
  export { wsIdentifiedPayloadSchema } from './ws-identified';
2
2
  export { campaignSavingPayloadSchema } from './campaign-saving';
3
- export { incomingMessageSchema } from './ws-message';
4
3
  export { serverMessageSchema } from './server-message';
@@ -1,4 +1,4 @@
1
- import { incomingMessageSchema, wsIdentifiedPayloadSchema } from './types';
1
+ import { serverMessageSchema } from './types';
2
2
  const DEFAULT_MAX_RECONNECT_ATTEMPTS = 10;
3
3
  const DEFAULT_BASE_RECONNECT_DELAY_MS = 500;
4
4
  const DEFAULT_MAX_RECONNECT_DELAY_MS = 30000;
@@ -81,19 +81,29 @@ export class WebSocketManager {
81
81
  this.bus.emit('ws:unparseable', raw);
82
82
  return;
83
83
  }
84
- const msgResult = incomingMessageSchema.safeParse(parsedJson);
85
- if (!msgResult.success) {
84
+ const result = serverMessageSchema.safeParse(parsedJson);
85
+ if (!result.success) {
86
86
  this.bus.emit('ws:unparseable', raw);
87
87
  return;
88
88
  }
89
- const msg = msgResult.data;
90
- if (msg.type === 'ws:identified') {
91
- const idResult = wsIdentifiedPayloadSchema.safeParse(msg.payload);
92
- if (idResult.success) {
93
- this.connectionId = idResult.data.connectionId;
89
+ // result.data is ServerMessageParsed — a strict discriminated union.
90
+ // The switch is exhaustive: adding a new event to serverMessageSchema
91
+ // without handling it here is a compile error.
92
+ const msg = result.data;
93
+ switch (msg.type) {
94
+ case 'ws:identified':
95
+ this.connectionId = msg.payload.connectionId;
96
+ this.bus.emit('ws:identified', msg.payload);
97
+ break;
98
+ case 'campaign:saving':
99
+ this.bus.emit('campaign:saving', msg.payload);
100
+ break;
101
+ default: {
102
+ // Exhaustive guard — msg is `never` if all cases are handled.
103
+ // If this line errors, a new ServerMessage member needs a case above.
104
+ const _exhaustive = msg;
94
105
  }
95
106
  }
96
- this.bus.emit(msg.type, msg.payload);
97
107
  }
98
108
  scheduleReconnect() {
99
109
  if (this.reconnectAttempts >= this.config.maxReconnectAttempts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studyportals/ws-client",
3
- "version": "0.1.1-beta.1",
3
+ "version": "0.1.1-beta.2",
4
4
  "description": "WebSocket client with reconnect, heartbeat, and typed event bus",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",