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

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