Skip to content

Commit 5efb23e

Browse files
committed
Allow lists of tenants when using helper methods
1 parent ce44c5e commit 5efb23e

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

src/collections/tenants/index.ts

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ const tenants = (
5252
return out;
5353
};
5454
return {
55-
create: (tenants: TenantBC | TenantCreate | (TenantBC | TenantCreate)[]) =>
55+
create: (tenants) =>
5656
new TenantsCreator(connection, collection, parseValueOrValueArray(tenants).map(Serialize.tenantCreate))
5757
.do()
5858
.then((res) => res.map(parseTenantREST)),
5959
get: async function () {
6060
const check = await dbVersionSupport.supportsTenantsGetGRPCMethod();
6161
return check.supports ? getGRPC() : getREST();
6262
},
63-
getByNames: <T extends TenantBase>(tenants: (string | T)[]) => getGRPC(tenants.map(parseStringOrTenant)),
64-
getByName: async <T extends TenantBase>(tenant: string | T) => {
63+
getByNames: (tenants) => getGRPC(tenants.map(parseStringOrTenant)),
64+
getByName: async (tenant) => {
6565
const tenantName = parseStringOrTenant(tenant);
6666
if (await dbVersionSupport.supportsTenantGetRESTMethod().then((check) => !check.supports)) {
6767
return getGRPC([tenantName]).then((tenants) => tenants[tenantName] ?? null);
@@ -76,30 +76,36 @@ const tenants = (
7676
throw err;
7777
});
7878
},
79-
remove: <T extends TenantBase>(tenants: string | T | (string | T)[]) =>
79+
remove: (tenants) =>
8080
new TenantsDeleter(
8181
connection,
8282
collection,
8383
parseValueOrValueArray(tenants).map(parseStringOrTenant)
8484
).do(),
8585
update,
86-
activate: (tenant: string | TenantBase) => {
87-
return update({
88-
name: parseStringOrTenant(tenant),
89-
activityStatus: 'ACTIVE',
90-
});
86+
activate: (tenant) => {
87+
return update(
88+
parseValueOrValueArray(tenant).map((tenant) => ({
89+
name: parseStringOrTenant(tenant),
90+
activityStatus: 'ACTIVE',
91+
}))
92+
);
9193
},
92-
deactivate: (tenant: string | TenantBase) => {
93-
return update({
94-
name: parseStringOrTenant(tenant),
95-
activityStatus: 'INACTIVE',
96-
});
94+
deactivate: (tenant) => {
95+
return update(
96+
parseValueOrValueArray(tenant).map((tenant) => ({
97+
name: parseStringOrTenant(tenant),
98+
activityStatus: 'INACTIVE',
99+
}))
100+
);
97101
},
98-
offload: (tenant: string | TenantBase) => {
99-
return update({
100-
name: parseStringOrTenant(tenant),
101-
activityStatus: 'OFFLOADED',
102-
});
102+
offload: (tenant) => {
103+
return update(
104+
parseValueOrValueArray(tenant).map((tenant) => ({
105+
name: parseStringOrTenant(tenant),
106+
activityStatus: 'OFFLOADED',
107+
}))
108+
);
103109
},
104110
};
105111
};
@@ -192,24 +198,24 @@ export interface Tenants {
192198
* Activate the specified tenant for a collection in Weaviate.
193199
* The collection must have been created with multi-tenancy enabled.
194200
*
195-
* @param {TenantBase | string} tenant The tenant to activate.
201+
* @param {string | TenantBase | (string | TenantBase)[]} tenant The tenant to activate.
196202
* @returns {Promise<Tenant[]>} The activated tenant as a list of Tenant.
197203
*/
198-
activate: (tenant: string | TenantBase) => Promise<Tenant[]>;
204+
activate: (tenant: string | TenantBase | (string | TenantBase)[]) => Promise<Tenant[]>;
199205
/**
200206
* Deactivate the specified tenant for a collection in Weaviate.
201207
* The collection must have been created with multi-tenancy enabled.
202208
*
203-
* @param {TenantBase | string} tenant The tenant to deactivate.
209+
* @param {string | TenantBase | (string | TenantBase)[]} tenant The tenant to deactivate.
204210
* @returns {Promise<Tenant[]>} The deactivated tenant as a list of Tenant
205211
*/
206-
deactivate: (tenant: string | TenantBase) => Promise<Tenant[]>;
212+
deactivate: (tenant: string | TenantBase | (string | TenantBase)[]) => Promise<Tenant[]>;
207213
/**
208214
* Offload the specified tenant for a collection in Weaviate.
209215
* The collection must have been created with multi-tenancy enabled.
210216
*
211-
* @param {TenantBase | string} tenant The tenant to offload.
217+
* @param {string | TenantBase | (string | TenantBase)[]} tenant The tenant to offload.
212218
* @returns {Promise<Tenant[]>} The offloaded tenant as a list of Tenant
213219
*/
214-
offload: (tenant: string | TenantBase) => Promise<Tenant[]>;
220+
offload: (tenant: string | TenantBase | (string | TenantBase)[]) => Promise<Tenant[]>;
215221
}

src/collections/tenants/integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ describe('Testing of the collection.tenants methods', () => {
187187
.then((tenants) => expect(tenants[tenantName].activityStatus).toBe('INACTIVE'));
188188

189189
await collection.tenants
190-
.activate(tenantName)
190+
.activate([tenantName])
191191
.then(() => collection.tenants.get())
192192
.then((tenants) => expect(tenants[tenantName].activityStatus).toBe('ACTIVE'));
193193
});

0 commit comments

Comments
 (0)