diff --git a/packages/storage/src/providers/s3/apis/internal/list.ts b/packages/storage/src/providers/s3/apis/internal/list.ts index 1035559bedc..7fe8ccf1ed0 100644 --- a/packages/storage/src/providers/s3/apis/internal/list.ts +++ b/packages/storage/src/providers/s3/apis/internal/list.ts @@ -20,7 +20,11 @@ import { resolveS3ConfigAndInput, validateStorageOperationInputWithPrefix, } from '../../utils'; -import { ResolvedS3Config } from '../../types/options'; +import { + ListAllOptionsWithPath, + ListPaginateOptionsWithPath, + ResolvedS3Config, +} from '../../types/options'; import { ListObjectsV2Input, ListObjectsV2Output, @@ -30,7 +34,6 @@ import { getStorageUserAgentValue } from '../../utils/userAgent'; import { logger } from '../../../../utils'; import { DEFAULT_DELIMITER, STORAGE_INPUT_PREFIX } from '../../utils/constants'; import { CommonPrefix } from '../../utils/client/types'; -import { StorageSubpathStrategy } from '../../../../types'; const MAX_PAGE_SIZE = 1000; @@ -76,12 +79,13 @@ export const list = async ( } ${anyOptions?.nextToken ? `nextToken: ${anyOptions?.nextToken}` : ''}.`, ); } + const listParams = { Bucket: bucket, Prefix: isInputWithPrefix ? `${generatedPrefix}${objectKey}` : objectKey, MaxKeys: options?.listAll ? undefined : options?.pageSize, ContinuationToken: options?.listAll ? undefined : options?.nextToken, - Delimiter: getDelimiter(options.subpathStrategy), + Delimiter: getDelimiter(options), }; logger.debug(`listing items from "${listParams.Prefix}"`); @@ -263,9 +267,9 @@ const mapCommonPrefixesToExcludedSubpaths = ( }; const getDelimiter = ( - subpathStrategy?: StorageSubpathStrategy, + options?: ListAllOptionsWithPath | ListPaginateOptionsWithPath, ): string | undefined => { - if (subpathStrategy?.strategy === 'exclude') { - return subpathStrategy?.delimiter ?? DEFAULT_DELIMITER; + if (options?.subpathStrategy?.strategy === 'exclude') { + return options?.subpathStrategy?.delimiter ?? DEFAULT_DELIMITER; } }; diff --git a/packages/storage/src/providers/s3/types/options.ts b/packages/storage/src/providers/s3/types/options.ts index b2b7dfd0ddc..deae81fee51 100644 --- a/packages/storage/src/providers/s3/types/options.ts +++ b/packages/storage/src/providers/s3/types/options.ts @@ -70,17 +70,19 @@ export type RemoveOptions = WriteOptions & CommonOptions; * @deprecated Use {@link ListAllOptionsWithPath} instead. * Input options type with prefix for S3 list all API. */ -export type ListAllOptionsWithPrefix = StorageListAllOptions & - ReadOptions & - CommonOptions; +export type ListAllOptionsWithPrefix = Omit< + StorageListAllOptions & ReadOptions & CommonOptions, + 'subpathStrategy' +>; /** * @deprecated Use {@link ListPaginateOptionsWithPath} instead. * Input options type with prefix for S3 list API to paginate items. */ -export type ListPaginateOptionsWithPrefix = StorageListPaginateOptions & - ReadOptions & - CommonOptions; +export type ListPaginateOptionsWithPrefix = Omit< + StorageListPaginateOptions & ReadOptions & CommonOptions, + 'subpathStrategy' +>; /** * Input options type with path for S3 list all API. diff --git a/packages/storage/src/providers/s3/types/outputs.ts b/packages/storage/src/providers/s3/types/outputs.ts index 44524536a3b..ec3b89941e0 100644 --- a/packages/storage/src/providers/s3/types/outputs.ts +++ b/packages/storage/src/providers/s3/types/outputs.ts @@ -94,7 +94,10 @@ export type GetPropertiesWithPathOutput = ItemBase & StorageItemWithPath; * @deprecated Use {@link ListAllWithPathOutput} instead. * Output type for S3 list API. Lists all bucket objects. */ -export type ListAllOutput = StorageListOutput; +export type ListAllOutput = Omit< + StorageListOutput, + 'excludedSubpaths' +>; /** * Output type with path for S3 list API. Lists all bucket objects. @@ -105,7 +108,10 @@ export type ListAllWithPathOutput = StorageListOutput; * @deprecated Use {@link ListPaginateWithPathOutput} instead. * Output type for S3 list API. Lists bucket objects with pagination. */ -export type ListPaginateOutput = StorageListOutput & { +export type ListPaginateOutput = Omit< + StorageListOutput, + 'excludedSubpaths' +> & { nextToken?: string; };