Beispiel #1
0
    LeaderElector.prototype.destroy = function () {
        var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
            return _regeneratorRuntime.wrap(function _callee12$(_context12) {
                while (1) {
                    switch (_context12.prev = _context12.next) {
                        case 0:
                            this.destroyed = true;
                            this.subs.map(function (sub) {
                                return sub.unsubscribe();
                            });
                            this.unloads.map(function (fn) {
                                return fn();
                            });
                            _context12.next = 5;
                            return this.die();

                        case 5:
                            this.bc && this.bc.destroy();

                        case 6:
                        case 'end':
                            return _context12.stop();
                    }
                }
            }, _callee12, this);
        }));

        function destroy() {
            return _ref12.apply(this, arguments);
        }

        return destroy;
    }();
Beispiel #2
0
export var requestIdlePromise = function () {
    var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
        var timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
        return _regeneratorRuntime.wrap(function _callee2$(_context2) {
            while (1) {
                switch (_context2.prev = _context2.next) {
                    case 0:
                        if (!(typeof window === 'object' && window.requestIdleCallback)) {
                            _context2.next = 4;
                            break;
                        }

                        return _context2.abrupt('return', new Promise(function (res) {
                            return window.requestIdleCallback(res, {
                                timeout: timeout
                            });
                        }));

                    case 4:
                        return _context2.abrupt('return', Promise.resolve());

                    case 5:
                    case 'end':
                        return _context2.stop();
                }
            }
        }, _callee2, this);
    }));

    return function requestIdlePromise() {
        return _ref2.apply(this, arguments);
    };
}();
Beispiel #3
0
                mergeMap(function () {
                    var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(results) {
                        var hasChanged;
                        return _regeneratorRuntime.wrap(function _callee5$(_context5) {
                            while (1) {
                                switch (_context5.prev = _context5.next) {
                                    case 0:
                                        _context5.next = 2;
                                        return _this2._ensureEqual();

                                    case 2:
                                        hasChanged = _context5.sent;

                                        if (!hasChanged) {
                                            _context5.next = 7;
                                            break;
                                        }

                                        return _context5.abrupt('return', 'WAITFORNEXTEMIT');

                                    case 7:
                                        return _context5.abrupt('return', results);

                                    case 8:
                                    case 'end':
                                        return _context5.stop();
                                }
                            }
                        }, _callee5, _this2);
                    }));

                    return function (_x2) {
                        return _ref6.apply(this, arguments);
                    };
                }()), filter(function (results) {
Beispiel #4
0
    Socket.prototype.destroy = function () {
        var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
            return _regeneratorRuntime.wrap(function _callee8$(_context8) {
                while (1) {
                    switch (_context8.prev = _context8.next) {
                        case 0:
                            this._destroyed = true;
                            this.subs.map(function (sub) {
                                return sub.unsubscribe();
                            });
                            this.bc && this.bc.destroy();

                        case 3:
                        case 'end':
                            return _context8.stop();
                    }
                }
            }, _callee8, this);
        }));

        function destroy() {
            return _ref8.apply(this, arguments);
        }

        return destroy;
    }();
Beispiel #5
0
    Socket.prototype.write = function () {
        var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(changeEvent) {
            var _this2 = this;

            var socketDoc;
            return _regeneratorRuntime.wrap(function _callee3$(_context3) {
                while (1) {
                    switch (_context3.prev = _context3.next) {
                        case 0:
                            socketDoc = changeEvent.toJSON();

                            delete socketDoc.db;

                            // TODO find a way to getAll on local documents
                            //  socketDoc._id = '_local/' + util.fastUnsecureHash(socketDoc);
                            socketDoc._id = '' + util.fastUnsecureHash(socketDoc) + socketDoc.t;
                            _context3.next = 5;
                            return this.database.lockedRun(function () {
                                return _this2.pouch.put(socketDoc);
                            });

                        case 5:
                            _context3.next = 7;
                            return this._updateLastTimestamp();

                        case 7:
                            _context3.t0 = this.bc;

                            if (!_context3.t0) {
                                _context3.next = 11;
                                break;
                            }

                            _context3.next = 11;
                            return this.bc.write('pull');

                        case 11:
                            return _context3.abrupt('return', true);

                        case 12:
                        case 'end':
                            return _context3.stop();
                    }
                }
            }, _callee3, this);
        }));

        function write(_x) {
            return _ref3.apply(this, arguments);
        }

        return write;
    }();
