@dxos/echo-pipeline 0.5.9-main.a22f041 → 0.5.9-main.a2de4fa

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.
Files changed (35) hide show
  1. package/dist/lib/browser/index.mjs +133 -228
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +145 -235
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -1
  8. package/dist/types/src/automerge/automerge-host.d.ts +1 -9
  9. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  10. package/dist/types/src/automerge/echo-network-adapter.d.ts +6 -0
  11. package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
  12. package/dist/types/src/automerge/echo-replicator.d.ts +1 -0
  13. package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
  14. package/dist/types/src/automerge/index.d.ts +0 -1
  15. package/dist/types/src/automerge/index.d.ts.map +1 -1
  16. package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
  17. package/package.json +33 -33
  18. package/src/automerge/automerge-doc-loader.test.ts +2 -3
  19. package/src/automerge/automerge-doc-loader.ts +4 -2
  20. package/src/automerge/automerge-host.ts +8 -35
  21. package/src/automerge/echo-network-adapter.ts +24 -8
  22. package/src/automerge/echo-replicator.ts +2 -0
  23. package/src/automerge/index.ts +0 -1
  24. package/src/automerge/mesh-echo-replicator.ts +8 -1
  25. package/src/automerge/storage-adapter.test.ts +103 -139
  26. package/src/space/space-protocol.test.ts +2 -0
  27. package/dist/types/src/automerge/automerge-storage-adapter.d.ts +0 -16
  28. package/dist/types/src/automerge/automerge-storage-adapter.d.ts.map +0 -1
  29. package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts +0 -25
  30. package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts.map +0 -1
  31. package/dist/types/src/automerge/migrations.d.ts +0 -7
  32. package/dist/types/src/automerge/migrations.d.ts.map +0 -1
  33. package/src/automerge/automerge-storage-adapter.ts +0 -103
  34. package/src/automerge/automerge-storage/342/200/223wrapper.ts +0 -59
  35. package/src/automerge/migrations.ts +0 -42
