@replit/river 0.15.1 → 0.15.3
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-660d3140.d.ts → builder-4d392f6c.d.ts} +1 -1
- package/dist/{chunk-O6YQ3JAH.js → chunk-5XMMDOLH.js} +148 -37
- package/dist/{chunk-MNWOTQWX.js → chunk-MXHIHC3U.js} +1 -1
- package/dist/{chunk-5TX4BKAD.js → chunk-NSJVTNVQ.js} +1 -1
- package/dist/{connection-162c0f7b.d.ts → connection-94896f3b.d.ts} +1 -1
- package/dist/{connection-93daccc3.d.ts → connection-99346822.d.ts} +1 -1
- package/dist/{index-76b801f8.d.ts → index-2e402bb8.d.ts} +84 -11
- package/dist/router/index.d.cts +3 -3
- package/dist/router/index.d.ts +3 -3
- package/dist/transport/impls/uds/client.cjs +198 -88
- 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 +67 -69
- 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 +198 -90
- 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 +67 -69
- 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 +198 -90
- package/dist/transport/index.d.cts +1 -1
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +1 -1
- 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
|
@@ -100,58 +100,6 @@ function isAck(controlFlag) {
|
|
|
100
100
|
return (controlFlag & 1 /* AckBit */) === 1 /* AckBit */;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
// codec/json.ts
|
|
104
|
-
var encoder = new TextEncoder();
|
|
105
|
-
var decoder = new TextDecoder();
|
|
106
|
-
function uint8ArrayToBase64(uint8Array) {
|
|
107
|
-
let binary = "";
|
|
108
|
-
uint8Array.forEach((byte) => {
|
|
109
|
-
binary += String.fromCharCode(byte);
|
|
110
|
-
});
|
|
111
|
-
return btoa(binary);
|
|
112
|
-
}
|
|
113
|
-
function base64ToUint8Array(base64) {
|
|
114
|
-
const binaryString = atob(base64);
|
|
115
|
-
const uint8Array = new Uint8Array(binaryString.length);
|
|
116
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
117
|
-
uint8Array[i] = binaryString.charCodeAt(i);
|
|
118
|
-
}
|
|
119
|
-
return uint8Array;
|
|
120
|
-
}
|
|
121
|
-
var NaiveJsonCodec = {
|
|
122
|
-
toBuffer: (obj) => {
|
|
123
|
-
return encoder.encode(
|
|
124
|
-
JSON.stringify(obj, function replacer(key) {
|
|
125
|
-
const val = this[key];
|
|
126
|
-
if (val instanceof Uint8Array) {
|
|
127
|
-
return { $t: uint8ArrayToBase64(val) };
|
|
128
|
-
} else {
|
|
129
|
-
return val;
|
|
130
|
-
}
|
|
131
|
-
})
|
|
132
|
-
);
|
|
133
|
-
},
|
|
134
|
-
fromBuffer: (buff) => {
|
|
135
|
-
try {
|
|
136
|
-
const parsed = JSON.parse(
|
|
137
|
-
decoder.decode(buff),
|
|
138
|
-
function reviver(_key, val) {
|
|
139
|
-
if (val?.$t) {
|
|
140
|
-
return base64ToUint8Array(val.$t);
|
|
141
|
-
} else {
|
|
142
|
-
return val;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
);
|
|
146
|
-
if (typeof parsed === "object")
|
|
147
|
-
return parsed;
|
|
148
|
-
return null;
|
|
149
|
-
} catch {
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
|
|
155
103
|
// transport/session.ts
|
|
156
104
|
var nanoid2 = (0, import_nanoid2.customAlphabet)("1234567890abcdefghijklmnopqrstuvxyz", 6);
|
|
157
105
|
var unsafeId = () => nanoid2();
|
|
@@ -161,15 +109,6 @@ var Connection = class {
|
|
|
161
109
|
this.debugId = `conn-${unsafeId()}`;
|
|
162
110
|
}
|
|
163
111
|
};
|
|
164
|
-
var HEARTBEAT_INTERVAL_MS = 1e3;
|
|
165
|
-
var HEARTBEATS_TILL_DEAD = 2;
|
|
166
|
-
var SESSION_DISCONNECT_GRACE_MS = 5e3;
|
|
167
|
-
var defaultSessionOptions = {
|
|
168
|
-
heartbeatIntervalMs: HEARTBEAT_INTERVAL_MS,
|
|
169
|
-
heartbeatsUntilDead: HEARTBEATS_TILL_DEAD,
|
|
170
|
-
sessionDisconnectGraceMs: SESSION_DISCONNECT_GRACE_MS,
|
|
171
|
-
codec: NaiveJsonCodec
|
|
172
|
-
};
|
|
173
112
|
var Session = class {
|
|
174
113
|
codec;
|
|
175
114
|
options;
|
|
@@ -493,14 +432,147 @@ function coerceErrorString(err) {
|
|
|
493
432
|
return `[coerced to error] ${String(err)}`;
|
|
494
433
|
}
|
|
495
434
|
|
|
435
|
+
// transport/rateLimit.ts
|
|
436
|
+
var LeakyBucketRateLimit = class {
|
|
437
|
+
budgetConsumed;
|
|
438
|
+
intervalHandles;
|
|
439
|
+
options;
|
|
440
|
+
constructor(options) {
|
|
441
|
+
this.options = options;
|
|
442
|
+
this.budgetConsumed = /* @__PURE__ */ new Map();
|
|
443
|
+
this.intervalHandles = /* @__PURE__ */ new Map();
|
|
444
|
+
}
|
|
445
|
+
getBackoffMs(user) {
|
|
446
|
+
if (!this.budgetConsumed.has(user))
|
|
447
|
+
return 0;
|
|
448
|
+
const exponent = Math.max(0, this.getBudgetConsumed(user) - 1);
|
|
449
|
+
const jitter = Math.floor(Math.random() * this.options.maxJitterMs);
|
|
450
|
+
const backoffMs = Math.min(
|
|
451
|
+
this.options.baseIntervalMs * 2 ** exponent,
|
|
452
|
+
this.options.maxBackoffMs
|
|
453
|
+
);
|
|
454
|
+
return backoffMs + jitter;
|
|
455
|
+
}
|
|
456
|
+
get totalBudgetRestoreTime() {
|
|
457
|
+
return this.options.budgetRestoreIntervalMs * this.options.attemptBudgetCapacity;
|
|
458
|
+
}
|
|
459
|
+
consumeBudget(user) {
|
|
460
|
+
this.stopLeak(user);
|
|
461
|
+
this.budgetConsumed.set(user, this.getBudgetConsumed(user) + 1);
|
|
462
|
+
}
|
|
463
|
+
getBudgetConsumed(user) {
|
|
464
|
+
return this.budgetConsumed.get(user) ?? 0;
|
|
465
|
+
}
|
|
466
|
+
hasBudget(user) {
|
|
467
|
+
return this.getBudgetConsumed(user) < this.options.attemptBudgetCapacity;
|
|
468
|
+
}
|
|
469
|
+
startRestoringBudget(user) {
|
|
470
|
+
if (this.intervalHandles.has(user)) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const restoreBudgetForUser = () => {
|
|
474
|
+
const currentBudget = this.budgetConsumed.get(user);
|
|
475
|
+
if (!currentBudget) {
|
|
476
|
+
this.stopLeak(user);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
const newBudget = currentBudget - 1;
|
|
480
|
+
if (newBudget === 0) {
|
|
481
|
+
this.budgetConsumed.delete(user);
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
this.budgetConsumed.set(user, newBudget);
|
|
485
|
+
};
|
|
486
|
+
restoreBudgetForUser();
|
|
487
|
+
const intervalHandle = setInterval(
|
|
488
|
+
restoreBudgetForUser,
|
|
489
|
+
this.options.budgetRestoreIntervalMs
|
|
490
|
+
);
|
|
491
|
+
this.intervalHandles.set(user, intervalHandle);
|
|
492
|
+
}
|
|
493
|
+
stopLeak(user) {
|
|
494
|
+
if (!this.intervalHandles.has(user)) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
clearInterval(this.intervalHandles.get(user));
|
|
498
|
+
this.intervalHandles.delete(user);
|
|
499
|
+
}
|
|
500
|
+
close() {
|
|
501
|
+
for (const user of this.intervalHandles.keys()) {
|
|
502
|
+
this.stopLeak(user);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
// codec/json.ts
|
|
508
|
+
var encoder = new TextEncoder();
|
|
509
|
+
var decoder = new TextDecoder();
|
|
510
|
+
function uint8ArrayToBase64(uint8Array) {
|
|
511
|
+
let binary = "";
|
|
512
|
+
uint8Array.forEach((byte) => {
|
|
513
|
+
binary += String.fromCharCode(byte);
|
|
514
|
+
});
|
|
515
|
+
return btoa(binary);
|
|
516
|
+
}
|
|
517
|
+
function base64ToUint8Array(base64) {
|
|
518
|
+
const binaryString = atob(base64);
|
|
519
|
+
const uint8Array = new Uint8Array(binaryString.length);
|
|
520
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
521
|
+
uint8Array[i] = binaryString.charCodeAt(i);
|
|
522
|
+
}
|
|
523
|
+
return uint8Array;
|
|
524
|
+
}
|
|
525
|
+
var NaiveJsonCodec = {
|
|
526
|
+
toBuffer: (obj) => {
|
|
527
|
+
return encoder.encode(
|
|
528
|
+
JSON.stringify(obj, function replacer(key) {
|
|
529
|
+
const val = this[key];
|
|
530
|
+
if (val instanceof Uint8Array) {
|
|
531
|
+
return { $t: uint8ArrayToBase64(val) };
|
|
532
|
+
} else {
|
|
533
|
+
return val;
|
|
534
|
+
}
|
|
535
|
+
})
|
|
536
|
+
);
|
|
537
|
+
},
|
|
538
|
+
fromBuffer: (buff) => {
|
|
539
|
+
try {
|
|
540
|
+
const parsed = JSON.parse(
|
|
541
|
+
decoder.decode(buff),
|
|
542
|
+
function reviver(_key, val) {
|
|
543
|
+
if (val?.$t) {
|
|
544
|
+
return base64ToUint8Array(val.$t);
|
|
545
|
+
} else {
|
|
546
|
+
return val;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
);
|
|
550
|
+
if (typeof parsed === "object")
|
|
551
|
+
return parsed;
|
|
552
|
+
return null;
|
|
553
|
+
} catch {
|
|
554
|
+
return null;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
|
|
496
559
|
// transport/transport.ts
|
|
497
|
-
var RECONNECT_JITTER_MAX_MS = 500;
|
|
498
|
-
var RECONNECT_INTERVAL_MS = 250;
|
|
499
560
|
var defaultTransportOptions = {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
561
|
+
heartbeatIntervalMs: 1e3,
|
|
562
|
+
heartbeatsUntilDead: 2,
|
|
563
|
+
sessionDisconnectGraceMs: 5e3,
|
|
564
|
+
codec: NaiveJsonCodec
|
|
565
|
+
};
|
|
566
|
+
var defaultConnectionRetryOptions = {
|
|
567
|
+
baseIntervalMs: 250,
|
|
568
|
+
maxJitterMs: 200,
|
|
569
|
+
maxBackoffMs: 32e3,
|
|
570
|
+
attemptBudgetCapacity: 15,
|
|
571
|
+
budgetRestoreIntervalMs: 200
|
|
572
|
+
};
|
|
573
|
+
var defaultClientTransportOptions = {
|
|
574
|
+
connectionRetryOptions: defaultConnectionRetryOptions,
|
|
575
|
+
...defaultTransportOptions
|
|
504
576
|
};
|
|
505
577
|
var Transport = class {
|
|
506
578
|
/**
|
|
@@ -775,14 +847,26 @@ var Transport = class {
|
|
|
775
847
|
}
|
|
776
848
|
};
|
|
777
849
|
var ClientTransport = class extends Transport {
|
|
850
|
+
/**
|
|
851
|
+
* The options for this transport.
|
|
852
|
+
*/
|
|
853
|
+
options;
|
|
778
854
|
/**
|
|
779
855
|
* The map of reconnect promises for each client ID.
|
|
780
856
|
*/
|
|
781
857
|
inflightConnectionPromises;
|
|
858
|
+
retryBudget;
|
|
782
859
|
tryReconnecting = true;
|
|
783
860
|
constructor(clientId, providedOptions) {
|
|
784
861
|
super(clientId, providedOptions);
|
|
862
|
+
this.options = {
|
|
863
|
+
...defaultClientTransportOptions,
|
|
864
|
+
...providedOptions
|
|
865
|
+
};
|
|
785
866
|
this.inflightConnectionPromises = /* @__PURE__ */ new Map();
|
|
867
|
+
this.retryBudget = new LeakyBucketRateLimit(
|
|
868
|
+
this.options.connectionRetryOptions
|
|
869
|
+
);
|
|
786
870
|
}
|
|
787
871
|
handleConnection(conn, to) {
|
|
788
872
|
if (this.state !== "open")
|
|
@@ -813,7 +897,10 @@ var ClientTransport = class extends Transport {
|
|
|
813
897
|
log?.info(
|
|
814
898
|
`${this.clientId} -- connection (id: ${conn.debugId}) to ${to} disconnected`
|
|
815
899
|
);
|
|
816
|
-
|
|
900
|
+
this.inflightConnectionPromises.delete(to);
|
|
901
|
+
if (this.tryReconnecting) {
|
|
902
|
+
void this.connect(to);
|
|
903
|
+
}
|
|
817
904
|
});
|
|
818
905
|
conn.addErrorListener((err) => {
|
|
819
906
|
log?.warn(
|
|
@@ -864,41 +951,64 @@ var ClientTransport = class extends Transport {
|
|
|
864
951
|
* Manually attempts to connect to a client.
|
|
865
952
|
* @param to The client ID of the node to connect to.
|
|
866
953
|
*/
|
|
867
|
-
async connect(to
|
|
868
|
-
|
|
954
|
+
async connect(to) {
|
|
955
|
+
const canProceedWithConnection = () => this.state === "open";
|
|
956
|
+
if (!canProceedWithConnection()) {
|
|
869
957
|
log?.info(
|
|
870
|
-
`${this.clientId} -- transport state is no longer open,
|
|
958
|
+
`${this.clientId} -- transport state is no longer open, cancelling attempt to connect to ${to}`
|
|
871
959
|
);
|
|
872
960
|
return;
|
|
873
961
|
}
|
|
874
962
|
let reconnectPromise = this.inflightConnectionPromises.get(to);
|
|
875
963
|
if (!reconnectPromise) {
|
|
876
|
-
|
|
964
|
+
log?.info(`${this.clientId} -- attempting connection to ${to}`);
|
|
965
|
+
const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
|
|
966
|
+
if (!this.retryBudget.hasBudget(to)) {
|
|
967
|
+
const errMsg = `not attempting to connect to ${to}, retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
|
|
968
|
+
log?.warn(`${this.clientId} -- ${errMsg}`);
|
|
969
|
+
this.protocolError(ProtocolError.RetriesExceeded, errMsg);
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
let sleep = Promise.resolve();
|
|
973
|
+
const backoffMs = this.retryBudget.getBackoffMs(to);
|
|
974
|
+
if (backoffMs > 0) {
|
|
975
|
+
sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
976
|
+
}
|
|
977
|
+
this.retryBudget.consumeBudget(to);
|
|
978
|
+
reconnectPromise = sleep.then(() => {
|
|
979
|
+
if (!canProceedWithConnection()) {
|
|
980
|
+
throw new Error("transport state is no longer open");
|
|
981
|
+
}
|
|
982
|
+
}).then(() => this.createNewOutgoingConnection(to)).then((conn) => {
|
|
983
|
+
if (!canProceedWithConnection()) {
|
|
984
|
+
log?.info(
|
|
985
|
+
`${this.clientId} -- transport state is no longer open, closing pre-handshake connection (id: ${conn.debugId}) to ${to}`
|
|
986
|
+
);
|
|
987
|
+
conn.close();
|
|
988
|
+
throw new Error("transport state is no longer open");
|
|
989
|
+
}
|
|
990
|
+
this.retryBudget.startRestoringBudget(to);
|
|
877
991
|
this.sendHandshake(to, conn);
|
|
878
992
|
return conn;
|
|
879
993
|
});
|
|
880
994
|
this.inflightConnectionPromises.set(to, reconnectPromise);
|
|
995
|
+
} else {
|
|
996
|
+
log?.info(
|
|
997
|
+
`${this.clientId} -- attempting connection to ${to} (reusing previous attempt)`
|
|
998
|
+
);
|
|
881
999
|
}
|
|
882
1000
|
try {
|
|
883
1001
|
await reconnectPromise;
|
|
884
1002
|
} catch (error) {
|
|
885
|
-
const errStr = coerceErrorString(error);
|
|
886
1003
|
this.inflightConnectionPromises.delete(to);
|
|
887
|
-
const
|
|
888
|
-
if (!
|
|
889
|
-
|
|
890
|
-
if (attempt >= this.options.retryAttemptsMax) {
|
|
891
|
-
const errMsg = `connection to ${to} failed after ${attempt} attempts (${errStr}), giving up`;
|
|
892
|
-
log?.error(`${this.clientId} -- ${errMsg}`);
|
|
893
|
-
this.protocolError(ProtocolError.RetriesExceeded, errMsg);
|
|
894
|
-
return;
|
|
1004
|
+
const errStr = coerceErrorString(error);
|
|
1005
|
+
if (!this.tryReconnecting || !canProceedWithConnection()) {
|
|
1006
|
+
log?.warn(`${this.clientId} -- connection to ${to} failed (${errStr})`);
|
|
895
1007
|
} else {
|
|
896
|
-
const jitter = Math.floor(Math.random() * this.options.retryJitterMs);
|
|
897
|
-
const backoffMs = this.options.retryIntervalMs * 2 ** attempt + jitter;
|
|
898
1008
|
log?.warn(
|
|
899
|
-
`${this.clientId} -- connection to ${to} failed (${errStr}),
|
|
1009
|
+
`${this.clientId} -- connection to ${to} failed (${errStr}), retrying`
|
|
900
1010
|
);
|
|
901
|
-
|
|
1011
|
+
return this.connect(to);
|
|
902
1012
|
}
|
|
903
1013
|
}
|
|
904
1014
|
}
|
|
@@ -911,9 +1021,9 @@ var ClientTransport = class extends Transport {
|
|
|
911
1021
|
log?.debug(`${this.clientId} -- sending handshake request to ${to}`);
|
|
912
1022
|
conn.send(this.codec.toBuffer(requestMsg));
|
|
913
1023
|
}
|
|
914
|
-
|
|
915
|
-
this.
|
|
916
|
-
super.
|
|
1024
|
+
close() {
|
|
1025
|
+
this.retryBudget.close();
|
|
1026
|
+
super.close();
|
|
917
1027
|
}
|
|
918
1028
|
};
|
|
919
1029
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClientTransport, c as
|
|
2
|
-
import { U as UdsConnection } from '../../../connection-
|
|
1
|
+
import { a as ClientTransport, c as ProvidedClientTransportOptions, b as TransportClientId } from '../../../index-2e402bb8.js';
|
|
2
|
+
import { U as UdsConnection } from '../../../connection-94896f3b.js';
|
|
3
3
|
import '../../../types-3e5768ec.js';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import 'node:net';
|
|
@@ -7,7 +7,7 @@ import 'node:stream';
|
|
|
7
7
|
|
|
8
8
|
declare class UnixDomainSocketClientTransport extends ClientTransport<UdsConnection> {
|
|
9
9
|
path: string;
|
|
10
|
-
constructor(socketPath: string, clientId: string, providedOptions?:
|
|
10
|
+
constructor(socketPath: string, clientId: string, providedOptions?: ProvidedClientTransportOptions);
|
|
11
11
|
createNewOutgoingConnection(to: TransportClientId): Promise<UdsConnection>;
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClientTransport, c as
|
|
2
|
-
import { U as UdsConnection } from '../../../connection-
|
|
1
|
+
import { a as ClientTransport, c as ProvidedClientTransportOptions, b as TransportClientId } from '../../../index-2e402bb8.js';
|
|
2
|
+
import { U as UdsConnection } from '../../../connection-94896f3b.js';
|
|
3
3
|
import '../../../types-3e5768ec.js';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import 'node:net';
|
|
@@ -7,7 +7,7 @@ import 'node:stream';
|
|
|
7
7
|
|
|
8
8
|
declare class UnixDomainSocketClientTransport extends ClientTransport<UdsConnection> {
|
|
9
9
|
path: string;
|
|
10
|
-
constructor(socketPath: string, clientId: string, providedOptions?:
|
|
10
|
+
constructor(socketPath: string, clientId: string, providedOptions?: ProvidedClientTransportOptions);
|
|
11
11
|
createNewOutgoingConnection(to: TransportClientId): Promise<UdsConnection>;
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UdsConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-MXHIHC3U.js";
|
|
4
4
|
import {
|
|
5
5
|
ClientTransport
|
|
6
|
-
} from "../../../chunk-
|
|
6
|
+
} from "../../../chunk-5XMMDOLH.js";
|
|
7
7
|
import "../../../chunk-GFRAOY75.js";
|
|
8
8
|
import {
|
|
9
9
|
log
|
|
@@ -142,60 +142,6 @@ var EventDispatcher = class {
|
|
|
142
142
|
|
|
143
143
|
// transport/session.ts
|
|
144
144
|
var import_nanoid2 = require("nanoid");
|
|
145
|
-
|
|
146
|
-
// codec/json.ts
|
|
147
|
-
var encoder = new TextEncoder();
|
|
148
|
-
var decoder = new TextDecoder();
|
|
149
|
-
function uint8ArrayToBase64(uint8Array) {
|
|
150
|
-
let binary = "";
|
|
151
|
-
uint8Array.forEach((byte) => {
|
|
152
|
-
binary += String.fromCharCode(byte);
|
|
153
|
-
});
|
|
154
|
-
return btoa(binary);
|
|
155
|
-
}
|
|
156
|
-
function base64ToUint8Array(base64) {
|
|
157
|
-
const binaryString = atob(base64);
|
|
158
|
-
const uint8Array = new Uint8Array(binaryString.length);
|
|
159
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
160
|
-
uint8Array[i] = binaryString.charCodeAt(i);
|
|
161
|
-
}
|
|
162
|
-
return uint8Array;
|
|
163
|
-
}
|
|
164
|
-
var NaiveJsonCodec = {
|
|
165
|
-
toBuffer: (obj) => {
|
|
166
|
-
return encoder.encode(
|
|
167
|
-
JSON.stringify(obj, function replacer(key) {
|
|
168
|
-
const val = this[key];
|
|
169
|
-
if (val instanceof Uint8Array) {
|
|
170
|
-
return { $t: uint8ArrayToBase64(val) };
|
|
171
|
-
} else {
|
|
172
|
-
return val;
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
);
|
|
176
|
-
},
|
|
177
|
-
fromBuffer: (buff) => {
|
|
178
|
-
try {
|
|
179
|
-
const parsed = JSON.parse(
|
|
180
|
-
decoder.decode(buff),
|
|
181
|
-
function reviver(_key, val) {
|
|
182
|
-
if (val?.$t) {
|
|
183
|
-
return base64ToUint8Array(val.$t);
|
|
184
|
-
} else {
|
|
185
|
-
return val;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
);
|
|
189
|
-
if (typeof parsed === "object")
|
|
190
|
-
return parsed;
|
|
191
|
-
return null;
|
|
192
|
-
} catch {
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
// transport/session.ts
|
|
199
145
|
var nanoid2 = (0, import_nanoid2.customAlphabet)("1234567890abcdefghijklmnopqrstuvxyz", 6);
|
|
200
146
|
var unsafeId = () => nanoid2();
|
|
201
147
|
var Connection = class {
|
|
@@ -204,15 +150,6 @@ var Connection = class {
|
|
|
204
150
|
this.debugId = `conn-${unsafeId()}`;
|
|
205
151
|
}
|
|
206
152
|
};
|
|
207
|
-
var HEARTBEAT_INTERVAL_MS = 1e3;
|
|
208
|
-
var HEARTBEATS_TILL_DEAD = 2;
|
|
209
|
-
var SESSION_DISCONNECT_GRACE_MS = 5e3;
|
|
210
|
-
var defaultSessionOptions = {
|
|
211
|
-
heartbeatIntervalMs: HEARTBEAT_INTERVAL_MS,
|
|
212
|
-
heartbeatsUntilDead: HEARTBEATS_TILL_DEAD,
|
|
213
|
-
sessionDisconnectGraceMs: SESSION_DISCONNECT_GRACE_MS,
|
|
214
|
-
codec: NaiveJsonCodec
|
|
215
|
-
};
|
|
216
153
|
var Session = class {
|
|
217
154
|
codec;
|
|
218
155
|
options;
|
|
@@ -407,14 +344,75 @@ function coerceErrorString(err) {
|
|
|
407
344
|
return `[coerced to error] ${String(err)}`;
|
|
408
345
|
}
|
|
409
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
|
+
|
|
410
399
|
// transport/transport.ts
|
|
411
|
-
var RECONNECT_JITTER_MAX_MS = 500;
|
|
412
|
-
var RECONNECT_INTERVAL_MS = 250;
|
|
413
400
|
var defaultTransportOptions = {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
401
|
+
heartbeatIntervalMs: 1e3,
|
|
402
|
+
heartbeatsUntilDead: 2,
|
|
403
|
+
sessionDisconnectGraceMs: 5e3,
|
|
404
|
+
codec: NaiveJsonCodec
|
|
405
|
+
};
|
|
406
|
+
var defaultConnectionRetryOptions = {
|
|
407
|
+
baseIntervalMs: 250,
|
|
408
|
+
maxJitterMs: 200,
|
|
409
|
+
maxBackoffMs: 32e3,
|
|
410
|
+
attemptBudgetCapacity: 15,
|
|
411
|
+
budgetRestoreIntervalMs: 200
|
|
412
|
+
};
|
|
413
|
+
var defaultClientTransportOptions = {
|
|
414
|
+
connectionRetryOptions: defaultConnectionRetryOptions,
|
|
415
|
+
...defaultTransportOptions
|
|
418
416
|
};
|
|
419
417
|
var Transport = class {
|
|
420
418
|
/**
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Server, Socket } from 'node:net';
|
|
2
|
-
import { S as ServerTransport, b as TransportClientId,
|
|
3
|
-
import { U as UdsConnection } from '../../../connection-
|
|
2
|
+
import { S as ServerTransport, b as TransportClientId, d as ProvidedTransportOptions } from '../../../index-2e402bb8.js';
|
|
3
|
+
import { U as UdsConnection } from '../../../connection-94896f3b.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
import 'node:stream';
|
|
7
7
|
|
|
8
8
|
declare class UnixDomainSocketServerTransport extends ServerTransport<UdsConnection> {
|
|
9
9
|
server: Server;
|
|
10
|
-
constructor(server: Server, clientId: TransportClientId, providedOptions?: Partial<
|
|
10
|
+
constructor(server: Server, clientId: TransportClientId, providedOptions?: Partial<ProvidedTransportOptions>);
|
|
11
11
|
connectionHandler: (sock: Socket) => void;
|
|
12
12
|
close(): void;
|
|
13
13
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Server, Socket } from 'node:net';
|
|
2
|
-
import { S as ServerTransport, b as TransportClientId,
|
|
3
|
-
import { U as UdsConnection } from '../../../connection-
|
|
2
|
+
import { S as ServerTransport, b as TransportClientId, d as ProvidedTransportOptions } from '../../../index-2e402bb8.js';
|
|
3
|
+
import { U as UdsConnection } from '../../../connection-94896f3b.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
import 'node:stream';
|
|
7
7
|
|
|
8
8
|
declare class UnixDomainSocketServerTransport extends ServerTransport<UdsConnection> {
|
|
9
9
|
server: Server;
|
|
10
|
-
constructor(server: Server, clientId: TransportClientId, providedOptions?: Partial<
|
|
10
|
+
constructor(server: Server, clientId: TransportClientId, providedOptions?: Partial<ProvidedTransportOptions>);
|
|
11
11
|
connectionHandler: (sock: Socket) => void;
|
|
12
12
|
close(): void;
|
|
13
13
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UdsConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-MXHIHC3U.js";
|
|
4
4
|
import {
|
|
5
5
|
ServerTransport
|
|
6
|
-
} from "../../../chunk-
|
|
6
|
+
} from "../../../chunk-5XMMDOLH.js";
|
|
7
7
|
import "../../../chunk-GFRAOY75.js";
|
|
8
8
|
import {
|
|
9
9
|
log
|