Skip to content

Commit

Permalink
Merge branch 'version-4' of https://github.com/pnp/pnpjs into version-4
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-rodgers committed Feb 27, 2024
2 parents 1c800bb + 29bdbd8 commit 2ae54c6
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 130 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,3 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- sp
- _Items and IItems now supports async iterator pattern

15 changes: 6 additions & 9 deletions docs/queryable/behaviors.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,16 @@ export function Caching(props?: ICachingProps): TimelinePipe<Queryable> {
const cached = getCachedValue();

// we need to ensure that result stays "undefined" unless we mean to set null as the result
if (cached === null) {
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) {
setCachedValue(response);
}));
this.on.post(async function (url: URL, result: any) {
setCachedValue(result);
return [url, result];
});

} else {
// if we find it in cache, override send request, and continue flow through timeline and parsers.
this.on.auth.clear();
this.on.send.replace(async function (this: Queryable) {
return new Response(cached, {});
});
result = cached;
}
}

Expand Down
2 changes: 2 additions & 0 deletions docs/sp/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ The addUsingPath method, supports the percent or pound characters in file names.

When using EnsureUniqueFileName property, you must omit the Overwrite parameter.

![Batching Not Supported Banner](https://img.shields.io/badge/Batching%20Not%20Supported-important.svg)

```TypeScript
import { spfi } from "@pnp/sp";
import "@pnp/sp/webs";
Expand Down
320 changes: 215 additions & 105 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions packages/queryable/behaviors/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,13 @@ 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
instance.on.rawData(noInherit(async function (response) {
setCachedValue(response);
this.on.post(noInherit(async function (url: URL, result: any) {
setCachedValue(result);
return [url, result];
}));

} else {
// if we find it in cache, override send request, and continue flow through timeline and parsers.
this.on.auth.clear();
this.on.send.replace(async function (this: Queryable) {
return new Response(cached, {});
});
result = cached;
}
}

Expand Down
8 changes: 1 addition & 7 deletions packages/queryable/behaviors/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,7 @@ 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") {

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);
result = await impl(response);
}

return [url, response, result];
Expand Down
1 change: 0 additions & 1 deletion packages/queryable/queryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const DefaultMoments = {
parse: asyncReduce<QueryableParseObserver>(),
post: asyncReduce<QueryablePostObserver>(),
data: broadcast<QueryableDataObserver>(),
rawData: broadcast<QueryableDataObserver>(),
} as const;

export type QueryableInit = Queryable<any> | string | [Queryable<any>, string];
Expand Down

0 comments on commit 2ae54c6

Please sign in to comment.