@dxos/echo-pipeline 0.5.9-main.a2de4fa → 0.5.9-main.a75fa71

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 (31) hide show
  1. package/dist/lib/browser/{chunk-I2J5TTHJ.mjs → chunk-HS77A4I4.mjs} +174 -23
  2. package/dist/lib/browser/{chunk-I2J5TTHJ.mjs.map → chunk-HS77A4I4.mjs.map} +4 -4
  3. package/dist/lib/browser/index.mjs +91 -42
  4. package/dist/lib/browser/index.mjs.map +3 -3
  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-Y5U7UXEL.cjs} +185 -34
  9. package/dist/lib/node/{chunk-QPCNQ4ZK.cjs.map → chunk-Y5U7UXEL.cjs.map} +4 -4
  10. package/dist/lib/node/index.cjs +126 -77
  11. package/dist/lib/node/index.cjs.map +3 -3
  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-host.d.ts +40 -2
  16. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  17. package/dist/types/src/automerge/echo-network-adapter.d.ts +2 -0
  18. package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
  19. package/dist/types/src/space/admission-discovery-extension.d.ts +30 -0
  20. package/dist/types/src/space/admission-discovery-extension.d.ts.map +1 -0
  21. package/dist/types/src/space/index.d.ts +1 -0
  22. package/dist/types/src/space/index.d.ts.map +1 -1
  23. package/dist/types/src/space/space-manager.d.ts +8 -0
  24. package/dist/types/src/space/space-manager.d.ts.map +1 -1
  25. package/package.json +33 -33
  26. package/src/automerge/automerge-host.ts +96 -18
  27. package/src/automerge/echo-network-adapter.ts +10 -4
  28. package/src/automerge/mesh-echo-replicator.ts +1 -1
  29. package/src/space/admission-discovery-extension.ts +90 -0
  30. package/src/space/index.ts +1 -0
  31. package/src/space/space-manager.ts +46 -1
