@dxos/echo-pipeline 0.5.1-main.4e99b85 → 0.5.1-main.4fc508c

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 (57) hide show
  1. package/dist/lib/browser/{chunk-KMWJLYEQ.mjs → chunk-RESTOZPT.mjs} +17 -17
  2. package/dist/lib/browser/{chunk-KMWJLYEQ.mjs.map → chunk-RESTOZPT.mjs.map} +2 -2
  3. package/dist/lib/browser/index.mjs +440 -177
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +2 -8
  7. package/dist/lib/browser/testing/index.mjs.map +4 -4
  8. package/dist/lib/node/{chunk-YZA42CKA.cjs → chunk-D25ZFWEF.cjs} +20 -20
  9. package/dist/lib/node/{chunk-YZA42CKA.cjs.map → chunk-D25ZFWEF.cjs.map} +2 -2
  10. package/dist/lib/node/index.cjs +450 -194
  11. package/dist/lib/node/index.cjs.map +4 -4
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +13 -18
  14. package/dist/lib/node/testing/index.cjs.map +4 -4
  15. package/dist/types/src/automerge/automerge-doc-loader.d.ts +3 -3
  16. package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -1
  17. package/dist/types/src/automerge/automerge-host.d.ts +14 -5
  18. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  19. package/dist/types/src/automerge/echo-network-adapter.d.ts +26 -0
  20. package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -0
  21. package/dist/types/src/automerge/echo-replicator.d.ts +43 -0
  22. package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -0
  23. package/dist/types/src/automerge/index.d.ts +1 -2
  24. package/dist/types/src/automerge/index.d.ts.map +1 -1
  25. package/dist/types/src/automerge/leveldb-storage-adapter.d.ts +3 -2
  26. package/dist/types/src/automerge/leveldb-storage-adapter.d.ts.map +1 -1
  27. package/dist/types/src/automerge/migrations.d.ts +1 -1
  28. package/dist/types/src/automerge/migrations.d.ts.map +1 -1
  29. package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
  30. package/dist/types/src/testing/index.d.ts +0 -1
  31. package/dist/types/src/testing/index.d.ts.map +1 -1
  32. package/package.json +33 -30
  33. package/src/automerge/automerge-doc-loader.test.ts +1 -1
  34. package/src/automerge/automerge-doc-loader.ts +26 -16
  35. package/src/automerge/automerge-host.test.ts +11 -3
  36. package/src/automerge/automerge-host.ts +62 -10
  37. package/src/automerge/automerge-repo.test.ts +1 -1
  38. package/src/automerge/echo-network-adapter.ts +155 -0
  39. package/src/automerge/echo-replicator.ts +56 -0
  40. package/src/automerge/index.ts +1 -2
  41. package/src/automerge/leveldb-storage-adapter.ts +2 -2
  42. package/src/automerge/migrations.ts +1 -1
  43. package/src/automerge/storage-adapter.test.ts +1 -1
  44. package/src/pipeline/pipeline.ts +1 -0
  45. package/src/testing/index.ts +0 -1
  46. package/dist/types/src/automerge/level.test.d.ts +0 -2
  47. package/dist/types/src/automerge/level.test.d.ts.map +0 -1
  48. package/dist/types/src/automerge/reference.d.ts +0 -15
  49. package/dist/types/src/automerge/reference.d.ts.map +0 -1
  50. package/dist/types/src/automerge/types.d.ts +0 -73
  51. package/dist/types/src/automerge/types.d.ts.map +0 -1
  52. package/dist/types/src/testing/level.d.ts +0 -3
  53. package/dist/types/src/testing/level.d.ts.map +0 -1
  54. package/src/automerge/level.test.ts +0 -82
  55. package/src/automerge/reference.ts +0 -31
  56. package/src/automerge/types.ts +0 -86
  57. package/src/testing/level.ts +0 -12
@@ -22,21 +22,243 @@ import {
22
22
  mapTimeframeToFeedIndexes,
23
23
  startAfter,
24
24
  valueEncoding
25
- } from "./chunk-KMWJLYEQ.mjs";
25
+ } from "./chunk-RESTOZPT.mjs";
26
26
 
27
27
  // packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
28
28
  import { Event } from "@dxos/async";
29
- import { next as automerge, getBackend } from "@dxos/automerge/automerge";
29
+ import { next as automerge, getBackend, getHeads } from "@dxos/automerge/automerge";
30
30
  import { Repo } from "@dxos/automerge/automerge-repo";
31
31
  import { Context } from "@dxos/context";
32
- import { invariant as invariant3 } from "@dxos/invariant";
32
+ import { invariant as invariant4 } from "@dxos/invariant";
33
33
  import { PublicKey } from "@dxos/keys";
34
- import { log as log3 } from "@dxos/log";
34
+ import { log as log4 } from "@dxos/log";
35
+ import { idCodec } from "@dxos/protocols";
35
36
  import { trace } from "@dxos/tracing";
36
37
  import { ComplexMap, ComplexSet, defaultMap, mapValues } from "@dxos/util";
37
38
 
