Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/backup/backupCreateStatusGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class BackupCreateStatusGetter extends CommandBase {
this.addErrors([...validateBackend(this.backend), ...validateBackupId(this.backupId)]);
};

do = (): Promise<BackupCreateStatusResponse | Error> => {
do = (): Promise<BackupCreateStatusResponse> => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
Expand Down
2 changes: 1 addition & 1 deletion src/backup/backupGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class BackupGetter extends CommandBase {
this.addErrors(validateBackend(this.backend));
};

do = (): Promise<BackupCreateResponse[] | Error> => {
do = (): Promise<BackupCreateResponse[]> => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
Expand Down
2 changes: 1 addition & 1 deletion src/backup/backupRestoreStatusGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class BackupRestoreStatusGetter extends CommandBase {
this.addErrors([...validateBackend(this.backend), ...validateBackupId(this.backupId)]);
};

do = (): Promise<BackupRestoreStatusResponse | Error> => {
do = (): Promise<BackupRestoreStatusResponse> => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
Expand Down
57 changes: 31 additions & 26 deletions src/backup/journey.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import weaviate, { WeaviateClient } from '../index';
import { BackupCreateResponse } from '../types';
import {
BackupCreateResponse,
BackupCreateStatusResponse,
BackupRestoreResponse,
BackupRestoreStatusResponse,
} from '../types';

const {
createTestFoodSchemaAndData,
Expand Down Expand Up @@ -53,14 +58,14 @@ describe('create and restore backup with waiting', () => {
.withBackend(BACKEND)
.withBackupId(BACKUP_ID)
.do()
.then((createStatusResponse: any) => {
.then((createStatusResponse: BackupCreateStatusResponse) => {
expect(createStatusResponse.id).toBe(BACKUP_ID);
expect(createStatusResponse.path).toBe(`${DOCKER_COMPOSE_BACKUPS_DIR}/${BACKUP_ID}`);
expect(createStatusResponse.backend).toBe(BACKEND);
expect(createStatusResponse.status).toBe(weaviate.backup.CreateStatus.SUCCESS);
expect(createStatusResponse.error).toBeUndefined();
})
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on create status: ' + err);
});
});
Expand All @@ -83,7 +88,7 @@ describe('create and restore backup with waiting', () => {
.withBackupId(BACKUP_ID)
.withWaitForCompletion(true)
.do()
.then((restoreResponse: any) => {
.then((restoreResponse: BackupRestoreResponse) => {
expect(restoreResponse.id).toBe(BACKUP_ID);
expect(restoreResponse.classes).toHaveLength(1);
expect(restoreResponse.classes).toContain(PIZZA_CLASS_NAME);
Expand All @@ -92,7 +97,7 @@ describe('create and restore backup with waiting', () => {
expect(restoreResponse.status).toBe(weaviate.backup.RestoreStatus.SUCCESS);
expect(restoreResponse.error).toBeUndefined();
})
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on restore backup: ' + err);
});
});
Expand All @@ -105,14 +110,14 @@ describe('create and restore backup with waiting', () => {
.withBackend(BACKEND)
.withBackupId(BACKUP_ID)
.do()
.then((restoreStatusResponse: any) => {
.then((restoreStatusResponse: BackupRestoreStatusResponse) => {
expect(restoreStatusResponse.id).toBe(BACKUP_ID);
expect(restoreStatusResponse.path).toBe(`${DOCKER_COMPOSE_BACKUPS_DIR}/${BACKUP_ID}`);
expect(restoreStatusResponse.backend).toBe(BACKEND);
expect(restoreStatusResponse.status).toBe(weaviate.backup.RestoreStatus.SUCCESS);
expect(restoreStatusResponse.error).toBeUndefined();
})
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on restore status: ' + err);
});
});
Expand Down Expand Up @@ -140,7 +145,7 @@ describe('create and restore backup without waiting', () => {
.withBackend(BACKEND)
.withBackupId(BACKUP_ID)
.do()
.then((createResponse: any) => {
.then((createResponse: BackupCreateResponse) => {
expect(createResponse.id).toBe(BACKUP_ID);
expect(createResponse.classes).toHaveLength(1);
expect(createResponse.classes).toContain(PIZZA_CLASS_NAME);
Expand All @@ -149,7 +154,7 @@ describe('create and restore backup without waiting', () => {
expect(createResponse.status).toBe(weaviate.backup.CreateStatus.STARTED);
expect(createResponse.error).toBeUndefined();
})
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on create backup: ' + err);
});
});
Expand All @@ -160,7 +165,7 @@ describe('create and restore backup without waiting', () => {
const loop = () => {
statusGetter
.do()
.then((createStatusResponse: any) => {
.then((createStatusResponse: BackupCreateStatusResponse) => {
if (
createStatusResponse.status == weaviate.backup.CreateStatus.SUCCESS ||
createStatusResponse.status == weaviate.backup.CreateStatus.FAILED
Expand Down Expand Up @@ -205,7 +210,7 @@ describe('create and restore backup without waiting', () => {
.withBackend(BACKEND)
.withBackupId(BACKUP_ID)
.do()
.then((restoreResponse: any) => {
.then((restoreResponse: BackupRestoreResponse) => {
expect(restoreResponse.id).toBe(BACKUP_ID);
expect(restoreResponse.classes).toHaveLength(1);
expect(restoreResponse.classes).toContain(PIZZA_CLASS_NAME);
Expand All @@ -214,7 +219,7 @@ describe('create and restore backup without waiting', () => {
expect(restoreResponse.status).toBe(weaviate.backup.RestoreStatus.STARTED);
expect(restoreResponse.error).toBeUndefined();
})
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on restore backup: ' + err);
});
});
Expand All @@ -225,7 +230,7 @@ describe('create and restore backup without waiting', () => {
const loop = () => {
statusGetter
.do()
.then((restoreStatusResponse: any) => {
.then((restoreStatusResponse: BackupRestoreStatusResponse) => {
if (
restoreStatusResponse.status == weaviate.backup.RestoreStatus.SUCCESS ||
restoreStatusResponse.status == weaviate.backup.RestoreStatus.FAILED
Expand Down Expand Up @@ -277,7 +282,7 @@ describe('create and restore 1 of 2 classes', () => {
.withBackupId(BACKUP_ID)
.withWaitForCompletion(true)
.do()
.then((createResponse: any) => {
.then((createResponse: BackupCreateResponse) => {
expect(createResponse.id).toBe(BACKUP_ID);
expect(createResponse.classes).toHaveLength(2);
expect(createResponse.classes).toContain(PIZZA_CLASS_NAME);
Expand All @@ -287,7 +292,7 @@ describe('create and restore 1 of 2 classes', () => {
expect(createResponse.status).toBe(weaviate.backup.CreateStatus.SUCCESS);
expect(createResponse.error).toBeUndefined();
})
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on create backup: ' + err);
});
});
Expand All @@ -301,14 +306,14 @@ describe('create and restore 1 of 2 classes', () => {
.withBackend(BACKEND)
.withBackupId(BACKUP_ID)
.do()
.then((createStatusResponse: any) => {
.then((createStatusResponse: BackupCreateStatusResponse) => {
expect(createStatusResponse.id).toBe(BACKUP_ID);
expect(createStatusResponse.path).toBe(`${DOCKER_COMPOSE_BACKUPS_DIR}/${BACKUP_ID}`);
expect(createStatusResponse.backend).toBe(BACKEND);
expect(createStatusResponse.status).toBe(weaviate.backup.CreateStatus.SUCCESS);
expect(createStatusResponse.error).toBeUndefined();
})
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on create status: ' + err);
});
});
Expand All @@ -331,7 +336,7 @@ describe('create and restore 1 of 2 classes', () => {
.withBackupId(BACKUP_ID)
.withWaitForCompletion(true)
.do()
.then((restoreResponse: any) => {
.then((restoreResponse: BackupRestoreResponse) => {
expect(restoreResponse.id).toBe(BACKUP_ID);
expect(restoreResponse.classes).toHaveLength(1);
expect(restoreResponse.classes).toContain(PIZZA_CLASS_NAME);
Expand All @@ -354,14 +359,14 @@ describe('create and restore 1 of 2 classes', () => {
.withBackend(BACKEND)
.withBackupId(BACKUP_ID)
.do()
.then((restoreStatusResponse: any) => {
.then((restoreStatusResponse: BackupRestoreStatusResponse) => {
expect(restoreStatusResponse.id).toBe(BACKUP_ID);
expect(restoreStatusResponse.path).toBe(`${DOCKER_COMPOSE_BACKUPS_DIR}/${BACKUP_ID}`);
expect(restoreStatusResponse.backend).toBe(BACKEND);
expect(restoreStatusResponse.status).toBe(weaviate.backup.RestoreStatus.SUCCESS);
expect(restoreStatusResponse.error).toBeUndefined();
})
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on restore status: ' + err);
});
});
Expand Down Expand Up @@ -513,7 +518,7 @@ describe('fail restoring backup for existing class', () => {
.withBackupId(BACKUP_ID)
.withWaitForCompletion(true)
.do()
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on create backup: ' + err);
});
});
Expand All @@ -526,7 +531,7 @@ describe('fail restoring backup for existing class', () => {
.withBackupId(BACKUP_ID)
.withWaitForCompletion(true)
.do()
.then((resp: any) => {
.then((resp: BackupRestoreResponse) => {
expect(resp.error).toContain('already exists');
expect(resp.error).toContain(PIZZA_CLASS_NAME);
expect(resp.status).toBe(weaviate.backup.RestoreStatus.FAILED);
Expand Down Expand Up @@ -555,7 +560,7 @@ describe('fail creating existing backup', () => {
.withBackupId(BACKUP_ID)
.withWaitForCompletion(true)
.do()
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on create backup: ' + err);
});
});
Expand Down Expand Up @@ -657,7 +662,7 @@ describe('fail checking restore status for not started restore', () => {
.withBackupId(BACKUP_ID)
.withWaitForCompletion(true)
.do()
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on create backup: ' + err);
});
});
Expand Down Expand Up @@ -732,7 +737,7 @@ describe('fail restoring backup for both include and exclude classes', () => {
.withBackupId(BACKUP_ID)
.withWaitForCompletion(true)
.do()
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on create backup: ' + err);
});
});
Expand All @@ -742,7 +747,7 @@ describe('fail restoring backup for both include and exclude classes', () => {
.classDeleter()
.withClassName(PIZZA_CLASS_NAME)
.do()
.catch((err: any) => {
.catch((err: Error) => {
throw new Error('should not fail on class delete: ' + err);
});
});
Expand Down
34 changes: 19 additions & 15 deletions src/batch/journey.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import weaviate, { WeaviateClient } from '../index';
import { BatchReference, BatchReferenceResponse, WeaviateObject } from '../types';

const thingClassName = 'BatchJourneyTestThing';
const otherThingClassName = 'BatchJourneyTestOtherThing';
Expand All @@ -12,7 +13,7 @@ const thingIds = [

const otherThingIds = ['5b354a0f-fe66-4fe7-ad62-4db72ddab815', '8727fa2b-610a-4a5c-af26-e558943f71c7'];

const someObjects = [
const someObjects: WeaviateObject[] = [
{
class: thingClassName,
id: thingIds[0],
Expand Down Expand Up @@ -76,10 +77,10 @@ describe('batch importing', () => {
.withObject(someObjects[0])
.withObjects(someObjects[1])
.withObjects(someObjects[2], someObjects[3])
.withObjects([someObjects[4], someObjects[5]]);
.withObjects(...[someObjects[4], someObjects[5]]);

expect(batcher.objects).toHaveLength(someObjects.length);
batcher.objects.forEach((obj: any, i: number) => {
batcher.objects.forEach((obj: WeaviateObject, i: number) => {
expect(obj.class).toBe(someObjects[i].class);
expect(obj.id).toBe(someObjects[i].id);
});
Expand Down Expand Up @@ -109,7 +110,7 @@ describe('batch importing', () => {
.withObject(toImport[1])
.do()
.then()
.catch((e: any) => {
.catch((e: Error) => {
throw new Error('it should not have errord ' + e);
});
});
Expand All @@ -122,7 +123,7 @@ describe('batch importing', () => {
return Promise.all([
client.data.getterById().withId(thingIds[0]).withClassName(thingClassName).do(),
client.data.getterById().withId(thingIds[1]).withClassName(thingClassName).do(),
]).catch((e: any) => {
]).catch((e: Error) => {
throw new Error('it should not have errord ' + e);
});
});
Expand Down Expand Up @@ -189,7 +190,7 @@ describe('batch importing', () => {
client.batch
.objectsBatcher()
.withConsistencyLevel(weaviate.replication.ConsistencyLevel.ONE)
.withObjects([toImport[0], toImport[1]])
.withObjects(...[toImport[0], toImport[1]])
.do()
.then()
.catch((e: any) => {
Expand Down Expand Up @@ -218,10 +219,10 @@ describe('batch importing', () => {
.referencesBatcher()
.withReference(someReferences[0])
.withReferences(someReferences[1], someReferences[2])
.withReferences([someReferences[3]]);
.withReferences(...[someReferences[3]]);

expect(batcher.references).toHaveLength(someReferences.length);
batcher.references.forEach((ref: any, i: number) => {
batcher.references.forEach((ref: BatchReference, i: number) => {
expect(ref.from).toBe(someReferences[i].from);
expect(ref.to).toBe(someReferences[i].to);
});
Expand All @@ -240,9 +241,9 @@ describe('batch importing', () => {
})
.withConsistencyLevel(weaviate.replication.ConsistencyLevel.ALL)
.do()
.then((res: any) => {
res.forEach((elem: any) => {
expect(elem.result.errors).toBeUndefined();
.then((res: BatchReferenceResponse[]) => {
res.forEach((elem: BatchReferenceResponse) => {
expect(elem.result!.errors).toBeUndefined();
});
})
.catch((e: any) => {
Expand Down Expand Up @@ -271,9 +272,9 @@ describe('batch importing', () => {
.referencesBatcher()
.withReferences(reference1, reference2)
.do()
.then((res: any[]) => {
res.forEach((elem: any) => {
expect(elem.result.errors).toBeUndefined();
.then((res: BatchReferenceResponse[]) => {
res.forEach((elem: BatchReferenceResponse) => {
expect(elem.result!.errors).toBeUndefined();
});
})
.catch((e: any) => {
Expand Down Expand Up @@ -546,7 +547,10 @@ const setup = async (client: WeaviateClient) => {
};

const setupData = (client: WeaviateClient) => {
return client.batch.objectsBatcher().withObjects(someObjects).do();
return client.batch
.objectsBatcher()
.withObjects(...someObjects)
.do();
};

const cleanup = (client: WeaviateClient) =>
Expand Down
Loading