"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getErrorReports = void 0;
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const fetch_1 = require("./fetch");
/**
 * Fetches the error reports JSON as an Observable.
 * Can optionally cache the result.
 *
 * @param useCache Whether to cache the result for future subscribers. Default: true.
 * @returns Observable of ErrorReport array
 */
function getErrorReports(useCache = true) {
    // Internal cache holder
    let cached$;
    // The actual getter
    const fetch$ = () => (0, rxjs_1.defer)(() => (0, fetch_1.fetchAndResolve)('/error-reports-v2.json', 'json', false));
    if (!useCache) {
        return fetch$();
    }
    // Create cached observable if needed
    if (!cached$) {
        cached$ = fetch$().pipe((0, operators_1.shareReplay)({ bufferSize: 1, refCount: false }));
    }
    return cached$;
}
exports.getErrorReports = getErrorReports;
//# sourceMappingURL=error-reports.js.map