@@ -26,10 +26,12 @@ 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 chunk_QPCNQ4ZK_exports = {};
30
- __export(chunk_QPCNQ4ZK_exports, {
29
+ var chunk_Y5U7UXEL_exports = {};
30
+ __export(chunk_Y5U7UXEL_exports, {
31
31
  AuthExtension: () => AuthExtension,
32
32
  AuthStatus: () => AuthStatus,
33
+ CredentialRetrieverExtension: () => CredentialRetrieverExtension,
34
+ CredentialServerExtension: () => CredentialServerExtension,
33
35
  DataServiceImpl: () => DataServiceImpl,
34
36
  MOCK_AUTH_PROVIDER: () => MOCK_AUTH_PROVIDER,
35
37
  MOCK_AUTH_VERIFIER: () => MOCK_AUTH_VERIFIER,
@@ -51,7 +53,7 @@ __export(chunk_QPCNQ4ZK_exports, {
51
53
  startAfter: () => startAfter,
52
54
  valueEncoding: () => valueEncoding
53
55
  });
54
- module.exports = __toCommonJS(chunk_QPCNQ4ZK_exports);
56
+ module.exports = __toCommonJS(chunk_Y5U7UXEL_exports);
55
57
  var import_hypercore = require("@dxos/hypercore");
56
58
  var import_protocols = require("@dxos/protocols");
57
59
  var import_invariant = require("@dxos/invariant");
@@ -110,20 +112,24 @@ var import_credentials3 = require("@dxos/protocols/proto/dxos/halo/credentials")
110
112
  var import_timeframe3 = require("@dxos/timeframe");
111
113
  var import_tracing2 = require("@dxos/tracing");
112
114
  var import_util4 = require("@dxos/util");
115
+ var import_async7 = require("@dxos/async");
116
+ var import_context7 = require("@dxos/context");
117
+ var import_protocols6 = require("@dxos/protocols");
118
+ var import_teleport2 = require("@dxos/teleport");
113
119
  var import_crypto4 = require("@dxos/crypto");
114
120
  var import_keys6 = require("@dxos/keys");
115
121
  var import_log8 = require("@dxos/log");
116
122
  var import_network_manager = require("@dxos/network-manager");
117
- var import_teleport2 = require("@dxos/teleport");
123
+ var import_teleport3 = require("@dxos/teleport");
118
124
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
119
125
  var import_teleport_extension_replicator = require("@dxos/teleport-extension-replicator");
120
126
  var import_tracing3 = require("@dxos/tracing");
121
127
  var import_util5 = require("@dxos/util");
122
- var import_async7 = require("@dxos/async");
128
+ var import_async8 = require("@dxos/async");
123
129
  var import_debug3 = require("@dxos/debug");
124
130
  var import_keys7 = require("@dxos/keys");
125
131
  var import_log9 = require("@dxos/log");
126
- var import_protocols6 = require("@dxos/protocols");
132
+ var import_protocols7 = require("@dxos/protocols");
127
133
  var import_util6 = require("@dxos/util");
128
134
  var codec = import_protocols.schema.getCodecForType("dxos.echo.feed.FeedMessage");
129
135
  var valueEncoding = (0, import_hypercore.createCodecEncoding)(codec);
@@ -273,7 +279,10 @@ var MetadataStore = class {
273
279
  this._spaceLargeMetadata = new import_util.ComplexMap(import_keys2.PublicKey.hash);
274
280
  this._metadataFile = void 0;
275
281
  this.update = new import_async.Event();
276
- this._invitationCleanupCtx = new import_context2.Context();
282
+ this._invitationCleanupCtx = new import_context2.Context(void 0, {
283
+ F: __dxlog_file2,
284
+ L: 53
285
+ });
277
286
  this._directory = directory;
278
287
  }
279
288
  get metadata() {
@@ -707,7 +716,10 @@ var PipelineState = class {
707
716
  constructor(_feeds, _timeframeClock) {
708
717
  this._feeds = _feeds;
709
718
  this._timeframeClock = _timeframeClock;
710
- this._ctx = new import_context3.Context();
719
+ this._ctx = new import_context3.Context(void 0, {
720
+ F: __dxlog_file5,
721
+ L: 41
722
+ });
711
723
  this.timeframeUpdate = this._timeframeClock.update;
712
724
  this.stalled = new import_async3.Event();
713
725
  this._startTimeframe = new import_timeframe2.Timeframe();
@@ -755,7 +767,10 @@ var PipelineState = class {
755
767
  *
756
768
  * @param timeout Timeout in milliseconds to specify the maximum wait time.
757
769
  */
758
- async waitUntilReachedTargetTimeframe({ ctx = new import_context3.Context(), timeout, breakOnStall = true } = {}) {
770
+ async waitUntilReachedTargetTimeframe({ ctx = new import_context3.Context(void 0, {
771
+ F: __dxlog_file5,
772
+ L: 129
773
+ }), timeout, breakOnStall = true } = {}) {
759
774
  (0, import_log3.log)("waitUntilReachedTargetTimeframe", {
760
775
  timeout,
761
776
  current: this.timeframe,
@@ -920,7 +935,10 @@ var Pipeline = class {
920
935
  await this._feedSetIterator?.close();
921
936
  await this._processingTrigger.wait();
922
937
  await this._state._ctx.dispose();
923
- this._state._ctx = new import_context3.Context();
938
+ this._state._ctx = new import_context3.Context(void 0, {
939
+ F: __dxlog_file5,
940
+ L: 309
941
+ });
924
942
  this._state._reachedTargetPromise = void 0;
925
943
  this._state._reachedTarget = false;
926
944
  this._isStarted = false;
@@ -1124,6 +1142,9 @@ var AuthExtension = class extends import_teleport.RpcExtension {
1124
1142
  C: (f, a) => f(...a)
1125
1143
  });
1126
1144
  }
1145
+ }, {
1146
+ F: __dxlog_file6,
1147
+ L: 26
1127
1148
  });
1128
1149
  }
1129
1150
  async getHandlers() {
@@ -1216,7 +1237,10 @@ var CONTROL_PIPELINE_SNAPSHOT_DELAY = 1e4;
1216
1237
  var USE_SNAPSHOTS = true;
1217
1238
  var ControlPipeline = class {
1218
1239
  constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
1219
- this._ctx = new import_context6.Context();
1240
+ this._ctx = new import_context6.Context(void 0, {
1241
+ F: __dxlog_file7,
1242
+ L: 47
1243
+ });
1220
1244
  this._lastTimeframeSaveTime = Date.now();
1221
1245
  this.onFeedAdmitted = new import_util4.Callback();
1222
1246
  this._usage = new import_tracing2.TimeUsageCounter();
@@ -1295,7 +1319,10 @@ var ControlPipeline = class {
1295
1319
  C: (f, a) => f(...a)
1296
1320
  });
1297
1321
  setTimeout(async () => {
1298
- void this._consumePipeline(new import_context6.Context());
1322
+ void this._consumePipeline(new import_context6.Context(void 0, {
1323
+ F: __dxlog_file7,
1324
+ L: 130
1325
+ }));
1299
1326
  });
1300
1327
  await this._pipeline.start();
1301
1328
  (0, import_log7.log)("started", void 0, {
@@ -1684,6 +1711,67 @@ var createIdFromSpaceKey = async (spaceKey) => {
1684
1711
  SPACE_IDS_CACHE.set(spaceKey, spaceId);
1685
1712
  return spaceId;
1686
1713
  };
1714
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/admission-discovery-extension.ts";
1715
+ var CredentialRetrieverExtension = class extends import_teleport2.RpcExtension {
1716
+ constructor(_request, _onResult) {
1717
+ super({
1718
+ requested: {
1719
+ AdmissionDiscoveryService: import_protocols6.schema.getService("dxos.mesh.teleport.AdmissionDiscoveryService")
1720
+ }
1721
+ });
1722
+ this._request = _request;
1723
+ this._onResult = _onResult;
1724
+ this._ctx = new import_context7.Context(void 0, {
1725
+ F: __dxlog_file9,
1726
+ L: 25
1727
+ });
1728
+ }
1729
+ async getHandlers() {
1730
+ return {};
1731
+ }
1732
+ async onOpen(context) {
1733
+ await super.onOpen(context);
1734
+ (0, import_async7.scheduleTask)(this._ctx, async () => {
1735
+ try {
1736
+ const result = await this.rpc.AdmissionDiscoveryService.getAdmissionCredential(this._request);
1737
+ this._onResult.wake(result.admissionCredential);
1738
+ } catch (err) {
1739
+ context.close(err);
1740
+ }
1741
+ });
1742
+ }
1743
+ async onClose() {
1744
+ await this._ctx.dispose();
1745
+ }
1746
+ async onAbort() {
1747
+ await this._ctx.dispose();
1748
+ }
1749
+ };
1750
+ var CredentialServerExtension = class extends import_teleport2.RpcExtension {
1751
+ constructor(_space) {
1752
+ super({
1753
+ exposed: {
1754
+ AdmissionDiscoveryService: import_protocols6.schema.getService("dxos.mesh.teleport.AdmissionDiscoveryService")
1755
+ }
1756
+ });
1757
+ this._space = _space;
1758
+ }
1759
+ async getHandlers() {
1760
+ return {
1761
+ AdmissionDiscoveryService: {
1762
+ getAdmissionCredential: async (request) => {
1763
+ const memberInfo = this._space.spaceState.members.get(request.memberKey);
1764
+ if (!memberInfo?.credential) {
1765
+ throw new import_protocols6.ProtocolError("Space member not found.", request);
1766
+ }
1767
+ return {
1768
+ admissionCredential: memberInfo.credential
1769
+ };
1770
+ }
1771
+ }
1772
+ };
1773
+ }
1774
+ };
1687
1775
  function _ts_decorate6(decorators, target, key, desc) {
1688
1776
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1689
1777
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -1694,7 +1782,7 @@ function _ts_decorate6(decorators, target, key, desc) {
1694
1782
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1695
1783
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1696
1784
  }
1697
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-protocol.ts";
1785
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-protocol.ts";
1698
1786
  var MOCK_AUTH_PROVIDER = async (nonce) => Buffer.from("mock");
1699
1787
  var MOCK_AUTH_VERIFIER = async (nonce, credential) => true;
1700
1788
  var SpaceProtocol = class {
@@ -1730,7 +1818,7 @@ var SpaceProtocol = class {
1730
1818
  (0, import_log8.log)("addFeed", {
1731
1819
  key: feed.key
1732
1820
  }, {
1733
- F: __dxlog_file9,
1821
+ F: __dxlog_file10,
1734
1822
  L: 109,
1735
1823
  S: this,
1736
1824
  C: (f, a) => f(...a)
@@ -1748,7 +1836,7 @@ var SpaceProtocol = class {
1748
1836
  const credentials = await this._swarmIdentity.credentialProvider(Buffer.from(""));
1749
1837
  await this.blobSync.open();
1750
1838
  (0, import_log8.log)("starting...", void 0, {
1751
- F: __dxlog_file9,
1839
+ F: __dxlog_file10,
1752
1840
  L: 128,
1753
1841
  S: this,
1754
1842
  C: (f, a) => f(...a)
@@ -1762,7 +1850,7 @@ var SpaceProtocol = class {
1762
1850
  label: `swarm ${topic.truncate()} for space ${this._spaceKey.truncate()}`
1763
1851
  });
1764
1852
  (0, import_log8.log)("started", void 0, {
1765
- F: __dxlog_file9,
1853
+ F: __dxlog_file10,
1766
1854
  L: 138,
1767
1855
  S: this,
1768
1856
  C: (f, a) => f(...a)
@@ -1775,14 +1863,14 @@ var SpaceProtocol = class {
1775
1863
  await this.blobSync.close();
1776
1864
  if (this._connection) {
1777
1865
  (0, import_log8.log)("stopping...", void 0, {
1778
- F: __dxlog_file9,
1866
+ F: __dxlog_file10,
1779
1867
  L: 149,
1780
1868
  S: this,
1781
1869
  C: (f, a) => f(...a)
1782
1870
  });
1783
1871
  await this._connection.close();
1784
1872
  (0, import_log8.log)("stopped", void 0, {
1785
- F: __dxlog_file9,
1873
+ F: __dxlog_file10,
1786
1874
  L: 151,
1787
1875
  S: this,
1788
1876
  C: (f, a) => f(...a)
@@ -1837,7 +1925,7 @@ var SpaceProtocolSession = class {
1837
1925
  this._onSessionAuth = onSessionAuth;
1838
1926
  this._onAuthFailure = onAuthFailure;
1839
1927
  this._blobSync = blobSync;
1840
- this._teleport = new import_teleport2.Teleport(wireParams);
1928
+ this._teleport = new import_teleport3.Teleport(wireParams);
1841
1929
  }
1842
1930
  get authStatus() {
1843
1931
  return this._authStatus;
@@ -1855,7 +1943,7 @@ var SpaceProtocolSession = class {
1855
1943
  verifier: this._swarmIdentity.credentialAuthenticator,
1856
1944
  onAuthSuccess: () => {
1857
1945
  (0, import_log8.log)("Peer authenticated", void 0, {
1858
- F: __dxlog_file9,
1946
+ F: __dxlog_file10,
1859
1947
  L: 248,
1860
1948
  S: this,
1861
1949
  C: (f, a) => f(...a)
@@ -1873,7 +1961,7 @@ var SpaceProtocolSession = class {
1873
1961
  }
1874
1962
  async close() {
1875
1963
  (0, import_log8.log)("close", void 0, {
1876
- F: __dxlog_file9,
1964
+ F: __dxlog_file10,
1877
1965
  L: 264,
1878
1966
  S: this,
1879
1967
  C: (f, a) => f(...a)
@@ -1900,7 +1988,7 @@ function _ts_decorate7(decorators, target, key, desc) {
1900
1988
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1901
1989
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1902
1990
  }
1903
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
1991
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
1904
1992
  var SpaceManager = class {
1905
1993
  constructor({ feedStore, networkManager, metadataStore, snapshotStore, blobStore }) {
1906
1994
  this._spaces = new import_util6.ComplexMap(import_keys7.PublicKey.hash);
@@ -1923,19 +2011,19 @@ var SpaceManager = class {
1923
2011
  ].map((space) => space.close()));
1924
2012
  }
1925
2013
  async constructSpace({ metadata, swarmIdentity, onAuthorizedConnection, onAuthFailure, onDelegatedInvitationStatusChange, onMemberRolesChanged, memberKey }) {
1926
- import_log9.log.trace("dxos.echo.space-manager.construct-space", import_protocols6.trace.begin({
2014
+ import_log9.log.trace("dxos.echo.space-manager.construct-space", import_protocols7.trace.begin({
1927
2015
  id: this._instanceId
1928
2016
  }), {
1929
- F: __dxlog_file10,
1930
- L: 94,
2017
+ F: __dxlog_file11,
2018
+ L: 103,
1931
2019
  S: this,
1932
2020
  C: (f, a) => f(...a)
1933
2021
  });
1934
2022
  (0, import_log9.log)("constructing space...", {
1935
2023
  spaceKey: metadata.genesisFeedKey
1936
2024
  }, {
1937
- F: __dxlog_file10,
1938
- L: 95,
2025
+ F: __dxlog_file11,
2026
+ L: 104,
1939
2027
  S: this,
1940
2028
  C: (f, a) => f(...a)
1941
2029
  });
@@ -1964,30 +2052,93 @@ var SpaceManager = class {
1964
2052
  onMemberRolesChanged
1965
2053
  });
1966
2054
  this._spaces.set(space.key, space);
1967
- import_log9.log.trace("dxos.echo.space-manager.construct-space", import_protocols6.trace.end({
2055
+ import_log9.log.trace("dxos.echo.space-manager.construct-space", import_protocols7.trace.end({
1968
2056
  id: this._instanceId
1969
2057
  }), {
1970
- F: __dxlog_file10,
1971
- L: 126,
2058
+ F: __dxlog_file11,
2059
+ L: 135,
1972
2060
  S: this,
1973
2061
  C: (f, a) => f(...a)
1974
2062
  });
1975
2063
  return space;
1976
2064
  }
2065
+ async requestSpaceAdmissionCredential(params) {
2066
+ const traceKey = "dxos.echo.space-manager.request-space-admission";
2067
+ import_log9.log.trace(traceKey, import_protocols7.trace.begin({
2068
+ id: this._instanceId
2069
+ }), {
2070
+ F: __dxlog_file11,
2071
+ L: 141,
2072
+ S: this,
2073
+ C: (f, a) => f(...a)
2074
+ });
2075
+ (0, import_log9.log)("requesting space admission credential...", {
2076
+ spaceKey: params.spaceKey
2077
+ }, {
2078
+ F: __dxlog_file11,
2079
+ L: 142,
2080
+ S: this,
2081
+ C: (f, a) => f(...a)
2082
+ });
2083
+ const onCredentialResolved = new import_async8.Trigger();
2084
+ const protocol = new SpaceProtocol({
2085
+ topic: params.spaceKey,
2086
+ swarmIdentity: params.swarmIdentity,
2087
+ networkManager: this._networkManager,
2088
+ onSessionAuth: (session) => {
2089
+ session.addExtension("dxos.mesh.teleport.admission-discovery", new CredentialRetrieverExtension({
2090
+ spaceKey: params.spaceKey,
2091
+ memberKey: params.identityKey
2092
+ }, onCredentialResolved));
2093
+ },
2094
+ onAuthFailure: (session) => session.close(),
2095
+ blobStore: this._blobStore
2096
+ });
2097
+ try {
2098
+ await protocol.start();
2099
+ const credential = await onCredentialResolved.wait({
2100
+ timeout: params.timeout
2101
+ });
2102
+ import_log9.log.trace(traceKey, import_protocols7.trace.end({
2103
+ id: this._instanceId
2104
+ }), {
2105
+ F: __dxlog_file11,
2106
+ L: 165,
2107
+ S: this,
2108
+ C: (f, a) => f(...a)
2109
+ });
2110
+ return credential;
2111
+ } catch (err) {
2112
+ import_log9.log.trace(traceKey, import_protocols7.trace.error({
2113
+ id: this._instanceId,
2114
+ error: err
2115
+ }), {
2116
+ F: __dxlog_file11,
2117
+ L: 168,
2118
+ S: this,
2119
+ C: (f, a) => f(...a)
2120
+ });
2121
+ throw err;
2122
+ } finally {
2123
+ await protocol.stop();
2124
+ }
2125
+ }
1977
2126
  };
1978
2127
  _ts_decorate7([
1979
- import_async7.synchronized
2128
+ import_async8.synchronized
1980
2129
  ], SpaceManager.prototype, "open", null);
1981
2130
  _ts_decorate7([
1982
- import_async7.synchronized
2131
+ import_async8.synchronized
1983
2132
  ], SpaceManager.prototype, "close", null);
1984
2133
  SpaceManager = _ts_decorate7([
1985
- (0, import_async7.trackLeaks)("open", "close")
2134
+ (0, import_async8.trackLeaks)("open", "close")
1986
2135
  ], SpaceManager);
1987
2136
  // Annotate the CommonJS export names for ESM import in node:
1988
2137
  0 && (module.exports = {
1989
2138
  AuthExtension,
1990
2139
  AuthStatus,
2140
+ CredentialRetrieverExtension,
2141
+ CredentialServerExtension,
1991
2142
  DataServiceImpl,
1992
2143
  MOCK_AUTH_PROVIDER,
1993
2144
  MOCK_AUTH_VERIFIER,
@@ -2009,4 +2160,4 @@ SpaceManager = _ts_decorate7([
2009
2160
  startAfter,
2010
2161
  valueEncoding
2011
2162
  });
2012
- //# sourceMappingURL=chunk-QPCNQ4ZK.cjs.map
2163
+ //# sourceMappingURL=chunk-Y5U7UXEL.cjs.map