Skip to content

Commit

Permalink
chore(storage): enable eslint and remove tslint (#13004)
Browse files Browse the repository at this point in the history
* chore(storage): enable eslint and remove tslint

* chore(storage): run yarn lint:fix

* chore(storage): manual fix of linter reported errors

* chore(storage): re-baseline jest statements coverage threshold
  • Loading branch information
HuiSF authored Feb 16, 2024
1 parent 29c8d60 commit 0d2aa5d
Show file tree
Hide file tree
Showing 67 changed files with 369 additions and 282 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = {
'packages/react-native',
'packages/rtn-push-notification',
'packages/rtn-web-browser',
'packages/storage',
// 'packages/storage',
],
rules: {
camelcase: [
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
branches: 75,
functions: 80,
lines: 81,
statements: 91,
statements: 90,
},
},
};
3 changes: 2 additions & 1 deletion packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"clean": "npm run clean:size && rimraf lib-esm lib dist",
"clean:size": "rimraf dual-publish-tmp tmp*",
"format": "echo \"Not implemented\"",
"lint": "tslint 'src/**/*.ts' && npm run ts-coverage",
"lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
"lint:fix": "eslint '**/*.{ts,tsx}' --fix",
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
},
"typesVersions": {
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/errors/CanceledError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

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

import { StorageError } from './StorageError';

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/storage/src/providers/s3/apis/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// SPDX-License-Identifier: Apache-2.0

import { Amplify } from '@aws-amplify/core';

import { CopyInput, CopyOutput, S3Exception } from '../types';
import { copy as copyInternal } from './internal/copy';
import { StorageValidationErrorCode } from '../../../errors/types/validation';

import { copy as copyInternal } from './internal/copy';

/**
* Copy an object from a source object to a new object within the same bucket. Can optionally copy files across
* different level or identityId (if source object's level is 'protected').
Expand Down
2 changes: 2 additions & 0 deletions packages/storage/src/providers/s3/apis/downloadData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const downloadData = (input: DownloadDataInput): DownloadDataOutput => {
abortController.abort(message);
},
});

return downloadTask;
};

Expand Down Expand Up @@ -91,6 +92,7 @@ const downloadDataJob =
}),
},
);

return {
key,
body,
Expand Down
5 changes: 4 additions & 1 deletion packages/storage/src/providers/s3/apis/getProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// SPDX-License-Identifier: Apache-2.0

import { Amplify } from '@aws-amplify/core';
import { GetPropertiesOutput, GetPropertiesInput, S3Exception } from '../types';

import { GetPropertiesInput, GetPropertiesOutput, S3Exception } from '../types';
import { StorageValidationErrorCode } from '../../../errors/types/validation';

import { getProperties as getPropertiesInternal } from './internal/getProperties';

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/storage/src/providers/s3/apis/getUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
// SPDX-License-Identifier: Apache-2.0

import { Amplify } from '@aws-amplify/core';

import { StorageValidationErrorCode } from '../../../errors/types/validation';
import { GetUrlInput, GetUrlOutput, S3Exception } from '../types';
import { StorageError } from '../../../errors/StorageError';

import { getUrl as getUrlInternal } from './internal/getUrl';

/**
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/internal/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

import { CopyInput, CopyOutput } from '../../types';
import { resolveS3ConfigAndInput } from '../../utils';
import { StorageValidationErrorCode } from '../../../../errors/types/validation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@

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

import { GetPropertiesInput, GetPropertiesOutput } from '../../types';
import { resolveS3ConfigAndInput } from '../../utils';
import { headObject } from '../../utils/client';
import { getStorageUserAgentValue } from '../../utils/userAgent';
import { logger } from '../../../../utils';

export const getProperties = async function (
export const getProperties = async (
amplify: AmplifyClassV6,
input: GetPropertiesInput,
action?: StorageAction,
): Promise<GetPropertiesOutput> {
): Promise<GetPropertiesOutput> => {
const { key, options } = input;
const { s3Config, bucket, keyPrefix } = await resolveS3ConfigAndInput(
amplify,
Expand All @@ -34,6 +35,7 @@ export const getProperties = async function (
Key: finalKey,
},
);

return {
key,
contentType: response.ContentType,
Expand Down
10 changes: 6 additions & 4 deletions packages/storage/src/providers/s3/apis/internal/getUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
// SPDX-License-Identifier: Apache-2.0

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

import { GetUrlInput, GetUrlOutput } from '../../types';
import { StorageValidationErrorCode } from '../../../../errors/types/validation';
import { getPresignedGetObjectUrl } from '../../utils/client';
import { getProperties } from './getProperties';
import { resolveS3ConfigAndInput } from '../../utils';
import { assertValidationError } from '../../../../errors/utils/assertValidationError';
import {
DEFAULT_PRESIGN_EXPIRATION,
MAX_URL_EXPIRATION,
} from '../../utils/constants';
import { StorageAction } from '@aws-amplify/core/internals/utils';

export const getUrl = async function (
import { getProperties } from './getProperties';

export const getUrl = async (
amplify: AmplifyClassV6,
input: GetUrlInput,
): Promise<GetUrlOutput> {
): Promise<GetUrlOutput> => {
const { key, options } = input;

if (options?.validateObjectExistence) {
Expand Down
17 changes: 10 additions & 7 deletions packages/storage/src/providers/s3/apis/internal/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@

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

import {
ListAllInput,
ListPaginateInput,
ListAllOutput,
ListPaginateOutput,
ListOutputItem,
ListPaginateInput,
ListPaginateOutput,
} from '../../types';
import { resolveS3ConfigAndInput } from '../../utils';
import { ResolvedS3Config } from '../../types/options';
import {
listObjectsV2,
ListObjectsV2Input,
ListObjectsV2Output,
listObjectsV2,
} from '../../utils/client';
import { getStorageUserAgentValue } from '../../utils/userAgent';
import { logger } from '../../../../utils';

const MAX_PAGE_SIZE = 1000;

type ListInputArgs = {
interface ListInputArgs {
s3Config: ResolvedS3Config;
listParams: ListObjectsV2Input;
prefix: string;
};
}

export const list = async (
amplify: AmplifyClassV6,
Expand Down Expand Up @@ -54,9 +55,10 @@ export const list = async (
ContinuationToken: options?.listAll ? undefined : options?.nextToken,
};
logger.debug(`listing items from "${listParams.Prefix}"`);

return options.listAll
? await _listAll({ s3Config, listParams, prefix })
: await _list({ s3Config, listParams, prefix });
? _listAll({ s3Config, listParams, prefix })
: _list({ s3Config, listParams, prefix });
};

const _listAll = async ({
Expand Down Expand Up @@ -116,6 +118,7 @@ const _list = async ({
lastModified: item.LastModified,
size: item.Size,
}));

return {
items: listResult,
nextToken: response.NextContinuationToken,
Expand Down
2 changes: 2 additions & 0 deletions packages/storage/src/providers/s3/apis/internal/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

import { RemoveInput, RemoveOutput } from '../../types';
import { resolveS3ConfigAndInput } from '../../utils';
import { deleteObject } from '../../utils/client';
Expand Down Expand Up @@ -31,6 +32,7 @@ export const remove = async (
Key: finalKey,
},
);

return {
key,
};
Expand Down
10 changes: 7 additions & 3 deletions packages/storage/src/providers/s3/apis/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
// SPDX-License-Identifier: Apache-2.0

import { Amplify } from '@aws-amplify/core';

import {
ListAllInput,
ListPaginateInput,
ListAllOutput,
ListPaginateInput,
ListPaginateOutput,
S3Exception,
} from '../types';
import { StorageValidationErrorCode } from '../../../errors/types/validation';

import { list as listInternal } from './internal/list';

type ListApi = {
interface ListApi {
/**
* List files with given prefix in pages
* pageSize defaulted to 1000. Additionally, the result will include a nextToken if there are more items to retrieve.
Expand All @@ -28,7 +32,7 @@ type ListApi = {
* @throws validation: {@link StorageValidationErrorCode } - thrown when there are issues with credentials
*/
(input?: ListAllInput): Promise<ListAllOutput>;
};
}

