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

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