Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node Clone - Fix #2903

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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