11import * as fs from 'fs' ;
22import * as path from 'path' ;
33import { EqualVersionError , ValueError } from './error' ;
4- import { FetcherInterface } from './fetcher' ;
4+ import { BaseFetcher , Fetcher } from './fetcher' ;
55import { Metadata , Targets } from './models' ;
66import { TargetFile } from './models/file' ;
7- import { Fetcher } from './requestsFetcher' ;
8- import { TrustedMetadataSet } from './trusted_metadata_set' ;
7+ import { TrustedMetadataStore } from './store' ;
98import { Config , defaultConfig } from './utils/config' ;
109import { 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