From 034c97bccf645f64ec20ce05634333b75a0e8897 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Thu, 12 Nov 2015 04:24:41 +0000 Subject: [PATCH] Stable Version 2.3.0 --- .jshintrc | 34 -- .npmignore | 36 ++ .travis.yml | 9 +- CHANGELOG.md | 7 + CONTRIBUTING.md | 43 +- Gruntfile.js | 96 ----- README.md | 74 ++-- dist/js-data-redis.js | 893 ++++++++++++++++++++++++++++++++++++++-- mocha.start.js | 140 +------ package.json | 46 ++- src/index.js | 2 +- test/create.spec.js | 27 -- test/destroy.spec.js | 20 - test/destroyAll.spec.js | 24 -- test/find.spec.js | 72 ---- test/findAll.spec.js | 137 ------ test/update.spec.js | 40 -- test/updateAll.spec.js | 45 -- webpack.config.js | 24 ++ 19 files changed, 1061 insertions(+), 708 deletions(-) delete mode 100644 .jshintrc create mode 100644 .npmignore delete mode 100644 Gruntfile.js delete mode 100644 test/create.spec.js delete mode 100644 test/destroy.spec.js delete mode 100644 test/destroyAll.spec.js delete mode 100644 test/find.spec.js delete mode 100644 test/findAll.spec.js delete mode 100644 test/update.spec.js delete mode 100644 test/updateAll.spec.js create mode 100644 webpack.config.js diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 5778044..0000000 --- a/.jshintrc +++ /dev/null @@ -1,34 +0,0 @@ -{ - "node": false, - "browser": true, - "esnext": true, - "asi": true, - "bitwise": true, - "camelcase": true, - "curly": true, - "eqeqeq": true, - "immed": true, - "indent": 2, - "latedef": true, - "newcap": true, - "undef": true, - "unused": true, - "noarg": true, - "quotmark": "single", - "regexp": true, - "strict": false, - "trailing": true, - "smarttabs": true, - "globals": { - "describe": true, - "it": true, - "beforeEach": true, - "afterEach": true, - "assert": true, - "fail": true, - "console": true, - "require": true, - "module": true, - "exports": true - } -} diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..0e75e56 --- /dev/null +++ b/.npmignore @@ -0,0 +1,36 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Commenting this out is preferred by some people, see +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- +node_modules + +# Users Environment Variables +.lock-wscript + +.idea/ +*.iml +coverage/ +src/ +test/ +mocha.start.js +webpack.config.js \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index b9932c8..51ae0d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,8 @@ +sudo: false language: node_js node_js: + - "stable" + - "0.12" - "0.10" services: - redis-server -before_install: - - npm install -g npm - - npm install -g grunt-cli -script: - - grunt test - - grunt coveralls || true diff --git a/CHANGELOG.md b/CHANGELOG.md index 411eb25..e2b111b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +##### 2.3.0 - 11 November 2015 + +###### Other +- Rebuilt with Babel 6 +- Dropped Grunt +- Integrated js-data-adapter-tests + ##### 2.2.0 - 09 September 2015 ###### Backwards compatible API changes diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c7ec053..e7138b2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,24 +1,47 @@ # Contributing Guide -First, support is handled via the [Gitter Channel](https://gitter.im/js-data/js-data) and the [Mailing List](https://groups.io/org/groupsio/jsdata). Ask your questions there. +First, support is handled via the [Slack Channel](http://slack.js-data.io) and +the [Mailing List](https://groups.io/org/groupsio/jsdata). Ask your questions +there. -When submitting issues on GitHub, please include as much detail as possible to make debugging quick and easy. +When submitting issues on GitHub, please include as much detail as possible to +make debugging quick and easy. -- good - Your versions of js-data, js-data-redis, etc., relevant console logs/error, code examples that revealed the issue -- better - A [plnkr](http://plnkr.co/), [fiddle](http://jsfiddle.net/), or [bin](http://jsbin.com/?html,output) that demonstrates the issue -- best - A Pull Request that fixes the issue, including test coverage for the issue and the fix +- good - Your versions of js-data, js-data-redis, etc., relevant console +logs/error, code examples that revealed the issue +- better - A [plnkr](http://plnkr.co/), [fiddle](http://jsfiddle.net/), or +[bin](http://jsbin.com/?html,output) that demonstrates the issue +- best - A Pull Request that fixes the issue, including test coverage for the +issue and the fix [Github Issues](https://github.com/js-data/js-data-redis/issues). #### Submitting Pull Requests -1. Contribute to the issue/discussion that is the reason you'll be developing in the first place +1. Contribute to the issue/discussion that is the reason you'll be developing in +the first place 1. Fork js-data-redis 1. `git clone git@github.com:/js-data-redis.git` -1. `cd js-data-redis; npm install; bower install;` +1. `cd js-data-redis; npm install;` 1. Write your code, including relevant documentation and tests -1. Run `grunt test` (build and test) +1. Run `npm test` (build and test) + - You need io.js or Node 4.x that includes generator support without a flag 1. Your code will be linted and checked for formatting, the tests will be run -1. The `dist/` folder & files will be generated, do NOT commit `dist/*`! They will be committed when a release is cut. +1. The `dist/` folder & files will be generated, do NOT commit `dist/*`! They +will be committed when a release is cut. 1. Submit your PR and we'll review! -1. Thanks! \ No newline at end of file +1. Thanks! + +#### Have write access? + +Here's how to make a release on the `master` branch: + +1. Bump `package.json` to the appropriate version. +1. `npm test` must succeed. +1. This time, the built `dist/js-data-redis.js` file _will_ be committed, so stage its changes. +1. Mention the release version in the commit message, e.g. `Stable Version 1.2.3` +1. Push to master. +1. Create a git tag. Name it the version of the release, e.g. `1.2.3` + - Easiest way is to just create a GitHub Release, which will create the tag for you. Name the Release and the git tag the same thing. +1. `git fetch origin` if you tagged it via GitHub Release, so you can get the tag on your local machine. +1. `npm publish .` (Make sure you got the version bumped correctly!) diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index 0948f3f..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,96 +0,0 @@ -/* - * js-data-redis - * https://github.com/js-data/js-data-redis - * - * Copyright (c) 2014-2015 Jason Dobry - * Licensed under the MIT license. - */ -module.exports = function (grunt) { - require('jit-grunt')(grunt, { - coveralls: 'grunt-karma-coveralls' - }); - require('time-grunt')(grunt); - - var pkg = grunt.file.readJSON('package.json'); - - // Project configuration. - grunt.initConfig({ - pkg: pkg, - watch: { - dist: { - files: ['src/**/*.js'], - tasks: ['build'] - } - }, - coveralls: { - options: { - coverage_dir: 'coverage' - } - }, - mochaTest: { - all: { - options: { - reporter: 'spec' - }, - src: ['mocha.start.js', 'test/**/*.js'] - } - }, - webpack: { - dist: { - debug: true, - entry: './src/index.js', - output: { - filename: './dist/js-data-redis.js', - libraryTarget: 'commonjs2', - library: 'js-data-redis' - }, - externals: [ - 'mout/string/underscore', - 'mout/random/guid', - 'mout/array/map', - 'mout/array/unique', - 'js-data', - 'redis' - ], - module: { - loaders: [ - { test: /(src)(.+)\.js$/, exclude: /node_modules/, loader: 'babel-loader?blacklist=useStrict' } - ], - preLoaders: [ - { - test: /(src)(.+)\.js$|(test)(.+)\.js$/, // include .js files - exclude: /node_modules/, // exclude any and all files in the node_modules folder - loader: "jshint-loader?failOnHint=true" - } - ] - } - } - } - }); - - grunt.registerTask('standard', function () { - var child_process = require('child_process'); - var done = this.async(); - grunt.log.writeln('Linting for correcting formatting...'); - child_process.exec('node node_modules/standard/bin/cmd.js --parser babel-eslint src/index.js', function (err, stdout) { - console.log(stdout); - if (err) { - grunt.log.writeln('Failed due to ' + (stdout.split('\n').length - 2) + ' lint errors!'); - done(err); - } else { - grunt.log.writeln('Done linting.'); - done(); - } - }); - }); - - grunt.registerTask('n', ['mochaTest']); - - grunt.registerTask('test', ['build', 'n']); - grunt.registerTask('build', [ - 'standard', - 'webpack' - ]); - grunt.registerTask('go', ['build', 'watch:dist']); - grunt.registerTask('default', ['build']); -}; diff --git a/README.md b/README.md index dc3765d..95c6f57 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,14 @@ js-data logo -## js-data-redis [![npm version](https://img.shields.io/npm/v/js-data-redis.svg?style=flat-square)](https://www.npmjs.org/package/js-data-redis) [![Travis CI](https://img.shields.io/travis/js-data/js-data-redis.svg?style=flat-square)](https://travis-ci.org/js-data/js-data-redis) [![npm downloads](https://img.shields.io/npm/dm/js-data-redis.svg?style=flat-square)](https://www.npmjs.org/package/js-data-redis) [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/js-data/js-data-redis/blob/master/LICENSE) +## js-data-redis [![Slack Status][sl_b]][sl_l] [![npm version][npm_b]][npm_l] [![Travis CI][travis_b]][travis_l] [![npm downloads][dn_b]][dn_l] [![Coverage Status][cov_b]][cov_l] [![Codacy][cod_b]][cod_l] Redis adapter for [js-data](http://www.js-data.io/). ### API Documentation [DSRedisAdapter](http://www.js-data.io/docs/dsredisadapter) -### Project Status - -__Latest Release:__ [![Latest Release](https://img.shields.io/github/release/js-data/js-data-redis.svg?style=flat-square)](https://github.com/js-data/js-data-redis/releases) - -__Status:__ - -[![Codacity](https://img.shields.io/codacy/64cca2890a594370a5c9f4d5c0e3fcc3.svg?style=flat-square)](https://www.codacy.com/public/jasondobry/js-data-redis/dashboard) - -__Supported Platforms:__ - -[![node version](https://img.shields.io/badge/Node-0.10%2B-green.svg?style=flat-square)](https://github.com/js-data/js-data) - ### Quick Start -`npm install --save js-data js-data-redis`. +`npm install --save js-data js-data-redis redis`. ```js var JSData = require('js-data'); @@ -38,11 +26,13 @@ store.registerAdapter('redis', adapter, { default: true }); // "store" will now use the Redis adapter for all async operations ``` +Read about using [JSData on the Server](http://www.js-data.io/docs/jsdata-on-the-server). + ### Changelog [CHANGELOG.md](https://github.com/js-data/js-data-redis/blob/master/CHANGELOG.md) ### Community -- [Gitter Channel](https://gitter.im/js-data/js-data) - Better than IRC! +- [Slack Channel](http://slack.js-data.io) - Better than IRC! - [Announcements](http://www.js-data.io/blog) - [Mailing List](https://groups.io/org/groupsio/jsdata) - Ask your questions! - [Issues](https://github.com/js-data/js-data-redis/issues) - Found a bug? Feature request? Submit an issue! @@ -51,29 +41,52 @@ store.registerAdapter('redis', adapter, { default: true }); ### Contributing -First, support is handled via the [Gitter Channel](https://gitter.im/js-data/js-data) and the [Mailing List](https://groups.io/org/groupsio/jsdata). Ask your questions there. +First, support is handled via the [Slack Channel](http://slack.js-data.io) and +the [Mailing List](https://groups.io/org/groupsio/jsdata). Ask your questions +there. -When submitting issues on GitHub, please include as much detail as possible to make debugging quick and easy. +When submitting issues on GitHub, please include as much detail as possible to +make debugging quick and easy. -- good - Your versions of js-data, js-data-redis, etc., relevant console logs/error, code examples that revealed the issue -- better - A [plnkr](http://plnkr.co/), [fiddle](http://jsfiddle.net/), or [bin](http://jsbin.com/?html,output) that demonstrates the issue -- best - A Pull Request that fixes the issue, including test coverage for the issue and the fix +- good - Your versions of js-data, js-data-redis, etc., relevant console +logs/error, code examples that revealed the issue +- better - A [plnkr](http://plnkr.co/), [fiddle](http://jsfiddle.net/), or +[bin](http://jsbin.com/?html,output) that demonstrates the issue +- best - A Pull Request that fixes the issue, including test coverage for the +issue and the fix [Github Issues](https://github.com/js-data/js-data-redis/issues). #### Submitting Pull Requests -1. Contribute to the issue/discussion that is the reason you'll be developing in the first place +1. Contribute to the issue/discussion that is the reason you'll be developing in +the first place 1. Fork js-data-redis 1. `git clone git@github.com:/js-data-redis.git` -1. `cd js-data-redis; npm install; bower install;` +1. `cd js-data-redis; npm install;` 1. Write your code, including relevant documentation and tests -1. Run `grunt test` (build and test) +1. Run `npm test` (build and test) + - You need io.js or Node 4.x that includes generator support without a flag 1. Your code will be linted and checked for formatting, the tests will be run -1. The `dist/` folder & files will be generated, do NOT commit `dist/*`! They will be committed when a release is cut. +1. The `dist/` folder & files will be generated, do NOT commit `dist/*`! They +will be committed when a release is cut. 1. Submit your PR and we'll review! 1. Thanks! +#### Have write access? + +Here's how to make a release on the `master` branch: + +1. Bump `package.json` to the appropriate version. +1. `npm test` must succeed. +1. This time, the built `dist/js-data-redis.js` file _will_ be committed, so stage its changes. +1. Mention the release version in the commit message, e.g. `Stable Version 1.2.3` +1. Push to master. +1. Create a git tag. Name it the version of the release, e.g. `1.2.3` + - Easiest way is to just create a GitHub Release, which will create the tag for you. Name the Release and the git tag the same thing. +1. `git fetch origin` if you tagged it via GitHub Release, so you can get the tag on your local machine. +1. `npm publish .` (Make sure you got the version bumped correctly!) + ### License The MIT License (MIT) @@ -97,3 +110,16 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +[sl_b]: http://slack.js-data.io/badge.svg +[sl_l]: http://slack.js-data.io +[npm_b]: https://img.shields.io/npm/v/js-data-redis.svg?style=flat +[npm_l]: https://www.npmjs.org/package/js-data-redis +[travis_b]: https://img.shields.io/travis/js-data/js-data-redis.svg +[travis_l]: https://travis-ci.org/js-data/js-data-redis +[dn_b]: https://img.shields.io/npm/dm/js-data-redis.svg?style=flat +[dn_l]: https://www.npmjs.org/package/js-data-redis +[cov_b]: https://img.shields.io/coveralls/js-data/js-data-redis/master.svg?style=flat +[cov_l]: https://coveralls.io/github/js-data/js-data-redis?branch=master +[cod_b]: https://img.shields.io/codacy/64cca2890a594370a5c9f4d5c0e3fcc3.svg +[cod_l]: https://www.codacy.com/app/jasondobry/js-data-redis/dashboard diff --git a/dist/js-data-redis.js b/dist/js-data-redis.js index 971dd11..d211bb9 100644 --- a/dist/js-data-redis.js +++ b/dist/js-data-redis.js @@ -45,22 +45,20 @@ module.exports = /* 0 */ /***/ function(module, exports, __webpack_require__) { - Object.defineProperty(exports, '__esModule', { - value: true - }); + 'use strict'; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var JSData = __webpack_require__(1); var redis = __webpack_require__(2); var map = __webpack_require__(3); - var unique = __webpack_require__(4); - var underscore = __webpack_require__(5); - var guid = __webpack_require__(6); + var unique = __webpack_require__(14); + var underscore = __webpack_require__(16); + var guid = __webpack_require__(26); var DSUtils = JSData.DSUtils; var emptyStore = new JSData.DS(); @@ -121,7 +119,7 @@ module.exports = var instance = undefined; options = options || {}; - options['with'] = options['with'] || []; + options.with = options.with || []; return new DSUtils.Promise(function (resolve, reject) { return _this3.client.GET(getPath(resourceConfig) + '-' + id, function (err, item) { if (err) { @@ -140,22 +138,22 @@ module.exports = var relationName = def.relation; var relationDef = resourceConfig.getResource(relationName); var containedName = null; - if (DSUtils.contains(options['with'], relationName)) { + if (DSUtils.contains(options.with, relationName)) { containedName = relationName; - } else if (DSUtils.contains(options['with'], def.localField)) { + } else if (DSUtils.contains(options.with, def.localField)) { containedName = def.localField; } if (containedName) { (function () { var __options = DSUtils.deepMixIn({}, options.orig ? options.orig() : options); - __options['with'] = options['with'].slice(); + __options.with = options.with.slice(); __options = DSUtils._(relationDef, __options); - DSUtils.remove(__options['with'], containedName); - DSUtils.forEach(__options['with'], function (relation, i) { + DSUtils.remove(__options.with, containedName); + DSUtils.forEach(__options.with, function (relation, i) { if (relation && relation.indexOf(containedName) === 0 && relation.length >= containedName.length && relation[containedName.length] === '.') { - __options['with'][i] = relation.substr(containedName.length + 1); + __options.with[i] = relation.substr(containedName.length + 1); } else { - __options['with'][i] = ''; + __options.with[i] = ''; } }); @@ -215,7 +213,7 @@ module.exports = var items = null; options = options || {}; - options['with'] = options['with'] || []; + options.with = options.with || []; return this.getIds(resourceConfig).then(function (ids) { var tasks = []; var path = getPath(resourceConfig); @@ -232,22 +230,22 @@ module.exports = var relationName = def.relation; var relationDef = resourceConfig.getResource(relationName); var containedName = null; - if (DSUtils.contains(options['with'], relationName)) { + if (DSUtils.contains(options.with, relationName)) { containedName = relationName; - } else if (DSUtils.contains(options['with'], def.localField)) { + } else if (DSUtils.contains(options.with, def.localField)) { containedName = def.localField; } if (containedName) { (function () { var __options = DSUtils.deepMixIn({}, options.orig ? options.orig() : options); - __options['with'] = options['with'].slice(); + __options.with = options.with.slice(); __options = DSUtils._(relationDef, __options); - DSUtils.remove(__options['with'], containedName); - DSUtils.forEach(__options['with'], function (relation, i) { + DSUtils.remove(__options.with, containedName); + DSUtils.forEach(__options.with, function (relation, i) { if (relation && relation.indexOf(containedName) === 0 && relation.length >= containedName.length && relation[containedName.length] === '.') { - __options['with'][i] = relation.substr(containedName.length + 1); + __options.with[i] = relation.substr(containedName.length + 1); } else { - __options['with'][i] = ''; + __options.with[i] = ''; } }); @@ -418,8 +416,7 @@ module.exports = return DSRedisAdapter; })(); - exports['default'] = DSRedisAdapter; - module.exports = exports['default']; + module.exports = DSRedisAdapter; /***/ }, /* 1 */ @@ -435,27 +432,859 @@ module.exports = /***/ }, /* 3 */ -/***/ function(module, exports) { +/***/ function(module, exports, __webpack_require__) { + + var makeIterator = __webpack_require__(4); + + /** + * Array map + */ + function map(arr, callback, thisObj) { + callback = makeIterator(callback, thisObj); + var results = []; + if (arr == null){ + return results; + } + + var i = -1, len = arr.length; + while (++i < len) { + results[i] = callback(arr[i], i, arr); + } + + return results; + } + + module.exports = map; + - module.exports = require("mout/array/map"); /***/ }, /* 4 */ -/***/ function(module, exports) { +/***/ function(module, exports, __webpack_require__) { + + var identity = __webpack_require__(5); + var prop = __webpack_require__(6); + var deepMatches = __webpack_require__(7); + + /** + * Converts argument into a valid iterator. + * Used internally on most array/object/collection methods that receives a + * callback/iterator providing a shortcut syntax. + */ + function makeIterator(src, thisObj){ + if (src == null) { + return identity; + } + switch(typeof src) { + case 'function': + // function is the first to improve perf (most common case) + // also avoid using `Function#call` if not needed, which boosts + // perf a lot in some cases + return (typeof thisObj !== 'undefined')? function(val, i, arr){ + return src.call(thisObj, val, i, arr); + } : src; + case 'object': + return function(val){ + return deepMatches(val, src); + }; + case 'string': + case 'number': + return prop(src); + } + } + + module.exports = makeIterator; + + - module.exports = require("mout/array/unique"); /***/ }, /* 5 */ /***/ function(module, exports) { - module.exports = require("mout/string/underscore"); + + + /** + * Returns the first argument provided to it. + */ + function identity(val){ + return val; + } + + module.exports = identity; + + + /***/ }, /* 6 */ /***/ function(module, exports) { - module.exports = require("mout/random/guid"); + + + /** + * Returns a function that gets a property of the passed object + */ + function prop(name){ + return function(obj){ + return obj[name]; + }; + } + + module.exports = prop; + + + + +/***/ }, +/* 7 */ +/***/ function(module, exports, __webpack_require__) { + + var forOwn = __webpack_require__(8); + var isArray = __webpack_require__(11); + + function containsMatch(array, pattern) { + var i = -1, length = array.length; + while (++i < length) { + if (deepMatches(array[i], pattern)) { + return true; + } + } + + return false; + } + + function matchArray(target, pattern) { + var i = -1, patternLength = pattern.length; + while (++i < patternLength) { + if (!containsMatch(target, pattern[i])) { + return false; + } + } + + return true; + } + + function matchObject(target, pattern) { + var result = true; + forOwn(pattern, function(val, key) { + if (!deepMatches(target[key], val)) { + // Return false to break out of forOwn early + return (result = false); + } + }); + + return result; + } + + /** + * Recursively check if the objects match. + */ + function deepMatches(target, pattern){ + if (target && typeof target === 'object') { + if (isArray(target) && isArray(pattern)) { + return matchArray(target, pattern); + } else { + return matchObject(target, pattern); + } + } else { + return target === pattern; + } + } + + module.exports = deepMatches; + + + + +/***/ }, +/* 8 */ +/***/ function(module, exports, __webpack_require__) { + + var hasOwn = __webpack_require__(9); + var forIn = __webpack_require__(10); + + /** + * Similar to Array/forEach but works over object properties and fixes Don't + * Enum bug on IE. + * based on: http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation + */ + function forOwn(obj, fn, thisObj){ + forIn(obj, function(val, key){ + if (hasOwn(obj, key)) { + return fn.call(thisObj, obj[key], key, obj); + } + }); + } + + module.exports = forOwn; + + + + +/***/ }, +/* 9 */ +/***/ function(module, exports) { + + + + /** + * Safer Object.hasOwnProperty + */ + function hasOwn(obj, prop){ + return Object.prototype.hasOwnProperty.call(obj, prop); + } + + module.exports = hasOwn; + + + + +/***/ }, +/* 10 */ +/***/ function(module, exports, __webpack_require__) { + + var hasOwn = __webpack_require__(9); + + var _hasDontEnumBug, + _dontEnums; + + function checkDontEnum(){ + _dontEnums = [ + 'toString', + 'toLocaleString', + 'valueOf', + 'hasOwnProperty', + 'isPrototypeOf', + 'propertyIsEnumerable', + 'constructor' + ]; + + _hasDontEnumBug = true; + + for (var key in {'toString': null}) { + _hasDontEnumBug = false; + } + } + + /** + * Similar to Array/forEach but works over object properties and fixes Don't + * Enum bug on IE. + * based on: http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation + */ + function forIn(obj, fn, thisObj){ + var key, i = 0; + // no need to check if argument is a real object that way we can use + // it for arrays, functions, date, etc. + + //post-pone check till needed + if (_hasDontEnumBug == null) checkDontEnum(); + + for (key in obj) { + if (exec(fn, obj, key, thisObj) === false) { + break; + } + } + + + if (_hasDontEnumBug) { + var ctor = obj.constructor, + isProto = !!ctor && obj === ctor.prototype; + + while (key = _dontEnums[i++]) { + // For constructor, if it is a prototype object the constructor + // is always non-enumerable unless defined otherwise (and + // enumerated above). For non-prototype objects, it will have + // to be defined on this object, since it cannot be defined on + // any prototype objects. + // + // For other [[DontEnum]] properties, check if the value is + // different than Object prototype value. + if ( + (key !== 'constructor' || + (!isProto && hasOwn(obj, key))) && + obj[key] !== Object.prototype[key] + ) { + if (exec(fn, obj, key, thisObj) === false) { + break; + } + } + } + } + } + + function exec(fn, obj, key, thisObj){ + return fn.call(thisObj, obj[key], key, obj); + } + + module.exports = forIn; + + + + +/***/ }, +/* 11 */ +/***/ function(module, exports, __webpack_require__) { + + var isKind = __webpack_require__(12); + /** + */ + var isArray = Array.isArray || function (val) { + return isKind(val, 'Array'); + }; + module.exports = isArray; + + + +/***/ }, +/* 12 */ +/***/ function(module, exports, __webpack_require__) { + + var kindOf = __webpack_require__(13); + /** + * Check if value is from a specific "kind". + */ + function isKind(val, kind){ + return kindOf(val) === kind; + } + module.exports = isKind; + + + +/***/ }, +/* 13 */ +/***/ function(module, exports) { + + + + var _rKind = /^\[object (.*)\]$/, + _toString = Object.prototype.toString, + UNDEF; + + /** + * Gets the "kind" of value. (e.g. "String", "Number", etc) + */ + function kindOf(val) { + if (val === null) { + return 'Null'; + } else if (val === UNDEF) { + return 'Undefined'; + } else { + return _rKind.exec( _toString.call(val) )[1]; + } + } + module.exports = kindOf; + + + +/***/ }, +/* 14 */ +/***/ function(module, exports, __webpack_require__) { + + var filter = __webpack_require__(15); + + /** + * @return {array} Array of unique items + */ + function unique(arr, compare){ + compare = compare || isEqual; + return filter(arr, function(item, i, arr){ + var n = arr.length; + while (++i < n) { + if ( compare(item, arr[i]) ) { + return false; + } + } + return true; + }); + } + + function isEqual(a, b){ + return a === b; + } + + module.exports = unique; + + + + +/***/ }, +/* 15 */ +/***/ function(module, exports, __webpack_require__) { + + var makeIterator = __webpack_require__(4); + + /** + * Array filter + */ + function filter(arr, callback, thisObj) { + callback = makeIterator(callback, thisObj); + var results = []; + if (arr == null) { + return results; + } + + var i = -1, len = arr.length, value; + while (++i < len) { + value = arr[i]; + if (callback(value, i, arr)) { + results.push(value); + } + } + + return results; + } + + module.exports = filter; + + + + +/***/ }, +/* 16 */ +/***/ function(module, exports, __webpack_require__) { + + var toString = __webpack_require__(17); + var slugify = __webpack_require__(18); + var unCamelCase = __webpack_require__(25); + /** + * Replaces spaces with underscores, split camelCase text, remove non-word chars, remove accents and convert to lower case. + */ + function underscore(str){ + str = toString(str); + str = unCamelCase(str); + return slugify(str, "_"); + } + module.exports = underscore; + + + +/***/ }, +/* 17 */ +/***/ function(module, exports) { + + + + /** + * Typecast a value to a String, using an empty string value for null or + * undefined. + */ + function toString(val){ + return val == null ? '' : val.toString(); + } + + module.exports = toString; + + + + +/***/ }, +/* 18 */ +/***/ function(module, exports, __webpack_require__) { + + var toString = __webpack_require__(17); + var replaceAccents = __webpack_require__(19); + var removeNonWord = __webpack_require__(20); + var trim = __webpack_require__(21); + /** + * Convert to lower case, remove accents, remove non-word chars and + * replace spaces with the specified delimeter. + * Does not split camelCase text. + */ + function slugify(str, delimeter){ + str = toString(str); + + if (delimeter == null) { + delimeter = "-"; + } + str = replaceAccents(str); + str = removeNonWord(str); + str = trim(str) //should come after removeNonWord + .replace(/ +/g, delimeter) //replace spaces with delimeter + .toLowerCase(); + return str; + } + module.exports = slugify; + + + +/***/ }, +/* 19 */ +/***/ function(module, exports, __webpack_require__) { + + var toString = __webpack_require__(17); + /** + * Replaces all accented chars with regular ones + */ + function replaceAccents(str){ + str = toString(str); + + // verifies if the String has accents and replace them + if (str.search(/[\xC0-\xFF]/g) > -1) { + str = str + .replace(/[\xC0-\xC5]/g, "A") + .replace(/[\xC6]/g, "AE") + .replace(/[\xC7]/g, "C") + .replace(/[\xC8-\xCB]/g, "E") + .replace(/[\xCC-\xCF]/g, "I") + .replace(/[\xD0]/g, "D") + .replace(/[\xD1]/g, "N") + .replace(/[\xD2-\xD6\xD8]/g, "O") + .replace(/[\xD9-\xDC]/g, "U") + .replace(/[\xDD]/g, "Y") + .replace(/[\xDE]/g, "P") + .replace(/[\xE0-\xE5]/g, "a") + .replace(/[\xE6]/g, "ae") + .replace(/[\xE7]/g, "c") + .replace(/[\xE8-\xEB]/g, "e") + .replace(/[\xEC-\xEF]/g, "i") + .replace(/[\xF1]/g, "n") + .replace(/[\xF2-\xF6\xF8]/g, "o") + .replace(/[\xF9-\xFC]/g, "u") + .replace(/[\xFE]/g, "p") + .replace(/[\xFD\xFF]/g, "y"); + } + return str; + } + module.exports = replaceAccents; + + + +/***/ }, +/* 20 */ +/***/ function(module, exports, __webpack_require__) { + + var toString = __webpack_require__(17); + // This pattern is generated by the _build/pattern-removeNonWord.js script + var PATTERN = /[^\x20\x2D0-9A-Z\x5Fa-z\xC0-\xD6\xD8-\xF6\xF8-\xFF]/g; + + /** + * Remove non-word chars. + */ + function removeNonWord(str){ + str = toString(str); + return str.replace(PATTERN, ''); + } + + module.exports = removeNonWord; + + + +/***/ }, +/* 21 */ +/***/ function(module, exports, __webpack_require__) { + + var toString = __webpack_require__(17); + var WHITE_SPACES = __webpack_require__(22); + var ltrim = __webpack_require__(23); + var rtrim = __webpack_require__(24); + /** + * Remove white-spaces from beginning and end of string. + */ + function trim(str, chars) { + str = toString(str); + chars = chars || WHITE_SPACES; + return ltrim(rtrim(str, chars), chars); + } + + module.exports = trim; + + + +/***/ }, +/* 22 */ +/***/ function(module, exports) { + + + /** + * Contains all Unicode white-spaces. Taken from + * http://en.wikipedia.org/wiki/Whitespace_character. + */ + module.exports = [ + ' ', '\n', '\r', '\t', '\f', '\v', '\u00A0', '\u1680', '\u180E', + '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006', + '\u2007', '\u2008', '\u2009', '\u200A', '\u2028', '\u2029', '\u202F', + '\u205F', '\u3000' + ]; + + + +/***/ }, +/* 23 */ +/***/ function(module, exports, __webpack_require__) { + + var toString = __webpack_require__(17); + var WHITE_SPACES = __webpack_require__(22); + /** + * Remove chars from beginning of string. + */ + function ltrim(str, chars) { + str = toString(str); + chars = chars || WHITE_SPACES; + + var start = 0, + len = str.length, + charLen = chars.length, + found = true, + i, c; + + while (found && start < len) { + found = false; + i = -1; + c = str.charAt(start); + + while (++i < charLen) { + if (c === chars[i]) { + found = true; + start++; + break; + } + } + } + + return (start >= len) ? '' : str.substr(start, len); + } + + module.exports = ltrim; + + + +/***/ }, +/* 24 */ +/***/ function(module, exports, __webpack_require__) { + + var toString = __webpack_require__(17); + var WHITE_SPACES = __webpack_require__(22); + /** + * Remove chars from end of string. + */ + function rtrim(str, chars) { + str = toString(str); + chars = chars || WHITE_SPACES; + + var end = str.length - 1, + charLen = chars.length, + found = true, + i, c; + + while (found && end >= 0) { + found = false; + i = -1; + c = str.charAt(end); + + while (++i < charLen) { + if (c === chars[i]) { + found = true; + end--; + break; + } + } + } + + return (end >= 0) ? str.substring(0, end + 1) : ''; + } + + module.exports = rtrim; + + + +/***/ }, +/* 25 */ +/***/ function(module, exports, __webpack_require__) { + + var toString = __webpack_require__(17); + + var CAMEL_CASE_BORDER = /([a-z\xE0-\xFF])([A-Z\xC0\xDF])/g; + + /** + * Add space between camelCase text. + */ + function unCamelCase(str, delimiter){ + if (delimiter == null) { + delimiter = ' '; + } + + function join(str, c1, c2) { + return c1 + delimiter + c2; + } + + str = toString(str); + str = str.replace(CAMEL_CASE_BORDER, join); + str = str.toLowerCase(); //add space between camelCase text + return str; + } + module.exports = unCamelCase; + + + +/***/ }, +/* 26 */ +/***/ function(module, exports, __webpack_require__) { + + var randHex = __webpack_require__(27); + var choice = __webpack_require__(28); + + /** + * Returns pseudo-random guid (UUID v4) + * IMPORTANT: it's not totally "safe" since randHex/choice uses Math.random + * by default and sequences can be predicted in some cases. See the + * "random/random" documentation for more info about it and how to replace + * the default PRNG. + */ + function guid() { + return ( + randHex(8)+'-'+ + randHex(4)+'-'+ + // v4 UUID always contain "4" at this position to specify it was + // randomly generated + '4' + randHex(3) +'-'+ + // v4 UUID always contain chars [a,b,8,9] at this position + choice(8, 9, 'a', 'b') + randHex(3)+'-'+ + randHex(12) + ); + } + module.exports = guid; + + + +/***/ }, +/* 27 */ +/***/ function(module, exports, __webpack_require__) { + + var choice = __webpack_require__(28); + + var _chars = '0123456789abcdef'.split(''); + + /** + * Returns a random hexadecimal string + */ + function randHex(size){ + size = size && size > 0? size : 6; + var str = ''; + while (size--) { + str += choice(_chars); + } + return str; + } + + module.exports = randHex; + + + + +/***/ }, +/* 28 */ +/***/ function(module, exports, __webpack_require__) { + + var randInt = __webpack_require__(29); + var isArray = __webpack_require__(11); + + /** + * Returns a random element from the supplied arguments + * or from the array (if single argument is an array). + */ + function choice(items) { + var target = (arguments.length === 1 && isArray(items))? items : arguments; + return target[ randInt(0, target.length - 1) ]; + } + + module.exports = choice; + + + + +/***/ }, +/* 29 */ +/***/ function(module, exports, __webpack_require__) { + + var MIN_INT = __webpack_require__(30); + var MAX_INT = __webpack_require__(31); + var rand = __webpack_require__(32); + + /** + * Gets random integer inside range or snap to min/max values. + */ + function randInt(min, max){ + min = min == null? MIN_INT : ~~min; + max = max == null? MAX_INT : ~~max; + // can't be max + 0.5 otherwise it will round up if `rand` + // returns `max` causing it to overflow range. + // -0.5 and + 0.49 are required to avoid bias caused by rounding + return Math.round( rand(min - 0.5, max + 0.499999999999) ); + } + + module.exports = randInt; + + + +/***/ }, +/* 30 */ +/***/ function(module, exports) { + + /** + * @constant Minimum 32-bit signed integer value (-2^31). + */ + + module.exports = -2147483648; + + + +/***/ }, +/* 31 */ +/***/ function(module, exports) { + + /** + * @constant Maximum 32-bit signed integer value. (2^31 - 1) + */ + + module.exports = 2147483647; + + + +/***/ }, +/* 32 */ +/***/ function(module, exports, __webpack_require__) { + + var random = __webpack_require__(33); + var MIN_INT = __webpack_require__(30); + var MAX_INT = __webpack_require__(31); + + /** + * Returns random number inside range + */ + function rand(min, max){ + min = min == null? MIN_INT : min; + max = max == null? MAX_INT : max; + return min + (max - min) * random(); + } + + module.exports = rand; + + + +/***/ }, +/* 33 */ +/***/ function(module, exports) { + + + + /** + * Just a wrapper to Math.random. No methods inside mout/random should call + * Math.random() directly so we can inject the pseudo-random number + * generator if needed (ie. in case we need a seeded random or a better + * algorithm than the native one) + */ + function random(){ + return random.get(); + } + + // we expose the method so it can be swapped if needed + random.get = Math.random; + + module.exports = random; + + + /***/ } /******/ ]); \ No newline at end of file diff --git a/mocha.start.js b/mocha.start.js index 273bb82..d52f353 100644 --- a/mocha.start.js +++ b/mocha.start.js @@ -1,45 +1,20 @@ /*global assert:true */ 'use strict'; -var assert = require('chai').assert; -assert.equalObjects = function (a, b, m) { - assert.deepEqual(JSON.parse(JSON.stringify(a)), JSON.parse(JSON.stringify(b)), m || 'Objects should be equal!'); -}; -var mocha = require('mocha'); -var sinon = require('sinon'); -var DSRedisAdapter = require('./'); var JSData = require('js-data'); +var TestRunner = require('js-data-adapter-tests'); + +var mocha = require('mocha'); +var coMocha = require('co-mocha'); + +coMocha(mocha); JSData.DSUtils.Promise = require('bluebird'); -var adapter, store, DSUtils, DSErrors, Profile, User, Post, Comment; +var DSRedisAdapter = require('./'); var globals = module.exports = { - fail: function (msg) { - assert.equal('should not reach this!: ' + msg, 'failure'); - }, - TYPES_EXCEPT_STRING: [123, 123.123, null, undefined, {}, [], true, false, function () { - }], - TYPES_EXCEPT_STRING_OR_ARRAY: [123, 123.123, null, undefined, {}, true, false, function () { - }], - TYPES_EXCEPT_STRING_OR_NUMBER: [null, undefined, {}, [], true, false, function () { - }], - TYPES_EXCEPT_STRING_OR_OBJECT: [123, 123.123, null, undefined, [], true, false, function () { - }], - TYPES_EXCEPT_STRING_OR_NUMBER_OBJECT: [null, undefined, [], true, false, function () { - }], - TYPES_EXCEPT_STRING_OR_ARRAY_OR_NUMBER: [null, undefined, {}, true, false, function () { - }], - TYPES_EXCEPT_NUMBER: ['string', null, undefined, {}, [], true, false, function () { - }], - TYPES_EXCEPT_OBJECT: ['string', 123, 123.123, null, undefined, true, false, function () { - }], - TYPES_EXCEPT_BOOLEAN: ['string', 123, 123.123, null, undefined, {}, [], function () { - }], - TYPES_EXCEPT_FUNCTION: ['string', 123, 123.123, null, undefined, {}, [], true, false], - assert: assert, - sinon: sinon, - adapter: undefined, - store: undefined + TestRunner: TestRunner, + assert: TestRunner.assert }; var test = new mocha(); @@ -52,90 +27,19 @@ for (var key in globals) { } test.globals(testGlobals); -beforeEach(function () { - store = new JSData.DS({ - log: false - }); - adapter = new DSRedisAdapter(); - DSUtils = JSData.DSUtils; - DSErrors = JSData.DSErrors; - globals.Profile = global.Profile = Profile = store.defineResource({ - name: 'profile' - }); - globals.User = global.User = User = store.defineResource({ - name: 'user', - relations: { - hasMany: { - post: { - localField: 'posts', - foreignKey: 'post' - } - }, - hasOne: { - profile: { - localField: 'profile', - localKey: 'profileId' - } - } - } - }); - globals.Post = global.Post = Post = store.defineResource({ - name: 'post', - relations: { - belongsTo: { - user: { - localField: 'user', - localKey: 'userId' - } - }, - hasMany: { - comment: { - localField: 'comments', - foreignKey: 'postId' - } - } - } - }); - globals.Comment = global.Comment = Comment = store.defineResource({ - name: 'comment', - relations: { - belongsTo: { - post: { - localField: 'post', - localKey: 'postId' - }, - user: { - localField: 'user', - localKey: 'userId' - } - } - } - }); - - globals.store = store; - global.store = globals.store; - - globals.adapter = adapter; - global.adapter = globals.adapter; - - globals.DSUtils = DSUtils; - global.DSUtils = globals.DSUtils; - - globals.DSErrors = DSErrors; - global.DSErrors = globals.DSErrors; +TestRunner.init({ + DS: JSData.DS, + Adapter: DSRedisAdapter, + features: [] }); -afterEach(function (done) { - globals.adapter = null; - global.adapter = null; - - adapter.destroyAll(User).then(function () { - return adapter.destroyAll(Profile); - }).then(function () { - return adapter.destroyAll(Post); - }).then(function () { - return adapter.destroyAll(Comment); - }).then(function () { - done(); - }).catch(done); +beforeEach(function () { + globals.DSUtils = global.DSUtils = this.$$DSUtils; + globals.DSErrors = global.DSErrors = this.$$DSErrors; + globals.adapter = global.adapter = this.$$adapter; + globals.store = global.store = this.$$store; + globals.User = global.User = this.$$User; + globals.Profile = global.Profile = this.$$Profile; + globals.Post = global.Post = this.$$Post; + globals.Comment = global.Comment = this.$$Comment; }); diff --git a/package.json b/package.json index 786d45a..271930f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "js-data-redis", "description": "Redis adapter for js-data.", - "version": "2.2.0", + "version": "2.3.0", "homepage": "http://www.js-data.io/docs/dsredisadapter", "repository": { "type": "git", @@ -22,32 +22,34 @@ "redis" ], "devDependencies": { - "babel-core": "5.8.23", - "babel-eslint": "^4.1.1", - "babel-loader": "5.3.2", - "bluebird": "2.10.0", - "chai": "3.2.0", - "grunt": "0.4.5", - "grunt-contrib-watch": "0.6.1", - "grunt-karma-coveralls": "2.5.4", - "grunt-mocha-test": "0.12.7", - "grunt-webpack": "1.0.11", - "jit-grunt": "0.9.1", - "jshint": "2.8.0", - "jshint-loader": "0.8.3", - "sinon": "1.16.1", - "standard": "^5.2.2", - "time-grunt": "1.2.1", - "webpack-dev-server": "1.10.1" + "babel-core": "6.1.4", + "babel-eslint": "4.1.5", + "babel-loader": "6.1.0", + "babel-preset-es2015": "6.1.2", + "bluebird": "3.0.5", + "co-mocha": "1.1.2", + "codacy-coverage": "1.1.3", + "coveralls": "2.11.4", + "istanbul": "0.4.0", + "js-data-adapter-tests": "~1.x", + "mocha": "2.3.3", + "mout": "0.11.1", + "standard": "5.3.1", + "webpack": "1.12.4" }, "scripts": { - "test": "grunt test" + "lint": "standard src/index.js", + "build": "webpack --config webpack.config.js --progress --colors", + "mocha": "mocha --timeout 20000 --reporter dot mocha.start.js", + "cover": "istanbul cover --hook-run-in-context node_modules/mocha/bin/_mocha -- --timeout 20000 --reporter dot mocha.start.js", + "test": "npm run lint && npm run build && npm run cover", + "ci": "npm run test && cat coverage/lcov.info | coveralls || true && cat ./coverage/lcov.info | codacy-coverage || true" }, - "dependencies": { - "mout": "0.11.0" + "standard": { + "parser": "babel-eslint" }, "peerDependencies": { - "js-data": ">=2.0.0", + "js-data": "~2.x", "redis": ">=0.12.1" } } diff --git a/src/index.js b/src/index.js index fe9f805..be9b1fe 100644 --- a/src/index.js +++ b/src/index.js @@ -309,4 +309,4 @@ class DSRedisAdapter { } } -export default DSRedisAdapter +module.exports = DSRedisAdapter diff --git a/test/create.spec.js b/test/create.spec.js deleted file mode 100644 index 0924a23..0000000 --- a/test/create.spec.js +++ /dev/null @@ -1,27 +0,0 @@ -describe('DSRedisAdapter#create', function () { - it('should create a user in Redis', function () { - var id; - return adapter.create(User, { name: 'John' }).then(function (user) { - id = user.id; - assert.equal(user.name, 'John'); - assert.isString(user.id); - return adapter.find(User, user.id); - }) - .then(function (user) { - assert.equal(user.name, 'John'); - assert.isString(user.id); - assert.deepEqual(user, { id: id, name: 'John' }); - return adapter.destroy(User, user.id); - }) - .then(function (user) { - assert.isFalse(!!user); - return adapter.find(User, id); - }) - .then(function () { - throw new Error('Should not have reached here!'); - }) - .catch(function (err) { - assert.equal(err.message, 'Not Found!'); - }); - }); -}); diff --git a/test/destroy.spec.js b/test/destroy.spec.js deleted file mode 100644 index 5710ca6..0000000 --- a/test/destroy.spec.js +++ /dev/null @@ -1,20 +0,0 @@ -describe('DSRedisAdapter#destroy', function () { - it('should destroy a user from Redis', function () { - var id; - return adapter.create(User, { name: 'John' }) - .then(function (user) { - id = user.id; - return adapter.destroy(User, user.id); - }) - .then(function (user) { - assert.isFalse(!!user); - return adapter.find(User, id); - }) - .then(function () { - throw new Error('Should not have reached here!'); - }) - .catch(function (err) { - assert.equal(err.message, 'Not Found!'); - }); - }); -}); diff --git a/test/destroyAll.spec.js b/test/destroyAll.spec.js deleted file mode 100644 index 45fe535..0000000 --- a/test/destroyAll.spec.js +++ /dev/null @@ -1,24 +0,0 @@ -describe('DSRedisAdapter#destroyAll', function () { - it('should destroy all items', function () { - var id; - return adapter.create(User, { name: 'John' }) - .then(function (user) { - id = user.id; - return adapter.findAll(User, { - name: 'John' - }); - }).then(function (users) { - assert.equal(users.length, 1); - assert.deepEqual(users[0], { id: id, name: 'John' }); - return adapter.destroyAll(User, { - name: 'John' - }); - }).then(function () { - return adapter.findAll(User, { - name: 'John' - }); - }).then(function (users) { - assert.equal(users.length, 0); - }); - }); -}); diff --git a/test/find.spec.js b/test/find.spec.js deleted file mode 100644 index 23eee2a..0000000 --- a/test/find.spec.js +++ /dev/null @@ -1,72 +0,0 @@ -var Promise = require('bluebird'); - -describe('DSRedisAdapter#find', function () { - it('should find a user in Redis', function () { - var id, id2, _user, _post, _comments; - return adapter.create(User, {name: 'John'}) - .then(function (user) { - _user = user; - id = user.id; - assert.equal(user.name, 'John'); - assert.isString(user.id); - return adapter.find(User, user.id); - }) - .then(function (user) { - assert.equal(user.name, 'John'); - assert.isString(user.id); - assert.equalObjects(user, {id: id, name: 'John'}); - return adapter.create(Post, { - content: 'test', - userId: user.id - }); - }) - .then(function (post) { - _post = post; - id2 = post.id; - assert.equal(post.content, 'test'); - assert.isString(post.id); - assert.isString(post.userId); - return Promise.all([ - adapter.create(Comment, { - content: 'test2', - postId: post.id, - userId: _user.id - }), - adapter.create(Comment, { - content: 'test3', - postId: post.id, - userId: _user.id - }) - ]); - }) - .then(function (comments) { - _comments = comments; - _comments.sort(function (a, b) { - return a.content > b.content; - }); - return adapter.find(Post, _post.id, {'with': ['user', 'comment']}); - }) - .then(function (post) { - post.comments.sort(function (a, b) { - return a.content > b.content; - }); - assert.equalObjects(post.user, _user); - assert.equalObjects(post.comments, _comments); - return adapter.destroy(User, id); - }) - .then(function (user) { - assert.isFalse(!!user); - return adapter.find(User, id); - }) - .then(function () { - return adapter.destroy(Post, id2); - }) - .then(function () { - throw new Error('Should not have reached here!'); - }) - .catch(function (err) { - assert.equal(err.message, 'Not Found!'); - return true; - }); - }); -}); diff --git a/test/findAll.spec.js b/test/findAll.spec.js deleted file mode 100644 index 95abbd5..0000000 --- a/test/findAll.spec.js +++ /dev/null @@ -1,137 +0,0 @@ -var Promise = require('bluebird'); -describe('DSRedisAdapter#findAll', function () { - it('should filter users', function () { - var id; - - return adapter.findAll(User, { - age: 30 - }).then(function (users) { - assert.equal(users.length, 0); - return adapter.create(User, {name: 'John'}); - }).then(function (user) { - id = user.id; - return adapter.findAll(User, { - name: 'John' - }); - }).then(function (users) { - assert.equal(users.length, 1); - assert.deepEqual(users[0], {id: id, name: 'John'}); - return adapter.destroy(User, id); - }).then(function (destroyedUser) { - assert.isFalse(!!destroyedUser); - }); - }); - it('should load relations', function () { - return store.utils.Promise.all([ - adapter.create(User, {name: 'foo'}).then(function (user) { - return store.utils.Promise.all([ - adapter.create(Post, {name: 'foo2', userId: user.id}).then(function (post) { - return store.utils.Promise.all([ - adapter.create(Comment, {name: 'foo4', userId: user.id, postId: post.id}), - adapter.create(Comment, {name: 'bar4', userId: user.id, postId: post.id}) - ]) - }) - ]); - }), - adapter.create(User, {name: 'bar'}).then(function (user) { - return store.utils.Promise.all([ - adapter.create(Post, {name: 'foo3', userId: user.id}).then(function (post) { - return store.utils.Promise.all([ - adapter.create(Comment, {name: 'foo5', userId: user.id, postId: post.id}), - adapter.create(Comment, {name: 'bar5', userId: user.id, postId: post.id}) - ]) - }) - ]); - }) - ]).then(function () { - return adapter.findAll(Post, null, {with: ['user', 'comment']}); - }).then(function (posts) { - assert.equal(posts.length, 2); - assert.equal(posts[0].comments.length, 2); - assert.equal(posts[1].comments.length, 2); - assert.equal(posts[0].user.id, posts[0].userId); - assert.equal(posts[1].user.id, posts[1].userId); - return adapter.destroyAll(Post); - }); - }); - it('should load belongsTo relations', function () { - return adapter.create(Profile, { - email: 'foo@test.com' - }).then(function (profile) { - return Promise.all([ - adapter.create(User, {name: 'John', profileId: profile.id}).then(function (user) { - return adapter.create(Post, {content: 'foo', userId: user.id}); - }), - adapter.create(User, {name: 'Sally'}).then(function (user) { - return adapter.create(Post, {content: 'bar', userId: user.id}); - }) - ]) - }) - .spread(function (post1, post2) { - return Promise.all([ - adapter.create(Comment, { - content: 'test2', - postId: post1.id, - userId: post1.userId - }), - adapter.create(Comment, { - content: 'test3', - postId: post2.id, - userId: post2.userId - }) - ]); - }) - .then(function () { - return adapter.findAll(Comment, {}, {'with': ['user', 'user.profile', 'post', 'post.user']}); - }) - .then(function (comments) { - assert.isDefined(comments[0].post); - assert.isDefined(comments[0].post.user); - assert.isDefined(comments[0].user); - assert.isDefined(comments[0].user.profile || comments[1].user.profile); - assert.isDefined(comments[1].post); - assert.isDefined(comments[1].post.user); - assert.isDefined(comments[1].user); - }); - }); - it('should load hasMany and belongsTo relations', function () { - return adapter.create(Profile, { - email: 'foo@test.com' - }).then(function (profile) { - return Promise.all([ - adapter.create(User, {name: 'John', profileId: profile.id}).then(function (user) { - return adapter.create(Post, {content: 'foo', userId: user.id}); - }), - adapter.create(User, {name: 'Sally'}).then(function (user) { - return adapter.create(Post, {content: 'bar', userId: user.id}); - }) - ]); - }) - .spread(function (post1, post2) { - return Promise.all([ - adapter.create(Comment, { - content: 'test2', - postId: post1.id, - userId: post1.userId - }), - adapter.create(Comment, { - content: 'test3', - postId: post2.id, - userId: post2.userId - }) - ]); - }) - .then(function () { - return adapter.findAll(Post, {}, {'with': ['user', 'comment', 'comment.user', 'comment.user.profile']}); - }) - .then(function (posts) { - assert.isDefined(posts[0].comments); - assert.isDefined(posts[0].comments[0].user); - assert.isDefined(posts[0].comments[0].user.profile || posts[1].comments[0].user.profile); - assert.isDefined(posts[0].user); - assert.isDefined(posts[1].comments); - assert.isDefined(posts[1].comments[0].user); - assert.isDefined(posts[1].user); - }); - }); -}); diff --git a/test/update.spec.js b/test/update.spec.js deleted file mode 100644 index 3ae94c2..0000000 --- a/test/update.spec.js +++ /dev/null @@ -1,40 +0,0 @@ -describe('DSRedisAdapter#update', function () { - it('should update a user in Redis', function () { - var id; - return adapter.create(User, { name: 'John' }) - .then(function (user) { - id = user.id; - assert.equal(user.name, 'John'); - assert.isString(user.id); - return adapter.find(User, user.id); - }) - .then(function (foundUser) { - assert.equal(foundUser.name, 'John'); - assert.isString(foundUser.id); - assert.deepEqual(foundUser, { id: id, name: 'John' }); - return adapter.update(User, foundUser.id, { name: 'Johnny' }); - }) - .then(function (updatedUser) { - assert.equal(updatedUser.name, 'Johnny'); - assert.isString(updatedUser.id); - assert.deepEqual(updatedUser, { id: id, name: 'Johnny' }); - return adapter.find(User, updatedUser.id); - }) - .then(function (foundUser) { - assert.equal(foundUser.name, 'Johnny'); - assert.isString(foundUser.id); - assert.deepEqual(foundUser, { id: id, name: 'Johnny' }); - return adapter.destroy(User, foundUser.id); - }) - .then(function (user) { - assert.isFalse(!!user); - return adapter.find(User, id); - }) - .then(function () { - throw new Error('Should not have reached here!'); - }) - .catch(function (err) { - assert.equal(err.message, 'Not Found!'); - }); - }); -}); diff --git a/test/updateAll.spec.js b/test/updateAll.spec.js deleted file mode 100644 index 28b0742..0000000 --- a/test/updateAll.spec.js +++ /dev/null @@ -1,45 +0,0 @@ -describe('DSRedisAdapter#updateAll', function () { - it('should update all items', function () { - var id, id2; - return adapter.create(User, { name: 'John', age: 20 }) - .then(function (user) { - id = user.id; - return adapter.create(User, { name: 'John', age: 30 }); - }).then(function (user) { - id2 = user.id; - return adapter.findAll(User, { - name: 'John' - }); - }).then(function (users) { - users.sort(function (a, b) { - return a.age - b.age; - }); - assert.deepEqual(users, [{ id: id, name: 'John', age: 20 }, { id: id2, name: 'John', age: 30 }]); - return adapter.updateAll(User, { - name: 'Johnny' - }, { - name: 'John' - }); - }).then(function (users) { - users.sort(function (a, b) { - return a.age - b.age; - }); - assert.deepEqual(users, [{ id: id, name: 'Johnny', age: 20 }, { id: id2, name: 'Johnny', age: 30 }]); - return adapter.findAll(User, { - name: 'John' - }); - }).then(function (users) { - assert.deepEqual(users, []); - assert.equal(users.length, 0); - return adapter.findAll(User, { - name: 'Johnny' - }); - }).then(function (users) { - users.sort(function (a, b) { - return a.age - b.age; - }); - assert.deepEqual(users, [{ id: id, name: 'Johnny', age: 20 }, { id: id2, name: 'Johnny', age: 30 }]); - return adapter.destroyAll(User); - }); - }); -}); diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..616f88e --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,24 @@ +module.exports = { + entry: './src/index.js', + output: { + filename: './dist/js-data-redis.js', + libraryTarget: 'commonjs2', + library: 'js-data-redis' + }, + externals: [ + 'js-data', + 'redis' + ], + module: { + loaders: [ + { + test: /(src)(.+)\.js$/, + exclude: /node_modules/, + loader: 'babel', + query: { + presets: ['es2015'] + } + } + ] + } +}; \ No newline at end of file