@waku/discovery 0.0.4-08fc2d1.0 → 0.0.4-88a29c3.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.
package/bundle/index.js CHANGED
@@ -537,6 +537,11 @@ var ProtocolError;
537
537
  * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
538
538
  */
539
539
  ProtocolError["TOPIC_DECODER_MISMATCH"] = "Topic decoder mismatch";
540
+ /**
541
+ * The topics passed in the decoders do not match each other, or don't exist at all.
542
+ * Ensure that all the pubsub topics used in the decoders are valid and match each other.
543
+ */
544
+ ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
540
545
  /**
541
546
  * Failure to find a peer with suitable protocols. This may due to a connection issue.
542
547
  * Mitigation can be: retrying after a given time period, display connectivity issue
@@ -567,12 +572,6 @@ var ProtocolError;
567
572
  ProtocolError["REQUEST_TIMEOUT"] = "Request timeout";
568
573
  })(ProtocolError || (ProtocolError = {}));
569
574
 
570
- var PageDirection;
571
- (function (PageDirection) {
572
- PageDirection["BACKWARD"] = "backward";
573
- PageDirection["FORWARD"] = "forward";
574
- })(PageDirection || (PageDirection = {}));
575
-
576
575
  var Tags;
577
576
  (function (Tags) {
578
577
  Tags["BOOTSTRAP"] = "bootstrap";
@@ -596,6 +595,13 @@ var EConnectionStateEvents;
596
595
  */
597
596
  const DEFAULT_CLUSTER_ID = 1;
598
597
 
