Skip to content

Commit 35ff2f9

Browse files
authored
feat: add return fields for list backups and support ordering (#358)
1 parent cef88c5 commit 35ff2f9

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/collections/backup/client.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
BackupReturn,
2929
BackupStatusArgs,
3030
BackupStatusReturn,
31+
ListBackupOptions,
3132
} from './types.js';
3233

3334
export const backup = (connection: Connection): Backup => {
@@ -205,8 +206,12 @@ export const backup = (connection: Connection): Backup => {
205206
}
206207
: parseResponse(res);
207208
},
208-
list: (backend: Backend): Promise<BackupReturn[]> => {
209-
return connection.get<BackupReturn[]>(`/backups/${backend}`);
209+
list: (backend: Backend, opts?: ListBackupOptions): Promise<BackupReturn[]> => {
210+
let url = `/backups/${backend}`;
211+
if (opts?.startedAtAsc) {
212+
url += '?order=asc';
213+
}
214+
return connection.get<BackupReturn[]>(url);
210215
},
211216
};
212217
};
@@ -261,7 +266,8 @@ export interface Backup {
261266
/** List existing backups (completed and in-progress) created in a given backend.
262267
*
263268
* @param {Backend} backend Backend whence to list backups.
269+
* @param {ListBackupOptions} [opts] The options available when listing backups.
264270
* @returns {Promise<BackupReturn[]>} The response from Weaviate.
265-
* */
266-
list(backend: Backend): Promise<BackupReturn[]>;
271+
*/
272+
list(backend: Backend, opts?: ListBackupOptions): Promise<BackupReturn[]>;
267273
}

src/collections/backup/integration.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,36 @@ describe('Integration testing of backups', () => {
228228
});
229229
});
230230

231+
requireAtLeast(1, 33, 2).it('get all backups in ascending order', async () => {
232+
await clientPromise.then(async (client) => {
233+
await client.collections.create({ name: 'TestListBackupsAsc' }).then((col) => col.data.insert());
234+
235+
const wantBackups: string[] = [];
236+
for (let i = 0; i < 3; i++) {
237+
wantBackups.push(
238+
await client.backup
239+
.create({
240+
backupId: randomBackupId(),
241+
backend: 'filesystem',
242+
includeCollections: ['TestListBackupsAsc'],
243+
waitForCompletion: true,
244+
})
245+
.then((res) => res.id)
246+
);
247+
}
248+
249+
const sortAscending = true;
250+
const gotBackups = await client.backup.list('filesystem', { startedAtAsc: sortAscending });
251+
252+
// There may be other backups created in other tests;
253+
expect(gotBackups.length).toBeGreaterThanOrEqual(wantBackups.length);
254+
// Expect the backups to be sorted in ascending order
255+
expect(
256+
gotBackups.every((value, idx, a) => idx === 0 || a[idx - 1].startedAt! <= value.startedAt!)
257+
).toBe(sortAscending);
258+
});
259+
});
260+
231261
function randomBackupId() {
232262
return 'backup-id-' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
233263
}

src/collections/backup/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ export type BackupReturn = BackupStatusReturn & {
2121
backend: Backend;
2222
/** The collections that were included in the backup */
2323
collections: string[];
24+
/** Timestamp when the backup process started */
25+
startedAt?: Date;
26+
/** Timestamp when the backup process completed (successfully or with failure) */
27+
completedAt?: Date;
28+
/** Size of the backup in Gibs */
29+
size?: number;
2430
};
2531

2632
/** Configuration options available when creating a backup */
@@ -72,3 +78,8 @@ export type BackupCancelArgs = {
7278
/** The backend to use for the backup. */
7379
backend: Backend;
7480
};
81+
82+
/** The options available when listing backups. */
83+
export type ListBackupOptions = {
84+
startedAtAsc?: boolean;
85+
};

0 commit comments

Comments
 (0)