-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Vlad Frangu <[email protected]>
- Loading branch information
1 parent
ee3e7c3
commit 7e828a8
Showing
36 changed files
with
541 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": [ | ||
"@apify/ts" | ||
], | ||
"parserOptions": { | ||
"project": "tsconfig.eslint.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# This file tells Git which files shouldn't be added to source control | ||
|
||
dist | ||
.idea | ||
node_modules | ||
coverage | ||
package-lock.json | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
legacy-peer-deps=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Config } from '@jest/types'; | ||
|
||
export default async (): Promise<Config.InitialOptions> => ({ | ||
verbose: true, | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testRunner: 'jest-circus/runner', | ||
testTimeout: 20_000, | ||
collectCoverage: true, | ||
collectCoverageFrom: [ | ||
'**/src/**/*.ts', | ||
'**/src/**/*.js', | ||
'!**/node_modules/**', | ||
], | ||
maxWorkers: 3, | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/test/tsconfig.json', | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Agent as HttpAgent, AgentOptions, ClientRequest, ClientRequestArgs } from 'http'; | ||
|
||
/** | ||
* @see https://github.com/nodejs/node/blob/533cafcf7e3ab72e98a2478bc69aedfdf06d3a5e/lib/_http_client.js#L129-L162 | ||
* @see https://github.com/nodejs/node/blob/533cafcf7e3ab72e98a2478bc69aedfdf06d3a5e/lib/_http_client.js#L234-L246 | ||
* @see https://github.com/nodejs/node/blob/533cafcf7e3ab72e98a2478bc69aedfdf06d3a5e/lib/_http_client.js#L304-L305 | ||
* Wraps an existing Agent instance, | ||
* so there's no need to replace `agent.addRequest`. | ||
*/ | ||
export class WrappedAgent<T extends HttpAgent> implements HttpAgent { | ||
agent: T; | ||
|
||
constructor(agent: T) { | ||
this.agent = agent; | ||
} | ||
|
||
addRequest(request: ClientRequest, options: ClientRequestArgs): void { | ||
// @ts-expect-error @types/node has incorrect types | ||
this.agent.addRequest(request, options); | ||
} | ||
|
||
get keepAlive(): boolean { | ||
// @ts-expect-error @types/node has incorrect types | ||
return this.agent.keepAlive; | ||
} | ||
|
||
get maxSockets(): HttpAgent['maxSockets'] { | ||
return this.agent.maxSockets; | ||
} | ||
|
||
get options(): AgentOptions { | ||
// @ts-expect-error @types/node has incorrect types | ||
return this.agent.options; | ||
} | ||
|
||
get defaultPort(): number { | ||
// @ts-expect-error @types/node has incorrect types | ||
return this.agent.defaultPort; | ||
} | ||
|
||
get protocol(): string { | ||
// @ts-expect-error @types/node has incorrect types | ||
return this.agent.protocol; | ||
} | ||
|
||
destroy(): void { | ||
this.agent.destroy(); | ||
} | ||
|
||
// Let's implement `HttpAgent` so we don't have to | ||
// type `WrappedAgent as unknown as HttpAgent` | ||
get maxFreeSockets(): HttpAgent['maxFreeSockets'] { | ||
return this.agent.maxFreeSockets; | ||
} | ||
|
||
get maxTotalSockets(): HttpAgent['maxTotalSockets'] { | ||
return this.agent.maxTotalSockets; | ||
} | ||
|
||
get freeSockets(): HttpAgent['freeSockets'] { | ||
return this.agent.freeSockets; | ||
} | ||
|
||
get sockets(): HttpAgent['sockets'] { | ||
return this.agent.sockets; | ||
} | ||
|
||
get requests(): HttpAgent['requests'] { | ||
return this.agent.requests; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { OptionsInit as GotOptionsInit } from 'got-cjs'; | ||
|
||
export { GotOptionsInit }; | ||
|
||
export interface Context extends Record<string, unknown> { | ||
proxyUrl?: string; | ||
headerGeneratorOptions?: Record<string, unknown>; | ||
useHeaderGenerator?: boolean; | ||
headerGenerator?: { getHeaders: (options: Record<string, unknown>) => Record<string, string> }; | ||
insecureHTTPParser?: boolean; | ||
} | ||
|
||
export interface OptionsInit extends Context, GotOptionsInit {} |
Oops, something went wrong.