Skip to content

Commit 6648fd4

Browse files
committed
feat: enabling isolatedDeclarations
1 parent f8b22bc commit 6648fd4

File tree

13 files changed

+68
-36
lines changed

13 files changed

+68
-36
lines changed

src/fixtures/runCustomFixtures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface CustomFixture {
2222
}[];
2323
}
2424

25-
export const runCustomFixtures = ({ targetId, clientId, tests }: CustomFixture) => {
25+
export const runCustomFixtures = ({ targetId, clientId, tests }: CustomFixture): void => {
2626
describe(`custom fixtures for ${targetId}:${clientId}`, () => {
2727
it.each(tests.map(t => [t.it, t]))('%s', async (_, { expected: fixtureFile, options, input: request }) => {
2828
const opts: HTTPSnippetOptions = {};

src/helpers/code-builder.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class CodeBuilder {
2424

2525
indentationCharacter: string = DEFAULT_INDENTATION_CHARACTER;
2626

27-
lineJoin = DEFAULT_LINE_JOIN;
27+
lineJoin: string = DEFAULT_LINE_JOIN;
2828

2929
/**
3030
* Helper object to format and aggragate lines of code.
@@ -46,30 +46,30 @@ export class CodeBuilder {
4646
/**
4747
* Add the line at the beginning of the current lines
4848
*/
49-
unshift = (line: string, indentationLevel?: number) => {
49+
unshift = (line: string, indentationLevel?: number): void => {
5050
const newLine = this.indentLine(line, indentationLevel);
5151
this.code.unshift(newLine);
5252
};
5353

5454
/**
5555
* Add the line at the end of the current lines
5656
*/
57-
push = (line: string, indentationLevel?: number) => {
57+
push = (line: string, indentationLevel?: number): void => {
5858
const newLine = this.indentLine(line, indentationLevel);
5959
this.code.push(newLine);
6060
};
6161

6262
/**
6363
* Add an empty line at the end of current lines
6464
*/
65-
blank = () => {
65+
blank = (): void => {
6666
this.code.push('');
6767
};
6868

6969
/**
7070
* Concatenate all current lines using the given lineJoin, then apply any replacers that may have been added
7171
*/
72-
join = () => {
72+
join = (): string => {
7373
const unreplacedCode = this.code.join(this.lineJoin);
7474
const replacedOutput = this.postProcessors.reduce((accumulator, replacer) => replacer(accumulator), unreplacedCode);
7575
return replacedOutput;
@@ -79,7 +79,7 @@ export class CodeBuilder {
7979
* Often when writing modules you may wish to add a literal tag or bit of metadata that you wish to transform after other processing as a final step.
8080
* To do so, you can provide a PostProcessor function and it will be run automatically for you when you call `join()` later on.
8181
*/
82-
addPostProcessor = (postProcessor: PostProcessor) => {
82+
addPostProcessor = (postProcessor: PostProcessor): void => {
8383
this.postProcessors = [...this.postProcessors, postProcessor];
8484
};
8585
}

src/helpers/escape.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface EscapeOptions {
3030
* See https://tc39.es/ecma262/multipage/structured-data.html#sec-quotejsonstring
3131
* for the complete original algorithm.
3232
*/
33-
export function escapeString(rawValue: any, options: EscapeOptions = {}) {
33+
export function escapeString(rawValue: any, options: EscapeOptions = {}): string {
3434
const { delimiter = '"', escapeChar = '\\', escapeNewlines = true } = options;
3535

3636
const stringValue = rawValue.toString();
@@ -79,7 +79,7 @@ export function escapeString(rawValue: any, options: EscapeOptions = {}) {
7979
*
8080
* If value is not a string, it will be stringified with .toString() first.
8181
*/
82-
export const escapeForSingleQuotes = (value: any) => escapeString(value, { delimiter: "'" });
82+
export const escapeForSingleQuotes = (value: any): string => escapeString(value, { delimiter: "'" });
8383

8484
/**
8585
* Make a string value safe to insert literally into a snippet within double quotes,
@@ -88,4 +88,4 @@ export const escapeForSingleQuotes = (value: any) => escapeString(value, { delim
8888
*
8989
* If value is not a string, it will be stringified with .toString() first.
9090
*/
91-
export const escapeForDoubleQuotes = (value: any) => escapeString(value, { delimiter: '"' });
91+
export const escapeForDoubleQuotes = (value: any): string => escapeString(value, { delimiter: '"' });

src/helpers/headers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ type Headers<T> = Record<string, T>;
33
/**
44
* Given a headers object retrieve a specific header out of it via a case-insensitive key.
55
*/
6-
export const getHeaderName = <T>(headers: Headers<T>, name: string) =>
6+
export const getHeaderName = <T>(headers: Headers<T>, name: string): string | undefined =>
77
Object.keys(headers).find(header => header.toLowerCase() === name.toLowerCase());
88

99
/**
1010
* Given a headers object retrieve the contents of a header out of it via a case-insensitive key.
1111
*/
12-
export const getHeader = <T>(headers: Headers<T>, name: string) => {
12+
export const getHeader = <T>(headers: Headers<T>, name: string): T | undefined => {
1313
const headerName = getHeaderName(headers, name);
1414
if (!headerName) {
1515
return undefined;
@@ -20,12 +20,12 @@ export const getHeader = <T>(headers: Headers<T>, name: string) => {
2020
/**
2121
* Determine if a given case-insensitive header exists within a header object.
2222
*/
23-
export const hasHeader = <T>(headers: Headers<T>, name: string) => Boolean(getHeaderName(headers, name));
23+
export const hasHeader = <T>(headers: Headers<T>, name: string): boolean => Boolean(getHeaderName(headers, name));
2424

2525
/**
2626
* Determines if a given MIME type is JSON, or a variant of such.
2727
*/
28-
export const isMimeTypeJSON = (mimeType: string) =>
28+
export const isMimeTypeJSON = (mimeType: string): boolean =>
2929
['application/json', 'application/x-json', 'text/json', 'text/x-json', '+json'].some(
3030
type => mimeType.indexOf(type) > -1,
3131
);

src/helpers/reducer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
export type ReducedHelperObject = Record<string, string[] | string>;
22

3-
export const reducer = <T extends { name: string; value: string }>(accumulator: ReducedHelperObject, pair: T) => {
3+
export const reducer = <T extends { name: string; value: string }>(
4+
accumulator: ReducedHelperObject,
5+
pair: T,
6+
): ReducedHelperObject => {
47
const currentValue = accumulator[pair.name];
58
if (currentValue === undefined) {
69
accumulator[pair.name] = pair.value;

src/helpers/shell.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Use 'strong quoting' using single quotes so that we only need to deal with nested single quote characters.
33
* see: http://wiki.bash-hackers.org/syntax/quoting#strong_quoting
44
*/
5-
export const quote = (value = '') => {
5+
export const quote = (value = ''): string => {
66
const safe = /^[a-z0-9-_/.@%^=:]+$/i;
77

88
const isShellSafe = safe.test(value);
@@ -15,4 +15,4 @@ export const quote = (value = '') => {
1515
return `'${value.replace(/'/g, "'\\''")}'`;
1616
};
1717

18-
export const escape = (value: string) => value.replace(/\r/g, '\\r').replace(/\n/g, '\\n');
18+
export const escape = (value: string): string => value.replace(/\r/g, '\\r').replace(/\n/g, '\\n');

src/helpers/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ export interface AvailableTarget extends TargetInfo {
66
clients: ClientInfo[];
77
}
88

9-
export const availableTargets = () =>
9+
export const availableTargets = (): AvailableTarget[] =>
1010
Object.keys(targets).map<AvailableTarget>(targetId => ({
1111
...targets[targetId as TargetId].info,
1212
clients: Object.keys(targets[targetId as TargetId].clientsById).map(
1313
clientId => targets[targetId as TargetId].clientsById[clientId].info,
1414
),
1515
}));
1616

17-
export const extname = (targetId: TargetId, clientId: ClientId) => {
17+
export const extname = (targetId: TargetId, clientId: ClientId): '' | `.${string}` => {
1818
const target = targets[targetId];
1919
if (!target) {
2020
return '';

src/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('HTTPSnippet', () => {
1616
// @ts-expect-error intentionally incorrect
1717
const result = snippet.convert(null);
1818

19-
expect(result).toBe(false);
19+
expect(result).toStrictEqual([false]);
2020
});
2121

2222
describe('repair malformed `postData`', () => {

src/index.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class HTTPSnippet {
105105
}
106106
}
107107

108-
init() {
108+
init(): HTTPSnippet {
109109
this.initCalled = true;
110110

111111
this.requests = this.entries.map(({ request }) => {
@@ -134,7 +134,15 @@ export class HTTPSnippet {
134134
return this;
135135
}
136136

137-
prepare(harRequest: HarRequest, options: HTTPSnippetOptions) {
137+
prepare(
138+
harRequest: HarRequest,
139+
options: HTTPSnippetOptions,
140+
): Request & {
141+
allHeaders: Record<string, string[] | string>;
142+
fullUrl: string;
143+
url: any;
144+
uriObj: any;
145+
} {
138146
const request: Request = {
139147
...harRequest,
140148
fullUrl: '',
@@ -308,12 +316,12 @@ export class HTTPSnippet {
308316
...urlWithParsedQuery,
309317
query: null,
310318
search: null,
311-
}); //?
319+
});
312320

313321
const fullUrl = urlFormat({
314322
...urlWithParsedQuery,
315323
...uriObj,
316-
}); //?
324+
});
317325

318326
return {
319327
...request,
@@ -324,7 +332,7 @@ export class HTTPSnippet {
324332
};
325333
}
326334

327-
convert(targetId: TargetId, clientId?: ClientId, options?: Options) {
335+
convert(targetId: TargetId, clientId?: ClientId, options?: Options): (string | false)[] {
328336
if (!this.initCalled) {
329337
this.init();
330338
}
@@ -335,15 +343,15 @@ export class HTTPSnippet {
335343

336344
const target = targets[targetId];
337345
if (!target) {
338-
return false;
346+
return [false];
339347
}
340348

341349
const { convert } = target.clientsById[clientId || target.info.default];
342350
const results = this.requests.map(request => convert(request, options));
343351
return results;
344352
}
345353

346-
installation(targetId: TargetId, clientId?: ClientId, options?: Options) {
354+
installation(targetId: TargetId, clientId?: ClientId, options?: Options): (string | false)[] {
347355
if (!this.initCalled) {
348356
this.init();
349357
}

src/targets/index.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,28 @@ export interface Target {
100100
info: TargetInfo;
101101
}
102102

103-
export const targets = {
103+
type supportedTargets =
104+
| 'c'
105+
| 'clojure'
106+
| 'csharp'
107+
| 'go'
108+
| 'http'
109+
| 'java'
110+
| 'javascript'
111+
| 'json'
112+
| 'kotlin'
113+
| 'node'
114+
| 'objc'
115+
| 'ocaml'
116+
| 'php'
117+
| 'powershell'
118+
| 'python'
119+
| 'r'
120+
| 'ruby'
121+
| 'shell'
122+
| 'swift';
123+
124+
export const targets: Record<supportedTargets, Target> = {
104125
c,
105126
clojure,
106127
csharp,
@@ -181,7 +202,7 @@ export const isTarget = (target: Target): target is Target => {
181202
return true;
182203
};
183204

184-
export const addTarget = (target: Target) => {
205+
export const addTarget = (target: Target): void => {
185206
if (!isTarget(target)) {
186207
return;
187208
}
@@ -228,11 +249,11 @@ export const isClient = (client: Client): client is Client => {
228249
return true;
229250
};
230251

231-
export const addClientPlugin = (plugin: ClientPlugin) => {
252+
export const addClientPlugin = (plugin: ClientPlugin): void => {
232253
addTargetClient(plugin.target, plugin.client);
233254
};
234255

235-
export const addTargetClient = (targetId: TargetId, client: Client) => {
256+
export const addTargetClient = (targetId: TargetId, client: Client): void => {
236257
if (!isClient(client)) {
237258
return;
238259
}

0 commit comments

Comments
 (0)