From db0527717d3ca97e4a0a5916c9fe18705a6dfc05 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar <ashwinkumar2468@gmail.com> Date: Wed, 13 Sep 2023 08:57:55 -0700 Subject: [PATCH 1/2] fix(Storage): update storage type names (#12022) * chore(storage): align api types names * fix(Storage): update storage type names * fix: code cleanup --------- Co-authored-by: Sridhar <ashwsrir@amazon.com> Co-authored-by: AllanZhengYP <zheallan@amazon.com> --- packages/storage/src/index.ts | 23 ++++++++ .../storage/src/providers/s3/apis/copy.ts | 11 ++-- .../src/providers/s3/apis/downloadData.ts | 18 ++---- .../src/providers/s3/apis/getProperties.ts | 13 ++--- .../storage/src/providers/s3/apis/getUrl.ts | 14 ++--- .../src/providers/s3/apis/internal/copy.ts | 13 ++--- .../s3/apis/internal/getProperties.ts | 9 ++- .../src/providers/s3/apis/internal/getUrl.ts | 10 ++-- .../src/providers/s3/apis/internal/list.ts | 29 ++++------ .../src/providers/s3/apis/internal/remove.ts | 13 ++--- .../storage/src/providers/s3/apis/list.ts | 34 ++++++------ .../storage/src/providers/s3/apis/remove.ts | 16 ++---- .../src/providers/s3/apis/server/copy.ts | 12 ++-- .../providers/s3/apis/server/getProperties.ts | 9 ++- .../src/providers/s3/apis/server/getUrl.ts | 9 ++- .../src/providers/s3/apis/server/list.ts | 38 +++++++------ .../src/providers/s3/apis/server/remove.ts | 12 ++-- .../src/providers/s3/apis/uploadData/index.ts | 21 +++---- .../uploadData/multipart/getDataChunker.ts | 4 +- .../uploadData/multipart/initialUpload.ts | 4 +- .../uploadData/multipart/uploadHandlers.ts | 11 +--- .../s3/apis/uploadData/putObjectJob.ts | 11 +--- packages/storage/src/providers/s3/index.ts | 22 ++++++++ .../storage/src/providers/s3/types/index.ts | 42 +++++++++----- .../storage/src/providers/s3/types/inputs.ts | 38 +++++++++++++ .../storage/src/providers/s3/types/options.ts | 55 +++++++++++++++---- .../storage/src/providers/s3/types/outputs.ts | 44 +++++++++++++++ .../storage/src/providers/s3/types/results.ts | 42 -------------- packages/storage/src/types/index.ts | 28 +++++----- packages/storage/src/types/inputs.ts | 49 +++++++++++++++++ packages/storage/src/types/options.ts | 5 -- .../src/types/{results.ts => outputs.ts} | 14 ++--- packages/storage/src/types/requests.ts | 36 ------------ 33 files changed, 396 insertions(+), 313 deletions(-) create mode 100644 packages/storage/src/providers/s3/types/inputs.ts create mode 100644 packages/storage/src/providers/s3/types/outputs.ts delete mode 100644 packages/storage/src/providers/s3/types/results.ts create mode 100644 packages/storage/src/types/inputs.ts rename packages/storage/src/types/{results.ts => outputs.ts} (77%) delete mode 100644 packages/storage/src/types/requests.ts diff --git a/packages/storage/src/index.ts b/packages/storage/src/index.ts index 4a4c9bd45b7..c0923b44efa 100644 --- a/packages/storage/src/index.ts +++ b/packages/storage/src/index.ts @@ -10,6 +10,29 @@ export { copy, getUrl, } from './providers/s3'; + +export { + UploadDataInput, + DownloadDataInput, + RemoveInput, + ListAllInput, + ListPaginateInput, + GetPropertiesInput, + CopyInput, + GetUrlInput, +} from './providers/s3/types/inputs'; + +export { + UploadDataOutput, + DownloadDataOutput, + RemoveOutput, + ListAllOutput, + ListPaginateOutput, + GetPropertiesOutput, + CopyOutput, + GetUrlOutput, +} from './providers/s3/types/outputs'; + // TODO[AllanZhengYP]: support isCancelError in Node.js with node-fetch export { isCancelError } from './errors/CanceledError'; export { StorageError } from './errors/StorageError'; diff --git a/packages/storage/src/providers/s3/apis/copy.ts b/packages/storage/src/providers/s3/apis/copy.ts index 9baee642de8..17c32e557e2 100644 --- a/packages/storage/src/providers/s3/apis/copy.ts +++ b/packages/storage/src/providers/s3/apis/copy.ts @@ -2,8 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; -import { CopyRequest } from '../../../types'; -import { S3CopyResult } from '../types'; +import { CopyInput, CopyOutput } from '../types'; import { copy as copyInternal } from './internal/copy'; /** @@ -11,12 +10,12 @@ import { copy as copyInternal } from './internal/copy'; * different level or identityId (if source object's level is 'protected'). * * @async - * @param {CopyRequest} copyRequest - The request object. - * @return {Promise<S3CopyResult>} Promise resolves upon successful copy of the object. + * @param {CopyInput} input - The request object. + * @return {Promise<CopyOutput>} Promise resolves upon successful copy of the object. * @throws service: {@link S3Exception} - Thrown when checking for existence of the object * @throws validation: {@link StorageValidationErrorCode } - Thrown when * source or destination key are not defined. */ -export const copy = async (copyRequest: CopyRequest): Promise<S3CopyResult> => { - return copyInternal(Amplify, copyRequest); +export const copy = async (input: CopyInput): Promise<CopyOutput> => { + return copyInternal(Amplify, input); }; diff --git a/packages/storage/src/providers/s3/apis/downloadData.ts b/packages/storage/src/providers/s3/apis/downloadData.ts index 2ee1ce265ec..de948b18536 100644 --- a/packages/storage/src/providers/s3/apis/downloadData.ts +++ b/packages/storage/src/providers/s3/apis/downloadData.ts @@ -3,19 +3,18 @@ import { Amplify } from '@aws-amplify/core'; -import { S3TransferOptions, S3DownloadDataResult } from '../types'; +import { DownloadDataInput, DownloadDataOutput } from '../types'; import { resolveS3ConfigAndInput } from '../utils/resolveS3ConfigAndInput'; import { StorageValidationErrorCode } from '../../../errors/types/validation'; -import { StorageDownloadDataRequest, DownloadTask } from '../../../types'; import { createDownloadTask } from '../utils'; import { getObject } from '../utils/client'; /** * Download S3 object data to memory * - * @param {StorageDownloadDataRequest<S3TransferOptions>} downloadDataRequest The parameters that are passed to the + * @param {DownloadDataRequest<S3DownloadDataOptions>} input The parameters that are passed to the * downloadData operation. - * @returns {DownloadTask<S3DownloadDataResult>} Cancelable task exposing result promise from `result` property. + * @returns {DownloadDataOutput} Cancelable task exposing result promise from `result` property. * @throws service: {@link S3Exception} - thrown when checking for existence of the object * @throws validation: {@link StorageValidationErrorCode } - Validation errors * @@ -41,13 +40,11 @@ import { getObject } from '../utils/client'; * } *``` */ -export const downloadData = ( - downloadDataRequest: StorageDownloadDataRequest<S3TransferOptions> -): DownloadTask<S3DownloadDataResult> => { +export const downloadData = (input: DownloadDataInput): DownloadDataOutput => { const abortController = new AbortController(); const downloadTask = createDownloadTask({ - job: downloadDataJob(downloadDataRequest, abortController.signal), + job: downloadDataJob(input, abortController.signal), onCancel: (abortErrorOverwrite?: Error) => { abortController.abort(abortErrorOverwrite); }, @@ -57,10 +54,7 @@ export const downloadData = ( const downloadDataJob = ( - { - options: downloadDataOptions, - key, - }: StorageDownloadDataRequest<S3TransferOptions>, + { options: downloadDataOptions, key }: DownloadDataInput, abortSignal: AbortSignal ) => async () => { diff --git a/packages/storage/src/providers/s3/apis/getProperties.ts b/packages/storage/src/providers/s3/apis/getProperties.ts index 523e6e53364..33034f4132a 100644 --- a/packages/storage/src/providers/s3/apis/getProperties.ts +++ b/packages/storage/src/providers/s3/apis/getProperties.ts @@ -2,21 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; -import { StorageOperationRequest, StorageOptions } from '../../../types'; -import { S3GetPropertiesResult } from '../types'; +import { GetPropertiesOutput, GetPropertiesInput } from '../types'; import { getProperties as getPropertiesInternal } from './internal/getProperties'; /** * Gets the properties of a file. The properties include S3 system metadata and * the user metadata that was provided when uploading the file. * - * @param {StorageOperationRequest} req The request to make an API call. - * @returns {Promise<S3GetPropertiesResult>} A promise that resolves the properties. + * @param {GetPropertiesInput} The input to make an API call. + * @returns {Promise<GetPropertiesOutput>} A promise that resolves the properties. * @throws A {@link S3Exception} when the underlying S3 service returned error. * @throws A {@link StorageValidationErrorCode} when API call parameters are invalid. */ export const getProperties = ( - req: StorageOperationRequest<StorageOptions> -): Promise<S3GetPropertiesResult> => { - return getPropertiesInternal(Amplify, req); + input: GetPropertiesInput +): Promise<GetPropertiesOutput> => { + return getPropertiesInternal(Amplify, input); }; diff --git a/packages/storage/src/providers/s3/apis/getUrl.ts b/packages/storage/src/providers/s3/apis/getUrl.ts index 9c87b12a467..4fdcafa2a4d 100644 --- a/packages/storage/src/providers/s3/apis/getUrl.ts +++ b/packages/storage/src/providers/s3/apis/getUrl.ts @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; -import { StorageDownloadDataRequest } from '../../../types'; -import { S3GetUrlOptions, S3GetUrlResult } from '../types'; +import {} from '../../../types'; +import { GetUrlInput, GetUrlOutput } from '../types'; import { getUrl as getUrlInternal } from './internal/getUrl'; /** @@ -14,15 +14,13 @@ import { getUrl as getUrlInternal } from './internal/getUrl'; * to true, this method will verify the given object already exists in S3 before returning a presigned * URL, and will throw {@link StorageError} if the object does not exist. * - * @param {StorageDownloadDataRequest<S3GetUrlOptions>} The request object - * @return {Promise<S3GetUrlResult>} url of the object + * @param {GetUrlInput} The input object + * @return {Promise<GetUrlOutput>} url of the object * @throws service: {@link S3Exception} - thrown when checking for existence of the object * @throws validation: {@link StorageValidationErrorCode } - Validation errors * thrown either username or key are not defined. * */ -export const getUrl = ( - req: StorageDownloadDataRequest<S3GetUrlOptions> -): Promise<S3GetUrlResult> => { - return getUrlInternal(Amplify, req); +export const getUrl = (input: GetUrlInput): Promise<GetUrlOutput> => { + return getUrlInternal(Amplify, input); }; diff --git a/packages/storage/src/providers/s3/apis/internal/copy.ts b/packages/storage/src/providers/s3/apis/internal/copy.ts index 1fe6db384e9..0120a49e97b 100644 --- a/packages/storage/src/providers/s3/apis/internal/copy.ts +++ b/packages/storage/src/providers/s3/apis/internal/copy.ts @@ -2,8 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { AmplifyClassV6 } from '@aws-amplify/core'; -import { S3CopyResult } from '../../types'; -import { CopyRequest } from '../../../../types'; +import { CopyInput, CopyOutput } from '../../types'; import { resolveS3ConfigAndInput } from '../../utils'; import { StorageValidationErrorCode } from '../../../../errors/types/validation'; import { assertValidationError } from '../../../../errors/utils/assertValidationError'; @@ -11,12 +10,12 @@ import { copyObject } from '../../utils/client'; export const copy = async ( amplify: AmplifyClassV6, - copyRequest: CopyRequest -): Promise<S3CopyResult> => { + input: CopyInput +): Promise<CopyOutput> => { const { source: { key: sourceKey }, destination: { key: destinationKey }, - } = copyRequest; + } = input; assertValidationError(!!sourceKey, StorageValidationErrorCode.NoSourceKey); assertValidationError( @@ -28,10 +27,10 @@ export const copy = async ( s3Config, bucket, keyPrefix: sourceKeyPrefix, - } = await resolveS3ConfigAndInput(amplify, copyRequest.source); + } = await resolveS3ConfigAndInput(amplify, input.source); const { keyPrefix: destinationKeyPrefix } = await resolveS3ConfigAndInput( amplify, - copyRequest.destination + input.destination ); // resolveS3ConfigAndInput does not make extra API calls or storage access if called repeatedly. // TODO(ashwinkumar6) V6-logger: warn `You may copy files from another user if the source level is "protected", currently it's ${srcLevel}` diff --git a/packages/storage/src/providers/s3/apis/internal/getProperties.ts b/packages/storage/src/providers/s3/apis/internal/getProperties.ts index 11448142fb4..ce8c4d3168e 100644 --- a/packages/storage/src/providers/s3/apis/internal/getProperties.ts +++ b/packages/storage/src/providers/s3/apis/internal/getProperties.ts @@ -2,16 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 import { AmplifyClassV6 } from '@aws-amplify/core'; -import { StorageOptions, StorageOperationRequest } from '../../../../types'; -import { S3GetPropertiesResult } from '../../types'; +import { GetPropertiesInput, GetPropertiesOutput } from '../../types'; import { resolveS3ConfigAndInput } from '../../utils'; import { headObject } from '../../utils/client'; export const getProperties = async function ( amplify: AmplifyClassV6, - getPropertiesRequest: StorageOperationRequest<StorageOptions> -): Promise<S3GetPropertiesResult> { - const { key, options } = getPropertiesRequest; + input: GetPropertiesInput +): Promise<GetPropertiesOutput> { + const { key, options } = input; const { s3Config, bucket, keyPrefix } = await resolveS3ConfigAndInput( amplify, options diff --git a/packages/storage/src/providers/s3/apis/internal/getUrl.ts b/packages/storage/src/providers/s3/apis/internal/getUrl.ts index a99ebb26fb1..a0562c7c479 100644 --- a/packages/storage/src/providers/s3/apis/internal/getUrl.ts +++ b/packages/storage/src/providers/s3/apis/internal/getUrl.ts @@ -2,9 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { AmplifyClassV6 } from '@aws-amplify/core'; - -import { StorageDownloadDataRequest } from '../../../../types'; -import { S3GetUrlOptions, S3GetUrlResult } from '../../types'; +import { GetUrlInput, GetUrlOutput } from '../../types'; import { StorageValidationErrorCode } from '../../../../errors/types/validation'; import { getPresignedGetObjectUrl } from '../../utils/client'; import { getProperties } from './getProperties'; @@ -17,9 +15,9 @@ import { export const getUrl = async function ( amplify: AmplifyClassV6, - getUrlRequest: StorageDownloadDataRequest<S3GetUrlOptions> -): Promise<S3GetUrlResult> { - const { key, options } = getUrlRequest; + input: GetUrlInput +): Promise<GetUrlOutput> { + const { key, options } = input; if (options?.validateObjectExistence) { await getProperties(amplify, { key, options }); diff --git a/packages/storage/src/providers/s3/apis/internal/list.ts b/packages/storage/src/providers/s3/apis/internal/list.ts index fff8647d7ad..f5321198262 100644 --- a/packages/storage/src/providers/s3/apis/internal/list.ts +++ b/packages/storage/src/providers/s3/apis/internal/list.ts @@ -3,14 +3,11 @@ import { AmplifyClassV6 } from '@aws-amplify/core'; import { - StorageListRequest, - StorageListAllOptions, - StorageListPaginateOptions, -} from '../../../../types'; -import { - S3ListOutputItem, - S3ListAllResult, - S3ListPaginateResult, + ListAllInput, + ListPaginateInput, + ListAllOutput, + ListPaginateOutput, + ListOutputItem, } from '../../types'; import { resolveS3ConfigAndInput } from '../../utils'; import { ResolvedS3Config } from '../../types/options'; @@ -22,7 +19,7 @@ import { const MAX_PAGE_SIZE = 1000; -type ListRequestArgs = { +type ListInputArgs = { s3Config: ResolvedS3Config; listParams: ListObjectsV2Input; prefix: string; @@ -30,11 +27,9 @@ type ListRequestArgs = { export const list = async ( amplify: AmplifyClassV6, - listRequest?: - | StorageListRequest<StorageListAllOptions> - | StorageListRequest<StorageListPaginateOptions> -): Promise<S3ListAllResult | S3ListPaginateResult> => { - const { options = {}, prefix: path = '' } = listRequest ?? {}; + input?: ListAllInput | ListPaginateInput +): Promise<ListAllOutput | ListPaginateOutput> => { + const { options = {}, prefix: path = '' } = input ?? {}; const { s3Config, bucket, @@ -55,9 +50,9 @@ const _listAll = async ({ s3Config, listParams, prefix, -}: ListRequestArgs): Promise<S3ListAllResult> => { +}: ListInputArgs): Promise<ListAllOutput> => { // TODO(ashwinkumar6) V6-logger: pageSize and nextToken aren't required when listing all items - const listResult: S3ListOutputItem[] = []; + const listResult: ListOutputItem[] = []; let continuationToken = listParams.ContinuationToken; do { const { items: pageResults, nextToken: pageNextToken } = await _list({ @@ -82,7 +77,7 @@ const _list = async ({ s3Config, listParams, prefix, -}: ListRequestArgs): Promise<S3ListPaginateResult> => { +}: ListInputArgs): Promise<ListPaginateOutput> => { const listParamsClone = { ...listParams }; if (!listParamsClone.MaxKeys || listParamsClone.MaxKeys > MAX_PAGE_SIZE) { listParamsClone.MaxKeys = MAX_PAGE_SIZE; diff --git a/packages/storage/src/providers/s3/apis/internal/remove.ts b/packages/storage/src/providers/s3/apis/internal/remove.ts index 15e8314c9a9..93fc9a6bead 100644 --- a/packages/storage/src/providers/s3/apis/internal/remove.ts +++ b/packages/storage/src/providers/s3/apis/internal/remove.ts @@ -2,20 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 import { AmplifyClassV6 } from '@aws-amplify/core'; - -import { - StorageOperationRequest, - StorageRemoveOptions, - StorageRemoveResult, -} from '../../../../types'; +import { RemoveInput, RemoveOutput } from '../../types'; import { resolveS3ConfigAndInput } from '../../utils'; import { deleteObject } from '../../utils/client'; export const remove = async ( amplify: AmplifyClassV6, - removeRequest: StorageOperationRequest<StorageRemoveOptions> -): Promise<StorageRemoveResult> => { - const { key, options = {} } = removeRequest; + input: RemoveInput +): Promise<RemoveOutput> => { + const { key, options = {} } = input; const { s3Config, keyPrefix, bucket } = await resolveS3ConfigAndInput( amplify, options diff --git a/packages/storage/src/providers/s3/apis/list.ts b/packages/storage/src/providers/s3/apis/list.ts index f54f78f0678..d7910c43ba3 100644 --- a/packages/storage/src/providers/s3/apis/list.ts +++ b/packages/storage/src/providers/s3/apis/list.ts @@ -3,37 +3,35 @@ import { Amplify } from '@aws-amplify/core'; import { - StorageListAllOptions, - StorageListPaginateOptions, - StorageListRequest, -} from '../../../types'; -import { S3ListAllResult, S3ListPaginateResult } from '../types'; + ListAllInput, + ListPaginateInput, + ListAllOutput, + ListPaginateOutput, +} from '../types'; import { list as listInternal } from './internal/list'; -type S3ListApi = { +type ListApi = { /** * List files with given prefix in pages * pageSize defaulted to 1000. Additionally, the result will include a nextToken if there are more items to retrieve. - * @param {StorageListRequest<StorageListPaginateOptions>} req - The request object - * @return {Promise<S3ListPaginateResult>} - Promise resolves to list of keys and metadata with + * @param {ListPaginateInput} The input object + * @return {Promise<ListPaginateOutput>} - Promise resolves to list of keys and metadata with * @throws service: {@link S3Exception} - S3 service errors thrown when checking for existence of bucket * @throws validation: {@link StorageValidationErrorCode } - thrown when there are issues with credentials */ - ( - req?: StorageListRequest<StorageListPaginateOptions> - ): Promise<S3ListPaginateResult>; + (input?: ListPaginateInput): Promise<ListPaginateOutput>; /** * List all files from S3. You can set `listAll` to true in `options` to get all the files from S3. - * @param {StorageListRequest<StorageListAllOptions>} req - The request object - * @return {Promise<S3ListAllResult>} - Promise resolves to list of keys and metadata for all objects in path + * @param {ListAllInput} The input object + * @return {Promise<ListAllOutput>} - Promise resolves to list of keys and metadata for all objects in path * @throws service: {@link S3Exception} - S3 service errors thrown when checking for existence of bucket * @throws validation: {@link StorageValidationErrorCode } - thrown when there are issues with credentials */ - (req?: StorageListRequest<StorageListAllOptions>): Promise<S3ListAllResult>; + (input?: ListAllInput): Promise<ListAllOutput>; }; -export const list: S3ListApi = ( - req -): Promise<S3ListAllResult | S3ListPaginateResult> => { - return listInternal(Amplify, req ?? {}); +export const list: ListApi = ( + input?: ListAllInput | ListPaginateInput +): Promise<ListAllOutput | ListPaginateOutput> => { + return listInternal(Amplify, input ?? {}); }; diff --git a/packages/storage/src/providers/s3/apis/remove.ts b/packages/storage/src/providers/s3/apis/remove.ts index 76d0a75b3a2..4a4b7428c42 100644 --- a/packages/storage/src/providers/s3/apis/remove.ts +++ b/packages/storage/src/providers/s3/apis/remove.ts @@ -2,22 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; -import { - StorageOperationRequest, - StorageRemoveOptions, - StorageRemoveResult, -} from '../../../types'; +import { RemoveInput, RemoveOutput } from '../types'; import { remove as removeInternal } from './internal/remove'; /** * Remove a file from your S3 bucket. - * @param {StorageOperationRequest<StorageRemoveOptions>} req - The request object - * @return {Promise<StorageRemoveResult>} - Promise resolves upon successful removal of the object + * @param {RemoveInput} The input object + * @return {Promise<RemoveOutput>} - Promise resolves upon successful removal of the object * @throws service: {@link S3Exception} - S3 service errors thrown while getting properties * @throws validation: {@link StorageValidationErrorCode } - Validation errors thrown */ -export const remove = ( - req: StorageOperationRequest<StorageRemoveOptions> -): Promise<StorageRemoveResult> => { - return removeInternal(Amplify, req); +export const remove = (input: RemoveInput): Promise<RemoveOutput> => { + return removeInternal(Amplify, input); }; diff --git a/packages/storage/src/providers/s3/apis/server/copy.ts b/packages/storage/src/providers/s3/apis/server/copy.ts index 75b039f0aae..ea8e9de90f8 100644 --- a/packages/storage/src/providers/s3/apis/server/copy.ts +++ b/packages/storage/src/providers/s3/apis/server/copy.ts @@ -5,16 +5,12 @@ import { AmplifyServer, getAmplifyServerContext, } from '@aws-amplify/core/internals/adapter-core'; -import { CopyRequest } from '../../../../types'; -import { S3CopyResult } from '../../types'; +import { CopyInput, CopyOutput } from '../../types'; import { copy as copyInternal } from '../internal/copy'; export const copy = async ( contextSpec: AmplifyServer.ContextSpec, - copyRequest: CopyRequest -): Promise<S3CopyResult> => { - return copyInternal( - getAmplifyServerContext(contextSpec).amplify, - copyRequest - ); + input: CopyInput +): Promise<CopyOutput> => { + return copyInternal(getAmplifyServerContext(contextSpec).amplify, input); }; diff --git a/packages/storage/src/providers/s3/apis/server/getProperties.ts b/packages/storage/src/providers/s3/apis/server/getProperties.ts index d9ec4f490f1..c26bf24f502 100644 --- a/packages/storage/src/providers/s3/apis/server/getProperties.ts +++ b/packages/storage/src/providers/s3/apis/server/getProperties.ts @@ -5,16 +5,15 @@ import { AmplifyServer, getAmplifyServerContext, } from '@aws-amplify/core/internals/adapter-core'; -import { StorageOperationRequest, StorageOptions } from '../../../../types'; -import { S3GetPropertiesResult } from '../../types'; +import { GetPropertiesInput, GetPropertiesOutput } from '../../types'; import { getProperties as getPropertiesInternal } from '../internal/getProperties'; export const getProperties = ( contextSpec: AmplifyServer.ContextSpec, - req: StorageOperationRequest<StorageOptions> -): Promise<S3GetPropertiesResult> => { + input: GetPropertiesInput +): Promise<GetPropertiesOutput> => { return getPropertiesInternal( getAmplifyServerContext(contextSpec).amplify, - req + input ); }; diff --git a/packages/storage/src/providers/s3/apis/server/getUrl.ts b/packages/storage/src/providers/s3/apis/server/getUrl.ts index 44a1ad76740..7b6cc802cbe 100644 --- a/packages/storage/src/providers/s3/apis/server/getUrl.ts +++ b/packages/storage/src/providers/s3/apis/server/getUrl.ts @@ -5,13 +5,12 @@ import { AmplifyServer, getAmplifyServerContext, } from '@aws-amplify/core/internals/adapter-core'; -import { StorageDownloadDataRequest } from '../../../../types'; -import { S3GetUrlOptions, S3GetUrlResult } from '../../types'; +import { GetUrlInput, GetUrlOutput } from '../../types'; import { getUrl as getUrlInternal } from '../internal/getUrl'; export const getUrl = async ( contextSpec: AmplifyServer.ContextSpec, - req: StorageDownloadDataRequest<S3GetUrlOptions> -): Promise<S3GetUrlResult> => { - return getUrlInternal(getAmplifyServerContext(contextSpec).amplify, req); + input: GetUrlInput +): Promise<GetUrlOutput> => { + return getUrlInternal(getAmplifyServerContext(contextSpec).amplify, input); }; diff --git a/packages/storage/src/providers/s3/apis/server/list.ts b/packages/storage/src/providers/s3/apis/server/list.ts index 68b81fdf165..970301c1622 100644 --- a/packages/storage/src/providers/s3/apis/server/list.ts +++ b/packages/storage/src/providers/s3/apis/server/list.ts @@ -6,39 +6,45 @@ import { getAmplifyServerContext, } from '@aws-amplify/core/internals/adapter-core'; import { - StorageListAllOptions, - StorageListPaginateOptions, - StorageListRequest, -} from '../../../../types'; -import { S3ListAllResult, S3ListPaginateResult } from '../../types'; + ListAllInput, + ListPaginateInput, + ListAllOutput, + ListPaginateOutput, +} from '../../types'; import { list as listInternal } from '../internal/list'; -type S3ListApi = { +type ListApi = { /** * Lists bucket objects with pagination. - * @param {StorageListRequest<StorageListPaginateOptions>} req - The request object - * @return {Promise<S3ListPaginateResult>} - Promise resolves to list of keys and metadata with + * @param {ListPaginateInput} The input object + * @return {Promise<ListPaginateOutput>} - Promise resolves to list of keys and metadata with * pageSize defaulting to 1000. Additionally the result will include a nextToken if there are more items to retrieve * @throws service: {@link S3Exception} - S3 service errors thrown when checking for existence of bucket * @throws validation: {@link StorageValidationErrorCode } - thrown when there are issues with credentials */ ( contextSpec: AmplifyServer.ContextSpec, - req?: StorageListRequest<StorageListPaginateOptions> - ): Promise<S3ListPaginateResult>; + input?: ListPaginateInput + ): Promise<ListPaginateOutput>; /** * Lists all bucket objects. - * @param {StorageListRequest<StorageListAllOptions>} req - The request object - * @return {Promise<S3ListAllResult>} - Promise resolves to list of keys and metadata for all objects in path + * @param {ListAllInput} The input object + * @return {Promise<ListAllOutput>} - Promise resolves to list of keys and metadata for all objects in path * @throws service: {@link S3Exception} - S3 service errors thrown when checking for existence of bucket * @throws validation: {@link StorageValidationErrorCode } - thrown when there are issues with credentials */ ( contextSpec: AmplifyServer.ContextSpec, - req?: StorageListRequest<StorageListAllOptions> - ): Promise<S3ListAllResult>; + input?: ListAllInput + ): Promise<ListAllOutput>; }; -export const list: S3ListApi = (contextSpec, req) => { - return listInternal(getAmplifyServerContext(contextSpec).amplify, req ?? {}); +export const list: ListApi = ( + contextSpec: AmplifyServer.ContextSpec, + input?: ListAllInput | ListPaginateInput +): Promise<ListAllOutput | ListPaginateOutput> => { + return listInternal( + getAmplifyServerContext(contextSpec).amplify, + input ?? {} + ); }; diff --git a/packages/storage/src/providers/s3/apis/server/remove.ts b/packages/storage/src/providers/s3/apis/server/remove.ts index bfd1a97ef8d..d54d0687333 100644 --- a/packages/storage/src/providers/s3/apis/server/remove.ts +++ b/packages/storage/src/providers/s3/apis/server/remove.ts @@ -5,16 +5,12 @@ import { AmplifyServer, getAmplifyServerContext, } from '@aws-amplify/core/internals/adapter-core'; -import { - StorageOperationRequest, - StorageRemoveOptions, - StorageRemoveResult, -} from '../../../../types'; +import { RemoveInput, RemoveOutput } from '../../types'; import { remove as removeInternal } from '../internal/remove'; export const remove = ( contextSpec: AmplifyServer.ContextSpec, - req: StorageOperationRequest<StorageRemoveOptions> -): Promise<StorageRemoveResult> => { - return removeInternal(getAmplifyServerContext(contextSpec).amplify, req); + input: RemoveInput +): Promise<RemoveOutput> => { + return removeInternal(getAmplifyServerContext(contextSpec).amplify, input); }; diff --git a/packages/storage/src/providers/s3/apis/uploadData/index.ts b/packages/storage/src/providers/s3/apis/uploadData/index.ts index 3dcf3a783a7..03dbe76f19b 100644 --- a/packages/storage/src/providers/s3/apis/uploadData/index.ts +++ b/packages/storage/src/providers/s3/apis/uploadData/index.ts @@ -1,9 +1,8 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { S3UploadDataResult, S3UploadOptions } from '../../types'; +import { UploadDataInput, UploadDataOutput } from '../../types'; import { createUploadTask } from '../../utils'; -import { StorageUploadDataRequest, UploadTask } from '../../../../types'; import { assertValidationError } from '../../../../errors/utils/assertValidationError'; import { StorageValidationErrorCode } from '../../../../errors/types/validation'; import { DEFAULT_PART_SIZE, MAX_OBJECT_SIZE } from '../../utils/constants'; @@ -19,9 +18,9 @@ import { getMultipartUploadHandlers } from './multipart'; * * Maximum object size is 5TB. * * Maximum object size if the size cannot be determined before upload is 50GB. * - * @param {StorageUploadDataRequest<S3UploadOptions>} uploadDataRequest The parameters that are passed to the + * @param {UploadDataInput} The input parameters that are passed to the * uploadData operation. - * @returns {UploadTask<S3UploadDataResult>} Cancelable and Resumable task exposing result promise from `result` + * @returns {UploadDataOutput} Cancelable and Resumable task exposing result promise from `result` * property. * @throws service: {@link S3Exception} - thrown when checking for existence of the object * @throws validation: {@link StorageValidationErrorCode } - Validation errors. @@ -60,10 +59,8 @@ import { getMultipartUploadHandlers } from './multipart'; * await uploadTask.result; * ``` */ -export const uploadData = ( - uploadDataRequest: StorageUploadDataRequest<S3UploadOptions> -): UploadTask<S3UploadDataResult> => { - const { data } = uploadDataRequest; +export const uploadData = (input: UploadDataInput): UploadDataOutput => { + const { data } = input; const dataByteLength = byteLength(data); assertValidationError( @@ -75,18 +72,14 @@ export const uploadData = ( const abortController = new AbortController(); return createUploadTask({ isMultipartUpload: false, - job: putObjectJob( - uploadDataRequest, - abortController.signal, - dataByteLength - ), + job: putObjectJob(input, abortController.signal, dataByteLength), onCancel: (abortErrorOverwrite?: Error) => { abortController.abort(abortErrorOverwrite); }, }); } else { const { multipartUploadJob, onPause, onResume, onCancel } = - getMultipartUploadHandlers(uploadDataRequest, dataByteLength); + getMultipartUploadHandlers(input, dataByteLength); return createUploadTask({ isMultipartUpload: true, job: multipartUploadJob, diff --git a/packages/storage/src/providers/s3/apis/uploadData/multipart/getDataChunker.ts b/packages/storage/src/providers/s3/apis/uploadData/multipart/getDataChunker.ts index bb91d363010..75e391cc4db 100644 --- a/packages/storage/src/providers/s3/apis/uploadData/multipart/getDataChunker.ts +++ b/packages/storage/src/providers/s3/apis/uploadData/multipart/getDataChunker.ts @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { StorageUploadSourceOptions } from '../../../../../types'; +import { StorageUploadDataPayload } from '../../../../../types'; import { StorageValidationErrorCode, validationErrorMap, @@ -16,7 +16,7 @@ export type PartToUpload = { }; export const getDataChunker = ( - data: StorageUploadSourceOptions, + data: StorageUploadDataPayload, totalSize?: number ) => { const partSize = calculatePartSize(totalSize); diff --git a/packages/storage/src/providers/s3/apis/uploadData/multipart/initialUpload.ts b/packages/storage/src/providers/s3/apis/uploadData/multipart/initialUpload.ts index be62c10fcac..1c81e9efa1a 100644 --- a/packages/storage/src/providers/s3/apis/uploadData/multipart/initialUpload.ts +++ b/packages/storage/src/providers/s3/apis/uploadData/multipart/initialUpload.ts @@ -9,12 +9,12 @@ import { getUploadsCacheKey, } from './uploadCache'; import { ResolvedS3Config } from '../../../types/options'; -import { StorageUploadSourceOptions } from '../../../../../types'; +import { StorageUploadDataPayload } from '../../../../../types'; import { Part, createMultipartUpload } from '../../../utils/client'; type LoadOrCreateMultipartUploadOptions = { s3Config: ResolvedS3Config; - data: StorageUploadSourceOptions; + data: StorageUploadDataPayload; bucket: string; accessLevel: StorageAccessLevel; keyPrefix: string; 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 708bc04b92e..62f01d1de1e 100644 --- a/packages/storage/src/providers/s3/apis/uploadData/multipart/uploadHandlers.ts +++ b/packages/storage/src/providers/s3/apis/uploadData/multipart/uploadHandlers.ts @@ -4,10 +4,9 @@ import { Amplify, StorageAccessLevel } from '@aws-amplify/core'; import { getDataChunker } from './getDataChunker'; -import { S3UploadOptions } from '../../../types'; +import { UploadDataInput } from '../../../types'; import { resolveS3ConfigAndInput } from '../../../utils'; -import { StorageUploadDataRequest } from '../../../../../types'; -import { S3Item } from '../../../types/results'; +import { Item as S3Item } from '../../../types/outputs'; import { DEFAULT_ACCESS_LEVEL, DEFAULT_QUEUE_SIZE, @@ -33,11 +32,7 @@ import { * @internal */ export const getMultipartUploadHandlers = ( - { - options: uploadDataOptions, - key, - data, - }: StorageUploadDataRequest<S3UploadOptions>, + { options: uploadDataOptions, key, data }: UploadDataInput, size?: number ) => { let resolveCallback: ((value: S3Item) => void) | undefined; diff --git a/packages/storage/src/providers/s3/apis/uploadData/putObjectJob.ts b/packages/storage/src/providers/s3/apis/uploadData/putObjectJob.ts index 081947e0daf..50922b1334b 100644 --- a/packages/storage/src/providers/s3/apis/uploadData/putObjectJob.ts +++ b/packages/storage/src/providers/s3/apis/uploadData/putObjectJob.ts @@ -3,10 +3,9 @@ import { Amplify } from '@aws-amplify/core'; -import { S3UploadOptions } from '../../types'; +import { UploadDataInput } from '../../types'; import { calculateContentMd5, resolveS3ConfigAndInput } from '../../utils'; -import { StorageUploadDataRequest } from '../../../../types'; -import { S3Item } from '../../types/results'; +import { Item as S3Item } from '../../types/outputs'; import { putObject } from '../../utils/client'; /** @@ -16,11 +15,7 @@ import { putObject } from '../../utils/client'; */ export const putObjectJob = ( - { - options: uploadDataOptions, - key, - data, - }: StorageUploadDataRequest<S3UploadOptions>, + { options: uploadDataOptions, key, data }: UploadDataInput, abortSignal: AbortSignal, totalLength?: number ) => diff --git a/packages/storage/src/providers/s3/index.ts b/packages/storage/src/providers/s3/index.ts index d4bf1fb7ae4..dd2f2eb015e 100644 --- a/packages/storage/src/providers/s3/index.ts +++ b/packages/storage/src/providers/s3/index.ts @@ -10,3 +10,25 @@ export { copy, getUrl, } from './apis'; + +export { + UploadDataInput, + DownloadDataInput, + RemoveInput, + ListAllInput, + ListPaginateInput, + GetPropertiesInput, + CopyInput, + GetUrlInput, +} from './types/inputs'; + +export { + UploadDataOutput, + DownloadDataOutput, + RemoveOutput, + ListAllOutput, + ListPaginateOutput, + GetPropertiesOutput, + CopyOutput, + GetUrlOutput, +} from './types/outputs'; diff --git a/packages/storage/src/providers/s3/types/index.ts b/packages/storage/src/providers/s3/types/index.ts index 9e2ecb86f1f..7f8b49c6c15 100644 --- a/packages/storage/src/providers/s3/types/index.ts +++ b/packages/storage/src/providers/s3/types/index.ts @@ -2,20 +2,34 @@ // SPDX-License-Identifier: Apache-2.0 export { - S3Options, - S3TransferOptions, - S3GetUrlOptions, - S3UploadOptions, + GetUrlOptions, + UploadDataOptions, + GetPropertiesOptions, + ListAllOptions, + ListPaginateOptions, + RemoveOptions, + DownloadDataOptions, } from './options'; export { - S3DownloadDataResult, - S3DownloadFileResult, - S3GetUrlResult, - S3UploadDataResult, - S3ListOutputItem, - S3ListAllResult, - S3ListPaginateResult, - S3GetPropertiesResult, - S3CopyResult, -} from './results'; + DownloadDataOutput, + DownloadFileOutput, + GetUrlOutput, + UploadDataOutput, + ListOutputItem, + ListAllOutput, + ListPaginateOutput, + GetPropertiesOutput, + CopyOutput, + RemoveOutput, +} from './outputs'; +export { + CopyInput, + GetPropertiesInput, + GetUrlInput, + ListAllInput, + ListPaginateInput, + RemoveInput, + DownloadDataInput, + UploadDataInput, +} 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 new file mode 100644 index 00000000000..3640d6cd7ca --- /dev/null +++ b/packages/storage/src/providers/s3/types/inputs.ts @@ -0,0 +1,38 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { + StorageCopyInput, + StorageGetPropertiesInput, + StorageGetUrlInput, + StorageListInput, + StorageRemoveInput, + StorageDownloadDataInput, + StorageUploadDataInput, +} from '../../../types'; +import { + GetPropertiesOptions, + GetUrlOptions, + ListAllOptions, + ListPaginateOptions, + RemoveOptions, + DownloadDataOptions, + UploadDataOptions, +} from '../types'; + +export type CopyInput = StorageCopyInput; + +export type GetPropertiesInput = + StorageGetPropertiesInput<GetPropertiesOptions>; + +export type GetUrlInput = StorageGetUrlInput<GetUrlOptions>; + +export type ListAllInput = StorageListInput<ListAllOptions>; + +export type ListPaginateInput = StorageListInput<ListPaginateOptions>; + +export type RemoveInput = StorageRemoveInput<RemoveOptions>; + +export type DownloadDataInput = StorageDownloadDataInput<DownloadDataOptions>; + +export type UploadDataInput = StorageUploadDataInput<UploadDataOptions>; diff --git a/packages/storage/src/providers/s3/types/options.ts b/packages/storage/src/providers/s3/types/options.ts index 94bd3241fa2..b2bd747e1e9 100644 --- a/packages/storage/src/providers/s3/types/options.ts +++ b/packages/storage/src/providers/s3/types/options.ts @@ -5,12 +5,16 @@ import { Credentials } from '@aws-sdk/types'; import { TransferProgressEvent } from '../../../types'; -import { StorageOptions } from '../../../types/options'; +import { + StorageOptions, + StorageListAllOptions, + StorageListPaginateOptions, +} from '../../../types/options'; /** - * Request options type for S3 Storage operations. + * Input options type for S3 Storage operations. */ -export type S3Options = StorageOptions & { +export type Options = StorageOptions & { /** * Whether to use accelerate endpoint. * @default false @@ -19,16 +23,34 @@ export type S3Options = StorageOptions & { }; /** - * Request options type for S3 downloadData, uploadData APIs. + * Input options type for S3 getProperties API. */ -export type S3TransferOptions = S3Options & { - /** - * Callback function tracking the upload/download progress. - */ - onProgress?: (event: TransferProgressEvent) => void; -}; +export type GetPropertiesOptions = Options; + +/** + * Input options type for S3 getProperties API. + */ +export type RemoveOptions = Options; + +/** + * Input options type for S3 list API. + */ +export type ListAllOptions = StorageListAllOptions; + +/** + * Input options type for S3 list API. + */ +export type ListPaginateOptions = StorageListPaginateOptions; + +/** + * Input options type for S3 downloadData API. + */ +export type DownloadDataOptions = TransferOptions; -export type S3GetUrlOptions = S3Options & { +/** + * Input options type for S3 getUrl API. + */ +export type GetUrlOptions = Options & { /** * Whether to head object to make sure the object existence before downloading. * @default false @@ -41,7 +63,7 @@ export type S3GetUrlOptions = S3Options & { expiresIn?: number; }; -export type S3UploadOptions = Omit<S3TransferOptions, 'targetIdentityId'> & { +export type UploadDataOptions = Omit<TransferOptions, 'targetIdentityId'> & { /** * The default content-disposition header value of the file when downloading it. * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition @@ -76,3 +98,12 @@ export type ResolvedS3Config = { forcePathStyle?: boolean; useAccelerateEndpoint?: boolean; }; +/** + * Input options type for S3 downloadData, uploadData APIs. + */ +type TransferOptions = Options & { + /** + * Callback function tracking the upload/download progress. + */ + onProgress?: (event: TransferProgressEvent) => void; +}; diff --git a/packages/storage/src/providers/s3/types/outputs.ts b/packages/storage/src/providers/s3/types/outputs.ts new file mode 100644 index 00000000000..d7c36f66f5c --- /dev/null +++ b/packages/storage/src/providers/s3/types/outputs.ts @@ -0,0 +1,44 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { + StorageDownloadDataOutput, + StorageGetUrlOutput, + StorageItem, + StorageListOutput, + DownloadTask, + UploadTask, +} from '../../../types'; + +export interface Item extends StorageItem { + /** + * VersionId used to reference a specific version of the object. + */ + versionId?: string; + /** + * A standard MIME type describing the format of the object data. + */ + contentType?: string; +} + +export type DownloadDataOutput = DownloadTask<StorageDownloadDataOutput<Item>>; + +export type DownloadFileOutput = Item; + +export type GetUrlOutput = StorageGetUrlOutput; + +export type UploadDataOutput = UploadTask<Item>; + +export type GetPropertiesOutput = Item; + +export type ListOutputItem = Item; + +export type ListAllOutput = StorageListOutput<Item>; + +export type ListPaginateOutput = StorageListOutput<Item> & { + nextToken?: string; +}; + +// TODO: expose more properties if required +export type CopyOutput = Pick<Item, 'key'>; +export type RemoveOutput = Pick<Item, 'key'>; diff --git a/packages/storage/src/providers/s3/types/results.ts b/packages/storage/src/providers/s3/types/results.ts deleted file mode 100644 index 0e187e733f0..00000000000 --- a/packages/storage/src/providers/s3/types/results.ts +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -import { - StorageDownloadDataResult, - StorageGetUrlResult, - StorageItem, - StorageUploadResult, - StorageListResult, -} from '../../../types'; - -export interface S3Item extends StorageItem { - /** - * VersionId used to reference a specific version of the object. - */ - versionId?: string; - /** - * A standard MIME type describing the format of the object data. - */ - contentType?: string; -} - -export type S3DownloadDataResult = StorageDownloadDataResult<S3Item>; - -export type S3DownloadFileResult = S3Item; - -export type S3GetUrlResult = StorageGetUrlResult; - -export type S3UploadDataResult = S3Item; - -export type S3GetPropertiesResult = S3Item; - -export type S3ListOutputItem = S3Item; - -export type S3ListAllResult = StorageListResult<S3Item>; - -export type S3ListPaginateResult = StorageListResult<S3Item> & { - nextToken?: string; -}; - -// TODO: expose more properties if required -export type S3CopyResult = Required<Pick<S3Item, 'key'>>; diff --git a/packages/storage/src/types/index.ts b/packages/storage/src/types/index.ts index 31e0446d596..4f82a8299b9 100644 --- a/packages/storage/src/types/index.ts +++ b/packages/storage/src/types/index.ts @@ -3,12 +3,16 @@ export { DownloadTask, TransferProgressEvent, UploadTask } from './common'; export { - StorageListRequest, - StorageOperationRequest, - StorageDownloadDataRequest, - StorageUploadDataRequest, - CopyRequest, -} from './requests'; + StorageOperationInput, + StorageListInput, + StorageGetPropertiesInput, + StorageRemoveInput, + StorageDownloadDataInput, + StorageUploadDataInput, + StorageCopyInput, + StorageGetUrlInput, + StorageUploadDataPayload, +} from './inputs'; export { StorageOptions, StorageRemoveOptions, @@ -16,13 +20,11 @@ export { StorageListPaginateOptions, StorageCopySourceOptions, StorageCopyDestinationOptions, - StorageUploadSourceOptions, } from './options'; export { StorageItem, - StorageListResult, - StorageDownloadDataResult, - StorageGetUrlResult, - StorageUploadResult, - StorageRemoveResult, -} from './results'; + StorageListOutput, + StorageDownloadDataOutput, + StorageGetUrlOutput, + StorageUploadOutput, +} from './outputs'; diff --git a/packages/storage/src/types/inputs.ts b/packages/storage/src/types/inputs.ts new file mode 100644 index 00000000000..61ed132335b --- /dev/null +++ b/packages/storage/src/types/inputs.ts @@ -0,0 +1,49 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { + StorageOptions, + StorageListAllOptions, + StorageListPaginateOptions, + StorageCopySourceOptions, + StorageCopyDestinationOptions, +} from './options'; + +export type StorageOperationInput<Options extends StorageOptions> = { + key: string; + options?: Options; +}; + +export type StorageGetPropertiesInput<Options extends StorageOptions> = + StorageOperationInput<Options>; + +export type StorageRemoveInput<Options extends StorageOptions> = + StorageOperationInput<Options>; + +export type StorageListInput< + Options extends StorageListAllOptions | StorageListPaginateOptions +> = { + prefix?: string; + options?: Options; +}; + +export type StorageGetUrlInput<Options extends StorageOptions> = + StorageOperationInput<Options>; + +export type StorageDownloadDataInput<Options extends StorageOptions> = + StorageOperationInput<Options>; + +export type StorageUploadDataInput<Options extends StorageOptions> = + StorageOperationInput<Options> & { + data: StorageUploadDataPayload; + }; + +export type StorageCopyInput = { + source: StorageCopySourceOptions; + destination: StorageCopyDestinationOptions; +}; + +/** + * The data payload type for upload operation. + */ +export type StorageUploadDataPayload = Blob | BufferSource | string | File; diff --git a/packages/storage/src/types/options.ts b/packages/storage/src/types/options.ts index e0d79933a62..3a95ffa764d 100644 --- a/packages/storage/src/types/options.ts +++ b/packages/storage/src/types/options.ts @@ -10,11 +10,6 @@ export type StorageOptions = targetIdentityId?: string; }; -/** - * The data payload type for upload operation. - */ -export type StorageUploadSourceOptions = Blob | BufferSource | string | File; - export type StorageListAllOptions = StorageOptions & { listAll: true; }; diff --git a/packages/storage/src/types/results.ts b/packages/storage/src/types/outputs.ts similarity index 77% rename from packages/storage/src/types/results.ts rename to packages/storage/src/types/outputs.ts index fb35ccde051..766acf95365 100644 --- a/packages/storage/src/types/results.ts +++ b/packages/storage/src/types/outputs.ts @@ -7,7 +7,7 @@ export type StorageItem = { /** * Key of the object */ - key?: string; + key: string; /** * Creation date of the object. */ @@ -28,11 +28,11 @@ export type StorageItem = { metadata?: Record<string, string>; }; -export type StorageDownloadDataResult<T extends StorageItem> = T & { +export type StorageDownloadDataOutput<T extends StorageItem> = T & { body: ResponseBodyMixin; }; -export type StorageGetUrlResult = { +export type StorageGetUrlOutput = { /** * presigned URL of the given object. */ @@ -43,12 +43,8 @@ export type StorageGetUrlResult = { expiresAt: Date; }; -export type StorageUploadResult<Item extends StorageItem> = Item; - -export type StorageRemoveResult = { - key: string; -}; +export type StorageUploadOutput<Item extends StorageItem> = Item; -export type StorageListResult<Item extends StorageItem> = { +export type StorageListOutput<Item extends StorageItem> = { items: Item[]; }; diff --git a/packages/storage/src/types/requests.ts b/packages/storage/src/types/requests.ts deleted file mode 100644 index 2b8f59db3b1..00000000000 --- a/packages/storage/src/types/requests.ts +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -import { - StorageOptions, - StorageUploadSourceOptions, - StorageListAllOptions, - StorageListPaginateOptions, - StorageCopySourceOptions, - StorageCopyDestinationOptions, -} from './options'; - -export type StorageOperationRequest<Options extends StorageOptions> = { - key: string; - options?: Options; -}; - -export type StorageListRequest< - Options extends StorageListAllOptions | StorageListPaginateOptions -> = { - prefix?: string; - options?: Options; -}; - -export type StorageDownloadDataRequest<Options extends StorageOptions> = - StorageOperationRequest<Options>; - -export type StorageUploadDataRequest<Options extends StorageOptions> = - StorageOperationRequest<Options> & { - data: StorageUploadSourceOptions; - }; - -export type CopyRequest = { - source: StorageCopySourceOptions; - destination: StorageCopyDestinationOptions; -}; From 7c217083c826d9e842a04fae6bc08f51a7b7e82f Mon Sep 17 00:00:00 2001 From: Ashwin Kumar <ashwinkumar2468@gmail.com> Date: Wed, 13 Sep 2023 11:44:59 -0700 Subject: [PATCH 2/2] fix(storage): fix listOutput types (#12027) Co-authored-by: Sridhar <ashwsrir@amazon.com> --- packages/storage/src/providers/s3/types/index.ts | 1 - packages/storage/src/providers/s3/types/outputs.ts | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/storage/src/providers/s3/types/index.ts b/packages/storage/src/providers/s3/types/index.ts index 7f8b49c6c15..17c64167090 100644 --- a/packages/storage/src/providers/s3/types/index.ts +++ b/packages/storage/src/providers/s3/types/index.ts @@ -12,7 +12,6 @@ export { } from './options'; export { DownloadDataOutput, - DownloadFileOutput, GetUrlOutput, UploadDataOutput, ListOutputItem, diff --git a/packages/storage/src/providers/s3/types/outputs.ts b/packages/storage/src/providers/s3/types/outputs.ts index d7c36f66f5c..1c149a9213a 100644 --- a/packages/storage/src/providers/s3/types/outputs.ts +++ b/packages/storage/src/providers/s3/types/outputs.ts @@ -23,19 +23,17 @@ export interface Item extends StorageItem { export type DownloadDataOutput = DownloadTask<StorageDownloadDataOutput<Item>>; -export type DownloadFileOutput = Item; - export type GetUrlOutput = StorageGetUrlOutput; export type UploadDataOutput = UploadTask<Item>; export type GetPropertiesOutput = Item; -export type ListOutputItem = Item; +export type ListOutputItem = Omit<StorageItem, 'metadata'>; -export type ListAllOutput = StorageListOutput<Item>; +export type ListAllOutput = StorageListOutput<ListOutputItem>; -export type ListPaginateOutput = StorageListOutput<Item> & { +export type ListPaginateOutput = StorageListOutput<ListOutputItem> & { nextToken?: string; };