Skip to content

Commit

Permalink
support totals for getExtractedContent getTasks (#38)
Browse files Browse the repository at this point in the history
lucasjacks0n authored Jun 18, 2024

Verified

This commit was signed with the committer’s verified signature.
rouault Even Rouault
1 parent 477eb08 commit 901bd3c
Showing 3 changed files with 54 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "getindexify",
"version": "0.0.46",
"version": "0.0.47",
"description": "This is the TypeScript client for interacting with the Indexify service.",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
24 changes: 16 additions & 8 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ import {
IMtlsConfig,
IContent,
IExtractResponse,
IExtractionPolicy,
IExtractedMetadata,
} from "./types";
import { v4 as uuidv4 } from "uuid";
@@ -229,25 +228,31 @@ class IndexifyClient {
labelsEq,
startId,
limit,
returnTotal = false,
}: {
parentId?: string;
source?: string;
labelsEq?: string;
startId?: string;
limit?: number;
} = {}): Promise<IContentMetadata[]> {
returnTotal?: boolean;
} = {}): Promise<{ contentList: IContentMetadata[]; total?: number }> {
const resp = await this.client.get("content", {
params: {
parent_id: parentId,
labels_eq: labelsEq,
source,
start_id: startId,
limit,
return_total: returnTotal,
},
});
return resp.data.content_list.map((content: IBaseContentMetadata) => {
return this.baseContentToContentMetadata(content);
});
const contentList = resp.data.content_list.map(
(content: IBaseContentMetadata) => {
return this.baseContentToContentMetadata(content);
}
);
return { contentList, total: resp.data.total };
}

async addDocuments(
@@ -331,21 +336,24 @@ class IndexifyClient {
extractionPolicyId,
startId,
limit,
returnTotal = false,
}: {
contentId?: string;
extractionPolicyId?: string;
startId?: string;
limit?: number;
}): Promise<ITask[]> {
returnTotal: boolean;
}): Promise<{ tasks: ITask[]; total?: number }> {
const resp = await this.client.get("tasks", {
params: {
content_id: contentId,
extraction_policy: extractionPolicyId,
start_id: startId,
limit,
return_total: returnTotal,
},
});
return resp.data.tasks;
return { tasks: resp.data.tasks, total: resp.data.total };
}

async getSchemas(): Promise<ISchema[]> {
@@ -358,7 +366,7 @@ class IndexifyClient {
fileInput: string | Blob,
labels: Record<string, any> = {},
id?: string
): Promise<string> {
): Promise<string> {
function isBlob(input: any): input is Blob {
return input instanceof Blob;
}
52 changes: 37 additions & 15 deletions tests/client.test.ts
Original file line number Diff line number Diff line change
@@ -102,8 +102,8 @@ test("addDocuments", async () => {
{ text: "This is a mixed test 2", labels: {} },
]);

const content = await client.getExtractedContent();
expect(content.length).toBe(8);
const {contentList} = await client.getExtractedContent();
expect(contentList.length).toBe(8);
});

test("searchIndex", async () => {
@@ -154,7 +154,7 @@ test("uploadFile", async () => {
});
});

test("getExtractedContent", async () => {
test.only("getExtractedContent", async () => {
const nanoid = generateNanoId(8);
const client = await IndexifyClient.createNamespace({
name: `testgetcontent.${nanoid}`,
@@ -172,17 +172,27 @@ test("getExtractedContent", async () => {
{ text: "This is a test2", labels: { source: "test" } },
]);

let content;

content = await client.getExtractedContent({ parentId: "idontexist" });
expect(content.length).toBe(0);
let contentList;
let resp = await client.getExtractedContent({
parentId: "idontexist",
});
contentList = resp.contentList
expect(contentList.length).toBe(0);

content = await client.getExtractedContent({ labelsEq: "source:test" });
expect(content.length).toBe(2);
expect(content[0].content_url).toContain("http://");
resp = await client.getExtractedContent({
labelsEq: "source:test",
returnTotal:true
});
contentList = resp.contentList
expect(contentList.length).toBe(2);
expect(resp.total).toBe(2);
expect(contentList[0].content_url).toContain("http://");

content = await client.getExtractedContent({ labelsEq: "source:nothing" });
expect(content.length).toBe(0);
resp = await client.getExtractedContent({
labelsEq: "source:nothing",
});
contentList = resp.contentList
expect(contentList.length).toBe(0);
});

test("getStructuredMetadata", async () => {
@@ -249,12 +259,12 @@ test("downloadContent", async () => {
{ text: "This is a download", labels: { source: "testdownload" } },
]);

const content = await client.getExtractedContent({
const { contentList } = await client.getExtractedContent({
labelsEq: "source:testdownload",
});
expect(content.length).toBeGreaterThanOrEqual(1);
expect(contentList.length).toBeGreaterThanOrEqual(1);

const resData = await client.downloadContent<string>(content[0].id);
const resData = await client.downloadContent<string>(contentList[0].id);
expect(resData).toBe("This is a download");
});

@@ -354,6 +364,18 @@ test("generateUniqueHexId", async () => {
expect(client.generateUniqueHexId()).toHaveLength(16);
});

test("getTasks", async () => {
const nanoid = generateNanoId(8);
const namespaceName = `testgettasks.${nanoid}`;
const client = await IndexifyClient.createNamespace({name:namespaceName});
const { tasks, total } = await client.getTasks({
limit: 10,
returnTotal: true,
});
expect(tasks.length).toBe(0)
expect(total).toBe(0)
});

// test.only("MTLS", async () => {
// const fs = require("fs")
// const https = require("https")

0 comments on commit 901bd3c

Please sign in to comment.