<commit_before>import {divideURL, emptyObject} from '../utils/utils';
import AddressAllocation from '../allocation/AddressAllocation';

class Loader {

  constructor(runtimeURL, runtimeConfiguration, runtimeDescriptorsInstance) {
    if (!runtimeConfiguration) throw   Error('[Runtime.Loader] The descriptor need to know the runtime configuration');
    if (!runtimeDescriptorsInstance) throw   Error('[Runtime.Loader] The descriptor need to know the runtime Descriptor instance');

    this.runtimeConfiguration = runtimeConfiguration;
    this.descriptors = runtimeDescriptorsInstance;
  }

  /**
   * Set runtime url
   * @param  {string} value runtimeURL
   */
  set runtimeURL(value) {
    this._runtimeURL = value;
  }

  /**
   * Get runtime url
   * @return {string} value runtimeURL
   */
  get runtimeURL() {
    return this._runtimeURL;
  }

  /**
   * Set Registry component
   * @param  {Registry} value Registry Component
   */
  set registry(value) {
    this._registry = value;

    // Install AddressAllocation
    let addressAllocation = AddressAllocation.instance;
    this._addressAllocation = addressAllocation;

    console.log('[Loader - AddressAllocation] - ', addressAllocation);
  }

  /**
   * Get Registry component
   * @return {Registry} Registry component
   */
  get registry() {
    return this._registry;
  }

  /**
   * Set Message Bus component
   * @param  {MessageBus} value Message bus component
   */
  set messageBus(value) {
    this._messagesBus = value;
  }

  /**
   * Get Message Bus component
   * @return {MessageBus} Message Bus component
   */
  get messageBus() {
    return this._messagesBus;
  }

  /**
   * Set Runtime Factory component
   * @param  {runtimeFactory} value Factory includes the specific implementations for each environment
   */
  set runtimeFactory(value) {
    this._runtimeFactory = value;
  }

  /**
   * Get Runtime Factory component
   * @return {runtimeFactory} Runtime Factory component
   */
  get runtimeFactory() {
    return this._runtimeFactory;
  }


  /**
   * Deploy Hyperty from Catalogue URL
   *
   * @see https://github.com/reTHINK-project/specs/tree/master/datamodel/core/address
   *
   * @param {URL.HypertyCatalogueURL} hypertyCatalogueURL - The Catalogue URL used to identify descriptors in the Catalogue.
   * @param {boolean|URL.HypertyURL} [reuseURL=false] reuseURL - reuseURL is used to reuse the hypertyURL previously registred, by default the reuse is disabled;
   * @param {URL} appURL - the app url origin address;
   * @param {object} IdpConstraint - constraints to be used when selecting the identity to be associated with the Hyperty including origin, idp, and idHint.
   * @returns {Promise<Boolean, Error>} this is Promise and returns true if all components are loaded with success or an error if someone fails.
   *
   * @memberOf Loader
   */
  loadHyperty(hypertyCatalogueURL, reuseURL = false, appURL, IdpConstraint) {

    if (!this._readyToUse()) return false;
    if (!hypertyCatalogueURL) throw new   Error('[Runtime.Loader] Hyperty descriptor url parameter is needed');

    return new Promise((resolve, reject) => {

      let _hypertyURL;
      let _hypertySandbox;
      let _hypertyDescriptor;
      let _hypertySourcePackage;
      let haveError = false;

      let errorReason = (reason) => {
        console.  Error('[Runtime.Loader] Something failed on the deploy hyperty: ', reason);
        reject(reason);
      };

      let handleError = (reason) => {
        haveError = true;
        reject(reason);
      };

      // Get Hyperty descriptor
      // TODO: the request Module should be changed,<commit_msg>added idpConstraint to Hyperty loading<commit_after>import {divideURL, emptyObject} from '../utils/utils';
import AddressAllocation from '../allocation/AddressAllocation';

class Loader {

  constructor(runtimeURL, runtimeConfiguration, runtimeDescriptorsInstance) {
    if (!runtimeConfiguration) throw   Error('[Runtime.Loader] The descriptor need to know the runtime configuration');
    if (!runtimeDescriptorsInstance) throw   Error('[Runtime.Loader] The descriptor need to know the runtime Descriptor instance');

    this.runtimeConfiguration = runtimeConfiguration;
    this.descriptors = runtimeDescriptorsInstance;
  }

  /**
   * Set runtime url
   * @param  {string} value runtimeURL
   */
  set runtimeURL(value) {
    this._runtimeURL = value;
  }

  /**
   * Get runtime url
   * @return {string} value runtimeURL
   */
  get runtimeURL() {
    return this._runtimeURL;
  }

  /**
   * Set Registry component
   * @param  {Registry} value Registry Component
   */
  set registry(value) {
    this._registry = value;

    // Install AddressAllocation
    let addressAllocation = AddressAllocation.instance;
    this._addressAllocation = addressAllocation;

    console.log('[Loader - AddressAllocation] - ', addressAllocation);
  }

  /**
   * Get Registry component
   * @return {Registry} Registry component
   */
  get registry() {
    return this._registry;
  }

  /**
   * Set Message Bus component
   * @param  {MessageBus} value Message bus component
   */
  set messageBus(value) {
    this._messagesBus = value;
  }

  /**
   * Get Message Bus component
   * @return {MessageBus} Message Bus component
   */
  get messageBus() {
    return this._messagesBus;
  }

  /**
   * Set Runtime Factory component
   * @param  {runtimeFactory} value Factory includes the specific implementations for each environment
   */
  set runtimeFactory(value) {
    this._runtimeFactory = value;
  }

  /**
   * Get Runtime Factory component
   * @return {runtimeFactory} Runtime Factory component
   */
  get runtimeFactory() {
    return this._runtimeFactory;
  }


  /**
   * Deploy Hyperty from Catalogue URL
   *
   * @see https://github.com/reTHINK-project/specs/tree/master/datamodel/core/address
   *
   * @param {URL.HypertyCatalogueURL} hypertyCatalogueURL - The Catalogue URL used to identify descriptors in the Catalogue.
   * @param {boolean|URL.HypertyURL} [reuseURL=false] reuseURL - reuseURL is used to reuse the hypertyURL previously registred, by default the reuse is disabled;
   * @param {URL} appURL - the app url origin address;
   * @param {object} IdpConstraint - constraints to be used when selecting the identity to be associated with the Hyperty including origin, idp, and idHint.
   * @returns {Promise<Boolean, Error>} this is Promise and returns true if all components are loaded with success or an error if someone fails.
   *
   * @memberOf Loader
   */
  loadHyperty(hypertyCatalogueURL, reuseURL = false, IdpConstraint, appURL) {

    if (!this._readyToUse()) return false;
    if (!hypertyCatalogueURL) throw new   Error('[Runtime.Loader] Hyperty descriptor url parameter is needed');

    return new Promise((resolve, reject) => {

      let _hypertyURL;
      let _hypertySandbox;
      let _hypertyDescriptor;
      let _hypertySourcePackage;
      let haveError = false;

      let errorReason = (reason) => {
        console.  Error('[Runtime.Loader] Something failed on the deploy hyperty: ', reason);
        reject(reason);
      };

      let handleError = (reason) => {
        haveError = true;
        reject(reason);
      };

      // Get Hyperty descriptor
      // TODO: the request Module should be changed,
{'fraction_non_alphanumeric': 0.09612488018622484, 'fraction_numerical': 0.0, 'mean_word_length': 3.2688486265341905, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1838461', 'n_tokens_mistral': 2034, 'n_tokens_neox': 1979, 'n_words': 631}