Skip to content

Commit

Permalink
Type Axios -> AxiosInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
1cedsoda committed Feb 1, 2024
1 parent 354da99 commit 00e8464
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 260 deletions.
2 changes: 1 addition & 1 deletion packages/ts-axios/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pastapi-ts-axios",
"version": "0.2.0",
"version": "0.2.1",
"main": "dist/index",
"types": "dist/index",
"files": [
Expand Down
4 changes: 2 additions & 2 deletions packages/ts-axios/src/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { fuck } from "./helpers";

export const apiClass = (ast: Operation[]) => `
export class Client {
public axiosInstance: Axios
public axiosInstance: AxiosInstance
constructor (
axiosInstance?: Axios,
axiosInstance?: AxiosInstance,
) {
this.axiosInstance = axiosInstance ?? axios.create()
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-axios/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const generate = (ops: Operation[], prettierConfig?: Options | undefined)
export const generateRaw = (ops: Operation[]): string => `${buildHeader()}
import { z } from "zod";
import axios, { AxiosRequestConfig, Axios } from "axios";
import axios, { AxiosRequestConfig, AxiosInstance } from "axios";
${operationNamespaces(ops)}
${apiClass(ops)}
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-axios/src/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const operationNamespace = (o: Operation) => {
)}
}
export const request = async (axios: Axios, vars: Variables, config?: AxiosRequestConfig<${
export const request = async (axios: AxiosInstance, vars: Variables, config?: AxiosRequestConfig<${
o.requestBodies.length > 0 ? `Pick<RequestBody, "body">` : `undefined`
}>) => axios.request<RequestBody, ResponseBody>({
method: "${o.method}",
Expand Down
20 changes: 10 additions & 10 deletions packages/ts-axios/test/api1/gen/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { z } from "zod";
import axios, { AxiosRequestConfig, Axios } from "axios";
import axios, { AxiosRequestConfig, AxiosInstance } from "axios";

export namespace GetUser {
export const requestBodySchemas = {};
Expand All @@ -30,7 +30,7 @@ export namespace GetUser {
export type Variables = RequestBody & {};

export const request = async (
axios: Axios,
axios: AxiosInstance,
vars: Variables,
config?: AxiosRequestConfig<undefined>,
) =>
Expand Down Expand Up @@ -71,7 +71,7 @@ export namespace PostUser {
export type Variables = RequestBody & {};

export const request = async (
axios: Axios,
axios: AxiosInstance,
vars: Variables,
config?: AxiosRequestConfig<Pick<RequestBody, "body">>,
) =>
Expand Down Expand Up @@ -113,7 +113,7 @@ export namespace GetUserId {
};

export const request = async (
axios: Axios,
axios: AxiosInstance,
vars: Variables,
config?: AxiosRequestConfig<undefined>,
) =>
Expand Down Expand Up @@ -155,7 +155,7 @@ export namespace GetCookie {
};

export const request = async (
axios: Axios,
axios: AxiosInstance,
vars: Variables,
config?: AxiosRequestConfig<undefined>,
) =>
Expand Down Expand Up @@ -201,7 +201,7 @@ export namespace GetHeader {
};

export const request = async (
axios: Axios,
axios: AxiosInstance,
vars: Variables,
config?: AxiosRequestConfig<undefined>,
) =>
Expand Down Expand Up @@ -250,7 +250,7 @@ export namespace GetQuery {
};

export const request = async (
axios: Axios,
axios: AxiosInstance,
vars: Variables,
config?: AxiosRequestConfig<undefined>,
) =>
Expand Down Expand Up @@ -289,7 +289,7 @@ export namespace GetError {
export type Variables = RequestBody & {};

export const request = async (
axios: Axios,
axios: AxiosInstance,
vars: Variables,
config?: AxiosRequestConfig<undefined>,
) =>
Expand All @@ -304,8 +304,8 @@ export namespace GetError {
}

export class Client {
public axiosInstance: Axios;
constructor(axiosInstance?: Axios) {
public axiosInstance: AxiosInstance;
constructor(axiosInstance?: AxiosInstance) {
this.axiosInstance = axiosInstance ?? axios.create();
}

Expand Down
Loading

0 comments on commit 00e8464

Please sign in to comment.