@dxos/echo-pipeline 0.6.0 → 0.6.1-main.04e8aa0
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-HS77A4I4.mjs → chunk-A2LCXJVD.mjs} +16 -1
- package/dist/lib/browser/chunk-A2LCXJVD.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +170 -90
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-Y5U7UXEL.cjs → chunk-GHBIMYZK.cjs} +19 -4
- package/dist/lib/node/chunk-GHBIMYZK.cjs.map +7 -0
- package/dist/lib/node/index.cjs +214 -136
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +11 -11
- package/dist/types/src/automerge/automerge-host.d.ts +12 -9
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-network-adapter.d.ts +2 -2
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-replicator.d.ts +5 -6
- package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
- package/dist/types/src/automerge/heads-store.d.ts +13 -0
- package/dist/types/src/automerge/heads-store.d.ts.map +1 -0
- package/dist/types/src/db-host/data-service.d.ts +4 -2
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/package.json +33 -33
- package/src/automerge/automerge-doc-loader.ts +1 -1
- package/src/automerge/automerge-host.test.ts +34 -17
- package/src/automerge/automerge-host.ts +56 -16
- package/src/automerge/automerge-repo.test.ts +76 -1
- package/src/automerge/echo-network-adapter.ts +10 -6
- package/src/automerge/echo-replicator.ts +6 -9
- package/src/automerge/heads-store.ts +39 -0
- package/src/automerge/mesh-echo-replicator.ts +5 -5
- package/src/db-host/data-service.ts +22 -2
- package/dist/lib/browser/chunk-HS77A4I4.mjs.map +0 -7
- package/dist/lib/node/chunk-Y5U7UXEL.cjs.map +0 -7
|
@@ -25,20 +25,22 @@ import {
|
|
|
25
25
|
mapTimeframeToFeedIndexes,
|
|
26
26
|
startAfter,
|
|
27
27
|
valueEncoding
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-A2LCXJVD.mjs";
|
|
29
29
|
|
|
30
30
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
31
31
|
import { Event, asyncTimeout } from "@dxos/async";
|
|
32
32
|
import { next as automerge, getBackend, getHeads, isAutomerge, save } from "@dxos/automerge/automerge";
|
|
33
33
|
import { Repo } from "@dxos/automerge/automerge-repo";
|
|
34
|
-
import {
|
|
34
|
+
import { Resource as Resource2, cancelWithContext } from "@dxos/context";
|
|
35
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
35
36
|
import { PublicKey } from "@dxos/keys";
|
|
37
|
+
import { log as log2 } from "@dxos/log";
|
|
36
38
|
import { objectPointerCodec } from "@dxos/protocols";
|
|
37
39
|
import { trace } from "@dxos/tracing";
|
|
38
40
|
import { mapValues } from "@dxos/util";
|
|
39
41
|
|
|
40
42
|
// packages/core/echo/echo-pipeline/src/automerge/echo-network-adapter.ts
|
|
41
|
-
import {
|
|
43
|
+
import { synchronized, Trigger } from "@dxos/async";
|
|
42
44
|
import { NetworkAdapter } from "@dxos/automerge/automerge-repo";
|
|
43
45
|
import { LifecycleState } from "@dxos/context";
|
|
44
46
|
import { invariant } from "@dxos/invariant";
|
|
@@ -87,19 +89,13 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
87
89
|
disconnect() {
|
|
88
90
|
}
|
|
89
91
|
async open() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
S: this,
|
|
94
|
-
A: [
|
|
95
|
-
"this._lifecycleState === LifecycleState.CLOSED",
|
|
96
|
-
""
|
|
97
|
-
]
|
|
98
|
-
});
|
|
92
|
+
if (this._lifecycleState === LifecycleState.OPEN) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
99
95
|
this._lifecycleState = LifecycleState.OPEN;
|
|
100
96
|
log("emit ready", void 0, {
|
|
101
97
|
F: __dxlog_file,
|
|
102
|
-
L:
|
|
98
|
+
L: 65,
|
|
103
99
|
S: this,
|
|
104
100
|
C: (f, a) => f(...a)
|
|
105
101
|
});
|
|
@@ -108,15 +104,9 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
108
104
|
});
|
|
109
105
|
}
|
|
110
106
|
async close() {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
S: this,
|
|
115
|
-
A: [
|
|
116
|
-
"this._lifecycleState === LifecycleState.OPEN",
|
|
117
|
-
""
|
|
118
|
-
]
|
|
119
|
-
});
|
|
107
|
+
if (this._lifecycleState === LifecycleState.CLOSED) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
120
110
|
for (const replicator of this._replicators) {
|
|
121
111
|
await replicator.disconnect();
|
|
122
112
|
}
|
|
@@ -131,7 +121,7 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
131
121
|
async addReplicator(replicator) {
|
|
132
122
|
invariant(this._lifecycleState === LifecycleState.OPEN, void 0, {
|
|
133
123
|
F: __dxlog_file,
|
|
134
|
-
L:
|
|
124
|
+
L: 91,
|
|
135
125
|
S: this,
|
|
136
126
|
A: [
|
|
137
127
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -140,7 +130,7 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
140
130
|
});
|
|
141
131
|
invariant(this.peerId, void 0, {
|
|
142
132
|
F: __dxlog_file,
|
|
143
|
-
L:
|
|
133
|
+
L: 92,
|
|
144
134
|
S: this,
|
|
145
135
|
A: [
|
|
146
136
|
"this.peerId",
|
|
@@ -149,7 +139,7 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
149
139
|
});
|
|
150
140
|
invariant(!this._replicators.has(replicator), void 0, {
|
|
151
141
|
F: __dxlog_file,
|
|
152
|
-
L:
|
|
142
|
+
L: 93,
|
|
153
143
|
S: this,
|
|
154
144
|
A: [
|
|
155
145
|
"!this._replicators.has(replicator)",
|
|
@@ -168,7 +158,7 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
168
158
|
async removeReplicator(replicator) {
|
|
169
159
|
invariant(this._lifecycleState === LifecycleState.OPEN, void 0, {
|
|
170
160
|
F: __dxlog_file,
|
|
171
|
-
L:
|
|
161
|
+
L: 107,
|
|
172
162
|
S: this,
|
|
173
163
|
A: [
|
|
174
164
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -177,7 +167,7 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
177
167
|
});
|
|
178
168
|
invariant(this._replicators.has(replicator), void 0, {
|
|
179
169
|
F: __dxlog_file,
|
|
180
|
-
L:
|
|
170
|
+
L: 108,
|
|
181
171
|
S: this,
|
|
182
172
|
A: [
|
|
183
173
|
"this._replicators.has(replicator)",
|
|
@@ -192,20 +182,20 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
192
182
|
if (!connection) {
|
|
193
183
|
return false;
|
|
194
184
|
}
|
|
195
|
-
return connection.connection.
|
|
185
|
+
return connection.connection.shouldAdvertise(params);
|
|
196
186
|
}
|
|
197
187
|
_onConnectionOpen(connection) {
|
|
198
188
|
log("Connection opened", {
|
|
199
189
|
peerId: connection.peerId
|
|
200
190
|
}, {
|
|
201
191
|
F: __dxlog_file,
|
|
202
|
-
L:
|
|
192
|
+
L: 123,
|
|
203
193
|
S: this,
|
|
204
194
|
C: (f, a) => f(...a)
|
|
205
195
|
});
|
|
206
196
|
invariant(!this._connections.has(connection.peerId), void 0, {
|
|
207
197
|
F: __dxlog_file,
|
|
208
|
-
L:
|
|
198
|
+
L: 124,
|
|
209
199
|
S: this,
|
|
210
200
|
A: [
|
|
211
201
|
"!this._connections.has(connection.peerId as PeerId)",
|
|
@@ -234,7 +224,7 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
234
224
|
if (connectionEntry.isOpen) {
|
|
235
225
|
log.catch(err, void 0, {
|
|
236
226
|
F: __dxlog_file,
|
|
237
|
-
L:
|
|
227
|
+
L: 143,
|
|
238
228
|
S: this,
|
|
239
229
|
C: (f, a) => f(...a)
|
|
240
230
|
});
|
|
@@ -245,7 +235,7 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
245
235
|
peerId: connection.peerId
|
|
246
236
|
}, {
|
|
247
237
|
F: __dxlog_file,
|
|
248
|
-
L:
|
|
238
|
+
L: 148,
|
|
249
239
|
S: this,
|
|
250
240
|
C: (f, a) => f(...a)
|
|
251
241
|
});
|
|
@@ -260,14 +250,14 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
260
250
|
peerId: connection.peerId
|
|
261
251
|
}, {
|
|
262
252
|
F: __dxlog_file,
|
|
263
|
-
L:
|
|
253
|
+
L: 157,
|
|
264
254
|
S: this,
|
|
265
255
|
C: (f, a) => f(...a)
|
|
266
256
|
});
|
|
267
257
|
const entry = this._connections.get(connection.peerId);
|
|
268
258
|
invariant(entry, void 0, {
|
|
269
259
|
F: __dxlog_file,
|
|
270
|
-
L:
|
|
260
|
+
L: 159,
|
|
271
261
|
S: this,
|
|
272
262
|
A: [
|
|
273
263
|
"entry",
|
|
@@ -284,14 +274,14 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
284
274
|
peerId: connection.peerId
|
|
285
275
|
}, {
|
|
286
276
|
F: __dxlog_file,
|
|
287
|
-
L:
|
|
277
|
+
L: 165,
|
|
288
278
|
S: this,
|
|
289
279
|
C: (f, a) => f(...a)
|
|
290
280
|
});
|
|
291
281
|
const entry = this._connections.get(connection.peerId);
|
|
292
282
|
invariant(entry, void 0, {
|
|
293
283
|
F: __dxlog_file,
|
|
294
|
-
L:
|
|
284
|
+
L: 167,
|
|
295
285
|
S: this,
|
|
296
286
|
A: [
|
|
297
287
|
"entry",
|
|
@@ -304,13 +294,13 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
304
294
|
});
|
|
305
295
|
void entry.reader.cancel().catch((err) => log.catch(err, void 0, {
|
|
306
296
|
F: __dxlog_file,
|
|
307
|
-
L:
|
|
297
|
+
L: 172,
|
|
308
298
|
S: this,
|
|
309
299
|
C: (f, a) => f(...a)
|
|
310
300
|
}));
|
|
311
301
|
void entry.writer.abort().catch((err) => log.catch(err, void 0, {
|
|
312
302
|
F: __dxlog_file,
|
|
313
|
-
L:
|
|
303
|
+
L: 173,
|
|
314
304
|
S: this,
|
|
315
305
|
C: (f, a) => f(...a)
|
|
316
306
|
}));
|
|
@@ -341,6 +331,34 @@ var createEchoPeerMetadata = () => ({
|
|
|
341
331
|
});
|
|
342
332
|
var isEchoPeerMetadata = (metadata) => metadata?.dxos_peerSource === "EchoNetworkAdapter";
|
|
343
333
|
|
|
334
|
+
// packages/core/echo/echo-pipeline/src/automerge/heads-store.ts
|
|
335
|
+
import { headsEncoding } from "@dxos/indexing";
|
|
336
|
+
var HeadsStore = class {
|
|
337
|
+
constructor({ db }) {
|
|
338
|
+
this._db = db;
|
|
339
|
+
}
|
|
340
|
+
setHeads(documentId, heads, batch) {
|
|
341
|
+
batch.put(documentId, heads, {
|
|
342
|
+
sublevel: this._db,
|
|
343
|
+
keyEncoding: "utf8",
|
|
344
|
+
valueEncoding: headsEncoding
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
async getHeads(documentId) {
|
|
348
|
+
try {
|
|
349
|
+
return await this._db.get(documentId, {
|
|
350
|
+
keyEncoding: "utf8",
|
|
351
|
+
valueEncoding: headsEncoding
|
|
352
|
+
});
|
|
353
|
+
} catch (err) {
|
|
354
|
+
if (err.notFound) {
|
|
355
|
+
return void 0;
|
|
356
|
+
}
|
|
357
|
+
throw err;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
|
|
344
362
|
// packages/core/echo/echo-pipeline/src/automerge/leveldb-storage-adapter.ts
|
|
345
363
|
import { LifecycleState as LifecycleState2, Resource } from "@dxos/context";
|
|
346
364
|
var LevelDBStorageAdapter = class extends Resource {
|
|
@@ -587,25 +605,26 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
587
605
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
588
606
|
}
|
|
589
607
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
590
|
-
var AutomergeHost = class {
|
|
608
|
+
var AutomergeHost = class extends Resource2 {
|
|
591
609
|
constructor({ db, indexMetadataStore }) {
|
|
592
|
-
|
|
593
|
-
F: __dxlog_file3,
|
|
594
|
-
L: 71
|
|
595
|
-
});
|
|
610
|
+
super();
|
|
596
611
|
this._echoNetworkAdapter = new EchoNetworkAdapter({
|
|
597
612
|
getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
|
|
598
613
|
});
|
|
614
|
+
this._db = db;
|
|
599
615
|
this._storage = new LevelDBStorageAdapter({
|
|
600
|
-
db,
|
|
616
|
+
db: db.sublevel("automerge"),
|
|
601
617
|
callbacks: {
|
|
602
618
|
beforeSave: async (params) => this._beforeSave(params),
|
|
603
619
|
afterSave: async () => this._afterSave()
|
|
604
620
|
}
|
|
605
621
|
});
|
|
622
|
+
this._headsStore = new HeadsStore({
|
|
623
|
+
db: db.sublevel("heads")
|
|
624
|
+
});
|
|
606
625
|
this._indexMetadataStore = indexMetadataStore;
|
|
607
626
|
}
|
|
608
|
-
async
|
|
627
|
+
async _open() {
|
|
609
628
|
this._peerId = `host-${PublicKey.random().toHex()}`;
|
|
610
629
|
await this._storage.open?.();
|
|
611
630
|
this._clientNetwork = new LocalHostNetworkAdapter();
|
|
@@ -625,7 +644,7 @@ var AutomergeHost = class {
|
|
|
625
644
|
await this._clientNetwork.whenConnected();
|
|
626
645
|
await this._echoNetworkAdapter.whenConnected();
|
|
627
646
|
}
|
|
628
|
-
async
|
|
647
|
+
async _close() {
|
|
629
648
|
await this._storage.close?.();
|
|
630
649
|
await this._clientNetwork.close();
|
|
631
650
|
await this._echoNetworkAdapter.close();
|
|
@@ -676,6 +695,56 @@ var AutomergeHost = class {
|
|
|
676
695
|
return this._repo.create(initialValue);
|
|
677
696
|
}
|
|
678
697
|
}
|
|
698
|
+
async reIndexHeads(documentIds) {
|
|
699
|
+
for (const documentId of documentIds) {
|
|
700
|
+
log2.info("reindexing heads for document", {
|
|
701
|
+
documentId
|
|
702
|
+
}, {
|
|
703
|
+
F: __dxlog_file3,
|
|
704
|
+
L: 191,
|
|
705
|
+
S: this,
|
|
706
|
+
C: (f, a) => f(...a)
|
|
707
|
+
});
|
|
708
|
+
const handle = this._repo.find(documentId);
|
|
709
|
+
await handle.whenReady([
|
|
710
|
+
"ready",
|
|
711
|
+
"requesting"
|
|
712
|
+
]);
|
|
713
|
+
if (handle.inState([
|
|
714
|
+
"requesting"
|
|
715
|
+
])) {
|
|
716
|
+
log2.warn("document is not available locally, skipping", {
|
|
717
|
+
documentId
|
|
718
|
+
}, {
|
|
719
|
+
F: __dxlog_file3,
|
|
720
|
+
L: 195,
|
|
721
|
+
S: this,
|
|
722
|
+
C: (f, a) => f(...a)
|
|
723
|
+
});
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
const doc = handle.docSync();
|
|
727
|
+
invariant3(doc, void 0, {
|
|
728
|
+
F: __dxlog_file3,
|
|
729
|
+
L: 200,
|
|
730
|
+
S: this,
|
|
731
|
+
A: [
|
|
732
|
+
"doc",
|
|
733
|
+
""
|
|
734
|
+
]
|
|
735
|
+
});
|
|
736
|
+
const heads = getHeads(doc);
|
|
737
|
+
const batch = this._db.batch();
|
|
738
|
+
this._headsStore.setHeads(documentId, heads, batch);
|
|
739
|
+
await batch.write();
|
|
740
|
+
}
|
|
741
|
+
log2.info("done reindexing heads", void 0, {
|
|
742
|
+
F: __dxlog_file3,
|
|
743
|
+
L: 207,
|
|
744
|
+
S: this,
|
|
745
|
+
C: (f, a) => f(...a)
|
|
746
|
+
});
|
|
747
|
+
}
|
|
679
748
|
// TODO(dmaretskyi): Share based on HALO permissions and space affinity.
|
|
680
749
|
// Hosts, running in the worker, don't share documents unless requested by other peers.
|
|
681
750
|
// NOTE: If both peers return sharePolicy=false the replication will not happen
|
|
@@ -705,7 +774,8 @@ var AutomergeHost = class {
|
|
|
705
774
|
return;
|
|
706
775
|
}
|
|
707
776
|
const spaceKey = getSpaceKeyFromDoc(doc) ?? void 0;
|
|
708
|
-
const
|
|
777
|
+
const heads = getHeads(doc);
|
|
778
|
+
this._headsStore.setHeads(handle.documentId, heads, batch);
|
|
709
779
|
const objectIds = Object.keys(doc.objects ?? {});
|
|
710
780
|
const encodedIds = objectIds.map((objectId) => objectPointerCodec.encode({
|
|
711
781
|
documentId: handle.documentId,
|
|
@@ -714,7 +784,7 @@ var AutomergeHost = class {
|
|
|
714
784
|
}));
|
|
715
785
|
const idToLastHash = new Map(encodedIds.map((id) => [
|
|
716
786
|
id,
|
|
717
|
-
|
|
787
|
+
heads
|
|
718
788
|
]));
|
|
719
789
|
this._indexMetadataStore.markDirty(idToLastHash, batch);
|
|
720
790
|
}
|
|
@@ -763,18 +833,30 @@ var AutomergeHost = class {
|
|
|
763
833
|
/**
|
|
764
834
|
* Flush documents to disk.
|
|
765
835
|
*/
|
|
766
|
-
async flush({ states }) {
|
|
836
|
+
async flush({ states } = {}) {
|
|
767
837
|
if (states) {
|
|
768
838
|
await Promise.all(states.map(async ({ heads, documentId }) => {
|
|
769
839
|
if (!heads) {
|
|
770
840
|
return;
|
|
771
841
|
}
|
|
772
|
-
const handle = this.
|
|
842
|
+
const handle = this._repo.handles[documentId] ?? this._repo.find(documentId);
|
|
773
843
|
await waitForHeads(handle, heads);
|
|
774
844
|
}) ?? []);
|
|
775
845
|
}
|
|
776
846
|
await this._repo.flush(states?.map(({ documentId }) => documentId));
|
|
777
847
|
}
|
|
848
|
+
async getHeads(documentId) {
|
|
849
|
+
const handle = this._repo.handles[documentId];
|
|
850
|
+
if (handle) {
|
|
851
|
+
const doc = handle.docSync();
|
|
852
|
+
if (!doc) {
|
|
853
|
+
return void 0;
|
|
854
|
+
}
|
|
855
|
+
return getHeads(doc);
|
|
856
|
+
} else {
|
|
857
|
+
return this._headsStore.getHeads(documentId);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
778
860
|
/**
|
|
779
861
|
* Host <-> Client sync.
|
|
780
862
|
*/
|
|
@@ -847,8 +929,8 @@ import { interpretAsDocumentId } from "@dxos/automerge/automerge-repo";
|
|
|
847
929
|
import { cancelWithContext as cancelWithContext2 } from "@dxos/context";
|
|
848
930
|
import { warnAfterTimeout } from "@dxos/debug";
|
|
849
931
|
import { SpaceDocVersion } from "@dxos/echo-protocol";
|
|
850
|
-
import { invariant as
|
|
851
|
-
import { log as
|
|
932
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
933
|
+
import { log as log3 } from "@dxos/log";
|
|
852
934
|
import { trace as trace2 } from "@dxos/tracing";
|
|
853
935
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
854
936
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -886,7 +968,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
886
968
|
}
|
|
887
969
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
888
970
|
const doc = existingDocHandle.docSync();
|
|
889
|
-
|
|
971
|
+
invariant4(doc, void 0, {
|
|
890
972
|
F: __dxlog_file4,
|
|
891
973
|
L: 84,
|
|
892
974
|
S: this,
|
|
@@ -895,7 +977,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
895
977
|
""
|
|
896
978
|
]
|
|
897
979
|
});
|
|
898
|
-
|
|
980
|
+
invariant4(doc.version === SpaceDocVersion.CURRENT, void 0, {
|
|
899
981
|
F: __dxlog_file4,
|
|
900
982
|
L: 85,
|
|
901
983
|
S: this,
|
|
@@ -916,7 +998,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
916
998
|
let hasUrlsToLoad = false;
|
|
917
999
|
const urlsToLoad = {};
|
|
918
1000
|
for (const objectId of objectIds) {
|
|
919
|
-
|
|
1001
|
+
invariant4(this._spaceRootDocHandle, void 0, {
|
|
920
1002
|
F: __dxlog_file4,
|
|
921
1003
|
L: 97,
|
|
922
1004
|
S: this,
|
|
@@ -929,7 +1011,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
929
1011
|
continue;
|
|
930
1012
|
}
|
|
931
1013
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
932
|
-
|
|
1014
|
+
invariant4(spaceRootDoc, void 0, {
|
|
933
1015
|
F: __dxlog_file4,
|
|
934
1016
|
L: 102,
|
|
935
1017
|
S: this,
|
|
@@ -941,7 +1023,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
941
1023
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
942
1024
|
if (documentUrl == null) {
|
|
943
1025
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
944
|
-
|
|
1026
|
+
log3.info("loading delayed until object links are initialized", {
|
|
945
1027
|
objectId
|
|
946
1028
|
}, {
|
|
947
1029
|
F: __dxlog_file4,
|
|
@@ -959,7 +1041,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
959
1041
|
}
|
|
960
1042
|
}
|
|
961
1043
|
getObjectDocumentId(objectId) {
|
|
962
|
-
|
|
1044
|
+
invariant4(this._spaceRootDocHandle, void 0, {
|
|
963
1045
|
F: __dxlog_file4,
|
|
964
1046
|
L: 118,
|
|
965
1047
|
S: this,
|
|
@@ -969,7 +1051,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
969
1051
|
]
|
|
970
1052
|
});
|
|
971
1053
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
972
|
-
|
|
1054
|
+
invariant4(spaceRootDoc, void 0, {
|
|
973
1055
|
F: __dxlog_file4,
|
|
974
1056
|
L: 120,
|
|
975
1057
|
S: this,
|
|
@@ -993,7 +1075,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
993
1075
|
linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
|
|
994
1076
|
}
|
|
995
1077
|
getSpaceRootDocHandle() {
|
|
996
|
-
|
|
1078
|
+
invariant4(this._spaceRootDocHandle, void 0, {
|
|
997
1079
|
F: __dxlog_file4,
|
|
998
1080
|
L: 140,
|
|
999
1081
|
S: this,
|
|
@@ -1005,7 +1087,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1005
1087
|
return this._spaceRootDocHandle;
|
|
1006
1088
|
}
|
|
1007
1089
|
createDocumentForObject(objectId) {
|
|
1008
|
-
|
|
1090
|
+
invariant4(this._spaceRootDocHandle, void 0, {
|
|
1009
1091
|
F: __dxlog_file4,
|
|
1010
1092
|
L: 145,
|
|
1011
1093
|
S: this,
|
|
@@ -1047,7 +1129,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1047
1129
|
};
|
|
1048
1130
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
1049
1131
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
1050
|
-
|
|
1132
|
+
log3.warn("object already inlined in a different document, ignoring the link", {
|
|
1051
1133
|
...logMeta,
|
|
1052
1134
|
actualDocumentUrl: objectDocumentHandle.url
|
|
1053
1135
|
}, {
|
|
@@ -1059,7 +1141,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1059
1141
|
continue;
|
|
1060
1142
|
}
|
|
1061
1143
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
1062
|
-
|
|
1144
|
+
log3.warn("object document was already loaded", logMeta, {
|
|
1063
1145
|
F: __dxlog_file4,
|
|
1064
1146
|
L: 184,
|
|
1065
1147
|
S: this,
|
|
@@ -1068,7 +1150,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1068
1150
|
continue;
|
|
1069
1151
|
}
|
|
1070
1152
|
const handle = this._repo.find(automergeUrl);
|
|
1071
|
-
|
|
1153
|
+
log3.debug("document loading triggered", logMeta, {
|
|
1072
1154
|
F: __dxlog_file4,
|
|
1073
1155
|
L: 188,
|
|
1074
1156
|
S: this,
|
|
@@ -1088,7 +1170,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1088
1170
|
break;
|
|
1089
1171
|
} catch (err) {
|
|
1090
1172
|
if (`${err}`.includes("Timeout")) {
|
|
1091
|
-
|
|
1173
|
+
log3.info("wraparound", {
|
|
1092
1174
|
id: docHandle.documentId,
|
|
1093
1175
|
state: docHandle.state
|
|
1094
1176
|
}, {
|
|
@@ -1117,15 +1199,13 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1117
1199
|
}
|
|
1118
1200
|
async _createObjectOnDocumentLoad(handle, objectId) {
|
|
1119
1201
|
try {
|
|
1120
|
-
await handle.
|
|
1121
|
-
"ready"
|
|
1122
|
-
]);
|
|
1202
|
+
await handle.whenReady();
|
|
1123
1203
|
const logMeta = {
|
|
1124
1204
|
objectId,
|
|
1125
1205
|
docUrl: handle.url
|
|
1126
1206
|
};
|
|
1127
1207
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1128
|
-
|
|
1208
|
+
log3.info("document loaded after all listeners were removed", logMeta, {
|
|
1129
1209
|
F: __dxlog_file4,
|
|
1130
1210
|
L: 231,
|
|
1131
1211
|
S: this,
|
|
@@ -1135,7 +1215,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1135
1215
|
}
|
|
1136
1216
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
1137
1217
|
if (objectDocHandle?.url !== handle.url) {
|
|
1138
|
-
|
|
1218
|
+
log3.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1139
1219
|
F: __dxlog_file4,
|
|
1140
1220
|
L: 236,
|
|
1141
1221
|
S: this,
|
|
@@ -1149,7 +1229,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1149
1229
|
});
|
|
1150
1230
|
} catch (err) {
|
|
1151
1231
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1152
|
-
|
|
1232
|
+
log3.warn("failed to load a document", {
|
|
1153
1233
|
objectId,
|
|
1154
1234
|
automergeUrl: handle.url,
|
|
1155
1235
|
retryLoading: shouldRetryLoading,
|
|
@@ -1177,10 +1257,10 @@ AutomergeDocumentLoaderImpl = _ts_decorate3([
|
|
|
1177
1257
|
|
|
1178
1258
|
// packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts
|
|
1179
1259
|
import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
|
|
1180
|
-
import { Resource as
|
|
1181
|
-
import { invariant as
|
|
1260
|
+
import { Resource as Resource3 } from "@dxos/context";
|
|
1261
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1182
1262
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
1183
|
-
import { log as
|
|
1263
|
+
import { log as log4 } from "@dxos/log";
|
|
1184
1264
|
import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
|
|
1185
1265
|
import { ComplexMap, ComplexSet, defaultMap } from "@dxos/util";
|
|
1186
1266
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
|
|
@@ -1209,7 +1289,7 @@ var MeshEchoReplicator = class {
|
|
|
1209
1289
|
this._context = null;
|
|
1210
1290
|
}
|
|
1211
1291
|
createExtension() {
|
|
1212
|
-
|
|
1292
|
+
invariant5(this._context, void 0, {
|
|
1213
1293
|
F: __dxlog_file5,
|
|
1214
1294
|
L: 54,
|
|
1215
1295
|
S: this,
|
|
@@ -1221,7 +1301,7 @@ var MeshEchoReplicator = class {
|
|
|
1221
1301
|
const connection = new MeshReplicatorConnection({
|
|
1222
1302
|
ownPeerId: this._context.peerId,
|
|
1223
1303
|
onRemoteConnected: async () => {
|
|
1224
|
-
|
|
1304
|
+
log4("onRemoteConnected", {
|
|
1225
1305
|
peerId: connection.peerId
|
|
1226
1306
|
}, {
|
|
1227
1307
|
F: __dxlog_file5,
|
|
@@ -1229,7 +1309,7 @@ var MeshEchoReplicator = class {
|
|
|
1229
1309
|
S: this,
|
|
1230
1310
|
C: (f, a) => f(...a)
|
|
1231
1311
|
});
|
|
1232
|
-
|
|
1312
|
+
invariant5(this._context, void 0, {
|
|
1233
1313
|
F: __dxlog_file5,
|
|
1234
1314
|
L: 60,
|
|
1235
1315
|
S: this,
|
|
@@ -1247,7 +1327,7 @@ var MeshEchoReplicator = class {
|
|
|
1247
1327
|
}
|
|
1248
1328
|
},
|
|
1249
1329
|
onRemoteDisconnected: async () => {
|
|
1250
|
-
|
|
1330
|
+
log4("onRemoteDisconnected", {
|
|
1251
1331
|
peerId: connection.peerId
|
|
1252
1332
|
}, {
|
|
1253
1333
|
F: __dxlog_file5,
|
|
@@ -1261,7 +1341,7 @@ var MeshEchoReplicator = class {
|
|
|
1261
1341
|
this._connections.delete(connection);
|
|
1262
1342
|
},
|
|
1263
1343
|
shouldAdvertize: async (params) => {
|
|
1264
|
-
|
|
1344
|
+
log4("shouldAdvertize", {
|
|
1265
1345
|
peerId: connection.peerId,
|
|
1266
1346
|
documentId: params.documentId
|
|
1267
1347
|
}, {
|
|
@@ -1270,7 +1350,7 @@ var MeshEchoReplicator = class {
|
|
|
1270
1350
|
S: this,
|
|
1271
1351
|
C: (f, a) => f(...a)
|
|
1272
1352
|
});
|
|
1273
|
-
|
|
1353
|
+
invariant5(this._context, void 0, {
|
|
1274
1354
|
F: __dxlog_file5,
|
|
1275
1355
|
L: 79,
|
|
1276
1356
|
S: this,
|
|
@@ -1282,7 +1362,7 @@ var MeshEchoReplicator = class {
|
|
|
1282
1362
|
try {
|
|
1283
1363
|
const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
|
|
1284
1364
|
if (!spaceKey) {
|
|
1285
|
-
|
|
1365
|
+
log4("space key not found for share policy check", {
|
|
1286
1366
|
peerId: connection.peerId,
|
|
1287
1367
|
documentId: params.documentId
|
|
1288
1368
|
}, {
|
|
@@ -1295,7 +1375,7 @@ var MeshEchoReplicator = class {
|
|
|
1295
1375
|
}
|
|
1296
1376
|
const authorizedDevices = this._authorizedDevices.get(spaceKey);
|
|
1297
1377
|
if (!connection.remoteDeviceKey) {
|
|
1298
|
-
|
|
1378
|
+
log4("device key not found for share policy check", {
|
|
1299
1379
|
peerId: connection.peerId,
|
|
1300
1380
|
documentId: params.documentId
|
|
1301
1381
|
}, {
|
|
@@ -1307,7 +1387,7 @@ var MeshEchoReplicator = class {
|
|
|
1307
1387
|
return false;
|
|
1308
1388
|
}
|
|
1309
1389
|
const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
|
|
1310
|
-
|
|
1390
|
+
log4("share policy check", {
|
|
1311
1391
|
localPeer: this._context.peerId,
|
|
1312
1392
|
remotePeer: connection.peerId,
|
|
1313
1393
|
documentId: params.documentId,
|
|
@@ -1322,7 +1402,7 @@ var MeshEchoReplicator = class {
|
|
|
1322
1402
|
});
|
|
1323
1403
|
return isAuthorized;
|
|
1324
1404
|
} catch (err) {
|
|
1325
|
-
|
|
1405
|
+
log4.catch(err, void 0, {
|
|
1326
1406
|
F: __dxlog_file5,
|
|
1327
1407
|
L: 111,
|
|
1328
1408
|
S: this,
|
|
@@ -1336,7 +1416,7 @@ var MeshEchoReplicator = class {
|
|
|
1336
1416
|
return connection.replicatorExtension;
|
|
1337
1417
|
}
|
|
1338
1418
|
authorizeDevice(spaceKey, deviceKey) {
|
|
1339
|
-
|
|
1419
|
+
log4("authorizeDevice", {
|
|
1340
1420
|
spaceKey,
|
|
1341
1421
|
deviceKey
|
|
1342
1422
|
}, {
|
|
@@ -1353,7 +1433,7 @@ var MeshEchoReplicator = class {
|
|
|
1353
1433
|
}
|
|
1354
1434
|
}
|
|
1355
1435
|
};
|
|
1356
|
-
var MeshReplicatorConnection = class extends
|
|
1436
|
+
var MeshReplicatorConnection = class extends Resource3 {
|
|
1357
1437
|
constructor(_params) {
|
|
1358
1438
|
super();
|
|
1359
1439
|
this._params = _params;
|
|
@@ -1382,7 +1462,7 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1382
1462
|
onStartReplication: async (info, remotePeerId) => {
|
|
1383
1463
|
this.remoteDeviceKey = remotePeerId;
|
|
1384
1464
|
this._remotePeerId = info.id;
|
|
1385
|
-
|
|
1465
|
+
log4("onStartReplication", {
|
|
1386
1466
|
id: info.id,
|
|
1387
1467
|
thisPeerId: this.peerId,
|
|
1388
1468
|
remotePeerId: remotePeerId.toHex()
|
|
@@ -1410,7 +1490,7 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1410
1490
|
});
|
|
1411
1491
|
}
|
|
1412
1492
|
get peerId() {
|
|
1413
|
-
|
|
1493
|
+
invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1414
1494
|
F: __dxlog_file5,
|
|
1415
1495
|
L: 215,
|
|
1416
1496
|
S: this,
|
|
@@ -1421,7 +1501,7 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1421
1501
|
});
|
|
1422
1502
|
return this._remotePeerId;
|
|
1423
1503
|
}
|
|
1424
|
-
async
|
|
1504
|
+
async shouldAdvertise(params) {
|
|
1425
1505
|
return this._params.shouldAdvertize(params);
|
|
1426
1506
|
}
|
|
1427
1507
|
/**
|
|
@@ -1429,7 +1509,7 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1429
1509
|
* Call after the remote peer has connected.
|
|
1430
1510
|
*/
|
|
1431
1511
|
async enable() {
|
|
1432
|
-
|
|
1512
|
+
invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1433
1513
|
F: __dxlog_file5,
|
|
1434
1514
|
L: 228,
|
|
1435
1515
|
S: this,
|