Skip to content

[ENH] add regeneration script for js library #4115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions .github/workflows/_javascript-client-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: ./.github/actions/rust
with:
github-token: ${{ github.token }}
- uses: pnpm/action-setup@v3
with:
version: "9"
Expand Down
57 changes: 56 additions & 1 deletion bin/ts-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,60 @@

set -e

# Function to check if server is ready
check_server() {
curl -s http://localhost:8000/openapi.json > /dev/null
return $?
}

# Function to wait for server with exponential backoff
wait_for_server() {
local max_attempts=10
local attempt=1
local base_delay=1
local max_delay=32

echo "Waiting for server to start..."
while [ $attempt -le $max_attempts ]; do
if check_server; then
echo "Server is ready!"
return 0
fi

delay=$((base_delay * (2 ** (attempt - 1)))) # Exponential backoff
delay=$((delay < max_delay ? delay : max_delay)) # Cap at max_delay

echo "Attempt $attempt/$max_attempts: Server not ready, waiting ${delay}s..."
sleep $delay
attempt=$((attempt + 1))
done

echo "Error: Server failed to start after $max_attempts attempts"
return 1
}

# Start the Chroma server in the background
echo "Building and starting Chroma server..."
cargo build --bin chroma
cargo run --bin chroma run &
SERVER_PID=$!

# Wait for the server to be ready
wait_for_server

# Install dependencies
cd clients/js
pnpm -r test --verbose
echo "Installing dependencies..."
pnpm i -g openapi-generator-plus @openapi-generator-plus/typescript-fetch-client-generator

# Generate the JS client
echo "Generating JS client..."
chmod +x genapi.sh
./genapi.sh

# Cleanup: kill the server process
kill $SERVER_PID

# Install dependencies and run tests
echo "Running tests..."
pnpm -r test --verbose
8 changes: 6 additions & 2 deletions clients/js/genapi.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env sh
set -e

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

# Run the OpenAPI generator
echo "Running OpenAPI generator..."
openapi-generator-plus -c config.yml

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

