Skip to content

Commit 6c5b1d3

Browse files
authored
Merge pull request #271 from weaviate/ux/add-collections-use-method-to-replace-get
Add `collections.use` and replace `collections.get` in tests with it
2 parents e30bd50 + 9100b2b commit 6c5b1d3

File tree

14 files changed

+51
-48
lines changed

14 files changed

+51
-48
lines changed

src/collections/aggregate/integration.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('Testing of the collection.aggregate methods', () => {
3939

4040
beforeAll(async () => {
4141
client = await weaviate.connectToLocal();
42-
collection = client.collections.get(collectionName);
42+
collection = client.collections.use(collectionName);
4343
return client.collections
4444
.create({
4545
name: collectionName,
@@ -168,7 +168,7 @@ describe('Testing of the collection.aggregate methods', () => {
168168
});
169169

170170
it('should aggregate data without a search and one non-generic property metric', async () => {
171-
const result = await (await client).collections.get(collectionName).aggregate.overAll({
171+
const result = await (await client).collections.use(collectionName).aggregate.overAll({
172172
returnMetrics: collection.metrics
173173
.aggregate('text')
174174
.text(['count', 'topOccurrencesOccurs', 'topOccurrencesValue']),
@@ -307,7 +307,7 @@ describe('Testing of the collection.aggregate methods with named vectors', () =>
307307

308308
beforeAll(async () => {
309309
client = await weaviate.connectToLocal();
310-
collection = client.collections.get(collectionName);
310+
collection = client.collections.use(collectionName);
311311
const query = () =>
312312
client.collections.create<TestCollectionAggregateVectors>({
313313
name: collectionName,
@@ -355,7 +355,7 @@ describe('Testing of collection.aggregate.overAll with a multi-tenancy collectio
355355

356356
beforeAll(async () => {
357357
client = await weaviate.connectToLocal();
358-
collection = client.collections.get(collectionName);
358+
collection = client.collections.use(collectionName);
359359
return client.collections
360360
.create({
361361
name: collectionName,
@@ -407,7 +407,7 @@ describe('Testing of collection.aggregate search methods', () => {
407407

408408
beforeAll(async () => {
409409
client = await weaviate.connectToLocal();
410-
collection = client.collections.get(collectionName);
410+
collection = client.collections.use(collectionName);
411411
return client.collections
412412
.create({
413413
name: collectionName,

src/collections/backup/integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Integration testing of backups', () => {
1111
grpcPort: 50061,
1212
});
1313

14-
const getCollection = (client: WeaviateClient) => client.collections.get('TestBackupCollection');
14+
const getCollection = (client: WeaviateClient) => client.collections.use('TestBackupCollection');
1515

1616
beforeAll(() =>
1717
clientPromise.then((client) =>

src/collections/config/integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ describe('Testing of the collection.config namespace', () => {
580580
vectorizer: 'none',
581581
})
582582
.do();
583-
const collection = client.collections.get(collectionName);
583+
const collection = client.collections.use(collectionName);
584584
const config = await collection.config
585585
.update({
586586
vectorizers: weaviate.reconfigure.vectorizer.update({
@@ -631,7 +631,7 @@ describe('Testing of the collection.config namespace', () => {
631631
return;
632632
}
633633
const collectionName = 'TestCollectionConfigUpdateGenerative';
634-
const collection = client.collections.get(collectionName);
634+
const collection = client.collections.use(collectionName);
635635
await client.collections.create({
636636
name: collectionName,
637637
vectorizers: weaviate.configure.vectorizer.none(),

src/collections/data/integration.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('Testing of the collection.data methods with a single target reference'
4040

4141
beforeAll(async () => {
4242
client = await weaviate.connectToLocal();
43-
collection = client.collections.get(collectionName);
43+
collection = client.collections.use(collectionName);
4444
await client.collections
4545
.create<TestCollectionData>({
4646
name: collectionName,
@@ -500,8 +500,8 @@ describe('Testing of the collection.data methods with a multi target reference',
500500

501501
beforeAll(async () => {
502502
client = await weaviate.connectToLocal();
503-
collectionOne = client.collections.get(classNameOne);
504-
collectionTwo = client.collections.get(classNameTwo);
503+
collectionOne = client.collections.use(classNameOne);
504+
collectionTwo = client.collections.use(classNameTwo);
505505
oneId = await client.collections
506506
.create({
507507
name: classNameOne,
@@ -1019,7 +1019,7 @@ describe('Testing of BYOV insertion with legacy vectorizer', () => {
10191019

10201020
it('should insert and retrieve many vectors using the new client', async () => {
10211021
const client = await weaviate.connectToLocal();
1022-
const collection = client.collections.get(collectionName);
1022+
const collection = client.collections.use(collectionName);
10231023
const { uuids, hasErrors } = await collection.data.insertMany([
10241024
{ vectors: [1, 2, 3] },
10251025
{ vectors: [4, 5, 6] },
@@ -1035,7 +1035,7 @@ describe('Testing of BYOV insertion with legacy vectorizer', () => {
10351035

10361036
it('should insert and retrieve single vectors using the new client', async () => {
10371037
const client = await weaviate.connectToLocal();
1038-
const collection = client.collections.get(collectionName);
1038+
const collection = client.collections.use(collectionName);
10391039
const id = await collection.data.insert({ vectors: [7, 8, 9] });
10401040
const object = await collection.query.fetchObjectById(id, { includeVector: true });
10411041
expect(object?.vectors.default).toEqual([7, 8, 9]);

src/collections/filters/integration.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Testing of the filter class with a simple collection', () => {
3232

3333
beforeAll(async () => {
3434
client = await weaviate.connectToLocal();
35-
collection = client.collections.get(collectionName);
35+
collection = client.collections.use(collectionName);
3636
ids = await client.collections
3737
.create({
3838
name: collectionName,
@@ -111,8 +111,8 @@ describe('Testing of the filter class with a simple collection', () => {
111111
});
112112

113113
it('should filter a fetch objects query with a single filter and non-generic collection', async () => {
114-
const res = await client.collections.get(collectionName).query.fetchObjects({
115-
filters: client.collections.get(collectionName).filter.byProperty('text').equal('two'),
114+
const res = await client.collections.use(collectionName).query.fetchObjects({
115+
filters: client.collections.use(collectionName).filter.byProperty('text').equal('two'),
116116
});
117117
expect(res.objects.length).toEqual(1);
118118
const obj = res.objects[0];
@@ -295,7 +295,7 @@ describe('Testing of the filter class with complex data types', () => {
295295

296296
beforeAll(async () => {
297297
client = await weaviate.connectToLocal();
298-
collection = client.collections.get(collectionName);
298+
collection = client.collections.use(collectionName);
299299
await client.collections
300300
.create<TestCollectionFilterComplex>({
301301
name: collectionName,

src/collections/generate/integration.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ maybe('Testing of the collection.generate methods with a simple collection', ()
4242

4343
beforeAll(async () => {
4444
client = await makeOpenAIClient();
45-
collection = client.collections.get(collectionName);
45+
collection = client.collections.use(collectionName);
4646
id = await client.collections
4747
.create({
4848
name: collectionName,
@@ -70,7 +70,7 @@ maybe('Testing of the collection.generate methods with a simple collection', ()
7070

7171
describe('using a non-generic collection', () => {
7272
it('should generate without search', async () => {
73-
const ret = await client.collections.get(collectionName).generate.fetchObjects({
73+
const ret = await client.collections.use(collectionName).generate.fetchObjects({
7474
singlePrompt: 'Write a haiku about ducks for {testProp}',
7575
groupedTask: 'What is the value of testProp here?',
7676
groupedProperties: ['testProp'],
@@ -183,7 +183,7 @@ maybe('Testing of the groupBy collection.generate methods with a simple collecti
183183

184184
beforeAll(async () => {
185185
client = await makeOpenAIClient();
186-
collection = client.collections.get(collectionName);
186+
collection = client.collections.use(collectionName);
187187
id = await client.collections
188188
.create({
189189
name: collectionName,
@@ -331,7 +331,7 @@ maybe('Testing of the collection.generate methods with a multi vector collection
331331

332332
beforeAll(async () => {
333333
client = await makeOpenAIClient();
334-
collection = client.collections.get(collectionName);
334+
collection = client.collections.use(collectionName);
335335
const query = () =>
336336
client.collections
337337
.create({

src/collections/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ const collections = (connection: Connection, dbVersionSupport: DbVersionSupport)
276276
get: <TProperties extends Properties | undefined = undefined, TName extends string = string>(
277277
name: TName
278278
) => collection<TProperties, TName>(connection, name, dbVersionSupport),
279+
use: <TProperties extends Properties | undefined = undefined, TName extends string = string>(
280+
name: TName
281+
) => collection<TProperties, TName>(connection, name, dbVersionSupport),
279282
};
280283
};
281284

@@ -292,9 +295,9 @@ export interface Collections {
292295
name: TName
293296
): Collection<TProperties, TName>;
294297
listAll(): Promise<CollectionConfig[]>;
295-
// use<TProperties extends Properties | undefined = undefined, TName extends string = string>(
296-
// name: TName
297-
// ): Collection<TProperties, TName>;
298+
use<TProperties extends Properties | undefined = undefined, TName extends string = string>(
299+
name: TName
300+
): Collection<TProperties, TName>;
298301
}
299302

300303
export default collections;

src/collections/integration.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Testing of the collections.create method', () => {
7777
},
7878
],
7979
})
80-
.then(() => contextionary.collections.get(collectionName).config.get());
80+
.then(() => contextionary.collections.use(collectionName).config.get());
8181
expect(response.name).toEqual(collectionName);
8282
expect(response.properties?.length).toEqual(1);
8383
expect(response.properties[0].name).toEqual('testProp');
@@ -166,7 +166,7 @@ describe('Testing of the collections.create method', () => {
166166
.create({
167167
name: collectionName,
168168
})
169-
.then(() => contextionary.collections.get(collectionName).config.get());
169+
.then(() => contextionary.collections.use(collectionName).config.get());
170170
expect(response.name).toEqual(collectionName);
171171
expect(response.properties?.length).toEqual(0);
172172
expect(response.vectorizers.default.indexConfig).toBeDefined();
@@ -188,7 +188,7 @@ describe('Testing of the collections.create method', () => {
188188
const response = await contextionary.collections
189189
.create(schema)
190190
.then(async (collection) => expect(await collection.exists()).toEqual(true))
191-
.then(() => contextionary.collections.get(collectionName).config.get());
191+
.then(() => contextionary.collections.use(collectionName).config.get());
192192
expect(response.name).toEqual(collectionName);
193193
expect(response.properties?.length).toEqual(1);
194194
expect(response.properties[0].name).toEqual('testProp');
@@ -525,7 +525,7 @@ describe('Testing of the collections.create method', () => {
525525
}),
526526
})
527527
.then(async (collection) => expect(await collection.exists()).toEqual(true))
528-
.then(() => cluster.collections.get(collectionName).config.get());
528+
.then(() => cluster.collections.use(collectionName).config.get());
529529

530530
expect(response.name).toEqual(collectionName);
531531
expect(response.description).toEqual('A test collection');
@@ -628,7 +628,7 @@ describe('Testing of the collections.create method', () => {
628628
vectorizers: weaviate.configure.vectorizer.text2VecContextionary(),
629629
})
630630
.then(async (collection) => expect(await collection.exists()).toEqual(true))
631-
.then(() => contextionary.collections.get(collectionName).config.get());
631+
.then(() => contextionary.collections.use(collectionName).config.get());
632632
expect(response.name).toEqual(collectionName);
633633
expect(response.properties?.length).toEqual(1);
634634
expect(response.properties?.[0].name).toEqual('testProp');
@@ -656,7 +656,7 @@ describe('Testing of the collections.create method', () => {
656656
vectorizers: weaviate.configure.vectorizer.text2VecOpenAI(),
657657
})
658658
.then(async (collection) => expect(await collection.exists()).toEqual(true))
659-
.then(() => openai.collections.get(collectionName).config.get());
659+
.then(() => openai.collections.use(collectionName).config.get());
660660
expect(response.name).toEqual(collectionName);
661661
expect(response.properties?.length).toEqual(1);
662662
expect(response.properties?.[0].name).toEqual('testProp');
@@ -684,7 +684,7 @@ describe('Testing of the collections.create method', () => {
684684
generative: weaviate.configure.generative.openAI(),
685685
})
686686
.then(async (collection) => expect(await collection.exists()).toEqual(true))
687-
.then(() => openai.collections.get(collectionName).config.get());
687+
.then(() => openai.collections.use(collectionName).config.get());
688688
expect(response.name).toEqual(collectionName);
689689
expect(response.properties?.length).toEqual(1);
690690
expect(response.properties?.[0].name).toEqual('testProp');

src/collections/iterator/integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('Testing of the collection.iterator method with a simple collection', (
2323

2424
beforeAll(async () => {
2525
client = await weaviate.connectToLocal({ port: 8080, grpcPort: 50051 });
26-
collection = client.collections.get(collectionName);
26+
collection = client.collections.use(collectionName);
2727
id = await client.collections
2828
.create({
2929
name: collectionName,

src/collections/query/integration.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Testing of the collection.query methods with a simple collection', ()
2727

2828
beforeAll(async () => {
2929
client = await weaviate.connectToLocal();
30-
collection = client.collections.get(collectionName);
30+
collection = client.collections.use(collectionName);
3131
id = await client.collections
3232
.create({
3333
name: collectionName,
@@ -111,7 +111,7 @@ describe('Testing of the collection.query methods with a simple collection', ()
111111
});
112112

113113
it('should query with bm25 and weighted query properties with a non-generic collection', async () => {
114-
const ret = await client.collections.get(collectionName).query.bm25('carrot', {
114+
const ret = await client.collections.use(collectionName).query.bm25('carrot', {
115115
queryProperties: [
116116
{
117117
name: 'testProp',
@@ -230,7 +230,7 @@ describe('Testing of the collection.query methods with a collection with a refer
230230

231231
beforeAll(async () => {
232232
client = await weaviate.connectToLocal();
233-
collection = client.collections.get(collectionName);
233+
collection = client.collections.use(collectionName);
234234
return client.collections
235235
.create({
236236
name: collectionName,
@@ -270,7 +270,7 @@ describe('Testing of the collection.query methods with a collection with a refer
270270

271271
describe('using a non-generic collection', () => {
272272
it('should query without searching returning the referenced object', async () => {
273-
const ret = await client.collections.get(collectionName).query.fetchObjects({
273+
const ret = await client.collections.use(collectionName).query.fetchObjects({
274274
returnProperties: ['testProp'],
275275
returnReferences: [
276276
{
@@ -450,7 +450,7 @@ describe('Testing of the collection.query methods with a collection with a neste
450450

451451
beforeAll(async () => {
452452
client = await weaviate.connectToLocal();
453-
collection = client.collections.get(collectionName);
453+
collection = client.collections.use(collectionName);
454454
return client.collections
455455
.create<TestCollectionQueryWithNestedProps>({
456456
name: collectionName,
@@ -575,7 +575,7 @@ describe('Testing of the collection.query methods with a collection with a multi
575575

576576
beforeAll(async () => {
577577
client = await weaviate.connectToLocal();
578-
collection = client.collections.get(collectionName);
578+
collection = client.collections.use(collectionName);
579579
const query = () =>
580580
client.collections
581581
.create<TestCollectionQueryWithMultiVector>({
@@ -1085,7 +1085,7 @@ describe('Testing of the groupBy collection.query methods with a simple collecti
10851085

10861086
beforeAll(async () => {
10871087
client = await weaviate.connectToLocal();
1088-
collection = client.collections.get(collectionName);
1088+
collection = client.collections.use(collectionName);
10891089
id = await client.collections
10901090
.create({
10911091
name: collectionName,
@@ -1207,7 +1207,7 @@ describe('Testing of the groupBy collection.query methods with a simple collecti
12071207
});
12081208

12091209
it('should groupBy with nearVector and a non-generic collection', async () => {
1210-
const ret = await client.collections.get(collectionName).query.nearVector(vector, {
1210+
const ret = await client.collections.use(collectionName).query.nearVector(vector, {
12111211
groupBy: {
12121212
numberOfGroups: 1,
12131213
objectsPerGroup: 1,
@@ -1246,7 +1246,7 @@ describe('Testing of the collection.query methods with a multi-tenancy collectio
12461246

12471247
beforeAll(async () => {
12481248
client = await weaviate.connectToLocal();
1249-
collection = client.collections.get(collectionName);
1249+
collection = client.collections.use(collectionName);
12501250
[id1, id2] = await client.collections
12511251
.create<TestCollectionMultiTenancy>({
12521252
name: collectionName,
@@ -1394,7 +1394,7 @@ describe('Testing of the collection.query methods with a multi-tenancy collectio
13941394
// 'X-OpenAI-Api-Key': process.env.OPENAI_APIKEY as string,
13951395
// },
13961396
// });
1397-
// collection = client.collections.get(collectionName);
1397+
// collection = client.collections.use(collectionName);
13981398
// [id1, id2] = await client.collections
13991399
// .create({
14001400
// name: collectionName,

src/collections/sort/integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ describe('Testing of the Sort class with a simple collection', () => {
3434

3535
beforeAll(async () => {
3636
client = await weaviate.connectToLocal();
37-
collection = client.collections.get(collectionName);
38-
collections = [collection, client.collections.get(collectionName)];
37+
collection = client.collections.use(collectionName);
38+
collections = [collection, client.collections.use(collectionName)];
3939
ids = await client.collections
4040
.create({
4141
name: collectionName,

src/collections/tenants/integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Testing of the collection.tenants methods', () => {
1717

1818
beforeAll(async () => {
1919
client = await weaviate.connectToLocal();
20-
collection = client.collections.get(collectionName);
20+
collection = client.collections.use(collectionName);
2121
return client.collections
2222
.create({
2323
name: collectionName,

src/collections/tenants/unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('Mock testing of tenants.get() method with a REST server', () => {
8282

8383
it('should get mocked tenants', async () => {
8484
const client = await weaviate.connectToLocal({ port: 8954, grpcPort: 8955 });
85-
const collection = client.collections.get(TENANTS_COLLECTION_NAME);
85+
const collection = client.collections.use(TENANTS_COLLECTION_NAME);
8686
const tenants = await collection.tenants.get();
8787
expect(tenants).toEqual<Record<string, Tenant>>({
8888
hot: { name: 'hot', activityStatus: 'ACTIVE' },
@@ -108,7 +108,7 @@ describe('Mock testing of tenants.get() method with a gRPC server', () => {
108108

109109
it('should get the mocked tenants', async () => {
110110
const client = await weaviate.connectToLocal({ port: 8956, grpcPort: 8957 });
111-
const collection = client.collections.get(TENANTS_COLLECTION_NAME);
111+
const collection = client.collections.use(TENANTS_COLLECTION_NAME);
112112
const tenants = await collection.tenants.get();
113113
expect(tenants).toEqual<Record<string, Tenant>>({
114114
hot: { name: 'hot', activityStatus: 'ACTIVE' },

0 commit comments

Comments
 (0)