@dxos/echo-pipeline 0.4.9 → 0.4.10-main.06ef97a
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-RTEEJ723.mjs → chunk-RA6MLCZM.mjs} +14 -27
- package/dist/lib/browser/chunk-RA6MLCZM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +314 -12
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-7VZVCCNF.cjs → chunk-KGIYLJBT.cjs} +20 -33
- package/dist/lib/node/chunk-KGIYLJBT.cjs.map +7 -0
- package/dist/lib/node/index.cjs +335 -32
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +11 -11
- package/dist/types/src/automerge/automerge-doc-loader.d.ts +66 -0
- package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge-doc-loader.test.d.ts +2 -0
- package/dist/types/src/automerge/automerge-doc-loader.test.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge-host.d.ts +2 -1
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/index.d.ts +3 -0
- package/dist/types/src/automerge/index.d.ts.map +1 -1
- package/dist/types/src/automerge/reference.d.ts +15 -0
- package/dist/types/src/automerge/reference.d.ts.map +1 -0
- package/dist/types/src/automerge/types.d.ts +67 -0
- package/dist/types/src/automerge/types.d.ts.map +1 -0
- package/dist/types/src/space/space.d.ts +4 -8
- package/dist/types/src/space/space.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts +2 -2
- package/package.json +30 -30
- package/src/automerge/automerge-doc-loader.test.ts +97 -0
- package/src/automerge/automerge-doc-loader.ts +241 -0
- package/src/automerge/automerge-host.ts +15 -6
- package/src/automerge/index.ts +3 -0
- package/src/automerge/reference.ts +31 -0
- package/src/automerge/types.ts +83 -0
- package/src/db-host/data-service.ts +1 -1
- package/src/space/space.test.ts +7 -7
- package/src/space/space.ts +6 -21
- package/dist/lib/browser/chunk-RTEEJ723.mjs.map +0 -7
- package/dist/lib/node/chunk-7VZVCCNF.cjs.map +0 -7
package/dist/lib/node/index.cjs
CHANGED
|
@@ -18,34 +18,39 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var node_exports = {};
|
|
20
20
|
__export(node_exports, {
|
|
21
|
-
AuthExtension: () =>
|
|
22
|
-
AuthStatus: () =>
|
|
21
|
+
AuthExtension: () => import_chunk_KGIYLJBT.AuthExtension,
|
|
22
|
+
AuthStatus: () => import_chunk_KGIYLJBT.AuthStatus,
|
|
23
|
+
AutomergeDocumentLoaderImpl: () => AutomergeDocumentLoaderImpl,
|
|
23
24
|
AutomergeHost: () => AutomergeHost,
|
|
24
25
|
AutomergeStorageAdapter: () => AutomergeStorageAdapter,
|
|
25
|
-
DataServiceImpl: () =>
|
|
26
|
+
DataServiceImpl: () => import_chunk_KGIYLJBT.DataServiceImpl,
|
|
26
27
|
LocalHostNetworkAdapter: () => LocalHostNetworkAdapter,
|
|
27
|
-
MOCK_AUTH_PROVIDER: () =>
|
|
28
|
-
MOCK_AUTH_VERIFIER: () =>
|
|
28
|
+
MOCK_AUTH_PROVIDER: () => import_chunk_KGIYLJBT.MOCK_AUTH_PROVIDER,
|
|
29
|
+
MOCK_AUTH_VERIFIER: () => import_chunk_KGIYLJBT.MOCK_AUTH_VERIFIER,
|
|
29
30
|
MeshNetworkAdapter: () => MeshNetworkAdapter,
|
|
30
|
-
MetadataStore: () =>
|
|
31
|
-
Pipeline: () =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
MetadataStore: () => import_chunk_KGIYLJBT.MetadataStore,
|
|
32
|
+
Pipeline: () => import_chunk_KGIYLJBT.Pipeline,
|
|
33
|
+
REFERENCE_TYPE_TAG: () => REFERENCE_TYPE_TAG,
|
|
34
|
+
SnapshotManager: () => import_chunk_KGIYLJBT.SnapshotManager,
|
|
35
|
+
SnapshotStore: () => import_chunk_KGIYLJBT.SnapshotStore,
|
|
36
|
+
Space: () => import_chunk_KGIYLJBT.Space,
|
|
37
|
+
SpaceManager: () => import_chunk_KGIYLJBT.SpaceManager,
|
|
38
|
+
SpaceProtocol: () => import_chunk_KGIYLJBT.SpaceProtocol,
|
|
39
|
+
SpaceProtocolSession: () => import_chunk_KGIYLJBT.SpaceProtocolSession,
|
|
40
|
+
TimeframeClock: () => import_chunk_KGIYLJBT.TimeframeClock,
|
|
41
|
+
codec: () => import_chunk_KGIYLJBT.codec,
|
|
42
|
+
createMappedFeedWriter: () => import_chunk_KGIYLJBT.createMappedFeedWriter,
|
|
43
|
+
decodeReference: () => decodeReference,
|
|
44
|
+
encodeReference: () => encodeReference,
|
|
41
45
|
getSpaceKeyFromDoc: () => getSpaceKeyFromDoc,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
isEncodedReferenceObject: () => isEncodedReferenceObject,
|
|
47
|
+
mapFeedIndexesToTimeframe: () => import_chunk_KGIYLJBT.mapFeedIndexesToTimeframe,
|
|
48
|
+
mapTimeframeToFeedIndexes: () => import_chunk_KGIYLJBT.mapTimeframeToFeedIndexes,
|
|
49
|
+
startAfter: () => import_chunk_KGIYLJBT.startAfter,
|
|
50
|
+
valueEncoding: () => import_chunk_KGIYLJBT.valueEncoding
|
|
46
51
|
});
|
|
47
52
|
module.exports = __toCommonJS(node_exports);
|
|
48
|
-
var
|
|
53
|
+
var import_chunk_KGIYLJBT = require("./chunk-KGIYLJBT.cjs");
|
|
49
54
|
var import_automerge = require("@dxos/automerge/automerge");
|
|
50
55
|
var import_automerge_repo = require("@dxos/automerge/automerge-repo");
|
|
51
56
|
var import_automerge_repo_storage_indexeddb = require("@dxos/automerge/automerge-repo-storage-indexeddb");
|
|
@@ -67,6 +72,12 @@ var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
|
|
|
67
72
|
var import_invariant2 = require("@dxos/invariant");
|
|
68
73
|
var import_log3 = require("@dxos/log");
|
|
69
74
|
var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
|
|
75
|
+
var import_async3 = require("@dxos/async");
|
|
76
|
+
var import_context2 = require("@dxos/context");
|
|
77
|
+
var import_debug = require("@dxos/debug");
|
|
78
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
79
|
+
var import_log4 = require("@dxos/log");
|
|
80
|
+
var import_echo_db = require("@dxos/echo-db");
|
|
70
81
|
var AutomergeStorageAdapter = class {
|
|
71
82
|
constructor(_directory) {
|
|
72
83
|
this._directory = _directory;
|
|
@@ -441,7 +452,7 @@ var AutomergeHost = class {
|
|
|
441
452
|
isRequested
|
|
442
453
|
}, {
|
|
443
454
|
F: __dxlog_file3,
|
|
444
|
-
L:
|
|
455
|
+
L: 101,
|
|
445
456
|
S: this,
|
|
446
457
|
C: (f, a) => f(...a)
|
|
447
458
|
});
|
|
@@ -455,7 +466,7 @@ var AutomergeHost = class {
|
|
|
455
466
|
documentId
|
|
456
467
|
}, {
|
|
457
468
|
F: __dxlog_file3,
|
|
458
|
-
L:
|
|
469
|
+
L: 108,
|
|
459
470
|
S: this,
|
|
460
471
|
C: (f, a) => f(...a)
|
|
461
472
|
});
|
|
@@ -469,7 +480,7 @@ var AutomergeHost = class {
|
|
|
469
480
|
documentId
|
|
470
481
|
}, {
|
|
471
482
|
F: __dxlog_file3,
|
|
472
|
-
L:
|
|
483
|
+
L: 117,
|
|
473
484
|
S: this,
|
|
474
485
|
C: (f, a) => f(...a)
|
|
475
486
|
});
|
|
@@ -486,7 +497,7 @@ var AutomergeHost = class {
|
|
|
486
497
|
isAuthorized
|
|
487
498
|
}, {
|
|
488
499
|
F: __dxlog_file3,
|
|
489
|
-
L:
|
|
500
|
+
L: 123,
|
|
490
501
|
S: this,
|
|
491
502
|
C: (f, a) => f(...a)
|
|
492
503
|
});
|
|
@@ -494,7 +505,7 @@ var AutomergeHost = class {
|
|
|
494
505
|
} catch (err) {
|
|
495
506
|
import_log.log.catch(err, void 0, {
|
|
496
507
|
F: __dxlog_file3,
|
|
497
|
-
L:
|
|
508
|
+
L: 133,
|
|
498
509
|
S: this,
|
|
499
510
|
C: (f, a) => f(...a)
|
|
500
511
|
});
|
|
@@ -509,6 +520,7 @@ var AutomergeHost = class {
|
|
|
509
520
|
this._repo.on("document", listener);
|
|
510
521
|
this._ctx.onDispose(() => {
|
|
511
522
|
this._repo.off("document", listener);
|
|
523
|
+
Object.values(this._repo.handles).forEach((handle) => handle.off("change"));
|
|
512
524
|
});
|
|
513
525
|
}
|
|
514
526
|
}
|
|
@@ -524,9 +536,6 @@ var AutomergeHost = class {
|
|
|
524
536
|
_onDocument(handle) {
|
|
525
537
|
const listener = (event) => this._onUpdate(event);
|
|
526
538
|
handle.on("change", listener);
|
|
527
|
-
this._ctx.onDispose(() => {
|
|
528
|
-
handle.off("change", listener);
|
|
529
|
-
});
|
|
530
539
|
}
|
|
531
540
|
_onUpdate(event) {
|
|
532
541
|
if (this._metadata == null) {
|
|
@@ -554,7 +563,7 @@ var AutomergeHost = class {
|
|
|
554
563
|
}).catch((err) => {
|
|
555
564
|
this._ctx.disposed && import_log.log.catch(err, void 0, {
|
|
556
565
|
F: __dxlog_file3,
|
|
557
|
-
L:
|
|
566
|
+
L: 191,
|
|
558
567
|
S: this,
|
|
559
568
|
C: (f, a) => f(...a)
|
|
560
569
|
});
|
|
@@ -566,7 +575,7 @@ var AutomergeHost = class {
|
|
|
566
575
|
state: handle.state,
|
|
567
576
|
hasDoc: !!handle.docSync(),
|
|
568
577
|
heads: handle.docSync() ? import_automerge.next.getHeads(handle.docSync()) : null,
|
|
569
|
-
data: handle.docSync()
|
|
578
|
+
data: handle.docSync() && (0, import_util.mapValues)(handle.docSync(), (value, key) => {
|
|
570
579
|
try {
|
|
571
580
|
switch (key) {
|
|
572
581
|
case "access":
|
|
@@ -594,6 +603,10 @@ var AutomergeHost = class {
|
|
|
594
603
|
//
|
|
595
604
|
// Methods for client-services.
|
|
596
605
|
//
|
|
606
|
+
async flush({ documentIds }) {
|
|
607
|
+
await Promise.all(documentIds?.map((id) => this._repo.find(id).whenReady()) ?? []);
|
|
608
|
+
await this._repo.flush(documentIds);
|
|
609
|
+
}
|
|
597
610
|
syncRepo(request) {
|
|
598
611
|
return this._clientNetwork.syncRepo(request);
|
|
599
612
|
}
|
|
@@ -615,7 +628,7 @@ var AutomergeHost = class {
|
|
|
615
628
|
deviceKey
|
|
616
629
|
}, {
|
|
617
630
|
F: __dxlog_file3,
|
|
618
|
-
L:
|
|
631
|
+
L: 264,
|
|
619
632
|
S: this,
|
|
620
633
|
C: (f, a) => f(...a)
|
|
621
634
|
});
|
|
@@ -663,10 +676,296 @@ var getSpaceKeyFromDoc = (doc) => {
|
|
|
663
676
|
}
|
|
664
677
|
return String(rawSpaceKey);
|
|
665
678
|
};
|
|
679
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
680
|
+
var AutomergeDocumentLoaderImpl = class {
|
|
681
|
+
constructor(_spaceKey, _repo) {
|
|
682
|
+
this._spaceKey = _spaceKey;
|
|
683
|
+
this._repo = _repo;
|
|
684
|
+
this._spaceRootDocHandle = null;
|
|
685
|
+
this._objectDocumentHandles = /* @__PURE__ */ new Map();
|
|
686
|
+
this._objectsPendingDocumentLoad = /* @__PURE__ */ new Set();
|
|
687
|
+
this.onObjectDocumentLoaded = new import_async3.Event();
|
|
688
|
+
}
|
|
689
|
+
getAllHandles() {
|
|
690
|
+
return [
|
|
691
|
+
...new Set(this._objectDocumentHandles.values())
|
|
692
|
+
];
|
|
693
|
+
}
|
|
694
|
+
async loadSpaceRootDocHandle(ctx, spaceState) {
|
|
695
|
+
if (this._spaceRootDocHandle != null) {
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
if (!spaceState.rootUrl) {
|
|
699
|
+
import_log4.log.error("Database opened with no rootUrl", {
|
|
700
|
+
spaceKey: this._spaceKey
|
|
701
|
+
}, {
|
|
702
|
+
F: __dxlog_file4,
|
|
703
|
+
L: 66,
|
|
704
|
+
S: this,
|
|
705
|
+
C: (f, a) => f(...a)
|
|
706
|
+
});
|
|
707
|
+
this._createContextBoundSpaceRootDocument(ctx);
|
|
708
|
+
} else {
|
|
709
|
+
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
710
|
+
const doc = existingDocHandle.docSync();
|
|
711
|
+
(0, import_invariant3.invariant)(doc, void 0, {
|
|
712
|
+
F: __dxlog_file4,
|
|
713
|
+
L: 71,
|
|
714
|
+
S: this,
|
|
715
|
+
A: [
|
|
716
|
+
"doc",
|
|
717
|
+
""
|
|
718
|
+
]
|
|
719
|
+
});
|
|
720
|
+
if (doc.access == null) {
|
|
721
|
+
this._initDocAccess(existingDocHandle);
|
|
722
|
+
}
|
|
723
|
+
this._spaceRootDocHandle = existingDocHandle;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
loadObjectDocument(objectId) {
|
|
727
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
728
|
+
F: __dxlog_file4,
|
|
729
|
+
L: 80,
|
|
730
|
+
S: this,
|
|
731
|
+
A: [
|
|
732
|
+
"this._spaceRootDocHandle",
|
|
733
|
+
""
|
|
734
|
+
]
|
|
735
|
+
});
|
|
736
|
+
if (this._objectDocumentHandles.has(objectId) || this._objectsPendingDocumentLoad.has(objectId)) {
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
740
|
+
(0, import_invariant3.invariant)(spaceRootDoc, void 0, {
|
|
741
|
+
F: __dxlog_file4,
|
|
742
|
+
L: 85,
|
|
743
|
+
S: this,
|
|
744
|
+
A: [
|
|
745
|
+
"spaceRootDoc",
|
|
746
|
+
""
|
|
747
|
+
]
|
|
748
|
+
});
|
|
749
|
+
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
750
|
+
if (documentUrl == null) {
|
|
751
|
+
this._objectsPendingDocumentLoad.add(objectId);
|
|
752
|
+
import_log4.log.info("loading delayed until object links are initialized", {
|
|
753
|
+
objectId
|
|
754
|
+
}, {
|
|
755
|
+
F: __dxlog_file4,
|
|
756
|
+
L: 89,
|
|
757
|
+
S: this,
|
|
758
|
+
C: (f, a) => f(...a)
|
|
759
|
+
});
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
this._loadLinkedObjects({
|
|
763
|
+
[objectId]: documentUrl
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
onObjectLinksUpdated(links) {
|
|
767
|
+
if (!links) {
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
const linksAwaitingLoad = Object.entries(links).filter(([objectId]) => this._objectsPendingDocumentLoad.has(objectId));
|
|
771
|
+
this._loadLinkedObjects(Object.fromEntries(linksAwaitingLoad));
|
|
772
|
+
linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
|
|
773
|
+
}
|
|
774
|
+
getSpaceRootDocHandle() {
|
|
775
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
776
|
+
F: __dxlog_file4,
|
|
777
|
+
L: 107,
|
|
778
|
+
S: this,
|
|
779
|
+
A: [
|
|
780
|
+
"this._spaceRootDocHandle",
|
|
781
|
+
""
|
|
782
|
+
]
|
|
783
|
+
});
|
|
784
|
+
return this._spaceRootDocHandle;
|
|
785
|
+
}
|
|
786
|
+
createDocumentForObject(objectId) {
|
|
787
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
788
|
+
F: __dxlog_file4,
|
|
789
|
+
L: 112,
|
|
790
|
+
S: this,
|
|
791
|
+
A: [
|
|
792
|
+
"this._spaceRootDocHandle",
|
|
793
|
+
""
|
|
794
|
+
]
|
|
795
|
+
});
|
|
796
|
+
const spaceDocHandle = this._repo.create();
|
|
797
|
+
this._initDocAccess(spaceDocHandle);
|
|
798
|
+
this.onObjectBoundToDocument(spaceDocHandle, objectId);
|
|
799
|
+
this._spaceRootDocHandle.change((newDoc) => {
|
|
800
|
+
newDoc.links ??= {};
|
|
801
|
+
newDoc.links[objectId] = spaceDocHandle.url;
|
|
802
|
+
});
|
|
803
|
+
return spaceDocHandle;
|
|
804
|
+
}
|
|
805
|
+
onObjectBoundToDocument(handle, objectId) {
|
|
806
|
+
this._objectDocumentHandles.set(objectId, handle);
|
|
807
|
+
}
|
|
808
|
+
clearHandleReferences() {
|
|
809
|
+
const objectsWithHandles = [
|
|
810
|
+
...this._objectDocumentHandles.keys()
|
|
811
|
+
];
|
|
812
|
+
this._objectDocumentHandles.clear();
|
|
813
|
+
this._spaceRootDocHandle = null;
|
|
814
|
+
return objectsWithHandles;
|
|
815
|
+
}
|
|
816
|
+
_loadLinkedObjects(links) {
|
|
817
|
+
if (!links) {
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
for (const [objectId, automergeUrl] of Object.entries(links)) {
|
|
821
|
+
const logMeta = {
|
|
822
|
+
objectId,
|
|
823
|
+
automergeUrl
|
|
824
|
+
};
|
|
825
|
+
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
826
|
+
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
827
|
+
import_log4.log.warn("object already inlined in a different document, ignoring the link", {
|
|
828
|
+
...logMeta,
|
|
829
|
+
actualDocumentUrl: objectDocumentHandle.url
|
|
830
|
+
}, {
|
|
831
|
+
F: __dxlog_file4,
|
|
832
|
+
L: 142,
|
|
833
|
+
S: this,
|
|
834
|
+
C: (f, a) => f(...a)
|
|
835
|
+
});
|
|
836
|
+
continue;
|
|
837
|
+
}
|
|
838
|
+
if (objectDocumentHandle?.url === automergeUrl) {
|
|
839
|
+
import_log4.log.warn("object document was already loaded", logMeta, {
|
|
840
|
+
F: __dxlog_file4,
|
|
841
|
+
L: 149,
|
|
842
|
+
S: this,
|
|
843
|
+
C: (f, a) => f(...a)
|
|
844
|
+
});
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
847
|
+
const handle = this._repo.find(automergeUrl);
|
|
848
|
+
import_log4.log.debug("document loading triggered", logMeta, {
|
|
849
|
+
F: __dxlog_file4,
|
|
850
|
+
L: 153,
|
|
851
|
+
S: this,
|
|
852
|
+
C: (f, a) => f(...a)
|
|
853
|
+
});
|
|
854
|
+
this._objectDocumentHandles.set(objectId, handle);
|
|
855
|
+
void this._createObjectOnDocumentLoad(handle, objectId);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
async _initDocHandle(ctx, url) {
|
|
859
|
+
const docHandle = this._repo.find(url);
|
|
860
|
+
while (true) {
|
|
861
|
+
try {
|
|
862
|
+
await (0, import_debug.warnAfterTimeout)(5e3, "Automerge root doc load timeout (AutomergeDb)", async () => {
|
|
863
|
+
await (0, import_context2.cancelWithContext)(ctx, docHandle.whenReady());
|
|
864
|
+
});
|
|
865
|
+
break;
|
|
866
|
+
} catch (err) {
|
|
867
|
+
if (`${err}`.includes("Timeout")) {
|
|
868
|
+
import_log4.log.info("wraparound", {
|
|
869
|
+
id: docHandle.documentId,
|
|
870
|
+
state: docHandle.state
|
|
871
|
+
}, {
|
|
872
|
+
F: __dxlog_file4,
|
|
873
|
+
L: 169,
|
|
874
|
+
S: this,
|
|
875
|
+
C: (f, a) => f(...a)
|
|
876
|
+
});
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
throw err;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
if (docHandle.state === "unavailable") {
|
|
883
|
+
throw new Error("Automerge document is unavailable");
|
|
884
|
+
}
|
|
885
|
+
return docHandle;
|
|
886
|
+
}
|
|
887
|
+
_createContextBoundSpaceRootDocument(ctx) {
|
|
888
|
+
const docHandle = this._repo.create();
|
|
889
|
+
this._spaceRootDocHandle = docHandle;
|
|
890
|
+
ctx.onDispose(() => {
|
|
891
|
+
docHandle.delete();
|
|
892
|
+
this._spaceRootDocHandle = null;
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
_initDocAccess(handle) {
|
|
896
|
+
handle.change((newDoc) => {
|
|
897
|
+
newDoc.access ??= {
|
|
898
|
+
spaceKey: this._spaceKey.toHex()
|
|
899
|
+
};
|
|
900
|
+
newDoc.access.spaceKey = this._spaceKey.toHex();
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
async _createObjectOnDocumentLoad(handle, objectId) {
|
|
904
|
+
try {
|
|
905
|
+
await handle.doc([
|
|
906
|
+
"ready"
|
|
907
|
+
]);
|
|
908
|
+
const logMeta = {
|
|
909
|
+
objectId,
|
|
910
|
+
docUrl: handle.url
|
|
911
|
+
};
|
|
912
|
+
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
913
|
+
import_log4.log.info("document loaded after all listeners were removed", logMeta, {
|
|
914
|
+
F: __dxlog_file4,
|
|
915
|
+
L: 205,
|
|
916
|
+
S: this,
|
|
917
|
+
C: (f, a) => f(...a)
|
|
918
|
+
});
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
922
|
+
if (objectDocHandle?.url !== handle.url) {
|
|
923
|
+
import_log4.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
924
|
+
F: __dxlog_file4,
|
|
925
|
+
L: 210,
|
|
926
|
+
S: this,
|
|
927
|
+
C: (f, a) => f(...a)
|
|
928
|
+
});
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
this.onObjectDocumentLoaded.emit({
|
|
932
|
+
handle,
|
|
933
|
+
objectId
|
|
934
|
+
});
|
|
935
|
+
} catch (err) {
|
|
936
|
+
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
937
|
+
import_log4.log.warn("failed to load a document", {
|
|
938
|
+
objectId,
|
|
939
|
+
automergeUrl: handle.url,
|
|
940
|
+
retryLoading: shouldRetryLoading,
|
|
941
|
+
err
|
|
942
|
+
}, {
|
|
943
|
+
F: __dxlog_file4,
|
|
944
|
+
L: 216,
|
|
945
|
+
S: this,
|
|
946
|
+
C: (f, a) => f(...a)
|
|
947
|
+
});
|
|
948
|
+
if (shouldRetryLoading) {
|
|
949
|
+
await this._createObjectOnDocumentLoad(handle, objectId);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
955
|
+
var encodeReference = (reference) => ({
|
|
956
|
+
"@type": REFERENCE_TYPE_TAG,
|
|
957
|
+
// NOTE: Automerge do not support undefined values, so we need to use null instead.
|
|
958
|
+
itemId: reference.itemId ?? null,
|
|
959
|
+
protocol: reference.protocol ?? null,
|
|
960
|
+
host: reference.host ?? null
|
|
961
|
+
});
|
|
962
|
+
var decodeReference = (value) => new import_echo_db.Reference(value.itemId, value.protocol ?? void 0, value.host ?? void 0);
|
|
963
|
+
var isEncodedReferenceObject = (value) => typeof value === "object" && value !== null && value["@type"] === REFERENCE_TYPE_TAG;
|
|
666
964
|
// Annotate the CommonJS export names for ESM import in node:
|
|
667
965
|
0 && (module.exports = {
|
|
668
966
|
AuthExtension,
|
|
669
967
|
AuthStatus,
|
|
968
|
+
AutomergeDocumentLoaderImpl,
|
|
670
969
|
AutomergeHost,
|
|
671
970
|
AutomergeStorageAdapter,
|
|
672
971
|
DataServiceImpl,
|
|
@@ -676,6 +975,7 @@ var getSpaceKeyFromDoc = (doc) => {
|
|
|
676
975
|
MeshNetworkAdapter,
|
|
677
976
|
MetadataStore,
|
|
678
977
|
Pipeline,
|
|
978
|
+
REFERENCE_TYPE_TAG,
|
|
679
979
|
SnapshotManager,
|
|
680
980
|
SnapshotStore,
|
|
681
981
|
Space,
|
|
@@ -685,7 +985,10 @@ var getSpaceKeyFromDoc = (doc) => {
|
|
|
685
985
|
TimeframeClock,
|
|
686
986
|
codec,
|
|
687
987
|
createMappedFeedWriter,
|
|
988
|
+
decodeReference,
|
|
989
|
+
encodeReference,
|
|
688
990
|
getSpaceKeyFromDoc,
|
|
991
|
+
isEncodedReferenceObject,
|
|
689
992
|
mapFeedIndexesToTimeframe,
|
|
690
993
|
mapTimeframeToFeedIndexes,
|
|
691
994
|
startAfter,
|