@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.
Files changed (83) hide show
  1. package/README.md +28 -8
  2. package/dist/{builder-1f26296b.d.ts → builder-c593de11.d.ts} +14 -13
  3. package/dist/{chunk-3JGVFWKQ.js → chunk-24O3BKZA.js} +205 -180
  4. package/dist/chunk-4HOR4NUO.js +40 -0
  5. package/dist/chunk-ANGOKBE5.js +708 -0
  6. package/dist/{chunk-R6H2BIMC.js → chunk-GZ7HCLLM.js} +31 -7
  7. package/dist/{chunk-T7M7OKPE.js → chunk-H4BYJELI.js} +5 -1
  8. package/dist/chunk-IIBVKYDB.js +62 -0
  9. package/dist/chunk-IUDKWAOK.js +47 -0
  10. package/dist/chunk-WTOIOXB7.js +125 -0
  11. package/dist/chunk-XOTIAXAH.js +44 -0
  12. package/dist/codec/index.cjs +13 -7
  13. package/dist/codec/index.js +2 -4
  14. package/dist/connection-2956a1c5.d.ts +17 -0
  15. package/dist/connection-aaea7c88.d.ts +15 -0
  16. package/dist/connection-cd963ed5.d.ts +18 -0
  17. package/dist/index-d91775d9.d.ts +442 -0
  18. package/dist/logging/index.cjs +8 -3
  19. package/dist/logging/index.d.cts +6 -1
  20. package/dist/logging/index.d.ts +6 -1
  21. package/dist/logging/index.js +5 -3
  22. package/dist/messageFraming-b200ef25.d.ts +20 -0
  23. package/dist/router/index.cjs +249 -211
  24. package/dist/router/index.d.cts +6 -7
  25. package/dist/router/index.d.ts +6 -7
  26. package/dist/router/index.js +3 -3
  27. package/dist/transport/impls/stdio/client.cjs +891 -0
  28. package/dist/transport/impls/stdio/client.d.cts +27 -0
  29. package/dist/transport/impls/stdio/client.d.ts +27 -0
  30. package/dist/transport/impls/stdio/client.js +42 -0
  31. package/dist/transport/impls/stdio/server.cjs +861 -0
  32. package/dist/transport/impls/stdio/server.d.cts +25 -0
  33. package/dist/transport/impls/stdio/server.d.ts +25 -0
  34. package/dist/transport/impls/stdio/server.js +33 -0
  35. package/dist/transport/impls/uds/client.cjs +893 -0
  36. package/dist/transport/impls/uds/client.d.cts +16 -0
  37. package/dist/transport/impls/uds/client.d.ts +16 -0
  38. package/dist/transport/impls/uds/client.js +44 -0
  39. package/dist/transport/impls/uds/server.cjs +863 -0
  40. package/dist/transport/impls/uds/server.d.cts +16 -0
  41. package/dist/transport/impls/uds/server.d.ts +16 -0
  42. package/dist/transport/impls/uds/server.js +39 -0
  43. package/dist/transport/impls/ws/client.cjs +587 -248
  44. package/dist/transport/impls/ws/client.d.cts +6 -21
  45. package/dist/transport/impls/ws/client.d.ts +6 -21
  46. package/dist/transport/impls/ws/client.js +77 -7
  47. package/dist/transport/impls/ws/server.cjs +541 -194
  48. package/dist/transport/impls/ws/server.d.cts +6 -10
  49. package/dist/transport/impls/ws/server.d.ts +6 -10
  50. package/dist/transport/impls/ws/server.js +31 -8
  51. package/dist/transport/index.cjs +652 -129
  52. package/dist/transport/index.d.cts +3 -276
  53. package/dist/transport/index.d.ts +3 -276
  54. package/dist/transport/index.js +13 -10
  55. package/dist/util/testHelpers.cjs +40 -602
  56. package/dist/util/testHelpers.d.cts +18 -37
  57. package/dist/util/testHelpers.d.ts +18 -37
  58. package/dist/util/testHelpers.js +27 -47
  59. package/package.json +29 -14
  60. package/dist/chunk-3MQETIGZ.js +0 -80
  61. package/dist/chunk-5IC5XMWK.js +0 -140
  62. package/dist/chunk-L7D75G4K.js +0 -29
  63. package/dist/chunk-LQXPKF3A.js +0 -282
  64. package/dist/chunk-PJ2EUO7O.js +0 -63
  65. package/dist/chunk-WVT5QXMZ.js +0 -20
  66. package/dist/chunk-ZE4MX7DF.js +0 -75
  67. package/dist/connection-2529fc14.d.ts +0 -10
  68. package/dist/connection-316d6e3a.d.ts +0 -10
  69. package/dist/connection-8e19874c.d.ts +0 -11
  70. package/dist/connection-f7688cc1.d.ts +0 -11
  71. package/dist/transport/impls/stdio/stdio.cjs +0 -508
  72. package/dist/transport/impls/stdio/stdio.d.cts +0 -26
  73. package/dist/transport/impls/stdio/stdio.d.ts +0 -26
  74. package/dist/transport/impls/stdio/stdio.js +0 -70
  75. package/dist/transport/impls/unixsocket/client.cjs +0 -506
  76. package/dist/transport/impls/unixsocket/client.d.cts +0 -16
  77. package/dist/transport/impls/unixsocket/client.d.ts +0 -16
  78. package/dist/transport/impls/unixsocket/client.js +0 -67
  79. package/dist/transport/impls/unixsocket/server.cjs +0 -510
  80. package/dist/transport/impls/unixsocket/server.d.cts +0 -18
  81. package/dist/transport/impls/unixsocket/server.d.ts +0 -18
  82. package/dist/transport/impls/unixsocket/server.js +0 -73
  83. /package/dist/{chunk-ORAG7IAU.js → chunk-5IZ2UHWV.js} +0 -0
