@arbidocs/sdk 0.3.46 → 0.3.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4709,10 +4709,17 @@ async function listDocuments(arbi) {
4709
4709
  return requireData(await arbi.fetch.GET("/v1/document/list"), "Failed to fetch documents");
4710
4710
  }
4711
4711
  async function* listPaginated(arbi, options = {}) {
4712
- const { pageSize = 5e3, order = "id_asc", fields, signal, lookahead = 3 } = options;
4713
- const fetchPage = async (pageOffset) => {
4712
+ const {
4713
+ pageSize = 5e3,
4714
+ firstPageSize,
4715
+ order = "id_asc",
4716
+ fields,
4717
+ signal,
4718
+ lookahead = 1
4719
+ } = options;
4720
+ const fetchPage = async (pageOffset, limit) => {
4714
4721
  const query = {
4715
- limit: pageSize,
4722
+ limit,
4716
4723
  offset: pageOffset,
4717
4724
  order
4718
4725
  };
@@ -4735,19 +4742,21 @@ async function* listPaginated(arbi, options = {}) {
4735
4742
  const queue = [];
4736
4743
  const tryEnqueue = () => {
4737
4744
  while (!done && queue.length < depth && issued < MAX_PAGES) {
4738
- const p2 = fetchPage(nextOffsetToIssue);
4739
- p2.catch(() => {
4745
+ const limit = issued === 0 && firstPageSize !== void 0 ? firstPageSize : pageSize;
4746
+ const promise = fetchPage(nextOffsetToIssue, limit);
4747
+ promise.catch(() => {
4740
4748
  });
4741
- queue.push(p2);
4742
- nextOffsetToIssue += pageSize;
4749
+ queue.push({ limit, promise });
4750
+ nextOffsetToIssue += limit;
4743
4751
  issued++;
4744
4752
  }
4745
4753
  };
4746
4754
  tryEnqueue();
4747
4755
  while (queue.length > 0 && !signal?.aborted) {
4748
- const page = await queue.shift();
4756
+ const { limit, promise } = queue.shift();
4757
+ const page = await promise;
4749
4758
  if (signal?.aborted) return;
4750
- const isShort = page.length < pageSize;
4759
+ const isShort = page.length < limit;
4751
4760
  if (isShort) done = true;
4752
4761
  tryEnqueue();
4753
4762
  if (page.length > 0) {