Skip to content

Commit d0e6e69

Browse files
authored
release(required): Amplify JS release (#13942)
2 parents 554c3d5 + bf58ebc commit d0e6e69

File tree

7 files changed

+74
-10
lines changed

7 files changed

+74
-10
lines changed

.github/ISSUE_TEMPLATE/1.bug_report.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ body:
126126
multiple: false
127127
options:
128128
- Amplify CLI
129-
- Amplify Gen 2 (Preview)
129+
- Amplify Gen 2
130130
- CDK
131131
- Other
132132
- type: textarea

packages/core/__tests__/Cache/StorageCacheCommon.test.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defaultConfig } from '../../src/Cache/constants';
33
import { StorageCacheCommon } from '../../src/Cache/StorageCacheCommon';
44
import { KeyValueStorageInterface } from '../../src/types';
55
import { ConsoleLogger } from '../../src/Logger';
6+
import { StorageCache } from '../../src/Cache/StorageCache';
67
import {
78
getByteLength,
89
getCurrentSizeKey,
@@ -584,16 +585,20 @@ describe('StorageCacheCommon', () => {
584585
});
585586

586587
describe('clear()', () => {
587-
const cache = getStorageCache(config);
588+
const cache = new StorageCache(config);
588589

589590
it('clears the cache, including the currentSizeKey', async () => {
590-
mockGetAllCacheKeys.mockReturnValue([
591-
currentSizeKey,
592-
`${keyPrefix}some-key`,
593-
]);
591+
await cache.setItem('key1', 'value1');
592+
await cache.setItem('key2', 'value2');
593+
594+
expect(await cache.getItem('key1')).toBe('value1');
595+
expect(await cache.getItem('key2')).toBe('value2');
596+
594597
await cache.clear();
595-
expect(loggerSpy.debug).toHaveBeenCalledWith('Clear Cache');
596-
expect(mockKeyValueStorageRemoveItem).toHaveBeenCalledTimes(2);
598+
599+
expect(await cache.getItem('key1')).toBeNull();
600+
expect(await cache.getItem('key2')).toBeNull();
601+
expect(await cache.getCurrentCacheSize()).toBe(0);
597602
});
598603
});
599604

packages/core/src/Cache/StorageCacheCommon.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,8 @@ export abstract class StorageCacheCommon {
588588
try {
589589
const keys = await this.getAllKeys();
590590
for (const key of keys) {
591-
await this.getStorage().removeItem(key);
591+
const prefixedKey = `${this.config.keyPrefix}${key}`;
592+
await this.getStorage().removeItem(prefixedKey);
592593
}
593594
} catch (e) {
594595
logger.warn(`clear failed! ${e}`);

packages/storage/__tests__/providers/s3/apis/list.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,47 @@ describe('list API', () => {
506506
},
507507
);
508508

509+
it.each(pathTestCases)(
510+
'should list objects with CommonPrefix and nextToken in results with custom path: $path',
511+
async ({ path }) => {
512+
mockListObject.mockImplementationOnce(() => {
513+
return {
514+
CommonPrefixes: [
515+
{ Prefix: 'photos/2023/' },
516+
{ Prefix: 'photos/2024/' },
517+
{ Prefix: 'photos/2025/' },
518+
{ Prefix: 'photos/2026/' },
519+
{ Prefix: 'photos/2027/' },
520+
{ Prefix: 'photos/time-traveling/' },
521+
],
522+
NextContinuationToken: 'yup_there_is_more',
523+
};
524+
});
525+
const response = await listPaginatedWrapper({
526+
path: resolvePath(path),
527+
});
528+
expect(response.excludedSubpaths).toEqual([
529+
'photos/2023/',
530+
'photos/2024/',
531+
'photos/2025/',
532+
'photos/2026/',
533+
'photos/2027/',
534+
'photos/time-traveling/',
535+
]);
536+
537+
expect(response.nextToken).toEqual('yup_there_is_more');
538+
expect(listObjectsV2).toHaveBeenCalledTimes(1);
539+
await expect(listObjectsV2).toBeLastCalledWithConfigAndInput(
540+
listObjectClientConfig,
541+
{
542+
Bucket: bucket,
543+
MaxKeys: 1000,
544+
Prefix: resolvePath(path),
545+
},
546+
);
547+
},
548+
);
549+
509550
it.each(pathTestCases)(
510551
'should list all objects having three pages with custom path: $path',
511552
async ({ path: inputPath }) => {

packages/storage/__tests__/providers/s3/apis/uploadData/index.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,22 @@ describe('uploadData with path', () => {
180180
},
181181
);
182182

183+
it('should use putObject for 0 bytes data (e.g. create a folder)', () => {
184+
const testInput = {
185+
path: 'test-path',
186+
data: '', // 0 bytes
187+
};
188+
189+
uploadData(testInput);
190+
191+
expect(mockPutObjectJob).toHaveBeenCalledWith(
192+
testInput,
193+
expect.any(AbortSignal),
194+
expect.any(Number),
195+
);
196+
expect(mockGetMultipartUploadHandlers).not.toHaveBeenCalled();
197+
});
198+
183199
it('should use uploadTask', async () => {
184200
mockPutObjectJob.mockReturnValueOnce('putObjectJob');
185201
mockCreateUploadTask.mockReturnValueOnce('uploadTask');

packages/storage/src/providers/s3/apis/internal/list.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ const _listWithPath = async ({
238238
if (!contents) {
239239
return {
240240
items: [],
241+
nextToken: nextContinuationToken,
241242
excludedSubpaths,
242243
};
243244
}

packages/storage/src/providers/s3/apis/uploadData/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export function uploadData(input: UploadDataInput | UploadDataWithPathInput) {
135135
StorageValidationErrorCode.ObjectIsTooLarge,
136136
);
137137

138-
if (dataByteLength && dataByteLength <= DEFAULT_PART_SIZE) {
138+
if (dataByteLength !== undefined && dataByteLength <= DEFAULT_PART_SIZE) {
139139
// Single part upload
140140
const abortController = new AbortController();
141141

0 commit comments

Comments
 (0)