Skip to content

Commit

Permalink
fix(storage): omit subPathStrategy when prefix is defined (aws-amplif…
Browse files Browse the repository at this point in the history
…y#13606)

* fix: omit subPathStrategy on prefix

* chore: fix build

* chore: address feedback
  • Loading branch information
israx authored Jul 18, 2024
1 parent af46e39 commit d3b9546
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
16 changes: 10 additions & 6 deletions packages/storage/src/providers/s3/apis/internal/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import {
resolveS3ConfigAndInput,
validateStorageOperationInputWithPrefix,
} from '../../utils';
import { ResolvedS3Config } from '../../types/options';
import {
ListAllOptionsWithPath,
ListPaginateOptionsWithPath,
ResolvedS3Config,
} from '../../types/options';
import {
ListObjectsV2Input,
ListObjectsV2Output,
Expand All @@ -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;

Expand Down Expand Up @@ -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}"`);

Expand Down Expand Up @@ -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;
}
};
14 changes: 8 additions & 6 deletions packages/storage/src/providers/s3/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions packages/storage/src/providers/s3/types/outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ListOutputItem>;
export type ListAllOutput = Omit<
StorageListOutput<ListOutputItem>,
'excludedSubpaths'
>;

/**
* Output type with path for S3 list API. Lists all bucket objects.
Expand All @@ -105,7 +108,10 @@ export type ListAllWithPathOutput = StorageListOutput<ListOutputItemWithPath>;
* @deprecated Use {@link ListPaginateWithPathOutput} instead.
* Output type for S3 list API. Lists bucket objects with pagination.
*/
export type ListPaginateOutput = StorageListOutput<ListOutputItem> & {
export type ListPaginateOutput = Omit<
StorageListOutput<ListOutputItem>,
'excludedSubpaths'
> & {
nextToken?: string;
};

Expand Down

0 comments on commit d3b9546

Please sign in to comment.