UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

1 lines 2.37 kB
{"version":3,"file":"validateStorageOperationInputWithPrefix.mjs","sources":["../../../../../src/providers/s3/utils/validateStorageOperationInputWithPrefix.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { assertValidationError } from '../../../errors/utils/assertValidationError';\nimport { StorageValidationErrorCode } from '../../../errors/types/validation';\nimport { STORAGE_INPUT_PATH, STORAGE_INPUT_PREFIX } from './constants';\nimport { resolveIdentityId } from './resolveIdentityId';\n// Local assertion function with StorageOperationInputWithPrefixPath as Input\nconst _isInputWithPath = (input) => {\n return input.path !== undefined;\n};\nexport const validateStorageOperationInputWithPrefix = (input, identityId) => {\n // Validate prefix & path not present at the same time\n assertValidationError(!(input.prefix && input.path), StorageValidationErrorCode.InvalidStorageOperationPrefixInput);\n if (_isInputWithPath(input)) {\n const { path } = input;\n const objectKey = typeof path === 'string'\n ? path\n : path({ identityId: resolveIdentityId(identityId) });\n // Assert on no leading slash in the path parameter\n assertValidationError(!objectKey.startsWith('/'), StorageValidationErrorCode.InvalidStoragePathInput);\n return {\n inputType: STORAGE_INPUT_PATH,\n objectKey,\n };\n }\n else {\n return { inputType: STORAGE_INPUT_PREFIX, objectKey: input.prefix ?? '' };\n }\n};\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAKA;AACA,MAAM,gBAAgB,GAAG,CAAC,KAAK,KAAK;AACpC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,SAAS;AACnC,CAAC;AACW,MAAC,uCAAuC,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK;AAC9E;AACA,IAAI,qBAAqB,CAAC,EAAE,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,0BAA0B,CAAC,kCAAkC,CAAC;AACvH,IAAI,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE;AACjC,QAAQ,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK;AAC9B,QAAQ,MAAM,SAAS,GAAG,OAAO,IAAI,KAAK;AAC1C,cAAc;AACd,cAAc,IAAI,CAAC,EAAE,UAAU,EAAE,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;AACjE;AACA,QAAQ,qBAAqB,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,0BAA0B,CAAC,uBAAuB,CAAC;AAC7G,QAAQ,OAAO;AACf,YAAY,SAAS,EAAE,kBAAkB;AACzC,YAAY,SAAS;AACrB,SAAS;AACT;AACA,SAAS;AACT,QAAQ,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,IAAI,EAAE,EAAE;AACjF;AACA;;;;"}