@replit/river 0.10.0 → 0.10.1
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/{router/builder.d.ts → builder-3c4485f0.d.ts} +76 -21
- package/dist/chunk-7WJ6YLE5.js +683 -0
- package/dist/chunk-AJQU4AZG.js +284 -0
- package/dist/chunk-ORAG7IAU.js +0 -0
- package/dist/chunk-PC65ZFWJ.js +29 -0
- package/dist/chunk-R6H2BIMC.js +49 -0
- package/dist/chunk-RGMHF6PF.js +65 -0
- package/dist/chunk-SLUSVGQH.js +30 -0
- package/dist/chunk-UU2Z7LDR.js +113 -0
- package/dist/chunk-WVT5QXMZ.js +20 -0
- package/dist/chunk-ZE4MX7DF.js +75 -0
- package/dist/codec/index.cjs +94 -0
- package/dist/codec/index.d.cts +15 -0
- package/dist/codec/index.d.ts +15 -4
- package/dist/codec/index.js +10 -2
- package/dist/connection-8e19874c.d.ts +11 -0
- package/dist/connection-f7688cc1.d.ts +11 -0
- package/dist/logging/index.cjs +56 -0
- package/dist/logging/index.d.cts +28 -0
- package/dist/logging/index.d.ts +6 -6
- package/dist/logging/index.js +9 -40
- package/dist/router/index.cjs +770 -0
- package/dist/router/index.d.cts +114 -0
- package/dist/router/index.d.ts +114 -12
- package/dist/router/index.js +24 -5
- package/dist/transport/impls/ws/client.cjs +505 -0
- package/dist/transport/impls/ws/client.d.cts +42 -0
- package/dist/transport/impls/ws/client.d.ts +8 -8
- package/dist/transport/impls/ws/client.js +10 -100
- package/dist/transport/impls/ws/server.cjs +457 -0
- package/dist/transport/impls/ws/server.d.cts +21 -0
- package/dist/transport/impls/ws/server.d.ts +11 -10
- package/dist/transport/impls/ws/server.js +11 -52
- package/dist/transport/index.cjs +362 -0
- package/dist/transport/{transport.d.ts → index.d.cts} +119 -7
- package/dist/transport/index.d.ts +273 -4
- package/dist/transport/index.js +20 -2
- package/dist/{codec/types.d.ts → types-3e5768ec.d.ts} +3 -2
- package/dist/util/testHelpers.cjs +731 -0
- package/dist/util/testHelpers.d.cts +79 -0
- package/dist/util/testHelpers.d.ts +22 -19
- package/dist/util/testHelpers.js +135 -163
- package/package.json +41 -13
- package/dist/__tests__/bandwidth.bench.d.ts +0 -2
- package/dist/__tests__/bandwidth.bench.d.ts.map +0 -1
- package/dist/__tests__/bandwidth.bench.js +0 -90
- package/dist/__tests__/cleanup.test.d.ts +0 -2
- package/dist/__tests__/cleanup.test.d.ts.map +0 -1
- package/dist/__tests__/cleanup.test.js +0 -165
- package/dist/__tests__/disconnects.test.d.ts +0 -2
- package/dist/__tests__/disconnects.test.d.ts.map +0 -1
- package/dist/__tests__/disconnects.test.js +0 -163
- package/dist/__tests__/e2e.test.d.ts +0 -2
- package/dist/__tests__/e2e.test.d.ts.map +0 -1
- package/dist/__tests__/e2e.test.js +0 -317
- package/dist/__tests__/fixtures/cleanup.d.ts +0 -12
- package/dist/__tests__/fixtures/cleanup.d.ts.map +0 -1
- package/dist/__tests__/fixtures/cleanup.js +0 -36
- package/dist/__tests__/fixtures/largePayload.json +0 -33
- package/dist/__tests__/fixtures/observable.d.ts +0 -26
- package/dist/__tests__/fixtures/observable.d.ts.map +0 -1
- package/dist/__tests__/fixtures/observable.js +0 -38
- package/dist/__tests__/fixtures/observable.test.d.ts +0 -2
- package/dist/__tests__/fixtures/observable.test.d.ts.map +0 -1
- package/dist/__tests__/fixtures/observable.test.js +0 -39
- package/dist/__tests__/fixtures/services.d.ts +0 -288
- package/dist/__tests__/fixtures/services.d.ts.map +0 -1
- package/dist/__tests__/fixtures/services.js +0 -207
- package/dist/__tests__/handler.test.d.ts +0 -2
- package/dist/__tests__/handler.test.d.ts.map +0 -1
- package/dist/__tests__/handler.test.js +0 -120
- package/dist/__tests__/serialize.test.d.ts +0 -2
- package/dist/__tests__/serialize.test.d.ts.map +0 -1
- package/dist/__tests__/serialize.test.js +0 -208
- package/dist/__tests__/typescript-stress.test.d.ts +0 -1583
- package/dist/__tests__/typescript-stress.test.d.ts.map +0 -1
- package/dist/__tests__/typescript-stress.test.js +0 -123
- package/dist/codec/binary.d.ts +0 -7
- package/dist/codec/binary.d.ts.map +0 -1
- package/dist/codec/binary.js +0 -20
- package/dist/codec/codec.test.d.ts +0 -5
- package/dist/codec/codec.test.d.ts.map +0 -1
- package/dist/codec/codec.test.js +0 -41
- package/dist/codec/index.d.ts.map +0 -1
- package/dist/codec/json.d.ts +0 -7
- package/dist/codec/json.d.ts.map +0 -1
- package/dist/codec/json.js +0 -51
- package/dist/codec/types.d.ts.map +0 -1
- package/dist/codec/types.js +0 -1
- package/dist/logging/index.d.ts.map +0 -1
- package/dist/router/builder.d.ts.map +0 -1
- package/dist/router/builder.js +0 -91
- package/dist/router/client.d.ts +0 -72
- package/dist/router/client.d.ts.map +0 -1
- package/dist/router/client.js +0 -257
- package/dist/router/context.d.ts +0 -30
- package/dist/router/context.d.ts.map +0 -1
- package/dist/router/context.js +0 -1
- package/dist/router/defs.d.ts +0 -16
- package/dist/router/defs.d.ts.map +0 -1
- package/dist/router/defs.js +0 -11
- package/dist/router/index.d.ts.map +0 -1
- package/dist/router/result.d.ts +0 -26
- package/dist/router/result.d.ts.map +0 -1
- package/dist/router/result.js +0 -22
- package/dist/router/server.d.ts +0 -39
- package/dist/router/server.d.ts.map +0 -1
- package/dist/router/server.js +0 -260
- package/dist/transport/events.d.ts +0 -19
- package/dist/transport/events.d.ts.map +0 -1
- package/dist/transport/events.js +0 -26
- package/dist/transport/impls/stdio/stdio.d.ts +0 -33
- package/dist/transport/impls/stdio/stdio.d.ts.map +0 -1
- package/dist/transport/impls/stdio/stdio.js +0 -75
- package/dist/transport/impls/stdio/stdio.test.d.ts +0 -2
- package/dist/transport/impls/stdio/stdio.test.d.ts.map +0 -1
- package/dist/transport/impls/stdio/stdio.test.js +0 -24
- package/dist/transport/impls/ws/client.d.ts.map +0 -1
- package/dist/transport/impls/ws/connection.d.ts +0 -11
- package/dist/transport/impls/ws/connection.d.ts.map +0 -1
- package/dist/transport/impls/ws/connection.js +0 -23
- package/dist/transport/impls/ws/server.d.ts.map +0 -1
- package/dist/transport/impls/ws/ws.test.d.ts +0 -2
- package/dist/transport/impls/ws/ws.test.d.ts.map +0 -1
- package/dist/transport/impls/ws/ws.test.js +0 -185
- package/dist/transport/index.d.ts.map +0 -1
- package/dist/transport/message.d.ts +0 -142
- package/dist/transport/message.d.ts.map +0 -1
- package/dist/transport/message.js +0 -113
- package/dist/transport/message.test.d.ts +0 -2
- package/dist/transport/message.test.d.ts.map +0 -1
- package/dist/transport/message.test.js +0 -52
- package/dist/transport/transport.d.ts.map +0 -1
- package/dist/transport/transport.js +0 -281
- package/dist/util/testHelpers.d.ts.map +0 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as it_pushable from 'it-pushable';
|
|
2
|
+
import WebSocket from 'isomorphic-ws';
|
|
3
|
+
import { WebSocketServer } from 'ws';
|
|
4
|
+
import http from 'http';
|
|
5
|
+
import { WebSocketClientTransport } from '../transport/impls/ws/client.cjs';
|
|
6
|
+
import { TransportClientId, TransportMessage, OpaqueTransportMessage, Transport, Connection } from '../transport/index.cjs';
|
|
7
|
+
import { C as Codec } from '../types-3e5768ec.js';
|
|
8
|
+
import { WebSocketServerTransport } from '../transport/impls/ws/server.cjs';
|
|
9
|
+
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-3c4485f0.js';
|
|
10
|
+
import { Static } from '@sinclair/typebox';
|
|
11
|
+
import '../connection-f7688cc1.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates a WebSocket server instance using the provided HTTP server.
|
|
15
|
+
* Only used as helper for testing.
|
|
16
|
+
* @param server - The HTTP server instance to use for the WebSocket server.
|
|
17
|
+
* @returns A Promise that resolves to the created WebSocket server instance.
|
|
18
|
+
*/
|
|
19
|
+
declare function createWebSocketServer(server: http.Server): Promise<WebSocket.Server<typeof WebSocket, typeof http.IncomingMessage>>;
|
|
20
|
+
/**
|
|
21
|
+
* Starts listening on the given server and returns the automatically allocated port number.
|
|
22
|
+
* This should only be used for testing.
|
|
23
|
+
* @param server - The http server to listen on.
|
|
24
|
+
* @returns A promise that resolves with the allocated port number.
|
|
25
|
+
* @throws An error if a port cannot be allocated.
|
|
26
|
+
*/
|
|
27
|
+
declare function onServerReady(server: http.Server): Promise<number>;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a WebSocket client that connects to a local server at the specified port.
|
|
30
|
+
* This should only be used for testing.
|
|
31
|
+
* @param port - The port number to connect to.
|
|
32
|
+
* @returns A Promise that resolves to a WebSocket instance.
|
|
33
|
+
*/
|
|
34
|
+
declare function createLocalWebSocketClient(port: number): Promise<WebSocket>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a pair of WebSocket transports for testing purposes.
|
|
37
|
+
* @param port - The port number to use for the client transport. This should be acquired after starting a server via {@link createWebSocketServer}.
|
|
38
|
+
* @param wss - The WebSocketServer instance to use for the server transport.
|
|
39
|
+
* @returns An array containing the client and server {@link WebSocketClientTransport} instances.
|
|
40
|
+
*/
|
|
41
|
+
declare function createWsTransports(port: number, wss: WebSocketServer, codec?: Codec): [WebSocketClientTransport, WebSocketServerTransport];
|
|
42
|
+
/**
|
|
43
|
+
* Converts a payload object to a transport message with reasonable defaults.
|
|
44
|
+
* This should only be used for testing.
|
|
45
|
+
* @param payload - The payload object to be converted.
|
|
46
|
+
* @param streamId - The optional stream ID.
|
|
47
|
+
* @returns The transport message.
|
|
48
|
+
*/
|
|
49
|
+
declare function payloadToTransportMessage<Payload extends object>(payload: Payload, streamId?: string, from?: TransportClientId, to?: TransportClientId): TransportMessage<Payload>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a dummy opaque transport message for testing purposes.
|
|
52
|
+
* @returns The created opaque transport message.
|
|
53
|
+
*/
|
|
54
|
+
declare function createDummyTransportMessage(): OpaqueTransportMessage;
|
|
55
|
+
/**
|
|
56
|
+
* Retrieves the next value from an async iterable iterator.
|
|
57
|
+
* @param iter The async iterable iterator.
|
|
58
|
+
* @returns A promise that resolves to the next value from the iterator.
|
|
59
|
+
*/
|
|
60
|
+
declare function iterNext<T>(iter: AsyncIterableIterator<T>): Promise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* Waits for a message on the transport.
|
|
63
|
+
* @param {Transport} t - The transport to listen to.
|
|
64
|
+
* @param filter - An optional filter function to apply to the received messages.
|
|
65
|
+
* @returns A promise that resolves with the payload of the first message that passes the filter.
|
|
66
|
+
*/
|
|
67
|
+
declare function waitForMessage(t: Transport<Connection>, filter?: (msg: OpaqueTransportMessage) => boolean, rejectMismatch?: boolean): Promise<unknown>;
|
|
68
|
+
declare function asClientRpc<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'rpc', I, O, E, Init>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>;
|
|
69
|
+
declare function asClientStream<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'stream', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>];
|
|
70
|
+
declare function asClientSubscription<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'subscription', I, O, E>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => Promise<it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>>;
|
|
71
|
+
declare function asClientUpload<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'upload', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): Promise<readonly [it_pushable.Pushable<Static<I>, void, unknown>, Promise<{
|
|
72
|
+
ok: boolean;
|
|
73
|
+
payload: {
|
|
74
|
+
code: string;
|
|
75
|
+
message: string;
|
|
76
|
+
};
|
|
77
|
+
} | Result<Static<O>, Static<E>>>]>;
|
|
78
|
+
|
|
79
|
+
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer, createWsTransports, iterNext, onServerReady, payloadToTransportMessage, waitForMessage };
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import * as it_pushable from 'it-pushable';
|
|
2
2
|
import WebSocket from 'isomorphic-ws';
|
|
3
3
|
import { WebSocketServer } from 'ws';
|
|
4
4
|
import http from 'http';
|
|
5
|
-
import { WebSocketClientTransport } from '../transport/impls/ws/client';
|
|
6
|
-
import {
|
|
7
|
-
import { Codec } from '../
|
|
8
|
-
import { WebSocketServerTransport } from '../transport/impls/ws/server';
|
|
9
|
-
import { PayloadType, Procedure,
|
|
5
|
+
import { WebSocketClientTransport } from '../transport/impls/ws/client.js';
|
|
6
|
+
import { TransportClientId, TransportMessage, OpaqueTransportMessage, Transport, Connection } from '../transport/index.js';
|
|
7
|
+
import { C as Codec } from '../types-3e5768ec.js';
|
|
8
|
+
import { WebSocketServerTransport } from '../transport/impls/ws/server.js';
|
|
9
|
+
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-3c4485f0.js';
|
|
10
10
|
import { Static } from '@sinclair/typebox';
|
|
11
|
+
import '../connection-8e19874c.js';
|
|
12
|
+
|
|
11
13
|
/**
|
|
12
14
|
* Creates a WebSocket server instance using the provided HTTP server.
|
|
13
15
|
* Only used as helper for testing.
|
|
14
16
|
* @param server - The HTTP server instance to use for the WebSocket server.
|
|
15
17
|
* @returns A Promise that resolves to the created WebSocket server instance.
|
|
16
18
|
*/
|
|
17
|
-
|
|
19
|
+
declare function createWebSocketServer(server: http.Server): Promise<WebSocket.Server<typeof WebSocket, typeof http.IncomingMessage>>;
|
|
18
20
|
/**
|
|
19
21
|
* Starts listening on the given server and returns the automatically allocated port number.
|
|
20
22
|
* This should only be used for testing.
|
|
@@ -22,21 +24,21 @@ export declare function createWebSocketServer(server: http.Server): Promise<WebS
|
|
|
22
24
|
* @returns A promise that resolves with the allocated port number.
|
|
23
25
|
* @throws An error if a port cannot be allocated.
|
|
24
26
|
*/
|
|
25
|
-
|
|
27
|
+
declare function onServerReady(server: http.Server): Promise<number>;
|
|
26
28
|
/**
|
|
27
29
|
* Creates a WebSocket client that connects to a local server at the specified port.
|
|
28
30
|
* This should only be used for testing.
|
|
29
31
|
* @param port - The port number to connect to.
|
|
30
32
|
* @returns A Promise that resolves to a WebSocket instance.
|
|
31
33
|
*/
|
|
32
|
-
|
|
34
|
+
declare function createLocalWebSocketClient(port: number): Promise<WebSocket>;
|
|
33
35
|
/**
|
|
34
36
|
* Creates a pair of WebSocket transports for testing purposes.
|
|
35
37
|
* @param port - The port number to use for the client transport. This should be acquired after starting a server via {@link createWebSocketServer}.
|
|
36
38
|
* @param wss - The WebSocketServer instance to use for the server transport.
|
|
37
39
|
* @returns An array containing the client and server {@link WebSocketClientTransport} instances.
|
|
38
40
|
*/
|
|
39
|
-
|
|
41
|
+
declare function createWsTransports(port: number, wss: WebSocketServer, codec?: Codec): [WebSocketClientTransport, WebSocketServerTransport];
|
|
40
42
|
/**
|
|
41
43
|
* Converts a payload object to a transport message with reasonable defaults.
|
|
42
44
|
* This should only be used for testing.
|
|
@@ -44,33 +46,34 @@ export declare function createWsTransports(port: number, wss: WebSocketServer, c
|
|
|
44
46
|
* @param streamId - The optional stream ID.
|
|
45
47
|
* @returns The transport message.
|
|
46
48
|
*/
|
|
47
|
-
|
|
49
|
+
declare function payloadToTransportMessage<Payload extends object>(payload: Payload, streamId?: string, from?: TransportClientId, to?: TransportClientId): TransportMessage<Payload>;
|
|
48
50
|
/**
|
|
49
51
|
* Creates a dummy opaque transport message for testing purposes.
|
|
50
52
|
* @returns The created opaque transport message.
|
|
51
53
|
*/
|
|
52
|
-
|
|
54
|
+
declare function createDummyTransportMessage(): OpaqueTransportMessage;
|
|
53
55
|
/**
|
|
54
56
|
* Retrieves the next value from an async iterable iterator.
|
|
55
57
|
* @param iter The async iterable iterator.
|
|
56
58
|
* @returns A promise that resolves to the next value from the iterator.
|
|
57
59
|
*/
|
|
58
|
-
|
|
60
|
+
declare function iterNext<T>(iter: AsyncIterableIterator<T>): Promise<any>;
|
|
59
61
|
/**
|
|
60
62
|
* Waits for a message on the transport.
|
|
61
63
|
* @param {Transport} t - The transport to listen to.
|
|
62
64
|
* @param filter - An optional filter function to apply to the received messages.
|
|
63
65
|
* @returns A promise that resolves with the payload of the first message that passes the filter.
|
|
64
66
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
declare function waitForMessage(t: Transport<Connection>, filter?: (msg: OpaqueTransportMessage) => boolean, rejectMismatch?: boolean): Promise<unknown>;
|
|
68
|
+
declare function asClientRpc<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'rpc', I, O, E, Init>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>;
|
|
69
|
+
declare function asClientStream<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'stream', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>];
|
|
70
|
+
declare function asClientSubscription<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'subscription', I, O, E>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => Promise<it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>>;
|
|
71
|
+
declare function asClientUpload<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'upload', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): Promise<readonly [it_pushable.Pushable<Static<I>, void, unknown>, Promise<{
|
|
70
72
|
ok: boolean;
|
|
71
73
|
payload: {
|
|
72
74
|
code: string;
|
|
73
75
|
message: string;
|
|
74
76
|
};
|
|
75
77
|
} | Result<Static<O>, Static<E>>>]>;
|
|
76
|
-
|
|
78
|
+
|
|
79
|
+
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer, createWsTransports, iterNext, onServerReady, payloadToTransportMessage, waitForMessage };
|
package/dist/util/testHelpers.js
CHANGED
|
@@ -1,179 +1,151 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import {
|
|
2
|
+
UNCAUGHT_ERROR
|
|
3
|
+
} from "../chunk-7WJ6YLE5.js";
|
|
4
|
+
import "../chunk-ORAG7IAU.js";
|
|
5
|
+
import {
|
|
6
|
+
WebSocketClientTransport
|
|
7
|
+
} from "../chunk-UU2Z7LDR.js";
|
|
8
|
+
import {
|
|
9
|
+
WebSocketServerTransport
|
|
10
|
+
} from "../chunk-RGMHF6PF.js";
|
|
11
|
+
import "../chunk-WVT5QXMZ.js";
|
|
12
|
+
import "../chunk-PC65ZFWJ.js";
|
|
13
|
+
import "../chunk-R6H2BIMC.js";
|
|
14
|
+
import "../chunk-AJQU4AZG.js";
|
|
15
|
+
import {
|
|
16
|
+
msg
|
|
17
|
+
} from "../chunk-ZE4MX7DF.js";
|
|
18
|
+
import "../chunk-SLUSVGQH.js";
|
|
19
|
+
|
|
20
|
+
// util/testHelpers.ts
|
|
21
|
+
import WebSocket from "isomorphic-ws";
|
|
22
|
+
import { WebSocketServer } from "ws";
|
|
23
|
+
import { pushable } from "it-pushable";
|
|
24
|
+
async function createWebSocketServer(server) {
|
|
25
|
+
return new WebSocketServer({ server });
|
|
16
26
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
server.listen(() => {
|
|
27
|
-
const addr = server.address();
|
|
28
|
-
if (typeof addr === 'object' && addr) {
|
|
29
|
-
resolve(addr.port);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
reject(new Error("couldn't find a port to allocate"));
|
|
33
|
-
}
|
|
34
|
-
});
|
|
27
|
+
async function onServerReady(server) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
server.listen(() => {
|
|
30
|
+
const addr = server.address();
|
|
31
|
+
if (typeof addr === "object" && addr) {
|
|
32
|
+
resolve(addr.port);
|
|
33
|
+
} else {
|
|
34
|
+
reject(new Error("couldn't find a port to allocate"));
|
|
35
|
+
}
|
|
35
36
|
});
|
|
37
|
+
});
|
|
36
38
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* @returns A Promise that resolves to a WebSocket instance.
|
|
42
|
-
*/
|
|
43
|
-
export async function createLocalWebSocketClient(port) {
|
|
44
|
-
const sock = new WebSocket(`ws://localhost:${port}`);
|
|
45
|
-
sock.binaryType = 'arraybuffer';
|
|
46
|
-
return sock;
|
|
39
|
+
async function createLocalWebSocketClient(port) {
|
|
40
|
+
const sock = new WebSocket(`ws://localhost:${port}`);
|
|
41
|
+
sock.binaryType = "arraybuffer";
|
|
42
|
+
return sock;
|
|
47
43
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
];
|
|
44
|
+
function createWsTransports(port, wss, codec) {
|
|
45
|
+
const options = codec ? { codec } : void 0;
|
|
46
|
+
return [
|
|
47
|
+
new WebSocketClientTransport(
|
|
48
|
+
() => createLocalWebSocketClient(port),
|
|
49
|
+
"client",
|
|
50
|
+
"SERVER",
|
|
51
|
+
options
|
|
52
|
+
),
|
|
53
|
+
new WebSocketServerTransport(wss, "SERVER", options)
|
|
54
|
+
];
|
|
60
55
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
* This should only be used for testing.
|
|
64
|
-
* @param payload - The payload object to be converted.
|
|
65
|
-
* @param streamId - The optional stream ID.
|
|
66
|
-
* @returns The transport message.
|
|
67
|
-
*/
|
|
68
|
-
export function payloadToTransportMessage(payload, streamId, from = 'client', to = 'SERVER') {
|
|
69
|
-
return msg(from, to, streamId ?? 'stream', payload, 'service', 'procedure');
|
|
56
|
+
function payloadToTransportMessage(payload, streamId, from = "client", to = "SERVER") {
|
|
57
|
+
return msg(from, to, streamId ?? "stream", payload, "service", "procedure");
|
|
70
58
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return payloadToTransportMessage({
|
|
77
|
-
msg: 'cool',
|
|
78
|
-
test: Math.random(),
|
|
79
|
-
});
|
|
59
|
+
function createDummyTransportMessage() {
|
|
60
|
+
return payloadToTransportMessage({
|
|
61
|
+
msg: "cool",
|
|
62
|
+
test: Math.random()
|
|
63
|
+
});
|
|
80
64
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
* @param iter The async iterable iterator.
|
|
84
|
-
* @returns A promise that resolves to the next value from the iterator.
|
|
85
|
-
*/
|
|
86
|
-
export async function iterNext(iter) {
|
|
87
|
-
return await iter.next().then((res) => res.value);
|
|
65
|
+
async function iterNext(iter) {
|
|
66
|
+
return await iter.next().then((res) => res.value);
|
|
88
67
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
else if (rejectMismatch) {
|
|
106
|
-
reject(new Error('message didnt match the filter'));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
t.addEventListener('message', onMessage);
|
|
110
|
-
});
|
|
68
|
+
async function waitForMessage(t, filter, rejectMismatch) {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
function cleanup() {
|
|
71
|
+
t.removeEventListener("message", onMessage);
|
|
72
|
+
}
|
|
73
|
+
function onMessage(msg2) {
|
|
74
|
+
if (!filter || filter?.(msg2)) {
|
|
75
|
+
cleanup();
|
|
76
|
+
resolve(msg2.payload);
|
|
77
|
+
} else if (rejectMismatch) {
|
|
78
|
+
reject(new Error("message didnt match the filter"));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
t.addEventListener("message", onMessage);
|
|
82
|
+
});
|
|
111
83
|
}
|
|
112
84
|
function catchProcError(err) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
85
|
+
const errorMsg = err instanceof Error ? err.message : `[coerced to error] ${err}`;
|
|
86
|
+
return {
|
|
87
|
+
ok: false,
|
|
88
|
+
payload: {
|
|
89
|
+
code: UNCAUGHT_ERROR,
|
|
90
|
+
message: errorMsg
|
|
91
|
+
}
|
|
92
|
+
};
|
|
121
93
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
.catch(catchProcError);
|
|
127
|
-
};
|
|
94
|
+
function asClientRpc(state, proc, extendedContext) {
|
|
95
|
+
return async (msg2) => {
|
|
96
|
+
return await proc.handler({ ...extendedContext, state }, msg2).catch(catchProcError);
|
|
97
|
+
};
|
|
128
98
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
99
|
+
function asClientStream(state, proc, init, extendedContext) {
|
|
100
|
+
const input = pushable({ objectMode: true });
|
|
101
|
+
const output = pushable({
|
|
102
|
+
objectMode: true
|
|
103
|
+
});
|
|
104
|
+
(async () => {
|
|
105
|
+
if (init) {
|
|
106
|
+
const _proc = proc;
|
|
107
|
+
await _proc.handler({ ...extendedContext, state }, init, input, output).catch((err) => output.push(catchProcError(err)));
|
|
108
|
+
} else {
|
|
109
|
+
const _proc = proc;
|
|
110
|
+
await _proc.handler({ ...extendedContext, state }, input, output).catch((err) => output.push(catchProcError(err)));
|
|
111
|
+
}
|
|
112
|
+
})();
|
|
113
|
+
return [input, output];
|
|
114
|
+
}
|
|
115
|
+
function asClientSubscription(state, proc, extendedContext) {
|
|
116
|
+
const output = pushable({
|
|
117
|
+
objectMode: true
|
|
118
|
+
});
|
|
119
|
+
return async (msg2) => {
|
|
134
120
|
(async () => {
|
|
135
|
-
|
|
136
|
-
const _proc = proc;
|
|
137
|
-
await _proc
|
|
138
|
-
.handler({ ...extendedContext, state }, init, input, output)
|
|
139
|
-
.catch((err) => output.push(catchProcError(err)));
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
const _proc = proc;
|
|
143
|
-
await _proc
|
|
144
|
-
.handler({ ...extendedContext, state }, input, output)
|
|
145
|
-
.catch((err) => output.push(catchProcError(err)));
|
|
146
|
-
}
|
|
121
|
+
return await proc.handler({ ...extendedContext, state }, msg2, output).catch((err) => output.push(catchProcError(err)));
|
|
147
122
|
})();
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
export function asClientSubscription(state, proc, extendedContext) {
|
|
151
|
-
const output = pushable({
|
|
152
|
-
objectMode: true,
|
|
153
|
-
});
|
|
154
|
-
return async (msg) => {
|
|
155
|
-
(async () => {
|
|
156
|
-
return await proc
|
|
157
|
-
.handler({ ...extendedContext, state }, msg, output)
|
|
158
|
-
.catch((err) => output.push(catchProcError(err)));
|
|
159
|
-
})();
|
|
160
|
-
return output;
|
|
161
|
-
};
|
|
123
|
+
return output;
|
|
124
|
+
};
|
|
162
125
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const result = _proc
|
|
175
|
-
.handler({ ...extendedContext, state }, input)
|
|
176
|
-
.catch(catchProcError);
|
|
177
|
-
return [input, result];
|
|
178
|
-
}
|
|
126
|
+
async function asClientUpload(state, proc, init, extendedContext) {
|
|
127
|
+
const input = pushable({ objectMode: true });
|
|
128
|
+
if (init) {
|
|
129
|
+
const _proc = proc;
|
|
130
|
+
const result = _proc.handler({ ...extendedContext, state }, init, input).catch(catchProcError);
|
|
131
|
+
return [input, result];
|
|
132
|
+
} else {
|
|
133
|
+
const _proc = proc;
|
|
134
|
+
const result = _proc.handler({ ...extendedContext, state }, input).catch(catchProcError);
|
|
135
|
+
return [input, result];
|
|
136
|
+
}
|
|
179
137
|
}
|
|
138
|
+
export {
|
|
139
|
+
asClientRpc,
|
|
140
|
+
asClientStream,
|
|
141
|
+
asClientSubscription,
|
|
142
|
+
asClientUpload,
|
|
143
|
+
createDummyTransportMessage,
|
|
144
|
+
createLocalWebSocketClient,
|
|
145
|
+
createWebSocketServer,
|
|
146
|
+
createWsTransports,
|
|
147
|
+
iterNext,
|
|
148
|
+
onServerReady,
|
|
149
|
+
payloadToTransportMessage,
|
|
150
|
+
waitForMessage
|
|
151
|
+
};
|
package/package.json
CHANGED
|
@@ -1,28 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@replit/river",
|
|
3
|
-
"sideEffects": false,
|
|
4
3
|
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
|
|
5
|
-
"version": "0.10.
|
|
4
|
+
"version": "0.10.1",
|
|
6
5
|
"type": "module",
|
|
7
6
|
"exports": {
|
|
8
|
-
".":
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"./
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/router/index.js",
|
|
9
|
+
"require": "./dist/router/index.cjs"
|
|
10
|
+
},
|
|
11
|
+
"./logging": {
|
|
12
|
+
"import": "./dist/logging/index.js",
|
|
13
|
+
"require": "./dist/logging/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./codec": {
|
|
16
|
+
"import": "./dist/codec/index.js",
|
|
17
|
+
"require": "./dist/codec/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./transport": {
|
|
20
|
+
"import": "./dist/transport/index.js",
|
|
21
|
+
"require": "./dist/transport/index.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./transport/ws/client": {
|
|
24
|
+
"import": "./dist/transport/impls/ws/client.js",
|
|
25
|
+
"require": "./dist/transport/impls/ws/client.cjs"
|
|
26
|
+
},
|
|
27
|
+
"./transport/ws/server": {
|
|
28
|
+
"import": "./dist/transport/impls/ws/server.js",
|
|
29
|
+
"require": "./dist/transport/impls/ws/server.cjs"
|
|
30
|
+
},
|
|
31
|
+
"./transport/stdio": {
|
|
32
|
+
"import": "./dist/transport/impls/stdio/stdio.js",
|
|
33
|
+
"require": "./dist/transport/impls/stdio/stdio.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./test-util": {
|
|
36
|
+
"import": "./dist/util/testHelpers.js",
|
|
37
|
+
"require": "./dist/util/testHelpers.cjs"
|
|
38
|
+
}
|
|
16
39
|
},
|
|
40
|
+
"sideEffects": [
|
|
41
|
+
"./dist/logging/index.js"
|
|
42
|
+
],
|
|
17
43
|
"files": [
|
|
18
44
|
"dist"
|
|
19
45
|
],
|
|
20
46
|
"dependencies": {
|
|
21
47
|
"@msgpack/msgpack": "^3.0.0-beta2",
|
|
22
|
-
"
|
|
48
|
+
"nanoid": "^4.0.2"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@sinclair/typebox": "^0.31.28",
|
|
23
52
|
"isomorphic-ws": "^5.0.0",
|
|
24
53
|
"it-pushable": "^3.2.1",
|
|
25
|
-
"nanoid": "^4.0.2",
|
|
26
54
|
"ws": "^8.13.0"
|
|
27
55
|
},
|
|
28
56
|
"devDependencies": {
|
|
@@ -36,7 +64,7 @@
|
|
|
36
64
|
"scripts": {
|
|
37
65
|
"check": "tsc --noEmit && npx prettier . --check",
|
|
38
66
|
"format": "npx prettier . --write",
|
|
39
|
-
"build": "
|
|
67
|
+
"build": "tsup && du -sh dist",
|
|
40
68
|
"prepack": "npm run build",
|
|
41
69
|
"release": "npm publish --access public",
|
|
42
70
|
"test:ui": "echo \"remember to go to /__vitest__ in the webview\" && vitest --ui --api.host 0.0.0.0 --api.port 3000",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bandwidth.bench.d.ts","sourceRoot":"","sources":["../../__tests__/bandwidth.bench.ts"],"names":[],"mappings":""}
|