1 | import { assertValidationError } from '../../../errors/utils/assertValidationError.mjs';
|
2 | import { StorageValidationErrorCode } from '../../../errors/types/validation.mjs';
|
3 | import { isInputWithPath } from './isInputWithPath.mjs';
|
4 | import { STORAGE_INPUT_PATH, STORAGE_INPUT_KEY } from './constants.mjs';
|
5 |
|
6 |
|
7 |
|
8 | const validateStorageOperationInput = (input, identityId) => {
|
9 | assertValidationError(
|
10 |
|
11 | (!!input.key && !input.path) ||
|
12 |
|
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 |
|
28 | export { validateStorageOperationInput };
|
29 |
|