Skip to content

Commit e5991d1

Browse files
committed
chore: custom json type + pipeline
1 parent bfc546c commit e5991d1

4 files changed

Lines changed: 20 additions & 26 deletions

File tree

.github/workflows/pipeline.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Pipeline
22

3+
permissions:
4+
contents: read
5+
36
on:
47
push:
58
branches:
@@ -17,7 +20,7 @@ jobs:
1720
runs-on: ubuntu-latest
1821
strategy:
1922
matrix:
20-
node-version: [24.x, 22.x]
23+
node-version: [22.x, 24.x]
2124
fail-fast: true
2225

2326
steps:
@@ -35,11 +38,11 @@ jobs:
3538
- name: Install dependencies
3639
run: pnpm i
3740

38-
- name: Run ESLint
39-
run: pnpm run lint
41+
- name: Run lint
42+
run: pnpm lint
4043

4144
- name: Run tests with coverage
42-
run: pnpm test -- --coverage
45+
run: pnpm tc
4346

4447
- name: Upload coverage reports to Codecov
4548
if: github.ref_name == 'main'

src/request.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Curl, Easy, type HttpPostField } from "node-libcurl";
22
import type {
33
BufferEncoding,
4+
CustomJsonType,
45
GetJSON,
56
HttpVerb,
67
Options,
@@ -49,7 +50,7 @@ const createCurlObjectWithDefaults = (
4950
const handleQueryString = (
5051
curl: Easy,
5152
url: string,
52-
qs?: { [key: string]: any },
53+
qs?: { [key: string]: unknown },
5354
): void => {
5455
url = qs && Object.keys(qs).length ? handleQs(url, qs) : url;
5556
curl.setOpt(Curl.option.URL, url);
@@ -75,7 +76,11 @@ const handleOutgoingHeaders = (curl: Easy, returnedHeaderArray: string[]) => {
7576
* @param {any} json - The JSON body to be sent
7677
* @param {string[]} httpHeaders - HTTP headers for the request
7778
*/
78-
const setJSONPayload = (curl: Easy, json: any, httpHeaders: string[]): void => {
79+
const setJSONPayload = (
80+
curl: Easy,
81+
json: CustomJsonType,
82+
httpHeaders: string[],
83+
): void => {
7984
httpHeaders.push("Content-Type: application/json");
8085
const payload = JSON.stringify(json);
8186
httpHeaders.push(`Content-Length: ${Buffer.byteLength(payload, "utf-8")}`);

src/types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { IncomingHttpHeaders } from "http";
22
import type { CurlOption, Easy, HttpPostField } from "node-libcurl";
33

4+
// biome-ignore lint/suspicious/noExplicitAny: to match sync-request input type
5+
export type CustomJsonType = any;
6+
47
export type HttpVerb =
58
| "GET"
69
| "HEAD"
@@ -32,14 +35,14 @@ export type SetEasyOptionCallback = (
3235

3336
export interface Options {
3437
headers?: IncomingHttpHeaders;
35-
qs?: { [key: string]: any };
38+
qs?: { [key: string]: CustomJsonType };
3639

3740
// You should only specify one of these.
3841
// They are processed in the order listed below.
3942
//
4043
// When no json, body or formdata is provided, Content-Length = 0
4144
// will be set in the headers.
42-
json?: any;
45+
json?: CustomJsonType;
4346
body?: string | Buffer;
4447
formData?: HttpPostField[];
4548

@@ -57,7 +60,7 @@ export type GetBody = {
5760
(encoding?: undefined): Buffer;
5861
};
5962

60-
export type GetJSON = <T = any>(encoding?: BufferEncoding) => T;
63+
export type GetJSON = <T = CustomJsonType>(encoding?: BufferEncoding) => T;
6164

6265
export interface Response {
6366
statusCode: number;

tests/app/errorHandler.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)