@replit/river 0.15.0 → 0.15.2
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 +41 -22
- package/dist/{builder-ca6c4259.d.ts → builder-ebd945c0.d.ts} +1 -1
- package/dist/{chunk-IVNV5HBI.js → chunk-B7VTDQR7.js} +160 -51
- package/dist/{chunk-BSAIT634.js → chunk-UJHTHOTT.js} +1 -1
- package/dist/{chunk-FFT7PSUV.js → chunk-ZRB6IKPV.js} +1 -1
- package/dist/{connection-0c5eeb14.d.ts → connection-10a24478.d.ts} +1 -1
- package/dist/{connection-14675d77.d.ts → connection-f4492948.d.ts} +1 -1
- package/dist/{index-f922ec84.d.ts → index-bbccacef.d.ts} +90 -16
- package/dist/router/index.d.cts +3 -3
- package/dist/router/index.d.ts +3 -3
- package/dist/transport/impls/uds/client.cjs +206 -92
- package/dist/transport/impls/uds/client.d.cts +3 -3
- package/dist/transport/impls/uds/client.d.ts +3 -3
- package/dist/transport/impls/uds/client.js +2 -2
- package/dist/transport/impls/uds/server.cjs +75 -73
- package/dist/transport/impls/uds/server.d.cts +3 -3
- package/dist/transport/impls/uds/server.d.ts +3 -3
- package/dist/transport/impls/uds/server.js +2 -2
- package/dist/transport/impls/ws/client.cjs +206 -94
- package/dist/transport/impls/ws/client.d.cts +3 -3
- package/dist/transport/impls/ws/client.d.ts +3 -3
- package/dist/transport/impls/ws/client.js +2 -2
- package/dist/transport/impls/ws/server.cjs +75 -73
- package/dist/transport/impls/ws/server.d.cts +3 -3
- package/dist/transport/impls/ws/server.d.ts +3 -3
- package/dist/transport/impls/ws/server.js +2 -2
- package/dist/transport/index.cjs +211 -105
- package/dist/transport/index.d.cts +1 -1
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +3 -3
- package/dist/util/testHelpers.cjs +61 -64
- package/dist/util/testHelpers.d.cts +10 -4
- package/dist/util/testHelpers.d.ts +10 -4
- package/dist/util/testHelpers.js +13 -5
- package/package.json +1 -1
|
@@ -108,6 +108,11 @@ function isAck(controlFlag) {
|
|
|
108
108
|
var log;
|
|
109
109
|
|
|
110
110
|
// transport/events.ts
|
|
111
|
+
var ProtocolError = {
|
|
112
|
+
RetriesExceeded: "conn_retry_exceeded",
|
|
113
|
+
HandshakeFailed: "handshake_failed",
|
|
114
|
+
UseAfterDestroy: "use_after_destroy"
|
|
115
|
+
};
|
|
111
116
|
var EventDispatcher = class {
|
|
112
117
|
eventListeners = {};
|
|
113
118
|
numberOfListeners(eventType) {
|
|
@@ -137,60 +142,6 @@ var EventDispatcher = class {
|
|
|
137
142
|
|
|
138
143
|
// transport/session.ts
|
|
139
144
|
var import_nanoid2 = require("nanoid");
|
|
140
|
-
|
|
141
|
-
// codec/json.ts
|
|
142
|
-
var encoder = new TextEncoder();
|
|
143
|
-
var decoder = new TextDecoder();
|
|
144
|
-
function uint8ArrayToBase64(uint8Array) {
|
|
145
|
-
let binary = "";
|
|
146
|
-
uint8Array.forEach((byte) => {
|
|
147
|
-
binary += String.fromCharCode(byte);
|
|
148
|
-
});
|
|
149
|
-
return btoa(binary);
|
|
150
|
-
}
|
|
151
|
-
function base64ToUint8Array(base64) {
|
|
152
|
-
const binaryString = atob(base64);
|
|
153
|
-
const uint8Array = new Uint8Array(binaryString.length);
|
|
154
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
155
|
-
uint8Array[i] = binaryString.charCodeAt(i);
|
|
156
|
-
}
|
|
157
|
-
return uint8Array;
|
|
158
|
-
}
|
|
159
|
-
var NaiveJsonCodec = {
|
|
160
|
-
toBuffer: (obj) => {
|
|
161
|
-
return encoder.encode(
|
|
162
|
-
JSON.stringify(obj, function replacer(key) {
|
|
163
|
-
const val = this[key];
|
|
164
|
-
if (val instanceof Uint8Array) {
|
|
165
|
-
return { $t: uint8ArrayToBase64(val) };
|
|
166
|
-
} else {
|
|
167
|
-
return val;
|
|
168
|
-
}
|
|
169
|
-
})
|
|
170
|
-
);
|
|
171
|
-
},
|
|
172
|
-
fromBuffer: (buff) => {
|
|
173
|
-
try {
|
|
174
|
-
const parsed = JSON.parse(
|
|
175
|
-
decoder.decode(buff),
|
|
176
|
-
function reviver(_key, val) {
|
|
177
|
-
if (val?.$t) {
|
|
178
|
-
return base64ToUint8Array(val.$t);
|
|
179
|
-
} else {
|
|
180
|
-
return val;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
);
|
|
184
|
-
if (typeof parsed === "object")
|
|
185
|
-
return parsed;
|
|
186
|
-
return null;
|
|
187
|
-
} catch {
|
|
188
|
-
return null;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
// transport/session.ts
|
|
194
145
|
var nanoid2 = (0, import_nanoid2.customAlphabet)("1234567890abcdefghijklmnopqrstuvxyz", 6);
|
|
195
146
|
var unsafeId = () => nanoid2();
|
|
196
147
|
var Connection = class {
|
|
@@ -199,15 +150,6 @@ var Connection = class {
|
|
|
199
150
|
this.debugId = `conn-${unsafeId()}`;
|
|
200
151
|
}
|
|
201
152
|
};
|
|
202
|
-
var HEARTBEAT_INTERVAL_MS = 1e3;
|
|
203
|
-
var HEARTBEATS_TILL_DEAD = 2;
|
|
204
|
-
var SESSION_DISCONNECT_GRACE_MS = 5e3;
|
|
205
|
-
var defaultSessionOptions = {
|
|
206
|
-
heartbeatIntervalMs: HEARTBEAT_INTERVAL_MS,
|
|
207
|
-
heartbeatsUntilDead: HEARTBEATS_TILL_DEAD,
|
|
208
|
-
sessionDisconnectGraceMs: SESSION_DISCONNECT_GRACE_MS,
|
|
209
|
-
codec: NaiveJsonCodec
|
|
210
|
-
};
|
|
211
153
|
var Session = class {
|
|
212
154
|
codec;
|
|
213
155
|
options;
|
|
@@ -402,14 +344,74 @@ function coerceErrorString(err) {
|
|
|
402
344
|
return `[coerced to error] ${String(err)}`;
|
|
403
345
|
}
|
|
404
346
|
|
|
347
|
+
// codec/json.ts
|
|
348
|
+
var encoder = new TextEncoder();
|
|
349
|
+
var decoder = new TextDecoder();
|
|
350
|
+
function uint8ArrayToBase64(uint8Array) {
|
|
351
|
+
let binary = "";
|
|
352
|
+
uint8Array.forEach((byte) => {
|
|
353
|
+
binary += String.fromCharCode(byte);
|
|
354
|
+
});
|
|
355
|
+
return btoa(binary);
|
|
356
|
+
}
|
|
357
|
+
function base64ToUint8Array(base64) {
|
|
358
|
+
const binaryString = atob(base64);
|
|
359
|
+
const uint8Array = new Uint8Array(binaryString.length);
|
|
360
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
361
|
+
uint8Array[i] = binaryString.charCodeAt(i);
|
|
362
|
+
}
|
|
363
|
+
return uint8Array;
|
|
364
|
+
}
|
|
365
|
+
var NaiveJsonCodec = {
|
|
366
|
+
toBuffer: (obj) => {
|
|
367
|
+
return encoder.encode(
|
|
368
|
+
JSON.stringify(obj, function replacer(key) {
|
|
369
|
+
const val = this[key];
|
|
370
|
+
if (val instanceof Uint8Array) {
|
|
371
|
+
return { $t: uint8ArrayToBase64(val) };
|
|
372
|
+
} else {
|
|
373
|
+
return val;
|
|
374
|
+
}
|
|
375
|
+
})
|
|
376
|
+
);
|
|
377
|
+
},
|
|
378
|
+
fromBuffer: (buff) => {
|
|
379
|
+
try {
|
|
380
|
+
const parsed = JSON.parse(
|
|
381
|
+
decoder.decode(buff),
|
|
382
|
+
function reviver(_key, val) {
|
|
383
|
+
if (val?.$t) {
|
|
384
|
+
return base64ToUint8Array(val.$t);
|
|
385
|
+
} else {
|
|
386
|
+
return val;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
);
|
|
390
|
+
if (typeof parsed === "object")
|
|
391
|
+
return parsed;
|
|
392
|
+
return null;
|
|
393
|
+
} catch {
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
|
|
405
399
|
// transport/transport.ts
|
|
406
|
-
var RECONNECT_JITTER_MAX_MS = 500;
|
|
407
|
-
var RECONNECT_INTERVAL_MS = 250;
|
|
408
400
|
var defaultTransportOptions = {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
401
|
+
heartbeatIntervalMs: 1e3,
|
|
402
|
+
heartbeatsUntilDead: 2,
|
|
403
|
+
sessionDisconnectGraceMs: 5e3,
|
|
404
|
+
codec: NaiveJsonCodec
|
|
405
|
+
};
|
|
406
|
+
var defaultClientTransportOptions = {
|
|
407
|
+
connectionRetryOptions: {
|
|
408
|
+
baseIntervalMs: 250,
|
|
409
|
+
maxJitterMs: 200,
|
|
410
|
+
maxBackoffMs: 32e3,
|
|
411
|
+
attemptBudgetCapacity: 15,
|
|
412
|
+
budgetRestoreIntervalMs: 200
|
|
413
|
+
},
|
|
414
|
+
...defaultTransportOptions
|
|
413
415
|
};
|
|
414
416
|
var Transport = class {
|
|
415
417
|
/**
|
|
@@ -624,7 +626,7 @@ var Transport = class {
|
|
|
624
626
|
if (this.state === "destroyed") {
|
|
625
627
|
const err = "transport is destroyed, cant send";
|
|
626
628
|
log?.error(`${this.clientId} -- ` + err + `: ${JSON.stringify(msg)}`);
|
|
627
|
-
this.protocolError(
|
|
629
|
+
this.protocolError(ProtocolError.UseAfterDestroy, err);
|
|
628
630
|
return void 0;
|
|
629
631
|
} else if (this.state === "closed") {
|
|
630
632
|
log?.info(
|
|
@@ -736,7 +738,7 @@ var ServerTransport = class extends Transport {
|
|
|
736
738
|
const parsed = this.parseMsg(data);
|
|
737
739
|
if (!parsed) {
|
|
738
740
|
this.protocolError(
|
|
739
|
-
|
|
741
|
+
ProtocolError.HandshakeFailed,
|
|
740
742
|
"received non-transport message"
|
|
741
743
|
);
|
|
742
744
|
return false;
|
|
@@ -755,7 +757,7 @@ var ServerTransport = class extends Transport {
|
|
|
755
757
|
)}`
|
|
756
758
|
);
|
|
757
759
|
this.protocolError(
|
|
758
|
-
|
|
760
|
+
ProtocolError.HandshakeFailed,
|
|
759
761
|
"invalid handshake request"
|
|
760
762
|
);
|
|
761
763
|
return false;
|
|
@@ -773,7 +775,7 @@ var ServerTransport = class extends Transport {
|
|
|
773
775
|
`${this.clientId} -- received handshake msg with incompatible protocol version (got: ${gotVersion}, expected: ${PROTOCOL_VERSION})`
|
|
774
776
|
);
|
|
775
777
|
this.protocolError(
|
|
776
|
-
|
|
778
|
+
ProtocolError.HandshakeFailed,
|
|
777
779
|
`incorrect version (got: ${gotVersion} wanted ${PROTOCOL_VERSION})`
|
|
778
780
|
);
|
|
779
781
|
return false;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { S as ServerTransport, b as TransportClientId,
|
|
1
|
+
import { S as ServerTransport, b as TransportClientId, d as ProvidedTransportOptions } from '../../../index-bbccacef.js';
|
|
2
2
|
import { WebSocketServer } from 'ws';
|
|
3
3
|
import { WebSocket } from 'isomorphic-ws';
|
|
4
|
-
import { W as WebSocketConnection } from '../../../connection-
|
|
4
|
+
import { W as WebSocketConnection } from '../../../connection-f4492948.js';
|
|
5
5
|
import '../../../types-3e5768ec.js';
|
|
6
6
|
import '@sinclair/typebox';
|
|
7
7
|
|
|
8
8
|
declare class WebSocketServerTransport extends ServerTransport<WebSocketConnection> {
|
|
9
9
|
wss: WebSocketServer;
|
|
10
|
-
constructor(wss: WebSocketServer, clientId: TransportClientId, providedOptions?: Partial<
|
|
10
|
+
constructor(wss: WebSocketServer, clientId: TransportClientId, providedOptions?: Partial<ProvidedTransportOptions>);
|
|
11
11
|
connectionHandler: (ws: WebSocket) => void;
|
|
12
12
|
close(): void;
|
|
13
13
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { S as ServerTransport, b as TransportClientId,
|
|
1
|
+
import { S as ServerTransport, b as TransportClientId, d as ProvidedTransportOptions } from '../../../index-bbccacef.js';
|
|
2
2
|
import { WebSocketServer } from 'ws';
|
|
3
3
|
import { WebSocket } from 'isomorphic-ws';
|
|
4
|
-
import { W as WebSocketConnection } from '../../../connection-
|
|
4
|
+
import { W as WebSocketConnection } from '../../../connection-f4492948.js';
|
|
5
5
|
import '../../../types-3e5768ec.js';
|
|
6
6
|
import '@sinclair/typebox';
|
|
7
7
|
|
|
8
8
|
declare class WebSocketServerTransport extends ServerTransport<WebSocketConnection> {
|
|
9
9
|
wss: WebSocketServer;
|
|
10
|
-
constructor(wss: WebSocketServer, clientId: TransportClientId, providedOptions?: Partial<
|
|
10
|
+
constructor(wss: WebSocketServer, clientId: TransportClientId, providedOptions?: Partial<ProvidedTransportOptions>);
|
|
11
11
|
connectionHandler: (ws: WebSocket) => void;
|
|
12
12
|
close(): void;
|
|
13
13
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WebSocketConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-ZRB6IKPV.js";
|
|
4
4
|
import {
|
|
5
5
|
ServerTransport
|
|
6
|
-
} from "../../../chunk-
|
|
6
|
+
} from "../../../chunk-B7VTDQR7.js";
|
|
7
7
|
import "../../../chunk-GFRAOY75.js";
|
|
8
8
|
import "../../../chunk-H4BYJELI.js";
|
|
9
9
|
import "../../../chunk-GZ7HCLLM.js";
|