@dxos/echo-pipeline 0.5.9-main.1c1903d → 0.5.9-main.21b00b3
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/dist/lib/node/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ __export(node_exports, {
|
|
|
22
22
|
AuthStatus: () => import_chunk_QPCNQ4ZK.AuthStatus,
|
|
23
23
|
AutomergeDocumentLoaderImpl: () => AutomergeDocumentLoaderImpl,
|
|
24
24
|
AutomergeHost: () => AutomergeHost,
|
|
25
|
+
AutomergeStorageAdapter: () => AutomergeStorageAdapter,
|
|
25
26
|
DataServiceImpl: () => import_chunk_QPCNQ4ZK.DataServiceImpl,
|
|
26
27
|
LevelDBStorageAdapter: () => LevelDBStorageAdapter,
|
|
27
28
|
LocalHostNetworkAdapter: () => LocalHostNetworkAdapter,
|
|
@@ -70,19 +71,23 @@ var import_async3 = require("@dxos/async");
|
|
|
70
71
|
var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
|
|
71
72
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
72
73
|
var import_invariant3 = require("@dxos/invariant");
|
|
74
|
+
var import_automerge_repo_storage_indexeddb = require("@dxos/automerge/automerge-repo-storage-indexeddb");
|
|
75
|
+
var import_log3 = require("@dxos/log");
|
|
76
|
+
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
77
|
+
var import_util2 = require("@dxos/util");
|
|
73
78
|
var import_async4 = require("@dxos/async");
|
|
74
79
|
var import_context4 = require("@dxos/context");
|
|
75
80
|
var import_debug = require("@dxos/debug");
|
|
76
81
|
var import_invariant4 = require("@dxos/invariant");
|
|
77
|
-
var
|
|
82
|
+
var import_log4 = require("@dxos/log");
|
|
78
83
|
var import_tracing2 = require("@dxos/tracing");
|
|
79
84
|
var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
|
|
80
85
|
var import_context5 = require("@dxos/context");
|
|
81
86
|
var import_invariant5 = require("@dxos/invariant");
|
|
82
87
|
var import_keys2 = require("@dxos/keys");
|
|
83
|
-
var
|
|
88
|
+
var import_log5 = require("@dxos/log");
|
|
84
89
|
var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
|
|
85
|
-
var
|
|
90
|
+
var import_util3 = require("@dxos/util");
|
|
86
91
|
function _ts_decorate(decorators, target, key, desc) {
|
|
87
92
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
88
93
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -201,14 +206,13 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
201
206
|
peerId: this.peerId,
|
|
202
207
|
onConnectionOpen: this._onConnectionOpen.bind(this),
|
|
203
208
|
onConnectionClosed: this._onConnectionClosed.bind(this),
|
|
204
|
-
onConnectionAuthScopeChanged: this._onConnectionAuthScopeChanged.bind(this),
|
|
205
209
|
getContainingSpaceForDocument: this._params.getContainingSpaceForDocument
|
|
206
210
|
});
|
|
207
211
|
}
|
|
208
212
|
async removeReplicator(replicator) {
|
|
209
213
|
(0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
210
214
|
F: __dxlog_file,
|
|
211
|
-
L:
|
|
215
|
+
L: 102,
|
|
212
216
|
S: this,
|
|
213
217
|
A: [
|
|
214
218
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -217,13 +221,14 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
217
221
|
});
|
|
218
222
|
(0, import_invariant2.invariant)(this._replicators.has(replicator), void 0, {
|
|
219
223
|
F: __dxlog_file,
|
|
220
|
-
L:
|
|
224
|
+
L: 103,
|
|
221
225
|
S: this,
|
|
222
226
|
A: [
|
|
223
227
|
"this._replicators.has(replicator)",
|
|
224
228
|
""
|
|
225
229
|
]
|
|
226
230
|
});
|
|
231
|
+
"";
|
|
227
232
|
await replicator.disconnect();
|
|
228
233
|
this._replicators.delete(replicator);
|
|
229
234
|
}
|
|
@@ -289,49 +294,27 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
289
294
|
S: this,
|
|
290
295
|
C: (f, a) => f(...a)
|
|
291
296
|
});
|
|
292
|
-
this.
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
_onConnectionAuthScopeChanged(connection) {
|
|
299
|
-
(0, import_log2.log)("Connection auth scope changed", {
|
|
300
|
-
peerId: connection.peerId
|
|
301
|
-
}, {
|
|
302
|
-
F: __dxlog_file,
|
|
303
|
-
L: 153,
|
|
304
|
-
S: this,
|
|
305
|
-
C: (f, a) => f(...a)
|
|
306
|
-
});
|
|
307
|
-
const entry = this._connections.get(connection.peerId);
|
|
308
|
-
(0, import_invariant2.invariant)(entry, void 0, {
|
|
309
|
-
F: __dxlog_file,
|
|
310
|
-
L: 155,
|
|
311
|
-
S: this,
|
|
312
|
-
A: [
|
|
313
|
-
"entry",
|
|
314
|
-
""
|
|
315
|
-
]
|
|
316
|
-
});
|
|
317
|
-
this.emit("peer-disconnected", {
|
|
318
|
-
peerId: connection.peerId
|
|
297
|
+
this.emit("peer-candidate", {
|
|
298
|
+
peerId: connection.peerId,
|
|
299
|
+
peerMetadata: {
|
|
300
|
+
// TODO(dmaretskyi): Refactor this.
|
|
301
|
+
dxos_peerSource: "EchoNetworkAdapter"
|
|
302
|
+
}
|
|
319
303
|
});
|
|
320
|
-
this._emitPeerCandidate(connection);
|
|
321
304
|
}
|
|
322
305
|
_onConnectionClosed(connection) {
|
|
323
306
|
(0, import_log2.log)("Connection closed", {
|
|
324
307
|
peerId: connection.peerId
|
|
325
308
|
}, {
|
|
326
309
|
F: __dxlog_file,
|
|
327
|
-
L:
|
|
310
|
+
L: 155,
|
|
328
311
|
S: this,
|
|
329
312
|
C: (f, a) => f(...a)
|
|
330
313
|
});
|
|
331
314
|
const entry = this._connections.get(connection.peerId);
|
|
332
315
|
(0, import_invariant2.invariant)(entry, void 0, {
|
|
333
316
|
F: __dxlog_file,
|
|
334
|
-
L:
|
|
317
|
+
L: 157,
|
|
335
318
|
S: this,
|
|
336
319
|
A: [
|
|
337
320
|
"entry",
|
|
@@ -344,27 +327,18 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
344
327
|
});
|
|
345
328
|
void entry.reader.cancel().catch((err) => import_log2.log.catch(err, void 0, {
|
|
346
329
|
F: __dxlog_file,
|
|
347
|
-
L:
|
|
330
|
+
L: 162,
|
|
348
331
|
S: this,
|
|
349
332
|
C: (f, a) => f(...a)
|
|
350
333
|
}));
|
|
351
334
|
void entry.writer.abort().catch((err) => import_log2.log.catch(err, void 0, {
|
|
352
335
|
F: __dxlog_file,
|
|
353
|
-
L:
|
|
336
|
+
L: 163,
|
|
354
337
|
S: this,
|
|
355
338
|
C: (f, a) => f(...a)
|
|
356
339
|
}));
|
|
357
340
|
this._connections.delete(connection.peerId);
|
|
358
341
|
}
|
|
359
|
-
_emitPeerCandidate(connection) {
|
|
360
|
-
this.emit("peer-candidate", {
|
|
361
|
-
peerId: connection.peerId,
|
|
362
|
-
peerMetadata: {
|
|
363
|
-
// TODO(dmaretskyi): Refactor this.
|
|
364
|
-
dxos_peerSource: "EchoNetworkAdapter"
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
342
|
};
|
|
369
343
|
_ts_decorate([
|
|
370
344
|
import_async2.synchronized
|
|
@@ -603,6 +577,108 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
603
577
|
return id;
|
|
604
578
|
}
|
|
605
579
|
};
|
|
580
|
+
var AutomergeStorageAdapter = class {
|
|
581
|
+
constructor(_directory) {
|
|
582
|
+
this._directory = _directory;
|
|
583
|
+
this._state = "opened";
|
|
584
|
+
}
|
|
585
|
+
async load(key) {
|
|
586
|
+
if (this._state !== "opened") {
|
|
587
|
+
return void 0;
|
|
588
|
+
}
|
|
589
|
+
const filename = this._getFilename(key);
|
|
590
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
591
|
+
const { size } = await file.stat();
|
|
592
|
+
if (!size || size === 0) {
|
|
593
|
+
return void 0;
|
|
594
|
+
}
|
|
595
|
+
const buffer = await file.read(0, size);
|
|
596
|
+
return (0, import_util2.bufferToArray)(buffer);
|
|
597
|
+
}
|
|
598
|
+
async save(key, data) {
|
|
599
|
+
if (this._state !== "opened") {
|
|
600
|
+
return void 0;
|
|
601
|
+
}
|
|
602
|
+
const filename = this._getFilename(key);
|
|
603
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
604
|
+
await file.write(0, (0, import_util2.arrayToBuffer)(data));
|
|
605
|
+
await file.truncate?.(data.length);
|
|
606
|
+
await file.flush?.();
|
|
607
|
+
}
|
|
608
|
+
async remove(key) {
|
|
609
|
+
if (this._state !== "opened") {
|
|
610
|
+
return void 0;
|
|
611
|
+
}
|
|
612
|
+
const filename = this._getFilename(key);
|
|
613
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
614
|
+
await file.destroy();
|
|
615
|
+
}
|
|
616
|
+
async loadRange(keyPrefix) {
|
|
617
|
+
if (this._state !== "opened") {
|
|
618
|
+
return [];
|
|
619
|
+
}
|
|
620
|
+
const filename = this._getFilename(keyPrefix);
|
|
621
|
+
const entries = await this._directory.list();
|
|
622
|
+
return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
623
|
+
const file = this._directory.getOrCreateFile(entry);
|
|
624
|
+
const { size } = await file.stat();
|
|
625
|
+
const buffer = await file.read(0, size);
|
|
626
|
+
return {
|
|
627
|
+
key: this._getKeyFromFilename(entry),
|
|
628
|
+
data: (0, import_util2.bufferToArray)(buffer)
|
|
629
|
+
};
|
|
630
|
+
}));
|
|
631
|
+
}
|
|
632
|
+
async removeRange(keyPrefix) {
|
|
633
|
+
if (this._state !== "opened") {
|
|
634
|
+
return void 0;
|
|
635
|
+
}
|
|
636
|
+
const filename = this._getFilename(keyPrefix);
|
|
637
|
+
const entries = await this._directory.list();
|
|
638
|
+
await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
639
|
+
const file = this._directory.getOrCreateFile(entry);
|
|
640
|
+
await file.destroy();
|
|
641
|
+
}));
|
|
642
|
+
}
|
|
643
|
+
async close() {
|
|
644
|
+
this._state = "closed";
|
|
645
|
+
}
|
|
646
|
+
_getFilename(key) {
|
|
647
|
+
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
648
|
+
}
|
|
649
|
+
_getKeyFromFilename(filename) {
|
|
650
|
+
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
|
|
654
|
+
var levelMigration = async ({ db, directory }) => {
|
|
655
|
+
const isNewLevel = !await db.iterator({
|
|
656
|
+
...encodingOptions
|
|
657
|
+
}).next();
|
|
658
|
+
if (!isNewLevel) {
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
const oldStorageAdapter = directory.type === import_random_access_storage.StorageType.IDB ? new import_automerge_repo_storage_indexeddb.IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory);
|
|
662
|
+
const chunks = await oldStorageAdapter.loadRange([]);
|
|
663
|
+
if (chunks.length === 0) {
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
const batch = db.batch();
|
|
667
|
+
import_log3.log.info("found chunks on old storage adapter", {
|
|
668
|
+
chunks: chunks.length
|
|
669
|
+
}, {
|
|
670
|
+
F: __dxlog_file3,
|
|
671
|
+
L: 37,
|
|
672
|
+
S: void 0,
|
|
673
|
+
C: (f, a) => f(...a)
|
|
674
|
+
});
|
|
675
|
+
for (const { key, data } of await oldStorageAdapter.loadRange([])) {
|
|
676
|
+
data && batch.put(key, data, {
|
|
677
|
+
...encodingOptions
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
await batch.write();
|
|
681
|
+
};
|
|
606
682
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
607
683
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
608
684
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -613,25 +689,31 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
613
689
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
614
690
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
615
691
|
}
|
|
616
|
-
var
|
|
692
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
617
693
|
var AutomergeHost = class {
|
|
618
|
-
constructor({ db, indexMetadataStore }) {
|
|
694
|
+
constructor({ directory, db, indexMetadataStore }) {
|
|
619
695
|
this._ctx = new import_context.Context();
|
|
620
696
|
this._echoNetworkAdapter = new EchoNetworkAdapter({
|
|
621
697
|
getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
|
|
622
698
|
});
|
|
623
699
|
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
700
|
+
this._directory = directory;
|
|
701
|
+
this._db = db;
|
|
702
|
+
this._indexMetadataStore = indexMetadataStore;
|
|
703
|
+
}
|
|
704
|
+
async open() {
|
|
705
|
+
this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
|
|
706
|
+
this._directory && await levelMigration({
|
|
707
|
+
db: this._db,
|
|
708
|
+
directory: this._directory
|
|
709
|
+
});
|
|
624
710
|
this._storage = new LevelDBStorageAdapter({
|
|
625
|
-
db,
|
|
711
|
+
db: this._db,
|
|
626
712
|
callbacks: {
|
|
627
713
|
beforeSave: async (params) => this._beforeSave(params),
|
|
628
714
|
afterSave: async () => this._afterSave()
|
|
629
715
|
}
|
|
630
716
|
});
|
|
631
|
-
this._indexMetadataStore = indexMetadataStore;
|
|
632
|
-
}
|
|
633
|
-
async open() {
|
|
634
|
-
this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
|
|
635
717
|
await this._storage.open?.();
|
|
636
718
|
this._clientNetwork = new LocalHostNetworkAdapter();
|
|
637
719
|
this._repo = new import_automerge_repo.Repo({
|
|
@@ -684,8 +766,8 @@ var AutomergeHost = class {
|
|
|
684
766
|
documentId,
|
|
685
767
|
isRequested
|
|
686
768
|
}, {
|
|
687
|
-
F:
|
|
688
|
-
L:
|
|
769
|
+
F: __dxlog_file4,
|
|
770
|
+
L: 156,
|
|
689
771
|
S: this,
|
|
690
772
|
C: (f, a) => f(...a)
|
|
691
773
|
});
|
|
@@ -770,8 +852,8 @@ var AutomergeHost = class {
|
|
|
770
852
|
async flush({ states }) {
|
|
771
853
|
await Promise.all(states?.map(async ({ heads, documentId }) => {
|
|
772
854
|
(0, import_invariant.invariant)(heads, "heads are required for flush", {
|
|
773
|
-
F:
|
|
774
|
-
L:
|
|
855
|
+
F: __dxlog_file4,
|
|
856
|
+
L: 250,
|
|
775
857
|
S: this,
|
|
776
858
|
A: [
|
|
777
859
|
"heads",
|
|
@@ -849,7 +931,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
849
931
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
850
932
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
851
933
|
}
|
|
852
|
-
var
|
|
934
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
853
935
|
var AutomergeDocumentLoaderImpl = class {
|
|
854
936
|
constructor(_spaceId, _repo, _spaceKey) {
|
|
855
937
|
this._spaceId = _spaceId;
|
|
@@ -871,10 +953,10 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
871
953
|
return;
|
|
872
954
|
}
|
|
873
955
|
if (!spaceState.rootUrl) {
|
|
874
|
-
|
|
956
|
+
import_log4.log.error("Database opened with no rootUrl", {
|
|
875
957
|
spaceId: this._spaceId
|
|
876
958
|
}, {
|
|
877
|
-
F:
|
|
959
|
+
F: __dxlog_file5,
|
|
878
960
|
L: 72,
|
|
879
961
|
S: this,
|
|
880
962
|
C: (f, a) => f(...a)
|
|
@@ -884,7 +966,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
884
966
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
885
967
|
const doc = existingDocHandle.docSync();
|
|
886
968
|
(0, import_invariant4.invariant)(doc, void 0, {
|
|
887
|
-
F:
|
|
969
|
+
F: __dxlog_file5,
|
|
888
970
|
L: 77,
|
|
889
971
|
S: this,
|
|
890
972
|
A: [
|
|
@@ -906,7 +988,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
906
988
|
const urlsToLoad = {};
|
|
907
989
|
for (const objectId of objectIds) {
|
|
908
990
|
(0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
|
|
909
|
-
F:
|
|
991
|
+
F: __dxlog_file5,
|
|
910
992
|
L: 90,
|
|
911
993
|
S: this,
|
|
912
994
|
A: [
|
|
@@ -919,7 +1001,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
919
1001
|
}
|
|
920
1002
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
921
1003
|
(0, import_invariant4.invariant)(spaceRootDoc, void 0, {
|
|
922
|
-
F:
|
|
1004
|
+
F: __dxlog_file5,
|
|
923
1005
|
L: 95,
|
|
924
1006
|
S: this,
|
|
925
1007
|
A: [
|
|
@@ -930,10 +1012,10 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
930
1012
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
931
1013
|
if (documentUrl == null) {
|
|
932
1014
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
933
|
-
|
|
1015
|
+
import_log4.log.info("loading delayed until object links are initialized", {
|
|
934
1016
|
objectId
|
|
935
1017
|
}, {
|
|
936
|
-
F:
|
|
1018
|
+
F: __dxlog_file5,
|
|
937
1019
|
L: 99,
|
|
938
1020
|
S: this,
|
|
939
1021
|
C: (f, a) => f(...a)
|
|
@@ -957,7 +1039,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
957
1039
|
}
|
|
958
1040
|
getSpaceRootDocHandle() {
|
|
959
1041
|
(0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
|
|
960
|
-
F:
|
|
1042
|
+
F: __dxlog_file5,
|
|
961
1043
|
L: 122,
|
|
962
1044
|
S: this,
|
|
963
1045
|
A: [
|
|
@@ -969,7 +1051,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
969
1051
|
}
|
|
970
1052
|
createDocumentForObject(objectId) {
|
|
971
1053
|
(0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
|
|
972
|
-
F:
|
|
1054
|
+
F: __dxlog_file5,
|
|
973
1055
|
L: 127,
|
|
974
1056
|
S: this,
|
|
975
1057
|
A: [
|
|
@@ -1008,11 +1090,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1008
1090
|
};
|
|
1009
1091
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
1010
1092
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
1011
|
-
|
|
1093
|
+
import_log4.log.warn("object already inlined in a different document, ignoring the link", {
|
|
1012
1094
|
...logMeta,
|
|
1013
1095
|
actualDocumentUrl: objectDocumentHandle.url
|
|
1014
1096
|
}, {
|
|
1015
|
-
F:
|
|
1097
|
+
F: __dxlog_file5,
|
|
1016
1098
|
L: 157,
|
|
1017
1099
|
S: this,
|
|
1018
1100
|
C: (f, a) => f(...a)
|
|
@@ -1020,8 +1102,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1020
1102
|
continue;
|
|
1021
1103
|
}
|
|
1022
1104
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
1023
|
-
|
|
1024
|
-
F:
|
|
1105
|
+
import_log4.log.warn("object document was already loaded", logMeta, {
|
|
1106
|
+
F: __dxlog_file5,
|
|
1025
1107
|
L: 164,
|
|
1026
1108
|
S: this,
|
|
1027
1109
|
C: (f, a) => f(...a)
|
|
@@ -1029,8 +1111,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1029
1111
|
continue;
|
|
1030
1112
|
}
|
|
1031
1113
|
const handle = this._repo.find(automergeUrl);
|
|
1032
|
-
|
|
1033
|
-
F:
|
|
1114
|
+
import_log4.log.debug("document loading triggered", logMeta, {
|
|
1115
|
+
F: __dxlog_file5,
|
|
1034
1116
|
L: 168,
|
|
1035
1117
|
S: this,
|
|
1036
1118
|
C: (f, a) => f(...a)
|
|
@@ -1049,11 +1131,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1049
1131
|
break;
|
|
1050
1132
|
} catch (err) {
|
|
1051
1133
|
if (`${err}`.includes("Timeout")) {
|
|
1052
|
-
|
|
1134
|
+
import_log4.log.info("wraparound", {
|
|
1053
1135
|
id: docHandle.documentId,
|
|
1054
1136
|
state: docHandle.state
|
|
1055
1137
|
}, {
|
|
1056
|
-
F:
|
|
1138
|
+
F: __dxlog_file5,
|
|
1057
1139
|
L: 184,
|
|
1058
1140
|
S: this,
|
|
1059
1141
|
C: (f, a) => f(...a)
|
|
@@ -1094,8 +1176,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1094
1176
|
docUrl: handle.url
|
|
1095
1177
|
};
|
|
1096
1178
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1097
|
-
|
|
1098
|
-
F:
|
|
1179
|
+
import_log4.log.info("document loaded after all listeners were removed", logMeta, {
|
|
1180
|
+
F: __dxlog_file5,
|
|
1099
1181
|
L: 220,
|
|
1100
1182
|
S: this,
|
|
1101
1183
|
C: (f, a) => f(...a)
|
|
@@ -1104,8 +1186,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1104
1186
|
}
|
|
1105
1187
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
1106
1188
|
if (objectDocHandle?.url !== handle.url) {
|
|
1107
|
-
|
|
1108
|
-
F:
|
|
1189
|
+
import_log4.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1190
|
+
F: __dxlog_file5,
|
|
1109
1191
|
L: 225,
|
|
1110
1192
|
S: this,
|
|
1111
1193
|
C: (f, a) => f(...a)
|
|
@@ -1118,13 +1200,13 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1118
1200
|
});
|
|
1119
1201
|
} catch (err) {
|
|
1120
1202
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1121
|
-
|
|
1203
|
+
import_log4.log.warn("failed to load a document", {
|
|
1122
1204
|
objectId,
|
|
1123
1205
|
automergeUrl: handle.url,
|
|
1124
1206
|
retryLoading: shouldRetryLoading,
|
|
1125
1207
|
err
|
|
1126
1208
|
}, {
|
|
1127
|
-
F:
|
|
1209
|
+
F: __dxlog_file5,
|
|
1128
1210
|
L: 231,
|
|
1129
1211
|
S: this,
|
|
1130
1212
|
C: (f, a) => f(...a)
|
|
@@ -1143,12 +1225,12 @@ _ts_decorate3([
|
|
|
1143
1225
|
AutomergeDocumentLoaderImpl = _ts_decorate3([
|
|
1144
1226
|
import_tracing2.trace.resource()
|
|
1145
1227
|
], AutomergeDocumentLoaderImpl);
|
|
1146
|
-
var
|
|
1228
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
|
|
1147
1229
|
var MeshEchoReplicator = class {
|
|
1148
1230
|
constructor() {
|
|
1149
1231
|
this._connections = /* @__PURE__ */ new Set();
|
|
1150
1232
|
this._connectionsPerPeer = /* @__PURE__ */ new Map();
|
|
1151
|
-
this._authorizedDevices = new
|
|
1233
|
+
this._authorizedDevices = new import_util3.ComplexMap(import_keys2.PublicKey.hash);
|
|
1152
1234
|
this._context = null;
|
|
1153
1235
|
}
|
|
1154
1236
|
async connect(context) {
|
|
@@ -1164,7 +1246,7 @@ var MeshEchoReplicator = class {
|
|
|
1164
1246
|
}
|
|
1165
1247
|
createExtension() {
|
|
1166
1248
|
(0, import_invariant5.invariant)(this._context, void 0, {
|
|
1167
|
-
F:
|
|
1249
|
+
F: __dxlog_file6,
|
|
1168
1250
|
L: 54,
|
|
1169
1251
|
S: this,
|
|
1170
1252
|
A: [
|
|
@@ -1175,16 +1257,16 @@ var MeshEchoReplicator = class {
|
|
|
1175
1257
|
const connection = new MeshReplicatorConnection({
|
|
1176
1258
|
ownPeerId: this._context.peerId,
|
|
1177
1259
|
onRemoteConnected: async () => {
|
|
1178
|
-
(0,
|
|
1260
|
+
(0, import_log5.log)("onRemoteConnected", {
|
|
1179
1261
|
peerId: connection.peerId
|
|
1180
1262
|
}, {
|
|
1181
|
-
F:
|
|
1263
|
+
F: __dxlog_file6,
|
|
1182
1264
|
L: 59,
|
|
1183
1265
|
S: this,
|
|
1184
1266
|
C: (f, a) => f(...a)
|
|
1185
1267
|
});
|
|
1186
1268
|
(0, import_invariant5.invariant)(this._context, void 0, {
|
|
1187
|
-
F:
|
|
1269
|
+
F: __dxlog_file6,
|
|
1188
1270
|
L: 60,
|
|
1189
1271
|
S: this,
|
|
1190
1272
|
A: [
|
|
@@ -1192,20 +1274,18 @@ var MeshEchoReplicator = class {
|
|
|
1192
1274
|
""
|
|
1193
1275
|
]
|
|
1194
1276
|
});
|
|
1195
|
-
if (this._connectionsPerPeer.has(connection.peerId)) {
|
|
1196
|
-
this._context.onConnectionAuthScopeChanged(connection);
|
|
1197
|
-
} else {
|
|
1277
|
+
if (!this._connectionsPerPeer.has(connection.peerId)) {
|
|
1198
1278
|
this._connectionsPerPeer.set(connection.peerId, connection);
|
|
1199
1279
|
await connection.enable();
|
|
1200
1280
|
this._context.onConnectionOpen(connection);
|
|
1201
1281
|
}
|
|
1202
1282
|
},
|
|
1203
1283
|
onRemoteDisconnected: async () => {
|
|
1204
|
-
(0,
|
|
1284
|
+
(0, import_log5.log)("onRemoteDisconnected", {
|
|
1205
1285
|
peerId: connection.peerId
|
|
1206
1286
|
}, {
|
|
1207
|
-
F:
|
|
1208
|
-
L:
|
|
1287
|
+
F: __dxlog_file6,
|
|
1288
|
+
L: 69,
|
|
1209
1289
|
S: this,
|
|
1210
1290
|
C: (f, a) => f(...a)
|
|
1211
1291
|
});
|
|
@@ -1215,18 +1295,18 @@ var MeshEchoReplicator = class {
|
|
|
1215
1295
|
this._connections.delete(connection);
|
|
1216
1296
|
},
|
|
1217
1297
|
shouldAdvertize: async (params) => {
|
|
1218
|
-
(0,
|
|
1298
|
+
(0, import_log5.log)("shouldAdvertize", {
|
|
1219
1299
|
peerId: connection.peerId,
|
|
1220
1300
|
documentId: params.documentId
|
|
1221
1301
|
}, {
|
|
1222
|
-
F:
|
|
1223
|
-
L:
|
|
1302
|
+
F: __dxlog_file6,
|
|
1303
|
+
L: 76,
|
|
1224
1304
|
S: this,
|
|
1225
1305
|
C: (f, a) => f(...a)
|
|
1226
1306
|
});
|
|
1227
1307
|
(0, import_invariant5.invariant)(this._context, void 0, {
|
|
1228
|
-
F:
|
|
1229
|
-
L:
|
|
1308
|
+
F: __dxlog_file6,
|
|
1309
|
+
L: 77,
|
|
1230
1310
|
S: this,
|
|
1231
1311
|
A: [
|
|
1232
1312
|
"this._context",
|
|
@@ -1236,12 +1316,12 @@ var MeshEchoReplicator = class {
|
|
|
1236
1316
|
try {
|
|
1237
1317
|
const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
|
|
1238
1318
|
if (!spaceKey) {
|
|
1239
|
-
(0,
|
|
1319
|
+
(0, import_log5.log)("space key not found for share policy check", {
|
|
1240
1320
|
peerId: connection.peerId,
|
|
1241
1321
|
documentId: params.documentId
|
|
1242
1322
|
}, {
|
|
1243
|
-
F:
|
|
1244
|
-
L:
|
|
1323
|
+
F: __dxlog_file6,
|
|
1324
|
+
L: 81,
|
|
1245
1325
|
S: this,
|
|
1246
1326
|
C: (f, a) => f(...a)
|
|
1247
1327
|
});
|
|
@@ -1249,19 +1329,19 @@ var MeshEchoReplicator = class {
|
|
|
1249
1329
|
}
|
|
1250
1330
|
const authorizedDevices = this._authorizedDevices.get(spaceKey);
|
|
1251
1331
|
if (!connection.remoteDeviceKey) {
|
|
1252
|
-
(0,
|
|
1332
|
+
(0, import_log5.log)("device key not found for share policy check", {
|
|
1253
1333
|
peerId: connection.peerId,
|
|
1254
1334
|
documentId: params.documentId
|
|
1255
1335
|
}, {
|
|
1256
|
-
F:
|
|
1257
|
-
L:
|
|
1336
|
+
F: __dxlog_file6,
|
|
1337
|
+
L: 91,
|
|
1258
1338
|
S: this,
|
|
1259
1339
|
C: (f, a) => f(...a)
|
|
1260
1340
|
});
|
|
1261
1341
|
return false;
|
|
1262
1342
|
}
|
|
1263
1343
|
const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
|
|
1264
|
-
(0,
|
|
1344
|
+
(0, import_log5.log)("share policy check", {
|
|
1265
1345
|
localPeer: this._context.peerId,
|
|
1266
1346
|
remotePeer: connection.peerId,
|
|
1267
1347
|
documentId: params.documentId,
|
|
@@ -1269,16 +1349,16 @@ var MeshEchoReplicator = class {
|
|
|
1269
1349
|
spaceKey,
|
|
1270
1350
|
isAuthorized
|
|
1271
1351
|
}, {
|
|
1272
|
-
F:
|
|
1273
|
-
L:
|
|
1352
|
+
F: __dxlog_file6,
|
|
1353
|
+
L: 99,
|
|
1274
1354
|
S: this,
|
|
1275
1355
|
C: (f, a) => f(...a)
|
|
1276
1356
|
});
|
|
1277
1357
|
return isAuthorized;
|
|
1278
1358
|
} catch (err) {
|
|
1279
|
-
|
|
1280
|
-
F:
|
|
1281
|
-
L:
|
|
1359
|
+
import_log5.log.catch(err, void 0, {
|
|
1360
|
+
F: __dxlog_file6,
|
|
1361
|
+
L: 109,
|
|
1282
1362
|
S: this,
|
|
1283
1363
|
C: (f, a) => f(...a)
|
|
1284
1364
|
});
|
|
@@ -1290,16 +1370,16 @@ var MeshEchoReplicator = class {
|
|
|
1290
1370
|
return connection.replicatorExtension;
|
|
1291
1371
|
}
|
|
1292
1372
|
authorizeDevice(spaceKey, deviceKey) {
|
|
1293
|
-
(0,
|
|
1373
|
+
(0, import_log5.log)("authorizeDevice", {
|
|
1294
1374
|
spaceKey,
|
|
1295
1375
|
deviceKey
|
|
1296
1376
|
}, {
|
|
1297
|
-
F:
|
|
1298
|
-
L:
|
|
1377
|
+
F: __dxlog_file6,
|
|
1378
|
+
L: 120,
|
|
1299
1379
|
S: this,
|
|
1300
1380
|
C: (f, a) => f(...a)
|
|
1301
1381
|
});
|
|
1302
|
-
(0,
|
|
1382
|
+
(0, import_util3.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util3.ComplexSet(import_keys2.PublicKey.hash)).add(deviceKey);
|
|
1303
1383
|
}
|
|
1304
1384
|
};
|
|
1305
1385
|
var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
@@ -1331,13 +1411,13 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1331
1411
|
onStartReplication: async (info, remotePeerId) => {
|
|
1332
1412
|
this.remoteDeviceKey = remotePeerId;
|
|
1333
1413
|
this._remotePeerId = info.id;
|
|
1334
|
-
(0,
|
|
1414
|
+
(0, import_log5.log)("onStartReplication", {
|
|
1335
1415
|
id: info.id,
|
|
1336
1416
|
thisPeerId: this.peerId,
|
|
1337
1417
|
remotePeerId: remotePeerId.toHex()
|
|
1338
1418
|
}, {
|
|
1339
|
-
F:
|
|
1340
|
-
L:
|
|
1419
|
+
F: __dxlog_file6,
|
|
1420
|
+
L: 185,
|
|
1341
1421
|
S: this,
|
|
1342
1422
|
C: (f, a) => f(...a)
|
|
1343
1423
|
});
|
|
@@ -1360,8 +1440,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1360
1440
|
}
|
|
1361
1441
|
get peerId() {
|
|
1362
1442
|
(0, import_invariant5.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1363
|
-
F:
|
|
1364
|
-
L:
|
|
1443
|
+
F: __dxlog_file6,
|
|
1444
|
+
L: 208,
|
|
1365
1445
|
S: this,
|
|
1366
1446
|
A: [
|
|
1367
1447
|
"this._remotePeerId != null",
|
|
@@ -1379,8 +1459,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1379
1459
|
*/
|
|
1380
1460
|
async enable() {
|
|
1381
1461
|
(0, import_invariant5.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1382
|
-
F:
|
|
1383
|
-
L:
|
|
1462
|
+
F: __dxlog_file6,
|
|
1463
|
+
L: 221,
|
|
1384
1464
|
S: this,
|
|
1385
1465
|
A: [
|
|
1386
1466
|
"this._remotePeerId != null",
|
|
@@ -1402,6 +1482,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1402
1482
|
AuthStatus,
|
|
1403
1483
|
AutomergeDocumentLoaderImpl,
|
|
1404
1484
|
AutomergeHost,
|
|
1485
|
+
AutomergeStorageAdapter,
|
|
1405
1486
|
DataServiceImpl,
|
|
1406
1487
|
LevelDBStorageAdapter,
|
|
1407
1488
|
LocalHostNetworkAdapter,
|