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"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/sails-hook-orm-mongorito@1.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const Mongorito = require('mongorito'),\n      _ = require('lodash');\n\n/**\n * Validate configurations\n *\n * @private\n */\nvar _configure = function () {\n  var connection = sails.config.models.connection;\n\n  // A connection must be provided\n  if (!connection) {\n    throw new Error(\n      'No `sails.config.models.connection` provided.\\n' +\n      'Your application won\\'t be able to connect to a MongoDB database if you don\\'t set one.'\n    );\n  }\n\n  // The connection adapter must of type `mongorito`\n  if (sails.config.connections[connection].adapter !== 'mongorito') {\n    throw new Error(\n      'The connection adapter must be of type `mongorito`.\\n' +\n      'This isn\\'t the case for your `sails.config.connections.' + connection + '` connection.'\n    );\n  }\n\n  // An `host` and `database` configuration must at lease be provided\n  if (!sails.config.connections[connection].host || !sails.config.connections[connection].database) {\n    throw new Error('An `host` and `database` configuration must at lease be provided');\n  }\n};\n\nmodule.exports = function (sails) {\n\n  return {\n\n    configure: _configure,\n\n    /**\n     * Initialize hook\n     *\n     * @param cb\n     */\n    initialize: function (cb) {\n      var connection = sails.config.connections[sails.config.models.connection],\n        uri,\n        options = {};\n\n      // Build URI\n      // ======================================\n\n      // Credentials\n      if (connection.user && connection.password) {\n        uri = connection.user + ':' + connection.password + '@';\n\n        options.uri_decode_auth = true;\n      }\n\n      // Host & Port & Database\n      uri += connection.host + (connection.port ? ':' + connection.port : '') + '/' + connection.database;\n\n      // Database connection & Models loading\n      // ======================================\n\n      Mongorito.connect(uri, options).then(function () {\n\n        // Expose Mongorito Model as global variable\n        global['MongoritoModel'] = Mongorito.Model;\n\n        // Load model definitions using the module loader\n        sails.log.verbose('Loading the app\\'s models from `%s`...', sails.config.paths.models);\n        sails.modules.loadModels(function modulesLoaded(err, models) {\n          if (err) { return cb(err); }\n\n          sails.models = {};\n          _.each(models, function (model) {\n            sails.models[model.identity] = model;\n            sails.models[model.identity].globalId = model.globalId;\n            sails.models[model.identity].identity = model.identity;\n\n            // Expose model as global variable\n            global[model.globalId] = model;\n          });\n\n          // At this point, we know Mongorito has connected to the database and models has been loaded,\n          // everything is ready to go, and we can safely trigger `initialize`'s callback.\n          return cb();\n        });\n      }, function (err) {\n        return cb(err);\n      });\n    }\n  }\n};\n"]}