@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.

package/dist/index.js CHANGED
@@ -1066,36 +1066,45 @@ var _FuelGraphqlSubscriber = class {
1066
1066
  });
1067
1067
  this.stream = response.body.getReader();
1068
1068
  }
1069
+ events = [];
1070
+ parsingLeftover = "";
1069
1071
  async next() {
1070
1072
  if (!this.stream) {
1071
1073
  await this.setStream();
1072
1074
  }
1073
1075
  while (true) {
1076
+ if (this.events.length > 0) {
1077
+ const { data, errors } = this.events.shift();
1078
+ if (Array.isArray(errors)) {
1079
+ throw new import_errors.FuelError(
1080
+ import_errors.FuelError.CODES.INVALID_REQUEST,
1081
+ errors.map((err) => err.message).join("\n\n")
1082
+ );
1083
+ }
1084
+ return { value: data, done: false };
1085
+ }
1074
1086
  const { value, done } = await this.stream.read();
1075
1087
  if (done) {
1076
1088
  return { value, done };
1077
1089
  }
1078
- const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
1079
- if (!text.startsWith("data:")) {
1090
+ const decoded = _FuelGraphqlSubscriber.textDecoder.decode(value).replace(":keep-alive-text\n\n", "");
1091
+ if (decoded === "") {
1080
1092
  continue;
1081
1093
  }
1082
- let data;
1083
- let errors;
1084
- try {
1085
- ({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
1086
- } catch (e) {
1087
- throw new import_errors.FuelError(
1088
- import_errors.ErrorCode.STREAM_PARSING_ERROR,
1089
- `Error while parsing stream data response: ${text}`
1090
- );
1091
- }
1092
- if (Array.isArray(errors)) {
1093
- throw new import_errors.FuelError(
1094
- import_errors.FuelError.CODES.INVALID_REQUEST,
1095
- errors.map((err) => err.message).join("\n\n")
1096
- );
1097
- }
1098
- return { value: data, done: false };
1094
+ const text = `${this.parsingLeftover}${decoded}`;
1095
+ const regex = /data:.*\n\n/g;
1096
+ const matches = [...text.matchAll(regex)].flatMap((match) => match);
1097
+ matches.forEach((match) => {
1098
+ try {
1099
+ this.events.push(JSON.parse(match.replace(/^data:/, "")));
1100
+ } catch (e) {
1101
+ throw new import_errors.FuelError(
1102
+ import_errors.ErrorCode.STREAM_PARSING_ERROR,
1103
+ `Error while parsing stream data response: ${text}`
1104
+ );
1105
+ }
1106
+ });
1107
+ this.parsingLeftover = text.replace(matches.join(), "");
1099
1108
  }
1100
1109
  }
1101
1110
  /**