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

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