@dxos/echo-pipeline 0.5.1-main.4e99b85 → 0.5.1-main.4f405fb
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 +440 -177
- 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 +450 -194
- 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 +3 -3
- 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 +3 -2
- 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 +26 -16
- 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 +2 -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 -82
- 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();
|
|
@@ -169,19 +381,20 @@ var LevelDBStorageAdapter = class extends import_context2.Resource {
|
|
|
169
381
|
};
|
|
170
382
|
var keyEncoder = {
|
|
171
383
|
encode: (key) => Buffer.from(key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-")),
|
|
172
|
-
decode: (key) => Buffer.from(key).toString().split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"))
|
|
384
|
+
decode: (key) => Buffer.from(key).toString().split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%")),
|
|
385
|
+
format: "buffer"
|
|
173
386
|
};
|
|
174
387
|
var encodingOptions = {
|
|
175
388
|
keyEncoding: keyEncoder,
|
|
176
389
|
valueEncoding: "buffer"
|
|
177
390
|
};
|
|
178
391
|
var isLevelDbNotFoundError = (err) => err.code === "LEVEL_NOT_FOUND";
|
|
179
|
-
var
|
|
180
|
-
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 {
|
|
181
394
|
constructor() {
|
|
182
395
|
super(...arguments);
|
|
183
396
|
this._peers = /* @__PURE__ */ new Map();
|
|
184
|
-
this._connected = new
|
|
397
|
+
this._connected = new import_async3.Trigger();
|
|
185
398
|
this._isConnected = false;
|
|
186
399
|
}
|
|
187
400
|
/**
|
|
@@ -204,8 +417,8 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
204
417
|
}
|
|
205
418
|
send(message) {
|
|
206
419
|
const peer = this._peers.get(message.targetId);
|
|
207
|
-
(0,
|
|
208
|
-
F:
|
|
420
|
+
(0, import_invariant3.invariant)(peer, "Peer not found.", {
|
|
421
|
+
F: __dxlog_file2,
|
|
209
422
|
L: 51,
|
|
210
423
|
S: this,
|
|
211
424
|
A: [
|
|
@@ -229,8 +442,8 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
229
442
|
syncRepo({ id, syncMessage }) {
|
|
230
443
|
const peerId = this._getPeerId(id);
|
|
231
444
|
return new import_codec_protobuf.Stream(({ next, close }) => {
|
|
232
|
-
(0,
|
|
233
|
-
F:
|
|
445
|
+
(0, import_invariant3.invariant)(!this._peers.has(peerId), "Peer already connected.", {
|
|
446
|
+
F: __dxlog_file2,
|
|
234
447
|
L: 73,
|
|
235
448
|
S: this,
|
|
236
449
|
A: [
|
|
@@ -242,7 +455,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
242
455
|
connected: true,
|
|
243
456
|
send: (message) => {
|
|
244
457
|
next({
|
|
245
|
-
syncMessage:
|
|
458
|
+
syncMessage: import_automerge_repo3.cbor.encode(message)
|
|
246
459
|
});
|
|
247
460
|
},
|
|
248
461
|
disconnect: () => {
|
|
@@ -253,8 +466,8 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
253
466
|
});
|
|
254
467
|
}
|
|
255
468
|
});
|
|
256
|
-
(0,
|
|
257
|
-
F:
|
|
469
|
+
(0, import_invariant3.invariant)(this._isConnected, void 0, {
|
|
470
|
+
F: __dxlog_file2,
|
|
258
471
|
L: 90,
|
|
259
472
|
S: this,
|
|
260
473
|
A: [
|
|
@@ -269,8 +482,8 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
269
482
|
});
|
|
270
483
|
}
|
|
271
484
|
async sendSyncMessage({ id, syncMessage }) {
|
|
272
|
-
(0,
|
|
273
|
-
F:
|
|
485
|
+
(0, import_invariant3.invariant)(this._isConnected, void 0, {
|
|
486
|
+
F: __dxlog_file2,
|
|
274
487
|
L: 99,
|
|
275
488
|
S: this,
|
|
276
489
|
A: [
|
|
@@ -278,12 +491,12 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
278
491
|
""
|
|
279
492
|
]
|
|
280
493
|
});
|
|
281
|
-
const message =
|
|
494
|
+
const message = import_automerge_repo3.cbor.decode(syncMessage);
|
|
282
495
|
this.emit("message", message);
|
|
283
496
|
}
|
|
284
497
|
async getHostInfo() {
|
|
285
|
-
(0,
|
|
286
|
-
F:
|
|
498
|
+
(0, import_invariant3.invariant)(this._isConnected, void 0, {
|
|
499
|
+
F: __dxlog_file2,
|
|
287
500
|
L: 105,
|
|
288
501
|
S: this,
|
|
289
502
|
A: [
|
|
@@ -291,8 +504,8 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
291
504
|
""
|
|
292
505
|
]
|
|
293
506
|
});
|
|
294
|
-
(0,
|
|
295
|
-
F:
|
|
507
|
+
(0, import_invariant3.invariant)(this.peerId, "Peer id not set.", {
|
|
508
|
+
F: __dxlog_file2,
|
|
296
509
|
L: 106,
|
|
297
510
|
S: this,
|
|
298
511
|
A: [
|
|
@@ -308,12 +521,12 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapte
|
|
|
308
521
|
return id;
|
|
309
522
|
}
|
|
310
523
|
};
|
|
311
|
-
var
|
|
312
|
-
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 {
|
|
313
526
|
constructor() {
|
|
314
527
|
super(...arguments);
|
|
315
528
|
this._extensions = /* @__PURE__ */ new Map();
|
|
316
|
-
this._connected = new
|
|
529
|
+
this._connected = new import_async4.Trigger();
|
|
317
530
|
}
|
|
318
531
|
/**
|
|
319
532
|
* Emits `ready` event. That signals to `Repo` that it can start using the adapter.
|
|
@@ -330,8 +543,8 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
330
543
|
send(message) {
|
|
331
544
|
const receiverId = message.targetId;
|
|
332
545
|
const extension = this._extensions.get(receiverId);
|
|
333
|
-
(0,
|
|
334
|
-
F:
|
|
546
|
+
(0, import_invariant4.invariant)(extension, "Extension not found.", {
|
|
547
|
+
F: __dxlog_file3,
|
|
335
548
|
L: 38,
|
|
336
549
|
S: this,
|
|
337
550
|
A: [
|
|
@@ -340,9 +553,9 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
340
553
|
]
|
|
341
554
|
});
|
|
342
555
|
extension.sendSyncMessage({
|
|
343
|
-
payload:
|
|
344
|
-
}).catch((err) =>
|
|
345
|
-
F:
|
|
556
|
+
payload: import_automerge_repo4.cbor.encode(message)
|
|
557
|
+
}).catch((err) => import_log3.log.catch(err, void 0, {
|
|
558
|
+
F: __dxlog_file3,
|
|
346
559
|
L: 39,
|
|
347
560
|
S: this,
|
|
348
561
|
C: (f, a) => f(...a)
|
|
@@ -351,8 +564,8 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
351
564
|
disconnect() {
|
|
352
565
|
}
|
|
353
566
|
createExtension() {
|
|
354
|
-
(0,
|
|
355
|
-
F:
|
|
567
|
+
(0, import_invariant4.invariant)(this.peerId, "Peer id not set.", {
|
|
568
|
+
F: __dxlog_file3,
|
|
356
569
|
L: 47,
|
|
357
570
|
S: this,
|
|
358
571
|
A: [
|
|
@@ -366,12 +579,12 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
366
579
|
}, {
|
|
367
580
|
onStartReplication: async (info, remotePeerId) => {
|
|
368
581
|
await this._connected.wait();
|
|
369
|
-
(0,
|
|
582
|
+
(0, import_log3.log)("onStartReplication", {
|
|
370
583
|
id: info.id,
|
|
371
584
|
thisPeerId: this.peerId,
|
|
372
585
|
remotePeerId: remotePeerId.toHex()
|
|
373
586
|
}, {
|
|
374
|
-
F:
|
|
587
|
+
F: __dxlog_file3,
|
|
375
588
|
L: 70,
|
|
376
589
|
S: this,
|
|
377
590
|
C: (f, a) => f(...a)
|
|
@@ -379,12 +592,12 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
379
592
|
if (!this._extensions.has(info.id)) {
|
|
380
593
|
peerInfo = info;
|
|
381
594
|
this._extensions.set(info.id, extension);
|
|
382
|
-
(0,
|
|
595
|
+
(0, import_log3.log)("peer-candidate", {
|
|
383
596
|
id: info.id,
|
|
384
597
|
thisPeerId: this.peerId,
|
|
385
598
|
remotePeerId: remotePeerId.toHex()
|
|
386
599
|
}, {
|
|
387
|
-
F:
|
|
600
|
+
F: __dxlog_file3,
|
|
388
601
|
L: 76,
|
|
389
602
|
S: this,
|
|
390
603
|
C: (f, a) => f(...a)
|
|
@@ -402,7 +615,7 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
402
615
|
if (!peerInfo) {
|
|
403
616
|
return;
|
|
404
617
|
}
|
|
405
|
-
const message =
|
|
618
|
+
const message = import_automerge_repo4.cbor.decode(payload);
|
|
406
619
|
this.emit("message", message);
|
|
407
620
|
},
|
|
408
621
|
onClose: async () => {
|
|
@@ -491,7 +704,7 @@ var AutomergeStorageAdapter = class {
|
|
|
491
704
|
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
492
705
|
}
|
|
493
706
|
};
|
|
494
|
-
var
|
|
707
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
|
|
495
708
|
var levelMigration = async ({ db, directory }) => {
|
|
496
709
|
const isNewLevel = !await db.iterator({
|
|
497
710
|
...encodingOptions
|
|
@@ -505,10 +718,10 @@ var levelMigration = async ({ db, directory }) => {
|
|
|
505
718
|
return;
|
|
506
719
|
}
|
|
507
720
|
const batch = db.batch();
|
|
508
|
-
|
|
721
|
+
import_log4.log.info("found chunks on old storage adapter", {
|
|
509
722
|
chunks: chunks.length
|
|
510
723
|
}, {
|
|
511
|
-
F:
|
|
724
|
+
F: __dxlog_file4,
|
|
512
725
|
L: 36,
|
|
513
726
|
S: void 0,
|
|
514
727
|
C: (f, a) => f(...a)
|
|
@@ -520,7 +733,7 @@ var levelMigration = async ({ db, directory }) => {
|
|
|
520
733
|
}
|
|
521
734
|
await batch.write();
|
|
522
735
|
};
|
|
523
|
-
function
|
|
736
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
524
737
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
525
738
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
526
739
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -530,15 +743,16 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
530
743
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
531
744
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
532
745
|
}
|
|
533
|
-
var
|
|
746
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
534
747
|
var AutomergeHost = class {
|
|
535
|
-
constructor({ directory, db,
|
|
748
|
+
constructor({ directory, db, indexMetadataStore }) {
|
|
536
749
|
this._ctx = new import_context.Context();
|
|
750
|
+
this._echoNetworkAdapter = new EchoNetworkAdapter();
|
|
537
751
|
this._authorizedDevices = new import_util.ComplexMap(import_keys.PublicKey.hash);
|
|
538
752
|
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
539
753
|
this._directory = directory;
|
|
540
754
|
this._db = db;
|
|
541
|
-
this.
|
|
755
|
+
this._indexMetadataStore = indexMetadataStore;
|
|
542
756
|
}
|
|
543
757
|
async open() {
|
|
544
758
|
this._directory && await levelMigration({
|
|
@@ -547,7 +761,10 @@ var AutomergeHost = class {
|
|
|
547
761
|
});
|
|
548
762
|
this._storage = new LevelDBStorageAdapter({
|
|
549
763
|
db: this._db,
|
|
550
|
-
callbacks:
|
|
764
|
+
callbacks: {
|
|
765
|
+
beforeSave: async (params) => this._beforeSave(params),
|
|
766
|
+
afterSave: async () => this._afterSave()
|
|
767
|
+
}
|
|
551
768
|
});
|
|
552
769
|
await this._storage.open?.();
|
|
553
770
|
this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
|
|
@@ -557,7 +774,8 @@ var AutomergeHost = class {
|
|
|
557
774
|
peerId: this._peerId,
|
|
558
775
|
network: [
|
|
559
776
|
this._clientNetwork,
|
|
560
|
-
this._meshNetwork
|
|
777
|
+
this._meshNetwork,
|
|
778
|
+
this._echoNetworkAdapter
|
|
561
779
|
],
|
|
562
780
|
storage: this._storage,
|
|
563
781
|
// TODO(dmaretskyi): Share based on HALO permissions and space affinity.
|
|
@@ -569,6 +787,12 @@ var AutomergeHost = class {
|
|
|
569
787
|
if (!documentId) {
|
|
570
788
|
return false;
|
|
571
789
|
}
|
|
790
|
+
const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
|
|
791
|
+
if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
|
|
792
|
+
return this._echoNetworkAdapter.shouldAdvertize(peerId, {
|
|
793
|
+
documentId
|
|
794
|
+
});
|
|
795
|
+
}
|
|
572
796
|
const doc = this._repo.handles[documentId]?.docSync();
|
|
573
797
|
if (!doc) {
|
|
574
798
|
const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
|
|
@@ -577,8 +801,8 @@ var AutomergeHost = class {
|
|
|
577
801
|
documentId,
|
|
578
802
|
isRequested
|
|
579
803
|
}, {
|
|
580
|
-
F:
|
|
581
|
-
L:
|
|
804
|
+
F: __dxlog_file5,
|
|
805
|
+
L: 124,
|
|
582
806
|
S: this,
|
|
583
807
|
C: (f, a) => f(...a)
|
|
584
808
|
});
|
|
@@ -591,22 +815,22 @@ var AutomergeHost = class {
|
|
|
591
815
|
peerId,
|
|
592
816
|
documentId
|
|
593
817
|
}, {
|
|
594
|
-
F:
|
|
595
|
-
L:
|
|
818
|
+
F: __dxlog_file5,
|
|
819
|
+
L: 131,
|
|
596
820
|
S: this,
|
|
597
821
|
C: (f, a) => f(...a)
|
|
598
822
|
});
|
|
599
823
|
return false;
|
|
600
824
|
}
|
|
601
825
|
const authorizedDevices = this._authorizedDevices.get(import_keys.PublicKey.from(spaceKey));
|
|
602
|
-
const deviceKeyHex =
|
|
826
|
+
const deviceKeyHex = peerMetadata?.dxos_deviceKey;
|
|
603
827
|
if (!deviceKeyHex) {
|
|
604
828
|
(0, import_log.log)("device key not found for share policy check", {
|
|
605
829
|
peerId,
|
|
606
830
|
documentId
|
|
607
831
|
}, {
|
|
608
|
-
F:
|
|
609
|
-
L:
|
|
832
|
+
F: __dxlog_file5,
|
|
833
|
+
L: 140,
|
|
610
834
|
S: this,
|
|
611
835
|
C: (f, a) => f(...a)
|
|
612
836
|
});
|
|
@@ -622,16 +846,16 @@ var AutomergeHost = class {
|
|
|
622
846
|
spaceKey,
|
|
623
847
|
isAuthorized
|
|
624
848
|
}, {
|
|
625
|
-
F:
|
|
626
|
-
L:
|
|
849
|
+
F: __dxlog_file5,
|
|
850
|
+
L: 146,
|
|
627
851
|
S: this,
|
|
628
852
|
C: (f, a) => f(...a)
|
|
629
853
|
});
|
|
630
854
|
return isAuthorized;
|
|
631
855
|
} catch (err) {
|
|
632
856
|
import_log.log.catch(err, void 0, {
|
|
633
|
-
F:
|
|
634
|
-
L:
|
|
857
|
+
F: __dxlog_file5,
|
|
858
|
+
L: 156,
|
|
635
859
|
S: this,
|
|
636
860
|
C: (f, a) => f(...a)
|
|
637
861
|
});
|
|
@@ -641,16 +865,52 @@ var AutomergeHost = class {
|
|
|
641
865
|
});
|
|
642
866
|
this._clientNetwork.ready();
|
|
643
867
|
this._meshNetwork.ready();
|
|
868
|
+
await this._echoNetworkAdapter.open();
|
|
644
869
|
await this._clientNetwork.whenConnected();
|
|
870
|
+
await this._echoNetworkAdapter.whenConnected();
|
|
645
871
|
}
|
|
646
872
|
async close() {
|
|
647
873
|
await this._storage.close?.();
|
|
648
874
|
await this._clientNetwork.close();
|
|
875
|
+
await this._echoNetworkAdapter.close();
|
|
649
876
|
await this._ctx.dispose();
|
|
650
877
|
}
|
|
651
878
|
get repo() {
|
|
652
879
|
return this._repo;
|
|
653
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
|
+
}
|
|
654
914
|
_automergeDocs() {
|
|
655
915
|
return (0, import_util.mapValues)(this._repo.handles, (handle) => ({
|
|
656
916
|
state: handle.state,
|
|
@@ -682,8 +942,8 @@ var AutomergeHost = class {
|
|
|
682
942
|
async flush({ states }) {
|
|
683
943
|
await Promise.all(states?.map(async ({ heads, documentId }) => {
|
|
684
944
|
(0, import_invariant.invariant)(heads, "heads are required for flush", {
|
|
685
|
-
F:
|
|
686
|
-
L:
|
|
945
|
+
F: __dxlog_file5,
|
|
946
|
+
L: 252,
|
|
687
947
|
S: this,
|
|
688
948
|
A: [
|
|
689
949
|
"heads",
|
|
@@ -715,33 +975,33 @@ var AutomergeHost = class {
|
|
|
715
975
|
spaceKey,
|
|
716
976
|
deviceKey
|
|
717
977
|
}, {
|
|
718
|
-
F:
|
|
719
|
-
L:
|
|
978
|
+
F: __dxlog_file5,
|
|
979
|
+
L: 282,
|
|
720
980
|
S: this,
|
|
721
981
|
C: (f, a) => f(...a)
|
|
722
982
|
});
|
|
723
983
|
(0, import_util.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util.ComplexSet(import_keys.PublicKey.hash)).add(deviceKey);
|
|
724
984
|
}
|
|
725
985
|
};
|
|
726
|
-
|
|
986
|
+
_ts_decorate2([
|
|
727
987
|
import_tracing.trace.info()
|
|
728
988
|
], AutomergeHost.prototype, "_peerId", void 0);
|
|
729
|
-
|
|
989
|
+
_ts_decorate2([
|
|
730
990
|
import_tracing.trace.info({
|
|
731
991
|
depth: null
|
|
732
992
|
})
|
|
733
993
|
], AutomergeHost.prototype, "_automergeDocs", null);
|
|
734
|
-
|
|
994
|
+
_ts_decorate2([
|
|
735
995
|
import_tracing.trace.info({
|
|
736
996
|
depth: null
|
|
737
997
|
})
|
|
738
998
|
], AutomergeHost.prototype, "_automergePeers", null);
|
|
739
|
-
|
|
999
|
+
_ts_decorate2([
|
|
740
1000
|
import_tracing.trace.span({
|
|
741
1001
|
showInBrowserTimeline: true
|
|
742
1002
|
})
|
|
743
1003
|
], AutomergeHost.prototype, "flush", null);
|
|
744
|
-
AutomergeHost =
|
|
1004
|
+
AutomergeHost = _ts_decorate2([
|
|
745
1005
|
import_tracing.trace.resource()
|
|
746
1006
|
], AutomergeHost);
|
|
747
1007
|
var getSpaceKeyFromDoc = (doc) => {
|
|
@@ -769,7 +1029,7 @@ var waitForHeads = async (handle, heads) => {
|
|
|
769
1029
|
var changeIsPresentInDoc = (doc, changeHash) => {
|
|
770
1030
|
return !!(0, import_automerge.getBackend)(doc).getChangeByHash(changeHash);
|
|
771
1031
|
};
|
|
772
|
-
function
|
|
1032
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
773
1033
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
774
1034
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
775
1035
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -779,7 +1039,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
779
1039
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
780
1040
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
781
1041
|
}
|
|
782
|
-
var
|
|
1042
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
783
1043
|
var AutomergeDocumentLoaderImpl = class {
|
|
784
1044
|
constructor(_spaceKey, _repo) {
|
|
785
1045
|
this._spaceKey = _spaceKey;
|
|
@@ -787,23 +1047,24 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
787
1047
|
this._spaceRootDocHandle = null;
|
|
788
1048
|
this._objectDocumentHandles = /* @__PURE__ */ new Map();
|
|
789
1049
|
this._objectsPendingDocumentLoad = /* @__PURE__ */ new Set();
|
|
790
|
-
this.onObjectDocumentLoaded = new
|
|
1050
|
+
this.onObjectDocumentLoaded = new import_async5.Event();
|
|
791
1051
|
}
|
|
792
1052
|
getAllHandles() {
|
|
793
|
-
return [
|
|
1053
|
+
return this._spaceRootDocHandle != null ? [
|
|
1054
|
+
this._spaceRootDocHandle,
|
|
794
1055
|
...new Set(this._objectDocumentHandles.values())
|
|
795
|
-
];
|
|
1056
|
+
] : [];
|
|
796
1057
|
}
|
|
797
1058
|
async loadSpaceRootDocHandle(ctx, spaceState) {
|
|
798
1059
|
if (this._spaceRootDocHandle != null) {
|
|
799
1060
|
return;
|
|
800
1061
|
}
|
|
801
1062
|
if (!spaceState.rootUrl) {
|
|
802
|
-
|
|
1063
|
+
import_log5.log.error("Database opened with no rootUrl", {
|
|
803
1064
|
spaceKey: this._spaceKey
|
|
804
1065
|
}, {
|
|
805
|
-
F:
|
|
806
|
-
L:
|
|
1066
|
+
F: __dxlog_file6,
|
|
1067
|
+
L: 70,
|
|
807
1068
|
S: this,
|
|
808
1069
|
C: (f, a) => f(...a)
|
|
809
1070
|
});
|
|
@@ -811,9 +1072,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
811
1072
|
} else {
|
|
812
1073
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
813
1074
|
const doc = existingDocHandle.docSync();
|
|
814
|
-
(0,
|
|
815
|
-
F:
|
|
816
|
-
L:
|
|
1075
|
+
(0, import_invariant5.invariant)(doc, void 0, {
|
|
1076
|
+
F: __dxlog_file6,
|
|
1077
|
+
L: 75,
|
|
817
1078
|
S: this,
|
|
818
1079
|
A: [
|
|
819
1080
|
"doc",
|
|
@@ -826,45 +1087,54 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
826
1087
|
this._spaceRootDocHandle = existingDocHandle;
|
|
827
1088
|
}
|
|
828
1089
|
}
|
|
829
|
-
loadObjectDocument(
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
if (this._objectDocumentHandles.has(objectId) || this._objectsPendingDocumentLoad.has(objectId)) {
|
|
840
|
-
return;
|
|
841
|
-
}
|
|
842
|
-
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
843
|
-
(0, import_invariant4.invariant)(spaceRootDoc, void 0, {
|
|
844
|
-
F: __dxlog_file5,
|
|
845
|
-
L: 88,
|
|
846
|
-
S: this,
|
|
847
|
-
A: [
|
|
848
|
-
"spaceRootDoc",
|
|
849
|
-
""
|
|
850
|
-
]
|
|
851
|
-
});
|
|
852
|
-
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
853
|
-
if (documentUrl == null) {
|
|
854
|
-
this._objectsPendingDocumentLoad.add(objectId);
|
|
855
|
-
import_log4.log.info("loading delayed until object links are initialized", {
|
|
856
|
-
objectId
|
|
857
|
-
}, {
|
|
858
|
-
F: __dxlog_file5,
|
|
859
|
-
L: 92,
|
|
1090
|
+
loadObjectDocument(objectIdOrMany) {
|
|
1091
|
+
const objectIds = Array.isArray(objectIdOrMany) ? objectIdOrMany : [
|
|
1092
|
+
objectIdOrMany
|
|
1093
|
+
];
|
|
1094
|
+
let hasUrlsToLoad = false;
|
|
1095
|
+
const urlsToLoad = {};
|
|
1096
|
+
for (const objectId of objectIds) {
|
|
1097
|
+
(0, import_invariant5.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1098
|
+
F: __dxlog_file6,
|
|
1099
|
+
L: 88,
|
|
860
1100
|
S: this,
|
|
861
|
-
|
|
1101
|
+
A: [
|
|
1102
|
+
"this._spaceRootDocHandle",
|
|
1103
|
+
""
|
|
1104
|
+
]
|
|
862
1105
|
});
|
|
863
|
-
|
|
1106
|
+
if (this._objectDocumentHandles.has(objectId) || this._objectsPendingDocumentLoad.has(objectId)) {
|
|
1107
|
+
continue;
|
|
1108
|
+
}
|
|
1109
|
+
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
1110
|
+
(0, import_invariant5.invariant)(spaceRootDoc, void 0, {
|
|
1111
|
+
F: __dxlog_file6,
|
|
1112
|
+
L: 93,
|
|
1113
|
+
S: this,
|
|
1114
|
+
A: [
|
|
1115
|
+
"spaceRootDoc",
|
|
1116
|
+
""
|
|
1117
|
+
]
|
|
1118
|
+
});
|
|
1119
|
+
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
1120
|
+
if (documentUrl == null) {
|
|
1121
|
+
this._objectsPendingDocumentLoad.add(objectId);
|
|
1122
|
+
import_log5.log.info("loading delayed until object links are initialized", {
|
|
1123
|
+
objectId
|
|
1124
|
+
}, {
|
|
1125
|
+
F: __dxlog_file6,
|
|
1126
|
+
L: 97,
|
|
1127
|
+
S: this,
|
|
1128
|
+
C: (f, a) => f(...a)
|
|
1129
|
+
});
|
|
1130
|
+
} else {
|
|
1131
|
+
urlsToLoad[objectId] = documentUrl;
|
|
1132
|
+
hasUrlsToLoad = true;
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
if (hasUrlsToLoad) {
|
|
1136
|
+
this._loadLinkedObjects(urlsToLoad);
|
|
864
1137
|
}
|
|
865
|
-
this._loadLinkedObjects({
|
|
866
|
-
[objectId]: documentUrl
|
|
867
|
-
});
|
|
868
1138
|
}
|
|
869
1139
|
onObjectLinksUpdated(links) {
|
|
870
1140
|
if (!links) {
|
|
@@ -875,9 +1145,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
875
1145
|
linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
|
|
876
1146
|
}
|
|
877
1147
|
getSpaceRootDocHandle() {
|
|
878
|
-
(0,
|
|
879
|
-
F:
|
|
880
|
-
L:
|
|
1148
|
+
(0, import_invariant5.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1149
|
+
F: __dxlog_file6,
|
|
1150
|
+
L: 120,
|
|
881
1151
|
S: this,
|
|
882
1152
|
A: [
|
|
883
1153
|
"this._spaceRootDocHandle",
|
|
@@ -887,9 +1157,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
887
1157
|
return this._spaceRootDocHandle;
|
|
888
1158
|
}
|
|
889
1159
|
createDocumentForObject(objectId) {
|
|
890
|
-
(0,
|
|
891
|
-
F:
|
|
892
|
-
L:
|
|
1160
|
+
(0, import_invariant5.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1161
|
+
F: __dxlog_file6,
|
|
1162
|
+
L: 125,
|
|
893
1163
|
S: this,
|
|
894
1164
|
A: [
|
|
895
1165
|
"this._spaceRootDocHandle",
|
|
@@ -927,30 +1197,30 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
927
1197
|
};
|
|
928
1198
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
929
1199
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
930
|
-
|
|
1200
|
+
import_log5.log.warn("object already inlined in a different document, ignoring the link", {
|
|
931
1201
|
...logMeta,
|
|
932
1202
|
actualDocumentUrl: objectDocumentHandle.url
|
|
933
1203
|
}, {
|
|
934
|
-
F:
|
|
935
|
-
L:
|
|
1204
|
+
F: __dxlog_file6,
|
|
1205
|
+
L: 155,
|
|
936
1206
|
S: this,
|
|
937
1207
|
C: (f, a) => f(...a)
|
|
938
1208
|
});
|
|
939
1209
|
continue;
|
|
940
1210
|
}
|
|
941
1211
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
942
|
-
|
|
943
|
-
F:
|
|
944
|
-
L:
|
|
1212
|
+
import_log5.log.warn("object document was already loaded", logMeta, {
|
|
1213
|
+
F: __dxlog_file6,
|
|
1214
|
+
L: 162,
|
|
945
1215
|
S: this,
|
|
946
1216
|
C: (f, a) => f(...a)
|
|
947
1217
|
});
|
|
948
1218
|
continue;
|
|
949
1219
|
}
|
|
950
1220
|
const handle = this._repo.find(automergeUrl);
|
|
951
|
-
|
|
952
|
-
F:
|
|
953
|
-
L:
|
|
1221
|
+
import_log5.log.debug("document loading triggered", logMeta, {
|
|
1222
|
+
F: __dxlog_file6,
|
|
1223
|
+
L: 166,
|
|
954
1224
|
S: this,
|
|
955
1225
|
C: (f, a) => f(...a)
|
|
956
1226
|
});
|
|
@@ -963,17 +1233,17 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
963
1233
|
while (true) {
|
|
964
1234
|
try {
|
|
965
1235
|
await (0, import_debug.warnAfterTimeout)(5e3, "Automerge root doc load timeout (AutomergeDb)", async () => {
|
|
966
|
-
await (0,
|
|
1236
|
+
await (0, import_context4.cancelWithContext)(ctx, docHandle.whenReady());
|
|
967
1237
|
});
|
|
968
1238
|
break;
|
|
969
1239
|
} catch (err) {
|
|
970
1240
|
if (`${err}`.includes("Timeout")) {
|
|
971
|
-
|
|
1241
|
+
import_log5.log.info("wraparound", {
|
|
972
1242
|
id: docHandle.documentId,
|
|
973
1243
|
state: docHandle.state
|
|
974
1244
|
}, {
|
|
975
|
-
F:
|
|
976
|
-
L:
|
|
1245
|
+
F: __dxlog_file6,
|
|
1246
|
+
L: 182,
|
|
977
1247
|
S: this,
|
|
978
1248
|
C: (f, a) => f(...a)
|
|
979
1249
|
});
|
|
@@ -1013,9 +1283,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1013
1283
|
docUrl: handle.url
|
|
1014
1284
|
};
|
|
1015
1285
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1016
|
-
|
|
1017
|
-
F:
|
|
1018
|
-
L:
|
|
1286
|
+
import_log5.log.info("document loaded after all listeners were removed", logMeta, {
|
|
1287
|
+
F: __dxlog_file6,
|
|
1288
|
+
L: 218,
|
|
1019
1289
|
S: this,
|
|
1020
1290
|
C: (f, a) => f(...a)
|
|
1021
1291
|
});
|
|
@@ -1023,9 +1293,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1023
1293
|
}
|
|
1024
1294
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
1025
1295
|
if (objectDocHandle?.url !== handle.url) {
|
|
1026
|
-
|
|
1027
|
-
F:
|
|
1028
|
-
L:
|
|
1296
|
+
import_log5.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1297
|
+
F: __dxlog_file6,
|
|
1298
|
+
L: 223,
|
|
1029
1299
|
S: this,
|
|
1030
1300
|
C: (f, a) => f(...a)
|
|
1031
1301
|
});
|
|
@@ -1037,14 +1307,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1037
1307
|
});
|
|
1038
1308
|
} catch (err) {
|
|
1039
1309
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1040
|
-
|
|
1310
|
+
import_log5.log.warn("failed to load a document", {
|
|
1041
1311
|
objectId,
|
|
1042
1312
|
automergeUrl: handle.url,
|
|
1043
1313
|
retryLoading: shouldRetryLoading,
|
|
1044
1314
|
err
|
|
1045
1315
|
}, {
|
|
1046
|
-
F:
|
|
1047
|
-
L:
|
|
1316
|
+
F: __dxlog_file6,
|
|
1317
|
+
L: 229,
|
|
1048
1318
|
S: this,
|
|
1049
1319
|
C: (f, a) => f(...a)
|
|
1050
1320
|
});
|
|
@@ -1054,24 +1324,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1054
1324
|
}
|
|
1055
1325
|
}
|
|
1056
1326
|
};
|
|
1057
|
-
|
|
1327
|
+
_ts_decorate3([
|
|
1058
1328
|
import_tracing2.trace.span({
|
|
1059
1329
|
showInBrowserTimeline: true
|
|
1060
1330
|
})
|
|
1061
1331
|
], AutomergeDocumentLoaderImpl.prototype, "loadSpaceRootDocHandle", null);
|
|
1062
|
-
AutomergeDocumentLoaderImpl =
|
|
1332
|
+
AutomergeDocumentLoaderImpl = _ts_decorate3([
|
|
1063
1333
|
import_tracing2.trace.resource()
|
|
1064
1334
|
], AutomergeDocumentLoaderImpl);
|
|
1065
|
-
var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
1066
|
-
var encodeReference = (reference) => ({
|
|
1067
|
-
"@type": REFERENCE_TYPE_TAG,
|
|
1068
|
-
// NOTE: Automerge do not support undefined values, so we need to use null instead.
|
|
1069
|
-
itemId: reference.itemId ?? null,
|
|
1070
|
-
protocol: reference.protocol ?? null,
|
|
1071
|
-
host: reference.host ?? null
|
|
1072
|
-
});
|
|
1073
|
-
var decodeReference = (value) => new import_echo_schema.Reference(value.itemId, value.protocol ?? void 0, value.host ?? void 0);
|
|
1074
|
-
var isEncodedReferenceObject = (value) => typeof value === "object" && value !== null && value["@type"] === REFERENCE_TYPE_TAG;
|
|
1075
1335
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1076
1336
|
0 && (module.exports = {
|
|
1077
1337
|
AuthExtension,
|
|
@@ -1087,7 +1347,6 @@ var isEncodedReferenceObject = (value) => typeof value === "object" && value !==
|
|
|
1087
1347
|
MeshNetworkAdapter,
|
|
1088
1348
|
MetadataStore,
|
|
1089
1349
|
Pipeline,
|
|
1090
|
-
REFERENCE_TYPE_TAG,
|
|
1091
1350
|
SnapshotManager,
|
|
1092
1351
|
SnapshotStore,
|
|
1093
1352
|
Space,
|
|
@@ -1097,12 +1356,9 @@ var isEncodedReferenceObject = (value) => typeof value === "object" && value !==
|
|
|
1097
1356
|
TimeframeClock,
|
|
1098
1357
|
codec,
|
|
1099
1358
|
createMappedFeedWriter,
|
|
1100
|
-
decodeReference,
|
|
1101
|
-
encodeReference,
|
|
1102
1359
|
encodingOptions,
|
|
1103
1360
|
getSpaceKeyFromDoc,
|
|
1104
1361
|
hasInvitationExpired,
|
|
1105
|
-
isEncodedReferenceObject,
|
|
1106
1362
|
mapFeedIndexesToTimeframe,
|
|
1107
1363
|
mapTimeframeToFeedIndexes,
|
|
1108
1364
|
startAfter,
|