import { groupFiles } from 'cpb-api/common/index.js';
import { title } from 'cpb-common';
import BucketList from './bucket/list.js';
import File from './file/index.js';
import LSD from './list.js';
import Metadata from './metadata/index.js';
/**
* @module cpb-storage
* @description
* ### Cloud Storage Operations
*/
/**
*
*/
export {
/**
* @method module:cpb-storage.LSD
*/
LSD,
/**
* @method module:cpb-storage.BucketList
*/
BucketList,
/**
* @member module:cpb-storage.Metadata
*/
Metadata,
/**
* @member module:cpb-storage.File
*/
File,
};
/**
* Get top-level directories in bucket
* @method module:cpb-storage.getTopLevelDirs
* @async
* @param {string} bucket - storage bucket
* @param {?boolean} versions
* @param {?string} prefix
* @param {?string} [delimiter='/']
* @return {Promise<string[]|*>}
*/
export async function getTopLevelDirs({ bucket, versions, prefix, delimiter = '/' }) {
title('getTopLevelDirs', { bucket, delimiter, prefix, versions });
if (!bucket) {
throw new TypeError('!bucket');
}
return await LSD({ bucket, delimiter, prefix, versions });
}
/**
* gets list of loose files in the bucket
* @method module:cpb-storage.getTopLevelFiles
* @async
* @param {string} bucket - storage bucket
* @param {?string} [delimiter='/']
* @param {?string} prefix
* @param {?boolean} [versions=true]
* @return {Promise<GroupedFiles>}
*/
export async function getTopLevelFiles({ bucket, delimiter = '/', prefix, versions = true }) {
title('getTopLevelFiles', { bucket });
if (!bucket) {
throw new TypeError('!bucket');
}
const result = await LSD({ bucket, delimiter, prefix, versions }),
[files, deletedFiles] = groupFiles(result.files, true);
return [files, deletedFiles];
}