Skip to content
Merged
Show file tree
Hide file tree
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
33 changes: 0 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,39 +138,6 @@ On timeout, an `APIConnectionTimeoutError` is thrown.

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

## Auto-pagination

List methods in the ZeroEntropy API are paginated.
You can use the `for await … of` syntax to iterate through items across all pages:

```ts
async function fetchAllDocuments(params) {
const allDocuments = [];
// Automatically fetches more pages as needed.
for await (const documentGetInfoListResponse of client.documents.getInfoList({
collection_name: 'example_collection',
})) {
allDocuments.push(documentGetInfoListResponse);
}
return allDocuments;
}
```

Alternatively, you can request a single page at a time:

```ts
let page = await client.documents.getInfoList({ collection_name: 'example_collection' });
for (const documentGetInfoListResponse of page.documents) {
console.log(documentGetInfoListResponse);
}

// Convenience methods are provided for manually paginating:
while (page.hasNextPage()) {
page = await page.getNextPage();
// ...
}
```

## Advanced Usage

### Accessing raw Response data (e.g., headers)
Expand Down
2 changes: 1 addition & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Methods:
- <code title="post /documents/delete-document">client.documents.<a href="./src/resources/documents.ts">delete</a>({ ...params }) -> DocumentDeleteResponse</code>
- <code title="post /documents/add-document">client.documents.<a href="./src/resources/documents.ts">add</a>({ ...params }) -> DocumentAddResponse</code>
- <code title="post /documents/get-document-info">client.documents.<a href="./src/resources/documents.ts">getInfo</a>({ ...params }) -> DocumentGetInfoResponse</code>
- <code title="post /documents/get-document-info-list">client.documents.<a href="./src/resources/documents.ts">getInfoList</a>({ ...params }) -> DocumentGetInfoListResponsesGetDocumentInfoListCursor</code>
- <code title="post /documents/get-document-info-list">client.documents.<a href="./src/resources/documents.ts">getInfoList</a>({ ...params }) -> DocumentGetInfoListResponse</code>
- <code title="post /documents/get-page-info">client.documents.<a href="./src/resources/documents.ts">getPageInfo</a>({ ...params }) -> DocumentGetPageInfoResponse</code>

