diff --git a/src/collections/backup/client.ts b/src/collections/backup/client.ts index f220ba0c..54f0503e 100644 --- a/src/collections/backup/client.ts +++ b/src/collections/backup/client.ts @@ -28,6 +28,7 @@ import { BackupReturn, BackupStatusArgs, BackupStatusReturn, + ListBackupOptions, } from './types.js'; export const backup = (connection: Connection): Backup => { @@ -205,8 +206,12 @@ export const backup = (connection: Connection): Backup => { } : parseResponse(res); }, - list: (backend: Backend): Promise => { - return connection.get(`/backups/${backend}`); + list: (backend: Backend, opts?: ListBackupOptions): Promise => { + let url = `/backups/${backend}`; + if (opts?.startedAtAsc) { + url += '?order=asc'; + } + return connection.get(url); }, }; }; @@ -261,7 +266,8 @@ export interface Backup { /** List existing backups (completed and in-progress) created in a given backend. * * @param {Backend} backend Backend whence to list backups. + * @param {ListBackupOptions} [opts] The options available when listing backups. * @returns {Promise} The response from Weaviate. - * */ - list(backend: Backend): Promise; + */ + list(backend: Backend, opts?: ListBackupOptions): Promise; } diff --git a/src/collections/backup/integration.test.ts b/src/collections/backup/integration.test.ts index a50eb5b0..5e762bb1 100644 --- a/src/collections/backup/integration.test.ts +++ b/src/collections/backup/integration.test.ts @@ -228,6 +228,36 @@ describe('Integration testing of backups', () => { }); }); + requireAtLeast(1, 33, 2).it('get all backups in ascending order', async () => { + await clientPromise.then(async (client) => { + await client.collections.create({ name: 'TestListBackupsAsc' }).then((col) => col.data.insert()); + + const wantBackups: string[] = []; + for (let i = 0; i < 3; i++) { + wantBackups.push( + await client.backup + .create({ + backupId: randomBackupId(), + backend: 'filesystem', + includeCollections: ['TestListBackupsAsc'], + waitForCompletion: true, + }) + .then((res) => res.id) + ); + } + + const sortAscending = true; + const gotBackups = await client.backup.list('filesystem', { startedAtAsc: sortAscending }); + + // There may be other backups created in other tests; + expect(gotBackups.length).toBeGreaterThanOrEqual(wantBackups.length); + // Expect the backups to be sorted in ascending order + expect( + gotBackups.every((value, idx, a) => idx === 0 || a[idx - 1].startedAt! <= value.startedAt!) + ).toBe(sortAscending); + }); + }); + function randomBackupId() { return 'backup-id-' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); } diff --git a/src/collections/backup/types.ts b/src/collections/backup/types.ts index 4403bb0e..f24bc8d8 100644 --- a/src/collections/backup/types.ts +++ b/src/collections/backup/types.ts @@ -21,6 +21,12 @@ export type BackupReturn = BackupStatusReturn & { backend: Backend; /** The collections that were included in the backup */ collections: string[]; + /** Timestamp when the backup process started */ + startedAt?: Date; + /** Timestamp when the backup process completed (successfully or with failure) */ + completedAt?: Date; + /** Size of the backup in Gibs */ + size?: number; }; /** Configuration options available when creating a backup */ @@ -72,3 +78,8 @@ export type BackupCancelArgs = { /** The backend to use for the backup. */ backend: Backend; }; + +/** The options available when listing backups. */ +export type ListBackupOptions = { + startedAtAsc?: boolean; +};