Skip to content

Commit

Permalink
Stable Version 1.0.2.
Browse files Browse the repository at this point in the history
Convert to ES6.
  • Loading branch information
jmdobry committed Mar 10, 2015
1 parent db2de67 commit e1e9086
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 169 deletions.
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"node": false,
"browser": true,
"es5": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
##### 1.0.2 - 10 March 2015

Converted to ES6.

##### 1.0.1 - 25 February 2015

Updated dependencies
Expand Down
38 changes: 32 additions & 6 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* js-data-redis
* http://github.com/js-data/js-data-redis
*
* Copyright (c) 2014 Jason Dobry <http://www.js-data.io/js-data-redis>
* Copyright (c) 2014-2015 Jason Dobry <http://www.js-data.io/docs/dsredisadapter>
* Licensed under the MIT license. <https://github.com/js-data/js-data-redis/blob/master/LICENSE>
*/
module.exports = function (grunt) {
Expand All @@ -18,10 +18,6 @@ module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: pkg,
jshint: {
all: ['Gruntfile.js', 'src/**/*.js', 'test/*.js'],
jshintrc: '.jshintrc'
},
watch: {
dist: {
files: ['src/**/*.js'],
Expand All @@ -40,14 +36,44 @@ module.exports = function (grunt) {
},
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',
'js-data',
'js-data-schema',
'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('n', ['mochaTest']);

grunt.registerTask('test', ['build', 'n']);
grunt.registerTask('build', [
'jshint'
'webpack'
]);
grunt.registerTask('go', ['build', 'watch:dist']);
grunt.registerTask('default', ['build']);
Expand Down
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<img src="https://raw.githubusercontent.com/js-data/js-data/master/js-data.png" alt="js-data logo" title="js-data" align="right" width="64" height="64" />

## js-data-redis [![NPM version](https://badge.fury.io/js/js-data-redis.png)](http://badge.fury.io/js/js-data-redis)
## 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)

Redis adapter for [js-data](http://www.js-data.io/).

## API Documentation
### API Documentation
[DSRedisAdapter](http://www.js-data.io/docs/dsredisadapter)

## Project Status
### Project Status

| Branch | Master |
| ------ | ------ |
| NPM | [![NPM](https://nodei.co/npm/js-data-redis.png?downloads=true&stars=true)](https://nodei.co/npm/js-data-redis/) |
| Build Status | [![Build Status](https://travis-ci.org/js-data/js-data-redis.png?branch=master)](https://travis-ci.org/js-data/js-data-redis) |
| Code Climate | [![Code Climate](https://codeclimate.com/github/js-data/js-data-redis.png)](https://codeclimate.com/github/js-data/js-data-redis) |
| Dependency Status | [![Dependency Status](https://gemnasium.com/js-data/js-data-redis.png)](https://gemnasium.com/js-data/js-data-redis) |
| Coverage | [![Coverage Status](https://coveralls.io/repos/js-data/js-data-redis/badge.png?branch=master)](https://coveralls.io/r/js-data/js-data-redis?branch=master) |
__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)

## Quick Start
__Status:__

[![Dependency Status](https://img.shields.io/gemnasium/js-data/js-data-redis.svg?style=flat-square)](https://gemnasium.com/js-data/js-data-redis) [![Coverage Status](https://img.shields.io/coveralls/js-data/js-data-redis/master.svg?style=flat-square)](https://coveralls.io/r/js-data/js-data-redis?branch=master) [![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`.

```js
Expand All @@ -33,16 +35,16 @@ store.registerAdapter('redis', adapter, { default: true });
// "store" will now use the Redis adapter for all async operations
```

## Changelog
### Changelog
[CHANGELOG.md](https://github.com/js-data/js-data-redis/blob/master/CHANGELOG.md)

## Community
### Community
- [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!
- [GitHub](https://github.com/js-data/js-data-redis) - View the source code for js-data.
- [Contributing Guide](https://github.com/js-data/js-data-redis/blob/master/CONTRIBUTING.md)

## Contributing
### Contributing

First, feel free to contact me with questions. [Mailing List](https://groups.io/org/groupsio/jsdata). [Issues](https://github.com/js-data/js-data-redis/issues).

Expand All @@ -55,7 +57,7 @@ First, feel free to contact me with questions. [Mailing List](https://groups.io/
1. Write your code, including relevant documentation and tests
1. Submit a PR and we'll review

## License
### License

The MIT License (MIT)

Expand Down
233 changes: 233 additions & 0 deletions dist/js-data-redis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

/******/ // The require function
/******/ function __webpack_require__(moduleId) {

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = true;

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

var _classCallCheck = function (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 underscore = __webpack_require__(3);
var guid = __webpack_require__(4);
var P = JSData.DSUtils.Promise;
var deepMixIn = JSData.DSUtils.deepMixIn;
var forEach = JSData.DSUtils.forEach;
var emptyStore = new JSData.DS();
var filter = emptyStore.defaults.defaultFilter;

function getPath(resourceConfig) {
if (resourceConfig) {
return resourceConfig.table || underscore(resourceConfig.name);
}
}

var Defaults = function Defaults() {
_classCallCheck(this, Defaults);
};

var DSRedisAdapter = (function () {
function DSRedisAdapter(options) {
_classCallCheck(this, DSRedisAdapter);

options = options || {};
this.defaults = new Defaults();
deepMixIn(this.defaults, options);
this.client = redis.createClient(this.defaults);
}

_createClass(DSRedisAdapter, {
getIds: {
value: function getIds(resourceConfig) {
var _this = this;
return new P(function (resolve, reject) {
return _this.client.SMEMBERS(getPath(resourceConfig), function (err, ids) {
return err ? reject(err) : resolve(ids);
});
});
}
},
GET: {
value: function GET(path) {
var _this = this;
return new P(function (resolve, reject) {
return _this.client.GET(path, function (err, value) {
return err ? reject(err) : resolve(JSON.parse(value));
});
});
}
},
find: {
value: function find(resourceConfig, id) {
var _this = this;
return new P(function (resolve, reject) {
return _this.client.GET("" + getPath(resourceConfig) + "-" + id, function (err, item) {
if (err) {
reject(err);
} else if (!item) {
reject(new Error("Not Found!"));
} else {
resolve(JSON.parse(item));
}
});
});
}
},
findAll: {
value: function findAll(resourceConfig, params) {
var _this = this;
return _this.getIds(resourceConfig).then(function (ids) {
var tasks = [];
var path = getPath(resourceConfig);
forEach(ids, function (id) {
return tasks.push(_this.GET("" + path + "-" + id));
});
return P.all(tasks);
}).then(function (items) {
return filter.call(emptyStore, items, resourceConfig.name, params, { allowSimpleWhere: true });
});
}
},
create: {
value: function create(resourceConfig, attrs) {
var _this = this;
return new P(function (resolve, reject) {
attrs[resourceConfig.idAttribute] = attrs[resourceConfig.idAttribute] || guid();
return _this.client.multi().SET("" + getPath(resourceConfig) + "-" + attrs[resourceConfig.idAttribute], JSON.stringify(attrs)).SADD(getPath(resourceConfig), attrs[resourceConfig.idAttribute]).exec(function (err) {
return err ? reject(err) : resolve(attrs);
});
});
}
},
update: {
value: function update(resourceConfig, id, attrs) {
var _this = this;
return new P(function (resolve, reject) {
var path = "" + getPath(resourceConfig) + "-" + id;
return _this.client.GET(path, function (err, value) {
if (err) {
reject(err);
} else if (!value) {
reject(new Error("Not Found!"));
} else {
value = JSON.parse(value);
deepMixIn(value, attrs);
_this.client.SET(path, JSON.stringify(value), function (err) {
return err ? reject(err) : resolve(value);
});
}
});
});
}
},
updateAll: {
value: function updateAll(resourceConfig, attrs, params) {
var _this = this;
return _this.findAll(resourceConfig, params).then(function (items) {
var tasks = [];
forEach(items, function (item) {
return tasks.push(_this.update(resourceConfig, item[resourceConfig.idAttribute], attrs));
});
return P.all(tasks);
});
}
},
destroy: {
value: function destroy(resourceConfig, id) {
var _this = this;
return new P(function (resolve, reject) {
var path = getPath(resourceConfig);
return _this.client.multi().DEL("" + path + "-" + id).SREM(path, id).exec(function (err) {
return err ? reject(err) : resolve();
});
});
}
},
destroyAll: {
value: function destroyAll(resourceConfig, params) {
var _this = this;
return _this.findAll(resourceConfig, params).then(function (items) {
var tasks = [];
forEach(items, function (item) {
return tasks.push(_this.destroy(resourceConfig, item[resourceConfig.idAttribute]));
});
return P.all(tasks);
});
}
}
});

return DSRedisAdapter;
})();

module.exports = DSRedisAdapter;

/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

module.exports = require("js-data");

/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {

module.exports = require("redis");

/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {

module.exports = require("mout/string/underscore");

/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {

module.exports = require("mout/random/guid");

/***/ }
/******/ ]);
4 changes: 3 additions & 1 deletion mocha.start.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ for (var key in globals) {
test.globals(testGlobals);

beforeEach(function () {
store = new JSData.DS();
store = new JSData.DS({
log: false
});
adapter = new DSRedisAdapter();
DSUtils = JSData.DSUtils;
DSErrors = JSData.DSErrors;
Expand Down
Loading

0 comments on commit e1e9086

Please sign in to comment.