Skip to content
This repository was archived by the owner on Mar 28, 2025. It is now read-only.

Commit 16d3636

Browse files
authored
update types (#28)
1 parent fc5a800 commit 16d3636

File tree

3 files changed

+72
-27
lines changed

3 files changed

+72
-27
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "getindexify",
3-
"version": "0.0.35",
3+
"version": "0.0.36",
44
"description": "This is the TypeScript client for interacting with the Indexify service.",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

src/types.ts

+31-13
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export interface IIndex {
3232

3333
export interface IBaseContentMetadata {
3434
id: string;
35-
parent_id?: string;
35+
parent_id: string;
36+
root_content_id: string;
3637
namespace: string;
3738
name: string;
3839
mime_type: string;
@@ -41,7 +42,9 @@ export interface IBaseContentMetadata {
4142
created_at: number;
4243
source: string;
4344
size: number;
45+
hash: string;
4446
}
47+
4548
export interface IContentMetadata extends IBaseContentMetadata {
4649
content_url: string;
4750
}
@@ -62,18 +65,33 @@ export interface IExtractionPolicy {
6265
content_source?: string;
6366
}
6467

68+
export interface ITaskContentMetadata {
69+
id: string;
70+
parent_id: string;
71+
root_content_id: string;
72+
namespace: string;
73+
name: string;
74+
content_type: string;
75+
labels: Record<string, string>;
76+
storage_url: string;
77+
created_at: number;
78+
source: string;
79+
size_bytes: number;
80+
tombstoned: boolean;
81+
hash: string;
82+
extraction_policy_ids: Record<string, number>;
83+
}
84+
6585
export interface ITask {
66-
content_metadata: IContentMetadata;
86+
id: string;
6787
extractor: string;
68-
extraction_policy: string;
6988
extraction_policy_id: string;
70-
id: string;
71-
input_params: Record<string, string>;
89+
output_index_table_mapping: Record<string, string>;
90+
namespace: string;
91+
content_metadata: ITaskContentMetadata;
92+
input_params: { [key: string]: any };
7293
outcome: string;
73-
output_index_table_mapping: {
74-
embedding: string;
75-
};
76-
repository: string;
94+
index_tables: string[];
7795
}
7896

7997
export interface IDocument {
@@ -103,15 +121,16 @@ export interface IContentResp {
103121
}
104122

105123
export interface IExtractResponse {
106-
features: IFeature[]
107-
content: IContentResp[]
124+
features: IFeature[];
125+
content: IContentResp[];
108126
}
109-
110127
export interface ISearchIndexResponse {
111128
content_id: string;
112129
text: string;
113130
confidence_score: number;
114131
labels: Record<string, string>;
132+
content_metadata: IContentMetadata;
133+
root_content_metadata?: IContentMetadata;
115134
}
116135

117136
export interface IAddExtractorPolicyResponse {
@@ -123,4 +142,3 @@ export interface IMtlsConfig {
123142
keyPath: string;
124143
caPath?: string; // Optional, only if using a custom CA
125144
}
126-

tests/client.test.ts

+40-13
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,53 @@
11
import { IndexifyClient } from "../src";
22
import { IExtractionPolicy } from "../src/types";
33
import { isAxiosError } from "axios";
4+
45
const fs = require("fs");
56

67
jest.setTimeout(30000);
78

9+
function generateNanoId(length: number = 21): string {
10+
const characters =
11+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
12+
let result = "";
13+
for (let i = 0; i < length; i++) {
14+
const randomIndex = Math.floor(Math.random() * characters.length);
15+
result += characters[randomIndex];
16+
}
17+
return result;
18+
}
19+
820
test("Create Client", async () => {
921
const client = await IndexifyClient.createClient();
1022
expect(client.namespace).toBe("default");
1123
});
1224

1325
test("Create Namespace", async () => {
26+
const nanoid = generateNanoId(8);
27+
const namespaceName = `testnamespace.${nanoid}`;
1428
const client = await IndexifyClient.createNamespace({
15-
namespace: "testnamespace",
29+
namespace: namespaceName,
1630
extraction_policies: [
1731
{
32+
id: nanoid,
1833
extractor: "tensorlake/minilm-l6",
19-
name: "testpolicy",
34+
name: `testpolicy`,
2035
},
2136
],
37+
}).catch((e) => {
38+
if (isAxiosError(e)) {
39+
console.log(e.response?.data);
40+
}
41+
console.log("error creating namespace");
42+
throw e;
2243
});
2344

24-
expect(client.namespace).toBe("testnamespace");
45+
expect(client.namespace).toBe(namespaceName);
2546
// test get namespaces
2647
const namespaces = await IndexifyClient.namespaces();
27-
expect(
28-
namespaces.filter((item) => item.name === "testnamespace").length
29-
).toBe(1);
48+
expect(namespaces.filter((item) => item.name === namespaceName).length).toBe(
49+
1
50+
);
3051
});
3152

3253
test("Get Extractors", async () => {
@@ -36,8 +57,9 @@ test("Get Extractors", async () => {
3657
});
3758

3859
test("Add Documents", async () => {
60+
const nanoid = generateNanoId(8);
3961
const client = await IndexifyClient.createNamespace({
40-
namespace: "test.adddocuments",
62+
namespace: `test.adddocuments.${nanoid}`,
4163
});
4264

4365
// add single documents
@@ -71,14 +93,16 @@ test("Add Documents", async () => {
7193
});
7294

7395
test("Search", async () => {
96+
const nanoid = generateNanoId(8);
97+
7498
const policy: IExtractionPolicy = {
7599
extractor: "tensorlake/minilm-l6",
76-
name: "minilml6",
100+
name: `minilml6.${nanoid}`,
77101
labels_eq: "source:test",
78102
};
79103

80104
const client = await IndexifyClient.createNamespace({
81-
namespace: "testsearch",
105+
namespace: `testsearch.${nanoid}`,
82106
});
83107

84108
const resp = await client.addExtractionPolicy(policy);
@@ -91,9 +115,10 @@ test("Search", async () => {
91115
{ text: "This is a test2", labels: { source: "test" } },
92116
]);
93117

94-
await new Promise((r) => setTimeout(r, 15000));
118+
await new Promise((r) => setTimeout(r, 10000));
95119

96120
const searchResult = await client.searchIndex(indexName, "test", 3);
121+
console.log(searchResult);
97122
expect(searchResult.length).toBe(2);
98123
});
99124

@@ -114,8 +139,9 @@ test("Upload file", async () => {
114139
});
115140

116141
test("Get content", async () => {
142+
const nanoid = generateNanoId(8);
117143
const client = await IndexifyClient.createNamespace({
118-
namespace: "testgetcontent",
144+
namespace: `testgetcontent.${nanoid}`,
119145
});
120146
await client.addDocuments([
121147
{ text: "This is a test1", labels: { source: "test" } },
@@ -136,8 +162,9 @@ test("Get content", async () => {
136162
});
137163

138164
test("Download content", async () => {
165+
const nanoid = generateNanoId(8);
139166
const client = await IndexifyClient.createNamespace({
140-
namespace: "testgetcontent",
167+
namespace: `testgetcontent.${nanoid}`,
141168
});
142169
await client.addDocuments([
143170
{ text: "This is a download", labels: { source: "testdownload" } },
@@ -175,7 +202,7 @@ test("Ingest remote url", async () => {
175202
);
176203
});
177204

178-
test.only("Test Extract Method", async () => {
205+
test("Test Extract Method", async () => {
179206
// Test minilm feature extract
180207
const client = await IndexifyClient.createClient();
181208
const res = await client.extract({

0 commit comments

Comments
 (0)