Skip to content

Commit

Permalink
remove node-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
enguerranws committed Oct 17, 2024
1 parent f66e8a1 commit 49fd25e
Show file tree
Hide file tree
Showing 8 changed files with 516 additions and 504 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
"rules": {
"no-extra-boolean-cast": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off"
},
};
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "[email protected]:JeromeBu/shared-routes.git"
},
"scripts": {
"typecheck": "tsc --noEmit -p test",
"typecheck": "tsc --noEmit",
"build": "pnpm build:cjs && pnpm build:esm # && pnpm build:deno",
"watch": "tsc -w & tsc -p tsconfig.esm.json -w",
"build:cjs": "tsc",
Expand Down Expand Up @@ -65,13 +65,12 @@
"husky": "^8.0.0",
"js2mjs": "^0.3.0",
"lint-staged": "^11.1.1",
"node-fetch": "^3.3.1",
"openapi-types": "^12.1.0",
"prettier": "^2.3.2",
"supertest": "^6.3.3",
"ts-node": "^10.9.1",
"typescript": "^5.3.2",
"vitest": "^0.31.0",
"typescript": "^5.6.2",
"vitest": "^2.1.2",
"zod": "^3.22.4",
"zod-to-json-schema": "^3.21.0"
},
Expand Down
985 changes: 502 additions & 483 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions src/fetch/createFetchSharedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type { HttpResponse, UnknownSharedRoute, Url } from "..";
import { configureCreateHttpClient, HandlerCreator } from "..";
import { ResponseType } from "../defineRoutes";
import { queryParamsToString } from "./queryParamsToString";
import type nodeFetch from "node-fetch";
import type { Response as FetchResponse } from "node-fetch";
import {
ValidationOptions,
validateInputParams,
Expand All @@ -20,12 +18,7 @@ const objectFromEntries = (
return result;
};

declare function browserFetch(
input: RequestInfo | URL,
init?: RequestInit,
): Promise<FetchResponse>;

type Fetch = typeof browserFetch | typeof nodeFetch;
type Fetch = typeof fetch;

type FetchConfig = RequestInit & { baseURL?: Url } & ValidationOptions;

Expand Down Expand Up @@ -68,7 +61,6 @@ export const createFetchHandlerCreator =
);

const processedBody = await responseTypeToResponseBody(res, route.responseType);

const responseBody =
options?.skipResponseValidation ||
options?.skipResponseValidationForStatuses?.includes(res.status)
Expand All @@ -81,15 +73,15 @@ export const createFetchHandlerCreator =
route,
withIssuesInMessage: true,
});

return {
body: responseBody,
status: res.status,
// @ts-ignore
headers: objectFromEntries(res.headers.entries()),
};
};

const responseTypeToResponseBody = (res: FetchResponse, responseType: ResponseType) => {
const responseTypeToResponseBody = (res: Response, responseType: ResponseType) => {
switch (responseType) {
case "json":
return res.json();
Expand Down
2 changes: 1 addition & 1 deletion src/openapi/createOpenApiGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const extractFromUrl = (
schema: { type: "string" },
in: "path",
});
return `{${group1}}` + group2 ?? "";
return `{${group1}}` + group2;
});

return {
Expand Down
2 changes: 1 addition & 1 deletion test/createAxiosAndFetchSharedClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { z } from "zod";
import { createAxiosSharedClient } from "../src/axios";
import { createFetchSharedClient } from "../src/fetch";
import { describe, it, expect } from "vitest";
import fetch from "node-fetch";

describe("createAxiosSharedCaller", () => {
it("create a caller from axios and sharedRoutes object", async () => {
Expand Down Expand Up @@ -41,6 +40,7 @@ describe("createAxiosSharedCaller", () => {

// the code below will not past test as no server is receiving the calls,
// but it is usefull to check that types are working fine.
// @ts-ignore
const _notExecuted = async () => {
const addBookResponse = await axiosSharedCaller.addBook({
body: { title: "lala", author: "bob" },
Expand Down
2 changes: 1 addition & 1 deletion test/expressAndSupertest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ const expectToMatch = <T>(actual: T, expected: Partial<T>) =>
// title: z.string(),
// author: z.string(),
// });

// @ts-ignore
const _routes = defineRoutes({
addBook: defineRoute({
method: "post",
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
"strict": true,
"downlevelIteration": true,
"jsx": "react-jsx",
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true
},
"include": ["src"],
"include": ["src", "test"],
"exclude": ["src/**/*.deno.ts", "src/**/*.deno.tsx"]
}

0 comments on commit 49fd25e

Please sign in to comment.