From f315ba8cbc790f61b810bd16576cc4e98a9ac180 Mon Sep 17 00:00:00 2001 From: gkampitakis Date: Wed, 22 Oct 2025 14:24:01 +0300 Subject: [PATCH 1/3] feat: add return fields for list backups and support ordering --- src/backup/index.ts | 1 + src/collections/backup/client.ts | 12 +++++++++--- src/collections/backup/types.ts | 6 ++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/backup/index.ts b/src/backup/index.ts index 9b395cd6..f5e91551 100644 --- a/src/backup/index.ts +++ b/src/backup/index.ts @@ -7,6 +7,7 @@ import BackupRestorer from './backupRestorer.js'; export type Backend = 'filesystem' | 's3' | 'gcs' | 'azure'; export type BackupStatus = 'STARTED' | 'TRANSFERRING' | 'TRANSFERRED' | 'SUCCESS' | 'FAILED'; export type BackupCompressionLevel = 'DefaultCompression' | 'BestSpeed' | 'BestCompression'; +export type BackupListOrder = 'asc' | 'desc'; export interface Backup { creator: () => BackupCreator; diff --git a/src/collections/backup/client.ts b/src/collections/backup/client.ts index f220ba0c..23d37a3a 100644 --- a/src/collections/backup/client.ts +++ b/src/collections/backup/client.ts @@ -2,6 +2,7 @@ import { Backend, BackupCreateStatusGetter, BackupCreator, + BackupListOrder, BackupRestoreStatusGetter, BackupRestorer, } from '../../backup/index.js'; @@ -205,8 +206,12 @@ export const backup = (connection: Connection): Backup => { } : parseResponse(res); }, - list: (backend: Backend): Promise => { - return connection.get(`/backups/${backend}`); + list: (backend: Backend, order?: BackupListOrder): Promise => { + let url = `/backups/${backend}`; + if (order) { + url += `?order=${order}`; + } + 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 {BackupListOrder} [order] Order in which to list backups. * @returns {Promise} The response from Weaviate. * */ - list(backend: Backend): Promise; + list(backend: Backend, order?: BackupListOrder): Promise; } diff --git a/src/collections/backup/types.ts b/src/collections/backup/types.ts index 4403bb0e..a4a47747 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 */ From 88fe7a33e5072445a952a9536de5f74163312d95 Mon Sep 17 00:00:00 2001 From: gkampitakis Date: Thu, 23 Oct 2025 13:04:26 +0300 Subject: [PATCH 2/3] fix: use a single boolean for ascending sorting --- src/backup/index.ts | 1 - src/collections/backup/client.ts | 11 ++++---- src/collections/backup/integration.test.ts | 30 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/backup/index.ts b/src/backup/index.ts index f5e91551..9b395cd6 100644 --- a/src/backup/index.ts +++ b/src/backup/index.ts @@ -7,7 +7,6 @@ import BackupRestorer from './backupRestorer.js'; export type Backend = 'filesystem' | 's3' | 'gcs' | 'azure'; export type BackupStatus = 'STARTED' | 'TRANSFERRING' | 'TRANSFERRED' | 'SUCCESS' | 'FAILED'; export type BackupCompressionLevel = 'DefaultCompression' | 'BestSpeed' | 'BestCompression'; -export type BackupListOrder = 'asc' | 'desc'; export interface Backup { creator: () => BackupCreator; diff --git a/src/collections/backup/client.ts b/src/collections/backup/client.ts index 23d37a3a..d7bf79b3 100644 --- a/src/collections/backup/client.ts +++ b/src/collections/backup/client.ts @@ -2,7 +2,6 @@ import { Backend, BackupCreateStatusGetter, BackupCreator, - BackupListOrder, BackupRestoreStatusGetter, BackupRestorer, } from '../../backup/index.js'; @@ -206,10 +205,10 @@ export const backup = (connection: Connection): Backup => { } : parseResponse(res); }, - list: (backend: Backend, order?: BackupListOrder): Promise => { + list: (backend: Backend, sortAscending?: boolean): Promise => { let url = `/backups/${backend}`; - if (order) { - url += `?order=${order}`; + if (sortAscending) { + url += '?order=asc'; } return connection.get(url); }, @@ -266,8 +265,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 {BackupListOrder} [order] Order in which to list backups. + * @param {sortAscending} [boolean] Sort list of backups in ascending order based on creation time. Default is descending order. * @returns {Promise} The response from Weaviate. * */ - list(backend: Backend, order?: BackupListOrder): Promise; + list(backend: Backend, sortAscending?: boolean): Promise; } diff --git a/src/collections/backup/integration.test.ts b/src/collections/backup/integration.test.ts index a50eb5b0..fcc2b387 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', 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); } From 42c0b1b994c0b934390c97bd7a7f3c6ea76df581 Mon Sep 17 00:00:00 2001 From: gkampitakis Date: Wed, 29 Oct 2025 18:49:46 +0200 Subject: [PATCH 3/3] chore: address pr comments --- src/collections/backup/client.ts | 11 ++++++----- src/collections/backup/integration.test.ts | 2 +- src/collections/backup/types.ts | 5 +++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/collections/backup/client.ts b/src/collections/backup/client.ts index d7bf79b3..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,9 +206,9 @@ export const backup = (connection: Connection): Backup => { } : parseResponse(res); }, - list: (backend: Backend, sortAscending?: boolean): Promise => { + list: (backend: Backend, opts?: ListBackupOptions): Promise => { let url = `/backups/${backend}`; - if (sortAscending) { + if (opts?.startedAtAsc) { url += '?order=asc'; } return connection.get(url); @@ -265,8 +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 {sortAscending} [boolean] Sort list of backups in ascending order based on creation time. Default is descending order. + * @param {ListBackupOptions} [opts] The options available when listing backups. * @returns {Promise} The response from Weaviate. - * */ - list(backend: Backend, sortAscending?: boolean): Promise; + */ + list(backend: Backend, opts?: ListBackupOptions): Promise; } diff --git a/src/collections/backup/integration.test.ts b/src/collections/backup/integration.test.ts index fcc2b387..5e762bb1 100644 --- a/src/collections/backup/integration.test.ts +++ b/src/collections/backup/integration.test.ts @@ -247,7 +247,7 @@ describe('Integration testing of backups', () => { } const sortAscending = true; - const gotBackups = await client.backup.list('filesystem', sortAscending); + const gotBackups = await client.backup.list('filesystem', { startedAtAsc: sortAscending }); // There may be other backups created in other tests; expect(gotBackups.length).toBeGreaterThanOrEqual(wantBackups.length); diff --git a/src/collections/backup/types.ts b/src/collections/backup/types.ts index a4a47747..f24bc8d8 100644 --- a/src/collections/backup/types.ts +++ b/src/collections/backup/types.ts @@ -78,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; +};