@dxos/echo-pipeline 0.5.9-next.a50ff17 → 0.6.1-main.04e8aa0

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.
Files changed (49) hide show
  1. package/dist/lib/browser/{chunk-I2J5TTHJ.mjs → chunk-A2LCXJVD.mjs} +189 -23
  2. package/dist/lib/browser/chunk-A2LCXJVD.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +279 -143
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +11 -7
  7. package/dist/lib/browser/testing/index.mjs.map +1 -1
  8. package/dist/lib/node/{chunk-QPCNQ4ZK.cjs → chunk-GHBIMYZK.cjs} +200 -34
  9. package/dist/lib/node/chunk-GHBIMYZK.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +294 -160
  11. package/dist/lib/node/index.cjs.map +4 -4
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +21 -17
  14. package/dist/lib/node/testing/index.cjs.map +1 -1
  15. package/dist/types/src/automerge/automerge-doc-loader.d.ts +2 -1
  16. package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -1
  17. package/dist/types/src/automerge/automerge-host.d.ts +50 -10
  18. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  19. package/dist/types/src/automerge/echo-network-adapter.d.ts +4 -2
  20. package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
  21. package/dist/types/src/automerge/echo-replicator.d.ts +5 -6
  22. package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
  23. package/dist/types/src/automerge/heads-store.d.ts +13 -0
  24. package/dist/types/src/automerge/heads-store.d.ts.map +1 -0
  25. package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
  26. package/dist/types/src/db-host/data-service.d.ts +4 -2
  27. package/dist/types/src/db-host/data-service.d.ts.map +1 -1
  28. package/dist/types/src/space/admission-discovery-extension.d.ts +30 -0
  29. package/dist/types/src/space/admission-discovery-extension.d.ts.map +1 -0
  30. package/dist/types/src/space/index.d.ts +1 -0
  31. package/dist/types/src/space/index.d.ts.map +1 -1
  32. package/dist/types/src/space/space-manager.d.ts +8 -0
  33. package/dist/types/src/space/space-manager.d.ts.map +1 -1
  34. package/package.json +33 -33
  35. package/src/automerge/automerge-doc-loader.test.ts +8 -5
  36. package/src/automerge/automerge-doc-loader.ts +30 -21
  37. package/src/automerge/automerge-host.test.ts +34 -17
  38. package/src/automerge/automerge-host.ts +148 -44
  39. package/src/automerge/automerge-repo.test.ts +76 -1
  40. package/src/automerge/echo-network-adapter.ts +20 -10
  41. package/src/automerge/echo-replicator.ts +6 -9
  42. package/src/automerge/heads-store.ts +39 -0
  43. package/src/automerge/mesh-echo-replicator.ts +12 -7
  44. package/src/db-host/data-service.ts +22 -2
  45. package/src/space/admission-discovery-extension.ts +90 -0
  46. package/src/space/index.ts +1 -0
  47. package/src/space/space-manager.ts +46 -1
  48. package/dist/lib/browser/chunk-I2J5TTHJ.mjs.map +0 -7
  49. package/dist/lib/node/chunk-QPCNQ4ZK.cjs.map +0 -7
@@ -145,6 +145,21 @@ var DataServiceImpl = class {
145
145
  sendSyncMessage(request) {
146
146
  return this._automergeHost.sendSyncMessage(request);
147
147
  }
148
+ async getDocumentHeads(request) {
149
+ const states = await Promise.all(request.documentIds?.map(async (documentId) => {
150
+ const heads = await this._automergeHost.getHeads(documentId);
151
+ return {
152
+ documentId,
153
+ heads
154
+ };
155
+ }) ?? []);
156
+ return {
157
+ states
158
+ };
159
+ }
160
+ async reIndexHeads(request, options) {
161
+ await this._automergeHost.reIndexHeads(request.documentIds ?? []);
162
+ }
148
163
  };
149
164
 
150
165
  // packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts
