Skip to content

Commit f8b22bc

Browse files
kanadguptaerunion
andauthored
chore: various doc + typing + CI touchups (#270)
- [x] properly run typechecking during CI - [x] JSDocs + type enhancements - [x] super hard to notice bug fix --------- Co-authored-by: Jon Ursenbach <[email protected]>
1 parent f5e3d50 commit f8b22bc

File tree

6 files changed

+51
-14
lines changed

6 files changed

+51
-14
lines changed

package-lock.json

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"attw": "attw --pack --format table-flipped",
7171
"build": "tsup",
7272
"clean": "rm -rf dist/",
73-
"lint": "npm run lint:js && npm run prettier",
73+
"lint": "npm run lint:js && npm run prettier && tsc",
7474
"lint:js": "eslint . --ext .js,.cjs,.ts && prettier --check .",
7575
"prebuild": "npm run clean",
7676
"prepack": "npm run build",
@@ -80,7 +80,8 @@
8080
},
8181
"dependencies": {
8282
"qs": "^6.11.2",
83-
"stringify-object": "^3.3.0"
83+
"stringify-object": "^3.3.0",
84+
"type-fest": "^4.15.0"
8485
},
8586
"devDependencies": {
8687
"@readme/eslint-config": "^14.4.2",
@@ -94,7 +95,6 @@
9495
"prettier": "^3.0.3",
9596
"require-directory": "^2.1.1",
9697
"tsup": "^8.0.1",
97-
"type-fest": "^4.15.0",
9898
"typescript": "^5.4.4",
9999
"vitest": "^3.0.5"
100100
},

src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import type { CodeBuilderOptions } from './helpers/code-builder.js';
12
import type { ReducedHelperObject } from './helpers/reducer.js';
23
import type { ClientId, TargetId } from './targets/index.js';
34
import type { Param, PostDataCommon, Request as NpmHarRequest } from 'har-format';
45
import type { UrlWithParsedQuery } from 'node:url';
6+
import type { Merge } from 'type-fest';
57

68
import { format as urlFormat, parse as urlParse } from 'node:url';
79

@@ -25,6 +27,8 @@ type PostDataBase = PostDataCommon & {
2527
text?: string;
2628
};
2729

30+
export type { Client } from './targets/index.js';
31+
2832
export type HarRequest = Omit<NpmHarRequest, 'postData'> & { postData: PostDataBase };
2933

3034
export interface RequestExtras {
@@ -58,6 +62,8 @@ interface HarEntry {
5862
};
5963
}
6064

65+
export type Options = Merge<CodeBuilderOptions, Record<string, any>>;
66+
6167
export interface HTTPSnippetOptions {
6268
harIsAlreadyEncoded?: boolean;
6369
}
@@ -318,13 +324,13 @@ export class HTTPSnippet {
318324
};
319325
}
320326

321-
convert(targetId: TargetId, clientId?: ClientId, options?: any) {
327+
convert(targetId: TargetId, clientId?: ClientId, options?: Options) {
322328
if (!this.initCalled) {
323329
this.init();
324330
}
325331

326332
if (!options && clientId) {
327-
options = clientId;
333+
options = { clientId };
328334
}
329335

330336
const target = targets[targetId];
@@ -337,13 +343,13 @@ export class HTTPSnippet {
337343
return results;
338344
}
339345

340-
installation(targetId: TargetId, clientId?: ClientId, options?: any) {
346+
installation(targetId: TargetId, clientId?: ClientId, options?: Options) {
341347
if (!this.initCalled) {
342348
this.init();
343349
}
344350

345351
if (!options && clientId) {
346-
options = clientId;
352+
options = { clientId };
347353
}
348354

349355
const target = targets[targetId];

src/targets/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ describe('addTargetClient', () => {
303303
link: 'https://example.com',
304304
description: 'A custom HTTP library',
305305
extname: '.custom',
306-
installation: request => {
307-
return `brew install ${request.fullUrl}`;
306+
installation: (request, opts) => {
307+
return `brew install ${request.fullUrl}/${opts?.clientId}`;
308308
},
309309
},
310310
convert: () => {
@@ -320,7 +320,7 @@ describe('addTargetClient', () => {
320320
expect(result).toBe('This was generated from a custom client.');
321321

322322
const install = snippet.installation('node', 'custom')[0];
323-
expect(install).toBe('brew install https://httpbin.org/anything');
323+
expect(install).toBe('brew install https://httpbin.org/anything/custom');
324324
});
325325
});
326326

src/targets/index.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,47 @@ export type TargetId = keyof typeof targets;
2727
export type ClientId = string;
2828

2929
export interface ClientInfo<T extends Record<string, any> = Record<string, any>> {
30+
/**
31+
* A description of the client.
32+
*
33+
* @example Promise based HTTP client for the browser and node.js
34+
*/
3035
description: string;
36+
37+
/**
38+
* The default file extension for the client.
39+
*
40+
* @example `.js`
41+
*/
3142
extname: Extension;
3243
/**
3344
* Retrieve or generate a command to install the client.
3445
*
35-
* @example `npm install axios`
46+
* @example () => 'npm install axios --save';
3647
*/
3748
installation?: Converter<T>;
49+
50+
/**
51+
* A unique identifier for the client.
52+
*
53+
* This should be a string that is unique to the client for the given target.
54+
*
55+
* @example `axios`
56+
*/
3857
key: ClientId;
58+
59+
/**
60+
* A link to the documentation or homepage of the client.
61+
*
62+
* @example https://github.com/axios/axios
63+
*/
3964
link: string;
65+
66+
/**
67+
* The formatted name of the client.
68+
*
69+
* @example Axios
70+
*/
4071
title: string;
4172
}
4273

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"lib": ["DOM", "ES2020"],
88
"module": "ESNext",
99
"moduleResolution": "Bundler",
10+
"noEmit": true,
1011
"outDir": "dist",
1112
"resolveJsonModule": true,
1213
"target": "ES2020",

0 commit comments

Comments
 (0)