Skip to content

Commit 4f364c5

Browse files
feat(api): manual updates
1 parent d68a8eb commit 4f364c5

File tree

6 files changed

+85
-56
lines changed

6 files changed

+85
-56
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 15
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/zeroentropy%2Fzeroentropy-f06c49dfd4b38a4f9d5bcad56348156bbf641aa8b7968acfbf655ad6ceff2126.yml
33
openapi_spec_hash: cac52dd65fbcb65ffa7a183e764b7f06
4-
config_hash: a7dc8380ffa9d78eee964a96e0eb7b54
4+
config_hash: 34c8a6deaedce51a258bc46b38c9caa0

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,39 @@ On timeout, an `APIConnectionTimeoutError` is thrown.
126126

127127
Note that requests which time out will be [retried twice by default](#retries).
128128

129+
## Auto-pagination
130+
131+
List methods in the ZeroEntropy API are paginated.
132+
You can use the `for await … of` syntax to iterate through items across all pages:
133+
134+
```ts
135+
async function fetchAllDocumentGetInfoListResponses(params) {
136+
const allDocumentGetInfoListResponses = [];
137+
// Automatically fetches more pages as needed.
138+
for await (const documentGetInfoListResponse of client.documents.getInfoList({
139+
collection_name: 'example_collection',
140+
})) {
141+
allDocumentGetInfoListResponses.push(documentGetInfoListResponse);
142+
}
143+
return allDocumentGetInfoListResponses;
144+
}
145+
```
146+
147+
Alternatively, you can request a single page at a time:
148+
149+
```ts
150+
let page = await client.documents.getInfoList({ collection_name: 'example_collection' });
151+
for (const documentGetInfoListResponse of page.documents) {
152+
console.log(documentGetInfoListResponse);
153+
}
154+
155+
// Convenience methods are provided for manually paginating:
156+
while (page.hasNextPage()) {
157+
page = await page.getNextPage();
158+
// ...
159+
}
160+
```
161+
129162
## Advanced Usage
130163

131164
### Accessing raw Response data (e.g., headers)

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Methods:
4949
- <code title="post /documents/delete-document">client.documents.<a href="./src/resources/documents.ts">delete</a>({ ...params }) -> DocumentDeleteResponse</code>
5050
- <code title="post /documents/add-document">client.documents.<a href="./src/resources/documents.ts">add</a>({ ...params }) -> DocumentAddResponse</code>
5151
- <code title="post /documents/get-document-info">client.documents.<a href="./src/resources/documents.ts">getInfo</a>({ ...params }) -> DocumentGetInfoResponse</code>
52-
- <code title="post /documents/get-document-info-list">client.documents.<a href="./src/resources/documents.ts">getInfoList</a>({ ...params }) -> DocumentGetInfoListResponse</code>
52+
- <code title="post /documents/get-document-info-list">client.documents.<a href="./src/resources/documents.ts">getInfoList</a>({ ...params }) -> DocumentGetInfoListResponsesGetDocumentInfoListCursor</code>
5353
- <code title="post /documents/get-page-info">client.documents.<a href="./src/resources/documents.ts">getPageInfo</a>({ ...params }) -> DocumentGetPageInfoResponse</code>
5454

5555
# Queries

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
DocumentDeleteResponse,
2525
DocumentGetInfoListParams,
2626
DocumentGetInfoListResponse,
27+
DocumentGetInfoListResponsesGetDocumentInfoListCursor,
2728
DocumentGetInfoParams,
2829
DocumentGetInfoResponse,
2930
DocumentGetPageInfoParams,
@@ -204,6 +205,8 @@ ZeroEntropy.Admin = Admin;
204205
ZeroEntropy.Status = Status;
205206
ZeroEntropy.Collections = Collections;
206207
ZeroEntropy.Documents = Documents;
208+
ZeroEntropy.DocumentGetInfoListResponsesGetDocumentInfoListCursor =
209+
DocumentGetInfoListResponsesGetDocumentInfoListCursor;
207210
ZeroEntropy.Queries = Queries;
208211
ZeroEntropy.Parsers = Parsers;
209212
export declare namespace ZeroEntropy {
@@ -245,6 +248,7 @@ export declare namespace ZeroEntropy {
245248
type DocumentGetInfoResponse as DocumentGetInfoResponse,
246249
type DocumentGetInfoListResponse as DocumentGetInfoListResponse,
247250
type DocumentGetPageInfoResponse as DocumentGetPageInfoResponse,
251+
DocumentGetInfoListResponsesGetDocumentInfoListCursor as DocumentGetInfoListResponsesGetDocumentInfoListCursor,
248252
type DocumentUpdateParams as DocumentUpdateParams,
249253
type DocumentDeleteParams as DocumentDeleteParams,
250254
type DocumentAddParams as DocumentAddParams,

src/resources/documents.ts

Lines changed: 45 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { APIResource } from '../resource';
44
import * as Core from '../core';
5+
import { GetDocumentInfoListCursor, type GetDocumentInfoListCursorParams } from '../pagination';
56

67
export class Documents extends APIResource {
78
/**
@@ -79,8 +80,12 @@ export class Documents extends APIResource {
7980
getInfoList(
8081
body: DocumentGetInfoListParams,
8182
options?: Core.RequestOptions,
82-
): Core.APIPromise<DocumentGetInfoListResponse> {
83-
return this._client.post('/documents/get-document-info-list', { body, ...options });
83+
): Core.PagePromise<DocumentGetInfoListResponsesGetDocumentInfoListCursor, DocumentGetInfoListResponse> {
84+
return this._client.getAPIList(
85+
'/documents/get-document-info-list',
86+
DocumentGetInfoListResponsesGetDocumentInfoListCursor,
87+
{ body, method: 'post', ...options },
88+
);
8489
}
8590

8691
/**
@@ -98,6 +103,8 @@ export class Documents extends APIResource {
98103
}
99104
}
100105

106+
export class DocumentGetInfoListResponsesGetDocumentInfoListCursor extends GetDocumentInfoListCursor<DocumentGetInfoListResponse> {}
107+
101108
export interface DocumentUpdateResponse {
102109
new_id: string;
103110

@@ -170,51 +177,45 @@ export namespace DocumentGetInfoResponse {
170177
}
171178

172179
export interface DocumentGetInfoListResponse {
173-
documents: Array<DocumentGetInfoListResponse.Document>;
174-
}
180+
id: string;
175181

176-
export namespace DocumentGetInfoListResponse {
177-
export interface Document {
178-
id: string;
182+
collection_name: string;
179183

180-
collection_name: string;
184+
created_at: string;
181185

182-
created_at: string;
186+
/**
187+
* A URL to the document data, which can be used to download the raw document
188+
* content or to display the document in frontend applications.
189+
*
190+
* NOTE: If a `/documents/update-document` call returned a new document id, then
191+
* this url will be invalidated and must be retrieved again.
192+
*/
193+
file_url: string;
183194

184-
/**
185-
* A URL to the document data, which can be used to download the raw document
186-
* content or to display the document in frontend applications.
187-
*
188-
* NOTE: If a `/documents/update-document` call returned a new document id, then
189-
* this url will be invalidated and must be retrieved again.
190-
*/
191-
file_url: string;
195+
index_status:
196+
| 'not_parsed'
197+
| 'parsing'
198+
| 'not_indexed'
199+
| 'indexing'
200+
| 'indexed'
201+
| 'parsing_failed'
202+
| 'indexing_failed';
192203

193-
index_status:
194-
| 'not_parsed'
195-
| 'parsing'
196-
| 'not_indexed'
197-
| 'indexing'
198-
| 'indexed'
199-
| 'parsing_failed'
200-
| 'indexing_failed';
204+
metadata: Record<string, string | Array<string>>;
201205

202-
metadata: Record<string, string | Array<string>>;
203-
204-
/**
205-
* The number of pages in this document. This will be `null` if the document is
206-
* parsing or failed to parse. It can also be `null` if the document is a filetype
207-
* that does not support pages.
208-
*/
209-
num_pages: number | null;
206+
/**
207+
* The number of pages in this document. This will be `null` if the document is
208+
* parsing or failed to parse. It can also be `null` if the document is a filetype
209+
* that does not support pages.
210+
*/
211+
num_pages: number | null;
210212

211-
path: string;
213+
path: string;
212214

213-
/**
214-
* The total size of the raw document data, in bytes.
215-
*/
216-
size: number;
217-
}
215+
/**
216+
* The total size of the raw document data, in bytes.
217+
*/
218+
size: number;
218219
}
219220

220221
export interface DocumentGetPageInfoResponse {
@@ -401,26 +402,12 @@ export interface DocumentGetInfoParams {
401402
include_content?: boolean;
402403
}
403404

404-
export interface DocumentGetInfoListParams {
405+
export interface DocumentGetInfoListParams extends GetDocumentInfoListCursorParams {
405406
/**
406407
* The name of the collection.
407408
*/
408409
collection_name: string;
409410

410-
/**
411-
* The maximum number of documents to return. This field is by default 1024, and
412-
* cannot be set larger than 1024
413-
*/
414-
limit?: number;
415-
416-
/**
417-
* All documents returned will have a path strictly greater than the provided
418-
* `path_gt` argument. (Comparison will be based on lexicographic comparison. It is
419-
* guaranteed that two strings are lexicographically equal if and only if they have
420-
* identical binary representations.).
421-
*/
422-
path_gt?: string | null;
423-
424411
/**
425412
* All documents returned will have a path that starts with the provided path
426413
* prefix.
@@ -456,6 +443,9 @@ export interface DocumentGetPageInfoParams {
456443
include_content?: boolean;
457444
}
458445

446+
Documents.DocumentGetInfoListResponsesGetDocumentInfoListCursor =
447+
DocumentGetInfoListResponsesGetDocumentInfoListCursor;
448+
459449
export declare namespace Documents {
460450
export {
461451
type DocumentUpdateResponse as DocumentUpdateResponse,
@@ -464,6 +454,7 @@ export declare namespace Documents {
464454
type DocumentGetInfoResponse as DocumentGetInfoResponse,
465455
type DocumentGetInfoListResponse as DocumentGetInfoListResponse,
466456
type DocumentGetPageInfoResponse as DocumentGetPageInfoResponse,
457+
DocumentGetInfoListResponsesGetDocumentInfoListCursor as DocumentGetInfoListResponsesGetDocumentInfoListCursor,
467458
type DocumentUpdateParams as DocumentUpdateParams,
468459
type DocumentDeleteParams as DocumentDeleteParams,
469460
type DocumentAddParams as DocumentAddParams,

src/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export {
1111
type CollectionGetListParams,
1212
} from './collections';
1313
export {
14+
DocumentGetInfoListResponsesGetDocumentInfoListCursor,
1415
Documents,
1516
type DocumentUpdateResponse,
1617
type DocumentDeleteResponse,

0 commit comments

Comments
 (0)