Beispiel #6
0
var dumpRxDatabase = function () {
    var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
        var _this = this;

        var decrypted = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
        var collections = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
        var json, useCollections;
        return _regeneratorRuntime.wrap(function _callee$(_context) {
            while (1) {
                switch (_context.prev = _context.next) {
                    case 0:
                        json = {
                            name: this.name,
                            instanceToken: this.token,
                            encrypted: false,
                            passwordHash: null,
                            collections: []
                        };


                        if (this.password) {
                            json.passwordHash = util.hash(this.password);
                            if (decrypted) json.encrypted = false;else json.encrypted = true;
                        }

                        useCollections = Object.keys(this.collections).filter(function (colName) {
                            return !collections || collections.includes(colName);
                        }).filter(function (colName) {
                            return colName.charAt(0) !== '_';
                        }).map(function (colName) {
                            return _this.collections[colName];
                        });
                        _context.next = 5;
                        return Promise.all(useCollections.map(function (col) {
                            return col.dump(decrypted);
                        }));

                    case 5:
                        json.collections = _context.sent;
                        return _context.abrupt('return', json);

                    case 7:
                    case 'end':
                        return _context.stop();
                }
            }
        }, _callee, this);
    }));

    return function dumpRxDatabase() {
        return _ref.apply(this, arguments);
    };
}();
Beispiel #7
0
    Socket.prototype.fetchDocs = function () {
        var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
            var _this4 = this;

            var lastTimeDoc, lastTime, result;
            return _regeneratorRuntime.wrap(function _callee5$(_context5) {
                while (1) {
                    switch (_context5.prev = _context5.next) {
                        case 0:
                            _context5.next = 2;
                            return this._getLastTimeDoc();

                        case 2:
                            lastTimeDoc = _context5.sent;
                            lastTime = lastTimeDoc ? lastTimeDoc.time : 0;

                            if (!(this.lastTimestamp >= lastTime)) {
                                _context5.next = 8;
                                break;
                            }

                            return _context5.abrupt('return', []);

                        case 8:
                            this.lastTimestamp = lastTime;
                            _context5.next = 11;
                            return this.database.lockedRun(function () {
                                return _this4.pouch.allDocs({
                                    include_docs: true
                                });
                            });

                        case 11:
                            result = _context5.sent;
                            return _context5.abrupt('return', result.rows.map(function (row) {
                                return row.doc;
                            }));

                        case 13:
                        case 'end':
                            return _context5.stop();
                    }
                }
            }, _callee5, this);
        }));

        function fetchDocs() {
            return _ref5.apply(this, arguments);
        }

        return fetchDocs;
    }();
Beispiel #8
0
var dumpRxCollection = function () {
    var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
        var decrypted = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
        var encrypted, json, query, docs;
        return _regeneratorRuntime.wrap(function _callee3$(_context3) {
            while (1) {
                switch (_context3.prev = _context3.next) {
                    case 0:
                        encrypted = !decrypted;
                        json = {
                            name: this.name,
                            schemaHash: this.schema.hash,
                            encrypted: false,
                            passwordHash: null,
                            docs: []
                        };


                        if (this.database.password && encrypted) {
                            json.passwordHash = util.hash(this.database.password);
                            json.encrypted = true;
                        }

                        query = RxQuery.create('find', {}, this);
                        _context3.next = 6;
                        return this._pouchFind(query, null, encrypted);

                    case 6:
                        docs = _context3.sent;

                        json.docs = docs.map(function (docData) {
                            delete docData._rev;
                            return docData;
                        });
                        return _context3.abrupt('return', json);

                    case 9:
                    case 'end':
                        return _context3.stop();
                }
            }
        }, _callee3, this);
    }));

    return function dumpRxCollection() {
        return _ref3.apply(this, arguments);
    };
}();
Beispiel #9
0
    LeaderElector.prototype.getLeaderObject = function () {
        var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
            var obj, ret;
            return _regeneratorRuntime.wrap(function _callee$(_context) {
                while (1) {
                    switch (_context.prev = _context.next) {
                        case 0:
                            obj = void 0;
                            _context.prev = 1;
                            _context.next = 4;
                            return this.database._adminPouch.get(documentID);

                        case 4:
                            obj = _context.sent;
                            _context.next = 14;
                            break;

                        case 7:
                            _context.prev = 7;
                            _context.t0 = _context['catch'](1);

                            obj = this.createLeaderObject();
                            _context.next = 12;
                            return this.database._adminPouch.put(obj);

                        case 12:
                            ret = _context.sent;

                            obj._rev = ret.rev;

                        case 14:
                            return _context.abrupt('return', obj);

                        case 15:
                        case 'end':
                            return _context.stop();
                    }
                }
            }, _callee, this, [[1, 7]]);
        }));

        function getLeaderObject() {
            return _ref.apply(this, arguments);
        }

        return getLeaderObject;
    }();
Beispiel #10
0
    Socket.prototype._updateLastTimestamp = function () {
        var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
            var done;
            return _regeneratorRuntime.wrap(function _callee4$(_context4) {
                while (1) {
                    switch (_context4.prev = _context4.next) {
                        case 0:
                            // run until sucess
                            done = false;

                        case 1:
                            if (done) {
                                _context4.next = 12;
                                break;
                            }

                            _context4.prev = 2;
                            _context4.next = 5;
                            return this._updateLastTimestampRun();

                        case 5:
                            done = true;
                            _context4.next = 10;
                            break;

                        case 8:
                            _context4.prev = 8;
                            _context4.t0 = _context4['catch'](2);

                        case 10:
                            _context4.next = 1;
                            break;

                        case 12:
                        case 'end':
                            return _context4.stop();
                    }
                }
            }, _callee4, this, [[2, 8]]);
        }));

        function _updateLastTimestamp() {
            return _ref4.apply(this, arguments);
        }

        return _updateLastTimestamp;
    }();