# Queries
Expand Down
4 changes: 0 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
DocumentDeleteResponse,
DocumentGetInfoListParams,
DocumentGetInfoListResponse,
DocumentGetInfoListResponsesGetDocumentInfoListCursor,
DocumentGetInfoParams,
DocumentGetInfoResponse,
DocumentGetPageInfoParams,
Expand Down Expand Up @@ -205,8 +204,6 @@ ZeroEntropy.Admin = Admin;
ZeroEntropy.Status = Status;
ZeroEntropy.Collections = Collections;
ZeroEntropy.Documents = Documents;
ZeroEntropy.DocumentGetInfoListResponsesGetDocumentInfoListCursor =
DocumentGetInfoListResponsesGetDocumentInfoListCursor;
ZeroEntropy.Queries = Queries;
ZeroEntropy.Parsers = Parsers;
export declare namespace ZeroEntropy {
Expand Down Expand Up @@ -248,7 +245,6 @@ export declare namespace ZeroEntropy {
type DocumentGetInfoResponse as DocumentGetInfoResponse,
type DocumentGetInfoListResponse as DocumentGetInfoListResponse,
type DocumentGetPageInfoResponse as DocumentGetPageInfoResponse,
DocumentGetInfoListResponsesGetDocumentInfoListCursor as DocumentGetInfoListResponsesGetDocumentInfoListCursor,
type DocumentUpdateParams as DocumentUpdateParams,
type DocumentDeleteParams as DocumentDeleteParams,
type DocumentAddParams as DocumentAddParams,
Expand Down
71 changes: 39 additions & 32 deletions src/resources/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { APIResource } from '../resource';
import * as Core from '../core';
import { GetDocumentInfoListCursor, type GetDocumentInfoListCursorParams } from '../pagination';

export class Documents extends APIResource {
/**
Expand Down Expand Up @@ -80,12 +79,8 @@ export class Documents extends APIResource {
getInfoList(
body: DocumentGetInfoListParams,
options?: Core.RequestOptions,
): Core.PagePromise<DocumentGetInfoListResponsesGetDocumentInfoListCursor, DocumentGetInfoListResponse> {
return this._client.getAPIList(
'/documents/get-document-info-list',
DocumentGetInfoListResponsesGetDocumentInfoListCursor,
{ body, method: 'post', ...options },
);
): Core.APIPromise<DocumentGetInfoListResponse> {
return this._client.post('/documents/get-document-info-list', { body, ...options });
}

/**
Expand All @@ -103,8 +98,6 @@ export class Documents extends APIResource {
}
}

export class DocumentGetInfoListResponsesGetDocumentInfoListCursor extends GetDocumentInfoListCursor<DocumentGetInfoListResponse> {}

export interface DocumentUpdateResponse {
new_id: string;

Expand Down Expand Up @@ -163,29 +156,35 @@ export namespace DocumentGetInfoResponse {
}

export interface DocumentGetInfoListResponse {
id: string;
documents: Array<DocumentGetInfoListResponse.Document>;
}

collection_name: string;
export namespace DocumentGetInfoListResponse {
export interface Document {
id: string;

index_status:
| 'not_parsed'
| 'parsing'
| 'not_indexed'
| 'indexing'
| 'indexed'
| 'parsing_failed'
| 'indexing_failed';
collection_name: string;

metadata: Record<string, string | Array<string>>;
index_status:
| 'not_parsed'
| 'parsing'
| 'not_indexed'
| 'indexing'
| 'indexed'
| 'parsing_failed'
| 'indexing_failed';

/**
* The number of pages in this document. This will be `null` if the document is
* parsing or failed to parse. It can also be `null` if the document is a filetype
* that does not support pages.
*/
num_pages: number | null;
metadata: Record<string, string | Array<string>>;

path: string;
/**
* The number of pages in this document. This will be `null` if the document is
* parsing or failed to parse. It can also be `null` if the document is a filetype
* that does not support pages.
*/
num_pages: number | null;

path: string;
}
}

export interface DocumentGetPageInfoResponse {
Expand Down Expand Up @@ -369,11 +368,23 @@ export interface DocumentGetInfoParams {
include_content?: boolean;
}

export interface DocumentGetInfoListParams extends GetDocumentInfoListCursorParams {
export interface DocumentGetInfoListParams {
/**
* The name of the collection.
*/
collection_name: string;

/**
* All documents returned will have a UUID strictly greater than the provided UUID.
* (Comparison will be on the binary representations of the UUIDs)
*/
id_gt?: string | null;

/**
* The maximum number of documents to return. This field is by default 1024, and
* cannot be set larger than 1024
*/
limit?: number;
}

export interface DocumentGetPageInfoParams {
Expand Down Expand Up @@ -404,9 +415,6 @@ export interface DocumentGetPageInfoParams {
include_content?: boolean;
}

Documents.DocumentGetInfoListResponsesGetDocumentInfoListCursor =
DocumentGetInfoListResponsesGetDocumentInfoListCursor;

export declare namespace Documents {
export {
type DocumentUpdateResponse as DocumentUpdateResponse,
Expand All @@ -415,7 +423,6 @@ export declare namespace Documents {
type DocumentGetInfoResponse as DocumentGetInfoResponse,
type DocumentGetInfoListResponse as DocumentGetInfoListResponse,
type DocumentGetPageInfoResponse as DocumentGetPageInfoResponse,
DocumentGetInfoListResponsesGetDocumentInfoListCursor as DocumentGetInfoListResponsesGetDocumentInfoListCursor,
type DocumentUpdateParams as DocumentUpdateParams,
type DocumentDeleteParams as DocumentDeleteParams,
type DocumentAddParams as DocumentAddParams,
Expand Down
1 change: 0 additions & 1 deletion src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export {
type CollectionGetListParams,
} from './collections';
export {
DocumentGetInfoListResponsesGetDocumentInfoListCursor,
Documents,
type DocumentUpdateResponse,
type DocumentDeleteResponse,
Expand Down