Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion src/collections/deserialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,10 @@ export class Deserialize {
objects: verbose
? reply.objects.map((obj) => {
return {
id: stringify(obj.uuid),
// stringify() throws on anything but a 16-byte uuid; the server
// can omit the uuid on a BatchDeleteObject, so guard it here
// instead of letting an opaque TypeError escape.
id: obj.uuid.length === 16 ? stringify(obj.uuid) : undefined,
successful: obj.successful,
error: obj.error,
};
Expand Down
30 changes: 30 additions & 0 deletions src/collections/deserialize/unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { v4 } from 'uuid';
import { describe, expect, it } from 'vitest';
import { BatchDeleteReply } from '../../proto/v1/batch_delete.js';
import { Deserialize } from './index.js';

describe('Unit testing of Deserialize.deleteMany', () => {
const baseReply = (uuid: Uint8Array): BatchDeleteReply => ({
took: 0,
failed: 0,
matches: 1,
successful: 1,
objects: [{ uuid, successful: true, error: '' }],
});

it('should stringify a well-formed 16-byte uuid', () => {
const id = v4();
const uuid = Uint8Array.from(Buffer.from(id.replace(/-/g, ''), 'hex'));

const result = Deserialize.deleteMany(baseReply(uuid), true);

expect(result.objects![0].id).toBe(id);
});

it('should return an undefined id instead of throwing when the server omits the uuid', () => {
const result = Deserialize.deleteMany(baseReply(new Uint8Array(0)), true);

expect(result.objects![0].id).toBeUndefined();
expect(result.objects![0].successful).toBe(true);
});
});
3 changes: 2 additions & 1 deletion src/collections/types/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export type DataObject<T> = {
};

export type DeleteManyObject = {
id: string;
/** Undefined when the server returned no uuid for this object. */
id?: string;
successful: boolean;
error?: string;
};
Expand Down
2 changes: 1 addition & 1 deletion test/collections/journey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Journey testing of the client using a WCD cluster', () => {
dateOfBirth: Date;
};

afterAll(() => client.collections.delete(collectionName));
afterAll(() => client?.collections.delete(collectionName));

beforeAll(async () => {
client = await weaviate.connectToWeaviateCloud(
Expand Down
Loading