Beispiel #11
0
var importDumpRxDatabase = function () {
    var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(dump) {
        var _this2 = this;

        var missingCollections;
        return _regeneratorRuntime.wrap(function _callee2$(_context2) {
            while (1) {
                switch (_context2.prev = _context2.next) {
                    case 0:
                        /**
                         * collections must be created before the import
                         * because we do not know about the other collection-settings here
                         */
                        missingCollections = dump.collections.filter(function (col) {
                            return !_this2.collections[col.name];
                        }).map(function (col) {
                            return col.name;
                        });

                        if (!(missingCollections.length > 0)) {
                            _context2.next = 3;
                            break;
                        }

                        throw RxError.newRxError('JD1', {
                            missingCollections: missingCollections
                        });

                    case 3:
                        return _context2.abrupt('return', Promise.all(dump.collections.map(function (colDump) {
                            return _this2.collections[colDump.name].importDump(colDump);
                        })));

                    case 4:
                    case 'end':
                        return _context2.stop();
                }
            }
        }, _callee2, this);
    }));

    return function importDumpRxDatabase(_x3) {
        return _ref2.apply(this, arguments);
    };
}();
Beispiel #12
0
var IteratorFn = function () {
  function IteratorFn(arr) {
    _classCallCheck(this, IteratorFn);

    this.arr = arr;
  }

  _createClass(IteratorFn, [{
    key: _Symbol$iterator,
    value: /*#__PURE__*/_regeneratorRuntime.mark(function value() {
      var i;
      return _regeneratorRuntime.wrap(function value$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              console.info('@@@@@@@@@@@@');
              i = 0;

            case 2:
              if (!(i < this.arr.length)) {
                _context2.next = 8;
                break;
              }

              _context2.next = 5;
              return i;

            case 5:
              i++;
              _context2.next = 2;
              break;

            case 8:
            case 'end':
              return _context2.stop();
          }
        }
      }, value, this);
    })
  }]);

  return IteratorFn;
}();
Beispiel #13
0
    Socket.prototype.deleteDoc = function () {
        var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(doc) {
            var _this5 = this;

            var success;
            return _regeneratorRuntime.wrap(function _callee6$(_context6) {
                while (1) {
                    switch (_context6.prev = _context6.next) {
                        case 0:
                            success = true;
                            _context6.prev = 1;
                            _context6.next = 4;
                            return this.database.lockedRun(function () {
                                return _this5.pouch.remove(doc);
                            });

                        case 4:
                            _context6.next = 9;
                            break;

                        case 6:
                            _context6.prev = 6;
                            _context6.t0 = _context6['catch'](1);

                            success = false;

                        case 9:
                            return _context6.abrupt('return', success);

                        case 10:
                        case 'end':
                            return _context6.stop();
                    }
                }
            }, _callee6, this, [[1, 6]]);
        }));

        function deleteDoc(_x2) {
            return _ref6.apply(this, arguments);
        }

        return deleteDoc;
    }();
Beispiel #14
0
    RxQuery.prototype.exec = function () {
        var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
            var changed;
            return _regeneratorRuntime.wrap(function _callee4$(_context4) {
                while (1) {
                    switch (_context4.prev = _context4.next) {
                        case 0:
                            changed = true;

                            // we run _ensureEqual() until we are in sync with the database-state

                        case 1:
                            if (!changed) {
                                _context4.next = 7;
                                break;
                            }

                            _context4.next = 4;
                            return this._ensureEqual();

                        case 4:
                            changed = _context4.sent;
                            _context4.next = 1;
                            break;

                        case 7:
                            return _context4.abrupt('return', this._results$.getValue());

                        case 8:
                        case 'end':
                            return _context4.stop();
                    }
                }
            }, _callee4, this);
        }));

        function exec() {
            return _ref5.apply(this, arguments);
        }

        return exec;
    }();
Beispiel #15
0
export var promiseWait = function () {
    var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
        var ms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
        return _regeneratorRuntime.wrap(function _callee$(_context) {
            while (1) {
                switch (_context.prev = _context.next) {
                    case 0:
                        return _context.abrupt('return', new Promise(function (res) {
                            return setTimeout(res, ms);
                        }));

                    case 1:
                    case 'end':
                        return _context.stop();
                }
            }
        }, _callee, this);
    }));

    return function promiseWait() {
        return _ref.apply(this, arguments);
    };
}();
function asyncFn() {
  var _marked = /*#__PURE__*/_regeneratorRuntime.mark(main);

  var it = null;

  function timer() {
    setTimeout(function () {
      it && it.next({ a: 1, b: 2 });
    }, 2000);
  }

  function main() {
    var res;
    return _regeneratorRuntime.wrap(function main$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return timer();

          case 2:
            res = _context.sent;

            console.info(res);
            return _context.abrupt('return', res);

          case 5:
          case 'end':
            return _context.stop();
        }
      }
    }, _marked, this);
  }

  it = main();
  it.next();
}
Beispiel #17
0
    RxQuery.prototype._setResultData = function () {
        var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(newResultData) {
            var docs, newResultDocs;
            return _regeneratorRuntime.wrap(function _callee3$(_context3) {
                while (1) {
                    switch (_context3.prev = _context3.next) {
                        case 0:
                            this._resultsData = newResultData;

                            _context3.next = 3;
                            return this.collection._createDocuments(this._resultsData);

                        case 3:
                            docs = _context3.sent;
                            newResultDocs = docs;

                            if (this.op === 'findOne') {
                                if (docs.length === 0) newResultDocs = null;else newResultDocs = docs[0];
                            }

                            this._results$.next(newResultDocs);

                        case 7:
                        case 'end':
                            return _context3.stop();
                    }
                }
            }, _callee3, this);
        }));

        function _setResultData(_x) {
            return _ref4.apply(this, arguments);
        }

        return _setResultData;
    }();
