@aws-amplify/storage 6.0.28 → 6.0.29-gen2-storage.e54bfa9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/errors/types/validation.js +22 -2
- package/dist/cjs/errors/types/validation.js.map +1 -1
- package/dist/cjs/providers/s3/apis/copy.js +2 -12
- package/dist/cjs/providers/s3/apis/copy.js.map +1 -1
- package/dist/cjs/providers/s3/apis/downloadData.js +13 -38
- package/dist/cjs/providers/s3/apis/downloadData.js.map +1 -1
- package/dist/cjs/providers/s3/apis/getProperties.js +2 -11
- package/dist/cjs/providers/s3/apis/getProperties.js.map +1 -1
- package/dist/cjs/providers/s3/apis/getUrl.js +2 -18
- package/dist/cjs/providers/s3/apis/getUrl.js.map +1 -1
- package/dist/cjs/providers/s3/apis/internal/copy.js +41 -7
- package/dist/cjs/providers/s3/apis/internal/copy.js.map +1 -1
- package/dist/cjs/providers/s3/apis/internal/getProperties.js +10 -6
- package/dist/cjs/providers/s3/apis/internal/getProperties.js.map +1 -1
- package/dist/cjs/providers/s3/apis/internal/getUrl.js +8 -6
- package/dist/cjs/providers/s3/apis/internal/getUrl.js.map +1 -1
- package/dist/cjs/providers/s3/apis/internal/list.js +86 -16
- package/dist/cjs/providers/s3/apis/internal/list.js.map +1 -1
- package/dist/cjs/providers/s3/apis/internal/remove.js +20 -7
- package/dist/cjs/providers/s3/apis/internal/remove.js.map +1 -1
- package/dist/cjs/providers/s3/apis/list.js +4 -4
- package/dist/cjs/providers/s3/apis/list.js.map +1 -1
- package/dist/cjs/providers/s3/apis/remove.js +2 -9
- package/dist/cjs/providers/s3/apis/remove.js.map +1 -1
- package/dist/cjs/providers/s3/apis/server/copy.js +4 -4
- package/dist/cjs/providers/s3/apis/server/copy.js.map +1 -1
- package/dist/cjs/providers/s3/apis/server/getProperties.js +2 -2
- package/dist/cjs/providers/s3/apis/server/getProperties.js.map +1 -1
- package/dist/cjs/providers/s3/apis/server/getUrl.js +2 -2
- package/dist/cjs/providers/s3/apis/server/getUrl.js.map +1 -1
- package/dist/cjs/providers/s3/apis/server/list.js +4 -4
- package/dist/cjs/providers/s3/apis/server/list.js.map +1 -1
- package/dist/cjs/providers/s3/apis/server/remove.js +2 -2
- package/dist/cjs/providers/s3/apis/server/remove.js.map +1 -1
- package/dist/cjs/providers/s3/apis/uploadData/index.js +4 -50
- package/dist/cjs/providers/s3/apis/uploadData/index.js.map +1 -1
- package/dist/cjs/providers/s3/apis/uploadData/multipart/initialUpload.js +1 -1
- package/dist/cjs/providers/s3/apis/uploadData/multipart/initialUpload.js.map +1 -1
- package/dist/cjs/providers/s3/apis/uploadData/multipart/uploadCache.js +8 -1
- package/dist/cjs/providers/s3/apis/uploadData/multipart/uploadCache.js.map +1 -1
- package/dist/cjs/providers/s3/apis/uploadData/multipart/uploadHandlers.js +28 -13
- package/dist/cjs/providers/s3/apis/uploadData/multipart/uploadHandlers.js.map +1 -1
- package/dist/cjs/providers/s3/apis/uploadData/putObjectJob.js +10 -5
- package/dist/cjs/providers/s3/apis/uploadData/putObjectJob.js.map +1 -1
- package/dist/cjs/providers/s3/utils/client/utils/parsePayload.js +1 -1
- package/dist/cjs/providers/s3/utils/client/utils/parsePayload.js.map +1 -1
- package/dist/cjs/providers/s3/utils/constants.js +4 -1
- package/dist/cjs/providers/s3/utils/constants.js.map +1 -1
- package/dist/cjs/providers/s3/utils/index.js +7 -1
- package/dist/cjs/providers/s3/utils/index.js.map +1 -1
- package/dist/cjs/providers/s3/utils/isInputWithPath.js +11 -0
- package/dist/cjs/providers/s3/utils/isInputWithPath.js.map +1 -0
- package/dist/cjs/providers/s3/utils/resolveS3ConfigAndInput.js +2 -1
- package/dist/cjs/providers/s3/utils/resolveS3ConfigAndInput.js.map +1 -1
- package/dist/cjs/providers/s3/utils/validateStorageOperationInput.js +31 -0
- package/dist/cjs/providers/s3/utils/validateStorageOperationInput.js.map +1 -0
- package/dist/cjs/providers/s3/utils/validateStorageOperationInputWithPrefix.js +32 -0
- package/dist/cjs/providers/s3/utils/validateStorageOperationInputWithPrefix.js.map +1 -0
- package/dist/esm/errors/types/validation.d.ts +7 -2
- package/dist/esm/errors/types/validation.mjs +22 -2
- package/dist/esm/errors/types/validation.mjs.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/providers/s3/apis/copy.d.ts +22 -9
- package/dist/esm/providers/s3/apis/copy.mjs +2 -12
- package/dist/esm/providers/s3/apis/copy.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/downloadData.d.ts +41 -7
- package/dist/esm/providers/s3/apis/downloadData.mjs +15 -39
- package/dist/esm/providers/s3/apis/downloadData.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/getProperties.d.ts +18 -5
- package/dist/esm/providers/s3/apis/getProperties.mjs +2 -11
- package/dist/esm/providers/s3/apis/getProperties.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/getUrl.d.ts +27 -7
- package/dist/esm/providers/s3/apis/getUrl.mjs +2 -18
- package/dist/esm/providers/s3/apis/getUrl.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/internal/copy.d.ts +4 -2
- package/dist/esm/providers/s3/apis/internal/copy.mjs +41 -6
- package/dist/esm/providers/s3/apis/internal/copy.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/internal/getProperties.d.ts +2 -2
- package/dist/esm/providers/s3/apis/internal/getProperties.mjs +11 -6
- package/dist/esm/providers/s3/apis/internal/getProperties.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/internal/getUrl.d.ts +2 -2
- package/dist/esm/providers/s3/apis/internal/getUrl.mjs +10 -7
- package/dist/esm/providers/s3/apis/internal/getUrl.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/internal/list.d.ts +2 -2
- package/dist/esm/providers/s3/apis/internal/list.mjs +87 -16
- package/dist/esm/providers/s3/apis/internal/list.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/internal/remove.d.ts +2 -2
- package/dist/esm/providers/s3/apis/internal/remove.mjs +21 -7
- package/dist/esm/providers/s3/apis/internal/remove.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/list.d.ts +39 -22
- package/dist/esm/providers/s3/apis/list.mjs +2 -2
- package/dist/esm/providers/s3/apis/list.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/remove.d.ts +18 -5
- package/dist/esm/providers/s3/apis/remove.mjs +2 -9
- package/dist/esm/providers/s3/apis/remove.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/server/copy.d.ts +27 -2
- package/dist/esm/providers/s3/apis/server/copy.mjs +2 -2
- package/dist/esm/providers/s3/apis/server/copy.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/server/getProperties.d.ts +26 -2
- package/dist/esm/providers/s3/apis/server/getProperties.mjs +2 -2
- package/dist/esm/providers/s3/apis/server/getProperties.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/server/getUrl.d.ts +40 -2
- package/dist/esm/providers/s3/apis/server/getUrl.mjs +2 -2
- package/dist/esm/providers/s3/apis/server/getUrl.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/server/list.d.ts +41 -22
- package/dist/esm/providers/s3/apis/server/list.mjs +2 -2
- package/dist/esm/providers/s3/apis/server/list.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/server/remove.d.ts +24 -2
- package/dist/esm/providers/s3/apis/server/remove.mjs +2 -2
- package/dist/esm/providers/s3/apis/server/remove.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/uploadData/index.d.ts +64 -7
- package/dist/esm/providers/s3/apis/uploadData/index.mjs +4 -50
- package/dist/esm/providers/s3/apis/uploadData/index.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/uploadData/multipart/initialUpload.d.ts +2 -2
- package/dist/esm/providers/s3/apis/uploadData/multipart/initialUpload.mjs +1 -1
- package/dist/esm/providers/s3/apis/uploadData/multipart/initialUpload.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/uploadData/multipart/uploadCache.d.ts +1 -1
- package/dist/esm/providers/s3/apis/uploadData/multipart/uploadCache.mjs +8 -1
- package/dist/esm/providers/s3/apis/uploadData/multipart/uploadCache.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/uploadData/multipart/uploadHandlers.d.ts +4 -4
- package/dist/esm/providers/s3/apis/uploadData/multipart/uploadHandlers.mjs +30 -14
- package/dist/esm/providers/s3/apis/uploadData/multipart/uploadHandlers.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/uploadData/putObjectJob.d.ts +3 -3
- package/dist/esm/providers/s3/apis/uploadData/putObjectJob.mjs +11 -5
- package/dist/esm/providers/s3/apis/uploadData/putObjectJob.mjs.map +1 -1
- package/dist/esm/providers/s3/index.d.ts +2 -2
- package/dist/esm/providers/s3/types/index.d.ts +3 -3
- package/dist/esm/providers/s3/types/inputs.d.ts +51 -11
- package/dist/esm/providers/s3/types/options.d.ts +41 -10
- package/dist/esm/providers/s3/types/outputs.d.ts +68 -13
- package/dist/esm/providers/s3/utils/client/utils/parsePayload.mjs +1 -1
- package/dist/esm/providers/s3/utils/client/utils/parsePayload.mjs.map +1 -1
- package/dist/esm/providers/s3/utils/constants.d.ts +3 -0
- package/dist/esm/providers/s3/utils/constants.mjs +4 -1
- package/dist/esm/providers/s3/utils/constants.mjs.map +1 -1
- package/dist/esm/providers/s3/utils/index.d.ts +3 -0
- package/dist/esm/providers/s3/utils/index.mjs +3 -0
- package/dist/esm/providers/s3/utils/index.mjs.map +1 -1
- package/dist/esm/providers/s3/utils/isInputWithPath.d.ts +2 -0
- package/dist/esm/providers/s3/utils/isInputWithPath.mjs +8 -0
- package/dist/esm/providers/s3/utils/isInputWithPath.mjs.map +1 -0
- package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.d.ts +2 -1
- package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.mjs +2 -1
- package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.mjs.map +1 -1
- package/dist/esm/providers/s3/utils/validateStorageOperationInput.d.ts +5 -0
- package/dist/esm/providers/s3/utils/validateStorageOperationInput.mjs +29 -0
- package/dist/esm/providers/s3/utils/validateStorageOperationInput.mjs.map +1 -0
- package/dist/esm/providers/s3/utils/validateStorageOperationInputWithPrefix.d.ts +5 -0
- package/dist/esm/providers/s3/utils/validateStorageOperationInputWithPrefix.mjs +30 -0
- package/dist/esm/providers/s3/utils/validateStorageOperationInputWithPrefix.mjs.map +1 -0
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/inputs.d.ts +41 -13
- package/dist/esm/types/options.d.ts +1 -0
- package/dist/esm/types/outputs.d.ts +26 -6
- package/package.json +107 -107
- package/src/errors/types/validation.ts +23 -2
- package/src/index.ts +16 -0
- package/src/providers/s3/apis/copy.ts +30 -11
- package/src/providers/s3/apis/downloadData.ts +78 -19
- package/src/providers/s3/apis/getProperties.ts +31 -8
- package/src/providers/s3/apis/getUrl.ts +37 -10
- package/src/providers/s3/apis/internal/copy.ts +89 -8
- package/src/providers/s3/apis/internal/getProperties.ts +27 -12
- package/src/providers/s3/apis/internal/getUrl.ts +28 -14
- package/src/providers/s3/apis/internal/list.ts +135 -29
- package/src/providers/s3/apis/internal/remove.ts +36 -13
- package/src/providers/s3/apis/list.ts +54 -26
- package/src/providers/s3/apis/remove.ts +28 -7
- package/src/providers/s3/apis/server/copy.ts +42 -5
- package/src/providers/s3/apis/server/getProperties.ts +41 -4
- package/src/providers/s3/apis/server/getUrl.ts +55 -4
- package/src/providers/s3/apis/server/list.ts +64 -32
- package/src/providers/s3/apis/server/remove.ts +39 -4
- package/src/providers/s3/apis/uploadData/index.ts +77 -8
- package/src/providers/s3/apis/uploadData/multipart/initialUpload.ts +4 -3
- package/src/providers/s3/apis/uploadData/multipart/uploadCache.ts +11 -2
- package/src/providers/s3/apis/uploadData/multipart/uploadHandlers.ts +50 -20
- package/src/providers/s3/apis/uploadData/putObjectJob.ts +23 -9
- package/src/providers/s3/index.ts +16 -0
- package/src/providers/s3/types/index.ts +37 -14
- package/src/providers/s3/types/inputs.ts +95 -26
- package/src/providers/s3/types/options.ts +73 -27
- package/src/providers/s3/types/outputs.ts +80 -13
- package/src/providers/s3/utils/client/utils/parsePayload.ts +1 -1
- package/src/providers/s3/utils/constants.ts +4 -0
- package/src/providers/s3/utils/index.ts +3 -0
- package/src/providers/s3/utils/isInputWithPath.ts +13 -0
- package/src/providers/s3/utils/resolveS3ConfigAndInput.ts +3 -2
- package/src/providers/s3/utils/validateStorageOperationInput.ts +39 -0
- package/src/providers/s3/utils/validateStorageOperationInputWithPrefix.ts +46 -0
- package/src/types/index.ts +16 -8
- package/src/types/inputs.ts +73 -20
- package/src/types/options.ts +1 -0
- package/src/types/outputs.ts +29 -6
|
@@ -7,11 +7,19 @@ import { StorageAction } from '@aws-amplify/core/internals/utils';
|
|
|
7
7
|
import {
|
|
8
8
|
ListAllInput,
|
|
9
9
|
ListAllOutput,
|
|
10
|
+
ListAllWithPathInput,
|
|
11
|
+
ListAllWithPathOutput,
|
|
10
12
|
ListOutputItem,
|
|
13
|
+
ListOutputItemWithPath,
|
|
11
14
|
ListPaginateInput,
|
|
12
15
|
ListPaginateOutput,
|
|
16
|
+
ListPaginateWithPathInput,
|
|
17
|
+
ListPaginateWithPathOutput,
|
|
13
18
|
} from '../../types';
|
|
14
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
resolveS3ConfigAndInput,
|
|
21
|
+
validateStorageOperationInputWithPrefix,
|
|
22
|
+
} from '../../utils';
|
|
15
23
|
import { ResolvedS3Config } from '../../types/options';
|
|
16
24
|
import {
|
|
17
25
|
ListObjectsV2Input,
|
|
@@ -20,25 +28,43 @@ import {
|
|
|
20
28
|
} from '../../utils/client';
|
|
21
29
|
import { getStorageUserAgentValue } from '../../utils/userAgent';
|
|
22
30
|
import { logger } from '../../../../utils';
|
|
31
|
+
import { STORAGE_INPUT_PREFIX } from '../../utils/constants';
|
|
23
32
|
|
|
24
33
|
const MAX_PAGE_SIZE = 1000;
|
|
25
34
|
|
|
26
35
|
interface ListInputArgs {
|
|
27
36
|
s3Config: ResolvedS3Config;
|
|
28
37
|
listParams: ListObjectsV2Input;
|
|
29
|
-
|
|
38
|
+
generatedPrefix?: string;
|
|
30
39
|
}
|
|
31
40
|
|
|
32
41
|
export const list = async (
|
|
33
42
|
amplify: AmplifyClassV6,
|
|
34
|
-
input
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
input:
|
|
44
|
+
| ListAllInput
|
|
45
|
+
| ListPaginateInput
|
|
46
|
+
| ListAllWithPathInput
|
|
47
|
+
| ListPaginateWithPathInput,
|
|
48
|
+
): Promise<
|
|
49
|
+
| ListAllOutput
|
|
50
|
+
| ListPaginateOutput
|
|
51
|
+
| ListAllWithPathOutput
|
|
52
|
+
| ListPaginateWithPathOutput
|
|
53
|
+
> => {
|
|
54
|
+
const { options = {} } = input;
|
|
37
55
|
const {
|
|
38
56
|
s3Config,
|
|
39
57
|
bucket,
|
|
40
|
-
keyPrefix:
|
|
58
|
+
keyPrefix: generatedPrefix,
|
|
59
|
+
identityId,
|
|
41
60
|
} = await resolveS3ConfigAndInput(amplify, options);
|
|
61
|
+
|
|
62
|
+
const { inputType, objectKey } = validateStorageOperationInputWithPrefix(
|
|
63
|
+
input,
|
|
64
|
+
identityId,
|
|
65
|
+
);
|
|
66
|
+
const isInputWithPrefix = inputType === STORAGE_INPUT_PREFIX;
|
|
67
|
+
|
|
42
68
|
// @ts-expect-error pageSize and nextToken should not coexist with listAll
|
|
43
69
|
if (options?.listAll && (options?.pageSize || options?.nextToken)) {
|
|
44
70
|
const anyOptions = options as any;
|
|
@@ -50,34 +76,53 @@ export const list = async (
|
|
|
50
76
|
}
|
|
51
77
|
const listParams = {
|
|
52
78
|
Bucket: bucket,
|
|
53
|
-
Prefix: `${
|
|
79
|
+
Prefix: isInputWithPrefix ? `${generatedPrefix}${objectKey}` : objectKey,
|
|
54
80
|
MaxKeys: options?.listAll ? undefined : options?.pageSize,
|
|
55
81
|
ContinuationToken: options?.listAll ? undefined : options?.nextToken,
|
|
56
82
|
};
|
|
57
83
|
logger.debug(`listing items from "${listParams.Prefix}"`);
|
|
58
84
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
85
|
+
const listInputArgs: ListInputArgs = {
|
|
86
|
+
s3Config,
|
|
87
|
+
listParams,
|
|
88
|
+
};
|
|
89
|
+
if (options.listAll) {
|
|
90
|
+
if (isInputWithPrefix) {
|
|
91
|
+
return _listAllWithPrefix({
|
|
92
|
+
...listInputArgs,
|
|
93
|
+
generatedPrefix,
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
return _listAllWithPath(listInputArgs);
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
if (isInputWithPrefix) {
|
|
100
|
+
return _listWithPrefix({ ...listInputArgs, generatedPrefix });
|
|
101
|
+
} else {
|
|
102
|
+
return _listWithPath(listInputArgs);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
62
105
|
};
|
|
63
106
|
|
|
64
|
-
|
|
107
|
+
/** @deprecated Use {@link _listAllWithPath} instead. */
|
|
108
|
+
const _listAllWithPrefix = async ({
|
|
65
109
|
s3Config,
|
|
66
110
|
listParams,
|
|
67
|
-
|
|
111
|
+
generatedPrefix,
|
|
68
112
|
}: ListInputArgs): Promise<ListAllOutput> => {
|
|
69
113
|
const listResult: ListOutputItem[] = [];
|
|
70
114
|
let continuationToken = listParams.ContinuationToken;
|
|
71
115
|
do {
|
|
72
|
-
const { items: pageResults, nextToken: pageNextToken } =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
116
|
+
const { items: pageResults, nextToken: pageNextToken } =
|
|
117
|
+
await _listWithPrefix({
|
|
118
|
+
generatedPrefix,
|
|
119
|
+
s3Config,
|
|
120
|
+
listParams: {
|
|
121
|
+
...listParams,
|
|
122
|
+
ContinuationToken: continuationToken,
|
|
123
|
+
MaxKeys: MAX_PAGE_SIZE,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
81
126
|
listResult.push(...pageResults);
|
|
82
127
|
continuationToken = pageNextToken;
|
|
83
128
|
} while (continuationToken);
|
|
@@ -87,10 +132,11 @@ const _listAll = async ({
|
|
|
87
132
|
};
|
|
88
133
|
};
|
|
89
134
|
|
|
90
|
-
|
|
135
|
+
/** @deprecated Use {@link _listWithPath} instead. */
|
|
136
|
+
const _listWithPrefix = async ({
|
|
91
137
|
s3Config,
|
|
92
138
|
listParams,
|
|
93
|
-
|
|
139
|
+
generatedPrefix,
|
|
94
140
|
}: ListInputArgs): Promise<ListPaginateOutput> => {
|
|
95
141
|
const listParamsClone = { ...listParams };
|
|
96
142
|
if (!listParamsClone.MaxKeys || listParamsClone.MaxKeys > MAX_PAGE_SIZE) {
|
|
@@ -112,15 +158,75 @@ const _list = async ({
|
|
|
112
158
|
};
|
|
113
159
|
}
|
|
114
160
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
161
|
+
return {
|
|
162
|
+
items: response.Contents.map(item => ({
|
|
163
|
+
key: generatedPrefix
|
|
164
|
+
? item.Key!.substring(generatedPrefix.length)
|
|
165
|
+
: item.Key!,
|
|
166
|
+
eTag: item.ETag,
|
|
167
|
+
lastModified: item.LastModified,
|
|
168
|
+
size: item.Size,
|
|
169
|
+
})),
|
|
170
|
+
nextToken: response.NextContinuationToken,
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const _listAllWithPath = async ({
|
|
175
|
+
s3Config,
|
|
176
|
+
listParams,
|
|
177
|
+
}: ListInputArgs): Promise<ListAllWithPathOutput> => {
|
|
178
|
+
const listResult: ListOutputItemWithPath[] = [];
|
|
179
|
+
let continuationToken = listParams.ContinuationToken;
|
|
180
|
+
do {
|
|
181
|
+
const { items: pageResults, nextToken: pageNextToken } =
|
|
182
|
+
await _listWithPath({
|
|
183
|
+
s3Config,
|
|
184
|
+
listParams: {
|
|
185
|
+
...listParams,
|
|
186
|
+
ContinuationToken: continuationToken,
|
|
187
|
+
MaxKeys: MAX_PAGE_SIZE,
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
listResult.push(...pageResults);
|
|
191
|
+
continuationToken = pageNextToken;
|
|
192
|
+
} while (continuationToken);
|
|
121
193
|
|
|
122
194
|
return {
|
|
123
195
|
items: listResult,
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const _listWithPath = async ({
|
|
200
|
+
s3Config,
|
|
201
|
+
listParams,
|
|
202
|
+
}: ListInputArgs): Promise<ListPaginateWithPathOutput> => {
|
|
203
|
+
const listParamsClone = { ...listParams };
|
|
204
|
+
if (!listParamsClone.MaxKeys || listParamsClone.MaxKeys > MAX_PAGE_SIZE) {
|
|
205
|
+
logger.debug(`defaulting pageSize to ${MAX_PAGE_SIZE}.`);
|
|
206
|
+
listParamsClone.MaxKeys = MAX_PAGE_SIZE;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const response: ListObjectsV2Output = await listObjectsV2(
|
|
210
|
+
{
|
|
211
|
+
...s3Config,
|
|
212
|
+
userAgentValue: getStorageUserAgentValue(StorageAction.List),
|
|
213
|
+
},
|
|
214
|
+
listParamsClone,
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
if (!response?.Contents) {
|
|
218
|
+
return {
|
|
219
|
+
items: [],
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return {
|
|
224
|
+
items: response.Contents.map(item => ({
|
|
225
|
+
path: item.Key!,
|
|
226
|
+
eTag: item.ETag,
|
|
227
|
+
lastModified: item.LastModified,
|
|
228
|
+
size: item.Size,
|
|
229
|
+
})),
|
|
124
230
|
nextToken: response.NextContinuationToken,
|
|
125
231
|
};
|
|
126
232
|
};
|
|
@@ -4,24 +4,43 @@
|
|
|
4
4
|
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
5
5
|
import { StorageAction } from '@aws-amplify/core/internals/utils';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
RemoveInput,
|
|
9
|
+
RemoveOutput,
|
|
10
|
+
RemoveWithPathInput,
|
|
11
|
+
RemoveWithPathOutput,
|
|
12
|
+
} from '../../types';
|
|
13
|
+
import {
|
|
14
|
+
resolveS3ConfigAndInput,
|
|
15
|
+
validateStorageOperationInput,
|
|
16
|
+
} from '../../utils';
|
|
9
17
|
import { deleteObject } from '../../utils/client';
|
|
10
18
|
import { getStorageUserAgentValue } from '../../utils/userAgent';
|
|
11
19
|
import { logger } from '../../../../utils';
|
|
20
|
+
import { STORAGE_INPUT_KEY } from '../../utils/constants';
|
|
12
21
|
|
|
13
22
|
export const remove = async (
|
|
14
23
|
amplify: AmplifyClassV6,
|
|
15
|
-
input: RemoveInput,
|
|
16
|
-
): Promise<RemoveOutput> => {
|
|
17
|
-
const {
|
|
18
|
-
const { s3Config, keyPrefix, bucket } =
|
|
19
|
-
amplify,
|
|
20
|
-
|
|
24
|
+
input: RemoveInput | RemoveWithPathInput,
|
|
25
|
+
): Promise<RemoveOutput | RemoveWithPathOutput> => {
|
|
26
|
+
const { options = {} } = input ?? {};
|
|
27
|
+
const { s3Config, keyPrefix, bucket, identityId } =
|
|
28
|
+
await resolveS3ConfigAndInput(amplify, options);
|
|
29
|
+
|
|
30
|
+
const { inputType, objectKey } = validateStorageOperationInput(
|
|
31
|
+
input,
|
|
32
|
+
identityId,
|
|
21
33
|
);
|
|
22
34
|
|
|
23
|
-
|
|
24
|
-
|
|
35
|
+
let finalKey;
|
|
36
|
+
if (inputType === STORAGE_INPUT_KEY) {
|
|
37
|
+
finalKey = `${keyPrefix}${objectKey}`;
|
|
38
|
+
logger.debug(`remove "${objectKey}" from "${finalKey}".`);
|
|
39
|
+
} else {
|
|
40
|
+
finalKey = objectKey;
|
|
41
|
+
logger.debug(`removing object in path "${finalKey}"`);
|
|
42
|
+
}
|
|
43
|
+
|
|
25
44
|
await deleteObject(
|
|
26
45
|
{
|
|
27
46
|
...s3Config,
|
|
@@ -33,7 +52,11 @@ export const remove = async (
|
|
|
33
52
|
},
|
|
34
53
|
);
|
|
35
54
|
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
55
|
+
return inputType === STORAGE_INPUT_KEY
|
|
56
|
+
? {
|
|
57
|
+
key: objectKey,
|
|
58
|
+
}
|
|
59
|
+
: {
|
|
60
|
+
path: objectKey,
|
|
61
|
+
};
|
|
39
62
|
};
|
|
@@ -1,41 +1,69 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
3
|
import { Amplify } from '@aws-amplify/core';
|
|
5
4
|
|
|
6
5
|
import {
|
|
7
6
|
ListAllInput,
|
|
8
7
|
ListAllOutput,
|
|
8
|
+
ListAllWithPathInput,
|
|
9
|
+
ListAllWithPathOutput,
|
|
9
10
|
ListPaginateInput,
|
|
10
11
|
ListPaginateOutput,
|
|
11
|
-
|
|
12
|
+
ListPaginateWithPathInput,
|
|
13
|
+
ListPaginateWithPathOutput,
|
|
12
14
|
} from '../types';
|
|
13
|
-
import { StorageValidationErrorCode } from '../../../errors/types/validation';
|
|
14
15
|
|
|
15
16
|
import { list as listInternal } from './internal/list';
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
/**
|
|
19
|
+
* List files in pages with the given `path`.
|
|
20
|
+
* `pageSize` is defaulted to 1000. Additionally, the result will include a `nextToken` if there are more items to retrieve.
|
|
21
|
+
* @param input - The `ListPaginateWithPathInput` object.
|
|
22
|
+
* @returns A list of objects with path and metadata
|
|
23
|
+
* @throws service: `S3Exception` - S3 service errors thrown when checking for existence of bucket
|
|
24
|
+
* @throws validation: `StorageValidationErrorCode` - thrown when there are issues with credentials
|
|
25
|
+
*/
|
|
26
|
+
export function list(
|
|
27
|
+
input: ListPaginateWithPathInput,
|
|
28
|
+
): Promise<ListPaginateWithPathOutput>;
|
|
29
|
+
/**
|
|
30
|
+
* List all files from S3 for a given `path`. You can set `listAll` to true in `options` to get all the files from S3.
|
|
31
|
+
* @param input - The `ListAllWithPathInput` object.
|
|
32
|
+
* @returns A list of all objects with path and metadata
|
|
33
|
+
* @throws service: `S3Exception` - S3 service errors thrown when checking for existence of bucket
|
|
34
|
+
* @throws validation: `StorageValidationErrorCode` - thrown when there are issues with credentials
|
|
35
|
+
*/
|
|
36
|
+
export function list(
|
|
37
|
+
input: ListAllWithPathInput,
|
|
38
|
+
): Promise<ListAllWithPathOutput>;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated The `prefix` and `accessLevel` parameters are deprecated and may be removed in the next major version.
|
|
41
|
+
* Please use {@link https://docs.amplify.aws/react/build-a-backend/storage/list | path} instead.
|
|
42
|
+
* List files in pages with the given `prefix`.
|
|
43
|
+
* `pageSize` is defaulted to 1000. Additionally, the result will include a `nextToken` if there are more items to retrieve.
|
|
44
|
+
* @param input - The `ListPaginateInput` object.
|
|
45
|
+
* @returns A list of objects with key and metadata
|
|
46
|
+
* @throws service: `S3Exception` - S3 service errors thrown when checking for existence of bucket
|
|
47
|
+
* @throws validation: `StorageValidationErrorCode` - thrown when there are issues with credentials
|
|
48
|
+
*/
|
|
49
|
+
export function list(input?: ListPaginateInput): Promise<ListPaginateOutput>;
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated The `prefix` and `accessLevel` parameters are deprecated and may be removed in the next major version.
|
|
52
|
+
* Please use {@link https://docs.amplify.aws/react/build-a-backend/storage/list | path} instead.
|
|
53
|
+
* List all files from S3 for a given `prefix`. You can set `listAll` to true in `options` to get all the files from S3.
|
|
54
|
+
* @param input - The `ListAllInput` object.
|
|
55
|
+
* @returns A list of all objects with key and metadata
|
|
56
|
+
* @throws service: `S3Exception` - S3 service errors thrown when checking for existence of bucket
|
|
57
|
+
* @throws validation: `StorageValidationErrorCode` - thrown when there are issues with credentials
|
|
58
|
+
*/
|
|
59
|
+
export function list(input?: ListAllInput): Promise<ListAllOutput>;
|
|
36
60
|
|
|
37
|
-
export
|
|
38
|
-
input?:
|
|
39
|
-
|
|
61
|
+
export function list(
|
|
62
|
+
input?:
|
|
63
|
+
| ListAllInput
|
|
64
|
+
| ListPaginateInput
|
|
65
|
+
| ListAllWithPathInput
|
|
66
|
+
| ListPaginateWithPathInput,
|
|
67
|
+
) {
|
|
40
68
|
return listInternal(Amplify, input ?? {});
|
|
41
|
-
}
|
|
69
|
+
}
|
|
@@ -3,18 +3,39 @@
|
|
|
3
3
|
|
|
4
4
|
import { Amplify } from '@aws-amplify/core';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
RemoveInput,
|
|
8
|
+
RemoveOutput,
|
|
9
|
+
RemoveWithPathInput,
|
|
10
|
+
RemoveWithPathOutput,
|
|
11
|
+
} from '../types';
|
|
8
12
|
|
|
9
13
|
import { remove as removeInternal } from './internal/remove';
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
16
|
* Remove a file from your S3 bucket.
|
|
13
|
-
* @param input - The
|
|
17
|
+
* @param input - The `RemoveWithPathInput` object.
|
|
18
|
+
* @return Output containing the removed object path.
|
|
19
|
+
* @throws service: `S3Exception` - S3 service errors thrown while while removing the object.
|
|
20
|
+
* @throws validation: `StorageValidationErrorCode` - Validation errors thrown
|
|
21
|
+
* when there is no path or path is empty or path has a leading slash.
|
|
22
|
+
*/
|
|
23
|
+
export function remove(
|
|
24
|
+
input: RemoveWithPathInput,
|
|
25
|
+
): Promise<RemoveWithPathOutput>;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
|
|
28
|
+
* Please use {@link https://docs.amplify.aws/react/build-a-backend/storage/remove | path} instead.
|
|
29
|
+
*
|
|
30
|
+
* Remove a file from your S3 bucket.
|
|
31
|
+
* @param input - The `RemoveInput` object.
|
|
14
32
|
* @return Output containing the removed object key
|
|
15
|
-
* @throws service:
|
|
16
|
-
* @throws validation:
|
|
33
|
+
* @throws service: `S3Exception` - S3 service errors thrown while while removing the object
|
|
34
|
+
* @throws validation: `StorageValidationErrorCode` - Validation errors thrown
|
|
35
|
+
* when there is no key or its empty.
|
|
17
36
|
*/
|
|
18
|
-
export
|
|
37
|
+
export function remove(input: RemoveInput): Promise<RemoveOutput>;
|
|
38
|
+
|
|
39
|
+
export function remove(input: RemoveInput | RemoveWithPathInput) {
|
|
19
40
|
return removeInternal(Amplify, input);
|
|
20
|
-
}
|
|
41
|
+
}
|
|
@@ -1,17 +1,54 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
3
|
import {
|
|
5
4
|
AmplifyServer,
|
|
6
5
|
getAmplifyServerContext,
|
|
7
6
|
} from '@aws-amplify/core/internals/adapter-core';
|
|
8
7
|
|
|
9
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
CopyInput,
|
|
10
|
+
CopyOutput,
|
|
11
|
+
CopyWithPathInput,
|
|
12
|
+
CopyWithPathOutput,
|
|
13
|
+
} from '../../types';
|
|
10
14
|
import { copy as copyInternal } from '../internal/copy';
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Copy an object from a source to a destination object within the same bucket.
|
|
18
|
+
*
|
|
19
|
+
* @param contextSpec - The isolated server context.
|
|
20
|
+
* @param input - The `CopyWithPathInput` object.
|
|
21
|
+
* @returns Output containing the destination object path.
|
|
22
|
+
* @throws service: `S3Exception` - Thrown when checking for existence of the object
|
|
23
|
+
* @throws validation: `StorageValidationErrorCode` - Thrown when
|
|
24
|
+
* source or destination path is not defined.
|
|
25
|
+
*/
|
|
26
|
+
export function copy(
|
|
27
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
28
|
+
input: CopyWithPathInput,
|
|
29
|
+
): Promise<CopyWithPathOutput>;
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
|
|
32
|
+
* Please use {@link https://docs.amplify.aws/react/build-a-backend/storage/copy | path} instead.
|
|
33
|
+
*
|
|
34
|
+
* Copy an object from a source to a destination object within the same bucket. Can optionally copy files across
|
|
35
|
+
* different accessLevel or identityId (if source object's accessLevel is 'protected').
|
|
36
|
+
*
|
|
37
|
+
* @param contextSpec - The isolated server context.
|
|
38
|
+
* @param input - The `CopyInput` object.
|
|
39
|
+
* @returns Output containing the destination object key.
|
|
40
|
+
* @throws service: `S3Exception` - Thrown when checking for existence of the object
|
|
41
|
+
* @throws validation: `StorageValidationErrorCode` - Thrown when
|
|
42
|
+
* source or destination key is not defined.
|
|
43
|
+
*/
|
|
44
|
+
export function copy(
|
|
13
45
|
contextSpec: AmplifyServer.ContextSpec,
|
|
14
46
|
input: CopyInput,
|
|
15
|
-
): Promise<CopyOutput
|
|
47
|
+
): Promise<CopyOutput>;
|
|
48
|
+
|
|
49
|
+
export function copy(
|
|
50
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
51
|
+
input: CopyInput | CopyWithPathInput,
|
|
52
|
+
) {
|
|
16
53
|
return copyInternal(getAmplifyServerContext(contextSpec).amplify, input);
|
|
17
|
-
}
|
|
54
|
+
}
|
|
@@ -6,15 +6,52 @@ import {
|
|
|
6
6
|
getAmplifyServerContext,
|
|
7
7
|
} from '@aws-amplify/core/internals/adapter-core';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
GetPropertiesInput,
|
|
11
|
+
GetPropertiesOutput,
|
|
12
|
+
GetPropertiesWithPathInput,
|
|
13
|
+
GetPropertiesWithPathOutput,
|
|
14
|
+
} from '../../types';
|
|
10
15
|
import { getProperties as getPropertiesInternal } from '../internal/getProperties';
|
|
11
16
|
|
|
12
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Gets the properties of a file. The properties include S3 system metadata and
|
|
19
|
+
* the user metadata that was provided when uploading the file.
|
|
20
|
+
*
|
|
21
|
+
* @param contextSpec - The isolated server context.
|
|
22
|
+
* @param input - The `GetPropertiesWithPathInput` object.
|
|
23
|
+
* @returns Requested object properties.
|
|
24
|
+
* @throws An `S3Exception` when the underlying S3 service returned error.
|
|
25
|
+
* @throws A `StorageValidationErrorCode` when API call parameters are invalid.
|
|
26
|
+
*/
|
|
27
|
+
export function getProperties(
|
|
28
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
29
|
+
input: GetPropertiesWithPathInput,
|
|
30
|
+
): Promise<GetPropertiesWithPathOutput>;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
|
|
33
|
+
* Please use {@link https://docs.amplify.aws/javascript/build-a-backend/storage/get-properties/ | path} instead.
|
|
34
|
+
*
|
|
35
|
+
* Gets the properties of a file. The properties include S3 system metadata and
|
|
36
|
+
* the user metadata that was provided when uploading the file.
|
|
37
|
+
*
|
|
38
|
+
* @param contextSpec - The isolated server context.
|
|
39
|
+
* @param input - The `GetPropertiesInput` object.
|
|
40
|
+
* @returns Requested object properties.
|
|
41
|
+
* @throws An `S3Exception` when the underlying S3 service returned error.
|
|
42
|
+
* @throws A `StorageValidationErrorCode` when API call parameters are invalid.
|
|
43
|
+
*/
|
|
44
|
+
export function getProperties(
|
|
13
45
|
contextSpec: AmplifyServer.ContextSpec,
|
|
14
46
|
input: GetPropertiesInput,
|
|
15
|
-
): Promise<GetPropertiesOutput
|
|
47
|
+
): Promise<GetPropertiesOutput>;
|
|
48
|
+
|
|
49
|
+
export function getProperties(
|
|
50
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
51
|
+
input: GetPropertiesInput | GetPropertiesWithPathInput,
|
|
52
|
+
) {
|
|
16
53
|
return getPropertiesInternal(
|
|
17
54
|
getAmplifyServerContext(contextSpec).amplify,
|
|
18
55
|
input,
|
|
19
56
|
);
|
|
20
|
-
}
|
|
57
|
+
}
|
|
@@ -6,12 +6,63 @@ import {
|
|
|
6
6
|
getAmplifyServerContext,
|
|
7
7
|
} from '@aws-amplify/core/internals/adapter-core';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
GetUrlInput,
|
|
11
|
+
GetUrlOutput,
|
|
12
|
+
GetUrlWithPathInput,
|
|
13
|
+
GetUrlWithPathOutput,
|
|
14
|
+
} from '../../types';
|
|
10
15
|
import { getUrl as getUrlInternal } from '../internal/getUrl';
|
|
11
16
|
|
|
12
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Get a temporary presigned URL to download the specified S3 object.
|
|
19
|
+
* The presigned URL expires when the associated role used to sign the request expires or
|
|
20
|
+
* the option `expiresIn` is reached. The `expiresAt` property in the output object indicates when the URL MAY expire.
|
|
21
|
+
*
|
|
22
|
+
* By default, it will not validate the object that exists in S3. If you set the `options.validateObjectExistence`
|
|
23
|
+
* to true, this method will verify the given object already exists in S3 before returning a presigned
|
|
24
|
+
* URL, and will throw `StorageError` if the object does not exist.
|
|
25
|
+
*
|
|
26
|
+
* @param contextSpec - The isolated server context.
|
|
27
|
+
* @param input - The `GetUrlWithPathInput` object.
|
|
28
|
+
* @returns Presigned URL and timestamp when the URL may expire.
|
|
29
|
+
* @throws service: `S3Exception` - thrown when checking for existence of the object
|
|
30
|
+
* @throws validation: `StorageValidationErrorCode` - Validation errors
|
|
31
|
+
* thrown either username or key are not defined.
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
export function getUrl(
|
|
35
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
36
|
+
input: GetUrlWithPathInput,
|
|
37
|
+
): Promise<GetUrlWithPathOutput>;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
|
|
40
|
+
* Please use {@link https://docs.amplify.aws/javascript/build-a-backend/storage/download/#generate-a-download-url | path} instead.
|
|
41
|
+
*
|
|
42
|
+
* Get a temporary presigned URL to download the specified S3 object.
|
|
43
|
+
* The presigned URL expires when the associated role used to sign the request expires or
|
|
44
|
+
* the option `expiresIn` is reached. The `expiresAt` property in the output object indicates when the URL MAY expire.
|
|
45
|
+
*
|
|
46
|
+
* By default, it will not validate the object that exists in S3. If you set the `options.validateObjectExistence`
|
|
47
|
+
* to true, this method will verify the given object already exists in S3 before returning a presigned
|
|
48
|
+
* URL, and will throw `StorageError` if the object does not exist.
|
|
49
|
+
*
|
|
50
|
+
* @param contextSpec - The isolated server context.
|
|
51
|
+
* @param input - The `GetUrlInput` object.
|
|
52
|
+
* @returns Presigned URL and timestamp when the URL may expire.
|
|
53
|
+
* @throws service: `S3Exception` - thrown when checking for existence of the object
|
|
54
|
+
* @throws validation: `StorageValidationErrorCode` - Validation errors
|
|
55
|
+
* thrown either username or key are not defined.
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
export function getUrl(
|
|
13
59
|
contextSpec: AmplifyServer.ContextSpec,
|
|
14
60
|
input: GetUrlInput,
|
|
15
|
-
): Promise<GetUrlOutput
|
|
61
|
+
): Promise<GetUrlOutput>;
|
|
62
|
+
|
|
63
|
+
export function getUrl(
|
|
64
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
65
|
+
input: GetUrlInput | GetUrlWithPathInput,
|
|
66
|
+
) {
|
|
16
67
|
return getUrlInternal(getAmplifyServerContext(contextSpec).amplify, input);
|
|
17
|
-
}
|
|
68
|
+
}
|