'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _regenerator;

function _load_regenerator() {
  return _regenerator = _interopRequireDefault(require('babel-runtime/regenerator'));
}

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _semver;

function _load_semver() {
  return _semver = _interopRequireDefault(require('semver'));
}

var _ramda;

function _load_ramda() {
  return _ramda = _interopRequireDefault(require('ramda'));
}

var _models;

function _load_models() {
  return _models = require('../../scope/models');
}

var _scope;

function _load_scope() {
  return _scope = require('../../scope');
}

var _component;

function _load_component() {
  return _component = _interopRequireDefault(require('../component'));
}

var _bitId;

function _load_bitId() {
  return _bitId = require('../../bit-id');
}

var _logger;

function _load_logger() {
  return _logger = _interopRequireDefault(require('../../logger/logger'));
}

var _bitMap;

function _load_bitMap() {
  return _bitMap = _interopRequireDefault(require('../bit-map/bit-map'));
}

var _consumer;

function _load_consumer() {
  return _consumer = _interopRequireDefault(require('../consumer'));
}

var _utils;

function _load_utils() {
  return _utils = require('../../utils');
}

var _constants;

function _load_constants() {
  return _constants = require('../../constants');
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var ComponentsList = function () {
  function ComponentsList(consumer) {
    _classCallCheck(this, ComponentsList);

    this._fromFileSystem = {};
    this._fromBitMap = {};

    this.consumer = consumer;
    this.scope = consumer.scope;
    this.bitMap = consumer.bitMap;
  }

  /**
   * List all bit ids stored in the model
   */


  _createClass(ComponentsList, [{
    key: 'getFromObjects',
    value: function () {
      var _ref = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee() {
        var componentsObjects;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                if (this._fromObjects) {
                  _context.next = 5;
                  break;
                }

                _context.next = 3;
                return this.scope.objects.listComponents(false);

              case 3:
                componentsObjects = _context.sent;

                this._fromObjects = componentsObjects.map(function (componentObjects) {
                  return new (_bitId || _load_bitId()).BitId({
                    scope: componentObjects.scope,
                    name: componentObjects.name,
                    version: componentObjects.scope ? componentObjects.latest() : null
                  });
                });

              case 5:
                return _context.abrupt('return', this._fromObjects);

              case 6:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

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

      return getFromObjects;
    }()
  }, {
    key: '_getAuthoredAndImportedFromFS',
    value: function () {
      var _ref2 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee2() {
        var _ref3, _ref4, authored, imported;

        return (_regenerator || _load_regenerator()).default.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                _context2.next = 2;
                return Promise.all([this.getFromFileSystem((_constants || _load_constants()).COMPONENT_ORIGINS.AUTHORED), this.getFromFileSystem((_constants || _load_constants()).COMPONENT_ORIGINS.IMPORTED)]);

              case 2:
                _ref3 = _context2.sent;
                _ref4 = _slicedToArray(_ref3, 2);
                authored = _ref4[0];
                imported = _ref4[1];

                authored = authored || [];
                imported = imported || [];
                return _context2.abrupt('return', authored.concat(imported));

              case 9:
              case 'end':
                return _context2.stop();
            }
          }
        }, _callee2, this);
      }));

      function _getAuthoredAndImportedFromFS() {
        return _ref2.apply(this, arguments);
      }

      return _getAuthoredAndImportedFromFS;
    }()

    /**
     * Components that are in the model (either, committed from a local scope or imported), and were
     * changed in the file system
     *
     * @param {boolean} [load=false] - Whether to load the component (false will return only the id)
     * @return {Promise<string[]>}
     */

  }, {
    key: 'listModifiedComponents',
    value: function () {
      var _ref5 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee3() {
        var _this = this;

        var load = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
        var fileSystemComponents;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                if (this._modifiedComponents) {
                  _context3.next = 7;
                  break;
                }

                _context3.next = 3;
                return this._getAuthoredAndImportedFromFS();

              case 3:
                fileSystemComponents = _context3.sent;
                _context3.next = 6;
                return (0, (_utils || _load_utils()).filterAsync)(fileSystemComponents, function (component) {
                  return _this.consumer.getComponentStatusById(component.id).then(function (status) {
                    return status.modified;
                  });
                });

              case 6:
                this._modifiedComponents = _context3.sent;

              case 7:
                if (!load) {
                  _context3.next = 9;
                  break;
                }

                return _context3.abrupt('return', this._modifiedComponents);

              case 9:
                return _context3.abrupt('return', this._modifiedComponents.map(function (component) {
                  return component.id;
                }));

              case 10:
              case 'end':
                return _context3.stop();
            }
          }
        }, _callee3, this);
      }));

      function listModifiedComponents() {
        return _ref5.apply(this, arguments);
      }

      return listModifiedComponents;
    }()
  }, {
    key: 'listOutdatedComponents',
    value: function () {
      var _ref6 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee4() {
        var fileSystemComponents, componentsFromModel;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee4$(_context4) {
          while (1) {
            switch (_context4.prev = _context4.next) {
              case 0:
                _context4.next = 2;
                return this._getAuthoredAndImportedFromFS();

              case 2:
                fileSystemComponents = _context4.sent;
                _context4.next = 5;
                return this.scope.objects.listComponents(false);

              case 5:
                componentsFromModel = _context4.sent;
                return _context4.abrupt('return', fileSystemComponents.filter(function (component) {
                  var modelComponent = componentsFromModel.find(function (c) {
                    return c.toBitId().isEqualWithoutVersion(component.id);
                  });
                  if (!modelComponent) return false;
                  var latestVersion = modelComponent.latest();
                  if (component.id.hasVersion() && (_semver || _load_semver()).default.gt(latestVersion, component.id.version)) {
                    component.latestVersion = latestVersion;
                    return true;
                  }
                  return false;
                }));

              case 7:
              case 'end':
                return _context4.stop();
            }
          }
        }, _callee4, this);
      }));

      function listOutdatedComponents() {
        return _ref6.apply(this, arguments);
      }

      return listOutdatedComponents;
    }()
  }, {
    key: 'newModifiedAndAutoTaggedComponents',
    value: function () {
      var _ref7 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee5() {
        var _ref8, _ref9, newComponents, modifiedComponents, autoTagPendingModel, autoTagPending, components;

        return (_regenerator || _load_regenerator()).default.wrap(function _callee5$(_context5) {
          while (1) {
            switch (_context5.prev = _context5.next) {
              case 0:
                _context5.next = 2;
                return Promise.all([this.listNewComponents(true), this.listModifiedComponents(true)]);

              case 2:
                _ref8 = _context5.sent;
                _ref9 = _slicedToArray(_ref8, 2);
                newComponents = _ref9[0];
                modifiedComponents = _ref9[1];
                _context5.next = 8;
                return this.listAutoTagPendingComponents();

              case 8:
                autoTagPendingModel = _context5.sent;
                _context5.next = 11;
                return this.scope.toConsumerComponents(autoTagPendingModel);

              case 11:
                autoTagPending = _context5.sent;
                components = [].concat(_toConsumableArray(newComponents), _toConsumableArray(modifiedComponents), _toConsumableArray(autoTagPending));
                return _context5.abrupt('return', Promise.all(components));

              case 14:
              case 'end':
                return _context5.stop();
            }
          }
        }, _callee5, this);
      }));

      function newModifiedAndAutoTaggedComponents() {
        return _ref7.apply(this, arguments);
      }

      return newModifiedAndAutoTaggedComponents;
    }()
  }, {
    key: 'authoredAndImportedComponents',
    value: function () {
      var _ref10 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee6() {
        return (_regenerator || _load_regenerator()).default.wrap(function _callee6$(_context6) {
          while (1) {
            switch (_context6.prev = _context6.next) {
              case 0:
                return _context6.abrupt('return', this._getAuthoredAndImportedFromFS());

              case 1:
              case 'end':
                return _context6.stop();
            }
          }
        }, _callee6, this);
      }));

      function authoredAndImportedComponents() {
        return _ref10.apply(this, arguments);
      }

      return authoredAndImportedComponents;
    }()
  }, {
    key: 'idsFromObjects',
    value: function () {
      var _ref11 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee7() {
        var fromObjects;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee7$(_context7) {
          while (1) {
            switch (_context7.prev = _context7.next) {
              case 0:
                _context7.next = 2;
                return this.getFromObjects();

              case 2:
                fromObjects = _context7.sent;
                return _context7.abrupt('return', new (Function.prototype.bind.apply((_bitId || _load_bitId()).BitIds, [null].concat(_toConsumableArray(fromObjects))))());

              case 4:
              case 'end':
                return _context7.stop();
            }
          }
        }, _callee7, this);
      }));

      function idsFromObjects() {
        return _ref11.apply(this, arguments);
      }

      return idsFromObjects;
    }()

    /**
     * Components that are registered in bit.map but have never been committed
     *
     * @param {boolean} [load=false] - Whether to load the component (false will return only the id)
     * @return {Promise.<string[] | Component[]>}
     * @memberof ComponentsList
     */

  }, {
    key: 'listNewComponents',
    value: function () {
      var _ref12 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee8() {
        var load = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;

        var idsFromBitMap, idsFromObjects, newComponents, newComponentsIds, _ref13, components;

        return (_regenerator || _load_regenerator()).default.wrap(function _callee8$(_context8) {
          while (1) {
            switch (_context8.prev = _context8.next) {
              case 0:
                idsFromBitMap = this.idsFromBitMap();
                _context8.next = 3;
                return this.idsFromObjects();

              case 3:
                idsFromObjects = _context8.sent;
                newComponents = [];

                idsFromBitMap.forEach(function (id) {
                  if (!idsFromObjects.searchWithoutScopeAndVersion(id)) {
                    newComponents.push(id);
                  }
                });
                newComponentsIds = new (Function.prototype.bind.apply((_bitId || _load_bitId()).BitIds, [null].concat(newComponents)))();

                if (!(!load || !newComponents.length)) {
                  _context8.next = 9;
                  break;
                }

                return _context8.abrupt('return', newComponentsIds);

              case 9:
                _context8.next = 11;
                return this.consumer.loadComponents(newComponentsIds, false);

              case 11:
                _ref13 = _context8.sent;
                components = _ref13.components;
                return _context8.abrupt('return', components);

              case 14:
              case 'end':
                return _context8.stop();
            }
          }
        }, _callee8, this);
      }));

      function listNewComponents() {
        return _ref12.apply(this, arguments);
      }

      return listNewComponents;
    }()

    /**
     * Authored exported components (easily identified by having a scope) which are not saved in the model are
     * import-pending. Exclude them from the 'newComponents' and add them to 'importPendingComponents'.
     */

  }, {
    key: 'listNewComponentsAndImportPending',
    value: function () {
      var _ref14 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee9() {
        var allNewComponents, newComponents, importPendingComponents;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee9$(_context9) {
          while (1) {
            switch (_context9.prev = _context9.next) {
              case 0:
                _context9.next = 2;
                return this.listNewComponents(true);

              case 2:
                allNewComponents = _context9.sent;
                newComponents = [];
                importPendingComponents = [];

                allNewComponents.forEach(function (component) {
                  if (component.id.scope) {
                    importPendingComponents.push(component);
                  } else {
                    newComponents.push(component);
                  }
                });
                return _context9.abrupt('return', { newComponents, importPendingComponents });

              case 7:
              case 'end':
                return _context9.stop();
            }
          }
        }, _callee9, this);
      }));

      function listNewComponentsAndImportPending() {
        return _ref14.apply(this, arguments);
      }

      return listNewComponentsAndImportPending;
    }()
  }, {
    key: 'listCommitPendingOfAllScope',
    value: function () {
      var _ref15 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee10(version) {
        var includeImported = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
        var commitPendingComponents, importedComponents, commitPendingComponentsLatest, warnings;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee10$(_context10) {
          while (1) {
            switch (_context10.prev = _context10.next) {
              case 0:
                commitPendingComponents = void 0;

                commitPendingComponents = this.idsFromBitMap((_constants || _load_constants()).COMPONENT_ORIGINS.AUTHORED);
                if (includeImported) {
                  importedComponents = this.idsFromBitMap((_constants || _load_constants()).COMPONENT_ORIGINS.IMPORTED);

                  commitPendingComponents = commitPendingComponents.concat(importedComponents);
                }
                _context10.next = 5;
                return this.scope.latestVersions(commitPendingComponents, false);

              case 5:
                commitPendingComponentsLatest = _context10.sent;
                warnings = [];

                commitPendingComponentsLatest.forEach(function (componentId) {
                  if ((_semver || _load_semver()).default.gt(componentId.version, version)) {
                    warnings.push(`warning: ${componentId.toString()} has a version greater than ${version}`);
                  }
                });
                return _context10.abrupt('return', { commitPendingComponents, warnings });

              case 9:
              case 'end':
                return _context10.stop();
            }
          }
        }, _callee10, this);
      }));

      function listCommitPendingOfAllScope(_x4) {
        return _ref15.apply(this, arguments);
      }

      return listCommitPendingOfAllScope;
    }()

    /**
     * New and modified components are commit pending
     *
     * @return {Promise<string[]>}
     */

  }, {
    key: 'listCommitPendingComponents',
    value: function () {
      var _ref16 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee11() {
        var _ref17, _ref18, newComponents, modifiedComponents;

        return (_regenerator || _load_regenerator()).default.wrap(function _callee11$(_context11) {
          while (1) {
            switch (_context11.prev = _context11.next) {
              case 0:
                _context11.next = 2;
                return Promise.all([this.listNewComponents(), this.listModifiedComponents()]);

              case 2:
                _ref17 = _context11.sent;
                _ref18 = _slicedToArray(_ref17, 2);
                newComponents = _ref18[0];
                modifiedComponents = _ref18[1];
                return _context11.abrupt('return', (_bitId || _load_bitId()).BitIds.fromArray([].concat(_toConsumableArray(newComponents), _toConsumableArray(modifiedComponents))));

              case 7:
              case 'end':
                return _context11.stop();
            }
          }
        }, _callee11, this);
      }));

      function listCommitPendingComponents() {
        return _ref16.apply(this, arguments);
      }

      return listCommitPendingComponents;
    }()

    /**
     * Components from the model where the scope is local are pending for export
     * Also, components that their model version is higher than their bit.map version.
     */

  }, {
    key: 'listExportPendingComponentsIds',
    value: function () {
      var _ref19 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee13() {
        var _this2 = this;

        var idsFromObjects, ids;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee13$(_context13) {
          while (1) {
            switch (_context13.prev = _context13.next) {
              case 0:
                _context13.next = 2;
                return this.idsFromObjects();

              case 2:
                idsFromObjects = _context13.sent;
                _context13.next = 5;
                return (0, (_utils || _load_utils()).filterAsync)(idsFromObjects, function () {
                  var _ref20 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee12(componentId) {
                    var status;
                    return (_regenerator || _load_regenerator()).default.wrap(function _callee12$(_context12) {
                      while (1) {
                        switch (_context12.prev = _context12.next) {
                          case 0:
                            _context12.prev = 0;
                            _context12.next = 3;
                            return _this2.consumer.getComponentStatusById(componentId);

                          case 3:
                            status = _context12.sent;
                            return _context12.abrupt('return', status.staged);

                          case 7:
                            _context12.prev = 7;
                            _context12.t0 = _context12['catch'](0);

                            if ((_component || _load_component()).default.isComponentInvalidByErrorType(_context12.t0)) {
                              _context12.next = 11;
                              break;
                            }

                            throw _context12.t0;

                          case 11:
                          case 'end':
                            return _context12.stop();
                        }
                      }
                    }, _callee12, _this2, [[0, 7]]);
                  }));

                  return function (_x5) {
                    return _ref20.apply(this, arguments);
                  };
                }());

              case 5:
                ids = _context13.sent;
                return _context13.abrupt('return', (_bitId || _load_bitId()).BitIds.fromArray(ids));

              case 7:
              case 'end':
                return _context13.stop();
            }
          }
        }, _callee13, this);
      }));

      function listExportPendingComponentsIds() {
        return _ref19.apply(this, arguments);
      }

      return listExportPendingComponentsIds;
    }()
  }, {
    key: 'listExportPendingComponents',
    value: function () {
      var _ref21 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee14() {
        var _this3 = this;

        var exportPendingComponentsIds;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee14$(_context14) {
          while (1) {
            switch (_context14.prev = _context14.next) {
              case 0:
                _context14.next = 2;
                return this.listExportPendingComponentsIds();

              case 2:
                exportPendingComponentsIds = _context14.sent;
                return _context14.abrupt('return', Promise.all(exportPendingComponentsIds.map(function (id) {
                  return _this3.scope.sources.get(id);
                })));

              case 4:
              case 'end':
                return _context14.stop();
            }
          }
        }, _callee14, this);
      }));

      function listExportPendingComponents() {
        return _ref21.apply(this, arguments);
      }

      return listExportPendingComponents;
    }()
  }, {
    key: 'listAutoTagPendingComponents',
    value: function () {
      var _ref22 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee15() {
        var modifiedComponents, modifiedComponentsLatestVersions;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee15$(_context15) {
          while (1) {
            switch (_context15.prev = _context15.next) {
              case 0:
                _context15.next = 2;
                return this.listModifiedComponents();

              case 2:
                modifiedComponents = _context15.sent;

                if (!(!modifiedComponents || !modifiedComponents.length)) {
                  _context15.next = 5;
                  break;
                }

                return _context15.abrupt('return', []);

              case 5:
                _context15.next = 7;
                return this.scope.latestVersions(modifiedComponents);

              case 7:
                modifiedComponentsLatestVersions = _context15.sent;
                return _context15.abrupt('return', this.consumer.listComponentsForAutoTagging(modifiedComponentsLatestVersions));

              case 9:
              case 'end':
                return _context15.stop();
            }
          }
        }, _callee15, this);
      }));

      function listAutoTagPendingComponents() {
        return _ref22.apply(this, arguments);
      }

      return listAutoTagPendingComponents;
    }()
  }, {
    key: 'idsFromBitMap',
    value: function idsFromBitMap(origin) {
      var fromBitMap = this.getFromBitMap(origin);
      return fromBitMap;
    }

    /**
     * Finds all components that are saved in the file system.
     * Components might be stored in the default component directory and also might be outside
     * of that directory. The bit.map is used to find them all
     * If they are on bit.map but not on the file-system, populate them to _invalidComponents property
     */

  }, {
    key: 'getFromFileSystem',
    value: function () {
      var _ref23 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee16(origin) {
        var cacheKeyName, idsFromBitMap, _ref24, components, invalidComponents;

        return (_regenerator || _load_regenerator()).default.wrap(function _callee16$(_context16) {
          while (1) {
            switch (_context16.prev = _context16.next) {
              case 0:
                cacheKeyName = origin || 'all';

                if (this._fromFileSystem[cacheKeyName]) {
                  _context16.next = 10;
                  break;
                }

                idsFromBitMap = this.idsFromBitMap(origin);
                _context16.next = 5;
                return this.consumer.loadComponents(idsFromBitMap, false);

              case 5:
                _ref24 = _context16.sent;
                components = _ref24.components;
                invalidComponents = _ref24.invalidComponents;

                this._fromFileSystem[cacheKeyName] = components;
                if (!this._invalidComponents && !origin) {
                  this._invalidComponents = invalidComponents;
                }

              case 10:
                return _context16.abrupt('return', this._fromFileSystem[cacheKeyName]);

              case 11:
              case 'end':
                return _context16.stop();
            }
          }
        }, _callee16, this);
      }));

      function getFromFileSystem(_x6) {
        return _ref23.apply(this, arguments);
      }

      return getFromFileSystem;
    }()

    /**
     * components that are on bit.map but not on the file-system
     */

  }, {
    key: 'listInvalidComponents',
    value: function () {
      var _ref25 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee17() {
        return (_regenerator || _load_regenerator()).default.wrap(function _callee17$(_context17) {
          while (1) {
            switch (_context17.prev = _context17.next) {
              case 0:
                if (this._invalidComponents) {
                  _context17.next = 3;
                  break;
                }

                _context17.next = 3;
                return this.getFromFileSystem();

              case 3:
                return _context17.abrupt('return', this._invalidComponents);

              case 4:
              case 'end':
                return _context17.stop();
            }
          }
        }, _callee17, this);
      }));

      function listInvalidComponents() {
        return _ref25.apply(this, arguments);
      }

      return listInvalidComponents;
    }()
  }, {
    key: 'getFromBitMap',
    value: function getFromBitMap(origin) {
      var cacheKeyName = origin || 'all';
      if (!this._fromBitMap[cacheKeyName]) {
        var originParam = origin ? [origin] : undefined;
        this._fromBitMap[cacheKeyName] = this.bitMap.getAllBitIds(originParam);
      }
      return this._fromBitMap[cacheKeyName];
    }

    // components can be one of the following: Component[] | ModelComponent[] | string[]

  }], [{
    key: 'sortComponentsByName',
    value: function sortComponentsByName(components) {
      var getName = function getName(component) {
        var name = void 0;
        if ((_ramda || _load_ramda()).default.is((_models || _load_models()).Component, component)) name = component.id();else if ((_ramda || _load_ramda()).default.is((_component || _load_component()).default, component)) name = component.id.toString();else name = component;
        return name.toUpperCase(); // ignore upper and lowercase
      };
      // $FlowFixMe
      return components.sort(function (a, b) {
        var nameA = getName(a);
        var nameB = getName(b);
        if (nameA < nameB) {
          return -1;
        }
        if (nameA > nameB) {
          return 1;
        }

        // names must be equal
        return 0;
      });
    }
  }]);

  return ComponentsList;
}();

exports.default = ComponentsList;