Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Update API overload types #13214

Merged
merged 5 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/aws-amplify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import {
CopyInput,
CopyInputWithKey,

Check warning on line 8 in packages/storage/src/providers/s3/apis/copy.ts

View workflow job for this annotation

GitHub Actions / unit-tests / Unit Test - @aws-amplify/storage

Deprecated: Use {@link CopyInputWithPath} instead
CopyInputWithPath,
CopyOutput,
CopyOutputWithKey,

Check warning on line 11 in packages/storage/src/providers/s3/apis/copy.ts

View workflow job for this annotation

GitHub Actions / unit-tests / Unit Test - @aws-amplify/storage

Deprecated: Use {@link CopyOutputWithPath} instead
CopyOutputWithPath,
} from '../types';

Expand Down Expand Up @@ -38,7 +38,8 @@
* @throws validation: `StorageValidationErrorCode` - Thrown when
* source or destination key is not defined.
*/
(input: CopyInputWithKey): Promise<CopyOutputWithKey>;

Check warning on line 41 in packages/storage/src/providers/s3/apis/copy.ts

View workflow job for this annotation

GitHub Actions / unit-tests / Unit Test - @aws-amplify/storage

Deprecated: Use {@link CopyInputWithPath} instead

Check warning on line 41 in packages/storage/src/providers/s3/apis/copy.ts

View workflow job for this annotation

GitHub Actions / unit-tests / Unit Test - @aws-amplify/storage

Deprecated: Use {@link CopyOutputWithPath} instead
(input: CopyInput): Promise<CopyOutput>;
}

export const copy: Copy = <Output extends CopyOutput>(
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/downloadData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import {
DownloadDataInput,
DownloadDataInputWithKey,

Check warning on line 9 in packages/storage/src/providers/s3/apis/downloadData.ts

View workflow job for this annotation

GitHub Actions / unit-tests / Unit Test - @aws-amplify/storage

Deprecated: Use {@link DownloadDataInputWithPath} instead
DownloadDataInputWithPath,
DownloadDataOutput,
DownloadDataOutputWithKey,

Check warning on line 12 in packages/storage/src/providers/s3/apis/downloadData.ts

View workflow job for this annotation

GitHub Actions / unit-tests / Unit Test - @aws-amplify/storage

Deprecated: Use {@link DownloadDataOutputWithPath} instead
DownloadDataOutputWithPath,
} from '../types';
import { resolveS3ConfigAndInput } from '../utils/resolveS3ConfigAndInput';
Expand All @@ -19,7 +19,7 @@
import { logger } from '../../../utils';
import {
StorageDownloadDataOutput,
StorageItemWithKey,

Check warning on line 22 in packages/storage/src/providers/s3/apis/downloadData.ts

View workflow job for this annotation

GitHub Actions / unit-tests / Unit Test - @aws-amplify/storage

Deprecated: Use {@link StorageItemWithPath} instead
StorageItemWithPath,
} from '../../../types';
import { STORAGE_INPUT_KEY } from '../utils/constants';
Expand Down Expand Up @@ -89,7 +89,8 @@
* }
*```
*/
(input: DownloadDataInputWithKey): DownloadDataOutputWithKey;

Check warning on line 92 in packages/storage/src/providers/s3/apis/downloadData.ts

View workflow job for this annotation

GitHub Actions / unit-tests / Unit Test - @aws-amplify/storage

Deprecated: Use {@link DownloadDataInputWithPath} instead

Check warning on line 92 in packages/storage/src/providers/s3/apis/downloadData.ts

View workflow job for this annotation

GitHub Actions / unit-tests / Unit Test - @aws-amplify/storage

Deprecated: Use {@link DownloadDataOutputWithPath} instead
(input: DownloadDataInput): DownloadDataOutput;
}

export const downloadData: DownloadData = <Output extends DownloadDataOutput>(
Expand All @@ -110,7 +111,7 @@
const downloadDataJob =
(downloadDataInput: DownloadDataInput, abortSignal: AbortSignal) =>
async (): Promise<
StorageDownloadDataOutput<StorageItemWithKey | StorageItemWithPath>

Check warning on line 114 in packages/storage/src/providers/s3/apis/downloadData.ts

View workflow job for this annotation

GitHub Actions / unit-tests / Unit Test - @aws-amplify/storage

Deprecated: Use {@link StorageItemWithPath} instead
> => {
const { options: downloadDataOptions } = downloadDataInput;
const { bucket, keyPrefix, s3Config, identityId } =
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/getProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface GetProperties {
* @throws A `StorageValidationErrorCode` when API call parameters are invalid.
*/
(input: GetPropertiesInputWithKey): Promise<GetPropertiesOutputWithKey>;
(input: GetPropertiesInput): Promise<GetPropertiesOutput>;
}

export const getProperties: GetProperties = <
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/getUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface GetUrl {
*
*/
(input: GetUrlInputWithKey): Promise<GetUrlOutput>;
(input: GetUrlInput): Promise<GetUrlOutput>;
}

export const getUrl: GetUrl = (input: GetUrlInput): Promise<GetUrlOutput> =>
Expand Down
2 changes: 2 additions & 0 deletions packages/storage/src/providers/s3/apis/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ interface ListApi {
* @throws validation: `StorageValidationErrorCode` - thrown when there are issues with credentials
*/
(input?: ListAllInputWithPrefix): Promise<ListAllOutputWithPrefix>;
(input?: ListAllInput): Promise<ListAllOutput>;
(input?: ListPaginateInput): Promise<ListPaginateOutput>;
ashika112 marked this conversation as resolved.
Show resolved Hide resolved
}

export const list: ListApi = <
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface RemoveApi {
* when there is no key or its empty.
*/
(input: RemoveInputWithKey): Promise<RemoveOutputWithKey>;
(input: RemoveInput): Promise<RemoveOutput>;
}

export const remove: RemoveApi = <Output extends RemoveOutput>(
Expand Down
5 changes: 5 additions & 0 deletions packages/storage/src/providers/s3/apis/server/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ interface Copy {
contextSpec: AmplifyServer.ContextSpec,
input: CopyInputWithKey,
): Promise<CopyOutputWithKey>;

(
contextSpec: AmplifyServer.ContextSpec,
input: CopyInput,
): Promise<CopyOutput>;
}

export const copy: Copy = <Output extends CopyOutput>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ interface GetProperties {
contextSpec: AmplifyServer.ContextSpec,
input: GetPropertiesInputWithKey,
): Promise<GetPropertiesOutputWithKey>;
(
contextSpec: AmplifyServer.ContextSpec,
input: GetPropertiesInput,
): Promise<GetPropertiesOutput>;
}

export const getProperties: GetProperties = <
Expand Down
4 changes: 4 additions & 0 deletions packages/storage/src/providers/s3/apis/server/getUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ interface GetUrl {
contextSpec: AmplifyServer.ContextSpec,
input: GetUrlInputWithKey,
): Promise<GetUrlOutput>;
(
contextSpec: AmplifyServer.ContextSpec,
input: GetUrlInput,
): Promise<GetUrlOutput>;
}
export const getUrl: GetUrl = async (
contextSpec: AmplifyServer.ContextSpec,
Expand Down
8 changes: 8 additions & 0 deletions packages/storage/src/providers/s3/apis/server/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ interface ListApi {
contextSpec: AmplifyServer.ContextSpec,
input?: ListAllInputWithPrefix,
): Promise<ListAllOutputWithPrefix>;
(
contextSpec: AmplifyServer.ContextSpec,
input?: ListPaginateInput,
): Promise<ListPaginateOutput>;
(
contextSpec: AmplifyServer.ContextSpec,
input?: ListAllInput,
): Promise<ListAllOutput>;
}

export const list: ListApi = <
Expand Down
4 changes: 4 additions & 0 deletions packages/storage/src/providers/s3/apis/server/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ interface RemoveApi {
contextSpec: AmplifyServer.ContextSpec,
input: RemoveInputWithKey,
): Promise<RemoveOutputWithKey>;
(
contextSpec: AmplifyServer.ContextSpec,
input: RemoveInput,
): Promise<RemoveOutput>;
}

export const remove: RemoveApi = <Output extends RemoveOutput>(
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/uploadData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ interface UploadData {
* ```
*/
(input: UploadDataInputWithKey): UploadDataOutputWithKey;
(input: UploadDataInput): UploadDataOutput;
}