39
+ // packages/core/echo/echo-pipeline/src/automerge/echo-network-adapter.ts
40
+ import { Trigger, synchronized } from "@dxos/async";
41
+ import { NetworkAdapter } from "@dxos/automerge/automerge-repo";
42
+ import { LifecycleState } from "@dxos/context";
43
+ import { invariant } from "@dxos/invariant";
44
+ import { log } from "@dxos/log";
45
+ function _ts_decorate(decorators, target, key, desc) {
46
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
47
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
48
+ r = Reflect.decorate(decorators, target, key, desc);
49
+ else
50
+ for (var i = decorators.length - 1; i >= 0; i--)
51
+ if (d = decorators[i])
52
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
53
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
54
+ }
55
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/echo-network-adapter.ts";
56
+ var EchoNetworkAdapter = class extends NetworkAdapter {
57
+ constructor() {
58
+ super(...arguments);
59
+ this._replicators = /* @__PURE__ */ new Set();
60
+ /**
61
+ * Remote peer id -> connection.
62
+ */
63
+ this._connections = /* @__PURE__ */ new Map();
64
+ this._lifecycleState = LifecycleState.CLOSED;
65
+ this._connected = new Trigger();
66
+ }
67
+ connect(peerId, peerMetadata) {
68
+ this.peerId = peerId;
69
+ this.peerMetadata = peerMetadata;
70
+ this._connected.wake();
71
+ }
72
+ send(message) {
73
+ const connectionEntry = this._connections.get(message.targetId);
74
+ if (!connectionEntry) {
75
+ throw new Error("Connection not found.");
76
+ }
77
+ connectionEntry.writer.write(message).catch((err) => {
78
+ if (connectionEntry.isOpen) {
79
+ log.catch(err, void 0, {
80
+ F: __dxlog_file,
81
+ L: 40,
82
+ S: this,
83
+ C: (f, a) => f(...a)
84
+ });
85
+ }
86
+ });
87
+ }
88
+ disconnect() {
89
+ }
90
+ async open() {
91
+ invariant(this._lifecycleState === LifecycleState.CLOSED, void 0, {
92
+ F: __dxlog_file,
93
+ L: 51,
94
+ S: this,
95
+ A: [
96
+ "this._lifecycleState === LifecycleState.CLOSED",
97
+ ""
98
+ ]
99
+ });
100
+ this._lifecycleState = LifecycleState.OPEN;
101
+ this.emit("ready", {
102
+ network: this
103
+ });
104
+ }
105
+ async close() {
106
+ invariant(this._lifecycleState === LifecycleState.OPEN, void 0, {
107
+ F: __dxlog_file,
108
+ L: 61,
109
+ S: this,
110
+ A: [
111
+ "this._lifecycleState === LifecycleState.OPEN",
112
+ ""
113
+ ]
114
+ });
115
+ for (const replicator of this._replicators) {
116
+ await replicator.disconnect();
117
+ }
118
+ this._replicators.clear();
119
+ this._lifecycleState = LifecycleState.CLOSED;
120
+ }
121
+ async whenConnected() {
122
+ await this._connected.wait({
123
+ timeout: 1e4
124
+ });
125
+ }
126
+ async addReplicator(replicator) {
127
+ invariant(this.peerId, void 0, {
128
+ F: __dxlog_file,
129
+ L: 77,
130
+ S: this,
131
+ A: [
132
+ "this.peerId",
133
+ ""
134
+ ]
135
+ });
136
+ invariant(!this._replicators.has(replicator), void 0, {
137
+ F: __dxlog_file,
138
+ L: 78,
139
+ S: this,
140
+ A: [
141
+ "!this._replicators.has(replicator)",
142
+ ""
143
+ ]
144
+ });
145
+ await replicator.connect({
146
+ peerId: this.peerId,
147
+ onConnectionOpen: this._onConnectionOpen.bind(this),
148
+ onConnectionClosed: this._onConnectionClosed.bind(this)
149
+ });
150
+ }
151
+ async removeReplicator(replicator) {
152
+ invariant(this._replicators.has(replicator), void 0, {
153
+ F: __dxlog_file,
154
+ L: 89,
155
+ S: this,
156
+ A: [
157
+ "this._replicators.has(replicator)",
158
+ ""
159
+ ]
160
+ });
161
+ await replicator.disconnect();
162
+ }
163
+ async shouldAdvertize(peerId, params) {
164
+ const connection = this._connections.get(peerId);
165
+ if (!connection) {
166
+ return false;
167
+ }
168
+ return connection.connection.shouldAdvertize(params);
169
+ }
170
+ _onConnectionOpen(connection) {
171
+ invariant(!this._connections.has(connection.peerId), void 0, {
172
+ F: __dxlog_file,
173
+ L: 103,
174
+ S: this,
175
+ A: [
176
+ "!this._connections.has(connection.peerId as PeerId)",
177
+ ""
178
+ ]
179
+ });
180
+ const reader = connection.readable.getReader();
181
+ const writer = connection.writable.getWriter();
182
+ const connectionEntry = {
183
+ connection,
184
+ reader,
185
+ writer,
186
+ isOpen: true
187
+ };
188
+ this._connections.set(connection.peerId, connectionEntry);
189
+ queueMicrotask(async () => {
190
+ try {
191
+ while (true) {
192
+ const { done, value } = await reader.read();
193
+ if (done) {
194
+ break;
195
+ }
196
+ this.emit("message", value);
197
+ }
198
+ } catch (err) {
199
+ if (connectionEntry.isOpen) {
200
+ log.catch(err, void 0, {
201
+ F: __dxlog_file,
202
+ L: 122,
203
+ S: this,
204
+ C: (f, a) => f(...a)
205
+ });
206
+ }
207
+ }
208
+ });
209
+ this.emit("peer-candidate", {
210
+ peerId: connection.peerId,
211
+ peerMetadata: {
212
+ // TODO(dmaretskyi): Refactor this.
213
+ dxos_peerSource: "EchoNetworkAdapter"
214
+ }
215
+ });
216
+ }
217
+ _onConnectionClosed(connection) {
218
+ const entry = this._connections.get(connection.peerId);
219
+ invariant(entry, void 0, {
220
+ F: __dxlog_file,
221
+ L: 138,
222
+ S: this,
223
+ A: [
224
+ "entry",
225
+ ""
226
+ ]
227
+ });
228
+ entry.isOpen = false;
229
+ this.emit("peer-disconnected", {
230
+ peerId: connection.peerId
231
+ });
232
+ void entry.reader.cancel().catch((err) => log.catch(err, void 0, {
233
+ F: __dxlog_file,
234
+ L: 143,
235
+ S: this,
236
+ C: (f, a) => f(...a)
237
+ }));
238
+ void entry.writer.abort().catch((err) => log.catch(err, void 0, {
239
+ F: __dxlog_file,
240
+ L: 144,
241
+ S: this,
242
+ C: (f, a) => f(...a)
243
+ }));
244
+ this._connections.delete(connection.peerId);
245
+ }
246
+ };
247
+ _ts_decorate([
248
+ synchronized
249
+ ], EchoNetworkAdapter.prototype, "open", null);
250
+ _ts_decorate([
251
+ synchronized
252
+ ], EchoNetworkAdapter.prototype, "close", null);
253
+ _ts_decorate([
254
+ synchronized
255
+ ], EchoNetworkAdapter.prototype, "addReplicator", null);
256
+ _ts_decorate([
257
+ synchronized
258
+ ], EchoNetworkAdapter.prototype, "removeReplicator", null);
259
+
38
260
  // packages/core/echo/echo-pipeline/src/automerge/leveldb-storage-adapter.ts
