Skip to content

Commit

Permalink
fix: improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
simllll committed Oct 13, 2021
1 parent 2b67aa0 commit 51f3caf
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 58 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hokify/nuxt-haxios-module",
"version": "1.1.3",
"version": "1.1.4",
"description": "Secure and easy Haxios integration with Nuxt.js",
"license": "MIT",
"contributors": [
Expand All @@ -27,7 +27,7 @@
"@nuxtjs/proxy": "^2.1.0",
"consola": "^2.15.3",
"defu": "^5.0.0",
"haxios": "^1.0.29",
"haxios": "^1.0.30",
"null-loader": "^4.0.1"
},
"devDependencies": {
Expand Down
154 changes: 98 additions & 56 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,131 @@
import { AxiosError, HAxiosRequestConfig, AxiosRequestConfig, AxiosResponse, AxiosStatic, AxiosConfig } from 'haxios'
import Vue from 'vue'
import './vuex'
import {
AxiosError,
HAxiosRequestConfig,
AxiosRequestConfig,
AxiosResponse,
AxiosStatic,
AxiosConfig,
DefaultRequestConfig
} from 'haxios';
import Vue from 'vue';
import './vuex';

interface NuxtAxiosInstance extends AxiosStatic {
$request<
RETURN = any,
INPUT = any,
CONFIG extends HAxiosRequestConfig<INPUT> = HAxiosRequestConfig<INPUT>
>(config?: CONFIG): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>
CONFIG extends HAxiosRequestConfig<INPUT> = DefaultRequestConfig<INPUT>
>(
config?: CONFIG
): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>;
$get<
RETURN = any,
INPUT = any,
CONFIG extends HAxiosRequestConfig<INPUT> = HAxiosRequestConfig<INPUT>
>(url: string, config?: CONFIG): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>
CONFIG extends HAxiosRequestConfig<INPUT> = DefaultRequestConfig<INPUT>
>(
url: string,
config?: CONFIG
): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>;
$delete<
RETURN = any,
INPUT = any,
CONFIG extends HAxiosRequestConfig<INPUT> = HAxiosRequestConfig<INPUT>
>(url: string, config?: CONFIG): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>
CONFIG extends HAxiosRequestConfig<INPUT> = DefaultRequestConfig<INPUT>
>(
url: string,
config?: CONFIG
): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>;
$head<
RETURN = any,
INPUT = any,
CONFIG extends HAxiosRequestConfig<INPUT> = HAxiosRequestConfig<INPUT>
>(url: string, config?: CONFIG): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>
CONFIG extends HAxiosRequestConfig<INPUT> = DefaultRequestConfig<INPUT>
>(
url: string,
config?: CONFIG
): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>;
$options<
RETURN = any,
INPUT = any,
CONFIG extends HAxiosRequestConfig<INPUT> = HAxiosRequestConfig<INPUT>
>(url: string, config?: CONFIG): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>
CONFIG extends HAxiosRequestConfig<INPUT> = DefaultRequestConfig<INPUT>
>(
url: string,
config?: CONFIG
): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>;
$post<
RETURN = any,
INPUT = any,
CONFIG extends HAxiosRequestConfig<INPUT> = HAxiosRequestConfig<INPUT>
>(url: string, data?: INPUT, config?: CONFIG): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>
CONFIG extends HAxiosRequestConfig<INPUT> = DefaultRequestConfig<INPUT>
>(
url: string,
data?: INPUT,
config?: CONFIG
): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>;
$put<
RETURN = any,
INPUT = any,
CONFIG extends HAxiosRequestConfig<INPUT> = HAxiosRequestConfig<INPUT>
>(url: string, data?: any, config?: CONFIG): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>
CONFIG extends HAxiosRequestConfig<INPUT> = DefaultRequestConfig<INPUT>
>(
url: string,
data?: any,
config?: CONFIG
): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>;
$patch<
RETURN = any,
INPUT = any,
CONFIG extends HAxiosRequestConfig<INPUT> = HAxiosRequestConfig<INPUT>
>(url: string, data?: any, config?: CONFIG): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>
CONFIG extends HAxiosRequestConfig<INPUT> = DefaultRequestConfig<INPUT>
>(
url: string,
data?: any,
config?: CONFIG
): Promise<AxiosResponse<RETURN, INPUT, CONFIG>['data']>;

setBaseURL(baseURL: string): void
setHeader(name: string, value?: string | false, scopes?: string | string[]): void
setToken(token: string | false, type?: string, scopes?: string | string[]): void
setBaseURL(baseURL: string): void;
setHeader(name: string, value?: string | false, scopes?: string | string[]): void;
setToken(token: string | false, type?: string, scopes?: string | string[]): void;

onRequest(callback: (config: HAxiosRequestConfig) => void | HAxiosRequestConfig | Promise<HAxiosRequestConfig>): void
onRequest(
callback: (
config: HAxiosRequestConfig
) => void | HAxiosRequestConfig | Promise<HAxiosRequestConfig>
): void;
onResponse<
RETURN = any,
INPUT = any,
CONFIG extends HAxiosRequestConfig<INPUT> = HAxiosRequestConfig<INPUT>
>(callback: (response: AxiosResponse<RETURN, INPUT, CONFIG>) => void | AxiosResponse<RETURN, INPUT, CONFIG> | Promise<AxiosResponse<RETURN, INPUT, CONFIG>> ): void
onError(callback: (error: AxiosError) => any): void
onRequestError(callback: (error: AxiosError) => any): void
onResponseError(callback: (error: AxiosError) => any): void
CONFIG extends HAxiosRequestConfig<INPUT> = DefaultRequestConfig<INPUT>
>(
callback: (
response: AxiosResponse<RETURN, INPUT, CONFIG>
) => void | AxiosResponse<RETURN, INPUT, CONFIG> | Promise<AxiosResponse<RETURN, INPUT, CONFIG>>
): void;
onError(callback: (error: AxiosError) => any): void;
onRequestError(callback: (error: AxiosError) => any): void;
onResponseError(callback: (error: AxiosError) => any): void;

create(options?: HAxiosRequestConfig): NuxtAxiosInstance
create(options?: HAxiosRequestConfig): NuxtAxiosInstance;
}

interface AxiosOptions {
baseURL?: string,
browserBaseURL?: string,
credentials?: boolean,
debug?: boolean,
host?: string,
prefix?: string,
progress?: boolean,
proxyHeaders?: boolean,
proxyHeadersIgnore?: string[],
proxy?: boolean,
port?: string | number,
retry?: boolean | AxiosConfig['retryConfig'],
https?: boolean,
baseURL?: string;
browserBaseURL?: string;
credentials?: boolean;
debug?: boolean;
host?: string;
prefix?: string;
progress?: boolean;
proxyHeaders?: boolean;
proxyHeadersIgnore?: string[];
proxy?: boolean;
port?: string | number;
retry?: boolean | AxiosConfig['retryConfig'];
https?: boolean;
headers?: {
common?: Record<string, string>,
delete?: Record<string, string>,
get?: Record<string, string>,
head?: Record<string, string>,
post?: Record<string, string>,
put?: Record<string, string>,
patch?: Record<string, string>,
},
common?: Record<string, string>;
delete?: Record<string, string>;
get?: Record<string, string>;
head?: Record<string, string>;
post?: Record<string, string>;
put?: Record<string, string>;
patch?: Record<string, string>;
};
}

declare module 'haxios' {
Expand All @@ -94,30 +136,30 @@ declare module 'haxios' {

declare module '@nuxt/vue-app' {
interface Context {
$axios: NuxtAxiosInstance
$axios: NuxtAxiosInstance;
}
interface NuxtAppOptions {
$axios: NuxtAxiosInstance
$axios: NuxtAxiosInstance;
}
}

// Nuxt 2.9+
declare module '@nuxt/types' {
interface Context {
$axios: NuxtAxiosInstance
$axios: NuxtAxiosInstance;
}

interface NuxtAppOptions {
$axios: NuxtAxiosInstance
$axios: NuxtAxiosInstance;
}

interface Configuration {
axios?: AxiosOptions
axios?: AxiosOptions;
}
}

declare module 'vue/types/vue' {
interface Vue {
$axios: NuxtAxiosInstance
$axios: NuxtAxiosInstance;
}
}

0 comments on commit 51f3caf

Please sign in to comment.