export const uploadData: UploadData = <Output extends UploadDataOutput>(
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/src/providers/s3/utils/isInputWithPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
1 change: 0 additions & 1 deletion packages/storage/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export {
UploadTask,
} from './common';
export {
StorageOperationInput,
StorageGetPropertiesInputWithKey,
StorageGetPropertiesInputWithPath,
StorageListInputWithPrefix,
Expand Down
14 changes: 3 additions & 11 deletions packages/storage/src/types/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -43,15 +41,9 @@ export type StorageDownloadDataInputWithKey<Options extends StorageOptions> =
export type StorageDownloadDataInputWithPath<Options> =
StorageOperationInputWithPath & StorageOperationOptionsInput<Options>;

// TODO: This needs to be removed after refactor of all storage APIs
export interface StorageOperationInput<Options extends StorageOptions> {
key: string;
options?: Options;
}

/** @deprecated Use {@link StorageGetPropertiesInputWithPath} instead. */
export type StorageGetPropertiesInputWithKey<Options extends StorageOptions> =
StorageOperationInputWithKey & StorageOperationInput<Options>;
StorageOperationInputWithKey & StorageOperationOptionsInput<Options>;

export type StorageGetPropertiesInputWithPath<Options> =
StorageOperationInputWithPath & StorageOperationOptionsInput<Options>;
Expand All @@ -73,7 +65,7 @@ export type StorageListInputWithPath<

/** @deprecated Use {@link StorageGetUrlInputWithPath} instead. */
export type StorageGetUrlInputWithKey<Options extends StorageOptions> =
StorageOperationInputWithKey & StorageOperationInput<Options>;
StorageOperationInputWithKey & StorageOperationOptionsInput<Options>;

export type StorageGetUrlInputWithPath<Options> =
StorageOperationInputWithPath & StorageOperationOptionsInput<Options>;
Expand Down
Loading