@waku/core 0.0.31-1887f4f.0 → 0.0.31-77b2cdd.0

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 (47) hide show
  1. package/bundle/{base_protocol-WTp5jKZK.js → base_protocol-Dge5_tvU.js} +3 -7
  2. package/bundle/{index-COT0phC8.js → index-Gts2Ddu_.js} +38 -52
  3. package/bundle/index.js +214 -193
  4. package/bundle/lib/base_protocol.js +2 -2
  5. package/bundle/lib/message/version_0.js +2 -2
  6. package/bundle/{version_0-SMRUXDNR.js → version_0-CNRKFufI.js} +154 -308
  7. package/dist/.tsbuildinfo +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/lib/base_protocol.d.ts +2 -3
  12. package/dist/lib/base_protocol.js +3 -7
  13. package/dist/lib/base_protocol.js.map +1 -1
  14. package/dist/lib/connection_manager.d.ts +1 -1
  15. package/dist/lib/connection_manager.js.map +1 -1
  16. package/dist/lib/filter/index.d.ts +3 -2
  17. package/dist/lib/filter/index.js +4 -2
  18. package/dist/lib/filter/index.js.map +1 -1
  19. package/dist/lib/health_manager.d.ts +14 -0
  20. package/dist/lib/health_manager.js +70 -0
  21. package/dist/lib/health_manager.js.map +1 -0
  22. package/dist/lib/light_push/index.d.ts +3 -2
  23. package/dist/lib/light_push/index.js +4 -2
  24. package/dist/lib/light_push/index.js.map +1 -1
  25. package/dist/lib/metadata/index.d.ts +2 -2
  26. package/dist/lib/metadata/index.js +9 -9
  27. package/dist/lib/metadata/index.js.map +1 -1
  28. package/dist/lib/store/index.d.ts +5 -44
  29. package/dist/lib/store/index.js +39 -45
  30. package/dist/lib/store/index.js.map +1 -1
  31. package/dist/lib/store/rpc.d.ts +22 -0
  32. package/dist/lib/store/rpc.js +74 -0
  33. package/dist/lib/store/rpc.js.map +1 -0
  34. package/package.json +1 -1
  35. package/src/index.ts +2 -2
  36. package/src/lib/base_protocol.ts +3 -7
  37. package/src/lib/connection_manager.ts +1 -1
  38. package/src/lib/filter/index.ts +3 -10
  39. package/src/lib/health_manager.ts +90 -0
  40. package/src/lib/light_push/index.ts +6 -9
  41. package/src/lib/metadata/index.ts +11 -12
  42. package/src/lib/store/index.ts +53 -93
  43. package/src/lib/store/rpc.ts +92 -0
  44. package/dist/lib/store/history_rpc.d.ts +0 -27
  45. package/dist/lib/store/history_rpc.js +0 -72
  46. package/dist/lib/store/history_rpc.js.map +0 -1
  47. package/src/lib/store/history_rpc.ts +0 -93
@@ -1,4 +1,4 @@
1
- import { h as bytesToUtf8, T as Tags, L as Logger, i as ensureShardingConfigured } from './index-COT0phC8.js';
1
+ import { h as bytesToUtf8, T as Tags, L as Logger, e as pubsubTopicsToShardInfo } from './index-Gts2Ddu_.js';
2
2
 