Beispiel #18
0
    RxQuery.prototype._ensureEqual = function () {
        var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
            var _this = this;

            var ret;
            return _regeneratorRuntime.wrap(function _callee$(_context) {
                while (1) {
                    switch (_context.prev = _context.next) {
                        case 0:
                            _context.next = 2;
                            return this._ensureEqualQueue.requestIdlePromise();

                        case 2:
                            _context.next = 4;
                            return this._ensureEqualQueue.wrapCall(function () {
                                return _this.__ensureEqual();
                            });

                        case 4:
                            ret = _context.sent;
                            return _context.abrupt('return', ret);

                        case 6:
                        case 'end':
                            return _context.stop();
                    }
                }
            }, _callee, this);
        }));

        function _ensureEqual() {
            return _ref2.apply(this, arguments);
        }

        return _ensureEqual;
    }();
Beispiel #19
0
            return _regeneratorRuntime.wrap(function _callee11$(_context11) {
                while (1) {
                    switch (_context11.prev = _context11.next) {
                        case 0:
                            if (!this.isLeader) {
                                _context11.next = 2;
                                break;
                            }

                            return _context11.abrupt('return', Promise.resolve(true));

                        case 2:
                            if (this.isWaiting) {
                                _context11.next = 14;
                                break;
                            }

                            this.isWaiting = true;

                            // apply now
                            this.applyOnce();

                            fallbackIntervalTime = SIGNAL_TIME * 5;
                            _context11.t0 = this.electionChannel;
                            _context11.next = _context11.t0 === 'broadcast' ? 9 : _context11.t0 === 'socket' ? 11 : 13;
                            break;

                        case 9:
                            // apply when leader dies
                            this.subs.push(this.bc.$.pipe(filter(function (msg) {
                                return msg.type === 'death';
                            })).subscribe(function () {
                                return _this3.applyOnce();
                            }));
                            return _context11.abrupt('break', 13);

                        case 11:
                            // no message via socket, so just use the interval but set it lower
                            fallbackIntervalTime = SIGNAL_TIME * 2;
                            return _context11.abrupt('break', 13);

                        case 13:

                            // apply on interval incase leader dies without notification
                            _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
                                return _regeneratorRuntime.wrap(function _callee10$(_context10) {
                                    while (1) {
                                        switch (_context10.prev = _context10.next) {
                                            case 0:
                                                if (!(!_this3.destroyed && !_this3.isLeader)) {
                                                    _context10.next = 16;
                                                    break;
                                                }

                                                _context10.next = 3;
                                                return util.promiseWait(fallbackIntervalTime);

                                            case 3:
                                                _context10.t0 = _this3.electionChannel;
                                                _context10.next = _context10.t0 === 'broadcast' ? 6 : _context10.t0 === 'socket' ? 9 : 12;
                                                break;

                                            case 6:
                                                _context10.next = 8;
                                                return util.requestIdlePromise(fallbackIntervalTime);

                                            case 8:
                                                return _context10.abrupt('break', 12);

                                            case 9:
                                                _context10.next = 11;
                                                return _this3.database.requestIdlePromise(fallbackIntervalTime);

                                            case 11:
                                                return _context10.abrupt('break', 12);

                                            case 12:
                                                _context10.next = 14;
                                                return _this3.applyOnce();

                                            case 14:
                                                _context10.next = 0;
                                                break;

                                            case 16:
                                            case 'end':
                                                return _context10.stop();
                                        }
                                    }
                                }, _callee10, _this3);
                            }))();

                        case 14:
                            return _context11.abrupt('return', this.becomeLeader$.asObservable().pipe(filter(function (i) {
                                return i.isLeader === true;
                            }), first()).toPromise());

                        case 15:
                        case 'end':
                            return _context11.stop();
                    }
                }
            }, _callee11, this);
