Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(storage): extract isInputWithPath into separate file #13114

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { isInputWithPath } from '../../../../../src/providers/s3/utils';

describe('isInputWithPath', () => {
it('should return true if input contains path', async () => {
expect(isInputWithPath({ path: '' })).toBe(true);
});
it('should return false if input does not contain path', async () => {
expect(isInputWithPath({ key: '' })).toBe(false);
});
});
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { calculateContentMd5 } from './md5';
export { resolveS3ConfigAndInput } from './resolveS3ConfigAndInput';
export { createDownloadTask, createUploadTask } from './transferTask';
export { validateStorageOperationInput } from './validateStorageOperationInput';
export { isInputWithPath } from './isInputWithPath';
13 changes: 13 additions & 0 deletions packages/storage/src/providers/s3/utils/isInputWithPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import {
StorageOperationInputPath,
StorageOperationInputType,
} from '../../../types/inputs';

export const isInputWithPath = (
input: StorageOperationInputType,
): input is StorageOperationInputPath => {
return input.path !== undefined;
};
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { StrictUnion } from '@aws-amplify/core/internals/utils';

import {
StorageOperationInputKey,
StorageOperationInputPath,
} from '../../../types/inputs';
import { StorageOperationInputType as Input } from '../../../types/inputs';
import { assertValidationError } from '../../../errors/utils/assertValidationError';
import { StorageValidationErrorCode } from '../../../errors/types/validation';

import { isInputWithPath } from './isInputWithPath';
import { STORAGE_INPUT_KEY, STORAGE_INPUT_PATH } from './constants';

type Input = StrictUnion<StorageOperationInputKey | StorageOperationInputPath>;

const isInputWithPath = (input: Input): input is StorageOperationInputPath => {
return input.path !== undefined;
};

export const validateStorageOperationInput = (
input: Input,
identityId?: string,
Expand Down
8 changes: 8 additions & 0 deletions packages/storage/src/types/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { StrictUnion } from '@aws-amplify/core/internals/utils';

import {
StorageListAllOptions,
StorageListPaginateOptions,
StorageOptions,
} from './options';

// TODO: rename to StorageOperationInput once the other type with
// the same named is removed
export type StorageOperationInputType = StrictUnion<
StorageOperationInputKey | StorageOperationInputPath
>;

/** @deprecated Use {@link StorageOperationInputPath} instead. */
export interface StorageOperationInputKey {
/** @deprecated Use `path` instead. */
Expand Down
Loading