From 1d4c329c15579f311013297953cd95ffa14e41da Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Sat, 27 Feb 2016 20:16:45 -0800 Subject: [PATCH] 1.0.0-alpha.2 --- CHANGELOG.md | 5 +++++ CONTRIBUTORS | 2 +- dist/js-data-mongodb.js | 31 ++++++++++++++++--------------- dist/js-data-mongodb.js.map | 2 +- package.json | 2 +- src/index.js | 31 ++++++++++++++++--------------- 6 files changed, 40 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8db67e9..398ed00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +##### 1.0.0-alpha.2 - 27 February 2016 + +###### Backwards compatible bug fixes +- Fixed use of options + ##### 1.0.0-alpha.1 - 26 February 2016 ###### Breaking API changes diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 80252af..2813981 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -4,5 +4,5 @@ # # Names should be added to this file as: # [commit count] Name - 24 Jason Dobry + 26 Jason Dobry 1 John Grogg diff --git a/dist/js-data-mongodb.js b/dist/js-data-mongodb.js index 82263e7..1039e14 100644 --- a/dist/js-data-mongodb.js +++ b/dist/js-data-mongodb.js @@ -40,6 +40,7 @@ var isArray = jsData.utils.isArray; var isObject = jsData.utils.isObject; var isString = jsData.utils.isString; var isUndefined = jsData.utils.isUndefined; +var plainCopy = jsData.utils.plainCopy; var resolve = jsData.utils.resolve; @@ -425,20 +426,20 @@ addHiddenPropsToTarget(MongoDBAdapter.prototype, { * @method * @return {Object} */ - getQuery: function getQuery(Resource, query) { - query || (query = {}); + getQuery: function getQuery(mapper, query) { + query = plainCopy(query || {}); query.where || (query.where = {}); - forOwn(query, function (v, k) { - if (reserved.indexOf(k) === -1) { - if (isObject(v)) { - query.where[k] = v; + forOwn(query, function (config, keyword) { + if (reserved.indexOf(keyword) === -1) { + if (isObject(config)) { + query.where[keyword] = config; } else { - query.where[k] = { - '==': v + query.where[keyword] = { + '==': config }; } - delete query[k]; + delete query[keyword]; } }); @@ -582,8 +583,8 @@ addHiddenPropsToTarget(MongoDBAdapter.prototype, { * @method * @return {Object} */ - getQueryOptions: function getQueryOptions(Resource, query) { - query = query || {}; + getQueryOptions: function getQueryOptions(mapper, query) { + query = plainCopy(query || {}); query.orderBy = query.orderBy || query.sort; query.skip = query.skip || query.offset; @@ -625,7 +626,7 @@ addHiddenPropsToTarget(MongoDBAdapter.prototype, { */ getOpt: function getOpt(opt, opts) { opts || (opts = {}); - return isUndefined(opts[opt]) ? this[opt] : opts[opt]; + return isUndefined(opts[opt]) ? plainCopy(this[opt]) : plainCopy(opts[opt]); }, @@ -636,8 +637,8 @@ addHiddenPropsToTarget(MongoDBAdapter.prototype, { * @method * @return {*} */ - toObjectID: function toObjectID(Resource, id) { - if (id !== undefined && Resource.idAttribute === '_id' && typeof id === 'string' && bson.ObjectID.isValid(id) && !(id instanceof bson.ObjectID)) { + toObjectID: function toObjectID(mapper, id) { + if (id !== undefined && mapper.idAttribute === '_id' && typeof id === 'string' && bson.ObjectID.isValid(id) && !(id instanceof bson.ObjectID)) { return new bson.ObjectID(id); } return id; @@ -1130,7 +1131,7 @@ addHiddenPropsToTarget(MongoDBAdapter.prototype, { * * @name MongoDBAdapter#destroy * @method - * @param {Object} Resource The Resource. + * @param {Object} mapper The mapper. * @param {(string|number)} id Primary key of the record to destroy. * @param {Object} [opts] Configuration options. * @param {boolean} [opts.raw=false] Whether to return a more detailed diff --git a/dist/js-data-mongodb.js.map b/dist/js-data-mongodb.js.map index 2ba08f4..9a0d405 100644 --- a/dist/js-data-mongodb.js.map +++ b/dist/js-data-mongodb.js.map @@ -1 +1 @@ -{"version":3,"file":"js-data-mongodb.js","sources":["../src/index.js"],"sourcesContent":["import {MongoClient} from 'mongodb'\nimport {ObjectID} from 'bson'\nimport {utils} from 'js-data'\nimport underscore from 'mout/string/underscore'\n\nconst {\n addHiddenPropsToTarget,\n fillIn,\n forEachRelation,\n forOwn,\n get,\n isArray,\n isObject,\n isString,\n isUndefined,\n resolve\n} = utils\n\nconst reserved = [\n 'orderBy',\n 'sort',\n 'limit',\n 'offset',\n 'skip',\n 'where'\n]\n\nfunction unique (array) {\n const seen = {}\n const final = []\n array.forEach(function (item) {\n if (item in seen) {\n return\n }\n final.push(item)\n seen[item] = 0\n })\n return final\n}\n\nconst noop = function (...args) {\n const self = this\n const opts = args[args.length - 1]\n self.dbg(opts.op, ...args)\n return resolve()\n}\n\nconst noop2 = function (...args) {\n const self = this\n const opts = args[args.length - 2]\n self.dbg(opts.op, ...args)\n return resolve()\n}\n\nconst DEFAULTS = {\n /**\n * Whether to log debugging information.\n *\n * @name MongoDBAdapter#debug\n * @type {boolean}\n * @default false\n */\n debug: false,\n\n /**\n * Whether to return detailed result objects instead of just record data.\n *\n * @name MongoDBAdapter#raw\n * @type {boolean}\n * @default false\n */\n raw: false,\n\n /**\n * Convert ObjectIDs to strings when pulling records out of the database.\n *\n * @name MongoDBAdapter#translateId\n * @type {boolean}\n * @default true\n */\n translateId: true,\n\n /**\n * MongoDB URI.\n *\n * @name MongoDBAdapter#uri\n * @type {string}\n * @default mongodb://localhost:27017\n */\n uri: 'mongodb://localhost:27017'\n}\n\nconst FIND_OPTS_DEFAULTS = {}\nconst FIND_ONE_OPTS_DEFAULTS = {}\nconst INSERT_OPTS_DEFAULTS = {}\nconst INSERT_MANY_OPTS_DEFAULTS = {}\nconst UPDATE_OPTS_DEFAULTS = {}\nconst REMOVE_OPTS_DEFAULTS = {}\n\n/**\n * MongoDBAdapter class.\n *\n * @example\n * // Use Container instead of DataStore on the server\n * import {Container} from 'js-data'\n * import MongoDBAdapter from 'js-data-mongodb'\n *\n * // Create a store to hold your Mappers\n * const store = new Container({\n * mapperDefaults: {\n * // MongoDB uses \"_id\" as the primary key\n * idAttribute: '_id'\n * }\n * })\n *\n * // Create an instance of MongoDBAdapter with default settings\n * const adapter = new MongoDBAdapter()\n *\n * // Mappers in \"store\" will use the MongoDB adapter by default\n * store.registerAdapter('mongodb', adapter, { default: true })\n *\n * // Create a Mapper that maps to a \"user\" collection\n * store.defineMapper('user')\n *\n * @class MongoDBAdapter\n * @param {Object} [opts] Configuration opts.\n * @param {boolean} [opts.debug=false] Whether to log debugging information.\n * @param {Object} [opts.findOpts] Options to pass to collection#find.\n * @param {Object} [opts.findOneOpts] Options to pass to collection#findOne.\n * @param {Object} [opts.insertOpts] Options to pass to collection#insert.\n * @param {Object} [opts.insertManyOpts] Options to pass to\n * collection#insertMany.\n * @param {boolean} [opts.raw=false] Whether to return detailed result objects\n * instead of just record data.\n * @param {Object} [opts.removeOpts] Options to pass to collection#remove.\n * @param {boolean} [opts.translateId=true] Convert ObjectIDs to strings when\n * pulling records out of the database.\n * @param {Object} [opts.updateOpts] Options to pass to collection#update.\n * @param {string} [opts.uri=\"mongodb://localhost:27017\"] MongoDB URI.\n */\nexport default function MongoDBAdapter (opts) {\n const self = this\n opts || (opts = {})\n if (isString(opts)) {\n opts = { uri: opts }\n }\n fillIn(opts, DEFAULTS)\n fillIn(self, opts)\n\n /**\n * Default options to pass to collection#find.\n *\n * @name MongoDBAdapter#findOpts\n * @type {Object}\n * @default {}\n */\n self.findOpts || (self.findOpts = {})\n fillIn(self.findOpts, FIND_OPTS_DEFAULTS)\n\n /**\n * Default options to pass to collection#findOne.\n *\n * @name MongoDBAdapter#findOneOpts\n * @type {Object}\n * @default {}\n */\n self.findOneOpts || (self.findOneOpts = {})\n fillIn(self.findOneOpts, FIND_ONE_OPTS_DEFAULTS)\n\n /**\n * Default options to pass to collection#insert.\n *\n * @name MongoDBAdapter#insertOpts\n * @type {Object}\n * @default {}\n */\n self.insertOpts || (self.insertOpts = {})\n fillIn(self.insertOpts, INSERT_OPTS_DEFAULTS)\n\n /**\n * Default options to pass to collection#insertMany.\n *\n * @name MongoDBAdapter#insertManyOpts\n * @type {Object}\n * @default {}\n */\n self.insertManyOpts || (self.insertManyOpts = {})\n fillIn(self.insertManyOpts, INSERT_MANY_OPTS_DEFAULTS)\n\n /**\n * Default options to pass to collection#update.\n *\n * @name MongoDBAdapter#updateOpts\n * @type {Object}\n * @default {}\n */\n self.updateOpts || (self.updateOpts = {})\n fillIn(self.updateOpts, UPDATE_OPTS_DEFAULTS)\n\n /**\n * Default options to pass to collection#update.\n *\n * @name MongoDBAdapter#removeOpts\n * @type {Object}\n * @default {}\n */\n self.removeOpts || (self.removeOpts = {})\n fillIn(self.removeOpts, REMOVE_OPTS_DEFAULTS)\n\n /**\n * A Promise that resolves to a reference to the MongoDB client being used by\n * this adapter.\n *\n * @name MongoDBAdapter#client\n * @type {Object}\n */\n self.client = new Promise(function (resolve, reject) {\n MongoClient.connect(opts.uri, function (err, db) {\n return err ? reject(err) : resolve(db)\n })\n })\n}\n\naddHiddenPropsToTarget(MongoDBAdapter.prototype, {\n /**\n * Translate ObjectIDs to strings.\n *\n * @name MongoDBAdapter#_translateId\n * @method\n * @return {*}\n */\n _translateId (r, opts) {\n opts || (opts = {})\n if (this.getOpt('translateId', opts)) {\n if (isArray(r)) {\n r.forEach(function (_r) {\n const __id = _r._id ? _r._id.toString() : _r._id\n _r._id = typeof __id === 'string' ? __id : _r._id\n })\n } else if (isObject(r)) {\n const __id = r._id ? r._id.toString() : r._id\n r._id = typeof __id === 'string' ? __id : r._id\n }\n }\n return r\n },\n\n /**\n * @name MongoDBAdapter#afterCreate\n * @method\n */\n afterCreate: noop2,\n\n /**\n * @name MongoDBAdapter#afterCreateMany\n * @method\n */\n afterCreateMany: noop2,\n\n /**\n * @name MongoDBAdapter#afterDestroy\n * @method\n */\n afterDestroy: noop2,\n\n /**\n * @name MongoDBAdapter#afterDestroyAll\n * @method\n */\n afterDestroyAll: noop2,\n\n /**\n * @name MongoDBAdapter#afterFind\n * @method\n */\n afterFind: noop2,\n\n /**\n * @name MongoDBAdapter#afterFindAll\n * @method\n */\n afterFindAll: noop2,\n\n /**\n * @name MongoDBAdapter#afterUpdate\n * @method\n */\n afterUpdate: noop2,\n\n /**\n * @name MongoDBAdapter#afterUpdateAll\n * @method\n */\n afterUpdateAll: noop2,\n\n /**\n * @name MongoDBAdapter#afterUpdateMany\n * @method\n */\n afterUpdateMany: noop2,\n\n /**\n * @name MongoDBAdapter#beforeCreate\n * @method\n */\n beforeCreate: noop,\n\n /**\n * @name MongoDBAdapter#beforeCreateMany\n * @method\n */\n beforeCreateMany: noop,\n\n /**\n * @name MongoDBAdapter#beforeDestroy\n * @method\n */\n beforeDestroy: noop,\n\n /**\n * @name MongoDBAdapter#beforeDestroyAll\n * @method\n */\n beforeDestroyAll: noop,\n\n /**\n * @name MongoDBAdapter#beforeFind\n * @method\n */\n beforeFind: noop,\n\n /**\n * @name MongoDBAdapter#beforeFindAll\n * @method\n */\n beforeFindAll: noop,\n\n /**\n * @name MongoDBAdapter#beforeUpdate\n * @method\n */\n beforeUpdate: noop,\n\n /**\n * @name MongoDBAdapter#beforeUpdateAll\n * @method\n */\n beforeUpdateAll: noop,\n\n /**\n * @name MongoDBAdapter#beforeUpdateMany\n * @method\n */\n beforeUpdateMany: noop,\n\n /**\n * @name MongoDBAdapter#dbg\n * @method\n */\n dbg (...args) {\n this.log('debug', ...args)\n },\n\n /**\n * Return a Promise that resolves to a reference to the MongoDB client being\n * used by this adapter.\n *\n * Useful when you need to do anything custom with the MongoDB client library.\n *\n * @name MongoDBAdapter#getClient\n * @method\n * @return {Object} MongoDB client.\n */\n getClient () {\n return this.client\n },\n\n /**\n * Map filtering params in a selection query to MongoDB a filtering object.\n *\n * Handles the following:\n *\n * - where\n * - and bunch of filtering operators\n *\n * @name MongoDBAdapter#getQuery\n * @method\n * @return {Object}\n */\n getQuery (Resource, query) {\n query || (query = {})\n query.where || (query.where = {})\n\n forOwn(query, function (v, k) {\n if (reserved.indexOf(k) === -1) {\n if (isObject(v)) {\n query.where[k] = v\n } else {\n query.where[k] = {\n '==': v\n }\n }\n delete query[k]\n }\n })\n\n let mongoQuery = {}\n\n if (Object.keys(query.where).length !== 0) {\n forOwn(query.where, function (criteria, field) {\n if (!isObject(criteria)) {\n query.where[field] = {\n '==': criteria\n }\n }\n forOwn(criteria, function (v, op) {\n if (op === '==' || op === '===' || op === 'contains') {\n mongoQuery[field] = v\n } else if (op === '!=' || op === '!==' || op === 'notContains') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$ne = v\n } else if (op === '>') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$gt = v\n } else if (op === '>=') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$gte = v\n } else if (op === '<') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$lt = v\n } else if (op === '<=') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$lte = v\n } else if (op === 'in') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$in = v\n } else if (op === 'notIn') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$nin = v\n } else if (op === '|==' || op === '|===' || op === '|contains') {\n mongoQuery.$or = mongoQuery.$or || []\n let orEqQuery = {}\n orEqQuery[field] = v\n mongoQuery.$or.push(orEqQuery)\n } else if (op === '|!=' || op === '|!==' || op === '|notContains') {\n mongoQuery.$or = mongoQuery.$or || []\n let orNeQuery = {}\n orNeQuery[field] = {\n '$ne': v\n }\n mongoQuery.$or.push(orNeQuery)\n } else if (op === '|>') {\n mongoQuery.$or = mongoQuery.$or || []\n let orGtQuery = {}\n orGtQuery[field] = {\n '$gt': v\n }\n mongoQuery.$or.push(orGtQuery)\n } else if (op === '|>=') {\n mongoQuery.$or = mongoQuery.$or || []\n let orGteQuery = {}\n orGteQuery[field] = {\n '$gte': v\n }\n mongoQuery.$or.push(orGteQuery)\n } else if (op === '|<') {\n mongoQuery.$or = mongoQuery.$or || []\n let orLtQuery = {}\n orLtQuery[field] = {\n '$lt': v\n }\n mongoQuery.$or.push(orLtQuery)\n } else if (op === '|<=') {\n mongoQuery.$or = mongoQuery.$or || []\n let orLteQuery = {}\n orLteQuery[field] = {\n '$lte': v\n }\n mongoQuery.$or.push(orLteQuery)\n } else if (op === '|in') {\n mongoQuery.$or = mongoQuery.$or || []\n let orInQuery = {}\n orInQuery[field] = {\n '$in': v\n }\n mongoQuery.$or.push(orInQuery)\n } else if (op === '|notIn') {\n mongoQuery.$or = mongoQuery.$or || []\n let orNinQuery = {}\n orNinQuery[field] = {\n '$nin': v\n }\n mongoQuery.$or.push(orNinQuery)\n }\n })\n })\n }\n\n return mongoQuery\n },\n\n /**\n * Logging utility method.\n *\n * @name MongoDBAdapter#log\n * @method\n */\n log (level, ...args) {\n if (level && !args.length) {\n args.push(level)\n level = 'debug'\n }\n if (level === 'debug' && !this.debug) {\n return\n }\n const prefix = `${level.toUpperCase()}: (MongoDBAdapter)`\n if (console[level]) {\n console[level](prefix, ...args)\n } else {\n console.log(prefix, ...args)\n }\n },\n\n /**\n * Map non-filtering params in a selection query to MongoDB query options.\n *\n * Handles the following:\n *\n * - limit\n * - skip/offset\n * - orderBy/sort\n *\n * @name MongoDBAdapter#getQueryOptions\n * @method\n * @return {Object}\n */\n getQueryOptions (Resource, query) {\n query = query || {}\n query.orderBy = query.orderBy || query.sort\n query.skip = query.skip || query.offset\n\n let queryOptions = {}\n\n if (query.orderBy) {\n if (isString(query.orderBy)) {\n query.orderBy = [\n [query.orderBy, 'asc']\n ]\n }\n for (var i = 0; i < query.orderBy.length; i++) {\n if (isString(query.orderBy[i])) {\n query.orderBy[i] = [query.orderBy[i], 'asc']\n }\n }\n queryOptions.sort = query.orderBy\n }\n\n if (query.skip) {\n queryOptions.skip = +query.skip\n }\n\n if (query.limit) {\n queryOptions.limit = +query.limit\n }\n\n return queryOptions\n },\n\n /**\n * Resolve the value of the specified option based on the given options and\n * this adapter's settings.\n *\n * @name MongoDBAdapter#getOpt\n * @method\n * @param {string} opt The name of the option.\n * @param {Object} [opts] Configuration options.\n * @return {*} The value of the specified option.\n */\n getOpt (opt, opts) {\n opts || (opts = {})\n return isUndefined(opts[opt]) ? this[opt] : opts[opt]\n },\n\n /**\n * Turn an _id into an ObjectID if it isn't already an ObjectID.\n *\n * @name MongoDBAdapter#toObjectID\n * @method\n * @return {*}\n */\n toObjectID (Resource, id) {\n if (id !== undefined && Resource.idAttribute === '_id' && typeof id === 'string' && ObjectID.isValid(id) && !(id instanceof ObjectID)) {\n return new ObjectID(id)\n }\n return id\n },\n\n /**\n * Return the foreignKey from the given record for the provided relationship.\n *\n * If the foreignKeys in your database are saved as ObjectIDs, then override\n * this method and change it to something like:\n *\n * ```\n * return this.toObjectID(mapper, this.constructor.prototype.makeHasManyForeignKey.call(this, mapper, def, record))\n * ```\n *\n * There may be other reasons why you may want to override this method, like\n * when the id of the parent doesn't exactly match up to the key on the child.\n *\n * @name MongoDBAdapter#makeHasManyForeignKey\n * @method\n * @return {*}\n */\n makeHasManyForeignKey (mapper, def, record) {\n return def.getForeignKey(record)\n },\n\n /**\n * Return the foreignKeys from the given record for the provided relationship.\n *\n * @name MongoDBAdapter#makeHasManyForeignKeys\n * @method\n * @return {*}\n */\n makeHasManyForeignKeys (mapper, def, record) {\n return get(record, mapper.idAttribute)\n },\n\n /**\n * Load a hasMany relationship.\n *\n * @name MongoDBAdapter#loadHasMany\n * @method\n * @return {Promise}\n */\n loadHasMany (mapper, def, records, __opts) {\n const self = this\n let singular = false\n\n if (isObject(records) && !isArray(records)) {\n singular = true\n records = [records]\n }\n const IDs = records.map(function (record) {\n return self.makeHasManyForeignKey(mapper, def, record)\n })\n const query = {}\n const criteria = query[def.foreignKey] = {}\n if (singular) {\n // more efficient query when we only have one record\n criteria['=='] = IDs[0]\n } else {\n criteria['in'] = IDs.filter(function (id) {\n return id\n })\n }\n return self.findAll(def.getRelation(), query, __opts).then(function (relatedItems) {\n records.forEach(function (record) {\n let attached = []\n // avoid unneccesary iteration when we only have one record\n if (singular) {\n attached = relatedItems\n } else {\n relatedItems.forEach(function (relatedItem) {\n if (get(relatedItem, def.foreignKey) === record[mapper.idAttribute]) {\n attached.push(relatedItem)\n }\n })\n }\n def.setLocalField(record, attached)\n })\n })\n },\n\n /**\n * Load a hasOne relationship.\n *\n * @name MongoDBAdapter#loadHasOne\n * @method\n * @return {Promise}\n */\n loadHasOne (mapper, def, records, __opts) {\n if (isObject(records) && !isArray(records)) {\n records = [records]\n }\n return this.loadHasMany(mapper, def, records, __opts).then(function () {\n records.forEach(function (record) {\n const relatedData = def.getLocalField(record)\n if (isArray(relatedData) && relatedData.length) {\n def.setLocalField(record, relatedData[0])\n }\n })\n })\n },\n\n /**\n * Return the foreignKey from the given record for the provided relationship.\n *\n * @name MongoDBAdapter#makeBelongsToForeignKey\n * @method\n * @return {*}\n */\n makeBelongsToForeignKey (mapper, def, record) {\n return this.toObjectID(def.getRelation(), def.getForeignKey(record))\n },\n\n /**\n * Load a belongsTo relationship.\n *\n * @name MongoDBAdapter#loadBelongsTo\n * @method\n * @return {Promise}\n */\n loadBelongsTo (mapper, def, records, __opts) {\n const self = this\n const relationDef = def.getRelation()\n\n if (isObject(records) && !isArray(records)) {\n const record = records\n return self.find(relationDef, self.makeBelongsToForeignKey(mapper, def, record), __opts).then(function (relatedItem) {\n def.setLocalField(record, relatedItem)\n })\n } else {\n const keys = records.map(function (record) {\n return self.makeBelongsToForeignKey(mapper, def, record)\n }).filter(function (key) {\n return key\n })\n return self.findAll(relationDef, {\n where: {\n [relationDef.idAttribute]: {\n 'in': keys\n }\n }\n }, __opts).then(function (relatedItems) {\n records.forEach(function (record) {\n relatedItems.forEach(function (relatedItem) {\n if (relatedItem[relationDef.idAttribute] === record[def.foreignKey]) {\n def.setLocalField(record, relatedItem)\n }\n })\n })\n })\n }\n },\n\n /**\n * Retrieve the record with the given primary key.\n *\n * @name MongoDBAdapter#find\n * @method\n * @param {Object} mapper The mapper.\n * @param {(string|number)} id Primary key of the record to retrieve.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.findOneOpts] Options to pass to collection#findOne.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {string[]} [opts.with=[]] Relations to eager load.\n * @return {Promise}\n */\n find (mapper, id, opts) {\n const self = this\n let record, op\n opts || (opts = {})\n opts.with || (opts.with = [])\n\n const findOneOpts = self.getOpt('findOneOpts', opts)\n findOneOpts.fields || (findOneOpts.fields = {})\n\n return self.getClient().then(function (client) {\n // beforeFind lifecycle hook\n op = opts.op = 'beforeFind'\n return resolve(self[op](mapper, id, opts)).then(function () {\n return new Promise(function (resolve, reject) {\n let mongoQuery = {}\n mongoQuery[mapper.idAttribute] = self.toObjectID(mapper, id)\n client.collection(mapper.table || underscore(mapper.name)).findOne(mongoQuery, findOneOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n })\n }).then(function (_record) {\n if (!_record) {\n return\n }\n record = _record\n self._translateId(record, opts)\n const tasks = []\n\n forEachRelation(mapper, opts, function (def, __opts) {\n const relatedMapper = def.getRelation()\n let task\n\n if (def.foreignKey && (def.type === 'hasOne' || def.type === 'hasMany')) {\n if (def.type === 'hasOne') {\n task = self.loadHasOne(mapper, def, record, __opts)\n } else {\n task = self.loadHasMany(mapper, def, record, __opts)\n }\n } else if (def.type === 'hasMany' && def.localKeys) {\n let localKeys = []\n let itemKeys = get(record, def.localKeys) || []\n itemKeys = isArray(itemKeys) ? itemKeys : Object.keys(itemKeys)\n localKeys = localKeys.concat(itemKeys)\n task = self.findAll(relatedMapper, {\n where: {\n [relatedMapper.idAttribute]: {\n 'in': unique(localKeys).filter(function (x) { return x }).map(function (x) { return self.toObjectID(relatedMapper, x) })\n }\n }\n }, __opts).then(function (relatedItems) {\n def.setLocalField(record, relatedItems)\n })\n } else if (def.type === 'hasMany' && def.foreignKeys) {\n task = self.findAll(relatedMapper, {\n where: {\n [def.foreignKeys]: {\n 'contains': self.makeHasManyForeignKeys(mapper, def, record)\n }\n }\n }, __opts).then(function (relatedItems) {\n def.setLocalField(record, relatedItems)\n })\n } else if (def.type === 'belongsTo') {\n task = self.loadBelongsTo(mapper, def, record, __opts)\n }\n if (task) {\n tasks.push(task)\n }\n })\n\n return Promise.all(tasks)\n }).then(function () {\n // afterFind lifecycle hook\n op = opts.op = 'afterFind'\n return resolve(self[op](mapper, id, opts, record)).then(function (_record) {\n // Allow for re-assignment from lifecycle hook\n record = isUndefined(_record) ? record : _record\n return self.getOpt('raw', opts) ? {\n data: record,\n found: record ? 1 : 0\n } : record\n })\n })\n },\n\n /**\n * Retrieve the records that match the selection query.\n *\n * @name MongoDBAdapter#findAll\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object} query Selection query.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.findOpts] Options to pass to collection#find.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {string[]} [opts.with=[]] Relations to eager load.\n * @return {Promise}\n */\n findAll (mapper, query, opts) {\n const self = this\n opts || (opts = {})\n opts.with || (opts.with = [])\n\n let records = []\n let op\n const findOpts = self.getOpt('findOpts', opts)\n fillIn(findOpts, self.getQueryOptions(mapper, query))\n findOpts.fields || (findOpts.fields = {})\n const mongoQuery = self.getQuery(mapper, query)\n\n return self.getClient().then(function (client) {\n // beforeFindAll lifecycle hook\n op = opts.op = 'beforeFindAll'\n return resolve(self[op](mapper, query, opts)).then(function () {\n return new Promise(function (resolve, reject) {\n client.collection(mapper.table || underscore(mapper.name)).find(mongoQuery, findOpts).toArray(function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n })\n }).then(function (_records) {\n records = _records\n self._translateId(records, opts)\n const tasks = []\n forEachRelation(mapper, opts, function (def, __opts) {\n const relatedMapper = def.getRelation()\n let task\n if (def.foreignKey && (def.type === 'hasOne' || def.type === 'hasMany')) {\n if (def.type === 'hasMany') {\n task = self.loadHasMany(mapper, def, records, __opts)\n } else {\n task = self.loadHasOne(mapper, def, records, __opts)\n }\n } else if (def.type === 'hasMany' && def.localKeys) {\n let localKeys = []\n records.forEach(function (item) {\n let itemKeys = item[def.localKeys] || []\n itemKeys = isArray(itemKeys) ? itemKeys : Object.keys(itemKeys)\n localKeys = localKeys.concat(itemKeys)\n })\n task = self.findAll(relatedMapper, {\n where: {\n [relatedMapper.idAttribute]: {\n 'in': unique(localKeys).filter(function (x) { return x }).map(function (x) { return self.toObjectID(relatedMapper, x) })\n }\n }\n }, __opts).then(function (relatedItems) {\n records.forEach(function (item) {\n let attached = []\n let itemKeys = get(item, def.localKeys) || []\n itemKeys = isArray(itemKeys) ? itemKeys : Object.keys(itemKeys)\n relatedItems.forEach(function (relatedItem) {\n if (itemKeys && itemKeys.indexOf(relatedItem[relatedMapper.idAttribute]) !== -1) {\n attached.push(relatedItem)\n }\n })\n def.setLocalField(item, attached)\n })\n return relatedItems\n })\n } else if (def.type === 'hasMany' && def.foreignKeys) {\n throw new Error('findAll eager load hasMany foreignKeys not supported!')\n } else if (def.type === 'belongsTo') {\n task = self.loadBelongsTo(mapper, def, records, __opts)\n }\n if (task) {\n tasks.push(task)\n }\n })\n return Promise.all(tasks)\n }).then(function () {\n // afterFindAll lifecycle hook\n op = opts.op = 'afterFindAll'\n return resolve(self[op](mapper, query, opts, records)).then(function (_records) {\n // Allow for re-assignment from lifecycle hook\n records = isUndefined(_records) ? records : _records\n return self.getOpt('raw', opts) ? {\n data: records,\n found: records.length\n } : records\n })\n })\n },\n\n /**\n * Create a new record.\n *\n * @name MongoDBAdapter#create\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object} props The record to be created.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.insertOpts] Options to pass to collection#insert.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @return {Promise}\n */\n create (mapper, props, opts) {\n const self = this\n let op\n props || (props = {})\n opts || (opts = {})\n\n const insertOpts = self.getOpt('insertOpts', opts)\n\n return self.getClient().then(function (client) {\n // beforeCreate lifecycle hook\n op = opts.op = 'beforeCreate'\n return resolve(self[op](mapper, props, opts)).then(function (_props) {\n // Allow for re-assignment from lifecycle hook\n _props = isUndefined(_props) ? props : _props\n return new Promise(function (resolve, reject) {\n const collection = client.collection(mapper.table || underscore(mapper.name))\n const method = collection.insertOne ? 'insertOne' : 'insert'\n collection[method](_props, insertOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n }).then(function (cursor) {\n let record\n let r = cursor.ops ? cursor.ops : cursor\n self._translateId(r, opts)\n record = isArray(r) ? r[0] : r\n\n // afterCreate lifecycle hook\n op = opts.op = 'afterCreate'\n return self[op](mapper, props, opts, record).then(function (_record) {\n // Allow for re-assignment from lifecycle hook\n record = isUndefined(_record) ? record : _record\n const result = {}\n fillIn(result, cursor)\n delete result.connection\n result.data = record\n result.created = record ? 1 : 0\n return self.getOpt('raw', opts) ? result : result.data\n })\n })\n })\n },\n\n /**\n * Create multiple records in a single batch.\n *\n * @name MongoDBAdapter#createMany\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object} props The records to be created.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.insertManyOpts] Options to pass to\n * collection#insertMany.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @return {Promise}\n */\n createMany (mapper, props, opts) {\n const self = this\n let op\n props || (props = {})\n opts || (opts = {})\n\n const insertManyOpts = self.getOpt('insertManyOpts', opts)\n\n return self.getClient().then(function (client) {\n // beforeCreateMany lifecycle hook\n op = opts.op = 'beforeCreateMany'\n return resolve(self[op](mapper, props, opts)).then(function (_props) {\n // Allow for re-assignment from lifecycle hook\n _props = isUndefined(_props) ? props : _props\n return new Promise(function (resolve, reject) {\n const collection = client.collection(mapper.table || underscore(mapper.name))\n collection.insertMany(_props, insertManyOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n }).then(function (cursor) {\n let records\n let r = cursor.ops ? cursor.ops : cursor\n self._translateId(r, opts)\n records = r\n\n // afterCreateMany lifecycle hook\n op = opts.op = 'afterCreateMany'\n return self[op](mapper, props, opts, records).then(function (_records) {\n // Allow for re-assignment from lifecycle hook\n records = isUndefined(_records) ? records : _records\n const result = {}\n fillIn(result, cursor)\n delete result.connection\n result.data = records\n result.created = records.length\n return self.getOpt('raw', opts) ? result : result.data\n })\n })\n })\n },\n\n /**\n * Destroy the record with the given primary key.\n *\n * @name MongoDBAdapter#destroy\n * @method\n * @param {Object} Resource The Resource.\n * @param {(string|number)} id Primary key of the record to destroy.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.removeOpts] Options to pass to collection#remove.\n * @return {Promise}\n */\n destroy (mapper, id, opts) {\n const self = this\n let op\n opts || (opts = {})\n const removeOpts = self.getOpt('removeOpts', opts)\n\n return self.getClient().then(function (client) {\n // beforeDestroy lifecycle hook\n op = opts.op = 'beforeDestroy'\n return resolve(self[op](mapper, id, opts)).then(function () {\n return new Promise(function (resolve, reject) {\n const mongoQuery = {}\n mongoQuery[mapper.idAttribute] = self.toObjectID(mapper, id)\n const collection = client.collection(mapper.table || underscore(mapper.name))\n collection[collection.deleteOne ? 'deleteOne' : 'remove'](mongoQuery, removeOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n })\n }).then(function (cursor) {\n // afterDestroy lifecycle hook\n op = opts.op = 'afterDestroy'\n return resolve(self[op](mapper, id, opts, cursor)).then(function (_cursor) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_cursor) ? cursor : _cursor\n })\n }).then(function (cursor) {\n if (cursor) {\n delete cursor.connection\n }\n return self.getOpt('raw', opts) ? cursor : undefined\n })\n },\n\n /**\n * Destroy the records that match the selection query.\n *\n * @name MongoDBAdapter#destroyAll\n * @method\n * @param {Object} mapper the mapper.\n * @param {Object} [query] Selection query.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.removeOpts] Options to pass to collection#remove.\n * @return {Promise}\n */\n destroyAll (mapper, query, opts) {\n const self = this\n let op\n query || (query = {})\n opts || (opts = {})\n const removeOpts = self.getOpt('removeOpts', opts)\n fillIn(removeOpts, self.getQueryOptions(mapper, query))\n\n return self.getClient().then(function (client) {\n // beforeDestroyAll lifecycle hook\n op = opts.op = 'beforeDestroyAll'\n return resolve(self[op](mapper, query, opts)).then(function () {\n const mongoQuery = self.getQuery(mapper, query)\n return new Promise(function (resolve, reject) {\n const collection = client.collection(mapper.table || underscore(mapper.name))\n collection[collection.deleteMany ? 'deleteMany' : 'remove'](mongoQuery, removeOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n })\n }).then(function (cursor) {\n // afterDestroyAll lifecycle hook\n op = opts.op = 'afterDestroyAll'\n return resolve(self[op](mapper, query, opts, cursor)).then(function (_cursor) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_cursor) ? cursor : _cursor\n })\n }).then(function (cursor) {\n if (cursor) {\n delete cursor.connection\n }\n return self.getOpt('raw', opts) ? cursor : undefined\n })\n },\n\n /**\n * Apply the given update to the record with the specified primary key.\n *\n * @name MongoDBAdapter#update\n * @method\n * @param {Object} mapper The mapper.\n * @param {(string|number)} id The primary key of the record to be updated.\n * @param {Object} props The update to apply to the record.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.updateOpts] Options to pass to collection#update.\n * @return {Promise}\n */\n update (mapper, id, props, opts) {\n const self = this\n props || (props = {})\n opts || (opts = {})\n let op\n const updateOpts = self.getOpt('updateOpts', opts)\n\n return self.find(mapper, id, { raw: false }).then(function (record) {\n if (!record) {\n throw new Error('Not Found')\n }\n // beforeUpdate lifecycle hook\n op = opts.op = 'beforeUpdate'\n return resolve(self[op](mapper, id, props, opts))\n }).then(function (_props) {\n // Allow for re-assignment from lifecycle hook\n _props = isUndefined(_props) ? props : _props\n return self.getClient().then(function (client) {\n return new Promise(function (resolve, reject) {\n const mongoQuery = {}\n mongoQuery[mapper.idAttribute] = self.toObjectID(mapper, id)\n const collection = client.collection(mapper.table || underscore(mapper.name))\n collection[collection.updateOne ? 'updateOne' : 'update'](mongoQuery, { $set: _props }, updateOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n })\n }).then(function (cursor) {\n if (cursor) {\n delete cursor.connection\n }\n return self.find(mapper, id, { raw: false }).then(function (record) {\n // afterUpdate lifecycle hook\n op = opts.op = 'afterUpdate'\n return resolve(self[op](mapper, id, props, opts, record)).then(function (_record) {\n // Allow for re-assignment from lifecycle hook\n record = isUndefined(_record) ? record : _record\n const result = {}\n fillIn(result, cursor)\n result.data = record\n result.updated = record ? 1 : 0\n return self.getOpt('raw', opts) ? result : result.data\n })\n })\n })\n },\n\n /**\n * Apply the given update to all records that match the selection query.\n *\n * @name MongoDBAdapter#updateAll\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object} props The update to apply to the selected records.\n * @param {Object} [query] Selection query.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.updateOpts] Options to pass to collection#update.\n * @return {Promise}\n */\n updateAll (mapper, props, query, opts) {\n const self = this\n props || (props = {})\n query || (query = {})\n opts || (opts = {})\n let op, ids\n const updateOpts = self.getOpt('updateOpts', opts)\n updateOpts.multi = true\n\n return self.getClient().then(function (client) {\n const queryOptions = self.getQueryOptions(mapper, query)\n queryOptions.$set = props\n const mongoQuery = self.getQuery(mapper, query)\n\n // beforeUpdateAll lifecycle hook\n op = opts.op = 'beforeUpdateAll'\n return resolve(self[op](mapper, props, query, opts)).then(function () {\n return self.findAll(mapper, query, { raw: false })\n }).then(function (records) {\n ids = records.map(function (record) {\n return self.toObjectID(mapper, record[mapper.idAttribute])\n })\n\n return new Promise(function (resolve, reject) {\n const collection = client.collection(mapper.table || underscore(mapper.name))\n collection[collection.updateMany ? 'updateMany' : 'update'](mongoQuery, queryOptions, updateOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n }).then(function (cursor) {\n if (cursor) {\n delete cursor.connection\n }\n const query = {}\n query[mapper.idAttribute] = {\n 'in': ids\n }\n return self.findAll(mapper, query, { raw: false }).then(function (records) {\n // afterUpdateAll lifecycle hook\n op = opts.op = 'afterUpdateAll'\n return self[op](mapper, props, query, opts, records).then(function (_records) {\n // Allow for re-assignment from lifecycle hook\n records = isUndefined(_records) ? records : _records\n const result = {}\n fillIn(result, cursor)\n result.data = records\n result.updated = records.length\n return self.getOpt('raw', opts) ? result : result.data\n })\n })\n })\n })\n },\n\n /**\n * Not supported.\n *\n * @name MongoDBAdapter#updateMany\n * @method\n */\n updateMany () {\n throw new Error('not supported!')\n }\n})\n"],"names":["utils","ObjectID"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAME,yBAUEA,aAVF;IACA,SASEA,aATF;IACA,kBAQEA,aARF;IACA,SAOEA,aAPF;IACA,MAMEA,aANF;IACA,UAKEA,aALF;IACA,WAIEA,aAJF;IACA,WAGEA,aAHF;IACA,cAEEA,aAFF;IACA,UACEA,aADF;;;AAGF,IAAM,WAAW,CACf,SADe,EAEf,MAFe,EAGf,OAHe,EAIf,QAJe,EAKf,MALe,EAMf,OANe,CAAX;;AASN,SAAS,MAAT,CAAiB,KAAjB,EAAwB;MAChB,OAAO,EAAP,CADgB;MAEhB,QAAQ,EAAR,CAFgB;QAGhB,OAAN,CAAc,UAAU,IAAV,EAAgB;QACxB,QAAQ,IAAR,EAAc;aAAA;KAAlB;UAGM,IAAN,CAAW,IAAX,EAJ4B;SAKvB,IAAL,IAAa,CAAb,CAL4B;GAAhB,CAAd,CAHsB;SAUf,KAAP,CAVsB;CAAxB;;AAaA,IAAM,OAAO,SAAP,IAAO,GAAmB;MACxB,OAAO,IAAP,CADwB;;oCAAN;;GAAM;;MAExB,OAAO,KAAK,KAAK,MAAL,GAAc,CAAd,CAAZ,CAFwB;OAGzB,GAAL,cAAS,KAAK,EAAL,SAAY,KAArB,EAH8B;SAIvB,SAAP,CAJ8B;CAAnB;;AAOb,IAAM,QAAQ,SAAR,KAAQ,GAAmB;M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AoB;;sBAElE,YAAY,QAAZ,IAAwB,OAAxB,GAAkC,QAAlC,CAFkE;gBAGtE,SAAS,EAAT,CAHsE;mBAIrE,MAAP,EAAe,MAAf,EAJ4E;mBAKrE,IAAP,GAAc,OAAd,CAL4E;mBAMrE,OAAP,GAAiB,QAAQ,MAAR,CAN2D;mBAOrE,KAAK,MAAL,CAAY,KAAZ,EAAmB,IAAnB,IAA2B,MAA3B,GAAoC,OAAO,IAAP,CAPiC;WAApB,CAA1D,CAHyE;SAAnB,CAAxD,CARwB;OAAlB,CAbR,CAP6C;KAAlB,CAA7B,CATqC;GA9+BQ;;;;;;;;;oCA0iCjC;UACN,IAAI,KAAJ,CAAU,gBAAV,CAAN,CADY;GA1iCiC;CAAjD;;"} \ No newline at end of file +{"version":3,"file":"js-data-mongodb.js","sources":["../src/index.js"],"sourcesContent":["import {MongoClient} from 'mongodb'\nimport {ObjectID} from 'bson'\nimport {utils} from 'js-data'\nimport underscore from 'mout/string/underscore'\n\nconst {\n addHiddenPropsToTarget,\n fillIn,\n forEachRelation,\n forOwn,\n get,\n isArray,\n isObject,\n isString,\n isUndefined,\n plainCopy,\n resolve\n} = utils\n\nconst reserved = [\n 'orderBy',\n 'sort',\n 'limit',\n 'offset',\n 'skip',\n 'where'\n]\n\nfunction unique (array) {\n const seen = {}\n const final = []\n array.forEach(function (item) {\n if (item in seen) {\n return\n }\n final.push(item)\n seen[item] = 0\n })\n return final\n}\n\nconst noop = function (...args) {\n const self = this\n const opts = args[args.length - 1]\n self.dbg(opts.op, ...args)\n return resolve()\n}\n\nconst noop2 = function (...args) {\n const self = this\n const opts = args[args.length - 2]\n self.dbg(opts.op, ...args)\n return resolve()\n}\n\nconst DEFAULTS = {\n /**\n * Whether to log debugging information.\n *\n * @name MongoDBAdapter#debug\n * @type {boolean}\n * @default false\n */\n debug: false,\n\n /**\n * Whether to return detailed result objects instead of just record data.\n *\n * @name MongoDBAdapter#raw\n * @type {boolean}\n * @default false\n */\n raw: false,\n\n /**\n * Convert ObjectIDs to strings when pulling records out of the database.\n *\n * @name MongoDBAdapter#translateId\n * @type {boolean}\n * @default true\n */\n translateId: true,\n\n /**\n * MongoDB URI.\n *\n * @name MongoDBAdapter#uri\n * @type {string}\n * @default mongodb://localhost:27017\n */\n uri: 'mongodb://localhost:27017'\n}\n\nconst FIND_OPTS_DEFAULTS = {}\nconst FIND_ONE_OPTS_DEFAULTS = {}\nconst INSERT_OPTS_DEFAULTS = {}\nconst INSERT_MANY_OPTS_DEFAULTS = {}\nconst UPDATE_OPTS_DEFAULTS = {}\nconst REMOVE_OPTS_DEFAULTS = {}\n\n/**\n * MongoDBAdapter class.\n *\n * @example\n * // Use Container instead of DataStore on the server\n * import {Container} from 'js-data'\n * import MongoDBAdapter from 'js-data-mongodb'\n *\n * // Create a store to hold your Mappers\n * const store = new Container({\n * mapperDefaults: {\n * // MongoDB uses \"_id\" as the primary key\n * idAttribute: '_id'\n * }\n * })\n *\n * // Create an instance of MongoDBAdapter with default settings\n * const adapter = new MongoDBAdapter()\n *\n * // Mappers in \"store\" will use the MongoDB adapter by default\n * store.registerAdapter('mongodb', adapter, { default: true })\n *\n * // Create a Mapper that maps to a \"user\" collection\n * store.defineMapper('user')\n *\n * @class MongoDBAdapter\n * @param {Object} [opts] Configuration opts.\n * @param {boolean} [opts.debug=false] Whether to log debugging information.\n * @param {Object} [opts.findOpts] Options to pass to collection#find.\n * @param {Object} [opts.findOneOpts] Options to pass to collection#findOne.\n * @param {Object} [opts.insertOpts] Options to pass to collection#insert.\n * @param {Object} [opts.insertManyOpts] Options to pass to\n * collection#insertMany.\n * @param {boolean} [opts.raw=false] Whether to return detailed result objects\n * instead of just record data.\n * @param {Object} [opts.removeOpts] Options to pass to collection#remove.\n * @param {boolean} [opts.translateId=true] Convert ObjectIDs to strings when\n * pulling records out of the database.\n * @param {Object} [opts.updateOpts] Options to pass to collection#update.\n * @param {string} [opts.uri=\"mongodb://localhost:27017\"] MongoDB URI.\n */\nexport default function MongoDBAdapter (opts) {\n const self = this\n opts || (opts = {})\n if (isString(opts)) {\n opts = { uri: opts }\n }\n fillIn(opts, DEFAULTS)\n fillIn(self, opts)\n\n /**\n * Default options to pass to collection#find.\n *\n * @name MongoDBAdapter#findOpts\n * @type {Object}\n * @default {}\n */\n self.findOpts || (self.findOpts = {})\n fillIn(self.findOpts, FIND_OPTS_DEFAULTS)\n\n /**\n * Default options to pass to collection#findOne.\n *\n * @name MongoDBAdapter#findOneOpts\n * @type {Object}\n * @default {}\n */\n self.findOneOpts || (self.findOneOpts = {})\n fillIn(self.findOneOpts, FIND_ONE_OPTS_DEFAULTS)\n\n /**\n * Default options to pass to collection#insert.\n *\n * @name MongoDBAdapter#insertOpts\n * @type {Object}\n * @default {}\n */\n self.insertOpts || (self.insertOpts = {})\n fillIn(self.insertOpts, INSERT_OPTS_DEFAULTS)\n\n /**\n * Default options to pass to collection#insertMany.\n *\n * @name MongoDBAdapter#insertManyOpts\n * @type {Object}\n * @default {}\n */\n self.insertManyOpts || (self.insertManyOpts = {})\n fillIn(self.insertManyOpts, INSERT_MANY_OPTS_DEFAULTS)\n\n /**\n * Default options to pass to collection#update.\n *\n * @name MongoDBAdapter#updateOpts\n * @type {Object}\n * @default {}\n */\n self.updateOpts || (self.updateOpts = {})\n fillIn(self.updateOpts, UPDATE_OPTS_DEFAULTS)\n\n /**\n * Default options to pass to collection#update.\n *\n * @name MongoDBAdapter#removeOpts\n * @type {Object}\n * @default {}\n */\n self.removeOpts || (self.removeOpts = {})\n fillIn(self.removeOpts, REMOVE_OPTS_DEFAULTS)\n\n /**\n * A Promise that resolves to a reference to the MongoDB client being used by\n * this adapter.\n *\n * @name MongoDBAdapter#client\n * @type {Object}\n */\n self.client = new Promise(function (resolve, reject) {\n MongoClient.connect(opts.uri, function (err, db) {\n return err ? reject(err) : resolve(db)\n })\n })\n}\n\naddHiddenPropsToTarget(MongoDBAdapter.prototype, {\n /**\n * Translate ObjectIDs to strings.\n *\n * @name MongoDBAdapter#_translateId\n * @method\n * @return {*}\n */\n _translateId (r, opts) {\n opts || (opts = {})\n if (this.getOpt('translateId', opts)) {\n if (isArray(r)) {\n r.forEach(function (_r) {\n const __id = _r._id ? _r._id.toString() : _r._id\n _r._id = typeof __id === 'string' ? __id : _r._id\n })\n } else if (isObject(r)) {\n const __id = r._id ? r._id.toString() : r._id\n r._id = typeof __id === 'string' ? __id : r._id\n }\n }\n return r\n },\n\n /**\n * @name MongoDBAdapter#afterCreate\n * @method\n */\n afterCreate: noop2,\n\n /**\n * @name MongoDBAdapter#afterCreateMany\n * @method\n */\n afterCreateMany: noop2,\n\n /**\n * @name MongoDBAdapter#afterDestroy\n * @method\n */\n afterDestroy: noop2,\n\n /**\n * @name MongoDBAdapter#afterDestroyAll\n * @method\n */\n afterDestroyAll: noop2,\n\n /**\n * @name MongoDBAdapter#afterFind\n * @method\n */\n afterFind: noop2,\n\n /**\n * @name MongoDBAdapter#afterFindAll\n * @method\n */\n afterFindAll: noop2,\n\n /**\n * @name MongoDBAdapter#afterUpdate\n * @method\n */\n afterUpdate: noop2,\n\n /**\n * @name MongoDBAdapter#afterUpdateAll\n * @method\n */\n afterUpdateAll: noop2,\n\n /**\n * @name MongoDBAdapter#afterUpdateMany\n * @method\n */\n afterUpdateMany: noop2,\n\n /**\n * @name MongoDBAdapter#beforeCreate\n * @method\n */\n beforeCreate: noop,\n\n /**\n * @name MongoDBAdapter#beforeCreateMany\n * @method\n */\n beforeCreateMany: noop,\n\n /**\n * @name MongoDBAdapter#beforeDestroy\n * @method\n */\n beforeDestroy: noop,\n\n /**\n * @name MongoDBAdapter#beforeDestroyAll\n * @method\n */\n beforeDestroyAll: noop,\n\n /**\n * @name MongoDBAdapter#beforeFind\n * @method\n */\n beforeFind: noop,\n\n /**\n * @name MongoDBAdapter#beforeFindAll\n * @method\n */\n beforeFindAll: noop,\n\n /**\n * @name MongoDBAdapter#beforeUpdate\n * @method\n */\n beforeUpdate: noop,\n\n /**\n * @name MongoDBAdapter#beforeUpdateAll\n * @method\n */\n beforeUpdateAll: noop,\n\n /**\n * @name MongoDBAdapter#beforeUpdateMany\n * @method\n */\n beforeUpdateMany: noop,\n\n /**\n * @name MongoDBAdapter#dbg\n * @method\n */\n dbg (...args) {\n this.log('debug', ...args)\n },\n\n /**\n * Return a Promise that resolves to a reference to the MongoDB client being\n * used by this adapter.\n *\n * Useful when you need to do anything custom with the MongoDB client library.\n *\n * @name MongoDBAdapter#getClient\n * @method\n * @return {Object} MongoDB client.\n */\n getClient () {\n return this.client\n },\n\n /**\n * Map filtering params in a selection query to MongoDB a filtering object.\n *\n * Handles the following:\n *\n * - where\n * - and bunch of filtering operators\n *\n * @name MongoDBAdapter#getQuery\n * @method\n * @return {Object}\n */\n getQuery (mapper, query) {\n query = plainCopy(query || {})\n query.where || (query.where = {})\n\n forOwn(query, function (config, keyword) {\n if (reserved.indexOf(keyword) === -1) {\n if (isObject(config)) {\n query.where[keyword] = config\n } else {\n query.where[keyword] = {\n '==': config\n }\n }\n delete query[keyword]\n }\n })\n\n let mongoQuery = {}\n\n if (Object.keys(query.where).length !== 0) {\n forOwn(query.where, function (criteria, field) {\n if (!isObject(criteria)) {\n query.where[field] = {\n '==': criteria\n }\n }\n forOwn(criteria, function (v, op) {\n if (op === '==' || op === '===' || op === 'contains') {\n mongoQuery[field] = v\n } else if (op === '!=' || op === '!==' || op === 'notContains') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$ne = v\n } else if (op === '>') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$gt = v\n } else if (op === '>=') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$gte = v\n } else if (op === '<') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$lt = v\n } else if (op === '<=') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$lte = v\n } else if (op === 'in') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$in = v\n } else if (op === 'notIn') {\n mongoQuery[field] = mongoQuery[field] || {}\n mongoQuery[field].$nin = v\n } else if (op === '|==' || op === '|===' || op === '|contains') {\n mongoQuery.$or = mongoQuery.$or || []\n let orEqQuery = {}\n orEqQuery[field] = v\n mongoQuery.$or.push(orEqQuery)\n } else if (op === '|!=' || op === '|!==' || op === '|notContains') {\n mongoQuery.$or = mongoQuery.$or || []\n let orNeQuery = {}\n orNeQuery[field] = {\n '$ne': v\n }\n mongoQuery.$or.push(orNeQuery)\n } else if (op === '|>') {\n mongoQuery.$or = mongoQuery.$or || []\n let orGtQuery = {}\n orGtQuery[field] = {\n '$gt': v\n }\n mongoQuery.$or.push(orGtQuery)\n } else if (op === '|>=') {\n mongoQuery.$or = mongoQuery.$or || []\n let orGteQuery = {}\n orGteQuery[field] = {\n '$gte': v\n }\n mongoQuery.$or.push(orGteQuery)\n } else if (op === '|<') {\n mongoQuery.$or = mongoQuery.$or || []\n let orLtQuery = {}\n orLtQuery[field] = {\n '$lt': v\n }\n mongoQuery.$or.push(orLtQuery)\n } else if (op === '|<=') {\n mongoQuery.$or = mongoQuery.$or || []\n let orLteQuery = {}\n orLteQuery[field] = {\n '$lte': v\n }\n mongoQuery.$or.push(orLteQuery)\n } else if (op === '|in') {\n mongoQuery.$or = mongoQuery.$or || []\n let orInQuery = {}\n orInQuery[field] = {\n '$in': v\n }\n mongoQuery.$or.push(orInQuery)\n } else if (op === '|notIn') {\n mongoQuery.$or = mongoQuery.$or || []\n let orNinQuery = {}\n orNinQuery[field] = {\n '$nin': v\n }\n mongoQuery.$or.push(orNinQuery)\n }\n })\n })\n }\n\n return mongoQuery\n },\n\n /**\n * Logging utility method.\n *\n * @name MongoDBAdapter#log\n * @method\n */\n log (level, ...args) {\n if (level && !args.length) {\n args.push(level)\n level = 'debug'\n }\n if (level === 'debug' && !this.debug) {\n return\n }\n const prefix = `${level.toUpperCase()}: (MongoDBAdapter)`\n if (console[level]) {\n console[level](prefix, ...args)\n } else {\n console.log(prefix, ...args)\n }\n },\n\n /**\n * Map non-filtering params in a selection query to MongoDB query options.\n *\n * Handles the following:\n *\n * - limit\n * - skip/offset\n * - orderBy/sort\n *\n * @name MongoDBAdapter#getQueryOptions\n * @method\n * @return {Object}\n */\n getQueryOptions (mapper, query) {\n query = plainCopy(query || {})\n query.orderBy = query.orderBy || query.sort\n query.skip = query.skip || query.offset\n\n let queryOptions = {}\n\n if (query.orderBy) {\n if (isString(query.orderBy)) {\n query.orderBy = [\n [query.orderBy, 'asc']\n ]\n }\n for (var i = 0; i < query.orderBy.length; i++) {\n if (isString(query.orderBy[i])) {\n query.orderBy[i] = [query.orderBy[i], 'asc']\n }\n }\n queryOptions.sort = query.orderBy\n }\n\n if (query.skip) {\n queryOptions.skip = +query.skip\n }\n\n if (query.limit) {\n queryOptions.limit = +query.limit\n }\n\n return queryOptions\n },\n\n /**\n * Resolve the value of the specified option based on the given options and\n * this adapter's settings.\n *\n * @name MongoDBAdapter#getOpt\n * @method\n * @param {string} opt The name of the option.\n * @param {Object} [opts] Configuration options.\n * @return {*} The value of the specified option.\n */\n getOpt (opt, opts) {\n opts || (opts = {})\n return isUndefined(opts[opt]) ? plainCopy(this[opt]) : plainCopy(opts[opt])\n },\n\n /**\n * Turn an _id into an ObjectID if it isn't already an ObjectID.\n *\n * @name MongoDBAdapter#toObjectID\n * @method\n * @return {*}\n */\n toObjectID (mapper, id) {\n if (id !== undefined && mapper.idAttribute === '_id' && typeof id === 'string' && ObjectID.isValid(id) && !(id instanceof ObjectID)) {\n return new ObjectID(id)\n }\n return id\n },\n\n /**\n * Return the foreignKey from the given record for the provided relationship.\n *\n * If the foreignKeys in your database are saved as ObjectIDs, then override\n * this method and change it to something like:\n *\n * ```\n * return this.toObjectID(mapper, this.constructor.prototype.makeHasManyForeignKey.call(this, mapper, def, record))\n * ```\n *\n * There may be other reasons why you may want to override this method, like\n * when the id of the parent doesn't exactly match up to the key on the child.\n *\n * @name MongoDBAdapter#makeHasManyForeignKey\n * @method\n * @return {*}\n */\n makeHasManyForeignKey (mapper, def, record) {\n return def.getForeignKey(record)\n },\n\n /**\n * Return the foreignKeys from the given record for the provided relationship.\n *\n * @name MongoDBAdapter#makeHasManyForeignKeys\n * @method\n * @return {*}\n */\n makeHasManyForeignKeys (mapper, def, record) {\n return get(record, mapper.idAttribute)\n },\n\n /**\n * Load a hasMany relationship.\n *\n * @name MongoDBAdapter#loadHasMany\n * @method\n * @return {Promise}\n */\n loadHasMany (mapper, def, records, __opts) {\n const self = this\n let singular = false\n\n if (isObject(records) && !isArray(records)) {\n singular = true\n records = [records]\n }\n const IDs = records.map(function (record) {\n return self.makeHasManyForeignKey(mapper, def, record)\n })\n const query = {}\n const criteria = query[def.foreignKey] = {}\n if (singular) {\n // more efficient query when we only have one record\n criteria['=='] = IDs[0]\n } else {\n criteria['in'] = IDs.filter(function (id) {\n return id\n })\n }\n return self.findAll(def.getRelation(), query, __opts).then(function (relatedItems) {\n records.forEach(function (record) {\n let attached = []\n // avoid unneccesary iteration when we only have one record\n if (singular) {\n attached = relatedItems\n } else {\n relatedItems.forEach(function (relatedItem) {\n if (get(relatedItem, def.foreignKey) === record[mapper.idAttribute]) {\n attached.push(relatedItem)\n }\n })\n }\n def.setLocalField(record, attached)\n })\n })\n },\n\n /**\n * Load a hasOne relationship.\n *\n * @name MongoDBAdapter#loadHasOne\n * @method\n * @return {Promise}\n */\n loadHasOne (mapper, def, records, __opts) {\n if (isObject(records) && !isArray(records)) {\n records = [records]\n }\n return this.loadHasMany(mapper, def, records, __opts).then(function () {\n records.forEach(function (record) {\n const relatedData = def.getLocalField(record)\n if (isArray(relatedData) && relatedData.length) {\n def.setLocalField(record, relatedData[0])\n }\n })\n })\n },\n\n /**\n * Return the foreignKey from the given record for the provided relationship.\n *\n * @name MongoDBAdapter#makeBelongsToForeignKey\n * @method\n * @return {*}\n */\n makeBelongsToForeignKey (mapper, def, record) {\n return this.toObjectID(def.getRelation(), def.getForeignKey(record))\n },\n\n /**\n * Load a belongsTo relationship.\n *\n * @name MongoDBAdapter#loadBelongsTo\n * @method\n * @return {Promise}\n */\n loadBelongsTo (mapper, def, records, __opts) {\n const self = this\n const relationDef = def.getRelation()\n\n if (isObject(records) && !isArray(records)) {\n const record = records\n return self.find(relationDef, self.makeBelongsToForeignKey(mapper, def, record), __opts).then(function (relatedItem) {\n def.setLocalField(record, relatedItem)\n })\n } else {\n const keys = records.map(function (record) {\n return self.makeBelongsToForeignKey(mapper, def, record)\n }).filter(function (key) {\n return key\n })\n return self.findAll(relationDef, {\n where: {\n [relationDef.idAttribute]: {\n 'in': keys\n }\n }\n }, __opts).then(function (relatedItems) {\n records.forEach(function (record) {\n relatedItems.forEach(function (relatedItem) {\n if (relatedItem[relationDef.idAttribute] === record[def.foreignKey]) {\n def.setLocalField(record, relatedItem)\n }\n })\n })\n })\n }\n },\n\n /**\n * Retrieve the record with the given primary key.\n *\n * @name MongoDBAdapter#find\n * @method\n * @param {Object} mapper The mapper.\n * @param {(string|number)} id Primary key of the record to retrieve.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.findOneOpts] Options to pass to collection#findOne.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {string[]} [opts.with=[]] Relations to eager load.\n * @return {Promise}\n */\n find (mapper, id, opts) {\n const self = this\n let record, op\n opts || (opts = {})\n opts.with || (opts.with = [])\n\n const findOneOpts = self.getOpt('findOneOpts', opts)\n findOneOpts.fields || (findOneOpts.fields = {})\n\n return self.getClient().then(function (client) {\n // beforeFind lifecycle hook\n op = opts.op = 'beforeFind'\n return resolve(self[op](mapper, id, opts)).then(function () {\n return new Promise(function (resolve, reject) {\n let mongoQuery = {}\n mongoQuery[mapper.idAttribute] = self.toObjectID(mapper, id)\n client.collection(mapper.table || underscore(mapper.name)).findOne(mongoQuery, findOneOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n })\n }).then(function (_record) {\n if (!_record) {\n return\n }\n record = _record\n self._translateId(record, opts)\n const tasks = []\n\n forEachRelation(mapper, opts, function (def, __opts) {\n const relatedMapper = def.getRelation()\n let task\n\n if (def.foreignKey && (def.type === 'hasOne' || def.type === 'hasMany')) {\n if (def.type === 'hasOne') {\n task = self.loadHasOne(mapper, def, record, __opts)\n } else {\n task = self.loadHasMany(mapper, def, record, __opts)\n }\n } else if (def.type === 'hasMany' && def.localKeys) {\n let localKeys = []\n let itemKeys = get(record, def.localKeys) || []\n itemKeys = isArray(itemKeys) ? itemKeys : Object.keys(itemKeys)\n localKeys = localKeys.concat(itemKeys)\n task = self.findAll(relatedMapper, {\n where: {\n [relatedMapper.idAttribute]: {\n 'in': unique(localKeys).filter(function (x) { return x }).map(function (x) { return self.toObjectID(relatedMapper, x) })\n }\n }\n }, __opts).then(function (relatedItems) {\n def.setLocalField(record, relatedItems)\n })\n } else if (def.type === 'hasMany' && def.foreignKeys) {\n task = self.findAll(relatedMapper, {\n where: {\n [def.foreignKeys]: {\n 'contains': self.makeHasManyForeignKeys(mapper, def, record)\n }\n }\n }, __opts).then(function (relatedItems) {\n def.setLocalField(record, relatedItems)\n })\n } else if (def.type === 'belongsTo') {\n task = self.loadBelongsTo(mapper, def, record, __opts)\n }\n if (task) {\n tasks.push(task)\n }\n })\n\n return Promise.all(tasks)\n }).then(function () {\n // afterFind lifecycle hook\n op = opts.op = 'afterFind'\n return resolve(self[op](mapper, id, opts, record)).then(function (_record) {\n // Allow for re-assignment from lifecycle hook\n record = isUndefined(_record) ? record : _record\n return self.getOpt('raw', opts) ? {\n data: record,\n found: record ? 1 : 0\n } : record\n })\n })\n },\n\n /**\n * Retrieve the records that match the selection query.\n *\n * @name MongoDBAdapter#findAll\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object} query Selection query.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.findOpts] Options to pass to collection#find.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {string[]} [opts.with=[]] Relations to eager load.\n * @return {Promise}\n */\n findAll (mapper, query, opts) {\n const self = this\n opts || (opts = {})\n opts.with || (opts.with = [])\n\n let records = []\n let op\n const findOpts = self.getOpt('findOpts', opts)\n fillIn(findOpts, self.getQueryOptions(mapper, query))\n findOpts.fields || (findOpts.fields = {})\n const mongoQuery = self.getQuery(mapper, query)\n\n return self.getClient().then(function (client) {\n // beforeFindAll lifecycle hook\n op = opts.op = 'beforeFindAll'\n return resolve(self[op](mapper, query, opts)).then(function () {\n return new Promise(function (resolve, reject) {\n client.collection(mapper.table || underscore(mapper.name)).find(mongoQuery, findOpts).toArray(function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n })\n }).then(function (_records) {\n records = _records\n self._translateId(records, opts)\n const tasks = []\n forEachRelation(mapper, opts, function (def, __opts) {\n const relatedMapper = def.getRelation()\n let task\n if (def.foreignKey && (def.type === 'hasOne' || def.type === 'hasMany')) {\n if (def.type === 'hasMany') {\n task = self.loadHasMany(mapper, def, records, __opts)\n } else {\n task = self.loadHasOne(mapper, def, records, __opts)\n }\n } else if (def.type === 'hasMany' && def.localKeys) {\n let localKeys = []\n records.forEach(function (item) {\n let itemKeys = item[def.localKeys] || []\n itemKeys = isArray(itemKeys) ? itemKeys : Object.keys(itemKeys)\n localKeys = localKeys.concat(itemKeys)\n })\n task = self.findAll(relatedMapper, {\n where: {\n [relatedMapper.idAttribute]: {\n 'in': unique(localKeys).filter(function (x) { return x }).map(function (x) { return self.toObjectID(relatedMapper, x) })\n }\n }\n }, __opts).then(function (relatedItems) {\n records.forEach(function (item) {\n let attached = []\n let itemKeys = get(item, def.localKeys) || []\n itemKeys = isArray(itemKeys) ? itemKeys : Object.keys(itemKeys)\n relatedItems.forEach(function (relatedItem) {\n if (itemKeys && itemKeys.indexOf(relatedItem[relatedMapper.idAttribute]) !== -1) {\n attached.push(relatedItem)\n }\n })\n def.setLocalField(item, attached)\n })\n return relatedItems\n })\n } else if (def.type === 'hasMany' && def.foreignKeys) {\n throw new Error('findAll eager load hasMany foreignKeys not supported!')\n } else if (def.type === 'belongsTo') {\n task = self.loadBelongsTo(mapper, def, records, __opts)\n }\n if (task) {\n tasks.push(task)\n }\n })\n return Promise.all(tasks)\n }).then(function () {\n // afterFindAll lifecycle hook\n op = opts.op = 'afterFindAll'\n return resolve(self[op](mapper, query, opts, records)).then(function (_records) {\n // Allow for re-assignment from lifecycle hook\n records = isUndefined(_records) ? records : _records\n return self.getOpt('raw', opts) ? {\n data: records,\n found: records.length\n } : records\n })\n })\n },\n\n /**\n * Create a new record.\n *\n * @name MongoDBAdapter#create\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object} props The record to be created.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.insertOpts] Options to pass to collection#insert.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @return {Promise}\n */\n create (mapper, props, opts) {\n const self = this\n let op\n props || (props = {})\n opts || (opts = {})\n\n const insertOpts = self.getOpt('insertOpts', opts)\n\n return self.getClient().then(function (client) {\n // beforeCreate lifecycle hook\n op = opts.op = 'beforeCreate'\n return resolve(self[op](mapper, props, opts)).then(function (_props) {\n // Allow for re-assignment from lifecycle hook\n _props = isUndefined(_props) ? props : _props\n return new Promise(function (resolve, reject) {\n const collection = client.collection(mapper.table || underscore(mapper.name))\n const method = collection.insertOne ? 'insertOne' : 'insert'\n collection[method](_props, insertOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n }).then(function (cursor) {\n let record\n let r = cursor.ops ? cursor.ops : cursor\n self._translateId(r, opts)\n record = isArray(r) ? r[0] : r\n\n // afterCreate lifecycle hook\n op = opts.op = 'afterCreate'\n return self[op](mapper, props, opts, record).then(function (_record) {\n // Allow for re-assignment from lifecycle hook\n record = isUndefined(_record) ? record : _record\n const result = {}\n fillIn(result, cursor)\n delete result.connection\n result.data = record\n result.created = record ? 1 : 0\n return self.getOpt('raw', opts) ? result : result.data\n })\n })\n })\n },\n\n /**\n * Create multiple records in a single batch.\n *\n * @name MongoDBAdapter#createMany\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object} props The records to be created.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.insertManyOpts] Options to pass to\n * collection#insertMany.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @return {Promise}\n */\n createMany (mapper, props, opts) {\n const self = this\n let op\n props || (props = {})\n opts || (opts = {})\n\n const insertManyOpts = self.getOpt('insertManyOpts', opts)\n\n return self.getClient().then(function (client) {\n // beforeCreateMany lifecycle hook\n op = opts.op = 'beforeCreateMany'\n return resolve(self[op](mapper, props, opts)).then(function (_props) {\n // Allow for re-assignment from lifecycle hook\n _props = isUndefined(_props) ? props : _props\n return new Promise(function (resolve, reject) {\n const collection = client.collection(mapper.table || underscore(mapper.name))\n collection.insertMany(_props, insertManyOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n }).then(function (cursor) {\n let records\n let r = cursor.ops ? cursor.ops : cursor\n self._translateId(r, opts)\n records = r\n\n // afterCreateMany lifecycle hook\n op = opts.op = 'afterCreateMany'\n return self[op](mapper, props, opts, records).then(function (_records) {\n // Allow for re-assignment from lifecycle hook\n records = isUndefined(_records) ? records : _records\n const result = {}\n fillIn(result, cursor)\n delete result.connection\n result.data = records\n result.created = records.length\n return self.getOpt('raw', opts) ? result : result.data\n })\n })\n })\n },\n\n /**\n * Destroy the record with the given primary key.\n *\n * @name MongoDBAdapter#destroy\n * @method\n * @param {Object} mapper The mapper.\n * @param {(string|number)} id Primary key of the record to destroy.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.removeOpts] Options to pass to collection#remove.\n * @return {Promise}\n */\n destroy (mapper, id, opts) {\n const self = this\n let op\n opts || (opts = {})\n const removeOpts = self.getOpt('removeOpts', opts)\n\n return self.getClient().then(function (client) {\n // beforeDestroy lifecycle hook\n op = opts.op = 'beforeDestroy'\n return resolve(self[op](mapper, id, opts)).then(function () {\n return new Promise(function (resolve, reject) {\n const mongoQuery = {}\n mongoQuery[mapper.idAttribute] = self.toObjectID(mapper, id)\n const collection = client.collection(mapper.table || underscore(mapper.name))\n collection[collection.deleteOne ? 'deleteOne' : 'remove'](mongoQuery, removeOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n })\n }).then(function (cursor) {\n // afterDestroy lifecycle hook\n op = opts.op = 'afterDestroy'\n return resolve(self[op](mapper, id, opts, cursor)).then(function (_cursor) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_cursor) ? cursor : _cursor\n })\n }).then(function (cursor) {\n if (cursor) {\n delete cursor.connection\n }\n return self.getOpt('raw', opts) ? cursor : undefined\n })\n },\n\n /**\n * Destroy the records that match the selection query.\n *\n * @name MongoDBAdapter#destroyAll\n * @method\n * @param {Object} mapper the mapper.\n * @param {Object} [query] Selection query.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.removeOpts] Options to pass to collection#remove.\n * @return {Promise}\n */\n destroyAll (mapper, query, opts) {\n const self = this\n let op\n query || (query = {})\n opts || (opts = {})\n const removeOpts = self.getOpt('removeOpts', opts)\n fillIn(removeOpts, self.getQueryOptions(mapper, query))\n\n return self.getClient().then(function (client) {\n // beforeDestroyAll lifecycle hook\n op = opts.op = 'beforeDestroyAll'\n return resolve(self[op](mapper, query, opts)).then(function () {\n const mongoQuery = self.getQuery(mapper, query)\n return new Promise(function (resolve, reject) {\n const collection = client.collection(mapper.table || underscore(mapper.name))\n collection[collection.deleteMany ? 'deleteMany' : 'remove'](mongoQuery, removeOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n })\n }).then(function (cursor) {\n // afterDestroyAll lifecycle hook\n op = opts.op = 'afterDestroyAll'\n return resolve(self[op](mapper, query, opts, cursor)).then(function (_cursor) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_cursor) ? cursor : _cursor\n })\n }).then(function (cursor) {\n if (cursor) {\n delete cursor.connection\n }\n return self.getOpt('raw', opts) ? cursor : undefined\n })\n },\n\n /**\n * Apply the given update to the record with the specified primary key.\n *\n * @name MongoDBAdapter#update\n * @method\n * @param {Object} mapper The mapper.\n * @param {(string|number)} id The primary key of the record to be updated.\n * @param {Object} props The update to apply to the record.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.updateOpts] Options to pass to collection#update.\n * @return {Promise}\n */\n update (mapper, id, props, opts) {\n const self = this\n props || (props = {})\n opts || (opts = {})\n let op\n const updateOpts = self.getOpt('updateOpts', opts)\n\n return self.find(mapper, id, { raw: false }).then(function (record) {\n if (!record) {\n throw new Error('Not Found')\n }\n // beforeUpdate lifecycle hook\n op = opts.op = 'beforeUpdate'\n return resolve(self[op](mapper, id, props, opts))\n }).then(function (_props) {\n // Allow for re-assignment from lifecycle hook\n _props = isUndefined(_props) ? props : _props\n return self.getClient().then(function (client) {\n return new Promise(function (resolve, reject) {\n const mongoQuery = {}\n mongoQuery[mapper.idAttribute] = self.toObjectID(mapper, id)\n const collection = client.collection(mapper.table || underscore(mapper.name))\n collection[collection.updateOne ? 'updateOne' : 'update'](mongoQuery, { $set: _props }, updateOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n })\n }).then(function (cursor) {\n if (cursor) {\n delete cursor.connection\n }\n return self.find(mapper, id, { raw: false }).then(function (record) {\n // afterUpdate lifecycle hook\n op = opts.op = 'afterUpdate'\n return resolve(self[op](mapper, id, props, opts, record)).then(function (_record) {\n // Allow for re-assignment from lifecycle hook\n record = isUndefined(_record) ? record : _record\n const result = {}\n fillIn(result, cursor)\n result.data = record\n result.updated = record ? 1 : 0\n return self.getOpt('raw', opts) ? result : result.data\n })\n })\n })\n },\n\n /**\n * Apply the given update to all records that match the selection query.\n *\n * @name MongoDBAdapter#updateAll\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object} props The update to apply to the selected records.\n * @param {Object} [query] Selection query.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.updateOpts] Options to pass to collection#update.\n * @return {Promise}\n */\n updateAll (mapper, props, query, opts) {\n const self = this\n props || (props = {})\n query || (query = {})\n opts || (opts = {})\n let op, ids\n const updateOpts = self.getOpt('updateOpts', opts)\n updateOpts.multi = true\n\n return self.getClient().then(function (client) {\n const queryOptions = self.getQueryOptions(mapper, query)\n queryOptions.$set = props\n const mongoQuery = self.getQuery(mapper, query)\n\n // beforeUpdateAll lifecycle hook\n op = opts.op = 'beforeUpdateAll'\n return resolve(self[op](mapper, props, query, opts)).then(function () {\n return self.findAll(mapper, query, { raw: false })\n }).then(function (records) {\n ids = records.map(function (record) {\n return self.toObjectID(mapper, record[mapper.idAttribute])\n })\n\n return new Promise(function (resolve, reject) {\n const collection = client.collection(mapper.table || underscore(mapper.name))\n collection[collection.updateMany ? 'updateMany' : 'update'](mongoQuery, queryOptions, updateOpts, function (err, cursor) {\n return err ? reject(err) : resolve(cursor)\n })\n })\n }).then(function (cursor) {\n if (cursor) {\n delete cursor.connection\n }\n const query = {}\n query[mapper.idAttribute] = {\n 'in': ids\n }\n return self.findAll(mapper, query, { raw: false }).then(function (records) {\n // afterUpdateAll lifecycle hook\n op = opts.op = 'afterUpdateAll'\n return self[op](mapper, props, query, opts, records).then(function (_records) {\n // Allow for re-assignment from lifecycle hook\n records = isUndefined(_records) ? records : _records\n const result = {}\n fillIn(result, cursor)\n result.data = records\n result.updated = records.length\n return self.getOpt('raw', opts) ? result : result.data\n })\n })\n })\n })\n },\n\n /**\n * Not supported.\n *\n * @name MongoDBAdapter#updateMany\n * @method\n */\n updateMany () {\n throw new Error('not supported!')\n }\n})\n"],"names":["utils","ObjectID"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAME,yBAWEA,aAXF;IACA,SAUEA,aAVF;IACA,kBASEA,aATF;IACA,SAQEA,aARF;IACA,MAOEA,aAPF;IAC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C;CAAjD;;"} \ No newline at end of file diff --git a/package.json b/package.json index bf3b46c..30f0f14 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "js-data-mongodb", "description": "MongoDB adapter for js-data.", - "version": "1.0.0-alpha.1", + "version": "1.0.0-alpha.2", "homepage": "https://github.com/js-data/js-data-mongodb", "repository": { "type": "git", diff --git a/src/index.js b/src/index.js index 2180fe7..c57c157 100644 --- a/src/index.js +++ b/src/index.js @@ -13,6 +13,7 @@ const { isObject, isString, isUndefined, + plainCopy, resolve } = utils @@ -387,20 +388,20 @@ addHiddenPropsToTarget(MongoDBAdapter.prototype, { * @method * @return {Object} */ - getQuery (Resource, query) { - query || (query = {}) + getQuery (mapper, query) { + query = plainCopy(query || {}) query.where || (query.where = {}) - forOwn(query, function (v, k) { - if (reserved.indexOf(k) === -1) { - if (isObject(v)) { - query.where[k] = v + forOwn(query, function (config, keyword) { + if (reserved.indexOf(keyword) === -1) { + if (isObject(config)) { + query.where[keyword] = config } else { - query.where[k] = { - '==': v + query.where[keyword] = { + '==': config } } - delete query[k] + delete query[keyword] } }) @@ -534,8 +535,8 @@ addHiddenPropsToTarget(MongoDBAdapter.prototype, { * @method * @return {Object} */ - getQueryOptions (Resource, query) { - query = query || {} + getQueryOptions (mapper, query) { + query = plainCopy(query || {}) query.orderBy = query.orderBy || query.sort query.skip = query.skip || query.offset @@ -578,7 +579,7 @@ addHiddenPropsToTarget(MongoDBAdapter.prototype, { */ getOpt (opt, opts) { opts || (opts = {}) - return isUndefined(opts[opt]) ? this[opt] : opts[opt] + return isUndefined(opts[opt]) ? plainCopy(this[opt]) : plainCopy(opts[opt]) }, /** @@ -588,8 +589,8 @@ addHiddenPropsToTarget(MongoDBAdapter.prototype, { * @method * @return {*} */ - toObjectID (Resource, id) { - if (id !== undefined && Resource.idAttribute === '_id' && typeof id === 'string' && ObjectID.isValid(id) && !(id instanceof ObjectID)) { + toObjectID (mapper, id) { + if (id !== undefined && mapper.idAttribute === '_id' && typeof id === 'string' && ObjectID.isValid(id) && !(id instanceof ObjectID)) { return new ObjectID(id) } return id @@ -1062,7 +1063,7 @@ addHiddenPropsToTarget(MongoDBAdapter.prototype, { * * @name MongoDBAdapter#destroy * @method - * @param {Object} Resource The Resource. + * @param {Object} mapper The mapper. * @param {(string|number)} id Primary key of the record to destroy. * @param {Object} [opts] Configuration options. * @param {boolean} [opts.raw=false] Whether to return a more detailed