diff --git a/packages/storage/__tests__/providers/s3/apis/uploadData/byteLength.test.ts b/packages/storage/__tests__/providers/s3/apis/uploadData/byteLength.test.ts new file mode 100644 index 00000000000..24b46ac4f0d --- /dev/null +++ b/packages/storage/__tests__/providers/s3/apis/uploadData/byteLength.test.ts @@ -0,0 +1,39 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { byteLength } from '../../../../../src/providers/s3/apis/uploadData/byteLength'; + +describe('byteLength', () => { + it('returns 0 for null or undefined', () => { + expect(byteLength(undefined)).toBe(0); + expect(byteLength(null)).toBe(0); + }); + + it('calculates byte length correctly for ASCII strings', () => { + expect(byteLength('hello')).toBe(5); + }); + + it('calculates byte length correctly for multi-byte characters', () => { + expect(byteLength('èちは')).toBe(8); + }); + + it('handles Uint8Array correctly', () => { + const input = new Uint8Array([1, 2, 3]); + expect(byteLength(input)).toBe(3); + }); + + it('handles ArrayBuffer correctly', () => { + const buffer = new ArrayBuffer(8); + expect(byteLength(buffer)).toBe(8); + }); + + it('handles File object correctly', () => { + const file = new Blob(['hello']); + expect(byteLength(file)).toBe(5); + }); + + it('returns undefined for unsupported types', () => { + const input = { unsupportedType: true }; + expect(byteLength(input)).toBeUndefined(); + }); +}); diff --git a/packages/storage/src/providers/s3/apis/internal/list.ts b/packages/storage/src/providers/s3/apis/internal/list.ts index 7fe8ccf1ed0..bbcb342a603 100644 --- a/packages/storage/src/providers/s3/apis/internal/list.ts +++ b/packages/storage/src/providers/s3/apis/internal/list.ts @@ -21,8 +21,8 @@ import { validateStorageOperationInputWithPrefix, } from '../../utils'; import { - ListAllOptionsWithPath, - ListPaginateOptionsWithPath, + ListAllWithPathOptions, + ListPaginateWithPathOptions, ResolvedS3Config, } from '../../types/options'; import { @@ -267,7 +267,7 @@ const mapCommonPrefixesToExcludedSubpaths = ( }; const getDelimiter = ( - options?: ListAllOptionsWithPath | ListPaginateOptionsWithPath, + options?: ListAllWithPathOptions | ListPaginateWithPathOptions, ): string | undefined => { if (options?.subpathStrategy?.strategy === 'exclude') { return options?.subpathStrategy?.delimiter ?? DEFAULT_DELIMITER; diff --git a/packages/storage/src/providers/s3/apis/uploadData/multipart/uploadHandlers.ts b/packages/storage/src/providers/s3/apis/uploadData/multipart/uploadHandlers.ts index e216feeede7..8d002df37db 100644 --- a/packages/storage/src/providers/s3/apis/uploadData/multipart/uploadHandlers.ts +++ b/packages/storage/src/providers/s3/apis/uploadData/multipart/uploadHandlers.ts @@ -17,7 +17,7 @@ import { } from '../../../utils/constants'; import { ResolvedS3Config, - UploadDataOptionsWithKey, + UploadDataWithKeyOptions, } from '../../../types/options'; import { StorageError } from '../../../../../errors/StorageError'; import { CanceledError } from '../../../../../errors/CanceledError'; @@ -99,7 +99,7 @@ export const getMultipartUploadHandlers = ( // Resolve "key" specific options if (inputType === STORAGE_INPUT_KEY) { - const accessLevel = (uploadDataOptions as UploadDataOptionsWithKey) + const accessLevel = (uploadDataOptions as UploadDataWithKeyOptions) ?.accessLevel; resolvedKeyPrefix = resolvedS3Options.keyPrefix; diff --git a/packages/storage/src/providers/s3/types/errors.ts b/packages/storage/src/providers/s3/types/errors.ts deleted file mode 100644 index 9d757af7b6f..00000000000 --- a/packages/storage/src/providers/s3/types/errors.ts +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -export enum S3Exception { - NotFoundException = 'NotFoundException', - ForbiddenException = 'ForbiddenException', - BadRequestException = 'BadRequestException', -} diff --git a/packages/storage/src/providers/s3/types/index.ts b/packages/storage/src/providers/s3/types/index.ts index 4efd666fb33..d38e3b8b523 100644 --- a/packages/storage/src/providers/s3/types/index.ts +++ b/packages/storage/src/providers/s3/types/index.ts @@ -2,23 +2,21 @@ // SPDX-License-Identifier: Apache-2.0 export { - GetUrlOptionsWithKey, - GetUrlOptionsWithPath, - UploadDataOptionsWithPath, - UploadDataOptionsWithKey, - GetPropertiesOptionsWithKey, - GetPropertiesOptionsWithPath, - ListAllOptionsWithPrefix, - ListPaginateOptionsWithPrefix, - ListAllOptionsWithPath, - ListPaginateOptionsWithPath, + GetUrlWithKeyOptions, + GetUrlWithPathOptions, + UploadDataWithPathOptions, + UploadDataWithKeyOptions, + GetPropertiesWithKeyOptions, + GetPropertiesWithPathOptions, + ListAllWithPrefixOptions, + ListPaginateWithPrefixOptions, + ListAllWithPathOptions, + ListPaginateWithPathOptions, RemoveOptions, - DownloadDataOptionsWithPath, - DownloadDataOptionsWithKey, - CopyDestinationOptionsWithKey, - CopySourceOptionsWithKey, - CopyWithPathSourceOptions, - CopyWithPathDestinationOptions, + DownloadDataWithPathOptions, + DownloadDataWithKeyOptions, + CopyDestinationWithKeyOptions, + CopySourceWithKeyOptions, } from './options'; export { UploadDataOutput, @@ -58,4 +56,3 @@ export { ListAllWithPathInput, ListPaginateWithPathInput, } from './inputs'; -export { S3Exception } from './errors'; diff --git a/packages/storage/src/providers/s3/types/inputs.ts b/packages/storage/src/providers/s3/types/inputs.ts index f7bd6c5db44..7b405964fb6 100644 --- a/packages/storage/src/providers/s3/types/inputs.ts +++ b/packages/storage/src/providers/s3/types/inputs.ts @@ -18,21 +18,21 @@ import { StorageUploadDataInputWithPath, } from '../../../types'; import { - CopyDestinationOptionsWithKey, - CopySourceOptionsWithKey, - DownloadDataOptionsWithKey, - DownloadDataOptionsWithPath, - GetPropertiesOptionsWithKey, - GetPropertiesOptionsWithPath, - GetUrlOptionsWithKey, - GetUrlOptionsWithPath, - ListAllOptionsWithPath, - ListAllOptionsWithPrefix, - ListPaginateOptionsWithPath, - ListPaginateOptionsWithPrefix, + CopyDestinationWithKeyOptions, + CopySourceWithKeyOptions, + DownloadDataWithKeyOptions, + DownloadDataWithPathOptions, + GetPropertiesWithKeyOptions, + GetPropertiesWithPathOptions, + GetUrlWithKeyOptions, + GetUrlWithPathOptions, + ListAllWithPathOptions, + ListAllWithPrefixOptions, + ListPaginateWithPathOptions, + ListPaginateWithPrefixOptions, RemoveOptions, - UploadDataOptionsWithKey, - UploadDataOptionsWithPath, + UploadDataWithKeyOptions, + UploadDataWithPathOptions, } from '../types'; // TODO: support use accelerate endpoint option @@ -41,8 +41,8 @@ import { * Input type for S3 copy API. */ export type CopyInput = StorageCopyInputWithKey< - CopySourceOptionsWithKey, - CopyDestinationOptionsWithKey + CopySourceWithKeyOptions, + CopyDestinationWithKeyOptions >; /** * Input type with path for S3 copy API. @@ -54,48 +54,48 @@ export type CopyWithPathInput = StorageCopyInputWithPath; * Input type for S3 getProperties API. */ export type GetPropertiesInput = - StorageGetPropertiesInputWithKey; + StorageGetPropertiesInputWithKey; /** * Input type with for S3 getProperties API. */ export type GetPropertiesWithPathInput = - StorageGetPropertiesInputWithPath; + StorageGetPropertiesInputWithPath; /** * @deprecated Use {@link GetUrlWithPathInput} instead. * Input type for S3 getUrl API. */ -export type GetUrlInput = StorageGetUrlInputWithKey; +export type GetUrlInput = StorageGetUrlInputWithKey; /** * Input type with path for S3 getUrl API. */ export type GetUrlWithPathInput = - StorageGetUrlInputWithPath; + StorageGetUrlInputWithPath; /** * Input type with path for S3 list API. Lists all bucket objects. */ export type ListAllWithPathInput = - StorageListInputWithPath; + StorageListInputWithPath; /** * Input type with path for S3 list API. Lists bucket objects with pagination. */ export type ListPaginateWithPathInput = - StorageListInputWithPath; + StorageListInputWithPath; /** * @deprecated Use {@link ListAllWithPathInput} instead. * Input type for S3 list API. Lists all bucket objects. */ -export type ListAllInput = StorageListInputWithPrefix; +export type ListAllInput = StorageListInputWithPrefix; /** * @deprecated Use {@link ListPaginateWithPathInput} instead. * Input type for S3 list API. Lists bucket objects with pagination. */ export type ListPaginateInput = - StorageListInputWithPrefix; + StorageListInputWithPrefix; /** * @deprecated Use {@link RemoveWithPathInput} instead. @@ -115,23 +115,23 @@ export type RemoveWithPathInput = StorageRemoveInputWithPath< * Input type for S3 downloadData API. */ export type DownloadDataInput = - StorageDownloadDataInputWithKey; + StorageDownloadDataInputWithKey; /** * Input type with path for S3 downloadData API. */ export type DownloadDataWithPathInput = - StorageDownloadDataInputWithPath; + StorageDownloadDataInputWithPath; /** * @deprecated Use {@link UploadDataWithPathInput} instead. * Input type for S3 uploadData API. */ export type UploadDataInput = - StorageUploadDataInputWithKey; + StorageUploadDataInputWithKey; /** * Input type with path for S3 uploadData API. */ export type UploadDataWithPathInput = - StorageUploadDataInputWithPath; + StorageUploadDataInputWithPath; diff --git a/packages/storage/src/providers/s3/types/options.ts b/packages/storage/src/providers/s3/types/options.ts index c9948eabe3b..9a608c6dd2b 100644 --- a/packages/storage/src/providers/s3/types/options.ts +++ b/packages/storage/src/providers/s3/types/options.ts @@ -74,9 +74,9 @@ interface TransferOptions { /** * Input options type for S3 getProperties API. */ -/** @deprecated Use {@link GetPropertiesOptionsWithPath} instead. */ -export type GetPropertiesOptionsWithKey = ReadOptions & CommonOptions; -export type GetPropertiesOptionsWithPath = CommonOptions; +/** @deprecated Use {@link GetPropertiesWithPathOptions} instead. */ +export type GetPropertiesWithKeyOptions = ReadOptions & CommonOptions; +export type GetPropertiesWithPathOptions = CommonOptions; /** * Input options type for S3 getProperties API. @@ -84,25 +84,25 @@ export type GetPropertiesOptionsWithPath = CommonOptions; export type RemoveOptions = WriteOptions & CommonOptions; /** - * @deprecated Use {@link ListAllOptionsWithPath} instead. + * @deprecated Use {@link ListAllWithPathOptions} instead. * Input options type with prefix for S3 list all API. */ -export type ListAllOptionsWithPrefix = StorageListAllOptions & +export type ListAllWithPrefixOptions = StorageListAllOptions & ReadOptions & CommonOptions; /** - * @deprecated Use {@link ListPaginateOptionsWithPath} instead. + * @deprecated Use {@link ListPaginateWithPathOptions} instead. * Input options type with prefix for S3 list API to paginate items. */ -export type ListPaginateOptionsWithPrefix = StorageListPaginateOptions & +export type ListPaginateWithPrefixOptions = StorageListPaginateOptions & ReadOptions & CommonOptions; /** * Input options type with path for S3 list all API. */ -export type ListAllOptionsWithPath = Omit< +export type ListAllWithPathOptions = Omit< StorageListAllOptions, 'accessLevel' > & @@ -113,7 +113,7 @@ export type ListAllOptionsWithPath = Omit< /** * Input options type with path for S3 list API to paginate items. */ -export type ListPaginateOptionsWithPath = Omit< +export type ListPaginateWithPathOptions = Omit< StorageListPaginateOptions, 'accessLevel' > & @@ -150,9 +150,9 @@ export type GetUrlOptions = CommonOptions & { contentType?: string; }; -/** @deprecated Use {@link GetUrlOptionsWithPath} instead. */ -export type GetUrlOptionsWithKey = ReadOptions & GetUrlOptions; -export type GetUrlOptionsWithPath = GetUrlOptions; +/** @deprecated Use {@link GetUrlWithPathOptions} instead. */ +export type GetUrlWithKeyOptions = ReadOptions & GetUrlOptions; +export type GetUrlWithPathOptions = GetUrlOptions; /** * Input options type for S3 downloadData API. @@ -161,9 +161,9 @@ export type DownloadDataOptions = CommonOptions & TransferOptions & BytesRangeOptions; -/** @deprecated Use {@link DownloadDataOptionsWithPath} instead. */ -export type DownloadDataOptionsWithKey = ReadOptions & DownloadDataOptions; -export type DownloadDataOptionsWithPath = DownloadDataOptions; +/** @deprecated Use {@link DownloadDataWithPathOptions} instead. */ +export type DownloadDataWithKeyOptions = ReadOptions & DownloadDataOptions; +export type DownloadDataWithPathOptions = DownloadDataOptions; export type UploadDataOptions = CommonOptions & TransferOptions & { @@ -192,19 +192,19 @@ export type UploadDataOptions = CommonOptions & metadata?: Record; }; -/** @deprecated Use {@link UploadDataOptionsWithPath} instead. */ -export type UploadDataOptionsWithKey = WriteOptions & UploadDataOptions; -export type UploadDataOptionsWithPath = UploadDataOptions; +/** @deprecated Use {@link UploadDataWithPathOptions} instead. */ +export type UploadDataWithKeyOptions = WriteOptions & UploadDataOptions; +export type UploadDataWithPathOptions = UploadDataOptions; /** @deprecated This may be removed in the next major version. */ -export type CopySourceOptionsWithKey = ReadOptions & { +export type CopySourceWithKeyOptions = ReadOptions & { /** @deprecated This may be removed in the next major version. */ key: string; bucket?: StorageBucket; }; /** @deprecated This may be removed in the next major version. */ -export type CopyDestinationOptionsWithKey = WriteOptions & { +export type CopyDestinationWithKeyOptions = WriteOptions & { /** @deprecated This may be removed in the next major version. */ key: string; bucket?: StorageBucket;