@replit/river 0.10.4 → 0.10.6
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 +121 -6
- package/dist/{chunk-UU2Z7LDR.js → chunk-5735JCTZ.js} +2 -5
- package/dist/{chunk-PC65ZFWJ.js → chunk-KRYKORQT.js} +1 -1
- package/dist/{chunk-RGMHF6PF.js → chunk-LRQGTUTI.js} +6 -8
- package/dist/{chunk-AJQU4AZG.js → chunk-MF3Z3IDF.js} +1 -3
- package/dist/{chunk-FWPZDOFL.js → chunk-SCULZ4KS.js} +18 -0
- package/dist/chunk-XWRKNZSC.js +80 -0
- package/dist/connection-2529fc14.d.ts +10 -0
- package/dist/connection-316d6e3a.d.ts +10 -0
- package/dist/router/index.cjs +18 -0
- package/dist/router/index.js +1 -1
- package/dist/transport/impls/stdio/stdio.cjs +78 -38
- package/dist/transport/impls/stdio/stdio.d.cts +4 -11
- package/dist/transport/impls/stdio/stdio.d.ts +4 -11
- package/dist/transport/impls/stdio/stdio.js +21 -36
- package/dist/transport/impls/unixsocket/client.cjs +506 -0
- package/dist/transport/impls/unixsocket/client.d.cts +16 -0
- package/dist/transport/impls/unixsocket/client.d.ts +16 -0
- package/dist/transport/impls/unixsocket/client.js +67 -0
- package/dist/transport/impls/unixsocket/server.cjs +510 -0
- package/dist/transport/impls/unixsocket/server.d.cts +18 -0
- package/dist/transport/impls/unixsocket/server.d.ts +18 -0
- package/dist/transport/impls/unixsocket/server.js +73 -0
- package/dist/transport/impls/ws/client.cjs +1 -6
- package/dist/transport/impls/ws/client.d.cts +0 -1
- package/dist/transport/impls/ws/client.d.ts +0 -1
- package/dist/transport/impls/ws/client.js +3 -3
- package/dist/transport/impls/ws/server.cjs +5 -9
- package/dist/transport/impls/ws/server.d.cts +0 -2
- package/dist/transport/impls/ws/server.d.ts +0 -2
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/index.cjs +1 -3
- package/dist/transport/index.d.cts +6 -7
- package/dist/transport/index.d.ts +6 -7
- package/dist/transport/index.js +1 -1
- package/dist/util/testHelpers.cjs +24 -15
- package/dist/util/testHelpers.d.cts +6 -3
- package/dist/util/testHelpers.d.ts +6 -3
- package/dist/util/testHelpers.js +19 -8
- package/package.json +23 -14
|
@@ -138,6 +138,7 @@ var Transport = class {
|
|
|
138
138
|
eventDispatcher;
|
|
139
139
|
/**
|
|
140
140
|
* Creates a new Transport instance.
|
|
141
|
+
* This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
|
|
141
142
|
* @param codec The codec used to encode and decode messages.
|
|
142
143
|
* @param clientId The client ID of this transport.
|
|
143
144
|
*/
|
|
@@ -240,9 +241,6 @@ var Transport = class {
|
|
|
240
241
|
}
|
|
241
242
|
} else {
|
|
242
243
|
log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
|
|
243
|
-
if (msg.to !== this.clientId) {
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
244
|
this.eventDispatcher.dispatchEvent("message", msg);
|
|
247
245
|
if (!isAck(msg.controlFlags)) {
|
|
248
246
|
const ackMsg = reply(msg, { ack: msg.id });
|
|
@@ -431,9 +429,6 @@ var WebSocketClientTransport = class extends Transport {
|
|
|
431
429
|
this.serverId = serverId;
|
|
432
430
|
this.options = options;
|
|
433
431
|
this.reconnectPromises = /* @__PURE__ */ new Map();
|
|
434
|
-
this.setupConnectionStatusListeners();
|
|
435
|
-
}
|
|
436
|
-
setupConnectionStatusListeners() {
|
|
437
432
|
this.createNewConnection(this.serverId);
|
|
438
433
|
}
|
|
439
434
|
async createNewConnection(to, attempt = 0) {
|
|
@@ -35,7 +35,6 @@ declare class WebSocketClientTransport extends Transport<WebSocketConnection> {
|
|
|
35
35
|
* @param providedOptions An optional object containing configuration options for the transport.
|
|
36
36
|
*/
|
|
37
37
|
constructor(wsGetter: () => Promise<WebSocket>, clientId: TransportClientId, serverId: TransportClientId, providedOptions?: Partial<Options>);
|
|
38
|
-
setupConnectionStatusListeners(): void;
|
|
39
38
|
createNewConnection(to: string, attempt?: number): Promise<void>;
|
|
40
39
|
}
|
|
41
40
|
|
|
@@ -35,7 +35,6 @@ declare class WebSocketClientTransport extends Transport<WebSocketConnection> {
|
|
|
35
35
|
* @param providedOptions An optional object containing configuration options for the transport.
|
|
36
36
|
*/
|
|
37
37
|
constructor(wsGetter: () => Promise<WebSocket>, clientId: TransportClientId, serverId: TransportClientId, providedOptions?: Partial<Options>);
|
|
38
|
-
setupConnectionStatusListeners(): void;
|
|
39
38
|
createNewConnection(to: string, attempt?: number): Promise<void>;
|
|
40
39
|
}
|
|
41
40
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WebSocketClientTransport
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import "../../../chunk-
|
|
3
|
+
} from "../../../chunk-5735JCTZ.js";
|
|
4
|
+
import "../../../chunk-KRYKORQT.js";
|
|
5
5
|
import "../../../chunk-R6H2BIMC.js";
|
|
6
|
-
import "../../../chunk-
|
|
6
|
+
import "../../../chunk-MF3Z3IDF.js";
|
|
7
7
|
import "../../../chunk-ZE4MX7DF.js";
|
|
8
8
|
import "../../../chunk-SLUSVGQH.js";
|
|
9
9
|
export {
|
|
@@ -184,6 +184,7 @@ var Transport = class {
|
|
|
184
184
|
eventDispatcher;
|
|
185
185
|
/**
|
|
186
186
|
* Creates a new Transport instance.
|
|
187
|
+
* This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
|
|
187
188
|
* @param codec The codec used to encode and decode messages.
|
|
188
189
|
* @param clientId The client ID of this transport.
|
|
189
190
|
*/
|
|
@@ -286,9 +287,6 @@ var Transport = class {
|
|
|
286
287
|
}
|
|
287
288
|
} else {
|
|
288
289
|
log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
|
|
289
|
-
if (msg.to !== this.clientId) {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
290
|
this.eventDispatcher.dispatchEvent("message", msg);
|
|
293
291
|
if (!isAck(msg.controlFlags)) {
|
|
294
292
|
const ackMsg = reply(msg, { ack: msg.id });
|
|
@@ -409,13 +407,14 @@ var defaultOptions = {
|
|
|
409
407
|
};
|
|
410
408
|
var WebSocketServerTransport = class extends Transport {
|
|
411
409
|
wss;
|
|
412
|
-
clientId;
|
|
413
410
|
constructor(wss, clientId, providedOptions) {
|
|
414
411
|
const options = { ...defaultOptions, ...providedOptions };
|
|
415
412
|
super(options.codec, clientId);
|
|
416
413
|
this.wss = wss;
|
|
417
|
-
|
|
418
|
-
|
|
414
|
+
wss.on("listening", () => {
|
|
415
|
+
log?.info(`${this.clientId} -- server is listening`);
|
|
416
|
+
});
|
|
417
|
+
this.wss.on("connection", this.connectionHandler);
|
|
419
418
|
}
|
|
420
419
|
connectionHandler = (ws) => {
|
|
421
420
|
let conn = void 0;
|
|
@@ -438,9 +437,6 @@ var WebSocketServerTransport = class extends Transport {
|
|
|
438
437
|
);
|
|
439
438
|
};
|
|
440
439
|
};
|
|
441
|
-
setupConnectionStatusListeners() {
|
|
442
|
-
this.wss.on("connection", this.connectionHandler);
|
|
443
|
-
}
|
|
444
440
|
async createNewConnection(to) {
|
|
445
441
|
const err = `${this.clientId} -- failed to send msg to ${to}, client probably dropped`;
|
|
446
442
|
log?.warn(err);
|
|
@@ -10,10 +10,8 @@ interface Options {
|
|
|
10
10
|
}
|
|
11
11
|
declare class WebSocketServerTransport extends Transport<WebSocketConnection> {
|
|
12
12
|
wss: WebSocketServer;
|
|
13
|
-
clientId: TransportClientId;
|
|
14
13
|
constructor(wss: WebSocketServer, clientId: TransportClientId, providedOptions?: Partial<Options>);
|
|
15
14
|
connectionHandler: (ws: WebSocket) => void;
|
|
16
|
-
setupConnectionStatusListeners(): void;
|
|
17
15
|
createNewConnection(to: string): Promise<void>;
|
|
18
16
|
close(): Promise<void>;
|
|
19
17
|
}
|
|
@@ -10,10 +10,8 @@ interface Options {
|
|
|
10
10
|
}
|
|
11
11
|
declare class WebSocketServerTransport extends Transport<WebSocketConnection> {
|
|
12
12
|
wss: WebSocketServer;
|
|
13
|
-
clientId: TransportClientId;
|
|
14
13
|
constructor(wss: WebSocketServer, clientId: TransportClientId, providedOptions?: Partial<Options>);
|
|
15
14
|
connectionHandler: (ws: WebSocket) => void;
|
|
16
|
-
setupConnectionStatusListeners(): void;
|
|
17
15
|
createNewConnection(to: string): Promise<void>;
|
|
18
16
|
close(): Promise<void>;
|
|
19
17
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WebSocketServerTransport
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-LRQGTUTI.js";
|
|
4
|
+
import "../../../chunk-KRYKORQT.js";
|
|
4
5
|
import "../../../chunk-WVT5QXMZ.js";
|
|
5
|
-
import "../../../chunk-PC65ZFWJ.js";
|
|
6
6
|
import "../../../chunk-R6H2BIMC.js";
|
|
7
|
-
import "../../../chunk-
|
|
7
|
+
import "../../../chunk-MF3Z3IDF.js";
|
|
8
8
|
import "../../../chunk-ZE4MX7DF.js";
|
|
9
9
|
import "../../../chunk-SLUSVGQH.js";
|
|
10
10
|
export {
|
package/dist/transport/index.cjs
CHANGED
|
@@ -155,6 +155,7 @@ var Transport = class {
|
|
|
155
155
|
eventDispatcher;
|
|
156
156
|
/**
|
|
157
157
|
* Creates a new Transport instance.
|
|
158
|
+
* This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
|
|
158
159
|
* @param codec The codec used to encode and decode messages.
|
|
159
160
|
* @param clientId The client ID of this transport.
|
|
160
161
|
*/
|
|
@@ -257,9 +258,6 @@ var Transport = class {
|
|
|
257
258
|
}
|
|
258
259
|
} else {
|
|
259
260
|
log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg2)}`);
|
|
260
|
-
if (msg2.to !== this.clientId) {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
261
|
this.eventDispatcher.dispatchEvent("message", msg2);
|
|
264
262
|
if (!isAck(msg2.controlFlags)) {
|
|
265
263
|
const ackMsg = reply(msg2, { ack: msg2.id });
|
|
@@ -194,18 +194,17 @@ declare abstract class Transport<ConnType extends Connection> {
|
|
|
194
194
|
eventDispatcher: EventDispatcher<EventTypes>;
|
|
195
195
|
/**
|
|
196
196
|
* Creates a new Transport instance.
|
|
197
|
+
* This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
|
|
197
198
|
* @param codec The codec used to encode and decode messages.
|
|
198
199
|
* @param clientId The client ID of this transport.
|
|
199
200
|
*/
|
|
200
201
|
constructor(codec: Codec, clientId: TransportClientId);
|
|
201
202
|
/**
|
|
202
|
-
* Abstract method that
|
|
203
|
-
*
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
* Abstract method that creates a new {@link Connection} object. This should call
|
|
208
|
-
* {@link onConnect} when the connection is established. The downstream implementation needs to implement this.
|
|
203
|
+
* Abstract method that creates a new {@link Connection} object.
|
|
204
|
+
* This should call {@link onConnect} when the connection is established.
|
|
205
|
+
* The downstream implementation needs to implement this. If the downstream
|
|
206
|
+
* transport cannot make new outgoing connections (e.g. a server transport),
|
|
207
|
+
* it is ok to log an error and return.
|
|
209
208
|
* @param to The client ID of the node to connect to.
|
|
210
209
|
* @returns The new connection object.
|
|
211
210
|
*/
|
|
@@ -194,18 +194,17 @@ declare abstract class Transport<ConnType extends Connection> {
|
|
|
194
194
|
eventDispatcher: EventDispatcher<EventTypes>;
|
|
195
195
|
/**
|
|
196
196
|
* Creates a new Transport instance.
|
|
197
|
+
* This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
|
|
197
198
|
* @param codec The codec used to encode and decode messages.
|
|
198
199
|
* @param clientId The client ID of this transport.
|
|
199
200
|
*/
|
|
200
201
|
constructor(codec: Codec, clientId: TransportClientId);
|
|
201
202
|
/**
|
|
202
|
-
* Abstract method that
|
|
203
|
-
*
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
* Abstract method that creates a new {@link Connection} object. This should call
|
|
208
|
-
* {@link onConnect} when the connection is established. The downstream implementation needs to implement this.
|
|
203
|
+
* Abstract method that creates a new {@link Connection} object.
|
|
204
|
+
* This should call {@link onConnect} when the connection is established.
|
|
205
|
+
* The downstream implementation needs to implement this. If the downstream
|
|
206
|
+
* transport cannot make new outgoing connections (e.g. a server transport),
|
|
207
|
+
* it is ok to log an error and return.
|
|
209
208
|
* @param to The client ID of the node to connect to.
|
|
210
209
|
* @returns The new connection object.
|
|
211
210
|
*/
|
package/dist/transport/index.js
CHANGED
|
@@ -38,8 +38,10 @@ __export(testHelpers_exports, {
|
|
|
38
38
|
createLocalWebSocketClient: () => createLocalWebSocketClient,
|
|
39
39
|
createWebSocketServer: () => createWebSocketServer,
|
|
40
40
|
createWsTransports: () => createWsTransports,
|
|
41
|
+
getUnixSocketPath: () => getUnixSocketPath,
|
|
41
42
|
iterNext: () => iterNext,
|
|
42
|
-
|
|
43
|
+
onUnixSocketServeReady: () => onUnixSocketServeReady,
|
|
44
|
+
onWsServerReady: () => onWsServerReady,
|
|
43
45
|
payloadToTransportMessage: () => payloadToTransportMessage,
|
|
44
46
|
waitForMessage: () => waitForMessage
|
|
45
47
|
});
|
|
@@ -173,6 +175,7 @@ var Transport = class {
|
|
|
173
175
|
eventDispatcher;
|
|
174
176
|
/**
|
|
175
177
|
* Creates a new Transport instance.
|
|
178
|
+
* This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
|
|
176
179
|
* @param codec The codec used to encode and decode messages.
|
|
177
180
|
* @param clientId The client ID of this transport.
|
|
178
181
|
*/
|
|
@@ -275,9 +278,6 @@ var Transport = class {
|
|
|
275
278
|
}
|
|
276
279
|
} else {
|
|
277
280
|
log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg2)}`);
|
|
278
|
-
if (msg2.to !== this.clientId) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
281
|
this.eventDispatcher.dispatchEvent("message", msg2);
|
|
282
282
|
if (!isAck(msg2.controlFlags)) {
|
|
283
283
|
const ackMsg = reply(msg2, { ack: msg2.id });
|
|
@@ -466,9 +466,6 @@ var WebSocketClientTransport = class extends Transport {
|
|
|
466
466
|
this.serverId = serverId;
|
|
467
467
|
this.options = options;
|
|
468
468
|
this.reconnectPromises = /* @__PURE__ */ new Map();
|
|
469
|
-
this.setupConnectionStatusListeners();
|
|
470
|
-
}
|
|
471
|
-
setupConnectionStatusListeners() {
|
|
472
469
|
this.createNewConnection(this.serverId);
|
|
473
470
|
}
|
|
474
471
|
async createNewConnection(to, attempt = 0) {
|
|
@@ -809,6 +806,9 @@ function _pushable(getNext, options) {
|
|
|
809
806
|
},
|
|
810
807
|
get readableLength() {
|
|
811
808
|
return _pushable2.readableLength;
|
|
809
|
+
},
|
|
810
|
+
onEmpty: (opts) => {
|
|
811
|
+
return _pushable2.onEmpty(opts);
|
|
812
812
|
}
|
|
813
813
|
};
|
|
814
814
|
return pushable2;
|
|
@@ -820,13 +820,14 @@ var defaultOptions2 = {
|
|
|
820
820
|
};
|
|
821
821
|
var WebSocketServerTransport = class extends Transport {
|
|
822
822
|
wss;
|
|
823
|
-
clientId;
|
|
824
823
|
constructor(wss, clientId, providedOptions) {
|
|
825
824
|
const options = { ...defaultOptions2, ...providedOptions };
|
|
826
825
|
super(options.codec, clientId);
|
|
827
826
|
this.wss = wss;
|
|
828
|
-
|
|
829
|
-
|
|
827
|
+
wss.on("listening", () => {
|
|
828
|
+
log?.info(`${this.clientId} -- server is listening`);
|
|
829
|
+
});
|
|
830
|
+
this.wss.on("connection", this.connectionHandler);
|
|
830
831
|
}
|
|
831
832
|
connectionHandler = (ws) => {
|
|
832
833
|
let conn = void 0;
|
|
@@ -849,9 +850,6 @@ var WebSocketServerTransport = class extends Transport {
|
|
|
849
850
|
);
|
|
850
851
|
};
|
|
851
852
|
};
|
|
852
|
-
setupConnectionStatusListeners() {
|
|
853
|
-
this.wss.on("connection", this.connectionHandler);
|
|
854
|
-
}
|
|
855
853
|
async createNewConnection(to) {
|
|
856
854
|
const err = `${this.clientId} -- failed to send msg to ${to}, client probably dropped`;
|
|
857
855
|
log?.warn(err);
|
|
@@ -876,10 +874,11 @@ var RiverUncaughtSchema = import_typebox2.Type.Object({
|
|
|
876
874
|
});
|
|
877
875
|
|
|
878
876
|
// util/testHelpers.ts
|
|
877
|
+
var import_nanoid2 = require("nanoid");
|
|
879
878
|
async function createWebSocketServer(server) {
|
|
880
879
|
return new import_ws.WebSocketServer({ server });
|
|
881
880
|
}
|
|
882
|
-
|
|
881
|
+
function onWsServerReady(server) {
|
|
883
882
|
return new Promise((resolve, reject) => {
|
|
884
883
|
server.listen(() => {
|
|
885
884
|
const addr = server.address();
|
|
@@ -891,6 +890,11 @@ async function onServerReady(server) {
|
|
|
891
890
|
});
|
|
892
891
|
});
|
|
893
892
|
}
|
|
893
|
+
function onUnixSocketServeReady(server, path) {
|
|
894
|
+
return new Promise((resolve) => {
|
|
895
|
+
server.listen(path, resolve);
|
|
896
|
+
});
|
|
897
|
+
}
|
|
894
898
|
async function createLocalWebSocketClient(port) {
|
|
895
899
|
const sock = new import_isomorphic_ws.default(`ws://localhost:${port}`);
|
|
896
900
|
sock.binaryType = "arraybuffer";
|
|
@@ -990,6 +994,9 @@ async function asClientUpload(state, proc, init, extendedContext) {
|
|
|
990
994
|
return [input, result];
|
|
991
995
|
}
|
|
992
996
|
}
|
|
997
|
+
var getUnixSocketPath = () => {
|
|
998
|
+
return process.platform === "win32" ? `\\\\?\\pipe\\${(0, import_nanoid2.nanoid)()}` : `/tmp/${(0, import_nanoid2.nanoid)()}.sock`;
|
|
999
|
+
};
|
|
993
1000
|
// Annotate the CommonJS export names for ESM import in node:
|
|
994
1001
|
0 && (module.exports = {
|
|
995
1002
|
asClientRpc,
|
|
@@ -1000,8 +1007,10 @@ async function asClientUpload(state, proc, init, extendedContext) {
|
|
|
1000
1007
|
createLocalWebSocketClient,
|
|
1001
1008
|
createWebSocketServer,
|
|
1002
1009
|
createWsTransports,
|
|
1010
|
+
getUnixSocketPath,
|
|
1003
1011
|
iterNext,
|
|
1004
|
-
|
|
1012
|
+
onUnixSocketServeReady,
|
|
1013
|
+
onWsServerReady,
|
|
1005
1014
|
payloadToTransportMessage,
|
|
1006
1015
|
waitForMessage
|
|
1007
1016
|
});
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import * as it_pushable from 'it-pushable';
|
|
2
2
|
import WebSocket from 'isomorphic-ws';
|
|
3
3
|
import { WebSocketServer } from 'ws';
|
|
4
|
-
import http from 'http';
|
|
4
|
+
import http from 'node:http';
|
|
5
5
|
import { WebSocketClientTransport } from '../transport/impls/ws/client.cjs';
|
|
6
6
|
import { TransportClientId, TransportMessage, OpaqueTransportMessage, Transport, Connection } from '../transport/index.cjs';
|
|
7
7
|
import { C as Codec } from '../types-3e5768ec.js';
|
|
8
8
|
import { WebSocketServerTransport } from '../transport/impls/ws/server.cjs';
|
|
9
9
|
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-87111051.js';
|
|
10
10
|
import { Static } from '@sinclair/typebox';
|
|
11
|
+
import net from 'node:net';
|
|
11
12
|
import '../connection-f7688cc1.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -24,7 +25,8 @@ declare function createWebSocketServer(server: http.Server): Promise<WebSocket.S
|
|
|
24
25
|
* @returns A promise that resolves with the allocated port number.
|
|
25
26
|
* @throws An error if a port cannot be allocated.
|
|
26
27
|
*/
|
|
27
|
-
declare function
|
|
28
|
+
declare function onWsServerReady(server: http.Server): Promise<number>;
|
|
29
|
+
declare function onUnixSocketServeReady(server: net.Server, path: string): Promise<void>;
|
|
28
30
|
/**
|
|
29
31
|
* Creates a WebSocket client that connects to a local server at the specified port.
|
|
30
32
|
* This should only be used for testing.
|
|
@@ -75,5 +77,6 @@ declare function asClientUpload<State extends object | unknown, I extends Payloa
|
|
|
75
77
|
message: string;
|
|
76
78
|
};
|
|
77
79
|
} | Result<Static<O>, Static<E>>>]>;
|
|
80
|
+
declare const getUnixSocketPath: () => string;
|
|
78
81
|
|
|
79
|
-
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer, createWsTransports, iterNext,
|
|
82
|
+
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer, createWsTransports, getUnixSocketPath, iterNext, onUnixSocketServeReady, onWsServerReady, payloadToTransportMessage, waitForMessage };
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import * as it_pushable from 'it-pushable';
|
|
2
2
|
import WebSocket from 'isomorphic-ws';
|
|
3
3
|
import { WebSocketServer } from 'ws';
|
|
4
|
-
import http from 'http';
|
|
4
|
+
import http from 'node:http';
|
|
5
5
|
import { WebSocketClientTransport } from '../transport/impls/ws/client.js';
|
|
6
6
|
import { TransportClientId, TransportMessage, OpaqueTransportMessage, Transport, Connection } from '../transport/index.js';
|
|
7
7
|
import { C as Codec } from '../types-3e5768ec.js';
|
|
8
8
|
import { WebSocketServerTransport } from '../transport/impls/ws/server.js';
|
|
9
9
|
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-87111051.js';
|
|
10
10
|
import { Static } from '@sinclair/typebox';
|
|
11
|
+
import net from 'node:net';
|
|
11
12
|
import '../connection-8e19874c.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -24,7 +25,8 @@ declare function createWebSocketServer(server: http.Server): Promise<WebSocket.S
|
|
|
24
25
|
* @returns A promise that resolves with the allocated port number.
|
|
25
26
|
* @throws An error if a port cannot be allocated.
|
|
26
27
|
*/
|
|
27
|
-
declare function
|
|
28
|
+
declare function onWsServerReady(server: http.Server): Promise<number>;
|
|
29
|
+
declare function onUnixSocketServeReady(server: net.Server, path: string): Promise<void>;
|
|
28
30
|
/**
|
|
29
31
|
* Creates a WebSocket client that connects to a local server at the specified port.
|
|
30
32
|
* This should only be used for testing.
|
|
@@ -75,5 +77,6 @@ declare function asClientUpload<State extends object | unknown, I extends Payloa
|
|
|
75
77
|
message: string;
|
|
76
78
|
};
|
|
77
79
|
} | Result<Static<O>, Static<E>>>]>;
|
|
80
|
+
declare const getUnixSocketPath: () => string;
|
|
78
81
|
|
|
79
|
-
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer, createWsTransports, iterNext,
|
|
82
|
+
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer, createWsTransports, getUnixSocketPath, iterNext, onUnixSocketServeReady, onWsServerReady, payloadToTransportMessage, waitForMessage };
|
package/dist/util/testHelpers.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UNCAUGHT_ERROR,
|
|
3
3
|
pushable
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-ORAG7IAU.js";
|
|
4
|
+
} from "../chunk-SCULZ4KS.js";
|
|
6
5
|
import {
|
|
7
6
|
WebSocketClientTransport
|
|
8
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-5735JCTZ.js";
|
|
9
8
|
import {
|
|
10
9
|
WebSocketServerTransport
|
|
11
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-LRQGTUTI.js";
|
|
11
|
+
import "../chunk-KRYKORQT.js";
|
|
12
|
+
import "../chunk-ORAG7IAU.js";
|
|
12
13
|
import "../chunk-WVT5QXMZ.js";
|
|
13
|
-
import "../chunk-PC65ZFWJ.js";
|
|
14
14
|
import "../chunk-R6H2BIMC.js";
|
|
15
|
-
import "../chunk-
|
|
15
|
+
import "../chunk-MF3Z3IDF.js";
|
|
16
16
|
import {
|
|
17
17
|
msg
|
|
18
18
|
} from "../chunk-ZE4MX7DF.js";
|
|
@@ -21,10 +21,11 @@ import "../chunk-SLUSVGQH.js";
|
|
|
21
21
|
// util/testHelpers.ts
|
|
22
22
|
import WebSocket from "isomorphic-ws";
|
|
23
23
|
import { WebSocketServer } from "ws";
|
|
24
|
+
import { nanoid } from "nanoid";
|
|
24
25
|
async function createWebSocketServer(server) {
|
|
25
26
|
return new WebSocketServer({ server });
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
function onWsServerReady(server) {
|
|
28
29
|
return new Promise((resolve, reject) => {
|
|
29
30
|
server.listen(() => {
|
|
30
31
|
const addr = server.address();
|
|
@@ -36,6 +37,11 @@ async function onServerReady(server) {
|
|
|
36
37
|
});
|
|
37
38
|
});
|
|
38
39
|
}
|
|
40
|
+
function onUnixSocketServeReady(server, path) {
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
server.listen(path, resolve);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
39
45
|
async function createLocalWebSocketClient(port) {
|
|
40
46
|
const sock = new WebSocket(`ws://localhost:${port}`);
|
|
41
47
|
sock.binaryType = "arraybuffer";
|
|
@@ -135,6 +141,9 @@ async function asClientUpload(state, proc, init, extendedContext) {
|
|
|
135
141
|
return [input, result];
|
|
136
142
|
}
|
|
137
143
|
}
|
|
144
|
+
var getUnixSocketPath = () => {
|
|
145
|
+
return process.platform === "win32" ? `\\\\?\\pipe\\${nanoid()}` : `/tmp/${nanoid()}.sock`;
|
|
146
|
+
};
|
|
138
147
|
export {
|
|
139
148
|
asClientRpc,
|
|
140
149
|
asClientStream,
|
|
@@ -144,8 +153,10 @@ export {
|
|
|
144
153
|
createLocalWebSocketClient,
|
|
145
154
|
createWebSocketServer,
|
|
146
155
|
createWsTransports,
|
|
156
|
+
getUnixSocketPath,
|
|
147
157
|
iterNext,
|
|
148
|
-
|
|
158
|
+
onUnixSocketServeReady,
|
|
159
|
+
onWsServerReady,
|
|
149
160
|
payloadToTransportMessage,
|
|
150
161
|
waitForMessage
|
|
151
162
|
};
|
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.10.
|
|
4
|
+
"version": "0.10.6",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -28,6 +28,14 @@
|
|
|
28
28
|
"import": "./dist/transport/impls/ws/server.js",
|
|
29
29
|
"require": "./dist/transport/impls/ws/server.cjs"
|
|
30
30
|
},
|
|
31
|
+
"./transport/unixsocket/client": {
|
|
32
|
+
"import": "./dist/transport/impls/unixsocket/client.js",
|
|
33
|
+
"require": "./dist/transport/impls/unixsocket/client.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./transport/unixsocket/server": {
|
|
36
|
+
"import": "./dist/transport/impls/unixsocket/server.js",
|
|
37
|
+
"require": "./dist/transport/impls/unixsocket/server.cjs"
|
|
38
|
+
},
|
|
31
39
|
"./transport/stdio": {
|
|
32
40
|
"import": "./dist/transport/impls/stdio/stdio.js",
|
|
33
41
|
"require": "./dist/transport/impls/stdio/stdio.cjs"
|
|
@@ -55,11 +63,21 @@
|
|
|
55
63
|
},
|
|
56
64
|
"devDependencies": {
|
|
57
65
|
"@types/ws": "^8.5.5",
|
|
58
|
-
"@vitest/ui": "^1.0
|
|
66
|
+
"@vitest/ui": "^1.1.0",
|
|
59
67
|
"prettier": "^3.0.0",
|
|
60
68
|
"tsup": "^7.2.0",
|
|
61
69
|
"typescript": "^5.2.2",
|
|
62
|
-
"vitest": "^1.0
|
|
70
|
+
"vitest": "^1.1.0"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"check": "tsc --noEmit && npx prettier . --check",
|
|
74
|
+
"format": "npx prettier . --write",
|
|
75
|
+
"build": "rm -rf dist && tsup && du -sh dist",
|
|
76
|
+
"prepack": "npm run build",
|
|
77
|
+
"release": "npm publish --access public",
|
|
78
|
+
"test:ui": "echo \"remember to go to /__vitest__ in the webview\" && vitest --ui --api.host 0.0.0.0 --api.port 3000",
|
|
79
|
+
"test": "vitest --test-timeout=500",
|
|
80
|
+
"bench": "vitest bench"
|
|
63
81
|
},
|
|
64
82
|
"engines": {
|
|
65
83
|
"node": ">=16"
|
|
@@ -70,14 +88,5 @@
|
|
|
70
88
|
"jsonschema"
|
|
71
89
|
],
|
|
72
90
|
"author": "Jacky Zhao",
|
|
73
|
-
"license": "MIT"
|
|
74
|
-
|
|
75
|
-
"check": "tsc --noEmit && npx prettier . --check",
|
|
76
|
-
"format": "npx prettier . --write",
|
|
77
|
-
"build": "rm -rf dist && tsup && du -sh dist",
|
|
78
|
-
"release": "npm publish --access public",
|
|
79
|
-
"test:ui": "echo \"remember to go to /__vitest__ in the webview\" && vitest --ui --api.host 0.0.0.0 --api.port 3000",
|
|
80
|
-
"test": "vitest --test-timeout=500",
|
|
81
|
-
"bench": "vitest bench"
|
|
82
|
-
}
|
|
83
|
-
}
|
|
91
|
+
"license": "MIT"
|
|
92
|
+
}
|