Skip to content

Commit bcc3cbc

Browse files
authored
[Chore] Refactor Storage Options (#13613)
* refactor storage options naming * update casts * add bytelength base test
1 parent 555defc commit bcc3cbc

File tree

7 files changed

+106
-78
lines changed

7 files changed

+106
-78
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { byteLength } from '../../../../../src/providers/s3/apis/uploadData/byteLength';
5+
6+
describe('byteLength', () => {
7+
it('returns 0 for null or undefined', () => {
8+
expect(byteLength(undefined)).toBe(0);
9+
expect(byteLength(null)).toBe(0);
10+
});
11+
12+
it('calculates byte length correctly for ASCII strings', () => {
13+
expect(byteLength('hello')).toBe(5);
14+
});
15+
16+
it('calculates byte length correctly for multi-byte characters', () => {
17+
expect(byteLength('èちは')).toBe(8);
18+
});
19+
20+
it('handles Uint8Array correctly', () => {
21+
const input = new Uint8Array([1, 2, 3]);
22+
expect(byteLength(input)).toBe(3);
23+
});
24+
25+
it('handles ArrayBuffer correctly', () => {
26+
const buffer = new ArrayBuffer(8);
27+
expect(byteLength(buffer)).toBe(8);
28+
});
29+
30+
it('handles File object correctly', () => {
31+
const file = new Blob(['hello']);
32+
expect(byteLength(file)).toBe(5);
33+
});
34+
35+
it('returns undefined for unsupported types', () => {
36+
const input = { unsupportedType: true };
37+
expect(byteLength(input)).toBeUndefined();
38+
});
39+
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import {
2121
validateStorageOperationInputWithPrefix,
2222
} from '../../utils';
2323
import {
24-
ListAllOptionsWithPath,
25-
ListPaginateOptionsWithPath,
24+
ListAllWithPathOptions,
25+
ListPaginateWithPathOptions,
2626
ResolvedS3Config,
2727
} from '../../types/options';
2828
import {
@@ -267,7 +267,7 @@ const mapCommonPrefixesToExcludedSubpaths = (
267267
};
268268

269269
const getDelimiter = (
270-
options?: ListAllOptionsWithPath | ListPaginateOptionsWithPath,
270+
options?: ListAllWithPathOptions | ListPaginateWithPathOptions,
271271
): string | undefined => {
272272
if (options?.subpathStrategy?.strategy === 'exclude') {
273273
return options?.subpathStrategy?.delimiter ?? DEFAULT_DELIMITER;

packages/storage/src/providers/s3/apis/uploadData/multipart/uploadHandlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from '../../../utils/constants';
1818
import {
1919
ResolvedS3Config,
20-
UploadDataOptionsWithKey,
20+
UploadDataWithKeyOptions,
2121
} from '../../../types/options';
2222
import { StorageError } from '../../../../../errors/StorageError';
2323
import { CanceledError } from '../../../../../errors/CanceledError';
@@ -99,7 +99,7 @@ export const getMultipartUploadHandlers = (
9999

100100
// Resolve "key" specific options
101101
if (inputType === STORAGE_INPUT_KEY) {
102-
const accessLevel = (uploadDataOptions as UploadDataOptionsWithKey)
102+
const accessLevel = (uploadDataOptions as UploadDataWithKeyOptions)
103103
?.accessLevel;
104104

105105
resolvedKeyPrefix = resolvedS3Options.keyPrefix;

packages/storage/src/providers/s3/types/errors.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/storage/src/providers/s3/types/index.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
export {
5-
GetUrlOptionsWithKey,
6-
GetUrlOptionsWithPath,
7-
UploadDataOptionsWithPath,
8-
UploadDataOptionsWithKey,
9-
GetPropertiesOptionsWithKey,
10-
GetPropertiesOptionsWithPath,
11-
ListAllOptionsWithPrefix,
12-
ListPaginateOptionsWithPrefix,
13-
ListAllOptionsWithPath,
14-
ListPaginateOptionsWithPath,
5+
GetUrlWithKeyOptions,
6+
GetUrlWithPathOptions,
7+
UploadDataWithPathOptions,
8+
UploadDataWithKeyOptions,
9+
GetPropertiesWithKeyOptions,
10+
GetPropertiesWithPathOptions,
11+
ListAllWithPrefixOptions,
12+
ListPaginateWithPrefixOptions,
13+
ListAllWithPathOptions,
14+
ListPaginateWithPathOptions,
1515
RemoveOptions,
16-
DownloadDataOptionsWithPath,
17-
DownloadDataOptionsWithKey,
18-
CopyDestinationOptionsWithKey,
19-
CopySourceOptionsWithKey,
20-
CopyWithPathSourceOptions,
21-
CopyWithPathDestinationOptions,
16+
DownloadDataWithPathOptions,
17+
DownloadDataWithKeyOptions,
18+
CopyDestinationWithKeyOptions,
19+
CopySourceWithKeyOptions,
2220
} from './options';
2321
export {
2422
UploadDataOutput,
@@ -58,4 +56,3 @@ export {
5856
ListAllWithPathInput,
5957
ListPaginateWithPathInput,
6058
} from './inputs';
61-
export { S3Exception } from './errors';

packages/storage/src/providers/s3/types/inputs.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ import {
1818
StorageUploadDataInputWithPath,
1919
} from '../../../types';
2020
import {
21-
CopyDestinationOptionsWithKey,
22-
CopySourceOptionsWithKey,
23-
DownloadDataOptionsWithKey,
24-
DownloadDataOptionsWithPath,
25-
GetPropertiesOptionsWithKey,
26-
GetPropertiesOptionsWithPath,
27-
GetUrlOptionsWithKey,
28-
GetUrlOptionsWithPath,
29-
ListAllOptionsWithPath,
30-
ListAllOptionsWithPrefix,
31-
ListPaginateOptionsWithPath,
32-
ListPaginateOptionsWithPrefix,
21+
CopyDestinationWithKeyOptions,
22+
CopySourceWithKeyOptions,
23+
DownloadDataWithKeyOptions,
24+
DownloadDataWithPathOptions,
25+
GetPropertiesWithKeyOptions,
26+
GetPropertiesWithPathOptions,
27+
GetUrlWithKeyOptions,
28+
GetUrlWithPathOptions,
29+
ListAllWithPathOptions,
30+
ListAllWithPrefixOptions,
31+
ListPaginateWithPathOptions,
32+
ListPaginateWithPrefixOptions,
3333
RemoveOptions,
34-
UploadDataOptionsWithKey,
35-
UploadDataOptionsWithPath,
34+
UploadDataWithKeyOptions,
35+
UploadDataWithPathOptions,
3636
} from '../types';
3737

3838
// TODO: support use accelerate endpoint option
@@ -41,8 +41,8 @@ import {
4141
* Input type for S3 copy API.
4242
*/
4343
export type CopyInput = StorageCopyInputWithKey<
44-
CopySourceOptionsWithKey,
45-
CopyDestinationOptionsWithKey
44+
CopySourceWithKeyOptions,
45+
CopyDestinationWithKeyOptions
4646
>;
4747
/**
4848
* Input type with path for S3 copy API.
@@ -54,48 +54,48 @@ export type CopyWithPathInput = StorageCopyInputWithPath;
5454
* Input type for S3 getProperties API.
5555
*/
5656
export type GetPropertiesInput =
57-
StorageGetPropertiesInputWithKey<GetPropertiesOptionsWithKey>;
57+
StorageGetPropertiesInputWithKey<GetPropertiesWithKeyOptions>;
5858
/**
5959
* Input type with for S3 getProperties API.
6060
*/
6161
export type GetPropertiesWithPathInput =
62-
StorageGetPropertiesInputWithPath<GetPropertiesOptionsWithPath>;
62+
StorageGetPropertiesInputWithPath<GetPropertiesWithPathOptions>;
6363

6464
/**
6565
* @deprecated Use {@link GetUrlWithPathInput} instead.
6666
* Input type for S3 getUrl API.
6767
*/
68-
export type GetUrlInput = StorageGetUrlInputWithKey<GetUrlOptionsWithKey>;
68+
export type GetUrlInput = StorageGetUrlInputWithKey<GetUrlWithKeyOptions>;
6969
/**
7070
* Input type with path for S3 getUrl API.
7171
*/
7272
export type GetUrlWithPathInput =
73-
StorageGetUrlInputWithPath<GetUrlOptionsWithPath>;
73+
StorageGetUrlInputWithPath<GetUrlWithPathOptions>;
7474

7575
/**
7676
* Input type with path for S3 list API. Lists all bucket objects.
7777
*/
7878
export type ListAllWithPathInput =
79-
StorageListInputWithPath<ListAllOptionsWithPath>;
79+
StorageListInputWithPath<ListAllWithPathOptions>;
8080

8181
/**
8282
* Input type with path for S3 list API. Lists bucket objects with pagination.
8383
*/
8484
export type ListPaginateWithPathInput =
85-
StorageListInputWithPath<ListPaginateOptionsWithPath>;
85+
StorageListInputWithPath<ListPaginateWithPathOptions>;
8686

8787
/**
8888
* @deprecated Use {@link ListAllWithPathInput} instead.
8989
* Input type for S3 list API. Lists all bucket objects.
9090
*/
91-
export type ListAllInput = StorageListInputWithPrefix<ListAllOptionsWithPrefix>;
91+
export type ListAllInput = StorageListInputWithPrefix<ListAllWithPrefixOptions>;
9292

9393
/**
9494
* @deprecated Use {@link ListPaginateWithPathInput} instead.
9595
* Input type for S3 list API. Lists bucket objects with pagination.
9696
*/
9797
export type ListPaginateInput =
98-
StorageListInputWithPrefix<ListPaginateOptionsWithPrefix>;
98+
StorageListInputWithPrefix<ListPaginateWithPrefixOptions>;
9999

100100
/**
101101
* @deprecated Use {@link RemoveWithPathInput} instead.
@@ -115,23 +115,23 @@ export type RemoveWithPathInput = StorageRemoveInputWithPath<
115115
* Input type for S3 downloadData API.
116116
*/
117117
export type DownloadDataInput =
118-
StorageDownloadDataInputWithKey<DownloadDataOptionsWithKey>;
118+
StorageDownloadDataInputWithKey<DownloadDataWithKeyOptions>;
119119

120120
/**
121121
* Input type with path for S3 downloadData API.
122122
*/
123123
export type DownloadDataWithPathInput =
124-
StorageDownloadDataInputWithPath<DownloadDataOptionsWithPath>;
124+
StorageDownloadDataInputWithPath<DownloadDataWithPathOptions>;
125125

126126
/**
127127
* @deprecated Use {@link UploadDataWithPathInput} instead.
128128
* Input type for S3 uploadData API.
129129
*/
130130
export type UploadDataInput =
131-
StorageUploadDataInputWithKey<UploadDataOptionsWithKey>;
131+
StorageUploadDataInputWithKey<UploadDataWithKeyOptions>;
132132

133133
/**
134134
* Input type with path for S3 uploadData API.
135135
*/
136136
export type UploadDataWithPathInput =
137-
StorageUploadDataInputWithPath<UploadDataOptionsWithPath>;
137+
StorageUploadDataInputWithPath<UploadDataWithPathOptions>;

packages/storage/src/providers/s3/types/options.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,35 @@ interface TransferOptions {
7474
/**
7575
* Input options type for S3 getProperties API.
7676
*/
77-
/** @deprecated Use {@link GetPropertiesOptionsWithPath} instead. */
78-
export type GetPropertiesOptionsWithKey = ReadOptions & CommonOptions;
79-
export type GetPropertiesOptionsWithPath = CommonOptions;
77+
/** @deprecated Use {@link GetPropertiesWithPathOptions} instead. */
78+
export type GetPropertiesWithKeyOptions = ReadOptions & CommonOptions;
79+
export type GetPropertiesWithPathOptions = CommonOptions;
8080

8181
/**
8282
* Input options type for S3 getProperties API.
8383
*/
8484
export type RemoveOptions = WriteOptions & CommonOptions;
8585

8686
/**
87-
* @deprecated Use {@link ListAllOptionsWithPath} instead.
87+
* @deprecated Use {@link ListAllWithPathOptions} instead.
8888
* Input options type with prefix for S3 list all API.
8989
*/
90-
export type ListAllOptionsWithPrefix = StorageListAllOptions &
90+
export type ListAllWithPrefixOptions = StorageListAllOptions &
9191
ReadOptions &
9292
CommonOptions;
9393

9494
/**
95-
* @deprecated Use {@link ListPaginateOptionsWithPath} instead.
95+
* @deprecated Use {@link ListPaginateWithPathOptions} instead.
9696
* Input options type with prefix for S3 list API to paginate items.
9797
*/
98-
export type ListPaginateOptionsWithPrefix = StorageListPaginateOptions &
98+
export type ListPaginateWithPrefixOptions = StorageListPaginateOptions &
9999
ReadOptions &
100100
CommonOptions;
101101

102102
/**
103103
* Input options type with path for S3 list all API.
104104
*/
105-
export type ListAllOptionsWithPath = Omit<
105+
export type ListAllWithPathOptions = Omit<
106106
StorageListAllOptions,
107107
'accessLevel'
108108
> &
@@ -113,7 +113,7 @@ export type ListAllOptionsWithPath = Omit<
113113
/**
114114
* Input options type with path for S3 list API to paginate items.
115115
*/
116-
export type ListPaginateOptionsWithPath = Omit<
116+
export type ListPaginateWithPathOptions = Omit<
117117
StorageListPaginateOptions,
118118
'accessLevel'
119119
> &
@@ -150,9 +150,9 @@ export type GetUrlOptions = CommonOptions & {
150150
contentType?: string;
151151
};
152152

153-
/** @deprecated Use {@link GetUrlOptionsWithPath} instead. */
154-
export type GetUrlOptionsWithKey = ReadOptions & GetUrlOptions;
155-
export type GetUrlOptionsWithPath = GetUrlOptions;
153+
/** @deprecated Use {@link GetUrlWithPathOptions} instead. */
154+
export type GetUrlWithKeyOptions = ReadOptions & GetUrlOptions;
155+
export type GetUrlWithPathOptions = GetUrlOptions;
156156

157157
/**
158158
* Input options type for S3 downloadData API.
@@ -161,9 +161,9 @@ export type DownloadDataOptions = CommonOptions &
161161
TransferOptions &
162162
BytesRangeOptions;
163163

164-
/** @deprecated Use {@link DownloadDataOptionsWithPath} instead. */
165-
export type DownloadDataOptionsWithKey = ReadOptions & DownloadDataOptions;
166-
export type DownloadDataOptionsWithPath = DownloadDataOptions;
164+
/** @deprecated Use {@link DownloadDataWithPathOptions} instead. */
165+
export type DownloadDataWithKeyOptions = ReadOptions & DownloadDataOptions;
166+
export type DownloadDataWithPathOptions = DownloadDataOptions;
167167

168168
export type UploadDataOptions = CommonOptions &
169169
TransferOptions & {
@@ -192,19 +192,19 @@ export type UploadDataOptions = CommonOptions &
192192
metadata?: Record<string, string>;
193193
};
194194

195-
/** @deprecated Use {@link UploadDataOptionsWithPath} instead. */
196-
export type UploadDataOptionsWithKey = WriteOptions & UploadDataOptions;
197-
export type UploadDataOptionsWithPath = UploadDataOptions;
195+
/** @deprecated Use {@link UploadDataWithPathOptions} instead. */
196+
export type UploadDataWithKeyOptions = WriteOptions & UploadDataOptions;
197+
export type UploadDataWithPathOptions = UploadDataOptions;
198198

199199
/** @deprecated This may be removed in the next major version. */
200-
export type CopySourceOptionsWithKey = ReadOptions & {
200+
export type CopySourceWithKeyOptions = ReadOptions & {
201201
/** @deprecated This may be removed in the next major version. */
202202
key: string;
203203
bucket?: StorageBucket;
204204
};
205205

206206
/** @deprecated This may be removed in the next major version. */
207-
export type CopyDestinationOptionsWithKey = WriteOptions & {
207+
export type CopyDestinationWithKeyOptions = WriteOptions & {
208208
/** @deprecated This may be removed in the next major version. */
209209
key: string;
210210
bucket?: StorageBucket;

0 commit comments

Comments
 (0)