From db053cfb8e49b781932a5fa671fddee47bb187cd Mon Sep 17 00:00:00 2001 From: Conicaw Date: Wed, 5 Jul 2023 17:37:57 -0500 Subject: [PATCH] style: run format Run format --- lib/http.constants.ts | 2 +- lib/http.module.ts | 42 +++++++-------------- lib/http.service.ts | 50 ++++++++++++------------- lib/index.ts | 6 +-- lib/interfaces/http-module.interface.ts | 24 ++++++------ 5 files changed, 53 insertions(+), 71 deletions(-) diff --git a/lib/http.constants.ts b/lib/http.constants.ts index e5c0f7c..21f6d84 100644 --- a/lib/http.constants.ts +++ b/lib/http.constants.ts @@ -1,3 +1,3 @@ export const AXIOS_INSTANCE_TOKEN = 'AXIOS_INSTANCE_TOKEN'; export const HTTP_MODULE_ID = 'HTTP_MODULE_ID'; -export const HTTP_MODULE_OPTIONS = 'HTTP_MODULE_OPTIONS'; \ No newline at end of file +export const HTTP_MODULE_OPTIONS = 'HTTP_MODULE_OPTIONS'; diff --git a/lib/http.module.ts b/lib/http.module.ts index 69a4070..9779959 100644 --- a/lib/http.module.ts +++ b/lib/http.module.ts @@ -1,28 +1,20 @@ import { DynamicModule, Module, Provider } from '@nestjs/common'; import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util'; import Axios from 'axios'; -import { - AXIOS_INSTANCE_TOKEN, - HTTP_MODULE_ID, - HTTP_MODULE_OPTIONS, -} from './http.constants'; +import { AXIOS_INSTANCE_TOKEN, HTTP_MODULE_ID, HTTP_MODULE_OPTIONS } from './http.constants'; import { HttpService } from './http.service'; -import { - HttpModuleAsyncOptions, - HttpModuleOptions, - HttpModuleOptionsFactory, -} from './interfaces'; +import { HttpModuleAsyncOptions, HttpModuleOptions, HttpModuleOptionsFactory } from './interfaces'; import axiosRetry from 'axios-retry'; import axiosBetterStacktrace from 'axios-better-stacktrace'; const createAxiosInstance = (config?: HttpModuleOptions) => { const axiosInstance = Axios.create(config); axiosRetry(axiosInstance, config); - if(config?.isBetterStackTraceEnabled === undefined || config?.isBetterStackTraceEnabled) { + if (config?.isBetterStackTraceEnabled === undefined || config?.isBetterStackTraceEnabled) { axiosBetterStacktrace(axiosInstance); } return axiosInstance; -} +}; @Module({ providers: [ @@ -71,29 +63,23 @@ export class HttpModule { }; } - private static createAsyncProviders( - options: HttpModuleAsyncOptions, - ): Provider[] { + private static createAsyncProviders(options: HttpModuleAsyncOptions): Provider[] { if (options.useExisting || options.useFactory) { return [this.createAsyncOptionsProvider(options)]; } - const providers = [ - this.createAsyncOptionsProvider(options) - ]; + const providers = [this.createAsyncOptionsProvider(options)]; - if(options.useClass) + if (options.useClass) providers.push({ provide: options.useClass, useClass: options.useClass, - }) + }); return providers; } - private static createAsyncOptionsProvider( - options: HttpModuleAsyncOptions, - ): Provider { + private static createAsyncOptionsProvider(options: HttpModuleAsyncOptions): Provider { if (options.useFactory) { return { provide: HTTP_MODULE_OPTIONS, @@ -103,16 +89,14 @@ export class HttpModule { } let inject; - if (options.useExisting) - inject = [options.useExisting]; - else if (options.useClass) - inject = [options.useClass]; + if (options.useExisting) inject = [options.useExisting]; + else if (options.useClass) inject = [options.useClass]; return { provide: HTTP_MODULE_OPTIONS, useFactory: async (optionsFactory: HttpModuleOptionsFactory) => - optionsFactory.createHttpOptions(), + optionsFactory.createHttpOptions(), inject, }; } -} \ No newline at end of file +} diff --git a/lib/http.service.ts b/lib/http.service.ts index 6526732..d76b6b2 100644 --- a/lib/http.service.ts +++ b/lib/http.service.ts @@ -1,33 +1,33 @@ import { Injectable } from '@nestjs/common'; import { Inject } from '@nestjs/common'; -import Axios ,{ AxiosInstance } from 'axios'; -import { AXIOS_INSTANCE_TOKEN } from "./http.constants"; +import Axios, { AxiosInstance } from 'axios'; +import { AXIOS_INSTANCE_TOKEN } from './http.constants'; @Injectable() export class HttpService { - public readonly put: typeof Axios.put; - public readonly post: typeof Axios.post; - public readonly patch: typeof Axios.patch; - public readonly head: typeof Axios.patch; - public readonly delete: typeof Axios.delete; - public readonly get: typeof Axios.get; - public readonly request: typeof Axios.request; + public readonly put: typeof Axios.put; + public readonly post: typeof Axios.post; + public readonly patch: typeof Axios.patch; + public readonly head: typeof Axios.patch; + public readonly delete: typeof Axios.delete; + public readonly get: typeof Axios.get; + public readonly request: typeof Axios.request; - constructor( - @Inject(AXIOS_INSTANCE_TOKEN) - private readonly instance: AxiosInstance = Axios, - ) { - this.put = this.instance.put; - this.post = this.instance.post; - this.patch = this.instance.patch; - this.head = this.instance.head; - this.head = this.instance.head; - this.delete = this.instance.delete; - this.get = this.instance.get; - this.request = this.instance.request; - } + constructor( + @Inject(AXIOS_INSTANCE_TOKEN) + private readonly instance: AxiosInstance = Axios, + ) { + this.put = this.instance.put; + this.post = this.instance.post; + this.patch = this.instance.patch; + this.head = this.instance.head; + this.head = this.instance.head; + this.delete = this.instance.delete; + this.get = this.instance.get; + this.request = this.instance.request; + } - get axiosRef(): AxiosInstance { - return this.instance - } + get axiosRef(): AxiosInstance { + return this.instance; + } } diff --git a/lib/index.ts b/lib/index.ts index 4dd500b..fe9e904 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,3 +1,3 @@ -export { HttpService } from './http.service' -export { HttpModule } from './http.module' -export * from './interfaces' \ No newline at end of file +export { HttpService } from './http.service'; +export { HttpModule } from './http.module'; +export * from './interfaces'; diff --git a/lib/interfaces/http-module.interface.ts b/lib/interfaces/http-module.interface.ts index 3875a3f..1cf81c0 100644 --- a/lib/interfaces/http-module.interface.ts +++ b/lib/interfaces/http-module.interface.ts @@ -1,20 +1,18 @@ import { ModuleMetadata, Provider, Type } from '@nestjs/common'; import { AxiosRequestConfig } from 'axios'; -import { IAxiosRetryConfig } from 'axios-retry' +import { IAxiosRetryConfig } from 'axios-retry'; -export type HttpModuleOptions = (AxiosRequestConfig & IAxiosRetryConfig & { isBetterStackTraceEnabled?: boolean }); +export type HttpModuleOptions = AxiosRequestConfig & + IAxiosRetryConfig & { isBetterStackTraceEnabled?: boolean }; export interface HttpModuleOptionsFactory { - createHttpOptions(): Promise | HttpModuleOptions; + createHttpOptions(): Promise | HttpModuleOptions; } -export interface HttpModuleAsyncOptions - extends Pick { - useExisting?: Type; - useClass?: Type; - useFactory?: ( - ...args: any[] - ) => Promise | HttpModuleOptions; - inject?: any[]; - extraProviders?: Provider[]; -} \ No newline at end of file +export interface HttpModuleAsyncOptions extends Pick { + useExisting?: Type; + useClass?: Type; + useFactory?: (...args: any[]) => Promise | HttpModuleOptions; + inject?: any[]; + extraProviders?: Provider[]; +}