Skip to content

Commit

Permalink
upgrade node-fetch v3 and remove uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
sofisl committed Feb 15, 2025
1 parent 8db2694 commit 6f06e53
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/TeenyStatistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class TeenyStatistics {
this._options.concurrentRequests +
'. Use the TEENY_REQUEST_WARN_CONCURRENT_REQUESTS environment ' +
'variable or the concurrentRequests option of teeny-request to ' +
'increase or disable (0) this warning.',
'increase or disable (0) this warning.'

Check failure on line 156 in src/TeenyStatistics.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
warning.type = TeenyStatisticsWarning.CONCURRENT_REQUESTS;
warning.value = this._concurrentRequests;
Expand Down Expand Up @@ -187,7 +187,7 @@ export class TeenyStatistics {
let concurrentRequests = this.DEFAULT_WARN_CONCURRENT_REQUESTS;

const envConcurrentRequests = Number(
process.env.TEENY_REQUEST_WARN_CONCURRENT_REQUESTS,
process.env.TEENY_REQUEST_WARN_CONCURRENT_REQUESTS

Check failure on line 190 in src/TeenyStatistics.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
if (diConcurrentRequests !== undefined) {
concurrentRequests = diConcurrentRequests;
Expand Down
2 changes: 1 addition & 1 deletion src/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function shouldUseProxyForURI(uri: string): boolean {
*/
export function getAgent(
uri: string,
reqOpts: Options,
reqOpts: Options

Check failure on line 69 in src/agents.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
): HttpAnyAgent | undefined {
const isHttp = uri.startsWith('http://');
const proxy =
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {Agent, AgentOptions as HttpsAgentOptions} from 'https';
import {AgentOptions as HttpAgentOptions} from 'http';
import type * as f from 'node-fetch' with {'resolution-mode': 'import'};
import {PassThrough, Readable, pipeline} from 'stream';
import * as uuid from 'uuid';
import {getAgent} from './agents';
import {TeenyStatistics} from './TeenyStatistics';
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -213,7 +212,7 @@ function teenyRequest(
// TODO: add support for multipart uploads through streaming
throw new Error('Multipart without callback is not implemented.');
}
const boundary: string = uuid.v4();
const boundary: string = globalThis.crypto?.randomUUID();
(options.headers as Headers)['Content-Type'] =
`multipart/related; boundary=${boundary}`;
options.body = createMultipartStream(boundary, multipart);
Expand Down
22 changes: 11 additions & 11 deletions test/TeenyStatistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('TeenyStatistics', () => {
it('should have default concurrent requests', () => {
assert.strictEqual(
TeenyStatistics.DEFAULT_WARN_CONCURRENT_REQUESTS,
5000,
5000

Check failure on line 68 in test/TeenyStatistics.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
});

Expand Down Expand Up @@ -231,8 +231,8 @@ describe('TeenyStatistics', () => {
t.requestStarting();
assert(
emitWarnStub.calledOnceWith(
sinon.match.instanceOf(TeenyStatisticsWarning),
),
sinon.match.instanceOf(TeenyStatisticsWarning)

Check failure on line 234 in test/TeenyStatistics.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
)

Check failure on line 235 in test/TeenyStatistics.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
});

Expand All @@ -246,8 +246,8 @@ describe('TeenyStatistics', () => {
t.requestStarting();
assert(
emitWarnStub.calledOnceWith(
sinon.match.instanceOf(TeenyStatisticsWarning),
),
sinon.match.instanceOf(TeenyStatisticsWarning)

Check failure on line 249 in test/TeenyStatistics.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
)

Check failure on line 250 in test/TeenyStatistics.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);

// shouldn't emit on the next call (i.e. still greater than threshold)
Expand All @@ -271,8 +271,8 @@ describe('TeenyStatistics', () => {
t.requestStarting();
assert(
emitWarnStub.calledOnceWith(
sinon.match.instanceOf(TeenyStatisticsWarning),
),
sinon.match.instanceOf(TeenyStatisticsWarning)

Check failure on line 274 in test/TeenyStatistics.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
)

Check failure on line 275 in test/TeenyStatistics.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);

// let's bring the counter back down
Expand All @@ -298,7 +298,7 @@ describe('TeenyStatistics', () => {
assert.strictEqual(warning.value, 5e3);
assert.strictEqual(
warning.type,
TeenyStatisticsWarning.CONCURRENT_REQUESTS,
TeenyStatisticsWarning.CONCURRENT_REQUESTS
);
});

Expand All @@ -311,15 +311,15 @@ describe('TeenyStatistics', () => {
const errStr: string = emitWarnStub.firstCall.args[0].toString();
assert(
errStr.includes('Possible excessive concurrent requests detected.'),
'describes the nature of the warning',
'describes the nature of the warning'
);
assert(
errStr.includes('TEENY_REQUEST_WARN_CONCURRENT_REQUESTS'),
'mentions env var',
'mentions env var'
);
assert(
errStr.includes('concurrentRequests'),
'mentions concurrentRequests option',
'mentions concurrentRequests option'
);
assert(errStr.search(/\b0\b/) !== -1, 'mentions 0');
});
Expand Down
8 changes: 4 additions & 4 deletions test/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe('agents', () => {
maxSockets: 1000,
},
},
defaultOptions,
defaultOptions
);
const agent = getAgent(uri, options);
assert.strictEqual(agent!.maxSockets, 1000);
Expand All @@ -224,7 +224,7 @@ describe('agents', () => {
maxSockets: 1000,
},
},
defaultOptions,
defaultOptions
);
const agent = getAgent(uri, options);
assert.strictEqual(agent, undefined);
Expand All @@ -243,7 +243,7 @@ describe('agents', () => {
maxSockets: 1000,
},
},
defaultOptions,
defaultOptions
);
const agent = getAgent(uri, options);
assert.strictEqual(agent!.maxSockets, 1000);
Expand All @@ -256,7 +256,7 @@ describe('agents', () => {
maxSockets: 1000,
},
},
defaultOptions,
defaultOptions
);
const agent = getAgent(uri, options);
assert.strictEqual(agent, undefined);
Expand Down

0 comments on commit 6f06e53

Please sign in to comment.