@@ -1,33 +1,20 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { Transport, TransportClientId } from '../../index.cjs';
3
- import { C as Codec } from '../../../types-3e5768ec.js';
4
- import { W as WebSocketConnection } from '../../../connection-f7688cc1.js';
2
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-d91775d9.js';
3
+ import { W as WebSocketConnection } from '../../../connection-aaea7c88.js';
4
+ import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
 
7
- interface Options {
8
- retryIntervalMs: number;
9
- retryAttemptsMax: number;
10
- codec: Codec;
11
- }
12
- type WebSocketResult = {
13
- ws: WebSocket;
14
- } | {
15
- err: string;
16
- };
17
7
  /**
18
8
  * A transport implementation that uses a WebSocket connection with automatic reconnection.
19
9
  * @class
20
10
  * @extends Transport
21
11
  */
22
- declare class WebSocketClientTransport extends Transport<WebSocketConnection> {
12
+ declare class WebSocketClientTransport extends ClientTransport<WebSocketConnection> {
23
13
  /**
24
14
  * A function that returns a Promise that resolves to a WebSocket instance.
25
15
  */
26
16
  wsGetter: (to: TransportClientId) => Promise<WebSocket>;
27
- options: Options;
28
17
  serverId: TransportClientId;
29
- reconnectPromises: Map<TransportClientId, Promise<WebSocketResult>>;
30
- tryReconnecting: boolean;
31
18
  /**
32
19
  * Creates a new WebSocketClientTransport instance.
33
20
  * @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.
@@ -35,11 +22,9 @@ declare class WebSocketClientTransport extends Transport<WebSocketConnection> {
35
22
  * @param serverId The ID of the server this transport is connecting to.
36
23
  * @param providedOptions An optional object containing configuration options for the transport.
37
24
  */
38
- constructor(wsGetter: () => Promise<WebSocket>, sessionId: TransportClientId, serverId: TransportClientId, providedOptions?: Partial<Options>);
25
+ constructor(wsGetter: () => Promise<WebSocket>, sessionId: TransportClientId, serverId: TransportClientId, providedOptions?: Partial<TransportOptions>);
39
26
  reopen(): void;
40
- createNewConnection(to: string, attempt?: number): Promise<void>;
41
- close(): Promise<void>;
42
- destroy(): Promise<void>;
27
+ createNewOutgoingConnection(to: string): Promise<WebSocketConnection>;
43
28
  }
44
29
 
45
30
  export { WebSocketClientTransport };
@@ -1,33 +1,20 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { Transport, TransportClientId } from '../../index.js';
3
- import { C as Codec } from '../../../types-3e5768ec.js';
4
- import { W as WebSocketConnection } from '../../../connection-8e19874c.js';
2
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-d91775d9.js';
3
+ import { W as WebSocketConnection } from '../../../connection-aaea7c88.js';
4
+ import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
 
7
- interface Options {
8
- retryIntervalMs: number;
9
- retryAttemptsMax: number;
10
- codec: Codec;
11
- }
12
- type WebSocketResult = {
13
- ws: WebSocket;
14
- } | {
15
- err: string;
16
- };
17
7
  /**
18
8
  * A transport implementation that uses a WebSocket connection with automatic reconnection.
19
9
  * @class
20
10
  * @extends Transport
21
11
  */
22
- declare class WebSocketClientTransport extends Transport<WebSocketConnection> {
12
+ declare class WebSocketClientTransport extends ClientTransport<WebSocketConnection> {
23
13
  /**
24
14
  * A function that returns a Promise that resolves to a WebSocket instance.
25
15
  */
26
16
  wsGetter: (to: TransportClientId) => Promise<WebSocket>;
27
- options: Options;
28
17
  serverId: TransportClientId;
29
- reconnectPromises: Map<TransportClientId, Promise<WebSocketResult>>;
30
- tryReconnecting: boolean;
31
18
  /**
32
19
  * Creates a new WebSocketClientTransport instance.
33
20
  * @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.
@@ -35,11 +22,9 @@ declare class WebSocketClientTransport extends Transport<WebSocketConnection> {
35
22
  * @param serverId The ID of the server this transport is connecting to.
36
23
  * @param providedOptions An optional object containing configuration options for the transport.
37
24
  */
38
- constructor(wsGetter: () => Promise<WebSocket>, sessionId: TransportClientId, serverId: TransportClientId, providedOptions?: Partial<Options>);
25
+ constructor(wsGetter: () => Promise<WebSocket>, sessionId: TransportClientId, serverId: TransportClientId, providedOptions?: Partial<TransportOptions>);
39
26
  reopen(): void;
40
- createNewConnection(to: string, attempt?: number): Promise<void>;
41
- close(): Promise<void>;
42
- destroy(): Promise<void>;
27
+ createNewOutgoingConnection(to: string): Promise<WebSocketConnection>;
43
28
  }
44
29
 
45
30
  export { WebSocketClientTransport };
@@ -1,11 +1,81 @@
1
1
  import {
2
- WebSocketClientTransport
3
- } from "../../../chunk-5IC5XMWK.js";
4
- import "../../../chunk-L7D75G4K.js";
5
- import "../../../chunk-R6H2BIMC.js";
6
- import "../../../chunk-LQXPKF3A.js";
7
- import "../../../chunk-ZE4MX7DF.js";
8
- import "../../../chunk-T7M7OKPE.js";
2
+ WebSocketConnection
3
+ } from "../../../chunk-4HOR4NUO.js";
4
+ import {
5
+ ClientTransport
6
+ } from "../../../chunk-ANGOKBE5.js";
7
+ import "../../../chunk-GZ7HCLLM.js";
8
+ import "../../../chunk-WTOIOXB7.js";
9
+ import {
10
+ log
11
+ } from "../../../chunk-H4BYJELI.js";
12
+
13
+ // transport/impls/ws/client.ts
14
+ var WebSocketClientTransport = class extends ClientTransport {
15
+ /**
16
+ * A function that returns a Promise that resolves to a WebSocket instance.
17
+ */
18
+ wsGetter;
19
+ serverId;
20
+ /**
21
+ * Creates a new WebSocketClientTransport instance.
22
+ * @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.
23
+ * @param sessionId The ID of the client using the transport. This should be unique per session.
24
+ * @param serverId The ID of the server this transport is connecting to.
25
+ * @param providedOptions An optional object containing configuration options for the transport.
26
+ */
27
+ constructor(wsGetter, sessionId, serverId, providedOptions) {
28
+ super(sessionId, providedOptions);
29
+ this.wsGetter = wsGetter;
30
+ this.serverId = serverId;
31
+ void this.connect(this.serverId);
32
+ }
33
+ reopen() {
34
+ if (this.state === "destroyed") {
35
+ throw new Error("cant reopen a destroyed connection");
36
+ }
37
+ this.state = "open";
38
+ void this.connect(this.serverId);
39
+ }
40
+ async createNewOutgoingConnection(to) {
41
+ const wsRes = await new Promise((resolve) => {
42
+ log?.info(`${this.clientId} -- establishing a new websocket to ${to}`);
43
+ this.wsGetter(to).then((ws) => {
44
+ if (ws.readyState === ws.OPEN) {
45
+ resolve({ ws });
46
+ return;
47
+ }
48
+ if (ws.readyState === ws.CLOSING || ws.readyState === ws.CLOSED) {
49
+ resolve({ err: "ws is closing or closed" });
50
+ return;
51
+ }
52
+ const onOpen = () => {
53
+ ws.removeEventListener("open", onOpen);
54
+ resolve({ ws });
55
+ };
56
+ const onClose = (evt) => {
57
+ ws.removeEventListener("close", onClose);
58
+ resolve({ err: evt.reason });
59
+ };
60
+ ws.addEventListener("open", onOpen);
61
+ ws.addEventListener("close", onClose);
62
+ }).catch((e) => {
63
+ const reason = e instanceof Error ? e.message : "unknown reason";
64
+ resolve({ err: `couldn't get a new websocket: ${reason}` });
65
+ });
66
+ });
67
+ if ("ws" in wsRes) {
68
+ const conn = new WebSocketConnection(wsRes.ws);
69
+ log?.info(
70
+ `${this.clientId} -- websocket (id: ${conn.debugId}) to ${to} ok`
71
+ );
72
+ this.handleConnection(conn, to);
73
+ return conn;
74
+ } else {
75
+ throw new Error(wsRes.err);
76
+ }
77
+ }
78
+ };
9
79
  export {
10
80
  WebSocketClientTransport
11
81
  };