Skip to content

Commit

Permalink
feat(types): Enhance any types (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion authored Dec 27, 2022
1 parent cb1a114 commit 4485156
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.yarn.**/*
.yarn/**/*
build/**/*
dist/**/*
node_modules/**/*
17 changes: 12 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@ import { RxjsAxios } from "./lib/RxjsAxios";
export type AxiosObservable<T> = Observable<AxiosResponse<T>>;

/**
* Re-export all everithing from axios, except anything to do with promises.
* Re-export all everything from axios, except anything to do with promises or
* types enhencements
*/
export {
AxiosError,
CanceledError,
type AxiosAdapter,
type AxiosBasicCredentials,
type AxiosDefaults,
type AxiosHeaders,
type AxiosInterceptorManager,
type AxiosInterceptorOptions,
type AxiosProgressEvent,
type AxiosProxyConfig,
type AxiosRequestConfig,
type AxiosRequestHeaders,
type AxiosRequestTransformer,
type AxiosResponse,
type AxiosResponseHeaders,
type AxiosResponseTransformer,
type CreateAxiosDefaults,
type CustomParamsSerializer,
type FormDataVisitorHelpers,
Expand All @@ -45,6 +43,15 @@ export {
type TransitionalOptions,
type responseEncoding,
} from "axios";
export { RxjsAxios as Axios } from "./lib/RxjsAxios";

/**
* Export rxjs-axios especifics
*/
export {
RxjsAxios as Axios,
AxiosRequestTransformer,
AxiosResponseTransformer,
RxjsAxiosDefaults as AxiosDefaults,
} from "./lib/RxjsAxios";

export const axios = RxjsAxios.of(defaultAxios);
27 changes: 23 additions & 4 deletions src/lib/RxjsAxios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import axios, {
AxiosInstance,
AxiosInterceptorManager,
AxiosRequestConfig,
AxiosResponse, Cancel,
AxiosRequestHeaders,
AxiosResponse, AxiosResponseHeaders, Cancel,
CreateAxiosDefaults,
FormSerializerOptions,
GenericFormData,
Expand All @@ -14,9 +15,27 @@ import { Observable } from "rxjs";

import { observify } from "./observify";

export type AxiosRequestTransformer<T> = (
this: AxiosRequestConfig<T>,
data: T,
headers: AxiosRequestHeaders
) => T;

export type AxiosResponseTransformer<T> = (
this: AxiosRequestConfig<T>,
data: T,
headers: AxiosResponseHeaders,
status?: number
) => T;

export interface RxjsAxiosDefaults<T = unknown> extends AxiosDefaults<T> {
transformRequest?: AxiosRequestTransformer<T> | AxiosRequestTransformer<T>[];
transformResponse?: AxiosResponseTransformer<T> | AxiosResponseTransformer<T>[];
}

interface Interceptors {
request: AxiosInterceptorManager<AxiosRequestConfig>;
response: AxiosInterceptorManager<AxiosResponse>;
request: AxiosInterceptorManager<AxiosRequestConfig<unknown>>;
response: AxiosInterceptorManager<AxiosResponse<unknown>>;
}

interface Abortable {
Expand Down Expand Up @@ -62,7 +81,7 @@ export class RxjsAxios {
return axios.formToJSON(form);
}

public get defaults(): AxiosDefaults {
public get defaults(): RxjsAxiosDefaults {
return this.axios.defaults;
}

Expand Down

0 comments on commit 4485156

Please sign in to comment.