Skip to content

Commit

Permalink
Fix tests, allow tenant and db to be undefined in user-facing api
Browse files Browse the repository at this point in the history
  • Loading branch information
beggers committed Jan 4, 2024
1 parent a51e252 commit 4c7e737
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
26 changes: 13 additions & 13 deletions clients/js/src/AdminClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class AdminClient {
* @ignore
*/
private api: DefaultApi & ConfigOptions;
private apiAdapter: ClientAuthProtocolAdapter<any>|undefined;
private apiAdapter: ClientAuthProtocolAdapter<any> | undefined;
public tenant: string = DEFAULT_TENANT;
public database: string = DEFAULT_DATABASE;

Expand Down Expand Up @@ -146,10 +146,10 @@ export class AdminClient {
public async createTenant({
name,
}: {
name: string,
name: string | undefined,
}): Promise<Tenant> {
const newTenant = await this.api
.createTenant({name}, this.api.options)
.createTenant(name, this.api.options)
.then(handleSuccess)
.catch(handleError);

Expand All @@ -158,7 +158,7 @@ export class AdminClient {
throw new Error(newTenant.error);
}

return {name: name} as Tenant
return { name: name } as Tenant
}

/**
Expand All @@ -180,7 +180,7 @@ export class AdminClient {
public async getTenant({
name,
}: {
name: string,
name: string | undefined,
}): Promise<Tenant> {
const getTenant = await this.api
.getTenant(name, this.api.options)
Expand All @@ -191,7 +191,7 @@ export class AdminClient {
throw new Error(getTenant.error);
}

return {name: getTenant.name} as Tenant
return { name: getTenant.name } as Tenant
}

/**
Expand All @@ -216,11 +216,11 @@ export class AdminClient {
name,
tenantName
}: {
name: string,
tenantName: string,
name: string | undefined,
tenantName: string | undefined,
}): Promise<Database> {
const newDatabase = await this.api
.createDatabase(tenantName, {name}, this.api.options)
.createDatabase(name, tenantName, this.api.options)
.then(handleSuccess)
.catch(handleError);

Expand All @@ -229,7 +229,7 @@ export class AdminClient {
throw new Error(newDatabase.error);
}

return {name: name} as Database
return { name: name } as Database
}

/**
Expand All @@ -254,8 +254,8 @@ export class AdminClient {
name,
tenantName
}: {
name: string,
tenantName: string,
name: string | undefined,
tenantName: string | undefined,
}): Promise<Database> {
const getDatabase = await this.api
.getDatabase(name, tenantName, this.api.options)
Expand All @@ -266,7 +266,7 @@ export class AdminClient {
throw new Error(getDatabase.error);
}

return {name: getDatabase.name} as Database
return { name: getDatabase.name } as Database
}

}
4 changes: 2 additions & 2 deletions clients/js/src/ChromaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export class ChromaClient {
*/
private api: DefaultApi & ConfigOptions;
private apiAdapter: ClientAuthProtocolAdapter<any> | undefined;
private tenant: string = DEFAULT_TENANT;
private database: string = DEFAULT_DATABASE;
private tenant: string | undefined;
private database: string | undefined;
private _adminClient?: AdminClient

/**
Expand Down
18 changes: 10 additions & 8 deletions clients/js/src/CloudClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down

0 comments on commit 4c7e737

Please sign in to comment.