@dxos/echo-pipeline 0.4.10-main.0302e13 → 0.4.10-main.05dbd64

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 (74) hide show
  1. package/dist/lib/browser/{chunk-RTEEJ723.mjs → chunk-KMWJLYEQ.mjs} +77 -57
  2. package/dist/lib/browser/chunk-KMWJLYEQ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +368 -246
  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 +10 -2
  7. package/dist/lib/browser/testing/index.mjs.map +4 -4
  8. package/dist/lib/node/{chunk-7VZVCCNF.cjs → chunk-YZA42CKA.cjs} +82 -62
  9. package/dist/lib/node/chunk-YZA42CKA.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +391 -270
  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 +20 -13
  14. package/dist/lib/node/testing/index.cjs.map +4 -4
  15. package/dist/types/src/automerge/automerge-doc-loader.d.ts +2 -0
  16. package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -1
  17. package/dist/types/src/automerge/automerge-host.d.ts +21 -18
  18. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  19. package/dist/types/src/automerge/automerge-repo.test.d.ts +2 -0
  20. package/dist/types/src/automerge/automerge-repo.test.d.ts.map +1 -0
  21. package/dist/types/src/automerge/index.d.ts +2 -0
  22. package/dist/types/src/automerge/index.d.ts.map +1 -1
  23. package/dist/types/src/automerge/level.test.d.ts +2 -0
  24. package/dist/types/src/automerge/level.test.d.ts.map +1 -0
  25. package/dist/types/src/automerge/leveldb-storage-adapter.d.ts +30 -0
  26. package/dist/types/src/automerge/leveldb-storage-adapter.d.ts.map +1 -0
  27. package/dist/types/src/automerge/local-host-network-adapter.d.ts +8 -1
  28. package/dist/types/src/automerge/local-host-network-adapter.d.ts.map +1 -1
  29. package/dist/types/src/automerge/migrations.d.ts +7 -0
  30. package/dist/types/src/automerge/migrations.d.ts.map +1 -0
  31. package/dist/types/src/automerge/reference.d.ts +15 -0
  32. package/dist/types/src/automerge/reference.d.ts.map +1 -0
  33. package/dist/types/src/automerge/storage-adapter.test.d.ts +2 -0
  34. package/dist/types/src/automerge/storage-adapter.test.d.ts.map +1 -0
  35. package/dist/types/src/automerge/types.d.ts +8 -2
  36. package/dist/types/src/automerge/types.d.ts.map +1 -1
  37. package/dist/types/src/metadata/metadata-store.d.ts +2 -1
  38. package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
  39. package/dist/types/src/space/control-pipeline.d.ts +3 -1
  40. package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
  41. package/dist/types/src/space/space-manager.d.ts +3 -1
  42. package/dist/types/src/space/space-manager.d.ts.map +1 -1
  43. package/dist/types/src/space/space.d.ts +6 -9
  44. package/dist/types/src/space/space.d.ts.map +1 -1
  45. package/dist/types/src/testing/index.d.ts +1 -0
  46. package/dist/types/src/testing/index.d.ts.map +1 -1
  47. package/dist/types/src/testing/level.d.ts +3 -0
  48. package/dist/types/src/testing/level.d.ts.map +1 -0
  49. package/dist/types/src/testing/test-agent-builder.d.ts +2 -2
  50. package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
  51. package/package.json +33 -30
  52. package/src/automerge/automerge-doc-loader.ts +9 -0
  53. package/src/automerge/automerge-host.test.ts +22 -8
  54. package/src/automerge/automerge-host.ts +66 -118
  55. package/src/automerge/automerge-repo.test.ts +29 -0
  56. package/src/automerge/index.ts +2 -0
  57. package/src/automerge/level.test.ts +82 -0
  58. package/src/automerge/leveldb-storage-adapter.ts +117 -0
  59. package/src/automerge/local-host-network-adapter.ts +19 -13
  60. package/src/automerge/migrations.ts +41 -0
  61. package/src/automerge/reference.ts +31 -0
  62. package/src/automerge/storage-adapter.test.ts +90 -0
  63. package/src/automerge/types.ts +8 -5
  64. package/src/db-host/data-service.ts +1 -1
  65. package/src/metadata/metadata-store.ts +17 -8
  66. package/src/space/control-pipeline.ts +11 -1
  67. package/src/space/space-manager.ts +4 -0
  68. package/src/space/space.test.ts +7 -7
  69. package/src/space/space.ts +17 -22
  70. package/src/testing/index.ts +1 -0
  71. package/src/testing/level.ts +11 -0
  72. package/src/testing/test-agent-builder.ts +1 -0
  73. package/dist/lib/browser/chunk-RTEEJ723.mjs.map +0 -7
  74. package/dist/lib/node/chunk-7VZVCCNF.cjs.map +0 -7
