-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage): internals list API (#13874)
- Loading branch information
1 parent
cced539
commit 20f62a6
Showing
5 changed files
with
94 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { AmplifyClassV6 } from '@aws-amplify/core'; | ||
|
||
import { list as advancedList } from '../../../src/internals'; | ||
import { list as listInternal } from '../../../src/providers/s3/apis/internal/list'; | ||
import { ListAllWithPathOutput } from '../../../src'; | ||
|
||
jest.mock('../../../src/providers/s3/apis/internal/list'); | ||
const mockedListInternal = jest.mocked(listInternal); | ||
|
||
describe('list (internals)', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockedListInternal.mockResolvedValue({ | ||
items: [], | ||
} as ListAllWithPathOutput); | ||
}); | ||
|
||
it('should pass advanced option locationCredentialsProvider to internal list', async () => { | ||
const useAccelerateEndpoint = true; | ||
const bucket = { bucketName: 'bucket', region: 'us-east-1' }; | ||
const locationCredentialsProvider = async () => ({ | ||
credentials: { | ||
accessKeyId: 'akid', | ||
secretAccessKey: 'secret', | ||
sessionToken: 'token', | ||
expiration: new Date(), | ||
}, | ||
}); | ||
const result = await advancedList({ | ||
path: 'input/path/to/mock/object', | ||
options: { | ||
useAccelerateEndpoint, | ||
bucket, | ||
locationCredentialsProvider, | ||
}, | ||
}); | ||
expect(mockedListInternal).toHaveBeenCalledTimes(1); | ||
expect(mockedListInternal).toHaveBeenCalledWith( | ||
expect.any(AmplifyClassV6), | ||
{ | ||
path: 'input/path/to/mock/object', | ||
options: { | ||
useAccelerateEndpoint, | ||
bucket, | ||
locationCredentialsProvider, | ||
}, | ||
}, | ||
); | ||
expect(result).toEqual({ | ||
items: [], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Amplify } from '@aws-amplify/core'; | ||
|
||
import { list as listInternal } from '../../providers/s3/apis/internal/list'; | ||
import { ListInputWithPath } from '../types/inputs'; | ||
|
||
/** | ||
* @internal | ||
* List all or paginate files from S3 for a given `path`. | ||
* @param input - The `ListWithPathInputAndAdvancedOptions` object. | ||
* @returns A list of all objects with path and metadata | ||
* @throws service: `S3Exception` - S3 service errors thrown when checking for existence of bucket | ||
* @throws validation: `StorageValidationErrorCode` - thrown when there are issues with credentials | ||
*/ | ||
export function list(input?: ListInputWithPath) { | ||
return listInternal(Amplify, input ?? {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters