@dxos/edge-client 0.8.4-main.dedc0f3 → 0.8.4-main.ead640a
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/dist/lib/browser/index.mjs +162 -56
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +162 -56
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs.map +2 -2
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/edge-http-client.d.ts.map +1 -1
- package/dist/types/src/edge-ws-connection.d.ts +19 -0
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/http-client.d.ts +10 -7
- package/dist/types/src/http-client.d.ts.map +1 -1
- package/dist/types/src/testing/test-utils.d.ts +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -15
- package/src/edge-client.test.ts +4 -4
- package/src/edge-client.ts +36 -5
- package/src/edge-http-client.ts +5 -3
- package/src/edge-ws-connection.ts +118 -5
- package/src/http-client.test.ts +6 -4
- package/src/http-client.ts +13 -7
- package/src/testing/test-utils.ts +3 -3
|
@@ -123,7 +123,7 @@ var createStubEdgeIdentity = () => {
|
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
// src/edge-client.ts
|
|
126
|
-
import { Event, PersistentLifecycle, Trigger, TriggerState, scheduleMicroTask } from "@dxos/async";
|
|
126
|
+
import { Event, PersistentLifecycle, Trigger, TriggerState, scheduleMicroTask, scheduleTaskInterval as scheduleTaskInterval2 } from "@dxos/async";
|
|
127
127
|
import { Resource as Resource2 } from "@dxos/context";
|
|
128
128
|
import { log as log2, logInfo as logInfo2 } from "@dxos/log";
|
|
129
129
|
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -207,10 +207,28 @@ var EdgeWsConnection = class extends Resource {
|
|
|
207
207
|
device: this._identity.peerKey
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
|
+
get rtt() {
|
|
211
|
+
return this._rtt;
|
|
212
|
+
}
|
|
213
|
+
get uptime() {
|
|
214
|
+
return this._openTimestamp ? (Date.now() - this._openTimestamp) / 1e3 : 0;
|
|
215
|
+
}
|
|
216
|
+
get uploadRate() {
|
|
217
|
+
return this._uploadRate;
|
|
218
|
+
}
|
|
219
|
+
get downloadRate() {
|
|
220
|
+
return this._downloadRate;
|
|
221
|
+
}
|
|
222
|
+
get messagesSent() {
|
|
223
|
+
return this._messagesSent;
|
|
224
|
+
}
|
|
225
|
+
get messagesReceived() {
|
|
226
|
+
return this._messagesReceived;
|
|
227
|
+
}
|
|
210
228
|
send(message) {
|
|
211
229
|
invariant3(this._ws, void 0, {
|
|
212
230
|
F: __dxlog_file3,
|
|
213
|
-
L:
|
|
231
|
+
L: 93,
|
|
214
232
|
S: this,
|
|
215
233
|
A: [
|
|
216
234
|
"this._ws",
|
|
@@ -219,7 +237,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
219
237
|
});
|
|
220
238
|
invariant3(this._wsMuxer, void 0, {
|
|
221
239
|
F: __dxlog_file3,
|
|
222
|
-
L:
|
|
240
|
+
L: 94,
|
|
223
241
|
S: this,
|
|
224
242
|
A: [
|
|
225
243
|
"this._wsMuxer",
|
|
@@ -231,10 +249,11 @@ var EdgeWsConnection = class extends Resource {
|
|
|
231
249
|
payload: protocol.getPayloadType(message)
|
|
232
250
|
}, {
|
|
233
251
|
F: __dxlog_file3,
|
|
234
|
-
L:
|
|
252
|
+
L: 95,
|
|
235
253
|
S: this,
|
|
236
254
|
C: (f, a) => f(...a)
|
|
237
255
|
});
|
|
256
|
+
this._messagesSent++;
|
|
238
257
|
if (this._ws?.protocol.includes(EdgeWebsocketProtocol.V0)) {
|
|
239
258
|
const binary = buf.toBinary(MessageSchema, message);
|
|
240
259
|
if (binary.length > CLOUDFLARE_MESSAGE_MAX_BYTES) {
|
|
@@ -244,17 +263,20 @@ var EdgeWsConnection = class extends Resource {
|
|
|
244
263
|
payload: protocol.getPayloadType(message)
|
|
245
264
|
}, {
|
|
246
265
|
F: __dxlog_file3,
|
|
247
|
-
L:
|
|
266
|
+
L: 100,
|
|
248
267
|
S: this,
|
|
249
268
|
C: (f, a) => f(...a)
|
|
250
269
|
});
|
|
251
270
|
return;
|
|
252
271
|
}
|
|
272
|
+
this._recordBytes(binary.byteLength, 0);
|
|
253
273
|
this._ws.send(binary);
|
|
254
274
|
} else {
|
|
275
|
+
const binary = buf.toBinary(MessageSchema, message);
|
|
276
|
+
this._recordBytes(binary.byteLength, 0);
|
|
255
277
|
this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, {
|
|
256
278
|
F: __dxlog_file3,
|
|
257
|
-
L:
|
|
279
|
+
L: 113,
|
|
258
280
|
S: this,
|
|
259
281
|
C: (f, a) => f(...a)
|
|
260
282
|
}));
|
|
@@ -276,18 +298,20 @@ var EdgeWsConnection = class extends Resource {
|
|
|
276
298
|
if (this.isOpen) {
|
|
277
299
|
log("connected", void 0, {
|
|
278
300
|
F: __dxlog_file3,
|
|
279
|
-
L:
|
|
301
|
+
L: 130,
|
|
280
302
|
S: this,
|
|
281
303
|
C: (f, a) => f(...a)
|
|
282
304
|
});
|
|
305
|
+
this._openTimestamp = Date.now();
|
|
283
306
|
this._callbacks.onConnected();
|
|
284
307
|
this._scheduleHeartbeats();
|
|
308
|
+
this._scheduleRateCalculation();
|
|
285
309
|
} else {
|
|
286
310
|
log.verbose("connected after becoming inactive", {
|
|
287
311
|
currentIdentity: this._identity
|
|
288
312
|
}, {
|
|
289
313
|
F: __dxlog_file3,
|
|
290
|
-
L:
|
|
314
|
+
L: 136,
|
|
291
315
|
S: this,
|
|
292
316
|
C: (f, a) => f(...a)
|
|
293
317
|
});
|
|
@@ -295,12 +319,12 @@ var EdgeWsConnection = class extends Resource {
|
|
|
295
319
|
};
|
|
296
320
|
this._ws.onclose = (event) => {
|
|
297
321
|
if (this.isOpen) {
|
|
298
|
-
log.warn("disconnected
|
|
322
|
+
log.warn("server disconnected", {
|
|
299
323
|
code: event.code,
|
|
300
324
|
reason: event.reason
|
|
301
325
|
}, {
|
|
302
326
|
F: __dxlog_file3,
|
|
303
|
-
L:
|
|
327
|
+
L: 141,
|
|
304
328
|
S: this,
|
|
305
329
|
C: (f, a) => f(...a)
|
|
306
330
|
});
|
|
@@ -315,7 +339,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
315
339
|
info: event.message
|
|
316
340
|
}, {
|
|
317
341
|
F: __dxlog_file3,
|
|
318
|
-
L:
|
|
342
|
+
L: 148,
|
|
319
343
|
S: this,
|
|
320
344
|
C: (f, a) => f(...a)
|
|
321
345
|
});
|
|
@@ -325,7 +349,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
325
349
|
error: event.error
|
|
326
350
|
}, {
|
|
327
351
|
F: __dxlog_file3,
|
|
328
|
-
L:
|
|
352
|
+
L: 151,
|
|
329
353
|
S: this,
|
|
330
354
|
C: (f, a) => f(...a)
|
|
331
355
|
});
|
|
@@ -337,7 +361,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
337
361
|
event: event.type
|
|
338
362
|
}, {
|
|
339
363
|
F: __dxlog_file3,
|
|
340
|
-
L:
|
|
364
|
+
L: 159,
|
|
341
365
|
S: this,
|
|
342
366
|
C: (f, a) => f(...a)
|
|
343
367
|
});
|
|
@@ -345,13 +369,19 @@ var EdgeWsConnection = class extends Resource {
|
|
|
345
369
|
}
|
|
346
370
|
this._lastReceivedMessageTimestamp = Date.now();
|
|
347
371
|
if (event.data === "__pong__") {
|
|
372
|
+
if (this._pingTimestamp) {
|
|
373
|
+
this._rtt = Date.now() - this._pingTimestamp;
|
|
374
|
+
this._pingTimestamp = void 0;
|
|
375
|
+
}
|
|
348
376
|
this._rescheduleHeartbeatTimeout();
|
|
349
377
|
return;
|
|
350
378
|
}
|
|
351
379
|
const bytes = await toUint8Array(event.data);
|
|
380
|
+
this._recordBytes(0, bytes.byteLength);
|
|
352
381
|
if (!this.isOpen) {
|
|
353
382
|
return;
|
|
354
383
|
}
|
|
384
|
+
this._messagesReceived++;
|
|
355
385
|
const message = this._ws?.protocol?.includes(EdgeWebsocketProtocol.V0) ? buf.fromBinary(MessageSchema, bytes) : muxer.receiveData(bytes);
|
|
356
386
|
if (message) {
|
|
357
387
|
log("received", {
|
|
@@ -359,7 +389,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
359
389
|
payload: protocol.getPayloadType(message)
|
|
360
390
|
}, {
|
|
361
391
|
F: __dxlog_file3,
|
|
362
|
-
L:
|
|
392
|
+
L: 185,
|
|
363
393
|
S: this,
|
|
364
394
|
C: (f, a) => f(...a)
|
|
365
395
|
});
|
|
@@ -379,11 +409,11 @@ var EdgeWsConnection = class extends Resource {
|
|
|
379
409
|
if (err instanceof Error && err.message.includes("WebSocket is closed before the connection is established.")) {
|
|
380
410
|
return;
|
|
381
411
|
}
|
|
382
|
-
log.warn("
|
|
412
|
+
log.warn("error closing websocket", {
|
|
383
413
|
err
|
|
384
414
|
}, {
|
|
385
415
|
F: __dxlog_file3,
|
|
386
|
-
L:
|
|
416
|
+
L: 203,
|
|
387
417
|
S: this,
|
|
388
418
|
C: (f, a) => f(...a)
|
|
389
419
|
});
|
|
@@ -392,7 +422,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
392
422
|
_scheduleHeartbeats() {
|
|
393
423
|
invariant3(this._ws, void 0, {
|
|
394
424
|
F: __dxlog_file3,
|
|
395
|
-
L:
|
|
425
|
+
L: 208,
|
|
396
426
|
S: this,
|
|
397
427
|
A: [
|
|
398
428
|
"this._ws",
|
|
@@ -400,8 +430,10 @@ var EdgeWsConnection = class extends Resource {
|
|
|
400
430
|
]
|
|
401
431
|
});
|
|
402
432
|
scheduleTaskInterval(this._ctx, async () => {
|
|
433
|
+
this._pingTimestamp = Date.now();
|
|
403
434
|
this._ws?.send("__ping__");
|
|
404
435
|
}, SIGNAL_KEEPALIVE_INTERVAL);
|
|
436
|
+
this._pingTimestamp = Date.now();
|
|
405
437
|
this._ws.send("__ping__");
|
|
406
438
|
this._rescheduleHeartbeatTimeout();
|
|
407
439
|
}
|
|
@@ -412,7 +444,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
412
444
|
void this._inactivityTimeoutCtx?.dispose();
|
|
413
445
|
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
414
446
|
F: __dxlog_file3,
|
|
415
|
-
L:
|
|
447
|
+
L: 229
|
|
416
448
|
});
|
|
417
449
|
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
418
450
|
if (this.isOpen) {
|
|
@@ -421,7 +453,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
421
453
|
lastReceivedMessageTimestamp: this._lastReceivedMessageTimestamp
|
|
422
454
|
}, {
|
|
423
455
|
F: __dxlog_file3,
|
|
424
|
-
L:
|
|
456
|
+
L: 235,
|
|
425
457
|
S: this,
|
|
426
458
|
C: (f, a) => f(...a)
|
|
427
459
|
});
|
|
@@ -432,8 +464,61 @@ var EdgeWsConnection = class extends Resource {
|
|
|
432
464
|
}
|
|
433
465
|
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
434
466
|
}
|
|
467
|
+
_recordBytes(sent, received) {
|
|
468
|
+
const now = Date.now();
|
|
469
|
+
const currentSecond = Math.floor(now / 1e3) * 1e3;
|
|
470
|
+
const existingSample = this._bytesSamples.find((s) => Math.floor(s.timestamp / 1e3) * 1e3 === currentSecond);
|
|
471
|
+
if (existingSample) {
|
|
472
|
+
existingSample.sent += sent;
|
|
473
|
+
existingSample.received += received;
|
|
474
|
+
} else {
|
|
475
|
+
this._bytesSamples.push({
|
|
476
|
+
timestamp: now,
|
|
477
|
+
sent,
|
|
478
|
+
received
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
_scheduleRateCalculation() {
|
|
483
|
+
scheduleTaskInterval(this._ctx, async () => {
|
|
484
|
+
this._calculateRates();
|
|
485
|
+
}, this._rateUpdateInterval);
|
|
486
|
+
this._calculateRates();
|
|
487
|
+
}
|
|
488
|
+
_calculateRates() {
|
|
489
|
+
const now = Date.now();
|
|
490
|
+
const cutoff = now - this._rateWindow;
|
|
491
|
+
this._bytesSamples = this._bytesSamples.filter((s) => s.timestamp > cutoff);
|
|
492
|
+
if (this._bytesSamples.length === 0) {
|
|
493
|
+
this._uploadRate = 0;
|
|
494
|
+
this._downloadRate = 0;
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
let totalSent = 0;
|
|
498
|
+
let totalReceived = 0;
|
|
499
|
+
const oldestTimestamp = Math.min(...this._bytesSamples.map((s) => s.timestamp));
|
|
500
|
+
const timeSpan = (now - oldestTimestamp) / 1e3;
|
|
501
|
+
for (const sample of this._bytesSamples) {
|
|
502
|
+
totalSent += sample.sent;
|
|
503
|
+
totalReceived += sample.received;
|
|
504
|
+
}
|
|
505
|
+
this._uploadRate = timeSpan > 0 ? Math.round(totalSent / timeSpan) : 0;
|
|
506
|
+
this._downloadRate = timeSpan > 0 ? Math.round(totalReceived / timeSpan) : 0;
|
|
507
|
+
}
|
|
435
508
|
constructor(_identity, _connectionInfo, _callbacks) {
|
|
436
|
-
super(), _define_property(this, "_identity", void 0), _define_property(this, "_connectionInfo", void 0), _define_property(this, "_callbacks", void 0), _define_property(this, "_inactivityTimeoutCtx", void 0), _define_property(this, "_ws", void 0), _define_property(this, "_wsMuxer", void 0), _define_property(this, "_lastReceivedMessageTimestamp", void 0), this
|
|
509
|
+
super(), _define_property(this, "_identity", void 0), _define_property(this, "_connectionInfo", void 0), _define_property(this, "_callbacks", void 0), _define_property(this, "_inactivityTimeoutCtx", void 0), _define_property(this, "_ws", void 0), _define_property(this, "_wsMuxer", void 0), _define_property(this, "_lastReceivedMessageTimestamp", void 0), _define_property(this, "_openTimestamp", void 0), // Latency tracking.
|
|
510
|
+
_define_property(this, "_pingTimestamp", void 0), _define_property(this, "_rtt", void 0), // Rate tracking with sliding window.
|
|
511
|
+
_define_property(this, "_uploadRate", void 0), _define_property(this, "_downloadRate", void 0), _define_property(
|
|
512
|
+
this,
|
|
513
|
+
"_rateWindow",
|
|
514
|
+
void 0
|
|
515
|
+
// 10 second sliding window.
|
|
516
|
+
), _define_property(
|
|
517
|
+
this,
|
|
518
|
+
"_rateUpdateInterval",
|
|
519
|
+
void 0
|
|
520
|
+
// Update rates every second.
|
|
521
|
+
), _define_property(this, "_bytesSamples", void 0), _define_property(this, "_messagesSent", void 0), _define_property(this, "_messagesReceived", void 0), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks, this._lastReceivedMessageTimestamp = Date.now(), this._rtt = 0, this._uploadRate = 0, this._downloadRate = 0, this._rateWindow = 1e4, this._rateUpdateInterval = 1e3, this._bytesSamples = [], this._messagesSent = 0, this._messagesReceived = 0;
|
|
437
522
|
}
|
|
438
523
|
};
|
|
439
524
|
_ts_decorate([
|
|
@@ -482,6 +567,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
482
567
|
}
|
|
483
568
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
484
569
|
var DEFAULT_TIMEOUT = 1e4;
|
|
570
|
+
var STATUS_REFRESH_INTERVAL = 1e3;
|
|
485
571
|
var EdgeClient = class extends Resource2 {
|
|
486
572
|
get info() {
|
|
487
573
|
return {
|
|
@@ -492,7 +578,15 @@ var EdgeClient = class extends Resource2 {
|
|
|
492
578
|
};
|
|
493
579
|
}
|
|
494
580
|
get status() {
|
|
495
|
-
return
|
|
581
|
+
return {
|
|
582
|
+
state: Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED ? EdgeStatus.ConnectionState.CONNECTED : EdgeStatus.ConnectionState.NOT_CONNECTED,
|
|
583
|
+
uptime: this._currentConnection?.uptime ?? 0,
|
|
584
|
+
rtt: this._currentConnection?.rtt ?? 0,
|
|
585
|
+
rateBytesUp: this._currentConnection?.uploadRate ?? 0,
|
|
586
|
+
rateBytesDown: this._currentConnection?.downloadRate ?? 0,
|
|
587
|
+
messagesSent: this._currentConnection?.messagesSent ?? 0,
|
|
588
|
+
messagesReceived: this._currentConnection?.messagesReceived ?? 0
|
|
589
|
+
};
|
|
496
590
|
}
|
|
497
591
|
get identityKey() {
|
|
498
592
|
return this._identity.identityKey;
|
|
@@ -507,7 +601,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
507
601
|
oldIdentity: this._identity
|
|
508
602
|
}, {
|
|
509
603
|
F: __dxlog_file4,
|
|
510
|
-
L:
|
|
604
|
+
L: 118,
|
|
511
605
|
S: this,
|
|
512
606
|
C: (f, a) => f(...a)
|
|
513
607
|
});
|
|
@@ -524,7 +618,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
524
618
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
525
619
|
log2("waiting for websocket", void 0, {
|
|
526
620
|
F: __dxlog_file4,
|
|
527
|
-
L:
|
|
621
|
+
L: 131,
|
|
528
622
|
S: this,
|
|
529
623
|
C: (f, a) => f(...a)
|
|
530
624
|
});
|
|
@@ -554,7 +648,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
554
648
|
} catch (error) {
|
|
555
649
|
log2.catch(error, void 0, {
|
|
556
650
|
F: __dxlog_file4,
|
|
557
|
-
L:
|
|
651
|
+
L: 164,
|
|
558
652
|
S: this,
|
|
559
653
|
C: (f, a) => f(...a)
|
|
560
654
|
});
|
|
@@ -572,7 +666,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
572
666
|
info: this.info
|
|
573
667
|
}, {
|
|
574
668
|
F: __dxlog_file4,
|
|
575
|
-
L:
|
|
669
|
+
L: 177,
|
|
576
670
|
S: this,
|
|
577
671
|
C: (f, a) => f(...a)
|
|
578
672
|
});
|
|
@@ -581,11 +675,17 @@ var EdgeClient = class extends Resource2 {
|
|
|
581
675
|
err
|
|
582
676
|
}, {
|
|
583
677
|
F: __dxlog_file4,
|
|
584
|
-
L:
|
|
678
|
+
L: 179,
|
|
585
679
|
S: this,
|
|
586
680
|
C: (f, a) => f(...a)
|
|
587
681
|
});
|
|
588
682
|
});
|
|
683
|
+
scheduleTaskInterval2(this._ctx, async () => {
|
|
684
|
+
if (!this._currentConnection) {
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
this.statusChanged.emit(this.status);
|
|
688
|
+
}, STATUS_REFRESH_INTERVAL);
|
|
589
689
|
}
|
|
590
690
|
/**
|
|
591
691
|
* Close connection and free resources.
|
|
@@ -595,7 +695,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
595
695
|
peerKey: this._identity.peerKey
|
|
596
696
|
}, {
|
|
597
697
|
F: __dxlog_file4,
|
|
598
|
-
L:
|
|
698
|
+
L: 199,
|
|
599
699
|
S: this,
|
|
600
700
|
C: (f, a) => f(...a)
|
|
601
701
|
});
|
|
@@ -612,7 +712,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
612
712
|
if (this._identity !== identity) {
|
|
613
713
|
log2("identity changed during auth header request", void 0, {
|
|
614
714
|
F: __dxlog_file4,
|
|
615
|
-
L:
|
|
715
|
+
L: 213,
|
|
616
716
|
S: this,
|
|
617
717
|
C: (f, a) => f(...a)
|
|
618
718
|
});
|
|
@@ -625,7 +725,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
625
725
|
protocolHeader
|
|
626
726
|
}, {
|
|
627
727
|
F: __dxlog_file4,
|
|
628
|
-
L:
|
|
728
|
+
L: 219,
|
|
629
729
|
S: this,
|
|
630
730
|
C: (f, a) => f(...a)
|
|
631
731
|
});
|
|
@@ -640,7 +740,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
640
740
|
} else {
|
|
641
741
|
log2.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
642
742
|
F: __dxlog_file4,
|
|
643
|
-
L:
|
|
743
|
+
L: 229,
|
|
644
744
|
S: this,
|
|
645
745
|
C: (f, a) => f(...a)
|
|
646
746
|
});
|
|
@@ -653,7 +753,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
653
753
|
} else {
|
|
654
754
|
log2.verbose("restart requested by inactive connection", void 0, {
|
|
655
755
|
F: __dxlog_file4,
|
|
656
|
-
L:
|
|
756
|
+
L: 237,
|
|
657
757
|
S: this,
|
|
658
758
|
C: (f, a) => f(...a)
|
|
659
759
|
});
|
|
@@ -669,7 +769,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
669
769
|
type: message.payload?.typeUrl
|
|
670
770
|
}, {
|
|
671
771
|
F: __dxlog_file4,
|
|
672
|
-
L:
|
|
772
|
+
L: 245,
|
|
673
773
|
S: this,
|
|
674
774
|
C: (f, a) => f(...a)
|
|
675
775
|
});
|
|
@@ -706,7 +806,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
706
806
|
err
|
|
707
807
|
}, {
|
|
708
808
|
F: __dxlog_file4,
|
|
709
|
-
L:
|
|
809
|
+
L: 280,
|
|
710
810
|
S: this,
|
|
711
811
|
C: (f, a) => f(...a)
|
|
712
812
|
});
|
|
@@ -723,7 +823,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
723
823
|
payload: protocol.getPayloadType(message)
|
|
724
824
|
}, {
|
|
725
825
|
F: __dxlog_file4,
|
|
726
|
-
L:
|
|
826
|
+
L: 290,
|
|
727
827
|
S: this,
|
|
728
828
|
C: (f, a) => f(...a)
|
|
729
829
|
});
|
|
@@ -744,7 +844,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
744
844
|
statusText: response.statusText
|
|
745
845
|
}, {
|
|
746
846
|
F: __dxlog_file4,
|
|
747
|
-
L:
|
|
847
|
+
L: 302,
|
|
748
848
|
S: this,
|
|
749
849
|
C: (f, a) => f(...a)
|
|
750
850
|
});
|
|
@@ -769,8 +869,10 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
|
769
869
|
};
|
|
770
870
|
|
|
771
871
|
// src/edge-http-client.ts
|
|
772
|
-
import
|
|
773
|
-
import
|
|
872
|
+
import * as FetchHttpClient from "@effect/platform/FetchHttpClient";
|
|
873
|
+
import * as HttpClient from "@effect/platform/HttpClient";
|
|
874
|
+
import * as Effect2 from "effect/Effect";
|
|
875
|
+
import * as Function from "effect/Function";
|
|
774
876
|
import { sleep } from "@dxos/async";
|
|
775
877
|
import { Context as Context3 } from "@dxos/context";
|
|
776
878
|
import { log as log4 } from "@dxos/log";
|
|
@@ -778,7 +880,11 @@ import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
|
|
|
778
880
|
import { createUrl } from "@dxos/util";
|
|
779
881
|
|
|
780
882
|
// src/http-client.ts
|
|
781
|
-
import
|
|
883
|
+
import * as Context2 from "effect/Context";
|
|
884
|
+
import * as Duration from "effect/Duration";
|
|
885
|
+
import * as Effect from "effect/Effect";
|
|
886
|
+
import * as Layer from "effect/Layer";
|
|
887
|
+
import * as Schedule from "effect/Schedule";
|
|
782
888
|
import { log as log3 } from "@dxos/log";
|
|
783
889
|
function _define_property3(obj, key, value) {
|
|
784
890
|
if (key in obj) {
|
|
@@ -802,11 +908,11 @@ _define_property3(HttpConfig, "default", Layer.succeed(HttpConfig, {
|
|
|
802
908
|
retryTimes: 3,
|
|
803
909
|
retryBaseDelay: Duration.millis(1e3)
|
|
804
910
|
}));
|
|
805
|
-
var withRetry = (effect, { timeout = Duration.millis(1e3), retryBaseDelay = Duration.millis(1e3), retryTimes = 3 } = {}) => {
|
|
911
|
+
var withRetry = (effect, { timeout: timeout2 = Duration.millis(1e3), retryBaseDelay = Duration.millis(1e3), retryTimes = 3 } = {}) => {
|
|
806
912
|
return effect.pipe(Effect.flatMap((res) => (
|
|
807
913
|
// Treat 500 errors as retryable?
|
|
808
914
|
res.status === 500 ? Effect.fail(new Error(res.status.toString())) : res.json
|
|
809
|
-
)), Effect.timeout(
|
|
915
|
+
)), Effect.timeout(timeout2), Effect.retry({
|
|
810
916
|
schedule: Schedule.exponential(retryBaseDelay).pipe(Schedule.jittered),
|
|
811
917
|
times: retryTimes
|
|
812
918
|
}));
|
|
@@ -819,7 +925,7 @@ var withLogging = (effect) => effect.pipe(Effect.tap((res) => log3.info("respons
|
|
|
819
925
|
status: res.status
|
|
820
926
|
}, {
|
|
821
927
|
F: __dxlog_file5,
|
|
822
|
-
L:
|
|
928
|
+
L: 64,
|
|
823
929
|
S: void 0,
|
|
824
930
|
C: (f, a) => f(...a)
|
|
825
931
|
})));
|
|
@@ -1066,21 +1172,21 @@ var EdgeHttpClient = class {
|
|
|
1066
1172
|
// Internal
|
|
1067
1173
|
//
|
|
1068
1174
|
async _fetch(url, args) {
|
|
1069
|
-
return pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), Effect2.runPromise);
|
|
1175
|
+
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), Effect2.runPromise);
|
|
1070
1176
|
}
|
|
1071
1177
|
// TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
|
|
1072
1178
|
async _call(url, args) {
|
|
1073
1179
|
const shouldRetry = createRetryHandler(args);
|
|
1074
1180
|
const requestContext = args.context ?? new Context3(void 0, {
|
|
1075
1181
|
F: __dxlog_file6,
|
|
1076
|
-
L:
|
|
1182
|
+
L: 391
|
|
1077
1183
|
});
|
|
1078
1184
|
log4("fetch", {
|
|
1079
1185
|
url,
|
|
1080
1186
|
request: args.body
|
|
1081
1187
|
}, {
|
|
1082
1188
|
F: __dxlog_file6,
|
|
1083
|
-
L:
|
|
1189
|
+
L: 392,
|
|
1084
1190
|
S: this,
|
|
1085
1191
|
C: (f, a) => f(...a)
|
|
1086
1192
|
});
|
|
@@ -1108,7 +1214,7 @@ var EdgeHttpClient = class {
|
|
|
1108
1214
|
body
|
|
1109
1215
|
}, {
|
|
1110
1216
|
F: __dxlog_file6,
|
|
1111
|
-
L:
|
|
1217
|
+
L: 417,
|
|
1112
1218
|
S: this,
|
|
1113
1219
|
C: (f, a) => f(...a)
|
|
1114
1220
|
});
|
|
@@ -1133,7 +1239,7 @@ var EdgeHttpClient = class {
|
|
|
1133
1239
|
processingError
|
|
1134
1240
|
}, {
|
|
1135
1241
|
F: __dxlog_file6,
|
|
1136
|
-
L:
|
|
1242
|
+
L: 435,
|
|
1137
1243
|
S: this,
|
|
1138
1244
|
C: (f, a) => f(...a)
|
|
1139
1245
|
});
|
|
@@ -1146,7 +1252,7 @@ var EdgeHttpClient = class {
|
|
|
1146
1252
|
if (!this._edgeIdentity) {
|
|
1147
1253
|
log4.warn("unauthorized response received before identity was set", void 0, {
|
|
1148
1254
|
F: __dxlog_file6,
|
|
1149
|
-
L:
|
|
1255
|
+
L: 444,
|
|
1150
1256
|
S: this,
|
|
1151
1257
|
C: (f, a) => f(...a)
|
|
1152
1258
|
});
|
|
@@ -1164,7 +1270,7 @@ var EdgeHttpClient = class {
|
|
|
1164
1270
|
url: this._baseUrl
|
|
1165
1271
|
}, {
|
|
1166
1272
|
F: __dxlog_file6,
|
|
1167
|
-
L:
|
|
1273
|
+
L: 99,
|
|
1168
1274
|
S: this,
|
|
1169
1275
|
C: (f, a) => f(...a)
|
|
1170
1276
|
});
|
|
@@ -1184,7 +1290,7 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1184
1290
|
bodySize: requestBody.length
|
|
1185
1291
|
}, {
|
|
1186
1292
|
F: __dxlog_file6,
|
|
1187
|
-
L:
|
|
1293
|
+
L: 468,
|
|
1188
1294
|
S: void 0,
|
|
1189
1295
|
C: (f, a) => f(...a)
|
|
1190
1296
|
});
|
|
@@ -1198,14 +1304,14 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1198
1304
|
headers
|
|
1199
1305
|
};
|
|
1200
1306
|
};
|
|
1201
|
-
var createRetryHandler = ({ retry }) => {
|
|
1202
|
-
if (!
|
|
1307
|
+
var createRetryHandler = ({ retry: retry2 }) => {
|
|
1308
|
+
if (!retry2 || retry2.count < 1) {
|
|
1203
1309
|
return async () => false;
|
|
1204
1310
|
}
|
|
1205
1311
|
let retries = 0;
|
|
1206
|
-
const maxRetries =
|
|
1207
|
-
const baseTimeout =
|
|
1208
|
-
const jitter =
|
|
1312
|
+
const maxRetries = retry2.count ?? DEFAULT_MAX_RETRIES_COUNT;
|
|
1313
|
+
const baseTimeout = retry2.timeout ?? DEFAULT_RETRY_TIMEOUT;
|
|
1314
|
+
const jitter = retry2.jitter ?? DEFAULT_RETRY_JITTER;
|
|
1209
1315
|
return async (ctx, retryAfter) => {
|
|
1210
1316
|
if (++retries > maxRetries || ctx.disposed) {
|
|
1211
1317
|
return false;
|
|
@@ -1213,8 +1319,8 @@ var createRetryHandler = ({ retry }) => {
|
|
|
1213
1319
|
if (retryAfter) {
|
|
1214
1320
|
await sleep(retryAfter);
|
|
1215
1321
|
} else {
|
|
1216
|
-
const
|
|
1217
|
-
await sleep(
|
|
1322
|
+
const timeout2 = baseTimeout + Math.random() * jitter;
|
|
1323
|
+
await sleep(timeout2);
|
|
1218
1324
|
}
|
|
1219
1325
|
return true;
|
|
1220
1326
|
};
|