Skip to content
Merged
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
20 changes: 11 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ class Client {
let pageSize = options.pageSize;
if (pageSize > options.sizeLimit) pageSize = options.sizeLimit;

const controls0 = controls.filter((control) => {
return control.OID !== OID.PagedResults;
});

const pagedResults = {
OID: OID.PagedResults,
criticality: true,
Expand All @@ -119,31 +123,29 @@ class Client {
}
};

controls = controls.filter((control) => {
return control.OID !== OID.PagedResults;
});
controls.push(pagedResults);

let cookie = '';
const results = [];
let results = [];
let hasNext = true;
while (hasNext) {
pagedResults.value.cookie = cookie;
controls.length = 0;
controls = controls.concat(controls0);
controls.push(pagedResults);

results.push(await this._send(new Search(Object.assign({ baseObject, controls }, options))));
results = results.concat(await this._send(new Search(Object.assign({ baseObject, controls }, options))));

const responsePagedResults = controls.find((control) => {
return control.OID === OID.PagedResults;
});

if (responsePagedResults !== undefined) {
if (responsePagedResults !== undefined && responsePagedResults.value.cookie !== '') {
cookie = responsePagedResults.value.cookie;
} else {
hasNext = false;
}
}

return results.flat();
return results;

} else {
return this._send(new Search(Object.assign({ baseObject, controls }, options)));
Expand Down