@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.
@@ -605,10 +605,17 @@ type DocumentListFields = 'full' | 'lite';
605
605
  */
606
606
  interface ListPaginatedOptions {
607
607
  /**
608
- * Number of documents per page.
608
+ * Number of documents per page (applies to every page after the first).
609
609
  * @default 5000
610
610
  */
611
611
  pageSize?: number;
612
+ /**
613
+ * Size of the first page only. When set, the initial request uses this
614
+ * smaller limit so the caller can render something on screen before the
615
+ * full `pageSize`-sized pages stream in. Subsequent pages fall back to
616
+ * `pageSize`. When unset, every page uses `pageSize`.
617
+ */
618
+ firstPageSize?: number;
612
619
  /**
613
620
  * Sort order for pagination.
614
621
  * @default 'id_asc'
@@ -629,7 +636,7 @@ interface ListPaginatedOptions {
629
636
  * Number of pages kept in flight concurrently. A higher value hides more
630
637
  * backend + network latency between pages but increases peak backend load
631
638
  * and memory for not-yet-consumed pages. Clamped to `[1, MAX_PAGES]`.
632
- * @default 3
639
+ * @default 1
633
640
  */
634
641
  lookahead?: number;
635
642
  }
@@ -729,11 +736,16 @@ declare function listDocuments(arbi: ArbiClient): Promise<{
729
736
  *
730
737
  * Uses `limit`/`offset` pagination. A FIFO queue of up to `lookahead` requests
731
738
  * is kept in flight: as soon as a page is awaited off the queue the next
732
- * request is enqueued, so the backend is continuously working on the next few
733
- * pages while the consumer processes the current one. The default of 3 keeps
734
- * three pages in flight, which hides the backend scan + network latency
735
- * behind the consumer's per-page work (cache writes, rendering) even on
736
- * workspaces large enough for the consumer to be faster than a single page.
739
+ * request is enqueued, so the backend is continuously working on the next
740
+ * page while the consumer processes the current one. The default of 1 keeps
741
+ * one page in flight at a time (classic sequential pagination). Raise it when
742
+ * you want to pipeline each extra slot adds one more concurrent backend
743
+ * scan and one more not-yet-consumed page held in memory.
744
+ *
745
+ * Pair `firstPageSize` with a larger `pageSize` when you need the initial
746
+ * page on screen fast: e.g. `firstPageSize: 500, pageSize: 2000` renders the
747
+ * first 500 rows in a fifth of the time of a single 2500-row request, then
748
+ * streams in 2000-row pages after.
737
749
  *
738
750
  * Iteration stops at the first short page (length < `pageSize`) — in-flight
739
751
  * requests past that point are discarded. `MAX_PAGES` is a hard cap on the
@@ -605,10 +605,17 @@ type DocumentListFields = 'full' | 'lite';
605
605
  */
606
606
  interface ListPaginatedOptions {
607
607
  /**
608
- * Number of documents per page.
608
+ * Number of documents per page (applies to every page after the first).
609
609
  * @default 5000
610
610
  */
611
611
  pageSize?: number;
612
+ /**
613
+ * Size of the first page only. When set, the initial request uses this
614
+ * smaller limit so the caller can render something on screen before the
615
+ * full `pageSize`-sized pages stream in. Subsequent pages fall back to
616
+ * `pageSize`. When unset, every page uses `pageSize`.
617
+ */
618
+ firstPageSize?: number;
612
619
  /**
613
620
  * Sort order for pagination.
614
621
  * @default 'id_asc'
@@ -629,7 +636,7 @@ interface ListPaginatedOptions {
629
636
  * Number of pages kept in flight concurrently. A higher value hides more
630
637
  * backend + network latency between pages but increases peak backend load
631
638
  * and memory for not-yet-consumed pages. Clamped to `[1, MAX_PAGES]`.
632
- * @default 3
639
+ * @default 1
633
640
  */
634
641
  lookahead?: number;
635
642
  }
@@ -729,11 +736,16 @@ declare function listDocuments(arbi: ArbiClient): Promise<{
729
736
  *
730
737
  * Uses `limit`/`offset` pagination. A FIFO queue of up to `lookahead` requests
731
738
  * is kept in flight: as soon as a page is awaited off the queue the next
732
- * request is enqueued, so the backend is continuously working on the next few
733
- * pages while the consumer processes the current one. The default of 3 keeps
734
- * three pages in flight, which hides the backend scan + network latency
735
- * behind the consumer's per-page work (cache writes, rendering) even on
736
- * workspaces large enough for the consumer to be faster than a single page.
739
+ * request is enqueued, so the backend is continuously working on the next
740
+ * page while the consumer processes the current one. The default of 1 keeps
741
+ * one page in flight at a time (classic sequential pagination). Raise it when
742
+ * you want to pipeline each extra slot adds one more concurrent backend
743
+ * scan and one more not-yet-consumed page held in memory.
744
+ *
745
+ * Pair `firstPageSize` with a larger `pageSize` when you need the initial
746
+ * page on screen fast: e.g. `firstPageSize: 500, pageSize: 2000` renders the
747
+ * first 500 rows in a fifth of the time of a single 2500-row request, then
748
+ * streams in 2000-row pages after.
737
749
  *
738
750
  * Iteration stops at the first short page (length < `pageSize`) — in-flight
739
751
  * requests past that point are discarded. `MAX_PAGES` is a hard cap on the
package/dist/browser.cjs CHANGED
@@ -4160,10 +4160,17 @@ async function listDocuments(arbi) {
4160
4160
  return requireData(await arbi.fetch.GET("/v1/document/list"), "Failed to fetch documents");
4161
4161
  }
4162
4162
  async function* listPaginated(arbi, options = {}) {
4163
- const { pageSize = 5e3, order = "id_asc", fields, signal, lookahead = 3 } = options;
4164
- const fetchPage = async (pageOffset) => {
4163
+ const {
4164
+ pageSize = 5e3,
4165
+ firstPageSize,
4166
+ order = "id_asc",
4167
+ fields,
4168
+ signal,
4169
+ lookahead = 1
4170
+ } = options;
4171
+ const fetchPage = async (pageOffset, limit) => {
4165
4172
  const query = {
4166
- limit: pageSize,
4173
+ limit,
4167
4174
  offset: pageOffset,
4168
4175
  order
4169
4176
  };
@@ -4186,19 +4193,21 @@ async function* listPaginated(arbi, options = {}) {
4186
4193
  const queue = [];
4187
4194
  const tryEnqueue = () => {
4188
4195
  while (!done && queue.length < depth && issued < MAX_PAGES) {
4189
- const p2 = fetchPage(nextOffsetToIssue);
4190
- p2.catch(() => {
4196
+ const limit = issued === 0 && firstPageSize !== void 0 ? firstPageSize : pageSize;
4197
+ const promise = fetchPage(nextOffsetToIssue, limit);
4198
+ promise.catch(() => {
4191
4199
  });
4192
- queue.push(p2);
4193
- nextOffsetToIssue += pageSize;
4200
+ queue.push({ limit, promise });
4201
+ nextOffsetToIssue += limit;
4194
4202
  issued++;
4195
4203
  }
4196
4204
  };
4197
4205
  tryEnqueue();
4198
4206
  while (queue.length > 0 && !signal?.aborted) {
4199
- const page = await queue.shift();
4207
+ const { limit, promise } = queue.shift();
4208
+ const page = await promise;
4200
4209
  if (signal?.aborted) return;
4201
- const isShort = page.length < pageSize;
4210
+ const isShort = page.length < limit;
4202
4211
  if (isShort) done = true;
4203
4212
  tryEnqueue();
4204
4213
  if (page.length > 0) {