@dxos/edge-client 0.7.5-labs.c0e040f → 0.7.5-labs.d199c0f

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.
@@ -9,9 +9,9 @@ import {
9
9
  export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
10
10
 
11
11
  // packages/core/mesh/edge-client/src/edge-client.ts
12
- import { Trigger, scheduleMicroTask, TriggerState } from "@dxos/async";
13
- import { Resource as Resource3 } from "@dxos/context";
14
- import { log as log3, logInfo as logInfo2 } from "@dxos/log";
12
+ import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle } from "@dxos/async";
13
+ import { Resource as Resource2 } from "@dxos/context";
14
+ import { log as log2, logInfo as logInfo2 } from "@dxos/log";
15
15
 
16
16
  // packages/core/mesh/edge-client/src/edge-identity.ts
17
17
  import { invariant } from "@dxos/invariant";
@@ -288,118 +288,6 @@ var EdgeIdentityChangedError = class extends Error {
288
288
  }
289
289
  };
290
290
 
291
- // packages/core/mesh/edge-client/src/persistent-lifecycle.ts
292
- import { DeferredTask, sleep, synchronized } from "@dxos/async";
293
- import { cancelWithContext, LifecycleState, Resource as Resource2 } from "@dxos/context";
294
- import { warnAfterTimeout } from "@dxos/debug";
295
- import { log as log2 } from "@dxos/log";
296
- function _ts_decorate2(decorators, target, key, desc) {
297
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
298
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
299
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
300
- return c > 3 && r && Object.defineProperty(target, key, r), r;
301
- }
302
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/persistent-lifecycle.ts";
303
- var INIT_RESTART_DELAY = 100;
304
- var DEFAULT_MAX_RESTART_DELAY = 5e3;
305
- var PersistentLifecycle = class extends Resource2 {
306
- constructor({ start, stop, onRestart, maxRestartDelay = DEFAULT_MAX_RESTART_DELAY }) {
307
- super();
308
- this._currentContext = void 0;
309
- this._restartTask = void 0;
310
- this._restartAfter = 0;
311
- this._start = start;
312
- this._stop = stop;
313
- this._onRestart = onRestart;
314
- this._maxRestartDelay = maxRestartDelay;
315
- }
316
- async _open() {
317
- this._restartTask = new DeferredTask(this._ctx, async () => {
318
- try {
319
- await this._restart();
320
- } catch (err) {
321
- log2.warn("Restart failed", {
322
- err
323
- }, {
324
- F: __dxlog_file3,
325
- L: 65,
326
- S: this,
327
- C: (f, a) => f(...a)
328
- });
329
- this._restartTask?.schedule();
330
- }
331
- });
332
- this._currentContext = await this._start().catch((err) => {
333
- log2.warn("Start failed", {
334
- err
335
- }, {
336
- F: __dxlog_file3,
337
- L: 70,
338
- S: this,
339
- C: (f, a) => f(...a)
340
- });
341
- this._restartTask?.schedule();
342
- return void 0;
343
- });
344
- }
345
- async _close() {
346
- await this._restartTask?.join();
347
- await this._stopCurrentContext();
348
- this._restartTask = void 0;
349
- }
350
- async _restart() {
351
- log2(`restarting in ${this._restartAfter}ms`, {
352
- state: this._lifecycleState
353
- }, {
354
- F: __dxlog_file3,
355
- L: 83,
356
- S: this,
357
- C: (f, a) => f(...a)
358
- });
359
- await this._stopCurrentContext();
360
- if (this._lifecycleState !== LifecycleState.OPEN) {
361
- return;
362
- }
363
- await cancelWithContext(this._ctx, sleep(this._restartAfter));
364
- this._restartAfter = Math.min(Math.max(this._restartAfter * 2, INIT_RESTART_DELAY), this._maxRestartDelay);
365
- await warnAfterTimeout(5e3, "Connection establishment takes too long", async () => {
366
- this._currentContext = await this._start();
367
- });
368
- this._restartAfter = 0;
369
- await this._onRestart?.();
370
- }
371
- async _stopCurrentContext() {
372
- if (this._currentContext) {
373
- try {
374
- await this._stop(this._currentContext);
375
- } catch (err) {
376
- log2.catch(err, void 0, {
377
- F: __dxlog_file3,
378
- L: 105,
379
- S: this,
380
- C: (f, a) => f(...a)
381
- });
382
- }
383
- this._currentContext = void 0;
384
- }
385
- }
386
- /**
387
- * Scheduling restart should be done from outside.
388
- */
389
- scheduleRestart() {
390
- if (this._lifecycleState !== LifecycleState.OPEN) {
391
- return;
392
- }
393
- this._restartTask.schedule();
394
- }
395
- };
396
- _ts_decorate2([
397
- synchronized
398
- ], PersistentLifecycle.prototype, "_open", null);
399
- _ts_decorate2([
400
- synchronized
401
- ], PersistentLifecycle.prototype, "scheduleRestart", null);
402
-
403
291
  // packages/core/mesh/edge-client/src/utils.ts
