@dxos/echo-pipeline 0.5.9-main.5d79202 → 0.5.9-main.72c50cd
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/index.mjs +207 -121
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +203 -122
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/automerge/automerge-host.d.ts +8 -1
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/automerge-storage-adapter.d.ts +16 -0
- package/dist/types/src/automerge/automerge-storage-adapter.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts +25 -0
- package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts.map +1 -0
- package/dist/types/src/automerge/echo-network-adapter.d.ts +0 -6
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-replicator.d.ts +0 -1
- package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
- package/dist/types/src/automerge/index.d.ts +1 -0
- package/dist/types/src/automerge/index.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
- package/dist/types/src/automerge/migrations.d.ts +7 -0
- package/dist/types/src/automerge/migrations.d.ts.map +1 -0
- package/package.json +33 -33
- package/src/automerge/automerge-host.ts +21 -8
- package/src/automerge/automerge-storage-adapter.ts +103 -0
- package/src/automerge/automerge-storage/342/200/223wrapper.ts +59 -0
- package/src/automerge/echo-network-adapter.ts +8 -24
- package/src/automerge/echo-replicator.ts +0 -2
- package/src/automerge/index.ts +1 -0
- package/src/automerge/mesh-echo-replicator.ts +1 -3
- package/src/automerge/migrations.ts +42 -0
- package/src/automerge/storage-adapter.test.ts +139 -103
- package/src/space/space-protocol.test.ts +0 -2
|
@@ -32,7 +32,7 @@ import { Repo } from "@dxos/automerge/automerge-repo";
|
|
|
32
32
|
import { Context } from "@dxos/context";
|
|
33
33
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
34
34
|
import { PublicKey } from "@dxos/keys";
|
|
35
|
-
import { log as
|
|
35
|
+
import { log as log3 } from "@dxos/log";
|
|
36
36
|
import { objectPointerCodec } from "@dxos/protocols";
|
|
37
37
|
import { trace } from "@dxos/tracing";
|
|
38
38
|
import { mapValues } from "@dxos/util";
|
|
@@ -161,14 +161,13 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
161
161
|
peerId: this.peerId,
|
|
162
162
|
onConnectionOpen: this._onConnectionOpen.bind(this),
|
|
163
163
|
onConnectionClosed: this._onConnectionClosed.bind(this),
|
|
164
|
-
onConnectionAuthScopeChanged: this._onConnectionAuthScopeChanged.bind(this),
|
|
165
164
|
getContainingSpaceForDocument: this._params.getContainingSpaceForDocument
|
|
166
165
|
});
|
|
167
166
|
}
|
|
168
167
|
async removeReplicator(replicator) {
|
|
169
168
|
invariant(this._lifecycleState === LifecycleState.OPEN, void 0, {
|
|
170
169
|
F: __dxlog_file,
|
|
171
|
-
L:
|
|
170
|
+
L: 102,
|
|
172
171
|
S: this,
|
|
173
172
|
A: [
|
|
174
173
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -177,13 +176,14 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
177
176
|
});
|
|
178
177
|
invariant(this._replicators.has(replicator), void 0, {
|
|
179
178
|
F: __dxlog_file,
|
|
180
|
-
L:
|
|
179
|
+
L: 103,
|
|
181
180
|
S: this,
|
|
182
181
|
A: [
|
|
183
182
|
"this._replicators.has(replicator)",
|
|
184
183
|
""
|
|
185
184
|
]
|
|
186
185
|
});
|
|
186
|
+
"";
|
|
187
187
|
await replicator.disconnect();
|
|
188
188
|
this._replicators.delete(replicator);
|
|
189
189
|
}
|
|
@@ -249,49 +249,27 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
249
249
|
S: this,
|
|
250
250
|
C: (f, a) => f(...a)
|
|
251
251
|
});
|
|
252
|
-
this.
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
_onConnectionAuthScopeChanged(connection) {
|
|
259
|
-
log("Connection auth scope changed", {
|
|
260
|
-
peerId: connection.peerId
|
|
261
|
-
}, {
|
|
262
|
-
F: __dxlog_file,
|
|
263
|
-
L: 153,
|
|
264
|
-
S: this,
|
|
265
|
-
C: (f, a) => f(...a)
|
|
266
|
-
});
|
|
267
|
-
const entry = this._connections.get(connection.peerId);
|
|
268
|
-
invariant(entry, void 0, {
|
|
269
|
-
F: __dxlog_file,
|
|
270
|
-
L: 155,
|
|
271
|
-
S: this,
|
|
272
|
-
A: [
|
|
273
|
-
"entry",
|
|
274
|
-
""
|
|
275
|
-
]
|
|
276
|
-
});
|
|
277
|
-
this.emit("peer-disconnected", {
|
|
278
|
-
peerId: connection.peerId
|
|
252
|
+
this.emit("peer-candidate", {
|
|
253
|
+
peerId: connection.peerId,
|
|
254
|
+
peerMetadata: {
|
|
255
|
+
// TODO(dmaretskyi): Refactor this.
|
|
256
|
+
dxos_peerSource: "EchoNetworkAdapter"
|
|
257
|
+
}
|
|
279
258
|
});
|
|
280
|
-
this._emitPeerCandidate(connection);
|
|
281
259
|
}
|
|
282
260
|
_onConnectionClosed(connection) {
|
|
283
261
|
log("Connection closed", {
|
|
284
262
|
peerId: connection.peerId
|
|
285
263
|
}, {
|
|
286
264
|
F: __dxlog_file,
|
|
287
|
-
L:
|
|
265
|
+
L: 155,
|
|
288
266
|
S: this,
|
|
289
267
|
C: (f, a) => f(...a)
|
|
290
268
|
});
|
|
291
269
|
const entry = this._connections.get(connection.peerId);
|
|
292
270
|
invariant(entry, void 0, {
|
|
293
271
|
F: __dxlog_file,
|
|
294
|
-
L:
|
|
272
|
+
L: 157,
|
|
295
273
|
S: this,
|
|
296
274
|
A: [
|
|
297
275
|
"entry",
|
|
@@ -304,27 +282,18 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
304
282
|
});
|
|
305
283
|
void entry.reader.cancel().catch((err) => log.catch(err, void 0, {
|
|
306
284
|
F: __dxlog_file,
|
|
307
|
-
L:
|
|
285
|
+
L: 162,
|
|
308
286
|
S: this,
|
|
309
287
|
C: (f, a) => f(...a)
|
|
310
288
|
}));
|
|
311
289
|
void entry.writer.abort().catch((err) => log.catch(err, void 0, {
|
|
312
290
|
F: __dxlog_file,
|
|
313
|
-
L:
|
|
291
|
+
L: 163,
|
|
314
292
|
S: this,
|
|
315
293
|
C: (f, a) => f(...a)
|
|
316
294
|
}));
|
|
317
295
|
this._connections.delete(connection.peerId);
|
|
318
296
|
}
|
|
319
|
-
_emitPeerCandidate(connection) {
|
|
320
|
-
this.emit("peer-candidate", {
|
|
321
|
-
peerId: connection.peerId,
|
|
322
|
-
peerMetadata: {
|
|
323
|
-
// TODO(dmaretskyi): Refactor this.
|
|
324
|
-
dxos_peerSource: "EchoNetworkAdapter"
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
297
|
};
|
|
329
298
|
_ts_decorate([
|
|
330
299
|
synchronized
|
|
@@ -573,6 +542,118 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
573
542
|
}
|
|
574
543
|
};
|
|
575
544
|
|
|
545
|
+
// packages/core/echo/echo-pipeline/src/automerge/migrations.ts
|
|
546
|
+
import { IndexedDBStorageAdapter } from "@dxos/automerge/automerge-repo-storage-indexeddb";
|
|
547
|
+
import { log as log2 } from "@dxos/log";
|
|
548
|
+
import { StorageType } from "@dxos/random-access-storage";
|
|
549
|
+
|
|
550
|
+
// packages/core/echo/echo-pipeline/src/automerge/automerge-storage-adapter.ts
|
|
551
|
+
import { arrayToBuffer, bufferToArray } from "@dxos/util";
|
|
552
|
+
var AutomergeStorageAdapter = class {
|
|
553
|
+
constructor(_directory) {
|
|
554
|
+
this._directory = _directory;
|
|
555
|
+
this._state = "opened";
|
|
556
|
+
}
|
|
557
|
+
async load(key) {
|
|
558
|
+
if (this._state !== "opened") {
|
|
559
|
+
return void 0;
|
|
560
|
+
}
|
|
561
|
+
const filename = this._getFilename(key);
|
|
562
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
563
|
+
const { size } = await file.stat();
|
|
564
|
+
if (!size || size === 0) {
|
|
565
|
+
return void 0;
|
|
566
|
+
}
|
|
567
|
+
const buffer = await file.read(0, size);
|
|
568
|
+
return bufferToArray(buffer);
|
|
569
|
+
}
|
|
570
|
+
async save(key, data) {
|
|
571
|
+
if (this._state !== "opened") {
|
|
572
|
+
return void 0;
|
|
573
|
+
}
|
|
574
|
+
const filename = this._getFilename(key);
|
|
575
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
576
|
+
await file.write(0, arrayToBuffer(data));
|
|
577
|
+
await file.truncate?.(data.length);
|
|
578
|
+
await file.flush?.();
|
|
579
|
+
}
|
|
580
|
+
async remove(key) {
|
|
581
|
+
if (this._state !== "opened") {
|
|
582
|
+
return void 0;
|
|
583
|
+
}
|
|
584
|
+
const filename = this._getFilename(key);
|
|
585
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
586
|
+
await file.destroy();
|
|
587
|
+
}
|
|
588
|
+
async loadRange(keyPrefix) {
|
|
589
|
+
if (this._state !== "opened") {
|
|
590
|
+
return [];
|
|
591
|
+
}
|
|
592
|
+
const filename = this._getFilename(keyPrefix);
|
|
593
|
+
const entries = await this._directory.list();
|
|
594
|
+
return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
595
|
+
const file = this._directory.getOrCreateFile(entry);
|
|
596
|
+
const { size } = await file.stat();
|
|
597
|
+
const buffer = await file.read(0, size);
|
|
598
|
+
return {
|
|
599
|
+
key: this._getKeyFromFilename(entry),
|
|
600
|
+
data: bufferToArray(buffer)
|
|
601
|
+
};
|
|
602
|
+
}));
|
|
603
|
+
}
|
|
604
|
+
async removeRange(keyPrefix) {
|
|
605
|
+
if (this._state !== "opened") {
|
|
606
|
+
return void 0;
|
|
607
|
+
}
|
|
608
|
+
const filename = this._getFilename(keyPrefix);
|
|
609
|
+
const entries = await this._directory.list();
|
|
610
|
+
await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
611
|
+
const file = this._directory.getOrCreateFile(entry);
|
|
612
|
+
await file.destroy();
|
|
613
|
+
}));
|
|
614
|
+
}
|
|
615
|
+
async close() {
|
|
616
|
+
this._state = "closed";
|
|
617
|
+
}
|
|
618
|
+
_getFilename(key) {
|
|
619
|
+
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
620
|
+
}
|
|
621
|
+
_getKeyFromFilename(filename) {
|
|
622
|
+
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
// packages/core/echo/echo-pipeline/src/automerge/migrations.ts
|
|
627
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
|
|
628
|
+
var levelMigration = async ({ db, directory }) => {
|
|
629
|
+
const isNewLevel = !await db.iterator({
|
|
630
|
+
...encodingOptions
|
|
631
|
+
}).next();
|
|
632
|
+
if (!isNewLevel) {
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
const oldStorageAdapter = directory.type === StorageType.IDB ? new IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory);
|
|
636
|
+
const chunks = await oldStorageAdapter.loadRange([]);
|
|
637
|
+
if (chunks.length === 0) {
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
const batch = db.batch();
|
|
641
|
+
log2.info("found chunks on old storage adapter", {
|
|
642
|
+
chunks: chunks.length
|
|
643
|
+
}, {
|
|
644
|
+
F: __dxlog_file3,
|
|
645
|
+
L: 37,
|
|
646
|
+
S: void 0,
|
|
647
|
+
C: (f, a) => f(...a)
|
|
648
|
+
});
|
|
649
|
+
for (const { key, data } of await oldStorageAdapter.loadRange([])) {
|
|
650
|
+
data && batch.put(key, data, {
|
|
651
|
+
...encodingOptions
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
await batch.write();
|
|
655
|
+
};
|
|
656
|
+
|
|
576
657
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
577
658
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
578
659
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -584,25 +665,31 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
584
665
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
585
666
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
586
667
|
}
|
|
587
|
-
var
|
|
668
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
588
669
|
var AutomergeHost = class {
|
|
589
|
-
constructor({ db, indexMetadataStore }) {
|
|
670
|
+
constructor({ directory, db, indexMetadataStore }) {
|
|
590
671
|
this._ctx = new Context();
|
|
591
672
|
this._echoNetworkAdapter = new EchoNetworkAdapter({
|
|
592
673
|
getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
|
|
593
674
|
});
|
|
594
675
|
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
676
|
+
this._directory = directory;
|
|
677
|
+
this._db = db;
|
|
678
|
+
this._indexMetadataStore = indexMetadataStore;
|
|
679
|
+
}
|
|
680
|
+
async open() {
|
|
681
|
+
this._peerId = `host-${PublicKey.random().toHex()}`;
|
|
682
|
+
this._directory && await levelMigration({
|
|
683
|
+
db: this._db,
|
|
684
|
+
directory: this._directory
|
|
685
|
+
});
|
|
595
686
|
this._storage = new LevelDBStorageAdapter({
|
|
596
|
-
db,
|
|
687
|
+
db: this._db,
|
|
597
688
|
callbacks: {
|
|
598
689
|
beforeSave: async (params) => this._beforeSave(params),
|
|
599
690
|
afterSave: async () => this._afterSave()
|
|
600
691
|
}
|
|
601
692
|
});
|
|
602
|
-
this._indexMetadataStore = indexMetadataStore;
|
|
603
|
-
}
|
|
604
|
-
async open() {
|
|
605
|
-
this._peerId = `host-${PublicKey.random().toHex()}`;
|
|
606
693
|
await this._storage.open?.();
|
|
607
694
|
this._clientNetwork = new LocalHostNetworkAdapter();
|
|
608
695
|
this._repo = new Repo({
|
|
@@ -650,13 +737,13 @@ var AutomergeHost = class {
|
|
|
650
737
|
const doc = this._repo.handles[documentId]?.docSync();
|
|
651
738
|
if (!doc) {
|
|
652
739
|
const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
|
|
653
|
-
|
|
740
|
+
log3("doc share policy check", {
|
|
654
741
|
peerId,
|
|
655
742
|
documentId,
|
|
656
743
|
isRequested
|
|
657
744
|
}, {
|
|
658
|
-
F:
|
|
659
|
-
L:
|
|
745
|
+
F: __dxlog_file4,
|
|
746
|
+
L: 156,
|
|
660
747
|
S: this,
|
|
661
748
|
C: (f, a) => f(...a)
|
|
662
749
|
});
|
|
@@ -741,8 +828,8 @@ var AutomergeHost = class {
|
|
|
741
828
|
async flush({ states }) {
|
|
742
829
|
await Promise.all(states?.map(async ({ heads, documentId }) => {
|
|
743
830
|
invariant3(heads, "heads are required for flush", {
|
|
744
|
-
F:
|
|
745
|
-
L:
|
|
831
|
+
F: __dxlog_file4,
|
|
832
|
+
L: 250,
|
|
746
833
|
S: this,
|
|
747
834
|
A: [
|
|
748
835
|
"heads",
|
|
@@ -816,7 +903,7 @@ import { Event as Event2 } from "@dxos/async";
|
|
|
816
903
|
import { cancelWithContext } from "@dxos/context";
|
|
817
904
|
import { warnAfterTimeout } from "@dxos/debug";
|
|
818
905
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
819
|
-
import { log as
|
|
906
|
+
import { log as log4 } from "@dxos/log";
|
|
820
907
|
import { trace as trace2 } from "@dxos/tracing";
|
|
821
908
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
822
909
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -828,7 +915,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
828
915
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
829
916
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
830
917
|
}
|
|
831
|
-
var
|
|
918
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
832
919
|
var AutomergeDocumentLoaderImpl = class {
|
|
833
920
|
constructor(_spaceId, _repo, _spaceKey) {
|
|
834
921
|
this._spaceId = _spaceId;
|
|
@@ -850,10 +937,10 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
850
937
|
return;
|
|
851
938
|
}
|
|
852
939
|
if (!spaceState.rootUrl) {
|
|
853
|
-
|
|
940
|
+
log4.error("Database opened with no rootUrl", {
|
|
854
941
|
spaceId: this._spaceId
|
|
855
942
|
}, {
|
|
856
|
-
F:
|
|
943
|
+
F: __dxlog_file5,
|
|
857
944
|
L: 72,
|
|
858
945
|
S: this,
|
|
859
946
|
C: (f, a) => f(...a)
|
|
@@ -863,7 +950,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
863
950
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
864
951
|
const doc = existingDocHandle.docSync();
|
|
865
952
|
invariant4(doc, void 0, {
|
|
866
|
-
F:
|
|
953
|
+
F: __dxlog_file5,
|
|
867
954
|
L: 77,
|
|
868
955
|
S: this,
|
|
869
956
|
A: [
|
|
@@ -885,7 +972,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
885
972
|
const urlsToLoad = {};
|
|
886
973
|
for (const objectId of objectIds) {
|
|
887
974
|
invariant4(this._spaceRootDocHandle, void 0, {
|
|
888
|
-
F:
|
|
975
|
+
F: __dxlog_file5,
|
|
889
976
|
L: 90,
|
|
890
977
|
S: this,
|
|
891
978
|
A: [
|
|
@@ -898,7 +985,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
898
985
|
}
|
|
899
986
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
900
987
|
invariant4(spaceRootDoc, void 0, {
|
|
901
|
-
F:
|
|
988
|
+
F: __dxlog_file5,
|
|
902
989
|
L: 95,
|
|
903
990
|
S: this,
|
|
904
991
|
A: [
|
|
@@ -909,10 +996,10 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
909
996
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
910
997
|
if (documentUrl == null) {
|
|
911
998
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
912
|
-
|
|
999
|
+
log4.info("loading delayed until object links are initialized", {
|
|
913
1000
|
objectId
|
|
914
1001
|
}, {
|
|
915
|
-
F:
|
|
1002
|
+
F: __dxlog_file5,
|
|
916
1003
|
L: 99,
|
|
917
1004
|
S: this,
|
|
918
1005
|
C: (f, a) => f(...a)
|
|
@@ -936,7 +1023,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
936
1023
|
}
|
|
937
1024
|
getSpaceRootDocHandle() {
|
|
938
1025
|
invariant4(this._spaceRootDocHandle, void 0, {
|
|
939
|
-
F:
|
|
1026
|
+
F: __dxlog_file5,
|
|
940
1027
|
L: 122,
|
|
941
1028
|
S: this,
|
|
942
1029
|
A: [
|
|
@@ -948,7 +1035,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
948
1035
|
}
|
|
949
1036
|
createDocumentForObject(objectId) {
|
|
950
1037
|
invariant4(this._spaceRootDocHandle, void 0, {
|
|
951
|
-
F:
|
|
1038
|
+
F: __dxlog_file5,
|
|
952
1039
|
L: 127,
|
|
953
1040
|
S: this,
|
|
954
1041
|
A: [
|
|
@@ -987,11 +1074,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
987
1074
|
};
|
|
988
1075
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
989
1076
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
990
|
-
|
|
1077
|
+
log4.warn("object already inlined in a different document, ignoring the link", {
|
|
991
1078
|
...logMeta,
|
|
992
1079
|
actualDocumentUrl: objectDocumentHandle.url
|
|
993
1080
|
}, {
|
|
994
|
-
F:
|
|
1081
|
+
F: __dxlog_file5,
|
|
995
1082
|
L: 157,
|
|
996
1083
|
S: this,
|
|
997
1084
|
C: (f, a) => f(...a)
|
|
@@ -999,8 +1086,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
999
1086
|
continue;
|
|
1000
1087
|
}
|
|
1001
1088
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
1002
|
-
|
|
1003
|
-
F:
|
|
1089
|
+
log4.warn("object document was already loaded", logMeta, {
|
|
1090
|
+
F: __dxlog_file5,
|
|
1004
1091
|
L: 164,
|
|
1005
1092
|
S: this,
|
|
1006
1093
|
C: (f, a) => f(...a)
|
|
@@ -1008,8 +1095,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1008
1095
|
continue;
|
|
1009
1096
|
}
|
|
1010
1097
|
const handle = this._repo.find(automergeUrl);
|
|
1011
|
-
|
|
1012
|
-
F:
|
|
1098
|
+
log4.debug("document loading triggered", logMeta, {
|
|
1099
|
+
F: __dxlog_file5,
|
|
1013
1100
|
L: 168,
|
|
1014
1101
|
S: this,
|
|
1015
1102
|
C: (f, a) => f(...a)
|
|
@@ -1028,11 +1115,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1028
1115
|
break;
|
|
1029
1116
|
} catch (err) {
|
|
1030
1117
|
if (`${err}`.includes("Timeout")) {
|
|
1031
|
-
|
|
1118
|
+
log4.info("wraparound", {
|
|
1032
1119
|
id: docHandle.documentId,
|
|
1033
1120
|
state: docHandle.state
|
|
1034
1121
|
}, {
|
|
1035
|
-
F:
|
|
1122
|
+
F: __dxlog_file5,
|
|
1036
1123
|
L: 184,
|
|
1037
1124
|
S: this,
|
|
1038
1125
|
C: (f, a) => f(...a)
|
|
@@ -1073,8 +1160,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1073
1160
|
docUrl: handle.url
|
|
1074
1161
|
};
|
|
1075
1162
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1076
|
-
|
|
1077
|
-
F:
|
|
1163
|
+
log4.info("document loaded after all listeners were removed", logMeta, {
|
|
1164
|
+
F: __dxlog_file5,
|
|
1078
1165
|
L: 220,
|
|
1079
1166
|
S: this,
|
|
1080
1167
|
C: (f, a) => f(...a)
|
|
@@ -1083,8 +1170,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1083
1170
|
}
|
|
1084
1171
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
1085
1172
|
if (objectDocHandle?.url !== handle.url) {
|
|
1086
|
-
|
|
1087
|
-
F:
|
|
1173
|
+
log4.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1174
|
+
F: __dxlog_file5,
|
|
1088
1175
|
L: 225,
|
|
1089
1176
|
S: this,
|
|
1090
1177
|
C: (f, a) => f(...a)
|
|
@@ -1097,13 +1184,13 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1097
1184
|
});
|
|
1098
1185
|
} catch (err) {
|
|
1099
1186
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1100
|
-
|
|
1187
|
+
log4.warn("failed to load a document", {
|
|
1101
1188
|
objectId,
|
|
1102
1189
|
automergeUrl: handle.url,
|
|
1103
1190
|
retryLoading: shouldRetryLoading,
|
|
1104
1191
|
err
|
|
1105
1192
|
}, {
|
|
1106
|
-
F:
|
|
1193
|
+
F: __dxlog_file5,
|
|
1107
1194
|
L: 231,
|
|
1108
1195
|
S: this,
|
|
1109
1196
|
C: (f, a) => f(...a)
|
|
@@ -1128,10 +1215,10 @@ import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
|
|
|
1128
1215
|
import { Resource as Resource2 } from "@dxos/context";
|
|
1129
1216
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1130
1217
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
1131
|
-
import { log as
|
|
1218
|
+
import { log as log5 } from "@dxos/log";
|
|
1132
1219
|
import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
|
|
1133
1220
|
import { ComplexMap, ComplexSet, defaultMap } from "@dxos/util";
|
|
1134
|
-
var
|
|
1221
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
|
|
1135
1222
|
var MeshEchoReplicator = class {
|
|
1136
1223
|
constructor() {
|
|
1137
1224
|
this._connections = /* @__PURE__ */ new Set();
|
|
@@ -1158,7 +1245,7 @@ var MeshEchoReplicator = class {
|
|
|
1158
1245
|
}
|
|
1159
1246
|
createExtension() {
|
|
1160
1247
|
invariant5(this._context, void 0, {
|
|
1161
|
-
F:
|
|
1248
|
+
F: __dxlog_file6,
|
|
1162
1249
|
L: 54,
|
|
1163
1250
|
S: this,
|
|
1164
1251
|
A: [
|
|
@@ -1169,16 +1256,16 @@ var MeshEchoReplicator = class {
|
|
|
1169
1256
|
const connection = new MeshReplicatorConnection({
|
|
1170
1257
|
ownPeerId: this._context.peerId,
|
|
1171
1258
|
onRemoteConnected: async () => {
|
|
1172
|
-
|
|
1259
|
+
log5("onRemoteConnected", {
|
|
1173
1260
|
peerId: connection.peerId
|
|
1174
1261
|
}, {
|
|
1175
|
-
F:
|
|
1262
|
+
F: __dxlog_file6,
|
|
1176
1263
|
L: 59,
|
|
1177
1264
|
S: this,
|
|
1178
1265
|
C: (f, a) => f(...a)
|
|
1179
1266
|
});
|
|
1180
1267
|
invariant5(this._context, void 0, {
|
|
1181
|
-
F:
|
|
1268
|
+
F: __dxlog_file6,
|
|
1182
1269
|
L: 60,
|
|
1183
1270
|
S: this,
|
|
1184
1271
|
A: [
|
|
@@ -1186,20 +1273,18 @@ var MeshEchoReplicator = class {
|
|
|
1186
1273
|
""
|
|
1187
1274
|
]
|
|
1188
1275
|
});
|
|
1189
|
-
if (this._connectionsPerPeer.has(connection.peerId)) {
|
|
1190
|
-
this._context.onConnectionAuthScopeChanged(connection);
|
|
1191
|
-
} else {
|
|
1276
|
+
if (!this._connectionsPerPeer.has(connection.peerId)) {
|
|
1192
1277
|
this._connectionsPerPeer.set(connection.peerId, connection);
|
|
1193
1278
|
await connection.enable();
|
|
1194
1279
|
this._context.onConnectionOpen(connection);
|
|
1195
1280
|
}
|
|
1196
1281
|
},
|
|
1197
1282
|
onRemoteDisconnected: async () => {
|
|
1198
|
-
|
|
1283
|
+
log5("onRemoteDisconnected", {
|
|
1199
1284
|
peerId: connection.peerId
|
|
1200
1285
|
}, {
|
|
1201
|
-
F:
|
|
1202
|
-
L:
|
|
1286
|
+
F: __dxlog_file6,
|
|
1287
|
+
L: 69,
|
|
1203
1288
|
S: this,
|
|
1204
1289
|
C: (f, a) => f(...a)
|
|
1205
1290
|
});
|
|
@@ -1209,18 +1294,18 @@ var MeshEchoReplicator = class {
|
|
|
1209
1294
|
this._connections.delete(connection);
|
|
1210
1295
|
},
|
|
1211
1296
|
shouldAdvertize: async (params) => {
|
|
1212
|
-
|
|
1297
|
+
log5("shouldAdvertize", {
|
|
1213
1298
|
peerId: connection.peerId,
|
|
1214
1299
|
documentId: params.documentId
|
|
1215
1300
|
}, {
|
|
1216
|
-
F:
|
|
1217
|
-
L:
|
|
1301
|
+
F: __dxlog_file6,
|
|
1302
|
+
L: 76,
|
|
1218
1303
|
S: this,
|
|
1219
1304
|
C: (f, a) => f(...a)
|
|
1220
1305
|
});
|
|
1221
1306
|
invariant5(this._context, void 0, {
|
|
1222
|
-
F:
|
|
1223
|
-
L:
|
|
1307
|
+
F: __dxlog_file6,
|
|
1308
|
+
L: 77,
|
|
1224
1309
|
S: this,
|
|
1225
1310
|
A: [
|
|
1226
1311
|
"this._context",
|
|
@@ -1230,12 +1315,12 @@ var MeshEchoReplicator = class {
|
|
|
1230
1315
|
try {
|
|
1231
1316
|
const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
|
|
1232
1317
|
if (!spaceKey) {
|
|
1233
|
-
|
|
1318
|
+
log5("space key not found for share policy check", {
|
|
1234
1319
|
peerId: connection.peerId,
|
|
1235
1320
|
documentId: params.documentId
|
|
1236
1321
|
}, {
|
|
1237
|
-
F:
|
|
1238
|
-
L:
|
|
1322
|
+
F: __dxlog_file6,
|
|
1323
|
+
L: 81,
|
|
1239
1324
|
S: this,
|
|
1240
1325
|
C: (f, a) => f(...a)
|
|
1241
1326
|
});
|
|
@@ -1243,19 +1328,19 @@ var MeshEchoReplicator = class {
|
|
|
1243
1328
|
}
|
|
1244
1329
|
const authorizedDevices = this._authorizedDevices.get(spaceKey);
|
|
1245
1330
|
if (!connection.remoteDeviceKey) {
|
|
1246
|
-
|
|
1331
|
+
log5("device key not found for share policy check", {
|
|
1247
1332
|
peerId: connection.peerId,
|
|
1248
1333
|
documentId: params.documentId
|
|
1249
1334
|
}, {
|
|
1250
|
-
F:
|
|
1251
|
-
L:
|
|
1335
|
+
F: __dxlog_file6,
|
|
1336
|
+
L: 91,
|
|
1252
1337
|
S: this,
|
|
1253
1338
|
C: (f, a) => f(...a)
|
|
1254
1339
|
});
|
|
1255
1340
|
return false;
|
|
1256
1341
|
}
|
|
1257
1342
|
const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
|
|
1258
|
-
|
|
1343
|
+
log5("share policy check", {
|
|
1259
1344
|
localPeer: this._context.peerId,
|
|
1260
1345
|
remotePeer: connection.peerId,
|
|
1261
1346
|
documentId: params.documentId,
|
|
@@ -1263,16 +1348,16 @@ var MeshEchoReplicator = class {
|
|
|
1263
1348
|
spaceKey,
|
|
1264
1349
|
isAuthorized
|
|
1265
1350
|
}, {
|
|
1266
|
-
F:
|
|
1267
|
-
L:
|
|
1351
|
+
F: __dxlog_file6,
|
|
1352
|
+
L: 99,
|
|
1268
1353
|
S: this,
|
|
1269
1354
|
C: (f, a) => f(...a)
|
|
1270
1355
|
});
|
|
1271
1356
|
return isAuthorized;
|
|
1272
1357
|
} catch (err) {
|
|
1273
|
-
|
|
1274
|
-
F:
|
|
1275
|
-
L:
|
|
1358
|
+
log5.catch(err, void 0, {
|
|
1359
|
+
F: __dxlog_file6,
|
|
1360
|
+
L: 109,
|
|
1276
1361
|
S: this,
|
|
1277
1362
|
C: (f, a) => f(...a)
|
|
1278
1363
|
});
|
|
@@ -1284,12 +1369,12 @@ var MeshEchoReplicator = class {
|
|
|
1284
1369
|
return connection.replicatorExtension;
|
|
1285
1370
|
}
|
|
1286
1371
|
authorizeDevice(spaceKey, deviceKey) {
|
|
1287
|
-
|
|
1372
|
+
log5("authorizeDevice", {
|
|
1288
1373
|
spaceKey,
|
|
1289
1374
|
deviceKey
|
|
1290
1375
|
}, {
|
|
1291
|
-
F:
|
|
1292
|
-
L:
|
|
1376
|
+
F: __dxlog_file6,
|
|
1377
|
+
L: 120,
|
|
1293
1378
|
S: this,
|
|
1294
1379
|
C: (f, a) => f(...a)
|
|
1295
1380
|
});
|
|
@@ -1325,13 +1410,13 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1325
1410
|
onStartReplication: async (info, remotePeerId) => {
|
|
1326
1411
|
this.remoteDeviceKey = remotePeerId;
|
|
1327
1412
|
this._remotePeerId = info.id;
|
|
1328
|
-
|
|
1413
|
+
log5("onStartReplication", {
|
|
1329
1414
|
id: info.id,
|
|
1330
1415
|
thisPeerId: this.peerId,
|
|
1331
1416
|
remotePeerId: remotePeerId.toHex()
|
|
1332
1417
|
}, {
|
|
1333
|
-
F:
|
|
1334
|
-
L:
|
|
1418
|
+
F: __dxlog_file6,
|
|
1419
|
+
L: 185,
|
|
1335
1420
|
S: this,
|
|
1336
1421
|
C: (f, a) => f(...a)
|
|
1337
1422
|
});
|
|
@@ -1354,8 +1439,8 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1354
1439
|
}
|
|
1355
1440
|
get peerId() {
|
|
1356
1441
|
invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1357
|
-
F:
|
|
1358
|
-
L:
|
|
1442
|
+
F: __dxlog_file6,
|
|
1443
|
+
L: 208,
|
|
1359
1444
|
S: this,
|
|
1360
1445
|
A: [
|
|
1361
1446
|
"this._remotePeerId != null",
|
|
@@ -1373,8 +1458,8 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1373
1458
|
*/
|
|
1374
1459
|
async enable() {
|
|
1375
1460
|
invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1376
|
-
F:
|
|
1377
|
-
L:
|
|
1461
|
+
F: __dxlog_file6,
|
|
1462
|
+
L: 221,
|
|
1378
1463
|
S: this,
|
|
1379
1464
|
A: [
|
|
1380
1465
|
"this._remotePeerId != null",
|
|
@@ -1395,6 +1480,7 @@ export {
|
|
|
1395
1480
|
AuthStatus,
|
|
1396
1481
|
AutomergeDocumentLoaderImpl,
|
|
1397
1482
|
AutomergeHost,
|
|
1483
|
+
AutomergeStorageAdapter,
|
|
1398
1484
|
DataServiceImpl,
|
|
1399
1485
|
LevelDBStorageAdapter,
|
|
1400
1486
|
LocalHostNetworkAdapter,
|