From 4c1d2272c6c5bfe282312024ffacdb22d94e92be Mon Sep 17 00:00:00 2001 From: ashika112 Date: Tue, 2 Apr 2024 17:09:53 -0700 Subject: [PATCH 1/5] update overload type to include union --- packages/storage/src/providers/s3/apis/copy.ts | 1 + packages/storage/src/providers/s3/apis/downloadData.ts | 3 +++ packages/storage/src/providers/s3/apis/getProperties.ts | 3 +++ packages/storage/src/providers/s3/apis/getUrl.ts | 1 + packages/storage/src/providers/s3/apis/list.ts | 6 ++++++ packages/storage/src/providers/s3/apis/remove.ts | 1 + packages/storage/src/providers/s3/apis/uploadData/index.ts | 1 + 7 files changed, 16 insertions(+) diff --git a/packages/storage/src/providers/s3/apis/copy.ts b/packages/storage/src/providers/s3/apis/copy.ts index f71c11dfb56..86125aa6e12 100644 --- a/packages/storage/src/providers/s3/apis/copy.ts +++ b/packages/storage/src/providers/s3/apis/copy.ts @@ -39,6 +39,7 @@ interface Copy { * source or destination key is not defined. */ (input: CopyInputWithKey): Promise; + (input: CopyInputWithPath | CopyInputWithKey): Promise; } export const copy: Copy = ( diff --git a/packages/storage/src/providers/s3/apis/downloadData.ts b/packages/storage/src/providers/s3/apis/downloadData.ts index 6dcd17b7fab..6c538f27293 100644 --- a/packages/storage/src/providers/s3/apis/downloadData.ts +++ b/packages/storage/src/providers/s3/apis/downloadData.ts @@ -90,6 +90,9 @@ interface DownloadData { *``` */ (input: DownloadDataInputWithKey): DownloadDataOutputWithKey; + ( + input: DownloadDataInputWithPath | DownloadDataInputWithKey, + ): DownloadDataOutput; } export const downloadData: DownloadData = ( diff --git a/packages/storage/src/providers/s3/apis/getProperties.ts b/packages/storage/src/providers/s3/apis/getProperties.ts index 35afaa2e014..21e7d3752d4 100644 --- a/packages/storage/src/providers/s3/apis/getProperties.ts +++ b/packages/storage/src/providers/s3/apis/getProperties.ts @@ -38,6 +38,9 @@ interface GetProperties { * @throws A `StorageValidationErrorCode` when API call parameters are invalid. */ (input: GetPropertiesInputWithKey): Promise; + ( + input: GetPropertiesInputWithPath | GetPropertiesInputWithKey, + ): Promise; } export const getProperties: GetProperties = < diff --git a/packages/storage/src/providers/s3/apis/getUrl.ts b/packages/storage/src/providers/s3/apis/getUrl.ts index 5f426952fd5..90844715f55 100644 --- a/packages/storage/src/providers/s3/apis/getUrl.ts +++ b/packages/storage/src/providers/s3/apis/getUrl.ts @@ -50,6 +50,7 @@ interface GetUrl { * */ (input: GetUrlInputWithKey): Promise; + (input: GetUrlInputWithPath | GetUrlInputWithKey): Promise; } export const getUrl: GetUrl = (input: GetUrlInput): Promise => diff --git a/packages/storage/src/providers/s3/apis/list.ts b/packages/storage/src/providers/s3/apis/list.ts index 9ee3662430b..2a165610816 100644 --- a/packages/storage/src/providers/s3/apis/list.ts +++ b/packages/storage/src/providers/s3/apis/list.ts @@ -58,6 +58,12 @@ interface ListApi { * @throws validation: `StorageValidationErrorCode` - thrown when there are issues with credentials */ (input?: ListAllInputWithPrefix): Promise; + ( + input?: ListAllInputWithPath | ListAllInputWithPrefix, + ): Promise; + ( + input?: ListPaginateInputWithPath | ListPaginateInputWithPrefix, + ): Promise; } export const list: ListApi = < diff --git a/packages/storage/src/providers/s3/apis/remove.ts b/packages/storage/src/providers/s3/apis/remove.ts index f98d63c1735..bc856748a73 100644 --- a/packages/storage/src/providers/s3/apis/remove.ts +++ b/packages/storage/src/providers/s3/apis/remove.ts @@ -36,6 +36,7 @@ interface RemoveApi { * when there is no key or its empty. */ (input: RemoveInputWithKey): Promise; + (input: RemoveInputWithPath | RemoveInputWithKey): Promise; } export const remove: RemoveApi = ( diff --git a/packages/storage/src/providers/s3/apis/uploadData/index.ts b/packages/storage/src/providers/s3/apis/uploadData/index.ts index ae4bbeefa65..24e27ed0ad3 100644 --- a/packages/storage/src/providers/s3/apis/uploadData/index.ts +++ b/packages/storage/src/providers/s3/apis/uploadData/index.ts @@ -126,6 +126,7 @@ interface UploadData { * ``` */ (input: UploadDataInputWithKey): UploadDataOutputWithKey; + (input: UploadDataInputWithPath | UploadDataInputWithKey): UploadDataOutput; } export const uploadData: UploadData = ( From 517a6379bf5fb3d7e97307f11a4e6def46183519 Mon Sep 17 00:00:00 2001 From: ashika112 Date: Tue, 2 Apr 2024 17:38:42 -0700 Subject: [PATCH 2/5] update type name and cleanup --- .../src/providers/s3/utils/isInputWithPath.ts | 4 ++-- .../s3/utils/validateStorageOperationInput.ts | 2 +- packages/storage/src/types/index.ts | 1 - packages/storage/src/types/inputs.ts | 14 +++----------- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/storage/src/providers/s3/utils/isInputWithPath.ts b/packages/storage/src/providers/s3/utils/isInputWithPath.ts index b0943154351..86e5351f914 100644 --- a/packages/storage/src/providers/s3/utils/isInputWithPath.ts +++ b/packages/storage/src/providers/s3/utils/isInputWithPath.ts @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 import { - StorageOperationInputType, + StorageOperationInput, StorageOperationInputWithPath, } from '../../../types/inputs'; export const isInputWithPath = ( - input: StorageOperationInputType, + input: StorageOperationInput, ): input is StorageOperationInputWithPath => { return input.path !== undefined; }; diff --git a/packages/storage/src/providers/s3/utils/validateStorageOperationInput.ts b/packages/storage/src/providers/s3/utils/validateStorageOperationInput.ts index 12ff4eb0c2e..585701c81e9 100644 --- a/packages/storage/src/providers/s3/utils/validateStorageOperationInput.ts +++ b/packages/storage/src/providers/s3/utils/validateStorageOperationInput.ts @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { StorageOperationInputType as Input } from '../../../types/inputs'; +import { StorageOperationInput as Input } from '../../../types/inputs'; import { assertValidationError } from '../../../errors/utils/assertValidationError'; import { StorageValidationErrorCode } from '../../../errors/types/validation'; diff --git a/packages/storage/src/types/index.ts b/packages/storage/src/types/index.ts index 0f1a084f461..317fa20104c 100644 --- a/packages/storage/src/types/index.ts +++ b/packages/storage/src/types/index.ts @@ -8,7 +8,6 @@ export { UploadTask, } from './common'; export { - StorageOperationInput, StorageGetPropertiesInputWithKey, StorageGetPropertiesInputWithPath, StorageListInputWithPrefix, diff --git a/packages/storage/src/types/inputs.ts b/packages/storage/src/types/inputs.ts index 8a2cc0a0165..f371cbbb234 100644 --- a/packages/storage/src/types/inputs.ts +++ b/packages/storage/src/types/inputs.ts @@ -9,9 +9,7 @@ import { StorageOptions, } from './options'; -// TODO: rename to StorageOperationInput once the other type with -// the same named is removed -export type StorageOperationInputType = StrictUnion< +export type StorageOperationInput = StrictUnion< StorageOperationInputWithKey | StorageOperationInputWithPath >; export type StorageOperationInputWithPrefixPath = StrictUnion< @@ -43,15 +41,9 @@ export type StorageDownloadDataInputWithKey = export type StorageDownloadDataInputWithPath = StorageOperationInputWithPath & StorageOperationOptionsInput; -// TODO: This needs to be removed after refactor of all storage APIs -export interface StorageOperationInput { - key: string; - options?: Options; -} - /** @deprecated Use {@link StorageGetPropertiesInputWithPath} instead. */ export type StorageGetPropertiesInputWithKey = - StorageOperationInputWithKey & StorageOperationInput; + StorageOperationInputWithKey & StorageOperationOptionsInput; export type StorageGetPropertiesInputWithPath = StorageOperationInputWithPath & StorageOperationOptionsInput; @@ -73,7 +65,7 @@ export type StorageListInputWithPath< /** @deprecated Use {@link StorageGetUrlInputWithPath} instead. */ export type StorageGetUrlInputWithKey = - StorageOperationInputWithKey & StorageOperationInput; + StorageOperationInputWithKey & StorageOperationOptionsInput; export type StorageGetUrlInputWithPath = StorageOperationInputWithPath & StorageOperationOptionsInput; From 2f50d32f0a8db1918bcb2560eea3cc86e2accc1d Mon Sep 17 00:00:00 2001 From: ashika112 Date: Tue, 2 Apr 2024 17:44:05 -0700 Subject: [PATCH 3/5] update server api overload types --- packages/storage/src/providers/s3/apis/server/copy.ts | 5 +++++ .../storage/src/providers/s3/apis/server/getProperties.ts | 4 ++++ packages/storage/src/providers/s3/apis/server/getUrl.ts | 4 ++++ packages/storage/src/providers/s3/apis/server/list.ts | 8 ++++++++ packages/storage/src/providers/s3/apis/server/remove.ts | 4 ++++ 5 files changed, 25 insertions(+) diff --git a/packages/storage/src/providers/s3/apis/server/copy.ts b/packages/storage/src/providers/s3/apis/server/copy.ts index 2b77c86794a..4193f988eef 100644 --- a/packages/storage/src/providers/s3/apis/server/copy.ts +++ b/packages/storage/src/providers/s3/apis/server/copy.ts @@ -48,6 +48,11 @@ interface Copy { contextSpec: AmplifyServer.ContextSpec, input: CopyInputWithKey, ): Promise; + + ( + contextSpec: AmplifyServer.ContextSpec, + input: CopyInputWithPath | CopyInputWithKey, + ): Promise; } export const copy: Copy = ( diff --git a/packages/storage/src/providers/s3/apis/server/getProperties.ts b/packages/storage/src/providers/s3/apis/server/getProperties.ts index a66050f864d..fdc8bc2d917 100644 --- a/packages/storage/src/providers/s3/apis/server/getProperties.ts +++ b/packages/storage/src/providers/s3/apis/server/getProperties.ts @@ -48,6 +48,10 @@ interface GetProperties { contextSpec: AmplifyServer.ContextSpec, input: GetPropertiesInputWithKey, ): Promise; + ( + contextSpec: AmplifyServer.ContextSpec, + input: GetPropertiesInputWithPath | GetPropertiesInputWithKey, + ): Promise; } export const getProperties: GetProperties = < diff --git a/packages/storage/src/providers/s3/apis/server/getUrl.ts b/packages/storage/src/providers/s3/apis/server/getUrl.ts index c5cf6207e24..f6b2168ade1 100644 --- a/packages/storage/src/providers/s3/apis/server/getUrl.ts +++ b/packages/storage/src/providers/s3/apis/server/getUrl.ts @@ -60,6 +60,10 @@ interface GetUrl { contextSpec: AmplifyServer.ContextSpec, input: GetUrlInputWithKey, ): Promise; + ( + contextSpec: AmplifyServer.ContextSpec, + input: GetUrlInputWithPath | GetUrlInputWithKey, + ): Promise; } export const getUrl: GetUrl = async ( contextSpec: AmplifyServer.ContextSpec, diff --git a/packages/storage/src/providers/s3/apis/server/list.ts b/packages/storage/src/providers/s3/apis/server/list.ts index ea1250a7e3f..b68d0978a95 100644 --- a/packages/storage/src/providers/s3/apis/server/list.ts +++ b/packages/storage/src/providers/s3/apis/server/list.ts @@ -74,6 +74,14 @@ interface ListApi { contextSpec: AmplifyServer.ContextSpec, input?: ListAllInputWithPrefix, ): Promise; + ( + contextSpec: AmplifyServer.ContextSpec, + input?: ListPaginateInputWithPath | ListPaginateInputWithPrefix, + ): Promise; + ( + contextSpec: AmplifyServer.ContextSpec, + input?: ListAllInputWithPath | ListAllInputWithPrefix, + ): Promise; } export const list: ListApi = < diff --git a/packages/storage/src/providers/s3/apis/server/remove.ts b/packages/storage/src/providers/s3/apis/server/remove.ts index c27e2831020..28c8c581b60 100644 --- a/packages/storage/src/providers/s3/apis/server/remove.ts +++ b/packages/storage/src/providers/s3/apis/server/remove.ts @@ -46,6 +46,10 @@ interface RemoveApi { contextSpec: AmplifyServer.ContextSpec, input: RemoveInputWithKey, ): Promise; + ( + contextSpec: AmplifyServer.ContextSpec, + input: RemoveInputWithPath | RemoveInputWithKey, + ): Promise; } export const remove: RemoveApi = ( From 538a682d63d56034e80500e4ff75b351c363565e Mon Sep 17 00:00:00 2001 From: ashika112 Date: Tue, 2 Apr 2024 18:45:13 -0700 Subject: [PATCH 4/5] update bundle size --- packages/aws-amplify/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-amplify/package.json b/packages/aws-amplify/package.json index d022535b24d..c1af3d962ad 100644 --- a/packages/aws-amplify/package.json +++ b/packages/aws-amplify/package.json @@ -473,7 +473,7 @@ "name": "[Storage] getProperties (S3)", "path": "./dist/esm/storage/index.mjs", "import": "{ getProperties }", - "limit": "13.55 kB" + "limit": "13.56 kB" }, { "name": "[Storage] getUrl (S3)", From 3c1ec6303e7af0199b2c42aa530e6cc485afed4c Mon Sep 17 00:00:00 2001 From: ashika112 Date: Thu, 4 Apr 2024 11:57:37 -0700 Subject: [PATCH 5/5] update type to use strict union input --- packages/storage/src/providers/s3/apis/copy.ts | 2 +- packages/storage/src/providers/s3/apis/downloadData.ts | 4 +--- packages/storage/src/providers/s3/apis/getProperties.ts | 4 +--- packages/storage/src/providers/s3/apis/getUrl.ts | 2 +- packages/storage/src/providers/s3/apis/list.ts | 8 ++------ packages/storage/src/providers/s3/apis/remove.ts | 2 +- packages/storage/src/providers/s3/apis/server/copy.ts | 2 +- .../storage/src/providers/s3/apis/server/getProperties.ts | 2 +- packages/storage/src/providers/s3/apis/server/getUrl.ts | 2 +- packages/storage/src/providers/s3/apis/server/list.ts | 4 ++-- packages/storage/src/providers/s3/apis/server/remove.ts | 2 +- .../storage/src/providers/s3/apis/uploadData/index.ts | 2 +- 12 files changed, 14 insertions(+), 22 deletions(-) diff --git a/packages/storage/src/providers/s3/apis/copy.ts b/packages/storage/src/providers/s3/apis/copy.ts index 86125aa6e12..17b25d3de1c 100644 --- a/packages/storage/src/providers/s3/apis/copy.ts +++ b/packages/storage/src/providers/s3/apis/copy.ts @@ -39,7 +39,7 @@ interface Copy { * source or destination key is not defined. */ (input: CopyInputWithKey): Promise; - (input: CopyInputWithPath | CopyInputWithKey): Promise; + (input: CopyInput): Promise; } export const copy: Copy = ( diff --git a/packages/storage/src/providers/s3/apis/downloadData.ts b/packages/storage/src/providers/s3/apis/downloadData.ts index 6c538f27293..0f82719f211 100644 --- a/packages/storage/src/providers/s3/apis/downloadData.ts +++ b/packages/storage/src/providers/s3/apis/downloadData.ts @@ -90,9 +90,7 @@ interface DownloadData { *``` */ (input: DownloadDataInputWithKey): DownloadDataOutputWithKey; - ( - input: DownloadDataInputWithPath | DownloadDataInputWithKey, - ): DownloadDataOutput; + (input: DownloadDataInput): DownloadDataOutput; } export const downloadData: DownloadData = ( diff --git a/packages/storage/src/providers/s3/apis/getProperties.ts b/packages/storage/src/providers/s3/apis/getProperties.ts index 21e7d3752d4..d08b77d0fa7 100644 --- a/packages/storage/src/providers/s3/apis/getProperties.ts +++ b/packages/storage/src/providers/s3/apis/getProperties.ts @@ -38,9 +38,7 @@ interface GetProperties { * @throws A `StorageValidationErrorCode` when API call parameters are invalid. */ (input: GetPropertiesInputWithKey): Promise; - ( - input: GetPropertiesInputWithPath | GetPropertiesInputWithKey, - ): Promise; + (input: GetPropertiesInput): Promise; } export const getProperties: GetProperties = < diff --git a/packages/storage/src/providers/s3/apis/getUrl.ts b/packages/storage/src/providers/s3/apis/getUrl.ts index 90844715f55..24874da81d2 100644 --- a/packages/storage/src/providers/s3/apis/getUrl.ts +++ b/packages/storage/src/providers/s3/apis/getUrl.ts @@ -50,7 +50,7 @@ interface GetUrl { * */ (input: GetUrlInputWithKey): Promise; - (input: GetUrlInputWithPath | GetUrlInputWithKey): Promise; + (input: GetUrlInput): Promise; } export const getUrl: GetUrl = (input: GetUrlInput): Promise => diff --git a/packages/storage/src/providers/s3/apis/list.ts b/packages/storage/src/providers/s3/apis/list.ts index 2a165610816..51c8a17a9cf 100644 --- a/packages/storage/src/providers/s3/apis/list.ts +++ b/packages/storage/src/providers/s3/apis/list.ts @@ -58,12 +58,8 @@ interface ListApi { * @throws validation: `StorageValidationErrorCode` - thrown when there are issues with credentials */ (input?: ListAllInputWithPrefix): Promise; - ( - input?: ListAllInputWithPath | ListAllInputWithPrefix, - ): Promise; - ( - input?: ListPaginateInputWithPath | ListPaginateInputWithPrefix, - ): Promise; + (input?: ListAllInput): Promise; + (input?: ListPaginateInput): Promise; } export const list: ListApi = < diff --git a/packages/storage/src/providers/s3/apis/remove.ts b/packages/storage/src/providers/s3/apis/remove.ts index bc856748a73..78d93084860 100644 --- a/packages/storage/src/providers/s3/apis/remove.ts +++ b/packages/storage/src/providers/s3/apis/remove.ts @@ -36,7 +36,7 @@ interface RemoveApi { * when there is no key or its empty. */ (input: RemoveInputWithKey): Promise; - (input: RemoveInputWithPath | RemoveInputWithKey): Promise; + (input: RemoveInput): Promise; } export const remove: RemoveApi = ( diff --git a/packages/storage/src/providers/s3/apis/server/copy.ts b/packages/storage/src/providers/s3/apis/server/copy.ts index 4193f988eef..bd6e3d7e463 100644 --- a/packages/storage/src/providers/s3/apis/server/copy.ts +++ b/packages/storage/src/providers/s3/apis/server/copy.ts @@ -51,7 +51,7 @@ interface Copy { ( contextSpec: AmplifyServer.ContextSpec, - input: CopyInputWithPath | CopyInputWithKey, + input: CopyInput, ): Promise; } diff --git a/packages/storage/src/providers/s3/apis/server/getProperties.ts b/packages/storage/src/providers/s3/apis/server/getProperties.ts index fdc8bc2d917..9f5af13554f 100644 --- a/packages/storage/src/providers/s3/apis/server/getProperties.ts +++ b/packages/storage/src/providers/s3/apis/server/getProperties.ts @@ -50,7 +50,7 @@ interface GetProperties { ): Promise; ( contextSpec: AmplifyServer.ContextSpec, - input: GetPropertiesInputWithPath | GetPropertiesInputWithKey, + input: GetPropertiesInput, ): Promise; } diff --git a/packages/storage/src/providers/s3/apis/server/getUrl.ts b/packages/storage/src/providers/s3/apis/server/getUrl.ts index f6b2168ade1..d3a75a1299e 100644 --- a/packages/storage/src/providers/s3/apis/server/getUrl.ts +++ b/packages/storage/src/providers/s3/apis/server/getUrl.ts @@ -62,7 +62,7 @@ interface GetUrl { ): Promise; ( contextSpec: AmplifyServer.ContextSpec, - input: GetUrlInputWithPath | GetUrlInputWithKey, + input: GetUrlInput, ): Promise; } export const getUrl: GetUrl = async ( diff --git a/packages/storage/src/providers/s3/apis/server/list.ts b/packages/storage/src/providers/s3/apis/server/list.ts index b68d0978a95..4ac584dc998 100644 --- a/packages/storage/src/providers/s3/apis/server/list.ts +++ b/packages/storage/src/providers/s3/apis/server/list.ts @@ -76,11 +76,11 @@ interface ListApi { ): Promise; ( contextSpec: AmplifyServer.ContextSpec, - input?: ListPaginateInputWithPath | ListPaginateInputWithPrefix, + input?: ListPaginateInput, ): Promise; ( contextSpec: AmplifyServer.ContextSpec, - input?: ListAllInputWithPath | ListAllInputWithPrefix, + input?: ListAllInput, ): Promise; } diff --git a/packages/storage/src/providers/s3/apis/server/remove.ts b/packages/storage/src/providers/s3/apis/server/remove.ts index 28c8c581b60..a0f8ef9f6db 100644 --- a/packages/storage/src/providers/s3/apis/server/remove.ts +++ b/packages/storage/src/providers/s3/apis/server/remove.ts @@ -48,7 +48,7 @@ interface RemoveApi { ): Promise; ( contextSpec: AmplifyServer.ContextSpec, - input: RemoveInputWithPath | RemoveInputWithKey, + input: RemoveInput, ): Promise; } diff --git a/packages/storage/src/providers/s3/apis/uploadData/index.ts b/packages/storage/src/providers/s3/apis/uploadData/index.ts index 24e27ed0ad3..b7ec67e4848 100644 --- a/packages/storage/src/providers/s3/apis/uploadData/index.ts +++ b/packages/storage/src/providers/s3/apis/uploadData/index.ts @@ -126,7 +126,7 @@ interface UploadData { * ``` */ (input: UploadDataInputWithKey): UploadDataOutputWithKey; - (input: UploadDataInputWithPath | UploadDataInputWithKey): UploadDataOutput; + (input: UploadDataInput): UploadDataOutput; } export const uploadData: UploadData = (