@dxos/echo-pipeline 0.8.4-main.84f28bd → 0.8.4-main.b97322e

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.
@@ -38,7 +38,7 @@ import { log as log7 } from "@dxos/log";
38
38
  // src/db-host/documents-synchronizer.ts
39
39
  import { next as A2 } from "@automerge/automerge";
40
40
  import { UpdateScheduler } from "@dxos/async";
41
- import { Resource as Resource5 } from "@dxos/context";
41
+ import { LifecycleState as LifecycleState3, Resource as Resource5 } from "@dxos/context";
42
42
  import { invariant as invariant6 } from "@dxos/invariant";
43
43
  import { log as log6 } from "@dxos/log";
44
44
 
@@ -2193,10 +2193,13 @@ var DocumentsSynchronizer = class extends Resource5 {
2193
2193
  return mutation;
2194
2194
  }
2195
2195
  _writeMutation(documentId, mutation) {
2196
+ if (this._lifecycleState === LifecycleState3.CLOSED) {
2197
+ return;
2198
+ }
2196
2199
  const syncState = this._syncStates.get(documentId);
2197
2200
  invariant6(syncState, "Sync state for document not found", {
2198
2201
  F: __dxlog_file7,
2199
- L: 162,
2202
+ L: 165,
2200
2203
  S: this,
2201
2204
  A: [
2202
2205
  "syncState",
@@ -2357,7 +2360,7 @@ var DataServiceImpl = class {
2357
2360
  };
2358
2361
 
2359
2362
  // src/db-host/echo-host.ts
2360
- import { LifecycleState as LifecycleState5, Resource as Resource9 } from "@dxos/context";
2363
+ import { LifecycleState as LifecycleState6, Resource as Resource9 } from "@dxos/context";
2361
2364
  import { todo } from "@dxos/debug";
2362
2365
  import { createIdFromSpaceKey as createIdFromSpaceKey2, SpaceDocVersion as SpaceDocVersion3 } from "@dxos/echo-protocol";
2363
2366
  import { IndexMetadataStore, IndexStore, Indexer } from "@dxos/indexing";
@@ -2467,7 +2470,7 @@ import { trace as trace4 } from "@dxos/tracing";
2467
2470
 
2468
2471
  // src/query/query-executor.ts
2469
2472
  import { Match } from "effect";
2470
- import { Context as Context3, ContextDisposedError, LifecycleState as LifecycleState3, Resource as Resource6 } from "@dxos/context";
2473
+ import { Context as Context3, ContextDisposedError, LifecycleState as LifecycleState4, Resource as Resource6 } from "@dxos/context";
2471
2474
  import { DatabaseDirectory as DatabaseDirectory3, isEncodedReference, ObjectStructure } from "@dxos/echo-protocol";
2472
2475
  import { EscapedPropPath } from "@dxos/indexing";
2473
2476
  import { invariant as invariant10 } from "@dxos/invariant";
@@ -3014,7 +3017,7 @@ var QueryExecutor = class extends Resource6 {
3014
3017
  }));
3015
3018
  }
3016
3019
  async execQuery() {
3017
- invariant10(this._lifecycleState === LifecycleState3.OPEN, void 0, {
3020
+ invariant10(this._lifecycleState === LifecycleState4.OPEN, void 0, {
3018
3021
  F: __dxlog_file11,
3019
3022
  L: 173,
3020
3023
  S: this,
@@ -3552,6 +3555,18 @@ var QueryServiceImpl = class extends Resource7 {
3552
3555
  }
3553
3556
  execQuery(request) {
3554
3557
  return new Stream2(({ next, close, ctx }) => {
3558
+ if (this._params.indexer.config?.enabled !== true) {
3559
+ log10.error("indexer is disabled", {
3560
+ config: this._params.indexer.config
3561
+ }, {
3562
+ F: __dxlog_file12,
3563
+ L: 100,
3564
+ S: this,
3565
+ C: (f, a) => f(...a)
3566
+ });
3567
+ close();
3568
+ return;
3569
+ }
3555
3570
  const queryEntry = this._createQuery(ctx, request, next, close, close);
3556
3571
  scheduleMicroTask(ctx, async () => {
3557
3572
  await queryEntry.executor.open();
@@ -3567,7 +3582,7 @@ var QueryServiceImpl = class extends Resource7 {
3567
3582
  async reindex() {
3568
3583
  log10("Reindexing all documents...", void 0, {
3569
3584
  F: __dxlog_file12,
3570
- L: 113,
3585
+ L: 119,
3571
3586
  S: this,
3572
3587
  C: (f, a) => f(...a)
3573
3588
  });
@@ -3582,7 +3597,7 @@ var QueryServiceImpl = class extends Resource7 {
3582
3597
  count: ids.size
3583
3598
  }, {
3584
3599
  F: __dxlog_file12,
3585
- L: 121,
3600
+ L: 127,
3586
3601
  S: this,
3587
3602
  C: (f, a) => f(...a)
3588
3603
  });
@@ -3592,7 +3607,7 @@ var QueryServiceImpl = class extends Resource7 {
3592
3607
  count: ids.size
3593
3608
  }, {
3594
3609
  F: __dxlog_file12,
3595
- L: 125,
3610
+ L: 131,
3596
3611
  S: this,
3597
3612
  C: (f, a) => f(...a)
3598
3613
  });
@@ -3658,7 +3673,7 @@ var QueryServiceImpl = class extends Resource7 {
3658
3673
  } catch (err) {
3659
3674
  log10.catch(err, void 0, {
3660
3675
  F: __dxlog_file12,
3661
- L: 196,
3676
+ L: 202,
3662
3677
  S: this,
3663
3678
  C: (f, a) => f(...a)
3664
3679
  });
@@ -3669,7 +3684,7 @@ var QueryServiceImpl = class extends Resource7 {
3669
3684
  duration: performance.now() - begin
3670
3685
  }, {
3671
3686
  F: __dxlog_file12,
3672
- L: 200,
3687
+ L: 206,
3673
3688
  S: this,
3674
3689
  C: (f, a) => f(...a)
3675
3690
  });
@@ -3720,7 +3735,7 @@ var createDocumentsIterator = (automergeHost) => (
3720
3735
  }
3721
3736
  const linkHandle = await automergeHost.loadDoc(Context4.default(void 0, {
3722
3737
  F: __dxlog_file12,
3723
- L: 240
3738
+ L: 246
3724
3739
  }), urlString);
3725
3740
  for await (const result of getObjectsFromHandle(linkHandle)) {
3726
3741
  yield result;
@@ -3745,7 +3760,7 @@ var createDocumentsIterator = (automergeHost) => (
3745
3760
  import { interpretAsDocumentId as interpretAsDocumentId3 } from "@automerge/automerge-repo";
3746
3761
  import isEqual from "lodash.isequal";
3747
3762
  import { Event as Event3, UpdateScheduler as UpdateScheduler3 } from "@dxos/async";
3748
- import { Resource as Resource8, Context as Context5, LifecycleState as LifecycleState4 } from "@dxos/context";
3763
+ import { Resource as Resource8, Context as Context5, LifecycleState as LifecycleState5 } from "@dxos/context";
3749
3764
  import { invariant as invariant12 } from "@dxos/invariant";
3750
3765
 
3751
3766
  // src/db-host/database-root.ts
@@ -3894,7 +3909,7 @@ var SpaceStateManager = class extends Resource8 {
3894
3909
  return this._rootBySpace.get(spaceId);
3895
3910
  }
3896
3911
  getRootBySpaceId(spaceId) {
3897
- invariant12(this._lifecycleState === LifecycleState4.OPEN, void 0, {
3912
+ invariant12(this._lifecycleState === LifecycleState5.OPEN, void 0, {
3898
3913
  F: __dxlog_file15,
3899
3914
  L: 44,
3900
3915
  S: this,
@@ -4135,7 +4150,7 @@ var EchoHost = class extends Resource9 {
4135
4150
  * Create new space root.
4136
4151
  */
4137
4152
  async createSpaceRoot(spaceKey) {
4138
- invariant13(this._lifecycleState === LifecycleState5.OPEN, void 0, {
4153
+ invariant13(this._lifecycleState === LifecycleState6.OPEN, void 0, {
4139
4154
  F: __dxlog_file16,
4140
4155
  L: 255,
4141
4156
  S: this,
@@ -4163,7 +4178,7 @@ var EchoHost = class extends Resource9 {
4163
4178
  }
4164
4179
  // TODO(dmaretskyi): Change to document id.
4165
4180
  async openSpaceRoot(spaceId, automergeUrl) {
4166
- invariant13(this._lifecycleState === LifecycleState5.OPEN, void 0, {
4181
+ invariant13(this._lifecycleState === LifecycleState6.OPEN, void 0, {
4167
4182
  F: __dxlog_file16,
4168
4183
  L: 274,
4169
4184
  S: this,
@@ -4475,9 +4490,25 @@ var EchoEdgeReplicator = class {
4475
4490
  context: this._context,
4476
4491
  sharedPolicyEnabled: this._sharePolicyEnabled,
4477
4492
  onRemoteConnected: async () => {
4493
+ log13.trace("dxos.echo.edge.replicator.onRemoteConnected", {
4494
+ spaceId
4495
+ }, {
4496
+ F: __dxlog_file18,
4497
+ L: 135,
4498
+ S: this,
4499
+ C: (f, a) => f(...a)
4500
+ });
4478
4501
  this._context?.onConnectionOpen(connection);
4479
4502
  },
4480
4503
  onRemoteDisconnected: async () => {
4504
+ log13.trace("dxos.echo.edge.replicator.onRemoteDisconnected", {
4505
+ spaceId
4506
+ }, {
4507
+ F: __dxlog_file18,
4508
+ L: 139,
4509
+ S: this,
4510
+ C: (f, a) => f(...a)
4511
+ });
4481
4512
  this._context?.onConnectionClosed(connection);
4482
4513
  },
4483
4514
  onRestartRequested: async () => {
@@ -4491,7 +4522,7 @@ var EchoEdgeReplicator = class {
4491
4522
  restartDelay
4492
4523
  }, {
4493
4524
  F: __dxlog_file18,
4494
- L: 148,
4525
+ L: 150,
4495
4526
  S: this,
4496
4527
  C: (f, a) => f(...a)
4497
4528
  });
@@ -4513,6 +4544,16 @@ var EchoEdgeReplicator = class {
4513
4544
  if (ctx?.disposed) {
4514
4545
  return;
4515
4546
  }
4547
+ log13.trace("dxos.echo.edge.replicator.restart", {
4548
+ spaceId,
4549
+ reconnects,
4550
+ restartDelay
4551
+ }, {
4552
+ F: __dxlog_file18,
4553
+ L: 167,
4554
+ S: this,
4555
+ C: (f, a) => f(...a)
4556
+ });
4516
4557
  await this._openConnection(spaceId, reconnects + 1);
4517
4558
  } catch (e) {
4518
4559
  env.error = e;
@@ -4561,7 +4602,7 @@ var EdgeReplicatorConnection = class extends Resource11 {
4561
4602
  async _open(ctx) {
4562
4603
  log13("opening...", void 0, {
4563
4604
  F: __dxlog_file18,
4564
- L: 251,
4605
+ L: 254,
4565
4606
  S: this,
4566
4607
  C: (f, a) => f(...a)
4567
4608
  });
@@ -4569,12 +4610,29 @@ var EdgeReplicatorConnection = class extends Resource11 {
4569
4610
  this._ctx.onDispose(this._edgeConnection.onMessage((msg) => {
4570
4611
  this._onMessage(msg);
4571
4612
  }));
4613
+ let firstReconnect = true;
4614
+ this._ctx.onDispose(
4615
+ // NOTE: This will fire immediately if the connection is already open.
4616
+ this._edgeConnection.onReconnected(async () => {
4617
+ if (firstReconnect) {
4618
+ log13.verbose("first reconnect skipped", void 0, {
4619
+ F: __dxlog_file18,
4620
+ L: 269,
4621
+ S: this,
4622
+ C: (f, a) => f(...a)
4623
+ });
4624
+ firstReconnect = false;
4625
+ return;
4626
+ }
4627
+ this._onRestartRequested();
4628
+ })
4629
+ );
4572
4630
  await this._onRemoteConnected();
4573
4631
  }
4574
4632
  async _close() {
4575
4633
  log13("closing...", void 0, {
4576
4634
  F: __dxlog_file18,
4577
- L: 266,
4635
+ L: 282,
4578
4636
  S: this,
4579
4637
  C: (f, a) => f(...a)
4580
4638
  });
@@ -4585,7 +4643,7 @@ var EdgeReplicatorConnection = class extends Resource11 {
4585
4643
  get peerId() {
4586
4644
  invariant14(this._remotePeerId, "Not connected", {
4587
4645
  F: __dxlog_file18,
4588
- L: 275,
4646
+ L: 291,
4589
4647
  S: this,
4590
4648
  A: [
4591
4649
  "this._remotePeerId",
@@ -4610,7 +4668,7 @@ var EdgeReplicatorConnection = class extends Resource11 {
4610
4668
  remoteId: this._remotePeerId
4611
4669
  }, {
4612
4670
  F: __dxlog_file18,
4613
- L: 290,
4671
+ L: 306,
4614
4672
  S: this,
4615
4673
  C: (f, a) => f(...a)
4616
4674
  });
@@ -4636,7 +4694,7 @@ var EdgeReplicatorConnection = class extends Resource11 {
4636
4694
  remoteId: this._remotePeerId
4637
4695
  }, {
4638
4696
  F: __dxlog_file18,
4639
- L: 319,
4697
+ L: 335,
4640
4698
  S: this,
4641
4699
  C: (f, a) => f(...a)
4642
4700
  });
@@ -4659,21 +4717,32 @@ var EdgeReplicatorConnection = class extends Resource11 {
4659
4717
  remoteId: this._remotePeerId
4660
4718
  }, {
4661
4719
  F: __dxlog_file18,
4662
- L: 348,
4720
+ L: 364,
4663
4721
  S: this,
4664
4722
  C: (f, a) => f(...a)
4665
4723
  });
4666
4724
  const encoded = cbor2.encode(message);
4667
- await this._edgeConnection.send(buf.create(RouterMessageSchema, {
4668
- serviceId: this._targetServiceId,
4669
- source: {
4670
- identityKey: this._edgeConnection.identityKey,
4671
- peerKey: this._edgeConnection.peerKey
4672
- },
4673
- payload: {
4674
- value: bufferToArray2(encoded)
4675
- }
4676
- }));
4725
+ try {
4726
+ await this._edgeConnection.send(buf.create(RouterMessageSchema, {
4727
+ serviceId: this._targetServiceId,
4728
+ source: {
4729
+ identityKey: this._edgeConnection.identityKey,
4730
+ peerKey: this._edgeConnection.peerKey
4731
+ },
4732
+ payload: {
4733
+ value: bufferToArray2(encoded)
4734
+ }
4735
+ }));
4736
+ } catch (err) {
4737
+ log13.error("failed to send message", {
4738
+ err
4739
+ }, {
4740
+ F: __dxlog_file18,
4741
+ L: 384,
4742
+ S: this,
4743
+ C: (f, a) => f(...a)
4744
+ });
4745
+ }
4677
4746
  }
4678
4747
  };
4679
4748
  var isForbiddenErrorMessage = (message) => message.type === "error" && message.message === "Forbidden";