@dxos/echo-pipeline 0.6.14-staging.e15392e → 0.7.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.
@@ -3028,7 +3028,10 @@ var EchoHost = class extends Resource9 {
3028
3028
  version: SpaceDocVersion3.CURRENT,
3029
3029
  access: {
3030
3030
  spaceKey: spaceKey.toHex()
3031
- }
3031
+ },
3032
+ // Better to initialize them right away to avoid merge conflicts and data loss that can occur if those maps get created on the fly.
3033
+ objects: {},
3034
+ links: {}
3032
3035
  });
3033
3036
  await this._automergeHost.flush({
3034
3037
  documentIds: [
@@ -3041,7 +3044,7 @@ var EchoHost = class extends Resource9 {
3041
3044
  async openSpaceRoot(spaceId, automergeUrl) {
3042
3045
  invariant11(this._lifecycleState === LifecycleState4.OPEN, void 0, {
3043
3046
  F: __dxlog_file15,
3044
- L: 221,
3047
+ L: 225,
3045
3048
  S: this,
3046
3049
  A: [
3047
3050
  "this._lifecycleState === LifecycleState.OPEN",
@@ -3111,7 +3114,7 @@ var findInlineObjectOfType = (spaceDoc, typename) => {
3111
3114
  };
3112
3115
 
3113
3116
  // packages/core/echo/echo-pipeline/src/edge/echo-edge-replicator.ts
3114
- import { Mutex, scheduleTask as scheduleTask2 } from "@dxos/async";
3117
+ import { Mutex, scheduleTask as scheduleTask2, scheduleMicroTask } from "@dxos/async";
3115
3118
  import * as A5 from "@dxos/automerge/automerge";
3116
3119
  import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
3117
3120
  import { Context as Context6, Resource as Resource10 } from "@dxos/context";
@@ -3214,30 +3217,30 @@ var EchoEdgeReplicator = class {
3214
3217
  F: __dxlog_file16,
3215
3218
  L: 63
3216
3219
  });
3217
- this._edgeConnection.reconnect.on(this._ctx, async () => {
3218
- try {
3219
- var _usingCtx = _using_ctx();
3220
- const _guard = _usingCtx.u(await this._mutex.acquire());
3221
- const spaces = [
3222
- ...this._connectedSpaces
3223
- ];
3224
- for (const connection of this._connections.values()) {
3225
- await connection.close();
3226
- }
3227
- this._connections.clear();
3228
- if (this._context !== null) {
3229
- for (const spaceId of spaces) {
3230
- await this._openConnection(spaceId);
3231
- }
3220
+ this._ctx.onDispose(this._edgeConnection.onReconnected(() => {
3221
+ this._ctx && scheduleMicroTask(this._ctx, () => this._handleReconnect());
3222
+ }));
3223
+ }
3224
+ async _handleReconnect() {
3225
+ try {
3226
+ var _usingCtx = _using_ctx();
3227
+ const _guard = _usingCtx.u(await this._mutex.acquire());
3228
+ const spaces = [
3229
+ ...this._connectedSpaces
3230
+ ];
3231
+ for (const connection of this._connections.values()) {
3232
+ await connection.close();
3233
+ }
3234
+ this._connections.clear();
3235
+ if (this._context !== null) {
3236
+ for (const spaceId of spaces) {
3237
+ await this._openConnection(spaceId);
3232
3238
  }
3233
- } catch (_) {
3234
- _usingCtx.e = _;
3235
- } finally {
3236
- _usingCtx.d();
3237
3239
  }
3238
- });
3239
- for (const spaceId of this._connectedSpaces) {
3240
- await this._openConnection(spaceId);
3240
+ } catch (_) {
3241
+ _usingCtx.e = _;
3242
+ } finally {
3243
+ _usingCtx.d();
3241
3244
  }
3242
3245
  }
3243
3246
  async disconnect() {
@@ -3288,7 +3291,7 @@ var EchoEdgeReplicator = class {
3288
3291
  async _openConnection(spaceId, reconnects = 0) {
3289
3292
  invariant12(this._context, void 0, {
3290
3293
  F: __dxlog_file16,
3291
- L: 119,
3294
+ L: 121,
3292
3295
  S: this,
3293
3296
  A: [
3294
3297
  "this._context",
@@ -3297,7 +3300,7 @@ var EchoEdgeReplicator = class {
3297
3300
  });
3298
3301
  invariant12(!this._connections.has(spaceId), void 0, {
3299
3302
  F: __dxlog_file16,
3300
- L: 120,
3303
+ L: 122,
3301
3304
  S: this,
3302
3305
  A: [
3303
3306
  "!this._connections.has(spaceId)",
@@ -3327,7 +3330,7 @@ var EchoEdgeReplicator = class {
3327
3330
  restartDelay
3328
3331
  }, {
3329
3332
  F: __dxlog_file16,
3330
- L: 143,
3333
+ L: 145,
3331
3334
  S: this,
3332
3335
  C: (f, a) => f(...a)
3333
3336
  });
@@ -3385,11 +3388,11 @@ var EdgeReplicatorConnection = class extends Resource10 {
3385
3388
  async _open(ctx) {
3386
3389
  log11("open", void 0, {
3387
3390
  F: __dxlog_file16,
3388
- L: 237,
3391
+ L: 239,
3389
3392
  S: this,
3390
3393
  C: (f, a) => f(...a)
3391
3394
  });
3392
- this._ctx.onDispose(this._edgeConnection.addListener((msg) => {
3395
+ this._ctx.onDispose(this._edgeConnection.onMessage((msg) => {
3393
3396
  this._onMessage(msg);
3394
3397
  }));
3395
3398
  await this._onRemoteConnected();
@@ -3397,7 +3400,7 @@ var EdgeReplicatorConnection = class extends Resource10 {
3397
3400
  async _close() {
3398
3401
  log11("close", void 0, {
3399
3402
  F: __dxlog_file16,
3400
- L: 249,
3403
+ L: 251,
3401
3404
  S: this,
3402
3405
  C: (f, a) => f(...a)
3403
3406
  });
@@ -3407,7 +3410,7 @@ var EdgeReplicatorConnection = class extends Resource10 {
3407
3410
  get peerId() {
3408
3411
  invariant12(this._remotePeerId, "Not connected", {
3409
3412
  F: __dxlog_file16,
3410
- L: 255,
3413
+ L: 257,
3411
3414
  S: this,
3412
3415
  A: [
3413
3416
  "this._remotePeerId",
@@ -3447,7 +3450,7 @@ var EdgeReplicatorConnection = class extends Resource10 {
3447
3450
  };
3448
3451
  }, {
3449
3452
  F: __dxlog_file16,
3450
- L: 286,
3453
+ L: 288,
3451
3454
  S: this,
3452
3455
  C: (f, a) => f(...a)
3453
3456
  });
@@ -3470,7 +3473,7 @@ var EdgeReplicatorConnection = class extends Resource10 {
3470
3473
  documentId: message.documentId
3471
3474
  }, {
3472
3475
  F: __dxlog_file16,
3473
- L: 316,
3476
+ L: 318,
3474
3477
  S: this,
3475
3478
  C: (f, a) => f(...a)
3476
3479
  });