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

feat(react-storage): use aws-amplify's internals APIs #5903

Open
wants to merge 10 commits into
base: feat-storage-browser/main
Choose a base branch
from
Open
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"@types/jest": "^29.5.5",
"@types/react-test-renderer": "^18.0.2",
"@vitejs/plugin-vue": "^2.3.4",
"aws-amplify": "storage-browser",
"aws-amplify": "storage-browser-integrity",
"esbuild-register": "^3.5.0",
"eslint": "^8.44.0",
"fs-extra": "^11.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/projects/ui-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"peerDependencies": {
"@angular/core": ">= 14.0.0",
"@angular/common": ">= 14.0.0",
"aws-amplify": "storage-browser",
"aws-amplify": "storage-browser-integrity",
"rxjs": "^6.5.3 || ^7.4.0"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"tslib": "^2.5.2"
},
"peerDependencies": {
"aws-amplify": "storage-browser",
"aws-amplify": "storage-browser-integrity",
"react": "^16.14.0 || ^17.0 || ^18.0",
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"peerDependencies": {
"@aws-amplify/core": "*",
"aws-amplify": "storage-browser",
"aws-amplify": "storage-browser-integrity",
"react": "^16.14.0 || ^17.0 || ^18.0"
},
"sideEffects": false
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core-notifications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@aws-amplify/ui-react-core": "3.0.27"
},
"peerDependencies": {
"aws-amplify": "storage-browser",
"aws-amplify": "storage-browser-integrity",
"react": "^16.14.0 || ^17.0 || ^18.0"
},
"sideEffects": false
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"xstate": "^4.33.6"
},
"peerDependencies": {
"aws-amplify": "storage-browser",
"aws-amplify": "storage-browser-integrity",
"react": "^16.14.0 || ^17.0 || ^18.0"
},
"sideEffects": false
Expand Down
6 changes: 3 additions & 3 deletions packages/react-geo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
"tslib": "^2.5.2"
},
"peerDependencies": {
"@aws-amplify/geo": "storage-browser",
"aws-amplify": "storage-browser",
"@aws-amplify/geo": "storage-browser-integrity",
"aws-amplify": "storage-browser-integrity",
"react": "^16.14.0 || ^17.0 || ^18.0",
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
},
"devDependencies": {
"@aws-amplify/geo": "storage-browser",
"@aws-amplify/geo": "storage-browser-integrity",
"@types/mapbox__mapbox-gl-draw": "^1.3.3"
},
"sideEffects": [
Expand Down
2 changes: 1 addition & 1 deletion packages/react-liveness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"peerDependencies": {
"@aws-amplify/core": "*",
"aws-amplify": "storage-browser",
"aws-amplify": "storage-browser-integrity",
"react": "^16.14.0 || ^17.0 || ^18.0",
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"qrcode": "1.5.0"
},
"peerDependencies": {
"aws-amplify": "storage-browser",
"aws-amplify": "storage-browser-integrity",
"react": "^18",
"react-native": "^0.70 || ^0.71 || ^0.72"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@aws-amplify/ui-react-core-notifications": "2.0.27"
},
"peerDependencies": {
"aws-amplify": "storage-browser",
"aws-amplify": "storage-browser-integrity",
"react": "*",
"react-native": "^0.70 || ^0.71 || ^0.72 || ^0.73 || ^0.74 || ^0.75",
"react-native-safe-area-context": "^4.2.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/react-notifications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"tinycolor2": "1.4.2"
},
"peerDependencies": {
"aws-amplify": "storage-browser",
"aws-amplify": "storage-browser-integrity",
"react": "^16.14.0 || ^17.0 || ^18.0",
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/react-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"tslib": "^2.5.2"
},
"peerDependencies": {
"aws-amplify": "storage-browser",
"aws-amplify": "storage-browser-integrity",
"react": "^16.14.0 || ^17.0 || ^18.0",
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
},
Expand All @@ -66,7 +66,8 @@
"name": "createStorageBrowser",
"path": "dist/esm/browser.mjs",
"import": "{ createStorageBrowser }",
"limit": "15.2 kB"
"limit": "15.2 kB",
"ignore": ["@aws-amplify/storage"]
},
{
"name": "FileUploader",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as StorageModule from 'aws-amplify/storage';
import * as StorageModule from '../../../storage-internal';

import { copyHandler, CopyHandlerInput } from '../copy';

Expand All @@ -24,7 +24,7 @@ describe('copyHandler', () => {
region: `${baseInput.config.region}`,
};

const expected: StorageModule.CopyWithPathInput = {
const expected: StorageModule.CopyInput = {
destination: {
bucket,
path: 'destination/key',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as StorageModule from 'aws-amplify/storage';
import * as StorageModule from '../../../storage-internal';

import { deleteHandler, DeleteHandlerInput } from '../delete';

Expand All @@ -19,7 +19,7 @@ describe('deleteHandler', () => {
it('calls `remove` and returns the expected `key`', () => {
const { key } = deleteHandler(baseInput);

const expected: StorageModule.RemoveWithPathInput = {
const expected: StorageModule.RemoveInput = {
path: `${baseInput.prefix}${baseInput.data.key}`,
options: {
bucket: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as InternalStorageModule from '../../../storage-internal';
import * as StorageModule from 'aws-amplify/storage';

import {
Expand All @@ -8,7 +9,7 @@ import {
} from '../upload';

const isCancelErrorSpy = jest.spyOn(StorageModule, 'isCancelError');
const uploadDataSpy = jest.spyOn(StorageModule, 'uploadData');
const uploadDataSpy = jest.spyOn(InternalStorageModule, 'uploadData');

const credentials = jest.fn();

Expand Down Expand Up @@ -49,7 +50,7 @@ describe('uploadHandler', () => {
cancel,
pause,
resume,
result: Promise.resolve({ key: payload.name }),
result: Promise.resolve({ path: payload.name }),
state: 'SUCCESS',
});

Expand All @@ -68,7 +69,7 @@ describe('uploadHandler', () => {
it('calls upload with the expected values', () => {
uploadHandler({ ...baseInput, options: { preventOverwrite: true } });

const expected: StorageModule.UploadDataWithPathInput = {
const expected: InternalStorageModule.UploadDataInput = {
data: payload,
options: {
bucket: {
Expand All @@ -94,7 +95,7 @@ describe('uploadHandler', () => {
cancel,
pause,
resume,
result: Promise.resolve({ key: payload.name }),
result: Promise.resolve({ path: payload.name }),
state: 'SUCCESS',
};
});
Expand All @@ -120,7 +121,7 @@ describe('uploadHandler', () => {
cancel,
pause,
resume,
result: Promise.resolve({ key: payload.name }),
result: Promise.resolve({ path: payload.name }),
state: 'SUCCESS',
};
});
Expand All @@ -147,7 +148,7 @@ describe('uploadHandler', () => {
cancel,
pause,
resume,
result: Promise.resolve({ key: payload.name }),
result: Promise.resolve({ path: payload.name }),
state: 'SUCCESS',
});

Expand All @@ -169,7 +170,7 @@ describe('uploadHandler', () => {
cancel,
pause,
resume,
result: Promise.resolve({ key: payload.name }),
result: Promise.resolve({ path: payload.name }),
state: 'SUCCESS',
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copy } from 'aws-amplify/storage';
import { copy } from '../../storage-internal';
import {
TaskHandler,
TaskHandlerOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { remove } from 'aws-amplify/storage';
import { remove } from '../../storage-internal';

import {
TaskHandler,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { uploadData, UploadDataWithPathInput } from 'aws-amplify/storage';
import { uploadData, UploadDataInput } from '../../storage-internal';
import { isFunction } from '@aws-amplify/ui';

import {
Expand Down Expand Up @@ -45,7 +45,7 @@ export const uploadHandler: UploadHandler = ({

const bucket = constructBucket(config);

const input: UploadDataWithPathInput = {
const input: UploadDataInput = {
path: `${prefix}${key}`,
data,
options: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as StorageModule from 'aws-amplify/storage';
import * as StorageModule from '../../../storage-internal';
import { downloadAction } from '../downloadAction';

const getUrlSpy = jest.spyOn(StorageModule, 'getUrl');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as StorageModule from 'aws-amplify/storage';
import * as StorageModule from '../../../storage-internal';
import {
listLocationItemsAction,
parseResult,
Expand All @@ -15,9 +15,7 @@ const options = { delimiter: '/' };
const prefix = 'a_prefix/';
const initialValue = { nextToken: undefined, result: [] };

const generateMockItems = (
size: number
): StorageModule.ListPaginateWithPathOutput['items'] => {
const generateMockItems = (size: number): StorageModule.ListOutput['items'] => {
return Array.apply(0, new Array(size)).map((_, index) => ({
path: `${prefix}key${index}`,
lastModified: new Date(),
Expand All @@ -27,7 +25,7 @@ const generateMockItems = (

const generateMockSubpaths = (
size: number
): StorageModule.ListPaginateWithPathOutput['excludedSubpaths'] =>
): StorageModule.ListOutput['excludedSubpaths'] =>
Array.apply(0, new Array(size)).map((_, index) => {
return `subpath${index}`;
});
Expand All @@ -38,8 +36,6 @@ describe('listLocationItemsAction', () => {
});

it('returns the expected output shape in the happy path', async () => {
// @ts-expect-error `list` returns a union type of `ListPaginateOutput` | `ListAllOutput`
// causing the spy to yell due to the lack of `nextToken` on `ListAllOutput`
listSpy.mockResolvedValueOnce({ items: [], nextToken: 'tokeno' });
Comment on lines -41 to -42
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!


const { result, nextToken } = await listLocationItemsAction(initialValue, {
Expand All @@ -54,13 +50,11 @@ describe('listLocationItemsAction', () => {
it('merges the current action result with the previous action result', async () => {
listSpy
.mockResolvedValueOnce({
// @ts-expect-error - JS union interfaces casue type issues
items: generateMockItems(100),
excludedSubpaths: generateMockSubpaths(10),
nextToken: 'first',
})
.mockResolvedValueOnce({
// @ts-expect-error - JS union interfaces casue type issues
items: generateMockItems(100),
excludedSubpaths: generateMockSubpaths(10),
nextToken: 'second',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { uploadData } from 'aws-amplify/storage';
import { uploadData } from '../../storage-internal';

import { TaskAction, TaskActionInput, TaskActionOutput } from '../types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getUrl } from 'aws-amplify/storage';
import { getUrl } from '../../storage-internal';

import { DownloadActionInput, DownloadActionOutput } from '../types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {
StorageSubpathStrategy,
list,
ListPaginateWithPathInput,
ListPaginateWithPathOutput,
} from 'aws-amplify/storage';

import { StorageSubpathStrategy } from '../../storage-internal';
ListPaginateInput,
ListOutput,
} from '../../storage-internal';

import {
ListActionInput,
Expand All @@ -19,7 +18,7 @@ export interface ListLocationItemsActionInput
export interface ListLocationItemsActionOutput
extends ListActionOutput<LocationItem> {}

type ListOutputItem = ListPaginateWithPathOutput['items'][number];
type ListOutputItem = ListOutput['items'][number];

const parseResultItems = (
items: ListOutputItem[],
Expand Down Expand Up @@ -52,7 +51,7 @@ const parseResultExcludedPaths = (
paths?.map((key) => ({ key: key.slice(path.length), type: 'FOLDER' })) ?? [];

export const parseResult = (
output: ListPaginateWithPathOutput,
output: ListOutput,
path: string
): LocationItem[] => {
return [
Expand Down Expand Up @@ -93,7 +92,7 @@ export async function listLocationItemsAction(
const resolvedPageSize =
pageSize && (!hasPrevResults || refresh) ? pageSize + 1 : pageSize;

const listInput: ListPaginateWithPathInput = {
const listInput: ListPaginateInput = {
path,
options: {
bucket,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UploadDataWithPathInput } from 'aws-amplify/storage';
import { UploadDataInput } from '../storage-internal';
import { LocationCredentialsProvider } from '../storage-internal';

export interface FolderItem {
Expand Down Expand Up @@ -55,10 +55,7 @@ interface CancelableTaskResult extends TaskResult<TaskStatus | 'CANCELED'> {
}

interface UploadItemOptions
extends Pick<
NonNullable<UploadDataWithPathInput['options']>,
'preventOverwrite'
> {}
extends Pick<NonNullable<UploadDataInput['options']>, 'preventOverwrite'> {}

interface UploadActionInput extends TaskActionInput<UploadItemOptions> {}

Expand Down
Loading
Loading