@hyper-fetch/orpc 9.9.0 → 10.1.0

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.
Files changed (74) hide show
  1. package/README.md +117 -31
  2. package/__tests__/e2e/e2e.orpc-realtime-server.ts +181 -0
  3. package/__tests__/e2e/e2e.react-realtime.spec.tsx +181 -0
  4. package/__tests__/e2e/e2e.realtime.spec.ts +310 -0
  5. package/__tests__/features/adapter/adapter.lifecycle.spec.ts +23 -0
  6. package/__tests__/features/adapter/adapter.schema.spec.ts +19 -0
  7. package/__tests__/features/socket/socket.schema.spec.ts +179 -0
  8. package/__tests__/features/stream-adapter/stream-adapter.environment.spec.ts +163 -0
  9. package/__tests__/features/stream-adapter/stream-adapter.lifecycle.spec.ts +558 -0
  10. package/__tests__/features/stream-adapter/stream-adapter.listener-lifecycle.spec.ts +291 -0
  11. package/__tests__/features/stream-adapter/stream-adapter.protocol.spec.ts +609 -0
  12. package/__tests__/features/stream-adapter/stream-adapter.subscriptions.spec.ts +270 -0
  13. package/__tests__/features/websocket-adapter/websocket-adapter.environment.spec.ts +153 -0
  14. package/__tests__/features/websocket-adapter/websocket-adapter.handshake-error.spec.ts +80 -0
  15. package/__tests__/features/websocket-adapter/websocket-adapter.lifecycle.spec.ts +448 -0
  16. package/__tests__/features/websocket-adapter/websocket-adapter.listener-lifecycle.spec.ts +222 -0
  17. package/__tests__/features/websocket-adapter/websocket-adapter.protocol.spec.ts +415 -0
  18. package/__tests__/features/websocket-adapter/websocket-adapter.subscriptions.spec.ts +172 -0
  19. package/__tests__/utils/controlled-fetch.ts +160 -0
  20. package/__tests__/utils/controlled-websocket.ts +140 -0
  21. package/__tests__/utils/socket-error.ts +7 -0
  22. package/__tests__/utils/stream-socket.ts +54 -0
  23. package/__tests__/utils/websocket-socket.ts +45 -0
  24. package/__tests__/vitest.setup.ts +20 -0
  25. package/dist/adapter/adapter.fetch.d.ts.map +1 -1
  26. package/dist/adapter/adapter.schema.d.ts +32 -0
  27. package/dist/adapter/adapter.schema.d.ts.map +1 -1
  28. package/dist/adapter/adapter.utils.d.ts +22 -4
  29. package/dist/adapter/adapter.utils.d.ts.map +1 -1
  30. package/dist/index.d.ts +3 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.mjs +843 -13
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/socket/index.d.ts +3 -0
  35. package/dist/socket/index.d.ts.map +1 -0
  36. package/dist/socket/socket.subscriptions.d.ts +31 -0
  37. package/dist/socket/socket.subscriptions.d.ts.map +1 -0
  38. package/dist/socket/socket.types.d.ts +62 -0
  39. package/dist/socket/socket.types.d.ts.map +1 -0
  40. package/dist/socket/socket.utils.d.ts +56 -0
  41. package/dist/socket/socket.utils.d.ts.map +1 -0
  42. package/dist/stream-adapter/index.d.ts +3 -0
  43. package/dist/stream-adapter/index.d.ts.map +1 -0
  44. package/dist/stream-adapter/stream-adapter.d.ts +21 -0
  45. package/dist/stream-adapter/stream-adapter.d.ts.map +1 -0
  46. package/dist/stream-adapter/stream-adapter.types.d.ts +22 -0
  47. package/dist/stream-adapter/stream-adapter.types.d.ts.map +1 -0
  48. package/dist/stream-adapter/stream-adapter.utils.d.ts +22 -0
  49. package/dist/stream-adapter/stream-adapter.utils.d.ts.map +1 -0
  50. package/dist/websocket-adapter/index.d.ts +3 -0
  51. package/dist/websocket-adapter/index.d.ts.map +1 -0
  52. package/dist/websocket-adapter/websocket-adapter.d.ts +21 -0
  53. package/dist/websocket-adapter/websocket-adapter.d.ts.map +1 -0
  54. package/dist/websocket-adapter/websocket-adapter.types.d.ts +22 -0
  55. package/dist/websocket-adapter/websocket-adapter.types.d.ts.map +1 -0
  56. package/dist/websocket-adapter/websocket-adapter.utils.d.ts +35 -0
  57. package/dist/websocket-adapter/websocket-adapter.utils.d.ts.map +1 -0
  58. package/package.json +3 -1
  59. package/src/adapter/adapter.fetch.ts +4 -3
  60. package/src/adapter/adapter.schema.ts +57 -0
  61. package/src/adapter/adapter.utils.ts +40 -10
  62. package/src/index.ts +3 -0
  63. package/src/socket/index.ts +2 -0
  64. package/src/socket/socket.subscriptions.ts +178 -0
  65. package/src/socket/socket.types.ts +64 -0
  66. package/src/socket/socket.utils.ts +110 -0
  67. package/src/stream-adapter/index.ts +2 -0
  68. package/src/stream-adapter/stream-adapter.ts +301 -0
  69. package/src/stream-adapter/stream-adapter.types.ts +31 -0
  70. package/src/stream-adapter/stream-adapter.utils.ts +98 -0
  71. package/src/websocket-adapter/index.ts +2 -0
  72. package/src/websocket-adapter/websocket-adapter.ts +315 -0
  73. package/src/websocket-adapter/websocket-adapter.types.ts +31 -0
  74. package/src/websocket-adapter/websocket-adapter.utils.ts +119 -0