404
292
  var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
405
293
  const isSecure = baseUrl.startsWith("https") || baseUrl.startsWith("wss");
@@ -409,15 +297,15 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
409
297
  };
410
298
 
411
299
  // packages/core/mesh/edge-client/src/edge-client.ts
412
- function _ts_decorate3(decorators, target, key, desc) {
300
+ function _ts_decorate2(decorators, target, key, desc) {
413
301
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
414
302
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
415
303
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
416
304
  return c > 3 && r && Object.defineProperty(target, key, r), r;
417
305
  }
418
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
306
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
419
307
  var DEFAULT_TIMEOUT = 1e4;
420
- var EdgeClient = class extends Resource3 {
308
+ var EdgeClient = class extends Resource2 {
421
309
  constructor(_identity, _config) {
422
310
  super();
423
311
  this._identity = _identity;
@@ -452,12 +340,12 @@ var EdgeClient = class extends Resource3 {
452
340
  }
453
341
  setIdentity(identity) {
454
342
  if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {
455
- log3("Edge identity changed", {
343
+ log2("Edge identity changed", {
456
344
  identity,
457
345
  oldIdentity: this._identity
458
346
  }, {
459
- F: __dxlog_file4,
460
- L: 95,
347
+ F: __dxlog_file3,
348
+ L: 94,
461
349
  S: this,
462
350
  C: (f, a) => f(...a)
463
351
  });
@@ -478,9 +366,9 @@ var EdgeClient = class extends Resource3 {
478
366
  try {
479
367
  listener();
480
368
  } catch (error) {
481
- log3.catch(error, void 0, {
482
- F: __dxlog_file4,
483
- L: 117,
369
+ log2.catch(error, void 0, {
370
+ F: __dxlog_file3,
371
+ L: 116,
484
372
  S: this,
485
373
  C: (f, a) => f(...a)
486
374
  });
@@ -494,20 +382,20 @@ var EdgeClient = class extends Resource3 {
494
382
  * Open connection to messaging service.
495
383
  */
496
384
  async _open() {
497
- log3("opening...", {
385
+ log2("opening...", {
498
386
  info: this.info
499
387
  }, {
500
- F: __dxlog_file4,
501
- L: 129,
388
+ F: __dxlog_file3,
389
+ L: 128,
502
390
  S: this,
503
391
  C: (f, a) => f(...a)
504
392
  });
505
393
  this._persistentLifecycle.open().catch((err) => {
506
- log3.warn("Error while opening connection", {
394
+ log2.warn("Error while opening connection", {
507
395
  err
508
396
  }, {
509
- F: __dxlog_file4,
510
- L: 131,
397
+ F: __dxlog_file3,
398
+ L: 130,
511
399
  S: this,
512
400
  C: (f, a) => f(...a)
513
401
  });
@@ -517,11 +405,11 @@ var EdgeClient = class extends Resource3 {
517
405
  * Close connection and free resources.
518
406
  */
519
407
  async _close() {
520
- log3("closing...", {
408
+ log2("closing...", {
521
409
  peerKey: this._identity.peerKey
522
410
  }, {
523
- F: __dxlog_file4,
524
- L: 139,
411
+ F: __dxlog_file3,
412
+ L: 138,
525
413
  S: this,
526
414
  C: (f, a) => f(...a)
527
415
  });
@@ -536,9 +424,9 @@ var EdgeClient = class extends Resource3 {
536
424
  const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
537
425
  const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
538
426
  if (this._identity !== identity) {
539
- log3("identity changed during auth header request", void 0, {
540
- F: __dxlog_file4,
541
- L: 153,
427
+ log2("identity changed during auth header request", void 0, {
428
+ F: __dxlog_file3,
429
+ L: 152,
542
430
  S: this,
543
431
  C: (f, a) => f(...a)
544
432
  });
@@ -546,12 +434,12 @@ var EdgeClient = class extends Resource3 {
546
434
  }
547
435
  const restartRequired = new Trigger();
548
436
  const url = new URL(path, this._baseWsUrl);
549
- log3("Opening websocket", {
437
+ log2("Opening websocket", {
550
438
  url: url.toString(),
551
439
  protocolHeader
552
440
  }, {
553
- F: __dxlog_file4,
554
- L: 159,
441
+ F: __dxlog_file3,
442
+ L: 158,
555
443
  S: this,
556
444
  C: (f, a) => f(...a)
557
445
  });
@@ -564,9 +452,9 @@ var EdgeClient = class extends Resource3 {
564
452
  this._ready.wake();
565
453
  this._notifyReconnected();
566
454
  } else {
567
- log3.verbose("connected callback ignored, because connection is not active", void 0, {
568
- F: __dxlog_file4,
569
- L: 169,
455
+ log2.verbose("connected callback ignored, because connection is not active", void 0, {
456
+ F: __dxlog_file3,
457
+ L: 168,
570
458
  S: this,
571
459
  C: (f, a) => f(...a)
572
460
  });
@@ -577,9 +465,9 @@ var EdgeClient = class extends Resource3 {
577
465
  this._closeCurrentConnection();
578
466
  this._persistentLifecycle.scheduleRestart();
579
467
  } else {
580
- log3.verbose("restart requested by inactive connection", void 0, {
581
- F: __dxlog_file4,
582
- L: 177,
468
+ log2.verbose("restart requested by inactive connection", void 0, {
469
+ F: __dxlog_file3,
470
+ L: 176,
583
471
  S: this,
584
472
  C: (f, a) => f(...a)
585
473
  });
@@ -590,12 +478,12 @@ var EdgeClient = class extends Resource3 {
590
478
  if (this._isActive(connection)) {
591
479
  this._notifyMessageReceived(message);
592
480
  } else {
593
- log3.verbose("ignored a message on inactive connection", {
481
+ log2.verbose("ignored a message on inactive connection", {
594
482
  from: message.source,
595
483
  type: message.payload?.typeUrl
596
484
  }, {
597
- F: __dxlog_file4,
598
- L: 185,
485
+ F: __dxlog_file3,
486
+ L: 184,
599
487
  S: this,
600
488
  C: (f, a) => f(...a)
601
489
  });
@@ -625,11 +513,11 @@ var EdgeClient = class extends Resource3 {
625
513
  try {
626
514
  listener();
627
515
  } catch (err) {
628
- log3.error("ws reconnect listener failed", {
516
+ log2.error("ws reconnect listener failed", {
629
517
  err
630
518
  }, {
631
- F: __dxlog_file4,
632
- L: 218,
519
+ F: __dxlog_file3,
520
+ L: 217,
633
521
  S: this,
634
522
  C: (f, a) => f(...a)
635
523
  });
@@ -641,12 +529,12 @@ var EdgeClient = class extends Resource3 {
641
529
  try {
642
530
  listener(message);
643
531
  } catch (err) {
644
- log3.error("ws incoming message processing failed", {
532
+ log2.error("ws incoming message processing failed", {
645
533
  err,
646
534
  payload: protocol.getPayloadType(message)
647
535
  }, {
648
- F: __dxlog_file4,
649
- L: 228,
536
+ F: __dxlog_file3,
537
+ L: 227,
650
538
  S: this,
651
539
  C: (f, a) => f(...a)
652
540
  });
@@ -659,9 +547,9 @@ var EdgeClient = class extends Resource3 {
659
547
  */
660
548
  async send(message) {
661
549
  if (this._ready.state !== TriggerState.RESOLVED) {
662
- log3("waiting for websocket to become ready", void 0, {
663
- F: __dxlog_file4,
664
- L: 239,
550
+ log2("waiting for websocket to become ready", void 0, {
551
+ F: __dxlog_file3,
552
+ L: 238,
665
553
  S: this,
666
554
  C: (f, a) => f(...a)
667
555
  });
@@ -686,12 +574,12 @@ var EdgeClient = class extends Resource3 {
686
574
  if (response.status === 401) {
687
575
  return encodePresentationWsAuthHeader(await handleAuthChallenge(response, this._identity));
688
576
  } else {
689
- log3.warn("no auth challenge from edge", {
577
+ log2.warn("no auth challenge from edge", {
690
578
  status: response.status,
691
579
  statusText: response.statusText
692
580
  }, {
693
- F: __dxlog_file4,
694
- L: 264,
581
+ F: __dxlog_file3,
582
+ L: 263,
695
583
  S: this,
696
584
  C: (f, a) => f(...a)
697
585
  });
@@ -699,7 +587,7 @@ var EdgeClient = class extends Resource3 {
699
587
  }
700
588
  }
701
589
  };
702
- _ts_decorate3([
590
+ _ts_decorate2([
703
591
  logInfo2
704
592
  ], EdgeClient.prototype, "info", null);
705
593
  var encodePresentationWsAuthHeader = (encodedPresentation) => {
@@ -712,7 +600,7 @@ import { createCredential, signPresentation } from "@dxos/credentials";
712
600
  import { invariant as invariant3 } from "@dxos/invariant";
713
601
  import { Keyring } from "@dxos/keyring";
714
602
  import { PublicKey } from "@dxos/keys";
715
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
603
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
716
604
  var createDeviceEdgeIdentity = async (signer, key) => {
717
605
  return {
718
606
  identityKey: key.toHex(),
@@ -757,7 +645,7 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
757
645
  peerKey: peerKey.toHex(),
758
646
  presentCredentials: async ({ challenge }) => {
759
647
  invariant3(chain, void 0, {
760
- F: __dxlog_file5,
648
+ F: __dxlog_file4,
761
649
  L: 75,
762
650
  S: void 0,
763
651
  A: [
@@ -819,21 +707,21 @@ var createStubEdgeIdentity = () => {
819
707
  };
820
708
 
821
709
  // packages/core/mesh/edge-client/src/edge-http-client.ts
822
- import { sleep as sleep2 } from "@dxos/async";
710
+ import { sleep } from "@dxos/async";
823
711
  import { Context as Context2 } from "@dxos/context";
824
- import { log as log4 } from "@dxos/log";
712
+ import { log as log3 } from "@dxos/log";
825
713
  import { EdgeCallFailedError, EdgeAuthChallengeError } from "@dxos/protocols";
826
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
714
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
827
715
  var DEFAULT_RETRY_TIMEOUT = 1500;
828
716
  var DEFAULT_RETRY_JITTER = 500;
829
717
  var DEFAULT_MAX_RETRIES_COUNT = 3;
830
718
  var EdgeHttpClient = class {
831
719
  constructor(baseUrl) {
832
720
  this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
833
- log4("created", {
721
+ log3("created", {
834
722
  url: this._baseUrl
835
723
  }, {
836
- F: __dxlog_file6,
724
+ F: __dxlog_file5,
837
725
  L: 49,
838
726
  S: this,
839
727
  C: (f, a) => f(...a)
@@ -952,7 +840,7 @@ var EdgeHttpClient = class {
952
840
  }
953
841
  async _call(path, args) {
954
842
  const requestContext = args.context ?? new Context2(void 0, {
955
- F: __dxlog_file6,
843
+ F: __dxlog_file5,
956
844
  L: 177
957
845
  });
958
846
  const shouldRetry = createRetryHandler(args);
@@ -964,12 +852,12 @@ var EdgeHttpClient = class {
964
852
  }
965
853
  url += `?${queryParams.toString()}`;
966
854
  }
967
- log4("call", {
855
+ log3("call", {
968
856
  method: args.method,
969
857
  path,
970
858
  request: args.body
971
859
  }, {
972
- F: __dxlog_file6,
860
+ F: __dxlog_file5,
973
861
  L: 189,
974
862
  S: this,
975
863
  C: (f, a) => f(...a)
@@ -988,11 +876,11 @@ var EdgeHttpClient = class {
988
876
  if (body.success) {
989
877
  return body.data;
990
878
  }
991
- log4("unsuccessful edge response", {
879
+ log3("unsuccessful edge response", {
992
880
  path,
993
881
  body
994
882
  }, {
995
- F: __dxlog_file6,
883
+ F: __dxlog_file5,
996
884
  L: 208,
997
885
  S: this,
998
886
  C: (f, a) => f(...a)
@@ -1013,11 +901,11 @@ var EdgeHttpClient = class {
1013
901
  processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
1014
902
  }
1015
903
  if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
1016
- log4("retrying edge request", {
904
+ log3("retrying edge request", {
1017
905
  path,
1018
906
  processingError
1019
907
  }, {
1020
- F: __dxlog_file6,
908
+ F: __dxlog_file5,
1021
909
  L: 227,
1022
910
  S: this,
1023
911
  C: (f, a) => f(...a)
@@ -1029,8 +917,8 @@ var EdgeHttpClient = class {
1029
917
  }
1030
918
  async _handleUnauthorized(response) {
1031
919
  if (!this._edgeIdentity) {
1032
- log4.warn("edge unauthorized response received before identity was set", void 0, {
1033
- F: __dxlog_file6,
920
+ log3.warn("edge unauthorized response received before identity was set", void 0, {
921
+ F: __dxlog_file5,
1034
922
  L: 236,
1035
923
  S: this,
1036
924
  C: (f, a) => f(...a)
@@ -1039,8 +927,8 @@ var EdgeHttpClient = class {
1039
927
  }
1040
928
  const challenge = await handleAuthChallenge(response, this._edgeIdentity);
1041
929
  this._authHeader = encodeAuthHeader(challenge);
1042
- log4("auth header updated", void 0, {
1043
- F: __dxlog_file6,
930
+ log3("auth header updated", void 0, {
931
+ F: __dxlog_file5,
1044
932
  L: 241,
1045
933
  S: this,
1046
934
  C: (f, a) => f(...a)
@@ -1061,10 +949,10 @@ var createRetryHandler = (args) => {
1061
949
  return false;
1062
950
  }
1063
951
  if (retryAfter) {
1064
- await sleep2(retryAfter);
952
+ await sleep(retryAfter);
1065
953
  } else {
1066
954
  const timeout = baseTimeout + Math.random() * jitter;
1067
- await sleep2(timeout);
955
+ await sleep(timeout);
1068
956
  }
1069
957
  return true;
1070
958
  };