@dxos/echo-pipeline 0.6.6-main.e1a6e1f → 0.6.6-staging.41c080b

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 (33) hide show
  1. package/dist/lib/browser/{chunk-LNIQX6PQ.mjs → chunk-P6XSIJKM.mjs} +77 -38
  2. package/dist/lib/browser/{chunk-LNIQX6PQ.mjs.map → chunk-P6XSIJKM.mjs.map} +3 -3
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +8 -8
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-LTR534RP.cjs → chunk-IYTGTZ7D.cjs} +80 -41
  8. package/dist/lib/node/chunk-IYTGTZ7D.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +35 -35
  10. package/dist/lib/node/index.cjs.map +1 -1
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/testing/index.cjs +18 -18
  13. package/dist/lib/node/testing/index.cjs.map +3 -3
  14. package/dist/types/src/automerge/automerge-host.d.ts +1 -0
  15. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  16. package/dist/types/src/automerge/echo-network-adapter.d.ts +2 -1
  17. package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
  18. package/dist/types/src/automerge/echo-replicator.d.ts +5 -0
  19. package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
  20. package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts.map +1 -1
  21. package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
  22. package/dist/types/src/testing/test-network-adapter.d.ts +2 -1
  23. package/dist/types/src/testing/test-network-adapter.d.ts.map +1 -1
  24. package/package.json +33 -33
  25. package/src/automerge/automerge-host.ts +13 -1
  26. package/src/automerge/automerge-repo.test.ts +380 -366
  27. package/src/automerge/echo-network-adapter.test.ts +1 -0
  28. package/src/automerge/echo-network-adapter.ts +3 -0
  29. package/src/automerge/echo-replicator.ts +6 -0
  30. package/src/automerge/mesh-echo-replicator-connection.ts +18 -0
  31. package/src/automerge/mesh-echo-replicator.ts +10 -2
  32. package/src/testing/test-network-adapter.ts +5 -3
  33. package/dist/lib/node/chunk-LTR534RP.cjs.map +0 -7
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_LTR534RP_exports = {};
30
- __export(chunk_LTR534RP_exports, {
29
+ var chunk_IYTGTZ7D_exports = {};
30
+ __export(chunk_IYTGTZ7D_exports, {
31
31
  AuthExtension: () => AuthExtension,
32
32
  AuthStatus: () => AuthStatus,
33
33
  AutomergeHost: () => AutomergeHost,
@@ -63,7 +63,7 @@ __export(chunk_LTR534RP_exports, {
63
63
  startAfter: () => startAfter,
64
64
  valueEncoding: () => valueEncoding
65
65
  });
66
- module.exports = __toCommonJS(chunk_LTR534RP_exports);
66
+ module.exports = __toCommonJS(chunk_IYTGTZ7D_exports);
67
67
  var import_hypercore = require("@dxos/hypercore");
68
68
  var import_protocols = require("@dxos/protocols");
69
69
  var import_invariant = require("@dxos/invariant");
@@ -167,6 +167,7 @@ var import_invariant10 = require("@dxos/invariant");
167
167
  var import_keys9 = require("@dxos/keys");
168
168
  var import_log13 = require("@dxos/log");
169
169
  var import_util8 = require("@dxos/util");
170
+ var A2 = __toESM(require("@dxos/automerge/automerge"));
170
171
  var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
171
172
  var import_context12 = require("@dxos/context");
172
173
  var import_invariant11 = require("@dxos/invariant");
@@ -2018,7 +2019,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2018
2019
  this._lifecycleState = import_context10.LifecycleState.OPEN;
2019
2020
  (0, import_log12.log)("emit ready", void 0, {
2020
2021
  F: __dxlog_file11,
2021
- L: 79,
2022
+ L: 81,
2022
2023
  S: this,
2023
2024
  C: (f, a) => f(...a)
2024
2025
  });
@@ -2044,7 +2045,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2044
2045
  async addReplicator(replicator) {
2045
2046
  (0, import_invariant9.invariant)(this._lifecycleState === import_context10.LifecycleState.OPEN, void 0, {
2046
2047
  F: __dxlog_file11,
2047
- L: 105,
2048
+ L: 107,
2048
2049
  S: this,
2049
2050
  A: [
2050
2051
  "this._lifecycleState === LifecycleState.OPEN",
@@ -2053,7 +2054,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2053
2054
  });
2054
2055
  (0, import_invariant9.invariant)(this.peerId, void 0, {
2055
2056
  F: __dxlog_file11,
2056
- L: 106,
2057
+ L: 108,
2057
2058
  S: this,
2058
2059
  A: [
2059
2060
  "this.peerId",
@@ -2062,7 +2063,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2062
2063
  });
2063
2064
  (0, import_invariant9.invariant)(!this._replicators.has(replicator), void 0, {
2064
2065
  F: __dxlog_file11,
2065
- L: 107,
2066
+ L: 109,
2066
2067
  S: this,
2067
2068
  A: [
2068
2069
  "!this._replicators.has(replicator)",
@@ -2075,6 +2076,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2075
2076
  onConnectionOpen: this._onConnectionOpen.bind(this),
2076
2077
  onConnectionClosed: this._onConnectionClosed.bind(this),
2077
2078
  onConnectionAuthScopeChanged: this._onConnectionAuthScopeChanged.bind(this),
2079
+ isDocumentInRemoteCollection: this._params.isDocumentInRemoteCollection,
2078
2080
  getContainingSpaceForDocument: this._params.getContainingSpaceForDocument,
2079
2081
  getContainingSpaceIdForDocument: async (documentId) => {
2080
2082
  const key = await this._params.getContainingSpaceForDocument(documentId);
@@ -2085,7 +2087,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2085
2087
  async removeReplicator(replicator) {
2086
2088
  (0, import_invariant9.invariant)(this._lifecycleState === import_context10.LifecycleState.OPEN, void 0, {
2087
2089
  F: __dxlog_file11,
2088
- L: 125,
2090
+ L: 128,
2089
2091
  S: this,
2090
2092
  A: [
2091
2093
  "this._lifecycleState === LifecycleState.OPEN",
@@ -2094,7 +2096,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2094
2096
  });
2095
2097
  (0, import_invariant9.invariant)(this._replicators.has(replicator), void 0, {
2096
2098
  F: __dxlog_file11,
2097
- L: 126,
2099
+ L: 129,
2098
2100
  S: this,
2099
2101
  A: [
2100
2102
  "this._replicators.has(replicator)",
@@ -2150,7 +2152,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2150
2152
  if (connectionEntry.isOpen) {
2151
2153
  import_log12.log.catch(err, void 0, {
2152
2154
  F: __dxlog_file11,
2153
- L: 186,
2155
+ L: 189,
2154
2156
  S: this,
2155
2157
  C: (f, a) => f(...a)
2156
2158
  });
@@ -2171,13 +2173,13 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2171
2173
  peerId: connection.peerId
2172
2174
  }, {
2173
2175
  F: __dxlog_file11,
2174
- L: 204,
2176
+ L: 207,
2175
2177
  S: this,
2176
2178
  C: (f, a) => f(...a)
2177
2179
  });
2178
2180
  (0, import_invariant9.invariant)(!this._connections.has(connection.peerId), void 0, {
2179
2181
  F: __dxlog_file11,
2180
- L: 205,
2182
+ L: 208,
2181
2183
  S: this,
2182
2184
  A: [
2183
2185
  "!this._connections.has(connection.peerId as PeerId)",
@@ -2206,7 +2208,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2206
2208
  if (connectionEntry.isOpen) {
2207
2209
  import_log12.log.catch(err, void 0, {
2208
2210
  F: __dxlog_file11,
2209
- L: 224,
2211
+ L: 227,
2210
2212
  S: this,
2211
2213
  C: (f, a) => f(...a)
2212
2214
  });
@@ -2217,7 +2219,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2217
2219
  peerId: connection.peerId
2218
2220
  }, {
2219
2221
  F: __dxlog_file11,
2220
- L: 229,
2222
+ L: 232,
2221
2223
  S: this,
2222
2224
  C: (f, a) => f(...a)
2223
2225
  });
@@ -2243,14 +2245,14 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2243
2245
  peerId: connection.peerId
2244
2246
  }, {
2245
2247
  F: __dxlog_file11,
2246
- L: 250,
2248
+ L: 253,
2247
2249
  S: this,
2248
2250
  C: (f, a) => f(...a)
2249
2251
  });
2250
2252
  const entry = this._connections.get(connection.peerId);
2251
2253
  (0, import_invariant9.invariant)(entry, void 0, {
2252
2254
  F: __dxlog_file11,
2253
- L: 252,
2255
+ L: 255,
2254
2256
  S: this,
2255
2257
  A: [
2256
2258
  "entry",
@@ -2267,14 +2269,14 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2267
2269
  peerId: connection.peerId
2268
2270
  }, {
2269
2271
  F: __dxlog_file11,
2270
- L: 258,
2272
+ L: 261,
2271
2273
  S: this,
2272
2274
  C: (f, a) => f(...a)
2273
2275
  });
2274
2276
  const entry = this._connections.get(connection.peerId);
2275
2277
  (0, import_invariant9.invariant)(entry, void 0, {
2276
2278
  F: __dxlog_file11,
2277
- L: 260,
2279
+ L: 263,
2278
2280
  S: this,
2279
2281
  A: [
2280
2282
  "entry",
@@ -2288,13 +2290,13 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
2288
2290
  this._params.monitor?.recordPeerDisconnected(connection.peerId);
2289
2291
  void entry.reader.cancel().catch((err) => import_log12.log.catch(err, void 0, {
2290
2292
  F: __dxlog_file11,
2291
- L: 266,
2293
+ L: 269,
2292
2294
  S: this,
2293
2295
  C: (f, a) => f(...a)
2294
2296
  }));
2295
2297
  void entry.writer.abort().catch((err) => import_log12.log.catch(err, void 0, {
2296
2298
  F: __dxlog_file11,
2297
- L: 267,
2299
+ L: 270,
2298
2300
  S: this,
2299
2301
  C: (f, a) => f(...a)
2300
2302
  }));
@@ -2476,6 +2478,7 @@ var AutomergeHost = class extends import_context9.Resource {
2476
2478
  });
2477
2479
  this._echoNetworkAdapter = new EchoNetworkAdapter({
2478
2480
  getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this),
2481
+ isDocumentInRemoteCollection: this._isDocumentInRemoteCollection.bind(this),
2479
2482
  onCollectionStateQueried: this._onCollectionStateQueried.bind(this),
2480
2483
  onCollectionStateReceived: this._onCollectionStateReceived.bind(this),
2481
2484
  monitor: dataMonitor
@@ -2583,7 +2586,7 @@ var AutomergeHost = class extends import_context9.Resource {
2583
2586
  await Promise.all(headsToWait.map(async (entry, index) => {
2584
2587
  const handle = await this.loadDoc(import_context9.Context.default(void 0, {
2585
2588
  F: __dxlog_file12,
2586
- L: 226
2589
+ L: 227
2587
2590
  }), entry.documentId);
2588
2591
  await waitForHeads(handle, entry.heads);
2589
2592
  }));
@@ -2596,7 +2599,7 @@ var AutomergeHost = class extends import_context9.Resource {
2596
2599
  documentId
2597
2600
  }, {
2598
2601
  F: __dxlog_file12,
2599
- L: 238,
2602
+ L: 239,
2600
2603
  S: this,
2601
2604
  C: (f, a) => f(...a)
2602
2605
  });
@@ -2612,7 +2615,7 @@ var AutomergeHost = class extends import_context9.Resource {
2612
2615
  documentId
2613
2616
  }, {
2614
2617
  F: __dxlog_file12,
2615
- L: 242,
2618
+ L: 243,
2616
2619
  S: this,
2617
2620
  C: (f, a) => f(...a)
2618
2621
  });
@@ -2621,7 +2624,7 @@ var AutomergeHost = class extends import_context9.Resource {
2621
2624
  const doc = handle.docSync();
2622
2625
  (0, import_invariant8.invariant)(doc, void 0, {
2623
2626
  F: __dxlog_file12,
2624
- L: 247,
2627
+ L: 248,
2625
2628
  S: this,
2626
2629
  A: [
2627
2630
  "doc",
@@ -2635,7 +2638,7 @@ var AutomergeHost = class extends import_context9.Resource {
2635
2638
  }
2636
2639
  import_log11.log.info("done re-indexing heads", void 0, {
2637
2640
  F: __dxlog_file12,
2638
- L: 254,
2641
+ L: 255,
2639
2642
  S: this,
2640
2643
  C: (f, a) => f(...a)
2641
2644
  });
@@ -2707,6 +2710,16 @@ var AutomergeHost = class extends import_context9.Resource {
2707
2710
  _automergePeers() {
2708
2711
  return this._repo.peers;
2709
2712
  }
2713
+ async _isDocumentInRemoteCollection(params) {
2714
+ for (const collectionId of this._collectionSynchronizer.getRegisteredCollectionIds()) {
2715
+ const remoteCollections = this._collectionSynchronizer.getRemoteCollectionStates(collectionId);
2716
+ const remotePeerDocs = remoteCollections.get(params.peerId)?.documents;
2717
+ if (remotePeerDocs && params.documentId in remotePeerDocs) {
2718
+ return true;
2719
+ }
2720
+ }
2721
+ return false;
2722
+ }
2710
2723
  async _getContainingSpaceForDocument(documentId) {
2711
2724
  const doc = this._repo.handles[documentId]?.docSync();
2712
2725
  if (!doc) {
@@ -2821,7 +2834,7 @@ var AutomergeHost = class extends import_context9.Resource {
2821
2834
  count: different.length
2822
2835
  }, {
2823
2836
  F: __dxlog_file12,
2824
- L: 463,
2837
+ L: 475,
2825
2838
  S: this,
2826
2839
  C: (f, a) => f(...a)
2827
2840
  });
@@ -2881,7 +2894,7 @@ var changeIsPresentInDoc = (doc, changeHash) => {
2881
2894
  var decodeCollectionState = (state) => {
2882
2895
  (0, import_invariant8.invariant)(typeof state === "object" && state !== null, "Invalid state", {
2883
2896
  F: __dxlog_file12,
2884
- L: 516,
2897
+ L: 528,
2885
2898
  S: void 0,
2886
2899
  A: [
2887
2900
  "typeof state === 'object' && state !== null",
@@ -2913,7 +2926,7 @@ var MeshReplicatorConnection = class extends import_context12.Resource {
2913
2926
  write: async (message, controller) => {
2914
2927
  (0, import_invariant11.invariant)(this._isEnabled, "Writing to a disabled connection", {
2915
2928
  F: __dxlog_file13,
2916
- L: 48,
2929
+ L: 49,
2917
2930
  S: this,
2918
2931
  A: [
2919
2932
  "this._isEnabled",
@@ -2921,6 +2934,7 @@ var MeshReplicatorConnection = class extends import_context12.Resource {
2921
2934
  ]
2922
2935
  });
2923
2936
  try {
2937
+ logSendSync(message);
2924
2938
  await this.replicatorExtension.sendSyncMessage({
2925
2939
  payload: import_automerge_repo3.cbor.encode(message)
2926
2940
  });
@@ -2945,7 +2959,7 @@ var MeshReplicatorConnection = class extends import_context12.Resource {
2945
2959
  remotePeerId: remotePeerId.toHex()
2946
2960
  }, {
2947
2961
  F: __dxlog_file13,
2948
- L: 82,
2962
+ L: 84,
2949
2963
  S: this,
2950
2964
  C: (f, a) => f(...a)
2951
2965
  });
@@ -2972,7 +2986,7 @@ var MeshReplicatorConnection = class extends import_context12.Resource {
2972
2986
  get peerId() {
2973
2987
  (0, import_invariant11.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
2974
2988
  F: __dxlog_file13,
2975
- L: 108,
2989
+ L: 110,
2976
2990
  S: this,
2977
2991
  A: [
2978
2992
  "this._remotePeerId != null",
@@ -2994,7 +3008,7 @@ var MeshReplicatorConnection = class extends import_context12.Resource {
2994
3008
  enable() {
2995
3009
  (0, import_invariant11.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
2996
3010
  F: __dxlog_file13,
2997
- L: 125,
3011
+ L: 127,
2998
3012
  S: this,
2999
3013
  A: [
3000
3014
  "this._remotePeerId != null",
@@ -3010,6 +3024,26 @@ var MeshReplicatorConnection = class extends import_context12.Resource {
3010
3024
  this._isEnabled = false;
3011
3025
  }
3012
3026
  };
3027
+ var logSendSync = (message) => {
3028
+ (0, import_log14.log)("sendSyncMessage", () => {
3029
+ const decodedSyncMessage = message.type === "sync" && message.data ? A2.decodeSyncMessage(message.data) : void 0;
3030
+ return {
3031
+ sync: decodedSyncMessage && {
3032
+ headsLength: decodedSyncMessage.heads.length,
3033
+ requesting: decodedSyncMessage.need.length > 0,
3034
+ sendingChanges: decodedSyncMessage.changes.length > 0
3035
+ },
3036
+ type: message.type,
3037
+ from: message.senderId,
3038
+ to: message.targetId
3039
+ };
3040
+ }, {
3041
+ F: __dxlog_file13,
3042
+ L: 140,
3043
+ S: void 0,
3044
+ C: (f, a) => f(...a)
3045
+ });
3046
+ };
3013
3047
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/space-collection.ts";
3014
3048
  var deriveCollectionIdFromSpaceId = (spaceId) => `space:${spaceId}`;
3015
3049
  var getSpaceIdFromCollectionId = (collectionId) => {
@@ -3122,16 +3156,21 @@ var MeshEchoReplicator = class {
3122
3156
  try {
3123
3157
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
3124
3158
  if (!spaceKey) {
3125
- (0, import_log13.log)("space key not found for share policy check", {
3159
+ const remoteDocumentExists = await this._context.isDocumentInRemoteCollection({
3160
+ documentId: params.documentId,
3161
+ peerId: connection.peerId
3162
+ });
3163
+ (0, import_log13.log)("document not found locally for share policy check, accepting the remote document", {
3126
3164
  peerId: connection.peerId,
3127
- documentId: params.documentId
3165
+ documentId: params.documentId,
3166
+ remoteDocumentExists
3128
3167
  }, {
3129
3168
  F: __dxlog_file15,
3130
- L: 86,
3169
+ L: 90,
3131
3170
  S: this,
3132
3171
  C: (f, a) => f(...a)
3133
3172
  });
3134
- return false;
3173
+ return remoteDocumentExists;
3135
3174
  }
3136
3175
  const spaceId = await createIdFromSpaceKey(spaceKey);
3137
3176
  const authorizedDevices = this._authorizedDevices.get(spaceId);
@@ -3141,7 +3180,7 @@ var MeshEchoReplicator = class {
3141
3180
  documentId: params.documentId
3142
3181
  }, {
3143
3182
  F: __dxlog_file15,
3144
- L: 98,
3183
+ L: 106,
3145
3184
  S: this,
3146
3185
  C: (f, a) => f(...a)
3147
3186
  });
@@ -3157,7 +3196,7 @@ var MeshEchoReplicator = class {
3157
3196
  isAuthorized
3158
3197
  }, {
3159
3198
  F: __dxlog_file15,
3160
- L: 106,
3199
+ L: 114,
3161
3200
  S: this,
3162
3201
  C: (f, a) => f(...a)
3163
3202
  });
@@ -3165,7 +3204,7 @@ var MeshEchoReplicator = class {
3165
3204
  } catch (err) {
3166
3205
  import_log13.log.catch(err, void 0, {
3167
3206
  F: __dxlog_file15,
3168
- L: 116,
3207
+ L: 124,
3169
3208
  S: this,
3170
3209
  C: (f, a) => f(...a)
3171
3210
  });
@@ -3181,7 +3220,7 @@ var MeshEchoReplicator = class {
3181
3220
  collectionId
3182
3221
  }, {
3183
3222
  F: __dxlog_file15,
3184
- L: 126,
3223
+ L: 134,
3185
3224
  S: this,
3186
3225
  C: (f, a) => f(...a)
3187
3226
  });
@@ -3200,7 +3239,7 @@ var MeshEchoReplicator = class {
3200
3239
  deviceKey
3201
3240
  }, {
3202
3241
  F: __dxlog_file15,
3203
- L: 143,
3242
+ L: 151,
3204
3243
  S: this,
3205
3244
  C: (f, a) => f(...a)
3206
3245
  });
@@ -4213,4 +4252,4 @@ var isLegacyInvitationFormat = (invitation) => {
4213
4252
  startAfter,
4214
4253
  valueEncoding
4215
4254
  });
4216
- //# sourceMappingURL=chunk-LTR534RP.cjs.map
4255
+ //# sourceMappingURL=chunk-IYTGTZ7D.cjs.map