"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GerritHttp = void 0;
exports.setBaseUrl = setBaseUrl;
const common_1 = require("../common");
const regex_1 = require("../regex");
const url_1 = require("../url");
const index_1 = require("./index");
let baseUrl;
function setBaseUrl(url) {
    baseUrl = url;
}
/**
 * Access Gerrit REST-API and strip-of the "magic prefix" from responses.
 * @see https://gerrit-review.googlesource.com/Documentation/rest-api.html
 */
class GerritHttp extends index_1.Http {
    static magicPrefix = (0, regex_1.regEx)(/^\)]}'\n/g);
    constructor(options) {
        super('gerrit', options);
    }
    async request(path, options) {
        const url = (0, url_1.isHttpUrl)(path) ? path : baseUrl + path;
        const opts = {
            parseJson: (text) => (0, common_1.parseJson)(text.replace(GerritHttp.magicPrefix, ''), path),
            ...options,
        };
        opts.headers = {
            ...opts.headers,
        };
        return await super.request(url, opts);
    }
}
exports.GerritHttp = GerritHttp;
//# sourceMappingURL=gerrit.js.map