598
+ var HealthStatus;
599
+ (function (HealthStatus) {
600
+ HealthStatus["Unhealthy"] = "Unhealthy";
601
+ HealthStatus["MinimallyHealthy"] = "MinimallyHealthy";
602
+ HealthStatus["SufficientlyHealthy"] = "SufficientlyHealthy";
603
+ })(HealthStatus || (HealthStatus = {}));
604
+
599
605
  function equals$2(aa, bb) {
600
606
  if (aa === bb)
601
607
  return true;
@@ -23839,113 +23845,26 @@ var WakuMessage$1;
23839
23845
  /* eslint-disable @typescript-eslint/no-namespace */
23840
23846
  /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
23841
23847
  /* eslint-disable @typescript-eslint/no-empty-interface */
23842
- var Index;
23843
- (function (Index) {
23848
+ var WakuMessageKeyValue;
23849
+ (function (WakuMessageKeyValue) {
23844
23850
  let _codec;
23845
- Index.codec = () => {
23851
+ WakuMessageKeyValue.codec = () => {
23846
23852
  if (_codec == null) {
23847
23853
  _codec = message((obj, w, opts = {}) => {
23848
23854
  if (opts.lengthDelimited !== false) {
23849
23855
  w.fork();
23850
23856
  }
23851
- if ((obj.digest != null && obj.digest.byteLength > 0)) {
23857
+ if (obj.messageHash != null) {
23852
23858
  w.uint32(10);
23853
- w.bytes(obj.digest);
23854
- }
23855
- if ((obj.receiverTime != null && obj.receiverTime !== 0n)) {
23856
- w.uint32(16);
23857
- w.sint64(obj.receiverTime);
23858
- }
23859
- if ((obj.senderTime != null && obj.senderTime !== 0n)) {
23860
- w.uint32(24);
23861
- w.sint64(obj.senderTime);
23862
- }
23863
- if ((obj.pubsubTopic != null && obj.pubsubTopic !== '')) {
23864
- w.uint32(34);
23865
- w.string(obj.pubsubTopic);
23866
- }
23867
- if (opts.lengthDelimited !== false) {
23868
- w.ldelim();
23869
- }
23870
- }, (reader, length, opts = {}) => {
23871
- const obj = {
23872
- digest: alloc$2(0),
23873
- receiverTime: 0n,
23874
- senderTime: 0n,
23875
- pubsubTopic: ''
23876
- };
23877
- const end = length == null ? reader.len : reader.pos + length;
23878
- while (reader.pos < end) {
23879
- const tag = reader.uint32();
23880
- switch (tag >>> 3) {
23881
- case 1: {
23882
- obj.digest = reader.bytes();
23883
- break;
23884
- }
23885
- case 2: {
23886
- obj.receiverTime = reader.sint64();
23887
- break;
23888
- }
23889
- case 3: {
23890
- obj.senderTime = reader.sint64();
23891
- break;
23892
- }
23893
- case 4: {
23894
- obj.pubsubTopic = reader.string();
23895
- break;
23896
- }
23897
- default: {
23898
- reader.skipType(tag & 7);
23899
- break;
23900
- }
23901
- }
23902
- }
23903
- return obj;
23904
- });
23905
- }
23906
- return _codec;
23907
- };
23908
- Index.encode = (obj) => {
23909
- return encodeMessage(obj, Index.codec());
23910
- };
23911
- Index.decode = (buf, opts) => {
23912
- return decodeMessage(buf, Index.codec(), opts);
23913
- };
23914
- })(Index || (Index = {}));
23915
- var PagingInfo;
23916
- (function (PagingInfo) {
23917
- (function (Direction) {
23918
- Direction["BACKWARD"] = "BACKWARD";
23919
- Direction["FORWARD"] = "FORWARD";
23920
- })(PagingInfo.Direction || (PagingInfo.Direction = {}));
23921
- let __DirectionValues;
23922
- (function (__DirectionValues) {
23923
- __DirectionValues[__DirectionValues["BACKWARD"] = 0] = "BACKWARD";
23924
- __DirectionValues[__DirectionValues["FORWARD"] = 1] = "FORWARD";
23925
- })(__DirectionValues || (__DirectionValues = {}));
23926
- (function (Direction) {
23927
- Direction.codec = () => {
23928
- return enumeration(__DirectionValues);
23929
- };
23930
- })(PagingInfo.Direction || (PagingInfo.Direction = {}));
23931
- let _codec;
23932
- PagingInfo.codec = () => {
23933
- if (_codec == null) {
23934
- _codec = message((obj, w, opts = {}) => {
23935
- if (opts.lengthDelimited !== false) {
23936
- w.fork();
23937
- }
23938
- if (obj.pageSize != null) {
23939
- w.uint32(8);
23940
- w.uint64(obj.pageSize);
23859
+ w.bytes(obj.messageHash);
23941
23860
  }
23942
- if (obj.cursor != null) {
23861
+ if (obj.message != null) {
23943
23862
  w.uint32(18);
23944
- Index.codec().encode(obj.cursor, w);
23863
+ WakuMessage.codec().encode(obj.message, w);
23945
23864
  }
23946
- if (obj.direction != null) {
23947
- w.uint32(24);
23948
- PagingInfo.Direction.codec().encode(obj.direction, w);
23865
+ if (obj.pubsubTopic != null) {
23866
+ w.uint32(26);
23867
+ w.string(obj.pubsubTopic);
23949
23868
  }
23950
23869
  if (opts.lengthDelimited !== false) {
23951
23870
  w.ldelim();
@@ -23957,17 +23876,17 @@ var PagingInfo;
23957
23876
  const tag = reader.uint32();
23958
23877
  switch (tag >>> 3) {
23959
23878
  case 1: {
23960
- obj.pageSize = reader.uint64();
23879
+ obj.messageHash = reader.bytes();
23961
23880
  break;
23962
23881
  }
23963
23882
  case 2: {
23964
- obj.cursor = Index.codec().decode(reader, reader.uint32(), {
23965
- limits: opts.limits?.cursor
23883
+ obj.message = WakuMessage.codec().decode(reader, reader.uint32(), {
23884
+ limits: opts.limits?.message
23966
23885
  });
23967
23886
  break;
23968
23887
  }
23969
23888
  case 3: {
23970
- obj.direction = PagingInfo.Direction.codec().decode(reader);
23889
+ obj.pubsubTopic = reader.string();
23971
23890
  break;
23972
23891
  }
23973
23892
  default: {
@@ -23981,217 +23900,125 @@ var PagingInfo;
23981
23900
  }
23982
23901
  return _codec;
23983
23902
  };
23984
- PagingInfo.encode = (obj) => {
23985
- return encodeMessage(obj, PagingInfo.codec());
23903
+ WakuMessageKeyValue.encode = (obj) => {
23904
+ return encodeMessage(obj, WakuMessageKeyValue.codec());
23986
23905
  };
23987
- PagingInfo.decode = (buf, opts) => {
23988
- return decodeMessage(buf, PagingInfo.codec(), opts);
23906
+ WakuMessageKeyValue.decode = (buf, opts) => {
23907
+ return decodeMessage(buf, WakuMessageKeyValue.codec(), opts);
23989
23908
  };
23990
- })(PagingInfo || (PagingInfo = {}));
23991
- var ContentFilter;
23992
- (function (ContentFilter) {
23909
+ })(WakuMessageKeyValue || (WakuMessageKeyValue = {}));
23910
+ var StoreQueryRequest;
23911
+ (function (StoreQueryRequest) {
23993
23912
  let _codec;
23994
- ContentFilter.codec = () => {
23913
+ StoreQueryRequest.codec = () => {
23995
23914
  if (_codec == null) {
23996
23915
  _codec = message((obj, w, opts = {}) => {
23997
23916
  if (opts.lengthDelimited !== false) {
23998
23917
  w.fork();
23999
23918
  }
24000
- if ((obj.contentTopic != null && obj.contentTopic !== '')) {
23919
+ if ((obj.requestId != null && obj.requestId !== '')) {
24001
23920
  w.uint32(10);
24002
- w.string(obj.contentTopic);
23921
+ w.string(obj.requestId);
24003
23922
  }
24004
- if (opts.lengthDelimited !== false) {
24005
- w.ldelim();
23923
+ if ((obj.includeData != null && obj.includeData !== false)) {
23924
+ w.uint32(16);
23925
+ w.bool(obj.includeData);
24006
23926
  }
24007
- }, (reader, length, opts = {}) => {
24008
- const obj = {
24009
- contentTopic: ''
24010
- };
24011
- const end = length == null ? reader.len : reader.pos + length;
24012
- while (reader.pos < end) {
24013
- const tag = reader.uint32();
24014
- switch (tag >>> 3) {
24015
- case 1: {
24016
- obj.contentTopic = reader.string();
24017
- break;
24018
- }
24019
- default: {
24020
- reader.skipType(tag & 7);
24021
- break;
24022
- }
23927
+ if (obj.pubsubTopic != null) {
23928
+ w.uint32(82);
23929
+ w.string(obj.pubsubTopic);
23930
+ }
23931
+ if (obj.contentTopics != null) {
23932
+ for (const value of obj.contentTopics) {
23933
+ w.uint32(90);
23934
+ w.string(value);
24023
23935
  }
24024
23936
  }
24025
- return obj;
24026
- });
24027
- }
24028
- return _codec;
24029
- };
24030
- ContentFilter.encode = (obj) => {
24031
- return encodeMessage(obj, ContentFilter.codec());
24032
- };
24033
- ContentFilter.decode = (buf, opts) => {
24034
- return decodeMessage(buf, ContentFilter.codec(), opts);
24035
- };
24036
- })(ContentFilter || (ContentFilter = {}));
24037
- var HistoryQuery;
24038
- (function (HistoryQuery) {
24039
- let _codec;
24040
- HistoryQuery.codec = () => {
24041
- if (_codec == null) {
24042
- _codec = message((obj, w, opts = {}) => {
24043
- if (opts.lengthDelimited !== false) {
24044
- w.fork();
23937
+ if (obj.timeStart != null) {
23938
+ w.uint32(96);
23939
+ w.sint64(obj.timeStart);
24045
23940
  }
24046
- if (obj.pubsubTopic != null) {
24047
- w.uint32(18);
24048
- w.string(obj.pubsubTopic);
23941
+ if (obj.timeEnd != null) {
23942
+ w.uint32(104);
23943
+ w.sint64(obj.timeEnd);
24049
23944
  }
24050
- if (obj.contentFilters != null) {
24051
- for (const value of obj.contentFilters) {
24052
- w.uint32(26);
24053
- ContentFilter.codec().encode(value, w);
23945
+ if (obj.messageHashes != null) {
23946
+ for (const value of obj.messageHashes) {
23947
+ w.uint32(162);
23948
+ w.bytes(value);
24054
23949
  }
24055
23950
  }
24056
- if (obj.pagingInfo != null) {
24057
- w.uint32(34);
24058
- PagingInfo.codec().encode(obj.pagingInfo, w);
23951
+ if (obj.paginationCursor != null) {
23952
+ w.uint32(410);
23953
+ w.bytes(obj.paginationCursor);
24059
23954
  }
24060
- if (obj.startTime != null) {
24061
- w.uint32(40);
24062
- w.sint64(obj.startTime);
23955
+ if ((obj.paginationForward != null && obj.paginationForward !== false)) {
23956
+ w.uint32(416);
23957
+ w.bool(obj.paginationForward);
24063
23958
  }
24064
- if (obj.endTime != null) {
24065
- w.uint32(48);
24066
- w.sint64(obj.endTime);
23959
+ if (obj.paginationLimit != null) {
23960
+ w.uint32(424);
23961
+ w.uint64(obj.paginationLimit);
24067
23962
  }
24068
23963
  if (opts.lengthDelimited !== false) {
24069
23964
  w.ldelim();
24070
23965
  }
24071
23966
  }, (reader, length, opts = {}) => {
24072
23967
  const obj = {
24073
- contentFilters: []
23968
+ requestId: '',
23969
+ includeData: false,
23970
+ contentTopics: [],
23971
+ messageHashes: [],
23972
+ paginationForward: false
24074
23973
  };
24075
23974
  const end = length == null ? reader.len : reader.pos + length;
24076
23975
  while (reader.pos < end) {
24077
23976
  const tag = reader.uint32();
24078
23977
  switch (tag >>> 3) {
24079
- case 2: {
24080
- obj.pubsubTopic = reader.string();
23978
+ case 1: {
23979
+ obj.requestId = reader.string();
24081
23980
  break;
24082
23981
  }
24083
- case 3: {
24084
- if (opts.limits?.contentFilters != null && obj.contentFilters.length === opts.limits.contentFilters) {
24085
- throw new CodeError('decode error - map field "contentFilters" had too many elements', 'ERR_MAX_LENGTH');
24086
- }
24087
- obj.contentFilters.push(ContentFilter.codec().decode(reader, reader.uint32(), {
24088
- limits: opts.limits?.contentFilters$
24089
- }));
23982
+ case 2: {
23983
+ obj.includeData = reader.bool();
24090
23984
  break;
24091
23985
  }
24092
- case 4: {
24093
- obj.pagingInfo = PagingInfo.codec().decode(reader, reader.uint32(), {
24094
- limits: opts.limits?.pagingInfo
24095
- });
23986
+ case 10: {
23987
+ obj.pubsubTopic = reader.string();
24096
23988
  break;
24097
23989
  }
24098
- case 5: {
24099
- obj.startTime = reader.sint64();
23990
+ case 11: {
23991
+ if (opts.limits?.contentTopics != null && obj.contentTopics.length === opts.limits.contentTopics) {
23992
+ throw new CodeError('decode error - map field "contentTopics" had too many elements', 'ERR_MAX_LENGTH');
23993
+ }
23994
+ obj.contentTopics.push(reader.string());
24100
23995
  break;
24101
23996
  }
24102
- case 6: {
24103
- obj.endTime = reader.sint64();
23997
+ case 12: {
23998
+ obj.timeStart = reader.sint64();
24104
23999
  break;
24105
24000
  }
24106
- default: {
24107
- reader.skipType(tag & 7);
24001
+ case 13: {
24002
+ obj.timeEnd = reader.sint64();
24108
24003
  break;
24109
24004
  }
24110
- }
24111
- }
24112
- return obj;
24113
- });
24114
- }
24115
- return _codec;
24116
- };
24117
- HistoryQuery.encode = (obj) => {
24118
- return encodeMessage(obj, HistoryQuery.codec());
24119
- };
24120
- HistoryQuery.decode = (buf, opts) => {
24121
- return decodeMessage(buf, HistoryQuery.codec(), opts);
24122
- };
24123
- })(HistoryQuery || (HistoryQuery = {}));
24124
- var HistoryResponse;
24125
- (function (HistoryResponse) {
24126
- let HistoryError;
24127
- (function (HistoryError) {
24128
- HistoryError["NONE"] = "NONE";
24129
- HistoryError["INVALID_CURSOR"] = "INVALID_CURSOR";
24130
- HistoryError["TOO_MANY_REQUESTS"] = "TOO_MANY_REQUESTS";
24131
- HistoryError["SERVICE_UNAVAILABLE"] = "SERVICE_UNAVAILABLE";
24132
- })(HistoryError = HistoryResponse.HistoryError || (HistoryResponse.HistoryError = {}));
24133
- let __HistoryErrorValues;
24134
- (function (__HistoryErrorValues) {
24135
- __HistoryErrorValues[__HistoryErrorValues["NONE"] = 0] = "NONE";
24136
- __HistoryErrorValues[__HistoryErrorValues["INVALID_CURSOR"] = 1] = "INVALID_CURSOR";
24137
- __HistoryErrorValues[__HistoryErrorValues["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
24138
- __HistoryErrorValues[__HistoryErrorValues["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
24139
- })(__HistoryErrorValues || (__HistoryErrorValues = {}));
24140
- (function (HistoryError) {
24141
- HistoryError.codec = () => {
24142
- return enumeration(__HistoryErrorValues);
24143
- };
24144
- })(HistoryError = HistoryResponse.HistoryError || (HistoryResponse.HistoryError = {}));
24145
- let _codec;
24146
- HistoryResponse.codec = () => {
24147
- if (_codec == null) {
24148
- _codec = message((obj, w, opts = {}) => {
24149
- if (opts.lengthDelimited !== false) {
24150
- w.fork();
24151
- }
24152
- if (obj.messages != null) {
24153
- for (const value of obj.messages) {
24154
- w.uint32(18);
24155
- WakuMessage.codec().encode(value, w);
24156
- }
24157
- }
24158
- if (obj.pagingInfo != null) {
24159
- w.uint32(26);
24160
- PagingInfo.codec().encode(obj.pagingInfo, w);
24161
- }
24162
- if (obj.error != null && __HistoryErrorValues[obj.error] !== 0) {
24163
- w.uint32(32);
24164
- HistoryResponse.HistoryError.codec().encode(obj.error, w);
24165
- }
24166
- if (opts.lengthDelimited !== false) {
24167
- w.ldelim();
24168
- }
24169
- }, (reader, length, opts = {}) => {
24170
- const obj = {
24171
- messages: [],
24172
- error: HistoryError.NONE
24173
- };
24174
- const end = length == null ? reader.len : reader.pos + length;
24175
- while (reader.pos < end) {
24176
- const tag = reader.uint32();
24177
- switch (tag >>> 3) {
24178
- case 2: {
24179
- if (opts.limits?.messages != null && obj.messages.length === opts.limits.messages) {
24180
- throw new CodeError('decode error - map field "messages" had too many elements', 'ERR_MAX_LENGTH');
24005
+ case 20: {
24006
+ if (opts.limits?.messageHashes != null && obj.messageHashes.length === opts.limits.messageHashes) {
24007
+ throw new CodeError('decode error - map field "messageHashes" had too many elements', 'ERR_MAX_LENGTH');
24181
24008
  }
24182
- obj.messages.push(WakuMessage.codec().decode(reader, reader.uint32(), {
24183
- limits: opts.limits?.messages$
24184
- }));
24009
+ obj.messageHashes.push(reader.bytes());
24185
24010
  break;
24186
24011
  }
24187
- case 3: {
24188
- obj.pagingInfo = PagingInfo.codec().decode(reader, reader.uint32(), {
24189
- limits: opts.limits?.pagingInfo
24190
- });
24012
+ case 51: {
24013
+ obj.paginationCursor = reader.bytes();
24191
24014
  break;
24192
24015
  }
24193
- case 4: {
24194
- obj.error = HistoryResponse.HistoryError.codec().decode(reader);
24016
+ case 52: {
24017
+ obj.paginationForward = reader.bool();
24018
+ break;
24019
+ }
24020
+ case 53: {
24021
+ obj.paginationLimit = reader.uint64();
24195
24022
  break;
24196
24023
  }
24197
24024
  default: {
@@ -24205,17 +24032,17 @@ var HistoryResponse;
24205
24032
  }
24206
24033
  return _codec;
24207
24034
  };
24208
- HistoryResponse.encode = (obj) => {
24209
- return encodeMessage(obj, HistoryResponse.codec());
24035
+ StoreQueryRequest.encode = (obj) => {
24036
+ return encodeMessage(obj, StoreQueryRequest.codec());
24210
24037
  };
24211
- HistoryResponse.decode = (buf, opts) => {
24212
- return decodeMessage(buf, HistoryResponse.codec(), opts);
24038
+ StoreQueryRequest.decode = (buf, opts) => {
24039
+ return decodeMessage(buf, StoreQueryRequest.codec(), opts);
24213
24040
  };
24214
- })(HistoryResponse || (HistoryResponse = {}));
24215
- var HistoryRpc;
24216
- (function (HistoryRpc) {
24041
+ })(StoreQueryRequest || (StoreQueryRequest = {}));
24042
+ var StoreQueryResponse;
24043
+ (function (StoreQueryResponse) {
24217
24044
  let _codec;
24218
- HistoryRpc.codec = () => {
24045
+ StoreQueryResponse.codec = () => {
24219
24046
  if (_codec == null) {
24220
24047
  _codec = message((obj, w, opts = {}) => {
24221
24048
  if (opts.lengthDelimited !== false) {
@@ -24225,20 +24052,31 @@ var HistoryRpc;
24225
24052
  w.uint32(10);
24226
24053
  w.string(obj.requestId);
24227
24054
  }
24228
- if (obj.query != null) {
24229
- w.uint32(18);
24230
- HistoryQuery.codec().encode(obj.query, w);
24055
+ if (obj.statusCode != null) {
24056
+ w.uint32(80);
24057
+ w.uint32(obj.statusCode);
24231
24058
  }
24232
- if (obj.response != null) {
24233
- w.uint32(26);
24234
- HistoryResponse.codec().encode(obj.response, w);
24059
+ if (obj.statusDesc != null) {
24060
+ w.uint32(90);
24061
+ w.string(obj.statusDesc);
24062
+ }
24063
+ if (obj.messages != null) {
24064
+ for (const value of obj.messages) {
24065
+ w.uint32(162);
24066
+ WakuMessageKeyValue.codec().encode(value, w);
24067
+ }
24068
+ }
24069
+ if (obj.paginationCursor != null) {
24070
+ w.uint32(410);
24071
+ w.bytes(obj.paginationCursor);
24235
24072
  }
24236
24073
  if (opts.lengthDelimited !== false) {
24237
24074
  w.ldelim();
24238
24075
  }
24239
24076
  }, (reader, length, opts = {}) => {
24240
24077
  const obj = {
24241
- requestId: ''
24078
+ requestId: '',
24079
+ messages: []
24242
24080
  };
24243
24081
  const end = length == null ? reader.len : reader.pos + length;
24244
24082
  while (reader.pos < end) {
@@ -24248,16 +24086,25 @@ var HistoryRpc;
24248
24086
  obj.requestId = reader.string();
24249
24087
  break;
24250
24088
  }
24251
- case 2: {
24252
- obj.query = HistoryQuery.codec().decode(reader, reader.uint32(), {
24253
- limits: opts.limits?.query
24254
- });
24089
+ case 10: {
24090
+ obj.statusCode = reader.uint32();
24255
24091
  break;
24256
24092
  }
24257
- case 3: {
24258
- obj.response = HistoryResponse.codec().decode(reader, reader.uint32(), {
24259
- limits: opts.limits?.response
24260
- });
24093
+ case 11: {
24094
+ obj.statusDesc = reader.string();
24095
+ break;
24096
+ }
24097
+ case 20: {
24098
+ if (opts.limits?.messages != null && obj.messages.length === opts.limits.messages) {
24099
+ throw new CodeError('decode error - map field "messages" had too many elements', 'ERR_MAX_LENGTH');
24100
+ }
24101
+ obj.messages.push(WakuMessageKeyValue.codec().decode(reader, reader.uint32(), {
24102
+ limits: opts.limits?.messages$
24103
+ }));
24104
+ break;
24105
+ }
24106
+ case 51: {
24107
+ obj.paginationCursor = reader.bytes();
24261
24108
  break;
24262
24109
  }
24263
24110
  default: {
@@ -24271,13 +24118,13 @@ var HistoryRpc;
24271
24118
  }
24272
24119
  return _codec;
24273
24120
  };
24274
- HistoryRpc.encode = (obj) => {
24275
- return encodeMessage(obj, HistoryRpc.codec());
24121
+ StoreQueryResponse.encode = (obj) => {
24122
+ return encodeMessage(obj, StoreQueryResponse.codec());
24276
24123
  };
24277
- HistoryRpc.decode = (buf, opts) => {
24278
- return decodeMessage(buf, HistoryRpc.codec(), opts);
24124
+ StoreQueryResponse.decode = (buf, opts) => {
24125
+ return decodeMessage(buf, StoreQueryResponse.codec(), opts);
24279
24126
  };
24280
- })(HistoryRpc || (HistoryRpc = {}));
24127
+ })(StoreQueryResponse || (StoreQueryResponse = {}));
24281
24128
  var RateLimitProof;
24282
24129
  (function (RateLimitProof) {
24283
24130
  let _codec;
@@ -24859,11 +24706,11 @@ class WakuPeerExchange extends BaseProtocol {
24859
24706
  * Make a peer exchange query to a peer
24860
24707
  */
24861
24708
  async query(params) {
24862
- const { numPeers } = params;
24709
+ const { numPeers, peerId } = params;
24863
24710
  const rpcQuery = PeerExchangeRPC.createRequest({
24864
24711
  numPeers: BigInt(numPeers)
24865
24712
  });
24866
- const peer = await this.peerStore.get(params.peerId);
24713
+ const peer = await this.peerStore.get(peerId);
24867
24714
  if (!peer) {
24868
24715
  return {
24869
24716
  peerInfos: null,
@@ -25019,7 +24866,31 @@ class PeerExchangeDiscovery extends TypedEventEmitter {
25019
24866
  }
25020
24867
  const hasPeer = await this.components.peerStore.has(peerId);
25021
24868
  if (hasPeer) {
25022
- continue;
24869
+ const { hasMultiaddrDiff, hasShardDiff } = await this.checkPeerInfoDiff(peerInfo, shardInfo);
24870
+ if (hasMultiaddrDiff || hasShardDiff) {
24871
+ log$1.info(`Peer ${peerId.toString()} has updated multiaddrs or shardInfo, updating`);
24872
+ if (hasMultiaddrDiff) {
24873
+ log$1.info(`Peer ${peerId.toString()} has updated multiaddrs, updating`);
24874
+ await this.components.peerStore.patch(peerId, {
24875
+ multiaddrs: peerInfo.multiaddrs
24876
+ });
24877
+ }
24878
+ if (hasShardDiff && shardInfo) {
24879
+ log$1.info(`Peer ${peerId.toString()} has updated shardInfo, updating`);
24880
+ await this.components.peerStore.merge(peerId, {
24881
+ metadata: {
24882
+ shardInfo: encodeRelayShard(shardInfo)
24883
+ }
24884
+ });
24885
+ this.dispatchEvent(new CustomEvent("peer", {
24886
+ detail: {
24887
+ id: peerId,
24888
+ multiaddrs: peerInfo.multiaddrs
24889
+ }
24890
+ }));
24891
+ }
24892
+ continue;
24893
+ }
25023
24894
  }
25024
24895
  // update the tags for the peer
25025
24896
  await this.components.peerStore.save(peerId, {
@@ -25033,6 +24904,9 @@ class PeerExchangeDiscovery extends TypedEventEmitter {
25033
24904
  metadata: {
25034
24905
  shardInfo: encodeRelayShard(shardInfo)
25035
24906
  }
24907
+ }),
24908
+ ...(peerInfo.multiaddrs && {
24909
+ multiaddrs: peerInfo.multiaddrs
25036
24910
  })
25037
24911
  });
25038
24912
  log$1.info(`Discovered peer: ${peerId.toString()}`);
@@ -25050,6 +24924,24 @@ class PeerExchangeDiscovery extends TypedEventEmitter {
25050
24924
  this.queryingPeers.delete(peerIdStr);
25051
24925
  this.queryAttempts.delete(peerIdStr);
25052
24926
  }
24927
+ async checkPeerInfoDiff(peerInfo, shardInfo) {
24928
+ const { id: peerId } = peerInfo;
24929
+ const peer = await this.components.peerStore.get(peerId);
24930
+ const existingMultiaddrs = peer.addresses.map((a) => a.multiaddr.toString());
24931
+ const newMultiaddrs = peerInfo.multiaddrs.map((ma) => ma.toString());
24932
+ const hasMultiaddrDiff = existingMultiaddrs.some((ma) => !newMultiaddrs.includes(ma));
24933
+ let hasShardDiff = false;
24934
+ const existingShardInfoBytes = peer.metadata.get("shardInfo");
24935
+ if (existingShardInfoBytes) {
24936
+ const existingShardInfo = decodeRelayShard(existingShardInfoBytes);
24937
+ if (existingShardInfo || shardInfo) {
24938
+ hasShardDiff =
24939
+ existingShardInfo.clusterId !== shardInfo?.clusterId ||
24940
+ existingShardInfo.shards.some((shard) => !shardInfo?.shards.includes(shard));
24941
+ }
24942
+ }
24943
+ return { hasMultiaddrDiff, hasShardDiff };
24944
+ }
25053
24945
  }
25054
24946
  function wakuPeerExchangeDiscovery(pubsubTopics) {
25055
24947
  return (components) => new PeerExchangeDiscovery(components, pubsubTopics);