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

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.

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