export const list: ListApi = (
input?: ListAllInput | ListPaginateInput,
Expand Down
5 changes: 4 additions & 1 deletion packages/storage/src/providers/s3/apis/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// SPDX-License-Identifier: Apache-2.0

import { Amplify } from '@aws-amplify/core';
import { RemoveInput, RemoveOutput } from '../types';

import { RemoveInput, RemoveOutput, S3Exception } from '../types';
import { StorageValidationErrorCode } from '../../../errors/types/validation';

import { remove as removeInternal } from './internal/remove';

/**
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/server/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AmplifyServer,
getAmplifyServerContext,
} from '@aws-amplify/core/internals/adapter-core';

import { CopyInput, CopyOutput } from '../../types';
import { copy as copyInternal } from '../internal/copy';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AmplifyServer,
getAmplifyServerContext,
} from '@aws-amplify/core/internals/adapter-core';

import { GetPropertiesInput, GetPropertiesOutput } from '../../types';
import { getProperties as getPropertiesInternal } from '../internal/getProperties';

Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/server/getUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AmplifyServer,
getAmplifyServerContext,
} from '@aws-amplify/core/internals/adapter-core';

import { GetUrlInput, GetUrlOutput } from '../../types';
import { getUrl as getUrlInternal } from '../internal/getUrl';

Expand Down
9 changes: 6 additions & 3 deletions packages/storage/src/providers/s3/apis/server/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import {
AmplifyServer,
getAmplifyServerContext,
} from '@aws-amplify/core/internals/adapter-core';

import {
ListAllInput,
ListPaginateInput,
ListAllOutput,
ListPaginateInput,
ListPaginateOutput,
S3Exception,
} from '../../types';
import { list as listInternal } from '../internal/list';
import { StorageValidationErrorCode } from '../../../../errors/types/validation';

type ListApi = {
interface ListApi {
/**
* Lists bucket objects with pagination.
* @param {ListPaginateInput} The input object
Expand All @@ -37,7 +40,7 @@ type ListApi = {
contextSpec: AmplifyServer.ContextSpec,
input?: ListAllInput,
): Promise<ListAllOutput>;
};
}

export const list: ListApi = (
contextSpec: AmplifyServer.ContextSpec,
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/server/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AmplifyServer,
getAmplifyServerContext,
} from '@aws-amplify/core/internals/adapter-core';

import { RemoveInput, RemoveOutput } from '../../types';
import { remove as removeInternal } from '../internal/remove';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const byteLength = (input?: any): number | undefined => {
// handles browser File object
return input.size;
}

// TODO: support Node.js stream size when Node.js runtime is supported out-of-box.
return undefined;
};
5 changes: 4 additions & 1 deletion packages/storage/src/providers/s3/apis/uploadData/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { UploadDataInput, UploadDataOutput, S3Exception } from '../../types';
import { S3Exception, UploadDataInput, UploadDataOutput } from '../../types';
import { createUploadTask } from '../../utils';
import { assertValidationError } from '../../../../errors/utils/assertValidationError';
import { StorageValidationErrorCode } from '../../../../errors/types/validation';
import { DEFAULT_PART_SIZE, MAX_OBJECT_SIZE } from '../../utils/constants';

import { byteLength } from './byteLength';
import { putObjectJob } from './putObjectJob';
import { getMultipartUploadHandlers } from './multipart';
Expand Down Expand Up @@ -69,6 +70,7 @@ export const uploadData = (input: UploadDataInput): UploadDataOutput => {

if (dataByteLength && dataByteLength <= DEFAULT_PART_SIZE) {
const abortController = new AbortController();

return createUploadTask({
isMultipartUpload: false,
job: putObjectJob(input, abortController.signal, dataByteLength),
Expand All @@ -79,6 +81,7 @@ export const uploadData = (input: UploadDataInput): UploadDataOutput => {
} else {
const { multipartUploadJob, onPause, onResume, onCancel } =
getMultipartUploadHandlers(input, dataByteLength);

return createUploadTask({
isMultipartUpload: true,
job: multipartUploadJob,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export const calculatePartSize = (totalSize?: number): number => {
partSize *= 2;
partsCount = Math.ceil(totalSize / partSize);
}

return partSize;
};
Loading

0 comments on commit 0d2aa5d

Please sign in to comment.