@@ -18,168 +18,170 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var node_exports = {};
20
20
  __export(node_exports, {
21
- AuthExtension: () => import_chunk_7VZVCCNF.AuthExtension,
22
- AuthStatus: () => import_chunk_7VZVCCNF.AuthStatus,
21
+ AuthExtension: () => import_chunk_YZA42CKA.AuthExtension,
22
+ AuthStatus: () => import_chunk_YZA42CKA.AuthStatus,
23
23
  AutomergeDocumentLoaderImpl: () => AutomergeDocumentLoaderImpl,
24
24
  AutomergeHost: () => AutomergeHost,
25
25
  AutomergeStorageAdapter: () => AutomergeStorageAdapter,
26
- DataServiceImpl: () => import_chunk_7VZVCCNF.DataServiceImpl,
26
+ DataServiceImpl: () => import_chunk_YZA42CKA.DataServiceImpl,
27
+ LevelDBStorageAdapter: () => LevelDBStorageAdapter,
27
28
  LocalHostNetworkAdapter: () => LocalHostNetworkAdapter,
28
- MOCK_AUTH_PROVIDER: () => import_chunk_7VZVCCNF.MOCK_AUTH_PROVIDER,
29
- MOCK_AUTH_VERIFIER: () => import_chunk_7VZVCCNF.MOCK_AUTH_VERIFIER,
29
+ MOCK_AUTH_PROVIDER: () => import_chunk_YZA42CKA.MOCK_AUTH_PROVIDER,
30
+ MOCK_AUTH_VERIFIER: () => import_chunk_YZA42CKA.MOCK_AUTH_VERIFIER,
30
31
  MeshNetworkAdapter: () => MeshNetworkAdapter,
31
- MetadataStore: () => import_chunk_7VZVCCNF.MetadataStore,
32
- Pipeline: () => import_chunk_7VZVCCNF.Pipeline,
33
- SnapshotManager: () => import_chunk_7VZVCCNF.SnapshotManager,
34
- SnapshotStore: () => import_chunk_7VZVCCNF.SnapshotStore,
35
- Space: () => import_chunk_7VZVCCNF.Space,
36
- SpaceManager: () => import_chunk_7VZVCCNF.SpaceManager,
37
- SpaceProtocol: () => import_chunk_7VZVCCNF.SpaceProtocol,
38
- SpaceProtocolSession: () => import_chunk_7VZVCCNF.SpaceProtocolSession,
39
- TimeframeClock: () => import_chunk_7VZVCCNF.TimeframeClock,
40
- codec: () => import_chunk_7VZVCCNF.codec,
41
- createMappedFeedWriter: () => import_chunk_7VZVCCNF.createMappedFeedWriter,
32
+ MetadataStore: () => import_chunk_YZA42CKA.MetadataStore,
33
+ Pipeline: () => import_chunk_YZA42CKA.Pipeline,
34
+ REFERENCE_TYPE_TAG: () => REFERENCE_TYPE_TAG,
35
+ SnapshotManager: () => import_chunk_YZA42CKA.SnapshotManager,
36
+ SnapshotStore: () => import_chunk_YZA42CKA.SnapshotStore,
37
+ Space: () => import_chunk_YZA42CKA.Space,
38
+ SpaceManager: () => import_chunk_YZA42CKA.SpaceManager,
39
+ SpaceProtocol: () => import_chunk_YZA42CKA.SpaceProtocol,
40
+ SpaceProtocolSession: () => import_chunk_YZA42CKA.SpaceProtocolSession,
41
+ TimeframeClock: () => import_chunk_YZA42CKA.TimeframeClock,
42
+ codec: () => import_chunk_YZA42CKA.codec,
43
+ createMappedFeedWriter: () => import_chunk_YZA42CKA.createMappedFeedWriter,
44
+ decodeReference: () => decodeReference,
45
+ encodeReference: () => encodeReference,
46
+ encodingOptions: () => encodingOptions,
42
47
  getSpaceKeyFromDoc: () => getSpaceKeyFromDoc,
43
- mapFeedIndexesToTimeframe: () => import_chunk_7VZVCCNF.mapFeedIndexesToTimeframe,
44
- mapTimeframeToFeedIndexes: () => import_chunk_7VZVCCNF.mapTimeframeToFeedIndexes,
45
- startAfter: () => import_chunk_7VZVCCNF.startAfter,
46
- valueEncoding: () => import_chunk_7VZVCCNF.valueEncoding
48
+ hasInvitationExpired: () => import_chunk_YZA42CKA.hasInvitationExpired,
49
+ isEncodedReferenceObject: () => isEncodedReferenceObject,
50
+ mapFeedIndexesToTimeframe: () => import_chunk_YZA42CKA.mapFeedIndexesToTimeframe,
51
+ mapTimeframeToFeedIndexes: () => import_chunk_YZA42CKA.mapTimeframeToFeedIndexes,
52
+ startAfter: () => import_chunk_YZA42CKA.startAfter,
53
+ valueEncoding: () => import_chunk_YZA42CKA.valueEncoding
47
54
  });
48
55
  module.exports = __toCommonJS(node_exports);
49
- var import_chunk_7VZVCCNF = require("./chunk-7VZVCCNF.cjs");
56
+ var import_chunk_YZA42CKA = require("./chunk-YZA42CKA.cjs");
57
+ var import_async = require("@dxos/async");
50
58
  var import_automerge = require("@dxos/automerge/automerge");
51
59
  var import_automerge_repo = require("@dxos/automerge/automerge-repo");
52
- var import_automerge_repo_storage_indexeddb = require("@dxos/automerge/automerge-repo-storage-indexeddb");
53
60
  var import_context = require("@dxos/context");
54
61
  var import_keys = require("@dxos/keys");
55
62
  var import_log = require("@dxos/log");
56
- var import_protocols = require("@dxos/protocols");
57
- var import_random_access_storage = require("@dxos/random-access-storage");
58
63
  var import_tracing = require("@dxos/tracing");
59
64
  var import_util = require("@dxos/util");
60
- var import_util2 = require("@dxos/util");
61
- var import_async = require("@dxos/async");
65
+ var import_context2 = require("@dxos/context");
66
+ var import_async2 = require("@dxos/async");
62
67
  var import_automerge_repo2 = require("@dxos/automerge/automerge-repo");
63
68
  var import_codec_protobuf = require("@dxos/codec-protobuf");
64
69
  var import_invariant = require("@dxos/invariant");
65
- var import_log2 = require("@dxos/log");
66
- var import_async2 = require("@dxos/async");
70
+ var import_async3 = require("@dxos/async");
67
71
  var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
68
72
  var import_invariant2 = require("@dxos/invariant");
69
- var import_log3 = require("@dxos/log");
73
+ var import_log2 = require("@dxos/log");
70
74
  var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
71
- var import_async3 = require("@dxos/async");
72
- var import_context2 = require("@dxos/context");
75
+ var import_automerge_repo_storage_indexeddb = require("@dxos/automerge/automerge-repo-storage-indexeddb");
76
+ var import_log3 = require("@dxos/log");
77
+ var import_random_access_storage = require("@dxos/random-access-storage");
78
+ var import_util2 = require("@dxos/util");
79
+ var import_async4 = require("@dxos/async");
80
+ var import_context3 = require("@dxos/context");
73
81
  var import_debug = require("@dxos/debug");
