@dxos/echo-pipeline 0.5.1-main.ef0d69d → 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 +402 -149
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -8
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-YZA42CKA.cjs → chunk-D25ZFWEF.cjs} +20 -20
- package/dist/lib/node/{chunk-YZA42CKA.cjs.map → chunk-D25ZFWEF.cjs.map} +2 -2
- package/dist/lib/node/index.cjs +412 -166
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +13 -18
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/automerge/automerge-doc-loader.d.ts +1 -1
- package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -1
- package/dist/types/src/automerge/automerge-host.d.ts +14 -5
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-network-adapter.d.ts +26 -0
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -0
- package/dist/types/src/automerge/echo-replicator.d.ts +43 -0
- package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -0
- package/dist/types/src/automerge/index.d.ts +1 -2
- package/dist/types/src/automerge/index.d.ts.map +1 -1
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts +1 -1
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/migrations.d.ts +1 -1
- package/dist/types/src/automerge/migrations.d.ts.map +1 -1
- package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +0 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/package.json +33 -30
- package/src/automerge/automerge-doc-loader.test.ts +1 -1
- package/src/automerge/automerge-doc-loader.ts +4 -3
- package/src/automerge/automerge-host.test.ts +11 -3
- package/src/automerge/automerge-host.ts +62 -10
- package/src/automerge/automerge-repo.test.ts +1 -1
- package/src/automerge/echo-network-adapter.ts +155 -0
- package/src/automerge/echo-replicator.ts +56 -0
- package/src/automerge/index.ts +1 -2
- package/src/automerge/leveldb-storage-adapter.ts +1 -2
- package/src/automerge/migrations.ts +1 -1
- package/src/automerge/storage-adapter.test.ts +1 -1
- package/src/pipeline/pipeline.ts +1 -0
- package/src/testing/index.ts +0 -1
- package/dist/types/src/automerge/level.test.d.ts +0 -2
- package/dist/types/src/automerge/level.test.d.ts.map +0 -1
- package/dist/types/src/automerge/reference.d.ts +0 -15
- package/dist/types/src/automerge/reference.d.ts.map +0 -1
- package/dist/types/src/automerge/types.d.ts +0 -73
- package/dist/types/src/automerge/types.d.ts.map +0 -1
- package/dist/types/src/testing/level.d.ts +0 -3
- package/dist/types/src/testing/level.d.ts.map +0 -1
- package/src/automerge/level.test.ts +0 -114
- package/src/automerge/reference.ts +0 -31
- package/src/automerge/types.ts +0 -86
- package/src/testing/level.ts +0 -12
|
@@ -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",
|
|
@@ -823,9 +1093,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
823
1093
|
let hasUrlsToLoad = false;
|
|
824
1094
|
const urlsToLoad = {};
|
|
825
1095
|
for (const objectId of objectIds) {
|
|
826
|
-
|
|
827
|
-
F:
|
|
828
|
-
L:
|
|
1096
|
+
invariant5(this._spaceRootDocHandle, void 0, {
|
|
1097
|
+
F: __dxlog_file6,
|
|
1098
|
+
L: 88,
|
|
829
1099
|
S: this,
|
|
830
1100
|
A: [
|
|
831
1101
|
"this._spaceRootDocHandle",
|
|
@@ -836,9 +1106,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
836
1106
|
continue;
|
|
837
1107
|
}
|
|
838
1108
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
839
|
-
|
|
840
|
-
F:
|
|
841
|
-
L:
|
|
1109
|
+
invariant5(spaceRootDoc, void 0, {
|
|
1110
|
+
F: __dxlog_file6,
|
|
1111
|
+
L: 93,
|
|
842
1112
|
S: this,
|
|
843
1113
|
A: [
|
|
844
1114
|
"spaceRootDoc",
|
|
@@ -848,11 +1118,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
848
1118
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
849
1119
|
if (documentUrl == null) {
|
|
850
1120
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
851
|
-
|
|
1121
|
+
log5.info("loading delayed until object links are initialized", {
|
|
852
1122
|
objectId
|
|
853
1123
|
}, {
|
|
854
|
-
F:
|
|
855
|
-
L:
|
|
1124
|
+
F: __dxlog_file6,
|
|
1125
|
+
L: 97,
|
|
856
1126
|
S: this,
|
|
857
1127
|
C: (f, a) => f(...a)
|
|
858
1128
|
});
|
|
@@ -874,9 +1144,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
874
1144
|
linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
|
|
875
1145
|
}
|
|
876
1146
|
getSpaceRootDocHandle() {
|
|
877
|
-
|
|
878
|
-
F:
|
|
879
|
-
L:
|
|
1147
|
+
invariant5(this._spaceRootDocHandle, void 0, {
|
|
1148
|
+
F: __dxlog_file6,
|
|
1149
|
+
L: 120,
|
|
880
1150
|
S: this,
|
|
881
1151
|
A: [
|
|
882
1152
|
"this._spaceRootDocHandle",
|
|
@@ -886,9 +1156,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
886
1156
|
return this._spaceRootDocHandle;
|
|
887
1157
|
}
|
|
888
1158
|
createDocumentForObject(objectId) {
|
|
889
|
-
|
|
890
|
-
F:
|
|
891
|
-
L:
|
|
1159
|
+
invariant5(this._spaceRootDocHandle, void 0, {
|
|
1160
|
+
F: __dxlog_file6,
|
|
1161
|
+
L: 125,
|
|
892
1162
|
S: this,
|
|
893
1163
|
A: [
|
|
894
1164
|
"this._spaceRootDocHandle",
|
|
@@ -926,30 +1196,30 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
926
1196
|
};
|
|
927
1197
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
928
1198
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
929
|
-
|
|
1199
|
+
log5.warn("object already inlined in a different document, ignoring the link", {
|
|
930
1200
|
...logMeta,
|
|
931
1201
|
actualDocumentUrl: objectDocumentHandle.url
|
|
932
1202
|
}, {
|
|
933
|
-
F:
|
|
934
|
-
L:
|
|
1203
|
+
F: __dxlog_file6,
|
|
1204
|
+
L: 155,
|
|
935
1205
|
S: this,
|
|
936
1206
|
C: (f, a) => f(...a)
|
|
937
1207
|
});
|
|
938
1208
|
continue;
|
|
939
1209
|
}
|
|
940
1210
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
941
|
-
|
|
942
|
-
F:
|
|
943
|
-
L:
|
|
1211
|
+
log5.warn("object document was already loaded", logMeta, {
|
|
1212
|
+
F: __dxlog_file6,
|
|
1213
|
+
L: 162,
|
|
944
1214
|
S: this,
|
|
945
1215
|
C: (f, a) => f(...a)
|
|
946
1216
|
});
|
|
947
1217
|
continue;
|
|
948
1218
|
}
|
|
949
1219
|
const handle = this._repo.find(automergeUrl);
|
|
950
|
-
|
|
951
|
-
F:
|
|
952
|
-
L:
|
|
1220
|
+
log5.debug("document loading triggered", logMeta, {
|
|
1221
|
+
F: __dxlog_file6,
|
|
1222
|
+
L: 166,
|
|
953
1223
|
S: this,
|
|
954
1224
|
C: (f, a) => f(...a)
|
|
955
1225
|
});
|
|
@@ -967,12 +1237,12 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
967
1237
|
break;
|
|
968
1238
|
} catch (err) {
|
|
969
1239
|
if (`${err}`.includes("Timeout")) {
|
|
970
|
-
|
|
1240
|
+
log5.info("wraparound", {
|
|
971
1241
|
id: docHandle.documentId,
|
|
972
1242
|
state: docHandle.state
|
|
973
1243
|
}, {
|
|
974
|
-
F:
|
|
975
|
-
L:
|
|
1244
|
+
F: __dxlog_file6,
|
|
1245
|
+
L: 182,
|
|
976
1246
|
S: this,
|
|
977
1247
|
C: (f, a) => f(...a)
|
|
978
1248
|
});
|
|
@@ -1012,9 +1282,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1012
1282
|
docUrl: handle.url
|
|
1013
1283
|
};
|
|
1014
1284
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1015
|
-
|
|
1016
|
-
F:
|
|
1017
|
-
L:
|
|
1285
|
+
log5.info("document loaded after all listeners were removed", logMeta, {
|
|
1286
|
+
F: __dxlog_file6,
|
|
1287
|
+
L: 218,
|
|
1018
1288
|
S: this,
|
|
1019
1289
|
C: (f, a) => f(...a)
|
|
1020
1290
|
});
|
|
@@ -1022,9 +1292,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1022
1292
|
}
|
|
1023
1293
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
1024
1294
|
if (objectDocHandle?.url !== handle.url) {
|
|
1025
|
-
|
|
1026
|
-
F:
|
|
1027
|
-
L:
|
|
1295
|
+
log5.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1296
|
+
F: __dxlog_file6,
|
|
1297
|
+
L: 223,
|
|
1028
1298
|
S: this,
|
|
1029
1299
|
C: (f, a) => f(...a)
|
|
1030
1300
|
});
|
|
@@ -1036,14 +1306,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1036
1306
|
});
|
|
1037
1307
|
} catch (err) {
|
|
1038
1308
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1039
|
-
|
|
1309
|
+
log5.warn("failed to load a document", {
|
|
1040
1310
|
objectId,
|
|
1041
1311
|
automergeUrl: handle.url,
|
|
1042
1312
|
retryLoading: shouldRetryLoading,
|
|
1043
1313
|
err
|
|
1044
1314
|
}, {
|
|
1045
|
-
F:
|
|
1046
|
-
L:
|
|
1315
|
+
F: __dxlog_file6,
|
|
1316
|
+
L: 229,
|
|
1047
1317
|
S: this,
|
|
1048
1318
|
C: (f, a) => f(...a)
|
|
1049
1319
|
});
|
|
@@ -1053,27 +1323,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1053
1323
|
}
|
|
1054
1324
|
}
|
|
1055
1325
|
};
|
|
1056
|
-
|
|
1326
|
+
_ts_decorate3([
|
|
1057
1327
|
trace2.span({
|
|
1058
1328
|
showInBrowserTimeline: true
|
|
1059
1329
|
})
|
|
1060
1330
|
], AutomergeDocumentLoaderImpl.prototype, "loadSpaceRootDocHandle", null);
|
|
1061
|
-
AutomergeDocumentLoaderImpl =
|
|
1331
|
+
AutomergeDocumentLoaderImpl = _ts_decorate3([
|
|
1062
1332
|
trace2.resource()
|
|
1063
1333
|
], AutomergeDocumentLoaderImpl);
|
|
1064
|
-
|
|
1065
|
-
// packages/core/echo/echo-pipeline/src/automerge/reference.ts
|
|
1066
|
-
import { Reference } from "@dxos/echo-schema";
|
|
1067
|
-
var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
1068
|
-
var encodeReference = (reference) => ({
|
|
1069
|
-
"@type": REFERENCE_TYPE_TAG,
|
|
1070
|
-
// NOTE: Automerge do not support undefined values, so we need to use null instead.
|
|
1071
|
-
itemId: reference.itemId ?? null,
|
|
1072
|
-
protocol: reference.protocol ?? null,
|
|
1073
|
-
host: reference.host ?? null
|
|
1074
|
-
});
|
|
1075
|
-
var decodeReference = (value) => new Reference(value.itemId, value.protocol ?? void 0, value.host ?? void 0);
|
|
1076
|
-
var isEncodedReferenceObject = (value) => typeof value === "object" && value !== null && value["@type"] === REFERENCE_TYPE_TAG;
|
|
1077
1334
|
export {
|
|
1078
1335
|
AuthExtension,
|
|
1079
1336
|
AuthStatus,
|
|
@@ -1088,7 +1345,6 @@ export {
|
|
|
1088
1345
|
MeshNetworkAdapter,
|
|
1089
1346
|
MetadataStore,
|
|
1090
1347
|
Pipeline,
|
|
1091
|
-
REFERENCE_TYPE_TAG,
|
|
1092
1348
|
SnapshotManager,
|
|
1093
1349
|
SnapshotStore,
|
|
1094
1350
|
Space,
|
|
@@ -1098,12 +1354,9 @@ export {
|
|
|
1098
1354
|
TimeframeClock,
|
|
1099
1355
|
codec,
|
|
1100
1356
|
createMappedFeedWriter,
|
|
1101
|
-
decodeReference,
|
|
1102
|
-
encodeReference,
|
|
1103
1357
|
encodingOptions,
|
|
1104
1358
|
getSpaceKeyFromDoc,
|
|
1105
1359
|
hasInvitationExpired,
|
|
1106
|
-
isEncodedReferenceObject,
|
|
1107
1360
|
mapFeedIndexesToTimeframe,
|
|
1108
1361
|
mapTimeframeToFeedIndexes,
|
|
1109
1362
|
startAfter,
|