style: run format

Run format
This commit is contained in:
Conicaw 2023-07-05 17:37:57 -05:00
parent 1850dd8948
commit db053cfb8e
No known key found for this signature in database
GPG key ID: CE0B9DEFED1E6375
5 changed files with 53 additions and 71 deletions

View file

@ -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,10 +89,8 @@ 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,

View file

@ -1,7 +1,7 @@
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 {
@ -28,6 +28,6 @@ export class HttpService {
}
get axiosRef(): AxiosInstance {
return this.instance
return this.instance;
}
}

View file

@ -1,3 +1,3 @@
export { HttpService } from './http.service'
export { HttpModule } from './http.module'
export * from './interfaces'
export { HttpService } from './http.service';
export { HttpModule } from './http.module';
export * from './interfaces';

View file

@ -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> | HttpModuleOptions;
}
export interface HttpModuleAsyncOptions
extends Pick<ModuleMetadata, 'imports'> {
export interface HttpModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
useExisting?: Type<HttpModuleOptionsFactory>;
useClass?: Type<HttpModuleOptionsFactory>;
useFactory?: (
...args: any[]
) => Promise<HttpModuleOptions> | HttpModuleOptions;
useFactory?: (...args: any[]) => Promise<HttpModuleOptions> | HttpModuleOptions;
inject?: any[];
extraProviders?: Provider[];
}