@fuel-ts/account 0.0.0-rc-1976-20240416162235 → 0.0.0-rc-1976-20240417080846

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.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

@@ -38757,36 +38757,45 @@ ${MessageCoinFragmentFragmentDoc}`;
38757
38757
  });
38758
38758
  this.stream = response.body.getReader();
38759
38759
  }
38760
+ events = [];
38761
+ parsingLeftover = "";
38760
38762
  async next() {
38761
38763
  if (!this.stream) {
38762
38764
  await this.setStream();
38763
38765
  }
38764
38766
  while (true) {
38767
+ if (this.events.length > 0) {
38768
+ const { data, errors } = this.events.shift();
38769
+ if (Array.isArray(errors)) {
38770
+ throw new FuelError(
38771
+ FuelError.CODES.INVALID_REQUEST,
38772
+ errors.map((err) => err.message).join("\n\n")
38773
+ );
38774
+ }
38775
+ return { value: data, done: false };
38776
+ }
38765
38777
  const { value, done } = await this.stream.read();
38766
38778
  if (done) {
38767
38779
  return { value, done };
38768
38780
  }
38769
- const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
38770
- if (!text.startsWith("data:")) {
38781
+ const decoded = _FuelGraphqlSubscriber.textDecoder.decode(value).replace(":keep-alive-text\n\n", "");
38782
+ if (decoded === "") {
38771
38783
  continue;
38772
38784
  }
38773
- let data;
38774
- let errors;
38775
- try {
38776
- ({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
38777
- } catch (e) {
38778
- throw new FuelError(
38779
- ErrorCode.STREAM_PARSING_ERROR,
38780
- `Error while parsing stream data response: ${text}`
38781
- );
38782
- }
38783
- if (Array.isArray(errors)) {
38784
- throw new FuelError(
38785
- FuelError.CODES.INVALID_REQUEST,
38786
- errors.map((err) => err.message).join("\n\n")
38787
- );
38788
- }
38789
- return { value: data, done: false };
38785
+ const text = `${this.parsingLeftover}${decoded}`;
38786
+ const regex = /data:.*\n\n/g;
38787
+ const matches = [...text.matchAll(regex)].flatMap((match) => match);
38788
+ matches.forEach((match) => {
38789
+ try {
38790
+ this.events.push(JSON.parse(match.replace(/^data:/, "")));
38791
+ } catch (e) {
38792
+ throw new FuelError(
38793
+ ErrorCode.STREAM_PARSING_ERROR,
38794
+ `Error while parsing stream data response: ${text}`
38795
+ );
38796
+ }
38797
+ });
38798
+ this.parsingLeftover = text.replace(matches.join(), "");
38790
38799
  }
38791
38800
  }
38792
38801
  /**