From 5caac16912dcd26f860704cdecff7398c44c7ac8 Mon Sep 17 00:00:00 2001 From: Nikita Elfimov Date: Wed, 22 Jan 2025 18:16:46 +0300 Subject: [PATCH] fix(common): typecheck --- .github/ISSUE_TEMPLATE/bug.yaml | 2 +- .github/ISSUE_TEMPLATE/docs.yaml | 2 +- .github/ISSUE_TEMPLATE/feature.yaml | 2 +- .../test/connectrpc-errors.test.ts | 3 ++- .../domain.expection-factory.ts | 4 +++- .../guard.exception-factory.ts | 7 +++++-- .../validation.exception-factory.ts | 7 +++++-- .../src/connectrpc.interfaces.ts | 20 ++++++------------- .../src/module/external-renderer.module.ts | 2 +- .../nestjs-gateway/src/mesh/graphql.mesh.ts | 1 - .../integration/grpc-identity.test.ts | 5 +++-- .../src/services/keto-write-client.service.ts | 1 - .../src/utils/relation-tuple-converter.ts | 1 - .../src/module/s3-client.config-factory.ts | 1 - .../src/services/signed-url.service.ts | 1 - 15 files changed, 28 insertions(+), 31 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug.yaml b/.github/ISSUE_TEMPLATE/bug.yaml index a0827a26..84f43808 100644 --- a/.github/ISSUE_TEMPLATE/bug.yaml +++ b/.github/ISSUE_TEMPLATE/bug.yaml @@ -58,4 +58,4 @@ body: validations: required: true -projects: ['atls/11'] \ No newline at end of file +projects: ['atls/11'] diff --git a/.github/ISSUE_TEMPLATE/docs.yaml b/.github/ISSUE_TEMPLATE/docs.yaml index 7718a36f..3f4057cb 100644 --- a/.github/ISSUE_TEMPLATE/docs.yaml +++ b/.github/ISSUE_TEMPLATE/docs.yaml @@ -41,4 +41,4 @@ body: validations: required: true -projects: ['atls/11'] \ No newline at end of file +projects: ['atls/11'] diff --git a/.github/ISSUE_TEMPLATE/feature.yaml b/.github/ISSUE_TEMPLATE/feature.yaml index f3bb4939..71589d1f 100644 --- a/.github/ISSUE_TEMPLATE/feature.yaml +++ b/.github/ISSUE_TEMPLATE/feature.yaml @@ -44,4 +44,4 @@ body: validations: required: true -projects: ['atls/11'] \ No newline at end of file +projects: ['atls/11'] diff --git a/packages/nestjs-connectrpc-errors/integration/test/connectrpc-errors.test.ts b/packages/nestjs-connectrpc-errors/integration/test/connectrpc-errors.test.ts index 2fd43ac8..92aa2d17 100644 --- a/packages/nestjs-connectrpc-errors/integration/test/connectrpc-errors.test.ts +++ b/packages/nestjs-connectrpc-errors/integration/test/connectrpc-errors.test.ts @@ -1,8 +1,8 @@ import type { PromiseClient } from '@connectrpc/connect' import type { INestMicroservice } from '@nestjs/common' -import { ConnectError } from '@connectrpc/connect' import { ValidationError } from '@atls/protobuf-rpc' +import { ConnectError } from '@connectrpc/connect' import { Test } from '@nestjs/testing' import { createPromiseClient } from '@connectrpc/connect' import { createGrpcTransport } from '@connectrpc/connect-node' @@ -64,6 +64,7 @@ describe('grpc error', () => { expect( // @ts-expect-error error.details.map((detail: { value: Uint8Array }) => + // @ts-expect-error ValidationError.fromBinary(detail.value)) ).toEqual( expect.arrayContaining([ diff --git a/packages/nestjs-connectrpc-errors/src/exception-factories/domain.expection-factory.ts b/packages/nestjs-connectrpc-errors/src/exception-factories/domain.expection-factory.ts index 76515d5b..a2bd080a 100644 --- a/packages/nestjs-connectrpc-errors/src/exception-factories/domain.expection-factory.ts +++ b/packages/nestjs-connectrpc-errors/src/exception-factories/domain.expection-factory.ts @@ -1,12 +1,14 @@ import type { DomainError } from '@atls/core-errors' +import { LogicalError } from '@atls/protobuf-rpc' import { Code } from '@connectrpc/connect' import { ConnectError } from '@connectrpc/connect' -import { LogicalError } from '@atls/protobuf-rpc' import { RpcException } from '@nestjs/microservices' export const domainExceptionFactory = (error: DomainError): RpcException => { + // @ts-expect-error types const logicalError = new LogicalError({ + // @ts-expect-error types id: error.id, message: error.message, }) diff --git a/packages/nestjs-connectrpc-errors/src/exception-factories/guard.exception-factory.ts b/packages/nestjs-connectrpc-errors/src/exception-factories/guard.exception-factory.ts index 03f03ca7..4f2cf564 100644 --- a/packages/nestjs-connectrpc-errors/src/exception-factories/guard.exception-factory.ts +++ b/packages/nestjs-connectrpc-errors/src/exception-factories/guard.exception-factory.ts @@ -1,18 +1,20 @@ import type { GuardErrors } from '@atls/guard-clause' -import { Code } from '@connectrpc/connect' -import { ConnectError } from '@connectrpc/connect' import { ValidationError } from '@atls/protobuf-rpc' import { ValidationErrorMessage } from '@atls/protobuf-rpc' +import { Code } from '@connectrpc/connect' +import { ConnectError } from '@connectrpc/connect' import { RpcException } from '@nestjs/microservices' export const guardExceptionFactory = (errors: GuardErrors): RpcException => { const validationErrors: Array = errors.errors.map( (error) => + // @ts-expect-error types new ValidationError({ id: error.code, property: error.parameter, messages: [ + // @ts-expect-error types new ValidationErrorMessage({ id: error.code, constraint: error.message, @@ -22,6 +24,7 @@ export const guardExceptionFactory = (errors: GuardErrors): RpcException => { ) return new RpcException( + // @ts-expect-error types new ConnectError('Request validation failed', Code.InvalidArgument, undefined, validationErrors) ) } diff --git a/packages/nestjs-connectrpc-errors/src/exception-factories/validation.exception-factory.ts b/packages/nestjs-connectrpc-errors/src/exception-factories/validation.exception-factory.ts index 7c1ba4de..ae680200 100644 --- a/packages/nestjs-connectrpc-errors/src/exception-factories/validation.exception-factory.ts +++ b/packages/nestjs-connectrpc-errors/src/exception-factories/validation.exception-factory.ts @@ -2,10 +2,10 @@ import type { ValidationError as ValError } from '@nestjs/common' -import { Code } from '@connectrpc/connect' -import { ConnectError } from '@connectrpc/connect' import { ValidationError } from '@atls/protobuf-rpc' import { ValidationErrorMessage } from '@atls/protobuf-rpc' +import { Code } from '@connectrpc/connect' +import { ConnectError } from '@connectrpc/connect' import { RpcException } from '@nestjs/microservices' const traverseErrors = ( @@ -29,6 +29,7 @@ export const validationExceptionFactory = (errors: Array): RpcExceptio traverseErrors(errors, (error, id, property) => { const messages = Object.keys(error.constraints || {}).map((constraintId) => { + // @ts-expect-error types const validationErrorMessage = new ValidationErrorMessage({ id: constraintId, constraint: error.constraints![constraintId], @@ -38,6 +39,7 @@ export const validationExceptionFactory = (errors: Array): RpcExceptio }) validationErrors.push( + // @ts-expect-error types new ValidationError({ id, property, @@ -47,6 +49,7 @@ export const validationExceptionFactory = (errors: Array): RpcExceptio }) return new RpcException( + // @ts-expect-error types new ConnectError('Request validation failed', Code.InvalidArgument, undefined, validationErrors) ) } diff --git a/packages/nestjs-connectrpc/src/connectrpc.interfaces.ts b/packages/nestjs-connectrpc/src/connectrpc.interfaces.ts index 279c8b7e..81c8abc1 100644 --- a/packages/nestjs-connectrpc/src/connectrpc.interfaces.ts +++ b/packages/nestjs-connectrpc/src/connectrpc.interfaces.ts @@ -1,8 +1,8 @@ -import type * as http from 'http' -import type * as http2 from 'http2' -import type * as https from 'https' +import type * as http from 'http' +import type * as http2 from 'http2' +import type * as https from 'https' import type { ConnectRouterOptions } from '@connectrpc/connect' -import type { Observable } from 'rxjs' +import type { Observable } from 'rxjs' export interface ConnectRpcPattern { service: string @@ -48,17 +48,9 @@ export interface Http2InsecureOptions extends BaseServerOptions { serverOptions?: http2.ServerOptions } -export type ServerTypeOptions = - | Http2InsecureOptions - | Http2Options - | HttpOptions - | HttpsOptions +export type ServerTypeOptions = Http2InsecureOptions | Http2Options | HttpOptions | HttpsOptions -export type ServerInstance = - | http.Server - | http2.Http2Server - | https.Server - | null +export type ServerInstance = http.Server | http2.Http2Server | https.Server | null export interface ConstructorWithPrototype { prototype: Record diff --git a/packages/nestjs-external-renderer/src/module/external-renderer.module.ts b/packages/nestjs-external-renderer/src/module/external-renderer.module.ts index 0361f170..d5133bfb 100644 --- a/packages/nestjs-external-renderer/src/module/external-renderer.module.ts +++ b/packages/nestjs-external-renderer/src/module/external-renderer.module.ts @@ -69,7 +69,7 @@ export class ExternalRendererModule { provide: EXTERNAL_RENDERER_MODULE_OPTIONS, useFactory: async (optionsFactory: ExternalRendererOptionsFactory) => optionsFactory.createExternalRendererOptions(), - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion inject: [options.useExisting! || options.useClass!], } } diff --git a/packages/nestjs-gateway/src/mesh/graphql.mesh.ts b/packages/nestjs-gateway/src/mesh/graphql.mesh.ts index c8075b92..77223561 100644 --- a/packages/nestjs-gateway/src/mesh/graphql.mesh.ts +++ b/packages/nestjs-gateway/src/mesh/graphql.mesh.ts @@ -19,7 +19,6 @@ export class GraphQLMesh { this.mesh = await getMesh(await this.config.create()) } - return this.mesh } } diff --git a/packages/nestjs-grpc-identity/integration/grpc-identity.test.ts b/packages/nestjs-grpc-identity/integration/grpc-identity.test.ts index 025e8449..40d03ee9 100644 --- a/packages/nestjs-grpc-identity/integration/grpc-identity.test.ts +++ b/packages/nestjs-grpc-identity/integration/grpc-identity.test.ts @@ -4,6 +4,9 @@ import type { INestMicroservice } from '@nestjs/common' +import { readFileSync } from 'node:fs' +import { join } from 'node:path' + import { Metadata } from '@grpc/grpc-js' import { ClientsModule } from '@nestjs/microservices' import { Transport } from '@nestjs/microservices' @@ -14,9 +17,7 @@ import { beforeAll } from '@jest/globals' import { it } from '@jest/globals' import { expect } from '@jest/globals' import { afterAll } from '@jest/globals' -import { readFileSync } from 'node:fs' import { sign } from 'jsonwebtoken' -import { join } from 'node:path' import getPort from 'get-port' import { GrpcIdentityIntegrationModule } from './src/index.js' diff --git a/packages/nestjs-grpc-keto/src/services/keto-write-client.service.ts b/packages/nestjs-grpc-keto/src/services/keto-write-client.service.ts index 867521ba..960bf90d 100644 --- a/packages/nestjs-grpc-keto/src/services/keto-write-client.service.ts +++ b/packages/nestjs-grpc-keto/src/services/keto-write-client.service.ts @@ -78,7 +78,6 @@ export class KetoWriteClientService { // eslint-disable-next-line @typescript-eslint/no-unsafe-call delta.setAction(action).setRelationTuple(tuple) - return delta } } diff --git a/packages/nestjs-grpc-keto/src/utils/relation-tuple-converter.ts b/packages/nestjs-grpc-keto/src/utils/relation-tuple-converter.ts index 26334a73..163e0de6 100644 --- a/packages/nestjs-grpc-keto/src/utils/relation-tuple-converter.ts +++ b/packages/nestjs-grpc-keto/src/utils/relation-tuple-converter.ts @@ -121,7 +121,6 @@ export class RelationTupleConverter { // eslint-disable-next-line @typescript-eslint/no-unsafe-call subjectSet.setRelation(relation) - return subjectSet } diff --git a/packages/nestjs-s3-client/src/module/s3-client.config-factory.ts b/packages/nestjs-s3-client/src/module/s3-client.config-factory.ts index 54b08fc9..a2350a9d 100644 --- a/packages/nestjs-s3-client/src/module/s3-client.config-factory.ts +++ b/packages/nestjs-s3-client/src/module/s3-client.config-factory.ts @@ -1,6 +1,5 @@ import type { S3ClientConfig } from '@aws-sdk/client-s3' - import type { S3ClientModuleOptions } from './s3-client.module.interfaces.js' import { Inject } from '@nestjs/common' diff --git a/packages/nestjs-signed-url/src/services/signed-url.service.ts b/packages/nestjs-signed-url/src/services/signed-url.service.ts index 4131880e..8eec7c30 100644 --- a/packages/nestjs-signed-url/src/services/signed-url.service.ts +++ b/packages/nestjs-signed-url/src/services/signed-url.service.ts @@ -1,6 +1,5 @@ import type { SignUrlOptions } from '../storage/index.js' import type { SignedUrl } from '../storage/index.js' - import type { AbstractStorage } from '../storage/index.js' import { Inject } from '@nestjs/common'