@dxos/echo-pipeline 0.5.8 → 0.5.9-main.079a532
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-GANAND63.mjs → chunk-I2J5TTHJ.mjs} +48 -23
- package/dist/lib/browser/{chunk-GANAND63.mjs.map → chunk-I2J5TTHJ.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +152 -230
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +99 -4
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-M475BGBI.cjs → chunk-QPCNQ4ZK.cjs} +51 -25
- package/dist/lib/node/chunk-QPCNQ4ZK.cjs.map +7 -0
- package/dist/lib/node/index.cjs +174 -247
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +107 -13
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/automerge/automerge-doc-loader.d.ts +7 -3
- 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/echo-network-adapter.d.ts +6 -0
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-replicator.d.ts +1 -0
- package/dist/types/src/automerge/echo-replicator.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/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
- package/dist/types/src/space/space-manager.d.ts +2 -2
- package/dist/types/src/space/space-manager.d.ts.map +1 -1
- package/dist/types/src/space/space-protocol.d.ts +2 -2
- package/dist/types/src/space/space-protocol.d.ts.map +1 -1
- package/dist/types/src/space/space.d.ts +9 -1
- package/dist/types/src/space/space.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts +2 -2
- package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-network-adapter.d.ts +18 -0
- package/dist/types/src/testing/test-network-adapter.d.ts.map +1 -0
- package/package.json +33 -33
- package/src/automerge/automerge-doc-loader.test.ts +5 -2
- package/src/automerge/automerge-doc-loader.ts +10 -6
- package/src/automerge/automerge-host.test.ts +1 -553
- package/src/automerge/automerge-host.ts +17 -23
- package/src/automerge/automerge-repo.test.ts +450 -2
- package/src/automerge/echo-network-adapter.ts +24 -8
- package/src/automerge/echo-replicator.ts +2 -0
- package/src/automerge/index.ts +0 -1
- package/src/automerge/mesh-echo-replicator.ts +3 -1
- package/src/automerge/storage-adapter.test.ts +96 -66
- package/src/space/space-manager.ts +6 -4
- package/src/space/space-protocol.test.ts +5 -3
- package/src/space/space-protocol.ts +3 -3
- package/src/space/space.ts +32 -2
- package/src/testing/index.ts +1 -0
- package/src/testing/test-agent-builder.ts +4 -4
- package/src/testing/test-network-adapter.ts +62 -0
- package/dist/lib/node/chunk-M475BGBI.cjs.map +0 -7
- 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 -41
|
@@ -16,13 +16,14 @@ import {
|
|
|
16
16
|
SpaceProtocolSession,
|
|
17
17
|
TimeframeClock,
|
|
18
18
|
codec,
|
|
19
|
+
createIdFromSpaceKey,
|
|
19
20
|
createMappedFeedWriter,
|
|
20
21
|
hasInvitationExpired,
|
|
21
22
|
mapFeedIndexesToTimeframe,
|
|
22
23
|
mapTimeframeToFeedIndexes,
|
|
23
24
|
startAfter,
|
|
24
25
|
valueEncoding
|
|
25
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-I2J5TTHJ.mjs";
|
|
26
27
|
|
|
27
28
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
28
29
|
import { Event } from "@dxos/async";
|
|
@@ -31,7 +32,7 @@ import { Repo } from "@dxos/automerge/automerge-repo";
|
|
|
31
32
|
import { Context } from "@dxos/context";
|
|
32
33
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
33
34
|
import { PublicKey } from "@dxos/keys";
|
|
34
|
-
import { log as
|
|
35
|
+
import { log as log2 } from "@dxos/log";
|
|
35
36
|
import { objectPointerCodec } from "@dxos/protocols";
|
|
36
37
|
import { trace } from "@dxos/tracing";
|
|
37
38
|
import { mapValues } from "@dxos/util";
|
|
@@ -160,13 +161,14 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
160
161
|
peerId: this.peerId,
|
|
161
162
|
onConnectionOpen: this._onConnectionOpen.bind(this),
|
|
162
163
|
onConnectionClosed: this._onConnectionClosed.bind(this),
|
|
164
|
+
onConnectionAuthScopeChanged: this._onConnectionAuthScopeChanged.bind(this),
|
|
163
165
|
getContainingSpaceForDocument: this._params.getContainingSpaceForDocument
|
|
164
166
|
});
|
|
165
167
|
}
|
|
166
168
|
async removeReplicator(replicator) {
|
|
167
169
|
invariant(this._lifecycleState === LifecycleState.OPEN, void 0, {
|
|
168
170
|
F: __dxlog_file,
|
|
169
|
-
L:
|
|
171
|
+
L: 103,
|
|
170
172
|
S: this,
|
|
171
173
|
A: [
|
|
172
174
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -175,14 +177,13 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
175
177
|
});
|
|
176
178
|
invariant(this._replicators.has(replicator), void 0, {
|
|
177
179
|
F: __dxlog_file,
|
|
178
|
-
L:
|
|
180
|
+
L: 104,
|
|
179
181
|
S: this,
|
|
180
182
|
A: [
|
|
181
183
|
"this._replicators.has(replicator)",
|
|
182
184
|
""
|
|
183
185
|
]
|
|
184
186
|
});
|
|
185
|
-
"";
|
|
186
187
|
await replicator.disconnect();
|
|
187
188
|
this._replicators.delete(replicator);
|
|
188
189
|
}
|
|
@@ -248,27 +249,49 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
248
249
|
S: this,
|
|
249
250
|
C: (f, a) => f(...a)
|
|
250
251
|
});
|
|
251
|
-
this.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
252
|
+
this._emitPeerCandidate(connection);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Trigger doc-synchronizer shared documents set recalculation. Happens on peer-candidate.
|
|
256
|
+
* TODO(y): replace with a proper API call when sharePolicy update becomes supported by automerge-repo
|
|
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
|
+
]
|
|
257
276
|
});
|
|
277
|
+
this.emit("peer-disconnected", {
|
|
278
|
+
peerId: connection.peerId
|
|
279
|
+
});
|
|
280
|
+
this._emitPeerCandidate(connection);
|
|
258
281
|
}
|
|
259
282
|
_onConnectionClosed(connection) {
|
|
260
283
|
log("Connection closed", {
|
|
261
284
|
peerId: connection.peerId
|
|
262
285
|
}, {
|
|
263
286
|
F: __dxlog_file,
|
|
264
|
-
L:
|
|
287
|
+
L: 161,
|
|
265
288
|
S: this,
|
|
266
289
|
C: (f, a) => f(...a)
|
|
267
290
|
});
|
|
268
291
|
const entry = this._connections.get(connection.peerId);
|
|
269
292
|
invariant(entry, void 0, {
|
|
270
293
|
F: __dxlog_file,
|
|
271
|
-
L:
|
|
294
|
+
L: 163,
|
|
272
295
|
S: this,
|
|
273
296
|
A: [
|
|
274
297
|
"entry",
|
|
@@ -281,18 +304,27 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
|
281
304
|
});
|
|
282
305
|
void entry.reader.cancel().catch((err) => log.catch(err, void 0, {
|
|
283
306
|
F: __dxlog_file,
|
|
284
|
-
L:
|
|
307
|
+
L: 168,
|
|
285
308
|
S: this,
|
|
286
309
|
C: (f, a) => f(...a)
|
|
287
310
|
}));
|
|
288
311
|
void entry.writer.abort().catch((err) => log.catch(err, void 0, {
|
|
289
312
|
F: __dxlog_file,
|
|
290
|
-
L:
|
|
313
|
+
L: 169,
|
|
291
314
|
S: this,
|
|
292
315
|
C: (f, a) => f(...a)
|
|
293
316
|
}));
|
|
294
317
|
this._connections.delete(connection.peerId);
|
|
295
318
|
}
|
|
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
|
+
}
|
|
296
328
|
};
|
|
297
329
|
_ts_decorate([
|
|
298
330
|
synchronized
|
|
@@ -541,118 +573,6 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
541
573
|
}
|
|
542
574
|
};
|
|
543
575
|
|
|
544
|
-
// packages/core/echo/echo-pipeline/src/automerge/migrations.ts
|
|
545
|
-
import { IndexedDBStorageAdapter } from "@dxos/automerge/automerge-repo-storage-indexeddb";
|
|
546
|
-
import { log as log2 } from "@dxos/log";
|
|
547
|
-
import { StorageType } from "@dxos/random-access-storage";
|
|
548
|
-
|
|
549
|
-
// packages/core/echo/echo-pipeline/src/automerge/automerge-storage-adapter.ts
|
|
550
|
-
import { arrayToBuffer, bufferToArray } from "@dxos/util";
|
|
551
|
-
var AutomergeStorageAdapter = class {
|
|
552
|
-
constructor(_directory) {
|
|
553
|
-
this._directory = _directory;
|
|
554
|
-
this._state = "opened";
|
|
555
|
-
}
|
|
556
|
-
async load(key) {
|
|
557
|
-
if (this._state !== "opened") {
|
|
558
|
-
return void 0;
|
|
559
|
-
}
|
|
560
|
-
const filename = this._getFilename(key);
|
|
561
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
562
|
-
const { size } = await file.stat();
|
|
563
|
-
if (!size || size === 0) {
|
|
564
|
-
return void 0;
|
|
565
|
-
}
|
|
566
|
-
const buffer = await file.read(0, size);
|
|
567
|
-
return bufferToArray(buffer);
|
|
568
|
-
}
|
|
569
|
-
async save(key, data) {
|
|
570
|
-
if (this._state !== "opened") {
|
|
571
|
-
return void 0;
|
|
572
|
-
}
|
|
573
|
-
const filename = this._getFilename(key);
|
|
574
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
575
|
-
await file.write(0, arrayToBuffer(data));
|
|
576
|
-
await file.truncate?.(data.length);
|
|
577
|
-
await file.flush?.();
|
|
578
|
-
}
|
|
579
|
-
async remove(key) {
|
|
580
|
-
if (this._state !== "opened") {
|
|
581
|
-
return void 0;
|
|
582
|
-
}
|
|
583
|
-
const filename = this._getFilename(key);
|
|
584
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
585
|
-
await file.destroy();
|
|
586
|
-
}
|
|
587
|
-
async loadRange(keyPrefix) {
|
|
588
|
-
if (this._state !== "opened") {
|
|
589
|
-
return [];
|
|
590
|
-
}
|
|
591
|
-
const filename = this._getFilename(keyPrefix);
|
|
592
|
-
const entries = await this._directory.list();
|
|
593
|
-
return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
594
|
-
const file = this._directory.getOrCreateFile(entry);
|
|
595
|
-
const { size } = await file.stat();
|
|
596
|
-
const buffer = await file.read(0, size);
|
|
597
|
-
return {
|
|
598
|
-
key: this._getKeyFromFilename(entry),
|
|
599
|
-
data: bufferToArray(buffer)
|
|
600
|
-
};
|
|
601
|
-
}));
|
|
602
|
-
}
|
|
603
|
-
async removeRange(keyPrefix) {
|
|
604
|
-
if (this._state !== "opened") {
|
|
605
|
-
return void 0;
|
|
606
|
-
}
|
|
607
|
-
const filename = this._getFilename(keyPrefix);
|
|
608
|
-
const entries = await this._directory.list();
|
|
609
|
-
await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
610
|
-
const file = this._directory.getOrCreateFile(entry);
|
|
611
|
-
await file.destroy();
|
|
612
|
-
}));
|
|
613
|
-
}
|
|
614
|
-
async close() {
|
|
615
|
-
this._state = "closed";
|
|
616
|
-
}
|
|
617
|
-
_getFilename(key) {
|
|
618
|
-
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
619
|
-
}
|
|
620
|
-
_getKeyFromFilename(filename) {
|
|
621
|
-
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
622
|
-
}
|
|
623
|
-
};
|
|
624
|
-
|
|
625
|
-
// packages/core/echo/echo-pipeline/src/automerge/migrations.ts
|
|
626
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
|
|
627
|
-
var levelMigration = async ({ db, directory }) => {
|
|
628
|
-
const isNewLevel = !await db.iterator({
|
|
629
|
-
...encodingOptions
|
|
630
|
-
}).next();
|
|
631
|
-
if (!isNewLevel) {
|
|
632
|
-
return;
|
|
633
|
-
}
|
|
634
|
-
const oldStorageAdapter = directory.type === StorageType.IDB ? new IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory);
|
|
635
|
-
const chunks = await oldStorageAdapter.loadRange([]);
|
|
636
|
-
if (chunks.length === 0) {
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
const batch = db.batch();
|
|
640
|
-
log2.info("found chunks on old storage adapter", {
|
|
641
|
-
chunks: chunks.length
|
|
642
|
-
}, {
|
|
643
|
-
F: __dxlog_file3,
|
|
644
|
-
L: 36,
|
|
645
|
-
S: void 0,
|
|
646
|
-
C: (f, a) => f(...a)
|
|
647
|
-
});
|
|
648
|
-
for (const { key, data } of await oldStorageAdapter.loadRange([])) {
|
|
649
|
-
data && batch.put(key, data, {
|
|
650
|
-
...encodingOptions
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
await batch.write();
|
|
654
|
-
};
|
|
655
|
-
|
|
656
576
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
657
577
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
658
578
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -664,41 +584,37 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
664
584
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
665
585
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
666
586
|
}
|
|
667
|
-
var
|
|
587
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
668
588
|
var AutomergeHost = class {
|
|
669
|
-
constructor({
|
|
589
|
+
constructor({ db, indexMetadataStore }) {
|
|
670
590
|
this._ctx = new Context();
|
|
671
591
|
this._echoNetworkAdapter = new EchoNetworkAdapter({
|
|
672
592
|
getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
|
|
673
593
|
});
|
|
674
594
|
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
675
|
-
this._directory = directory;
|
|
676
|
-
this._db = db;
|
|
677
|
-
this._indexMetadataStore = indexMetadataStore;
|
|
678
|
-
}
|
|
679
|
-
async open() {
|
|
680
|
-
this._directory && await levelMigration({
|
|
681
|
-
db: this._db,
|
|
682
|
-
directory: this._directory
|
|
683
|
-
});
|
|
684
595
|
this._storage = new LevelDBStorageAdapter({
|
|
685
|
-
db
|
|
596
|
+
db,
|
|
686
597
|
callbacks: {
|
|
687
598
|
beforeSave: async (params) => this._beforeSave(params),
|
|
688
599
|
afterSave: async () => this._afterSave()
|
|
689
600
|
}
|
|
690
601
|
});
|
|
691
|
-
|
|
602
|
+
this._indexMetadataStore = indexMetadataStore;
|
|
603
|
+
}
|
|
604
|
+
async open() {
|
|
692
605
|
this._peerId = `host-${PublicKey.random().toHex()}`;
|
|
606
|
+
await this._storage.open?.();
|
|
693
607
|
this._clientNetwork = new LocalHostNetworkAdapter();
|
|
694
608
|
this._repo = new Repo({
|
|
695
609
|
peerId: this._peerId,
|
|
610
|
+
sharePolicy: this._sharePolicy.bind(this),
|
|
611
|
+
storage: this._storage,
|
|
696
612
|
network: [
|
|
613
|
+
// Downstream client.
|
|
697
614
|
this._clientNetwork,
|
|
615
|
+
// Upstream swarm.
|
|
698
616
|
this._echoNetworkAdapter
|
|
699
|
-
]
|
|
700
|
-
storage: this._storage,
|
|
701
|
-
sharePolicy: this._sharePolicy.bind(this)
|
|
617
|
+
]
|
|
702
618
|
});
|
|
703
619
|
this._clientNetwork.ready();
|
|
704
620
|
await this._echoNetworkAdapter.open();
|
|
@@ -734,13 +650,13 @@ var AutomergeHost = class {
|
|
|
734
650
|
const doc = this._repo.handles[documentId]?.docSync();
|
|
735
651
|
if (!doc) {
|
|
736
652
|
const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
|
|
737
|
-
|
|
653
|
+
log2("doc share policy check", {
|
|
738
654
|
peerId,
|
|
739
655
|
documentId,
|
|
740
656
|
isRequested
|
|
741
657
|
}, {
|
|
742
|
-
F:
|
|
743
|
-
L:
|
|
658
|
+
F: __dxlog_file3,
|
|
659
|
+
L: 143,
|
|
744
660
|
S: this,
|
|
745
661
|
C: (f, a) => f(...a)
|
|
746
662
|
});
|
|
@@ -825,8 +741,8 @@ var AutomergeHost = class {
|
|
|
825
741
|
async flush({ states }) {
|
|
826
742
|
await Promise.all(states?.map(async ({ heads, documentId }) => {
|
|
827
743
|
invariant3(heads, "heads are required for flush", {
|
|
828
|
-
F:
|
|
829
|
-
L:
|
|
744
|
+
F: __dxlog_file3,
|
|
745
|
+
L: 237,
|
|
830
746
|
S: this,
|
|
831
747
|
A: [
|
|
832
748
|
"heads",
|
|
@@ -899,8 +815,9 @@ var changeIsPresentInDoc = (doc, changeHash) => {
|
|
|
899
815
|
import { Event as Event2 } from "@dxos/async";
|
|
900
816
|
import { cancelWithContext } from "@dxos/context";
|
|
901
817
|
import { warnAfterTimeout } from "@dxos/debug";
|
|
818
|
+
import { SpaceDocVersion } from "@dxos/echo-protocol";
|
|
902
819
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
903
|
-
import { log as
|
|
820
|
+
import { log as log3 } from "@dxos/log";
|
|
904
821
|
import { trace as trace2 } from "@dxos/tracing";
|
|
905
822
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
906
823
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -912,11 +829,12 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
912
829
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
913
830
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
914
831
|
}
|
|
915
|
-
var
|
|
832
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
916
833
|
var AutomergeDocumentLoaderImpl = class {
|
|
917
|
-
constructor(
|
|
918
|
-
this.
|
|
834
|
+
constructor(_spaceId, _repo, _spaceKey) {
|
|
835
|
+
this._spaceId = _spaceId;
|
|
919
836
|
this._repo = _repo;
|
|
837
|
+
this._spaceKey = _spaceKey;
|
|
920
838
|
this._spaceRootDocHandle = null;
|
|
921
839
|
this._objectDocumentHandles = /* @__PURE__ */ new Map();
|
|
922
840
|
this._objectsPendingDocumentLoad = /* @__PURE__ */ new Set();
|
|
@@ -933,11 +851,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
933
851
|
return;
|
|
934
852
|
}
|
|
935
853
|
if (!spaceState.rootUrl) {
|
|
936
|
-
|
|
937
|
-
|
|
854
|
+
log3.error("Database opened with no rootUrl", {
|
|
855
|
+
spaceId: this._spaceId
|
|
938
856
|
}, {
|
|
939
|
-
F:
|
|
940
|
-
L:
|
|
857
|
+
F: __dxlog_file4,
|
|
858
|
+
L: 72,
|
|
941
859
|
S: this,
|
|
942
860
|
C: (f, a) => f(...a)
|
|
943
861
|
});
|
|
@@ -946,8 +864,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
946
864
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
947
865
|
const doc = existingDocHandle.docSync();
|
|
948
866
|
invariant4(doc, void 0, {
|
|
949
|
-
F:
|
|
950
|
-
L:
|
|
867
|
+
F: __dxlog_file4,
|
|
868
|
+
L: 77,
|
|
951
869
|
S: this,
|
|
952
870
|
A: [
|
|
953
871
|
"doc",
|
|
@@ -968,8 +886,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
968
886
|
const urlsToLoad = {};
|
|
969
887
|
for (const objectId of objectIds) {
|
|
970
888
|
invariant4(this._spaceRootDocHandle, void 0, {
|
|
971
|
-
F:
|
|
972
|
-
L:
|
|
889
|
+
F: __dxlog_file4,
|
|
890
|
+
L: 90,
|
|
973
891
|
S: this,
|
|
974
892
|
A: [
|
|
975
893
|
"this._spaceRootDocHandle",
|
|
@@ -981,8 +899,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
981
899
|
}
|
|
982
900
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
983
901
|
invariant4(spaceRootDoc, void 0, {
|
|
984
|
-
F:
|
|
985
|
-
L:
|
|
902
|
+
F: __dxlog_file4,
|
|
903
|
+
L: 95,
|
|
986
904
|
S: this,
|
|
987
905
|
A: [
|
|
988
906
|
"spaceRootDoc",
|
|
@@ -992,11 +910,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
992
910
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
993
911
|
if (documentUrl == null) {
|
|
994
912
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
995
|
-
|
|
913
|
+
log3.info("loading delayed until object links are initialized", {
|
|
996
914
|
objectId
|
|
997
915
|
}, {
|
|
998
|
-
F:
|
|
999
|
-
L:
|
|
916
|
+
F: __dxlog_file4,
|
|
917
|
+
L: 99,
|
|
1000
918
|
S: this,
|
|
1001
919
|
C: (f, a) => f(...a)
|
|
1002
920
|
});
|
|
@@ -1019,8 +937,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1019
937
|
}
|
|
1020
938
|
getSpaceRootDocHandle() {
|
|
1021
939
|
invariant4(this._spaceRootDocHandle, void 0, {
|
|
1022
|
-
F:
|
|
1023
|
-
L:
|
|
940
|
+
F: __dxlog_file4,
|
|
941
|
+
L: 122,
|
|
1024
942
|
S: this,
|
|
1025
943
|
A: [
|
|
1026
944
|
"this._spaceRootDocHandle",
|
|
@@ -1031,15 +949,17 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1031
949
|
}
|
|
1032
950
|
createDocumentForObject(objectId) {
|
|
1033
951
|
invariant4(this._spaceRootDocHandle, void 0, {
|
|
1034
|
-
F:
|
|
1035
|
-
L:
|
|
952
|
+
F: __dxlog_file4,
|
|
953
|
+
L: 127,
|
|
1036
954
|
S: this,
|
|
1037
955
|
A: [
|
|
1038
956
|
"this._spaceRootDocHandle",
|
|
1039
957
|
""
|
|
1040
958
|
]
|
|
1041
959
|
});
|
|
1042
|
-
const spaceDocHandle = this._repo.create(
|
|
960
|
+
const spaceDocHandle = this._repo.create({
|
|
961
|
+
version: SpaceDocVersion.CURRENT
|
|
962
|
+
});
|
|
1043
963
|
this._initDocAccess(spaceDocHandle);
|
|
1044
964
|
this.onObjectBoundToDocument(spaceDocHandle, objectId);
|
|
1045
965
|
this._spaceRootDocHandle.change((newDoc) => {
|
|
@@ -1070,30 +990,30 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1070
990
|
};
|
|
1071
991
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
1072
992
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
1073
|
-
|
|
993
|
+
log3.warn("object already inlined in a different document, ignoring the link", {
|
|
1074
994
|
...logMeta,
|
|
1075
995
|
actualDocumentUrl: objectDocumentHandle.url
|
|
1076
996
|
}, {
|
|
1077
|
-
F:
|
|
1078
|
-
L:
|
|
997
|
+
F: __dxlog_file4,
|
|
998
|
+
L: 159,
|
|
1079
999
|
S: this,
|
|
1080
1000
|
C: (f, a) => f(...a)
|
|
1081
1001
|
});
|
|
1082
1002
|
continue;
|
|
1083
1003
|
}
|
|
1084
1004
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
1085
|
-
|
|
1086
|
-
F:
|
|
1087
|
-
L:
|
|
1005
|
+
log3.warn("object document was already loaded", logMeta, {
|
|
1006
|
+
F: __dxlog_file4,
|
|
1007
|
+
L: 166,
|
|
1088
1008
|
S: this,
|
|
1089
1009
|
C: (f, a) => f(...a)
|
|
1090
1010
|
});
|
|
1091
1011
|
continue;
|
|
1092
1012
|
}
|
|
1093
1013
|
const handle = this._repo.find(automergeUrl);
|
|
1094
|
-
|
|
1095
|
-
F:
|
|
1096
|
-
L:
|
|
1014
|
+
log3.debug("document loading triggered", logMeta, {
|
|
1015
|
+
F: __dxlog_file4,
|
|
1016
|
+
L: 170,
|
|
1097
1017
|
S: this,
|
|
1098
1018
|
C: (f, a) => f(...a)
|
|
1099
1019
|
});
|
|
@@ -1105,18 +1025,18 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1105
1025
|
const docHandle = this._repo.find(url);
|
|
1106
1026
|
while (true) {
|
|
1107
1027
|
try {
|
|
1108
|
-
await warnAfterTimeout(5e3, "Automerge root doc load timeout (
|
|
1028
|
+
await warnAfterTimeout(5e3, "Automerge root doc load timeout (CoreDatabase)", async () => {
|
|
1109
1029
|
await cancelWithContext(ctx, docHandle.whenReady());
|
|
1110
1030
|
});
|
|
1111
1031
|
break;
|
|
1112
1032
|
} catch (err) {
|
|
1113
1033
|
if (`${err}`.includes("Timeout")) {
|
|
1114
|
-
|
|
1034
|
+
log3.info("wraparound", {
|
|
1115
1035
|
id: docHandle.documentId,
|
|
1116
1036
|
state: docHandle.state
|
|
1117
1037
|
}, {
|
|
1118
|
-
F:
|
|
1119
|
-
L:
|
|
1038
|
+
F: __dxlog_file4,
|
|
1039
|
+
L: 186,
|
|
1120
1040
|
S: this,
|
|
1121
1041
|
C: (f, a) => f(...a)
|
|
1122
1042
|
});
|
|
@@ -1156,9 +1076,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1156
1076
|
docUrl: handle.url
|
|
1157
1077
|
};
|
|
1158
1078
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1159
|
-
|
|
1160
|
-
F:
|
|
1161
|
-
L:
|
|
1079
|
+
log3.info("document loaded after all listeners were removed", logMeta, {
|
|
1080
|
+
F: __dxlog_file4,
|
|
1081
|
+
L: 222,
|
|
1162
1082
|
S: this,
|
|
1163
1083
|
C: (f, a) => f(...a)
|
|
1164
1084
|
});
|
|
@@ -1166,9 +1086,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1166
1086
|
}
|
|
1167
1087
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
1168
1088
|
if (objectDocHandle?.url !== handle.url) {
|
|
1169
|
-
|
|
1170
|
-
F:
|
|
1171
|
-
L:
|
|
1089
|
+
log3.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1090
|
+
F: __dxlog_file4,
|
|
1091
|
+
L: 227,
|
|
1172
1092
|
S: this,
|
|
1173
1093
|
C: (f, a) => f(...a)
|
|
1174
1094
|
});
|
|
@@ -1180,14 +1100,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1180
1100
|
});
|
|
1181
1101
|
} catch (err) {
|
|
1182
1102
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1183
|
-
|
|
1103
|
+
log3.warn("failed to load a document", {
|
|
1184
1104
|
objectId,
|
|
1185
1105
|
automergeUrl: handle.url,
|
|
1186
1106
|
retryLoading: shouldRetryLoading,
|
|
1187
1107
|
err
|
|
1188
1108
|
}, {
|
|
1189
|
-
F:
|
|
1190
|
-
L:
|
|
1109
|
+
F: __dxlog_file4,
|
|
1110
|
+
L: 233,
|
|
1191
1111
|
S: this,
|
|
1192
1112
|
C: (f, a) => f(...a)
|
|
1193
1113
|
});
|
|
@@ -1211,10 +1131,10 @@ import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
|
|
|
1211
1131
|
import { Resource as Resource2 } from "@dxos/context";
|
|
1212
1132
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1213
1133
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
1214
|
-
import { log as
|
|
1134
|
+
import { log as log4 } from "@dxos/log";
|
|
1215
1135
|
import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
|
|
1216
1136
|
import { ComplexMap, ComplexSet, defaultMap } from "@dxos/util";
|
|
1217
|
-
var
|
|
1137
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
|
|
1218
1138
|
var MeshEchoReplicator = class {
|
|
1219
1139
|
constructor() {
|
|
1220
1140
|
this._connections = /* @__PURE__ */ new Set();
|
|
@@ -1241,7 +1161,7 @@ var MeshEchoReplicator = class {
|
|
|
1241
1161
|
}
|
|
1242
1162
|
createExtension() {
|
|
1243
1163
|
invariant5(this._context, void 0, {
|
|
1244
|
-
F:
|
|
1164
|
+
F: __dxlog_file5,
|
|
1245
1165
|
L: 54,
|
|
1246
1166
|
S: this,
|
|
1247
1167
|
A: [
|
|
@@ -1252,16 +1172,16 @@ var MeshEchoReplicator = class {
|
|
|
1252
1172
|
const connection = new MeshReplicatorConnection({
|
|
1253
1173
|
ownPeerId: this._context.peerId,
|
|
1254
1174
|
onRemoteConnected: async () => {
|
|
1255
|
-
|
|
1175
|
+
log4("onRemoteConnected", {
|
|
1256
1176
|
peerId: connection.peerId
|
|
1257
1177
|
}, {
|
|
1258
|
-
F:
|
|
1178
|
+
F: __dxlog_file5,
|
|
1259
1179
|
L: 59,
|
|
1260
1180
|
S: this,
|
|
1261
1181
|
C: (f, a) => f(...a)
|
|
1262
1182
|
});
|
|
1263
1183
|
invariant5(this._context, void 0, {
|
|
1264
|
-
F:
|
|
1184
|
+
F: __dxlog_file5,
|
|
1265
1185
|
L: 60,
|
|
1266
1186
|
S: this,
|
|
1267
1187
|
A: [
|
|
@@ -1269,18 +1189,20 @@ var MeshEchoReplicator = class {
|
|
|
1269
1189
|
""
|
|
1270
1190
|
]
|
|
1271
1191
|
});
|
|
1272
|
-
if (
|
|
1192
|
+
if (this._connectionsPerPeer.has(connection.peerId)) {
|
|
1193
|
+
this._context.onConnectionAuthScopeChanged(connection);
|
|
1194
|
+
} else {
|
|
1273
1195
|
this._connectionsPerPeer.set(connection.peerId, connection);
|
|
1274
1196
|
await connection.enable();
|
|
1275
1197
|
this._context.onConnectionOpen(connection);
|
|
1276
1198
|
}
|
|
1277
1199
|
},
|
|
1278
1200
|
onRemoteDisconnected: async () => {
|
|
1279
|
-
|
|
1201
|
+
log4("onRemoteDisconnected", {
|
|
1280
1202
|
peerId: connection.peerId
|
|
1281
1203
|
}, {
|
|
1282
|
-
F:
|
|
1283
|
-
L:
|
|
1204
|
+
F: __dxlog_file5,
|
|
1205
|
+
L: 71,
|
|
1284
1206
|
S: this,
|
|
1285
1207
|
C: (f, a) => f(...a)
|
|
1286
1208
|
});
|
|
@@ -1290,18 +1212,18 @@ var MeshEchoReplicator = class {
|
|
|
1290
1212
|
this._connections.delete(connection);
|
|
1291
1213
|
},
|
|
1292
1214
|
shouldAdvertize: async (params) => {
|
|
1293
|
-
|
|
1215
|
+
log4("shouldAdvertize", {
|
|
1294
1216
|
peerId: connection.peerId,
|
|
1295
1217
|
documentId: params.documentId
|
|
1296
1218
|
}, {
|
|
1297
|
-
F:
|
|
1298
|
-
L:
|
|
1219
|
+
F: __dxlog_file5,
|
|
1220
|
+
L: 78,
|
|
1299
1221
|
S: this,
|
|
1300
1222
|
C: (f, a) => f(...a)
|
|
1301
1223
|
});
|
|
1302
1224
|
invariant5(this._context, void 0, {
|
|
1303
|
-
F:
|
|
1304
|
-
L:
|
|
1225
|
+
F: __dxlog_file5,
|
|
1226
|
+
L: 79,
|
|
1305
1227
|
S: this,
|
|
1306
1228
|
A: [
|
|
1307
1229
|
"this._context",
|
|
@@ -1311,12 +1233,12 @@ var MeshEchoReplicator = class {
|
|
|
1311
1233
|
try {
|
|
1312
1234
|
const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
|
|
1313
1235
|
if (!spaceKey) {
|
|
1314
|
-
|
|
1236
|
+
log4("space key not found for share policy check", {
|
|
1315
1237
|
peerId: connection.peerId,
|
|
1316
1238
|
documentId: params.documentId
|
|
1317
1239
|
}, {
|
|
1318
|
-
F:
|
|
1319
|
-
L:
|
|
1240
|
+
F: __dxlog_file5,
|
|
1241
|
+
L: 83,
|
|
1320
1242
|
S: this,
|
|
1321
1243
|
C: (f, a) => f(...a)
|
|
1322
1244
|
});
|
|
@@ -1324,19 +1246,19 @@ var MeshEchoReplicator = class {
|
|
|
1324
1246
|
}
|
|
1325
1247
|
const authorizedDevices = this._authorizedDevices.get(spaceKey);
|
|
1326
1248
|
if (!connection.remoteDeviceKey) {
|
|
1327
|
-
|
|
1249
|
+
log4("device key not found for share policy check", {
|
|
1328
1250
|
peerId: connection.peerId,
|
|
1329
1251
|
documentId: params.documentId
|
|
1330
1252
|
}, {
|
|
1331
|
-
F:
|
|
1332
|
-
L:
|
|
1253
|
+
F: __dxlog_file5,
|
|
1254
|
+
L: 93,
|
|
1333
1255
|
S: this,
|
|
1334
1256
|
C: (f, a) => f(...a)
|
|
1335
1257
|
});
|
|
1336
1258
|
return false;
|
|
1337
1259
|
}
|
|
1338
1260
|
const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
|
|
1339
|
-
|
|
1261
|
+
log4("share policy check", {
|
|
1340
1262
|
localPeer: this._context.peerId,
|
|
1341
1263
|
remotePeer: connection.peerId,
|
|
1342
1264
|
documentId: params.documentId,
|
|
@@ -1344,16 +1266,16 @@ var MeshEchoReplicator = class {
|
|
|
1344
1266
|
spaceKey,
|
|
1345
1267
|
isAuthorized
|
|
1346
1268
|
}, {
|
|
1347
|
-
F:
|
|
1348
|
-
L:
|
|
1269
|
+
F: __dxlog_file5,
|
|
1270
|
+
L: 101,
|
|
1349
1271
|
S: this,
|
|
1350
1272
|
C: (f, a) => f(...a)
|
|
1351
1273
|
});
|
|
1352
1274
|
return isAuthorized;
|
|
1353
1275
|
} catch (err) {
|
|
1354
|
-
|
|
1355
|
-
F:
|
|
1356
|
-
L:
|
|
1276
|
+
log4.catch(err, void 0, {
|
|
1277
|
+
F: __dxlog_file5,
|
|
1278
|
+
L: 111,
|
|
1357
1279
|
S: this,
|
|
1358
1280
|
C: (f, a) => f(...a)
|
|
1359
1281
|
});
|
|
@@ -1365,12 +1287,12 @@ var MeshEchoReplicator = class {
|
|
|
1365
1287
|
return connection.replicatorExtension;
|
|
1366
1288
|
}
|
|
1367
1289
|
authorizeDevice(spaceKey, deviceKey) {
|
|
1368
|
-
|
|
1290
|
+
log4("authorizeDevice", {
|
|
1369
1291
|
spaceKey,
|
|
1370
1292
|
deviceKey
|
|
1371
1293
|
}, {
|
|
1372
|
-
F:
|
|
1373
|
-
L:
|
|
1294
|
+
F: __dxlog_file5,
|
|
1295
|
+
L: 122,
|
|
1374
1296
|
S: this,
|
|
1375
1297
|
C: (f, a) => f(...a)
|
|
1376
1298
|
});
|
|
@@ -1406,13 +1328,13 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1406
1328
|
onStartReplication: async (info, remotePeerId) => {
|
|
1407
1329
|
this.remoteDeviceKey = remotePeerId;
|
|
1408
1330
|
this._remotePeerId = info.id;
|
|
1409
|
-
|
|
1331
|
+
log4("onStartReplication", {
|
|
1410
1332
|
id: info.id,
|
|
1411
1333
|
thisPeerId: this.peerId,
|
|
1412
1334
|
remotePeerId: remotePeerId.toHex()
|
|
1413
1335
|
}, {
|
|
1414
|
-
F:
|
|
1415
|
-
L:
|
|
1336
|
+
F: __dxlog_file5,
|
|
1337
|
+
L: 187,
|
|
1416
1338
|
S: this,
|
|
1417
1339
|
C: (f, a) => f(...a)
|
|
1418
1340
|
});
|
|
@@ -1435,8 +1357,8 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1435
1357
|
}
|
|
1436
1358
|
get peerId() {
|
|
1437
1359
|
invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1438
|
-
F:
|
|
1439
|
-
L:
|
|
1360
|
+
F: __dxlog_file5,
|
|
1361
|
+
L: 210,
|
|
1440
1362
|
S: this,
|
|
1441
1363
|
A: [
|
|
1442
1364
|
"this._remotePeerId != null",
|
|
@@ -1454,8 +1376,8 @@ var MeshReplicatorConnection = class extends Resource2 {
|
|
|
1454
1376
|
*/
|
|
1455
1377
|
async enable() {
|
|
1456
1378
|
invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1457
|
-
F:
|
|
1458
|
-
L:
|
|
1379
|
+
F: __dxlog_file5,
|
|
1380
|
+
L: 223,
|
|
1459
1381
|
S: this,
|
|
1460
1382
|
A: [
|
|
1461
1383
|
"this._remotePeerId != null",
|
|
@@ -1476,7 +1398,6 @@ export {
|
|
|
1476
1398
|
AuthStatus,
|
|
1477
1399
|
AutomergeDocumentLoaderImpl,
|
|
1478
1400
|
AutomergeHost,
|
|
1479
|
-
AutomergeStorageAdapter,
|
|
1480
1401
|
DataServiceImpl,
|
|
1481
1402
|
LevelDBStorageAdapter,
|
|
1482
1403
|
LocalHostNetworkAdapter,
|
|
@@ -1493,6 +1414,7 @@ export {
|
|
|
1493
1414
|
SpaceProtocolSession,
|
|
1494
1415
|
TimeframeClock,
|
|
1495
1416
|
codec,
|
|
1417
|
+
createIdFromSpaceKey,
|
|
1496
1418
|
createMappedFeedWriter,
|
|
1497
1419
|
encodingOptions,
|
|
1498
1420
|
getSpaceKeyFromDoc,
|