@dxos/echo-pipeline 0.5.1-main.a94bc56 → 0.5.1-main.ac072cc
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.
- package/dist/lib/browser/{chunk-KMWJLYEQ.mjs → chunk-RESTOZPT.mjs} +17 -17
- package/dist/lib/browser/{chunk-KMWJLYEQ.mjs.map → chunk-RESTOZPT.mjs.map} +2 -2
- package/dist/lib/browser/index.mjs +402 -149
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -8
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-YZA42CKA.cjs → chunk-D25ZFWEF.cjs} +20 -20
- package/dist/lib/node/{chunk-YZA42CKA.cjs.map → chunk-D25ZFWEF.cjs.map} +2 -2
- package/dist/lib/node/index.cjs +412 -166
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +13 -18
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/automerge/automerge-doc-loader.d.ts +1 -1
- package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -1
- package/dist/types/src/automerge/automerge-host.d.ts +14 -5
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-network-adapter.d.ts +26 -0
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -0
- package/dist/types/src/automerge/echo-replicator.d.ts +43 -0
- package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -0
- package/dist/types/src/automerge/index.d.ts +1 -2
- package/dist/types/src/automerge/index.d.ts.map +1 -1
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts +1 -1
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/migrations.d.ts +1 -1
- package/dist/types/src/automerge/migrations.d.ts.map +1 -1
- package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +0 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/package.json +33 -30
- package/src/automerge/automerge-doc-loader.test.ts +1 -1
- package/src/automerge/automerge-doc-loader.ts +4 -3
- package/src/automerge/automerge-host.test.ts +11 -3
- package/src/automerge/automerge-host.ts +62 -10
- package/src/automerge/automerge-repo.test.ts +1 -1
- package/src/automerge/echo-network-adapter.ts +155 -0
- package/src/automerge/echo-replicator.ts +56 -0
- package/src/automerge/index.ts +1 -2
- package/src/automerge/leveldb-storage-adapter.ts +1 -2
- package/src/automerge/migrations.ts +1 -1
- package/src/automerge/storage-adapter.test.ts +1 -1
- package/src/pipeline/pipeline.ts +1 -0
- package/src/testing/index.ts +0 -1
- package/dist/types/src/automerge/level.test.d.ts +0 -2
- package/dist/types/src/automerge/level.test.d.ts.map +0 -1
- package/dist/types/src/automerge/reference.d.ts +0 -15
- package/dist/types/src/automerge/reference.d.ts.map +0 -1
- package/dist/types/src/automerge/types.d.ts +0 -73
- package/dist/types/src/automerge/types.d.ts.map +0 -1
- package/dist/types/src/testing/level.d.ts +0 -3
- package/dist/types/src/testing/level.d.ts.map +0 -1
- package/src/automerge/level.test.ts +0 -114
- package/src/automerge/reference.ts +0 -31
- package/src/automerge/types.ts +0 -86
- package/src/testing/level.ts +0 -12
package/dist/lib/node/index.cjs
CHANGED
|
@@ -18,42 +18,38 @@ 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: () =>
|
|
22
|
-
AuthStatus: () =>
|
|
21
|
+
AuthExtension: () => import_chunk_D25ZFWEF.AuthExtension,
|
|
22
|
+
AuthStatus: () => import_chunk_D25ZFWEF.AuthStatus,
|
|
23
23
|
AutomergeDocumentLoaderImpl: () => AutomergeDocumentLoaderImpl,
|
|
24
24
|
AutomergeHost: () => AutomergeHost,
|
|
25
25
|
AutomergeStorageAdapter: () => AutomergeStorageAdapter,
|
|
26
|
-
DataServiceImpl: () =>
|
|
26
|
+
DataServiceImpl: () => import_chunk_D25ZFWEF.DataServiceImpl,
|
|
27
27
|
LevelDBStorageAdapter: () => LevelDBStorageAdapter,
|
|
28
28
|
LocalHostNetworkAdapter: () => LocalHostNetworkAdapter,
|
|
29
|
-
MOCK_AUTH_PROVIDER: () =>
|
|
30
|
-
MOCK_AUTH_VERIFIER: () =>
|
|
29
|
+
MOCK_AUTH_PROVIDER: () => import_chunk_D25ZFWEF.MOCK_AUTH_PROVIDER,
|
|
30
|
+
MOCK_AUTH_VERIFIER: () => import_chunk_D25ZFWEF.MOCK_AUTH_VERIFIER,
|
|
31
31
|
MeshNetworkAdapter: () => MeshNetworkAdapter,
|
|
32
|
-
MetadataStore: () =>
|
|
33
|
-
Pipeline: () =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
createMappedFeedWriter: () => import_chunk_YZA42CKA.createMappedFeedWriter,
|
|
44
|
-
decodeReference: () => decodeReference,
|
|
45
|
-
encodeReference: () => encodeReference,
|
|
32
|
+
MetadataStore: () => import_chunk_D25ZFWEF.MetadataStore,
|
|
33
|
+
Pipeline: () => import_chunk_D25ZFWEF.Pipeline,
|
|
34
|
+
SnapshotManager: () => import_chunk_D25ZFWEF.SnapshotManager,
|
|
35
|
+
SnapshotStore: () => import_chunk_D25ZFWEF.SnapshotStore,
|
|
36
|
+
Space: () => import_chunk_D25ZFWEF.Space,
|
|
37
|
+
SpaceManager: () => import_chunk_D25ZFWEF.SpaceManager,
|
|
38
|
+
SpaceProtocol: () => import_chunk_D25ZFWEF.SpaceProtocol,
|
|
39
|
+
SpaceProtocolSession: () => import_chunk_D25ZFWEF.SpaceProtocolSession,
|
|
40
|
+
TimeframeClock: () => import_chunk_D25ZFWEF.TimeframeClock,
|
|
41
|
+
codec: () => import_chunk_D25ZFWEF.codec,
|
|
42
|
+
createMappedFeedWriter: () => import_chunk_D25ZFWEF.createMappedFeedWriter,
|
|
46
43
|
encodingOptions: () => encodingOptions,
|
|
47
44
|
getSpaceKeyFromDoc: () => getSpaceKeyFromDoc,
|
|
48
|
-
hasInvitationExpired: () =>
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
valueEncoding: () => import_chunk_YZA42CKA.valueEncoding
|
|
45
|
+
hasInvitationExpired: () => import_chunk_D25ZFWEF.hasInvitationExpired,
|
|
46
|
+
mapFeedIndexesToTimeframe: () => import_chunk_D25ZFWEF.mapFeedIndexesToTimeframe,
|
|
47
|
+
mapTimeframeToFeedIndexes: () => import_chunk_D25ZFWEF.mapTimeframeToFeedIndexes,
|
|
48
|
+
startAfter: () => import_chunk_D25ZFWEF.startAfter,
|
|
49
|
+
valueEncoding: () => import_chunk_D25ZFWEF.valueEncoding
|
|
54
50
|
});
|
|
55
51
|
module.exports = __toCommonJS(node_exports);
|
|
56
|
-
var
|
|
52
|
+
var import_chunk_D25ZFWEF = require("./chunk-D25ZFWEF.cjs");
|
|
57
53
|
var import_async = require("@dxos/async");
|
|
58
54
|
var import_automerge = require("@dxos/automerge/automerge");
|
|
59
55
|
var import_automerge_repo = require("@dxos/automerge/automerge-repo");
|
|
@@ -61,37 +57,253 @@ var import_context = require("@dxos/context");
|
|
|
61
57
|
var import_invariant = require("@dxos/invariant");
|
|
62
58
|
var import_keys = require("@dxos/keys");
|
|
63
59
|
var import_log = require("@dxos/log");
|
|
60
|
+
var import_protocols = require("@dxos/protocols");
|
|
64
61
|
var import_tracing = require("@dxos/tracing");
|
|
65
62
|
var import_util = require("@dxos/util");
|
|
66
|
-
var import_context2 = require("@dxos/context");
|
|
67
63
|
var import_async2 = require("@dxos/async");
|
|
68
64
|
var import_automerge_repo2 = require("@dxos/automerge/automerge-repo");
|
|
69
|
-
var
|
|
65
|
+
var import_context2 = require("@dxos/context");
|
|
70
66
|
var import_invariant2 = require("@dxos/invariant");
|
|
67
|
+
var import_log2 = require("@dxos/log");
|
|
68
|
+
var import_context3 = require("@dxos/context");
|
|
71
69
|
var import_async3 = require("@dxos/async");
|
|
72
70
|
var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
|
|
71
|
+
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
73
72
|
var import_invariant3 = require("@dxos/invariant");
|
|
74
|
-
var
|
|
73
|
+
var import_async4 = require("@dxos/async");
|
|
74
|
+
var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
|
|
75
|
+
var import_invariant4 = require("@dxos/invariant");
|
|
76
|
+
var import_log3 = require("@dxos/log");
|
|
75
77
|
var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
|
|
76
78
|
var import_automerge_repo_storage_indexeddb = require("@dxos/automerge/automerge-repo-storage-indexeddb");
|
|
77
|
-
var
|
|
79
|
+
var import_log4 = require("@dxos/log");
|
|
78
80
|
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
79
81
|
var import_util2 = require("@dxos/util");
|
|
80
|
-
var
|
|
81
|
-
var
|
|
82
|
+
var import_async5 = require("@dxos/async");
|
|
83
|
+
var import_context4 = require("@dxos/context");
|
|
82
84
|
var import_debug = require("@dxos/debug");
|
|
83
|
-
var
|
|
84
|
-
var
|
|
85
|
+
var import_invariant5 = require("@dxos/invariant");
|
|
86
|
+
var import_log5 = require("@dxos/log");
|
|
85
87
|
var import_tracing2 = require("@dxos/tracing");
|
|
86
|
-
|
|
87
|
-
var
|
|
88
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
89
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
90
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
91
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
92
|
+
else
|
|
93
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
94
|
+
if (d = decorators[i])
|
|
95
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
96
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
97
|
+
}
|
|
98
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/echo-network-adapter.ts";
|
|
99
|
+
var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
100
|
+
constructor() {
|
|
101
|
+
super(...arguments);
|
|
102
|
+
this._replicators = /* @__PURE__ */ new Set();
|
|
103
|
+
this._connections = /* @__PURE__ */ new Map();
|
|
104
|
+
this._lifecycleState = import_context2.LifecycleState.CLOSED;
|
|
105
|
+
this._connected = new import_async2.Trigger();
|
|
106
|
+
}
|
|
107
|
+
connect(peerId, peerMetadata) {
|
|
108
|
+
this.peerId = peerId;
|
|
109
|
+
this.peerMetadata = peerMetadata;
|
|
110
|
+
this._connected.wake();
|
|
111
|
+
}
|
|
112
|
+
send(message) {
|
|
113
|
+
const connectionEntry = this._connections.get(message.targetId);
|
|
114
|
+
if (!connectionEntry) {
|
|
115
|
+
throw new Error("Connection not found.");
|
|
116
|
+
}
|
|
117
|
+
connectionEntry.writer.write(message).catch((err) => {
|
|
118
|
+
if (connectionEntry.isOpen) {
|
|
119
|
+
import_log2.log.catch(err, void 0, {
|
|
120
|
+
F: __dxlog_file,
|
|
121
|
+
L: 40,
|
|
122
|
+
S: this,
|
|
123
|
+
C: (f, a) => f(...a)
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
disconnect() {
|
|
129
|
+
}
|
|
130
|
+
async open() {
|
|
131
|
+
(0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.CLOSED, void 0, {
|
|
132
|
+
F: __dxlog_file,
|
|
133
|
+
L: 51,
|
|
134
|
+
S: this,
|
|
135
|
+
A: [
|
|
136
|
+
"this._lifecycleState === LifecycleState.CLOSED",
|
|
137
|
+
""
|
|
138
|
+
]
|
|
139
|
+
});
|
|
140
|
+
this._lifecycleState = import_context2.LifecycleState.OPEN;
|
|
141
|
+
this.emit("ready", {
|
|
142
|
+
network: this
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async close() {
|
|
146
|
+
(0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
147
|
+
F: __dxlog_file,
|
|
148
|
+
L: 61,
|
|
149
|
+
S: this,
|
|
150
|
+
A: [
|
|
151
|
+
"this._lifecycleState === LifecycleState.OPEN",
|
|
152
|
+
""
|
|
153
|
+
]
|
|
154
|
+
});
|
|
155
|
+
for (const replicator of this._replicators) {
|
|
156
|
+
await replicator.disconnect();
|
|
157
|
+
}
|
|
158
|
+
this._replicators.clear();
|
|
159
|
+
this._lifecycleState = import_context2.LifecycleState.CLOSED;
|
|
160
|
+
}
|
|
161
|
+
async whenConnected() {
|
|
162
|
+
await this._connected.wait({
|
|
163
|
+
timeout: 1e4
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
async addReplicator(replicator) {
|
|
167
|
+
(0, import_invariant2.invariant)(this.peerId, void 0, {
|
|
168
|
+
F: __dxlog_file,
|
|
169
|
+
L: 77,
|
|
170
|
+
S: this,
|
|
171
|
+
A: [
|
|
172
|
+
"this.peerId",
|
|
173
|
+
""
|
|
174
|
+
]
|
|
175
|
+
});
|
|
176
|
+
(0, import_invariant2.invariant)(!this._replicators.has(replicator), void 0, {
|
|
177
|
+
F: __dxlog_file,
|
|
178
|
+
L: 78,
|
|
179
|
+
S: this,
|
|
180
|
+
A: [
|
|
181
|
+
"!this._replicators.has(replicator)",
|
|
182
|
+
""
|
|
183
|
+
]
|
|
184
|
+
});
|
|
185
|
+
await replicator.connect({
|
|
186
|
+
peerId: this.peerId,
|
|
187
|
+
onConnectionOpen: this._onConnectionOpen.bind(this),
|
|
188
|
+
onConnectionClosed: this._onConnectionClosed.bind(this)
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
async removeReplicator(replicator) {
|
|
192
|
+
(0, import_invariant2.invariant)(this._replicators.has(replicator), void 0, {
|
|
193
|
+
F: __dxlog_file,
|
|
194
|
+
L: 89,
|
|
195
|
+
S: this,
|
|
196
|
+
A: [
|
|
197
|
+
"this._replicators.has(replicator)",
|
|
198
|
+
""
|
|
199
|
+
]
|
|
200
|
+
});
|
|
201
|
+
await replicator.disconnect();
|
|
202
|
+
}
|
|
203
|
+
async shouldAdvertize(peerId, params) {
|
|
204
|
+
const connection = this._connections.get(peerId);
|
|
205
|
+
if (!connection) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
return connection.connection.shouldAdvertize(params);
|
|
209
|
+
}
|
|
210
|
+
_onConnectionOpen(connection) {
|
|
211
|
+
(0, import_invariant2.invariant)(!this._connections.has(connection.peerId), void 0, {
|
|
212
|
+
F: __dxlog_file,
|
|
213
|
+
L: 103,
|
|
214
|
+
S: this,
|
|
215
|
+
A: [
|
|
216
|
+
"!this._connections.has(connection.peerId as PeerId)",
|
|
217
|
+
""
|
|
218
|
+
]
|
|
219
|
+
});
|
|
220
|
+
const reader = connection.readable.getReader();
|
|
221
|
+
const writer = connection.writable.getWriter();
|
|
222
|
+
const connectionEntry = {
|
|
223
|
+
connection,
|
|
224
|
+
reader,
|
|
225
|
+
writer,
|
|
226
|
+
isOpen: true
|
|
227
|
+
};
|
|
228
|
+
this._connections.set(connection.peerId, connectionEntry);
|
|
229
|
+
queueMicrotask(async () => {
|
|
230
|
+
try {
|
|
231
|
+
while (true) {
|
|
232
|
+
const { done, value } = await reader.read();
|
|
233
|
+
if (done) {
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
this.emit("message", value);
|
|
237
|
+
}
|
|
238
|
+
} catch (err) {
|
|
239
|
+
if (connectionEntry.isOpen) {
|
|
240
|
+
import_log2.log.catch(err, void 0, {
|
|
241
|
+
F: __dxlog_file,
|
|
242
|
+
L: 122,
|
|
243
|
+
S: this,
|
|
244
|
+
C: (f, a) => f(...a)
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
this.emit("peer-candidate", {
|
|
250
|
+
peerId: connection.peerId,
|
|
251
|
+
peerMetadata: {
|
|
252
|
+
// TODO(dmaretskyi): Refactor this.
|
|
253
|
+
dxos_peerSource: "EchoNetworkAdapter"
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
_onConnectionClosed(connection) {
|
|
258
|
+
const entry = this._connections.get(connection.peerId);
|
|
259
|
+
(0, import_invariant2.invariant)(entry, void 0, {
|
|
260
|
+
F: __dxlog_file,
|
|
261
|
+
L: 138,
|
|
262
|
+
S: this,
|
|
263
|
+
A: [
|
|
264
|
+
"entry",
|
|
265
|
+
""
|
|
266
|
+
]
|
|
267
|
+
});
|
|
268
|
+
entry.isOpen = false;
|
|
269
|
+
this.emit("peer-disconnected", {
|
|
270
|
+
peerId: connection.peerId
|
|
271
|
+
});
|
|
272
|
+
void entry.reader.cancel().catch((err) => import_log2.log.catch(err, void 0, {
|
|
273
|
+
F: __dxlog_file,
|
|
274
|
+
L: 143,
|
|
275
|
+
S: this,
|
|
276
|
+
C: (f, a) => f(...a)
|
|
277
|
+
}));
|
|
278
|
+
void entry.writer.abort().catch((err) => import_log2.log.catch(err, void 0, {
|
|
279
|
+
F: __dxlog_file,
|
|
280
|
+
L: 144,
|
|
281
|
+
S: this,
|
|
282
|
+
C: (f, a) => f(...a)
|
|
283
|
+
}));
|
|
284
|
+
this._connections.delete(connection.peerId);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
_ts_decorate([
|
|
288
|
+
import_async2.synchronized
|
|
289
|
+
], EchoNetworkAdapter.prototype, "open", null);
|
|
290
|
+
_ts_decorate([
|
|
291
|
+
import_async2.synchronized
|
|
292
|
+
], EchoNetworkAdapter.prototype, "close", null);
|
|
293
|
+
_ts_decorate([
|
|
294
|
+
import_async2.synchronized
|
|
295
|
+
], EchoNetworkAdapter.prototype, "addReplicator", null);
|
|
296
|
+
_ts_decorate([
|
|
297
|
+
import_async2.synchronized
|
|
298
|
+
], EchoNetworkAdapter.prototype, "removeReplicator", null);
|
|
299
|
+
var LevelDBStorageAdapter = class extends import_context3.Resource {
|
|
88
300
|
constructor(_params) {
|
|
89
301
|
super();
|
|
90
302
|
this._params = _params;
|
|
91
303
|
}
|
|
92
304
|
async load(keyArray) {
|
|
93
305
|
try {
|
|
94
|
-
if (this._lifecycleState !==
|
|
306
|
+
if (this._lifecycleState !== import_context3.LifecycleState.OPEN) {
|
|
95
307
|
return void 0;
|
|
96
308
|
}
|
|
97
309
|
return await this._params.db.get(keyArray, {
|
|
@@ -105,7 +317,7 @@ var LevelDBStorageAdapter = class extends import_context2.Resource {
|
|
|
105
317
|
}
|
|
106
318
|
}
|
|
107
319
|
async save(keyArray, binary) {
|
|
108
|
-
if (this._lifecycleState !==
|
|
320
|
+
if (this._lifecycleState !== import_context3.LifecycleState.OPEN) {
|
|
109
321
|
return void 0;
|
|
110
322
|
}
|
|
111
323
|
const batch = this._params.db.batch();
|
|
@@ -120,7 +332,7 @@ var LevelDBStorageAdapter = class extends import_context2.Resource {
|
|
|
120
332
|
await this._params.callbacks?.afterSave?.(keyArray);
|
|
121
333
|
}
|
|
122
334
|
async remove(keyArray) {
|
|
123
|
-
if (this._lifecycleState !==
|
|
335
|
+
if (this._lifecycleState !== import_context3.LifecycleState.OPEN) {
|
|
124
336
|
return void 0;
|
|
125
337
|
}
|
|
126
338
|
await this._params.db.del(keyArray, {
|
|
@@ -128,7 +340,7 @@ var LevelDBStorageAdapter = class extends import_context2.Resource {
|
|
|
128
340
|
});
|
|
129
341
|
}
|
|
130
342
|
async loadRange(keyPrefix) {
|
|
131
|
-
if (this._lifecycleState !==
|
|
343
|
+
if (this._lifecycleState !== import_context3.LifecycleState.OPEN) {
|
|
132
344
|
return [];
|
|
133
345
|
}
|
|
134
346
|
const result = [];
|
|
@@ -148,7 +360,7 @@ var LevelDBStorageAdapter = class extends import_context2.Resource {
|
|
|
148
360
|
return result;
|
|
149
361
|
}
|
|
150
362
|
async removeRange(keyPrefix) {
|
|
151
|
-
if (this._lifecycleState !==
|
|
363
|
+
if (this._lifecycleState !== import_context3.LifecycleState.OPEN) {
|
|
152
364
|
return void 0;
|
|
153
365
|
}
|
|
154
366
|
const batch = this._params.db.batch();
|
|
@@ -177,12 +389,12 @@ var encodingOptions = {
|
|
|
177
389
|
valueEncoding: "buffer"
|
|
178
390
|
};
|
|
179
391
|
var isLevelDbNotFoundError = (err) => err.code === "LEVEL_NOT_FOUND";
|
|
180
|
-
var
|
|
181
|
-
var LocalHostNetworkAdapter = class extends
|
|
392
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts";
|
|
393
|
+
var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
182
394
|
constructor() {
|
|
183
395
|
super(...arguments);
|
|
184
396
|
this._peers = /* @__PURE__ */ new Map();
|
|
185
|
-
this._connected = new
|
|
397
|
+
this._connected = new import_async3.Trigger();
|
|
186
398
|
this._isConnected = false;
|
|
187
399
|
}
|
|
188
400
|
/**
|
|
@@ -205,8 +417,8 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
205
417
|
}
|
|
206
418
|
send(message) {
|
|
207
419
|
const peer = this._peers.get(message.targetId);
|
|
208
|
-
(0,
|
|
209
|
-
F:
|
|
420
|
+
(0, import_invariant3.invariant)(peer, "Peer not found.", {
|
|
421
|
+
F: __dxlog_file2,
|
|
210
422
|
L: 51,
|
|
211
423
|
S: this,
|
|
212
424
|
A: [
|
|
@@ -230,8 +442,8 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
230
442
|
syncRepo({ id, syncMessage }) {
|
|
231
443
|
const peerId = this._getPeerId(id);
|
|
232
444
|
return new import_codec_protobuf.Stream(({ next, close }) => {
|
|
233
|
-
(0,
|
|
234
|
-
F:
|
|
445
|
+
(0, import_invariant3.invariant)(!this._peers.has(peerId), "Peer already connected.", {
|
|
446
|
+
F: __dxlog_file2,
|
|
235
447
|
L: 73,
|
|
236
448
|
S: this,
|
|
237
449
|
A: [
|
|
@@ -243,7 +455,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
243
455
|
connected: true,
|
|
244
456
|
send: (message) => {
|
|
245
457
|
next({
|
|
246
|
-
syncMessage:
|
|
458
|
+
syncMessage: import_automerge_repo3.cbor.encode(message)
|
|
247
459
|
});
|
|
248
460
|
},
|
|
249
461
|
disconnect: () => {
|
|
@@ -254,8 +466,8 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
254
466
|
});
|
|
255
467
|
}
|
|
256
468
|
});
|
|
257
|
-
(0,
|
|
258
|
-
F:
|
|
469
|
+
(0, import_invariant3.invariant)(this._isConnected, void 0, {
|
|
470
|
+
F: __dxlog_file2,
|
|
259
471
|
L: 90,
|
|
260
472
|
S: this,
|
|
261
473
|
A: [
|
|
@@ -270,8 +482,8 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
270
482
|
});
|
|
271
483
|
}
|
|
272
484
|
async sendSyncMessage({ id, syncMessage }) {
|
|
273
|
-
(0,
|
|
274
|
-
F:
|
|
485
|
+
(0, import_invariant3.invariant)(this._isConnected, void 0, {
|
|
486
|
+
F: __dxlog_file2,
|
|
275
487
|
L: 99,
|
|
276
488
|
S: this,
|
|
277
489
|
A: [
|
|
@@ -279,12 +491,12 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
279
491
|
""
|
|
280
492
|
]
|
|
281
493
|
});
|
|
282
|
-
const message =
|
|
494
|
+
const message = import_automerge_repo3.cbor.decode(syncMessage);
|
|
283
495
|
this.emit("message", message);
|
|
284
496
|
}
|
|
285
497
|
async getHostInfo() {
|
|
286
|
-
(0,
|
|
287
|
-
F:
|
|
498
|
+
(0, import_invariant3.invariant)(this._isConnected, void 0, {
|
|
499
|
+
F: __dxlog_file2,
|
|
288
500
|
L: 105,
|
|
289
501
|
S: this,
|
|
290
502
|
A: [
|
|
@@ -292,8 +504,8 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
292
504
|
""
|
|
293
505
|
]
|
|
294
506
|
});
|
|
295
|
-
(0,
|
|
296
|
-
F:
|
|
507
|
+
(0, import_invariant3.invariant)(this.peerId, "Peer id not set.", {
|
|
508
|
+
F: __dxlog_file2,
|
|
297
509
|
L: 106,
|
|
298
510
|
S: this,
|
|
299
511
|
A: [
|
|
@@ -309,12 +521,12 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
309
521
|
return id;
|
|
310
522
|
}
|
|
311
523
|
};
|
|
312
|
-
var
|
|
313
|
-
var MeshNetworkAdapter = class extends
|
|
524
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-network-adapter.ts";
|
|
525
|
+
var MeshNetworkAdapter = class extends import_automerge_repo4.NetworkAdapter {
|
|
314
526
|
constructor() {
|
|
315
527
|
super(...arguments);
|
|
316
528
|
this._extensions = /* @__PURE__ */ new Map();
|
|
317
|
-
this._connected = new
|
|
529
|
+
this._connected = new import_async4.Trigger();
|
|
318
530
|
}
|
|
319
531
|
/**
|
|
320
532
|
* Emits `ready` event. That signals to `Repo` that it can start using the adapter.
|
|
@@ -331,8 +543,8 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
331
543
|
send(message) {
|
|
332
544
|
const receiverId = message.targetId;
|
|
333
545
|
const extension = this._extensions.get(receiverId);
|
|
334
|
-
(0,
|
|
335
|
-
F:
|
|
546
|
+
(0, import_invariant4.invariant)(extension, "Extension not found.", {
|
|
547
|
+
F: __dxlog_file3,
|
|
336
548
|
L: 38,
|
|
337
549
|
S: this,
|
|
338
550
|
A: [
|
|
@@ -341,9 +553,9 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
341
553
|
]
|
|
342
554
|
});
|
|
343
555
|
extension.sendSyncMessage({
|
|
344
|
-
payload:
|
|
345
|
-
}).catch((err) =>
|
|
346
|
-
F:
|
|
556
|
+
payload: import_automerge_repo4.cbor.encode(message)
|
|
557
|
+
}).catch((err) => import_log3.log.catch(err, void 0, {
|
|
558
|
+
F: __dxlog_file3,
|
|
347
559
|
L: 39,
|
|
348
560
|
S: this,
|
|
349
561
|
C: (f, a) => f(...a)
|
|
@@ -352,8 +564,8 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
352
564
|
disconnect() {
|
|
353
565
|
}
|
|
354
566
|
createExtension() {
|
|
355
|
-
(0,
|
|
356
|
-
F:
|
|
567
|
+
(0, import_invariant4.invariant)(this.peerId, "Peer id not set.", {
|
|
568
|
+
F: __dxlog_file3,
|
|
357
569
|
L: 47,
|
|
358
570
|
S: this,
|
|
359
571
|
A: [
|
|
@@ -367,12 +579,12 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
367
579
|
}, {
|
|
368
580
|
onStartReplication: async (info, remotePeerId) => {
|
|
369
581
|
await this._connected.wait();
|
|
370
|
-
(0,
|
|
582
|
+
(0, import_log3.log)("onStartReplication", {
|
|
371
583
|
id: info.id,
|
|
372
584
|
thisPeerId: this.peerId,
|
|
373
585
|
remotePeerId: remotePeerId.toHex()
|
|
374
586
|
}, {
|
|
375
|
-
F:
|
|
587
|
+
F: __dxlog_file3,
|
|
376
588
|
L: 70,
|
|
377
589
|
S: this,
|
|
378
590
|
C: (f, a) => f(...a)
|
|
@@ -380,12 +592,12 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
380
592
|
if (!this._extensions.has(info.id)) {
|
|
381
593
|
peerInfo = info;
|
|
382
594
|
this._extensions.set(info.id, extension);
|
|
383
|
-
(0,
|
|
595
|
+
(0, import_log3.log)("peer-candidate", {
|
|
384
596
|
id: info.id,
|
|
385
597
|
thisPeerId: this.peerId,
|
|
386
598
|
remotePeerId: remotePeerId.toHex()
|
|
387
599
|
}, {
|
|
388
|
-
F:
|
|
600
|
+
F: __dxlog_file3,
|
|
389
601
|
L: 76,
|
|
390
602
|
S: this,
|
|
391
603
|
C: (f, a) => f(...a)
|
|
@@ -403,7 +615,7 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
403
615
|
if (!peerInfo) {
|
|
404
616
|
return;
|
|
405
617
|
}
|
|
406
|
-
const message =
|
|
618
|
+
const message = import_automerge_repo4.cbor.decode(payload);
|
|
407
619
|
this.emit("message", message);
|
|
408
620
|
},
|
|
409
621
|
onClose: async () => {
|
|
@@ -492,7 +704,7 @@ var AutomergeStorageAdapter = class {
|
|
|
492
704
|
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
493
705
|
}
|
|
494
706
|
};
|
|
495
|
-
var
|
|
707
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
|
|
496
708
|
var levelMigration = async ({ db, directory }) => {
|
|
497
709
|
const isNewLevel = !await db.iterator({
|
|
498
710
|
...encodingOptions
|
|
@@ -506,10 +718,10 @@ var levelMigration = async ({ db, directory }) => {
|
|
|
506
718
|
return;
|
|
507
719
|
}
|
|
508
720
|
const batch = db.batch();
|
|
509
|
-
|
|
721
|
+
import_log4.log.info("found chunks on old storage adapter", {
|
|
510
722
|
chunks: chunks.length
|
|
511
723
|
}, {
|
|
512
|
-
F:
|
|
724
|
+
F: __dxlog_file4,
|
|
513
725
|
L: 36,
|
|
514
726
|
S: void 0,
|
|
515
727
|
C: (f, a) => f(...a)
|
|
@@ -521,7 +733,7 @@ var levelMigration = async ({ db, directory }) => {
|
|
|
521
733
|
}
|
|
522
734
|
await batch.write();
|
|
523
735
|
};
|
|
524
|
-
function
|
|
736
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
525
737
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
526
738
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
527
739
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -531,15 +743,16 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
531
743
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
532
744
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
533
745
|
}
|
|
534
|
-
var
|
|
746
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
535
747
|
var AutomergeHost = class {
|
|
536
|
-
constructor({ directory, db,
|
|
748
|
+
constructor({ directory, db, indexMetadataStore }) {
|
|
537
749
|
this._ctx = new import_context.Context();
|
|
750
|
+
this._echoNetworkAdapter = new EchoNetworkAdapter();
|
|
538
751
|
this._authorizedDevices = new import_util.ComplexMap(import_keys.PublicKey.hash);
|
|
539
752
|
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
540
753
|
this._directory = directory;
|
|
541
754
|
this._db = db;
|
|
542
|
-
this.
|
|
755
|
+
this._indexMetadataStore = indexMetadataStore;
|
|
543
756
|
}
|
|
544
757
|
async open() {
|
|
545
758
|
this._directory && await levelMigration({
|
|
@@ -548,7 +761,10 @@ var AutomergeHost = class {
|
|
|
548
761
|
});
|
|
549
762
|
this._storage = new LevelDBStorageAdapter({
|
|
550
763
|
db: this._db,
|
|
551
|
-
callbacks:
|
|
764
|
+
callbacks: {
|
|
765
|
+
beforeSave: async (params) => this._beforeSave(params),
|
|
766
|
+
afterSave: async () => this._afterSave()
|
|
767
|
+
}
|
|
552
768
|
});
|
|
553
769
|
await this._storage.open?.();
|
|
554
770
|
this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
|
|
@@ -558,7 +774,8 @@ var AutomergeHost = class {
|
|
|
558
774
|
peerId: this._peerId,
|
|
559
775
|
network: [
|
|
560
776
|
this._clientNetwork,
|
|
561
|
-
this._meshNetwork
|
|
777
|
+
this._meshNetwork,
|
|
778
|
+
this._echoNetworkAdapter
|
|
562
779
|
],
|
|
563
780
|
storage: this._storage,
|
|
564
781
|
// TODO(dmaretskyi): Share based on HALO permissions and space affinity.
|
|
@@ -570,6 +787,12 @@ var AutomergeHost = class {
|
|
|
570
787
|
if (!documentId) {
|
|
571
788
|
return false;
|
|
572
789
|
}
|
|
790
|
+
const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
|
|
791
|
+
if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
|
|
792
|
+
return this._echoNetworkAdapter.shouldAdvertize(peerId, {
|
|
793
|
+
documentId
|
|
794
|
+
});
|
|
795
|
+
}
|
|
573
796
|
const doc = this._repo.handles[documentId]?.docSync();
|
|
574
797
|
if (!doc) {
|
|
575
798
|
const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
|
|
@@ -578,8 +801,8 @@ var AutomergeHost = class {
|
|
|
578
801
|
documentId,
|
|
579
802
|
isRequested
|
|
580
803
|
}, {
|
|
581
|
-
F:
|
|
582
|
-
L:
|
|
804
|
+
F: __dxlog_file5,
|
|
805
|
+
L: 124,
|
|
583
806
|
S: this,
|
|
584
807
|
C: (f, a) => f(...a)
|
|
585
808
|
});
|
|
@@ -592,22 +815,22 @@ var AutomergeHost = class {
|
|
|
592
815
|
peerId,
|
|
593
816
|
documentId
|
|
594
817
|
}, {
|
|
595
|
-
F:
|
|
596
|
-
L:
|
|
818
|
+
F: __dxlog_file5,
|
|
819
|
+
L: 131,
|
|
597
820
|
S: this,
|
|
598
821
|
C: (f, a) => f(...a)
|
|
599
822
|
});
|
|
600
823
|
return false;
|
|
601
824
|
}
|
|
602
825
|
const authorizedDevices = this._authorizedDevices.get(import_keys.PublicKey.from(spaceKey));
|
|
603
|
-
const deviceKeyHex =
|
|
826
|
+
const deviceKeyHex = peerMetadata?.dxos_deviceKey;
|
|
604
827
|
if (!deviceKeyHex) {
|
|
605
828
|
(0, import_log.log)("device key not found for share policy check", {
|
|
606
829
|
peerId,
|
|
607
830
|
documentId
|
|
608
831
|
}, {
|
|
609
|
-
F:
|
|
610
|
-
L:
|
|
832
|
+
F: __dxlog_file5,
|
|
833
|
+
L: 140,
|
|
611
834
|
S: this,
|
|
612
835
|
C: (f, a) => f(...a)
|
|
613
836
|
});
|
|
@@ -623,16 +846,16 @@ var AutomergeHost = class {
|
|
|
623
846
|
spaceKey,
|
|
624
847
|
isAuthorized
|
|
625
848
|
}, {
|
|
626
|
-
F:
|
|
627
|
-
L:
|
|
849
|
+
F: __dxlog_file5,
|
|
850
|
+
L: 146,
|
|
628
851
|
S: this,
|
|
629
852
|
C: (f, a) => f(...a)
|
|
630
853
|
});
|
|
631
854
|
return isAuthorized;
|
|
632
855
|
} catch (err) {
|
|
633
856
|
import_log.log.catch(err, void 0, {
|
|
634
|
-
F:
|
|
635
|
-
L:
|
|
857
|
+
F: __dxlog_file5,
|
|
858
|
+
L: 156,
|
|
636
859
|
S: this,
|
|
637
860
|
C: (f, a) => f(...a)
|
|
638
861
|
});
|
|
@@ -642,16 +865,52 @@ var AutomergeHost = class {
|
|
|
642
865
|
});
|
|
643
866
|
this._clientNetwork.ready();
|
|
644
867
|
this._meshNetwork.ready();
|
|
868
|
+
await this._echoNetworkAdapter.open();
|
|
645
869
|
await this._clientNetwork.whenConnected();
|
|
870
|
+
await this._echoNetworkAdapter.whenConnected();
|
|
646
871
|
}
|
|
647
872
|
async close() {
|
|
648
873
|
await this._storage.close?.();
|
|
649
874
|
await this._clientNetwork.close();
|
|
875
|
+
await this._echoNetworkAdapter.close();
|
|
650
876
|
await this._ctx.dispose();
|
|
651
877
|
}
|
|
652
878
|
get repo() {
|
|
653
879
|
return this._repo;
|
|
654
880
|
}
|
|
881
|
+
async addReplicator(replicator) {
|
|
882
|
+
await this._echoNetworkAdapter.addReplicator(replicator);
|
|
883
|
+
}
|
|
884
|
+
async removeReplicator(replicator) {
|
|
885
|
+
await this._echoNetworkAdapter.removeReplicator(replicator);
|
|
886
|
+
}
|
|
887
|
+
async _beforeSave({ path, batch }) {
|
|
888
|
+
const handle = this._repo.handles[path[0]];
|
|
889
|
+
if (!handle) {
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
const doc = handle.docSync();
|
|
893
|
+
if (!doc) {
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
const lastAvailableHash = (0, import_automerge.getHeads)(doc);
|
|
897
|
+
const objectIds = Object.keys(doc.objects ?? {});
|
|
898
|
+
const encodedIds = objectIds.map((objectId) => import_protocols.idCodec.encode({
|
|
899
|
+
documentId: handle.documentId,
|
|
900
|
+
objectId
|
|
901
|
+
}));
|
|
902
|
+
const idToLastHash = new Map(encodedIds.map((id) => [
|
|
903
|
+
id,
|
|
904
|
+
lastAvailableHash
|
|
905
|
+
]));
|
|
906
|
+
this._indexMetadataStore.markDirty(idToLastHash, batch);
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Called by AutomergeStorageAdapter after levelDB batch commit.
|
|
910
|
+
*/
|
|
911
|
+
async _afterSave() {
|
|
912
|
+
this._indexMetadataStore.notifyMarkedDirty();
|
|
913
|
+
}
|
|
655
914
|
_automergeDocs() {
|
|
656
915
|
return (0, import_util.mapValues)(this._repo.handles, (handle) => ({
|
|
657
916
|
state: handle.state,
|
|
@@ -683,8 +942,8 @@ var AutomergeHost = class {
|
|
|
683
942
|
async flush({ states }) {
|
|
684
943
|
await Promise.all(states?.map(async ({ heads, documentId }) => {
|
|
685
944
|
(0, import_invariant.invariant)(heads, "heads are required for flush", {
|
|
686
|
-
F:
|
|
687
|
-
L:
|
|
945
|
+
F: __dxlog_file5,
|
|
946
|
+
L: 252,
|
|
688
947
|
S: this,
|
|
689
948
|
A: [
|
|
690
949
|
"heads",
|
|
@@ -716,33 +975,33 @@ var AutomergeHost = class {
|
|
|
716
975
|
spaceKey,
|
|
717
976
|
deviceKey
|
|
718
977
|
}, {
|
|
719
|
-
F:
|
|
720
|
-
L:
|
|
978
|
+
F: __dxlog_file5,
|
|
979
|
+
L: 282,
|
|
721
980
|
S: this,
|
|
722
981
|
C: (f, a) => f(...a)
|
|
723
982
|
});
|
|
724
983
|
(0, import_util.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util.ComplexSet(import_keys.PublicKey.hash)).add(deviceKey);
|
|
725
984
|
}
|
|
726
985
|
};
|
|
727
|
-
|
|
986
|
+
_ts_decorate2([
|
|
728
987
|
import_tracing.trace.info()
|
|
729
988
|
], AutomergeHost.prototype, "_peerId", void 0);
|
|
730
|
-
|
|
989
|
+
_ts_decorate2([
|
|
731
990
|
import_tracing.trace.info({
|
|
732
991
|
depth: null
|
|
733
992
|
})
|
|
734
993
|
], AutomergeHost.prototype, "_automergeDocs", null);
|
|
735
|
-
|
|
994
|
+
_ts_decorate2([
|
|
736
995
|
import_tracing.trace.info({
|
|
737
996
|
depth: null
|
|
738
997
|
})
|
|
739
998
|
], AutomergeHost.prototype, "_automergePeers", null);
|
|
740
|
-
|
|
999
|
+
_ts_decorate2([
|
|
741
1000
|
import_tracing.trace.span({
|
|
742
1001
|
showInBrowserTimeline: true
|
|
743
1002
|
})
|
|
744
1003
|
], AutomergeHost.prototype, "flush", null);
|
|
745
|
-
AutomergeHost =
|
|
1004
|
+
AutomergeHost = _ts_decorate2([
|
|
746
1005
|
import_tracing.trace.resource()
|
|
747
1006
|
], AutomergeHost);
|
|
748
1007
|
var getSpaceKeyFromDoc = (doc) => {
|
|
@@ -770,7 +1029,7 @@ var waitForHeads = async (handle, heads) => {
|
|
|
770
1029
|
var changeIsPresentInDoc = (doc, changeHash) => {
|
|
771
1030
|
return !!(0, import_automerge.getBackend)(doc).getChangeByHash(changeHash);
|
|
772
1031
|
};
|
|
773
|
-
function
|
|
1032
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
774
1033
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
775
1034
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
776
1035
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -780,7 +1039,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
780
1039
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
781
1040
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
782
1041
|
}
|
|
783
|
-
var
|
|
1042
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
784
1043
|
var AutomergeDocumentLoaderImpl = class {
|
|
785
1044
|
constructor(_spaceKey, _repo) {
|
|
786
1045
|
this._spaceKey = _spaceKey;
|
|
@@ -788,23 +1047,24 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
788
1047
|
this._spaceRootDocHandle = null;
|
|
789
1048
|
this._objectDocumentHandles = /* @__PURE__ */ new Map();
|
|
790
1049
|
this._objectsPendingDocumentLoad = /* @__PURE__ */ new Set();
|
|
791
|
-
this.onObjectDocumentLoaded = new
|
|
1050
|
+
this.onObjectDocumentLoaded = new import_async5.Event();
|
|
792
1051
|
}
|
|
793
1052
|
getAllHandles() {
|
|
794
|
-
return [
|
|
1053
|
+
return this._spaceRootDocHandle != null ? [
|
|
1054
|
+
this._spaceRootDocHandle,
|
|
795
1055
|
...new Set(this._objectDocumentHandles.values())
|
|
796
|
-
];
|
|
1056
|
+
] : [];
|
|
797
1057
|
}
|
|
798
1058
|
async loadSpaceRootDocHandle(ctx, spaceState) {
|
|
799
1059
|
if (this._spaceRootDocHandle != null) {
|
|
800
1060
|
return;
|
|
801
1061
|
}
|
|
802
1062
|
if (!spaceState.rootUrl) {
|
|
803
|
-
|
|
1063
|
+
import_log5.log.error("Database opened with no rootUrl", {
|
|
804
1064
|
spaceKey: this._spaceKey
|
|
805
1065
|
}, {
|
|
806
|
-
F:
|
|
807
|
-
L:
|
|
1066
|
+
F: __dxlog_file6,
|
|
1067
|
+
L: 70,
|
|
808
1068
|
S: this,
|
|
809
1069
|
C: (f, a) => f(...a)
|
|
810
1070
|
});
|
|
@@ -812,9 +1072,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
812
1072
|
} else {
|
|
813
1073
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
814
1074
|
const doc = existingDocHandle.docSync();
|
|
815
|
-
(0,
|
|
816
|
-
F:
|
|
817
|
-
L:
|
|
1075
|
+
(0, import_invariant5.invariant)(doc, void 0, {
|
|
1076
|
+
F: __dxlog_file6,
|
|
1077
|
+
L: 75,
|
|
818
1078
|
S: this,
|
|
819
1079
|
A: [
|
|
820
1080
|
"doc",
|
|
@@ -834,9 +1094,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
834
1094
|
let hasUrlsToLoad = false;
|
|
835
1095
|
const urlsToLoad = {};
|
|
836
1096
|
for (const objectId of objectIds) {
|
|
837
|
-
(0,
|
|
838
|
-
F:
|
|
839
|
-
L:
|
|
1097
|
+
(0, import_invariant5.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1098
|
+
F: __dxlog_file6,
|
|
1099
|
+
L: 88,
|
|
840
1100
|
S: this,
|
|
841
1101
|
A: [
|
|
842
1102
|
"this._spaceRootDocHandle",
|
|
@@ -847,9 +1107,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
847
1107
|
continue;
|
|
848
1108
|
}
|
|
849
1109
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
850
|
-
(0,
|
|
851
|
-
F:
|
|
852
|
-
L:
|
|
1110
|
+
(0, import_invariant5.invariant)(spaceRootDoc, void 0, {
|
|
1111
|
+
F: __dxlog_file6,
|
|
1112
|
+
L: 93,
|
|
853
1113
|
S: this,
|
|
854
1114
|
A: [
|
|
855
1115
|
"spaceRootDoc",
|
|
@@ -859,11 +1119,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
859
1119
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
860
1120
|
if (documentUrl == null) {
|
|
861
1121
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
862
|
-
|
|
1122
|
+
import_log5.log.info("loading delayed until object links are initialized", {
|
|
863
1123
|
objectId
|
|
864
1124
|
}, {
|
|
865
|
-
F:
|
|
866
|
-
L:
|
|
1125
|
+
F: __dxlog_file6,
|
|
1126
|
+
L: 97,
|
|
867
1127
|
S: this,
|
|
868
1128
|
C: (f, a) => f(...a)
|
|
869
1129
|
});
|
|
@@ -885,9 +1145,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
885
1145
|
linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
|
|
886
1146
|
}
|
|
887
1147
|
getSpaceRootDocHandle() {
|
|
888
|
-
(0,
|
|
889
|
-
F:
|
|
890
|
-
L:
|
|
1148
|
+
(0, import_invariant5.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1149
|
+
F: __dxlog_file6,
|
|
1150
|
+
L: 120,
|
|
891
1151
|
S: this,
|
|
892
1152
|
A: [
|
|
893
1153
|
"this._spaceRootDocHandle",
|
|
@@ -897,9 +1157,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
897
1157
|
return this._spaceRootDocHandle;
|
|
898
1158
|
}
|
|
899
1159
|
createDocumentForObject(objectId) {
|
|
900
|
-
(0,
|
|
901
|
-
F:
|
|
902
|
-
L:
|
|
1160
|
+
(0, import_invariant5.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1161
|
+
F: __dxlog_file6,
|
|
1162
|
+
L: 125,
|
|
903
1163
|
S: this,
|
|
904
1164
|
A: [
|
|
905
1165
|
"this._spaceRootDocHandle",
|
|
@@ -937,30 +1197,30 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
937
1197
|
};
|
|
938
1198
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
939
1199
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
940
|
-
|
|
1200
|
+
import_log5.log.warn("object already inlined in a different document, ignoring the link", {
|
|
941
1201
|
...logMeta,
|
|
942
1202
|
actualDocumentUrl: objectDocumentHandle.url
|
|
943
1203
|
}, {
|
|
944
|
-
F:
|
|
945
|
-
L:
|
|
1204
|
+
F: __dxlog_file6,
|
|
1205
|
+
L: 155,
|
|
946
1206
|
S: this,
|
|
947
1207
|
C: (f, a) => f(...a)
|
|
948
1208
|
});
|
|
949
1209
|
continue;
|
|
950
1210
|
}
|
|
951
1211
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
952
|
-
|
|
953
|
-
F:
|
|
954
|
-
L:
|
|
1212
|
+
import_log5.log.warn("object document was already loaded", logMeta, {
|
|
1213
|
+
F: __dxlog_file6,
|
|
1214
|
+
L: 162,
|
|
955
1215
|
S: this,
|
|
956
1216
|
C: (f, a) => f(...a)
|
|
957
1217
|
});
|
|
958
1218
|
continue;
|
|
959
1219
|
}
|
|
960
1220
|
const handle = this._repo.find(automergeUrl);
|
|
961
|
-
|
|
962
|
-
F:
|
|
963
|
-
L:
|
|
1221
|
+
import_log5.log.debug("document loading triggered", logMeta, {
|
|
1222
|
+
F: __dxlog_file6,
|
|
1223
|
+
L: 166,
|
|
964
1224
|
S: this,
|
|
965
1225
|
C: (f, a) => f(...a)
|
|
966
1226
|
});
|
|
@@ -973,17 +1233,17 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
973
1233
|
while (true) {
|
|
974
1234
|
try {
|
|
975
1235
|
await (0, import_debug.warnAfterTimeout)(5e3, "Automerge root doc load timeout (AutomergeDb)", async () => {
|
|
976
|
-
await (0,
|
|
1236
|
+
await (0, import_context4.cancelWithContext)(ctx, docHandle.whenReady());
|
|
977
1237
|
});
|
|
978
1238
|
break;
|
|
979
1239
|
} catch (err) {
|
|
980
1240
|
if (`${err}`.includes("Timeout")) {
|
|
981
|
-
|
|
1241
|
+
import_log5.log.info("wraparound", {
|
|
982
1242
|
id: docHandle.documentId,
|
|
983
1243
|
state: docHandle.state
|
|
984
1244
|
}, {
|
|
985
|
-
F:
|
|
986
|
-
L:
|
|
1245
|
+
F: __dxlog_file6,
|
|
1246
|
+
L: 182,
|
|
987
1247
|
S: this,
|
|
988
1248
|
C: (f, a) => f(...a)
|
|
989
1249
|
});
|
|
@@ -1023,9 +1283,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1023
1283
|
docUrl: handle.url
|
|
1024
1284
|
};
|
|
1025
1285
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1026
|
-
|
|
1027
|
-
F:
|
|
1028
|
-
L:
|
|
1286
|
+
import_log5.log.info("document loaded after all listeners were removed", logMeta, {
|
|
1287
|
+
F: __dxlog_file6,
|
|
1288
|
+
L: 218,
|
|
1029
1289
|
S: this,
|
|
1030
1290
|
C: (f, a) => f(...a)
|
|
1031
1291
|
});
|
|
@@ -1033,9 +1293,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1033
1293
|
}
|
|
1034
1294
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
1035
1295
|
if (objectDocHandle?.url !== handle.url) {
|
|
1036
|
-
|
|
1037
|
-
F:
|
|
1038
|
-
L:
|
|
1296
|
+
import_log5.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1297
|
+
F: __dxlog_file6,
|
|
1298
|
+
L: 223,
|
|
1039
1299
|
S: this,
|
|
1040
1300
|
C: (f, a) => f(...a)
|
|
1041
1301
|
});
|
|
@@ -1047,14 +1307,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1047
1307
|
});
|
|
1048
1308
|
} catch (err) {
|
|
1049
1309
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1050
|
-
|
|
1310
|
+
import_log5.log.warn("failed to load a document", {
|
|
1051
1311
|
objectId,
|
|
1052
1312
|
automergeUrl: handle.url,
|
|
1053
1313
|
retryLoading: shouldRetryLoading,
|
|
1054
1314
|
err
|
|
1055
1315
|
}, {
|
|
1056
|
-
F:
|
|
1057
|
-
L:
|
|
1316
|
+
F: __dxlog_file6,
|
|
1317
|
+
L: 229,
|
|
1058
1318
|
S: this,
|
|
1059
1319
|
C: (f, a) => f(...a)
|
|
1060
1320
|
});
|
|
@@ -1064,24 +1324,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1064
1324
|
}
|
|
1065
1325
|
}
|
|
1066
1326
|
};
|
|
1067
|
-
|
|
1327
|
+
_ts_decorate3([
|
|
1068
1328
|
import_tracing2.trace.span({
|
|
1069
1329
|
showInBrowserTimeline: true
|
|
1070
1330
|
})
|
|
1071
1331
|
], AutomergeDocumentLoaderImpl.prototype, "loadSpaceRootDocHandle", null);
|
|
1072
|
-
AutomergeDocumentLoaderImpl =
|
|
1332
|
+
AutomergeDocumentLoaderImpl = _ts_decorate3([
|
|
1073
1333
|
import_tracing2.trace.resource()
|
|
1074
1334
|
], AutomergeDocumentLoaderImpl);
|
|
1075
|
-
var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
1076
|
-
var encodeReference = (reference) => ({
|
|
1077
|
-
"@type": REFERENCE_TYPE_TAG,
|
|
1078
|
-
// NOTE: Automerge do not support undefined values, so we need to use null instead.
|
|
1079
|
-
itemId: reference.itemId ?? null,
|
|
1080
|
-
protocol: reference.protocol ?? null,
|
|
1081
|
-
host: reference.host ?? null
|
|
1082
|
-
});
|
|
1083
|
-
var decodeReference = (value) => new import_echo_schema.Reference(value.itemId, value.protocol ?? void 0, value.host ?? void 0);
|
|
1084
|
-
var isEncodedReferenceObject = (value) => typeof value === "object" && value !== null && value["@type"] === REFERENCE_TYPE_TAG;
|
|
1085
1335
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1086
1336
|
0 && (module.exports = {
|
|
1087
1337
|
AuthExtension,
|
|
@@ -1097,7 +1347,6 @@ var isEncodedReferenceObject = (value) => typeof value === "object" && value !==
|
|
|
1097
1347
|
MeshNetworkAdapter,
|
|
1098
1348
|
MetadataStore,
|
|
1099
1349
|
Pipeline,
|
|
1100
|
-
REFERENCE_TYPE_TAG,
|
|
1101
1350
|
SnapshotManager,
|
|
1102
1351
|
SnapshotStore,
|
|
1103
1352
|
Space,
|
|
@@ -1107,12 +1356,9 @@ var isEncodedReferenceObject = (value) => typeof value === "object" && value !==
|
|
|
1107
1356
|
TimeframeClock,
|
|
1108
1357
|
codec,
|
|
1109
1358
|
createMappedFeedWriter,
|
|
1110
|
-
decodeReference,
|
|
1111
|
-
encodeReference,
|
|
1112
1359
|
encodingOptions,
|
|
1113
1360
|
getSpaceKeyFromDoc,
|
|
1114
1361
|
hasInvitationExpired,
|
|
1115
|
-
isEncodedReferenceObject,
|
|
1116
1362
|
mapFeedIndexesToTimeframe,
|
|
1117
1363
|
mapTimeframeToFeedIndexes,
|
|
1118
1364
|
startAfter,
|