Skip to content

Commit

Permalink
Merge pull request #2903 from bcameron1231/fix-2890
Browse files Browse the repository at this point in the history
Node Clone - Fix
  • Loading branch information
juliemturner authored Jan 17, 2024
2 parents 2cacb70 + fa8934f commit 0a18076
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/queryable/behaviors/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function Caching(props?: ICachingProps): TimelinePipe<Queryable> {
if (cached === null) {

// if we don't have a cached result we need to get it after the request is sent. Get the raw value (un-parsed) to store into cache
this.on.rawData(noInherit(async function (response) {
instance.on.rawData(noInherit(async function (response) {
setCachedValue(response);
}));

Expand Down
9 changes: 7 additions & 2 deletions packages/queryable/behaviors/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function TextParse(): TimelinePipe {
export function BlobParse(): TimelinePipe {

return parseBinderWithErrorCheck( async (response) => {
const binaryResponseBody = parseToAtob(await response.clone().text());
const binaryResponseBody = parseToAtob(await response.text());
// handle batch responses for things that are base64, like photos https://github.com/pnp/pnpjs/issues/2825
if(binaryResponseBody){
// Create an array buffer from the binary string
Expand Down Expand Up @@ -123,7 +123,12 @@ export function parseBinderWithErrorCheck(impl: (r: Response) => Promise<any>):
instance.on.parse(async (url: URL, response: Response, result: any): Promise<[URL, Response, any]> => {

if (response.ok && typeof result === "undefined") {
result = await impl(response);
const respClone = response.clone();

// https://github.com/node-fetch/node-fetch?tab=readme-ov-file#custom-highwatermark
const [implResult, raw] = await Promise.all([impl(response), respClone.text()]);
result = implResult;
(<any>instance).emit.rawData(raw);
}

return [url, response, result];
Expand Down
4 changes: 0 additions & 4 deletions packages/queryable/queryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ export class Queryable<R> extends Timeline<typeof DefaultMoments> implements IQu
let response = await this.emit.send(requestUrl, init);
log("Emitted send");

log("Emitting rawData");
this.emit.rawData(await response.clone().text());
log("Emitted rawData");

log("Emitting parse");
[requestUrl, response, result] = await this.emit.parse(requestUrl, response, result);
log("Emitted parse");
Expand Down

0 comments on commit 0a18076

Please sign in to comment.