From 98f9d55829a7d746fcb5506741ac8cd0d7d174a5 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Sat, 5 Mar 2016 16:14:52 -0800 Subject: [PATCH] 3.0.0-alpha.8 --- AUTHORS | 2 - CHANGELOG.md | 6 + conf.json | 3 +- dist/js-data-rethinkdb.js | 459 +++++----------------------------- dist/js-data-rethinkdb.js.map | 2 +- package.json | 21 +- scripts/AUTHORS | 7 - src/index.js | 396 ++++------------------------- test/handleErrors.test.js | 1 + 9 files changed, 123 insertions(+), 774 deletions(-) delete mode 100644 scripts/AUTHORS diff --git a/AUTHORS b/AUTHORS index 6f33d2c..6f2ea1e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,7 +1,5 @@ # This is the official list of js-data-rethinkdb project authors. # -# This file is controlled by scripts/authors.js -# # Names are formatted as: # # commits Name or Organization # The email address is not required for organizations. diff --git a/CHANGELOG.md b/CHANGELOG.md index 5705400..ce8103e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +##### 3.0.0-alpha.8 - 06 March 2016 + +###### Other +- Extracted common adapter functionality into js-data-adapter +- Extracted common js-data repo utility scripts into js-data-repo-tools + ##### 3.0.0-alpha.7 - 03 March 2016 ###### Backwards compatible API changes diff --git a/conf.json b/conf.json index f148e9b..651653a 100644 --- a/conf.json +++ b/conf.json @@ -15,10 +15,9 @@ "theme": "lumen", "systemName": "js-data-rethinkdb", "copyright": "js-data-rethinkdb Copyright © 2014-2016 js-data-rethinkdb project authors", - "outputSourceFiles": true, "syntaxTheme": "dark", "linenums": true, - "footer": "
Back to js-data.io
", + "footer": "
Back to api.js-data.io
", "analytics": { "ua": "UA-55528236-2", "domain": "api.js-data.io" diff --git a/dist/js-data-rethinkdb.js b/dist/js-data-rethinkdb.js index 0265c41..817ab97 100644 --- a/dist/js-data-rethinkdb.js +++ b/dist/js-data-rethinkdb.js @@ -3,16 +3,13 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var jsData = require('js-data'); +var Adapter = require('js-data-adapter'); +var Adapter__default = _interopDefault(Adapter); var rethinkdbdash = _interopDefault(require('rethinkdbdash')); var underscore = _interopDefault(require('mout/string/underscore')); var unique = _interopDefault(require('mout/array/unique')); var babelHelpers = {}; -babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { - return typeof obj; -} : function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; -}; babelHelpers.defineProperty = function (obj, key, value) { if (key in obj) { @@ -32,6 +29,7 @@ babelHelpers.defineProperty = function (obj, key, value) { babelHelpers; var addHiddenPropsToTarget = jsData.utils.addHiddenPropsToTarget; +var classCallCheck = jsData.utils.classCallCheck; var extend = jsData.utils.extend; var fillIn = jsData.utils.fillIn; var forEachRelation = jsData.utils.forEachRelation; @@ -41,47 +39,13 @@ var isArray = jsData.utils.isArray; var isObject = jsData.utils.isObject; var isString = jsData.utils.isString; var isUndefined = jsData.utils.isUndefined; +var omit = jsData.utils.omit; var plainCopy = jsData.utils.plainCopy; var resolve = jsData.utils.resolve; -var reserved = ['orderBy', 'sort', 'limit', 'offset', 'skip', 'where']; - -var noop = function noop() { - var self = this; - - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - var opts = args[args.length - 1]; - self.dbg.apply(self, [opts.op].concat(args)); - return resolve(); -}; - -var noop2 = function noop2() { - var self = this; - - for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - args[_key2] = arguments[_key2]; - } - - var opts = args[args.length - 2]; - self.dbg.apply(self, [opts.op].concat(args)); - return resolve(); -}; - var withoutRelations = function withoutRelations(mapper, props) { - var relationFields = mapper.relationFields || []; - - // Remove relations - var _props = {}; - forOwn(props, function (value, key) { - if (relationFields.indexOf(key) === -1) { - _props[key] = value; - } - }); - return _props; + return omit(props, mapper.relationFields || []); }; var DEFAULTS = { @@ -260,6 +224,7 @@ var OPERATORS = { * store.defineMapper('user') * * @class RethinkDBAdapter + * @extends Adapter * @param {Object} [opts] Configuration opts. * @param {string} [opts.authKey=""] RethinkDB authorization key. * @param {number} [opts.bufferSize=10] Buffer size for connection pool. @@ -275,9 +240,10 @@ var OPERATORS = { */ function RethinkDBAdapter(opts) { var self = this; + classCallCheck(self, RethinkDBAdapter); opts || (opts = {}); fillIn(opts, DEFAULTS); - fillIn(self, opts); + Adapter__default.call(this, opts); /** * Default options to pass to r#insert. @@ -341,16 +307,31 @@ function RethinkDBAdapter(opts) { self.indices = {}; } +// Setup prototype inheritance from Adapter +RethinkDBAdapter.prototype = Object.create(Adapter__default.prototype, { + constructor: { + value: RethinkDBAdapter, + enumerable: false, + writable: true, + configurable: true + } +}); + +Object.defineProperty(RethinkDBAdapter, '__super__', { + configurable: true, + value: Adapter__default +}); + /** * Alternative to ES6 class syntax for extending `RethinkDBAdapter`. * * @name RethinkDBAdapter.extend * @method * @param {Object} [instanceProps] Properties that will be added to the - * prototype of the subclass. + * prototype of the RethinkDBAdapter. * @param {Object} [classProps] Properties that will be added as static - * properties to the subclass itself. - * @return {Object} Subclass of `RethinkDBAdapter`. + * properties to the RethinkDBAdapter itself. + * @return {Object} RethinkDBAdapter of `RethinkDBAdapter`. */ RethinkDBAdapter.extend = extend; @@ -363,126 +344,6 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { throw new Error('Unknown RethinkDB Error'); } }, - - /** - * @name RethinkDBAdapter#afterCreate - * @method - */ - afterCreate: noop2, - - /** - * @name RethinkDBAdapter#afterCreateMany - * @method - */ - afterCreateMany: noop2, - - /** - * @name RethinkDBAdapter#afterDestroy - * @method - */ - afterDestroy: noop2, - - /** - * @name RethinkDBAdapter#afterDestroyAll - * @method - */ - afterDestroyAll: noop2, - - /** - * @name RethinkDBAdapter#afterFind - * @method - */ - afterFind: noop2, - - /** - * @name RethinkDBAdapter#afterFindAll - * @method - */ - afterFindAll: noop2, - - /** - * @name RethinkDBAdapter#afterUpdate - * @method - */ - afterUpdate: noop2, - - /** - * @name RethinkDBAdapter#afterUpdateAll - * @method - */ - afterUpdateAll: noop2, - - /** - * @name RethinkDBAdapter#afterUpdateMany - * @method - */ - afterUpdateMany: noop2, - - /** - * @name RethinkDBAdapter#beforeCreate - * @method - */ - beforeCreate: noop, - - /** - * @name RethinkDBAdapter#beforeCreateMany - * @method - */ - beforeCreateMany: noop, - - /** - * @name RethinkDBAdapter#beforeDestroy - * @method - */ - beforeDestroy: noop, - - /** - * @name RethinkDBAdapter#beforeDestroyAll - * @method - */ - beforeDestroyAll: noop, - - /** - * @name RethinkDBAdapter#beforeFind - * @method - */ - beforeFind: noop, - - /** - * @name RethinkDBAdapter#beforeFindAll - * @method - */ - beforeFindAll: noop, - - /** - * @name RethinkDBAdapter#beforeUpdate - * @method - */ - beforeUpdate: noop, - - /** - * @name RethinkDBAdapter#beforeUpdateAll - * @method - */ - beforeUpdateAll: noop, - - /** - * @name RethinkDBAdapter#beforeUpdateMany - * @method - */ - beforeUpdateMany: noop, - - /** - * @name RethinkDBAdapter#dbg - * @method - */ - dbg: function dbg() { - for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { - args[_key3] = arguments[_key3]; - } - - this.log.apply(this, ['debug'].concat(args)); - }, selectDb: function selectDb(opts) { return this.r.db(isUndefined(opts.db) ? this.db : opts.db); }, @@ -522,7 +383,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { // Transform non-keyword properties to "where" clause configuration forOwn(query, function (config, keyword) { - if (reserved.indexOf(keyword) === -1) { + if (Adapter.reserved.indexOf(keyword) === -1) { if (isObject(config)) { query.where[keyword] = config; } else { @@ -540,7 +401,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { if (Object.keys(query.where).length !== 0) { // Filter sequence using filter function rql = rql.filter(function (row) { - var subQuery = undefined; + var subQuery = void 0; // Apply filter for each field forOwn(query.where, function (criteria, field) { if (!isObject(criteria)) { @@ -620,7 +481,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { */ create: function create(mapper, props, opts) { var self = this; - var op = undefined; + var op = void 0; props || (props = {}); opts || (opts = {}); @@ -636,21 +497,19 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { return self.selectTable(mapper, opts).insert(props, insertOpts).run(self.getOpt('runOpts', opts)); }).then(function (cursor) { self._handleErrors(cursor); - var record = undefined; + var record = void 0; if (cursor && cursor.changes && cursor.changes.length && cursor.changes[0].new_val) { record = cursor.changes[0].new_val; } - var result = {}; - fillIn(result, cursor); - result.data = record; - result.created = record ? 1 : 0; - result = self.getOpt('raw', opts) ? result : result.data; + var response = new Adapter.Response(record, cursor, 'create'); + response.created = record ? 1 : 0; + response = self.respond(response, opts); // afterCreate lifecycle hook op = opts.op = 'afterCreate'; - return resolve(self[op](mapper, props, opts, result)).then(function (_result) { + return resolve(self[op](mapper, props, opts, response)).then(function (_response) { // Allow for re-assignment from lifecycle hook - return isUndefined(_result) ? result : _result; + return isUndefined(_response) ? response : _response; }); }); }, @@ -672,7 +531,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { */ createMany: function createMany(mapper, props, opts) { var self = this; - var op = undefined; + var op = void 0; props || (props = {}); opts || (opts = {}); @@ -697,9 +556,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { return change.new_val; }); } - var result = {}; - fillIn(result, cursor); - result.data = records; + var result = new Adapter.Response(records, cursor, 'createMany'); result.created = records.length; result = self.getOpt('raw', opts) ? result : result.data; @@ -729,7 +586,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { */ destroy: function destroy(mapper, id, opts) { var self = this; - var op = undefined; + var op = void 0; opts || (opts = {}); return self.waitForTable(mapper, opts).then(function () { @@ -741,8 +598,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { self.dbg(op, id, opts); return self.selectTable(mapper, opts).get(id).delete(self.getOpt('deleteOpts', opts)).run(self.getOpt('runOpts', opts)); }).then(function (cursor) { - var result = {}; - fillIn(result, cursor); + var result = new Adapter.Response(undefined, cursor, 'destroy'); result = self.getOpt('raw', opts) ? result : undefined; // afterDestroy lifecycle hook @@ -779,7 +635,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { */ destroyAll: function destroyAll(mapper, query, opts) { var self = this; - var op = undefined; + var op = void 0; query || (query = {}); opts || (opts = {}); @@ -792,8 +648,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { self.dbg(op, query, opts); return self.filterSequence(self.selectTable(mapper, opts), query).delete(self.getOpt('deleteOpts', opts)).run(self.getOpt('runOpts', opts)); }).then(function (cursor) { - var result = {}; - fillIn(result, cursor); + var result = new Adapter.Response(undefined, cursor, 'destroyAll'); result = self.getOpt('raw', opts) ? result : undefined; // afterDestroyAll lifecycle hook @@ -806,147 +661,6 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { }, - /** - * Return the foreignKey from the given record for the provided relationship. - * - * There may be reasons why you may want to override this method, like when - * the id of the parent doesn't exactly match up to the key on the child. - * - * @name RethinkDBAdapter#makeHasManyForeignKey - * @method - * @return {*} - */ - makeHasManyForeignKey: function makeHasManyForeignKey(mapper, def, record) { - return def.getForeignKey(record); - }, - - - /** - * Load a hasMany relationship. - * - * @name RethinkDBAdapter#loadHasMany - * @method - * @return {Promise} - */ - loadHasMany: function loadHasMany(mapper, def, records, __opts) { - var self = this; - var singular = false; - - if (isObject(records) && !isArray(records)) { - singular = true; - records = [records]; - } - var IDs = records.map(function (record) { - return self.makeHasManyForeignKey(mapper, def, record); - }); - var query = {}; - var criteria = query[def.foreignKey] = {}; - if (singular) { - // more efficient query when we only have one record - criteria['=='] = IDs[0]; - } else { - criteria['in'] = IDs.filter(function (id) { - return id; - }); - } - return self.findAll(def.getRelation(), query, __opts).then(function (relatedItems) { - records.forEach(function (record) { - var attached = []; - // avoid unneccesary iteration when we only have one record - if (singular) { - attached = relatedItems; - } else { - relatedItems.forEach(function (relatedItem) { - if (get(relatedItem, def.foreignKey) === record[mapper.idAttribute]) { - attached.push(relatedItem); - } - }); - } - def.setLocalField(record, attached); - }); - }); - }, - - - /** - * Load a hasOne relationship. - * - * @name RethinkDBAdapter#loadHasOne - * @method - * @return {Promise} - */ - loadHasOne: function loadHasOne(mapper, def, records, __opts) { - if (isObject(records) && !isArray(records)) { - records = [records]; - } - return this.loadHasMany(mapper, def, records, __opts).then(function () { - records.forEach(function (record) { - var relatedData = def.getLocalField(record); - if (isArray(relatedData) && relatedData.length) { - def.setLocalField(record, relatedData[0]); - } - }); - }); - }, - - - /** - * Return the foreignKey from the given record for the provided relationship. - * - * @name RethinkDBAdapter#makeBelongsToForeignKey - * @method - * @return {*} - */ - makeBelongsToForeignKey: function makeBelongsToForeignKey(mapper, def, record) { - return def.getForeignKey(record); - }, - - - /** - * Load a belongsTo relationship. - * - * @name RethinkDBAdapter#loadBelongsTo - * @method - * @return {Promise} - */ - loadBelongsTo: function loadBelongsTo(mapper, def, records, __opts) { - var self = this; - var relationDef = def.getRelation(); - - if (isObject(records) && !isArray(records)) { - var _ret = function () { - var record = records; - return { - v: self.find(relationDef, self.makeBelongsToForeignKey(mapper, def, record), __opts).then(function (relatedItem) { - def.setLocalField(record, relatedItem); - }) - }; - }(); - - if ((typeof _ret === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret)) === "object") return _ret.v; - } else { - var keys = records.map(function (record) { - return self.makeBelongsToForeignKey(mapper, def, record); - }).filter(function (key) { - return key; - }); - return self.findAll(relationDef, { - where: babelHelpers.defineProperty({}, relationDef.idAttribute, { - 'in': keys - }) - }, __opts).then(function (relatedItems) { - records.forEach(function (record) { - relatedItems.forEach(function (relatedItem) { - if (relatedItem[relationDef.idAttribute] === record[def.foreignKey]) { - def.setLocalField(record, relatedItem); - } - }); - }); - }); - } - }, - - /** * Retrieve the record with the given primary key. * @@ -963,8 +677,8 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { */ find: function find(mapper, id, opts) { var self = this; - var record = undefined, - op = undefined; + var record = void 0, + op = void 0; opts || (opts = {}); opts.with || (opts.with = []); @@ -1002,7 +716,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { forEachRelation(mapper, opts, function (def, __opts) { var relatedMapper = def.getRelation(); - var task = undefined; + var task = void 0; if (def.foreignKey && (def.type === 'hasOne' || def.type === 'hasMany')) { if (def.type === 'hasOne') { @@ -1042,10 +756,8 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { return Promise.all(tasks); }).then(function () { - var result = { - data: record, - found: record ? 1 : 0 - }; + var result = new Adapter.Response(record, {}, 'find'); + result.found = record ? 1 : 0; result = self.getOpt('raw', opts) ? result : result.data; // afterFind lifecycle hook @@ -1086,7 +798,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { opts.with || (opts.with = []); var records = []; - var op = undefined; + var op = void 0; var relationList = mapper.relationList || []; var tasks = [self.waitForTable(mapper, opts)]; @@ -1118,7 +830,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { forEachRelation(mapper, opts, function (def, __opts) { var relatedMapper = def.getRelation(); var idAttribute = mapper.idAttribute; - var task = undefined; + var task = void 0; if (def.foreignKey && (def.type === 'hasOne' || def.type === 'hasMany')) { if (def.type === 'hasMany') { task = self.loadHasMany(mapper, def, records, __opts); @@ -1185,10 +897,8 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { return Promise.all(tasks); }).then(function () { records || (records = []); - var result = { - data: records, - found: records.length - }; + var result = new Adapter.Response(records, {}, 'findAll'); + result.found = records.length; result = self.getOpt('raw', opts) ? result : result.data; // afterFindAll lifecycle hook @@ -1221,53 +931,6 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { }, - /** - * Resolve the value of the specified option based on the given options and - * this adapter's settings. - * - * @name RethinkDBAdapter#getOpt - * @method - * @param {string} opt The name of the option. - * @param {Object} [opts] Configuration options. - * @return {*} The value of the specified option. - */ - getOpt: function getOpt(opt, opts) { - opts || (opts = {}); - return isUndefined(opts[opt]) ? plainCopy(this[opt]) : plainCopy(opts[opt]); - }, - - - /** - * Logging utility method. - * - * @name RethinkDBAdapter#log - * @method - */ - log: function log(level) { - for (var _len4 = arguments.length, args = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { - args[_key4 - 1] = arguments[_key4]; - } - - if (level && !args.length) { - args.push(level); - level = 'debug'; - } - if (level === 'debug' && !this.debug) { - return; - } - var prefix = level.toUpperCase() + ': (RethinkDBAdapter)'; - if (console[level]) { - var _console; - - (_console = console)[level].apply(_console, [prefix].concat(args)); - } else { - var _console2; - - (_console2 = console).log.apply(_console2, [prefix].concat(args)); - } - }, - - /** * Apply the given update to the record with the specified primary key. * @@ -1287,7 +950,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { var self = this; props || (props = {}); opts || (opts = {}); - var op = undefined; + var op = void 0; return self.waitForTable(mapper, opts).then(function () { // beforeUpdate lifecycle hook @@ -1300,16 +963,14 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { updateOpts.returnChanges = true; return self.selectTable(mapper, opts).get(id).update(withoutRelations(mapper, props), updateOpts).run(self.getOpt('runOpts', opts)); }).then(function (cursor) { - var record = undefined; + var record = void 0; self._handleErrors(cursor); if (cursor && cursor.changes && cursor.changes.length && cursor.changes[0].new_val) { record = cursor.changes[0].new_val; } else { throw new Error('Not Found'); } - var result = {}; - fillIn(result, cursor); - result.data = record; + var result = new Adapter.Response(record, cursor, 'update'); result.updated = 1; result = self.getOpt('raw', opts) ? result : result.data; @@ -1351,7 +1012,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { props || (props = {}); query || (query = {}); opts || (opts = {}); - var op = undefined; + var op = void 0; return self.waitForTable(mapper, opts).then(function () { // beforeUpdateAll lifecycle hook @@ -1371,9 +1032,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { return change.new_val; }); } - var result = {}; - fillIn(result, cursor); - result.data = records; + var result = new Adapter.Response(records, cursor, 'update'); result.updated = records.length; result = self.getOpt('raw', opts) ? result : result.data; @@ -1405,7 +1064,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { var self = this; records || (records = []); opts || (opts = {}); - var op = undefined; + var op = void 0; var idAttribute = mapper.idAttribute; records = records.filter(function (record) { @@ -1427,16 +1086,14 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { }); return self.selectTable(mapper, opts).insert(_records, insertOpts).run(self.getOpt('runOpts', opts)); }).then(function (cursor) { - var updatedRecords = undefined; + var updatedRecords = void 0; self._handleErrors(cursor); if (cursor && cursor.changes && cursor.changes.length) { updatedRecords = cursor.changes.map(function (change) { return change.new_val; }); } - var result = {}; - fillIn(result, cursor); - result.data = updatedRecords || []; + var result = new Adapter.Response(updatedRecords || [], cursor, 'update'); result.updated = result.data.length; result = self.getOpt('raw', opts) ? result : result.data; diff --git a/dist/js-data-rethinkdb.js.map b/dist/js-data-rethinkdb.js.map index bbef1bd..dcc68da 100644 --- a/dist/js-data-rethinkdb.js.map +++ b/dist/js-data-rethinkdb.js.map @@ -1 +1 @@ -{"version":3,"file":"js-data-rethinkdb.js","sources":["../src/index.js"],"sourcesContent":["import {utils} from 'js-data'\nimport rethinkdbdash from 'rethinkdbdash'\nimport underscore from 'mout/string/underscore'\nimport unique from 'mout/array/unique'\n\nconst {\n addHiddenPropsToTarget,\n extend,\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\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 withoutRelations = function (mapper, props) {\n const relationFields = mapper.relationFields || []\n\n // Remove relations\n const _props = {}\n forOwn(props, function (value, key) {\n if (relationFields.indexOf(key) === -1) {\n _props[key] = value\n }\n })\n return _props\n}\n\nconst DEFAULTS = {\n /**\n * RethinkDB authorization key.\n *\n * @name RethinkDBAdapter#authKey\n * @type {string}\n */\n authKey: '',\n\n /**\n * Buffer size for connection pool.\n *\n * @name RethinkDBAdapter#bufferSize\n * @type {number}\n * @default 10\n */\n bufferSize: 10,\n\n /**\n * Default database.\n *\n * @name RethinkDBAdapter#db\n * @type {string}\n * @default \"test\"\n */\n db: 'test',\n\n /**\n * Whether to log debugging information.\n *\n * @name RethinkDBAdapter#debug\n * @type {boolean}\n * @default false\n */\n debug: false,\n\n /**\n * RethinkDB host.\n *\n * @name RethinkDBAdapter#host\n * @type {string}\n * @default \"localhost\"\n */\n host: 'localhost',\n\n /**\n * Minimum connections in pool.\n *\n * @name RethinkDBAdapter#min\n * @type {number}\n * @default 10\n */\n min: 10,\n\n /**\n * Maximum connections in pool.\n *\n * @name RethinkDBAdapter#max\n * @type {number}\n * @default 50\n */\n max: 50,\n\n /**\n * RethinkDB port.\n *\n * @name RethinkDBAdapter#port\n * @type {number}\n * @default 10\n */\n port: 28015,\n\n /**\n * Whether to return a more detailed response object.\n *\n * @name RethinkDBAdapter#raw\n * @type {boolean}\n * @default false\n */\n raw: false\n}\n\nconst INSERT_OPTS_DEFAULTS = {}\nconst UPDATE_OPTS_DEFAULTS = {}\nconst DELETE_OPTS_DEFAULTS = {}\nconst RUN_OPTS_DEFAULTS = {}\n\nconst equal = function (r, row, field, value) {\n return row(field).default(null).eq(value)\n}\n\nconst notEqual = function (r, row, field, value) {\n return row(field).default(null).ne(value)\n}\n\n/**\n * Default predicate functions for the filtering operators.\n *\n * @name RethinkDBAdapter.OPERATORS\n * @property {Function} == Equality operator.\n * @property {Function} != Inequality operator.\n * @property {Function} > \"Greater than\" operator.\n * @property {Function} >= \"Greater than or equal to\" operator.\n * @property {Function} < \"Less than\" operator.\n * @property {Function} <= \"Less than or equal to\" operator.\n * @property {Function} isectEmpty Operator to test that the intersection\n * between two arrays is empty.\n * @property {Function} isectNotEmpty Operator to test that the intersection\n * between two arrays is NOT empty.\n * @property {Function} in Operator to test whether a value is found in the\n * provided array.\n * @property {Function} notIn Operator to test whether a value is NOT found in\n * the provided array.\n * @property {Function} contains Operator to test whether an array contains the\n * provided value.\n * @property {Function} notContains Operator to test whether an array does NOT\n * contain the provided value.\n */\nconst OPERATORS = {\n '==': equal,\n '===': equal,\n '!=': notEqual,\n '!==': notEqual,\n '>': function (r, row, field, value) {\n return row(field).default(null).gt(value)\n },\n '>=': function (r, row, field, value) {\n return row(field).default(null).ge(value)\n },\n '<': function (r, row, field, value) {\n return row(field).default(null).lt(value)\n },\n '<=': function (r, row, field, value) {\n return row(field).default(null).le(value)\n },\n 'isectEmpty': function (r, row, field, value) {\n return row(field).default([]).setIntersection(r.expr(value).default([])).count().eq(0)\n },\n 'isectNotEmpty': function (r, row, field, value) {\n return row(field).default([]).setIntersection(r.expr(value).default([])).count().ne(0)\n },\n 'in': function (r, row, field, value) {\n return r.expr(value).default(r.expr([])).contains(row(field).default(null))\n },\n 'notIn': function (r, row, field, value) {\n return r.expr(value).default(r.expr([])).contains(row(field).default(null)).not()\n },\n 'contains': function (r, row, field, value) {\n return row(field).default([]).contains(value)\n },\n 'notContains': function (r, row, field, value) {\n return row(field).default([]).contains(value).not()\n }\n}\n\n/**\n * RethinkDBAdapter class.\n *\n * @example\n * // Use Container instead of DataStore on the server\n * import {Container} from 'js-data'\n * import RethinkdbDBAdapter from 'js-data-rethinkdb'\n *\n * // Create a store to hold your Mappers\n * const store = new Container()\n *\n * // Create an instance of RethinkdbDBAdapter with default settings\n * const adapter = new RethinkdbDBAdapter()\n *\n * // Mappers in \"store\" will use the RethinkDB adapter by default\n * store.registerAdapter('rethinkdb', adapter, { default: true })\n *\n * // Create a Mapper that maps to a \"user\" table\n * store.defineMapper('user')\n *\n * @class RethinkDBAdapter\n * @param {Object} [opts] Configuration opts.\n * @param {string} [opts.authKey=\"\"] RethinkDB authorization key.\n * @param {number} [opts.bufferSize=10] Buffer size for connection pool.\n * @param {string} [opts.db=\"test\"] Default database.\n * @param {boolean} [opts.debug=false] Whether to log debugging information.\n * @param {string} [opts.host=\"localhost\"] RethinkDB host.\n * @param {number} [opts.max=50] Maximum connections in pool.\n * @param {number} [opts.min=10] Minimum connections in pool.\n * @param {Object} [opts.operators] Override the default predicate functions for\n * specified operators.\n * @param {number} [opts.port=28015] RethinkDB port.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed response object.\n */\nexport default function RethinkDBAdapter (opts) {\n const self = this\n opts || (opts = {})\n fillIn(opts, DEFAULTS)\n fillIn(self, opts)\n\n /**\n * Default options to pass to r#insert.\n *\n * @name RethinkDBAdapter#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 r#update.\n *\n * @name RethinkDBAdapter#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 r#delete.\n *\n * @name RethinkDBAdapter#deleteOpts\n * @type {Object}\n * @default {}\n */\n self.deleteOpts || (self.deleteOpts = {})\n fillIn(self.deleteOpts, DELETE_OPTS_DEFAULTS)\n\n /**\n * Default options to pass to r#run.\n *\n * @name RethinkDBAdapter#runOpts\n * @type {Object}\n * @default {}\n */\n self.runOpts || (self.runOpts = {})\n fillIn(self.runOpts, RUN_OPTS_DEFAULTS)\n\n /**\n * Override the default predicate functions for specified operators.\n *\n * @name RethinkDBAdapter#operators\n * @type {Object}\n * @default {}\n */\n self.operators || (self.operators = {})\n\n /**\n * The rethinkdbdash instance used by this adapter. Use this directly when you\n * need to write custom queries.\n *\n * @name RethinkDBAdapter#r\n * @type {Object}\n */\n self.r = rethinkdbdash(opts)\n self.databases = {}\n self.tables = {}\n self.indices = {}\n}\n\n/**\n * Alternative to ES6 class syntax for extending `RethinkDBAdapter`.\n *\n * @name RethinkDBAdapter.extend\n * @method\n * @param {Object} [instanceProps] Properties that will be added to the\n * prototype of the subclass.\n * @param {Object} [classProps] Properties that will be added as static\n * properties to the subclass itself.\n * @return {Object} Subclass of `RethinkDBAdapter`.\n */\nRethinkDBAdapter.extend = extend\n\naddHiddenPropsToTarget(RethinkDBAdapter.prototype, {\n _handleErrors (cursor) {\n if (cursor && cursor.errors > 0) {\n if (cursor.first_error) {\n throw new Error(cursor.first_error)\n }\n throw new Error('Unknown RethinkDB Error')\n }\n },\n /**\n * @name RethinkDBAdapter#afterCreate\n * @method\n */\n afterCreate: noop2,\n\n /**\n * @name RethinkDBAdapter#afterCreateMany\n * @method\n */\n afterCreateMany: noop2,\n\n /**\n * @name RethinkDBAdapter#afterDestroy\n * @method\n */\n afterDestroy: noop2,\n\n /**\n * @name RethinkDBAdapter#afterDestroyAll\n * @method\n */\n afterDestroyAll: noop2,\n\n /**\n * @name RethinkDBAdapter#afterFind\n * @method\n */\n afterFind: noop2,\n\n /**\n * @name RethinkDBAdapter#afterFindAll\n * @method\n */\n afterFindAll: noop2,\n\n /**\n * @name RethinkDBAdapter#afterUpdate\n * @method\n */\n afterUpdate: noop2,\n\n /**\n * @name RethinkDBAdapter#afterUpdateAll\n * @method\n */\n afterUpdateAll: noop2,\n\n /**\n * @name RethinkDBAdapter#afterUpdateMany\n * @method\n */\n afterUpdateMany: noop2,\n\n /**\n * @name RethinkDBAdapter#beforeCreate\n * @method\n */\n beforeCreate: noop,\n\n /**\n * @name RethinkDBAdapter#beforeCreateMany\n * @method\n */\n beforeCreateMany: noop,\n\n /**\n * @name RethinkDBAdapter#beforeDestroy\n * @method\n */\n beforeDestroy: noop,\n\n /**\n * @name RethinkDBAdapter#beforeDestroyAll\n * @method\n */\n beforeDestroyAll: noop,\n\n /**\n * @name RethinkDBAdapter#beforeFind\n * @method\n */\n beforeFind: noop,\n\n /**\n * @name RethinkDBAdapter#beforeFindAll\n * @method\n */\n beforeFindAll: noop,\n\n /**\n * @name RethinkDBAdapter#beforeUpdate\n * @method\n */\n beforeUpdate: noop,\n\n /**\n * @name RethinkDBAdapter#beforeUpdateAll\n * @method\n */\n beforeUpdateAll: noop,\n\n /**\n * @name RethinkDBAdapter#beforeUpdateMany\n * @method\n */\n beforeUpdateMany: noop,\n\n /**\n * @name RethinkDBAdapter#dbg\n * @method\n */\n dbg (...args) {\n this.log('debug', ...args)\n },\n\n selectDb (opts) {\n return this.r.db(isUndefined(opts.db) ? this.db : opts.db)\n },\n\n selectTable (mapper, opts) {\n return this.selectDb(opts).table(mapper.table || underscore(mapper.name))\n },\n\n /**\n * Apply the specified selection query to the provided RQL sequence.\n *\n * @name RethinkDBAdapter#filterSequence\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object} [query] Selection query.\n * @param {Object} [query.where] Filtering criteria.\n * @param {string|Array} [query.orderBy] Sorting criteria.\n * @param {string|Array} [query.sort] Same as `query.sort`.\n * @param {number} [query.limit] Limit results.\n * @param {number} [query.skip] Offset results.\n * @param {number} [query.offset] Same as `query.skip`.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.operators] Override the default predicate functions\n * for specified operators.\n */\n filterSequence (sequence, query, opts) {\n const self = this\n const r = self.r\n\n query = plainCopy(query || {})\n opts || (opts = {})\n opts.operators || (opts.operators = {})\n query.where || (query.where = {})\n query.orderBy || (query.orderBy = query.sort)\n query.orderBy || (query.orderBy = [])\n query.skip || (query.skip = query.offset)\n\n // Transform non-keyword properties to \"where\" clause configuration\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 rql = sequence\n\n // Filter\n if (Object.keys(query.where).length !== 0) {\n // Filter sequence using filter function\n rql = rql.filter(function (row) {\n let subQuery\n // Apply filter for each field\n forOwn(query.where, function (criteria, field) {\n if (!isObject(criteria)) {\n criteria = { '==': criteria }\n }\n // Apply filter for each operator\n forOwn(criteria, function (value, operator) {\n let isOr = false\n if (operator && operator[0] === '|') {\n operator = operator.substr(1)\n isOr = true\n }\n let predicateFn = self.getOperator(operator, opts)\n if (predicateFn) {\n const predicateResult = predicateFn(r, row, field, value)\n if (isOr) {\n subQuery = subQuery ? subQuery.or(predicateResult) : predicateResult\n } else {\n subQuery = subQuery ? subQuery.and(predicateResult) : predicateResult\n }\n }\n })\n })\n return subQuery || true\n })\n }\n\n // Sort\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 rql = (query.orderBy[i][1] || '').toUpperCase() === 'DESC' ? rql.orderBy(r.desc(query.orderBy[i][0])) : rql.orderBy(query.orderBy[i][0])\n }\n }\n\n // Offset\n if (query.skip) {\n rql = rql.skip(+query.skip)\n }\n\n // Limit\n if (query.limit) {\n rql = rql.limit(+query.limit)\n }\n\n return rql\n },\n\n waitForDb (opts) {\n const self = this\n opts || (opts = {})\n const db = isUndefined(opts.db) ? self.db : opts.db\n if (!self.databases[db]) {\n self.databases[db] = self.r.branch(\n self.r.dbList().contains(db),\n true,\n self.r.dbCreate(db)\n ).run()\n }\n return self.databases[db]\n },\n\n /**\n * Create a new record.\n *\n * @name RethinkDBAdapter#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 r#insert.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @return {Promise}\n */\n create (mapper, props, opts) {\n const self = this\n let op\n props || (props = {})\n opts || (opts = {})\n\n return self.waitForTable(mapper, opts).then(function () {\n // beforeCreate lifecycle hook\n op = opts.op = 'beforeCreate'\n return resolve(self[op](mapper, props, opts))\n }).then(function (_props) {\n // Allow for re-assignment from lifecycle hook\n props = isUndefined(_props) ? props : _props\n const insertOpts = self.getOpt('insertOpts', opts)\n insertOpts.returnChanges = true\n return self.selectTable(mapper, opts).insert(props, insertOpts).run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n self._handleErrors(cursor)\n let record\n if (cursor && cursor.changes && cursor.changes.length && cursor.changes[0].new_val) {\n record = cursor.changes[0].new_val\n }\n let result = {}\n fillIn(result, cursor)\n result.data = record\n result.created = record ? 1 : 0\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterCreate lifecycle hook\n op = opts.op = 'afterCreate'\n return resolve(self[op](mapper, props, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Create multiple records in a single batch.\n *\n * @name RethinkDBAdapter#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.insertOpts] Options to pass to r#insert.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @return {Promise}\n */\n createMany (mapper, props, opts) {\n const self = this\n let op\n props || (props = {})\n opts || (opts = {})\n\n return self.waitForTable(mapper, opts).then(function () {\n // beforeCreateMany lifecycle hook\n op = opts.op = 'beforeCreateMany'\n return resolve(self[op](mapper, props, opts))\n }).then(function (_props) {\n // Allow for re-assignment from lifecycle hook\n props = isUndefined(_props) ? props : _props\n const insertOpts = self.getOpt('insertOpts', opts)\n insertOpts.returnChanges = true\n _props = props.map(function (record) {\n return withoutRelations(mapper, record)\n })\n return self.selectTable(mapper, opts).insert(_props, insertOpts).run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n self._handleErrors(cursor)\n let records = []\n if (cursor && cursor.changes && cursor.changes.length && cursor.changes) {\n records = cursor.changes.map(function (change) {\n return change.new_val\n })\n }\n let result = {}\n fillIn(result, cursor)\n result.data = records\n result.created = records.length\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterCreateMany lifecycle hook\n op = opts.op = 'afterCreateMany'\n return resolve(self[op](mapper, props, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Destroy the record with the given primary key.\n *\n * @name RethinkDBAdapter#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 {Object} [opts.deleteOpts] Options to pass to r#delete.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @return {Promise}\n */\n destroy (mapper, id, opts) {\n const self = this\n let op\n opts || (opts = {})\n\n return self.waitForTable(mapper, opts).then(function () {\n // beforeDestroy lifecycle hook\n op = opts.op = 'beforeDestroy'\n return resolve(self[op](mapper, id, opts))\n }).then(function () {\n op = opts.op = 'destroy'\n self.dbg(op, id, opts)\n return self.selectTable(mapper, opts).get(id).delete(self.getOpt('deleteOpts', opts)).run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n let result = {}\n fillIn(result, cursor)\n result = self.getOpt('raw', opts) ? result : undefined\n\n // afterDestroy lifecycle hook\n op = opts.op = 'afterDestroy'\n return resolve(self[op](mapper, id, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Destroy the records that match the selection query.\n *\n * @name RethinkDBAdapter#destroyAll\n * @method\n * @param {Object} mapper the mapper.\n * @param {Object} [query] Selection query.\n * @param {Object} [query.where] Filtering criteria.\n * @param {string|Array} [query.orderBy] Sorting criteria.\n * @param {string|Array} [query.sort] Same as `query.sort`.\n * @param {number} [query.limit] Limit results.\n * @param {number} [query.skip] Offset results.\n * @param {number} [query.offset] Same as `query.skip`.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.deleteOpts] Options to pass to r#delete.\n * @param {Object} [opts.operators] Override the default predicate functions\n * for specified operators.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @return {Promise}\n */\n destroyAll (mapper, query, opts) {\n const self = this\n let op\n query || (query = {})\n opts || (opts = {})\n\n return self.waitForTable(mapper, opts).then(function () {\n // beforeDestroyAll lifecycle hook\n op = opts.op = 'beforeDestroyAll'\n return resolve(self[op](mapper, query, opts))\n }).then(function () {\n op = opts.op = 'destroyAll'\n self.dbg(op, query, opts)\n return self\n .filterSequence(self.selectTable(mapper, opts), query)\n .delete(self.getOpt('deleteOpts', opts))\n .run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n let result = {}\n fillIn(result, cursor)\n result = self.getOpt('raw', opts) ? result : undefined\n\n // afterDestroyAll lifecycle hook\n op = opts.op = 'afterDestroyAll'\n return resolve(self[op](mapper, query, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Return the foreignKey from the given record for the provided relationship.\n *\n * There may be reasons why you may want to override this method, like when\n * the id of the parent doesn't exactly match up to the key on the child.\n *\n * @name RethinkDBAdapter#makeHasManyForeignKey\n * @method\n * @return {*}\n */\n makeHasManyForeignKey (mapper, def, record) {\n return def.getForeignKey(record)\n },\n\n /**\n * Load a hasMany relationship.\n *\n * @name RethinkDBAdapter#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 RethinkDBAdapter#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 RethinkDBAdapter#makeBelongsToForeignKey\n * @method\n * @return {*}\n */\n makeBelongsToForeignKey (mapper, def, record) {\n return def.getForeignKey(record)\n },\n\n /**\n * Load a belongsTo relationship.\n *\n * @name RethinkDBAdapter#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 RethinkDBAdapter#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 {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\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 relationList = mapper.relationList || []\n let tasks = [self.waitForTable(mapper, opts)]\n\n relationList.forEach(function (def) {\n const relationName = def.relation\n const relationDef = def.getRelation()\n if (!opts.with || opts.with.indexOf(relationName) === -1) {\n return\n }\n if (def.foreignKey && def.type !== 'belongsTo') {\n if (def.type === 'belongsTo') {\n tasks.push(self.waitForIndex(mapper.table || underscore(mapper.name), def.foreignKey, opts))\n } else {\n tasks.push(self.waitForIndex(relationDef.table || underscore(relationDef.name), def.foreignKey, opts))\n }\n }\n })\n return Promise.all(tasks).then(function () {\n // beforeFind lifecycle hook\n op = opts.op = 'beforeFind'\n return resolve(self[op](mapper, id, opts))\n }).then(function () {\n op = opts.op = 'find'\n self.dbg(op, id, opts)\n return self.selectTable(mapper, opts).get(id).run(self.getOpt('runOpts', opts))\n }).then(function (_record) {\n if (!_record) {\n return\n }\n record = _record\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 })\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': get(record, mapper.idAttribute)\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 let result = {\n data: record,\n found: record ? 1 : 0\n }\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterFind lifecycle hook\n op = opts.op = 'afterFind'\n return resolve(self[op](mapper, id, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Retrieve the records that match the selection query.\n *\n * @name RethinkDBAdapter#findAll\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object} [query] Selection query.\n * @param {Object} [query.where] Filtering criteria.\n * @param {string|Array} [query.orderBy] Sorting criteria.\n * @param {string|Array} [query.sort] Same as `query.sort`.\n * @param {number} [query.limit] Limit results.\n * @param {number} [query.skip] Offset results.\n * @param {number} [query.offset] Same as `query.skip`.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.operators] Override the default predicate functions\n * for specified operators.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\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 relationList = mapper.relationList || []\n let tasks = [self.waitForTable(mapper, opts)]\n\n relationList.forEach(function (def) {\n const relationName = def.relation\n const relationDef = def.getRelation()\n if (!opts.with || opts.with.indexOf(relationName) === -1) {\n return\n }\n if (def.foreignKey && def.type !== 'belongsTo') {\n if (def.type === 'belongsTo') {\n tasks.push(self.waitForIndex(mapper.table || underscore(mapper.name), def.foreignKey, opts))\n } else {\n tasks.push(self.waitForIndex(relationDef.table || underscore(relationDef.name), def.foreignKey, opts))\n }\n }\n })\n return Promise.all(tasks).then(function () {\n // beforeFindAll lifecycle hook\n op = opts.op = 'beforeFindAll'\n return resolve(self[op](mapper, query, opts))\n }).then(function () {\n op = opts.op = 'findAll'\n self.dbg(op, query, opts)\n return self.filterSequence(self.selectTable(mapper, opts), query).run(self.getOpt('runOpts', opts))\n }).then(function (_records) {\n records = _records\n const tasks = []\n forEachRelation(mapper, opts, function (def, __opts) {\n const relatedMapper = def.getRelation()\n const idAttribute = mapper.idAttribute\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 })\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 task = self.findAll(relatedMapper, {\n where: {\n [def.foreignKeys]: {\n 'isectNotEmpty': records.map(function (record) {\n return get(record, idAttribute)\n })\n }\n }\n }, __opts).then(function (relatedItems) {\n const foreignKeysField = def.foreignKeys\n records.forEach(function (record) {\n const _relatedItems = []\n const id = get(record, idAttribute)\n relatedItems.forEach(function (relatedItem) {\n const foreignKeys = get(relatedItems, foreignKeysField) || []\n if (foreignKeys.indexOf(id) !== -1) {\n _relatedItems.push(relatedItem)\n }\n })\n def.setLocalField(record, _relatedItems)\n })\n })\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 records || (records = [])\n let result = {\n data: records,\n found: records.length\n }\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterFindAll lifecycle hook\n op = opts.op = 'afterFindAll'\n return resolve(self[op](mapper, query, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Resolve the predicate function for the specified operator based on the\n * given options and this adapter's settings.\n *\n * @name RethinkDBAdapter#getOperator\n * @method\n * @param {string} operator The name of the operator.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.operators] Override the default predicate functions\n * for specified operators.\n * @return {*} The predicate function for the specified operator.\n */\n getOperator (operator, opts) {\n opts || (opts = {})\n opts.operators || (opts.operators = {})\n let ownOps = this.operators || {}\n return isUndefined(opts.operators[operator]) ? ownOps[operator] || OPERATORS[operator] : opts.operators[operator]\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 RethinkDBAdapter#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 * Logging utility method.\n *\n * @name RethinkDBAdapter#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()}: (RethinkDBAdapter)`\n if (console[level]) {\n console[level](prefix, ...args)\n } else {\n console.log(prefix, ...args)\n }\n },\n\n /**\n * Apply the given update to the record with the specified primary key.\n *\n * @name RethinkDBAdapter#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 {Object} [opts.updateOpts] Options to pass to r#update.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @return {Promise}\n */\n update (mapper, id, props, opts) {\n const self = this\n props || (props = {})\n opts || (opts = {})\n let op\n\n return self.waitForTable(mapper, opts).then(function () {\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 const updateOpts = self.getOpt('updateOpts', opts)\n updateOpts.returnChanges = true\n return self.selectTable(mapper, opts).get(id).update(withoutRelations(mapper, props), updateOpts).run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n let record\n self._handleErrors(cursor)\n if (cursor && cursor.changes && cursor.changes.length && cursor.changes[0].new_val) {\n record = cursor.changes[0].new_val\n } else {\n throw new Error('Not Found')\n }\n let result = {}\n fillIn(result, cursor)\n result.data = record\n result.updated = 1\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterUpdate lifecycle hook\n op = opts.op = 'afterUpdate'\n return resolve(self[op](mapper, id, props, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Apply the given update to all records that match the selection query.\n *\n * @name RethinkDBAdapter#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} [query.where] Filtering criteria.\n * @param {string|Array} [query.orderBy] Sorting criteria.\n * @param {string|Array} [query.sort] Same as `query.sort`.\n * @param {number} [query.limit] Limit results.\n * @param {number} [query.skip] Offset results.\n * @param {number} [query.offset] Same as `query.skip`.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.operators] Override the default predicate functions\n * for specified operators.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @param {Object} [opts.updateOpts] Options to pass to r#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\n\n return self.waitForTable(mapper, opts).then(function () {\n // beforeUpdateAll lifecycle hook\n op = opts.op = 'beforeUpdateAll'\n return resolve(self[op](mapper, props, query, opts))\n }).then(function (_props) {\n // Allow for re-assignment from lifecycle hook\n props = isUndefined(_props) ? props : _props\n const updateOpts = self.getOpt('updateOpts', opts)\n updateOpts.returnChanges = true\n return self.filterSequence(self.selectTable(mapper, opts), query).update(withoutRelations(mapper, props), updateOpts).run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n let records = []\n self._handleErrors(cursor)\n if (cursor && cursor.changes && cursor.changes.length) {\n records = cursor.changes.map(function (change) { return change.new_val })\n }\n let result = {}\n fillIn(result, cursor)\n result.data = records\n result.updated = records.length\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterUpdateAll lifecycle hook\n op = opts.op = 'afterUpdateAll'\n return resolve(self[op](mapper, props, query, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Update the given records in a single batch.\n *\n * @name RethinkDBAdapter#updateMany\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object[]} records The records to update.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.insertOpts] Options to pass to r#insert.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @return {Promise}\n */\n updateMany (mapper, records, opts) {\n const self = this\n records || (records = [])\n opts || (opts = {})\n let op\n const idAttribute = mapper.idAttribute\n\n records = records.filter(function (record) {\n return get(record, idAttribute)\n })\n\n return self.waitForTable(mapper, opts).then(function () {\n // beforeUpdateMany lifecycle hook\n op = opts.op = 'beforeUpdateMany'\n return resolve(self[op](mapper, records, opts))\n }).then(function (_records) {\n // Allow for re-assignment from lifecycle hook\n _records = isUndefined(_records) ? records : _records\n const insertOpts = self.getOpt('insertOpts', opts)\n insertOpts.returnChanges = true\n insertOpts.conflict = 'update'\n _records = _records.map(function (record) {\n return withoutRelations(mapper, record)\n })\n return self.selectTable(mapper, opts).insert(_records, insertOpts).run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n let updatedRecords\n self._handleErrors(cursor)\n if (cursor && cursor.changes && cursor.changes.length) {\n updatedRecords = cursor.changes.map(function (change) { return change.new_val })\n }\n let result = {}\n fillIn(result, cursor)\n result.data = updatedRecords || []\n result.updated = result.data.length\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterUpdateMany lifecycle hook\n op = opts.op = 'afterUpdateMany'\n return resolve(self[op](mapper, records, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n waitForTable (mapper, options) {\n const table = isString(mapper) ? mapper : (mapper.table || underscore(mapper.name))\n options = options || {}\n let db = isUndefined(options.db) ? this.db : options.db\n return this.waitForDb(options).then(() => {\n this.tables[db] = this.tables[db] || {}\n if (!this.tables[db][table]) {\n this.tables[db][table] = this.r.branch(this.r.db(db).tableList().contains(table), true, this.r.db(db).tableCreate(table)).run()\n }\n return this.tables[db][table]\n })\n },\n\n waitForIndex (table, index, options) {\n options = options || {}\n let db = isUndefined(options.db) ? this.db : options.db\n return this.waitForDb(options).then(() => this.waitForTable(table, options)).then(() => {\n this.indices[db] = this.indices[db] || {}\n this.indices[db][table] = this.indices[db][table] || {}\n if (!this.tables[db][table][index]) {\n this.tables[db][table][index] = this.r.branch(this.r.db(db).table(table).indexList().contains(index), true, this.r.db(db).table(table).indexCreate(index)).run().then(() => {\n return this.r.db(db).table(table).indexWait(index).run()\n })\n }\n return this.tables[db][table][index]\n })\n }\n})\n\nRethinkDBAdapter.OPERATORS = OPERATORS\n"],"names":["utils"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAME,yBAYEA,aAZF;IACA,SAWEA,aAXF;IACA,SAUEA,aAVF;IACA,kBASEA,aATF;IACA,SAQEA,aARF;IACA,MAOEA,aAPF;IACA,UAMEA,aANF;IACA,WAKEA,aALF;IACA,WAIEA,aAJF;IACA,cAGEA,aAHF;IACA,YAEEA,aAFF;IACA,UACEA,aADF;;;AAGF,IAAM,WAAW,CACf,SADe,EAEf,MAFe,EAGf,OAHe,EAIf,QAJe,EAKf,MALe,EAMf,OANe,CAAX;;AASN,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;MACzB,OAAO,IAAP,CADyB;;qCAAN;;GAAM;;MAEzB,OAAO,KAAK,KAAK,MAAL,GAAc,CAAd,CAAZ,CAFyB;OAG1B,GAAL,cAAS,KAAK,EAAL,SAAY,KAArB,EAH+B;SAIxB,SAAP,CAJ+B;CAAnB;;AAOd,IAAM,mBAAmB,SAAnB,gBAAmB,CAAU,MAAV,EAAkB,KAAlB,EAAyB;MAC1C,iBAAiB,OAAO,cAAP,IAAyB,EAAzB;;;MAGjB,SAAS,EAAT,CAJ0C;SAKzC,KAAP,EAAc,UAAU,KAAV,EAAiB,GAAjB,EAAsB;QAC9B,eAAe,OAAf,CAAuB,GAAvB,MAAgC,CAAC,CAAD,EAAI;aAC/B,GAAP,IAAc,KAA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hB,EAAuB,KAAvB,IAAgC,OAAK,CAAL,CAAO,MAAP,CAAc,OAAK,CAAL,CAAO,EAAP,CAAU,EAAV,EAAc,KAAd,CAAoB,KAApB,EAA2B,SAA3B,GAAuC,QAAvC,CAAgD,KAAhD,CAAd,EAAsE,IAAtE,EAA4E,OAAK,CAAL,CAAO,EAAP,CAAU,EAAV,EAAc,KAAd,CAAoB,KAApB,EAA2B,WAA3B,CAAuC,KAAvC,CAA5E,EAA2H,GAA3H,GAAiI,IAAjI,CAAsI,YAAM;iBACnK,OAAK,CAAL,CAAO,EAAP,CAAU,EAAV,EAAc,KAAd,CAAoB,KAApB,EAA2B,SAA3B,CAAqC,KAArC,EAA4C,GAA5C,EAAP,CAD0K;SAAN,CAAtK,CADkC;OAApC;aAKO,OAAK,MAAL,CAAY,EAAZ,EAAgB,KAAhB,EAAuB,KAAvB,CAAP,CARsF;KAAN,CAAlF,CAHmC;GA1jCY;CAAnD;;AA0kCA,iBAAiB,SAAjB,GAA6B,SAA7B;;"} \ No newline at end of file +{"version":3,"file":"js-data-rethinkdb.js","sources":["../src/index.js"],"sourcesContent":["import {utils} from 'js-data'\nimport Adapter from 'js-data-adapter'\nimport {\n reserved,\n Response\n} from 'js-data-adapter'\nimport rethinkdbdash from 'rethinkdbdash'\nimport underscore from 'mout/string/underscore'\nimport unique from 'mout/array/unique'\n\nconst {\n addHiddenPropsToTarget,\n classCallCheck,\n extend,\n fillIn,\n forEachRelation,\n forOwn,\n get,\n isArray,\n isObject,\n isString,\n isUndefined,\n omit,\n plainCopy,\n resolve\n} = utils\n\nconst withoutRelations = function (mapper, props) {\n return omit(props, mapper.relationFields || [])\n}\n\nconst DEFAULTS = {\n /**\n * RethinkDB authorization key.\n *\n * @name RethinkDBAdapter#authKey\n * @type {string}\n */\n authKey: '',\n\n /**\n * Buffer size for connection pool.\n *\n * @name RethinkDBAdapter#bufferSize\n * @type {number}\n * @default 10\n */\n bufferSize: 10,\n\n /**\n * Default database.\n *\n * @name RethinkDBAdapter#db\n * @type {string}\n * @default \"test\"\n */\n db: 'test',\n\n /**\n * Whether to log debugging information.\n *\n * @name RethinkDBAdapter#debug\n * @type {boolean}\n * @default false\n */\n debug: false,\n\n /**\n * RethinkDB host.\n *\n * @name RethinkDBAdapter#host\n * @type {string}\n * @default \"localhost\"\n */\n host: 'localhost',\n\n /**\n * Minimum connections in pool.\n *\n * @name RethinkDBAdapter#min\n * @type {number}\n * @default 10\n */\n min: 10,\n\n /**\n * Maximum connections in pool.\n *\n * @name RethinkDBAdapter#max\n * @type {number}\n * @default 50\n */\n max: 50,\n\n /**\n * RethinkDB port.\n *\n * @name RethinkDBAdapter#port\n * @type {number}\n * @default 10\n */\n port: 28015,\n\n /**\n * Whether to return a more detailed response object.\n *\n * @name RethinkDBAdapter#raw\n * @type {boolean}\n * @default false\n */\n raw: false\n}\n\nconst INSERT_OPTS_DEFAULTS = {}\nconst UPDATE_OPTS_DEFAULTS = {}\nconst DELETE_OPTS_DEFAULTS = {}\nconst RUN_OPTS_DEFAULTS = {}\n\nconst equal = function (r, row, field, value) {\n return row(field).default(null).eq(value)\n}\n\nconst notEqual = function (r, row, field, value) {\n return row(field).default(null).ne(value)\n}\n\n/**\n * Default predicate functions for the filtering operators.\n *\n * @name RethinkDBAdapter.OPERATORS\n * @property {Function} == Equality operator.\n * @property {Function} != Inequality operator.\n * @property {Function} > \"Greater than\" operator.\n * @property {Function} >= \"Greater than or equal to\" operator.\n * @property {Function} < \"Less than\" operator.\n * @property {Function} <= \"Less than or equal to\" operator.\n * @property {Function} isectEmpty Operator to test that the intersection\n * between two arrays is empty.\n * @property {Function} isectNotEmpty Operator to test that the intersection\n * between two arrays is NOT empty.\n * @property {Function} in Operator to test whether a value is found in the\n * provided array.\n * @property {Function} notIn Operator to test whether a value is NOT found in\n * the provided array.\n * @property {Function} contains Operator to test whether an array contains the\n * provided value.\n * @property {Function} notContains Operator to test whether an array does NOT\n * contain the provided value.\n */\nconst OPERATORS = {\n '==': equal,\n '===': equal,\n '!=': notEqual,\n '!==': notEqual,\n '>': function (r, row, field, value) {\n return row(field).default(null).gt(value)\n },\n '>=': function (r, row, field, value) {\n return row(field).default(null).ge(value)\n },\n '<': function (r, row, field, value) {\n return row(field).default(null).lt(value)\n },\n '<=': function (r, row, field, value) {\n return row(field).default(null).le(value)\n },\n 'isectEmpty': function (r, row, field, value) {\n return row(field).default([]).setIntersection(r.expr(value).default([])).count().eq(0)\n },\n 'isectNotEmpty': function (r, row, field, value) {\n return row(field).default([]).setIntersection(r.expr(value).default([])).count().ne(0)\n },\n 'in': function (r, row, field, value) {\n return r.expr(value).default(r.expr([])).contains(row(field).default(null))\n },\n 'notIn': function (r, row, field, value) {\n return r.expr(value).default(r.expr([])).contains(row(field).default(null)).not()\n },\n 'contains': function (r, row, field, value) {\n return row(field).default([]).contains(value)\n },\n 'notContains': function (r, row, field, value) {\n return row(field).default([]).contains(value).not()\n }\n}\n\n/**\n * RethinkDBAdapter class.\n *\n * @example\n * // Use Container instead of DataStore on the server\n * import {Container} from 'js-data'\n * import RethinkdbDBAdapter from 'js-data-rethinkdb'\n *\n * // Create a store to hold your Mappers\n * const store = new Container()\n *\n * // Create an instance of RethinkdbDBAdapter with default settings\n * const adapter = new RethinkdbDBAdapter()\n *\n * // Mappers in \"store\" will use the RethinkDB adapter by default\n * store.registerAdapter('rethinkdb', adapter, { default: true })\n *\n * // Create a Mapper that maps to a \"user\" table\n * store.defineMapper('user')\n *\n * @class RethinkDBAdapter\n * @extends Adapter\n * @param {Object} [opts] Configuration opts.\n * @param {string} [opts.authKey=\"\"] RethinkDB authorization key.\n * @param {number} [opts.bufferSize=10] Buffer size for connection pool.\n * @param {string} [opts.db=\"test\"] Default database.\n * @param {boolean} [opts.debug=false] Whether to log debugging information.\n * @param {string} [opts.host=\"localhost\"] RethinkDB host.\n * @param {number} [opts.max=50] Maximum connections in pool.\n * @param {number} [opts.min=10] Minimum connections in pool.\n * @param {Object} [opts.operators] Override the default predicate functions for\n * specified operators.\n * @param {number} [opts.port=28015] RethinkDB port.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed response object.\n */\nexport default function RethinkDBAdapter (opts) {\n const self = this\n classCallCheck(self, RethinkDBAdapter)\n opts || (opts = {})\n fillIn(opts, DEFAULTS)\n Adapter.call(this, opts)\n\n /**\n * Default options to pass to r#insert.\n *\n * @name RethinkDBAdapter#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 r#update.\n *\n * @name RethinkDBAdapter#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 r#delete.\n *\n * @name RethinkDBAdapter#deleteOpts\n * @type {Object}\n * @default {}\n */\n self.deleteOpts || (self.deleteOpts = {})\n fillIn(self.deleteOpts, DELETE_OPTS_DEFAULTS)\n\n /**\n * Default options to pass to r#run.\n *\n * @name RethinkDBAdapter#runOpts\n * @type {Object}\n * @default {}\n */\n self.runOpts || (self.runOpts = {})\n fillIn(self.runOpts, RUN_OPTS_DEFAULTS)\n\n /**\n * Override the default predicate functions for specified operators.\n *\n * @name RethinkDBAdapter#operators\n * @type {Object}\n * @default {}\n */\n self.operators || (self.operators = {})\n\n /**\n * The rethinkdbdash instance used by this adapter. Use this directly when you\n * need to write custom queries.\n *\n * @name RethinkDBAdapter#r\n * @type {Object}\n */\n self.r = rethinkdbdash(opts)\n self.databases = {}\n self.tables = {}\n self.indices = {}\n}\n\n// Setup prototype inheritance from Adapter\nRethinkDBAdapter.prototype = Object.create(Adapter.prototype, {\n constructor: {\n value: RethinkDBAdapter,\n enumerable: false,\n writable: true,\n configurable: true\n }\n})\n\nObject.defineProperty(RethinkDBAdapter, '__super__', {\n configurable: true,\n value: Adapter\n})\n\n/**\n * Alternative to ES6 class syntax for extending `RethinkDBAdapter`.\n *\n * @name RethinkDBAdapter.extend\n * @method\n * @param {Object} [instanceProps] Properties that will be added to the\n * prototype of the RethinkDBAdapter.\n * @param {Object} [classProps] Properties that will be added as static\n * properties to the RethinkDBAdapter itself.\n * @return {Object} RethinkDBAdapter of `RethinkDBAdapter`.\n */\nRethinkDBAdapter.extend = extend\n\naddHiddenPropsToTarget(RethinkDBAdapter.prototype, {\n _handleErrors (cursor) {\n if (cursor && cursor.errors > 0) {\n if (cursor.first_error) {\n throw new Error(cursor.first_error)\n }\n throw new Error('Unknown RethinkDB Error')\n }\n },\n\n selectDb (opts) {\n return this.r.db(isUndefined(opts.db) ? this.db : opts.db)\n },\n\n selectTable (mapper, opts) {\n return this.selectDb(opts).table(mapper.table || underscore(mapper.name))\n },\n\n /**\n * Apply the specified selection query to the provided RQL sequence.\n *\n * @name RethinkDBAdapter#filterSequence\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object} [query] Selection query.\n * @param {Object} [query.where] Filtering criteria.\n * @param {string|Array} [query.orderBy] Sorting criteria.\n * @param {string|Array} [query.sort] Same as `query.sort`.\n * @param {number} [query.limit] Limit results.\n * @param {number} [query.skip] Offset results.\n * @param {number} [query.offset] Same as `query.skip`.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.operators] Override the default predicate functions\n * for specified operators.\n */\n filterSequence (sequence, query, opts) {\n const self = this\n const r = self.r\n\n query = plainCopy(query || {})\n opts || (opts = {})\n opts.operators || (opts.operators = {})\n query.where || (query.where = {})\n query.orderBy || (query.orderBy = query.sort)\n query.orderBy || (query.orderBy = [])\n query.skip || (query.skip = query.offset)\n\n // Transform non-keyword properties to \"where\" clause configuration\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 rql = sequence\n\n // Filter\n if (Object.keys(query.where).length !== 0) {\n // Filter sequence using filter function\n rql = rql.filter(function (row) {\n let subQuery\n // Apply filter for each field\n forOwn(query.where, function (criteria, field) {\n if (!isObject(criteria)) {\n criteria = { '==': criteria }\n }\n // Apply filter for each operator\n forOwn(criteria, function (value, operator) {\n let isOr = false\n if (operator && operator[0] === '|') {\n operator = operator.substr(1)\n isOr = true\n }\n let predicateFn = self.getOperator(operator, opts)\n if (predicateFn) {\n const predicateResult = predicateFn(r, row, field, value)\n if (isOr) {\n subQuery = subQuery ? subQuery.or(predicateResult) : predicateResult\n } else {\n subQuery = subQuery ? subQuery.and(predicateResult) : predicateResult\n }\n }\n })\n })\n return subQuery || true\n })\n }\n\n // Sort\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 rql = (query.orderBy[i][1] || '').toUpperCase() === 'DESC' ? rql.orderBy(r.desc(query.orderBy[i][0])) : rql.orderBy(query.orderBy[i][0])\n }\n }\n\n // Offset\n if (query.skip) {\n rql = rql.skip(+query.skip)\n }\n\n // Limit\n if (query.limit) {\n rql = rql.limit(+query.limit)\n }\n\n return rql\n },\n\n waitForDb (opts) {\n const self = this\n opts || (opts = {})\n const db = isUndefined(opts.db) ? self.db : opts.db\n if (!self.databases[db]) {\n self.databases[db] = self.r.branch(\n self.r.dbList().contains(db),\n true,\n self.r.dbCreate(db)\n ).run()\n }\n return self.databases[db]\n },\n\n /**\n * Create a new record.\n *\n * @name RethinkDBAdapter#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 r#insert.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @return {Promise}\n */\n create (mapper, props, opts) {\n const self = this\n let op\n props || (props = {})\n opts || (opts = {})\n\n return self.waitForTable(mapper, opts).then(function () {\n // beforeCreate lifecycle hook\n op = opts.op = 'beforeCreate'\n return resolve(self[op](mapper, props, opts))\n }).then(function (_props) {\n // Allow for re-assignment from lifecycle hook\n props = isUndefined(_props) ? props : _props\n const insertOpts = self.getOpt('insertOpts', opts)\n insertOpts.returnChanges = true\n return self.selectTable(mapper, opts).insert(props, insertOpts).run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n self._handleErrors(cursor)\n let record\n if (cursor && cursor.changes && cursor.changes.length && cursor.changes[0].new_val) {\n record = cursor.changes[0].new_val\n }\n let response = new Response(record, cursor, 'create')\n response.created = record ? 1 : 0\n response = self.respond(response, opts)\n\n // afterCreate lifecycle hook\n op = opts.op = 'afterCreate'\n return resolve(self[op](mapper, props, opts, response)).then(function (_response) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_response) ? response : _response\n })\n })\n },\n\n /**\n * Create multiple records in a single batch.\n *\n * @name RethinkDBAdapter#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.insertOpts] Options to pass to r#insert.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @return {Promise}\n */\n createMany (mapper, props, opts) {\n const self = this\n let op\n props || (props = {})\n opts || (opts = {})\n\n return self.waitForTable(mapper, opts).then(function () {\n // beforeCreateMany lifecycle hook\n op = opts.op = 'beforeCreateMany'\n return resolve(self[op](mapper, props, opts))\n }).then(function (_props) {\n // Allow for re-assignment from lifecycle hook\n props = isUndefined(_props) ? props : _props\n const insertOpts = self.getOpt('insertOpts', opts)\n insertOpts.returnChanges = true\n _props = props.map(function (record) {\n return withoutRelations(mapper, record)\n })\n return self.selectTable(mapper, opts).insert(_props, insertOpts).run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n self._handleErrors(cursor)\n let records = []\n if (cursor && cursor.changes && cursor.changes.length && cursor.changes) {\n records = cursor.changes.map(function (change) {\n return change.new_val\n })\n }\n let result = new Response(records, cursor, 'createMany')\n result.created = records.length\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterCreateMany lifecycle hook\n op = opts.op = 'afterCreateMany'\n return resolve(self[op](mapper, props, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Destroy the record with the given primary key.\n *\n * @name RethinkDBAdapter#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 {Object} [opts.deleteOpts] Options to pass to r#delete.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @return {Promise}\n */\n destroy (mapper, id, opts) {\n const self = this\n let op\n opts || (opts = {})\n\n return self.waitForTable(mapper, opts).then(function () {\n // beforeDestroy lifecycle hook\n op = opts.op = 'beforeDestroy'\n return resolve(self[op](mapper, id, opts))\n }).then(function () {\n op = opts.op = 'destroy'\n self.dbg(op, id, opts)\n return self.selectTable(mapper, opts).get(id).delete(self.getOpt('deleteOpts', opts)).run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n let result = new Response(undefined, cursor, 'destroy')\n result = self.getOpt('raw', opts) ? result : undefined\n\n // afterDestroy lifecycle hook\n op = opts.op = 'afterDestroy'\n return resolve(self[op](mapper, id, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Destroy the records that match the selection query.\n *\n * @name RethinkDBAdapter#destroyAll\n * @method\n * @param {Object} mapper the mapper.\n * @param {Object} [query] Selection query.\n * @param {Object} [query.where] Filtering criteria.\n * @param {string|Array} [query.orderBy] Sorting criteria.\n * @param {string|Array} [query.sort] Same as `query.sort`.\n * @param {number} [query.limit] Limit results.\n * @param {number} [query.skip] Offset results.\n * @param {number} [query.offset] Same as `query.skip`.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.deleteOpts] Options to pass to r#delete.\n * @param {Object} [opts.operators] Override the default predicate functions\n * for specified operators.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @return {Promise}\n */\n destroyAll (mapper, query, opts) {\n const self = this\n let op\n query || (query = {})\n opts || (opts = {})\n\n return self.waitForTable(mapper, opts).then(function () {\n // beforeDestroyAll lifecycle hook\n op = opts.op = 'beforeDestroyAll'\n return resolve(self[op](mapper, query, opts))\n }).then(function () {\n op = opts.op = 'destroyAll'\n self.dbg(op, query, opts)\n return self\n .filterSequence(self.selectTable(mapper, opts), query)\n .delete(self.getOpt('deleteOpts', opts))\n .run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n let result = new Response(undefined, cursor, 'destroyAll')\n result = self.getOpt('raw', opts) ? result : undefined\n\n // afterDestroyAll lifecycle hook\n op = opts.op = 'afterDestroyAll'\n return resolve(self[op](mapper, query, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Retrieve the record with the given primary key.\n *\n * @name RethinkDBAdapter#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 {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\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 relationList = mapper.relationList || []\n let tasks = [self.waitForTable(mapper, opts)]\n\n relationList.forEach(function (def) {\n const relationName = def.relation\n const relationDef = def.getRelation()\n if (!opts.with || opts.with.indexOf(relationName) === -1) {\n return\n }\n if (def.foreignKey && def.type !== 'belongsTo') {\n if (def.type === 'belongsTo') {\n tasks.push(self.waitForIndex(mapper.table || underscore(mapper.name), def.foreignKey, opts))\n } else {\n tasks.push(self.waitForIndex(relationDef.table || underscore(relationDef.name), def.foreignKey, opts))\n }\n }\n })\n return Promise.all(tasks).then(function () {\n // beforeFind lifecycle hook\n op = opts.op = 'beforeFind'\n return resolve(self[op](mapper, id, opts))\n }).then(function () {\n op = opts.op = 'find'\n self.dbg(op, id, opts)\n return self.selectTable(mapper, opts).get(id).run(self.getOpt('runOpts', opts))\n }).then(function (_record) {\n if (!_record) {\n return\n }\n record = _record\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 })\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': get(record, mapper.idAttribute)\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 let result = new Response(record, {}, 'find')\n result.found = record ? 1 : 0\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterFind lifecycle hook\n op = opts.op = 'afterFind'\n return resolve(self[op](mapper, id, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Retrieve the records that match the selection query.\n *\n * @name RethinkDBAdapter#findAll\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object} [query] Selection query.\n * @param {Object} [query.where] Filtering criteria.\n * @param {string|Array} [query.orderBy] Sorting criteria.\n * @param {string|Array} [query.sort] Same as `query.sort`.\n * @param {number} [query.limit] Limit results.\n * @param {number} [query.skip] Offset results.\n * @param {number} [query.offset] Same as `query.skip`.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.operators] Override the default predicate functions\n * for specified operators.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\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 relationList = mapper.relationList || []\n let tasks = [self.waitForTable(mapper, opts)]\n\n relationList.forEach(function (def) {\n const relationName = def.relation\n const relationDef = def.getRelation()\n if (!opts.with || opts.with.indexOf(relationName) === -1) {\n return\n }\n if (def.foreignKey && def.type !== 'belongsTo') {\n if (def.type === 'belongsTo') {\n tasks.push(self.waitForIndex(mapper.table || underscore(mapper.name), def.foreignKey, opts))\n } else {\n tasks.push(self.waitForIndex(relationDef.table || underscore(relationDef.name), def.foreignKey, opts))\n }\n }\n })\n return Promise.all(tasks).then(function () {\n // beforeFindAll lifecycle hook\n op = opts.op = 'beforeFindAll'\n return resolve(self[op](mapper, query, opts))\n }).then(function () {\n op = opts.op = 'findAll'\n self.dbg(op, query, opts)\n return self.filterSequence(self.selectTable(mapper, opts), query).run(self.getOpt('runOpts', opts))\n }).then(function (_records) {\n records = _records\n const tasks = []\n forEachRelation(mapper, opts, function (def, __opts) {\n const relatedMapper = def.getRelation()\n const idAttribute = mapper.idAttribute\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 })\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 task = self.findAll(relatedMapper, {\n where: {\n [def.foreignKeys]: {\n 'isectNotEmpty': records.map(function (record) {\n return get(record, idAttribute)\n })\n }\n }\n }, __opts).then(function (relatedItems) {\n const foreignKeysField = def.foreignKeys\n records.forEach(function (record) {\n const _relatedItems = []\n const id = get(record, idAttribute)\n relatedItems.forEach(function (relatedItem) {\n const foreignKeys = get(relatedItems, foreignKeysField) || []\n if (foreignKeys.indexOf(id) !== -1) {\n _relatedItems.push(relatedItem)\n }\n })\n def.setLocalField(record, _relatedItems)\n })\n })\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 records || (records = [])\n let result = new Response(records, {}, 'findAll')\n result.found = records.length\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterFindAll lifecycle hook\n op = opts.op = 'afterFindAll'\n return resolve(self[op](mapper, query, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Resolve the predicate function for the specified operator based on the\n * given options and this adapter's settings.\n *\n * @name RethinkDBAdapter#getOperator\n * @method\n * @param {string} operator The name of the operator.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.operators] Override the default predicate functions\n * for specified operators.\n * @return {*} The predicate function for the specified operator.\n */\n getOperator (operator, opts) {\n opts || (opts = {})\n opts.operators || (opts.operators = {})\n let ownOps = this.operators || {}\n return isUndefined(opts.operators[operator]) ? ownOps[operator] || OPERATORS[operator] : opts.operators[operator]\n },\n\n /**\n * Apply the given update to the record with the specified primary key.\n *\n * @name RethinkDBAdapter#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 {Object} [opts.updateOpts] Options to pass to r#update.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @return {Promise}\n */\n update (mapper, id, props, opts) {\n const self = this\n props || (props = {})\n opts || (opts = {})\n let op\n\n return self.waitForTable(mapper, opts).then(function () {\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 const updateOpts = self.getOpt('updateOpts', opts)\n updateOpts.returnChanges = true\n return self.selectTable(mapper, opts).get(id).update(withoutRelations(mapper, props), updateOpts).run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n let record\n self._handleErrors(cursor)\n if (cursor && cursor.changes && cursor.changes.length && cursor.changes[0].new_val) {\n record = cursor.changes[0].new_val\n } else {\n throw new Error('Not Found')\n }\n let result = new Response(record, cursor, 'update')\n result.updated = 1\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterUpdate lifecycle hook\n op = opts.op = 'afterUpdate'\n return resolve(self[op](mapper, id, props, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Apply the given update to all records that match the selection query.\n *\n * @name RethinkDBAdapter#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} [query.where] Filtering criteria.\n * @param {string|Array} [query.orderBy] Sorting criteria.\n * @param {string|Array} [query.sort] Same as `query.sort`.\n * @param {number} [query.limit] Limit results.\n * @param {number} [query.skip] Offset results.\n * @param {number} [query.offset] Same as `query.skip`.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.operators] Override the default predicate functions\n * for specified operators.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @param {Object} [opts.updateOpts] Options to pass to r#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\n\n return self.waitForTable(mapper, opts).then(function () {\n // beforeUpdateAll lifecycle hook\n op = opts.op = 'beforeUpdateAll'\n return resolve(self[op](mapper, props, query, opts))\n }).then(function (_props) {\n // Allow for re-assignment from lifecycle hook\n props = isUndefined(_props) ? props : _props\n const updateOpts = self.getOpt('updateOpts', opts)\n updateOpts.returnChanges = true\n return self.filterSequence(self.selectTable(mapper, opts), query).update(withoutRelations(mapper, props), updateOpts).run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n let records = []\n self._handleErrors(cursor)\n if (cursor && cursor.changes && cursor.changes.length) {\n records = cursor.changes.map(function (change) { return change.new_val })\n }\n let result = new Response(records, cursor, 'update')\n result.updated = records.length\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterUpdateAll lifecycle hook\n op = opts.op = 'afterUpdateAll'\n return resolve(self[op](mapper, props, query, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n /**\n * Update the given records in a single batch.\n *\n * @name RethinkDBAdapter#updateMany\n * @method\n * @param {Object} mapper The mapper.\n * @param {Object[]} records The records to update.\n * @param {Object} [opts] Configuration options.\n * @param {Object} [opts.insertOpts] Options to pass to r#insert.\n * @param {boolean} [opts.raw=false] Whether to return a more detailed\n * response object.\n * @param {Object} [opts.runOpts] Options to pass to r#run.\n * @return {Promise}\n */\n updateMany (mapper, records, opts) {\n const self = this\n records || (records = [])\n opts || (opts = {})\n let op\n const idAttribute = mapper.idAttribute\n\n records = records.filter(function (record) {\n return get(record, idAttribute)\n })\n\n return self.waitForTable(mapper, opts).then(function () {\n // beforeUpdateMany lifecycle hook\n op = opts.op = 'beforeUpdateMany'\n return resolve(self[op](mapper, records, opts))\n }).then(function (_records) {\n // Allow for re-assignment from lifecycle hook\n _records = isUndefined(_records) ? records : _records\n const insertOpts = self.getOpt('insertOpts', opts)\n insertOpts.returnChanges = true\n insertOpts.conflict = 'update'\n _records = _records.map(function (record) {\n return withoutRelations(mapper, record)\n })\n return self.selectTable(mapper, opts).insert(_records, insertOpts).run(self.getOpt('runOpts', opts))\n }).then(function (cursor) {\n let updatedRecords\n self._handleErrors(cursor)\n if (cursor && cursor.changes && cursor.changes.length) {\n updatedRecords = cursor.changes.map(function (change) { return change.new_val })\n }\n let result = new Response(updatedRecords || [], cursor, 'update')\n result.updated = result.data.length\n result = self.getOpt('raw', opts) ? result : result.data\n\n // afterUpdateMany lifecycle hook\n op = opts.op = 'afterUpdateMany'\n return resolve(self[op](mapper, records, opts, result)).then(function (_result) {\n // Allow for re-assignment from lifecycle hook\n return isUndefined(_result) ? result : _result\n })\n })\n },\n\n waitForTable (mapper, options) {\n const table = isString(mapper) ? mapper : (mapper.table || underscore(mapper.name))\n options = options || {}\n let db = isUndefined(options.db) ? this.db : options.db\n return this.waitForDb(options).then(() => {\n this.tables[db] = this.tables[db] || {}\n if (!this.tables[db][table]) {\n this.tables[db][table] = this.r.branch(this.r.db(db).tableList().contains(table), true, this.r.db(db).tableCreate(table)).run()\n }\n return this.tables[db][table]\n })\n },\n\n waitForIndex (table, index, options) {\n options = options || {}\n let db = isUndefined(options.db) ? this.db : options.db\n return this.waitForDb(options).then(() => this.waitForTable(table, options)).then(() => {\n this.indices[db] = this.indices[db] || {}\n this.indices[db][table] = this.indices[db][table] || {}\n if (!this.tables[db][table][index]) {\n this.tables[db][table][index] = this.r.branch(this.r.db(db).table(table).indexList().contains(index), true, this.r.db(db).table(table).indexCreate(index)).run().then(() => {\n return this.r.db(db).table(table).indexWait(index).run()\n })\n }\n return this.tables[db][table][index]\n })\n }\n})\n\nRethinkDBAdapter.OPERATORS = OPERATORS\n"],"names":["utils","Adapter","reserved","Response"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAWE,yBAcEA,aAdF;IACA,iBAaEA,aAbF;IACA,SAYEA,aAZF;IACA,SAWEA,aAXF;IACA,kBAUEA,aAVF;IACA,SASEA,aATF;IACA,MAQEA,aARF;IACA,UAOEA,aAPF;IACA,WAMEA,aANF;IACA,WAKEA,aALF;IACA,cAIEA,aAJF;IACA,OAGEA,aAHF;IACA,YAEEA,aAFF;IACA,UACEA,aADF;;;AAGF,IAAM,mBAAmB,SAAnB,gBAAmB,CAAU,MAAV,EAAkB,KAAlB,EAAyB;SACzC,KAAK,KAAL,EAAY,OAAO,cAAP,IAAyB,EAAzB,CAAnB,CADgD;CAAzB;;AAIzB,IAAM,WAAW;;;;;;;WAON,EAAT;;;;;;;;;cASY,EAAZ;;;;;;;;;MASI,MAAJ;;;;;;;;;SASO,KAAP;;;;;;;;;QASM,WAAN;;;;;;;;;OASK,EAAL;;;;;;;;;OASK,EAAL;;;;;;;;;QASM,KAAN;;;;;;;;;OASK,KAAL;CA/EI;;AAkFN,IAAM,uBAAuB,EAAvB;AACN,IAAM,uBAAuB,EAAvB;AACN,IAAM,uBAAuB,EAAvB;AACN,IAAM,oBAAoB,EAApB;;AAEN,IA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,EAAP,CAAU,EAAV,EAAc,KAAd,CAAoB,KAApB,EAA2B,WAA3B,CAAuC,KAAvC,CAA5E,EAA2H,GAA3H,GAAiI,IAAjI,CAAsI,YAAM;iBACnK,OAAK,CAAL,CAAO,EAAP,CAAU,EAAV,EAAc,KAAd,CAAoB,KAApB,EAA2B,SAA3B,CAAqC,KAArC,EAA4C,GAA5C,EAAP,CAD0K;SAAN,CAAtK,CADkC;OAApC;aAKO,OAAK,MAAL,CAAY,EAAZ,EAAgB,KAAhB,EAAuB,KAAvB,CAAP,CARsF;KAAN,CAAlF,CAHmC;GA9wBY;CAAnD;;AA8xBA,iBAAiB,SAAjB,GAA6B,SAA7B;;"} \ No newline at end of file diff --git a/package.json b/package.json index e54a648..7081612 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "js-data-rethinkdb", "description": "RethinkDB adapter for js-data.", - "version": "3.0.0-alpha.7", + "version": "3.0.0-alpha.8", "homepage": "https://github.com/js-data/js-data-rethinkdb", "repository": { "type": "git", @@ -33,26 +33,28 @@ ] }, "scripts": { - "doc": "jsdoc -c conf.json src && node scripts/cleanup.js", + "lint": "repo-tools lint src/index.js mocha.start.js test/**/*.js scripts/**.js", "bundle": "rollup -c rollup.config.js -f cjs -o dist/js-data-rethinkdb.js -m dist/js-data-rethinkdb.js.map src/index.js", - "lint": "standard src/index.js mocha.start.js test/**/*.js scripts/**.js", + "doc": "jsdoc -c conf.json src node_modules/js-data-adapter/src && node scripts/cleanup.js", + "watch": "watch \"npm run bundle\" src/", "build": "npm run lint && npm run bundle", "mocha": "mocha -t 30000 -R dot -r source-map-support/register mocha.start.js", "cover": "istanbul cover --hook-run-in-context node_modules/mocha/bin/_mocha -- -t 30000 -R dot -r source-map-support/register mocha.start.js", "test": "npm run build && npm run cover", - "release": "npm test && npm run doc && node scripts/authors.js", + "repo-tools": "repo-tools updates && repo-tools changelog && repo-tools authors", + "release": "npm test && npm run doc && npm run repo-tools", "ci": "npm run test && cat coverage/lcov.info | coveralls || true && cat ./coverage/lcov.info | codacy-coverage || true" }, "dependencies": { - "mout": "0.11.1" + "js-data-adapter": "0.1.0", + "mout": "0.12.0" }, "peerDependencies": { - "js-data": "^3.0.0-alpha.15", + "js-data": "^3.0.0-alpha.16", "rethinkdbdash": ">=1.15.0" }, "devDependencies": { - "babel-core": "6.6.4", - "babel-eslint": "5.0.0", + "babel-core": "6.6.5", "babel-polyfill": "6.6.1", "babel-preset-es2015-rollup": "1.1.1", "chai": "3.5.0", @@ -61,12 +63,13 @@ "ink-docstrap": "1.1.4", "istanbul": "0.4.2", "js-data-adapter-tests": "^2.0.0-alpha.13", + "js-data-repo-tools": "0.2.0", "jsdoc": "3.4.0", "mocha": "2.4.5", "rollup": "0.25.4", "rollup-plugin-babel": "2.4.0", "sinon": "1.17.3", "source-map-support": "0.4.0", - "standard": "6.0.7" + "watch": "0.17.1" } } diff --git a/scripts/AUTHORS b/scripts/AUTHORS deleted file mode 100644 index 475aaa7..0000000 --- a/scripts/AUTHORS +++ /dev/null @@ -1,7 +0,0 @@ -# This is the official list of js-data-rethinkdb project authors. -# -# This file is controlled by scripts/authors.js -# -# Names are formatted as: -# # commits Name or Organization -# The email address is not required for organizations. diff --git a/src/index.js b/src/index.js index 6ee7845..6e80313 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,16 @@ import {utils} from 'js-data' +import Adapter from 'js-data-adapter' +import { + reserved, + Response +} from 'js-data-adapter' import rethinkdbdash from 'rethinkdbdash' import underscore from 'mout/string/underscore' import unique from 'mout/array/unique' const { addHiddenPropsToTarget, + classCallCheck, extend, fillIn, forEachRelation, @@ -14,44 +20,13 @@ const { isObject, isString, isUndefined, + omit, plainCopy, resolve } = utils -const reserved = [ - 'orderBy', - 'sort', - 'limit', - 'offset', - 'skip', - 'where' -] - -const noop = function (...args) { - const self = this - const opts = args[args.length - 1] - self.dbg(opts.op, ...args) - return resolve() -} - -const noop2 = function (...args) { - const self = this - const opts = args[args.length - 2] - self.dbg(opts.op, ...args) - return resolve() -} - const withoutRelations = function (mapper, props) { - const relationFields = mapper.relationFields || [] - - // Remove relations - const _props = {} - forOwn(props, function (value, key) { - if (relationFields.indexOf(key) === -1) { - _props[key] = value - } - }) - return _props + return omit(props, mapper.relationFields || []) } const DEFAULTS = { @@ -230,6 +205,7 @@ const OPERATORS = { * store.defineMapper('user') * * @class RethinkDBAdapter + * @extends Adapter * @param {Object} [opts] Configuration opts. * @param {string} [opts.authKey=""] RethinkDB authorization key. * @param {number} [opts.bufferSize=10] Buffer size for connection pool. @@ -245,9 +221,10 @@ const OPERATORS = { */ export default function RethinkDBAdapter (opts) { const self = this + classCallCheck(self, RethinkDBAdapter) opts || (opts = {}) fillIn(opts, DEFAULTS) - fillIn(self, opts) + Adapter.call(this, opts) /** * Default options to pass to r#insert. @@ -311,16 +288,31 @@ export default function RethinkDBAdapter (opts) { self.indices = {} } +// Setup prototype inheritance from Adapter +RethinkDBAdapter.prototype = Object.create(Adapter.prototype, { + constructor: { + value: RethinkDBAdapter, + enumerable: false, + writable: true, + configurable: true + } +}) + +Object.defineProperty(RethinkDBAdapter, '__super__', { + configurable: true, + value: Adapter +}) + /** * Alternative to ES6 class syntax for extending `RethinkDBAdapter`. * * @name RethinkDBAdapter.extend * @method * @param {Object} [instanceProps] Properties that will be added to the - * prototype of the subclass. + * prototype of the RethinkDBAdapter. * @param {Object} [classProps] Properties that will be added as static - * properties to the subclass itself. - * @return {Object} Subclass of `RethinkDBAdapter`. + * properties to the RethinkDBAdapter itself. + * @return {Object} RethinkDBAdapter of `RethinkDBAdapter`. */ RethinkDBAdapter.extend = extend @@ -333,121 +325,6 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { throw new Error('Unknown RethinkDB Error') } }, - /** - * @name RethinkDBAdapter#afterCreate - * @method - */ - afterCreate: noop2, - - /** - * @name RethinkDBAdapter#afterCreateMany - * @method - */ - afterCreateMany: noop2, - - /** - * @name RethinkDBAdapter#afterDestroy - * @method - */ - afterDestroy: noop2, - - /** - * @name RethinkDBAdapter#afterDestroyAll - * @method - */ - afterDestroyAll: noop2, - - /** - * @name RethinkDBAdapter#afterFind - * @method - */ - afterFind: noop2, - - /** - * @name RethinkDBAdapter#afterFindAll - * @method - */ - afterFindAll: noop2, - - /** - * @name RethinkDBAdapter#afterUpdate - * @method - */ - afterUpdate: noop2, - - /** - * @name RethinkDBAdapter#afterUpdateAll - * @method - */ - afterUpdateAll: noop2, - - /** - * @name RethinkDBAdapter#afterUpdateMany - * @method - */ - afterUpdateMany: noop2, - - /** - * @name RethinkDBAdapter#beforeCreate - * @method - */ - beforeCreate: noop, - - /** - * @name RethinkDBAdapter#beforeCreateMany - * @method - */ - beforeCreateMany: noop, - - /** - * @name RethinkDBAdapter#beforeDestroy - * @method - */ - beforeDestroy: noop, - - /** - * @name RethinkDBAdapter#beforeDestroyAll - * @method - */ - beforeDestroyAll: noop, - - /** - * @name RethinkDBAdapter#beforeFind - * @method - */ - beforeFind: noop, - - /** - * @name RethinkDBAdapter#beforeFindAll - * @method - */ - beforeFindAll: noop, - - /** - * @name RethinkDBAdapter#beforeUpdate - * @method - */ - beforeUpdate: noop, - - /** - * @name RethinkDBAdapter#beforeUpdateAll - * @method - */ - beforeUpdateAll: noop, - - /** - * @name RethinkDBAdapter#beforeUpdateMany - * @method - */ - beforeUpdateMany: noop, - - /** - * @name RethinkDBAdapter#dbg - * @method - */ - dbg (...args) { - this.log('debug', ...args) - }, selectDb (opts) { return this.r.db(isUndefined(opts.db) ? this.db : opts.db) @@ -612,17 +489,15 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { if (cursor && cursor.changes && cursor.changes.length && cursor.changes[0].new_val) { record = cursor.changes[0].new_val } - let result = {} - fillIn(result, cursor) - result.data = record - result.created = record ? 1 : 0 - result = self.getOpt('raw', opts) ? result : result.data + let response = new Response(record, cursor, 'create') + response.created = record ? 1 : 0 + response = self.respond(response, opts) // afterCreate lifecycle hook op = opts.op = 'afterCreate' - return resolve(self[op](mapper, props, opts, result)).then(function (_result) { + return resolve(self[op](mapper, props, opts, response)).then(function (_response) { // Allow for re-assignment from lifecycle hook - return isUndefined(_result) ? result : _result + return isUndefined(_response) ? response : _response }) }) }, @@ -668,9 +543,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { return change.new_val }) } - let result = {} - fillIn(result, cursor) - result.data = records + let result = new Response(records, cursor, 'createMany') result.created = records.length result = self.getOpt('raw', opts) ? result : result.data @@ -711,8 +584,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { self.dbg(op, id, opts) return self.selectTable(mapper, opts).get(id).delete(self.getOpt('deleteOpts', opts)).run(self.getOpt('runOpts', opts)) }).then(function (cursor) { - let result = {} - fillIn(result, cursor) + let result = new Response(undefined, cursor, 'destroy') result = self.getOpt('raw', opts) ? result : undefined // afterDestroy lifecycle hook @@ -764,8 +636,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { .delete(self.getOpt('deleteOpts', opts)) .run(self.getOpt('runOpts', opts)) }).then(function (cursor) { - let result = {} - fillIn(result, cursor) + let result = new Response(undefined, cursor, 'destroyAll') result = self.getOpt('raw', opts) ? result : undefined // afterDestroyAll lifecycle hook @@ -777,138 +648,6 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { }) }, - /** - * Return the foreignKey from the given record for the provided relationship. - * - * There may be reasons why you may want to override this method, like when - * the id of the parent doesn't exactly match up to the key on the child. - * - * @name RethinkDBAdapter#makeHasManyForeignKey - * @method - * @return {*} - */ - makeHasManyForeignKey (mapper, def, record) { - return def.getForeignKey(record) - }, - - /** - * Load a hasMany relationship. - * - * @name RethinkDBAdapter#loadHasMany - * @method - * @return {Promise} - */ - loadHasMany (mapper, def, records, __opts) { - const self = this - let singular = false - - if (isObject(records) && !isArray(records)) { - singular = true - records = [records] - } - const IDs = records.map(function (record) { - return self.makeHasManyForeignKey(mapper, def, record) - }) - const query = {} - const criteria = query[def.foreignKey] = {} - if (singular) { - // more efficient query when we only have one record - criteria['=='] = IDs[0] - } else { - criteria['in'] = IDs.filter(function (id) { - return id - }) - } - return self.findAll(def.getRelation(), query, __opts).then(function (relatedItems) { - records.forEach(function (record) { - let attached = [] - // avoid unneccesary iteration when we only have one record - if (singular) { - attached = relatedItems - } else { - relatedItems.forEach(function (relatedItem) { - if (get(relatedItem, def.foreignKey) === record[mapper.idAttribute]) { - attached.push(relatedItem) - } - }) - } - def.setLocalField(record, attached) - }) - }) - }, - - /** - * Load a hasOne relationship. - * - * @name RethinkDBAdapter#loadHasOne - * @method - * @return {Promise} - */ - loadHasOne (mapper, def, records, __opts) { - if (isObject(records) && !isArray(records)) { - records = [records] - } - return this.loadHasMany(mapper, def, records, __opts).then(function () { - records.forEach(function (record) { - const relatedData = def.getLocalField(record) - if (isArray(relatedData) && relatedData.length) { - def.setLocalField(record, relatedData[0]) - } - }) - }) - }, - - /** - * Return the foreignKey from the given record for the provided relationship. - * - * @name RethinkDBAdapter#makeBelongsToForeignKey - * @method - * @return {*} - */ - makeBelongsToForeignKey (mapper, def, record) { - return def.getForeignKey(record) - }, - - /** - * Load a belongsTo relationship. - * - * @name RethinkDBAdapter#loadBelongsTo - * @method - * @return {Promise} - */ - loadBelongsTo (mapper, def, records, __opts) { - const self = this - const relationDef = def.getRelation() - - if (isObject(records) && !isArray(records)) { - const record = records - return self.find(relationDef, self.makeBelongsToForeignKey(mapper, def, record), __opts).then(function (relatedItem) { - def.setLocalField(record, relatedItem) - }) - } else { - const keys = records.map(function (record) { - return self.makeBelongsToForeignKey(mapper, def, record) - }).filter(function (key) { - return key - }) - return self.findAll(relationDef, { - where: { - [relationDef.idAttribute]: { - 'in': keys - } - } - }, __opts).then(function (relatedItems) { - records.forEach(function (record) { - relatedItems.forEach(function (relatedItem) { - if (relatedItem[relationDef.idAttribute] === record[def.foreignKey]) { - def.setLocalField(record, relatedItem) - } - }) - }) - }) - } - }, - /** * Retrieve the record with the given primary key. * @@ -1005,10 +744,8 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { return Promise.all(tasks) }).then(function () { - let result = { - data: record, - found: record ? 1 : 0 - } + let result = new Response(record, {}, 'find') + result.found = record ? 1 : 0 result = self.getOpt('raw', opts) ? result : result.data // afterFind lifecycle hook @@ -1147,10 +884,8 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { return Promise.all(tasks) }).then(function () { records || (records = []) - let result = { - data: records, - found: records.length - } + let result = new Response(records, {}, 'findAll') + result.found = records.length result = self.getOpt('raw', opts) ? result : result.data // afterFindAll lifecycle hook @@ -1181,43 +916,6 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { return isUndefined(opts.operators[operator]) ? ownOps[operator] || OPERATORS[operator] : opts.operators[operator] }, - /** - * Resolve the value of the specified option based on the given options and - * this adapter's settings. - * - * @name RethinkDBAdapter#getOpt - * @method - * @param {string} opt The name of the option. - * @param {Object} [opts] Configuration options. - * @return {*} The value of the specified option. - */ - getOpt (opt, opts) { - opts || (opts = {}) - return isUndefined(opts[opt]) ? plainCopy(this[opt]) : plainCopy(opts[opt]) - }, - - /** - * Logging utility method. - * - * @name RethinkDBAdapter#log - * @method - */ - log (level, ...args) { - if (level && !args.length) { - args.push(level) - level = 'debug' - } - if (level === 'debug' && !this.debug) { - return - } - const prefix = `${level.toUpperCase()}: (RethinkDBAdapter)` - if (console[level]) { - console[level](prefix, ...args) - } else { - console.log(prefix, ...args) - } - }, - /** * Apply the given update to the record with the specified primary key. * @@ -1257,9 +955,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { } else { throw new Error('Not Found') } - let result = {} - fillIn(result, cursor) - result.data = record + let result = new Response(record, cursor, 'update') result.updated = 1 result = self.getOpt('raw', opts) ? result : result.data @@ -1318,9 +1014,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { if (cursor && cursor.changes && cursor.changes.length) { records = cursor.changes.map(function (change) { return change.new_val }) } - let result = {} - fillIn(result, cursor) - result.data = records + let result = new Response(records, cursor, 'update') result.updated = records.length result = self.getOpt('raw', opts) ? result : result.data @@ -1378,9 +1072,7 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, { if (cursor && cursor.changes && cursor.changes.length) { updatedRecords = cursor.changes.map(function (change) { return change.new_val }) } - let result = {} - fillIn(result, cursor) - result.data = updatedRecords || [] + let result = new Response(updatedRecords || [], cursor, 'update') result.updated = result.data.length result = self.getOpt('raw', opts) ? result : result.data diff --git a/test/handleErrors.test.js b/test/handleErrors.test.js index ed6deb2..d5b2960 100644 --- a/test/handleErrors.test.js +++ b/test/handleErrors.test.js @@ -1,3 +1,4 @@ +'use strict' describe('RethinkDBAdapter#handleErrors(err)', function () { it('should do nothing when passed a falsy value', function () { var Test = this