@fuel-ts/account 0.80.0 → 0.82.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.

Potentially problematic release.


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

@@ -944,36 +944,45 @@ var _FuelGraphqlSubscriber = class {
944
944
  });
945
945
  this.stream = response.body.getReader();
946
946
  }
947
+ events = [];
948
+ parsingLeftover = "";
947
949
  async next() {
948
950
  if (!this.stream) {
949
951
  await this.setStream();
950
952
  }
951
953
  while (true) {
954
+ if (this.events.length > 0) {
955
+ const { data, errors } = this.events.shift();
956
+ if (Array.isArray(errors)) {
957
+ throw new import_errors.FuelError(
958
+ import_errors.FuelError.CODES.INVALID_REQUEST,
959
+ errors.map((err) => err.message).join("\n\n")
960
+ );
961
+ }
962
+ return { value: data, done: false };
963
+ }
952
964
  const { value, done } = await this.stream.read();
953
965
  if (done) {
954
966
  return { value, done };
955
967
  }
956
- const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
957
- if (!text.startsWith("data:")) {
968
+ const decoded = _FuelGraphqlSubscriber.textDecoder.decode(value).replace(":keep-alive-text\n\n", "");
969
+ if (decoded === "") {
958
970
  continue;
959
971
  }
960
- let data;
961
- let errors;
962
- try {
963
- ({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
964
- } catch (e) {
965
- throw new import_errors.FuelError(
966
- import_errors.ErrorCode.STREAM_PARSING_ERROR,
967
- `Error while parsing stream data response: ${text}`
968
- );
969
- }
970
- if (Array.isArray(errors)) {
971
- throw new import_errors.FuelError(
972
- import_errors.FuelError.CODES.INVALID_REQUEST,
973
- errors.map((err) => err.message).join("\n\n")
974
- );
975
- }
976
- return { value: data, done: false };
972
+ const text = `${this.parsingLeftover}${decoded}`;
973
+ const regex = /data:.*\n\n/g;
974
+ const matches = [...text.matchAll(regex)].flatMap((match) => match);
975
+ matches.forEach((match) => {
976
+ try {
977
+ this.events.push(JSON.parse(match.replace(/^data:/, "")));
978
+ } catch (e) {
979
+ throw new import_errors.FuelError(
980
+ import_errors.ErrorCode.STREAM_PARSING_ERROR,
981
+ `Error while parsing stream data response: ${text}`
982
+ );
983
+ }
984
+ });
985
+ this.parsingLeftover = text.replace(matches.join(), "");
977
986
  }
978
987
  }
979
988
  /**