Skip to content

Commit

Permalink
refactor: use type instead of interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ruicsh committed Dec 8, 2023
1 parent 8e1dceb commit 4173f2c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ describe("creates an instance with options", () => {
it("simple json (GET) with generic type", async () => {
uri.pathname = "/file/simple.json";
const client = fletcher.create({ headers: { foo: "bar" } });
interface IFooBar {
type IFooBar = {
foo: string;
}
};
const actual = await client.json<IFooBar>(uri.href);

const expected: IFooBar = { foo: "bar" };
Expand Down
44 changes: 22 additions & 22 deletions src/fletcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,48 @@ export type FetchOptions = AxiosRequestConfig;

export { type ICookie, type CookieJar };

export interface IProxyConfig {
export type IProxyConfig = {
username?: string;
password?: string;
host: string;
port: number;
protocol?: string;
}
};

type RequestRedirect = "follow" | "error" | "manual";

type RequestData = Record<string, unknown>;

interface IOnAfterRequestArgs {
type IOnAfterRequestArgs = {
response: AxiosResponse;
}
};

export interface IOnAfterRequestFn {
export type IOnAfterRequestFn = {
(args: IOnAfterRequestArgs): Promise<void> | void;
}
};

export interface IFletcherBrowserUserOptions {
export type IFletcherBrowserUserOptions = {
blockedResourceTypes: boolean | string[];
endpoint: string;
onPageReady: (page: Page) => Promise<unknown>;
screenshot: ScreenshotOptions;
waitForSelector: string;
}
};

export interface ICacheParams {
export type ICacheParams = {
format: string;
url: string;
options?: Partial<IFletcherUserOptions>;
payload?: string;
}
};

export interface IFletcherCacheMethods {
export type IFletcherCacheMethods = {
hit: (key: string) => null | unknown;
write: (key: string, payload?: string) => void;
key: (params: ICacheParams) => string;
}
};

export interface IFletcherUserOptions {
export type IFletcherUserOptions = {
browser: Partial<IFletcherBrowserUserOptions>;
cache: boolean;
cacheMethods: Partial<IFletcherCacheMethods>;
Expand All @@ -85,9 +85,9 @@ export interface IFletcherUserOptions {
urlSearchParams: UrlSearchParams;
userAgent: string;
validateStatus: (statusCode: number) => boolean;
}
};

export interface IFletcherOptions {
export type IFletcherOptions = {
body?: string;
cache: boolean;
delay: number;
Expand All @@ -102,13 +102,13 @@ export interface IFletcherOptions {
timeout: number;
url: string;
validateStatus: (statusCode: number) => boolean;
}
};

interface IInstanceMethod<T> {
type IInstanceMethod<T> = {
(url: string, options?: Partial<IFletcherUserOptions>): Promise<T>;
}
};

export interface IInstance {
export type IInstance = {
embeddedJson: <T = unknown>(
url: string,
options?: Partial<IFletcherUserOptions>
Expand Down Expand Up @@ -142,12 +142,12 @@ export interface IInstance {
) => Promise<T>;
jsonld: IInstanceMethod<unknown[]>;
};
}
};

export interface IResponse {
export type IResponse = {
// body: Readable & Dispatcher.BodyMixin;
headers: AxiosResponseHeaders;
statusCode: number;
statusMessage?: string;
text: () => Promise<string>;
}
};
12 changes: 6 additions & 6 deletions src/helpers/async-retry.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import retrier, { type WrapOptions } from "retry";

export interface IOptions extends WrapOptions {
export type IOptions = WrapOptions & {
onRetry?: ((e: Error, attempt: number) => unknown) | undefined;
}
};

interface IErrorWithBail extends Error {
type IErrorWithBail = Error & {
bail?: (error: Error) => void;
}
};

interface IAsyncFn<T> {
type IAsyncFn<T> = {
(...args: unknown[]): Promise<T>;
}
};

export function retry<T>(fn: IAsyncFn<T>, opts: IOptions): Promise<T> {
function run(
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/cookie-jar.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable class-methods-use-this */
import Cookie from "cookie";

export interface ICookie {
export type ICookie = {
key: string;
value: string;
}
};

export class CookieJar {
cookies: ICookie[] = [];
Expand Down
4 changes: 2 additions & 2 deletions src/script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ describe("inline scripts", () => {

it("evaluates a script and returns its global scope", async () => {
uri.pathname = "/file/inline-script.html";
interface IPageData {
type IPageData = {
pageData: { foo: string };
}
};
const actual = await fletcher.script<IPageData>(uri.href, {
scriptPath: "script:nth-of-type(1)",
});
Expand Down
4 changes: 2 additions & 2 deletions src/services/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { Cache } from "../options/cache";
import { getJsonLd } from "../options/json-ld";
import { getScript } from "../options/script";

interface IExecutorFn<T = unknown> {
type IExecutorFn<T = unknown> = {
(page: Page): Promise<T>;
}
};

const cache = new Cache();

Expand Down

0 comments on commit 4173f2c

Please sign in to comment.