39
- import { LifecycleState, Resource } from "@dxos/context";
261
+ import { LifecycleState as LifecycleState2, Resource } from "@dxos/context";
40
262
  var LevelDBStorageAdapter = class extends Resource {
41
263
  constructor(_params) {
42
264
  super();
@@ -44,7 +266,7 @@ var LevelDBStorageAdapter = class extends Resource {
44
266
  }
45
267
  async load(keyArray) {
46
268
  try {
47
- if (this._lifecycleState !== LifecycleState.OPEN) {
269
+ if (this._lifecycleState !== LifecycleState2.OPEN) {
48
270
  return void 0;
49
271
  }
50
272
  return await this._params.db.get(keyArray, {
@@ -58,7 +280,7 @@ var LevelDBStorageAdapter = class extends Resource {
58
280
  }
59
281
  }
60
282
  async save(keyArray, binary) {
61
- if (this._lifecycleState !== LifecycleState.OPEN) {
283
+ if (this._lifecycleState !== LifecycleState2.OPEN) {
62
284
  return void 0;
63
285
  }
64
286
  const batch = this._params.db.batch();
@@ -73,7 +295,7 @@ var LevelDBStorageAdapter = class extends Resource {
73
295
  await this._params.callbacks?.afterSave?.(keyArray);
74
296
  }
75
297
  async remove(keyArray) {
76
- if (this._lifecycleState !== LifecycleState.OPEN) {
298
+ if (this._lifecycleState !== LifecycleState2.OPEN) {
77
299
  return void 0;
78
300
  }
79
301
  await this._params.db.del(keyArray, {
@@ -81,7 +303,7 @@ var LevelDBStorageAdapter = class extends Resource {
81
303
  });
82
304
  }
83
305
  async loadRange(keyPrefix) {
84
- if (this._lifecycleState !== LifecycleState.OPEN) {
306
+ if (this._lifecycleState !== LifecycleState2.OPEN) {
85
307
  return [];
86
308
  }
87
309
  const result = [];
@@ -101,7 +323,7 @@ var LevelDBStorageAdapter = class extends Resource {
101
323
  return result;
102
324
  }
103
325
  async removeRange(keyPrefix) {
104
- if (this._lifecycleState !== LifecycleState.OPEN) {
326
+ if (this._lifecycleState !== LifecycleState2.OPEN) {
105
327
  return void 0;
106
328
  }
107
329
  const batch = this._params.db.batch();
@@ -122,7 +344,8 @@ var LevelDBStorageAdapter = class extends Resource {
122
344
  };
123
345
  var keyEncoder = {
124
346
  encode: (key) => Buffer.from(key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-")),
125
- decode: (key) => Buffer.from(key).toString().split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"))
347
+ decode: (key) => Buffer.from(key).toString().split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%")),
348
+ format: "buffer"
126
349
  };
127
350
  var encodingOptions = {
128
351
  keyEncoding: keyEncoder,
@@ -131,16 +354,16 @@ var encodingOptions = {
131
354
  var isLevelDbNotFoundError = (err) => err.code === "LEVEL_NOT_FOUND";
132
355
 
133
356
  // packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts
134
- import { Trigger } from "@dxos/async";
135
- import { NetworkAdapter, cbor } from "@dxos/automerge/automerge-repo";
357
+ import { Trigger as Trigger2 } from "@dxos/async";
358
+ import { NetworkAdapter as NetworkAdapter2, cbor } from "@dxos/automerge/automerge-repo";
136
359
  import { Stream } from "@dxos/codec-protobuf";
137
- import { invariant } from "@dxos/invariant";
138
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts";
139
- var LocalHostNetworkAdapter = class extends NetworkAdapter {
360
+ import { invariant as invariant2 } from "@dxos/invariant";
361
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts";
362
+ var LocalHostNetworkAdapter = class extends NetworkAdapter2 {
140
363
  constructor() {
141
364
  super(...arguments);
142
365
  this._peers = /* @__PURE__ */ new Map();
143
- this._connected = new Trigger();
366
+ this._connected = new Trigger2();
144
367
  this._isConnected = false;
145
368
  }
146
369
  /**
@@ -163,8 +386,8 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
163
386
  }
164
387
  send(message) {
165
388
  const peer = this._peers.get(message.targetId);
166
- invariant(peer, "Peer not found.", {
167
- F: __dxlog_file,
389
+ invariant2(peer, "Peer not found.", {
390
+ F: __dxlog_file2,
168
391
  L: 51,
169
392
  S: this,
170
393
  A: [
@@ -188,8 +411,8 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
188
411
  syncRepo({ id, syncMessage }) {
189
412
  const peerId = this._getPeerId(id);
190
413
  return new Stream(({ next, close }) => {
191
- invariant(!this._peers.has(peerId), "Peer already connected.", {
192
- F: __dxlog_file,
414
+ invariant2(!this._peers.has(peerId), "Peer already connected.", {
415
+ F: __dxlog_file2,
193
416
  L: 73,
194
417
  S: this,
195
418
  A: [
@@ -212,8 +435,8 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
212
435
  });
213
436
  }
214
437
  });
215
- invariant(this._isConnected, void 0, {
216
- F: __dxlog_file,
438
+ invariant2(this._isConnected, void 0, {
439
+ F: __dxlog_file2,
217
440
  L: 90,
218
441
  S: this,
219
442
  A: [
@@ -228,8 +451,8 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
228
451
  });
229
452
  }
230
453
  async sendSyncMessage({ id, syncMessage }) {
231
- invariant(this._isConnected, void 0, {
232
- F: __dxlog_file,
454
+ invariant2(this._isConnected, void 0, {
455
+ F: __dxlog_file2,
233
456
  L: 99,
234
457
  S: this,
235
458
  A: [
@@ -241,8 +464,8 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
241
464
  this.emit("message", message);
242
465
  }
243
466
  async getHostInfo() {
244
- invariant(this._isConnected, void 0, {
245
- F: __dxlog_file,
467
+ invariant2(this._isConnected, void 0, {
468
+ F: __dxlog_file2,
246
469
  L: 105,
247
470
  S: this,
248
471
  A: [
@@ -250,8 +473,8 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
250
473
  ""
251
474
  ]
252
475
  });
253
- invariant(this.peerId, "Peer id not set.", {
254
- F: __dxlog_file,
476
+ invariant2(this.peerId, "Peer id not set.", {
477
+ F: __dxlog_file2,
255
478
  L: 106,
256
479
  S: this,
257
480
  A: [
@@ -269,17 +492,17 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
269
492
  };
270
493
 
271
494
  // packages/core/echo/echo-pipeline/src/automerge/mesh-network-adapter.ts
272
- import { Trigger as Trigger2 } from "@dxos/async";
273
- import { NetworkAdapter as NetworkAdapter2, cbor as cbor2 } from "@dxos/automerge/automerge-repo";
274
- import { invariant as invariant2 } from "@dxos/invariant";
275
- import { log } from "@dxos/log";
495
+ import { Trigger as Trigger3 } from "@dxos/async";
496
+ import { NetworkAdapter as NetworkAdapter3, cbor as cbor2 } from "@dxos/automerge/automerge-repo";
497
+ import { invariant as invariant3 } from "@dxos/invariant";
498
+ import { log as log2 } from "@dxos/log";
276
499
  import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
277
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-network-adapter.ts";
278
- var MeshNetworkAdapter = class extends NetworkAdapter2 {
500
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-network-adapter.ts";
501
+ var MeshNetworkAdapter = class extends NetworkAdapter3 {
279
502
  constructor() {
280
503
  super(...arguments);
281
504
  this._extensions = /* @__PURE__ */ new Map();
282
- this._connected = new Trigger2();
505
+ this._connected = new Trigger3();
283
506
  }
284
507
  /**
285
508
  * Emits `ready` event. That signals to `Repo` that it can start using the adapter.
@@ -296,8 +519,8 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
296
519
  send(message) {
297
520
  const receiverId = message.targetId;
298
521
  const extension = this._extensions.get(receiverId);
299
- invariant2(extension, "Extension not found.", {
300
- F: __dxlog_file2,
522
+ invariant3(extension, "Extension not found.", {
523
+ F: __dxlog_file3,
301
524
  L: 38,
302
525
  S: this,
303
526
  A: [
@@ -307,8 +530,8 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
307
530
  });
308
531
  extension.sendSyncMessage({
309
532
  payload: cbor2.encode(message)
310
- }).catch((err) => log.catch(err, void 0, {
311
- F: __dxlog_file2,
533
+ }).catch((err) => log2.catch(err, void 0, {
534
+ F: __dxlog_file3,
312
535
  L: 39,
313
536
  S: this,
314
537
  C: (f, a) => f(...a)
@@ -317,8 +540,8 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
317
540
  disconnect() {
318
541
  }
319
542
  createExtension() {
320
- invariant2(this.peerId, "Peer id not set.", {
321
- F: __dxlog_file2,
543
+ invariant3(this.peerId, "Peer id not set.", {
544
+ F: __dxlog_file3,
322
545
  L: 47,
323
546
  S: this,
324
547
  A: [
@@ -332,12 +555,12 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
332
555
  }, {
333
556
  onStartReplication: async (info, remotePeerId) => {
334
557
  await this._connected.wait();
335
- log("onStartReplication", {
558
+ log2("onStartReplication", {
336
559
  id: info.id,
337
560
  thisPeerId: this.peerId,
338
561
  remotePeerId: remotePeerId.toHex()
339
562
  }, {
340
- F: __dxlog_file2,
563
+ F: __dxlog_file3,
341
564
  L: 70,
342
565
  S: this,
343
566
  C: (f, a) => f(...a)
@@ -345,12 +568,12 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
345
568
  if (!this._extensions.has(info.id)) {
346
569
  peerInfo = info;
347
570
  this._extensions.set(info.id, extension);
348
- log("peer-candidate", {
571
+ log2("peer-candidate", {
349
572
  id: info.id,
350
573
  thisPeerId: this.peerId,
351
574
  remotePeerId: remotePeerId.toHex()
352
575
  }, {
353
- F: __dxlog_file2,
576
+ F: __dxlog_file3,
354
577
  L: 76,
355
578
  S: this,
356
579
  C: (f, a) => f(...a)
@@ -387,7 +610,7 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
387
610
 
388
611
  // packages/core/echo/echo-pipeline/src/automerge/migrations.ts
389
612
  import { IndexedDBStorageAdapter } from "@dxos/automerge/automerge-repo-storage-indexeddb";
390
- import { log as log2 } from "@dxos/log";
613
+ import { log as log3 } from "@dxos/log";
391
614
  import { StorageType } from "@dxos/random-access-storage";
392
615
 
393
616
  // packages/core/echo/echo-pipeline/src/automerge/automerge-storage-adapter.ts
@@ -467,7 +690,7 @@ var AutomergeStorageAdapter = class {
467
690
  };
468
691
 
469
692
  // packages/core/echo/echo-pipeline/src/automerge/migrations.ts
470
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
693
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
471
694
  var levelMigration = async ({ db, directory }) => {
472
695
  const isNewLevel = !await db.iterator({
473
696
  ...encodingOptions
@@ -481,10 +704,10 @@ var levelMigration = async ({ db, directory }) => {
481
704
  return;
482
705
  }
483
706
  const batch = db.batch();
484
- log2.info("found chunks on old storage adapter", {
707
+ log3.info("found chunks on old storage adapter", {
485
708
  chunks: chunks.length
486
709
  }, {
487
- F: __dxlog_file3,
710
+ F: __dxlog_file4,
488
711
  L: 36,
489
712
  S: void 0,
490
713
  C: (f, a) => f(...a)
@@ -498,7 +721,7 @@ var levelMigration = async ({ db, directory }) => {
498
721
  };
499
722
 
500
723
  // packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
501
- function _ts_decorate(decorators, target, key, desc) {
724
+ function _ts_decorate2(decorators, target, key, desc) {
502
725
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
503
726
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
504
727
  r = Reflect.decorate(decorators, target, key, desc);
@@ -508,10 +731,11 @@ function _ts_decorate(decorators, target, key, desc) {
508
731
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
509
732
  return c > 3 && r && Object.defineProperty(target, key, r), r;
510
733
  }
511
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
734
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
512
735
  var AutomergeHost = class {
513
- constructor({ directory, db, storageCallbacks }) {
736
+ constructor({ directory, db, indexMetadataStore }) {
514
737
  this._ctx = new Context();
738
+ this._echoNetworkAdapter = new EchoNetworkAdapter();
515
739
  /**
516
740
  * spaceKey -> deviceKey[]
517
741
  */
@@ -519,7 +743,7 @@ var AutomergeHost = class {
519
743
  this._requestedDocs = /* @__PURE__ */ new Set();
520
744
  this._directory = directory;
521
745
  this._db = db;
522
- this._storageCallbacks = storageCallbacks;
746
+ this._indexMetadataStore = indexMetadataStore;
523
747
  }
524
748
  async open() {
525
749
  this._directory && await levelMigration({
@@ -528,7 +752,10 @@ var AutomergeHost = class {
528
752
  });
529
753
  this._storage = new LevelDBStorageAdapter({
530
754
  db: this._db,
531
- callbacks: this._storageCallbacks
755
+ callbacks: {
756
+ beforeSave: async (params) => this._beforeSave(params),
757
+ afterSave: async () => this._afterSave()
758
+ }
532
759
  });
533
760
  await this._storage.open?.();
534
761
  this._peerId = `host-${PublicKey.random().toHex()}`;
@@ -538,7 +765,8 @@ var AutomergeHost = class {
538
765
  peerId: this._peerId,
539
766
  network: [
540
767
  this._clientNetwork,
541
- this._meshNetwork
768
+ this._meshNetwork,
769
+ this._echoNetworkAdapter
542
770
  ],
543
771
  storage: this._storage,
544
772
  // TODO(dmaretskyi): Share based on HALO permissions and space affinity.
@@ -550,16 +778,22 @@ var AutomergeHost = class {
550
778
  if (!documentId) {
551
779
  return false;
552
780
  }
781
+ const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
782
+ if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
783
+ return this._echoNetworkAdapter.shouldAdvertize(peerId, {
784
+ documentId
785
+ });
786
+ }
553
787
  const doc = this._repo.handles[documentId]?.docSync();
554
788
  if (!doc) {
555
789
  const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
556
- log3("doc share policy check", {
790
+ log4("doc share policy check", {
557
791
  peerId,
558
792
  documentId,
559
793
  isRequested
560
794
  }, {
561
- F: __dxlog_file4,
562
- L: 108,
795
+ F: __dxlog_file5,
796
+ L: 124,
563
797
  S: this,
564
798
  C: (f, a) => f(...a)
565
799
  });
@@ -568,26 +802,26 @@ var AutomergeHost = class {
568
802
  try {
569
803
  const spaceKey = getSpaceKeyFromDoc(doc);
570
804
  if (!spaceKey) {
571
- log3("space key not found for share policy check", {
805
+ log4("space key not found for share policy check", {
572
806
  peerId,
573
807
  documentId
574
808
  }, {
575
- F: __dxlog_file4,
576
- L: 115,
809
+ F: __dxlog_file5,
810
+ L: 131,
577
811
  S: this,
578
812
  C: (f, a) => f(...a)
579
813
  });
580
814
  return false;
581
815
  }
582
816
  const authorizedDevices = this._authorizedDevices.get(PublicKey.from(spaceKey));
583
- const deviceKeyHex = this.repo.peerMetadataByPeerId[peerId]?.dxos_deviceKey;
817
+ const deviceKeyHex = peerMetadata?.dxos_deviceKey;
584
818
  if (!deviceKeyHex) {
585
- log3("device key not found for share policy check", {
819
+ log4("device key not found for share policy check", {
586
820
  peerId,
587
821
  documentId
588
822
  }, {
589
- F: __dxlog_file4,
590
- L: 124,
823
+ F: __dxlog_file5,
824
+ L: 140,
591
825
  S: this,
592
826
  C: (f, a) => f(...a)
593
827
  });
@@ -595,7 +829,7 @@ var AutomergeHost = class {
595
829
  }
596
830
  const deviceKey = PublicKey.from(deviceKeyHex);
597
831
  const isAuthorized = authorizedDevices?.has(deviceKey) ?? false;
598
- log3("share policy check", {
832
+ log4("share policy check", {
599
833
  localPeer: this._peerId,
600
834
  remotePeer: peerId,
601
835
  documentId,
@@ -603,16 +837,16 @@ var AutomergeHost = class {
603
837
  spaceKey,
604
838
  isAuthorized
605
839
  }, {
606
- F: __dxlog_file4,
607
- L: 130,
840
+ F: __dxlog_file5,
841
+ L: 146,
608
842
  S: this,
609
843
  C: (f, a) => f(...a)
610
844
  });
611
845
  return isAuthorized;
612
846
  } catch (err) {
613
- log3.catch(err, void 0, {
614
- F: __dxlog_file4,
615
- L: 140,
847
+ log4.catch(err, void 0, {
848
+ F: __dxlog_file5,
849
+ L: 156,
616
850
  S: this,
617
851
  C: (f, a) => f(...a)
618
852
  });
@@ -622,16 +856,52 @@ var AutomergeHost = class {
622
856
  });
623
857
  this._clientNetwork.ready();
624
858
  this._meshNetwork.ready();
859
+ await this._echoNetworkAdapter.open();
625
860
  await this._clientNetwork.whenConnected();
861
+ await this._echoNetworkAdapter.whenConnected();
626
862
  }
627
863
  async close() {
628
864
  await this._storage.close?.();
629
865
  await this._clientNetwork.close();
866
+ await this._echoNetworkAdapter.close();
630
867
  await this._ctx.dispose();
631
868
  }
632
869
  get repo() {
633
870
  return this._repo;
634
871
  }
872
+ async addReplicator(replicator) {
873
+ await this._echoNetworkAdapter.addReplicator(replicator);
874
+ }
875
+ async removeReplicator(replicator) {
876
+ await this._echoNetworkAdapter.removeReplicator(replicator);
877
+ }
878
+ async _beforeSave({ path, batch }) {
879
+ const handle = this._repo.handles[path[0]];
880
+ if (!handle) {
881
+ return;
882
+ }
883
+ const doc = handle.docSync();
884
+ if (!doc) {
885
+ return;
886
+ }
887
+ const lastAvailableHash = getHeads(doc);
888
+ const objectIds = Object.keys(doc.objects ?? {});
889
+ const encodedIds = objectIds.map((objectId) => idCodec.encode({
890
+ documentId: handle.documentId,
891
+ objectId
892
+ }));
893
+ const idToLastHash = new Map(encodedIds.map((id) => [
894
+ id,
895
+ lastAvailableHash
896
+ ]));
897
+ this._indexMetadataStore.markDirty(idToLastHash, batch);
898
+ }
899
+ /**
900
+ * Called by AutomergeStorageAdapter after levelDB batch commit.
901
+ */
902
+ async _afterSave() {
903
+ this._indexMetadataStore.notifyMarkedDirty();
904
+ }
635
905
  _automergeDocs() {
636
906
  return mapValues(this._repo.handles, (handle) => ({
637
907
  state: handle.state,
@@ -662,9 +932,9 @@ var AutomergeHost = class {
662
932
  //
663
933
  async flush({ states }) {
664
934
  await Promise.all(states?.map(async ({ heads, documentId }) => {
665
- invariant3(heads, "heads are required for flush", {
666
- F: __dxlog_file4,
667
- L: 200,
935
+ invariant4(heads, "heads are required for flush", {
936
+ F: __dxlog_file5,
937
+ L: 252,
668
938
  S: this,
669
939
  A: [
670
940
  "heads",
@@ -692,37 +962,37 @@ var AutomergeHost = class {
692
962
  return this._meshNetwork.createExtension();
693
963
  }
694
964
  authorizeDevice(spaceKey, deviceKey) {
695
- log3("authorizeDevice", {
965
+ log4("authorizeDevice", {
696
966
  spaceKey,
697
967
  deviceKey
698
968
  }, {
699
- F: __dxlog_file4,
700
- L: 230,
969
+ F: __dxlog_file5,
970
+ L: 282,
701
971
  S: this,
702
972
  C: (f, a) => f(...a)
703
973
  });
704
974
  defaultMap(this._authorizedDevices, spaceKey, () => new ComplexSet(PublicKey.hash)).add(deviceKey);
705
975
  }
706
976
  };
707
- _ts_decorate([
977
+ _ts_decorate2([
708
978
  trace.info()
709
979
  ], AutomergeHost.prototype, "_peerId", void 0);
710
- _ts_decorate([
980
+ _ts_decorate2([
711
981
  trace.info({
712
982
  depth: null
713
983
  })
714
984
  ], AutomergeHost.prototype, "_automergeDocs", null);
715
- _ts_decorate([
985
+ _ts_decorate2([
716
986
  trace.info({
717
987
  depth: null
718
988
  })
719
989
  ], AutomergeHost.prototype, "_automergePeers", null);
720
- _ts_decorate([
990
+ _ts_decorate2([
721
991
  trace.span({
722
992
  showInBrowserTimeline: true
723
993
  })
724
994
  ], AutomergeHost.prototype, "flush", null);
725
- AutomergeHost = _ts_decorate([
995
+ AutomergeHost = _ts_decorate2([
726
996
  trace.resource()
727
997
  ], AutomergeHost);
728
998
  var getSpaceKeyFromDoc = (doc) => {
@@ -755,10 +1025,10 @@ var changeIsPresentInDoc = (doc, changeHash) => {
755
1025
  import { Event as Event2 } from "@dxos/async";
756
1026
  import { cancelWithContext } from "@dxos/context";
757
1027
  import { warnAfterTimeout } from "@dxos/debug";
758
- import { invariant as invariant4 } from "@dxos/invariant";
759
- import { log as log4 } from "@dxos/log";
1028
+ import { invariant as invariant5 } from "@dxos/invariant";
1029
+ import { log as log5 } from "@dxos/log";
760
1030
  import { trace as trace2 } from "@dxos/tracing";
761
- function _ts_decorate2(decorators, target, key, desc) {
1031
+ function _ts_decorate3(decorators, target, key, desc) {
762
1032
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
763
1033
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
764
1034
  r = Reflect.decorate(decorators, target, key, desc);
@@ -768,7 +1038,7 @@ function _ts_decorate2(decorators, target, key, desc) {
768
1038
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
769
1039
  return c > 3 && r && Object.defineProperty(target, key, r), r;
770
1040
  }
771
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
1041
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
772
1042
  var AutomergeDocumentLoaderImpl = class {
773
1043
  constructor(_spaceKey, _repo) {
774
1044
  this._spaceKey = _spaceKey;
@@ -779,20 +1049,21 @@ var AutomergeDocumentLoaderImpl = class {
779
1049
  this.onObjectDocumentLoaded = new Event2();
780
1050
  }
781
1051
  getAllHandles() {
782
- return [
1052
+ return this._spaceRootDocHandle != null ? [
1053
+ this._spaceRootDocHandle,
783
1054
  ...new Set(this._objectDocumentHandles.values())
784
- ];
1055
+ ] : [];
785
1056
  }
786
1057
  async loadSpaceRootDocHandle(ctx, spaceState) {
787
1058
  if (this._spaceRootDocHandle != null) {
788
1059
  return;
789
1060
  }
790
1061
  if (!spaceState.rootUrl) {
791
- log4.error("Database opened with no rootUrl", {
1062
+ log5.error("Database opened with no rootUrl", {
792
1063
  spaceKey: this._spaceKey
793
1064
  }, {
794
- F: __dxlog_file5,
795
- L: 69,
1065
+ F: __dxlog_file6,
1066
+ L: 70,
796
1067
  S: this,
797
1068
  C: (f, a) => f(...a)
798
1069
  });
@@ -800,9 +1071,9 @@ var AutomergeDocumentLoaderImpl = class {
800
1071
  } else {
801
1072
  const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
802
1073
  const doc = existingDocHandle.docSync();
803
- invariant4(doc, void 0, {
804
- F: __dxlog_file5,
805
- L: 74,
1074
+ invariant5(doc, void 0, {
1075
+ F: __dxlog_file6,
1076
+ L: 75,
806
1077
  S: this,
807
1078
  A: [
808
1079
  "doc",
@@ -815,45 +1086,54 @@ var AutomergeDocumentLoaderImpl = class {
815
1086
  this._spaceRootDocHandle = existingDocHandle;
816
1087
  }
817
1088
  }
818
- loadObjectDocument(objectId) {
819
- invariant4(this._spaceRootDocHandle, void 0, {
820
- F: __dxlog_file5,
821
- L: 83,
822
- S: this,
823
- A: [
824
- "this._spaceRootDocHandle",
825
- ""
826
- ]
827
- });
828
- if (this._objectDocumentHandles.has(objectId) || this._objectsPendingDocumentLoad.has(objectId)) {
829
- return;
830
- }
831
- const spaceRootDoc = this._spaceRootDocHandle.docSync();
832
- invariant4(spaceRootDoc, void 0, {
833
- F: __dxlog_file5,
834
- L: 88,
835
- S: this,
836
- A: [
837
- "spaceRootDoc",
838
- ""
839
- ]
840
- });
841
- const documentUrl = (spaceRootDoc.links ?? {})[objectId];
842
- if (documentUrl == null) {
843
- this._objectsPendingDocumentLoad.add(objectId);
844
- log4.info("loading delayed until object links are initialized", {
845
- objectId
846
- }, {
847
- F: __dxlog_file5,
848
- L: 92,
1089
+ loadObjectDocument(objectIdOrMany) {
1090
+ const objectIds = Array.isArray(objectIdOrMany) ? objectIdOrMany : [
1091
+ objectIdOrMany
1092
+ ];
1093
+ let hasUrlsToLoad = false;
1094
+ const urlsToLoad = {};
1095
+ for (const objectId of objectIds) {
1096
+ invariant5(this._spaceRootDocHandle, void 0, {
1097
+ F: __dxlog_file6,
1098
+ L: 88,
849
1099
  S: this,
850
- C: (f, a) => f(...a)
1100
+ A: [
1101
+ "this._spaceRootDocHandle",
1102
+ ""
1103
+ ]
851
1104
  });
852
- return;
1105
+ if (this._objectDocumentHandles.has(objectId) || this._objectsPendingDocumentLoad.has(objectId)) {
1106
+ continue;
1107
+ }
1108
+ const spaceRootDoc = this._spaceRootDocHandle.docSync();
1109
+ invariant5(spaceRootDoc, void 0, {
1110
+ F: __dxlog_file6,
1111
+ L: 93,
1112
+ S: this,
1113
+ A: [
1114
+ "spaceRootDoc",
1115
+ ""
1116
+ ]
1117
+ });
1118
+ const documentUrl = (spaceRootDoc.links ?? {})[objectId];
1119
+ if (documentUrl == null) {
1120
+ this._objectsPendingDocumentLoad.add(objectId);
1121
+ log5.info("loading delayed until object links are initialized", {
1122
+ objectId
1123
+ }, {
1124
+ F: __dxlog_file6,
1125
+ L: 97,
1126
+ S: this,
1127
+ C: (f, a) => f(...a)
1128
+ });
1129
+ } else {
1130
+ urlsToLoad[objectId] = documentUrl;
1131
+ hasUrlsToLoad = true;
1132
+ }
1133
+ }
1134
+ if (hasUrlsToLoad) {
1135
+ this._loadLinkedObjects(urlsToLoad);
853
1136
  }
854
- this._loadLinkedObjects({
855
- [objectId]: documentUrl
856
- });
857
1137
  }
858
1138
  onObjectLinksUpdated(links) {
859
1139
  if (!links) {
@@ -864,9 +1144,9 @@ var AutomergeDocumentLoaderImpl = class {
864
1144
  linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
865
1145
  }
866
1146
  getSpaceRootDocHandle() {
867
- invariant4(this._spaceRootDocHandle, void 0, {
868
- F: __dxlog_file5,
869
- L: 110,
1147
+ invariant5(this._spaceRootDocHandle, void 0, {
1148
+ F: __dxlog_file6,
1149
+ L: 120,
870
1150
  S: this,
871
1151
  A: [
872
1152
  "this._spaceRootDocHandle",
@@ -876,9 +1156,9 @@ var AutomergeDocumentLoaderImpl = class {
876
1156
  return this._spaceRootDocHandle;
877
1157
  }
878
1158
  createDocumentForObject(objectId) {
879
- invariant4(this._spaceRootDocHandle, void 0, {
880
- F: __dxlog_file5,
881
- L: 115,
1159
+ invariant5(this._spaceRootDocHandle, void 0, {
1160
+ F: __dxlog_file6,
1161
+ L: 125,
882
1162
  S: this,
883
1163
  A: [
884
1164
  "this._spaceRootDocHandle",
@@ -916,30 +1196,30 @@ var AutomergeDocumentLoaderImpl = class {
916
1196
  };
917
1197
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
918
1198
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
919
- log4.warn("object already inlined in a different document, ignoring the link", {
1199
+ log5.warn("object already inlined in a different document, ignoring the link", {
920
1200
  ...logMeta,
921
1201
  actualDocumentUrl: objectDocumentHandle.url
922
1202
  }, {
923
- F: __dxlog_file5,
924
- L: 145,
1203
+ F: __dxlog_file6,
1204
+ L: 155,
925
1205
  S: this,
926
1206
  C: (f, a) => f(...a)
927
1207
  });
928
1208
  continue;
929
1209
  }
930
1210
  if (objectDocumentHandle?.url === automergeUrl) {
931
- log4.warn("object document was already loaded", logMeta, {
932
- F: __dxlog_file5,
933
- L: 152,
1211
+ log5.warn("object document was already loaded", logMeta, {
1212
+ F: __dxlog_file6,
1213
+ L: 162,
934
1214
  S: this,
935
1215
  C: (f, a) => f(...a)
936
1216
  });
937
1217
  continue;
938
1218
  }
939
1219
  const handle = this._repo.find(automergeUrl);
940
- log4.debug("document loading triggered", logMeta, {
941
- F: __dxlog_file5,
942
- L: 156,
1220
+ log5.debug("document loading triggered", logMeta, {
1221
+ F: __dxlog_file6,
1222
+ L: 166,
943
1223
  S: this,
944
1224
  C: (f, a) => f(...a)
945
1225
  });
@@ -957,12 +1237,12 @@ var AutomergeDocumentLoaderImpl = class {
957
1237
  break;
958
1238
  } catch (err) {
959
1239
  if (`${err}`.includes("Timeout")) {
960
- log4.info("wraparound", {
1240
+ log5.info("wraparound", {
961
1241
  id: docHandle.documentId,
962
1242
  state: docHandle.state
963
1243
  }, {
964
- F: __dxlog_file5,
965
- L: 172,
1244
+ F: __dxlog_file6,
1245
+ L: 182,
966
1246
  S: this,
967
1247
  C: (f, a) => f(...a)
968
1248
  });
@@ -1002,9 +1282,9 @@ var AutomergeDocumentLoaderImpl = class {
1002
1282
  docUrl: handle.url
1003
1283
  };
1004
1284
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1005
- log4.info("document loaded after all listeners were removed", logMeta, {
1006
- F: __dxlog_file5,
1007
- L: 208,
1285
+ log5.info("document loaded after all listeners were removed", logMeta, {
1286
+ F: __dxlog_file6,
1287
+ L: 218,
1008
1288
  S: this,
1009
1289
  C: (f, a) => f(...a)
1010
1290
  });
@@ -1012,9 +1292,9 @@ var AutomergeDocumentLoaderImpl = class {
1012
1292
  }
1013
1293
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1014
1294
  if (objectDocHandle?.url !== handle.url) {
1015
- log4.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1016
- F: __dxlog_file5,
1017
- L: 213,
1295
+ log5.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1296
+ F: __dxlog_file6,
1297
+ L: 223,
1018
1298
  S: this,
1019
1299
  C: (f, a) => f(...a)
1020
1300
  });
@@ -1026,14 +1306,14 @@ var AutomergeDocumentLoaderImpl = class {
1026
1306
  });
1027
1307
  } catch (err) {
1028
1308
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1029
- log4.warn("failed to load a document", {
1309
+ log5.warn("failed to load a document", {
1030
1310
  objectId,
1031
1311
  automergeUrl: handle.url,
1032
1312
  retryLoading: shouldRetryLoading,
1033
1313
  err
1034
1314
  }, {
1035
- F: __dxlog_file5,
1036
- L: 219,
1315
+ F: __dxlog_file6,
1316
+ L: 229,
1037
1317
  S: this,
1038
1318
  C: (f, a) => f(...a)
1039
1319
  });
@@ -1043,27 +1323,14 @@ var AutomergeDocumentLoaderImpl = class {
1043
1323
  }
1044
1324
  }
1045
1325
  };
1046
- _ts_decorate2([
1326
+ _ts_decorate3([
1047
1327
  trace2.span({
1048
1328
  showInBrowserTimeline: true
1049
1329
  })
1050
1330
  ], AutomergeDocumentLoaderImpl.prototype, "loadSpaceRootDocHandle", null);
1051
- AutomergeDocumentLoaderImpl = _ts_decorate2([
1331
+ AutomergeDocumentLoaderImpl = _ts_decorate3([
1052
1332
  trace2.resource()
1053
1333
  ], AutomergeDocumentLoaderImpl);
1054
-
1055
- // packages/core/echo/echo-pipeline/src/automerge/reference.ts
1056
- import { Reference } from "@dxos/echo-schema";
1057
- var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
1058
- var encodeReference = (reference) => ({
1059
- "@type": REFERENCE_TYPE_TAG,
1060
- // NOTE: Automerge do not support undefined values, so we need to use null instead.
1061
- itemId: reference.itemId ?? null,
1062
- protocol: reference.protocol ?? null,
1063
- host: reference.host ?? null
1064
- });
1065
- var decodeReference = (value) => new Reference(value.itemId, value.protocol ?? void 0, value.host ?? void 0);
1066
- var isEncodedReferenceObject = (value) => typeof value === "object" && value !== null && value["@type"] === REFERENCE_TYPE_TAG;
1067
1334
  export {
1068
1335
  AuthExtension,
1069
1336
  AuthStatus,
@@ -1078,7 +1345,6 @@ export {
1078
1345
  MeshNetworkAdapter,
1079
1346
  MetadataStore,
1080
1347
  Pipeline,
1081
- REFERENCE_TYPE_TAG,
1082
1348
  SnapshotManager,
1083
1349
  SnapshotStore,
1084
1350
  Space,
@@ -1088,12 +1354,9 @@ export {
1088
1354
  TimeframeClock,
1089
1355
  codec,
1090
1356
  createMappedFeedWriter,
1091
- decodeReference,
1092
- encodeReference,
1093
1357
  encodingOptions,
1094
1358
  getSpaceKeyFromDoc,
1095
1359
  hasInvitationExpired,
1096
- isEncodedReferenceObject,
1097
1360
  mapFeedIndexesToTimeframe,
1098
1361
  mapTimeframeToFeedIndexes,
1099
1362
  startAfter,