UNPKG

1.43 kBJavaScriptView Raw
1import { InjectHeaders } from "@pnp/queryable";
2import { _Items, Items } from "./types.js";
3_Items.prototype.getAll = async function (requestSize = 2000, acceptHeader = "application/json;odata=nometadata") {
4 // this will be used for the actual query
5 // and we set no metadata here to try and reduce traffic
6 const items = Items(this, "").top(requestSize).using(InjectHeaders({
7 "Accept": acceptHeader,
8 }));
9 // let's copy over the odata query params that can be applied
10 // $top - allow setting the page size this way (override what we did above)
11 // $select - allow picking the return fields (good behavior)
12 // $filter - allow setting a filter, though this may fail for large lists
13 // $expand - allow expanding fields for filter/select support
14 this.query.forEach((v, k) => {
15 if (/^\$select|filter|top|expand$/i.test(k)) {
16 items.query.set(k, v);
17 }
18 });
19 // this will eventually hold the items we return
20 const itemsCollector = [];
21 // action that will gather up our results recursively
22 const gatherer = (last) => {
23 // collect that set of results
24 itemsCollector.push(...last.results);
25 // if we have more, repeat - otherwise resolve with the collected items
26 return last.hasNext ? last.getNext().then(gatherer) : itemsCollector;
27 };
28 return items.getPaged().then(gatherer);
29};
30//# sourceMappingURL=get-all.js.map
\No newline at end of file