Skip to content

Commit 1c62d82

Browse files
committed
Gen2 storage/update storage types (aws-amplify#5177)
1 parent 9ce5f9d commit 1c62d82

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

packages/react-core/src/hooks/useGetUrl.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import * as React from 'react';
22

3-
import { getUrl, GetUrlInput } from 'aws-amplify/storage';
3+
import {
4+
getUrl,
5+
GetUrlInput,
6+
GetUrlOutput,
7+
GetUrlWithPathInput,
8+
} from 'aws-amplify/storage';
49

510
import { isFunction } from '@aws-amplify/ui';
611

7-
export type UseGetUrlInput = GetUrlInput & {
12+
export type UseGetUrlInput = (GetUrlInput | GetUrlWithPathInput) & {
813
onError?: (error: Error) => void;
914
};
1015
interface UseGetUrlOutput {
@@ -19,13 +24,17 @@ const INIT_STATE: UseGetUrlOutput = {
1924
isLoading: true,
2025
};
2126

22-
const useGetUrl = (input: UseGetUrlInput): UseGetUrlOutput => {
27+
type GetUrl = (
28+
input: GetUrlInput | GetUrlWithPathInput
29+
) => Promise<GetUrlOutput>;
30+
31+
export default function useGetUrl(input: UseGetUrlInput): UseGetUrlOutput {
2332
const [result, setResult] = React.useState(() => INIT_STATE);
2433
React.useEffect(() => {
2534
const { onError, ...getUrlInput } = input;
2635
let ignore = false;
2736

28-
getUrl(getUrlInput)
37+
(getUrl as GetUrl)(getUrlInput)
2938
.then((response) => {
3039
if (ignore) {
3140
return;
@@ -51,6 +60,4 @@ const useGetUrl = (input: UseGetUrlInput): UseGetUrlOutput => {
5160
}, [input]);
5261

5362
return result;
54-
};
55-
56-
export default useGetUrl;
63+
}

packages/react-storage/src/components/StorageManager/__tests__/StorageManager.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const warnSpy = jest.spyOn(console, 'warn').mockImplementation();
1717

1818
const uploadDataSpy = jest
1919
.spyOn(Storage, 'uploadData')
20-
// @ts-expect-error remove this once StorageManager types are fixed
2120
.mockImplementation((input) => ({
2221
cancel: jest.fn(),
2322
pause: jest.fn(),

packages/react-storage/src/components/StorageManager/hooks/useUploadFiles/__tests__/useUploadFiles.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { useUploadFiles, UseUploadFilesProps } from '../useUploadFiles';
88

99
const uploadDataSpy = jest
1010
.spyOn(Storage, 'uploadData')
11-
// @ts-expect-error remove this once StorageManager types are fixed
1211
.mockImplementation((input) => {
1312
return {
1413
cancel: jest.fn(),
@@ -126,7 +125,6 @@ describe('useUploadFiles', () => {
126125

127126
it('should call onUploadError when upload fails', async () => {
128127
const errorMessage = new Error('Error');
129-
// @ts-expect-error remove this once StorageManager types are fixed
130128
uploadDataSpy.mockImplementationOnce(() => {
131129
return {
132130
cancel: jest.fn(),

packages/react-storage/src/components/StorageManager/utils/__tests__/uploadFile.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ describe('uploadFile', () => {
6262
it('calls errorCallback on upload error', async () => {
6363
uploadDataSpy.mockReturnValueOnce({
6464
...uploadDataOutput,
65-
// @ts-expect-error remove this once StorageManager types are fixed
6665
result: Promise.reject(new Error('Error')),
6766
state: 'ERROR',
6867
});

0 commit comments

Comments
 (0)