@arbidocs/sdk 0.3.44 → 0.3.46
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/{browser-MSSje4v8.d.cts → browser-HVCa8Ph5.d.cts} +20 -5
- package/dist/{browser-MSSje4v8.d.ts → browser-HVCa8Ph5.d.ts} +20 -5
- package/dist/browser.cjs +32 -10
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +32 -10
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +32 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +32 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -625,6 +625,13 @@ interface ListPaginatedOptions {
|
|
|
625
625
|
* AbortSignal to cancel iteration mid-stream.
|
|
626
626
|
*/
|
|
627
627
|
signal?: AbortSignal;
|
|
628
|
+
/**
|
|
629
|
+
* Number of pages kept in flight concurrently. A higher value hides more
|
|
630
|
+
* backend + network latency between pages but increases peak backend load
|
|
631
|
+
* and memory for not-yet-consumed pages. Clamped to `[1, MAX_PAGES]`.
|
|
632
|
+
* @default 3
|
|
633
|
+
*/
|
|
634
|
+
lookahead?: number;
|
|
628
635
|
}
|
|
629
636
|
/**
|
|
630
637
|
* Options for `listAll` — collects all pages into a single array.
|
|
@@ -718,11 +725,19 @@ declare function listDocuments(arbi: ArbiClient): Promise<{
|
|
|
718
725
|
} | null | undefined;
|
|
719
726
|
}[]>;
|
|
720
727
|
/**
|
|
721
|
-
* Async iterator that yields pages of documents
|
|
728
|
+
* Async iterator that yields pages of documents with a configurable lookahead.
|
|
729
|
+
*
|
|
730
|
+
* Uses `limit`/`offset` pagination. A FIFO queue of up to `lookahead` requests
|
|
731
|
+
* 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.
|
|
722
737
|
*
|
|
723
|
-
*
|
|
724
|
-
*
|
|
725
|
-
*
|
|
738
|
+
* Iteration stops at the first short page (length < `pageSize`) — in-flight
|
|
739
|
+
* requests past that point are discarded. `MAX_PAGES` is a hard cap on the
|
|
740
|
+
* number of requests issued.
|
|
726
741
|
*
|
|
727
742
|
* @example
|
|
728
743
|
* ```ts
|
|
@@ -732,7 +747,7 @@ declare function listDocuments(arbi: ArbiClient): Promise<{
|
|
|
732
747
|
* ```
|
|
733
748
|
*
|
|
734
749
|
* @param arbi - Authenticated ArbiClient
|
|
735
|
-
* @param options - Pagination options (pageSize, order, fields, signal)
|
|
750
|
+
* @param options - Pagination options (pageSize, order, fields, signal, lookahead)
|
|
736
751
|
* @yields Pages of documents until the backend returns a short page or signal is aborted
|
|
737
752
|
*/
|
|
738
753
|
declare function listPaginated(arbi: ArbiClient, options?: ListPaginatedOptions): AsyncGenerator<DocResponse[]>;
|
|
@@ -625,6 +625,13 @@ interface ListPaginatedOptions {
|
|
|
625
625
|
* AbortSignal to cancel iteration mid-stream.
|
|
626
626
|
*/
|
|
627
627
|
signal?: AbortSignal;
|
|
628
|
+
/**
|
|
629
|
+
* Number of pages kept in flight concurrently. A higher value hides more
|
|
630
|
+
* backend + network latency between pages but increases peak backend load
|
|
631
|
+
* and memory for not-yet-consumed pages. Clamped to `[1, MAX_PAGES]`.
|
|
632
|
+
* @default 3
|
|
633
|
+
*/
|
|
634
|
+
lookahead?: number;
|
|
628
635
|
}
|
|
629
636
|
/**
|
|
630
637
|
* Options for `listAll` — collects all pages into a single array.
|
|
@@ -718,11 +725,19 @@ declare function listDocuments(arbi: ArbiClient): Promise<{
|
|
|
718
725
|
} | null | undefined;
|
|
719
726
|
}[]>;
|
|
720
727
|
/**
|
|
721
|
-
* Async iterator that yields pages of documents
|
|
728
|
+
* Async iterator that yields pages of documents with a configurable lookahead.
|
|
729
|
+
*
|
|
730
|
+
* Uses `limit`/`offset` pagination. A FIFO queue of up to `lookahead` requests
|
|
731
|
+
* 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.
|
|
722
737
|
*
|
|
723
|
-
*
|
|
724
|
-
*
|
|
725
|
-
*
|
|
738
|
+
* Iteration stops at the first short page (length < `pageSize`) — in-flight
|
|
739
|
+
* requests past that point are discarded. `MAX_PAGES` is a hard cap on the
|
|
740
|
+
* number of requests issued.
|
|
726
741
|
*
|
|
727
742
|
* @example
|
|
728
743
|
* ```ts
|
|
@@ -732,7 +747,7 @@ declare function listDocuments(arbi: ArbiClient): Promise<{
|
|
|
732
747
|
* ```
|
|
733
748
|
*
|
|
734
749
|
* @param arbi - Authenticated ArbiClient
|
|
735
|
-
* @param options - Pagination options (pageSize, order, fields, signal)
|
|
750
|
+
* @param options - Pagination options (pageSize, order, fields, signal, lookahead)
|
|
736
751
|
* @yields Pages of documents until the backend returns a short page or signal is aborted
|
|
737
752
|
*/
|
|
738
753
|
declare function listPaginated(arbi: ArbiClient, options?: ListPaginatedOptions): AsyncGenerator<DocResponse[]>;
|
package/dist/browser.cjs
CHANGED
|
@@ -4160,13 +4160,11 @@ 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 } = options;
|
|
4164
|
-
|
|
4165
|
-
let pagesFetched = 0;
|
|
4166
|
-
while (!signal?.aborted && pagesFetched < MAX_PAGES) {
|
|
4163
|
+
const { pageSize = 5e3, order = "id_asc", fields, signal, lookahead = 3 } = options;
|
|
4164
|
+
const fetchPage = async (pageOffset) => {
|
|
4167
4165
|
const query = {
|
|
4168
4166
|
limit: pageSize,
|
|
4169
|
-
offset,
|
|
4167
|
+
offset: pageOffset,
|
|
4170
4168
|
order
|
|
4171
4169
|
};
|
|
4172
4170
|
if (fields) query.fields = fields;
|
|
@@ -4177,16 +4175,40 @@ async function* listPaginated(arbi, options = {}) {
|
|
|
4177
4175
|
if (error) {
|
|
4178
4176
|
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
|
|
4179
4177
|
}
|
|
4178
|
+
return data ?? [];
|
|
4179
|
+
};
|
|
4180
|
+
if (signal?.aborted) return;
|
|
4181
|
+
const depth = Math.max(1, Math.min(lookahead, MAX_PAGES));
|
|
4182
|
+
let issued = 0;
|
|
4183
|
+
let pagesYielded = 0;
|
|
4184
|
+
let nextOffsetToIssue = 0;
|
|
4185
|
+
let done = false;
|
|
4186
|
+
const queue = [];
|
|
4187
|
+
const tryEnqueue = () => {
|
|
4188
|
+
while (!done && queue.length < depth && issued < MAX_PAGES) {
|
|
4189
|
+
const p2 = fetchPage(nextOffsetToIssue);
|
|
4190
|
+
p2.catch(() => {
|
|
4191
|
+
});
|
|
4192
|
+
queue.push(p2);
|
|
4193
|
+
nextOffsetToIssue += pageSize;
|
|
4194
|
+
issued++;
|
|
4195
|
+
}
|
|
4196
|
+
};
|
|
4197
|
+
tryEnqueue();
|
|
4198
|
+
while (queue.length > 0 && !signal?.aborted) {
|
|
4199
|
+
const page = await queue.shift();
|
|
4180
4200
|
if (signal?.aborted) return;
|
|
4181
|
-
const
|
|
4201
|
+
const isShort = page.length < pageSize;
|
|
4202
|
+
if (isShort) done = true;
|
|
4203
|
+
tryEnqueue();
|
|
4182
4204
|
if (page.length > 0) {
|
|
4183
4205
|
yield page;
|
|
4184
|
-
|
|
4185
|
-
pagesFetched++;
|
|
4206
|
+
pagesYielded++;
|
|
4186
4207
|
}
|
|
4187
|
-
if (
|
|
4208
|
+
if (isShort) return;
|
|
4209
|
+
if (pagesYielded >= MAX_PAGES) break;
|
|
4188
4210
|
}
|
|
4189
|
-
if (
|
|
4211
|
+
if (!signal?.aborted && !done && pagesYielded >= MAX_PAGES) {
|
|
4190
4212
|
console.warn(
|
|
4191
4213
|
`[arbi-sdk] listPaginated hit MAX_PAGES (${MAX_PAGES}) \u2014 stopped. Workspace may have more than ${MAX_PAGES * pageSize} documents.`
|
|
4192
4214
|
);
|