Skip to content

Commit

Permalink
chore(storage): extract isInputWithPath into separate file (#13114)
Browse files Browse the repository at this point in the history
* fix: extract isInputWithPath into separate file

* chore: add unit test

* Update packages/storage/__tests__/providers/s3/apis/utils/isInputWithPath.test.ts

Co-authored-by: ashika112 <155593080+ashika112@users.noreply.github.com>

* Update packages/storage/__tests__/providers/s3/apis/utils/isInputWithPath.test.ts

* address feedback

---------

Co-authored-by: Ashwin Kumar <ashwsrir@amazon.com>
Co-authored-by: ashika112 <155593080+ashika112@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 13, 2024
1 parent e882c68 commit 1a1e0f4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
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

0 comments on commit 1a1e0f4

Please sign in to comment.