1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.MultiFetcher = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const MessageName_1 = require("./MessageName");
|
6 | const Report_1 = require("./Report");
|
7 | const structUtils = tslib_1.__importStar(require("./structUtils"));
|
8 | class 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 | }
|
38 | exports.MultiFetcher = MultiFetcher;
|