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