Beispiel #20
0
var importDumpRxCollection = function () {
    var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(exportedJSON) {
        var _this3 = this;

        var importFns;
        return _regeneratorRuntime.wrap(function _callee5$(_context5) {
            while (1) {
                switch (_context5.prev = _context5.next) {
                    case 0:
                        if (!(exportedJSON.schemaHash !== this.schema.hash)) {
                            _context5.next = 2;
                            break;
                        }

                        throw RxError.newRxError('JD2', {
                            schemaHash: exportedJSON.schemaHash,
                            own: this.schema.hash
                        });

                    case 2:
                        if (!(exportedJSON.encrypted && exportedJSON.passwordHash !== util.hash(this.database.password))) {
                            _context5.next = 4;
                            break;
                        }

                        throw RxError.newRxError('JD3', {
                            passwordHash: exportedJSON.passwordHash,
                            own: util.hash(this.database.password)
                        });

                    case 4:
                        importFns = exportedJSON.docs
                        // decrypt
                        .map(function (doc) {
                            return _this3._crypter.decrypt(doc);
                        })
                        // validate schema
                        .map(function (doc) {
                            return _this3.schema.validate(doc);
                        })
                        // import
                        .map(function () {
                            var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(doc) {
                                var primary, emitEvent;
                                return _regeneratorRuntime.wrap(function _callee4$(_context4) {
                                    while (1) {
                                        switch (_context4.prev = _context4.next) {
                                            case 0:
                                                _context4.next = 2;
                                                return _this3._pouchPut(doc);

                                            case 2:
                                                primary = doc[_this3.schema.primaryPath];
                                                // emit changeEvents

                                                emitEvent = RxChangeEvent.create('INSERT', _this3.database, _this3, null, doc);

                                                emitEvent.data.doc = primary;
                                                _this3.$emit(emitEvent);

                                            case 6:
                                            case 'end':
                                                return _context4.stop();
                                        }
                                    }
                                }, _callee4, _this3);
                            }));

                            return function (_x6) {
                                return _ref5.apply(this, arguments);
                            };
                        }());
                        return _context5.abrupt('return', Promise.all(importFns));

                    case 6:
                    case 'end':
                        return _context5.stop();
                }
            }
        }, _callee5, this);
    }));

    return function importDumpRxCollection(_x5) {
        return _ref4.apply(this, arguments);
    };
}();
Beispiel #21
0
    LeaderElector.prototype.die = function () {
        var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
            var success, leaderObj;
            return _regeneratorRuntime.wrap(function _callee9$(_context9) {
                while (1) {
                    switch (_context9.prev = _context9.next) {
                        case 0:
                            if (this.isLeader) {
                                _context9.next = 2;
                                break;
                            }

                            return _context9.abrupt('return', false);

                        case 2:
                            if (!this.isDead) {
                                _context9.next = 4;
                                break;
                            }

                            return _context9.abrupt('return', false);

                        case 4:
                            this.isDead = true;
                            this.isLeader = false;

                            if (this.signalLeadership) this.signalLeadership.unsubscribe();

                            // force.write to db
                            _context9.t0 = this.electionChannel;
                            _context9.next = _context9.t0 === 'broadcast' ? 10 : _context9.t0 === 'socket' ? 13 : 30;
                            break;

                        case 10:
                            _context9.next = 12;
                            return this.bc.write('death');

                        case 12:
                            return _context9.abrupt('break', 30);

                        case 13:
                            success = false;

                        case 14:
                            if (success) {
                                _context9.next = 29;
                                break;
                            }

                            _context9.prev = 15;
                            _context9.next = 18;
                            return this.getLeaderObject();

                        case 18:
                            leaderObj = _context9.sent;

                            leaderObj.t = 0;
                            _context9.next = 22;
                            return this.setLeaderObject(leaderObj);

                        case 22:
                            success = true;
                            _context9.next = 27;
                            break;

                        case 25:
                            _context9.prev = 25;
                            _context9.t1 = _context9['catch'](15);

                        case 27:
                            _context9.next = 14;
                            break;

                        case 29:
                            return _context9.abrupt('break', 30);

                        case 30:
                            return _context9.abrupt('return', true);

                        case 31:
                        case 'end':
                            return _context9.stop();
                    }
                }
            }, _callee9, this, [[15, 25]]);
        }));

        function die() {
            return _ref9.apply(this, arguments);
        }

        return die;
    }();
