Skip to content

Commit

Permalink
chore: add type to imports
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunnerLivio committed Sep 14, 2023
1 parent 29bb4bd commit 8b2302d
Show file tree
Hide file tree
Showing 31 changed files with 136 additions and 61 deletions.
2 changes: 1 addition & 1 deletion lib/health-check/error-logger/error-logger.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HealthIndicatorResult } from '../../health-indicator';
import { type HealthIndicatorResult } from '../../health-indicator';

export interface ErrorLogger {
getErrorMessage(message: string, causes: HealthIndicatorResult): string;
Expand Down
6 changes: 3 additions & 3 deletions lib/health-check/error-logger/error-logger.provider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Provider } from '@nestjs/common';
import { ErrorLogger } from './error-logger.interface';
import { type Provider } from '@nestjs/common';
import { type ErrorLogger } from './error-logger.interface';
import { JsonErrorLogger } from './json-error-logger.service';
import { PrettyErrorLogger } from './pretty-error-logger.service';
import { ErrorLogStyle } from '../../terminus-options.interface';
import { type ErrorLogStyle } from '../../terminus-options.interface';

export const ERROR_LOGGER = 'TERMINUS_ERROR_LOGGER';

Expand Down
4 changes: 2 additions & 2 deletions lib/health-check/error-logger/error-loggers.provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Type } from '@nestjs/common';
import { ErrorLogger } from './error-logger.interface';
import { type Type } from '@nestjs/common';
import { type ErrorLogger } from './error-logger.interface';
import { JsonErrorLogger } from './json-error-logger.service';
import { PrettyErrorLogger } from './pretty-error-logger.service';

Expand Down
2 changes: 1 addition & 1 deletion lib/health-check/error-logger/json-error-logger.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { ErrorLogger } from './error-logger.interface';
import { type ErrorLogger } from './error-logger.interface';

@Injectable()
export class JsonErrorLogger implements ErrorLogger {
Expand Down
4 changes: 2 additions & 2 deletions lib/health-check/error-logger/pretty-error-logger.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import * as boxen from 'boxen';
import { ErrorLogger } from './error-logger.interface';
import { HealthIndicatorResult } from '../../health-indicator';
import { type ErrorLogger } from './error-logger.interface';
import { type HealthIndicatorResult } from '../../health-indicator';

const GREEN = '\x1b[0m\x1b[32m';
const RED = '\x1b[0m\x1b[31m';
Expand Down
16 changes: 9 additions & 7 deletions lib/health-check/health-check-executor.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable, BeforeApplicationShutdown } from '@nestjs/common';
import { Injectable, type BeforeApplicationShutdown } from '@nestjs/common';
import {
HealthCheckResult,
HealthCheckStatus,
type HealthCheckResult,
type HealthCheckStatus,
} from './health-check-result.interface';
import { HealthCheckError } from '../health-check/health-check.error';
import { type HealthCheckError } from '../health-check/health-check.error';
import {
HealthIndicatorFunction,
HealthIndicatorResult,
type HealthIndicatorFunction,
type HealthIndicatorResult,
} from '../health-indicator';
import { isHealthCheckError } from '../utils';

Expand Down Expand Up @@ -70,7 +70,9 @@ export class HealthCheckExecutor implements BeforeApplicationShutdown {
} else {
const error = res.reason;
// Is not an expected error. Throw further!
if (!isHealthCheckError(error)) throw error;
if (!isHealthCheckError(error)) {
throw error;
}
// Is a expected health check error
errors.push((error as HealthCheckError).causes);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/health-check/health-check-result.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HealthIndicatorResult } from '../health-indicator';
import { type HealthIndicatorResult } from '../health-indicator';

/**
* @publicApi
Expand Down
1 change: 1 addition & 0 deletions lib/health-check/health-check.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Header } from '@nestjs/common';
import { getHealthCheckSchema } from './health-check.schema';

// eslint-disable-next-line @typescript-eslint/consistent-type-imports
type Swagger = typeof import('@nestjs/swagger');

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/health-check/health-check.schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HealthCheckStatus } from './health-check-result.interface';
import { HealthIndicatorResult } from '../health-indicator';
import { type HealthCheckStatus } from './health-check-result.interface';
import { type HealthIndicatorResult } from '../health-indicator';
import type {} from '@nestjs/swagger';

// These examples will be displayed on Swagger
Expand Down
4 changes: 2 additions & 2 deletions lib/health-check/health-check.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
import { ErrorLogger } from './error-logger/error-logger.interface';
import { ERROR_LOGGER } from './error-logger/error-logger.provider';
import { HealthCheckExecutor } from './health-check-executor.service';
import { HealthCheckResult } from './health-check-result.interface';
import { type HealthCheckResult } from './health-check-result.interface';
import { TERMINUS_LOGGER } from './logger/logger.provider';
import { HealthIndicatorFunction } from '../health-indicator';
import { type HealthIndicatorFunction } from '../health-indicator';

/**
* Handles Health Checks which can be used in
Expand Down
2 changes: 1 addition & 1 deletion lib/health-check/logger/logger.provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoggerService, Provider, Type } from '@nestjs/common';
import { type LoggerService, type Provider, type Type } from '@nestjs/common';
import { DefaultTerminusLogger } from './default-logger.service';

export const TERMINUS_LOGGER = 'TERMINUS_LOGGER';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* The settings for the typeorm ping check
*/
import { Connection as MongooseConnection } from 'mongoose';
import { DataSource } from 'typeorm';
import { type Connection as MongooseConnection } from 'mongoose';
import { type DataSource } from 'typeorm';

