Skip to content

Commit 3140593

Browse files
committed
[ENH] add regeneration script for js library
1 parent 7a3f562 commit 3140593

18 files changed

+8716
-6162
lines changed

.github/workflows/_javascript-client-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ jobs:
99
steps:
1010
- name: Checkout
1111
uses: actions/checkout@v4
12+
- name: Setup Rust
13+
uses: ./.github/actions/rust
14+
with:
15+
github-token: ${{ github.token }}
1216
- uses: pnpm/action-setup@v3
1317
with:
1418
version: "9"

bin/ts-integration-test.sh

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,61 @@
22

33
set -e
44

5+
# Function to check if server is ready
6+
check_server() {
7+
curl -s http://localhost:8000/openapi.json > /dev/null
8+
return $?
9+
}
10+
11+
# Function to wait for server with exponential backoff
12+
wait_for_server() {
13+
local max_attempts=10
14+
local attempt=1
15+
local base_delay=1
16+
local max_delay=32
17+
18+
echo "Waiting for server to start..."
19+
while [ $attempt -le $max_attempts ]; do
20+
if check_server; then
21+
echo "Server is ready!"
22+
return 0
23+
fi
24+
25+
delay=$((base_delay * (2 ** (attempt - 1)))) # Exponential backoff
26+
delay=$((delay < max_delay ? delay : max_delay)) # Cap at max_delay
27+
28+
echo "Attempt $attempt/$max_attempts: Server not ready, waiting ${delay}s..."
29+
sleep $delay
30+
attempt=$((attempt + 1))
31+
done
32+
33+
echo "Error: Server failed to start after $max_attempts attempts"
34+
return 1
35+
}
36+
37+
# Start the Chroma server in the background
38+
echo "Building and starting Chroma server..."
39+
cargo build --bin chroma
40+
cargo run --bin chroma run &
41+
SERVER_PID=$!
42+
43+
# Wait for the server to be ready
44+
wait_for_server
45+
46+
# Install dependencies
547
cd clients/js
6-
pnpm -r test --verbose
48+
echo "Installing dependencies..."
49+
pnpm install
50+
pnpm i -g openapi-generator-plus @openapi-generator-plus/typescript-fetch-client-generator
51+
52+
# Generate the JS client
53+
echo "Generating JS client..."
54+
chmod +x genapi.sh
55+
./genapi.sh
56+
57+
# Cleanup: kill the server process
58+
kill $SERVER_PID
59+
60+
# Install dependencies and run tests
61+
echo "Running tests..."
62+
pnpm -r test --verbose

clients/js/genapi.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/usr/bin/env sh
22
set -e
33

4-
curl -s http://localhost:8000/openapi.json | jq > openapi.json
4+
# Run the transformation script instead of copying the file
5+
echo "Fetching and transforming OpenAPI specification..."
6+
python3 transform-openapi.py
57

8+
# Run the OpenAPI generator
9+
echo "Running OpenAPI generator..."
610
openapi-generator-plus -c config.yml
711

812
if [[ "$OSTYPE" == "darwin"* ]]; then
@@ -16,4 +20,4 @@ echo "import 'isomorphic-fetch';" > temp.txt
1620
cat packages/chromadb-core/src/generated/runtime.ts >> temp.txt
1721
mv temp.txt packages/chromadb-core/src/generated/runtime.ts
1822

19-
rm openapi.json
23+
rm openapi.json