module.exports = _regeneratorRuntime.mark(function callee$0$0(parser) {
  var length, newValue, oldValue, port, protocol, routePacket, server, serverLen, type, typeNumber, valueLength;
  return _regeneratorRuntime.wrap(function callee$0$0$(context$1$0) {
    while (1) switch (context$1$0.prev = context$1$0.next) {
      case 0:
        context$1$0.next = 2;
        return parser.readUInt16LE();

      case 2:
        length = context$1$0.sent;
        context$1$0.next = 5;
        return parser.readUInt8();

      case 5:
        typeNumber = context$1$0.sent;

        type = types[typeNumber];

        if (!type) {
          context$1$0.next = 48;
          break;
        }

        context$1$0.t0 = type.name;
        context$1$0.next = context$1$0.t0 === 'DATABASE' ? 11 : context$1$0.t0 === 'LANGUAGE' ? 11 : context$1$0.t0 === 'CHARSET' ? 11 : context$1$0.t0 === 'PACKET_SIZE' ? 11 : context$1$0.t0 === 'DATABASE_MIRRORING_PARTNER' ? 11 : context$1$0.t0 === 'SQL_COLLATION' ? 16 : context$1$0.t0 === 'BEGIN_TXN' ? 16 : context$1$0.t0 === 'COMMIT_TXN' ? 16 : context$1$0.t0 === 'ROLLBACK_TXN' ? 16 : context$1$0.t0 === 'RESET_CONNECTION' ? 16 : context$1$0.t0 === 'ROUTING_CHANGE' ? 21 : 41;
        break;

      case 11:
        return context$1$0.delegateYield(parser.readBVarChar(), 't1', 12);

      case 12:
        newValue = context$1$0.t1;
        return context$1$0.delegateYield(parser.readBVarChar(), 't2', 14);

      case 14:
        oldValue = context$1$0.t2;
        return context$1$0.abrupt('break', 45);

      case 16:
        return context$1$0.delegateYield(parser.readBVarByte(), 't3', 17);

      case 17:
        newValue = context$1$0.t3;
        return context$1$0.delegateYield(parser.readBVarByte(), 't4', 19);

      case 19:
        oldValue = context$1$0.t4;
        return context$1$0.abrupt('break', 45);

      case 21:
        context$1$0.next = 23;
        return parser.readUInt16LE();

      case 23:
        valueLength = context$1$0.sent;
        context$1$0.next = 26;
        return parser.readBuffer(valueLength);

      case 26:
        routePacket = context$1$0.sent;

        protocol = routePacket.readUInt8(0);

        if (!(protocol !== 0)) {
          context$1$0.next = 30;
          break;
        }

        throw new Error('Unknown protocol byte in routing change event');

      case 30:
        port = routePacket.readUInt16LE(1);
        serverLen = routePacket.readUInt16LE(3);
        server = routePacket.toString('ucs2', 5, 5 + serverLen * 2);
        newValue = {
          protocol: protocol,
          port: port,
          server: server
        };
        context$1$0.next = 36;
        return parser.readUInt16LE();

      case 36:
        valueLength = context$1$0.sent;
        context$1$0.next = 39;
        return parser.readBuffer(valueLength);

      case 39:
        oldValue = context$1$0.sent;
        return context$1$0.abrupt('break', 45);

      case 41:
        console.error("Tedious > Unsupported ENVCHANGE type " + typeNumber);
        context$1$0.next = 44;
        return parser.readBuffer(length - 1);

      case 44:
        return context$1$0.abrupt('return');

      case 45:
        if (type.name === 'PACKET_SIZE') {
          newValue = parseInt(newValue);
          oldValue = parseInt(oldValue);
        }
        context$1$0.next = 52;
        break;

      case 48:
        console.error("Tedious > Unsupported ENVCHANGE type " + typeNumber);
        context$1$0.next = 51;
        return parser.readBuffer(length - 1);

      case 51:
        return context$1$0.abrupt('return');

      case 52:
        return context$1$0.abrupt('return', {
          name: 'ENVCHANGE',
          type: type.name,
          event: type.event,
          oldValue: oldValue,
          newValue: newValue
        });

      case 53:
      case 'end':
        return context$1$0.stop();
    }
  }, callee$0$0, this);
});
Beispiel #23
0
                        .map(function () {
                            var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(doc) {
                                var primary, emitEvent;
                                return _regeneratorRuntime.wrap(function _callee4$(_context4) {
                                    while (1) {
                                        switch (_context4.prev = _context4.next) {
                                            case 0:
                                                _context4.next = 2;
                                                return _this3._pouchPut(doc);

                                            case 2:
                                                primary = doc[_this3.schema.primaryPath];
                                                // emit changeEvents

                                                emitEvent = RxChangeEvent.create('INSERT', _this3.database, _this3, null, doc);

                                                emitEvent.data.doc = primary;
                                                _this3.$emit(emitEvent);

                                            case 6:
                                            case 'end':
                                                return _context4.stop();
                                        }
                                    }
                                }, _callee4, _this3);
                            }));

                            return function (_x6) {
                                return _ref5.apply(this, arguments);
                            };
                        }());
Beispiel #24
0
    LeaderElector.prototype.applySocket = function () {
        var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
            var leaderObj, minTime;
            return _regeneratorRuntime.wrap(function _callee3$(_context3) {
                while (1) {
                    switch (_context3.prev = _context3.next) {
                        case 0:
                            _context3.prev = 0;
                            _context3.next = 3;
                            return this.getLeaderObject();

                        case 3:
                            leaderObj = _context3.sent;
                            minTime = new Date().getTime() - SIGNAL_TIME * 2;

                            if (!(leaderObj.t >= minTime)) {
                                _context3.next = 7;
                                break;
                            }

                            throw RxError.newRxError('LE2');

                        case 7:
                            // write applying to db
                            leaderObj.apply = this.token;
                            leaderObj.t = new Date().getTime();
                            _context3.next = 11;
                            return this.setLeaderObject(leaderObj);

                        case 11:
                            _context3.next = 13;
                            return util.promiseWait(SIGNAL_TIME * 0.5);

                        case 13:
                            _context3.next = 15;
                            return this.getLeaderObject();

                        case 15:
                            leaderObj = _context3.sent;

                            if (!(leaderObj.apply !== this.token)) {
                                _context3.next = 18;
                                break;
                            }

                            throw RxError.newRxError('LE3');

                        case 18:
                            return _context3.abrupt('return', true);

                        case 21:
                            _context3.prev = 21;
                            _context3.t0 = _context3['catch'](0);
                            return _context3.abrupt('return', false);

                        case 24:
                        case 'end':
                            return _context3.stop();
                    }
                }
            }, _callee3, this, [[0, 21]]);
        }));

        function applySocket() {
            return _ref3.apply(this, arguments);
        }

        return applySocket;
    }();
