@dxos/echo-pipeline 0.1.46-next.c3cc04c → 0.1.47

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 (35) hide show
  1. package/dist/lib/browser/{chunk-QCDWBDL4.mjs → chunk-JEULF2QN.mjs} +58 -52
  2. package/dist/lib/browser/chunk-JEULF2QN.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -3
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +2 -3
  7. package/dist/lib/browser/testing/index.mjs.map +2 -2
  8. package/dist/lib/node/index.cjs +58 -53
  9. package/dist/lib/node/index.cjs.map +3 -3
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/testing/index.cjs +59 -53
  12. package/dist/lib/node/testing/index.cjs.map +3 -3
  13. package/dist/types/src/dbhost/data-service-host.d.ts.map +1 -1
  14. package/dist/types/src/metadata/metadata-store.d.ts +0 -6
  15. package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
  16. package/dist/types/src/space/space-manager.d.ts +2 -1
  17. package/dist/types/src/space/space-manager.d.ts.map +1 -1
  18. package/dist/types/src/space/space-protocol.d.ts +6 -2
  19. package/dist/types/src/space/space-protocol.d.ts.map +1 -1
  20. package/dist/types/src/testing/database-test-rig.d.ts +2 -1
  21. package/dist/types/src/testing/database-test-rig.d.ts.map +1 -1
  22. package/dist/types/src/testing/test-agent-builder.d.ts +1 -1
  23. package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
  24. package/package.json +30 -30
  25. package/src/dbhost/data-service-host.ts +19 -14
  26. package/src/metadata/metadata-store.ts +2 -8
  27. package/src/space/auth.ts +1 -1
  28. package/src/space/space-manager.ts +9 -1
  29. package/src/space/space-protocol.ts +12 -4
  30. package/src/space/space.test.ts +1 -1
  31. package/src/space/space.ts +1 -1
  32. package/src/testing/database-test-rig.ts +30 -7
  33. package/src/testing/test-agent-builder.ts +1 -1
  34. package/src/tests/database-unit.test.ts +58 -17
  35. package/dist/lib/browser/chunk-QCDWBDL4.mjs.map +0 -7
