"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getLoded = exports.apixFilesHost = void 0;

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var apixFilesHost = 'http://localhost:30000';
exports.apixFilesHost = apixFilesHost;

var fetchLode = function () {
  var _ref = _asyncToGenerator(function* (lodeUrl) {
    try {
      var result = yield fetch(lodeUrl, {
        mode: 'cors'
      });
      return result.text();
    } catch (error) {
      return '';
    }
  });

  return function fetchLode(_x) {
    return _ref.apply(this, arguments);
  };
}();

var getLoded = function () {
  var _ref2 = _asyncToGenerator(function* (examplesLodeUrl, declarationsLodeUrl) {
    var examples = yield fetchLode("".concat(apixFilesHost, "/examplesIndex.json"));

    if (!examples && examplesLodeUrl) {
      examples = yield fetchLode(examplesLodeUrl);
    }

    var declarations;

    if (declarationsLodeUrl) {
      declarations = yield fetchLode(declarationsLodeUrl);
    }

    var lode = {
      examples: undefined,
      declarations: undefined
    };

    if (examples) {
      lode.examples = JSON.parse(examples);
    }

    if (declarations) {
      lode.declarations = JSON.parse(declarations);
    }

    return lode;
  });

  return function getLoded(_x2, _x3) {
    return _ref2.apply(this, arguments);
  };
}();

exports.getLoded = getLoded;
//# sourceMappingURL=lodeUtils.js.map