Beispiel #25
0
};
'Hello'.replace(x, 'World'); // ["Hello", "World"]

var myIterable = {};
myIterable[_Symbol$iterator] = /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
  return _regeneratorRuntime.wrap(function _callee$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
          _context.next = 2;
          return 1;

        case 2:
          _context.next = 4;
          return 2;

        case 4:
          _context.next = 6;
          return 3;

        case 6:
        case 'end':
          return _context.stop();
      }
    }
  }, _callee, this);
});
var IteratorFn = function () {
  function IteratorFn(arr) {
    _classCallCheck(this, IteratorFn);
Beispiel #26
0
                            whileNoError = function () {
                                var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
                                    var circles;
                                    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
                                        while (1) {
                                            switch (_context4.prev = _context4.next) {
                                                case 0:
                                                    subs.push(_this.bc.$.pipe(filter(function () {
                                                        return !!_this.isApplying;
                                                    }), filter(function (msg) {
                                                        return msg.t >= applyTime;
                                                    }), filter(function (msg) {
                                                        return msg.type === 'apply';
                                                    }), filter(function (msg) {
                                                        if (msg.data < applyTime || msg.data === applyTime && msg.it > _this.token) return true;else return false;
                                                    }), filter(function () {
                                                        return errors.length < 1;
                                                    })).subscribe(function (msg) {
                                                        return errors.push('other is applying:' + msg.it);
                                                    }));
                                                    subs.push(_this.bc.$.pipe(filter(function () {
                                                        return !!_this.isApplying;
                                                    }), filter(function (msg) {
                                                        return msg.t >= applyTime;
                                                    }), filter(function (msg) {
                                                        return msg.type === 'tell';
                                                    }), filter(function () {
                                                        return errors.length < 1;
                                                    })).subscribe(function (msg) {
                                                        return errors.push('other is leader' + msg.it);
                                                    }));
                                                    subs.push(_this.bc.$.pipe(filter(function () {
                                                        return !!_this.isApplying;
                                                    }), filter(function (msg) {
                                                        return msg.type === 'apply';
                                                    }), filter(function (msg) {
                                                        if (msg.data > applyTime || msg.data === applyTime && msg.it > _this.token) return true;else return false;
                                                    })).subscribe(function () {
                                                        return _this.bc.write('apply', applyTime);
                                                    }));

                                                    circles = 3;

                                                case 4:
                                                    if (!(circles > 0)) {
                                                        _context4.next = 14;
                                                        break;
                                                    }

                                                    circles--;
                                                    _context4.next = 8;
                                                    return _this.bc.write('apply', applyTime);

                                                case 8:
                                                    _context4.next = 10;
                                                    return util.promiseWait(300);

                                                case 10:
                                                    if (!(errors.length > 0)) {
                                                        _context4.next = 12;
                                                        break;
                                                    }

                                                    return _context4.abrupt('return', false);

                                                case 12:
                                                    _context4.next = 4;
                                                    break;

                                                case 14:
                                                    return _context4.abrupt('return', true);

                                                case 15:
                                                case 'end':
                                                    return _context4.stop();
                                            }
                                        }
                                    }, _callee4, _this);
                                }));

                                return function whileNoError() {
                                    return _ref5.apply(this, arguments);
                                };
                            }();