@@ -0,0 +1,301 @@
1
+ /* eslint-disable @typescript-eslint/no-use-before-define */
2
+ import type { QueryParamsType } from "@hyper-fetch/core";
3
+ import { parseResponse, stringifyQueryParams } from "@hyper-fetch/core";
4
+ import type { SocketConnectionType } from "@hyper-fetch/sockets";
5
+ import { createReconnectingConnection, SocketAdapter } from "@hyper-fetch/sockets";
6
+ import { isORPCErrorStatus } from "@orpc/client";
7
+
8
+ import { createOrpcSerializer, getOrpcCallRequest, orpcEndpointMapper } from "../adapter/adapter.utils";
9
+ import { createOrpcSubscriptions } from "../socket/socket.subscriptions";
10
+ import type { OrpcSocketAdapterConfigType, OrpcSocketExtraType, OrpcSubscriptionType } from "../socket/socket.types";
11
+ import { getNotIteratorError, getOrpcResponseError } from "../socket/socket.utils";
12
+ import type { OrpcStreamAdapterOptionsType, OrpcStreamAdapterType } from "./stream-adapter.types";
13
+ import type { OrpcEventStreamMessageType } from "./stream-adapter.utils";
14
+ import { createEventStreamDecoder, getEventStreamIteratorEvent } from "./stream-adapter.utils";
15
+
16
+ /** Server side of one subscription - a running request, or the wait before it starts again */
17
+ type StreamTransportType = {
18
+ /** Aborts the running request. It is missing while the stream waits to start again. */
19
+ controller: AbortController | undefined;
20
+ /** Open timeout of the running request, or the delay before the stream starts again */
21
+ timer: ReturnType<typeof setTimeout> | undefined;
22
+ /** Failed starts in a row */
23
+ attempts: number;
24
+ timedOut: boolean;
25
+ };
26
+
27
+ type StreamSubscriptionType = OrpcSubscriptionType<StreamTransportType>;
28
+
29
+ /**
30
+ * Socket adapter for the event iterators of oRPC over HTTP. Every subscription is a call of the procedure with the
31
+ * RPC protocol - a `POST {url}/planet/onUpdate` with the serialized input - answered with a `text/event-stream`.
32
+ * The same protocol as the `RPCLink` of oRPC, so it works with the `RPCHandler` of `@orpc/server/fetch` or `/node`.
33
+ *
34
+ * There is no shared connection: "connected" means the adapter opens streams. `connect()` starts every
35
+ * subscription, `disconnect()` aborts them, `reconnect()` starts them again with the id of their last event.
36
+ * Listeners of the same procedure and input share one stream, the last one to unsubscribe aborts it.
37
+ * A subscription starts (`onStart`) when the server answers with the event stream, and ends (`onEnd`) when the
38
+ * iterator finishes, fails or the server rejects the call.
39
+ *
40
+ * @example
41
+ * const socket = new Socket({ url: "http://localhost:3000/rpc", adapter: OrpcStreamAdapter() });
42
+ * const sdk = createSocketSdk<typeof socket, OrpcSocketSchema<typeof router>>(socket, { camelCaseToKebabCase: false });
43
+ *
44
+ * sdk.planet.onUpdate.$listener.setPayload({ id: 1 }).listen(({ data, extra }) => console.log(data, extra.id));
45
+ */
46
+ export const OrpcStreamAdapter = ({
47
+ customJsonSerializers,
48
+ }: OrpcSocketAdapterConfigType = {}): OrpcStreamAdapterType => {
49
+ const serializer = createOrpcSerializer(customJsonSerializers);
50
+
51
+ return new SocketAdapter<
52
+ OrpcSocketExtraType,
53
+ OrpcStreamAdapterOptionsType,
54
+ undefined,
55
+ undefined,
56
+ QueryParamsType | string,
57
+ typeof stringifyQueryParams
58
+ >({ name: "orpc-stream", confirmsSubscriptions: true })
59
+ .setQueryParamsMapper(stringifyQueryParams)
60
+ .setConnector((bindings) => {
61
+ const { socket, adapter, getQueryParams, onConnectFailed } = bindings;
62
+
63
+ // Details of the current connection (after onConnect interceptors), every stream is opened with them.
64
+ // Set only while the adapter is connected.
65
+ let connection: SocketConnectionType<OrpcStreamAdapterType> | undefined;
66
+
67
+ const subscriptions = createOrpcSubscriptions<OrpcStreamAdapterType, StreamTransportType>({
68
+ bindings,
69
+ serializer,
70
+ start: (subscription) => startStream(subscription, 0),
71
+ stop: (subscription) => stopStream(subscription),
72
+ release: (subscription) => stopStream(subscription),
73
+ });
74
+
75
+ /**
76
+ * Aborts the request or the wait of the subscription. Whatever the old request reports later is ignored.
77
+ * For a stream the server ended it only releases the response.
78
+ */
79
+ const stopStream = (subscription: StreamSubscriptionType) => {
80
+ const { transport } = subscription;
81
+ subscription.transport = undefined;
82
+ subscription.started = false;
83
+ if (transport) {
84
+ clearTimeout(transport.timer);
85
+ transport.controller?.abort();
86
+ }
87
+ };
88
+
89
+ /** After a failure the stream starts again, after the `retry` of the last event or the socket reconnect time */
90
+ const scheduleRestart = (subscription: StreamSubscriptionType, attempts: number) => {
91
+ if (attempts > socket.reconnectAttempts) {
92
+ subscriptions.end(
93
+ subscription,
94
+ new Error(`Stopped restarting the stream of "${subscription.topic}" after ${attempts - 1} attempts`),
95
+ );
96
+ return;
97
+ }
98
+
99
+ const transport: StreamTransportType = { controller: undefined, timer: undefined, attempts, timedOut: false };
100
+ // Going offline closes the connection and stops the wait, coming back online starts the stream right away
101
+ transport.timer = setTimeout(() => {
102
+ startStream(subscription, attempts);
103
+ }, subscription.lastEventRetry ?? socket.reconnectTime);
104
+ subscription.transport = transport;
105
+ };
106
+
107
+ /** Returns `true` when the server ended the iterator */
108
+ const receiveMessage = (subscription: StreamSubscriptionType, message: OrpcEventStreamMessageType): boolean => {
109
+ try {
110
+ const event = getEventStreamIteratorEvent(message);
111
+ return event ? subscriptions.receive(subscription, event) : false;
112
+ } catch (error) {
113
+ // Data that is not JSON - the message is skipped, the stream goes on
114
+ subscriptions.report(subscription, error);
115
+ return false;
116
+ }
117
+ };
118
+
119
+ /**
120
+ * Reads the stream until the server ends it. Resolves the error of a call the server rejected, rejects when
121
+ * the transport failed - the network, the timeout or a stream cut in the middle of a message.
122
+ */
123
+ const readStream = async ({
124
+ subscription,
125
+ transport,
126
+ controller,
127
+ details: { url, queryParams, adapterOptions },
128
+ }: {
129
+ subscription: StreamSubscriptionType;
130
+ transport: StreamTransportType;
131
+ controller: AbortController;
132
+ details: SocketConnectionType<OrpcStreamAdapterType>;
133
+ }): Promise<Error | null> => {
134
+ const { headers, fetchOptions, fetch: customFetch } = adapterOptions ?? {};
135
+ const { lastEventId } = subscription;
136
+ const request = getOrpcCallRequest({
137
+ url,
138
+ endpoint: orpcEndpointMapper(subscription.topic),
139
+ queryParams: getQueryParams(queryParams),
140
+ // The server reads it as `lastEventId` and can resume where the previous stream stopped
141
+ headers: lastEventId === undefined ? { ...headers } : { ...headers, "last-event-id": lastEventId },
142
+ payload: subscription.payload,
143
+ method: "POST",
144
+ serializer,
145
+ });
146
+
147
+ // Checked to be a function when connecting
148
+ const fetchStream = customFetch ?? globalThis.fetch;
149
+ const response = await fetchStream(request.url, {
150
+ ...fetchOptions,
151
+ method: request.method,
152
+ headers: request.headers,
153
+ body: request.body,
154
+ signal: controller.signal,
155
+ });
156
+ clearTimeout(transport.timer);
157
+
158
+ if (isORPCErrorStatus(response.status)) {
159
+ const body = parseResponse(await response.text());
160
+ return getOrpcResponseError({ status: response.status, body, serializer });
161
+ }
162
+ if (!response.headers.get("content-type")?.startsWith("text/event-stream")) {
163
+ return getNotIteratorError(subscription.topic);
164
+ }
165
+ // The server accepted the call, the next failure counts from the beginning
166
+ transport.attempts = 0;
167
+ // Unless the listeners left while the response was on its way
168
+ if (subscription.transport === transport) {
169
+ subscriptions.confirm(subscription);
170
+ }
171
+
172
+ if (!response.body) {
173
+ return null;
174
+ }
175
+
176
+ const reader = response.body.getReader();
177
+ const textDecoder = new TextDecoder();
178
+ let ended = false;
179
+ const eventDecoder = createEventStreamDecoder((message) => {
180
+ // Messages after the end, or after the subscription stopped, are not delivered
181
+ if (!ended && subscription.transport === transport) {
182
+ ended = receiveMessage(subscription, message);
183
+ }
184
+ });
185
+
186
+ let chunk = await reader.read();
187
+ while (!chunk.done) {
188
+ eventDecoder.feed(textDecoder.decode(chunk.value, { stream: true }));
189
+ if (ended) {
190
+ return null;
191
+ }
192
+ // eslint-disable-next-line no-await-in-loop
193
+ chunk = await reader.read();
194
+ }
195
+ // A stream closed without the `done` event is a finished iterator, the same as in oRPC
196
+ eventDecoder.feed(textDecoder.decode());
197
+ eventDecoder.end();
198
+ return null;
199
+ };
200
+
201
+ const startStream = (subscription: StreamSubscriptionType, attempts: number) => {
202
+ // Not connected - the stream starts on connect
203
+ const details = connection;
204
+ if (!details) {
205
+ return;
206
+ }
207
+
208
+ const controller = new AbortController();
209
+ const transport: StreamTransportType = { controller, timer: undefined, attempts, timedOut: false };
210
+ subscription.transport = transport;
211
+ const isCurrent = () => subscription.transport === transport;
212
+
213
+ // Connection timeout - when the server does not answer in time, the stream starts again
214
+ transport.timer = setTimeout(() => {
215
+ transport.timedOut = true;
216
+ controller.abort();
217
+ }, socket.connectionTimeout);
218
+
219
+ readStream({ subscription, transport, controller, details }).then(
220
+ (rejection) => {
221
+ if (!isCurrent()) {
222
+ return;
223
+ }
224
+ // The server ended the iterator or rejected the call - the subscription is over
225
+ subscriptions.end(subscription, rejection ?? undefined);
226
+ },
227
+ (error) => {
228
+ if (!isCurrent()) {
229
+ return;
230
+ }
231
+ stopStream(subscription);
232
+ subscriptions.report(
233
+ subscription,
234
+ transport.timedOut
235
+ ? new Error(`The stream of "${subscription.topic}" did not open in ${socket.connectionTimeout}ms`)
236
+ : error,
237
+ );
238
+ scheduleRestart(subscription, transport.attempts + 1);
239
+ },
240
+ );
241
+ };
242
+
243
+ /** Aborts every stream. Listeners stay registered and keep the id of their last event for the next connection. */
244
+ const stopStreams = () => {
245
+ subscriptions.values().forEach(stopStream);
246
+ };
247
+
248
+ /**
249
+ * There is no shared transport - the connection is the set of streams opened with its details. It is ready at
250
+ * once, and it is never lost as a whole: every stream fails and starts again on its own (`scheduleRestart`).
251
+ */
252
+ const connectionLifecycle = createReconnectingConnection({
253
+ bindings,
254
+ autoConnect: adapter.adapterOptions?.autoConnect ?? true,
255
+ open: (attempt) => {
256
+ const details = attempt.connection;
257
+ if (typeof (details.adapterOptions?.fetch ?? globalThis.fetch) !== "function") {
258
+ onConnectFailed({ error: new Error("fetch is not available in this environment") });
259
+ return null;
260
+ }
261
+
262
+ connection = details;
263
+ attempt.ready();
264
+ subscriptions.values().forEach((subscription) => {
265
+ // A listener added by an `onConnected` callback is running already
266
+ if (!subscription.transport) {
267
+ startStream(subscription, 0);
268
+ }
269
+ });
270
+
271
+ return {
272
+ close: () => {
273
+ // The engine closes an attempt before it opens the next one, so these are always the current details
274
+ connection = undefined;
275
+ stopStreams();
276
+ },
277
+ };
278
+ },
279
+ });
280
+
281
+ // Event iterators only send data from the server. Throwing synchronously makes `emitter.emit()` fail right at
282
+ // the call site, the same as in the Server-Sent Events adapter.
283
+ const emit = () => {
284
+ throw new Error("Cannot emit events in the oRPC stream adapter, it only receives events of subscriptions");
285
+ };
286
+
287
+ return {
288
+ connect: connectionLifecycle.connect,
289
+ reconnect: connectionLifecycle.reconnect,
290
+ disconnect: connectionLifecycle.disconnect,
291
+ listen: subscriptions.listen,
292
+ emit,
293
+ // Nothing of this connector outlives the socket - no app manager subscriptions, no running or waiting streams
294
+ dispose: () => {
295
+ connectionLifecycle.dispose();
296
+ connection = undefined;
297
+ stopStreams();
298
+ },
299
+ };
300
+ });
301
+ };
@@ -0,0 +1,31 @@
1
+ import type { QueryParamsType, stringifyQueryParams } from "@hyper-fetch/core";
2
+ import type { SocketAdapter } from "@hyper-fetch/sockets";
3
+
4
+ import type { OrpcSocketExtraType } from "../socket/socket.types";
5
+
6
+ /** Options of the `OrpcStreamAdapter`, set with the `adapterOptions` of the socket or per connection in `onConnect` */
7
+ export type OrpcStreamAdapterOptionsType = {
8
+ /**
9
+ * Connects when the socket is created. Without it, call `socket.connect()`.
10
+ * @default true
11
+ */
12
+ autoConnect?: boolean;
13
+ /** Headers of every stream request, e.g. the `authorization` header */
14
+ headers?: Record<string, string>;
15
+ /**
16
+ * The `fetch` used for the streams, e.g. one with a proxy agent or a mock in tests. Defaults to the global `fetch`
17
+ * of browsers, Node.js 18+, Bun and Deno.
18
+ */
19
+ fetch?: typeof fetch;
20
+ /** Options passed to `fetch`, e.g. `credentials: "include"` for cookies on another origin */
21
+ fetchOptions?: Omit<RequestInit, "method" | "headers" | "body" | "signal">;
22
+ };
23
+
24
+ export type OrpcStreamAdapterType = SocketAdapter<
25
+ OrpcSocketExtraType,
26
+ OrpcStreamAdapterOptionsType,
27
+ undefined,
28
+ undefined,
29
+ QueryParamsType | string,
30
+ typeof stringifyQueryParams
31
+ >;
@@ -0,0 +1,98 @@
1
+ import type { OrpcIteratorEventType } from "../socket/socket.types";
2
+
3
+ /** One message of a `text/event-stream`, the fields of the Server-Sent Events format */
4
+ export type OrpcEventStreamMessageType = {
5
+ event: string | undefined;
6
+ data: string | undefined;
7
+ id: string | undefined;
8
+ retry: number | undefined;
9
+ };
10
+
11
+ const lineEnding = /\r\n|\r(?!\n)|\n/;
12
+ const messageDelimiter = /(?:\r\n|\r(?!\n)|\n){2}/g;
13
+
14
+ /** Reads the fields of one message, the same as `decodeEventMessage` of oRPC */
15
+ const decodeEventStreamMessage = (encoded: string): OrpcEventStreamMessageType => {
16
+ const message: OrpcEventStreamMessageType = { event: undefined, data: undefined, id: undefined, retry: undefined };
17
+
18
+ encoded.split(lineEnding).forEach((line) => {
19
+ const index = line.indexOf(":");
20
+ // Lines starting with a colon are comments, the keep-alive pings of oRPC
21
+ if (line === "" || index === 0) {
22
+ return;
23
+ }
24
+ const field = index === -1 ? line : line.slice(0, index);
25
+ const value = index === -1 ? "" : line.slice(line.charAt(index + 1) === " " ? index + 2 : index + 1);
26
+
27
+ if (field === "data") {
28
+ message.data = message.data === undefined ? value : `${message.data}\n${value}`;
29
+ } else if (field === "event") {
30
+ message.event = value;
31
+ } else if (field === "id") {
32
+ message.id = value;
33
+ } else if (field === "retry") {
34
+ const retry = Number.parseInt(value, 10);
35
+ if (retry >= 0 && retry.toString() === value) {
36
+ message.retry = retry;
37
+ }
38
+ }
39
+ });
40
+
41
+ return message;
42
+ };
43
+
44
+ /**
45
+ * Splits the text of a `text/event-stream` into messages, the same as the `EventDecoder` of oRPC. Chunks can end
46
+ * anywhere, the text after the last complete message waits for the next chunk.
47
+ */
48
+ export const createEventStreamDecoder = (onMessage: (message: OrpcEventStreamMessageType) => void) => {
49
+ let pending = "";
50
+ // A chunk that ended a message with `\r` may be followed by the `\n` of the same `\r\n`
51
+ let discardLeadingLineFeed = false;
52
+
53
+ const feed = (chunk: string) => {
54
+ pending += discardLeadingLineFeed && chunk.startsWith("\n") ? chunk.slice(1) : chunk;
55
+ discardLeadingLineFeed = false;
56
+
57
+ let start = 0;
58
+ const messages: string[] = [];
59
+ [...pending.matchAll(messageDelimiter)].forEach((match) => {
60
+ // `matchAll` always sets the index - older TypeScript versions type it as optional
61
+ const { index = 0 } = match;
62
+ messages.push(pending.slice(start, index));
63
+ start = index + match[0].length;
64
+ });
65
+ if (messages.length > 0) {
66
+ discardLeadingLineFeed = start === pending.length && pending.endsWith("\r");
67
+ }
68
+ pending = pending.slice(start);
69
+
70
+ messages.forEach((message) => onMessage(decodeEventStreamMessage(message)));
71
+ };
72
+
73
+ /** The same as oRPC - a stream that stops in the middle of a message is broken */
74
+ const end = () => {
75
+ if (pending !== "") {
76
+ throw new Error("The event stream ended before the last message was complete");
77
+ }
78
+ };
79
+
80
+ return { feed, end };
81
+ };
82
+
83
+ /**
84
+ * Maps a message to the event of the server iterator, the same as `toEventIterator` of oRPC. Messages without an
85
+ * event and data are keep-alive pings and return `null`. Throws when the data is not JSON.
86
+ */
87
+ export const getEventStreamIteratorEvent = (message: OrpcEventStreamMessageType): OrpcIteratorEventType | null => {
88
+ const event = message.event ?? (message.data !== undefined ? "message" : undefined);
89
+ const meta = { id: message.id, retry: message.retry };
90
+
91
+ if (event === "message" || event === "error") {
92
+ return { event, data: message.data ? JSON.parse(message.data) : undefined, meta };
93
+ }
94
+ if (event === "done" || event === "close") {
95
+ return { event: "done", data: undefined, meta };
96
+ }
97
+ return null;
98
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./websocket-adapter";
2
+ export * from "./websocket-adapter.types";