@replit/river 0.10.13 → 0.12.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.
- package/README.md +28 -8
- package/dist/{builder-1f26296b.d.ts → builder-c593de11.d.ts} +14 -13
- package/dist/{chunk-3JGVFWKQ.js → chunk-24O3BKZA.js} +205 -180
- package/dist/chunk-4HOR4NUO.js +40 -0
- package/dist/chunk-ANGOKBE5.js +708 -0
- package/dist/{chunk-R6H2BIMC.js → chunk-GZ7HCLLM.js} +31 -7
- package/dist/{chunk-T7M7OKPE.js → chunk-H4BYJELI.js} +5 -1
- package/dist/chunk-IIBVKYDB.js +62 -0
- package/dist/chunk-IUDKWAOK.js +47 -0
- package/dist/chunk-WTOIOXB7.js +125 -0
- package/dist/chunk-XOTIAXAH.js +44 -0
- package/dist/codec/index.cjs +13 -7
- package/dist/codec/index.js +2 -4
- package/dist/connection-2956a1c5.d.ts +17 -0
- package/dist/connection-aaea7c88.d.ts +15 -0
- package/dist/connection-cd963ed5.d.ts +18 -0
- package/dist/index-d91775d9.d.ts +442 -0
- package/dist/logging/index.cjs +8 -3
- package/dist/logging/index.d.cts +6 -1
- package/dist/logging/index.d.ts +6 -1
- package/dist/logging/index.js +5 -3
- package/dist/messageFraming-b200ef25.d.ts +20 -0
- package/dist/router/index.cjs +249 -211
- package/dist/router/index.d.cts +6 -7
- package/dist/router/index.d.ts +6 -7
- package/dist/router/index.js +3 -3
- package/dist/transport/impls/stdio/client.cjs +891 -0
- package/dist/transport/impls/stdio/client.d.cts +27 -0
- package/dist/transport/impls/stdio/client.d.ts +27 -0
- package/dist/transport/impls/stdio/client.js +42 -0
- package/dist/transport/impls/stdio/server.cjs +861 -0
- package/dist/transport/impls/stdio/server.d.cts +25 -0
- package/dist/transport/impls/stdio/server.d.ts +25 -0
- package/dist/transport/impls/stdio/server.js +33 -0
- package/dist/transport/impls/uds/client.cjs +893 -0
- package/dist/transport/impls/uds/client.d.cts +16 -0
- package/dist/transport/impls/uds/client.d.ts +16 -0
- package/dist/transport/impls/uds/client.js +44 -0
- package/dist/transport/impls/uds/server.cjs +863 -0
- package/dist/transport/impls/uds/server.d.cts +16 -0
- package/dist/transport/impls/uds/server.d.ts +16 -0
- package/dist/transport/impls/uds/server.js +39 -0
- package/dist/transport/impls/ws/client.cjs +587 -248
- package/dist/transport/impls/ws/client.d.cts +6 -21
- package/dist/transport/impls/ws/client.d.ts +6 -21
- package/dist/transport/impls/ws/client.js +77 -7
- package/dist/transport/impls/ws/server.cjs +541 -194
- package/dist/transport/impls/ws/server.d.cts +6 -10
- package/dist/transport/impls/ws/server.d.ts +6 -10
- package/dist/transport/impls/ws/server.js +31 -8
- package/dist/transport/index.cjs +652 -129
- package/dist/transport/index.d.cts +3 -276
- package/dist/transport/index.d.ts +3 -276
- package/dist/transport/index.js +13 -10
- package/dist/util/testHelpers.cjs +40 -602
- package/dist/util/testHelpers.d.cts +18 -37
- package/dist/util/testHelpers.d.ts +18 -37
- package/dist/util/testHelpers.js +27 -47
- package/package.json +29 -14
- package/dist/chunk-3MQETIGZ.js +0 -80
- package/dist/chunk-5IC5XMWK.js +0 -140
- package/dist/chunk-L7D75G4K.js +0 -29
- package/dist/chunk-LQXPKF3A.js +0 -282
- package/dist/chunk-PJ2EUO7O.js +0 -63
- package/dist/chunk-WVT5QXMZ.js +0 -20
- package/dist/chunk-ZE4MX7DF.js +0 -75
- package/dist/connection-2529fc14.d.ts +0 -10
- package/dist/connection-316d6e3a.d.ts +0 -10
- package/dist/connection-8e19874c.d.ts +0 -11
- package/dist/connection-f7688cc1.d.ts +0 -11
- package/dist/transport/impls/stdio/stdio.cjs +0 -508
- package/dist/transport/impls/stdio/stdio.d.cts +0 -26
- package/dist/transport/impls/stdio/stdio.d.ts +0 -26
- package/dist/transport/impls/stdio/stdio.js +0 -70
- package/dist/transport/impls/unixsocket/client.cjs +0 -506
- package/dist/transport/impls/unixsocket/client.d.cts +0 -16
- package/dist/transport/impls/unixsocket/client.d.ts +0 -16
- package/dist/transport/impls/unixsocket/client.js +0 -67
- package/dist/transport/impls/unixsocket/server.cjs +0 -510
- package/dist/transport/impls/unixsocket/server.d.cts +0 -18
- package/dist/transport/impls/unixsocket/server.d.ts +0 -18
- package/dist/transport/impls/unixsocket/server.js +0 -73
- /package/dist/{chunk-ORAG7IAU.js → chunk-5IZ2UHWV.js} +0 -0
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import * as it_pushable from 'it-pushable';
|
|
2
2
|
import WebSocket from 'isomorphic-ws';
|
|
3
|
-
import { WebSocketServer } from 'ws';
|
|
4
3
|
import http from 'node:http';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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-1f26296b.js';
|
|
4
|
+
import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-d91775d9.js';
|
|
5
|
+
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-c593de11.js';
|
|
10
6
|
import { Static } from '@sinclair/typebox';
|
|
11
7
|
import net from 'node:net';
|
|
12
|
-
import '../
|
|
8
|
+
import '../types-3e5768ec.js';
|
|
13
9
|
|
|
14
10
|
/**
|
|
15
11
|
* Creates a WebSocket server instance using the provided HTTP server.
|
|
@@ -17,7 +13,7 @@ import '../connection-f7688cc1.js';
|
|
|
17
13
|
* @param server - The HTTP server instance to use for the WebSocket server.
|
|
18
14
|
* @returns A Promise that resolves to the created WebSocket server instance.
|
|
19
15
|
*/
|
|
20
|
-
declare function createWebSocketServer(server: http.Server):
|
|
16
|
+
declare function createWebSocketServer(server: http.Server): WebSocket.Server<typeof WebSocket, typeof http.IncomingMessage>;
|
|
21
17
|
/**
|
|
22
18
|
* Starts listening on the given server and returns the automatically allocated port number.
|
|
23
19
|
* This should only be used for testing.
|
|
@@ -26,40 +22,25 @@ declare function createWebSocketServer(server: http.Server): Promise<WebSocket.S
|
|
|
26
22
|
* @throws An error if a port cannot be allocated.
|
|
27
23
|
*/
|
|
28
24
|
declare function onWsServerReady(server: http.Server): Promise<number>;
|
|
29
|
-
declare function
|
|
25
|
+
declare function onUdsServeReady(server: net.Server, path: string): Promise<void>;
|
|
30
26
|
/**
|
|
31
27
|
* Creates a WebSocket client that connects to a local server at the specified port.
|
|
32
28
|
* This should only be used for testing.
|
|
33
29
|
* @param port - The port number to connect to.
|
|
34
30
|
* @returns A Promise that resolves to a WebSocket instance.
|
|
35
31
|
*/
|
|
36
|
-
declare function createLocalWebSocketClient(port: number):
|
|
37
|
-
/**
|
|
38
|
-
* Creates a pair of WebSocket transports for testing purposes.
|
|
39
|
-
* @param port - The port number to use for the client transport. This should be acquired after starting a server via {@link createWebSocketServer}.
|
|
40
|
-
* @param wss - The WebSocketServer instance to use for the server transport.
|
|
41
|
-
* @returns An array containing the client and server {@link WebSocketClientTransport} instances.
|
|
42
|
-
*/
|
|
43
|
-
declare function createWsTransports(port: number, wss: WebSocketServer, codec?: Codec): [WebSocketClientTransport, WebSocketServerTransport];
|
|
44
|
-
/**
|
|
45
|
-
* Converts a payload object to a transport message with reasonable defaults.
|
|
46
|
-
* This should only be used for testing.
|
|
47
|
-
* @param payload - The payload object to be converted.
|
|
48
|
-
* @param streamId - The optional stream ID.
|
|
49
|
-
* @returns The transport message.
|
|
50
|
-
*/
|
|
51
|
-
declare function payloadToTransportMessage<Payload extends object>(payload: Payload, streamId?: string, from?: TransportClientId, to?: TransportClientId): TransportMessage<Payload>;
|
|
52
|
-
/**
|
|
53
|
-
* Creates a dummy opaque transport message for testing purposes.
|
|
54
|
-
* @returns The created opaque transport message.
|
|
55
|
-
*/
|
|
56
|
-
declare function createDummyTransportMessage(): OpaqueTransportMessage;
|
|
32
|
+
declare function createLocalWebSocketClient(port: number): WebSocket;
|
|
57
33
|
/**
|
|
58
34
|
* Retrieves the next value from an async iterable iterator.
|
|
59
35
|
* @param iter The async iterable iterator.
|
|
60
36
|
* @returns A promise that resolves to the next value from the iterator.
|
|
61
37
|
*/
|
|
62
|
-
declare function iterNext<T>(iter: AsyncIterableIterator<T>): Promise<
|
|
38
|
+
declare function iterNext<T>(iter: AsyncIterableIterator<T>): Promise<T>;
|
|
39
|
+
declare function payloadToTransportMessage<Payload extends Record<string, unknown>>(payload: Payload): PartialTransportMessage<Payload>;
|
|
40
|
+
declare function createDummyTransportMessage(): PartialTransportMessage<{
|
|
41
|
+
msg: string;
|
|
42
|
+
test: number;
|
|
43
|
+
}>;
|
|
63
44
|
/**
|
|
64
45
|
* Waits for a message on the transport.
|
|
65
46
|
* @param {Transport} t - The transport to listen to.
|
|
@@ -67,16 +48,16 @@ declare function iterNext<T>(iter: AsyncIterableIterator<T>): Promise<any>;
|
|
|
67
48
|
* @returns A promise that resolves with the payload of the first message that passes the filter.
|
|
68
49
|
*/
|
|
69
50
|
declare function waitForMessage(t: Transport<Connection>, filter?: (msg: OpaqueTransportMessage) => boolean, rejectMismatch?: boolean): Promise<unknown>;
|
|
70
|
-
declare function asClientRpc<State extends object
|
|
71
|
-
declare function asClientStream<State extends object
|
|
72
|
-
declare function asClientSubscription<State extends object
|
|
73
|
-
declare function asClientUpload<State extends object
|
|
51
|
+
declare function asClientRpc<State extends object, 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>>>;
|
|
52
|
+
declare function asClientStream<State extends object, 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>];
|
|
53
|
+
declare function asClientSubscription<State extends object, 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>) => it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>;
|
|
54
|
+
declare function asClientUpload<State extends object, 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'>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, Promise<{
|
|
74
55
|
ok: boolean;
|
|
75
56
|
payload: {
|
|
76
57
|
code: string;
|
|
77
58
|
message: string;
|
|
78
59
|
};
|
|
79
|
-
} | Result<Static<O>, Static<E>>>]
|
|
60
|
+
} | Result<Static<O>, Static<E>>>];
|
|
80
61
|
declare const getUnixSocketPath: () => string;
|
|
81
62
|
|
|
82
|
-
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer,
|
|
63
|
+
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer, getUnixSocketPath, iterNext, onUdsServeReady, onWsServerReady, payloadToTransportMessage, waitForMessage };
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import * as it_pushable from 'it-pushable';
|
|
2
2
|
import WebSocket from 'isomorphic-ws';
|
|
3
|
-
import { WebSocketServer } from 'ws';
|
|
4
3
|
import http from 'node:http';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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-1f26296b.js';
|
|
4
|
+
import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-d91775d9.js';
|
|
5
|
+
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-c593de11.js';
|
|
10
6
|
import { Static } from '@sinclair/typebox';
|
|
11
7
|
import net from 'node:net';
|
|
12
|
-
import '../
|
|
8
|
+
import '../types-3e5768ec.js';
|
|
13
9
|
|
|
14
10
|
/**
|
|
15
11
|
* Creates a WebSocket server instance using the provided HTTP server.
|
|
@@ -17,7 +13,7 @@ import '../connection-8e19874c.js';
|
|
|
17
13
|
* @param server - The HTTP server instance to use for the WebSocket server.
|
|
18
14
|
* @returns A Promise that resolves to the created WebSocket server instance.
|
|
19
15
|
*/
|
|
20
|
-
declare function createWebSocketServer(server: http.Server):
|
|
16
|
+
declare function createWebSocketServer(server: http.Server): WebSocket.Server<typeof WebSocket, typeof http.IncomingMessage>;
|
|
21
17
|
/**
|
|
22
18
|
* Starts listening on the given server and returns the automatically allocated port number.
|
|
23
19
|
* This should only be used for testing.
|
|
@@ -26,40 +22,25 @@ declare function createWebSocketServer(server: http.Server): Promise<WebSocket.S
|
|
|
26
22
|
* @throws An error if a port cannot be allocated.
|
|
27
23
|
*/
|
|
28
24
|
declare function onWsServerReady(server: http.Server): Promise<number>;
|
|
29
|
-
declare function
|
|
25
|
+
declare function onUdsServeReady(server: net.Server, path: string): Promise<void>;
|
|
30
26
|
/**
|
|
31
27
|
* Creates a WebSocket client that connects to a local server at the specified port.
|
|
32
28
|
* This should only be used for testing.
|
|
33
29
|
* @param port - The port number to connect to.
|
|
34
30
|
* @returns A Promise that resolves to a WebSocket instance.
|
|
35
31
|
*/
|
|
36
|
-
declare function createLocalWebSocketClient(port: number):
|
|
37
|
-
/**
|
|
38
|
-
* Creates a pair of WebSocket transports for testing purposes.
|
|
39
|
-
* @param port - The port number to use for the client transport. This should be acquired after starting a server via {@link createWebSocketServer}.
|
|
40
|
-
* @param wss - The WebSocketServer instance to use for the server transport.
|
|
41
|
-
* @returns An array containing the client and server {@link WebSocketClientTransport} instances.
|
|
42
|
-
*/
|
|
43
|
-
declare function createWsTransports(port: number, wss: WebSocketServer, codec?: Codec): [WebSocketClientTransport, WebSocketServerTransport];
|
|
44
|
-
/**
|
|
45
|
-
* Converts a payload object to a transport message with reasonable defaults.
|
|
46
|
-
* This should only be used for testing.
|
|
47
|
-
* @param payload - The payload object to be converted.
|
|
48
|
-
* @param streamId - The optional stream ID.
|
|
49
|
-
* @returns The transport message.
|
|
50
|
-
*/
|
|
51
|
-
declare function payloadToTransportMessage<Payload extends object>(payload: Payload, streamId?: string, from?: TransportClientId, to?: TransportClientId): TransportMessage<Payload>;
|
|
52
|
-
/**
|
|
53
|
-
* Creates a dummy opaque transport message for testing purposes.
|
|
54
|
-
* @returns The created opaque transport message.
|
|
55
|
-
*/
|
|
56
|
-
declare function createDummyTransportMessage(): OpaqueTransportMessage;
|
|
32
|
+
declare function createLocalWebSocketClient(port: number): WebSocket;
|
|
57
33
|
/**
|
|
58
34
|
* Retrieves the next value from an async iterable iterator.
|
|
59
35
|
* @param iter The async iterable iterator.
|
|
60
36
|
* @returns A promise that resolves to the next value from the iterator.
|
|
61
37
|
*/
|
|
62
|
-
declare function iterNext<T>(iter: AsyncIterableIterator<T>): Promise<
|
|
38
|
+
declare function iterNext<T>(iter: AsyncIterableIterator<T>): Promise<T>;
|
|
39
|
+
declare function payloadToTransportMessage<Payload extends Record<string, unknown>>(payload: Payload): PartialTransportMessage<Payload>;
|
|
40
|
+
declare function createDummyTransportMessage(): PartialTransportMessage<{
|
|
41
|
+
msg: string;
|
|
42
|
+
test: number;
|
|
43
|
+
}>;
|
|
63
44
|
/**
|
|
64
45
|
* Waits for a message on the transport.
|
|
65
46
|
* @param {Transport} t - The transport to listen to.
|
|
@@ -67,16 +48,16 @@ declare function iterNext<T>(iter: AsyncIterableIterator<T>): Promise<any>;
|
|
|
67
48
|
* @returns A promise that resolves with the payload of the first message that passes the filter.
|
|
68
49
|
*/
|
|
69
50
|
declare function waitForMessage(t: Transport<Connection>, filter?: (msg: OpaqueTransportMessage) => boolean, rejectMismatch?: boolean): Promise<unknown>;
|
|
70
|
-
declare function asClientRpc<State extends object
|
|
71
|
-
declare function asClientStream<State extends object
|
|
72
|
-
declare function asClientSubscription<State extends object
|
|
73
|
-
declare function asClientUpload<State extends object
|
|
51
|
+
declare function asClientRpc<State extends object, 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>>>;
|
|
52
|
+
declare function asClientStream<State extends object, 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>];
|
|
53
|
+
declare function asClientSubscription<State extends object, 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>) => it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>;
|
|
54
|
+
declare function asClientUpload<State extends object, 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'>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, Promise<{
|
|
74
55
|
ok: boolean;
|
|
75
56
|
payload: {
|
|
76
57
|
code: string;
|
|
77
58
|
message: string;
|
|
78
59
|
};
|
|
79
|
-
} | Result<Static<O>, Static<E>>>]
|
|
60
|
+
} | Result<Static<O>, Static<E>>>];
|
|
80
61
|
declare const getUnixSocketPath: () => string;
|
|
81
62
|
|
|
82
|
-
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer,
|
|
63
|
+
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer, getUnixSocketPath, iterNext, onUdsServeReady, onWsServerReady, payloadToTransportMessage, waitForMessage };
|
package/dist/util/testHelpers.js
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UNCAUGHT_ERROR,
|
|
3
3
|
pushable
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-24O3BKZA.js";
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import
|
|
9
|
-
WebSocketServerTransport
|
|
10
|
-
} from "../chunk-PJ2EUO7O.js";
|
|
11
|
-
import "../chunk-L7D75G4K.js";
|
|
12
|
-
import "../chunk-ORAG7IAU.js";
|
|
13
|
-
import "../chunk-WVT5QXMZ.js";
|
|
14
|
-
import "../chunk-R6H2BIMC.js";
|
|
15
|
-
import "../chunk-LQXPKF3A.js";
|
|
16
|
-
import {
|
|
17
|
-
msg
|
|
18
|
-
} from "../chunk-ZE4MX7DF.js";
|
|
19
|
-
import "../chunk-T7M7OKPE.js";
|
|
6
|
+
coerceErrorString
|
|
7
|
+
} from "../chunk-WTOIOXB7.js";
|
|
8
|
+
import "../chunk-H4BYJELI.js";
|
|
20
9
|
|
|
21
10
|
// util/testHelpers.ts
|
|
22
11
|
import WebSocket from "isomorphic-ws";
|
|
23
12
|
import { WebSocketServer } from "ws";
|
|
24
13
|
import { nanoid } from "nanoid";
|
|
25
|
-
|
|
14
|
+
function createWebSocketServer(server) {
|
|
26
15
|
return new WebSocketServer({ server });
|
|
27
16
|
}
|
|
28
17
|
function onWsServerReady(server) {
|
|
@@ -37,30 +26,25 @@ function onWsServerReady(server) {
|
|
|
37
26
|
});
|
|
38
27
|
});
|
|
39
28
|
}
|
|
40
|
-
function
|
|
29
|
+
function onUdsServeReady(server, path) {
|
|
41
30
|
return new Promise((resolve) => {
|
|
42
31
|
server.listen(path, resolve);
|
|
43
32
|
});
|
|
44
33
|
}
|
|
45
|
-
|
|
34
|
+
function createLocalWebSocketClient(port) {
|
|
46
35
|
const sock = new WebSocket(`ws://localhost:${port}`);
|
|
47
36
|
sock.binaryType = "arraybuffer";
|
|
48
37
|
return sock;
|
|
49
38
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
return [
|
|
53
|
-
new WebSocketClientTransport(
|
|
54
|
-
() => createLocalWebSocketClient(port),
|
|
55
|
-
"client",
|
|
56
|
-
"SERVER",
|
|
57
|
-
options
|
|
58
|
-
),
|
|
59
|
-
new WebSocketServerTransport(wss, "SERVER", options)
|
|
60
|
-
];
|
|
39
|
+
async function iterNext(iter) {
|
|
40
|
+
return await iter.next().then((res) => res.value);
|
|
61
41
|
}
|
|
62
|
-
function payloadToTransportMessage(payload
|
|
63
|
-
return
|
|
42
|
+
function payloadToTransportMessage(payload) {
|
|
43
|
+
return {
|
|
44
|
+
streamId: "stream",
|
|
45
|
+
controlFlags: 0,
|
|
46
|
+
payload
|
|
47
|
+
};
|
|
64
48
|
}
|
|
65
49
|
function createDummyTransportMessage() {
|
|
66
50
|
return payloadToTransportMessage({
|
|
@@ -68,18 +52,15 @@ function createDummyTransportMessage() {
|
|
|
68
52
|
test: Math.random()
|
|
69
53
|
});
|
|
70
54
|
}
|
|
71
|
-
async function iterNext(iter) {
|
|
72
|
-
return await iter.next().then((res) => res.value);
|
|
73
|
-
}
|
|
74
55
|
async function waitForMessage(t, filter, rejectMismatch) {
|
|
75
56
|
return new Promise((resolve, reject) => {
|
|
76
57
|
function cleanup() {
|
|
77
58
|
t.removeEventListener("message", onMessage);
|
|
78
59
|
}
|
|
79
|
-
function onMessage(
|
|
80
|
-
if (!filter || filter
|
|
60
|
+
function onMessage(msg) {
|
|
61
|
+
if (!filter || filter(msg)) {
|
|
81
62
|
cleanup();
|
|
82
|
-
resolve(
|
|
63
|
+
resolve(msg.payload);
|
|
83
64
|
} else if (rejectMismatch) {
|
|
84
65
|
reject(new Error("message didnt match the filter"));
|
|
85
66
|
}
|
|
@@ -88,7 +69,7 @@ async function waitForMessage(t, filter, rejectMismatch) {
|
|
|
88
69
|
});
|
|
89
70
|
}
|
|
90
71
|
function catchProcError(err) {
|
|
91
|
-
const errorMsg = err
|
|
72
|
+
const errorMsg = coerceErrorString(err);
|
|
92
73
|
return {
|
|
93
74
|
ok: false,
|
|
94
75
|
payload: {
|
|
@@ -98,8 +79,8 @@ function catchProcError(err) {
|
|
|
98
79
|
};
|
|
99
80
|
}
|
|
100
81
|
function asClientRpc(state, proc, extendedContext) {
|
|
101
|
-
return async (
|
|
102
|
-
return await proc.handler({ ...extendedContext, state },
|
|
82
|
+
return async (msg) => {
|
|
83
|
+
return await proc.handler({ ...extendedContext, state }, msg).catch(catchProcError);
|
|
103
84
|
};
|
|
104
85
|
}
|
|
105
86
|
function asClientStream(state, proc, init, extendedContext) {
|
|
@@ -107,7 +88,7 @@ function asClientStream(state, proc, init, extendedContext) {
|
|
|
107
88
|
const output = pushable({
|
|
108
89
|
objectMode: true
|
|
109
90
|
});
|
|
110
|
-
(async () => {
|
|
91
|
+
void (async () => {
|
|
111
92
|
if (init) {
|
|
112
93
|
const _proc = proc;
|
|
113
94
|
await _proc.handler({ ...extendedContext, state }, init, input, output).catch((err) => output.push(catchProcError(err)));
|
|
@@ -122,14 +103,14 @@ function asClientSubscription(state, proc, extendedContext) {
|
|
|
122
103
|
const output = pushable({
|
|
123
104
|
objectMode: true
|
|
124
105
|
});
|
|
125
|
-
return
|
|
126
|
-
(async () => {
|
|
127
|
-
return await proc.handler({ ...extendedContext, state },
|
|
106
|
+
return (msg) => {
|
|
107
|
+
void (async () => {
|
|
108
|
+
return await proc.handler({ ...extendedContext, state }, msg, output).catch((err) => output.push(catchProcError(err)));
|
|
128
109
|
})();
|
|
129
110
|
return output;
|
|
130
111
|
};
|
|
131
112
|
}
|
|
132
|
-
|
|
113
|
+
function asClientUpload(state, proc, init, extendedContext) {
|
|
133
114
|
const input = pushable({ objectMode: true });
|
|
134
115
|
if (init) {
|
|
135
116
|
const _proc = proc;
|
|
@@ -152,10 +133,9 @@ export {
|
|
|
152
133
|
createDummyTransportMessage,
|
|
153
134
|
createLocalWebSocketClient,
|
|
154
135
|
createWebSocketServer,
|
|
155
|
-
createWsTransports,
|
|
156
136
|
getUnixSocketPath,
|
|
157
137
|
iterNext,
|
|
158
|
-
|
|
138
|
+
onUdsServeReady,
|
|
159
139
|
onWsServerReady,
|
|
160
140
|
payloadToTransportMessage,
|
|
161
141
|
waitForMessage
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@replit/river",
|
|
3
3
|
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -28,17 +28,21 @@
|
|
|
28
28
|
"import": "./dist/transport/impls/ws/server.js",
|
|
29
29
|
"require": "./dist/transport/impls/ws/server.cjs"
|
|
30
30
|
},
|
|
31
|
-
"./transport/
|
|
32
|
-
"import": "./dist/transport/impls/
|
|
33
|
-
"require": "./dist/transport/impls/
|
|
31
|
+
"./transport/uds/client": {
|
|
32
|
+
"import": "./dist/transport/impls/uds/client.js",
|
|
33
|
+
"require": "./dist/transport/impls/uds/client.cjs"
|
|
34
34
|
},
|
|
35
|
-
"./transport/
|
|
36
|
-
"import": "./dist/transport/impls/
|
|
37
|
-
"require": "./dist/transport/impls/
|
|
35
|
+
"./transport/uds/server": {
|
|
36
|
+
"import": "./dist/transport/impls/uds/server.js",
|
|
37
|
+
"require": "./dist/transport/impls/uds/server.cjs"
|
|
38
38
|
},
|
|
39
|
-
"./transport/stdio": {
|
|
40
|
-
"import": "./dist/transport/impls/stdio/
|
|
41
|
-
"require": "./dist/transport/impls/stdio/
|
|
39
|
+
"./transport/stdio/client": {
|
|
40
|
+
"import": "./dist/transport/impls/stdio/client.js",
|
|
41
|
+
"require": "./dist/transport/impls/stdio/client.cjs"
|
|
42
|
+
},
|
|
43
|
+
"./transport/stdio/server": {
|
|
44
|
+
"import": "./dist/transport/impls/stdio/server.js",
|
|
45
|
+
"require": "./dist/transport/impls/stdio/server.cjs"
|
|
42
46
|
},
|
|
43
47
|
"./test-util": {
|
|
44
48
|
"import": "./dist/util/testHelpers.js",
|
|
@@ -63,20 +67,31 @@
|
|
|
63
67
|
},
|
|
64
68
|
"devDependencies": {
|
|
65
69
|
"@types/ws": "^8.5.5",
|
|
66
|
-
"@
|
|
70
|
+
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
|
71
|
+
"@typescript-eslint/parser": "^7.1.0",
|
|
72
|
+
"@vitest/ui": "^1.3.1",
|
|
73
|
+
"eslint": "^8.57.0",
|
|
74
|
+
"eslint-config-prettier": "^9.1.0",
|
|
75
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
67
76
|
"prettier": "^3.0.0",
|
|
68
77
|
"tsup": "^7.2.0",
|
|
69
78
|
"typescript": "^5.2.2",
|
|
70
|
-
"vitest": "^1.
|
|
79
|
+
"vitest": "^1.3.1"
|
|
71
80
|
},
|
|
72
81
|
"scripts": {
|
|
73
|
-
"check": "tsc --noEmit &&
|
|
74
|
-
"format": "npx prettier . --
|
|
82
|
+
"check": "tsc --noEmit && npm run format && npm run lint",
|
|
83
|
+
"format": "npx prettier . --check",
|
|
84
|
+
"format:fix": "npx prettier . --write",
|
|
85
|
+
"lint": "eslint .",
|
|
86
|
+
"lint:fix": "eslint . --fix",
|
|
87
|
+
"fix": "npm run format:fix && npm run lint:fix",
|
|
75
88
|
"build": "rm -rf dist && tsup && du -sh dist",
|
|
76
89
|
"prepack": "npm run build",
|
|
77
90
|
"release": "npm publish --access public",
|
|
78
91
|
"test:ui": "echo \"remember to go to /__vitest__ in the webview\" && vitest --ui --api.host 0.0.0.0 --api.port 3000",
|
|
79
92
|
"test": "vitest --test-timeout=500",
|
|
93
|
+
"test:single": "vitest run --test-timeout=500",
|
|
94
|
+
"test:flake": "./flake.sh",
|
|
80
95
|
"bench": "vitest bench"
|
|
81
96
|
},
|
|
82
97
|
"engines": {
|
package/dist/chunk-3MQETIGZ.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Connection
|
|
3
|
-
} from "./chunk-LQXPKF3A.js";
|
|
4
|
-
|
|
5
|
-
// transport/transforms/delim.ts
|
|
6
|
-
import { Transform } from "node:stream";
|
|
7
|
-
var DelimiterParser = class extends Transform {
|
|
8
|
-
delimiter;
|
|
9
|
-
buffer;
|
|
10
|
-
maxBufferSizeBytes;
|
|
11
|
-
constructor({ delimiter, maxBufferSizeBytes, ...options }) {
|
|
12
|
-
super(options);
|
|
13
|
-
this.maxBufferSizeBytes = maxBufferSizeBytes;
|
|
14
|
-
this.delimiter = Buffer.from(delimiter);
|
|
15
|
-
this.buffer = Buffer.alloc(0);
|
|
16
|
-
}
|
|
17
|
-
// tldr; backpressure will be automatically applied for transform streams
|
|
18
|
-
// but it relies on both the input/output streams connected on either end having
|
|
19
|
-
// implemented backpressure properly
|
|
20
|
-
// see: https://nodejs.org/en/guides/backpressuring-in-streams#lifecycle-of-pipe
|
|
21
|
-
_transform(chunk, _encoding, cb) {
|
|
22
|
-
let data = Buffer.concat([this.buffer, chunk]);
|
|
23
|
-
let position;
|
|
24
|
-
while ((position = data.indexOf(this.delimiter)) !== -1) {
|
|
25
|
-
this.push(data.subarray(0, position));
|
|
26
|
-
data = data.subarray(position + this.delimiter.length);
|
|
27
|
-
}
|
|
28
|
-
if (data.byteLength > this.maxBufferSizeBytes) {
|
|
29
|
-
const err = new Error(
|
|
30
|
-
`buffer overflow: ${data.byteLength}B > ${this.maxBufferSizeBytes}B`
|
|
31
|
-
);
|
|
32
|
-
this.emit("error", err);
|
|
33
|
-
return cb(err);
|
|
34
|
-
}
|
|
35
|
-
this.buffer = data;
|
|
36
|
-
cb();
|
|
37
|
-
}
|
|
38
|
-
_flush(cb) {
|
|
39
|
-
if (this.buffer.length) {
|
|
40
|
-
this.push(this.buffer);
|
|
41
|
-
}
|
|
42
|
-
this.buffer = Buffer.alloc(0);
|
|
43
|
-
cb();
|
|
44
|
-
}
|
|
45
|
-
_destroy(error, callback) {
|
|
46
|
-
this.buffer = Buffer.alloc(0);
|
|
47
|
-
super._destroy(error, callback);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
var defaultDelimiter = Buffer.from("\n");
|
|
51
|
-
function createDelimitedStream(options) {
|
|
52
|
-
return new DelimiterParser({
|
|
53
|
-
delimiter: options?.delimiter ?? defaultDelimiter,
|
|
54
|
-
maxBufferSizeBytes: options?.maxBufferSizeBytes ?? 16 * 1024 * 1024
|
|
55
|
-
// 16MB
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// transport/impls/stdio/connection.ts
|
|
60
|
-
var StreamConnection = class extends Connection {
|
|
61
|
-
output;
|
|
62
|
-
constructor(transport, connectedTo, output) {
|
|
63
|
-
super(transport, connectedTo);
|
|
64
|
-
this.output = output;
|
|
65
|
-
}
|
|
66
|
-
send(payload) {
|
|
67
|
-
if (!this.output.writable) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
return this.output.write(Buffer.concat([payload, defaultDelimiter]));
|
|
71
|
-
}
|
|
72
|
-
async close() {
|
|
73
|
-
this.output.end();
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export {
|
|
78
|
-
createDelimitedStream,
|
|
79
|
-
StreamConnection
|
|
80
|
-
};
|
package/dist/chunk-5IC5XMWK.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WebSocketConnection
|
|
3
|
-
} from "./chunk-L7D75G4K.js";
|
|
4
|
-
import {
|
|
5
|
-
NaiveJsonCodec
|
|
6
|
-
} from "./chunk-R6H2BIMC.js";
|
|
7
|
-
import {
|
|
8
|
-
Transport
|
|
9
|
-
} from "./chunk-LQXPKF3A.js";
|
|
10
|
-
import {
|
|
11
|
-
log
|
|
12
|
-
} from "./chunk-T7M7OKPE.js";
|
|
13
|
-
|
|
14
|
-
// transport/impls/ws/client.ts
|
|
15
|
-
var defaultOptions = {
|
|
16
|
-
retryIntervalMs: 250,
|
|
17
|
-
retryAttemptsMax: 5,
|
|
18
|
-
codec: NaiveJsonCodec
|
|
19
|
-
};
|
|
20
|
-
var WebSocketClientTransport = class extends Transport {
|
|
21
|
-
/**
|
|
22
|
-
* A function that returns a Promise that resolves to a WebSocket instance.
|
|
23
|
-
*/
|
|
24
|
-
wsGetter;
|
|
25
|
-
options;
|
|
26
|
-
serverId;
|
|
27
|
-
reconnectPromises;
|
|
28
|
-
tryReconnecting = true;
|
|
29
|
-
/**
|
|
30
|
-
* Creates a new WebSocketClientTransport instance.
|
|
31
|
-
* @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.
|
|
32
|
-
* @param sessionId The ID of the client using the transport. This should be unique per session.
|
|
33
|
-
* @param serverId The ID of the server this transport is connecting to.
|
|
34
|
-
* @param providedOptions An optional object containing configuration options for the transport.
|
|
35
|
-
*/
|
|
36
|
-
constructor(wsGetter, sessionId, serverId, providedOptions) {
|
|
37
|
-
const options = { ...defaultOptions, ...providedOptions };
|
|
38
|
-
super(options.codec, sessionId);
|
|
39
|
-
this.wsGetter = wsGetter;
|
|
40
|
-
this.serverId = serverId;
|
|
41
|
-
this.options = options;
|
|
42
|
-
this.reconnectPromises = /* @__PURE__ */ new Map();
|
|
43
|
-
this.createNewConnection(this.serverId);
|
|
44
|
-
}
|
|
45
|
-
reopen() {
|
|
46
|
-
if (this.state === "destroyed") {
|
|
47
|
-
throw new Error("cant reopen a destroyed connection");
|
|
48
|
-
}
|
|
49
|
-
this.state = "open";
|
|
50
|
-
this.createNewConnection(this.serverId);
|
|
51
|
-
}
|
|
52
|
-
async createNewConnection(to, attempt = 0) {
|
|
53
|
-
if (this.state === "destroyed") {
|
|
54
|
-
throw new Error("cant reopen a destroyed connection");
|
|
55
|
-
}
|
|
56
|
-
let reconnectPromise = this.reconnectPromises.get(to);
|
|
57
|
-
if (!reconnectPromise) {
|
|
58
|
-
if (!this.tryReconnecting) {
|
|
59
|
-
log?.info(
|
|
60
|
-
`${this.clientId} -- tryReconnecting is false, not attempting reconnect`
|
|
61
|
-
);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
reconnectPromise = new Promise(async (resolve) => {
|
|
65
|
-
log?.info(`${this.clientId} -- establishing a new websocket to ${to}`);
|
|
66
|
-
try {
|
|
67
|
-
const ws = await this.wsGetter(to);
|
|
68
|
-
if (ws.readyState === ws.OPEN) {
|
|
69
|
-
return resolve({ ws });
|
|
70
|
-
}
|
|
71
|
-
if (ws.readyState === ws.CLOSING || ws.readyState === ws.CLOSED) {
|
|
72
|
-
return resolve({ err: "ws is closing or closed" });
|
|
73
|
-
}
|
|
74
|
-
const onOpen = () => {
|
|
75
|
-
ws.removeEventListener("open", onOpen);
|
|
76
|
-
resolve({ ws });
|
|
77
|
-
};
|
|
78
|
-
const onClose = (evt) => {
|
|
79
|
-
ws.removeEventListener("close", onClose);
|
|
80
|
-
resolve({ err: evt.reason });
|
|
81
|
-
};
|
|
82
|
-
ws.addEventListener("open", onOpen);
|
|
83
|
-
ws.addEventListener("close", onClose);
|
|
84
|
-
} catch (e) {
|
|
85
|
-
const reason = e instanceof Error ? e.message : "unknown reason";
|
|
86
|
-
return resolve({ err: `couldn't get a new websocket: ${reason}` });
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
this.reconnectPromises.set(to, reconnectPromise);
|
|
90
|
-
}
|
|
91
|
-
const res = await reconnectPromise;
|
|
92
|
-
if (this.state !== "open") {
|
|
93
|
-
this.reconnectPromises.delete(to);
|
|
94
|
-
if ("ws" in res) {
|
|
95
|
-
res.ws.close();
|
|
96
|
-
}
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
if ("ws" in res && res.ws.readyState === res.ws.OPEN) {
|
|
100
|
-
if (res.ws === this.connections.get(to)?.ws) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
log?.info(`${this.clientId} -- websocket ok`);
|
|
104
|
-
const conn = new WebSocketConnection(this, to, res.ws);
|
|
105
|
-
this.onConnect(conn);
|
|
106
|
-
res.ws.onclose = () => {
|
|
107
|
-
this.reconnectPromises.delete(to);
|
|
108
|
-
this.onDisconnect(conn);
|
|
109
|
-
};
|
|
110
|
-
this.state = "open";
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
this.reconnectPromises.delete(to);
|
|
114
|
-
if (attempt >= this.options.retryAttemptsMax) {
|
|
115
|
-
throw new Error(
|
|
116
|
-
`${this.clientId} -- websocket to ${to} failed after ${attempt} attempts, giving up`
|
|
117
|
-
);
|
|
118
|
-
} else {
|
|
119
|
-
log?.warn(
|
|
120
|
-
`${this.clientId} -- websocket to ${to} failed, trying again in ${this.options.retryIntervalMs * attempt}ms`
|
|
121
|
-
);
|
|
122
|
-
setTimeout(
|
|
123
|
-
() => this.createNewConnection(to, attempt + 1),
|
|
124
|
-
this.options.retryIntervalMs * attempt
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
async close() {
|
|
129
|
-
super.close();
|
|
130
|
-
this.reconnectPromises.clear();
|
|
131
|
-
}
|
|
132
|
-
async destroy() {
|
|
133
|
-
super.destroy();
|
|
134
|
-
this.reconnectPromises.clear();
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export {
|
|
139
|
-
WebSocketClientTransport
|
|
140
|
-
};
|