3
3
  const decodeRelayShard = (bytes) => {
4
4
  // explicitly converting to Uint8Array to avoid Buffer
@@ -272,16 +272,14 @@ class BaseProtocol {
272
272
  components;
273
273
  log;
274
274
  pubsubTopics;
275
- options;
276
275
  addLibp2pEventListener;
277
276
  removeLibp2pEventListener;
278
277
  streamManager;
279
- constructor(multicodec, components, log, pubsubTopics, options) {
278
+ constructor(multicodec, components, log, pubsubTopics) {
280
279
  this.multicodec = multicodec;
281
280
  this.components = components;
282
281
  this.log = log;
283
282
  this.pubsubTopics = pubsubTopics;
284
- this.options = options;
285
283
  this.addLibp2pEventListener = components.events.addEventListener.bind(components.events);
286
284
  this.removeLibp2pEventListener = components.events.removeEventListener.bind(components.events);
287
285
  this.streamManager = new StreamManager(multicodec, components.connectionManager.getConnections.bind(components.connectionManager), this.addLibp2pEventListener);
@@ -319,9 +317,7 @@ class BaseProtocol {
319
317
  numPeers: 0
320
318
  }) {
321
319
  // Retrieve all connected peers that support the protocol & shard (if configured)
322
- const connectedPeersForProtocolAndShard = await getConnectedPeersForProtocolAndShard(this.components.connectionManager.getConnections(), this.peerStore, [this.multicodec], this.options?.shardInfo
323
- ? ensureShardingConfigured(this.options.shardInfo).shardInfo
324
- : undefined);
320
+ const connectedPeersForProtocolAndShard = await getConnectedPeersForProtocolAndShard(this.components.connectionManager.getConnections(), this.peerStore, [this.multicodec], pubsubTopicsToShardInfo(this.pubsubTopics));
325
321
  // Filter the peers based on discovery & number of peers requested
326
322
  const filteredPeers = filterPeersByDiscovery(connectedPeersForProtocolAndShard, numPeers, maxBootstrapPeers);
327
323
  // Sort the peers by latency
@@ -1037,6 +1037,11 @@ var ProtocolError;
1037
1037
  * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
1038
1038
  */
1039
1039
  ProtocolError["TOPIC_DECODER_MISMATCH"] = "Topic decoder mismatch";
1040
+ /**
1041
+ * The topics passed in the decoders do not match each other, or don't exist at all.
1042
+ * Ensure that all the pubsub topics used in the decoders are valid and match each other.
1043
+ */
1044
+ ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
1040
1045
  /**
1041
1046
  * Failure to find a peer with suitable protocols. This may due to a connection issue.
1042
1047
  * Mitigation can be: retrying after a given time period, display connectivity issue
@@ -1067,12 +1072,6 @@ var ProtocolError;
1067
1072
  ProtocolError["REQUEST_TIMEOUT"] = "Request timeout";
1068
1073
  })(ProtocolError || (ProtocolError = {}));
1069
1074
 
1070
- var PageDirection;
1071
- (function (PageDirection) {
1072
- PageDirection["BACKWARD"] = "backward";
1073
- PageDirection["FORWARD"] = "forward";
1074
- })(PageDirection || (PageDirection = {}));
1075
-
1076
1075
  var Tags;
1077
1076
  (function (Tags) {
1078
1077
  Tags["BOOTSTRAP"] = "bootstrap";
@@ -1096,6 +1095,13 @@ var EConnectionStateEvents;
1096
1095
  */
1097
1096
  const DEFAULT_CLUSTER_ID = 1;
1098
1097
 
1098
+ var HealthStatus;
1099
+ (function (HealthStatus) {
1100
+ HealthStatus["Unhealthy"] = "Unhealthy";
1101
+ HealthStatus["MinimallyHealthy"] = "MinimallyHealthy";
1102
+ HealthStatus["SufficientlyHealthy"] = "SufficientlyHealthy";
1103
+ })(HealthStatus || (HealthStatus = {}));
1104
+
1099
1105
  /**
1100
1106
  * Turns a `Uint8Array` into a string.
1101
1107
  *
@@ -1124,7 +1130,7 @@ const utf8ToBytes = (s) => fromString(s, "utf8");
1124
1130
  * Concatenate using Uint8Arrays as `Buffer` has a different behavior with `DataView`
1125
1131
  */
1126
1132
  function concat(byteArrays, totalLength) {
1127
- const len = totalLength ?? byteArrays.reduce((acc, curr) => acc + curr.length, 0);
1133
+ const len = byteArrays.reduce((acc, curr) => acc + curr.length, 0);
1128
1134
  const res = new Uint8Array(len);
1129
1135
  let offset = 0;
1130
1136
  for (const bytes of byteArrays) {
@@ -1176,6 +1182,27 @@ const pubsubTopicToSingleShardInfo = (pubsubTopics) => {
1176
1182
  shard
1177
1183
  };
1178
1184
  };
1185
+ const pubsubTopicsToShardInfo = (pubsubTopics) => {
1186
+ const shardInfoSet = new Set();
1187
+ const clusterIds = new Set();
1188
+ for (const topic of pubsubTopics) {
1189
+ const { clusterId, shard } = pubsubTopicToSingleShardInfo(topic);
1190
+ shardInfoSet.add(`${clusterId}:${shard}`);
1191
+ clusterIds.add(clusterId);
1192
+ }
1193
+ if (shardInfoSet.size === 0) {
1194
+ throw new Error("No valid pubsub topics provided");
1195
+ }
1196
+ if (clusterIds.size > 1) {
1197
+ throw new Error("Pubsub topics from multiple cluster IDs are not supported");
1198
+ }
1199
+ const clusterId = clusterIds.values().next().value;
1200
+ const shards = Array.from(shardInfoSet).map((info) => parseInt(info.split(":")[1]));
1201
+ return {
1202
+ clusterId,
1203
+ shards
1204
+ };
1205
+ };
1179
1206
  /**
1180
1207
  * Given a string, will throw an error if it is not formatted as a valid content topic for autosharding based on https://rfc.vac.dev/spec/51/
1181
1208
  * @param contentTopic String to validate
@@ -1253,49 +1280,6 @@ pubsubTopicShardInfo) {
1253
1280
  ? singleShardInfoToPubsubTopic(pubsubTopicShardInfo)
1254
1281
  : contentTopicToPubsubTopic(contentTopic, pubsubTopicShardInfo?.clusterId ?? DEFAULT_CLUSTER_ID);
1255
1282
  }
1256
- /**
1257
- * Validates sharding configuration and sets defaults where possible.
1258
- * @returns Validated sharding parameters, with any missing values set to defaults
1259
- */
1260
- const ensureShardingConfigured = (shardInfo) => {
1261
- const clusterId = shardInfo.clusterId ?? DEFAULT_CLUSTER_ID;
1262
- const shards = "shards" in shardInfo ? shardInfo.shards : [];
1263
- const contentTopics = "contentTopics" in shardInfo ? shardInfo.contentTopics : [];
1264
- const [application, version] = "application" in shardInfo && "version" in shardInfo
1265
- ? [shardInfo.application, shardInfo.version]
1266
- : [undefined, undefined];
1267
- const isShardsConfigured = shards && shards.length > 0;
1268
- const isContentTopicsConfigured = contentTopics && contentTopics.length > 0;
1269
- const isApplicationVersionConfigured = application && version;
1270
- if (isShardsConfigured) {
1271
- return {
1272
- shardingParams: { clusterId, shards },
1273
- shardInfo: { clusterId, shards },
1274
- pubsubTopics: shardInfoToPubsubTopics({ clusterId, shards })
1275
- };
1276
- }
1277
- if (isContentTopicsConfigured) {
1278
- const pubsubTopics = Array.from(new Set(contentTopics.map((topic) => contentTopicToPubsubTopic(topic, clusterId))));
1279
- const shards = Array.from(new Set(contentTopics.map((topic) => contentTopicToShardIndex(topic))));
1280
- return {
1281
- shardingParams: { clusterId, contentTopics },
1282
- shardInfo: { clusterId, shards },
1283
- pubsubTopics
1284
- };
1285
- }
1286
- if (isApplicationVersionConfigured) {
1287
- const pubsubTopic = contentTopicToPubsubTopic(`/${application}/${version}/default/default`, clusterId);
1288
- return {
1289
- shardingParams: { clusterId, application, version },
1290
- shardInfo: {
1291
- clusterId,
1292
- shards: [pubsubTopicToSingleShardInfo(pubsubTopic).shard]
1293
- },
1294
- pubsubTopics: [pubsubTopic]
1295
- };
1296
- }
1297
- throw new Error("Missing minimum required configuration options for static sharding or autosharding.");
1298
- };
1299
1283
 
1300
1284
  function getDefaultExportFromCjs (x) {
1301
1285
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -1876,6 +1860,8 @@ var common = setup;
1876
1860
  return false;
1877
1861
  }
1878
1862
 
1863
+ let m;
1864
+
1879
1865
  // Is webkit? http://stackoverflow.com/a/16459606/376773
1880
1866
  // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
1881
1867
  return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
@@ -1883,7 +1869,7 @@ var common = setup;
1883
1869
  (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
1884
1870
  // Is firefox >= v31?
1885
1871
  // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
1886
- (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
1872
+ (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
1887
1873
  // Double check webkit in userAgent just in case we are in a worker
1888
1874
  (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
1889
1875
  }
@@ -2051,4 +2037,4 @@ class Logger {
2051
2037
  }
2052
2038
  }
2053
2039
 
2054
- export { EConnectionStateEvents as E, Logger as L, ProtocolError as P, Tags as T, allocUnsafe as a, alloc as b, Protocols as c, EPeersByDiscoveryEvents as d, determinePubsubTopic as e, fromString as f, getDefaultExportFromCjs as g, bytesToUtf8 as h, ensureShardingConfigured as i, pubsubTopicToSingleShardInfo as p, shardInfoToPubsubTopics as s, utf8ToBytes as u };
2040
+ export { EConnectionStateEvents as E, HealthStatus as H, Logger as L, ProtocolError as P, Tags as T, allocUnsafe as a, alloc as b, Protocols as c, EPeersByDiscoveryEvents as d, pubsubTopicsToShardInfo as e, fromString as f, determinePubsubTopic as g, bytesToUtf8 as h, pubsubTopicToSingleShardInfo as p, shardInfoToPubsubTopics as s, utf8ToBytes as u };