-
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): add remaining copy changes for internals (#13889)
* chore: add remaining copy changes for internals * chore; explicitly call internal API with params * chore: copy return type * chore: feedback changes
- Loading branch information
1 parent
02cb08a
commit 0bca04a
Showing
8 changed files
with
127 additions
and
15 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,53 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { AmplifyClassV6 } from '@aws-amplify/core'; | ||
|
||
import { copy as advancedCopy } from '../../../src/internals'; | ||
import { copy as copyInternal } from '../../../src/providers/s3/apis/internal/copy'; | ||
|
||
jest.mock('../../../src/providers/s3/apis/internal/copy'); | ||
const mockedCopyInternal = jest.mocked(copyInternal); | ||
|
||
describe('copy (internals)', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockedCopyInternal.mockResolvedValue({ | ||
path: 'output/path/to/mock/object', | ||
}); | ||
}); | ||
|
||
it('should pass advanced option locationCredentialsProvider to internal list', async () => { | ||
const locationCredentialsProvider = async () => ({ | ||
credentials: { | ||
accessKeyId: 'akid', | ||
secretAccessKey: 'secret', | ||
sessionToken: 'token', | ||
expiration: new Date(), | ||
}, | ||
}); | ||
const copyInputWithAdvancedOptions = { | ||
source: { | ||
path: 'path/to/object', | ||
bucket: 'bucket', | ||
eTag: 'eTag', | ||
notModifiedSince: new Date(), | ||
}, | ||
destination: { | ||
path: 'path/to/object', | ||
bucket: 'bucket', | ||
}, | ||
options: { | ||
locationCredentialsProvider, | ||
}, | ||
}; | ||
const result = await advancedCopy(copyInputWithAdvancedOptions); | ||
expect(mockedCopyInternal).toHaveBeenCalledTimes(1); | ||
expect(mockedCopyInternal).toHaveBeenCalledWith( | ||
expect.any(AmplifyClassV6), | ||
copyInputWithAdvancedOptions, | ||
); | ||
expect(result).toEqual({ | ||
path: 'output/path/to/mock/object', | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Amplify } from '@aws-amplify/core'; | ||
|
||
import { copy as copyInternal } from '../../providers/s3/apis/internal/copy'; | ||
import { CopyInput } from '../types/inputs'; | ||
import { CopyOutput } from '../types/outputs'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const copy = (input: CopyInput) => | ||
copyInternal(Amplify, { | ||
source: { | ||
path: input.source.path, | ||
bucket: input.source.bucket, | ||
eTag: input.source.eTag, | ||
notModifiedSince: input.source.notModifiedSince, | ||
}, | ||
destination: { | ||
path: input.destination.path, | ||
bucket: input.destination.bucket, | ||
}, | ||
options: { | ||
// Advanced options | ||
locationCredentialsProvider: input.options?.locationCredentialsProvider, | ||
}, | ||
// Type casting is necessary because `copyInternal` supports both Gen1 and Gen2 signatures, but here | ||
// given in input can only be Gen2 signature, the return can only ben Gen2 signature. | ||
}) as Promise<CopyOutput>; |
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
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