@dxos/echo-pipeline 0.5.9-main.1c1903d → 0.5.9-main.1ea2105

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.
@@ -32,7 +32,6 @@ import { Repo } from "@dxos/automerge/automerge-repo";
32
32
  import { Context } from "@dxos/context";
33
33
  import { invariant as invariant3 } from "@dxos/invariant";
34
34
  import { PublicKey } from "@dxos/keys";
35
- import { log as log2 } from "@dxos/log";
36
35
  import { objectPointerCodec } from "@dxos/protocols";
37
36
  import { trace } from "@dxos/tracing";
38
37
  import { mapValues } from "@dxos/util";
@@ -591,7 +590,6 @@ var AutomergeHost = class {
591
590
  this._echoNetworkAdapter = new EchoNetworkAdapter({
592
591
  getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
593
592
  });
594
- this._requestedDocs = /* @__PURE__ */ new Set();
595
593
  this._storage = new LevelDBStorageAdapter({
596
594
  db,
597
595
  callbacks: {
@@ -647,21 +645,6 @@ var AutomergeHost = class {
647
645
  if (!documentId) {
648
646
  return false;
649
647
  }
650
- const doc = this._repo.handles[documentId]?.docSync();
651
- if (!doc) {
652
- const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
653
- log2("doc share policy check", {
654
- peerId,
655
- documentId,
656
- isRequested
657
- }, {
658
- F: __dxlog_file3,
659
- L: 143,
660
- S: this,
661
- C: (f, a) => f(...a)
662
- });
663
- return isRequested;
664
- }
665
648
  const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
666
649
  if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
667
650
  return this._echoNetworkAdapter.shouldAdvertize(peerId, {
@@ -742,7 +725,7 @@ var AutomergeHost = class {
742
725
  await Promise.all(states?.map(async ({ heads, documentId }) => {
743
726
  invariant3(heads, "heads are required for flush", {
744
727
  F: __dxlog_file3,
745
- L: 237,
728
+ L: 223,
746
729
  S: this,
747
730
  A: [
748
731
  "heads",
@@ -815,8 +798,9 @@ var changeIsPresentInDoc = (doc, changeHash) => {
815
798
  import { Event as Event2 } from "@dxos/async";
816
799
  import { cancelWithContext } from "@dxos/context";
817
800
  import { warnAfterTimeout } from "@dxos/debug";
801
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
818
802
  import { invariant as invariant4 } from "@dxos/invariant";
819
- import { log as log3 } from "@dxos/log";
803
+ import { log as log2 } from "@dxos/log";
820
804
  import { trace as trace2 } from "@dxos/tracing";
821
805
  function _ts_decorate3(decorators, target, key, desc) {
822
806
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -850,7 +834,7 @@ var AutomergeDocumentLoaderImpl = class {
850
834
  return;
851
835
  }
852
836
  if (!spaceState.rootUrl) {
853
- log3.error("Database opened with no rootUrl", {
837
+ log2.error("Database opened with no rootUrl", {
854
838
  spaceId: this._spaceId
855
839
  }, {
856
840
  F: __dxlog_file4,
@@ -909,7 +893,7 @@ var AutomergeDocumentLoaderImpl = class {
909
893
  const documentUrl = (spaceRootDoc.links ?? {})[objectId];
910
894
  if (documentUrl == null) {
911
895
  this._objectsPendingDocumentLoad.add(objectId);
912
- log3.info("loading delayed until object links are initialized", {
896
+ log2.info("loading delayed until object links are initialized", {
913
897
  objectId
914
898
  }, {
915
899
  F: __dxlog_file4,
@@ -956,7 +940,9 @@ var AutomergeDocumentLoaderImpl = class {
956
940
  ""
957
941
  ]
958
942
  });
959
- const spaceDocHandle = this._repo.create();
943
+ const spaceDocHandle = this._repo.create({
944
+ version: SpaceDocVersion.CURRENT
945
+ });
960
946
  this._initDocAccess(spaceDocHandle);
961
947
  this.onObjectBoundToDocument(spaceDocHandle, objectId);
962
948
  this._spaceRootDocHandle.change((newDoc) => {
@@ -987,30 +973,30 @@ var AutomergeDocumentLoaderImpl = class {
987
973
  };
988
974
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
989
975
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
990
- log3.warn("object already inlined in a different document, ignoring the link", {
976
+ log2.warn("object already inlined in a different document, ignoring the link", {
991
977
  ...logMeta,
992
978
  actualDocumentUrl: objectDocumentHandle.url
993
979
  }, {
994
980
  F: __dxlog_file4,
995
- L: 157,
981
+ L: 159,
996
982
  S: this,
997
983
  C: (f, a) => f(...a)
998
984
  });
999
985
  continue;
1000
986
  }
1001
987
  if (objectDocumentHandle?.url === automergeUrl) {
1002
- log3.warn("object document was already loaded", logMeta, {
988
+ log2.warn("object document was already loaded", logMeta, {
1003
989
  F: __dxlog_file4,
1004
- L: 164,
990
+ L: 166,
1005
991
  S: this,
1006
992
  C: (f, a) => f(...a)
1007
993
  });
1008
994
  continue;
1009
995
  }
1010
996
  const handle = this._repo.find(automergeUrl);
1011
- log3.debug("document loading triggered", logMeta, {
997
+ log2.debug("document loading triggered", logMeta, {
1012
998
  F: __dxlog_file4,
1013
- L: 168,
999
+ L: 170,
1014
1000
  S: this,
1015
1001
  C: (f, a) => f(...a)
1016
1002
  });
@@ -1028,12 +1014,12 @@ var AutomergeDocumentLoaderImpl = class {
1028
1014
  break;
1029
1015
  } catch (err) {
1030
1016
  if (`${err}`.includes("Timeout")) {
1031
- log3.info("wraparound", {
1017
+ log2.info("wraparound", {
1032
1018
  id: docHandle.documentId,
1033
1019
  state: docHandle.state
1034
1020
  }, {
1035
1021
  F: __dxlog_file4,
1036
- L: 184,
1022
+ L: 186,
1037
1023
  S: this,
1038
1024
  C: (f, a) => f(...a)
1039
1025
  });
@@ -1073,9 +1059,9 @@ var AutomergeDocumentLoaderImpl = class {
1073
1059
  docUrl: handle.url
1074
1060
  };
1075
1061
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1076
- log3.info("document loaded after all listeners were removed", logMeta, {
1062
+ log2.info("document loaded after all listeners were removed", logMeta, {
1077
1063
  F: __dxlog_file4,
1078
- L: 220,
1064
+ L: 222,
1079
1065
  S: this,
1080
1066
  C: (f, a) => f(...a)
1081
1067
  });
@@ -1083,9 +1069,9 @@ var AutomergeDocumentLoaderImpl = class {
1083
1069
  }
1084
1070
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1085
1071
  if (objectDocHandle?.url !== handle.url) {
1086
- log3.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1072
+ log2.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1087
1073
  F: __dxlog_file4,
1088
- L: 225,
1074
+ L: 227,
1089
1075
  S: this,
1090
1076
  C: (f, a) => f(...a)
1091
1077
  });
@@ -1097,14 +1083,14 @@ var AutomergeDocumentLoaderImpl = class {
1097
1083
  });
1098
1084
  } catch (err) {
1099
1085
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1100
- log3.warn("failed to load a document", {
1086
+ log2.warn("failed to load a document", {
1101
1087
  objectId,
1102
1088
  automergeUrl: handle.url,
1103
1089
  retryLoading: shouldRetryLoading,
1104
1090
  err
1105
1091
  }, {
1106
1092
  F: __dxlog_file4,
1107
- L: 231,
1093
+ L: 233,
1108
1094
  S: this,
1109
1095
  C: (f, a) => f(...a)
1110
1096
  });
@@ -1128,7 +1114,7 @@ import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
1128
1114
  import { Resource as Resource2 } from "@dxos/context";
1129
1115
  import { invariant as invariant5 } from "@dxos/invariant";
1130
1116
  import { PublicKey as PublicKey2 } from "@dxos/keys";
1131
- import { log as log4 } from "@dxos/log";
1117
+ import { log as log3 } from "@dxos/log";
1132
1118
  import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
1133
1119
  import { ComplexMap, ComplexSet, defaultMap } from "@dxos/util";
1134
1120
  var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
@@ -1169,7 +1155,7 @@ var MeshEchoReplicator = class {
1169
1155
  const connection = new MeshReplicatorConnection({
1170
1156
  ownPeerId: this._context.peerId,
1171
1157
  onRemoteConnected: async () => {
1172
- log4("onRemoteConnected", {
1158
+ log3("onRemoteConnected", {
1173
1159
  peerId: connection.peerId
1174
1160
  }, {
1175
1161
  F: __dxlog_file5,
@@ -1195,7 +1181,7 @@ var MeshEchoReplicator = class {
1195
1181
  }
1196
1182
  },
1197
1183
  onRemoteDisconnected: async () => {
1198
- log4("onRemoteDisconnected", {
1184
+ log3("onRemoteDisconnected", {
1199
1185
  peerId: connection.peerId
1200
1186
  }, {
1201
1187
  F: __dxlog_file5,
@@ -1209,7 +1195,7 @@ var MeshEchoReplicator = class {
1209
1195
  this._connections.delete(connection);
1210
1196
  },
1211
1197
  shouldAdvertize: async (params) => {
1212
- log4("shouldAdvertize", {
1198
+ log3("shouldAdvertize", {
1213
1199
  peerId: connection.peerId,
1214
1200
  documentId: params.documentId
1215
1201
  }, {
@@ -1230,7 +1216,7 @@ var MeshEchoReplicator = class {
1230
1216
  try {
1231
1217
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1232
1218
  if (!spaceKey) {
1233
- log4("space key not found for share policy check", {
1219
+ log3("space key not found for share policy check", {
1234
1220
  peerId: connection.peerId,
1235
1221
  documentId: params.documentId
1236
1222
  }, {
@@ -1243,7 +1229,7 @@ var MeshEchoReplicator = class {
1243
1229
  }
1244
1230
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1245
1231
  if (!connection.remoteDeviceKey) {
1246
- log4("device key not found for share policy check", {
1232
+ log3("device key not found for share policy check", {
1247
1233
  peerId: connection.peerId,
1248
1234
  documentId: params.documentId
1249
1235
  }, {
@@ -1255,7 +1241,7 @@ var MeshEchoReplicator = class {
1255
1241
  return false;
1256
1242
  }
1257
1243
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1258
- log4("share policy check", {
1244
+ log3("share policy check", {
1259
1245
  localPeer: this._context.peerId,
1260
1246
  remotePeer: connection.peerId,
1261
1247
  documentId: params.documentId,
@@ -1270,7 +1256,7 @@ var MeshEchoReplicator = class {
1270
1256
  });
1271
1257
  return isAuthorized;
1272
1258
  } catch (err) {
1273
- log4.catch(err, void 0, {
1259
+ log3.catch(err, void 0, {
1274
1260
  F: __dxlog_file5,
1275
1261
  L: 111,
1276
1262
  S: this,
@@ -1284,7 +1270,7 @@ var MeshEchoReplicator = class {
1284
1270
  return connection.replicatorExtension;
1285
1271
  }
1286
1272
  authorizeDevice(spaceKey, deviceKey) {
1287
- log4("authorizeDevice", {
1273
+ log3("authorizeDevice", {
1288
1274
  spaceKey,
1289
1275
  deviceKey
1290
1276
  }, {
@@ -1294,6 +1280,11 @@ var MeshEchoReplicator = class {
1294
1280
  C: (f, a) => f(...a)
1295
1281
  });
1296
1282
  defaultMap(this._authorizedDevices, spaceKey, () => new ComplexSet(PublicKey2.hash)).add(deviceKey);
1283
+ for (const connection of this._connections) {
1284
+ if (connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
1285
+ this._context?.onConnectionAuthScopeChanged(connection);
1286
+ }
1287
+ }
1297
1288
  }
1298
1289
  };
1299
1290
  var MeshReplicatorConnection = class extends Resource2 {
@@ -1325,13 +1316,13 @@ var MeshReplicatorConnection = class extends Resource2 {
1325
1316
  onStartReplication: async (info, remotePeerId) => {
1326
1317
  this.remoteDeviceKey = remotePeerId;
1327
1318
  this._remotePeerId = info.id;
1328
- log4("onStartReplication", {
1319
+ log3("onStartReplication", {
1329
1320
  id: info.id,
1330
1321
  thisPeerId: this.peerId,
1331
1322
  remotePeerId: remotePeerId.toHex()
1332
1323
  }, {
1333
1324
  F: __dxlog_file5,
1334
- L: 187,
1325
+ L: 192,
1335
1326
  S: this,
1336
1327
  C: (f, a) => f(...a)
1337
1328
  });
@@ -1355,7 +1346,7 @@ var MeshReplicatorConnection = class extends Resource2 {
1355
1346
  get peerId() {
1356
1347
  invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1357
1348
  F: __dxlog_file5,
1358
- L: 210,
1349
+ L: 215,
1359
1350
  S: this,
1360
1351
  A: [
1361
1352
  "this._remotePeerId != null",
@@ -1374,7 +1365,7 @@ var MeshReplicatorConnection = class extends Resource2 {
1374
1365
  async enable() {
1375
1366
  invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1376
1367
  F: __dxlog_file5,
1377
- L: 223,
1368
+ L: 228,
1378
1369
  S: this,
1379
1370
  A: [
1380
1371
  "this._remotePeerId != null",