Skip to content

Commit d3b9587

Browse files
authoredAug 16, 2023
Deprecate retries config opt in favor of retry (#422)
Signed-off-by: Brian DeHamer <bdehamer@github.com>
1 parent d1d7498 commit d3b9587

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed
 

‎.changeset/heavy-chairs-wash.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tuf-js': minor
3+
---
4+
5+
Deprecates in `fetchRetries` config option in the `UpdaterOptions` interface in favor of the new `fetchRetry` option.

‎packages/client/src/__tests__/updater.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Updater', () => {
2121
metadataBaseUrl: `${baseURL}/metadata`,
2222
targetBaseUrl: `${baseURL}/targets`,
2323
config: {
24-
fetchRetries: 0,
24+
fetchRetry: 0,
2525
fetchTimeout: 1000,
2626
},
2727
};

‎packages/client/src/config.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
export const defaultConfig = {
1+
import type { MakeFetchHappenOptions } from 'make-fetch-happen';
2+
3+
export type Config = {
4+
maxRootRotations: number;
5+
maxDelegations: number;
6+
rootMaxLength: number;
7+
timestampMaxLength: number;
8+
snapshotMaxLength: number;
9+
targetsMaxLength: number;
10+
prefixTargetsWithHash: boolean;
11+
fetchTimeout: number;
12+
// deprecated use fetchRetry instead
13+
fetchRetries: number | undefined;
14+
fetchRetry: MakeFetchHappenOptions['retry'];
15+
};
16+
17+
export const defaultConfig: Config = {
218
maxRootRotations: 32,
319
maxDelegations: 32,
420
rootMaxLength: 512000, //bytes
@@ -7,7 +23,6 @@ export const defaultConfig = {
723
targetsMaxLength: 5000000, // bytes
824
prefixTargetsWithHash: true,
925
fetchTimeout: 100000, // milliseconds
10-
fetchRetries: 2,
26+
fetchRetries: undefined,
27+
fetchRetry: 2,
1128
};
12-
13-
export type Config = typeof defaultConfig;

‎packages/client/src/fetcher.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import util from 'util';
66
import { DownloadHTTPError, DownloadLengthMismatchError } from './error';
77
import { withTempFile } from './utils/tmpfile';
88

9+
import type { MakeFetchHappenOptions } from 'make-fetch-happen';
10+
911
const log = debug('tuf:fetch');
1012

1113
type DownloadFileHandler<T> = (file: string) => Promise<T>;
@@ -74,26 +76,28 @@ export abstract class BaseFetcher implements Fetcher {
7476
}
7577
}
7678

79+
type Retry = MakeFetchHappenOptions['retry'];
80+
7781
interface FetcherOptions {
7882
timeout?: number;
79-
retries?: number;
83+
retry?: Retry;
8084
}
8185

8286
export class DefaultFetcher extends BaseFetcher {
8387
private timeout?: number;
84-
private retries?: number;
88+
private retry?: Retry;
8589

8690
constructor(options: FetcherOptions = {}) {
8791
super();
8892
this.timeout = options.timeout;
89-
this.retries = options.retries;
93+
this.retry = options.retry;
9094
}
9195

9296
public override async fetch(url: string): Promise<NodeJS.ReadableStream> {
9397
log('GET %s', url);
9498
const response = await fetch(url, {
9599
timeout: this.timeout,
96-
retry: this.retries,
100+
retry: this.retry,
97101
});
98102

99103
if (!response.ok || !response?.body) {

‎packages/client/src/updater.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class Updater {
6262
fetcher ||
6363
new DefaultFetcher({
6464
timeout: this.config.fetchTimeout,
65-
retries: this.config.fetchRetries,
65+
retry: this.config.fetchRetries ?? this.config.fetchRetry,
6666
});
6767
}
6868

0 commit comments

Comments
 (0)
Please sign in to comment.