Skip to content

Commit af1bf80

Browse files
committed
resolved merge conflict
2 parents 57e0d5d + d4c8b84 commit af1bf80

File tree

7 files changed

+34
-59
lines changed

7 files changed

+34
-59
lines changed

package-lock.json

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

src/__tests__/fetcher.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import nock from 'nock';
2-
import { Fetcher } from '../requestsFetcher';
2+
import { Fetcher } from '../fetcher';
33

44
describe('Fetcher Test', () => {
55
const baseURL = 'http://localhost:8080';

src/fetcher.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { DownloadLengthMismatchError } from './error';
1+
import fetch from 'make-fetch-happen';
2+
import { DownloadHTTPError, DownloadLengthMismatchError } from './error';
23

3-
export abstract class FetcherInterface {
4+
export abstract class BaseFetcher {
45
protected timeout?: number;
56

67
constructor(timeout?: number) {
@@ -30,3 +31,19 @@ export abstract class FetcherInterface {
3031
return Buffer.concat(chunks);
3132
}
3233
}
34+
35+
export class Fetcher extends BaseFetcher {
36+
constructor(timeout?: number) {
37+
super(timeout);
38+
}
39+
40+
public override async fetch(url: string): Promise<NodeJS.ReadableStream> {
41+
const response = await fetch(url, { timeout: this.timeout });
42+
43+
if (!response.ok || !response?.body) {
44+
throw new DownloadHTTPError('Failed to download', response.status);
45+
}
46+
47+
return response.body;
48+
}
49+
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { FetcherInterface } from './fetcher';
1+
export { BaseFetcher } from './fetcher';
22
export { Updater } from './updater';

src/requestsFetcher.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/trusted_metadata_set.ts renamed to src/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type TrustedSet = {
1515
targets?: Metadata<Targets>;
1616
} & { [key: string]: Metadata<Targets> };
1717

18-
export class TrustedMetadataSet {
18+
export class TrustedMetadataStore {
1919
private trustedSet: TrustedSet = {};
2020
private referenceTime: Date;
2121

src/updater.ts

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33
import { EqualVersionError, ValueError } from './error';
4-
import { FetcherInterface } from './fetcher';
4+
import { BaseFetcher, Fetcher } from './fetcher';
55
import { Metadata, Targets } from './models';
66
import { TargetFile } from './models/file';
7-
import { Fetcher } from './requestsFetcher';
8-
import { TrustedMetadataSet } from './trusted_metadata_set';
7+
import { TrustedMetadataStore } from './store';
98
import { Config, defaultConfig } from './utils/config';
109
import { MetadataKind } from './utils/types';
1110

@@ -14,7 +13,7 @@ interface UpdaterOptions {
1413
metadataBaseUrl: string;
1514
targetDir?: string;
1615
targetBaseUrl?: string;
17-
fetcher?: FetcherInterface;
16+
fetcher?: BaseFetcher;
1817
config?: Config;
1918
}
2019

@@ -28,9 +27,9 @@ export class Updater {
2827
private metadataBaseUrl: string;
2928
private targetDir?: string;
3029
private targetBaseUrl?: string;
31-
private trustedSet: TrustedMetadataSet;
30+
private trustedSet: TrustedMetadataStore;
3231
private config: Config;
33-
private fetcher: FetcherInterface;
32+
private fetcher: BaseFetcher;
3433

3534
constructor(options: UpdaterOptions) {
3635
const {
@@ -49,8 +48,8 @@ export class Updater {
4948
this.targetBaseUrl = targetBaseUrl;
5049

5150
const data = this.loadLocalMetadata(MetadataKind.Root);
52-
this.trustedSet = new TrustedMetadataSet(data);
5351

52+
this.trustedSet = new TrustedMetadataStore(data);
5453
this.config = { ...defaultConfig, ...config };
5554
this.fetcher = fetcher || new Fetcher(this.config.fetchTimeout);
5655
}
@@ -212,34 +211,12 @@ export class Updater {
212211
return this.trustedSet.getRole(role);
213212
}
214213

214+
// Returns the TargetFile instance with information for the given target path.
215+
//
216+
// Implicitly calls refresh if it hasn't already been called.
215217
public async getTargetInfo(
216218
targetPath: string
217219
): Promise<TargetFile | undefined> {
218-
/***
219-
* Returns ``TargetFile`` instance with information for ``target_path``.
220-
221-
The return value can be used as an argument to
222-
``download_target()`` and ``find_cached_target()``.
223-
224-
If ``refresh()`` has not been called before calling
225-
``get_targetinfo()``, the refresh will be done implicitly.
226-
227-
As a side-effect this method downloads all the additional (delegated
228-
targets) metadata it needs to return the target information.
229-
230-
Args:
231-
target_path: `path-relative-URL string
232-
<https://url.spec.whatwg.org/#path-relative-url-string>`_
233-
that uniquely identifies the target within the repository.
234-
235-
Raises:
236-
OSError: New metadata could not be written to disk
237-
RepositoryError: Metadata failed to verify in some way
238-
DownloadError: Download of a metadata file failed in some way
239-
240-
Returns:
241-
``TargetFile`` instance or ``None``.
242-
***/
243220
if (!this.trustedSet.targets) {
244221
this.refresh();
245222
}

0 commit comments

Comments
 (0)