clients/js/packages/chromadb-core/src/AdminClient.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class AdminClient {
150150
* ```
151151
*/
152152
public async createTenant({ name }: { name: string }): Promise<Tenant> {
153-
await this.api.createTenantV2({ name }, this.api.options);
153+
await this.api.createTenant({ name }, this.api.options);
154154

155155
return { name };
156156
}
@@ -172,7 +172,7 @@ export class AdminClient {
172172
* ```
173173
*/
174174
public async getTenant({ name }: { name: string }): Promise<Tenant> {
175-
const getTenant = (await this.api.getTenantV2(
175+
const getTenant = (await this.api.getTenant(
176176
name,
177177
this.api.options,
178178
)) as Tenant;
@@ -205,7 +205,7 @@ export class AdminClient {
205205
name: string;
206206
tenantName: string;
207207
}): Promise<{ name: string }> {
208-
await this.api.createDatabaseV2(tenantName, { name }, this.api.options);
208+
await this.api.createDatabase(tenantName, { name }, this.api.options);
209209

210210
return { name };
211211
}
@@ -235,9 +235,9 @@ export class AdminClient {
235235
name: string;
236236
tenantName: string;
237237
}): Promise<Database> {
238-
const result = (await this.api.getDatabaseV2(
239-
name,
238+
const result = (await this.api.getDatabase(
240239
tenantName,
240+
name,
241241
this.api.options,
242242
)) as Database;
243243

@@ -261,7 +261,7 @@ export class AdminClient {
261261
name: string;
262262
tenantName: string;
263263
}): Promise<void> {
264-
await this.api.deleteDatabaseV2(name, tenantName, this.api.options);
264+
await this.api.deleteDatabase(tenantName, name, this.api.options);
265265
return;
266266
}
267267

@@ -284,7 +284,7 @@ export class AdminClient {
284284
offset?: number;
285285
tenantName: string;
286286
}): Promise<Database[]> {
287-
const response = await this.api.listDatabasesV2(
287+
const response = await this.api.listDatabases(
288288
tenantName,
289289
limit,
290290
offset,

clients/js/packages/chromadb-core/src/ChromaClient.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class ChromaClient {
126126
*
127127
*/
128128
async getUserIdentity(): Promise<void> {
129-
const user_identity = (await this.api.getUserIdentityV2(
129+
const user_identity = (await this.api.getUserIdentity(
130130
this.api.options,
131131
)) as UserIdentity;
132132
const user_tenant = user_identity.tenant;
@@ -166,7 +166,7 @@ export class ChromaClient {
166166
*/
167167
async reset(): Promise<boolean> {
168168
await this.init();
169-
return await this.api.resetV2(this.api.options);
169+
return await this.api.reset(this.api.options);
170170
}
171171

172172
/**
@@ -180,7 +180,7 @@ export class ChromaClient {
180180
* ```
181181
*/
182182
async version(): Promise<string> {
183-
return await this.api.versionV2(this.api.options);
183+
return await this.api.version(this.api.options);
184184
}
185185

186186
/**
@@ -194,7 +194,7 @@ export class ChromaClient {
194194
* ```
195195
*/
196196
async heartbeat(): Promise<number> {
197-
const response = await this.api.heartbeatV2(this.api.options);
197+
const response = await this.api.heartbeat(this.api.options);
198198
return response["nanosecond heartbeat"];
199199
}
200200

@@ -226,22 +226,22 @@ export class ChromaClient {
226226
embeddingFunction = new DefaultEmbeddingFunction(),
227227
}: CreateCollectionParams): Promise<Collection> {
228228
await this.init();
229-
const newCollection = (await this.api.createCollectionV2(
229+
const newCollection = await this.api.createCollection(
230230
this.tenant,
231231
this.database,
232232
{
233233
name,
234234
// @ts-ignore: we need to generate the client libraries again
235235
configuration: null, //TODO: Configuration type in JavaScript
236-
metadata,
236+
metadata: metadata as any,
237237
},
238238
this.api.options,
239-
)) as CollectionParams;
239+
);
240240

241241
return wrapCollection(this, {
242242
name: newCollection.name,
243243
id: newCollection.id,
244-
metadata: newCollection.metadata,
244+
metadata: newCollection.metadata as CollectionMetadata | undefined,
245245
embeddingFunction,
246246
});
247247
}
@@ -273,23 +273,23 @@ export class ChromaClient {
273273
embeddingFunction = new DefaultEmbeddingFunction(),
274274
}: GetOrCreateCollectionParams): Promise<Collection> {
275275
await this.init();
276-
const newCollection = (await this.api.createCollectionV2(
276+
const newCollection = await this.api.createCollection(
277277
this.tenant,
278278
this.database,
279279
{
280280
name,
281281
// @ts-ignore: we need to generate the client libraries again
282282
configuration: null, //TODO: Configuration type in JavaScript
283-
metadata,
283+
metadata: metadata as any,
284284
get_or_create: true,
285285
},
286286
this.api.options,
287-
)) as CollectionParams;
287+
);
288288

289289
return wrapCollection(this, {
290290
name: newCollection.name,
291291
id: newCollection.id,
292-
metadata: newCollection.metadata,
292+
metadata: newCollection.metadata as CollectionMetadata | undefined,
293293
embeddingFunction,
294294
});
295295
}
@@ -315,7 +315,7 @@ export class ChromaClient {
315315
> {
316316
await this.init();
317317

318-
const response = (await this.api.listCollectionsV2(
318+
const response = (await this.api.listCollections(
319319
this.tenant,
320320
this.database,
321321
limit,
@@ -352,7 +352,7 @@ export class ChromaClient {
352352
}[]
353353
> {
354354
await this.init();
355-
const results = (await this.api.listCollectionsV2(
355+
const results = (await this.api.listCollections(
356356
this.tenant,
357357
this.database,
358358
limit,
@@ -376,7 +376,7 @@ export class ChromaClient {
376376
*/
377377
async countCollections(): Promise<number> {
378378
await this.init();
379-
const response = (await this.api.countCollectionsV2(
379+
const response = (await this.api.countCollections(
380380
this.tenant,
381381
this.database,
382382
this.api.options,
@@ -405,17 +405,17 @@ export class ChromaClient {
405405
embeddingFunction,
406406
}: GetCollectionParams): Promise<Collection> {
407407
await this.init();
408-
const response = (await this.api.getCollectionV2(
408+
const response = await this.api.getCollection(
409409
this.tenant,
410410
this.database,
411411
name,
412412
this.api.options,
413-
)) as CollectionParams;
413+
);
414414

415415
return wrapCollection(this, {
416416
id: response.id,
417417
name: response.name,
418-
metadata: response.metadata,
418+
metadata: response.metadata as CollectionMetadata | undefined,
419419
embeddingFunction:
420420
embeddingFunction !== undefined
421421
? embeddingFunction
@@ -440,10 +440,10 @@ export class ChromaClient {
440440
async deleteCollection({ name }: DeleteCollectionParams): Promise<void> {
441441
await this.init();
442442

443-
await this.api.deleteCollectionV2(
444-
name,
443+
await this.api.deleteCollection(
445444
this.tenant,
446445
this.database,
446+
name,
447447
this.api.options,
448448
);
449449
}

0 commit comments

Comments
 (0)