module.exports = _regeneratorRuntime.mark(function callee$0$0(parser, columnsMetaData, options) {
  var column, columnMetaData, columns, i, len, value;
  return _regeneratorRuntime.wrap(function callee$0$0$(context$1$0) {
    while (1) switch (context$1$0.prev = context$1$0.next) {
      case 0:
        columns = options.useColumnNames ? {} : [];
        i = 0, len = columnsMetaData.length;

      case 2:
        if (!(i < len)) {
          context$1$0.next = 11;
          break;
        }

        columnMetaData = columnsMetaData[i];
        return context$1$0.delegateYield(valueParse(parser, columnMetaData, options), 't0', 5);

      case 5:
        value = context$1$0.t0;

        column = {
          value: value,
          metadata: columnMetaData
        };
        if (options.useColumnNames) {
          if (columns[columnMetaData.colName] == null) {
            columns[columnMetaData.colName] = column;
          }
        } else {
          columns.push(column);
        }

      case 8:
        i++;
        context$1$0.next = 2;
        break;

      case 11:
        return context$1$0.abrupt('return', {
          name: 'ROW',
          event: 'row',
          columns: columns
        });

      case 12:
      case 'end':
        return context$1$0.stop();
    }
  }, callee$0$0, this);
});
Beispiel #28
0
    LeaderElector.prototype.leaderSignal = function () {
        var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
            var success, leaderObj;
            return _regeneratorRuntime.wrap(function _callee6$(_context6) {
                while (1) {
                    switch (_context6.prev = _context6.next) {
                        case 0:
                            if (!this.destroyed) {
                                _context6.next = 2;
                                break;
                            }

                            return _context6.abrupt('return');

                        case 2:
                            if (!this.leaderSignal_run) {
                                _context6.next = 4;
                                break;
                            }

                            return _context6.abrupt('return');

                        case 4:
                            this.leaderSignal_run = true;
                            _context6.t0 = this.electionChannel;
                            _context6.next = _context6.t0 === 'broadcast' ? 8 : _context6.t0 === 'socket' ? 11 : 31;
                            break;

                        case 8:
                            _context6.next = 10;
                            return this.bc.write('tell');

                        case 10:
                            return _context6.abrupt('break', 31);

                        case 11:
                            success = false;

                        case 12:
                            if (success) {
                                _context6.next = 30;
                                break;
                            }

                            _context6.prev = 13;
                            _context6.next = 16;
                            return this.getLeaderObject();

                        case 16:
                            leaderObj = _context6.sent;

                            leaderObj.is = this.token;
                            leaderObj.apply = this.token;
                            leaderObj.t = new Date().getTime();
                            _context6.next = 22;
                            return this.setLeaderObject(leaderObj);

                        case 22:
                            success = true;
                            _context6.next = 28;
                            break;

                        case 25:
                            _context6.prev = 25;
                            _context6.t1 = _context6['catch'](13);

                            console.dir(_context6.t1);

                        case 28:
                            _context6.next = 12;
                            break;

                        case 30:
                            return _context6.abrupt('break', 31);

                        case 31:
                            this.leaderSignal_run = false;
                            return _context6.abrupt('return');

                        case 33:
                        case 'end':
                            return _context6.stop();
                    }
                }
            }, _callee6, this, [[13, 25]]);
        }));

        function leaderSignal() {
            return _ref6.apply(this, arguments);
        }

        return leaderSignal;
    }();
Beispiel #29
0
import _Array$from from 'babel-runtime/core-js/array/from';
import _toConsumableArray from 'babel-runtime/helpers/toConsumableArray';
import _regeneratorRuntime from 'babel-runtime/regenerator';
var go = /*#__PURE__*/_regeneratorRuntime.mark(function go() {
  return _regeneratorRuntime.wrap(function go$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
          _context.next = 2;
          return 1;

        case 2:
          _context.next = 4;
          return 2;

        case 4:
          _context.next = 6;
          return 3;

        case 6:
        case 'end':
          return _context.stop();
      }
    }
  }, go, this);
});

var arr = [].concat(_toConsumableArray(go()));

var obj = { '1': 123, '2': 666, length: 3 };
Beispiel #30
0
            return _regeneratorRuntime.wrap(function _callee8$(_context8) {
                while (1) {
                    switch (_context8.prev = _context8.next) {
                        case 0:
                            if (!this.isDead) {
                                _context8.next = 2;
                                break;
                            }

                            return _context8.abrupt('return', false);

                        case 2:
                            if (!this.isLeader) {
                                _context8.next = 4;
                                break;
                            }

                            return _context8.abrupt('return', false);

                        case 4:
                            this.isLeader = true;

                            this.becomeLeader$.next({
                                isLeader: true
                            });

                            _context8.next = 8;
                            return this.leaderSignal();

                        case 8:
                            _context8.t0 = this.electionChannel;
                            _context8.next = _context8.t0 === 'broadcast' ? 11 : _context8.t0 === 'socket' ? 14 : 16;
                            break;

                        case 11:
                            this.signalLeadership = this.bc.$.pipe(filter(function () {
                                return !!_this2.isLeader;
                            }),
                            // BUGFIX: avoids loop-hole when for whatever reason 2 are leader
                            filter(function (msg) {
                                return msg.type !== 'tell';
                            })).subscribe(function () {
                                return _this2.leaderSignal();
                            });
                            this.subs.push(this.signalLeadership);
                            return _context8.abrupt('break', 16);

                        case 14:
                            _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
                                return _regeneratorRuntime.wrap(function _callee7$(_context7) {
                                    while (1) {
                                        switch (_context7.prev = _context7.next) {
                                            case 0:
                                                if (_this2.destroyed) {
                                                    _context7.next = 9;
                                                    break;
                                                }

                                                _context7.next = 3;
                                                return util.promiseWait(SIGNAL_TIME);

                                            case 3:
                                                if (_this2.isLeader) {
                                                    _context7.next = 5;
                                                    break;
                                                }

                                                return _context7.abrupt('return');

                                            case 5:
                                                _context7.next = 7;
                                                return _this2.leaderSignal();

                                            case 7:
                                                _context7.next = 0;
                                                break;

                                            case 9:
                                            case 'end':
                                                return _context7.stop();
                                        }
                                    }
                                }, _callee7, _this2);
                            }))();
                            return _context8.abrupt('break', 16);

                        case 16:

                            // this.die() on unload
                            this.unloads.push(unload.add(function () {
                                _this2.bc && _this2.bc.write('death');
                                _this2.die();
                            }));
                            return _context8.abrupt('return', true);

                        case 18:
                        case 'end':
                            return _context8.stop();
                    }
                }
            }, _callee8, this);