@dxos/echo-pipeline 0.5.9-main.4ed8273 → 0.5.9-main.59deb28
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 +74 -190
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +75 -186
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -1
- package/dist/types/src/automerge/automerge-host.d.ts +1 -8
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/index.d.ts +0 -1
- package/dist/types/src/automerge/index.d.ts.map +1 -1
- package/package.json +33 -33
- package/src/automerge/automerge-doc-loader.ts +4 -2
- package/src/automerge/automerge-host.ts +8 -21
- package/src/automerge/index.ts +0 -1
- package/src/automerge/storage-adapter.test.ts +103 -139
- package/dist/types/src/automerge/automerge-storage-adapter.d.ts +0 -16
- package/dist/types/src/automerge/automerge-storage-adapter.d.ts.map +0 -1
- package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts +0 -25
- package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts.map +0 -1
- package/dist/types/src/automerge/migrations.d.ts +0 -7
- package/dist/types/src/automerge/migrations.d.ts.map +0 -1
- package/src/automerge/automerge-storage-adapter.ts +0 -103
- package/src/automerge/automerge-storage/342/200/223wrapper.ts +0 -59
- package/src/automerge/migrations.ts +0 -42
|
@@ -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 log2 } from "@dxos/log";
|
|
36
36
|
import { objectPointerCodec } from "@dxos/protocols";
|
|
37
37
|
import { trace } from "@dxos/tracing";
|
|
38
38
|
import { mapValues } from "@dxos/util";
|
|
@@ -573,118 +573,6 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
573
573
|
}
|
|
574
574
|
};
|
|
575
575
|
|
|
576
|
-
// packages/core/echo/echo-pipeline/src/automerge/migrations.ts
|
|
577
|
-
import { IndexedDBStorageAdapter } from "@dxos/automerge/automerge-repo-storage-indexeddb";
|
|
578
|
-
import { log as log2 } from "@dxos/log";
|
|
579
|
-
import { StorageType } from "@dxos/random-access-storage";
|
|
580
|
-
|
|
581
|
-
// packages/core/echo/echo-pipeline/src/automerge/automerge-storage-adapter.ts
|
|
582
|
-
import { arrayToBuffer, bufferToArray } from "@dxos/util";
|
|
583
|
-
var AutomergeStorageAdapter = class {
|
|
584
|
-
constructor(_directory) {
|
|
585
|
-
this._directory = _directory;
|
|
586
|
-
this._state = "opened";
|
|
587
|
-
}
|
|
588
|
-
async load(key) {
|
|
589
|
-
if (this._state !== "opened") {
|
|
590
|
-
return void 0;
|
|
591
|
-
}
|
|
592
|
-
const filename = this._getFilename(key);
|
|
593
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
594
|
-
const { size } = await file.stat();
|
|
595
|
-
if (!size || size === 0) {
|
|
596
|
-
return void 0;
|
|
597
|
-
}
|
|
598
|
-
const buffer = await file.read(0, size);
|
|
599
|
-
return bufferToArray(buffer);
|
|
600
|
-
}
|
|
601
|
-
async save(key, data) {
|
|
602
|
-
if (this._state !== "opened") {
|
|
603
|
-
return void 0;
|
|
604
|
-
}
|
|
605
|
-
const filename = this._getFilename(key);
|
|
606
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
607
|
-
await file.write(0, arrayToBuffer(data));
|
|
608
|
-
await file.truncate?.(data.length);
|
|
609
|
-
await file.flush?.();
|
|
610
|
-
}
|
|
611
|
-
async remove(key) {
|
|
612
|
-
if (this._state !== "opened") {
|
|
613
|
-
return void 0;
|
|
614
|
-
}
|
|
615
|
-
const filename = this._getFilename(key);
|
|
616
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
617
|
-
await file.destroy();
|
|
618
|
-
}
|
|
619
|
-
async loadRange(keyPrefix) {
|
|
620
|
-
if (this._state !== "opened") {
|
|
621
|
-
return [];
|
|
622
|
-
}
|
|
623
|
-
const filename = this._getFilename(keyPrefix);
|
|
624
|
-
const entries = await this._directory.list();
|
|
625
|
-
return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
626
|
-
const file = this._directory.getOrCreateFile(entry);
|
|
627
|
-
const { size } = await file.stat();
|
|
628
|
-
const buffer = await file.read(0, size);
|
|
629
|
-
return {
|
|
630
|
-
key: this._getKeyFromFilename(entry),
|
|
631
|
-
data: bufferToArray(buffer)
|
|
632
|
-
};
|
|
633
|
-
}));
|
|
634
|
-
}
|
|
635
|
-
async removeRange(keyPrefix) {
|
|
636
|
-
if (this._state !== "opened") {
|
|
637
|
-
return void 0;
|
|
638
|
-
}
|
|
639
|
-
const filename = this._getFilename(keyPrefix);
|
|
640
|
-
const entries = await this._directory.list();
|
|
641
|
-
await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
642
|
-
const file = this._directory.getOrCreateFile(entry);
|
|
643
|
-
await file.destroy();
|
|
644
|
-
}));
|
|
645
|
-
}
|
|
646
|
-
async close() {
|
|
647
|
-
this._state = "closed";
|
|
648
|
-
}
|
|
649
|
-
_getFilename(key) {
|
|
650
|
-
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
651
|
-
}
|
|
652
|
-
_getKeyFromFilename(filename) {
|
|
653
|
-
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
|
|
657
|
-
// packages/core/echo/echo-pipeline/src/automerge/migrations.ts
|
|
658
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
|
|
659
|
-
var levelMigration = async ({ db, directory }) => {
|
|
660
|
-
const isNewLevel = !await db.iterator({
|
|
661
|
-
...encodingOptions
|
|
662
|
-
}).next();
|
|
663
|
-
if (!isNewLevel) {
|
|
664
|
-
return;
|
|
665
|
-
}
|
|
666
|
-
const oldStorageAdapter = directory.type === StorageType.IDB ? new IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory);
|
|
667
|
-
const chunks = await oldStorageAdapter.loadRange([]);
|
|
668
|
-
if (chunks.length === 0) {
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
const batch = db.batch();
|
|
672
|
-
log2.info("found chunks on old storage adapter", {
|
|
673
|
-
chunks: chunks.length
|
|
674
|
-
}, {
|
|
675
|
-
F: __dxlog_file3,
|
|
676
|
-
L: 37,
|
|
677
|
-
S: void 0,
|
|
678
|
-
C: (f, a) => f(...a)
|
|
679
|
-
});
|
|
680
|
-
for (const { key, data } of await oldStorageAdapter.loadRange([])) {
|
|
681
|
-
data && batch.put(key, data, {
|
|
682
|
-
...encodingOptions
|
|
683
|
-
});
|
|
684
|
-
}
|
|
685
|
-
await batch.write();
|
|
686
|
-
};
|
|
687
|
-
|
|
688
576
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
689
577
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
690
578
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -696,31 +584,25 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
696
584
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
697
585
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
698
586
|
}
|
|
699
|
-
var
|
|
587
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
700
588
|
var AutomergeHost = class {
|
|
701
|
-
constructor({
|
|
589
|
+
constructor({ db, indexMetadataStore }) {
|
|
702
590
|
this._ctx = new Context();
|
|
703
591
|
this._echoNetworkAdapter = new EchoNetworkAdapter({
|
|
704
592
|
getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
|
|
705
593
|
});
|
|
706
594
|
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
707
|
-
this._directory = directory;
|
|
708
|
-
this._db = db;
|
|
709
|
-
this._indexMetadataStore = indexMetadataStore;
|
|
710
|
-
}
|
|
711
|
-
async open() {
|
|
712
|
-
this._peerId = `host-${PublicKey.random().toHex()}`;
|
|
713
|
-
this._directory && await levelMigration({
|
|
714
|
-
db: this._db,
|
|
715
|
-
directory: this._directory
|
|
716
|
-
});
|
|
717
595
|
this._storage = new LevelDBStorageAdapter({
|
|
718
|
-
db
|
|
596
|
+
db,
|
|
719
597
|
callbacks: {
|
|
720
598
|
beforeSave: async (params) => this._beforeSave(params),
|
|
721
599
|
afterSave: async () => this._afterSave()
|
|
722
600
|
}
|
|
723
601
|
});
|
|
602
|
+
this._indexMetadataStore = indexMetadataStore;
|
|
603
|
+
}
|
|
604
|
+
async open() {
|
|
605
|
+
this._peerId = `host-${PublicKey.random().toHex()}`;
|
|
724
606
|
await this._storage.open?.();
|
|
725
607
|
this._clientNetwork = new LocalHostNetworkAdapter();
|
|
726
608
|
this._repo = new Repo({
|
|
@@ -768,13 +650,13 @@ var AutomergeHost = class {
|
|
|
768
650
|
const doc = this._repo.handles[documentId]?.docSync();
|
|
769
651
|
if (!doc) {
|
|
770
652
|
const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
|
|
771
|
-
|
|
653
|
+
log2("doc share policy check", {
|
|
772
654
|
peerId,
|
|
773
655
|
documentId,
|
|
774
656
|
isRequested
|
|
775
657
|
}, {
|
|
776
|
-
F:
|
|
777
|
-
L:
|
|
658
|
+
F: __dxlog_file3,
|
|
659
|
+
L: 143,
|
|
778
660
|
S: this,
|
|
779
661
|
C: (f, a) => f(...a)
|
|
780
662
|
});
|
|
@@ -859,8 +741,8 @@ var AutomergeHost = class {
|
|
|
859
741
|
async flush({ states }) {
|
|
860
742
|
await Promise.all(states?.map(async ({ heads, documentId }) => {
|
|
861
743
|
invariant3(heads, "heads are required for flush", {
|
|
862
|
-
F:
|
|
863
|
-
L:
|
|
744
|
+
F: __dxlog_file3,
|
|
745
|
+
L: 237,
|
|
864
746
|
S: this,
|
|
865
747
|
A: [
|
|
866
748
|
"heads",
|
|
@@ -933,8 +815,9 @@ var changeIsPresentInDoc = (doc, changeHash) => {
|
|
|
933
815
|
import { Event as Event2 } from "@dxos/async";
|
|
934
816
|
import { cancelWithContext } from "@dxos/context";
|
|
935
817
|
import { warnAfterTimeout } from "@dxos/debug";
|
|
818
|
+
import { SpaceDocVersion } from "@dxos/echo-protocol";
|
|
936
819
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
937
|
-
import { log as
|
|
820
|
+
import { log as log3 } from "@dxos/log";
|
|
938
821
|
import { trace as trace2 } from "@dxos/tracing";
|
|
939
822
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
940
823
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -946,7 +829,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
946
829
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
947
830
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
948
831
|
}
|
|
949
|
-
var
|
|
832
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
950
833
|
var AutomergeDocumentLoaderImpl = class {
|
|
951
834
|
constructor(_spaceId, _repo, _spaceKey) {
|
|
952
835
|
this._spaceId = _spaceId;
|
|
@@ -968,10 +851,10 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
968
851
|
return;
|
|
969
852
|
}
|
|
970
853
|
if (!spaceState.rootUrl) {
|
|
971
|
-
|
|
854
|
+
log3.error("Database opened with no rootUrl", {
|
|
972
855
|
spaceId: this._spaceId
|
|
973
856
|
}, {
|
|
974
|
-
F:
|
|
857
|
+
F: __dxlog_file4,
|
|
975
858
|
L: 72,
|
|
976
859
|
S: this,
|
|
977
860
|
C: (f, a) => f(...a)
|
|
@@ -981,7 +864,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
981
864
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
982
865
|
const doc = existingDocHandle.docSync();
|
|
983
866
|
invariant4(doc, void 0, {
|
|
984
|
-
F:
|
|
867
|
+
F: __dxlog_file4,
|
|
985
868
|
L: 77,
|
|
986
869
|
S: this,
|
|
987
870
|
A: [
|
|
@@ -1003,7 +886,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1003
886
|
const urlsToLoad = {};
|
|
1004
887
|
for (const objectId of objectIds) {
|
|
1005
888
|
invariant4(this._spaceRootDocHandle, void 0, {
|
|
1006
|
-
F:
|
|
889
|
+
F: __dxlog_file4,
|
|
1007
890
|
L: 90,
|
|
1008
891
|
S: this,
|
|
1009
892
|
A: [
|
|
@@ -1016,7 +899,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1016
899
|
}
|
|
1017
900
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
1018
901
|
invariant4(spaceRootDoc, void 0, {
|
|
1019
|
-
F:
|
|
902
|
+
F: __dxlog_file4,
|
|
1020
903
|
L: 95,
|
|
1021
904
|
S: this,
|
|
1022
905
|
A: [
|
|
@@ -1027,10 +910,10 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1027
910
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
1028
911
|
if (documentUrl == null) {
|
|
1029
912
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
1030
|
-
|
|
913
|
+
log3.info("loading delayed until object links are initialized", {
|
|
1031
914
|
objectId
|
|
1032
915
|
}, {
|
|
1033
|
-
F:
|
|
916
|
+
F: __dxlog_file4,
|
|
1034
917
|
L: 99,
|
|
1035
918
|
S: this,
|
|
1036
919
|
C: (f, a) => f(...a)
|
|
@@ -1054,7 +937,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1054
937
|
}
|
|
1055
938
|
getSpaceRootDocHandle() {
|
|
1056
939
|
invariant4(this._spaceRootDocHandle, void 0, {
|
|
1057
|
-
F:
|
|
940
|
+
F: __dxlog_file4,
|
|
1058
941
|
L: 122,
|
|
1059
942
|
S: this,
|
|
1060
943
|
A: [
|
|
@@ -1066,7 +949,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1066
949
|
}
|
|
1067
950
|
createDocumentForObject(objectId) {
|
|
1068
951
|
invariant4(this._spaceRootDocHandle, void 0, {
|
|
1069
|
-
F:
|
|
952
|
+
F: __dxlog_file4,
|
|
1070
953
|
L: 127,
|
|
1071
954
|
S: this,
|
|
1072
955
|
A: [
|
|
@@ -1074,7 +957,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1074
957
|
""
|
|
1075
958
|
]
|
|
1076
959
|
});
|
|
1077
|
-
const spaceDocHandle = this._repo.create(
|
|
960
|
+
const spaceDocHandle = this._repo.create({
|
|
961
|
+
version: SpaceDocVersion.CURRENT
|
|
962
|
+
});
|
|
1078
963
|
this._initDocAccess(spaceDocHandle);
|
|
1079
964
|
this.onObjectBoundToDocument(spaceDocHandle, objectId);
|
|
1080
965
|
this._spaceRootDocHandle.change((newDoc) => {
|
|
@@ -1105,30 +990,30 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1105
990
|
};
|
|
1106
991
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
1107
992
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
1108
|
-
|
|
993
|
+
log3.warn("object already inlined in a different document, ignoring the link", {
|
|
1109
994
|
...logMeta,
|
|
1110
995
|
actualDocumentUrl: objectDocumentHandle.url
|
|
1111
996
|
}, {
|
|
1112
|
-
F:
|
|
1113
|
-
L:
|
|
997
|
+
F: __dxlog_file4,
|
|
998
|
+
L: 159,
|
|
1114
999
|
S: this,
|
|
1115
1000
|
C: (f, a) => f(...a)
|
|
1116
1001
|
});
|
|
1117
1002
|
continue;
|
|
1118
1003
|
}
|
|
1119
1004
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
1120
|
-
|
|
1121
|
-
F:
|
|
1122
|
-
L:
|
|
1005
|
+
log3.warn("object document was already loaded", logMeta, {
|
|
1006
|
+
F: __dxlog_file4,
|
|
1007
|
+
L: 166,
|
|
1123
1008
|
S: this,
|
|
1124
1009
|
C: (f, a) => f(...a)
|
|
1125
1010
|
});
|
|
1126
1011
|
continue;
|
|
1127
1012
|
}
|
|
1128
1013
|
const handle = this._repo.find(automergeUrl);
|
|
1129
|
-
|
|
1130
|
-
F:
|
|
1131
|
-
L:
|
|
1014
|
+
log3.debug("document loading triggered", logMeta, {
|
|
1015
|
+
F: __dxlog_file4,
|
|
1016
|
+
L: 170,
|
|
1132
1017
|
S: this,
|
|
1133
1018
|
C: (f, a) => f(...a)
|
|
1134
1019
|
});
|
|
@@ -1146,12 +1031,12 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1146
1031
|
break;
|
|
1147
1032
|
} catch (err) {
|
|
1148
1033
|
if (`${err}`.includes("Timeout")) {
|
|
1149
|
-
|
|
1034
|
+
log3.info("wraparound", {
|
|
1150
1035
|
id: docHandle.documentId,
|
|
1151
1036
|
state: docHandle.state
|
|
1152
1037
|
}, {
|
|
1153
|
-
F:
|
|
1154
|
-
L:
|
|
1038
|
+
F: __dxlog_file4,
|
|
1039
|
+
L: 186,
|
|
1155
1040
|
S: this,
|
|
1156
1041
|
C: (f, a) => f(...a)
|
|
1157
1042
|
});
|
|
@@ -1191,9 +1076,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1191
1076
|
docUrl: handle.url
|
|
1192
1077
|
};
|
|
1193
1078
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1194
|
-
|
|
1195
|
-
F:
|
|
1196
|
-
L:
|
|
1079
|
+
log3.info("document loaded after all listeners were removed", logMeta, {
|
|
1080
|
+
F: __dxlog_file4,
|
|
1081
|
+
L: 222,
|
|
1197
1082
|
S: this,
|
|
1198
1083
|
C: (f, a) => f(...a)
|
|
1199
1084
|
});
|
|
@@ -1201,9 +1086,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1201
1086
|
}
|
|
1202
1087
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
1203
1088
|
if (objectDocHandle?.url !== handle.url) {
|
|
1204
|
-
|
|
1205
|
-
F:
|
|
1206
|
-
L:
|
|
1089
|
+
log3.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1090
|
+
F: __dxlog_file4,
|
|
1091
|
+
L: 227,
|
|
1207
1092
|
S: this,
|
|
1208
1093
|
C: (f, a) => f(...a)
|
|
1209
1094
|
});
|
|
@@ -1215,14 +1100,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1215
1100
|
});
|
|
1216
1101
|
} catch (err) {
|
|
1217
1102
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1218
|
-
|
|
1103
|
+
log3.warn("failed to load a document", {
|
|
1219
1104
|
objectId,
|
|
1220
1105
|
automergeUrl: handle.url,
|
|
1221
1106
|
retryLoading: shouldRetryLoading,
|
|
1222
1107
|
err
|
|
1223
1108
|
}, {
|
|
1224
|
-
F:
|
|
1225
|
-
L:
|
|
1109
|
+
F: __dxlog_file4,
|
|
1110
|
+
L: 233,
|
|
1226
1111
|
S: this,
|
|
1227
1112
|
C: (f, a) => f(...a)
|
|
1228
1113
|
});
|
|
@@ -1246,10 +1131,10 @@ import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
|
|
|
1246
1131
|
import { Resource as Resource2 } from "@dxos/context";
|
|
1247
1132
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1248
1133
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
1249
|
-
import { log as
|
|
1134
|
+
import { log as log4 } from "@dxos/log";
|
|
1250
1135
|
import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
|
|
1251
1136
|
import { ComplexMap, ComplexSet, defaultMap } from "@dxos/util";
|
|
1252
|
-
var
|
|
1137
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
|
|
1253
1138
|
var MeshEchoReplicator = class {
|
|
1254
1139
|
constructor() {
|
|
1255
1140
|
this._connections = /* @__PURE__ */ new Set();
|
|
@@ -1276,7 +1161,7 @@ var MeshEchoReplicator = class {
|
|
|
1276
1161
|
}
|
|
1277
1162
|
createExtension() {
|
|
1278
1163
|
invariant5(this._context, void 0, {
|
|
1279
|
-
F:
|
|
1164
|
+
F: __dxlog_file5,
|
|
1280
1165
|
L: 54,
|
|
1281
1166
|
S: this,
|
|
1282
1167
|
A: [
|
|
@@ -1287,16 +1172,16 @@ var MeshEchoReplicator = class {
|
|
|
1287
1172
|
const connection = new MeshReplicatorConnection({
|
|
1288
1173
|
ownPeerId: this._context.peerId,
|
|
1289
1174
|
onRemoteConnected: async () => {
|
|
1290
|
-
|
|
1175
|
+
log4("onRemoteConnected", {
|
|
1291
1176
|
peerId: connection.peerId
|
|
1292
1177
|
}, {
|
|
1293
|
-
F:
|
|
1178
|
+
F: __dxlog_file5,
|
|
1294
1179
|
L: 59,
|
|
1295
1180
|
S: this,
|
|
1296
1181
|
C: (f, a) => f(...a)
|
|
1297
1182
|
});
|
|
1298
1183
|
invariant5(this._context, void 0, {
|
|
1299
|
-
F:
|
|
1184
|
+
F: __dxlog_file5,
|
|
1300
1185
|
L: 60,
|
|
1301
1186
|
S: this,
|
|
1302
1187
|
A: [
|
|
@@ -1313,10 +1198,10 @@ var MeshEchoReplicator = class {
|
|
|
1313
1198
|
}
|
|
1314
1199
|
},
|
|
1315
1200
|
onRemoteDisconnected: async () => {
|
|
1316
|
-
|
|
1201
|
+
log4("onRemoteDisconnected", {
|
|
1317
1202
|
peerId: connection.peerId
|
|
1318
1203
|
}, {
|
|
1319
|
-
F:
|
|
1204
|
+
F: __dxlog_file5,
|
|
1320
1205
|
L: 71,
|
|
1321
1206
|
S: this,
|
|
1322
1207
|
C: (f, a) => f(...a)
|
|
@@ -1327,17 +1212,17 @@ var MeshEchoReplicator = class {
|
|
|
1327
1212
|
this._connections.delete(connection);
|
|
1328
1213
|
},
|
|
1329
1214
|
shouldAdvertize: async (params) => {
|
|
1330
|
-
|
|
1215
|
+
log4("shouldAdvertize", {
|
|
1331
1216
|
peerId: connection.peerId,
|
|
1332
1217
|
documentId: params.documentId
|
|
1333
1218
|
}, {
|
|
1334
|
-
F:
|
|
1219
|
+
F: __dxlog_file5,
|
|
1335
1220
|
L: 78,
|
|
1336
1221
|
S: this,
|
|
1337
1222
|
C: (f, a) => f(...a)
|
|
1338
1223
|
});
|
|
1339
1224
|
invariant5(this._context, void 0, {
|
|
1340
|
-
F:
|
|
1225
|
+
F: __dxlog_file5,
|
|
1341
1226
|
L: 79,
|
|
1342
1227
|
S: this,
|
|
1343
1228
|
A: [
|
|
@@ -1348,11 +1233,11 @@ var MeshEchoReplicator = class {
|
|
|
1348
1233
|
try {
|
|
1349
1234
|
const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
|
|
1350
1235
|
if (!spaceKey) {
|
|
1351
|
-
|
|
1236
|
+
log4("space key not found for share policy check", {
|
|
1352
1237
|
peerId: connection.peerId,
|
|
1353
1238
|
documentId: params.documentId
|
|
1354
1239
|
}, {
|
|
1355
|
-
F:
|
|
1240
|
+
F: __dxlog_file5,
|
|
1356
1241
|
L: 83,
|
|
1357
1242
|
S: this,
|
|
1358
1243
|
C: (f, a) => f(...a)
|
|
@@ -1361,11 +1246,11 @@ var MeshEchoReplicator = class {
|
|
|
1361
1246
|
}
|
|
1362
1247
|
const authorizedDevices = this._authorizedDevices.get(spaceKey);
|
|
1363
1248
|
if (!connection.remoteDeviceKey) {
|
|
1364
|
-
|
|
1249
|
+
log4("device key not found for share policy check", {
|
|
1365
1250
|
peerId: connection.peerId,
|
|
1366
1251
|
documentId: params.documentId
|
|
1367
1252
|
}, {
|
|
1368
|
-
F:
|
|
1253
|
+
F: __dxlog_file5,
|
|
1369
1254
|
L: 93,
|
|
1370
1255
|
S: this,
|
|
1371
1256
|
C: (f, a) => f(...a)
|
|
@@ -1373,7 +1258,7 @@ var MeshEchoReplicator = class {
|
|
|
1373
1258
|
return false;
|
|
1374
1259
|
}
|
|
1375
1260
|
const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
|
|
1376
|
-
|
|
1261
|
+
log4("share policy check", {
|
|
1377
1262
|
localPeer: this._context.peerId,
|
|
1378
1263
|
remotePeer: connection.peerId,
|
|
1379
1264
|
documentId: params.documentId,
|
|
@@ -1381,15 +1266,15 @@ var MeshEchoReplicator = class {
|
|
|
1381
1266
|
spaceKey,
|
|
1382
1267
|
isAuthorized
|
|
1383
1268
|
}, {
|
|
1384
|
-
F:
|
|
1269
|
+
F: __dxlog_file5,
|
|
1385
1270
|
L: 101,
|
|
1386
1271
|
S: this,
|
|
1387
1272
|
C: (f, a) => f(...a)
|
|
1388
1273
|
});
|
|
1389
1274
|
return isAuthorized;
|
|
1390
1275
|
} catch (err) {
|
|
1391
|
-
|
|
1392
|
-
F:
|
|
1276
|
+
log4.catch(err, void 0, {
|
|
1277
|
+
F: __dxlog_file5,
|
|
1393
1278
|
L: 111,
|
|
1394
1279
|
S: this,
|
|
1395
1280
|
C: (f, a) => f(...a)
|
|
@@ -1402,11 +1287,11 @@ var MeshEchoReplicator = class {
|
|
|
1402
1287
|
return connection.replicatorExtension;
|
|
1403
1288
|
}
|
|
1404
1289
|
authorizeDevice(spaceKey, deviceKey) {
|
|
1405
|
-
|
|
1290
|
+
log4("authorizeDevice", {
|
|
1406
1291
|
spaceKey,
|
|
1407
1292
|
deviceKey
|
|
1408
1293
|
}, {
|
|
1409
|
-
F:
|
|
1294
|
+
F: __dxlog_file5,
|
|
1410
1295
|
L: 122,
|
|
1411
1296
|
S: this,
|
|
1412
1297
|
C: (f, a) => f(...a)
|
|
@@ -1443,12 +1328,12 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1443
1328
|
onStartReplication: async (info, remotePeerId) => {
|
|
1444
1329
|
this.remoteDeviceKey = remotePeerId;
|
|
1445
1330
|
this._remotePeerId = info.id;
|
|
1446
|
-
|
|
1331
|
+
log4("onStartReplication", {
|
|
1447
1332
|
id: info.id,
|
|
1448
1333
|
thisPeerId: this.peerId,
|
|
1449
1334
|
remotePeerId: remotePeerId.toHex()
|
|
1450
1335
|
}, {
|
|
1451
|
-
F:
|
|
1336
|
+
F: __dxlog_file5,
|
|
1452
1337
|
L: 187,
|
|
1453
1338
|
S: this,
|
|
1454
1339
|
C: (f, a) => f(...a)
|
|
@@ -1472,7 +1357,7 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1472
1357
|
}
|
|
1473
1358
|
get peerId() {
|
|
1474
1359
|
invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1475
|
-
F:
|
|
1360
|
+
F: __dxlog_file5,
|
|
1476
1361
|
L: 210,
|
|
1477
1362
|
S: this,
|
|
1478
1363
|
A: [
|
|
@@ -1491,7 +1376,7 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1491
1376
|
*/
|
|
1492
1377
|
async enable() {
|
|
1493
1378
|
invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1494
|
-
F:
|
|
1379
|
+
F: __dxlog_file5,
|
|
1495
1380
|
L: 223,
|
|
1496
1381
|
S: this,
|
|
1497
1382
|
A: [
|
|
@@ -1513,7 +1398,6 @@ export {
|
|
|
1513
1398
|
AuthStatus,
|
|
1514
1399
|
AutomergeDocumentLoaderImpl,
|
|
1515
1400
|
AutomergeHost,
|
|
1516
|
-
AutomergeStorageAdapter,
|
|
1517
1401
|
DataServiceImpl,
|
|
1518
1402
|
LevelDBStorageAdapter,
|
|
1519
1403
|
LocalHostNetworkAdapter,
|