style: run format
Run format
This commit is contained in:
parent
1850dd8948
commit
db053cfb8e
5 changed files with 53 additions and 71 deletions
|
@ -1,17 +1,9 @@
|
||||||
import { DynamicModule, Module, Provider } from '@nestjs/common';
|
import { DynamicModule, Module, Provider } from '@nestjs/common';
|
||||||
import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util';
|
import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util';
|
||||||
import Axios from 'axios';
|
import Axios from 'axios';
|
||||||
import {
|
import { AXIOS_INSTANCE_TOKEN, HTTP_MODULE_ID, HTTP_MODULE_OPTIONS } from './http.constants';
|
||||||
AXIOS_INSTANCE_TOKEN,
|
|
||||||
HTTP_MODULE_ID,
|
|
||||||
HTTP_MODULE_OPTIONS,
|
|
||||||
} from './http.constants';
|
|
||||||
import { HttpService } from './http.service';
|
import { HttpService } from './http.service';
|
||||||
import {
|
import { HttpModuleAsyncOptions, HttpModuleOptions, HttpModuleOptionsFactory } from './interfaces';
|
||||||
HttpModuleAsyncOptions,
|
|
||||||
HttpModuleOptions,
|
|
||||||
HttpModuleOptionsFactory,
|
|
||||||
} from './interfaces';
|
|
||||||
import axiosRetry from 'axios-retry';
|
import axiosRetry from 'axios-retry';
|
||||||
import axiosBetterStacktrace from 'axios-better-stacktrace';
|
import axiosBetterStacktrace from 'axios-better-stacktrace';
|
||||||
|
|
||||||
|
@ -22,7 +14,7 @@ const createAxiosInstance = (config?: HttpModuleOptions) => {
|
||||||
axiosBetterStacktrace(axiosInstance);
|
axiosBetterStacktrace(axiosInstance);
|
||||||
}
|
}
|
||||||
return axiosInstance;
|
return axiosInstance;
|
||||||
}
|
};
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -71,29 +63,23 @@ export class HttpModule {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static createAsyncProviders(
|
private static createAsyncProviders(options: HttpModuleAsyncOptions): Provider[] {
|
||||||
options: HttpModuleAsyncOptions,
|
|
||||||
): Provider[] {
|
|
||||||
if (options.useExisting || options.useFactory) {
|
if (options.useExisting || options.useFactory) {
|
||||||
return [this.createAsyncOptionsProvider(options)];
|
return [this.createAsyncOptionsProvider(options)];
|
||||||
}
|
}
|
||||||
|
|
||||||
const providers = [
|
const providers = [this.createAsyncOptionsProvider(options)];
|
||||||
this.createAsyncOptionsProvider(options)
|
|
||||||
];
|
|
||||||
|
|
||||||
if (options.useClass)
|
if (options.useClass)
|
||||||
providers.push({
|
providers.push({
|
||||||
provide: options.useClass,
|
provide: options.useClass,
|
||||||
useClass: options.useClass,
|
useClass: options.useClass,
|
||||||
})
|
});
|
||||||
|
|
||||||
return providers;
|
return providers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static createAsyncOptionsProvider(
|
private static createAsyncOptionsProvider(options: HttpModuleAsyncOptions): Provider {
|
||||||
options: HttpModuleAsyncOptions,
|
|
||||||
): Provider {
|
|
||||||
if (options.useFactory) {
|
if (options.useFactory) {
|
||||||
return {
|
return {
|
||||||
provide: HTTP_MODULE_OPTIONS,
|
provide: HTTP_MODULE_OPTIONS,
|
||||||
|
@ -103,10 +89,8 @@ export class HttpModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
let inject;
|
let inject;
|
||||||
if (options.useExisting)
|
if (options.useExisting) inject = [options.useExisting];
|
||||||
inject = [options.useExisting];
|
else if (options.useClass) inject = [options.useClass];
|
||||||
else if (options.useClass)
|
|
||||||
inject = [options.useClass];
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
provide: HTTP_MODULE_OPTIONS,
|
provide: HTTP_MODULE_OPTIONS,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Inject } from '@nestjs/common';
|
import { Inject } from '@nestjs/common';
|
||||||
import Axios, { AxiosInstance } from 'axios';
|
import Axios, { AxiosInstance } from 'axios';
|
||||||
import { AXIOS_INSTANCE_TOKEN } from "./http.constants";
|
import { AXIOS_INSTANCE_TOKEN } from './http.constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class HttpService {
|
export class HttpService {
|
||||||
|
@ -28,6 +28,6 @@ export class HttpService {
|
||||||
}
|
}
|
||||||
|
|
||||||
get axiosRef(): AxiosInstance {
|
get axiosRef(): AxiosInstance {
|
||||||
return this.instance
|
return this.instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
export { HttpService } from './http.service'
|
export { HttpService } from './http.service';
|
||||||
export { HttpModule } from './http.module'
|
export { HttpModule } from './http.module';
|
||||||
export * from './interfaces'
|
export * from './interfaces';
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
import { ModuleMetadata, Provider, Type } from '@nestjs/common';
|
import { ModuleMetadata, Provider, Type } from '@nestjs/common';
|
||||||
import { AxiosRequestConfig } from 'axios';
|
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 {
|
export interface HttpModuleOptionsFactory {
|
||||||
createHttpOptions(): Promise<HttpModuleOptions> | HttpModuleOptions;
|
createHttpOptions(): Promise<HttpModuleOptions> | HttpModuleOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HttpModuleAsyncOptions
|
export interface HttpModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
||||||
extends Pick<ModuleMetadata, 'imports'> {
|
|
||||||
useExisting?: Type<HttpModuleOptionsFactory>;
|
useExisting?: Type<HttpModuleOptionsFactory>;
|
||||||
useClass?: Type<HttpModuleOptionsFactory>;
|
useClass?: Type<HttpModuleOptionsFactory>;
|
||||||
useFactory?: (
|
useFactory?: (...args: any[]) => Promise<HttpModuleOptions> | HttpModuleOptions;
|
||||||
...args: any[]
|
|
||||||
) => Promise<HttpModuleOptions> | HttpModuleOptions;
|
|
||||||
inject?: any[];
|
inject?: any[];
|
||||||
extraProviders?: Provider[];
|
extraProviders?: Provider[];
|
||||||
}
|
}
|
Loading…
Reference in a new issue