Comparing version 0.1.5 to 0.1.6
@@ -88,11 +88,11 @@ 'use strict'; | ||
for (var docId in docs) { | ||
var docData = docs[docId]; | ||
var serverVersion = _RemoteDoc2.default.prototype.getVersionFromOps(docData._ops); | ||
var doc = this.collection.getDoc(docData._id); | ||
var ops = docs[docId]; | ||
var serverVersion = _RemoteDoc2.default.prototype.getVersionFromOps(ops); | ||
var doc = this.collection.getDoc(docId); | ||
if (doc) { | ||
doc.applyOps(docData._ops); | ||
doc.applyOps(ops); | ||
doc.distillOps(); | ||
doc.serverVersion = serverVersion; | ||
} else { | ||
doc = this.collection.attach(docData._id, docData._ops, serverVersion); | ||
doc = this.collection.attach(docId, ops, serverVersion); | ||
} | ||
@@ -99,0 +99,0 @@ doc.save(); |
@@ -175,2 +175,3 @@ 'use strict'; | ||
// TODO: remove collection if was not able to read from it | ||
// Resolve anyway | ||
@@ -177,0 +178,0 @@ resolve(); |
@@ -11,2 +11,10 @@ 'use strict'; | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _getIterator2 = require('babel-runtime/core-js/get-iterator'); | ||
@@ -16,5 +24,5 @@ | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
@@ -112,69 +120,189 @@ var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
key: 'fillLocalCollectionsFromClientStorage', | ||
value: function fillLocalCollectionsFromClientStorage() { | ||
if (!this.model.storage) return _promise2.default.resolve(); | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
var collectionNames, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, collectionName, collection; | ||
var promises = []; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (this.model.storage) { | ||
_context.next = 2; | ||
break; | ||
} | ||
try { | ||
for (var _iterator = (0, _getIterator3.default)(this.model.storage.collectionNames), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var collectionName = _step.value; | ||
return _context.abrupt('return'); | ||
if (!(0, _util.isLocalCollection)(collectionName)) continue; | ||
var collection = this.getOrCreateCollection(collectionName); | ||
promises.push(collection.fillFromClientStorage()); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
case 2: | ||
_context.next = 4; | ||
return this.model.storage.getCollectionNames(); | ||
case 4: | ||
collectionNames = _context.sent; | ||
_iteratorNormalCompletion = true; | ||
_didIteratorError = false; | ||
_iteratorError = undefined; | ||
_context.prev = 8; | ||
_iterator = (0, _getIterator3.default)(collectionNames); | ||
case 10: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context.next = 20; | ||
break; | ||
} | ||
collectionName = _step.value; | ||
if ((0, _util.isLocalCollection)(collectionName)) { | ||
_context.next = 14; | ||
break; | ||
} | ||
return _context.abrupt('continue', 17); | ||
case 14: | ||
collection = this.getOrCreateCollection(collectionName); | ||
_context.next = 17; | ||
return collection.fillFromClientStorage(); | ||
case 17: | ||
_iteratorNormalCompletion = true; | ||
_context.next = 10; | ||
break; | ||
case 20: | ||
_context.next = 26; | ||
break; | ||
case 22: | ||
_context.prev = 22; | ||
_context.t0 = _context['catch'](8); | ||
_didIteratorError = true; | ||
_iteratorError = _context.t0; | ||
case 26: | ||
_context.prev = 26; | ||
_context.prev = 27; | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
case 29: | ||
_context.prev = 29; | ||
if (!_didIteratorError) { | ||
_context.next = 32; | ||
break; | ||
} | ||
throw _iteratorError; | ||
case 32: | ||
return _context.finish(29); | ||
case 33: | ||
return _context.finish(26); | ||
case 34: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
return _promise2.default.all(promises); | ||
} | ||
}, _callee, this, [[8, 22, 26, 34], [27,, 29, 33]]); | ||
})); | ||
return function fillLocalCollectionsFromClientStorage() { | ||
return ref.apply(this, arguments); | ||
}; | ||
}() | ||
}, { | ||
key: 'fillFromClientStorage', | ||
value: function fillFromClientStorage() { | ||
if (!this.model.storage) return _promise2.default.resolve(); | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2() { | ||
var collectionNames, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _collectionName2, _collection; | ||
var promises = []; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (this.model.storage) { | ||
_context2.next = 2; | ||
break; | ||
} | ||
try { | ||
for (var _iterator2 = (0, _getIterator3.default)(this.model.storage.collectionNames), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var collectionName = _step2.value; | ||
return _context2.abrupt('return'); | ||
var collection = this.getOrCreateCollection(collectionName); | ||
promises.push(collection.fillFromClientStorage()); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
case 2: | ||
_context2.next = 4; | ||
return this.model.storage.getCollectionNames(); | ||
case 4: | ||
collectionNames = _context2.sent; | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_context2.prev = 8; | ||
_iterator2 = (0, _getIterator3.default)(collectionNames); | ||
case 10: | ||
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) { | ||
_context2.next = 18; | ||
break; | ||
} | ||
_collectionName2 = _step2.value; | ||
_collection = this.getOrCreateCollection(_collectionName2); | ||
_context2.next = 15; | ||
return _collection.fillFromClientStorage(); | ||
case 15: | ||
_iteratorNormalCompletion2 = true; | ||
_context2.next = 10; | ||
break; | ||
case 18: | ||
_context2.next = 24; | ||
break; | ||
case 20: | ||
_context2.prev = 20; | ||
_context2.t0 = _context2['catch'](8); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context2.t0; | ||
case 24: | ||
_context2.prev = 24; | ||
_context2.prev = 25; | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
case 27: | ||
_context2.prev = 27; | ||
if (!_didIteratorError2) { | ||
_context2.next = 30; | ||
break; | ||
} | ||
throw _iteratorError2; | ||
case 30: | ||
return _context2.finish(27); | ||
case 31: | ||
return _context2.finish(24); | ||
case 32: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
return _promise2.default.all(promises); | ||
} | ||
}, _callee2, this, [[8, 20, 24, 32], [25,, 27, 31]]); | ||
})); | ||
return function fillFromClientStorage() { | ||
return ref.apply(this, arguments); | ||
}; | ||
}() | ||
}, { | ||
@@ -201,6 +329,6 @@ key: 'mergeDataFromServer', | ||
for (var collectionName in this.data) { | ||
if ((0, _util.isLocalCollection)(collectionName)) continue; | ||
var collection = this.data[collectionName]; | ||
data[collectionName] = collection.getSyncData(); | ||
for (var _collectionName3 in this.data) { | ||
if ((0, _util.isLocalCollection)(_collectionName3)) continue; | ||
var _collection2 = this.data[_collectionName3]; | ||
data[_collectionName3] = _collection2.getSyncData(); | ||
} | ||
@@ -215,5 +343,5 @@ | ||
for (var collectionName in this.data) { | ||
var collection = this.data[collectionName]; | ||
data[collectionName] = collection.bundle(); | ||
for (var _collectionName4 in this.data) { | ||
var _collection3 = this.data[_collectionName4]; | ||
data[_collectionName4] = _collection3.bundle(); | ||
} | ||
@@ -226,6 +354,6 @@ | ||
value: function unbundle(data) { | ||
for (var collectionName in data) { | ||
var collection = this.getOrCreateCollection(collectionName); | ||
var collectionBundle = data[collectionName]; | ||
collection.unbundle(collectionBundle); | ||
for (var _collectionName5 in data) { | ||
var _collection4 = this.getOrCreateCollection(_collectionName5); | ||
var collectionBundle = data[_collectionName5]; | ||
_collection4.unbundle(collectionBundle); | ||
} | ||
@@ -232,0 +360,0 @@ } |
@@ -131,2 +131,4 @@ 'use strict'; | ||
// undefined op | ||
if (!op) continue; | ||
// dublicate ops | ||
@@ -141,2 +143,3 @@ if (ids[op.id]) continue; | ||
// TODO: make possible to recreate doc after del? | ||
if (op.type === 'del' && !op.field) { | ||
@@ -388,2 +391,3 @@ distilledOps = [op]; | ||
// TODO: sort version? | ||
// versions.sort().reverse() | ||
@@ -390,0 +394,0 @@ return versions.join('|'); |
@@ -11,2 +11,6 @@ 'use strict'; | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _from = require('babel-runtime/core-js/array/from'); | ||
@@ -16,9 +20,9 @@ | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
@@ -33,14 +37,2 @@ var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _MongoQueries2 = require('./MongoQueries'); | ||
var _MongoQueries3 = _interopRequireDefault(_MongoQueries2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -50,8 +42,5 @@ | ||
var dbName = 'amelisa'; | ||
var IndexedDbStorage = function (_MongoQueries) { | ||
(0, _inherits3.default)(IndexedDbStorage, _MongoQueries); | ||
var IndexedDbStorage = function () { | ||
function IndexedDbStorage() { | ||
@@ -62,69 +51,112 @@ var collectionNames = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(IndexedDbStorage).call(this)); | ||
_this.collectionNames = collectionNames; | ||
_this.version = version; | ||
return _this; | ||
this.collectionNames = collectionNames; | ||
this.version = version; | ||
} | ||
(0, _createClass3.default)(IndexedDbStorage, [{ | ||
key: 'getCollectionNames', | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt('return', this.collectionNames); | ||
case 1: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return function getCollectionNames() { | ||
return ref.apply(this, arguments); | ||
}; | ||
}() | ||
}, { | ||
key: 'getExistingCollectionNames', | ||
value: function getExistingCollectionNames() { | ||
return (0, _from2.default)(this.db.objectStoreNames); | ||
} | ||
}, { | ||
key: 'init', | ||
value: function init() { | ||
var _this2 = this; | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2() { | ||
var _this = this; | ||
return new _promise2.default(function (resolve, reject) { | ||
var request = window.indexedDB.open(dbName, _this2.version); | ||
request.onsuccess = function (event) { | ||
debug('onsuccess'); | ||
_this2.db = event.target.result; | ||
resolve(_this2); | ||
}; | ||
request.onupgradeneeded = function (event) { | ||
debug('onupgradeneeded', event); | ||
var db = event.target.result; | ||
db.onerror = function (event) { | ||
debug('onerror upgrage', event); | ||
}; | ||
var prevCollectionNames = (0, _from2.default)(db.objectStoreNames); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
return _context2.abrupt('return', new _promise2.default(function (resolve, reject) { | ||
var request = window.indexedDB.open(dbName, _this.version); | ||
request.onsuccess = function (event) { | ||
debug('onsuccess'); | ||
_this.db = event.target.result; | ||
var existingCollectionNames = _this.getExistingCollectionNames(); | ||
_this.existingCollectionNames = existingCollectionNames; | ||
resolve(_this); | ||
}; | ||
request.onupgradeneeded = function (event) { | ||
debug('onupgradeneeded', event); | ||
_this.db = event.target.result; | ||
var existingCollectionNames = _this.getExistingCollectionNames(); | ||
_this.existingCollectionNames = existingCollectionNames; | ||
_this.db.onerror = function (event) { | ||
debug('onerror upgrage', event); | ||
}; | ||
try { | ||
for (var _iterator = (0, _getIterator3.default)(_this2.collectionNames), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var collectionName = _step.value; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
debug('collectionName', collectionName); | ||
if (prevCollectionNames.indexOf(collectionName) > -1) continue; | ||
try { | ||
for (var _iterator = (0, _getIterator3.default)(_this.collectionNames), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var collectionName = _step.value; | ||
var objectStore = db.createObjectStore(collectionName, { keyPath: '_id' }); | ||
objectStore.transaction.oncomplete = function (e) { | ||
debug('oncomplete', e); | ||
// TODO: handle it | ||
}; | ||
objectStore.transaction.onerror = function (e) { | ||
debug('onerror', e); | ||
}; | ||
debug('collectionName', collectionName); | ||
if (existingCollectionNames.indexOf(collectionName) > -1) continue; | ||
var objectStore = _this.db.createObjectStore(collectionName, { keyPath: '_id' }); | ||
objectStore.transaction.oncomplete = function (e) { | ||
debug('oncomplete', e); | ||
// TODO: handle it | ||
}; | ||
objectStore.transaction.onerror = function (e) { | ||
debug('onerror', e); | ||
}; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
}; | ||
request.onerror = function (event) { | ||
debug('onerror', event); | ||
reject(event.target.webkitErrorMessage || event.target.error); | ||
}; | ||
})); | ||
case 1: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
}; | ||
request.onerror = function (event) { | ||
debug('onerror', event); | ||
reject(event.target.webkitErrorMessage || event.target.error); | ||
}; | ||
}); | ||
} | ||
}, _callee2, this); | ||
})); | ||
return function init() { | ||
return ref.apply(this, arguments); | ||
}; | ||
}() | ||
}, { | ||
@@ -139,128 +171,234 @@ key: 'getObjectStore', | ||
} | ||
}, { | ||
key: 'getDocById', | ||
value: function getDocById(collectionName, docId) { | ||
var _this3 = this; | ||
return new _promise2.default(function (resolve, reject) { | ||
var objectStore = _this3.getObjectStore(collectionName, 'readonly'); | ||
var request = objectStore.get(docId); | ||
request.onsuccess = function (event) { | ||
resolve(event.target.result); | ||
}; | ||
request.onerror = function (event) { | ||
reject(event.target.webkitErrorMessage || event.target.error); | ||
}; | ||
}); | ||
} | ||
// async getDocById (collectionName, docId) { | ||
// return new Promise((resolve, reject) => { | ||
// let objectStore = this.getObjectStore(collectionName, 'readonly') | ||
// let request = objectStore.get(docId) | ||
// request.onsuccess = (event) => { | ||
// resolve(event.target.result) | ||
// } | ||
// request.onerror = (event) => { | ||
// reject(event.target.webkitErrorMessage || event.target.error) | ||
// } | ||
// }) | ||
// } | ||
}, { | ||
key: 'getAllDocs', | ||
value: function getAllDocs(collectionName) { | ||
return this.getDocsByQuery(collectionName, _MongoQueries3.default.allSelector); | ||
} | ||
}, { | ||
key: 'getDocsByQuery', | ||
value: function getDocsByQuery(collectionName, expression) { | ||
var _this4 = this; | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(collectionName) { | ||
var _this2 = this; | ||
return new _promise2.default(function (resolve, reject) { | ||
var allDocs = []; | ||
var objectStore = _this4.getObjectStore(collectionName, 'readonly'); | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
return _context3.abrupt('return', new _promise2.default(function (resolve, reject) { | ||
var docs = []; | ||
var objectStore = _this2.getObjectStore(collectionName, 'readonly'); | ||
var request = objectStore.openCursor(); | ||
request.onsuccess = function (event) { | ||
var cursor = event.target.result; | ||
if (cursor) { | ||
allDocs.push(cursor.value); | ||
cursor.continue(); | ||
} else { | ||
var docs = _this4.getQueryResultFromArray(allDocs, expression); | ||
resolve(docs); | ||
var request = objectStore.openCursor(); | ||
request.onsuccess = function (event) { | ||
var cursor = event.target.result; | ||
if (cursor) { | ||
docs.push(cursor.value); | ||
cursor.continue(); | ||
} else { | ||
resolve(docs); | ||
} | ||
}; | ||
request.onerror = function (event) { | ||
reject(event.target.webkitErrorMessage || event.target.error); | ||
}; | ||
})); | ||
case 1: | ||
case 'end': | ||
return _context3.stop(); | ||
} | ||
} | ||
}; | ||
request.onerror = function (event) { | ||
reject(event.target.webkitErrorMessage || event.target.error); | ||
}; | ||
}); | ||
} | ||
}, _callee3, this); | ||
})); | ||
return function getAllDocs(_x2) { | ||
return ref.apply(this, arguments); | ||
}; | ||
}() | ||
// getAllDocs (collectionName) { | ||
// return this.getDocsByQuery(collectionName, MongoQueries.allSelector) | ||
// } | ||
// async getDocsByQuery (collectionName, expression) { | ||
// return new Promise((resolve, reject) => { | ||
// let allDocs = [] | ||
// let objectStore = this.getObjectStore(collectionName, 'readonly') | ||
// | ||
// let request = objectStore.openCursor() | ||
// request.onsuccess = (event) => { | ||
// let cursor = event.target.result | ||
// if (cursor) { | ||
// allDocs.push(cursor.value) | ||
// cursor.continue() | ||
// } else { | ||
// let docs = this.getQueryResultFromArray(allDocs, expression) | ||
// resolve(docs) | ||
// } | ||
// } | ||
// request.onerror = (event) => { | ||
// reject(event.target.webkitErrorMessage || event.target.error) | ||
// } | ||
// }) | ||
// } | ||
}, { | ||
key: 'clearCollection', | ||
value: function clearCollection(collectionName) { | ||
var _this5 = this; | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(collectionName) { | ||
var _this3 = this; | ||
return new _promise2.default(function (resolve, reject) { | ||
var objectStore = _this5.getObjectStore(collectionName, 'readwrite'); | ||
var request = objectStore.clear(); | ||
request.onsuccess = function (event) { | ||
resolve(); | ||
}; | ||
request.onerror = function (event) { | ||
reject(event.target.webkitErrorMessage || event.target.error); | ||
}; | ||
}); | ||
} | ||
return _regenerator2.default.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
return _context4.abrupt('return', new _promise2.default(function (resolve, reject) { | ||
var objectStore = _this3.getObjectStore(collectionName, 'readwrite'); | ||
var request = objectStore.clear(); | ||
request.onsuccess = function (event) { | ||
resolve(); | ||
}; | ||
request.onerror = function (event) { | ||
reject(event.target.webkitErrorMessage || event.target.error); | ||
}; | ||
})); | ||
case 1: | ||
case 'end': | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4, this); | ||
})); | ||
return function clearCollection(_x3) { | ||
return ref.apply(this, arguments); | ||
}; | ||
}() | ||
}, { | ||
key: 'clear', | ||
value: function clear() { | ||
var promises = []; | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5() { | ||
var promises, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, collectionName; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
return _regenerator2.default.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
promises = []; | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_context5.prev = 4; | ||
try { | ||
for (var _iterator2 = (0, _getIterator3.default)(this.collectionNames), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var collectionName = _step2.value; | ||
promises.push(this.clearCollection(collectionName)); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
for (_iterator2 = (0, _getIterator3.default)(this.collectionNames); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
collectionName = _step2.value; | ||
promises.push(this.clearCollection(collectionName)); | ||
} | ||
_context5.next = 12; | ||
break; | ||
case 8: | ||
_context5.prev = 8; | ||
_context5.t0 = _context5['catch'](4); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context5.t0; | ||
case 12: | ||
_context5.prev = 12; | ||
_context5.prev = 13; | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
case 15: | ||
_context5.prev = 15; | ||
if (!_didIteratorError2) { | ||
_context5.next = 18; | ||
break; | ||
} | ||
throw _iteratorError2; | ||
case 18: | ||
return _context5.finish(15); | ||
case 19: | ||
return _context5.finish(12); | ||
case 20: | ||
return _context5.abrupt('return', _promise2.default.all(promises)); | ||
case 21: | ||
case 'end': | ||
return _context5.stop(); | ||
} | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
return _promise2.default.all(promises); | ||
} | ||
}, _callee5, this, [[4, 8, 12, 20], [13,, 15, 19]]); | ||
})); | ||
return function clear() { | ||
return ref.apply(this, arguments); | ||
}; | ||
}() | ||
}, { | ||
key: 'saveDoc', | ||
value: function saveDoc(collectionName, docId, state, serverVersion, version, ops) { | ||
var _this6 = this; | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(collectionName, docId, state, serverVersion, version, ops) { | ||
var _this4 = this; | ||
var doc = { | ||
_id: docId, | ||
_ops: ops, | ||
_v: version, | ||
_sv: serverVersion | ||
}; | ||
var doc; | ||
return _regenerator2.default.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
doc = { | ||
_id: docId, | ||
_ops: ops, | ||
// _v: version, | ||
_sv: serverVersion | ||
}; | ||
for (var key in state) { | ||
doc[key] = state[key]; | ||
} | ||
// for (let key in state) { | ||
// doc[key] = state[key] | ||
// } | ||
return new _promise2.default(function (resolve, reject) { | ||
var objectStore = _this6.getObjectStore(collectionName, 'readwrite'); | ||
var updateRequest = objectStore.put(doc); | ||
updateRequest.onsuccess = function (event) { | ||
resolve(); | ||
}; | ||
updateRequest.onerror = function (event) { | ||
reject(event.target.webkitErrorMessage || event.target.error); | ||
}; | ||
}); | ||
} | ||
return _context6.abrupt('return', new _promise2.default(function (resolve, reject) { | ||
var objectStore = _this4.getObjectStore(collectionName, 'readwrite'); | ||
var updateRequest = objectStore.put(doc); | ||
updateRequest.onsuccess = function (event) { | ||
resolve(); | ||
}; | ||
updateRequest.onerror = function (event) { | ||
reject(event.target.webkitErrorMessage || event.target.error); | ||
}; | ||
})); | ||
case 2: | ||
case 'end': | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee6, this); | ||
})); | ||
return function saveDoc(_x4, _x5, _x6, _x7, _x8, _x9) { | ||
return ref.apply(this, arguments); | ||
}; | ||
}() | ||
}]); | ||
return IndexedDbStorage; | ||
}(_MongoQueries3.default); | ||
}(); | ||
exports.default = IndexedDbStorage; | ||
module.exports = exports['default']; |
170
lib/Model.js
@@ -27,2 +27,6 @@ 'use strict'; | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
@@ -32,6 +36,2 @@ | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
@@ -106,3 +106,3 @@ | ||
debug('open'); | ||
_this.setOnline(); | ||
if (!_this.online) _this.setOnline(); | ||
}); | ||
@@ -112,3 +112,3 @@ | ||
debug('close'); | ||
_this.setOffline(); | ||
if (_this.online) _this.setOffline(); | ||
}); | ||
@@ -118,2 +118,3 @@ | ||
console.error('Connection error', err); | ||
if (_this.online) _this.setOffline(); | ||
}); | ||
@@ -130,17 +131,39 @@ | ||
key: 'ready', | ||
value: function ready() { | ||
var _this2 = this; | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
var _this2 = this; | ||
if (this.ready) return _promise2.default.resolve(); | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!this.ready) { | ||
_context.next = 2; | ||
break; | ||
} | ||
return new _promise2.default(function (resolve, reject) { | ||
_this2.once('ready', function () { | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
return _context.abrupt('return'); | ||
case 2: | ||
return _context.abrupt('return', new _promise2.default(function (resolve, reject) { | ||
_this2.once('ready', function () { | ||
resolve(); | ||
}); | ||
})); | ||
case 3: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return function ready() { | ||
return ref.apply(this, arguments); | ||
}; | ||
}() | ||
}, { | ||
key: 'fetch', | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2() { | ||
for (var _len = arguments.length, rawSubscribes = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -151,19 +174,19 @@ rawSubscribes[_key] = arguments[_key]; | ||
var subscription; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
subscription = new _Subscription2.default(rawSubscribes, this.collectionSet, this.querySet); | ||
_context.next = 3; | ||
_context2.next = 3; | ||
return subscription.fetch(); | ||
case 3: | ||
return _context.abrupt('return', subscription); | ||
return _context2.abrupt('return', subscription); | ||
case 4: | ||
case 'end': | ||
return _context.stop(); | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
}, _callee2, this); | ||
})); | ||
@@ -177,3 +200,3 @@ return function fetch(_x2) { | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2() { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3() { | ||
for (var _len2 = arguments.length, rawSubscribes = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
@@ -184,27 +207,27 @@ rawSubscribes[_key2] = arguments[_key2]; | ||
var subscription; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
if (!this.options.fetchOnly) { | ||
_context2.next = 2; | ||
_context3.next = 2; | ||
break; | ||
} | ||
return _context2.abrupt('return', this.fetch.apply(this, rawSubscribes)); | ||
return _context3.abrupt('return', this.fetch.apply(this, rawSubscribes)); | ||
case 2: | ||
subscription = new _Subscription2.default(rawSubscribes, this.collectionSet, this.querySet); | ||
_context2.next = 5; | ||
_context3.next = 5; | ||
return subscription.subscribe(); | ||
case 5: | ||
return _context2.abrupt('return', subscription); | ||
return _context3.abrupt('return', subscription); | ||
case 6: | ||
case 'end': | ||
return _context2.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
}, _callee3, this); | ||
})); | ||
@@ -257,2 +280,4 @@ return function subscribe(_x3) { | ||
var docs = message.docs; | ||
var ops = message.ops; | ||
var ackId = message.ackId; | ||
var error = message.error; | ||
@@ -268,3 +293,33 @@ | ||
} | ||
if (ackId) { | ||
callbacks = this.callbacks[ackId]; | ||
if (callbacks) { | ||
delete this.callbacks[ackId]; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = (0, _getIterator3.default)(callbacks), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var callback = _step.value; | ||
callback(); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
debug('onMessage', this.source, type, id, collectionName, docId, expression, !!callbacks, value, diffs, docs); | ||
@@ -275,9 +330,9 @@ | ||
if (callbacks && !error) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator = (0, _getIterator3.default)(callbacks), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var callback = _step.value; | ||
for (var _iterator2 = (0, _getIterator3.default)(callbacks), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var callback = _step2.value; | ||
@@ -287,12 +342,12 @@ callback(null, value); | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
@@ -308,9 +363,9 @@ } | ||
if (callbacks) { | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
try { | ||
for (var _iterator2 = (0, _getIterator3.default)(callbacks), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var callback = _step2.value; | ||
for (var _iterator3 = (0, _getIterator3.default)(callbacks), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var callback = _step3.value; | ||
@@ -324,12 +379,12 @@ if (error) { | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
} | ||
@@ -341,6 +396,13 @@ } | ||
case 'fetch': | ||
doc = this.collectionSet.getDoc(collectionName, docId); | ||
if (doc) { | ||
doc.onFetched(version, ops); | ||
} | ||
break; | ||
case 'sub': | ||
doc = this.collectionSet.getDoc(collectionName, docId); | ||
if (doc) { | ||
doc.onSubscribed(version); | ||
doc.onSubscribed(version, ops); | ||
} | ||
@@ -347,0 +409,0 @@ break; |
@@ -53,2 +53,4 @@ 'use strict'; | ||
value: function sendOp(op, channel) { | ||
var _this2 = this; | ||
// debug('sendOp', op) | ||
@@ -59,5 +61,9 @@ | ||
if ((op.type === 'q' || op.type === 'qdiff') && this.isDocs) { | ||
var projectedDocs = []; | ||
var projectedDocs = {}; | ||
for (var docId in op.docs) { | ||
projectedDocs.push(this.projection.projectDoc(op.docs[docId])); | ||
var ops = op.docs[docId]; | ||
var projectedOps = ops.map(function (docOp) { | ||
return _this2.projection.projectOp(docOp); | ||
}); | ||
projectedDocs[docId] = projectedOps; | ||
} | ||
@@ -64,0 +70,0 @@ op.docs = projectedDocs; |
@@ -128,11 +128,27 @@ 'use strict'; | ||
this.context.model.subscribe(rawSubscribes).then(function (subscription) { | ||
_this2.subscription = subscription; | ||
if (_util.isServer && this.props.onFetch && !this.state.hasResults) { | ||
// eslint-disable-line | ||
var promise = new _promise2.default(function (resolve, reject) { | ||
_this2.context.model.subscribe(rawSubscribes).then(function (subscription) { | ||
_this2.subscription = subscription; | ||
subscription.on('change', function () { | ||
_this2.refresh(); | ||
var data = _this2.getPropsFromSubscription(subscription); | ||
resolve(data); | ||
}); | ||
}); | ||
_this2.refresh(); | ||
}); | ||
this.props.onFetch(promise); // eslint-disable-line | ||
} else { | ||
this.context.model.subscribe(rawSubscribes).then(function (subscription) { | ||
_this2.subscription = subscription; | ||
if (!_util.isServer) { | ||
subscription.on('change', function () { | ||
_this2.refresh(); | ||
}); | ||
} | ||
_this2.refresh(); | ||
}); | ||
} | ||
} | ||
@@ -139,0 +155,0 @@ }, { |
@@ -21,3 +21,3 @@ 'use strict'; | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
var source, projectionHashes; | ||
var storage, source, projectionHashes; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
@@ -27,2 +27,17 @@ while (1) { | ||
case 0: | ||
storage = new _SqliteStorage2.default(['_app', '_session']); | ||
model.storage = storage; | ||
_context.next = 4; | ||
return storage.init(); | ||
case 4: | ||
_context.next = 6; | ||
return model.collectionSet.fillFromClientStorage(); | ||
case 6: | ||
model.set('_session.online', false); | ||
source = model.get('_app.source'); | ||
@@ -42,3 +57,3 @@ | ||
case 4: | ||
case 11: | ||
case 'end': | ||
@@ -67,2 +82,6 @@ return _context.stop(); | ||
var _SqliteStorage = require('./SqliteStorage'); | ||
var _SqliteStorage2 = _interopRequireDefault(_SqliteStorage); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -82,5 +101,5 @@ | ||
// TODO: reconnection interval should be random | ||
var wsOptions = { | ||
automaticOpen: false, | ||
reconnectOnError: true, | ||
reconnectInterval: 3000 | ||
@@ -94,2 +113,4 @@ }; | ||
window.model = model; | ||
var initPromise = new _promise2.default(function (resolve, reject) { | ||
@@ -96,0 +117,0 @@ initModel().then(function () { |
@@ -31,14 +31,9 @@ 'use strict'; | ||
case 0: | ||
if (!_util.isBrowser) { | ||
_context.next = 3; | ||
break; | ||
} | ||
_context.next = 3; | ||
_context.next = 2; | ||
return (0, _util.onDomReady)(); | ||
case 3: | ||
case 2: | ||
// unbundle _app.clientStorage, _app.collectionNames, _app.version and _app.newProjectionHashes | ||
if (_util.isBrowser) model.unbundleLocalData(); | ||
model.unbundleLocalData(); | ||
_ref = model.get('_app') || {}; | ||
@@ -50,3 +45,3 @@ clientStorage = _ref.clientStorage; | ||
if (!clientStorage) { | ||
_context.next = 20; | ||
_context.next = 19; | ||
break; | ||
@@ -59,21 +54,24 @@ } | ||
_context.next = 13; | ||
_context.next = 12; | ||
return storage.init(); | ||
case 13: | ||
_context.next = 15; | ||
case 12: | ||
_context.next = 14; | ||
return model.collectionSet.fillLocalCollectionsFromClientStorage(); | ||
case 15: | ||
case 14: | ||
// clear collections in storage, where projections have changed | ||
newProjectionHashes = model.get('_app.newProjectionHashes'); | ||
_context.next = 18; | ||
_context.next = 17; | ||
return model.onProjections(newProjectionHashes); | ||
case 18: | ||
_context.next = 20; | ||
case 17: | ||
_context.next = 19; | ||
return model.collectionSet.fillFromClientStorage(); | ||
case 20: | ||
case 19: | ||
model.set('_session.online', false); | ||
source = model.get('_app.source'); | ||
@@ -93,3 +91,3 @@ | ||
if (_util.isBrowser) model.unbundleData(); | ||
model.unbundleData(); | ||
@@ -138,7 +136,7 @@ case 25: | ||
if (!channel) { | ||
var wsUrl = options.wsUrl || 'ws://' + (_util.isBrowser ? window.location.host : 'localhost:3000'); | ||
var wsUrl = options.wsUrl || 'ws://' + window.location.host; | ||
// TODO: reconnection interval should be random | ||
var wsOptions = { | ||
automaticOpen: false, | ||
reconnectOnError: true, | ||
reconnectInterval: 3000 | ||
@@ -152,3 +150,3 @@ }; | ||
if (_util.isBrowser) window.model = model; | ||
window.model = model; | ||
@@ -155,0 +153,0 @@ var initPromise = new _promise2.default(function (resolve, reject) { |
@@ -103,6 +103,8 @@ 'use strict'; | ||
}, { | ||
key: 'onSubscribed', | ||
value: function onSubscribed(serverVersion) { | ||
debug('subscribed', serverVersion); | ||
key: 'onFetched', | ||
value: function onFetched(serverVersion, ops) { | ||
debug('fetched', serverVersion); | ||
this.serverVersion = serverVersion; | ||
this.applyOps(ops); | ||
this.emit('change'); | ||
this.save(); | ||
@@ -137,2 +139,37 @@ | ||
}, { | ||
key: 'onSubscribed', | ||
value: function onSubscribed(serverVersion, ops) { | ||
debug('subscribed', serverVersion); | ||
this.serverVersion = serverVersion; | ||
this.applyOps(ops); | ||
this.emit('change'); | ||
this.save(); | ||
var opsToSend = this.getOpsToSend(serverVersion); | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = (0, _getIterator3.default)(opsToSend), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var op = _step2.value; | ||
this.model.send(op); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'onOp', | ||
@@ -172,9 +209,9 @@ value: function onOp(op) { | ||
value: function sendAllOps() { | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
try { | ||
for (var _iterator2 = (0, _getIterator3.default)(this.ops), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var op = _step2.value; | ||
for (var _iterator3 = (0, _getIterator3.default)(this.ops), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var op = _step3.value; | ||
@@ -184,12 +221,12 @@ this.model.send(op); | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
} | ||
@@ -196,0 +233,0 @@ } |
@@ -194,8 +194,10 @@ 'use strict'; | ||
value: function fetch(channel, version, opId) { | ||
this.sendOpsToChannel(channel, version); | ||
var op = { | ||
id: opId, | ||
type: 'ack' | ||
type: 'fetch', | ||
collectionName: this.collectionName, | ||
docId: this.docId, | ||
version: this.version(), | ||
ops: this.getOpsToSend(version) | ||
}; | ||
if (opId) op.ackId = opId; | ||
this.sendOp(op, channel); | ||
@@ -217,4 +219,2 @@ | ||
this.sendOpsToChannel(channel, version); | ||
var op = { | ||
@@ -224,13 +224,7 @@ type: 'sub', | ||
docId: this.docId, | ||
version: this.version() | ||
version: this.version(), | ||
ops: this.getOpsToSend(version) | ||
}; | ||
if (opId) op.ackId = opId; | ||
this.sendOp(op, channel); | ||
if (opId) { | ||
op = { | ||
id: opId, | ||
type: 'ack' | ||
}; | ||
this.sendOp(op, channel); | ||
} | ||
} | ||
@@ -237,0 +231,0 @@ }, { |
@@ -172,3 +172,3 @@ 'use strict'; | ||
key: 'sendNotDocsQuerySnapshotToChannel', | ||
value: function sendNotDocsQuerySnapshotToChannel(channel) { | ||
value: function sendNotDocsQuerySnapshotToChannel(channel, opId) { | ||
var op = { | ||
@@ -179,3 +179,4 @@ type: 'q', | ||
version: this.version(), | ||
value: this.data | ||
value: this.data, | ||
ackId: opId | ||
}; | ||
@@ -188,3 +189,3 @@ | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(channel) { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(channel, opId) { | ||
var docs, op; | ||
@@ -202,3 +203,4 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
ids: this.getIds(), | ||
docs: docs | ||
docs: docs, | ||
ackId: opId | ||
}; | ||
@@ -219,3 +221,3 @@ | ||
})); | ||
return function sendDocsQuerySnapshotToChannel(_x) { | ||
return function sendDocsQuerySnapshotToChannel(_x, _x2) { | ||
return ref.apply(this, arguments); | ||
@@ -237,3 +239,3 @@ }; | ||
docs[doc._id] = doc; | ||
docs[doc._id] = doc._ops; | ||
} | ||
@@ -356,3 +358,3 @@ } catch (err) { | ||
docs[docId] = docMap[docId]; | ||
docs[docId] = docMap[docId]._ops; | ||
} | ||
@@ -454,3 +456,3 @@ _context2.next = 42; | ||
})); | ||
return function sendDiffQueryToChannel(_x2, _x3) { | ||
return function sendDiffQueryToChannel(_x3, _x4) { | ||
return ref.apply(this, arguments); | ||
@@ -506,3 +508,3 @@ }; | ||
})); | ||
return function subscribeDocs(_x4, _x5) { | ||
return function subscribeDocs(_x5, _x6) { | ||
return ref.apply(this, arguments); | ||
@@ -515,3 +517,2 @@ }; | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(channel, opId) { | ||
var op; | ||
return _regenerator2.default.wrap(function _callee4$(_context4) { | ||
@@ -522,15 +523,9 @@ while (1) { | ||
_context4.next = 2; | ||
return this.sendQuery(channel); | ||
return this.sendQuery(channel, opId); | ||
case 2: | ||
op = { | ||
id: opId, | ||
type: 'ack' | ||
}; | ||
this.sendOp(op, channel); | ||
this.maybeUnattach(); | ||
case 5: | ||
case 3: | ||
case 'end': | ||
@@ -542,3 +537,3 @@ return _context4.stop(); | ||
})); | ||
return function fetch(_x6, _x7) { | ||
return function fetch(_x7, _x8) { | ||
return ref.apply(this, arguments); | ||
@@ -551,3 +546,2 @@ }; | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(channel, opId) { | ||
var op; | ||
return _regenerator2.default.wrap(function _callee5$(_context5) { | ||
@@ -568,14 +562,5 @@ while (1) { | ||
_context5.next = 5; | ||
return this.sendQuery(channel); | ||
return this.sendQuery(channel, opId); | ||
case 5: | ||
op = { | ||
id: opId, | ||
type: 'ack' | ||
}; | ||
this.sendOp(op, channel); | ||
case 7: | ||
case 'end': | ||
@@ -587,3 +572,3 @@ return _context5.stop(); | ||
})); | ||
return function subscribe(_x8, _x9) { | ||
return function subscribe(_x9, _x10) { | ||
return ref.apply(this, arguments); | ||
@@ -595,3 +580,3 @@ }; | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(channel) { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(channel, opId) { | ||
return _regenerator2.default.wrap(function _callee6$(_context6) { | ||
@@ -607,3 +592,3 @@ while (1) { | ||
_context6.next = 3; | ||
return this.sendDocsQuerySnapshotToChannel(channel); | ||
return this.sendDocsQuerySnapshotToChannel(channel, opId); | ||
@@ -616,3 +601,3 @@ case 3: | ||
_context6.next = 7; | ||
return this.sendNotDocsQuerySnapshotToChannel(channel); | ||
return this.sendNotDocsQuerySnapshotToChannel(channel, opId); | ||
@@ -626,3 +611,3 @@ case 7: | ||
})); | ||
return function sendQuery(_x10) { | ||
return function sendQuery(_x11, _x12) { | ||
return ref.apply(this, arguments); | ||
@@ -629,0 +614,0 @@ }; |
@@ -57,5 +57,2 @@ 'use strict'; | ||
var debounceTimeout = 0; // let debug = require('debug')('Subscription') | ||
var Subscription = function (_EventEmitter) { | ||
@@ -176,9 +173,3 @@ (0, _inherits3.default)(Subscription, _EventEmitter); | ||
value: function onChange() { | ||
var _this4 = this; | ||
if (this.timeout) clearTimeout(this.timeout); | ||
this.timeout = setTimeout(function () { | ||
_this4.emit('change'); | ||
delete _this4.timeout; | ||
}, debounceTimeout); | ||
this.emit('change'); | ||
} | ||
@@ -201,5 +192,6 @@ }, { | ||
return Subscription; | ||
}(_events.EventEmitter); | ||
}(_events.EventEmitter); // let debug = require('debug')('Subscription') | ||
exports.default = Subscription; | ||
module.exports = exports['default']; |
@@ -27,3 +27,2 @@ 'use strict'; | ||
var isServer = process.title && process.title !== 'browser'; | ||
var isBrowser = process.title === 'browser'; | ||
@@ -109,3 +108,2 @@ var dbFields = { | ||
isServer: isServer, | ||
isBrowser: isBrowser, | ||
shallowClone: shallowClone, | ||
@@ -112,0 +110,0 @@ serverRequire: serverRequire, |
{ | ||
"name": "amelisa", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "", | ||
@@ -27,3 +27,3 @@ "main": "lib/index.js", | ||
"node-libs-browser": "^0.5.2", | ||
"reconnectable-websocket": "^0.1.2", | ||
"reconnectable-websocket": "^0.1.4", | ||
"redis-url": "^1.2.1", | ||
@@ -30,0 +30,0 @@ "superagent": "^1.4.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
303761
7380
5
57