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