From 4c7e7372d241d021b6d048164908cebe2f27edd7 Mon Sep 17 00:00:00 2001 From: Ben Eggers Date: Wed, 3 Jan 2024 16:32:53 -0800 Subject: [PATCH] Fix tests, allow tenant and db to be undefined in user-facing api --- clients/js/src/AdminClient.ts | 26 +++++++++++++------------- clients/js/src/ChromaClient.ts | 4 ++-- clients/js/src/CloudClient.ts | 18 ++++++++++-------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/clients/js/src/AdminClient.ts b/clients/js/src/AdminClient.ts index 7de713e8d4e..959a48d83a8 100644 --- a/clients/js/src/AdminClient.ts +++ b/clients/js/src/AdminClient.ts @@ -25,7 +25,7 @@ export class AdminClient { * @ignore */ private api: DefaultApi & ConfigOptions; - private apiAdapter: ClientAuthProtocolAdapter|undefined; + private apiAdapter: ClientAuthProtocolAdapter | undefined; public tenant: string = DEFAULT_TENANT; public database: string = DEFAULT_DATABASE; @@ -146,10 +146,10 @@ export class AdminClient { public async createTenant({ name, }: { - name: string, + name: string | undefined, }): Promise { const newTenant = await this.api - .createTenant({name}, this.api.options) + .createTenant(name, this.api.options) .then(handleSuccess) .catch(handleError); @@ -158,7 +158,7 @@ export class AdminClient { throw new Error(newTenant.error); } - return {name: name} as Tenant + return { name: name } as Tenant } /** @@ -180,7 +180,7 @@ export class AdminClient { public async getTenant({ name, }: { - name: string, + name: string | undefined, }): Promise { const getTenant = await this.api .getTenant(name, this.api.options) @@ -191,7 +191,7 @@ export class AdminClient { throw new Error(getTenant.error); } - return {name: getTenant.name} as Tenant + return { name: getTenant.name } as Tenant } /** @@ -216,11 +216,11 @@ export class AdminClient { name, tenantName }: { - name: string, - tenantName: string, + name: string | undefined, + tenantName: string | undefined, }): Promise { const newDatabase = await this.api - .createDatabase(tenantName, {name}, this.api.options) + .createDatabase(name, tenantName, this.api.options) .then(handleSuccess) .catch(handleError); @@ -229,7 +229,7 @@ export class AdminClient { throw new Error(newDatabase.error); } - return {name: name} as Database + return { name: name } as Database } /** @@ -254,8 +254,8 @@ export class AdminClient { name, tenantName }: { - name: string, - tenantName: string, + name: string | undefined, + tenantName: string | undefined, }): Promise { const getDatabase = await this.api .getDatabase(name, tenantName, this.api.options) @@ -266,7 +266,7 @@ export class AdminClient { throw new Error(getDatabase.error); } - return {name: getDatabase.name} as Database + return { name: getDatabase.name } as Database } } diff --git a/clients/js/src/ChromaClient.ts b/clients/js/src/ChromaClient.ts index d7c96c9d6f7..7c1eaff9f71 100644 --- a/clients/js/src/ChromaClient.ts +++ b/clients/js/src/ChromaClient.ts @@ -19,8 +19,8 @@ export class ChromaClient { */ private api: DefaultApi & ConfigOptions; private apiAdapter: ClientAuthProtocolAdapter | undefined; - private tenant: string = DEFAULT_TENANT; - private database: string = DEFAULT_DATABASE; + private tenant: string | undefined; + private database: string | undefined; private _adminClient?: AdminClient /** diff --git a/clients/js/src/CloudClient.ts b/clients/js/src/CloudClient.ts index 9ce77d2f59d..16fdf5f43ab 100644 --- a/clients/js/src/CloudClient.ts +++ b/clients/js/src/CloudClient.ts @@ -6,14 +6,15 @@ import { ChromaClient } from "./ChromaClient"; interface CloudClientParams { apiKey?: string; - database?: string; + database?: string | undefined; + tenant?: string | undefined; cloudHost?: string; cloudPort?: string; } -class CloudClient extends ChromaClient{ +class CloudClient extends ChromaClient { - constructor({apiKey, database, cloudHost, cloudPort}: CloudClientParams) { + constructor({ apiKey, database, tenant, cloudHost, cloudPort }: CloudClientParams) { // If no API key is provided, try to load it from the environment variable if (!apiKey) { apiKey = process.env.CHROMA_API_KEY; @@ -27,16 +28,17 @@ class CloudClient extends ChromaClient{ const path = `${cloudHost}:${cloudPort}`; - const auth = { - provider: "token", - credentials: apiKey, - providerOptions: { headerType: "X_CHROMA_TOKEN" }, - } + const auth = { + provider: "token", + credentials: apiKey, + providerOptions: { headerType: "X_CHROMA_TOKEN" }, + } return new ChromaClient({ path: path, auth: auth, database: database, + tenant: tenant, }) super()