rm openapi.json
rm openapi.json
2 changes: 1 addition & 1 deletion clients/js/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chromadb-root",
"private": true,
"version": "2.2.0",
"version": "2.2.1",
"description": "A JavaScript interface for chroma",
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion clients/js/packages/chromadb-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chromadb-client",
"version": "2.2.0",
"version": "2.2.1",
"description": "A JavaScript interface for chroma with embedding functions as peer dependencies",
"license": "Apache-2.0",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion clients/js/packages/chromadb-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@internal/chromadb-core",
"version": "2.2.0",
"version": "2.2.1",
"private": true,
"description": "Core functionality for ChromaDB JavaScript client",
"license": "Apache-2.0",
Expand Down
14 changes: 7 additions & 7 deletions clients/js/packages/chromadb-core/src/AdminClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class AdminClient {
* ```
*/
public async createTenant({ name }: { name: string }): Promise<Tenant> {
await this.api.createTenantV2({ name }, this.api.options);
await this.api.createTenant({ name }, this.api.options);

return { name };
}
Expand All @@ -172,7 +172,7 @@ export class AdminClient {
* ```
*/
public async getTenant({ name }: { name: string }): Promise<Tenant> {
const getTenant = (await this.api.getTenantV2(
const getTenant = (await this.api.getTenant(
name,
this.api.options,
)) as Tenant;
Expand Down Expand Up @@ -205,7 +205,7 @@ export class AdminClient {
name: string;
tenantName: string;
}): Promise<{ name: string }> {
await this.api.createDatabaseV2(tenantName, { name }, this.api.options);
await this.api.createDatabase(tenantName, { name }, this.api.options);

return { name };
}
Expand Down Expand Up @@ -235,9 +235,9 @@ export class AdminClient {
name: string;
tenantName: string;
}): Promise<Database> {
const result = (await this.api.getDatabaseV2(
name,
const result = (await this.api.getDatabase(
tenantName,
name,
this.api.options,
)) as Database;

Expand All @@ -261,7 +261,7 @@ export class AdminClient {
name: string;
tenantName: string;
}): Promise<void> {
await this.api.deleteDatabaseV2(name, tenantName, this.api.options);
await this.api.deleteDatabase(tenantName, name, this.api.options);
return;
}

Expand All @@ -284,7 +284,7 @@ export class AdminClient {
offset?: number;
tenantName: string;
}): Promise<Database[]> {
const response = await this.api.listDatabasesV2(
const response = await this.api.listDatabases(
tenantName,
limit,
offset,
Expand Down
40 changes: 20 additions & 20 deletions clients/js/packages/chromadb-core/src/ChromaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class ChromaClient {
*
*/
async getUserIdentity(): Promise<void> {
const user_identity = (await this.api.getUserIdentityV2(
const user_identity = (await this.api.getUserIdentity(
this.api.options,
)) as UserIdentity;
const user_tenant = user_identity.tenant;
Expand Down Expand Up @@ -166,7 +166,7 @@ export class ChromaClient {
*/
async reset(): Promise<boolean> {
await this.init();
return await this.api.resetV2(this.api.options);
return await this.api.reset(this.api.options);
}

/**
Expand All @@ -180,7 +180,7 @@ export class ChromaClient {
* ```
*/
async version(): Promise<string> {
return await this.api.versionV2(this.api.options);
return await this.api.version(this.api.options);
}

/**
Expand All @@ -194,7 +194,7 @@ export class ChromaClient {
* ```
*/
async heartbeat(): Promise<number> {
const response = await this.api.heartbeatV2(this.api.options);
const response = await this.api.heartbeat(this.api.options);
return response["nanosecond heartbeat"];
}

Expand Down Expand Up @@ -226,22 +226,22 @@ export class ChromaClient {
embeddingFunction = new DefaultEmbeddingFunction(),
}: CreateCollectionParams): Promise<Collection> {
await this.init();
const newCollection = (await this.api.createCollectionV2(
const newCollection = await this.api.createCollection(
this.tenant,
this.database,
{
name,
// @ts-ignore: we need to generate the client libraries again
configuration: null, //TODO: Configuration type in JavaScript
metadata,
metadata: metadata,
},
this.api.options,
)) as CollectionParams;
);

return wrapCollection(this, {
name: newCollection.name,
id: newCollection.id,
metadata: newCollection.metadata,
metadata: newCollection.metadata as CollectionMetadata | undefined,
embeddingFunction,
});
}
Expand Down Expand Up @@ -273,23 +273,23 @@ export class ChromaClient {
embeddingFunction = new DefaultEmbeddingFunction(),
}: GetOrCreateCollectionParams): Promise<Collection> {
await this.init();
const newCollection = (await this.api.createCollectionV2(
const newCollection = await this.api.createCollection(
this.tenant,
this.database,
{
name,
// @ts-ignore: we need to generate the client libraries again
configuration: null, //TODO: Configuration type in JavaScript
metadata,
metadata: metadata,
get_or_create: true,
},
this.api.options,
)) as CollectionParams;
);

return wrapCollection(this, {
name: newCollection.name,
id: newCollection.id,
metadata: newCollection.metadata,
metadata: newCollection.metadata as CollectionMetadata | undefined,
embeddingFunction,
});
}
Expand All @@ -315,7 +315,7 @@ export class ChromaClient {
> {
await this.init();

const response = (await this.api.listCollectionsV2(
const response = (await this.api.listCollections(
this.tenant,
this.database,
limit,
Expand Down Expand Up @@ -352,7 +352,7 @@ export class ChromaClient {
}[]
> {
await this.init();
const results = (await this.api.listCollectionsV2(
const results = (await this.api.listCollections(
this.tenant,
this.database,
limit,
Expand All @@ -376,7 +376,7 @@ export class ChromaClient {
*/
async countCollections(): Promise<number> {
await this.init();
const response = (await this.api.countCollectionsV2(
const response = (await this.api.countCollections(
this.tenant,
this.database,
this.api.options,
Expand Down Expand Up @@ -405,17 +405,17 @@ export class ChromaClient {
embeddingFunction,
}: GetCollectionParams): Promise<Collection> {
await this.init();
const response = (await this.api.getCollectionV2(
const response = await this.api.getCollection(
this.tenant,
this.database,
name,
this.api.options,
)) as CollectionParams;
);

return wrapCollection(this, {
id: response.id,
name: response.name,
metadata: response.metadata,
metadata: response.metadata as CollectionMetadata | undefined,
embeddingFunction:
embeddingFunction !== undefined
? embeddingFunction
Expand All @@ -440,10 +440,10 @@ export class ChromaClient {
async deleteCollection({ name }: DeleteCollectionParams): Promise<void> {
await this.init();

await this.api.deleteCollectionV2(
name,
await this.api.deleteCollection(
this.tenant,
this.database,
name,
this.api.options,
);
}
Expand Down
Loading
Loading