@dxos/echo-pipeline 0.3.11-next.0fb359e → 0.3.11-next.e28df4f
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-W3SSYW3X.mjs → chunk-D7UMNYLJ.mjs} +272 -85
- package/dist/lib/browser/chunk-D7UMNYLJ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +33 -11
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-KTFCZMAY.cjs → chunk-GQW6RLGD.cjs} +267 -83
- package/dist/lib/node/chunk-GQW6RLGD.cjs.map +7 -0
- package/dist/lib/node/index.cjs +26 -26
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +46 -25
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/automerge/automerge-host.d.ts +37 -2
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/index.d.ts +1 -1
- package/dist/types/src/automerge/index.d.ts.map +1 -1
- package/dist/types/src/metadata/metadata-store.d.ts +1 -3
- package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
- package/dist/types/src/space/data-pipeline.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.map +1 -1
- package/dist/types/src/space/space.d.ts +1 -1
- package/dist/types/src/space/space.d.ts.map +1 -1
- package/dist/types/src/testing/change-metadata.d.ts +8 -0
- package/dist/types/src/testing/change-metadata.d.ts.map +1 -0
- package/dist/types/src/testing/database-test-rig.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/package.json +33 -33
- package/src/automerge/automerge-host.test.ts +319 -34
- package/src/automerge/automerge-host.ts +137 -20
- package/src/automerge/index.ts +1 -1
- package/src/metadata/metadata-store.ts +12 -2
- package/src/pipeline/pipeline-stress.test.ts +9 -2
- package/src/space/data-pipeline.ts +4 -3
- package/src/space/space-manager.ts +3 -3
- package/src/space/space-protocol.ts +4 -0
- package/src/space/space.ts +8 -3
- package/src/testing/change-metadata.ts +27 -0
- package/src/testing/database-test-rig.ts +4 -1
- package/src/testing/index.ts +1 -0
- package/src/testing/test-agent-builder.ts +1 -1
- package/dist/lib/browser/chunk-W3SSYW3X.mjs.map +0 -7
- package/dist/lib/node/chunk-KTFCZMAY.cjs.map +0 -7
|
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_GQW6RLGD_exports = {};
|
|
30
|
+
__export(chunk_GQW6RLGD_exports, {
|
|
31
31
|
AuthExtension: () => AuthExtension,
|
|
32
32
|
AuthStatus: () => AuthStatus,
|
|
33
33
|
AutomergeHost: () => AutomergeHost,
|
|
@@ -54,7 +54,7 @@ __export(chunk_KTFCZMAY_exports, {
|
|
|
54
54
|
startAfter: () => startAfter,
|
|
55
55
|
valueEncoding: () => valueEncoding
|
|
56
56
|
});
|
|
57
|
-
module.exports = __toCommonJS(
|
|
57
|
+
module.exports = __toCommonJS(chunk_GQW6RLGD_exports);
|
|
58
58
|
var import_hypercore = require("@dxos/hypercore");
|
|
59
59
|
var import_protocols = require("@dxos/protocols");
|
|
60
60
|
var import_invariant = require("@dxos/invariant");
|
|
@@ -140,6 +140,7 @@ var import_network_manager = require("@dxos/network-manager");
|
|
|
140
140
|
var import_teleport2 = require("@dxos/teleport");
|
|
141
141
|
var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
|
|
142
142
|
var import_teleport_extension_replicator = require("@dxos/teleport-extension-replicator");
|
|
143
|
+
var import_tracing4 = require("@dxos/tracing");
|
|
143
144
|
var import_util8 = require("@dxos/util");
|
|
144
145
|
var import_async9 = require("@dxos/async");
|
|
145
146
|
var import_debug4 = require("@dxos/debug");
|
|
@@ -147,11 +148,17 @@ var import_keys7 = require("@dxos/keys");
|
|
|
147
148
|
var import_log12 = require("@dxos/log");
|
|
148
149
|
var import_protocols7 = require("@dxos/protocols");
|
|
149
150
|
var import_util9 = require("@dxos/util");
|
|
151
|
+
var import_async10 = require("@dxos/async");
|
|
152
|
+
var import_automerge = require("@dxos/automerge/automerge");
|
|
150
153
|
var import_automerge_repo = require("@dxos/automerge/automerge-repo");
|
|
154
|
+
var import_automerge_repo_storage_indexeddb = require("@dxos/automerge/automerge-repo-storage-indexeddb");
|
|
151
155
|
var import_codec_protobuf2 = require("@dxos/codec-protobuf");
|
|
152
156
|
var import_invariant10 = require("@dxos/invariant");
|
|
157
|
+
var import_keys8 = require("@dxos/keys");
|
|
153
158
|
var import_log13 = require("@dxos/log");
|
|
159
|
+
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
154
160
|
var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
|
|
161
|
+
var import_tracing5 = require("@dxos/tracing");
|
|
155
162
|
var import_util10 = require("@dxos/util");
|
|
156
163
|
var codec = import_protocols.schema.getCodecForType("dxos.echo.feed.FeedMessage");
|
|
157
164
|
var valueEncoding = (0, import_hypercore.createCodecEncoding)(codec);
|
|
@@ -619,12 +626,12 @@ var emptyLargeSpaceMetadata = () => ({});
|
|
|
619
626
|
var EchoMetadata = import_protocols4.schema.getCodecForType("dxos.echo.metadata.EchoMetadata");
|
|
620
627
|
var LargeSpaceMetadata = import_protocols4.schema.getCodecForType("dxos.echo.metadata.LargeSpaceMetadata");
|
|
621
628
|
var MetadataStore = class {
|
|
622
|
-
constructor(
|
|
623
|
-
this._directory = _directory;
|
|
629
|
+
constructor(directory) {
|
|
624
630
|
this._metadata = emptyEchoMetadata();
|
|
625
631
|
this._spaceLargeMetadata = new import_util3.ComplexMap(import_keys3.PublicKey.hash);
|
|
626
632
|
this._metadataFile = void 0;
|
|
627
633
|
this.update = new import_async2.Event();
|
|
634
|
+
this._directory = directory;
|
|
628
635
|
}
|
|
629
636
|
get metadata() {
|
|
630
637
|
return this._metadata;
|
|
@@ -653,7 +660,7 @@ var MetadataStore = class {
|
|
|
653
660
|
name: file.filename
|
|
654
661
|
}, {
|
|
655
662
|
F: __dxlog_file4,
|
|
656
|
-
L:
|
|
663
|
+
L: 85,
|
|
657
664
|
S: this,
|
|
658
665
|
C: (f, a) => f(...a)
|
|
659
666
|
});
|
|
@@ -673,6 +680,9 @@ var MetadataStore = class {
|
|
|
673
680
|
await file.close();
|
|
674
681
|
}
|
|
675
682
|
}
|
|
683
|
+
/**
|
|
684
|
+
* @internal
|
|
685
|
+
*/
|
|
676
686
|
async _writeFile(file, codec2, data) {
|
|
677
687
|
const encoded = (0, import_util3.arrayToBuffer)(codec2.encode(data));
|
|
678
688
|
const checksum = import_crc_32.default.buf(encoded);
|
|
@@ -686,7 +696,7 @@ var MetadataStore = class {
|
|
|
686
696
|
checksum
|
|
687
697
|
}, {
|
|
688
698
|
F: __dxlog_file4,
|
|
689
|
-
L:
|
|
699
|
+
L: 120,
|
|
690
700
|
S: this,
|
|
691
701
|
C: (f, a) => f(...a)
|
|
692
702
|
});
|
|
@@ -718,7 +728,7 @@ var MetadataStore = class {
|
|
|
718
728
|
err
|
|
719
729
|
}, {
|
|
720
730
|
F: __dxlog_file4,
|
|
721
|
-
L:
|
|
731
|
+
L: 151,
|
|
722
732
|
S: this,
|
|
723
733
|
C: (f, a) => f(...a)
|
|
724
734
|
});
|
|
@@ -735,7 +745,7 @@ var MetadataStore = class {
|
|
|
735
745
|
err
|
|
736
746
|
}, {
|
|
737
747
|
F: __dxlog_file4,
|
|
738
|
-
L:
|
|
748
|
+
L: 163,
|
|
739
749
|
S: this,
|
|
740
750
|
C: (f, a) => f(...a)
|
|
741
751
|
});
|
|
@@ -765,7 +775,7 @@ var MetadataStore = class {
|
|
|
765
775
|
err
|
|
766
776
|
}, {
|
|
767
777
|
F: __dxlog_file4,
|
|
768
|
-
L:
|
|
778
|
+
L: 192,
|
|
769
779
|
S: this,
|
|
770
780
|
C: (f, a) => f(...a)
|
|
771
781
|
});
|
|
@@ -786,7 +796,7 @@ var MetadataStore = class {
|
|
|
786
796
|
const space = this.spaces.find((space2) => space2.key === spaceKey);
|
|
787
797
|
(0, import_invariant4.invariant)(space, "Space not found", {
|
|
788
798
|
F: __dxlog_file4,
|
|
789
|
-
L:
|
|
799
|
+
L: 214,
|
|
790
800
|
S: this,
|
|
791
801
|
A: [
|
|
792
802
|
"space",
|
|
@@ -810,7 +820,7 @@ var MetadataStore = class {
|
|
|
810
820
|
async clear() {
|
|
811
821
|
(0, import_log3.log)("clearing all metadata", void 0, {
|
|
812
822
|
F: __dxlog_file4,
|
|
813
|
-
L:
|
|
823
|
+
L: 233,
|
|
814
824
|
S: this,
|
|
815
825
|
C: (f, a) => f(...a)
|
|
816
826
|
});
|
|
@@ -823,7 +833,7 @@ var MetadataStore = class {
|
|
|
823
833
|
async setIdentityRecord(record) {
|
|
824
834
|
(0, import_invariant4.invariant)(!this._metadata.identity, "Cannot overwrite existing identity in metadata", {
|
|
825
835
|
F: __dxlog_file4,
|
|
826
|
-
L:
|
|
836
|
+
L: 243,
|
|
827
837
|
S: this,
|
|
828
838
|
A: [
|
|
829
839
|
"!this._metadata.identity",
|
|
@@ -837,7 +847,7 @@ var MetadataStore = class {
|
|
|
837
847
|
async addSpace(record) {
|
|
838
848
|
(0, import_invariant4.invariant)(!(this._metadata.spaces ?? []).find((space) => space.key === record.key), "Cannot overwrite existing space in metadata", {
|
|
839
849
|
F: __dxlog_file4,
|
|
840
|
-
L:
|
|
850
|
+
L: 251,
|
|
841
851
|
S: this,
|
|
842
852
|
A: [
|
|
843
853
|
"!(this._metadata.spaces ?? []).find((space) => space.key === record.key)",
|
|
@@ -1531,7 +1541,7 @@ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipelin
|
|
|
1531
1541
|
var MESSAGES_PER_SNAPSHOT = 10;
|
|
1532
1542
|
var AUTOMATIC_SNAPSHOT_DEBOUNCE_INTERVAL = 5e3;
|
|
1533
1543
|
var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL = 5e3;
|
|
1534
|
-
var DataPipeline = class
|
|
1544
|
+
var DataPipeline = class {
|
|
1535
1545
|
constructor(_params) {
|
|
1536
1546
|
this._params = _params;
|
|
1537
1547
|
this._ctx = new import_context5.Context();
|
|
@@ -1652,22 +1662,23 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1652
1662
|
this._epochCtx = void 0;
|
|
1653
1663
|
}
|
|
1654
1664
|
async _consumePipeline() {
|
|
1665
|
+
const pipeline = this._pipeline;
|
|
1655
1666
|
if (this.currentEpoch) {
|
|
1656
1667
|
const waitForOneEpoch = this.onNewEpoch.waitForCount(1);
|
|
1657
1668
|
await this._processEpochInSeparateTask(this.currentEpoch);
|
|
1658
1669
|
await waitForOneEpoch;
|
|
1659
1670
|
}
|
|
1660
1671
|
let messageCounter = 0;
|
|
1661
|
-
(0, import_invariant8.invariant)(
|
|
1672
|
+
(0, import_invariant8.invariant)(pipeline, "Pipeline is not initialized.", {
|
|
1662
1673
|
F: __dxlog_file9,
|
|
1663
|
-
L:
|
|
1674
|
+
L: 229,
|
|
1664
1675
|
S: this,
|
|
1665
1676
|
A: [
|
|
1666
|
-
"
|
|
1677
|
+
"pipeline",
|
|
1667
1678
|
"'Pipeline is not initialized.'"
|
|
1668
1679
|
]
|
|
1669
1680
|
});
|
|
1670
|
-
for await (const msg of
|
|
1681
|
+
for await (const msg of pipeline.consume()) {
|
|
1671
1682
|
const span = this._usage.beginRecording();
|
|
1672
1683
|
this._mutations.inc();
|
|
1673
1684
|
const { feedKey, seq, data } = msg;
|
|
@@ -1676,7 +1687,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1676
1687
|
seq
|
|
1677
1688
|
}, {
|
|
1678
1689
|
F: __dxlog_file9,
|
|
1679
|
-
L:
|
|
1690
|
+
L: 235,
|
|
1680
1691
|
S: this,
|
|
1681
1692
|
C: (f, a) => f(...a)
|
|
1682
1693
|
});
|
|
@@ -1688,7 +1699,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1688
1699
|
feedKey
|
|
1689
1700
|
}, {
|
|
1690
1701
|
F: __dxlog_file9,
|
|
1691
|
-
L:
|
|
1702
|
+
L: 241,
|
|
1692
1703
|
S: this,
|
|
1693
1704
|
C: (f, a) => f(...a)
|
|
1694
1705
|
});
|
|
@@ -1711,16 +1722,16 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1711
1722
|
spaceKey: this._params.spaceKey.toHex()
|
|
1712
1723
|
}, {
|
|
1713
1724
|
F: __dxlog_file9,
|
|
1714
|
-
L:
|
|
1725
|
+
L: 258,
|
|
1715
1726
|
S: this,
|
|
1716
1727
|
C: (f, a) => f(...a)
|
|
1717
1728
|
});
|
|
1718
|
-
await this._noteTargetStateIfNeeded(
|
|
1729
|
+
await this._noteTargetStateIfNeeded(pipeline.state.pendingTimeframe);
|
|
1719
1730
|
}
|
|
1720
1731
|
} catch (err) {
|
|
1721
1732
|
import_log8.log.catch(err, void 0, {
|
|
1722
1733
|
F: __dxlog_file9,
|
|
1723
|
-
L:
|
|
1734
|
+
L: 268,
|
|
1724
1735
|
S: this,
|
|
1725
1736
|
C: (f, a) => f(...a)
|
|
1726
1737
|
});
|
|
@@ -1735,7 +1746,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1735
1746
|
_createSnapshot() {
|
|
1736
1747
|
(0, import_invariant8.invariant)(this.databaseHost, "Database backend is not initialized.", {
|
|
1737
1748
|
F: __dxlog_file9,
|
|
1738
|
-
L:
|
|
1749
|
+
L: 282,
|
|
1739
1750
|
S: this,
|
|
1740
1751
|
A: [
|
|
1741
1752
|
"this.databaseHost",
|
|
@@ -1764,7 +1775,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1764
1775
|
} catch (err) {
|
|
1765
1776
|
import_log8.log.warn("Failed to cache properties", err, {
|
|
1766
1777
|
F: __dxlog_file9,
|
|
1767
|
-
L:
|
|
1778
|
+
L: 311,
|
|
1768
1779
|
S: this,
|
|
1769
1780
|
C: (f, a) => f(...a)
|
|
1770
1781
|
});
|
|
@@ -1793,14 +1804,14 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1793
1804
|
if (err instanceof import_protocols6.CancelledError) {
|
|
1794
1805
|
(0, import_log8.log)("Epoch processing cancelled.", void 0, {
|
|
1795
1806
|
F: __dxlog_file9,
|
|
1796
|
-
L:
|
|
1807
|
+
L: 347,
|
|
1797
1808
|
S: this,
|
|
1798
1809
|
C: (f, a) => f(...a)
|
|
1799
1810
|
});
|
|
1800
1811
|
} else {
|
|
1801
1812
|
import_log8.log.catch(err, void 0, {
|
|
1802
1813
|
F: __dxlog_file9,
|
|
1803
|
-
L:
|
|
1814
|
+
L: 349,
|
|
1804
1815
|
S: this,
|
|
1805
1816
|
C: (f, a) => f(...a)
|
|
1806
1817
|
});
|
|
@@ -1823,7 +1834,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1823
1834
|
async _processEpoch(ctx, epoch) {
|
|
1824
1835
|
(0, import_invariant8.invariant)(this._isOpen, "Space is closed.", {
|
|
1825
1836
|
F: __dxlog_file9,
|
|
1826
|
-
L:
|
|
1837
|
+
L: 373,
|
|
1827
1838
|
S: this,
|
|
1828
1839
|
A: [
|
|
1829
1840
|
"this._isOpen",
|
|
@@ -1832,7 +1843,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1832
1843
|
});
|
|
1833
1844
|
(0, import_invariant8.invariant)(this._pipeline, void 0, {
|
|
1834
1845
|
F: __dxlog_file9,
|
|
1835
|
-
L:
|
|
1846
|
+
L: 374,
|
|
1836
1847
|
S: this,
|
|
1837
1848
|
A: [
|
|
1838
1849
|
"this._pipeline",
|
|
@@ -1844,7 +1855,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1844
1855
|
epoch: (0, import_log8.omit)(epoch, "proof")
|
|
1845
1856
|
}, {
|
|
1846
1857
|
F: __dxlog_file9,
|
|
1847
|
-
L:
|
|
1858
|
+
L: 377,
|
|
1848
1859
|
S: this,
|
|
1849
1860
|
C: (f, a) => f(...a)
|
|
1850
1861
|
});
|
|
@@ -1854,7 +1865,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1854
1865
|
}
|
|
1855
1866
|
(0, import_log8.log)("restarting pipeline from epoch", void 0, {
|
|
1856
1867
|
F: __dxlog_file9,
|
|
1857
|
-
L:
|
|
1868
|
+
L: 383,
|
|
1858
1869
|
S: this,
|
|
1859
1870
|
C: (f, a) => f(...a)
|
|
1860
1871
|
});
|
|
@@ -1865,7 +1876,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1865
1876
|
async waitUntilTimeframe(timeframe) {
|
|
1866
1877
|
(0, import_invariant8.invariant)(this._pipeline, "Pipeline is not initialized.", {
|
|
1867
1878
|
F: __dxlog_file9,
|
|
1868
|
-
L:
|
|
1879
|
+
L: 390,
|
|
1869
1880
|
S: this,
|
|
1870
1881
|
A: [
|
|
1871
1882
|
"this._pipeline",
|
|
@@ -1877,7 +1888,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1877
1888
|
async createEpoch() {
|
|
1878
1889
|
(0, import_invariant8.invariant)(this._pipeline, void 0, {
|
|
1879
1890
|
F: __dxlog_file9,
|
|
1880
|
-
L:
|
|
1891
|
+
L: 396,
|
|
1881
1892
|
S: this,
|
|
1882
1893
|
A: [
|
|
1883
1894
|
"this._pipeline",
|
|
@@ -1886,7 +1897,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1886
1897
|
});
|
|
1887
1898
|
(0, import_invariant8.invariant)(this.currentEpoch, void 0, {
|
|
1888
1899
|
F: __dxlog_file9,
|
|
1889
|
-
L:
|
|
1900
|
+
L: 397,
|
|
1890
1901
|
S: this,
|
|
1891
1902
|
A: [
|
|
1892
1903
|
"this.currentEpoch",
|
|
@@ -1917,7 +1928,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1917
1928
|
} catch (err) {
|
|
1918
1929
|
import_log8.log.catch(err, void 0, {
|
|
1919
1930
|
F: __dxlog_file9,
|
|
1920
|
-
L:
|
|
1931
|
+
L: 427,
|
|
1921
1932
|
S: this,
|
|
1922
1933
|
C: (f, a) => f(...a)
|
|
1923
1934
|
});
|
|
@@ -1986,7 +1997,7 @@ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeli
|
|
|
1986
1997
|
var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2 = 500;
|
|
1987
1998
|
var CONTROL_PIPELINE_SNAPSHOT_DELAY = 1e4;
|
|
1988
1999
|
var USE_SNAPSHOTS = true;
|
|
1989
|
-
var ControlPipeline = class
|
|
2000
|
+
var ControlPipeline = class {
|
|
1990
2001
|
constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
|
|
1991
2002
|
this._ctx = new import_context6.Context();
|
|
1992
2003
|
this._lastTimeframeSaveTime = Date.now();
|
|
@@ -2230,15 +2241,15 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
2230
2241
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2231
2242
|
}
|
|
2232
2243
|
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space.ts";
|
|
2233
|
-
var Space = class
|
|
2244
|
+
var Space = class {
|
|
2234
2245
|
constructor(params) {
|
|
2235
|
-
this.
|
|
2246
|
+
this._addFeedMutex = new import_async7.Mutex();
|
|
2236
2247
|
this.onCredentialProcessed = new import_util6.Callback();
|
|
2237
2248
|
this.stateUpdate = new import_async7.Event();
|
|
2238
2249
|
this._isOpen = false;
|
|
2239
2250
|
(0, import_invariant9.invariant)(params.spaceKey && params.feedProvider, void 0, {
|
|
2240
2251
|
F: __dxlog_file11,
|
|
2241
|
-
L:
|
|
2252
|
+
L: 78,
|
|
2242
2253
|
S: this,
|
|
2243
2254
|
A: [
|
|
2244
2255
|
"params.spaceKey && params.feedProvider",
|
|
@@ -2282,7 +2293,7 @@ var Space = class Space2 {
|
|
|
2282
2293
|
credential
|
|
2283
2294
|
}, {
|
|
2284
2295
|
F: __dxlog_file11,
|
|
2285
|
-
L:
|
|
2296
|
+
L: 116,
|
|
2286
2297
|
S: this,
|
|
2287
2298
|
C: (f, a) => f(...a)
|
|
2288
2299
|
});
|
|
@@ -2302,7 +2313,7 @@ var Space = class Space2 {
|
|
|
2302
2313
|
if (this._dataFeed) {
|
|
2303
2314
|
pipeline.setWriteFeed(this._dataFeed);
|
|
2304
2315
|
}
|
|
2305
|
-
await this.
|
|
2316
|
+
await this._addFeedMutex.executeSynchronized(async () => {
|
|
2306
2317
|
for (const feed of this._controlPipeline.spaceState.feeds.values()) {
|
|
2307
2318
|
if (feed.assertion.designation === import_credentials2.AdmittedFeed.Designation.DATA && !pipeline.hasFeed(feed.key)) {
|
|
2308
2319
|
await pipeline.addFeed(await this._feedProvider(feed.key, {
|
|
@@ -2347,7 +2358,7 @@ var Space = class Space2 {
|
|
|
2347
2358
|
setControlFeed(feed) {
|
|
2348
2359
|
(0, import_invariant9.invariant)(!this._controlFeed, "Control feed already set.", {
|
|
2349
2360
|
F: __dxlog_file11,
|
|
2350
|
-
L:
|
|
2361
|
+
L: 191,
|
|
2351
2362
|
S: this,
|
|
2352
2363
|
A: [
|
|
2353
2364
|
"!this._controlFeed",
|
|
@@ -2361,7 +2372,7 @@ var Space = class Space2 {
|
|
|
2361
2372
|
setDataFeed(feed) {
|
|
2362
2373
|
(0, import_invariant9.invariant)(!this._dataFeed, "Data feed already set.", {
|
|
2363
2374
|
F: __dxlog_file11,
|
|
2364
|
-
L:
|
|
2375
|
+
L: 198,
|
|
2365
2376
|
S: this,
|
|
2366
2377
|
A: [
|
|
2367
2378
|
"!this._dataFeed",
|
|
@@ -2387,7 +2398,7 @@ var Space = class Space2 {
|
|
|
2387
2398
|
async open(ctx) {
|
|
2388
2399
|
(0, import_log9.log)("opening...", void 0, {
|
|
2389
2400
|
F: __dxlog_file11,
|
|
2390
|
-
L:
|
|
2401
|
+
L: 220,
|
|
2391
2402
|
S: this,
|
|
2392
2403
|
C: (f, a) => f(...a)
|
|
2393
2404
|
});
|
|
@@ -2400,7 +2411,7 @@ var Space = class Space2 {
|
|
|
2400
2411
|
this._isOpen = true;
|
|
2401
2412
|
(0, import_log9.log)("opened", void 0, {
|
|
2402
2413
|
F: __dxlog_file11,
|
|
2403
|
-
L:
|
|
2414
|
+
L: 231,
|
|
2404
2415
|
S: this,
|
|
2405
2416
|
C: (f, a) => f(...a)
|
|
2406
2417
|
});
|
|
@@ -2410,7 +2421,7 @@ var Space = class Space2 {
|
|
|
2410
2421
|
key: this._key
|
|
2411
2422
|
}, {
|
|
2412
2423
|
F: __dxlog_file11,
|
|
2413
|
-
L:
|
|
2424
|
+
L: 236,
|
|
2414
2425
|
S: this,
|
|
2415
2426
|
C: (f, a) => f(...a)
|
|
2416
2427
|
});
|
|
@@ -2424,7 +2435,7 @@ var Space = class Space2 {
|
|
|
2424
2435
|
this._isOpen = false;
|
|
2425
2436
|
(0, import_log9.log)("closed", void 0, {
|
|
2426
2437
|
F: __dxlog_file11,
|
|
2427
|
-
L:
|
|
2438
|
+
L: 249,
|
|
2428
2439
|
S: this,
|
|
2429
2440
|
C: (f, a) => f(...a)
|
|
2430
2441
|
});
|
|
@@ -2432,13 +2443,13 @@ var Space = class Space2 {
|
|
|
2432
2443
|
async initializeDataPipeline() {
|
|
2433
2444
|
(0, import_log9.log)("initializeDataPipeline", void 0, {
|
|
2434
2445
|
F: __dxlog_file11,
|
|
2435
|
-
L:
|
|
2446
|
+
L: 254,
|
|
2436
2447
|
S: this,
|
|
2437
2448
|
C: (f, a) => f(...a)
|
|
2438
2449
|
});
|
|
2439
2450
|
(0, import_invariant9.invariant)(this._isOpen, "Space must be open to initialize data pipeline.", {
|
|
2440
2451
|
F: __dxlog_file11,
|
|
2441
|
-
L:
|
|
2452
|
+
L: 255,
|
|
2442
2453
|
S: this,
|
|
2443
2454
|
A: [
|
|
2444
2455
|
"this._isOpen",
|
|
@@ -2448,6 +2459,15 @@ var Space = class Space2 {
|
|
|
2448
2459
|
await this._dataPipeline.open();
|
|
2449
2460
|
}
|
|
2450
2461
|
};
|
|
2462
|
+
_ts_decorate6([
|
|
2463
|
+
import_tracing2.trace.info()
|
|
2464
|
+
], Space.prototype, "protocol", void 0);
|
|
2465
|
+
_ts_decorate6([
|
|
2466
|
+
import_tracing2.trace.info()
|
|
2467
|
+
], Space.prototype, "_controlPipeline", void 0);
|
|
2468
|
+
_ts_decorate6([
|
|
2469
|
+
import_tracing2.trace.info()
|
|
2470
|
+
], Space.prototype, "_dataPipeline", void 0);
|
|
2451
2471
|
_ts_decorate6([
|
|
2452
2472
|
import_log9.logInfo,
|
|
2453
2473
|
import_tracing2.trace.info()
|
|
@@ -2508,7 +2528,7 @@ var SpaceProtocol = class {
|
|
|
2508
2528
|
key: feed.key
|
|
2509
2529
|
}, {
|
|
2510
2530
|
F: __dxlog_file12,
|
|
2511
|
-
L:
|
|
2531
|
+
L: 103,
|
|
2512
2532
|
S: this,
|
|
2513
2533
|
C: (f, a) => f(...a)
|
|
2514
2534
|
});
|
|
@@ -2531,7 +2551,7 @@ var SpaceProtocol = class {
|
|
|
2531
2551
|
await this.blobSync.open();
|
|
2532
2552
|
(0, import_log11.log)("starting...", void 0, {
|
|
2533
2553
|
F: __dxlog_file12,
|
|
2534
|
-
L:
|
|
2554
|
+
L: 129,
|
|
2535
2555
|
S: this,
|
|
2536
2556
|
C: (f, a) => f(...a)
|
|
2537
2557
|
});
|
|
@@ -2545,7 +2565,7 @@ var SpaceProtocol = class {
|
|
|
2545
2565
|
});
|
|
2546
2566
|
(0, import_log11.log)("started", void 0, {
|
|
2547
2567
|
F: __dxlog_file12,
|
|
2548
|
-
L:
|
|
2568
|
+
L: 139,
|
|
2549
2569
|
S: this,
|
|
2550
2570
|
C: (f, a) => f(...a)
|
|
2551
2571
|
});
|
|
@@ -2555,14 +2575,14 @@ var SpaceProtocol = class {
|
|
|
2555
2575
|
if (this._connection) {
|
|
2556
2576
|
(0, import_log11.log)("stopping...", void 0, {
|
|
2557
2577
|
F: __dxlog_file12,
|
|
2558
|
-
L:
|
|
2578
|
+
L: 146,
|
|
2559
2579
|
S: this,
|
|
2560
2580
|
C: (f, a) => f(...a)
|
|
2561
2581
|
});
|
|
2562
2582
|
await this._connection.close();
|
|
2563
2583
|
(0, import_log11.log)("stopped", void 0, {
|
|
2564
2584
|
F: __dxlog_file12,
|
|
2565
|
-
L:
|
|
2585
|
+
L: 148,
|
|
2566
2586
|
S: this,
|
|
2567
2587
|
C: (f, a) => f(...a)
|
|
2568
2588
|
});
|
|
@@ -2586,11 +2606,18 @@ var SpaceProtocol = class {
|
|
|
2586
2606
|
}
|
|
2587
2607
|
};
|
|
2588
2608
|
_ts_decorate7([
|
|
2589
|
-
import_log11.logInfo
|
|
2609
|
+
import_log11.logInfo,
|
|
2610
|
+
import_tracing4.trace.info()
|
|
2590
2611
|
], SpaceProtocol.prototype, "_topic", void 0);
|
|
2612
|
+
_ts_decorate7([
|
|
2613
|
+
import_tracing4.trace.info()
|
|
2614
|
+
], SpaceProtocol.prototype, "_spaceKey", void 0);
|
|
2591
2615
|
_ts_decorate7([
|
|
2592
2616
|
import_log11.logInfo
|
|
2593
2617
|
], SpaceProtocol.prototype, "_ownPeerKey", null);
|
|
2618
|
+
SpaceProtocol = _ts_decorate7([
|
|
2619
|
+
import_tracing4.trace.resource()
|
|
2620
|
+
], SpaceProtocol);
|
|
2594
2621
|
var AuthStatus;
|
|
2595
2622
|
(function(AuthStatus2) {
|
|
2596
2623
|
AuthStatus2["INITIAL"] = "INITIAL";
|
|
@@ -2603,7 +2630,7 @@ var SpaceProtocolSession = class {
|
|
|
2603
2630
|
this.replicator = new import_teleport_extension_replicator.ReplicatorExtension().setOptions({
|
|
2604
2631
|
upload: true
|
|
2605
2632
|
});
|
|
2606
|
-
this._authStatus =
|
|
2633
|
+
this._authStatus = "INITIAL";
|
|
2607
2634
|
this._wireParams = wireParams;
|
|
2608
2635
|
this._swarmIdentity = swarmIdentity;
|
|
2609
2636
|
this._onSessionAuth = onSessionAuth;
|
|
@@ -2628,15 +2655,15 @@ var SpaceProtocolSession = class {
|
|
|
2628
2655
|
onAuthSuccess: () => {
|
|
2629
2656
|
(0, import_log11.log)("Peer authenticated", void 0, {
|
|
2630
2657
|
F: __dxlog_file12,
|
|
2631
|
-
L:
|
|
2658
|
+
L: 245,
|
|
2632
2659
|
S: this,
|
|
2633
2660
|
C: (f, a) => f(...a)
|
|
2634
2661
|
});
|
|
2635
|
-
this._authStatus =
|
|
2662
|
+
this._authStatus = "SUCCESS";
|
|
2636
2663
|
this._onSessionAuth?.(this._teleport);
|
|
2637
2664
|
},
|
|
2638
2665
|
onAuthFailure: () => {
|
|
2639
|
-
this._authStatus =
|
|
2666
|
+
this._authStatus = "FAILURE";
|
|
2640
2667
|
this._onAuthFailure?.(this._teleport);
|
|
2641
2668
|
}
|
|
2642
2669
|
}));
|
|
@@ -2646,7 +2673,7 @@ var SpaceProtocolSession = class {
|
|
|
2646
2673
|
async close() {
|
|
2647
2674
|
(0, import_log11.log)("close", void 0, {
|
|
2648
2675
|
F: __dxlog_file12,
|
|
2649
|
-
L:
|
|
2676
|
+
L: 261,
|
|
2650
2677
|
S: this,
|
|
2651
2678
|
C: (f, a) => f(...a)
|
|
2652
2679
|
});
|
|
@@ -2673,7 +2700,7 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
2673
2700
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2674
2701
|
}
|
|
2675
2702
|
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
|
|
2676
|
-
var SpaceManager = class
|
|
2703
|
+
var SpaceManager = class {
|
|
2677
2704
|
constructor({ feedStore, networkManager, modelFactory, metadataStore, snapshotStore, blobStore }) {
|
|
2678
2705
|
this._spaces = new import_util9.ComplexMap(import_keys7.PublicKey.hash);
|
|
2679
2706
|
this._instanceId = import_keys7.PublicKey.random().toHex();
|
|
@@ -2695,7 +2722,7 @@ var SpaceManager = class SpaceManager2 {
|
|
|
2695
2722
|
...this._spaces.values()
|
|
2696
2723
|
].map((space) => space.close()));
|
|
2697
2724
|
}
|
|
2698
|
-
async constructSpace({ metadata, swarmIdentity,
|
|
2725
|
+
async constructSpace({ metadata, swarmIdentity, onAuthorizedConnection, onAuthFailure, memberKey }) {
|
|
2699
2726
|
import_log12.log.trace("dxos.echo.space-manager.construct-space", import_protocols7.trace.begin({
|
|
2700
2727
|
id: this._instanceId
|
|
2701
2728
|
}), {
|
|
@@ -2718,7 +2745,7 @@ var SpaceManager = class SpaceManager2 {
|
|
|
2718
2745
|
topic: spaceKey,
|
|
2719
2746
|
swarmIdentity,
|
|
2720
2747
|
networkManager: this._networkManager,
|
|
2721
|
-
onSessionAuth:
|
|
2748
|
+
onSessionAuth: onAuthorizedConnection,
|
|
2722
2749
|
onAuthFailure,
|
|
2723
2750
|
blobStore: this._blobStore
|
|
2724
2751
|
});
|
|
@@ -2754,20 +2781,105 @@ _ts_decorate8([
|
|
|
2754
2781
|
SpaceManager = _ts_decorate8([
|
|
2755
2782
|
(0, import_async9.trackLeaks)("open", "close")
|
|
2756
2783
|
], SpaceManager);
|
|
2784
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
2785
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2786
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2787
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2788
|
+
else
|
|
2789
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2790
|
+
if (d = decorators[i])
|
|
2791
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2792
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2793
|
+
}
|
|
2757
2794
|
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
2758
2795
|
var AutomergeHost = class {
|
|
2759
2796
|
constructor(storageDirectory) {
|
|
2797
|
+
this._authorizedDevices = new import_util10.ComplexMap(import_keys8.PublicKey.hash);
|
|
2760
2798
|
this._meshNetwork = new MeshNetworkAdapter();
|
|
2761
2799
|
this._clientNetwork = new LocalHostNetworkAdapter();
|
|
2762
|
-
this._storage = new AutomergeStorageAdapter(storageDirectory);
|
|
2800
|
+
this._storage = storageDirectory.type === import_random_access_storage.StorageType.IDB ? new import_automerge_repo_storage_indexeddb.IndexedDBStorageAdapter(storageDirectory.path, "data") : new AutomergeStorageAdapter(storageDirectory);
|
|
2763
2801
|
this._repo = new import_automerge_repo.Repo({
|
|
2802
|
+
peerId: `host-${import_keys8.PublicKey.random().toHex()}`,
|
|
2764
2803
|
network: [
|
|
2765
2804
|
this._clientNetwork,
|
|
2766
2805
|
this._meshNetwork
|
|
2767
2806
|
],
|
|
2768
2807
|
storage: this._storage,
|
|
2769
2808
|
// TODO(dmaretskyi): Share based on HALO permissions and space affinity.
|
|
2770
|
-
|
|
2809
|
+
// Hosts, running in the worker, don't share documents unless requested by other peers.
|
|
2810
|
+
sharePolicy: async (peerId, documentId) => {
|
|
2811
|
+
if (peerId.startsWith("client-")) {
|
|
2812
|
+
return true;
|
|
2813
|
+
}
|
|
2814
|
+
if (!documentId) {
|
|
2815
|
+
return false;
|
|
2816
|
+
}
|
|
2817
|
+
const doc = this._repo.handles[documentId]?.docSync();
|
|
2818
|
+
if (!doc) {
|
|
2819
|
+
(0, import_log13.log)("doc not found for share policy check", {
|
|
2820
|
+
peerId,
|
|
2821
|
+
documentId
|
|
2822
|
+
}, {
|
|
2823
|
+
F: __dxlog_file14,
|
|
2824
|
+
L: 68,
|
|
2825
|
+
S: this,
|
|
2826
|
+
C: (f, a) => f(...a)
|
|
2827
|
+
});
|
|
2828
|
+
return false;
|
|
2829
|
+
}
|
|
2830
|
+
try {
|
|
2831
|
+
if (!doc.experimental_spaceKey) {
|
|
2832
|
+
(0, import_log13.log)("space key not found for share policy check", {
|
|
2833
|
+
peerId,
|
|
2834
|
+
documentId
|
|
2835
|
+
}, {
|
|
2836
|
+
F: __dxlog_file14,
|
|
2837
|
+
L: 74,
|
|
2838
|
+
S: this,
|
|
2839
|
+
C: (f, a) => f(...a)
|
|
2840
|
+
});
|
|
2841
|
+
return false;
|
|
2842
|
+
}
|
|
2843
|
+
const spaceKey = import_keys8.PublicKey.from(doc.experimental_spaceKey);
|
|
2844
|
+
const authorizedDevices = this._authorizedDevices.get(spaceKey);
|
|
2845
|
+
const deviceKeyHex = this.repo.peerMetadataByPeerId[peerId]?.dxos_deviceKey;
|
|
2846
|
+
if (!deviceKeyHex) {
|
|
2847
|
+
(0, import_log13.log)("device key not found for share policy check", {
|
|
2848
|
+
peerId,
|
|
2849
|
+
documentId
|
|
2850
|
+
}, {
|
|
2851
|
+
F: __dxlog_file14,
|
|
2852
|
+
L: 84,
|
|
2853
|
+
S: this,
|
|
2854
|
+
C: (f, a) => f(...a)
|
|
2855
|
+
});
|
|
2856
|
+
return false;
|
|
2857
|
+
}
|
|
2858
|
+
const deviceKey = import_keys8.PublicKey.from(deviceKeyHex);
|
|
2859
|
+
const isAuthorized = authorizedDevices?.has(deviceKey) ?? false;
|
|
2860
|
+
(0, import_log13.log)("share policy check", {
|
|
2861
|
+
peerId,
|
|
2862
|
+
documentId,
|
|
2863
|
+
deviceKey,
|
|
2864
|
+
spaceKey,
|
|
2865
|
+
isAuthorized
|
|
2866
|
+
}, {
|
|
2867
|
+
F: __dxlog_file14,
|
|
2868
|
+
L: 90,
|
|
2869
|
+
S: this,
|
|
2870
|
+
C: (f, a) => f(...a)
|
|
2871
|
+
});
|
|
2872
|
+
return isAuthorized;
|
|
2873
|
+
} catch (err) {
|
|
2874
|
+
import_log13.log.catch(err, void 0, {
|
|
2875
|
+
F: __dxlog_file14,
|
|
2876
|
+
L: 93,
|
|
2877
|
+
S: this,
|
|
2878
|
+
C: (f, a) => f(...a)
|
|
2879
|
+
});
|
|
2880
|
+
return false;
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2771
2883
|
});
|
|
2772
2884
|
this._clientNetwork.ready();
|
|
2773
2885
|
this._meshNetwork.ready();
|
|
@@ -2775,7 +2887,18 @@ var AutomergeHost = class {
|
|
|
2775
2887
|
get repo() {
|
|
2776
2888
|
return this._repo;
|
|
2777
2889
|
}
|
|
2890
|
+
_automergeDocs() {
|
|
2891
|
+
return (0, import_util10.mapValues)(this._repo.handles, (handle) => ({
|
|
2892
|
+
state: handle.state,
|
|
2893
|
+
hasDoc: !!handle.docSync(),
|
|
2894
|
+
heads: handle.docSync() ? import_automerge.next.getHeads(handle.docSync()) : null
|
|
2895
|
+
}));
|
|
2896
|
+
}
|
|
2897
|
+
_automergePeers() {
|
|
2898
|
+
return this._repo.peers;
|
|
2899
|
+
}
|
|
2778
2900
|
async close() {
|
|
2901
|
+
this._storage instanceof AutomergeStorageAdapter && await this._storage.close();
|
|
2779
2902
|
await this._clientNetwork.close();
|
|
2780
2903
|
}
|
|
2781
2904
|
//
|
|
@@ -2787,7 +2910,7 @@ var AutomergeHost = class {
|
|
|
2787
2910
|
sendSyncMessage(request) {
|
|
2788
2911
|
return this._clientNetwork.sendSyncMessage(request);
|
|
2789
2912
|
}
|
|
2790
|
-
getHostInfo() {
|
|
2913
|
+
async getHostInfo() {
|
|
2791
2914
|
return this._clientNetwork.getHostInfo();
|
|
2792
2915
|
}
|
|
2793
2916
|
//
|
|
@@ -2796,11 +2919,28 @@ var AutomergeHost = class {
|
|
|
2796
2919
|
createExtension() {
|
|
2797
2920
|
return this._meshNetwork.createExtension();
|
|
2798
2921
|
}
|
|
2922
|
+
authorizeDevice(spaceKey, deviceKey) {
|
|
2923
|
+
(0, import_util10.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util10.ComplexSet(import_keys8.PublicKey.hash)).add(deviceKey);
|
|
2924
|
+
}
|
|
2799
2925
|
};
|
|
2926
|
+
_ts_decorate9([
|
|
2927
|
+
import_tracing5.trace.info({
|
|
2928
|
+
depth: null
|
|
2929
|
+
})
|
|
2930
|
+
], AutomergeHost.prototype, "_automergeDocs", null);
|
|
2931
|
+
_ts_decorate9([
|
|
2932
|
+
import_tracing5.trace.info({
|
|
2933
|
+
depth: null
|
|
2934
|
+
})
|
|
2935
|
+
], AutomergeHost.prototype, "_automergePeers", null);
|
|
2936
|
+
AutomergeHost = _ts_decorate9([
|
|
2937
|
+
import_tracing5.trace.resource()
|
|
2938
|
+
], AutomergeHost);
|
|
2800
2939
|
var LocalHostNetworkAdapter = class extends import_automerge_repo.NetworkAdapter {
|
|
2801
2940
|
constructor() {
|
|
2802
2941
|
super(...arguments);
|
|
2803
2942
|
this._peers = /* @__PURE__ */ new Map();
|
|
2943
|
+
this._connected = new import_async10.Trigger();
|
|
2804
2944
|
}
|
|
2805
2945
|
/**
|
|
2806
2946
|
* Emits `ready` event. That signals to `Repo` that it can start using the adapter.
|
|
@@ -2812,12 +2952,13 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo.NetworkAdapter
|
|
|
2812
2952
|
}
|
|
2813
2953
|
connect(peerId) {
|
|
2814
2954
|
this.peerId = peerId;
|
|
2955
|
+
this._connected.wake();
|
|
2815
2956
|
}
|
|
2816
2957
|
send(message) {
|
|
2817
2958
|
const peer = this._peers.get(message.targetId);
|
|
2818
2959
|
(0, import_invariant10.invariant)(peer, "Peer not found.", {
|
|
2819
2960
|
F: __dxlog_file14,
|
|
2820
|
-
L:
|
|
2961
|
+
L: 187,
|
|
2821
2962
|
S: this,
|
|
2822
2963
|
A: [
|
|
2823
2964
|
"peer",
|
|
@@ -2837,7 +2978,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo.NetworkAdapter
|
|
|
2837
2978
|
return new import_codec_protobuf2.Stream(({ next, close }) => {
|
|
2838
2979
|
(0, import_invariant10.invariant)(!this._peers.has(peerId), "Peer already connected.", {
|
|
2839
2980
|
F: __dxlog_file14,
|
|
2840
|
-
L:
|
|
2981
|
+
L: 205,
|
|
2841
2982
|
S: this,
|
|
2842
2983
|
A: [
|
|
2843
2984
|
"!this._peers.has(peerId)",
|
|
@@ -2859,19 +3000,35 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo.NetworkAdapter
|
|
|
2859
3000
|
});
|
|
2860
3001
|
}
|
|
2861
3002
|
});
|
|
2862
|
-
this.
|
|
2863
|
-
|
|
2864
|
-
})
|
|
3003
|
+
this._connected.wait({
|
|
3004
|
+
timeout: 1e3
|
|
3005
|
+
}).then(() => {
|
|
3006
|
+
this.emit("peer-candidate", {
|
|
3007
|
+
peerMetadata: {},
|
|
3008
|
+
peerId
|
|
3009
|
+
});
|
|
3010
|
+
}).catch((err) => import_log13.log.catch(err, void 0, {
|
|
3011
|
+
F: __dxlog_file14,
|
|
3012
|
+
L: 230,
|
|
3013
|
+
S: this,
|
|
3014
|
+
C: (f, a) => f(...a)
|
|
3015
|
+
}));
|
|
2865
3016
|
});
|
|
2866
3017
|
}
|
|
2867
3018
|
async sendSyncMessage({ id, syncMessage }) {
|
|
3019
|
+
await this._connected.wait({
|
|
3020
|
+
timeout: 1e3
|
|
3021
|
+
});
|
|
2868
3022
|
const message = import_automerge_repo.cbor.decode(syncMessage);
|
|
2869
3023
|
this.emit("message", message);
|
|
2870
3024
|
}
|
|
2871
|
-
getHostInfo() {
|
|
3025
|
+
async getHostInfo() {
|
|
3026
|
+
await this._connected.wait({
|
|
3027
|
+
timeout: 1e3
|
|
3028
|
+
});
|
|
2872
3029
|
(0, import_invariant10.invariant)(this.peerId, "Peer id not set.", {
|
|
2873
3030
|
F: __dxlog_file14,
|
|
2874
|
-
L:
|
|
3031
|
+
L: 242,
|
|
2875
3032
|
S: this,
|
|
2876
3033
|
A: [
|
|
2877
3034
|
"this.peerId",
|
|
@@ -2907,7 +3064,7 @@ var MeshNetworkAdapter = class extends import_automerge_repo.NetworkAdapter {
|
|
|
2907
3064
|
const extension = this._extensions.get(receiverId);
|
|
2908
3065
|
(0, import_invariant10.invariant)(extension, "Extension not found.", {
|
|
2909
3066
|
F: __dxlog_file14,
|
|
2910
|
-
L:
|
|
3067
|
+
L: 277,
|
|
2911
3068
|
S: this,
|
|
2912
3069
|
A: [
|
|
2913
3070
|
"extension",
|
|
@@ -2918,7 +3075,7 @@ var MeshNetworkAdapter = class extends import_automerge_repo.NetworkAdapter {
|
|
|
2918
3075
|
payload: import_automerge_repo.cbor.encode(message)
|
|
2919
3076
|
}).catch((err) => import_log13.log.catch(err, void 0, {
|
|
2920
3077
|
F: __dxlog_file14,
|
|
2921
|
-
L:
|
|
3078
|
+
L: 278,
|
|
2922
3079
|
S: this,
|
|
2923
3080
|
C: (f, a) => f(...a)
|
|
2924
3081
|
}));
|
|
@@ -2928,7 +3085,7 @@ var MeshNetworkAdapter = class extends import_automerge_repo.NetworkAdapter {
|
|
|
2928
3085
|
createExtension() {
|
|
2929
3086
|
(0, import_invariant10.invariant)(this.peerId, "Peer id not set.", {
|
|
2930
3087
|
F: __dxlog_file14,
|
|
2931
|
-
L:
|
|
3088
|
+
L: 286,
|
|
2932
3089
|
S: this,
|
|
2933
3090
|
A: [
|
|
2934
3091
|
"this.peerId",
|
|
@@ -2939,13 +3096,17 @@ var MeshNetworkAdapter = class extends import_automerge_repo.NetworkAdapter {
|
|
|
2939
3096
|
const extension = new import_teleport_extension_automerge_replicator.AutomergeReplicator({
|
|
2940
3097
|
peerId: this.peerId
|
|
2941
3098
|
}, {
|
|
2942
|
-
onStartReplication: async (info) => {
|
|
3099
|
+
onStartReplication: async (info, remotePeerId) => {
|
|
2943
3100
|
if (this._extensions.has(info.id)) {
|
|
2944
3101
|
return;
|
|
2945
3102
|
}
|
|
2946
3103
|
peerInfo = info;
|
|
2947
3104
|
this._extensions.set(info.id, extension);
|
|
2948
3105
|
this.emit("peer-candidate", {
|
|
3106
|
+
// TODO(mykola): Hack, stop abusing `peerMetadata` field.
|
|
3107
|
+
peerMetadata: {
|
|
3108
|
+
dxos_deviceKey: remotePeerId.toHex()
|
|
3109
|
+
},
|
|
2949
3110
|
peerId: info.id
|
|
2950
3111
|
});
|
|
2951
3112
|
},
|
|
@@ -2954,9 +3115,13 @@ var MeshNetworkAdapter = class extends import_automerge_repo.NetworkAdapter {
|
|
|
2954
3115
|
this.emit("message", message);
|
|
2955
3116
|
},
|
|
2956
3117
|
onClose: async () => {
|
|
2957
|
-
|
|
3118
|
+
if (!peerInfo) {
|
|
3119
|
+
return;
|
|
3120
|
+
}
|
|
3121
|
+
this.emit("peer-disconnected", {
|
|
2958
3122
|
peerId: peerInfo.id
|
|
2959
3123
|
});
|
|
3124
|
+
this._extensions.delete(peerInfo.id);
|
|
2960
3125
|
}
|
|
2961
3126
|
});
|
|
2962
3127
|
return extension;
|
|
@@ -2966,8 +3131,12 @@ var AutomergeStorageAdapter = class extends import_automerge_repo.StorageAdapter
|
|
|
2966
3131
|
constructor(_directory) {
|
|
2967
3132
|
super();
|
|
2968
3133
|
this._directory = _directory;
|
|
3134
|
+
this._state = "opened";
|
|
2969
3135
|
}
|
|
2970
3136
|
async load(key) {
|
|
3137
|
+
if (this._state !== "opened") {
|
|
3138
|
+
return void 0;
|
|
3139
|
+
}
|
|
2971
3140
|
const filename = this._getFilename(key);
|
|
2972
3141
|
const file = this._directory.getOrCreateFile(filename);
|
|
2973
3142
|
const { size } = await file.stat();
|
|
@@ -2978,6 +3147,9 @@ var AutomergeStorageAdapter = class extends import_automerge_repo.StorageAdapter
|
|
|
2978
3147
|
return (0, import_util10.bufferToArray)(buffer);
|
|
2979
3148
|
}
|
|
2980
3149
|
async save(key, data) {
|
|
3150
|
+
if (this._state !== "opened") {
|
|
3151
|
+
return void 0;
|
|
3152
|
+
}
|
|
2981
3153
|
const filename = this._getFilename(key);
|
|
2982
3154
|
const file = this._directory.getOrCreateFile(filename);
|
|
2983
3155
|
await file.write(0, (0, import_util10.arrayToBuffer)(data));
|
|
@@ -2985,11 +3157,17 @@ var AutomergeStorageAdapter = class extends import_automerge_repo.StorageAdapter
|
|
|
2985
3157
|
await file.flush?.();
|
|
2986
3158
|
}
|
|
2987
3159
|
async remove(key) {
|
|
3160
|
+
if (this._state !== "opened") {
|
|
3161
|
+
return void 0;
|
|
3162
|
+
}
|
|
2988
3163
|
const filename = this._getFilename(key);
|
|
2989
3164
|
const file = this._directory.getOrCreateFile(filename);
|
|
2990
|
-
await file.
|
|
3165
|
+
await file.destroy();
|
|
2991
3166
|
}
|
|
2992
3167
|
async loadRange(keyPrefix) {
|
|
3168
|
+
if (this._state !== "opened") {
|
|
3169
|
+
return [];
|
|
3170
|
+
}
|
|
2993
3171
|
const filename = this._getFilename(keyPrefix);
|
|
2994
3172
|
const entries = await this._directory.list();
|
|
2995
3173
|
return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
@@ -3003,13 +3181,19 @@ var AutomergeStorageAdapter = class extends import_automerge_repo.StorageAdapter
|
|
|
3003
3181
|
}));
|
|
3004
3182
|
}
|
|
3005
3183
|
async removeRange(keyPrefix) {
|
|
3184
|
+
if (this._state !== "opened") {
|
|
3185
|
+
return void 0;
|
|
3186
|
+
}
|
|
3006
3187
|
const filename = this._getFilename(keyPrefix);
|
|
3007
3188
|
const entries = await this._directory.list();
|
|
3008
3189
|
await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
3009
|
-
const file = this._directory.getOrCreateFile(
|
|
3010
|
-
await file.
|
|
3190
|
+
const file = this._directory.getOrCreateFile(entry);
|
|
3191
|
+
await file.destroy();
|
|
3011
3192
|
}));
|
|
3012
3193
|
}
|
|
3194
|
+
async close() {
|
|
3195
|
+
this._state = "closed";
|
|
3196
|
+
}
|
|
3013
3197
|
_getFilename(key) {
|
|
3014
3198
|
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
3015
3199
|
}
|
|
@@ -3045,4 +3229,4 @@ var AutomergeStorageAdapter = class extends import_automerge_repo.StorageAdapter
|
|
|
3045
3229
|
startAfter,
|
|
3046
3230
|
valueEncoding
|
|
3047
3231
|
});
|
|
3048
|
-
//# sourceMappingURL=chunk-
|
|
3232
|
+
//# sourceMappingURL=chunk-GQW6RLGD.cjs.map
|