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

release(required): Amplify JS release #13942

Merged
merged 5 commits into from
Oct 21, 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 .github/ISSUE_TEMPLATE/1.bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ body:
multiple: false
options:
- Amplify CLI
- Amplify Gen 2 (Preview)
- Amplify Gen 2
- CDK
- Other
- type: textarea
Expand Down
19 changes: 12 additions & 7 deletions packages/core/__tests__/Cache/StorageCacheCommon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defaultConfig } from '../../src/Cache/constants';
import { StorageCacheCommon } from '../../src/Cache/StorageCacheCommon';
import { KeyValueStorageInterface } from '../../src/types';
import { ConsoleLogger } from '../../src/Logger';
import { StorageCache } from '../../src/Cache/StorageCache';
import {
getByteLength,
getCurrentSizeKey,
Expand Down Expand Up @@ -584,16 +585,20 @@ describe('StorageCacheCommon', () => {
});

describe('clear()', () => {
const cache = getStorageCache(config);
const cache = new StorageCache(config);

it('clears the cache, including the currentSizeKey', async () => {
mockGetAllCacheKeys.mockReturnValue([
currentSizeKey,
`${keyPrefix}some-key`,
]);
await cache.setItem('key1', 'value1');
await cache.setItem('key2', 'value2');

expect(await cache.getItem('key1')).toBe('value1');
expect(await cache.getItem('key2')).toBe('value2');

await cache.clear();
expect(loggerSpy.debug).toHaveBeenCalledWith('Clear Cache');
expect(mockKeyValueStorageRemoveItem).toHaveBeenCalledTimes(2);

expect(await cache.getItem('key1')).toBeNull();
expect(await cache.getItem('key2')).toBeNull();
expect(await cache.getCurrentCacheSize()).toBe(0);
});
});

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/Cache/StorageCacheCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ export abstract class StorageCacheCommon {
try {
const keys = await this.getAllKeys();
for (const key of keys) {
await this.getStorage().removeItem(key);
const prefixedKey = `${this.config.keyPrefix}${key}`;
await this.getStorage().removeItem(prefixedKey);
}
} catch (e) {
logger.warn(`clear failed! ${e}`);
Expand Down
41 changes: 41 additions & 0 deletions packages/storage/__tests__/providers/s3/apis/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,47 @@ describe('list API', () => {
},
);

it.each(pathTestCases)(
'should list objects with CommonPrefix and nextToken in results with custom path: $path',
async ({ path }) => {
mockListObject.mockImplementationOnce(() => {
return {
CommonPrefixes: [
{ Prefix: 'photos/2023/' },
{ Prefix: 'photos/2024/' },
{ Prefix: 'photos/2025/' },
{ Prefix: 'photos/2026/' },
{ Prefix: 'photos/2027/' },
{ Prefix: 'photos/time-traveling/' },
],
NextContinuationToken: 'yup_there_is_more',
};
});
const response = await listPaginatedWrapper({
path: resolvePath(path),
});
expect(response.excludedSubpaths).toEqual([
'photos/2023/',
'photos/2024/',
'photos/2025/',
'photos/2026/',
'photos/2027/',
'photos/time-traveling/',
]);

expect(response.nextToken).toEqual('yup_there_is_more');
expect(listObjectsV2).toHaveBeenCalledTimes(1);
await expect(listObjectsV2).toBeLastCalledWithConfigAndInput(
listObjectClientConfig,
{
Bucket: bucket,
MaxKeys: 1000,
Prefix: resolvePath(path),
},
);
},
);

it.each(pathTestCases)(
'should list all objects having three pages with custom path: $path',
async ({ path: inputPath }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,22 @@ describe('uploadData with path', () => {
},
);

it('should use putObject for 0 bytes data (e.g. create a folder)', () => {
const testInput = {
path: 'test-path',
data: '', // 0 bytes
};

uploadData(testInput);

expect(mockPutObjectJob).toHaveBeenCalledWith(
testInput,
expect.any(AbortSignal),
expect.any(Number),
);
expect(mockGetMultipartUploadHandlers).not.toHaveBeenCalled();
});

it('should use uploadTask', async () => {
mockPutObjectJob.mockReturnValueOnce('putObjectJob');
mockCreateUploadTask.mockReturnValueOnce('uploadTask');
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/internal/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const _listWithPath = async ({
if (!contents) {
return {
items: [],
nextToken: nextContinuationToken,
excludedSubpaths,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function uploadData(input: UploadDataInput | UploadDataWithPathInput) {
StorageValidationErrorCode.ObjectIsTooLarge,
);

if (dataByteLength && dataByteLength <= DEFAULT_PART_SIZE) {
if (dataByteLength !== undefined && dataByteLength <= DEFAULT_PART_SIZE) {
// Single part upload
const abortController = new AbortController();

Expand Down
Loading