@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 +2 -2
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.js +0 -1
- package/dist/websocket-manager.js +19 -9
- package/package.json +1 -1
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,
|
|
5
|
-
export { wsIdentifiedPayloadSchema, campaignSavingPayloadSchema,
|
|
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,
|
|
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';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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';
|
package/dist/types/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
85
|
-
if (!
|
|
84
|
+
const result = serverMessageSchema.safeParse(parsedJson);
|
|
85
|
+
if (!result.success) {
|
|
86
86
|
this.bus.emit('ws:unparseable', raw);
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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) {
|