@@ -22,7 +22,6 @@ __export(node_exports, {
22
22
  AuthStatus: () => import_chunk_QPCNQ4ZK.AuthStatus,
23
23
  AutomergeDocumentLoaderImpl: () => AutomergeDocumentLoaderImpl,
24
24
  AutomergeHost: () => AutomergeHost,
25
- AutomergeStorageAdapter: () => AutomergeStorageAdapter,
26
25
  DataServiceImpl: () => import_chunk_QPCNQ4ZK.DataServiceImpl,
27
26
  LevelDBStorageAdapter: () => LevelDBStorageAdapter,
28
27
  LocalHostNetworkAdapter: () => LocalHostNetworkAdapter,
@@ -57,7 +56,6 @@ var import_automerge_repo = require("@dxos/automerge/automerge-repo");
57
56
  var import_context = require("@dxos/context");
58
57
  var import_invariant = require("@dxos/invariant");
59
58
  var import_keys = require("@dxos/keys");
60
- var import_log = require("@dxos/log");
61
59
  var import_protocols = require("@dxos/protocols");
62
60
  var import_tracing = require("@dxos/tracing");
63
61
  var import_util = require("@dxos/util");
@@ -65,29 +63,26 @@ var import_async2 = require("@dxos/async");
65
63
  var import_automerge_repo2 = require("@dxos/automerge/automerge-repo");
66
64
  var import_context2 = require("@dxos/context");
67
65
  var import_invariant2 = require("@dxos/invariant");
68
- var import_log2 = require("@dxos/log");
66
+ var import_log = require("@dxos/log");
69
67
  var import_context3 = require("@dxos/context");
70
68
  var import_async3 = require("@dxos/async");
71
69
  var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
72
70
  var import_codec_protobuf = require("@dxos/codec-protobuf");
73
71
  var import_invariant3 = require("@dxos/invariant");
74
- var import_automerge_repo_storage_indexeddb = require("@dxos/automerge/automerge-repo-storage-indexeddb");
75
- var import_log3 = require("@dxos/log");
76
- var import_random_access_storage = require("@dxos/random-access-storage");
77
- var import_util2 = require("@dxos/util");
78
72
  var import_async4 = require("@dxos/async");
79
73
  var import_context4 = require("@dxos/context");
80
74
  var import_debug = require("@dxos/debug");
75
+ var import_echo_protocol = require("@dxos/echo-protocol");
81
76
  var import_invariant4 = require("@dxos/invariant");
82
- var import_log4 = require("@dxos/log");
77
+ var import_log2 = require("@dxos/log");
83
78
  var import_tracing2 = require("@dxos/tracing");
84
79
  var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
85
80
  var import_context5 = require("@dxos/context");
86
81
  var import_invariant5 = require("@dxos/invariant");
87
82
  var import_keys2 = require("@dxos/keys");
88
- var import_log5 = require("@dxos/log");
83
+ var import_log3 = require("@dxos/log");
89
84
  var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
90
- var import_util3 = require("@dxos/util");
85
+ var import_util2 = require("@dxos/util");
91
86
  function _ts_decorate(decorators, target, key, desc) {
92
87
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
93
88
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -120,7 +115,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
120
115
  }
121
116
  connectionEntry.writer.write(message).catch((err) => {
122
117
  if (connectionEntry.isOpen) {
123
- import_log2.log.catch(err, void 0, {
118
+ import_log.log.catch(err, void 0, {
124
119
  F: __dxlog_file,
125
120
  L: 49,
126
121
  S: this,
@@ -142,7 +137,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
142
137
  ]
143
138
  });
144
139
  this._lifecycleState = import_context2.LifecycleState.OPEN;
145
- (0, import_log2.log)("emit ready", void 0, {
140
+ (0, import_log.log)("emit ready", void 0, {
146
141
  F: __dxlog_file,
147
142
  L: 63,
148
143
  S: this,
@@ -206,13 +201,14 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
206
201
  peerId: this.peerId,
207
202
  onConnectionOpen: this._onConnectionOpen.bind(this),
208
203
  onConnectionClosed: this._onConnectionClosed.bind(this),
204
+ onConnectionAuthScopeChanged: this._onConnectionAuthScopeChanged.bind(this),
209
205
  getContainingSpaceForDocument: this._params.getContainingSpaceForDocument
210
206
  });
211
207
  }
212
208
  async removeReplicator(replicator) {
213
209
  (0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
214
210
  F: __dxlog_file,
215
- L: 102,
211
+ L: 103,
216
212
  S: this,
217
213
  A: [
218
214
  "this._lifecycleState === LifecycleState.OPEN",
@@ -221,14 +217,13 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
221
217
  });
222
218
  (0, import_invariant2.invariant)(this._replicators.has(replicator), void 0, {
223
219
  F: __dxlog_file,
224
- L: 103,
220
+ L: 104,
225
221
  S: this,
226
222
  A: [
227
223
  "this._replicators.has(replicator)",
228
224
  ""
229
225
  ]
230
226
  });
231
- "";
232
227
  await replicator.disconnect();
233
228
  this._replicators.delete(replicator);
234
229
  }
@@ -240,7 +235,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
240
235
  return connection.connection.shouldAdvertize(params);
241
236
  }
242
237
  _onConnectionOpen(connection) {
243
- (0, import_log2.log)("Connection opened", {
238
+ (0, import_log.log)("Connection opened", {
244
239
  peerId: connection.peerId
245
240
  }, {
246
241
  F: __dxlog_file,
@@ -277,7 +272,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
277
272
  }
278
273
  } catch (err) {
279
274
  if (connectionEntry.isOpen) {
280
- import_log2.log.catch(err, void 0, {
275
+ import_log.log.catch(err, void 0, {
281
276
  F: __dxlog_file,
282
277
  L: 139,
283
278
  S: this,
@@ -286,7 +281,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
286
281
  }
287
282
  }
288
283
  });
289
- (0, import_log2.log)("emit peer-candidate", {
284
+ (0, import_log.log)("emit peer-candidate", {
290
285
  peerId: connection.peerId
291
286
  }, {
292
287
  F: __dxlog_file,
@@ -294,27 +289,49 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
294
289
  S: this,
295
290
  C: (f, a) => f(...a)
296
291
  });
297
- this.emit("peer-candidate", {
298
- peerId: connection.peerId,
299
- peerMetadata: {
300
- // TODO(dmaretskyi): Refactor this.
301
- dxos_peerSource: "EchoNetworkAdapter"
302
- }
292
+ this._emitPeerCandidate(connection);
293
+ }
294
+ /**
295
+ * Trigger doc-synchronizer shared documents set recalculation. Happens on peer-candidate.
296
+ * TODO(y): replace with a proper API call when sharePolicy update becomes supported by automerge-repo
297
+ */
298
+ _onConnectionAuthScopeChanged(connection) {
299
+ (0, import_log.log)("Connection auth scope changed", {
300
+ peerId: connection.peerId
301
+ }, {
302
+ F: __dxlog_file,
303
+ L: 153,
304
+ S: this,
305
+ C: (f, a) => f(...a)
303
306
  });
307
+ const entry = this._connections.get(connection.peerId);
308
+ (0, import_invariant2.invariant)(entry, void 0, {
309
+ F: __dxlog_file,
310
+ L: 155,
311
+ S: this,
312
+ A: [
313
+ "entry",
314
+ ""
315
+ ]
316
+ });
317
+ this.emit("peer-disconnected", {
318
+ peerId: connection.peerId
319
+ });
320
+ this._emitPeerCandidate(connection);
304
321
  }
305
322
  _onConnectionClosed(connection) {
306
- (0, import_log2.log)("Connection closed", {
323
+ (0, import_log.log)("Connection closed", {
307
324
  peerId: connection.peerId
308
325
  }, {
309
326
  F: __dxlog_file,
310
- L: 155,
327
+ L: 161,
311
328
  S: this,
312
329
  C: (f, a) => f(...a)
313
330
  });
314
331
  const entry = this._connections.get(connection.peerId);
315
332
  (0, import_invariant2.invariant)(entry, void 0, {
316
333
  F: __dxlog_file,
317
- L: 157,
334
+ L: 163,
318
335
  S: this,
319
336
  A: [
320
337
  "entry",
@@ -325,20 +342,29 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
325
342
  this.emit("peer-disconnected", {
326
343
  peerId: connection.peerId
327
344
  });
328
- void entry.reader.cancel().catch((err) => import_log2.log.catch(err, void 0, {
345
+ void entry.reader.cancel().catch((err) => import_log.log.catch(err, void 0, {
329
346
  F: __dxlog_file,
330
- L: 162,
347
+ L: 168,
331
348
  S: this,
332
349
  C: (f, a) => f(...a)
333
350
  }));
334
- void entry.writer.abort().catch((err) => import_log2.log.catch(err, void 0, {
351
+ void entry.writer.abort().catch((err) => import_log.log.catch(err, void 0, {
335
352
  F: __dxlog_file,
336
- L: 163,
353
+ L: 169,
337
354
  S: this,
338
355
  C: (f, a) => f(...a)
339
356
  }));
340
357
  this._connections.delete(connection.peerId);
341
358
  }
359
+ _emitPeerCandidate(connection) {
360
+ this.emit("peer-candidate", {
361
+ peerId: connection.peerId,
362
+ peerMetadata: {
363
+ // TODO(dmaretskyi): Refactor this.
364
+ dxos_peerSource: "EchoNetworkAdapter"
365
+ }
366
+ });
367
+ }
342
368
  };
343
369
  _ts_decorate([
344
370
  import_async2.synchronized
@@ -577,108 +603,6 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
577
603
  return id;
578
604
  }
579
605
  };
580
- var AutomergeStorageAdapter = class {
581
- constructor(_directory) {
582
- this._directory = _directory;
583
- this._state = "opened";
584
- }
585
- async load(key) {
586
- if (this._state !== "opened") {
587
- return void 0;
588
- }
589
- const filename = this._getFilename(key);
590
- const file = this._directory.getOrCreateFile(filename);
591
- const { size } = await file.stat();
592
- if (!size || size === 0) {
593
- return void 0;
594
- }
595
- const buffer = await file.read(0, size);
596
- return (0, import_util2.bufferToArray)(buffer);
597
- }
598
- async save(key, data) {
599
- if (this._state !== "opened") {
600
- return void 0;
601
- }
602
- const filename = this._getFilename(key);
603
- const file = this._directory.getOrCreateFile(filename);
604
- await file.write(0, (0, import_util2.arrayToBuffer)(data));
605
- await file.truncate?.(data.length);
606
- await file.flush?.();
607
- }
608
- async remove(key) {
609
- if (this._state !== "opened") {
610
- return void 0;
611
- }
612
- const filename = this._getFilename(key);
613
- const file = this._directory.getOrCreateFile(filename);
614
- await file.destroy();
615
- }
616
- async loadRange(keyPrefix) {
617
- if (this._state !== "opened") {
618
- return [];
619
- }
620
- const filename = this._getFilename(keyPrefix);
621
- const entries = await this._directory.list();
622
- return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
623
- const file = this._directory.getOrCreateFile(entry);
624
- const { size } = await file.stat();
625
- const buffer = await file.read(0, size);
626
- return {
627
- key: this._getKeyFromFilename(entry),
628
- data: (0, import_util2.bufferToArray)(buffer)
629
- };
630
- }));
631
- }
632
- async removeRange(keyPrefix) {
633
- if (this._state !== "opened") {
634
- return void 0;
635
- }
636
- const filename = this._getFilename(keyPrefix);
637
- const entries = await this._directory.list();
638
- await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
639
- const file = this._directory.getOrCreateFile(entry);
640
- await file.destroy();
641
- }));
642
- }
643
- async close() {
644
- this._state = "closed";
645
- }
646
- _getFilename(key) {
647
- return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
648
- }
649
- _getKeyFromFilename(filename) {
650
- return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
651
- }
652
- };
653
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
654
- var levelMigration = async ({ db, directory }) => {
655
- const isNewLevel = !await db.iterator({
656
- ...encodingOptions
657
- }).next();
658
- if (!isNewLevel) {
659
- return;
660
- }
661
- const oldStorageAdapter = directory.type === import_random_access_storage.StorageType.IDB ? new import_automerge_repo_storage_indexeddb.IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory);
662
- const chunks = await oldStorageAdapter.loadRange([]);
663
- if (chunks.length === 0) {
664
- return;
665
- }
666
- const batch = db.batch();
667
- import_log3.log.info("found chunks on old storage adapter", {
668
- chunks: chunks.length
669
- }, {
670
- F: __dxlog_file3,
671
- L: 37,
672
- S: void 0,
673
- C: (f, a) => f(...a)
674
- });
675
- for (const { key, data } of await oldStorageAdapter.loadRange([])) {
676
- data && batch.put(key, data, {
677
- ...encodingOptions
678
- });
679
- }
680
- await batch.write();
681
- };
682
606
  function _ts_decorate2(decorators, target, key, desc) {
683
607
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
684
608
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -689,31 +613,24 @@ function _ts_decorate2(decorators, target, key, desc) {
689
613
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
690
614
  return c > 3 && r && Object.defineProperty(target, key, r), r;
691
615
  }
692
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
616
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
693
617
  var AutomergeHost = class {
694
- constructor({ directory, db, indexMetadataStore }) {
618
+ constructor({ db, indexMetadataStore }) {
695
619
  this._ctx = new import_context.Context();
696
620
  this._echoNetworkAdapter = new EchoNetworkAdapter({
697
621
  getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
698
622
  });
699
- this._requestedDocs = /* @__PURE__ */ new Set();
700
- this._directory = directory;
701
- this._db = db;
702
- this._indexMetadataStore = indexMetadataStore;
703
- }
704
- async open() {
705
- this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
706
- this._directory && await levelMigration({
707
- db: this._db,
708
- directory: this._directory
709
- });
710
623
  this._storage = new LevelDBStorageAdapter({
711
- db: this._db,
624
+ db,
712
625
  callbacks: {
713
626
  beforeSave: async (params) => this._beforeSave(params),
714
627
  afterSave: async () => this._afterSave()
715
628
  }
716
629
  });
630
+ this._indexMetadataStore = indexMetadataStore;
631
+ }
632
+ async open() {
633
+ this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
717
634
  await this._storage.open?.();
718
635
  this._clientNetwork = new LocalHostNetworkAdapter();
719
636
  this._repo = new import_automerge_repo.Repo({
@@ -758,21 +675,6 @@ var AutomergeHost = class {
758
675
  if (!documentId) {
759
676
  return false;
760
677
  }
761
- const doc = this._repo.handles[documentId]?.docSync();
762
- if (!doc) {
763
- const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
764
- (0, import_log.log)("doc share policy check", {
765
- peerId,
766
- documentId,
767
- isRequested
768
- }, {
769
- F: __dxlog_file4,
770
- L: 156,
771
- S: this,
772
- C: (f, a) => f(...a)
773
- });
774
- return isRequested;
775
- }
776
678
  const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
777
679
  if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
778
680
  return this._echoNetworkAdapter.shouldAdvertize(peerId, {
@@ -852,8 +754,8 @@ var AutomergeHost = class {
852
754
  async flush({ states }) {
853
755
  await Promise.all(states?.map(async ({ heads, documentId }) => {
854
756
  (0, import_invariant.invariant)(heads, "heads are required for flush", {
855
- F: __dxlog_file4,
856
- L: 250,
757
+ F: __dxlog_file3,
758
+ L: 223,
857
759
  S: this,
858
760
  A: [
859
761
  "heads",
@@ -931,7 +833,7 @@ function _ts_decorate3(decorators, target, key, desc) {
931
833
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
932
834
  return c > 3 && r && Object.defineProperty(target, key, r), r;
933
835
  }
934
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
836
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
935
837
  var AutomergeDocumentLoaderImpl = class {
936
838
  constructor(_spaceId, _repo, _spaceKey) {
937
839
  this._spaceId = _spaceId;
@@ -953,10 +855,10 @@ var AutomergeDocumentLoaderImpl = class {
953
855
  return;
954
856
  }
955
857
  if (!spaceState.rootUrl) {
956
- import_log4.log.error("Database opened with no rootUrl", {
858
+ import_log2.log.error("Database opened with no rootUrl", {
957
859
  spaceId: this._spaceId
958
860
  }, {
959
- F: __dxlog_file5,
861
+ F: __dxlog_file4,
960
862
  L: 72,
961
863
  S: this,
962
864
  C: (f, a) => f(...a)
@@ -966,7 +868,7 @@ var AutomergeDocumentLoaderImpl = class {
966
868
  const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
967
869
  const doc = existingDocHandle.docSync();
968
870
  (0, import_invariant4.invariant)(doc, void 0, {
969
- F: __dxlog_file5,
871
+ F: __dxlog_file4,
970
872
  L: 77,
971
873
  S: this,
972
874
  A: [
@@ -988,7 +890,7 @@ var AutomergeDocumentLoaderImpl = class {
988
890
  const urlsToLoad = {};
989
891
  for (const objectId of objectIds) {
990
892
  (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
991
- F: __dxlog_file5,
893
+ F: __dxlog_file4,
992
894
  L: 90,
993
895
  S: this,
994
896
  A: [
@@ -1001,7 +903,7 @@ var AutomergeDocumentLoaderImpl = class {
1001
903
  }
1002
904
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
1003
905
  (0, import_invariant4.invariant)(spaceRootDoc, void 0, {
1004
- F: __dxlog_file5,
906
+ F: __dxlog_file4,
1005
907
  L: 95,
1006
908
  S: this,
1007
909
  A: [
@@ -1012,10 +914,10 @@ var AutomergeDocumentLoaderImpl = class {
1012
914
  const documentUrl = (spaceRootDoc.links ?? {})[objectId];
1013
915
  if (documentUrl == null) {
1014
916
  this._objectsPendingDocumentLoad.add(objectId);
1015
- import_log4.log.info("loading delayed until object links are initialized", {
917
+ import_log2.log.info("loading delayed until object links are initialized", {
1016
918
  objectId
1017
919
  }, {
1018
- F: __dxlog_file5,
920
+ F: __dxlog_file4,
1019
921
  L: 99,
1020
922
  S: this,
1021
923
  C: (f, a) => f(...a)
@@ -1039,7 +941,7 @@ var AutomergeDocumentLoaderImpl = class {
1039
941
  }
1040
942
  getSpaceRootDocHandle() {
1041
943
  (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1042
- F: __dxlog_file5,
944
+ F: __dxlog_file4,
1043
945
  L: 122,
1044
946
  S: this,
1045
947
  A: [
@@ -1051,7 +953,7 @@ var AutomergeDocumentLoaderImpl = class {
1051
953
  }
1052
954
  createDocumentForObject(objectId) {
1053
955
  (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1054
- F: __dxlog_file5,
956
+ F: __dxlog_file4,
1055
957
  L: 127,
1056
958
  S: this,
1057
959
  A: [
@@ -1059,7 +961,9 @@ var AutomergeDocumentLoaderImpl = class {
1059
961
  ""
1060
962
  ]
1061
963
  });
1062
- const spaceDocHandle = this._repo.create();
964
+ const spaceDocHandle = this._repo.create({
965
+ version: import_echo_protocol.SpaceDocVersion.CURRENT
966
+ });
1063
967
  this._initDocAccess(spaceDocHandle);
1064
968
  this.onObjectBoundToDocument(spaceDocHandle, objectId);
1065
969
  this._spaceRootDocHandle.change((newDoc) => {
@@ -1090,30 +994,30 @@ var AutomergeDocumentLoaderImpl = class {
1090
994
  };
1091
995
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
1092
996
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
1093
- import_log4.log.warn("object already inlined in a different document, ignoring the link", {
997
+ import_log2.log.warn("object already inlined in a different document, ignoring the link", {
1094
998
  ...logMeta,
1095
999
  actualDocumentUrl: objectDocumentHandle.url
1096
1000
  }, {
1097
- F: __dxlog_file5,
1098
- L: 157,
1001
+ F: __dxlog_file4,
1002
+ L: 159,
1099
1003
  S: this,
1100
1004
  C: (f, a) => f(...a)
1101
1005
  });
1102
1006
  continue;
1103
1007
  }
1104
1008
  if (objectDocumentHandle?.url === automergeUrl) {
1105
- import_log4.log.warn("object document was already loaded", logMeta, {
1106
- F: __dxlog_file5,
1107
- L: 164,
1009
+ import_log2.log.warn("object document was already loaded", logMeta, {
1010
+ F: __dxlog_file4,
1011
+ L: 166,
1108
1012
  S: this,
1109
1013
  C: (f, a) => f(...a)
1110
1014
  });
1111
1015
  continue;
1112
1016
  }
1113
1017
  const handle = this._repo.find(automergeUrl);
1114
- import_log4.log.debug("document loading triggered", logMeta, {
1115
- F: __dxlog_file5,
1116
- L: 168,
1018
+ import_log2.log.debug("document loading triggered", logMeta, {
1019
+ F: __dxlog_file4,
1020
+ L: 170,
1117
1021
  S: this,
1118
1022
  C: (f, a) => f(...a)
1119
1023
  });
@@ -1131,12 +1035,12 @@ var AutomergeDocumentLoaderImpl = class {
1131
1035
  break;
1132
1036
  } catch (err) {
1133
1037
  if (`${err}`.includes("Timeout")) {
1134
- import_log4.log.info("wraparound", {
1038
+ import_log2.log.info("wraparound", {
1135
1039
  id: docHandle.documentId,
1136
1040
  state: docHandle.state
1137
1041
  }, {
1138
- F: __dxlog_file5,
1139
- L: 184,
1042
+ F: __dxlog_file4,
1043
+ L: 186,
1140
1044
  S: this,
1141
1045
  C: (f, a) => f(...a)
1142
1046
  });
@@ -1176,9 +1080,9 @@ var AutomergeDocumentLoaderImpl = class {
1176
1080
  docUrl: handle.url
1177
1081
  };
1178
1082
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1179
- import_log4.log.info("document loaded after all listeners were removed", logMeta, {
1180
- F: __dxlog_file5,
1181
- L: 220,
1083
+ import_log2.log.info("document loaded after all listeners were removed", logMeta, {
1084
+ F: __dxlog_file4,
1085
+ L: 222,
1182
1086
  S: this,
1183
1087
  C: (f, a) => f(...a)
1184
1088
  });
@@ -1186,9 +1090,9 @@ var AutomergeDocumentLoaderImpl = class {
1186
1090
  }
1187
1091
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1188
1092
  if (objectDocHandle?.url !== handle.url) {
1189
- import_log4.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1190
- F: __dxlog_file5,
1191
- L: 225,
1093
+ import_log2.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1094
+ F: __dxlog_file4,
1095
+ L: 227,
1192
1096
  S: this,
1193
1097
  C: (f, a) => f(...a)
1194
1098
  });
@@ -1200,14 +1104,14 @@ var AutomergeDocumentLoaderImpl = class {
1200
1104
  });
1201
1105
  } catch (err) {
1202
1106
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1203
- import_log4.log.warn("failed to load a document", {
1107
+ import_log2.log.warn("failed to load a document", {
1204
1108
  objectId,
1205
1109
  automergeUrl: handle.url,
1206
1110
  retryLoading: shouldRetryLoading,
1207
1111
  err
1208
1112
  }, {
1209
- F: __dxlog_file5,
1210
- L: 231,
1113
+ F: __dxlog_file4,
1114
+ L: 233,
1211
1115
  S: this,
1212
1116
  C: (f, a) => f(...a)
1213
1117
  });
@@ -1225,12 +1129,12 @@ _ts_decorate3([
1225
1129
  AutomergeDocumentLoaderImpl = _ts_decorate3([
1226
1130
  import_tracing2.trace.resource()
1227
1131
  ], AutomergeDocumentLoaderImpl);
1228
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1132
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1229
1133
  var MeshEchoReplicator = class {
1230
1134
  constructor() {
1231
1135
  this._connections = /* @__PURE__ */ new Set();
1232
1136
  this._connectionsPerPeer = /* @__PURE__ */ new Map();
1233
- this._authorizedDevices = new import_util3.ComplexMap(import_keys2.PublicKey.hash);
1137
+ this._authorizedDevices = new import_util2.ComplexMap(import_keys2.PublicKey.hash);
1234
1138
  this._context = null;
1235
1139
  }
1236
1140
  async connect(context) {
@@ -1246,7 +1150,7 @@ var MeshEchoReplicator = class {
1246
1150
  }
1247
1151
  createExtension() {
1248
1152
  (0, import_invariant5.invariant)(this._context, void 0, {
1249
- F: __dxlog_file6,
1153
+ F: __dxlog_file5,
1250
1154
  L: 54,
1251
1155
  S: this,
1252
1156
  A: [
@@ -1257,16 +1161,16 @@ var MeshEchoReplicator = class {
1257
1161
  const connection = new MeshReplicatorConnection({
1258
1162
  ownPeerId: this._context.peerId,
1259
1163
  onRemoteConnected: async () => {
1260
- (0, import_log5.log)("onRemoteConnected", {
1164
+ (0, import_log3.log)("onRemoteConnected", {
1261
1165
  peerId: connection.peerId
1262
1166
  }, {
1263
- F: __dxlog_file6,
1167
+ F: __dxlog_file5,
1264
1168
  L: 59,
1265
1169
  S: this,
1266
1170
  C: (f, a) => f(...a)
1267
1171
  });
1268
1172
  (0, import_invariant5.invariant)(this._context, void 0, {
1269
- F: __dxlog_file6,
1173
+ F: __dxlog_file5,
1270
1174
  L: 60,
1271
1175
  S: this,
1272
1176
  A: [
@@ -1274,18 +1178,20 @@ var MeshEchoReplicator = class {
1274
1178
  ""
1275
1179
  ]
1276
1180
  });
1277
- if (!this._connectionsPerPeer.has(connection.peerId)) {
1181
+ if (this._connectionsPerPeer.has(connection.peerId)) {
1182
+ this._context.onConnectionAuthScopeChanged(connection);
1183
+ } else {
1278
1184
  this._connectionsPerPeer.set(connection.peerId, connection);
1279
1185
  await connection.enable();
1280
1186
  this._context.onConnectionOpen(connection);
1281
1187
  }
1282
1188
  },
1283
1189
  onRemoteDisconnected: async () => {
1284
- (0, import_log5.log)("onRemoteDisconnected", {
1190
+ (0, import_log3.log)("onRemoteDisconnected", {
1285
1191
  peerId: connection.peerId
1286
1192
  }, {
1287
- F: __dxlog_file6,
1288
- L: 69,
1193
+ F: __dxlog_file5,
1194
+ L: 71,
1289
1195
  S: this,
1290
1196
  C: (f, a) => f(...a)
1291
1197
  });
@@ -1295,18 +1201,18 @@ var MeshEchoReplicator = class {
1295
1201
  this._connections.delete(connection);
1296
1202
  },
1297
1203
  shouldAdvertize: async (params) => {
1298
- (0, import_log5.log)("shouldAdvertize", {
1204
+ (0, import_log3.log)("shouldAdvertize", {
1299
1205
  peerId: connection.peerId,
1300
1206
  documentId: params.documentId
1301
1207
  }, {
1302
- F: __dxlog_file6,
1303
- L: 76,
1208
+ F: __dxlog_file5,
1209
+ L: 78,
1304
1210
  S: this,
1305
1211
  C: (f, a) => f(...a)
1306
1212
  });
1307
1213
  (0, import_invariant5.invariant)(this._context, void 0, {
1308
- F: __dxlog_file6,
1309
- L: 77,
1214
+ F: __dxlog_file5,
1215
+ L: 79,
1310
1216
  S: this,
1311
1217
  A: [
1312
1218
  "this._context",
@@ -1316,12 +1222,12 @@ var MeshEchoReplicator = class {
1316
1222
  try {
1317
1223
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1318
1224
  if (!spaceKey) {
1319
- (0, import_log5.log)("space key not found for share policy check", {
1225
+ (0, import_log3.log)("space key not found for share policy check", {
1320
1226
  peerId: connection.peerId,
1321
1227
  documentId: params.documentId
1322
1228
  }, {
1323
- F: __dxlog_file6,
1324
- L: 81,
1229
+ F: __dxlog_file5,
1230
+ L: 83,
1325
1231
  S: this,
1326
1232
  C: (f, a) => f(...a)
1327
1233
  });
@@ -1329,19 +1235,19 @@ var MeshEchoReplicator = class {
1329
1235
  }
1330
1236
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1331
1237
  if (!connection.remoteDeviceKey) {
1332
- (0, import_log5.log)("device key not found for share policy check", {
1238
+ (0, import_log3.log)("device key not found for share policy check", {
1333
1239
  peerId: connection.peerId,
1334
1240
  documentId: params.documentId
1335
1241
  }, {
1336
- F: __dxlog_file6,
1337
- L: 91,
1242
+ F: __dxlog_file5,
1243
+ L: 93,
1338
1244
  S: this,
1339
1245
  C: (f, a) => f(...a)
1340
1246
  });
1341
1247
  return false;
1342
1248
  }
1343
1249
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1344
- (0, import_log5.log)("share policy check", {
1250
+ (0, import_log3.log)("share policy check", {
1345
1251
  localPeer: this._context.peerId,
1346
1252
  remotePeer: connection.peerId,
1347
1253
  documentId: params.documentId,
@@ -1349,16 +1255,16 @@ var MeshEchoReplicator = class {
1349
1255
  spaceKey,
1350
1256
  isAuthorized
1351
1257
  }, {
1352
- F: __dxlog_file6,
1353
- L: 99,
1258
+ F: __dxlog_file5,
1259
+ L: 101,
1354
1260
  S: this,
1355
1261
  C: (f, a) => f(...a)
1356
1262
  });
1357
1263
  return isAuthorized;
1358
1264
  } catch (err) {
1359
- import_log5.log.catch(err, void 0, {
1360
- F: __dxlog_file6,
1361
- L: 109,
1265
+ import_log3.log.catch(err, void 0, {
1266
+ F: __dxlog_file5,
1267
+ L: 111,
1362
1268
  S: this,
1363
1269
  C: (f, a) => f(...a)
1364
1270
  });
@@ -1370,16 +1276,21 @@ var MeshEchoReplicator = class {
1370
1276
  return connection.replicatorExtension;
1371
1277
  }
1372
1278
  authorizeDevice(spaceKey, deviceKey) {
1373
- (0, import_log5.log)("authorizeDevice", {
1279
+ (0, import_log3.log)("authorizeDevice", {
1374
1280
  spaceKey,
1375
1281
  deviceKey
1376
1282
  }, {
1377
- F: __dxlog_file6,
1378
- L: 120,
1283
+ F: __dxlog_file5,
1284
+ L: 122,
1379
1285
  S: this,
1380
1286
  C: (f, a) => f(...a)
1381
1287
  });
1382
- (0, import_util3.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util3.ComplexSet(import_keys2.PublicKey.hash)).add(deviceKey);
1288
+ (0, import_util2.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util2.ComplexSet(import_keys2.PublicKey.hash)).add(deviceKey);
1289
+ for (const connection of this._connections) {
1290
+ if (connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
1291
+ this._context?.onConnectionAuthScopeChanged(connection);
1292
+ }
1293
+ }
1383
1294
  }
1384
1295
  };
1385
1296
  var MeshReplicatorConnection = class extends import_context5.Resource {
@@ -1411,13 +1322,13 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1411
1322
  onStartReplication: async (info, remotePeerId) => {
1412
1323
  this.remoteDeviceKey = remotePeerId;
1413
1324
  this._remotePeerId = info.id;
1414
- (0, import_log5.log)("onStartReplication", {
1325
+ (0, import_log3.log)("onStartReplication", {
1415
1326
  id: info.id,
1416
1327
  thisPeerId: this.peerId,
1417
1328
  remotePeerId: remotePeerId.toHex()
1418
1329
  }, {
1419
- F: __dxlog_file6,
1420
- L: 185,
1330
+ F: __dxlog_file5,
1331
+ L: 192,
1421
1332
  S: this,
1422
1333
  C: (f, a) => f(...a)
1423
1334
  });
@@ -1440,8 +1351,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1440
1351
  }
1441
1352
  get peerId() {
1442
1353
  (0, import_invariant5.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1443
- F: __dxlog_file6,
1444
- L: 208,
1354
+ F: __dxlog_file5,
1355
+ L: 215,
1445
1356
  S: this,
1446
1357
  A: [
1447
1358
  "this._remotePeerId != null",
@@ -1459,8 +1370,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1459
1370
  */
1460
1371
  async enable() {
1461
1372
  (0, import_invariant5.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1462
- F: __dxlog_file6,
1463
- L: 221,
1373
+ F: __dxlog_file5,
1374
+ L: 228,
1464
1375
  S: this,
1465
1376
  A: [
1466
1377
  "this._remotePeerId != null",
@@ -1482,7 +1393,6 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1482
1393
  AuthStatus,
1483
1394
  AutomergeDocumentLoaderImpl,
1484
1395
  AutomergeHost,
1485
- AutomergeStorageAdapter,
1486
1396
  DataServiceImpl,
1487
1397
  LevelDBStorageAdapter,
1488
1398
  LocalHostNetworkAdapter,