@@ -46,7 +46,6 @@ __export(src_exports, {
46
46
  MOCK_AUTH_VERIFIER: () => MOCK_AUTH_VERIFIER,
47
47
  MetadataStore: () => MetadataStore,
48
48
  Pipeline: () => Pipeline,
49
- STORAGE_VERSION: () => STORAGE_VERSION,
50
49
  SnapshotManager: () => SnapshotManager,
51
50
  SnapshotStore: () => SnapshotStore,
52
51
  Space: () => Space,
@@ -131,9 +130,8 @@ var __decorate = function(decorators, target, key, desc) {
131
130
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
132
131
  return c > 3 && r && Object.defineProperty(target, key, r), r;
133
132
  };
134
- var STORAGE_VERSION = 1;
135
133
  var emptyEchoMetadata = () => ({
136
- version: STORAGE_VERSION,
134
+ version: import_protocols.STORAGE_VERSION,
137
135
  spaces: [],
138
136
  created: new Date(),
139
137
  updated: new Date()
@@ -173,7 +171,7 @@ var MetadataStore = class {
173
171
  checksum
174
172
  }, {
175
173
  file: "metadata-store.ts",
176
- line: 70,
174
+ line: 63,
177
175
  scope: this,
178
176
  callSite: (f, a) => f(...a)
179
177
  });
@@ -191,7 +189,7 @@ var MetadataStore = class {
191
189
  err
192
190
  }, {
193
191
  file: "metadata-store.ts",
194
- line: 85,
192
+ line: 78,
195
193
  scope: this,
196
194
  callSite: (f, a) => f(...a)
197
195
  });
@@ -204,7 +202,7 @@ var MetadataStore = class {
204
202
  var _a;
205
203
  const data = {
206
204
  ...this._metadata,
207
- version: STORAGE_VERSION,
205
+ version: import_protocols.STORAGE_VERSION,
208
206
  created: (_a = this._metadata.created) != null ? _a : new Date(),
209
207
  updated: new Date()
210
208
  };
@@ -222,7 +220,7 @@ var MetadataStore = class {
222
220
  checksum
223
221
  }, {
224
222
  file: "metadata-store.ts",
225
- line: 116,
223
+ line: 109,
226
224
  scope: this,
227
225
  callSite: (f, a) => f(...a)
228
226
  });
@@ -241,11 +239,12 @@ var MetadataStore = class {
241
239
  async clear() {
242
240
  (0, import_log.log)("clearing all metadata", {}, {
243
241
  file: "metadata-store.ts",
244
- line: 132,
242
+ line: 125,
245
243
  scope: this,
246
244
  callSite: (f, a) => f(...a)
247
245
  });
248
246
  await this._directory.delete();
247
+ this._metadata = emptyEchoMetadata();
249
248
  }
250
249
  getIdentityRecord() {
251
250
  return this._metadata.identity;
@@ -772,7 +771,7 @@ var AuthExtension = class extends import_teleport.RpcExtension {
772
771
  (0, import_node_assert5.default)(success, "credential not verified");
773
772
  (0, import_async4.runInContext)(this._ctx, () => this._authParams.onAuthSuccess());
774
773
  } catch (err) {
775
- import_log4.log.warn("auth failed", err, {
774
+ (0, import_log4.log)("auth failed", err, {
776
775
  file: "auth.ts",
777
776
  line: 75,
778
777
  scope: this,
@@ -947,12 +946,13 @@ var DataServiceHost = class {
947
946
  this._itemDemuxer.mutation.on(ctx, (message) => {
948
947
  var _a;
949
948
  const { batch, meta } = message;
949
+ (0, import_node_assert6.default)(!meta.clientTag, "Unexpected client tag in mutation message");
950
950
  (0, import_log6.log)("message", {
951
951
  batch,
952
952
  meta
953
953
  }, {
954
954
  file: "data-service-host.ts",
955
- line: 49,
955
+ line: 51,
956
956
  scope: this,
957
957
  callSite: (f, a) => f(...a)
958
958
  });
@@ -961,10 +961,12 @@ var DataServiceHost = class {
961
961
  message.meta.seq
962
962
  ]);
963
963
  (_a = batch.objects) == null ? void 0 : _a.forEach((object) => {
964
- (0, import_echo_db.setMetadataOnObject)(object, meta);
964
+ (0, import_echo_db.setMetadataOnObject)(object, {
965
+ ...meta
966
+ });
965
967
  });
966
968
  if (clientTag) {
967
- (0, import_echo_db.tagMutationsInBatch)(batch, clientTag);
969
+ (0, import_echo_db.tagMutationsInBatch)(batch, clientTag, 0);
968
970
  }
969
971
  next({
970
972
  clientTag,
@@ -976,32 +978,18 @@ var DataServiceHost = class {
976
978
  });
977
979
  }
978
980
  async write(request) {
979
- var _a, _b, _c;
981
+ var _a, _b;
980
982
  (0, import_node_assert6.default)(this._writeStream, "Cannot write mutations in readonly mode");
981
983
  (0, import_log6.log)("write", {
982
984
  clientTag: request.clientTag,
983
985
  objectCount: (_b = (_a = request.batch.objects) == null ? void 0 : _a.length) != null ? _b : 0
984
986
  }, {
985
987
  file: "data-service-host.ts",
986
- line: 77,
988
+ line: 79,
987
989
  scope: this,
988
990
  callSite: (f, a) => f(...a)
989
991
  });
990
- const message = {
991
- batch: {
992
- objects: (_c = request.batch.objects) == null ? void 0 : _c.map((object) => {
993
- var _a2;
994
- return {
995
- ...object,
996
- mutations: (_a2 = object.mutations) == null ? void 0 : _a2.map((mutation) => ({
997
- ...mutation,
998
- meta: void 0
999
- })),
1000
- meta: void 0
1001
- };
1002
- })
1003
- }
1004
- };
992
+ const message = createDataMessage(request.batch);
1005
993
  const receipt = await this._writeStream.write(message, {
1006
994
  afterWrite: async (receipt2) => {
1007
995
  if (request.clientTag) {
@@ -1011,7 +999,7 @@ var DataServiceHost = class {
1011
999
  seq: receipt2.seq
1012
1000
  }, {
1013
1001
  file: "data-service-host.ts",
1014
- line: 96,
1002
+ line: 88,
1015
1003
  scope: this,
1016
1004
  callSite: (f, a) => f(...a)
1017
1005
  });
@@ -1025,6 +1013,24 @@ var DataServiceHost = class {
1025
1013
  return receipt;
1026
1014
  }
1027
1015
  };
1016
+ var createDataMessage = (batch) => {
1017
+ var _a;
1018
+ return {
1019
+ batch: {
1020
+ objects: (_a = batch.objects) == null ? void 0 : _a.map((object) => {
1021
+ var _a2;
1022
+ return {
1023
+ ...object,
1024
+ mutations: (_a2 = object.mutations) == null ? void 0 : _a2.map((mutation) => ({
1025
+ ...mutation,
1026
+ meta: void 0
1027
+ })),
1028
+ meta: void 0
1029
+ };
1030
+ })
1031
+ }
1032
+ };
1033
+ };
1028
1034
 
1029
1035
  // packages/core/echo/echo-pipeline/src/dbhost/database-host.ts
1030
1036
  var import_echo_db2 = require("@dxos/echo-db");
@@ -1703,7 +1709,7 @@ var Space = class Space2 {
1703
1709
  });
1704
1710
  }
1705
1711
  async initializeDataPipeline() {
1706
- import_log10.log.info("initializeDataPipeline", {}, {
1712
+ (0, import_log10.log)("initializeDataPipeline", {}, {
1707
1713
  file: "space.ts",
1708
1714
  line: 245,
1709
1715
  scope: this,
@@ -1756,12 +1762,13 @@ var __decorate7 = function(decorators, target, key, desc) {
1756
1762
  var MOCK_AUTH_PROVIDER = async (nonce) => Buffer.from("mock");
1757
1763
  var MOCK_AUTH_VERIFIER = async (nonce, credential) => true;
1758
1764
  var SpaceProtocol = class {
1759
- constructor({ topic, swarmIdentity, networkManager, onSessionAuth }) {
1765
+ constructor({ topic, swarmIdentity, networkManager, onSessionAuth, onAuthFailure }) {
1760
1766
  this._feeds = /* @__PURE__ */ new Set();
1761
1767
  this._sessions = new import_util6.ComplexMap(import_keys4.PublicKey.hash);
1762
1768
  this._networkManager = networkManager;
1763
1769
  this._swarmIdentity = swarmIdentity;
1764
1770
  this._onSessionAuth = onSessionAuth;
1771
+ this._onAuthFailure = onAuthFailure;
1765
1772
  this._topic = import_keys4.PublicKey.from((0, import_crypto3.discoveryKey)((0, import_crypto3.sha256)(topic.toHex())));
1766
1773
  }
1767
1774
  get sessions() {
@@ -1779,7 +1786,7 @@ var SpaceProtocol = class {
1779
1786
  key: feed.key
1780
1787
  }, {
1781
1788
  file: "space-protocol.ts",
1782
- line: 84,
1789
+ line: 87,
1783
1790
  scope: this,
1784
1791
  callSite: (f, a) => f(...a)
1785
1792
  });
@@ -1800,7 +1807,7 @@ var SpaceProtocol = class {
1800
1807
  };
1801
1808
  (0, import_log11.log)("starting...", {}, {
1802
1809
  file: "space-protocol.ts",
1803
- line: 107,
1810
+ line: 110,
1804
1811
  scope: this,
1805
1812
  callSite: (f, a) => f(...a)
1806
1813
  });
@@ -1813,7 +1820,7 @@ var SpaceProtocol = class {
1813
1820
  });
1814
1821
  (0, import_log11.log)("started", {}, {
1815
1822
  file: "space-protocol.ts",
1816
- line: 116,
1823
+ line: 119,
1817
1824
  scope: this,
1818
1825
  callSite: (f, a) => f(...a)
1819
1826
  });
@@ -1822,14 +1829,14 @@ var SpaceProtocol = class {
1822
1829
  if (this._connection) {
1823
1830
  (0, import_log11.log)("stopping...", {}, {
1824
1831
  file: "space-protocol.ts",
1825
- line: 121,
1832
+ line: 124,
1826
1833
  scope: this,
1827
1834
  callSite: (f, a) => f(...a)
1828
1835
  });
1829
1836
  await this._connection.close();
1830
1837
  (0, import_log11.log)("stopped", {}, {
1831
1838
  file: "space-protocol.ts",
1832
- line: 123,
1839
+ line: 126,
1833
1840
  scope: this,
1834
1841
  callSite: (f, a) => f(...a)
1835
1842
  });
@@ -1840,7 +1847,8 @@ var SpaceProtocol = class {
1840
1847
  const session = new SpaceProtocolSession({
1841
1848
  wireParams,
1842
1849
  swarmIdentity: this._swarmIdentity,
1843
- onSessionAuth: this._onSessionAuth
1850
+ onSessionAuth: this._onSessionAuth,
1851
+ onAuthFailure: this._onAuthFailure
1844
1852
  });
1845
1853
  this._sessions.set(wireParams.remotePeerId, session);
1846
1854
  for (const feed of this._feeds) {
@@ -1864,7 +1872,7 @@ var AuthStatus;
1864
1872
  })(AuthStatus || (AuthStatus = {}));
1865
1873
  var SpaceProtocolSession = class {
1866
1874
  // TODO(dmaretskyi): Allow to pass in extra extensions.
1867
- constructor({ wireParams, swarmIdentity, onSessionAuth }) {
1875
+ constructor({ wireParams, swarmIdentity, onSessionAuth, onAuthFailure }) {
1868
1876
  // TODO(dmaretskyi): Start with upload=false when switching it on the fly works.
1869
1877
  this.replicator = new import_teleport_extension_replicator.ReplicatorExtension().setOptions({
1870
1878
  upload: true
@@ -1873,6 +1881,7 @@ var SpaceProtocolSession = class {
1873
1881
  this._wireParams = wireParams;
1874
1882
  this._swarmIdentity = swarmIdentity;
1875
1883
  this._onSessionAuth = onSessionAuth;
1884
+ this._onAuthFailure = onAuthFailure;
1876
1885
  this._teleport = new import_teleport2.Teleport(wireParams);
1877
1886
  }
1878
1887
  get authStatus() {
@@ -1888,23 +1897,19 @@ var SpaceProtocolSession = class {
1888
1897
  verifier: this._swarmIdentity.credentialAuthenticator,
1889
1898
  onAuthSuccess: () => {
1890
1899
  var _a;
1891
- this._authStatus = AuthStatus.SUCCESS;
1892
1900
  (0, import_log11.log)("Peer authenticated", {}, {
1893
1901
  file: "space-protocol.ts",
1894
- line: 206,
1902
+ line: 213,
1895
1903
  scope: this,
1896
1904
  callSite: (f, a) => f(...a)
1897
1905
  });
1906
+ this._authStatus = AuthStatus.SUCCESS;
1898
1907
  (_a = this._onSessionAuth) == null ? void 0 : _a.call(this, this._teleport);
1899
1908
  },
1900
1909
  onAuthFailure: () => {
1901
- import_log11.log.warn("Auth failed", {}, {
1902
- file: "space-protocol.ts",
1903
- line: 211,
1904
- scope: this,
1905
- callSite: (f, a) => f(...a)
1906
- });
1910
+ var _a;
1907
1911
  this._authStatus = AuthStatus.FAILURE;
1912
+ (_a = this._onAuthFailure) == null ? void 0 : _a.call(this, this._teleport);
1908
1913
  }
1909
1914
  }));
1910
1915
  this._teleport.addExtension("dxos.mesh.teleport.replicator", this.replicator);
@@ -1952,13 +1957,13 @@ var SpaceManager = class SpaceManager2 {
1952
1957
  ...this._spaces.values()
1953
1958
  ].map((space) => space.close()));
1954
1959
  }
1955
- async constructSpace({ metadata, swarmIdentity, onNetworkConnection, memberKey }) {
1960
+ async constructSpace({ metadata, swarmIdentity, onNetworkConnection, onAuthFailure, memberKey }) {
1956
1961
  var _a;
1957
1962
  import_log12.log.trace("dxos.echo.space-manager.construct-space", import_protocols6.trace.begin({
1958
1963
  id: this._instanceId
1959
1964
  }), {
1960
1965
  file: "space-manager.ts",
1961
- line: 74,
1966
+ line: 81,
1962
1967
  scope: this,
1963
1968
  callSite: (f, a) => f(...a)
1964
1969
  });
@@ -1966,7 +1971,7 @@ var SpaceManager = class SpaceManager2 {
1966
1971
  spaceKey: metadata.genesisFeedKey
1967
1972
  }, {
1968
1973
  file: "space-manager.ts",
1969
- line: 75,
1974
+ line: 82,
1970
1975
  scope: this,
1971
1976
  callSite: (f, a) => f(...a)
1972
1977
  });
@@ -1976,7 +1981,8 @@ var SpaceManager = class SpaceManager2 {
1976
1981
  topic: spaceKey,
1977
1982
  swarmIdentity,
1978
1983
  networkManager: this._networkManager,
1979
- onSessionAuth: onNetworkConnection
1984
+ onSessionAuth: onNetworkConnection,
1985
+ onAuthFailure
1980
1986
  });
1981
1987
  const snapshotManager = new SnapshotManager(this._snapshotStore);
1982
1988
  const space = new Space({
@@ -1994,7 +2000,7 @@ var SpaceManager = class SpaceManager2 {
1994
2000
  id: this._instanceId
1995
2001
  }), {
1996
2002
  file: "space-manager.ts",
1997
- line: 100,
2003
+ line: 108,
1998
2004
  scope: this,
1999
2005
  callSite: (f, a) => f(...a)
2000
2006
  });
@@ -2028,7 +2034,6 @@ SpaceManager = __decorate8([
2028
2034
  MOCK_AUTH_VERIFIER,
2029
2035
  MetadataStore,
2030
2036
  Pipeline,
2031
- STORAGE_VERSION,
2032
2037
  SnapshotManager,
2033
2038
  SnapshotStore,
2034
2039
  Space,