@dxos/echo-pipeline 0.4.8-main.fff1521 → 0.4.8-next.06fa7e4
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-3FVT6KX6.mjs → chunk-WAN2XUWE.mjs} +38 -698
- package/dist/lib/browser/chunk-WAN2XUWE.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +633 -6
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -274
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-WZ4WTAN6.cjs → chunk-U6J2HC4T.cjs} +39 -689
- package/dist/lib/node/chunk-U6J2HC4T.cjs.map +7 -0
- package/dist/lib/node/index.cjs +647 -30
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +12 -282
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
- package/dist/types/src/space/data-pipeline.d.ts +0 -1
- package/dist/types/src/space/data-pipeline.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +0 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +2 -6
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/package.json +33 -33
- package/src/space/control-pipeline.ts +3 -1
- package/src/space/data-pipeline.ts +1 -44
- package/src/testing/index.ts +0 -1
- package/src/testing/util.ts +2 -26
- package/dist/lib/browser/chunk-3FVT6KX6.mjs.map +0 -7
- package/dist/lib/node/chunk-WZ4WTAN6.cjs.map +0 -7
- package/dist/types/src/testing/database-test-rig.d.ts +0 -67
- package/dist/types/src/testing/database-test-rig.d.ts.map +0 -1
- package/dist/types/src/tests/database.test.d.ts +0 -2
- package/dist/types/src/tests/database.test.d.ts.map +0 -1
- package/src/testing/database-test-rig.ts +0 -289
- package/src/tests/database.test.ts +0 -100
|
@@ -1487,7 +1487,7 @@ var AuthExtension = class extends RpcExtension {
|
|
|
1487
1487
|
import { Event as Event4, scheduleTask as scheduleTask2, sleep, synchronized as synchronized3, trackLeaks } from "@dxos/async";
|
|
1488
1488
|
import { Context as Context5 } from "@dxos/context";
|
|
1489
1489
|
import { checkCredentialType } from "@dxos/credentials";
|
|
1490
|
-
import {
|
|
1490
|
+
import { ItemManager } from "@dxos/echo-db";
|
|
1491
1491
|
import { invariant as invariant8 } from "@dxos/invariant";
|
|
1492
1492
|
import { log as log8, omit } from "@dxos/log";
|
|
1493
1493
|
import { CancelledError } from "@dxos/protocols";
|
|
@@ -1505,8 +1505,6 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
1505
1505
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1506
1506
|
}
|
|
1507
1507
|
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/data-pipeline.ts";
|
|
1508
|
-
var MESSAGES_PER_SNAPSHOT = 10;
|
|
1509
|
-
var AUTOMATIC_SNAPSHOT_DEBOUNCE_INTERVAL = 5e3;
|
|
1510
1508
|
var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL = 5e3;
|
|
1511
1509
|
var DataPipeline = class {
|
|
1512
1510
|
constructor(_params) {
|
|
@@ -1562,7 +1560,7 @@ var DataPipeline = class {
|
|
|
1562
1560
|
write: (data, options) => {
|
|
1563
1561
|
invariant8(this._pipeline, "Pipeline is not initialized.", {
|
|
1564
1562
|
F: __dxlog_file9,
|
|
1565
|
-
L:
|
|
1563
|
+
L: 152,
|
|
1566
1564
|
S: this,
|
|
1567
1565
|
A: [
|
|
1568
1566
|
"this._pipeline",
|
|
@@ -1571,7 +1569,7 @@ var DataPipeline = class {
|
|
|
1571
1569
|
});
|
|
1572
1570
|
invariant8(this.currentEpoch, "Epoch is not initialized.", {
|
|
1573
1571
|
F: __dxlog_file9,
|
|
1574
|
-
L:
|
|
1572
|
+
L: 153,
|
|
1575
1573
|
S: this,
|
|
1576
1574
|
A: [
|
|
1577
1575
|
"this.currentEpoch",
|
|
@@ -1597,7 +1595,7 @@ var DataPipeline = class {
|
|
|
1597
1595
|
}
|
|
1598
1596
|
log8("close", void 0, {
|
|
1599
1597
|
F: __dxlog_file9,
|
|
1600
|
-
L:
|
|
1598
|
+
L: 177,
|
|
1601
1599
|
S: this,
|
|
1602
1600
|
C: (f, a) => f(...a)
|
|
1603
1601
|
});
|
|
@@ -1605,14 +1603,13 @@ var DataPipeline = class {
|
|
|
1605
1603
|
await this._ctx.dispose();
|
|
1606
1604
|
await this._pipeline?.stop();
|
|
1607
1605
|
try {
|
|
1608
|
-
await this._saveCache();
|
|
1609
1606
|
if (this._pipeline) {
|
|
1610
1607
|
await this._saveTargetTimeframe(this._pipeline.state.timeframe);
|
|
1611
1608
|
}
|
|
1612
1609
|
} catch (err) {
|
|
1613
1610
|
log8.catch(err, void 0, {
|
|
1614
1611
|
F: __dxlog_file9,
|
|
1615
|
-
L:
|
|
1612
|
+
L: 189,
|
|
1616
1613
|
S: this,
|
|
1617
1614
|
C: (f, a) => f(...a)
|
|
1618
1615
|
});
|
|
@@ -1638,7 +1635,7 @@ var DataPipeline = class {
|
|
|
1638
1635
|
let messageCounter = 0;
|
|
1639
1636
|
invariant8(pipeline, "Pipeline is not initialized.", {
|
|
1640
1637
|
F: __dxlog_file9,
|
|
1641
|
-
L:
|
|
1638
|
+
L: 216,
|
|
1642
1639
|
S: this,
|
|
1643
1640
|
A: [
|
|
1644
1641
|
"pipeline",
|
|
@@ -1654,7 +1651,7 @@ var DataPipeline = class {
|
|
|
1654
1651
|
seq
|
|
1655
1652
|
}, {
|
|
1656
1653
|
F: __dxlog_file9,
|
|
1657
|
-
L:
|
|
1654
|
+
L: 222,
|
|
1658
1655
|
S: this,
|
|
1659
1656
|
C: (f, a) => f(...a)
|
|
1660
1657
|
});
|
|
@@ -1666,7 +1663,7 @@ var DataPipeline = class {
|
|
|
1666
1663
|
feedKey
|
|
1667
1664
|
}, {
|
|
1668
1665
|
F: __dxlog_file9,
|
|
1669
|
-
L:
|
|
1666
|
+
L: 228,
|
|
1670
1667
|
S: this,
|
|
1671
1668
|
C: (f, a) => f(...a)
|
|
1672
1669
|
});
|
|
@@ -1689,7 +1686,7 @@ var DataPipeline = class {
|
|
|
1689
1686
|
spaceKey: this._params.spaceKey.toHex()
|
|
1690
1687
|
}, {
|
|
1691
1688
|
F: __dxlog_file9,
|
|
1692
|
-
L:
|
|
1689
|
+
L: 245,
|
|
1693
1690
|
S: this,
|
|
1694
1691
|
C: (f, a) => f(...a)
|
|
1695
1692
|
});
|
|
@@ -1698,7 +1695,7 @@ var DataPipeline = class {
|
|
|
1698
1695
|
} catch (err) {
|
|
1699
1696
|
log8.catch(err, void 0, {
|
|
1700
1697
|
F: __dxlog_file9,
|
|
1701
|
-
L:
|
|
1698
|
+
L: 255,
|
|
1702
1699
|
S: this,
|
|
1703
1700
|
C: (f, a) => f(...a)
|
|
1704
1701
|
});
|
|
@@ -1713,7 +1710,7 @@ var DataPipeline = class {
|
|
|
1713
1710
|
_createSnapshot() {
|
|
1714
1711
|
invariant8(this.databaseHost, "Database backend is not initialized.", {
|
|
1715
1712
|
F: __dxlog_file9,
|
|
1716
|
-
L:
|
|
1713
|
+
L: 269,
|
|
1717
1714
|
S: this,
|
|
1718
1715
|
A: [
|
|
1719
1716
|
"this.databaseHost",
|
|
@@ -1731,24 +1728,6 @@ var DataPipeline = class {
|
|
|
1731
1728
|
await this._params.metadataStore.setSpaceDataLatestTimeframe(this._params.spaceKey, newTimeframe);
|
|
1732
1729
|
this._targetTimeframe = newTimeframe;
|
|
1733
1730
|
}
|
|
1734
|
-
async _saveCache() {
|
|
1735
|
-
const cache = {};
|
|
1736
|
-
try {
|
|
1737
|
-
const propertiesItem = this.itemManager.items.find((item) => item.modelMeta?.type === "dxos.org/model/document" && // TODO(burdon): Document?
|
|
1738
|
-
(getStateMachineFromItem(item)?.snapshot()).type === TYPE_PROPERTIES);
|
|
1739
|
-
if (propertiesItem) {
|
|
1740
|
-
cache.properties = getStateMachineFromItem(propertiesItem)?.snapshot();
|
|
1741
|
-
}
|
|
1742
|
-
} catch (err) {
|
|
1743
|
-
log8.warn("Failed to cache properties", err, {
|
|
1744
|
-
F: __dxlog_file9,
|
|
1745
|
-
L: 311,
|
|
1746
|
-
S: this,
|
|
1747
|
-
C: (f, a) => f(...a)
|
|
1748
|
-
});
|
|
1749
|
-
}
|
|
1750
|
-
await this._params.metadataStore.setCache(this._params.spaceKey, cache);
|
|
1751
|
-
}
|
|
1752
1731
|
async _noteTargetStateIfNeeded(timeframe) {
|
|
1753
1732
|
if (!this._pipeline?.state.reachedTarget) {
|
|
1754
1733
|
return;
|
|
@@ -1757,9 +1736,6 @@ var DataPipeline = class {
|
|
|
1757
1736
|
this._lastTimeframeSaveTime = Date.now();
|
|
1758
1737
|
await this._saveTargetTimeframe(timeframe);
|
|
1759
1738
|
}
|
|
1760
|
-
if (Date.now() - this._lastSnapshotSaveTime > AUTOMATIC_SNAPSHOT_DEBOUNCE_INTERVAL && timeframe.totalMessages() - this._lastAutomaticSnapshotTimeframe.totalMessages() > MESSAGES_PER_SNAPSHOT) {
|
|
1761
|
-
await this._saveCache();
|
|
1762
|
-
}
|
|
1763
1739
|
}
|
|
1764
1740
|
async _processEpochInSeparateTask(epoch) {
|
|
1765
1741
|
if (epoch.subject.assertion.number <= this._lastProcessedEpoch) {
|
|
@@ -1771,14 +1747,14 @@ var DataPipeline = class {
|
|
|
1771
1747
|
if (err instanceof CancelledError) {
|
|
1772
1748
|
log8("Epoch processing cancelled.", void 0, {
|
|
1773
1749
|
F: __dxlog_file9,
|
|
1774
|
-
L:
|
|
1750
|
+
L: 305,
|
|
1775
1751
|
S: this,
|
|
1776
1752
|
C: (f, a) => f(...a)
|
|
1777
1753
|
});
|
|
1778
1754
|
} else {
|
|
1779
1755
|
log8.catch(err, void 0, {
|
|
1780
1756
|
F: __dxlog_file9,
|
|
1781
|
-
L:
|
|
1757
|
+
L: 307,
|
|
1782
1758
|
S: this,
|
|
1783
1759
|
C: (f, a) => f(...a)
|
|
1784
1760
|
});
|
|
@@ -1801,7 +1777,7 @@ var DataPipeline = class {
|
|
|
1801
1777
|
async _processEpoch(ctx, epoch) {
|
|
1802
1778
|
invariant8(this._isOpen, "Space is closed.", {
|
|
1803
1779
|
F: __dxlog_file9,
|
|
1804
|
-
L:
|
|
1780
|
+
L: 331,
|
|
1805
1781
|
S: this,
|
|
1806
1782
|
A: [
|
|
1807
1783
|
"this._isOpen",
|
|
@@ -1810,7 +1786,7 @@ var DataPipeline = class {
|
|
|
1810
1786
|
});
|
|
1811
1787
|
invariant8(this._pipeline, void 0, {
|
|
1812
1788
|
F: __dxlog_file9,
|
|
1813
|
-
L:
|
|
1789
|
+
L: 332,
|
|
1814
1790
|
S: this,
|
|
1815
1791
|
A: [
|
|
1816
1792
|
"this._pipeline",
|
|
@@ -1822,7 +1798,7 @@ var DataPipeline = class {
|
|
|
1822
1798
|
epoch: omit(epoch, "proof")
|
|
1823
1799
|
}, {
|
|
1824
1800
|
F: __dxlog_file9,
|
|
1825
|
-
L:
|
|
1801
|
+
L: 335,
|
|
1826
1802
|
S: this,
|
|
1827
1803
|
C: (f, a) => f(...a)
|
|
1828
1804
|
});
|
|
@@ -1832,7 +1808,7 @@ var DataPipeline = class {
|
|
|
1832
1808
|
}
|
|
1833
1809
|
log8("restarting pipeline from epoch", void 0, {
|
|
1834
1810
|
F: __dxlog_file9,
|
|
1835
|
-
L:
|
|
1811
|
+
L: 341,
|
|
1836
1812
|
S: this,
|
|
1837
1813
|
C: (f, a) => f(...a)
|
|
1838
1814
|
});
|
|
@@ -1843,7 +1819,7 @@ var DataPipeline = class {
|
|
|
1843
1819
|
async waitUntilTimeframe(timeframe) {
|
|
1844
1820
|
invariant8(this._pipeline, "Pipeline is not initialized.", {
|
|
1845
1821
|
F: __dxlog_file9,
|
|
1846
|
-
L:
|
|
1822
|
+
L: 348,
|
|
1847
1823
|
S: this,
|
|
1848
1824
|
A: [
|
|
1849
1825
|
"this._pipeline",
|
|
@@ -1855,7 +1831,7 @@ var DataPipeline = class {
|
|
|
1855
1831
|
async createEpoch() {
|
|
1856
1832
|
invariant8(this._pipeline, void 0, {
|
|
1857
1833
|
F: __dxlog_file9,
|
|
1858
|
-
L:
|
|
1834
|
+
L: 354,
|
|
1859
1835
|
S: this,
|
|
1860
1836
|
A: [
|
|
1861
1837
|
"this._pipeline",
|
|
@@ -1864,7 +1840,7 @@ var DataPipeline = class {
|
|
|
1864
1840
|
});
|
|
1865
1841
|
invariant8(this.currentEpoch, void 0, {
|
|
1866
1842
|
F: __dxlog_file9,
|
|
1867
|
-
L:
|
|
1843
|
+
L: 355,
|
|
1868
1844
|
S: this,
|
|
1869
1845
|
A: [
|
|
1870
1846
|
"this.currentEpoch",
|
|
@@ -1888,14 +1864,13 @@ var DataPipeline = class {
|
|
|
1888
1864
|
}
|
|
1889
1865
|
async _flush() {
|
|
1890
1866
|
try {
|
|
1891
|
-
await this._saveCache();
|
|
1892
1867
|
if (this._pipeline) {
|
|
1893
1868
|
await this._saveTargetTimeframe(this._pipeline.state.timeframe);
|
|
1894
1869
|
}
|
|
1895
1870
|
} catch (err) {
|
|
1896
1871
|
log8.catch(err, void 0, {
|
|
1897
1872
|
F: __dxlog_file9,
|
|
1898
|
-
L:
|
|
1873
|
+
L: 384,
|
|
1899
1874
|
S: this,
|
|
1900
1875
|
C: (f, a) => f(...a)
|
|
1901
1876
|
});
|
|
@@ -2012,11 +1987,13 @@ var ControlPipeline = class {
|
|
|
2012
1987
|
queueMicrotask(async () => {
|
|
2013
1988
|
try {
|
|
2014
1989
|
const feed = await feedProvider(info.key);
|
|
2015
|
-
|
|
1990
|
+
if (!this._pipeline.hasFeed(feed.key)) {
|
|
1991
|
+
await this._pipeline.addFeed(feed);
|
|
1992
|
+
}
|
|
2016
1993
|
} catch (err) {
|
|
2017
1994
|
log9.catch(err, void 0, {
|
|
2018
1995
|
F: __dxlog_file10,
|
|
2019
|
-
L:
|
|
1996
|
+
L: 85,
|
|
2020
1997
|
S: this,
|
|
2021
1998
|
C: (f, a) => f(...a)
|
|
2022
1999
|
});
|
|
@@ -2046,7 +2023,7 @@ var ControlPipeline = class {
|
|
|
2046
2023
|
tf: snapshot?.timeframe
|
|
2047
2024
|
}, {
|
|
2048
2025
|
F: __dxlog_file10,
|
|
2049
|
-
L:
|
|
2026
|
+
L: 113,
|
|
2050
2027
|
S: this,
|
|
2051
2028
|
C: (f, a) => f(...a)
|
|
2052
2029
|
});
|
|
@@ -2055,7 +2032,7 @@ var ControlPipeline = class {
|
|
|
2055
2032
|
}
|
|
2056
2033
|
log9("starting...", void 0, {
|
|
2057
2034
|
F: __dxlog_file10,
|
|
2058
|
-
L:
|
|
2035
|
+
L: 118,
|
|
2059
2036
|
S: this,
|
|
2060
2037
|
C: (f, a) => f(...a)
|
|
2061
2038
|
});
|
|
@@ -2065,7 +2042,7 @@ var ControlPipeline = class {
|
|
|
2065
2042
|
await this._pipeline.start();
|
|
2066
2043
|
log9("started", void 0, {
|
|
2067
2044
|
F: __dxlog_file10,
|
|
2068
|
-
L:
|
|
2045
|
+
L: 124,
|
|
2069
2046
|
S: this,
|
|
2070
2047
|
C: (f, a) => f(...a)
|
|
2071
2048
|
});
|
|
@@ -2082,7 +2059,7 @@ var ControlPipeline = class {
|
|
|
2082
2059
|
message
|
|
2083
2060
|
}, {
|
|
2084
2061
|
F: __dxlog_file10,
|
|
2085
|
-
L:
|
|
2062
|
+
L: 137,
|
|
2086
2063
|
S: this,
|
|
2087
2064
|
C: (f, a) => f(...a)
|
|
2088
2065
|
});
|
|
@@ -2104,7 +2081,7 @@ var ControlPipeline = class {
|
|
|
2104
2081
|
snapshot
|
|
2105
2082
|
}, {
|
|
2106
2083
|
F: __dxlog_file10,
|
|
2107
|
-
L:
|
|
2084
|
+
L: 153,
|
|
2108
2085
|
S: this,
|
|
2109
2086
|
C: (f, a) => f(...a)
|
|
2110
2087
|
});
|
|
@@ -2119,7 +2096,7 @@ var ControlPipeline = class {
|
|
|
2119
2096
|
} catch (err) {
|
|
2120
2097
|
log9.catch(err, void 0, {
|
|
2121
2098
|
F: __dxlog_file10,
|
|
2122
|
-
L:
|
|
2099
|
+
L: 166,
|
|
2123
2100
|
S: this,
|
|
2124
2101
|
C: (f, a) => f(...a)
|
|
2125
2102
|
});
|
|
@@ -2133,7 +2110,7 @@ var ControlPipeline = class {
|
|
|
2133
2110
|
seq: msg.seq
|
|
2134
2111
|
}, {
|
|
2135
2112
|
F: __dxlog_file10,
|
|
2136
|
-
L:
|
|
2113
|
+
L: 176,
|
|
2137
2114
|
S: this,
|
|
2138
2115
|
C: (f, a) => f(...a)
|
|
2139
2116
|
});
|
|
@@ -2148,7 +2125,7 @@ var ControlPipeline = class {
|
|
|
2148
2125
|
msg
|
|
2149
2126
|
}, {
|
|
2150
2127
|
F: __dxlog_file10,
|
|
2151
|
-
L:
|
|
2128
|
+
L: 185,
|
|
2152
2129
|
S: this,
|
|
2153
2130
|
C: (f, a) => f(...a)
|
|
2154
2131
|
});
|
|
@@ -2167,7 +2144,7 @@ var ControlPipeline = class {
|
|
|
2167
2144
|
async stop() {
|
|
2168
2145
|
log9("stopping...", void 0, {
|
|
2169
2146
|
F: __dxlog_file10,
|
|
2170
|
-
L:
|
|
2147
|
+
L: 205,
|
|
2171
2148
|
S: this,
|
|
2172
2149
|
C: (f, a) => f(...a)
|
|
2173
2150
|
});
|
|
@@ -2176,7 +2153,7 @@ var ControlPipeline = class {
|
|
|
2176
2153
|
await this._saveTargetTimeframe(this._pipeline.state.timeframe);
|
|
2177
2154
|
log9("stopped", void 0, {
|
|
2178
2155
|
F: __dxlog_file10,
|
|
2179
|
-
L:
|
|
2156
|
+
L: 209,
|
|
2180
2157
|
S: this,
|
|
2181
2158
|
C: (f, a) => f(...a)
|
|
2182
2159
|
});
|
|
@@ -2189,7 +2166,7 @@ var ControlPipeline = class {
|
|
|
2189
2166
|
} catch (err) {
|
|
2190
2167
|
log9(err, void 0, {
|
|
2191
2168
|
F: __dxlog_file10,
|
|
2192
|
-
L:
|
|
2169
|
+
L: 218,
|
|
2193
2170
|
S: this,
|
|
2194
2171
|
C: (f, a) => f(...a)
|
|
2195
2172
|
});
|
|
@@ -2792,638 +2769,6 @@ SpaceManager = _ts_decorate8([
|
|
|
2792
2769
|
trackLeaks4("open", "close")
|
|
2793
2770
|
], SpaceManager);
|
|
2794
2771
|
|
|
2795
|
-
// packages/core/echo/echo-pipeline/src/automerge/automerge-storage-adapter.ts
|
|
2796
|
-
import { arrayToBuffer as arrayToBuffer2, bufferToArray } from "@dxos/util";
|
|
2797
|
-
var AutomergeStorageAdapter = class {
|
|
2798
|
-
constructor(_directory) {
|
|
2799
|
-
this._directory = _directory;
|
|
2800
|
-
this._state = "opened";
|
|
2801
|
-
}
|
|
2802
|
-
async load(key) {
|
|
2803
|
-
if (this._state !== "opened") {
|
|
2804
|
-
return void 0;
|
|
2805
|
-
}
|
|
2806
|
-
const filename = this._getFilename(key);
|
|
2807
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
2808
|
-
const { size } = await file.stat();
|
|
2809
|
-
if (!size || size === 0) {
|
|
2810
|
-
return void 0;
|
|
2811
|
-
}
|
|
2812
|
-
const buffer = await file.read(0, size);
|
|
2813
|
-
return bufferToArray(buffer);
|
|
2814
|
-
}
|
|
2815
|
-
async save(key, data) {
|
|
2816
|
-
if (this._state !== "opened") {
|
|
2817
|
-
return void 0;
|
|
2818
|
-
}
|
|
2819
|
-
const filename = this._getFilename(key);
|
|
2820
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
2821
|
-
await file.write(0, arrayToBuffer2(data));
|
|
2822
|
-
await file.truncate?.(data.length);
|
|
2823
|
-
await file.flush?.();
|
|
2824
|
-
}
|
|
2825
|
-
async remove(key) {
|
|
2826
|
-
if (this._state !== "opened") {
|
|
2827
|
-
return void 0;
|
|
2828
|
-
}
|
|
2829
|
-
const filename = this._getFilename(key);
|
|
2830
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
2831
|
-
await file.destroy();
|
|
2832
|
-
}
|
|
2833
|
-
async loadRange(keyPrefix) {
|
|
2834
|
-
if (this._state !== "opened") {
|
|
2835
|
-
return [];
|
|
2836
|
-
}
|
|
2837
|
-
const filename = this._getFilename(keyPrefix);
|
|
2838
|
-
const entries = await this._directory.list();
|
|
2839
|
-
return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
2840
|
-
const file = this._directory.getOrCreateFile(entry);
|
|
2841
|
-
const { size } = await file.stat();
|
|
2842
|
-
const buffer = await file.read(0, size);
|
|
2843
|
-
return {
|
|
2844
|
-
key: this._getKeyFromFilename(entry),
|
|
2845
|
-
data: bufferToArray(buffer)
|
|
2846
|
-
};
|
|
2847
|
-
}));
|
|
2848
|
-
}
|
|
2849
|
-
async removeRange(keyPrefix) {
|
|
2850
|
-
if (this._state !== "opened") {
|
|
2851
|
-
return void 0;
|
|
2852
|
-
}
|
|
2853
|
-
const filename = this._getFilename(keyPrefix);
|
|
2854
|
-
const entries = await this._directory.list();
|
|
2855
|
-
await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
2856
|
-
const file = this._directory.getOrCreateFile(entry);
|
|
2857
|
-
await file.destroy();
|
|
2858
|
-
}));
|
|
2859
|
-
}
|
|
2860
|
-
async close() {
|
|
2861
|
-
this._state = "closed";
|
|
2862
|
-
}
|
|
2863
|
-
_getFilename(key) {
|
|
2864
|
-
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
2865
|
-
}
|
|
2866
|
-
_getKeyFromFilename(filename) {
|
|
2867
|
-
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
2868
|
-
}
|
|
2869
|
-
};
|
|
2870
|
-
|
|
2871
|
-
// packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts
|
|
2872
|
-
import { Trigger as Trigger2 } from "@dxos/async";
|
|
2873
|
-
import { NetworkAdapter, cbor } from "@dxos/automerge/automerge-repo";
|
|
2874
|
-
import { Stream as Stream2 } from "@dxos/codec-protobuf";
|
|
2875
|
-
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2876
|
-
import { log as log13 } from "@dxos/log";
|
|
2877
|
-
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts";
|
|
2878
|
-
var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
2879
|
-
constructor() {
|
|
2880
|
-
super(...arguments);
|
|
2881
|
-
this._peers = /* @__PURE__ */ new Map();
|
|
2882
|
-
this._connected = new Trigger2();
|
|
2883
|
-
}
|
|
2884
|
-
/**
|
|
2885
|
-
* Emits `ready` event. That signals to `Repo` that it can start using the adapter.
|
|
2886
|
-
*/
|
|
2887
|
-
ready() {
|
|
2888
|
-
this.emit("ready", {
|
|
2889
|
-
network: this
|
|
2890
|
-
});
|
|
2891
|
-
}
|
|
2892
|
-
connect(peerId) {
|
|
2893
|
-
this.peerId = peerId;
|
|
2894
|
-
this._connected.wake();
|
|
2895
|
-
}
|
|
2896
|
-
send(message) {
|
|
2897
|
-
const peer = this._peers.get(message.targetId);
|
|
2898
|
-
invariant10(peer, "Peer not found.", {
|
|
2899
|
-
F: __dxlog_file14,
|
|
2900
|
-
L: 45,
|
|
2901
|
-
S: this,
|
|
2902
|
-
A: [
|
|
2903
|
-
"peer",
|
|
2904
|
-
"'Peer not found.'"
|
|
2905
|
-
]
|
|
2906
|
-
});
|
|
2907
|
-
peer.send(message);
|
|
2908
|
-
}
|
|
2909
|
-
async close() {
|
|
2910
|
-
this._peers.forEach((peer) => peer.disconnect());
|
|
2911
|
-
this.emit("close");
|
|
2912
|
-
}
|
|
2913
|
-
disconnect() {
|
|
2914
|
-
}
|
|
2915
|
-
syncRepo({ id, syncMessage }) {
|
|
2916
|
-
const peerId = this._getPeerId(id);
|
|
2917
|
-
return new Stream2(({ next, close }) => {
|
|
2918
|
-
invariant10(!this._peers.has(peerId), "Peer already connected.", {
|
|
2919
|
-
F: __dxlog_file14,
|
|
2920
|
-
L: 63,
|
|
2921
|
-
S: this,
|
|
2922
|
-
A: [
|
|
2923
|
-
"!this._peers.has(peerId)",
|
|
2924
|
-
"'Peer already connected.'"
|
|
2925
|
-
]
|
|
2926
|
-
});
|
|
2927
|
-
this._peers.set(peerId, {
|
|
2928
|
-
connected: true,
|
|
2929
|
-
send: (message) => {
|
|
2930
|
-
next({
|
|
2931
|
-
syncMessage: cbor.encode(message)
|
|
2932
|
-
});
|
|
2933
|
-
},
|
|
2934
|
-
disconnect: () => {
|
|
2935
|
-
this._peers.delete(peerId);
|
|
2936
|
-
close();
|
|
2937
|
-
this.emit("peer-disconnected", {
|
|
2938
|
-
peerId
|
|
2939
|
-
});
|
|
2940
|
-
}
|
|
2941
|
-
});
|
|
2942
|
-
this._connected.wait({
|
|
2943
|
-
timeout: 1e3
|
|
2944
|
-
}).then(() => {
|
|
2945
|
-
this.emit("peer-candidate", {
|
|
2946
|
-
peerMetadata: {},
|
|
2947
|
-
peerId
|
|
2948
|
-
});
|
|
2949
|
-
}).catch((err) => log13.catch(err, void 0, {
|
|
2950
|
-
F: __dxlog_file14,
|
|
2951
|
-
L: 88,
|
|
2952
|
-
S: this,
|
|
2953
|
-
C: (f, a) => f(...a)
|
|
2954
|
-
}));
|
|
2955
|
-
});
|
|
2956
|
-
}
|
|
2957
|
-
async sendSyncMessage({ id, syncMessage }) {
|
|
2958
|
-
await this._connected.wait({
|
|
2959
|
-
timeout: 1e3
|
|
2960
|
-
});
|
|
2961
|
-
const message = cbor.decode(syncMessage);
|
|
2962
|
-
this.emit("message", message);
|
|
2963
|
-
}
|
|
2964
|
-
async getHostInfo() {
|
|
2965
|
-
await this._connected.wait({
|
|
2966
|
-
timeout: 1e3
|
|
2967
|
-
});
|
|
2968
|
-
invariant10(this.peerId, "Peer id not set.", {
|
|
2969
|
-
F: __dxlog_file14,
|
|
2970
|
-
L: 100,
|
|
2971
|
-
S: this,
|
|
2972
|
-
A: [
|
|
2973
|
-
"this.peerId",
|
|
2974
|
-
"'Peer id not set.'"
|
|
2975
|
-
]
|
|
2976
|
-
});
|
|
2977
|
-
return {
|
|
2978
|
-
peerId: this.peerId
|
|
2979
|
-
};
|
|
2980
|
-
}
|
|
2981
|
-
_getPeerId(id) {
|
|
2982
|
-
return id;
|
|
2983
|
-
}
|
|
2984
|
-
};
|
|
2985
|
-
|
|
2986
|
-
// packages/core/echo/echo-pipeline/src/automerge/mesh-network-adapter.ts
|
|
2987
|
-
import { Trigger as Trigger3 } from "@dxos/async";
|
|
2988
|
-
import { NetworkAdapter as NetworkAdapter2, cbor as cbor2 } from "@dxos/automerge/automerge-repo";
|
|
2989
|
-
import { invariant as invariant11 } from "@dxos/invariant";
|
|
2990
|
-
import { log as log14 } from "@dxos/log";
|
|
2991
|
-
import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
|
|
2992
|
-
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-network-adapter.ts";
|
|
2993
|
-
var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
2994
|
-
constructor() {
|
|
2995
|
-
super(...arguments);
|
|
2996
|
-
this._extensions = /* @__PURE__ */ new Map();
|
|
2997
|
-
this._connected = new Trigger3();
|
|
2998
|
-
}
|
|
2999
|
-
/**
|
|
3000
|
-
* Emits `ready` event. That signals to `Repo` that it can start using the adapter.
|
|
3001
|
-
*/
|
|
3002
|
-
ready() {
|
|
3003
|
-
this.emit("ready", {
|
|
3004
|
-
network: this
|
|
3005
|
-
});
|
|
3006
|
-
}
|
|
3007
|
-
connect(peerId) {
|
|
3008
|
-
this.peerId = peerId;
|
|
3009
|
-
this._connected.wake();
|
|
3010
|
-
}
|
|
3011
|
-
send(message) {
|
|
3012
|
-
const receiverId = message.targetId;
|
|
3013
|
-
const extension = this._extensions.get(receiverId);
|
|
3014
|
-
invariant11(extension, "Extension not found.", {
|
|
3015
|
-
F: __dxlog_file15,
|
|
3016
|
-
L: 38,
|
|
3017
|
-
S: this,
|
|
3018
|
-
A: [
|
|
3019
|
-
"extension",
|
|
3020
|
-
"'Extension not found.'"
|
|
3021
|
-
]
|
|
3022
|
-
});
|
|
3023
|
-
extension.sendSyncMessage({
|
|
3024
|
-
payload: cbor2.encode(message)
|
|
3025
|
-
}).catch((err) => log14.catch(err, void 0, {
|
|
3026
|
-
F: __dxlog_file15,
|
|
3027
|
-
L: 39,
|
|
3028
|
-
S: this,
|
|
3029
|
-
C: (f, a) => f(...a)
|
|
3030
|
-
}));
|
|
3031
|
-
}
|
|
3032
|
-
disconnect() {
|
|
3033
|
-
}
|
|
3034
|
-
createExtension() {
|
|
3035
|
-
invariant11(this.peerId, "Peer id not set.", {
|
|
3036
|
-
F: __dxlog_file15,
|
|
3037
|
-
L: 47,
|
|
3038
|
-
S: this,
|
|
3039
|
-
A: [
|
|
3040
|
-
"this.peerId",
|
|
3041
|
-
"'Peer id not set.'"
|
|
3042
|
-
]
|
|
3043
|
-
});
|
|
3044
|
-
let peerInfo;
|
|
3045
|
-
const extension = new AutomergeReplicator({
|
|
3046
|
-
peerId: this.peerId
|
|
3047
|
-
}, {
|
|
3048
|
-
onStartReplication: async (info, remotePeerId) => {
|
|
3049
|
-
await this._connected.wait();
|
|
3050
|
-
log14("onStartReplication", {
|
|
3051
|
-
id: info.id,
|
|
3052
|
-
thisPeerId: this.peerId,
|
|
3053
|
-
remotePeerId: remotePeerId.toHex()
|
|
3054
|
-
}, {
|
|
3055
|
-
F: __dxlog_file15,
|
|
3056
|
-
L: 70,
|
|
3057
|
-
S: this,
|
|
3058
|
-
C: (f, a) => f(...a)
|
|
3059
|
-
});
|
|
3060
|
-
if (!this._extensions.has(info.id)) {
|
|
3061
|
-
peerInfo = info;
|
|
3062
|
-
this._extensions.set(info.id, extension);
|
|
3063
|
-
log14("peer-candidate", {
|
|
3064
|
-
id: info.id,
|
|
3065
|
-
thisPeerId: this.peerId,
|
|
3066
|
-
remotePeerId: remotePeerId.toHex()
|
|
3067
|
-
}, {
|
|
3068
|
-
F: __dxlog_file15,
|
|
3069
|
-
L: 76,
|
|
3070
|
-
S: this,
|
|
3071
|
-
C: (f, a) => f(...a)
|
|
3072
|
-
});
|
|
3073
|
-
this.emit("peer-candidate", {
|
|
3074
|
-
// TODO(mykola): Hack, stop abusing `peerMetadata` field.
|
|
3075
|
-
peerMetadata: {
|
|
3076
|
-
dxos_deviceKey: remotePeerId.toHex()
|
|
3077
|
-
},
|
|
3078
|
-
peerId: info.id
|
|
3079
|
-
});
|
|
3080
|
-
}
|
|
3081
|
-
},
|
|
3082
|
-
onSyncMessage: async ({ payload }) => {
|
|
3083
|
-
if (!peerInfo) {
|
|
3084
|
-
return;
|
|
3085
|
-
}
|
|
3086
|
-
const message = cbor2.decode(payload);
|
|
3087
|
-
this.emit("message", message);
|
|
3088
|
-
},
|
|
3089
|
-
onClose: async () => {
|
|
3090
|
-
if (!peerInfo) {
|
|
3091
|
-
return;
|
|
3092
|
-
}
|
|
3093
|
-
this.emit("peer-disconnected", {
|
|
3094
|
-
peerId: peerInfo.id
|
|
3095
|
-
});
|
|
3096
|
-
this._extensions.delete(peerInfo.id);
|
|
3097
|
-
}
|
|
3098
|
-
});
|
|
3099
|
-
return extension;
|
|
3100
|
-
}
|
|
3101
|
-
};
|
|
3102
|
-
|
|
3103
|
-
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
3104
|
-
import { next as automerge, getHeads } from "@dxos/automerge/automerge";
|
|
3105
|
-
import { Repo } from "@dxos/automerge/automerge-repo";
|
|
3106
|
-
import { IndexedDBStorageAdapter } from "@dxos/automerge/automerge-repo-storage-indexeddb";
|
|
3107
|
-
import { Context as Context7 } from "@dxos/context";
|
|
3108
|
-
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
3109
|
-
import { log as log15 } from "@dxos/log";
|
|
3110
|
-
import { idCodec } from "@dxos/protocols";
|
|
3111
|
-
import { StorageType } from "@dxos/random-access-storage";
|
|
3112
|
-
import { trace as trace6 } from "@dxos/tracing";
|
|
3113
|
-
import { ComplexMap as ComplexMap7, ComplexSet, defaultMap, mapValues } from "@dxos/util";
|
|
3114
|
-
|
|
3115
|
-
// packages/core/echo/echo-pipeline/src/automerge/automerge-storage–wrapper.ts
|
|
3116
|
-
var AutomergeStorageWrapper = class {
|
|
3117
|
-
constructor({ storage, callbacks }) {
|
|
3118
|
-
this._storage = storage;
|
|
3119
|
-
this._callbacks = callbacks;
|
|
3120
|
-
}
|
|
3121
|
-
async load(key) {
|
|
3122
|
-
return this._storage.load(key);
|
|
3123
|
-
}
|
|
3124
|
-
async save(key, value) {
|
|
3125
|
-
await this._callbacks.beforeSave?.(key);
|
|
3126
|
-
await this._storage.save(key, value);
|
|
3127
|
-
await this._callbacks.afterSave?.(key);
|
|
3128
|
-
}
|
|
3129
|
-
async remove(key) {
|
|
3130
|
-
return this._storage.remove(key);
|
|
3131
|
-
}
|
|
3132
|
-
async loadRange(keyPrefix) {
|
|
3133
|
-
return this._storage.loadRange(keyPrefix);
|
|
3134
|
-
}
|
|
3135
|
-
async removeRange(keyPrefix) {
|
|
3136
|
-
return this._storage.removeRange(keyPrefix);
|
|
3137
|
-
}
|
|
3138
|
-
async close() {
|
|
3139
|
-
if (this._storage instanceof AutomergeStorageAdapter) {
|
|
3140
|
-
return this._storage.close();
|
|
3141
|
-
}
|
|
3142
|
-
}
|
|
3143
|
-
};
|
|
3144
|
-
|
|
3145
|
-
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
3146
|
-
function _ts_decorate9(decorators, target, key, desc) {
|
|
3147
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3148
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
3149
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
3150
|
-
else
|
|
3151
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
3152
|
-
if (d = decorators[i])
|
|
3153
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3154
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3155
|
-
}
|
|
3156
|
-
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
3157
|
-
var AutomergeHost = class {
|
|
3158
|
-
constructor({ directory, metadata }) {
|
|
3159
|
-
this._ctx = new Context7();
|
|
3160
|
-
/**
|
|
3161
|
-
* spaceKey -> deviceKey[]
|
|
3162
|
-
*/
|
|
3163
|
-
this._authorizedDevices = new ComplexMap7(PublicKey8.hash);
|
|
3164
|
-
this._updatingMetadata = /* @__PURE__ */ new Map();
|
|
3165
|
-
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
3166
|
-
this._metadata = metadata;
|
|
3167
|
-
this._meshNetwork = new MeshNetworkAdapter();
|
|
3168
|
-
this._clientNetwork = new LocalHostNetworkAdapter();
|
|
3169
|
-
this._storage = new AutomergeStorageWrapper({
|
|
3170
|
-
storage: (
|
|
3171
|
-
// TODO(mykola): Delete specific handling of IDB storage.
|
|
3172
|
-
directory.type === StorageType.IDB ? new IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory)
|
|
3173
|
-
),
|
|
3174
|
-
callbacks: {
|
|
3175
|
-
beforeSave: (params) => this._beforeSave(params)
|
|
3176
|
-
}
|
|
3177
|
-
});
|
|
3178
|
-
this._peerId = `host-${PublicKey8.random().toHex()}`;
|
|
3179
|
-
this._repo = new Repo({
|
|
3180
|
-
peerId: this._peerId,
|
|
3181
|
-
network: [
|
|
3182
|
-
this._clientNetwork,
|
|
3183
|
-
this._meshNetwork
|
|
3184
|
-
],
|
|
3185
|
-
storage: this._storage,
|
|
3186
|
-
// TODO(dmaretskyi): Share based on HALO permissions and space affinity.
|
|
3187
|
-
// Hosts, running in the worker, don't share documents unless requested by other peers.
|
|
3188
|
-
sharePolicy: async (peerId, documentId) => {
|
|
3189
|
-
if (peerId.startsWith("client-")) {
|
|
3190
|
-
return false;
|
|
3191
|
-
}
|
|
3192
|
-
if (!documentId) {
|
|
3193
|
-
return false;
|
|
3194
|
-
}
|
|
3195
|
-
const doc = this._repo.handles[documentId]?.docSync();
|
|
3196
|
-
if (!doc) {
|
|
3197
|
-
const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
|
|
3198
|
-
log15("doc share policy check", {
|
|
3199
|
-
peerId,
|
|
3200
|
-
documentId,
|
|
3201
|
-
isRequested
|
|
3202
|
-
}, {
|
|
3203
|
-
F: __dxlog_file16,
|
|
3204
|
-
L: 96,
|
|
3205
|
-
S: this,
|
|
3206
|
-
C: (f, a) => f(...a)
|
|
3207
|
-
});
|
|
3208
|
-
return isRequested;
|
|
3209
|
-
}
|
|
3210
|
-
try {
|
|
3211
|
-
const spaceKey = getSpaceKeyFromDoc(doc);
|
|
3212
|
-
if (!spaceKey) {
|
|
3213
|
-
log15("space key not found for share policy check", {
|
|
3214
|
-
peerId,
|
|
3215
|
-
documentId
|
|
3216
|
-
}, {
|
|
3217
|
-
F: __dxlog_file16,
|
|
3218
|
-
L: 103,
|
|
3219
|
-
S: this,
|
|
3220
|
-
C: (f, a) => f(...a)
|
|
3221
|
-
});
|
|
3222
|
-
return false;
|
|
3223
|
-
}
|
|
3224
|
-
const authorizedDevices = this._authorizedDevices.get(PublicKey8.from(spaceKey));
|
|
3225
|
-
const deviceKeyHex = this.repo.peerMetadataByPeerId[peerId]?.dxos_deviceKey;
|
|
3226
|
-
if (!deviceKeyHex) {
|
|
3227
|
-
log15("device key not found for share policy check", {
|
|
3228
|
-
peerId,
|
|
3229
|
-
documentId
|
|
3230
|
-
}, {
|
|
3231
|
-
F: __dxlog_file16,
|
|
3232
|
-
L: 112,
|
|
3233
|
-
S: this,
|
|
3234
|
-
C: (f, a) => f(...a)
|
|
3235
|
-
});
|
|
3236
|
-
return false;
|
|
3237
|
-
}
|
|
3238
|
-
const deviceKey = PublicKey8.from(deviceKeyHex);
|
|
3239
|
-
const isAuthorized = authorizedDevices?.has(deviceKey) ?? false;
|
|
3240
|
-
log15("share policy check", {
|
|
3241
|
-
localPeer: this._peerId,
|
|
3242
|
-
remotePeer: peerId,
|
|
3243
|
-
documentId,
|
|
3244
|
-
deviceKey,
|
|
3245
|
-
spaceKey,
|
|
3246
|
-
isAuthorized
|
|
3247
|
-
}, {
|
|
3248
|
-
F: __dxlog_file16,
|
|
3249
|
-
L: 118,
|
|
3250
|
-
S: this,
|
|
3251
|
-
C: (f, a) => f(...a)
|
|
3252
|
-
});
|
|
3253
|
-
return isAuthorized;
|
|
3254
|
-
} catch (err) {
|
|
3255
|
-
log15.catch(err, void 0, {
|
|
3256
|
-
F: __dxlog_file16,
|
|
3257
|
-
L: 128,
|
|
3258
|
-
S: this,
|
|
3259
|
-
C: (f, a) => f(...a)
|
|
3260
|
-
});
|
|
3261
|
-
return false;
|
|
3262
|
-
}
|
|
3263
|
-
}
|
|
3264
|
-
});
|
|
3265
|
-
this._clientNetwork.ready();
|
|
3266
|
-
this._meshNetwork.ready();
|
|
3267
|
-
{
|
|
3268
|
-
const listener = ({ handle }) => this._onDocument(handle);
|
|
3269
|
-
this._repo.on("document", listener);
|
|
3270
|
-
this._ctx.onDispose(() => {
|
|
3271
|
-
this._repo.off("document", listener);
|
|
3272
|
-
});
|
|
3273
|
-
}
|
|
3274
|
-
}
|
|
3275
|
-
get repo() {
|
|
3276
|
-
return this._repo;
|
|
3277
|
-
}
|
|
3278
|
-
async _beforeSave(path) {
|
|
3279
|
-
const id = path[0];
|
|
3280
|
-
if (this._updatingMetadata.has(id)) {
|
|
3281
|
-
return this._updatingMetadata.get(id);
|
|
3282
|
-
}
|
|
3283
|
-
}
|
|
3284
|
-
_onDocument(handle) {
|
|
3285
|
-
const listener = (event) => this._onUpdate(event);
|
|
3286
|
-
handle.on("change", listener);
|
|
3287
|
-
this._ctx.onDispose(() => {
|
|
3288
|
-
handle.off("change", listener);
|
|
3289
|
-
});
|
|
3290
|
-
}
|
|
3291
|
-
_onUpdate(event) {
|
|
3292
|
-
if (this._metadata == null) {
|
|
3293
|
-
return;
|
|
3294
|
-
}
|
|
3295
|
-
const objectIds = getInlineChanges(event);
|
|
3296
|
-
if (objectIds.length === 0) {
|
|
3297
|
-
return;
|
|
3298
|
-
}
|
|
3299
|
-
const heads = getHeads(event.doc);
|
|
3300
|
-
const lastAvailableHash = heads.at(-1);
|
|
3301
|
-
if (!lastAvailableHash) {
|
|
3302
|
-
return;
|
|
3303
|
-
}
|
|
3304
|
-
const encodedIds = objectIds.map((objectId) => idCodec.encode({
|
|
3305
|
-
documentId: event.handle.documentId,
|
|
3306
|
-
objectId
|
|
3307
|
-
}));
|
|
3308
|
-
const idToLastHash = new Map(encodedIds.map((id) => [
|
|
3309
|
-
id,
|
|
3310
|
-
lastAvailableHash
|
|
3311
|
-
]));
|
|
3312
|
-
const markingDirtyPromise = this._metadata.markDirty(idToLastHash).then(() => {
|
|
3313
|
-
this._updatingMetadata.delete(event.handle.documentId);
|
|
3314
|
-
}).catch((err) => {
|
|
3315
|
-
this._ctx.disposed && log15.catch(err, void 0, {
|
|
3316
|
-
F: __dxlog_file16,
|
|
3317
|
-
L: 188,
|
|
3318
|
-
S: this,
|
|
3319
|
-
C: (f, a) => f(...a)
|
|
3320
|
-
});
|
|
3321
|
-
});
|
|
3322
|
-
this._updatingMetadata.set(event.handle.documentId, markingDirtyPromise);
|
|
3323
|
-
}
|
|
3324
|
-
_automergeDocs() {
|
|
3325
|
-
return mapValues(this._repo.handles, (handle) => ({
|
|
3326
|
-
state: handle.state,
|
|
3327
|
-
hasDoc: !!handle.docSync(),
|
|
3328
|
-
heads: handle.docSync() ? automerge.getHeads(handle.docSync()) : null,
|
|
3329
|
-
data: handle.docSync()?.doc && mapValues(handle.docSync()?.doc, (value, key) => {
|
|
3330
|
-
try {
|
|
3331
|
-
switch (key) {
|
|
3332
|
-
case "access":
|
|
3333
|
-
case "links":
|
|
3334
|
-
return value;
|
|
3335
|
-
case "objects":
|
|
3336
|
-
return Object.keys(value);
|
|
3337
|
-
default:
|
|
3338
|
-
return `${value}`;
|
|
3339
|
-
}
|
|
3340
|
-
} catch (err) {
|
|
3341
|
-
return `${err}`;
|
|
3342
|
-
}
|
|
3343
|
-
})
|
|
3344
|
-
}));
|
|
3345
|
-
}
|
|
3346
|
-
_automergePeers() {
|
|
3347
|
-
return this._repo.peers;
|
|
3348
|
-
}
|
|
3349
|
-
async close() {
|
|
3350
|
-
await this._storage.close();
|
|
3351
|
-
await this._clientNetwork.close();
|
|
3352
|
-
await this._ctx.dispose();
|
|
3353
|
-
}
|
|
3354
|
-
//
|
|
3355
|
-
// Methods for client-services.
|
|
3356
|
-
//
|
|
3357
|
-
syncRepo(request) {
|
|
3358
|
-
return this._clientNetwork.syncRepo(request);
|
|
3359
|
-
}
|
|
3360
|
-
sendSyncMessage(request) {
|
|
3361
|
-
return this._clientNetwork.sendSyncMessage(request);
|
|
3362
|
-
}
|
|
3363
|
-
async getHostInfo() {
|
|
3364
|
-
return this._clientNetwork.getHostInfo();
|
|
3365
|
-
}
|
|
3366
|
-
//
|
|
3367
|
-
// Mesh replication.
|
|
3368
|
-
//
|
|
3369
|
-
createExtension() {
|
|
3370
|
-
return this._meshNetwork.createExtension();
|
|
3371
|
-
}
|
|
3372
|
-
authorizeDevice(spaceKey, deviceKey) {
|
|
3373
|
-
log15("authorizeDevice", {
|
|
3374
|
-
spaceKey,
|
|
3375
|
-
deviceKey
|
|
3376
|
-
}, {
|
|
3377
|
-
F: __dxlog_file16,
|
|
3378
|
-
L: 255,
|
|
3379
|
-
S: this,
|
|
3380
|
-
C: (f, a) => f(...a)
|
|
3381
|
-
});
|
|
3382
|
-
defaultMap(this._authorizedDevices, spaceKey, () => new ComplexSet(PublicKey8.hash)).add(deviceKey);
|
|
3383
|
-
}
|
|
3384
|
-
};
|
|
3385
|
-
_ts_decorate9([
|
|
3386
|
-
trace6.info()
|
|
3387
|
-
], AutomergeHost.prototype, "_peerId", void 0);
|
|
3388
|
-
_ts_decorate9([
|
|
3389
|
-
trace6.info({
|
|
3390
|
-
depth: null
|
|
3391
|
-
})
|
|
3392
|
-
], AutomergeHost.prototype, "_automergeDocs", null);
|
|
3393
|
-
_ts_decorate9([
|
|
3394
|
-
trace6.info({
|
|
3395
|
-
depth: null
|
|
3396
|
-
})
|
|
3397
|
-
], AutomergeHost.prototype, "_automergePeers", null);
|
|
3398
|
-
AutomergeHost = _ts_decorate9([
|
|
3399
|
-
trace6.resource()
|
|
3400
|
-
], AutomergeHost);
|
|
3401
|
-
var getInlineChanges = (event) => {
|
|
3402
|
-
const inlineChangedObjectIds = /* @__PURE__ */ new Set();
|
|
3403
|
-
for (const { path } of event.patches) {
|
|
3404
|
-
if (path.length < 2) {
|
|
3405
|
-
continue;
|
|
3406
|
-
}
|
|
3407
|
-
switch (path[0]) {
|
|
3408
|
-
case "objects":
|
|
3409
|
-
if (path.length >= 2) {
|
|
3410
|
-
inlineChangedObjectIds.add(path[1]);
|
|
3411
|
-
}
|
|
3412
|
-
break;
|
|
3413
|
-
}
|
|
3414
|
-
}
|
|
3415
|
-
return [
|
|
3416
|
-
...inlineChangedObjectIds
|
|
3417
|
-
];
|
|
3418
|
-
};
|
|
3419
|
-
var getSpaceKeyFromDoc = (doc) => {
|
|
3420
|
-
const rawSpaceKey = doc.access?.spaceKey ?? doc.experimental_spaceKey;
|
|
3421
|
-
if (rawSpaceKey == null) {
|
|
3422
|
-
return null;
|
|
3423
|
-
}
|
|
3424
|
-
return String(rawSpaceKey);
|
|
3425
|
-
};
|
|
3426
|
-
|
|
3427
2772
|
export {
|
|
3428
2773
|
codec,
|
|
3429
2774
|
valueEncoding,
|
|
@@ -3448,11 +2793,6 @@ export {
|
|
|
3448
2793
|
SpaceProtocol,
|
|
3449
2794
|
AuthStatus,
|
|
3450
2795
|
SpaceProtocolSession,
|
|
3451
|
-
SpaceManager
|
|
3452
|
-
AutomergeStorageAdapter,
|
|
3453
|
-
LocalHostNetworkAdapter,
|
|
3454
|
-
MeshNetworkAdapter,
|
|
3455
|
-
AutomergeHost,
|
|
3456
|
-
getSpaceKeyFromDoc
|
|
2796
|
+
SpaceManager
|
|
3457
2797
|
};
|
|
3458
|
-
//# sourceMappingURL=chunk-
|
|
2798
|
+
//# sourceMappingURL=chunk-WAN2XUWE.mjs.map
|