/**
* @publicApi
Expand Down
4 changes: 2 additions & 2 deletions lib/health-indicator/database/mikro-orm.health.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as MikroOrm from '@mikro-orm/core';
import type * as MikroOrm from '@mikro-orm/core';
import { Injectable, Scope } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { HealthIndicator, HealthIndicatorResult } from '..';
import { HealthIndicator, type HealthIndicatorResult } from '..';
import { TimeoutError } from '../../errors';
import { HealthCheckError } from '../../health-check';
import {
Expand Down
4 changes: 2 additions & 2 deletions lib/health-indicator/database/mongoose.health.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable, Scope } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import * as NestJSMongoose from '@nestjs/mongoose';
import type * as NestJSMongoose from '@nestjs/mongoose';
import {
HealthIndicatorResult,
type HealthIndicatorResult,
TimeoutError,
ConnectionNotFoundError,
} from '../..';
Expand Down
1 change: 0 additions & 1 deletion lib/health-indicator/database/prisma.health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export class PrismaHealthIndicator extends HealthIndicator {
await this.pingDb(timeout, prismaClient);
isHealthy = true;
} catch (error) {
console.log(error);
if (error instanceof PromiseTimeoutError) {
throw new TimeoutError(
timeout,
Expand Down
4 changes: 2 additions & 2 deletions lib/health-indicator/database/sequelize.health.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable, Scope } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import * as NestJSSequelize from '@nestjs/sequelize';
import type * as NestJSSequelize from '@nestjs/sequelize';
import {
HealthIndicatorResult,
type HealthIndicatorResult,
TimeoutError,
ConnectionNotFoundError,
} from '../..';
Expand Down
10 changes: 6 additions & 4 deletions lib/health-indicator/database/typeorm.health.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable, Scope } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import * as NestJSTypeOrm from '@nestjs/typeorm';
import * as TypeOrm from 'typeorm';
import { HealthIndicator, HealthIndicatorResult } from '../';
import type * as NestJSTypeOrm from '@nestjs/typeorm';
import type * as TypeOrm from 'typeorm';
import { HealthIndicator, type HealthIndicatorResult } from '../';
import {
TimeoutError,
ConnectionNotFoundError,
Expand Down Expand Up @@ -80,7 +80,9 @@ export class TypeOrmHealthIndicator extends HealthIndicator {
: driver.buildConnectionUrl(connection.options),
driver.buildConnectionOptions(connection.options),
(err: Error, client: any) => {
if (err) return reject(new MongoConnectionError(err.message));
if (err) {
return reject(new MongoConnectionError(err.message));
}
client.close(() => resolve());
},
);
Expand Down
2 changes: 1 addition & 1 deletion lib/health-indicator/disk/disk-health-options.type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { XOR } from '../../utils/types';
import { type XOR } from '../../utils/types';

/**
* @internal
Expand Down
1 change: 0 additions & 1 deletion lib/health-indicator/disk/disk-usage-lib.provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import checkDiskSpace from 'check-disk-space';
import { CHECK_DISK_SPACE_LIB } from '../../terminus.constants';


/**
* Wrapper of the check-disk-space library.
*
Expand Down
8 changes: 4 additions & 4 deletions lib/health-indicator/disk/disk.health.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Injectable, Inject } from '@nestjs/common';
import { isNil } from '@nestjs/common/utils/shared.utils';
import checkDiskSpace from 'check-disk-space';
import type checkDiskSpace from 'check-disk-space';
import {
DiskHealthIndicatorOptions,
DiskOptionsWithThresholdPercent,
type DiskHealthIndicatorOptions,
type DiskOptionsWithThresholdPercent,
} from './disk-health-options.type';
import { HealthIndicator, HealthIndicatorResult } from '../';
import { HealthIndicator, type HealthIndicatorResult } from '../';
import { StorageExceededError } from '../../errors';
import { STORAGE_EXCEEDED } from '../../errors/messages.constant';
import { CHECK_DISK_SPACE_LIB } from '../../terminus.constants';
Expand Down
2 changes: 1 addition & 1 deletion lib/health-indicator/health-indicator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HealthIndicatorResult } from './';
import { type HealthIndicatorResult } from './';

/**
* A health indicator function for a health check
Expand Down
4 changes: 2 additions & 2 deletions lib/health-indicator/health-indicators.provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type } from '@nestjs/common';
import { type Type } from '@nestjs/common';
import {
TypeOrmHealthIndicator,
HttpHealthIndicator,
Expand All @@ -7,7 +7,7 @@ import {
DiskHealthIndicator,
MemoryHealthIndicator,
MicroserviceHealthIndicator,
HealthIndicator,
type HealthIndicator,
GRPCHealthIndicator,
PrismaHealthIndicator,
} from '.';
Expand Down
13 changes: 8 additions & 5 deletions lib/health-indicator/http/http.health.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { URL } from 'url';
import { type URL } from 'url';
import type * as NestJSAxios from '@nestjs/axios';
import { ConsoleLogger, Inject, Injectable, Scope } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { lastValueFrom, Observable } from 'rxjs';
import { AxiosRequestConfig, AxiosResponse } from './axios.interfaces';
import { HealthIndicator, HealthIndicatorResult } from '..';
import { AxiosError } from '../../errors/axios.error';
import { lastValueFrom, type Observable } from 'rxjs';
import {
type AxiosRequestConfig,
type AxiosResponse,
} from './axios.interfaces';
import { HealthIndicator, type HealthIndicatorResult } from '..';
import { type AxiosError } from '../../errors/axios.error';
import { HealthCheckError } from '../../health-check/health-check.error';
import { TERMINUS_LOGGER } from '../../health-check/logger/logger.provider';
import { checkPackages, isAxiosError } from '../../utils';
Expand Down
2 changes: 1 addition & 1 deletion lib/health-indicator/memory/memory.health.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { HealthIndicator, HealthIndicatorResult } from '../';
import { HealthIndicator, type HealthIndicatorResult } from '../';
import { StorageExceededError } from '../../errors';
import { STORAGE_EXCEEDED } from '../../errors/messages.constant';

Expand Down
10 changes: 6 additions & 4 deletions lib/health-indicator/microservice/grpc.health.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { join } from 'path';
import { Injectable, Scope } from '@nestjs/common';
import type * as NestJSMicroservices from '@nestjs/microservices';
import { Observable, lastValueFrom } from 'rxjs';
import { type Observable, lastValueFrom } from 'rxjs';
import {
HealthIndicatorResult,
type HealthIndicatorResult,
TimeoutError,
UnhealthyResponseCodeError,
} from '../..';
Expand All @@ -12,7 +12,7 @@ import {
checkPackages,
isError,
promiseTimeout,
PropType,
type PropType,
TimeoutError as PromiseTimeoutError,
} from '../../utils';
import { HealthIndicator } from '../health-indicator';
Expand Down Expand Up @@ -205,7 +205,9 @@ export class GRPCHealthIndicator extends HealthIndicator {
this.openChannels.set(service, healthService);
}
} catch (err) {
if (err instanceof TypeError) throw err;
if (err instanceof TypeError) {
throw err;
}
if (isError(err)) {
throw new HealthCheckError(
err.message,
Expand Down
4 changes: 2 additions & 2 deletions lib/health-indicator/microservice/microservice.health.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Injectable, Scope } from '@nestjs/common';
import * as NestJSMicroservices from '@nestjs/microservices';
import { HealthIndicator, HealthIndicatorResult } from '../';
import { HealthIndicator, type HealthIndicatorResult } from '../';
import { TimeoutError } from '../../errors';
import { HealthCheckError } from '../../health-check/health-check.error';
import {
checkPackages,
promiseTimeout,
TimeoutError as PromiseTimeoutError,
PropType,
type PropType,
isError,
} from '../../utils';

Expand Down
2 changes: 1 addition & 1 deletion lib/terminus-options.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoggerService, Type } from '@nestjs/common';
import { type LoggerService, type Type } from '@nestjs/common';

export type ErrorLogStyle = 'pretty' | 'json';

Expand Down
4 changes: 2 additions & 2 deletions lib/terminus.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DynamicModule, Module } from '@nestjs/common';
import { type DynamicModule, Module } from '@nestjs/common';
import { HealthCheckService } from './health-check';
import { getErrorLoggerProvider } from './health-check/error-logger/error-logger.provider';
import { ERROR_LOGGERS } from './health-check/error-logger/error-loggers.provider';
import { HealthCheckExecutor } from './health-check/health-check-executor.service';
import { getLoggerProvider } from './health-check/logger/logger.provider';
import { DiskUsageLibProvider } from './health-indicator/disk/disk-usage-lib.provider';
import { HEALTH_INDICATORS } from './health-indicator/health-indicators.provider';
import { TerminusModuleOptions } from './terminus-options.interface';
import { type TerminusModuleOptions } from './terminus-options.interface';

const providers = [
...ERROR_LOGGERS,
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/is-error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HealthCheckError } from '../';
import { AxiosError } from '../errors/axios.error';
import { type HealthCheckError } from '../';
import { type AxiosError } from '../errors/axios.error';

export function isHealthCheckError(err: any): err is HealthCheckError {
return err?.isHealthCheckError;
Expand Down
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8b2302d

Please sign in to comment.