74
82
  var import_invariant3 = require("@dxos/invariant");
75
83
  var import_log4 = require("@dxos/log");
76
- var AutomergeStorageAdapter = class {
77
- constructor(_directory) {
78
- this._directory = _directory;
79
- this._state = "opened";
84
+ var import_tracing2 = require("@dxos/tracing");
85
+ var import_echo_schema = require("@dxos/echo-schema");
86
+ var LevelDBStorageAdapter = class extends import_context2.Resource {
87
+ constructor(_params) {
88
+ super();
89
+ this._params = _params;
80
90
  }
81
- async load(key) {
82
- if (this._state !== "opened") {
83
- return void 0;
84
- }
85
- const filename = this._getFilename(key);
86
- const file = this._directory.getOrCreateFile(filename);
87
- const { size } = await file.stat();
88
- if (!size || size === 0) {
89
- return void 0;
91
+ async load(keyArray) {
92
+ try {
93
+ if (this._lifecycleState !== import_context2.LifecycleState.OPEN) {
94
+ return void 0;
95
+ }
96
+ return await this._params.db.get(keyArray, {
97
+ ...encodingOptions
98
+ });
99
+ } catch (err) {
100
+ if (isLevelDbNotFoundError(err)) {
101
+ return void 0;
102
+ }
103
+ throw err;
90
104
  }
91
- const buffer = await file.read(0, size);
92
- return (0, import_util2.bufferToArray)(buffer);
93
105
  }
94
- async save(key, data) {
95
- if (this._state !== "opened") {
106
+ async save(keyArray, binary) {
107
+ if (this._lifecycleState !== import_context2.LifecycleState.OPEN) {
96
108
  return void 0;
97
109
  }
98
- const filename = this._getFilename(key);
99
- const file = this._directory.getOrCreateFile(filename);
100
- await file.write(0, (0, import_util2.arrayToBuffer)(data));
101
- await file.truncate?.(data.length);
102
- await file.flush?.();
110
+ const batch = this._params.db.batch();
111
+ await this._params.callbacks?.beforeSave?.({
112
+ path: keyArray,
113
+ batch
114
+ });
115
+ batch.put(keyArray, Buffer.from(binary), {
116
+ ...encodingOptions
117
+ });
118
+ await batch.write();
119
+ await this._params.callbacks?.afterSave?.(keyArray);
103
120
  }
104
- async remove(key) {
105
- if (this._state !== "opened") {
121
+ async remove(keyArray) {
122
+ if (this._lifecycleState !== import_context2.LifecycleState.OPEN) {
106
123
  return void 0;
107
124
  }
108
- const filename = this._getFilename(key);
109
- const file = this._directory.getOrCreateFile(filename);
110
- await file.destroy();
125
+ await this._params.db.del(keyArray, {
126
+ ...encodingOptions
127
+ });
111
128
  }
112
129
  async loadRange(keyPrefix) {
113
- if (this._state !== "opened") {
130
+ if (this._lifecycleState !== import_context2.LifecycleState.OPEN) {
114
131
  return [];
115
132
  }
116
- const filename = this._getFilename(keyPrefix);
117
- const entries = await this._directory.list();
118
- return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
119
- const file = this._directory.getOrCreateFile(entry);
120
- const { size } = await file.stat();
121
- const buffer = await file.read(0, size);
122
- return {
123
- key: this._getKeyFromFilename(entry),
124
- data: (0, import_util2.bufferToArray)(buffer)
125
- };
126
- }));
133
+ const result = [];
134
+ for await (const [key, value] of this._params.db.iterator({
135
+ gte: keyPrefix,
136
+ lte: [
137
+ ...keyPrefix,
138
+ "\uFFFF"
139
+ ],
140
+ ...encodingOptions
141
+ })) {
142
+ result.push({
143
+ key,
144
+ data: value
145
+ });
146
+ }
147
+ return result;
127
148
  }
128
149
  async removeRange(keyPrefix) {
129
- if (this._state !== "opened") {
150
+ if (this._lifecycleState !== import_context2.LifecycleState.OPEN) {
130
151
  return void 0;
131
152
  }
132
- const filename = this._getFilename(keyPrefix);
133
- const entries = await this._directory.list();
134
- await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
135
- const file = this._directory.getOrCreateFile(entry);
136
- await file.destroy();
137
- }));
138
- }
139
- async close() {
140
- this._state = "closed";
141
- }
142
- _getFilename(key) {
143
- return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
144
- }
145
- _getKeyFromFilename(filename) {
146
- return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
147
- }
148
- };
149
- var AutomergeStorageWrapper = class {
150
- constructor({ storage, callbacks }) {
151
- this._storage = storage;
152
- this._callbacks = callbacks;
153
- }
154
- async load(key) {
155
- return this._storage.load(key);
156
- }
157
- async save(key, value) {
158
- await this._callbacks.beforeSave?.(key);
159
- await this._storage.save(key, value);
160
- await this._callbacks.afterSave?.(key);
161
- }
162
- async remove(key) {
163
- return this._storage.remove(key);
164
- }
165
- async loadRange(keyPrefix) {
166
- return this._storage.loadRange(keyPrefix);
167
- }
168
- async removeRange(keyPrefix) {
169
- return this._storage.removeRange(keyPrefix);
170
- }
171
- async close() {
172
- if (this._storage instanceof AutomergeStorageAdapter) {
173
- return this._storage.close();
153
+ const batch = this._params.db.batch();
154
+ for await (const [key] of this._params.db.iterator({
155
+ gte: keyPrefix,
156
+ lte: [
157
+ ...keyPrefix,
158
+ "\uFFFF"
159
+ ],
160
+ ...encodingOptions
161
+ })) {
162
+ batch.del(key, {
163
+ ...encodingOptions
164
+ });
174
165
  }
166
+ await batch.write();
175
167
  }
176
168
  };
169
+ var keyEncoder = {
170
+ encode: (key) => Buffer.from(key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-")),
171
+ decode: (key) => Buffer.from(key).toString().split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"))
172
+ };
173
+ var encodingOptions = {
174
+ keyEncoding: keyEncoder,
175
+ valueEncoding: "buffer"
176
+ };
177
+ var isLevelDbNotFoundError = (err) => err.code === "LEVEL_NOT_FOUND";
177
178
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts";
178
179
  var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
179
180
  constructor() {
180
181
  super(...arguments);
181
182
  this._peers = /* @__PURE__ */ new Map();
182
- this._connected = new import_async.Trigger();
183
+ this._connected = new import_async2.Trigger();
184
+ this._isConnected = false;
183
185
  }
184
186
  /**
185
187
  * Emits `ready` event. That signals to `Repo` that it can start using the adapter.
@@ -189,15 +191,21 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
189
191
  network: this
190
192
  });
191
193
  }
194
+ /**
195
+ * Called by `Repo` to connect to the network.
196
+ *
197
+ * @param peerId Our peer Id.
198
+ */
192
199
  connect(peerId) {
193
200
  this.peerId = peerId;
201
+ this._isConnected = true;
194
202
  this._connected.wake();
195
203
  }
196
204
  send(message) {
197
205
  const peer = this._peers.get(message.targetId);
198
206
  (0, import_invariant.invariant)(peer, "Peer not found.", {
199
207
  F: __dxlog_file,
200
- L: 45,
208
+ L: 51,
201
209
  S: this,
202
210
  A: [
203
211
  "peer",
@@ -212,12 +220,17 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
212
220
  }
213
221
  disconnect() {
214
222
  }
223
+ async whenConnected() {
224
+ await this._connected.wait({
225
+ timeout: 1e4
226
+ });
227
+ }
215
228
  syncRepo({ id, syncMessage }) {
216
229
  const peerId = this._getPeerId(id);
217
230
  return new import_codec_protobuf.Stream(({ next, close }) => {
218
231
  (0, import_invariant.invariant)(!this._peers.has(peerId), "Peer already connected.", {
219
232
  F: __dxlog_file,
220
- L: 63,
233
+ L: 73,
221
234
  S: this,
222
235
  A: [
223
236
  "!this._peers.has(peerId)",
@@ -239,35 +252,47 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
239
252
  });
240
253
  }
241
254
  });
242
- this._connected.wait({
243
- timeout: 1e3
244
- }).then(() => {
245
- this.emit("peer-candidate", {
246
- peerMetadata: {},
247
- peerId
248
- });
249
- }).catch((err) => import_log2.log.catch(err, void 0, {
255
+ (0, import_invariant.invariant)(this._isConnected, void 0, {
250
256
  F: __dxlog_file,
251
- L: 88,
257
+ L: 90,
252
258
  S: this,
253
- C: (f, a) => f(...a)
254
- }));
259
+ A: [
260
+ "this._isConnected",
261
+ ""
262
+ ]
263
+ });
264
+ this.emit("peer-candidate", {
265
+ peerMetadata: {},
266
+ peerId
267
+ });
255
268
  });
256
269
  }
257
270
  async sendSyncMessage({ id, syncMessage }) {
258
- await this._connected.wait({
259
- timeout: 1e3
271
+ (0, import_invariant.invariant)(this._isConnected, void 0, {
272
+ F: __dxlog_file,
273
+ L: 99,
274
+ S: this,
275
+ A: [
276
+ "this._isConnected",
277
+ ""
278
+ ]
260
279
  });
261
280
  const message = import_automerge_repo2.cbor.decode(syncMessage);
262
281
  this.emit("message", message);
263
282
  }
264
283
  async getHostInfo() {
265
- await this._connected.wait({
266
- timeout: 1e3
284
+ (0, import_invariant.invariant)(this._isConnected, void 0, {
285
+ F: __dxlog_file,
286
+ L: 105,
287
+ S: this,
288
+ A: [
289
+ "this._isConnected",
290
+ ""
291
+ ]
267
292
  });
268
293
  (0, import_invariant.invariant)(this.peerId, "Peer id not set.", {
269
294
  F: __dxlog_file,
270
- L: 100,
295
+ L: 106,
271
296
  S: this,
272
297
  A: [
273
298
  "this.peerId",
@@ -287,7 +312,7 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
287
312
  constructor() {
288
313
  super(...arguments);
289
314
  this._extensions = /* @__PURE__ */ new Map();
290
- this._connected = new import_async2.Trigger();
315
+ this._connected = new import_async3.Trigger();
291
316
  }
292
317
  /**
293
318
  * Emits `ready` event. That signals to `Repo` that it can start using the adapter.
@@ -315,7 +340,7 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
315
340
  });
316
341
  extension.sendSyncMessage({
317
342
  payload: import_automerge_repo3.cbor.encode(message)
318
- }).catch((err) => import_log3.log.catch(err, void 0, {
343
+ }).catch((err) => import_log2.log.catch(err, void 0, {
319
344
  F: __dxlog_file2,
320
345
  L: 39,
321
346
  S: this,
@@ -340,7 +365,7 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
340
365
  }, {
341
366
  onStartReplication: async (info, remotePeerId) => {
342
367
  await this._connected.wait();
343
- (0, import_log3.log)("onStartReplication", {
368
+ (0, import_log2.log)("onStartReplication", {
344
369
  id: info.id,
345
370
  thisPeerId: this.peerId,
346
371
  remotePeerId: remotePeerId.toHex()
@@ -353,7 +378,7 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
353
378
  if (!this._extensions.has(info.id)) {
354
379
  peerInfo = info;
355
380
  this._extensions.set(info.id, extension);
356
- (0, import_log3.log)("peer-candidate", {
381
+ (0, import_log2.log)("peer-candidate", {
357
382
  id: info.id,
358
383
  thisPeerId: this.peerId,
359
384
  remotePeerId: remotePeerId.toHex()
@@ -392,6 +417,108 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
392
417
  return extension;
393
418
  }
394
419
  };
420
+ var AutomergeStorageAdapter = class {
421
+ constructor(_directory) {
422
+ this._directory = _directory;
423
+ this._state = "opened";
424
+ }
425
+ async load(key) {
426
+ if (this._state !== "opened") {
427
+ return void 0;
428
+ }
429
+ const filename = this._getFilename(key);
430
+ const file = this._directory.getOrCreateFile(filename);
431
+ const { size } = await file.stat();
432
+ if (!size || size === 0) {
433
+ return void 0;
434
+ }
435
+ const buffer = await file.read(0, size);
436
+ return (0, import_util2.bufferToArray)(buffer);
437
+ }
438
+ async save(key, data) {
439
+ if (this._state !== "opened") {
440
+ return void 0;
441
+ }
442
+ const filename = this._getFilename(key);
443
+ const file = this._directory.getOrCreateFile(filename);
444
+ await file.write(0, (0, import_util2.arrayToBuffer)(data));
445
+ await file.truncate?.(data.length);
446
+ await file.flush?.();
447
+ }
448
+ async remove(key) {
449
+ if (this._state !== "opened") {
450
+ return void 0;
451
+ }
452
+ const filename = this._getFilename(key);
453
+ const file = this._directory.getOrCreateFile(filename);
454
+ await file.destroy();
455
+ }
456
+ async loadRange(keyPrefix) {
457
+ if (this._state !== "opened") {
458
+ return [];
459
+ }
460
+ const filename = this._getFilename(keyPrefix);
461
+ const entries = await this._directory.list();
462
+ return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
463
+ const file = this._directory.getOrCreateFile(entry);
464
+ const { size } = await file.stat();
465
+ const buffer = await file.read(0, size);
466
+ return {
467
+ key: this._getKeyFromFilename(entry),
468
+ data: (0, import_util2.bufferToArray)(buffer)
469
+ };
470
+ }));
471
+ }
472
+ async removeRange(keyPrefix) {
473
+ if (this._state !== "opened") {
474
+ return void 0;
475
+ }
476
+ const filename = this._getFilename(keyPrefix);
477
+ const entries = await this._directory.list();
478
+ await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
479
+ const file = this._directory.getOrCreateFile(entry);
480
+ await file.destroy();
481
+ }));
482
+ }
483
+ async close() {
484
+ this._state = "closed";
485
+ }
486
+ _getFilename(key) {
487
+ return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
488
+ }
489
+ _getKeyFromFilename(filename) {
490
+ return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
491
+ }
492
+ };
493
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
494
+ var levelMigration = async ({ db, directory }) => {
495
+ const isNewLevel = !await db.iterator({
496
+ ...encodingOptions
497
+ }).next();
498
+ if (!isNewLevel) {
499
+ return;
500
+ }
501
+ const oldStorageAdapter = directory.type === import_random_access_storage.StorageType.IDB ? new import_automerge_repo_storage_indexeddb.IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory);
502
+ const chunks = await oldStorageAdapter.loadRange([]);
503
+ if (chunks.length === 0) {
504
+ return;
505
+ }
506
+ const batch = db.batch();
507
+ import_log3.log.info("found chunks on old storage adapter", {
508
+ chunks: chunks.length
509
+ }, {
510
+ F: __dxlog_file3,
511
+ L: 36,
512
+ S: void 0,
513
+ C: (f, a) => f(...a)
514
+ });
515
+ for (const { key, data } of await oldStorageAdapter.loadRange([])) {
516
+ data && batch.put(key, data, {
517
+ ...encodingOptions
518
+ });
519
+ }
520
+ await batch.write();
521
+ };
395
522
  function _ts_decorate(decorators, target, key, desc) {
396
523
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
397
524
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -402,26 +529,29 @@ function _ts_decorate(decorators, target, key, desc) {
402
529
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
403
530
  return c > 3 && r && Object.defineProperty(target, key, r), r;
404
531
  }
405
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
532
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
406
533
  var AutomergeHost = class {
407
- constructor({ directory, metadata }) {
534
+ constructor({ directory, db, storageCallbacks }) {
408
535
  this._ctx = new import_context.Context();
409
536
  this._authorizedDevices = new import_util.ComplexMap(import_keys.PublicKey.hash);
410
- this._updatingMetadata = /* @__PURE__ */ new Map();
411
537
  this._requestedDocs = /* @__PURE__ */ new Set();
412
- this._metadata = metadata;
413
- this._meshNetwork = new MeshNetworkAdapter();
414
- this._clientNetwork = new LocalHostNetworkAdapter();
415
- this._storage = new AutomergeStorageWrapper({
416
- storage: (
417
- // TODO(mykola): Delete specific handling of IDB storage.
418
- directory.type === import_random_access_storage.StorageType.IDB ? new import_automerge_repo_storage_indexeddb.IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory)
419
- ),
420
- callbacks: {
421
- beforeSave: (params) => this._beforeSave(params)
422
- }
538
+ this._directory = directory;
539
+ this._db = db;
540
+ this._storageCallbacks = storageCallbacks;
541
+ }
542
+ async open() {
543
+ this._directory && await levelMigration({
544
+ db: this._db,
545
+ directory: this._directory
423
546
  });
547
+ this._storage = new LevelDBStorageAdapter({
548
+ db: this._db,
549
+ callbacks: this._storageCallbacks
550
+ });
551
+ await this._storage.open?.();
424
552
  this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
553
+ this._meshNetwork = new MeshNetworkAdapter();
554
+ this._clientNetwork = new LocalHostNetworkAdapter();
425
555
  this._repo = new import_automerge_repo.Repo({
426
556
  peerId: this._peerId,
427
557
  network: [
@@ -446,8 +576,8 @@ var AutomergeHost = class {
446
576
  documentId,
447
577
  isRequested
448
578
  }, {
449
- F: __dxlog_file3,
450
- L: 96,
579
+ F: __dxlog_file4,
580
+ L: 100,
451
581
  S: this,
452
582
  C: (f, a) => f(...a)
453
583
  });
@@ -460,8 +590,8 @@ var AutomergeHost = class {
460
590
  peerId,
461
591
  documentId
462
592
  }, {
463
- F: __dxlog_file3,
464
- L: 103,
593
+ F: __dxlog_file4,
594
+ L: 107,
465
595
  S: this,
466
596
  C: (f, a) => f(...a)
467
597
  });
@@ -474,8 +604,8 @@ var AutomergeHost = class {
474
604
  peerId,
475
605
  documentId
476
606
  }, {
477
- F: __dxlog_file3,
478
- L: 112,
607
+ F: __dxlog_file4,
608
+ L: 116,
479
609
  S: this,
480
610
  C: (f, a) => f(...a)
481
611
  });
@@ -491,16 +621,16 @@ var AutomergeHost = class {
491
621
  spaceKey,
492
622
  isAuthorized
493
623
  }, {
494
- F: __dxlog_file3,
495
- L: 118,
624
+ F: __dxlog_file4,
625
+ L: 122,
496
626
  S: this,
497
627
  C: (f, a) => f(...a)
498
628
  });
499
629
  return isAuthorized;
500
630
  } catch (err) {
501
631
  import_log.log.catch(err, void 0, {
502
- F: __dxlog_file3,
503
- L: 128,
632
+ F: __dxlog_file4,
633
+ L: 132,
504
634
  S: this,
505
635
  C: (f, a) => f(...a)
506
636
  });
@@ -510,69 +640,22 @@ var AutomergeHost = class {
510
640
  });
511
641
  this._clientNetwork.ready();
512
642
  this._meshNetwork.ready();
513
- {
514
- const listener = ({ handle }) => this._onDocument(handle);
515
- this._repo.on("document", listener);
516
- this._ctx.onDispose(() => {
517
- this._repo.off("document", listener);
518
- });
519
- }
643
+ await this._clientNetwork.whenConnected();
644
+ }
645
+ async close() {
646
+ await this._storage.close?.();
647
+ await this._clientNetwork.close();
648
+ await this._ctx.dispose();
520
649
  }
521
650
  get repo() {
522
651
  return this._repo;
523
652
  }
524
- async _beforeSave(path) {
525
- const id = path[0];
526
- if (this._updatingMetadata.has(id)) {
527
- return this._updatingMetadata.get(id);
528
- }
529
- }
530
- _onDocument(handle) {
531
- const listener = (event) => this._onUpdate(event);
532
- handle.on("change", listener);
533
- this._ctx.onDispose(() => {
534
- handle.off("change", listener);
535
- });
536
- }
537
- _onUpdate(event) {
538
- if (this._metadata == null) {
539
- return;
540
- }
541
- const objectIds = getInlineChanges(event);
542
- if (objectIds.length === 0) {
543
- return;
544
- }
545
- const heads = (0, import_automerge.getHeads)(event.doc);
546
- const lastAvailableHash = heads.join("");
547
- if (!lastAvailableHash) {
548
- return;
549
- }
550
- const encodedIds = objectIds.map((objectId) => import_protocols.idCodec.encode({
551
- documentId: event.handle.documentId,
552
- objectId
553
- }));
554
- const idToLastHash = new Map(encodedIds.map((id) => [
555
- id,
556
- lastAvailableHash
557
- ]));
558
- const markingDirtyPromise = this._metadata.markDirty(idToLastHash).then(() => {
559
- this._updatingMetadata.delete(event.handle.documentId);
560
- }).catch((err) => {
561
- this._ctx.disposed && import_log.log.catch(err, void 0, {
562
- F: __dxlog_file3,
563
- L: 188,
564
- S: this,
565
- C: (f, a) => f(...a)
566
- });
567
- });
568
- this._updatingMetadata.set(event.handle.documentId, markingDirtyPromise);
569
- }
570
653
  _automergeDocs() {
571
654
  return (0, import_util.mapValues)(this._repo.handles, (handle) => ({
572
655
  state: handle.state,
573
656
  hasDoc: !!handle.docSync(),
574
657
  heads: handle.docSync() ? import_automerge.next.getHeads(handle.docSync()) : null,
575
- data: handle.docSync()?.doc && (0, import_util.mapValues)(handle.docSync()?.doc, (value, key) => {
658
+ data: handle.docSync() && (0, import_util.mapValues)(handle.docSync(), (value, key) => {
576
659
  try {
577
660
  switch (key) {
578
661
  case "access":
@@ -592,14 +675,25 @@ var AutomergeHost = class {
592
675
  _automergePeers() {
593
676
  return this._repo.peers;
594
677
  }
595
- async close() {
596
- await this._storage.close();
597
- await this._clientNetwork.close();
598
- await this._ctx.dispose();
599
- }
600
678
  //
601
679
  // Methods for client-services.
602
680
  //
681
+ async flush({ documentIds }) {
682
+ await Promise.all(documentIds?.map((id) => this._repo.find(id).whenReady()) ?? []);
683
+ try {
684
+ await (0, import_async.asyncTimeout)(this._repo.flush(documentIds), 500);
685
+ } catch (err) {
686
+ import_log.log.warn("flush error", {
687
+ documentIds,
688
+ err
689
+ }, {
690
+ F: __dxlog_file4,
691
+ L: 196,
692
+ S: this,
693
+ C: (f, a) => f(...a)
694
+ });
695
+ }
696
+ }
603
697
  syncRepo(request) {
604
698
  return this._clientNetwork.syncRepo(request);
605
699
  }
@@ -620,8 +714,8 @@ var AutomergeHost = class {
620
714
  spaceKey,
621
715
  deviceKey
622
716
  }, {
623
- F: __dxlog_file3,
624
- L: 255,
717
+ F: __dxlog_file4,
718
+ L: 221,
625
719
  S: this,
626
720
  C: (f, a) => f(...a)
627
721
  });
@@ -641,27 +735,14 @@ _ts_decorate([
641
735
  depth: null
642
736
  })
643
737
  ], AutomergeHost.prototype, "_automergePeers", null);
738
+ _ts_decorate([
739
+ import_tracing.trace.span({
740
+ showInBrowserTimeline: true
741
+ })
742
+ ], AutomergeHost.prototype, "flush", null);
644
743
  AutomergeHost = _ts_decorate([
645
744
  import_tracing.trace.resource()
646
745
  ], AutomergeHost);
647
- var getInlineChanges = (event) => {
648
- const inlineChangedObjectIds = /* @__PURE__ */ new Set();
649
- for (const { path } of event.patches) {
650
- if (path.length < 2) {
651
- continue;
652
- }
653
- switch (path[0]) {
654
- case "objects":
655
- if (path.length >= 2) {
656
- inlineChangedObjectIds.add(path[1]);
657
- }
658
- break;
659
- }
660
- }
661
- return [
662
- ...inlineChangedObjectIds
663
- ];
664
- };
665
746
  var getSpaceKeyFromDoc = (doc) => {
666
747
  const rawSpaceKey = doc.access?.spaceKey ?? doc.experimental_spaceKey;
667
748
  if (rawSpaceKey == null) {
@@ -669,7 +750,17 @@ var getSpaceKeyFromDoc = (doc) => {
669
750
  }
670
751
  return String(rawSpaceKey);
671
752
  };
672
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
753
+ function _ts_decorate2(decorators, target, key, desc) {
754
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
755
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
756
+ r = Reflect.decorate(decorators, target, key, desc);
757
+ else
758
+ for (var i = decorators.length - 1; i >= 0; i--)
759
+ if (d = decorators[i])
760
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
761
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
762
+ }
763
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
673
764
  var AutomergeDocumentLoaderImpl = class {
674
765
  constructor(_spaceKey, _repo) {
675
766
  this._spaceKey = _spaceKey;
@@ -677,7 +768,12 @@ var AutomergeDocumentLoaderImpl = class {
677
768
  this._spaceRootDocHandle = null;
678
769
  this._objectDocumentHandles = /* @__PURE__ */ new Map();
679
770
  this._objectsPendingDocumentLoad = /* @__PURE__ */ new Set();
680
- this.onObjectDocumentLoaded = new import_async3.Event();
771
+ this.onObjectDocumentLoaded = new import_async4.Event();
772
+ }
773
+ getAllHandles() {
774
+ return [
775
+ ...new Set(this._objectDocumentHandles.values())
776
+ ];
681
777
  }
682
778
  async loadSpaceRootDocHandle(ctx, spaceState) {
683
779
  if (this._spaceRootDocHandle != null) {
@@ -687,8 +783,8 @@ var AutomergeDocumentLoaderImpl = class {
687
783
  import_log4.log.error("Database opened with no rootUrl", {
688
784
  spaceKey: this._spaceKey
689
785
  }, {
690
- F: __dxlog_file4,
691
- L: 60,
786
+ F: __dxlog_file5,
787
+ L: 69,
692
788
  S: this,
693
789
  C: (f, a) => f(...a)
694
790
  });
@@ -697,8 +793,8 @@ var AutomergeDocumentLoaderImpl = class {
697
793
  const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
698
794
  const doc = existingDocHandle.docSync();
699
795
  (0, import_invariant3.invariant)(doc, void 0, {
700
- F: __dxlog_file4,
701
- L: 65,
796
+ F: __dxlog_file5,
797
+ L: 74,
702
798
  S: this,
703
799
  A: [
704
800
  "doc",
@@ -713,8 +809,8 @@ var AutomergeDocumentLoaderImpl = class {
713
809
  }
714
810
  loadObjectDocument(objectId) {
715
811
  (0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
716
- F: __dxlog_file4,
717
- L: 74,
812
+ F: __dxlog_file5,
813
+ L: 83,
718
814
  S: this,
719
815
  A: [
720
816
  "this._spaceRootDocHandle",
@@ -726,8 +822,8 @@ var AutomergeDocumentLoaderImpl = class {
726
822
  }
727
823
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
728
824
  (0, import_invariant3.invariant)(spaceRootDoc, void 0, {
729
- F: __dxlog_file4,
730
- L: 79,
825
+ F: __dxlog_file5,
826
+ L: 88,
731
827
  S: this,
732
828
  A: [
733
829
  "spaceRootDoc",
@@ -740,8 +836,8 @@ var AutomergeDocumentLoaderImpl = class {
740
836
  import_log4.log.info("loading delayed until object links are initialized", {
741
837
  objectId
742
838
  }, {
743
- F: __dxlog_file4,
744
- L: 83,
839
+ F: __dxlog_file5,
840
+ L: 92,
745
841
  S: this,
746
842
  C: (f, a) => f(...a)
747
843
  });
@@ -761,8 +857,8 @@ var AutomergeDocumentLoaderImpl = class {
761
857
  }
762
858
  getSpaceRootDocHandle() {
763
859
  (0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
764
- F: __dxlog_file4,
765
- L: 101,
860
+ F: __dxlog_file5,
861
+ L: 110,
766
862
  S: this,
767
863
  A: [
768
864
  "this._spaceRootDocHandle",
@@ -773,8 +869,8 @@ var AutomergeDocumentLoaderImpl = class {
773
869
  }
774
870
  createDocumentForObject(objectId) {
775
871
  (0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
776
- F: __dxlog_file4,
777
- L: 106,
872
+ F: __dxlog_file5,
873
+ L: 115,
778
874
  S: this,
779
875
  A: [
780
876
  "this._spaceRootDocHandle",
@@ -816,8 +912,8 @@ var AutomergeDocumentLoaderImpl = class {
816
912
  ...logMeta,
817
913
  actualDocumentUrl: objectDocumentHandle.url
818
914
  }, {
819
- F: __dxlog_file4,
820
- L: 136,
915
+ F: __dxlog_file5,
916
+ L: 145,
821
917
  S: this,
822
918
  C: (f, a) => f(...a)
823
919
  });
@@ -825,8 +921,8 @@ var AutomergeDocumentLoaderImpl = class {
825
921
  }
826
922
  if (objectDocumentHandle?.url === automergeUrl) {
827
923
  import_log4.log.warn("object document was already loaded", logMeta, {
828
- F: __dxlog_file4,
829
- L: 143,
924
+ F: __dxlog_file5,
925
+ L: 152,
830
926
  S: this,
831
927
  C: (f, a) => f(...a)
832
928
  });
@@ -834,8 +930,8 @@ var AutomergeDocumentLoaderImpl = class {
834
930
  }
835
931
  const handle = this._repo.find(automergeUrl);
836
932
  import_log4.log.debug("document loading triggered", logMeta, {
837
- F: __dxlog_file4,
838
- L: 147,
933
+ F: __dxlog_file5,
934
+ L: 156,
839
935
  S: this,
840
936
  C: (f, a) => f(...a)
841
937
  });
@@ -848,7 +944,7 @@ var AutomergeDocumentLoaderImpl = class {
848
944
  while (true) {
849
945
  try {
850
946
  await (0, import_debug.warnAfterTimeout)(5e3, "Automerge root doc load timeout (AutomergeDb)", async () => {
851
- await (0, import_context2.cancelWithContext)(ctx, docHandle.whenReady());
947
+ await (0, import_context3.cancelWithContext)(ctx, docHandle.whenReady());
852
948
  });
853
949
  break;
854
950
  } catch (err) {
@@ -857,8 +953,8 @@ var AutomergeDocumentLoaderImpl = class {
857
953
  id: docHandle.documentId,
858
954
  state: docHandle.state
859
955
  }, {
860
- F: __dxlog_file4,
861
- L: 163,
956
+ F: __dxlog_file5,
957
+ L: 172,
862
958
  S: this,
863
959
  C: (f, a) => f(...a)
864
960
  });
@@ -899,8 +995,8 @@ var AutomergeDocumentLoaderImpl = class {
899
995
  };
900
996
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
901
997
  import_log4.log.info("document loaded after all listeners were removed", logMeta, {
902
- F: __dxlog_file4,
903
- L: 199,
998
+ F: __dxlog_file5,
999
+ L: 208,
904
1000
  S: this,
905
1001
  C: (f, a) => f(...a)
906
1002
  });
@@ -909,8 +1005,8 @@ var AutomergeDocumentLoaderImpl = class {
909
1005
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
910
1006
  if (objectDocHandle?.url !== handle.url) {
911
1007
  import_log4.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
912
- F: __dxlog_file4,
913
- L: 204,
1008
+ F: __dxlog_file5,
1009
+ L: 213,
914
1010
  S: this,
915
1011
  C: (f, a) => f(...a)
916
1012
  });
@@ -928,8 +1024,8 @@ var AutomergeDocumentLoaderImpl = class {
928
1024
  retryLoading: shouldRetryLoading,
929
1025
  err
930
1026
  }, {
931
- F: __dxlog_file4,
932
- L: 210,
1027
+ F: __dxlog_file5,
1028
+ L: 219,
933
1029
  S: this,
934
1030
  C: (f, a) => f(...a)
935
1031
  });
@@ -939,6 +1035,24 @@ var AutomergeDocumentLoaderImpl = class {
939
1035
  }
940
1036
  }
941
1037
  };
1038
+ _ts_decorate2([
1039
+ import_tracing2.trace.span({
1040
+ showInBrowserTimeline: true
1041
+ })
1042
+ ], AutomergeDocumentLoaderImpl.prototype, "loadSpaceRootDocHandle", null);
1043
+ AutomergeDocumentLoaderImpl = _ts_decorate2([
1044
+ import_tracing2.trace.resource()
1045
+ ], AutomergeDocumentLoaderImpl);
1046
+ var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
1047
+ var encodeReference = (reference) => ({
1048
+ "@type": REFERENCE_TYPE_TAG,
1049
+ // NOTE: Automerge do not support undefined values, so we need to use null instead.
1050
+ itemId: reference.itemId ?? null,
1051
+ protocol: reference.protocol ?? null,
1052
+ host: reference.host ?? null
1053
+ });
1054
+ var decodeReference = (value) => new import_echo_schema.Reference(value.itemId, value.protocol ?? void 0, value.host ?? void 0);
1055
+ var isEncodedReferenceObject = (value) => typeof value === "object" && value !== null && value["@type"] === REFERENCE_TYPE_TAG;
942
1056
  // Annotate the CommonJS export names for ESM import in node:
943
1057
  0 && (module.exports = {
944
1058
  AuthExtension,
@@ -947,12 +1061,14 @@ var AutomergeDocumentLoaderImpl = class {
947
1061
  AutomergeHost,
948
1062
  AutomergeStorageAdapter,
949
1063
  DataServiceImpl,
1064
+ LevelDBStorageAdapter,
950
1065
  LocalHostNetworkAdapter,
951
1066
  MOCK_AUTH_PROVIDER,
952
1067
  MOCK_AUTH_VERIFIER,
953
1068
  MeshNetworkAdapter,
954
1069
  MetadataStore,
955
1070
  Pipeline,
1071
+ REFERENCE_TYPE_TAG,
956
1072
  SnapshotManager,
957
1073
  SnapshotStore,
958
1074
  Space,
@@ -962,7 +1078,12 @@ var AutomergeDocumentLoaderImpl = class {
962
1078
  TimeframeClock,
963
1079
  codec,
964
1080
  createMappedFeedWriter,
1081
+ decodeReference,
1082
+ encodeReference,
1083
+ encodingOptions,
965
1084
  getSpaceKeyFromDoc,
1085
+ hasInvitationExpired,
1086
+ isEncodedReferenceObject,
966
1087
  mapFeedIndexesToTimeframe,
967
1088
  mapTimeframeToFeedIndexes,
968
1089
  startAfter,