@@ -184,7 +199,10 @@ var MetadataStore = class {
184
199
  this._spaceLargeMetadata = new ComplexMap(PublicKey2.hash);
185
200
  this._metadataFile = void 0;
186
201
  this.update = new Event();
187
- this._invitationCleanupCtx = new Context();
202
+ this._invitationCleanupCtx = new Context(void 0, {
203
+ F: __dxlog_file2,
204
+ L: 53
205
+ });
188
206
  this._directory = directory;
189
207
  }
190
208
  get metadata() {
@@ -641,7 +659,10 @@ var PipelineState = class {
641
659
  constructor(_feeds, _timeframeClock) {
642
660
  this._feeds = _feeds;
643
661
  this._timeframeClock = _timeframeClock;
644
- this._ctx = new Context2();
662
+ this._ctx = new Context2(void 0, {
663
+ F: __dxlog_file5,
664
+ L: 41
665
+ });
645
666
  this.timeframeUpdate = this._timeframeClock.update;
646
667
  this.stalled = new Event3();
647
668
  this._startTimeframe = new Timeframe2();
@@ -689,7 +710,10 @@ var PipelineState = class {
689
710
  *
690
711
  * @param timeout Timeout in milliseconds to specify the maximum wait time.
691
712
  */
692
- async waitUntilReachedTargetTimeframe({ ctx = new Context2(), timeout, breakOnStall = true } = {}) {
713
+ async waitUntilReachedTargetTimeframe({ ctx = new Context2(void 0, {
714
+ F: __dxlog_file5,
715
+ L: 129
716
+ }), timeout, breakOnStall = true } = {}) {
693
717
  log4("waitUntilReachedTargetTimeframe", {
694
718
  timeout,
695
719
  current: this.timeframe,
@@ -857,7 +881,10 @@ var Pipeline = class {
857
881
  await this._feedSetIterator?.close();
858
882
  await this._processingTrigger.wait();
859
883
  await this._state._ctx.dispose();
860
- this._state._ctx = new Context2();
884
+ this._state._ctx = new Context2(void 0, {
885
+ F: __dxlog_file5,
886
+ L: 309
887
+ });
861
888
  this._state._reachedTargetPromise = void 0;
862
889
  this._state._reachedTarget = false;
863
890
  this._isStarted = false;
@@ -1070,6 +1097,9 @@ var AuthExtension = class extends RpcExtension {
1070
1097
  C: (f, a) => f(...a)
1071
1098
  });
1072
1099
  }
1100
+ }, {
1101
+ F: __dxlog_file6,
1102
+ L: 26
1073
1103
  });
1074
1104
  }
1075
1105
  async getHandlers() {
@@ -1184,7 +1214,10 @@ var CONTROL_PIPELINE_SNAPSHOT_DELAY = 1e4;
1184
1214
  var USE_SNAPSHOTS = true;
1185
1215
  var ControlPipeline = class {
1186
1216
  constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
1187
- this._ctx = new Context4();
1217
+ this._ctx = new Context4(void 0, {
1218
+ F: __dxlog_file7,
1219
+ L: 47
1220
+ });
1188
1221
  this._lastTimeframeSaveTime = Date.now();
1189
1222
  this.onFeedAdmitted = new Callback();
1190
1223
  this._usage = new TimeUsageCounter();
@@ -1263,7 +1296,10 @@ var ControlPipeline = class {
1263
1296
  C: (f, a) => f(...a)
1264
1297
  });
1265
1298
  setTimeout(async () => {
1266
- void this._consumePipeline(new Context4());
1299
+ void this._consumePipeline(new Context4(void 0, {
1300
+ F: __dxlog_file7,
1301
+ L: 130
1302
+ }));
1267
1303
  });
1268
1304
  await this._pipeline.start();
1269
1305
  log6("started", void 0, {
@@ -1655,6 +1691,73 @@ var createIdFromSpaceKey = async (spaceKey) => {
1655
1691
  return spaceId;
1656
1692
  };
1657
1693
 
1694
+ // packages/core/echo/echo-pipeline/src/space/admission-discovery-extension.ts
1695
+ import { scheduleTask as scheduleTask2 } from "@dxos/async";
1696
+ import { Context as Context5 } from "@dxos/context";
1697
+ import { ProtocolError, schema as schema6 } from "@dxos/protocols";
1698
+ import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
1699
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/admission-discovery-extension.ts";
1700
+ var CredentialRetrieverExtension = class extends RpcExtension2 {
1701
+ constructor(_request, _onResult) {
1702
+ super({
1703
+ requested: {
1704
+ AdmissionDiscoveryService: schema6.getService("dxos.mesh.teleport.AdmissionDiscoveryService")
1705
+ }
1706
+ });
1707
+ this._request = _request;
1708
+ this._onResult = _onResult;
1709
+ this._ctx = new Context5(void 0, {
1710
+ F: __dxlog_file9,
1711
+ L: 25
1712
+ });
1713
+ }
1714
+ async getHandlers() {
1715
+ return {};
1716
+ }
1717
+ async onOpen(context) {
1718
+ await super.onOpen(context);
1719
+ scheduleTask2(this._ctx, async () => {
1720
+ try {
1721
+ const result = await this.rpc.AdmissionDiscoveryService.getAdmissionCredential(this._request);
1722
+ this._onResult.wake(result.admissionCredential);
1723
+ } catch (err) {
1724
+ context.close(err);
1725
+ }
1726
+ });
1727
+ }
1728
+ async onClose() {
1729
+ await this._ctx.dispose();
1730
+ }
1731
+ async onAbort() {
1732
+ await this._ctx.dispose();
1733
+ }
1734
+ };
1735
+ var CredentialServerExtension = class extends RpcExtension2 {
1736
+ constructor(_space) {
1737
+ super({
1738
+ exposed: {
1739
+ AdmissionDiscoveryService: schema6.getService("dxos.mesh.teleport.AdmissionDiscoveryService")
1740
+ }
1741
+ });
1742
+ this._space = _space;
1743
+ }
1744
+ async getHandlers() {
1745
+ return {
1746
+ AdmissionDiscoveryService: {
1747
+ getAdmissionCredential: async (request) => {
1748
+ const memberInfo = this._space.spaceState.members.get(request.memberKey);
1749
+ if (!memberInfo?.credential) {
1750
+ throw new ProtocolError("Space member not found.", request);
1751
+ }
1752
+ return {
1753
+ admissionCredential: memberInfo.credential
1754
+ };
1755
+ }
1756
+ }
1757
+ };
1758
+ }
1759
+ };
1760
+
1658
1761
  // packages/core/echo/echo-pipeline/src/space/space-protocol.ts
1659
1762
  import { discoveryKey, subtleCrypto as subtleCrypto3 } from "@dxos/crypto";
1660
1763
  import { PublicKey as PublicKey6 } from "@dxos/keys";
@@ -1675,7 +1778,7 @@ function _ts_decorate6(decorators, target, key, desc) {
1675
1778
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1676
1779
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1677
1780
  }
1678
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-protocol.ts";
1781
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-protocol.ts";
1679
1782
  var MOCK_AUTH_PROVIDER = async (nonce) => Buffer.from("mock");
1680
1783
  var MOCK_AUTH_VERIFIER = async (nonce, credential) => true;
1681
1784
  var SpaceProtocol = class {
@@ -1712,7 +1815,7 @@ var SpaceProtocol = class {
1712
1815
  log8("addFeed", {
1713
1816
  key: feed.key
1714
1817
  }, {
1715
- F: __dxlog_file9,
1818
+ F: __dxlog_file10,
1716
1819
  L: 109,
1717
1820
  S: this,
1718
1821
  C: (f, a) => f(...a)
@@ -1730,7 +1833,7 @@ var SpaceProtocol = class {
1730
1833
  const credentials = await this._swarmIdentity.credentialProvider(Buffer.from(""));
1731
1834
  await this.blobSync.open();
1732
1835
  log8("starting...", void 0, {
1733
- F: __dxlog_file9,
1836
+ F: __dxlog_file10,
1734
1837
  L: 128,
1735
1838
  S: this,
1736
1839
  C: (f, a) => f(...a)
@@ -1744,7 +1847,7 @@ var SpaceProtocol = class {
1744
1847
  label: `swarm ${topic.truncate()} for space ${this._spaceKey.truncate()}`
1745
1848
  });
1746
1849
  log8("started", void 0, {
1747
- F: __dxlog_file9,
1850
+ F: __dxlog_file10,
1748
1851
  L: 138,
1749
1852
  S: this,
1750
1853
  C: (f, a) => f(...a)
@@ -1757,14 +1860,14 @@ var SpaceProtocol = class {
1757
1860
  await this.blobSync.close();
1758
1861
  if (this._connection) {
1759
1862
  log8("stopping...", void 0, {
1760
- F: __dxlog_file9,
1863
+ F: __dxlog_file10,
1761
1864
  L: 149,
1762
1865
  S: this,
1763
1866
  C: (f, a) => f(...a)
1764
1867
  });
1765
1868
  await this._connection.close();
1766
1869
  log8("stopped", void 0, {
1767
- F: __dxlog_file9,
1870
+ F: __dxlog_file10,
1768
1871
  L: 151,
1769
1872
  S: this,
1770
1873
  C: (f, a) => f(...a)
@@ -1838,7 +1941,7 @@ var SpaceProtocolSession = class {
1838
1941
  verifier: this._swarmIdentity.credentialAuthenticator,
1839
1942
  onAuthSuccess: () => {
1840
1943
  log8("Peer authenticated", void 0, {
1841
- F: __dxlog_file9,
1944
+ F: __dxlog_file10,
1842
1945
  L: 248,
1843
1946
  S: this,
1844
1947
  C: (f, a) => f(...a)
@@ -1856,7 +1959,7 @@ var SpaceProtocolSession = class {
1856
1959
  }
1857
1960
  async close() {
1858
1961
  log8("close", void 0, {
1859
- F: __dxlog_file9,
1962
+ F: __dxlog_file10,
1860
1963
  L: 264,
1861
1964
  S: this,
1862
1965
  C: (f, a) => f(...a)
@@ -1875,7 +1978,7 @@ _ts_decorate6([
1875
1978
  ], SpaceProtocolSession.prototype, "authStatus", null);
1876
1979
 
1877
1980
  // packages/core/echo/echo-pipeline/src/space/space-manager.ts
1878
- import { synchronized as synchronized4, trackLeaks as trackLeaks3 } from "@dxos/async";
1981
+ import { synchronized as synchronized4, trackLeaks as trackLeaks3, Trigger as Trigger2 } from "@dxos/async";
1879
1982
  import { failUndefined as failUndefined2 } from "@dxos/debug";
1880
1983
  import { PublicKey as PublicKey7 } from "@dxos/keys";
1881
1984
  import { log as log9 } from "@dxos/log";
@@ -1891,7 +1994,7 @@ function _ts_decorate7(decorators, target, key, desc) {
1891
1994
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1892
1995
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1893
1996
  }
1894
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
1997
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
1895
1998
  var SpaceManager = class {
1896
1999
  constructor({ feedStore, networkManager, metadataStore, snapshotStore, blobStore }) {
1897
2000
  this._spaces = new ComplexMap5(PublicKey7.hash);
@@ -1917,16 +2020,16 @@ var SpaceManager = class {
1917
2020
  log9.trace("dxos.echo.space-manager.construct-space", trace4.begin({
1918
2021
  id: this._instanceId
1919
2022
  }), {
1920
- F: __dxlog_file10,
1921
- L: 94,
2023
+ F: __dxlog_file11,
2024
+ L: 103,
1922
2025
  S: this,
1923
2026
  C: (f, a) => f(...a)
1924
2027
  });
1925
2028
  log9("constructing space...", {
1926
2029
  spaceKey: metadata.genesisFeedKey
1927
2030
  }, {
1928
- F: __dxlog_file10,
1929
- L: 95,
2031
+ F: __dxlog_file11,
2032
+ L: 104,
1930
2033
  S: this,
1931
2034
  C: (f, a) => f(...a)
1932
2035
  });
@@ -1958,13 +2061,74 @@ var SpaceManager = class {
1958
2061
  log9.trace("dxos.echo.space-manager.construct-space", trace4.end({
1959
2062
  id: this._instanceId
1960
2063
  }), {
1961
- F: __dxlog_file10,
1962
- L: 126,
2064
+ F: __dxlog_file11,
2065
+ L: 135,
1963
2066
  S: this,
1964
2067
  C: (f, a) => f(...a)
1965
2068
  });
1966
2069
  return space;
1967
2070
  }
2071
+ async requestSpaceAdmissionCredential(params) {
2072
+ const traceKey = "dxos.echo.space-manager.request-space-admission";
2073
+ log9.trace(traceKey, trace4.begin({
2074
+ id: this._instanceId
2075
+ }), {
2076
+ F: __dxlog_file11,
2077
+ L: 141,
2078
+ S: this,
2079
+ C: (f, a) => f(...a)
2080
+ });
2081
+ log9("requesting space admission credential...", {
2082
+ spaceKey: params.spaceKey
2083
+ }, {
2084
+ F: __dxlog_file11,
2085
+ L: 142,
2086
+ S: this,
2087
+ C: (f, a) => f(...a)
2088
+ });
2089
+ const onCredentialResolved = new Trigger2();
2090
+ const protocol = new SpaceProtocol({
2091
+ topic: params.spaceKey,
2092
+ swarmIdentity: params.swarmIdentity,
2093
+ networkManager: this._networkManager,
2094
+ onSessionAuth: (session) => {
2095
+ session.addExtension("dxos.mesh.teleport.admission-discovery", new CredentialRetrieverExtension({
2096
+ spaceKey: params.spaceKey,
2097
+ memberKey: params.identityKey
2098
+ }, onCredentialResolved));
2099
+ },
2100
+ onAuthFailure: (session) => session.close(),
2101
+ blobStore: this._blobStore
2102
+ });
2103
+ try {
2104
+ await protocol.start();
2105
+ const credential = await onCredentialResolved.wait({
2106
+ timeout: params.timeout
2107
+ });
2108
+ log9.trace(traceKey, trace4.end({
2109
+ id: this._instanceId
2110
+ }), {
2111
+ F: __dxlog_file11,
2112
+ L: 165,
2113
+ S: this,
2114
+ C: (f, a) => f(...a)
2115
+ });
2116
+ return credential;
2117
+ } catch (err) {
2118
+ log9.trace(traceKey, trace4.error({
2119
+ id: this._instanceId,
2120
+ error: err
2121
+ }), {
2122
+ F: __dxlog_file11,
2123
+ L: 168,
2124
+ S: this,
2125
+ C: (f, a) => f(...a)
2126
+ });
2127
+ throw err;
2128
+ } finally {
2129
+ await protocol.stop();
2130
+ }
2131
+ }
1968
2132
  };
1969
2133
  _ts_decorate7([
1970
2134
  synchronized4
@@ -1994,6 +2158,8 @@ export {
1994
2158
  AuthExtension,
1995
2159
  Space,
1996
2160
  createIdFromSpaceKey,
2161
+ CredentialRetrieverExtension,
2162
+ CredentialServerExtension,
1997
2163
  MOCK_AUTH_PROVIDER,
1998
2164
  MOCK_AUTH_VERIFIER,
1999
2165
  SpaceProtocol,
@@ -2001,4 +2167,4 @@ export {
2001
2167
  SpaceProtocolSession,
2002
2168
  SpaceManager
2003
2169
  };
2004
- //# sourceMappingURL=chunk-I2J5TTHJ.mjs.map
2170
+ //# sourceMappingURL=chunk-A2LCXJVD.mjs.map