diff --git a/.eslintrc.js b/.eslintrc.js index f89f86e7765..1b77b469b46 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -40,9 +40,9 @@ module.exports = { // will enable lint by packages // 'adapter-nextjs', // 'packages/analytics', - 'packages/api', + // 'packages/api', 'packages/api-graphql', - 'packages/api-rest', + // 'packages/api-rest', 'packages/auth', // 'packages/aws-amplify', // 'packages/core', diff --git a/packages/api-rest/package.json b/packages/api-rest/package.json index b28363f49e6..e2799f16230 100644 --- a/packages/api-rest/package.json +++ b/packages/api-rest/package.json @@ -21,7 +21,8 @@ "clean": "npm run clean:size && rimraf dist lib lib-esm", "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 70.0" }, "exports": { diff --git a/packages/api-rest/src/apis/common/handler.ts b/packages/api-rest/src/apis/common/handler.ts index 45556f70a8a..9ae021e4e4e 100644 --- a/packages/api-rest/src/apis/common/handler.ts +++ b/packages/api-rest/src/apis/common/handler.ts @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 import { AmplifyClassV6 } from '@aws-amplify/core'; import { - HttpRequest, - unauthenticatedHandler, Headers, + HttpRequest, + authenticatedHandler, getRetryDecider, jitteredBackoff, - authenticatedHandler, + unauthenticatedHandler, } from '@aws-amplify/core/internals/aws-client-utils'; import { AWSCredentials, @@ -28,10 +28,10 @@ type HandlerOptions = Omit & { withCredentials?: boolean; }; -type SigningServiceInfo = { +interface SigningServiceInfo { service?: string; region?: string; -}; +} /** * Make REST API call with best-effort IAM auth. @@ -46,7 +46,7 @@ type SigningServiceInfo = { export const transferHandler = async ( amplify: AmplifyClassV6, options: HandlerOptions & { abortSignal: AbortSignal }, - signingServiceInfo?: SigningServiceInfo + signingServiceInfo?: SigningServiceInfo, ): Promise => { const { url, method, headers, body, withCredentials, abortSignal } = options; const resolvedBody = body @@ -88,6 +88,7 @@ export const transferHandler = async ( ...baseOptions, }); } + // Clean-up un-modeled properties from response. return { statusCode: response.statusCode, @@ -98,11 +99,11 @@ export const transferHandler = async ( const iamAuthApplicable = ( { headers }: HttpRequest, - signingServiceInfo?: SigningServiceInfo + signingServiceInfo?: SigningServiceInfo, ) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo; const resolveCredentials = async ( - amplify: AmplifyClassV6 + amplify: AmplifyClassV6, ): Promise => { try { const { credentials } = await amplify.Auth.fetchAuthSession(); @@ -112,5 +113,6 @@ const resolveCredentials = async ( } catch (e) { logger.debug('No credentials available, the request will be unsigned.'); } + return null; }; diff --git a/packages/api-rest/src/apis/common/internalPost.ts b/packages/api-rest/src/apis/common/internalPost.ts index 187e54184a5..4f7a6ccc416 100644 --- a/packages/api-rest/src/apis/common/internalPost.ts +++ b/packages/api-rest/src/apis/common/internalPost.ts @@ -4,9 +4,10 @@ import { AmplifyClassV6 } from '@aws-amplify/core'; import { InternalPostInput, RestApiResponse } from '../../types'; -import { transferHandler } from './handler'; import { createCancellableOperation } from '../../utils'; +import { transferHandler } from './handler'; + /** * This weak map provides functionality to cancel a request given the promise containing the `post` request. * @@ -25,7 +26,7 @@ const cancelTokenMap = new WeakMap, AbortController>(); */ export const post = ( amplify: AmplifyClassV6, - { url, options, abortController }: InternalPostInput + { url, options, abortController }: InternalPostInput, ): Promise => { const controller = abortController ?? new AbortController(); const responsePromise = createCancellableOperation(async () => { @@ -37,14 +38,16 @@ export const post = ( ...options, abortSignal: controller.signal, }, - options?.signingServiceInfo + options?.signingServiceInfo, ); + return response; }, controller); const responseWithCleanUp = responsePromise.finally(() => { cancelTokenMap.delete(responseWithCleanUp); }); + return responseWithCleanUp; }; @@ -55,7 +58,7 @@ export const post = ( */ export const cancel = ( promise: Promise, - message?: string + message?: string, ): boolean => { const controller = cancelTokenMap.get(promise); if (controller) { @@ -63,10 +66,12 @@ export const cancel = ( if (message && controller.signal.reason !== message) { // In runtimes where `AbortSignal.reason` is not supported, we track the reason ourselves. // @ts-expect-error reason is read-only property. - controller.signal['reason'] = message; + controller.signal.reason = message; } + return true; } + return false; }; @@ -75,7 +80,7 @@ export const cancel = ( */ export const updateRequestToBeCancellable = ( promise: Promise, - controller: AbortController + controller: AbortController, ) => { cancelTokenMap.set(promise, controller); }; diff --git a/packages/api-rest/src/apis/common/publicApis.ts b/packages/api-rest/src/apis/common/publicApis.ts index 1034f77b811..6a132a6b277 100644 --- a/packages/api-rest/src/apis/common/publicApis.ts +++ b/packages/api-rest/src/apis/common/publicApis.ts @@ -2,34 +2,36 @@ // SPDX-License-Identifier: Apache-2.0 import { AmplifyClassV6 } from '@aws-amplify/core'; + import { - GetInput, - GetOperation, - PostInput, - PostOperation, - PutInput, - PutOperation, + ApiInput, DeleteInput, DeleteOperation, + GetInput, + GetOperation, HeadInput, HeadOperation, PatchInput, PatchOperation, - ApiInput, + PostInput, + PostOperation, + PutInput, + PutOperation, RestApiOptionsBase, } from '../../types'; import { - resolveApiUrl, createCancellableOperation, logger, parseSigningInfo, + resolveApiUrl, } from '../../utils'; + import { transferHandler } from './handler'; const publicHandler = ( amplify: AmplifyClassV6, options: ApiInput, - method: string + method: string, ) => createCancellableOperation(async abortSignal => { const { apiName, options: apiOptions = {}, path: apiPath } = options; @@ -37,7 +39,7 @@ const publicHandler = ( amplify, apiName, apiPath, - apiOptions?.queryParams + apiOptions?.queryParams, ); const libraryConfigHeaders = await amplify.libraryOptions?.API?.REST?.headers?.({ @@ -57,8 +59,9 @@ const publicHandler = ( method, url, headers, - `IAM signing options: ${JSON.stringify(signingServiceInfo)}` + `IAM signing options: ${JSON.stringify(signingServiceInfo)}`, ); + return transferHandler( amplify, { @@ -68,7 +71,7 @@ const publicHandler = ( headers, abortSignal, }, - signingServiceInfo + signingServiceInfo, ); }); @@ -77,7 +80,7 @@ export const get = (amplify: AmplifyClassV6, input: GetInput): GetOperation => export const post = ( amplify: AmplifyClassV6, - input: PostInput + input: PostInput, ): PostOperation => publicHandler(amplify, input, 'POST'); export const put = (amplify: AmplifyClassV6, input: PutInput): PutOperation => @@ -85,15 +88,15 @@ export const put = (amplify: AmplifyClassV6, input: PutInput): PutOperation => export const del = ( amplify: AmplifyClassV6, - input: DeleteInput + input: DeleteInput, ): DeleteOperation => publicHandler(amplify, input, 'DELETE'); export const head = ( amplify: AmplifyClassV6, - input: HeadInput + input: HeadInput, ): HeadOperation => publicHandler(amplify, input, 'HEAD'); export const patch = ( amplify: AmplifyClassV6, - input: PatchInput + input: PatchInput, ): PatchOperation => publicHandler(amplify, input, 'PATCH'); diff --git a/packages/api-rest/src/apis/index.ts b/packages/api-rest/src/apis/index.ts index a51f49d0afb..57b9dbd310f 100644 --- a/packages/api-rest/src/apis/index.ts +++ b/packages/api-rest/src/apis/index.ts @@ -2,14 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; -import { - get as commonGet, - post as commonPost, - put as commonPut, - del as commonDel, - head as commonHead, - patch as commonPatch, -} from './common/publicApis'; + import { DeleteInput, DeleteOperation, @@ -26,6 +19,15 @@ import { } from '../types'; import { RestApiError } from '../errors'; +import { + del as commonDel, + get as commonGet, + head as commonHead, + patch as commonPatch, + post as commonPost, + put as commonPut, +} from './common/publicApis'; + /** * GET HTTP request * @param {GetInput} input - Input for GET operation diff --git a/packages/api-rest/src/apis/server.ts b/packages/api-rest/src/apis/server.ts index 3afe1bb9e32..78dd984d321 100644 --- a/packages/api-rest/src/apis/server.ts +++ b/packages/api-rest/src/apis/server.ts @@ -5,14 +5,7 @@ import { AmplifyServer, getAmplifyServerContext, } from '@aws-amplify/core/internals/adapter-core'; -import { - get as commonGet, - post as commonPost, - put as commonPut, - del as commonDel, - head as commonHead, - patch as commonPatch, -} from './common/publicApis'; + import { DeleteInput, DeleteOperation, @@ -29,6 +22,15 @@ import { } from '../types'; import { RestApiError } from '../errors'; +import { + del as commonDel, + get as commonGet, + head as commonHead, + patch as commonPatch, + post as commonPost, + put as commonPut, +} from './common/publicApis'; + /** * GET HTTP request (server-side) * @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context. @@ -52,11 +54,10 @@ import { RestApiError } from '../errors'; * }, * }); * ``` - * @see {@link clientGet} */ export const get = ( contextSpec: AmplifyServer.ContextSpec, - input: GetInput + input: GetInput, ): GetOperation => commonGet(getAmplifyServerContext(contextSpec).amplify, input); @@ -86,7 +87,7 @@ export const get = ( */ export const post = ( contextSpec: AmplifyServer.ContextSpec, - input: PostInput + input: PostInput, ): PostOperation => commonPost(getAmplifyServerContext(contextSpec).amplify, input); @@ -116,7 +117,7 @@ export const post = ( */ export const put = ( contextSpec: AmplifyServer.ContextSpec, - input: PutInput + input: PutInput, ): PutOperation => commonPut(getAmplifyServerContext(contextSpec).amplify, input); @@ -145,7 +146,7 @@ export const put = ( */ export const del = ( contextSpec: AmplifyServer.ContextSpec, - input: DeleteInput + input: DeleteInput, ): DeleteOperation => commonDel(getAmplifyServerContext(contextSpec).amplify, input); @@ -174,7 +175,7 @@ export const del = ( */ export const head = ( contextSpec: AmplifyServer.ContextSpec, - input: HeadInput + input: HeadInput, ): HeadOperation => commonHead(getAmplifyServerContext(contextSpec).amplify, input); @@ -204,6 +205,6 @@ export const head = ( */ export const patch = ( contextSpec: AmplifyServer.ContextSpec, - input: PatchInput + input: PatchInput, ): PatchOperation => commonPatch(getAmplifyServerContext(contextSpec).amplify, input); diff --git a/packages/api-rest/src/errors/CanceledError.ts b/packages/api-rest/src/errors/CanceledError.ts index 254c2c69eef..ce4082212e0 100644 --- a/packages/api-rest/src/errors/CanceledError.ts +++ b/packages/api-rest/src/errors/CanceledError.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { AmplifyErrorParams } from '@aws-amplify/core/internals/utils'; + import { RestApiError } from './RestApiError'; /** diff --git a/packages/api-rest/src/errors/assertValidatonError.ts b/packages/api-rest/src/errors/assertValidatonError.ts index e797fe1f16e..83ed1a353fd 100644 --- a/packages/api-rest/src/errors/assertValidatonError.ts +++ b/packages/api-rest/src/errors/assertValidatonError.ts @@ -9,7 +9,7 @@ import { RestApiValidationErrorCode, validationErrorMap } from './validation'; */ export function assertValidationError( assertion: boolean, - name: RestApiValidationErrorCode + name: RestApiValidationErrorCode, ): asserts assertion { const { message, recoverySuggestion } = validationErrorMap[name]; diff --git a/packages/api-rest/src/internals/server.ts b/packages/api-rest/src/internals/server.ts index 2cd55554e38..ef0c860fba8 100644 --- a/packages/api-rest/src/internals/server.ts +++ b/packages/api-rest/src/internals/server.ts @@ -26,7 +26,7 @@ import { InternalPostInput } from '../types'; */ export const post = ( contextSpec: AmplifyServer.ContextSpec, - input: InternalPostInput + input: InternalPostInput, ) => { return internalPost(getAmplifyServerContext(contextSpec).amplify, input); }; diff --git a/packages/api-rest/src/types/index.ts b/packages/api-rest/src/types/index.ts index 5255586493d..f2f3c214b17 100644 --- a/packages/api-rest/src/types/index.ts +++ b/packages/api-rest/src/types/index.ts @@ -19,7 +19,7 @@ export type HeadOperation = Operation>; /** * @internal */ -export type RestApiOptionsBase = { +export interface RestApiOptionsBase { headers?: Headers; queryParams?: Record; body?: DocumentType | FormData; @@ -35,7 +35,7 @@ export type RestApiOptionsBase = { * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials} */ withCredentials?: boolean; -}; +} type Headers = Record; @@ -44,16 +44,16 @@ type Headers = Record; * * @internal */ -export type Operation = { +export interface Operation { response: Promise; - cancel: (abortMessage?: string) => void; -}; + cancel(abortMessage?: string): void; +} -type ResponsePayload = { - blob: () => Promise; - json: () => Promise; - text: () => Promise; -}; +interface ResponsePayload { + blob(): Promise; + json(): Promise; + text(): Promise; +} /** * Basic response type of REST API. @@ -69,7 +69,7 @@ export interface RestApiResponse { /** * @internal */ -export type ApiInput = { +export interface ApiInput { /** * Name of the REST API configured in Amplify singleton. */ @@ -82,13 +82,13 @@ export type ApiInput = { * Options to overwrite the REST API call behavior. */ options?: Options; -}; +} /** * Input type to invoke REST POST API from GraphQl client. * @internal */ -export type InternalPostInput = { +export interface InternalPostInput { // Resolved GraphQl endpoint url url: URL; options?: RestApiOptionsBase & { @@ -111,4 +111,4 @@ export type InternalPostInput = { * controller. */ abortController?: AbortController; -}; +} diff --git a/packages/api-rest/src/utils/createCancellableOperation.ts b/packages/api-rest/src/utils/createCancellableOperation.ts index 26535a7e71d..f75010faabe 100644 --- a/packages/api-rest/src/utils/createCancellableOperation.ts +++ b/packages/api-rest/src/utils/createCancellableOperation.ts @@ -2,8 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 import { HttpResponse } from '@aws-amplify/core/internals/aws-client-utils'; + import { CanceledError } from '../errors'; import { Operation } from '../types'; + import { parseRestApiServiceError } from './serviceError'; import { logger } from './logger'; @@ -13,7 +15,7 @@ import { logger } from './logger'; */ export function createCancellableOperation( handler: () => Promise, - abortController: AbortController + abortController: AbortController, ): Promise; /** @@ -21,7 +23,7 @@ export function createCancellableOperation( * @internal */ export function createCancellableOperation( - handler: (signal: AbortSignal) => Promise + handler: (signal: AbortSignal) => Promise, ): Operation; /** @@ -31,13 +33,13 @@ export function createCancellableOperation( handler: | ((signal: AbortSignal) => Promise) | (() => Promise), - abortController?: AbortController + abortController?: AbortController, ): Operation | Promise { const isInternalPost = ( - handler: + targetHandler: | ((signal: AbortSignal) => Promise) - | (() => Promise) - ): handler is () => Promise => !!abortController; + | (() => Promise), + ): targetHandler is () => Promise => !!abortController; // For creating a cancellable operation for public REST APIs, we need to create an AbortController // internally. Whereas for internal POST APIs, we need to accept in the AbortController from the @@ -56,6 +58,7 @@ export function createCancellableOperation( if (response.statusCode >= 300) { throw await parseRestApiServiceError(response)!; } + return response; } catch (error: any) { const abortSignal = internalPostAbortSignal ?? publicApisAbortSignal; @@ -87,6 +90,7 @@ export function createCancellableOperation( abortReason = abortMessage; } }; + return { response: job(), cancel }; } } diff --git a/packages/api-rest/src/utils/parseSigningInfo.ts b/packages/api-rest/src/utils/parseSigningInfo.ts index 3414a6dd772..6c9e59df86e 100644 --- a/packages/api-rest/src/utils/parseSigningInfo.ts +++ b/packages/api-rest/src/utils/parseSigningInfo.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { AmplifyClassV6 } from '@aws-amplify/core'; + import { APIG_HOSTNAME_PATTERN, DEFAULT_IAM_SIGNING_REGION, @@ -19,7 +20,7 @@ export const parseSigningInfo = ( restApiOptions?: { amplify: AmplifyClassV6; apiName: string; - } + }, ) => { const { service: signingService = DEFAULT_REST_IAM_SIGNING_SERVICE, diff --git a/packages/api-rest/src/utils/resolveApiUrl.ts b/packages/api-rest/src/utils/resolveApiUrl.ts index f0cce97062a..718c6f393a0 100644 --- a/packages/api-rest/src/utils/resolveApiUrl.ts +++ b/packages/api-rest/src/utils/resolveApiUrl.ts @@ -6,6 +6,7 @@ import { AmplifyUrl, AmplifyUrlSearchParams, } from '@aws-amplify/core/internals/utils'; + import { RestApiError, RestApiValidationErrorCode, @@ -27,7 +28,7 @@ export const resolveApiUrl = ( amplify: AmplifyClassV6, apiName: string, path: string, - queryParams?: Record + queryParams?: Record, ): URL => { const urlStr = amplify.getConfig()?.API?.REST?.[apiName]?.endpoint; assertValidationError(!!urlStr, RestApiValidationErrorCode.InvalidApiName); @@ -40,6 +41,7 @@ export const resolveApiUrl = ( }); url.search = new AmplifyUrlSearchParams(mergedQueryParams).toString(); } + return url; } catch (error) { throw new RestApiError({ diff --git a/packages/api-rest/src/utils/resolveHeaders.ts b/packages/api-rest/src/utils/resolveHeaders.ts index fd6734ffa10..f83920970fe 100644 --- a/packages/api-rest/src/utils/resolveHeaders.ts +++ b/packages/api-rest/src/utils/resolveHeaders.ts @@ -3,10 +3,9 @@ export const resolveHeaders = ( headers?: Record, - body?: unknown + body?: unknown, ) => { const normalizedHeaders: Record = {}; - const isFormData = body instanceof FormData; for (const key in headers) { normalizedHeaders[key.toLowerCase()] = headers[key]; } @@ -22,5 +21,6 @@ export const resolveHeaders = ( delete normalizedHeaders['content-type']; } } + return normalizedHeaders; }; diff --git a/packages/api-rest/src/utils/serviceError.ts b/packages/api-rest/src/utils/serviceError.ts index a6a26e25eed..a4a13051e0e 100644 --- a/packages/api-rest/src/utils/serviceError.ts +++ b/packages/api-rest/src/utils/serviceError.ts @@ -19,7 +19,7 @@ import { RestApiError } from '../errors'; * be `UnknownError` and `Unknown error` respectively. */ export const parseRestApiServiceError = async ( - response?: HttpResponse + response?: HttpResponse, ): Promise<(RestApiError & MetadataBearer) | undefined> => { if (!response) { // Response is not considered an error. @@ -28,9 +28,9 @@ export const parseRestApiServiceError = async ( const parsedAwsError = await parseAwsJsonError(stubErrorResponse(response)); if (!parsedAwsError) { // Response is not considered an error. - return; } else { const bodyText = await response.body?.text(); + return buildRestApiError(parsedAwsError, { statusCode: response.statusCode, headers: response.headers, @@ -46,7 +46,7 @@ export const parseRestApiServiceError = async ( * make sure we can read the error response body as a JSON, and may fall back to read as text if it is not a valid JSON. */ const stubErrorResponse = (response: HttpResponse): HttpResponse => { - let bodyTextPromise: Promise | undefined = undefined; + let bodyTextPromise: Promise | undefined; const bodyProxy = new Proxy(response.body, { get(target, prop, receiver) { if (prop === 'json') { @@ -69,6 +69,7 @@ const stubErrorResponse = (response: HttpResponse): HttpResponse => { if (!bodyTextPromise) { bodyTextPromise = target.text(); } + return bodyTextPromise; }; } else { @@ -85,6 +86,7 @@ const stubErrorResponse = (response: HttpResponse): HttpResponse => { } }, }); + return responseProxy; }; @@ -93,7 +95,7 @@ const stubErrorResponse = (response: HttpResponse): HttpResponse => { */ const buildRestApiError = ( error: Error & MetadataBearer, - response?: ApiErrorResponse + response?: ApiErrorResponse, ): RestApiError & MetadataBearer => { const restApiError = new RestApiError({ name: error?.name, @@ -101,6 +103,7 @@ const buildRestApiError = ( underlyingError: error, response, }); + // $metadata is only required for backwards compatibility. return Object.assign(restApiError, { $metadata: error.$metadata }); }; diff --git a/packages/api-rest/tslint.json b/packages/api-rest/tslint.json deleted file mode 100644 index 1bb9e144d24..00000000000 --- a/packages/api-rest/tslint.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "defaultSeverity": "error", - "plugins": ["prettier"], - "extends": [], - "jsRules": {}, - "rules": { - "prefer-const": true, - "max-line-length": [true, 120], - "no-empty-interface": true, - "no-var-keyword": true, - "object-literal-shorthand": true, - "no-eval": true, - "space-before-function-paren": [ - true, - { - "anonymous": "never", - "named": "never" - } - ], - "no-parameter-reassignment": true, - "align": [true, "parameters"], - "no-duplicate-imports": true, - "one-variable-per-declaration": [false, "ignore-for-loop"], - "triple-equals": [true, "allow-null-check"], - "comment-format": [true, "check-space"], - "indent": [false], - "whitespace": [ - false, - "check-branch", - "check-decl", - "check-operator", - "check-preblock" - ], - "eofline": true, - "variable-name": [ - true, - "check-format", - "allow-pascal-case", - "allow-snake-case", - "allow-leading-underscore" - ], - "semicolon": [true, "always", "ignore-interfaces"] - }, - "rulesDirectory": [] -} diff --git a/packages/api/package.json b/packages/api/package.json index ee2fb94983c..44a54f0f276 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -23,7 +23,8 @@ "clean": "npm run clean:size && rimraf dist lib lib-esm", "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 88" }, "exports": { diff --git a/packages/api/src/API.ts b/packages/api/src/API.ts index 7a6d0dabbf6..db0559e4477 100644 --- a/packages/api/src/API.ts +++ b/packages/api/src/API.ts @@ -1,6 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { V6Client, CommonPublicClientOptions } from '@aws-amplify/api-graphql'; +import { CommonPublicClientOptions, V6Client } from '@aws-amplify/api-graphql'; import { generateClient as internalGenerateClient } from '@aws-amplify/api-graphql/internals'; import { Amplify } from '@aws-amplify/core'; @@ -8,7 +8,7 @@ import { Amplify } from '@aws-amplify/core'; * Generates an API client that can work with models or raw GraphQL */ export function generateClient = never>( - options: CommonPublicClientOptions = {} + options: CommonPublicClientOptions = {}, ): V6Client { return internalGenerateClient({ ...options, diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 4936b1141b9..35062beffce 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -1,6 +1,8 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +import type { V6Client } from '@aws-amplify/api-graphql'; + export { GraphQLQuery, GraphQLSubscription, SelectionSet } from './types'; export { generateClient } from './API'; @@ -13,8 +15,6 @@ export type { export { CONNECTION_STATE_CHANGE } from '@aws-amplify/api-graphql'; -import type { V6Client } from '@aws-amplify/api-graphql'; - // explicitly defaulting to `never` here resolves // TS2589: Type instantiation is excessively deep and possibly infinite. // When this type is used without a generic type arg, i.e. `let client: Client` diff --git a/packages/api/src/internals/InternalAPI.ts b/packages/api/src/internals/InternalAPI.ts index c8c7e6d8f50..5b65ca84fb3 100644 --- a/packages/api/src/internals/InternalAPI.ts +++ b/packages/api/src/internals/InternalAPI.ts @@ -4,13 +4,13 @@ import { AWSAppSyncRealTimeProvider, GraphQLOperation, GraphQLOptions, - GraphQLResult, - OperationTypeNode, GraphQLQuery, + GraphQLResult, GraphQLSubscription, + OperationTypeNode, } from '@aws-amplify/api-graphql'; import { InternalGraphQLAPIClass } from '@aws-amplify/api-graphql/internals'; -import { Amplify, Cache, ConsoleLogger } from '@aws-amplify/core'; +import { Amplify, Cache } from '@aws-amplify/core'; import { ApiAction, Category, @@ -28,7 +28,6 @@ import { CustomHeaders } from '@aws-amplify/data-schema-types'; * state as possible for V6 to reduce number of potentially impactful changes to DataStore. */ -const logger = new ConsoleLogger('API'); /** * @deprecated * Use RestApi or GraphQLAPI to reduce your application bundle size @@ -68,7 +67,7 @@ export class InternalAPIClass { graphql( options: GraphQLOptions, additionalHeaders?: CustomHeaders, - customUserAgentDetails?: CustomUserAgentDetails + customUserAgentDetails?: CustomUserAgentDetails, ): T extends GraphQLQuery ? Promise> : T extends GraphQLSubscription @@ -77,10 +76,11 @@ export class InternalAPIClass { value: GraphQLResult; }> : Promise> | Observable; - graphql( + + graphql<_ = any>( options: GraphQLOptions, additionalHeaders?: CustomHeaders, - customUserAgentDetails?: CustomUserAgentDetails + customUserAgentDetails?: CustomUserAgentDetails, ): Promise> | Observable { const apiUserAgentDetails: CustomUserAgentDetails = { category: Category.API, @@ -92,7 +92,7 @@ export class InternalAPIClass { Amplify, options, additionalHeaders, - apiUserAgentDetails + apiUserAgentDetails, ); } } diff --git a/packages/api/tslint.json b/packages/api/tslint.json deleted file mode 100644 index 1bb9e144d24..00000000000 --- a/packages/api/tslint.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "defaultSeverity": "error", - "plugins": ["prettier"], - "extends": [], - "jsRules": {}, - "rules": { - "prefer-const": true, - "max-line-length": [true, 120], - "no-empty-interface": true, - "no-var-keyword": true, - "object-literal-shorthand": true, - "no-eval": true, - "space-before-function-paren": [ - true, - { - "anonymous": "never", - "named": "never" - } - ], - "no-parameter-reassignment": true, - "align": [true, "parameters"], - "no-duplicate-imports": true, - "one-variable-per-declaration": [false, "ignore-for-loop"], - "triple-equals": [true, "allow-null-check"], - "comment-format": [true, "check-space"], - "indent": [false], - "whitespace": [ - false, - "check-branch", - "check-decl", - "check-operator", - "check-preblock" - ], - "eofline": true, - "variable-name": [ - true, - "check-format", - "allow-pascal-case", - "allow-snake-case", - "allow-leading-underscore" - ], - "semicolon": [true, "always", "ignore-interfaces"] - }, - "rulesDirectory": [] -}