File tree Expand file tree Collapse file tree 3 files changed +35
-7
lines changed Expand file tree Collapse file tree 3 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ import BackupRestorer from './backupRestorer.js';
77export type Backend = 'filesystem' | 's3' | 'gcs' | 'azure' ;
88export type BackupStatus = 'STARTED' | 'TRANSFERRING' | 'TRANSFERRED' | 'SUCCESS' | 'FAILED' ;
99export type BackupCompressionLevel = 'DefaultCompression' | 'BestSpeed' | 'BestCompression' ;
10- export type BackupListOrder = 'asc' | 'desc' ;
1110
1211export interface Backup {
1312 creator : ( ) => BackupCreator ;
Original file line number Diff line number Diff line change 22 Backend ,
33 BackupCreateStatusGetter ,
44 BackupCreator ,
5- BackupListOrder ,
65 BackupRestoreStatusGetter ,
76 BackupRestorer ,
87} from '../../backup/index.js' ;
@@ -206,10 +205,10 @@ export const backup = (connection: Connection): Backup => {
206205 }
207206 : parseResponse ( res ) ;
208207 } ,
209- list : ( backend : Backend , order ?: BackupListOrder ) : Promise < BackupReturn [ ] > => {
208+ list : ( backend : Backend , sortAscending ?: boolean ) : Promise < BackupReturn [ ] > => {
210209 let url = `/backups/${ backend } ` ;
211- if ( order ) {
212- url += ` ?order=${ order } ` ;
210+ if ( sortAscending ) {
211+ url += ' ?order=asc' ;
213212 }
214213 return connection . get < BackupReturn [ ] > ( url ) ;
215214 } ,
@@ -266,8 +265,8 @@ export interface Backup {
266265 /** List existing backups (completed and in-progress) created in a given backend.
267266 *
268267 * @param {Backend } backend Backend whence to list backups.
269- * @param {BackupListOrder } [order] Order in which to list backups .
268+ * @param {sortAscending } [boolean] Sort list of backups in ascending order based on creation time. Default is descending order .
270269 * @returns {Promise<BackupReturn[]> } The response from Weaviate.
271270 * */
272- list ( backend : Backend , order ?: BackupListOrder ) : Promise < BackupReturn [ ] > ;
271+ list ( backend : Backend , sortAscending ?: boolean ) : Promise < BackupReturn [ ] > ;
273272}
Original file line number Diff line number Diff 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' , 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 }
You can’t perform that action at this time.
0 commit comments