1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | 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; }; }();
|
8 |
|
9 | var _events = require('events');
|
10 |
|
11 | var _events2 = _interopRequireDefault(_events);
|
12 |
|
13 | var _bluebird = require('bluebird');
|
14 |
|
15 | var _bluebird2 = _interopRequireDefault(_bluebird);
|
16 |
|
17 | var _commands = require('./commands');
|
18 |
|
19 | var commands = _interopRequireWildcard(_commands);
|
20 |
|
21 | var _command2 = require('./command');
|
22 |
|
23 | var _command3 = _interopRequireDefault(_command2);
|
24 |
|
25 | var _data = require('./data');
|
26 |
|
27 | var _data2 = _interopRequireDefault(_data);
|
28 |
|
29 | var _expires = require('./expires');
|
30 |
|
31 | var _expires2 = _interopRequireDefault(_expires);
|
32 |
|
33 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
34 |
|
35 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
36 |
|
37 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
38 |
|
39 | function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
|
40 |
|
41 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
42 |
|
43 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
44 |
|
45 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
46 |
|
47 | var RedisMock = function (_EventEmitter) {
|
48 | _inherits(RedisMock, _EventEmitter);
|
49 |
|
50 | function RedisMock() {
|
51 | var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
52 | _ref$data = _ref.data,
|
53 | data = _ref$data === undefined ? {} : _ref$data;
|
54 |
|
55 | _classCallCheck(this, RedisMock);
|
56 |
|
57 | var _this = _possibleConstructorReturn(this, (RedisMock.__proto__ || Object.getPrototypeOf(RedisMock)).call(this));
|
58 |
|
59 | _this.channels = {};
|
60 | _this.batch = [];
|
61 |
|
62 | _this.expires = (0, _expires2.default)();
|
63 |
|
64 | _this.data = (0, _data2.default)(_this.expires, data);
|
65 |
|
66 | Object.keys(commands).forEach(function (command) {
|
67 | _this[command] = (0, _command3.default)(commands[command].bind(_this));
|
68 | });
|
69 |
|
70 | process.nextTick(function () {
|
71 | _this.emit('connect');
|
72 | _this.emit('ready');
|
73 | });
|
74 | return _this;
|
75 | }
|
76 |
|
77 | _createClass(RedisMock, [{
|
78 | key: 'multi',
|
79 | value: function multi(batch) {
|
80 | var _this2 = this;
|
81 |
|
82 | this.batch = batch.map(function (_ref2) {
|
83 | var _command;
|
84 |
|
85 | var _ref3 = _toArray(_ref2),
|
86 | command = _ref3[0],
|
87 | options = _ref3.slice(1);
|
88 |
|
89 | return (_command = _this2[command]).bind.apply(_command, [_this2].concat(_toConsumableArray(options)));
|
90 | });
|
91 |
|
92 | return this;
|
93 | }
|
94 | }, {
|
95 | key: 'exec',
|
96 | value: function exec(callback) {
|
97 | return _bluebird2.default.all(this.batch.map(function (promise) {
|
98 | return promise();
|
99 | })).then(function (results) {
|
100 | return results.map(function (result) {
|
101 | return [null, result];
|
102 | });
|
103 | }).nodeify(callback);
|
104 | }
|
105 | }]);
|
106 |
|
107 | return RedisMock;
|
108 | }(_events2.default);
|
109 |
|
110 | exports.default = RedisMock; |
\ | No newline at end of file |