UNPKG

1.26 kBJavaScriptView Raw
1import { assertValidationError } from '../../../errors/utils/assertValidationError.mjs';
2import { StorageValidationErrorCode } from '../../../errors/types/validation.mjs';
3import { isInputWithPath } from './isInputWithPath.mjs';
4import { STORAGE_INPUT_PATH, STORAGE_INPUT_KEY } from './constants.mjs';
5
6// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7// SPDX-License-Identifier: Apache-2.0
8const validateStorageOperationInput = (input, identityId) => {
9 assertValidationError(
10 // Key present without a path
11 (!!input.key && !input.path) ||
12 // Path present without a key
13 (!input.key && !!input.path), StorageValidationErrorCode.InvalidStorageOperationInput);
14 if (isInputWithPath(input)) {
15 const { path } = input;
16 const objectKey = typeof path === 'string' ? path : path({ identityId });
17 assertValidationError(!objectKey.startsWith('/'), StorageValidationErrorCode.InvalidStoragePathInput);
18 return {
19 inputType: STORAGE_INPUT_PATH,
20 objectKey,
21 };
22 }
23 else {
24 return { inputType: STORAGE_INPUT_KEY, objectKey: input.key };
25 }
26};
27
28export { validateStorageOperationInput };
29//# sourceMappingURL=validateStorageOperationInput.mjs.map