UNPKG

1.41 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.MultiFetcher = void 0;
4const tslib_1 = require("tslib");
5const MessageName_1 = require("./MessageName");
6const Report_1 = require("./Report");
7const structUtils = tslib_1.__importStar(require("./structUtils"));
8class MultiFetcher {
9 constructor(fetchers) {
10 this.fetchers = fetchers;
11 }
12 supports(locator, opts) {
13 if (!this.tryFetcher(locator, opts))
14 return false;
15 return true;
16 }
17 getLocalPath(locator, opts) {
18 const fetcher = this.getFetcher(locator, opts);
19 return fetcher.getLocalPath(locator, opts);
20 }
21 async fetch(locator, opts) {
22 const fetcher = this.getFetcher(locator, opts);
23 return await fetcher.fetch(locator, opts);
24 }
25 tryFetcher(locator, opts) {
26 const fetcher = this.fetchers.find(fetcher => fetcher.supports(locator, opts));
27 if (!fetcher)
28 return null;
29 return fetcher;
30 }
31 getFetcher(locator, opts) {
32 const fetcher = this.fetchers.find(fetcher => fetcher.supports(locator, opts));
33 if (!fetcher)
34 throw new Report_1.ReportError(MessageName_1.MessageName.FETCHER_NOT_FOUND, `${structUtils.prettyLocator(opts.project.configuration, locator)} isn't supported by any available fetcher`);
35 return fetcher;
36 }
37}
38exports.MultiFetcher = MultiFetcher;