@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.mjs CHANGED
@@ -916,36 +916,45 @@ var _FuelGraphqlSubscriber = class {
916
916
  });
917
917
  this.stream = response.body.getReader();
918
918
  }
919
+ events = [];
920
+ parsingLeftover = "";
919
921
  async next() {
920
922
  if (!this.stream) {
921
923
  await this.setStream();
922
924
  }
923
925
  while (true) {
926
+ if (this.events.length > 0) {
927
+ const { data, errors } = this.events.shift();
928
+ if (Array.isArray(errors)) {
929
+ throw new FuelError(
930
+ FuelError.CODES.INVALID_REQUEST,
931
+ errors.map((err) => err.message).join("\n\n")
932
+ );
933
+ }
934
+ return { value: data, done: false };
935
+ }
924
936
  const { value, done } = await this.stream.read();
925
937
  if (done) {
926
938
  return { value, done };
927
939
  }
928
- const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
929
- if (!text.startsWith("data:")) {
940
+ const decoded = _FuelGraphqlSubscriber.textDecoder.decode(value).replace(":keep-alive-text\n\n", "");
941
+ if (decoded === "") {
930
942
  continue;
931
943
  }
932
- let data;
933
- let errors;
934
- try {
935
- ({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
936
- } catch (e) {
937
- throw new FuelError(
938
- ErrorCode.STREAM_PARSING_ERROR,
939
- `Error while parsing stream data response: ${text}`
940
- );
941
- }
942
- if (Array.isArray(errors)) {
943
- throw new FuelError(
944
- FuelError.CODES.INVALID_REQUEST,
945
- errors.map((err) => err.message).join("\n\n")
946
- );
947
- }
948
- return { value: data, done: false };
944
+ const text = `${this.parsingLeftover}${decoded}`;
945
+ const regex = /data:.*\n\n/g;
946
+ const matches = [...text.matchAll(regex)].flatMap((match) => match);
947
+ matches.forEach((match) => {
948
+ try {
949
+ this.events.push(JSON.parse(match.replace(/^data:/, "")));
950
+ } catch (e) {
951
+ throw new FuelError(
952
+ ErrorCode.STREAM_PARSING_ERROR,
953
+ `Error while parsing stream data response: ${text}`
954
+ );
955
+ }
956
+ });
957
+ this.parsingLeftover = text.replace(matches.join(), "");
949
958
  }
950
959
  }
951
960
  /**