Comparing version 0.5.3 to 0.5.4
@@ -10,2 +10,6 @@ 'use strict'; | ||
var _map2 = require('fast.js/map'); | ||
var _map3 = _interopRequireDefault(_map2); | ||
var _forEach = require('fast.js/forEach'); | ||
@@ -15,6 +19,2 @@ | ||
var _map2 = require('fast.js/map'); | ||
var _map3 = _interopRequireDefault(_map2); | ||
var _checkTypes = require('check-types'); | ||
@@ -28,10 +28,2 @@ | ||
var _invariant = require('invariant'); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _DocumentModifier = require('./DocumentModifier'); | ||
var _DocumentModifier2 = _interopRequireDefault(_DocumentModifier); | ||
var _IndexManager = require('./IndexManager'); | ||
@@ -49,2 +41,6 @@ | ||
var _CollectionDelegate = require('./CollectionDelegate'); | ||
var _CollectionDelegate2 = _interopRequireDefault(_CollectionDelegate); | ||
var _Random = require('./Random'); | ||
@@ -68,2 +64,3 @@ | ||
var _defaultRandomGenerator = new _Random2.default(); | ||
var _defaultDelegate = _CollectionDelegate2.default; | ||
var _defaultCursorClass = _CursorObservable2.default; | ||
@@ -90,7 +87,6 @@ var _defaultStorageManager = _StorageManager2.default; | ||
_this._methods = {}; | ||
_this._modelName = name; | ||
// Init managers | ||
var storageManagerClass = options.storageManager || _defaultStorageManager; | ||
var delegateClass = options.delegate || _defaultDelegate; | ||
_this.cursorClass = options.cursorClass || _defaultCursorClass; | ||
@@ -100,2 +96,3 @@ _this.indexManager = new _IndexManager2.default(_this, options); | ||
_this.idGenerator = options.idGenerator || _defaultIdGenerator; | ||
_this.delegate = new delegateClass(_this, options); | ||
return _this; | ||
@@ -117,2 +114,13 @@ } | ||
/** | ||
* Return all currently indexed ids | ||
* @return {Array} | ||
*/ | ||
}, { | ||
key: 'getIndexIds', | ||
value: function getIndexIds() { | ||
return this.indexes._id.getAll(); | ||
} | ||
/** | ||
* Ensures index by delegating to IndexManager. | ||
@@ -154,8 +162,5 @@ * @param {String} key | ||
// Add to indexes and persist | ||
return this.indexManager.indexDocument(doc).then(function () { | ||
return _this2.storageManager.persist(doc._id, doc).then(function () { | ||
_this2.emit('insert', doc, null, randomId); | ||
return doc._id; | ||
}); | ||
return this.delegate.insert(doc, options).then(function (docId) { | ||
_this2.emit('insert', doc, null, randomId); | ||
return docId; | ||
}); | ||
@@ -165,5 +170,6 @@ } | ||
/** | ||
* Insert all documents in given list | ||
* Just a sugar for mulpitle inserts. Wrap all inserts | ||
* with a single Promise and return it. | ||
* @param {Array} docs | ||
* @param {Boolean} quiet | ||
* @param {Object} options | ||
* @return {Promise} | ||
@@ -174,5 +180,7 @@ */ | ||
key: 'insertAll', | ||
value: function insertAll(docs, options) { | ||
value: function insertAll(docs) { | ||
var _this3 = this; | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
return Promise.all((0, _map3.default)(docs, function (d) { | ||
@@ -199,3 +207,2 @@ return _this3.insert(d, options); | ||
// Fire sync event | ||
if (!options.quiet) { | ||
@@ -205,20 +212,7 @@ this.emit('sync:remove', query, options); | ||
// Remove locally | ||
return this.find(query).exec().then(function (docs) { | ||
(0, _invariant2.default)(docs.length <= 1 || options.multi, 'remove(..): multi removing is not enabled by options.multi'); | ||
var removeStorgePromises = (0, _map3.default)(docs, function (d) { | ||
return _this4.storageManager.delete(d._id); | ||
return this.delegate.remove(query, options).then(function (removedDocs) { | ||
(0, _forEach2.default)(removedDocs, function (d) { | ||
return _this4.emit('remove', null, d); | ||
}); | ||
var removeIndexPromises = (0, _map3.default)(docs, function (d) { | ||
return _this4.indexManager.deindexDocument(d); | ||
}); | ||
var allPromises = removeStorgePromises.concat(removeIndexPromises); | ||
return Promise.all(allPromises).then(function () { | ||
(0, _forEach2.default)(docs, function (d) { | ||
return _this4.emit('remove', null, d); | ||
}); | ||
return docs; | ||
}); | ||
return removedDocs; | ||
}); | ||
@@ -244,5 +238,2 @@ } | ||
options.upsert = false; | ||
// Fire sync event | ||
if (!options.quiet) { | ||
@@ -252,29 +243,7 @@ this.emit('sync:update', query, modifier, options); | ||
// Update locally | ||
return new _DocumentModifier2.default(this, query).modify(modifier, options).then(function (result) { | ||
var original = result.original; | ||
var updated = result.updated; | ||
updated = (0, _map3.default)(updated, function (x) { | ||
return _this5.create(x); | ||
return this.delegate.update(query, modifier, options).then(function (res) { | ||
(0, _forEach2.default)(res.updated, function (d, i) { | ||
_this5.emit('update', d, res.original[i]); | ||
}); | ||
var updateStorgePromises = (0, _map3.default)(updated, function (d) { | ||
return _this5.storageManager.persist(d._id, d); | ||
}); | ||
var updateIndexPromises = (0, _map3.default)(updated, function (d, i) { | ||
return _this5.indexManager.reindexDocument(original[i], d); | ||
}); | ||
var allPromises = updateStorgePromises.concat(updateIndexPromises); | ||
return Promise.all(allPromises).then(function () { | ||
(0, _forEach2.default)(updated, function (d, i) { | ||
_this5.emit('update', d, original[i]); | ||
}); | ||
return { | ||
modified: updated.length, | ||
original: original, | ||
updated: updated | ||
}; | ||
}); | ||
return res; | ||
}); | ||
@@ -284,13 +253,2 @@ } | ||
/** | ||
* Return all currently indexed ids | ||
* @return {Array} | ||
*/ | ||
}, { | ||
key: 'getIndexIds', | ||
value: function getIndexIds() { | ||
return this.indexes._id.getAll(); | ||
} | ||
/** | ||
* Make a cursor with given query and return. | ||
@@ -310,3 +268,3 @@ * By default all documents clonned before passed | ||
return new this.cursorClass(this, query, options); | ||
return this.delegate.find(query, options); | ||
} | ||
@@ -325,8 +283,6 @@ | ||
key: 'findOne', | ||
value: function findOne(query, sortObj) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
value: function findOne(query) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
return this.find(query, options).sort(sortObj).limit(1).aggregate(function (docs) { | ||
return docs[0]; | ||
}); | ||
return this.delegate.findOne(query, options); | ||
} | ||
@@ -349,6 +305,3 @@ | ||
options.noClone = true; | ||
return this.find(query, options).aggregate(function (docs) { | ||
return docs.length; | ||
}); | ||
return this.delegate.count(query, options); | ||
} | ||
@@ -368,6 +321,3 @@ | ||
options.noClone = true; | ||
return this.find(query, options).map(function (doc) { | ||
return doc._id; | ||
}); | ||
return this.delegate.ids(query, options); | ||
} | ||
@@ -416,2 +366,11 @@ }, { | ||
} | ||
}, { | ||
key: 'defaultDelegate', | ||
value: function defaultDelegate() { | ||
if (arguments.length > 0) { | ||
_defaultDelegate = arguments[0]; | ||
} else { | ||
return _defaultDelegate; | ||
} | ||
} | ||
}]); | ||
@@ -418,0 +377,0 @@ |
@@ -36,6 +36,2 @@ 'use strict'; | ||
var _keymirror = require('keymirror'); | ||
var _keymirror2 = _interopRequireDefault(_keymirror); | ||
var _DocumentRetriver = require('./DocumentRetriver'); | ||
@@ -73,13 +69,13 @@ | ||
// Pipeline processors definition | ||
var PIPELINE_TYPE = exports.PIPELINE_TYPE = (0, _keymirror2.default)({ | ||
Filter: null, | ||
Sort: null, | ||
Map: null, | ||
Aggregate: null, | ||
Reduce: null, | ||
Join: null, | ||
JoinEach: null, | ||
JoinAll: null, | ||
IfNotEmpty: null | ||
}); | ||
var PIPELINE_TYPE = exports.PIPELINE_TYPE = { | ||
Filter: 'Filter', | ||
Sort: 'Sort', | ||
Map: 'Map', | ||
Aggregate: 'Aggregate', | ||
Reduce: 'Reduce', | ||
Join: 'Join', | ||
JoinEach: 'JoinEach', | ||
JoinAll: 'JoinAll', | ||
IfNotEmpty: 'IfNotEmpty' | ||
}; | ||
@@ -86,0 +82,0 @@ var PIPELINE_PROCESSORS = exports.PIPELINE_PROCESSORS = (_PIPELINE_PROCESSORS = {}, _defineProperty(_PIPELINE_PROCESSORS, PIPELINE_TYPE.Filter, function (docs, pipeObj) { |
@@ -65,2 +65,3 @@ 'use strict'; | ||
_this.maybeUpdate = (0, _bind3.default)(_this.maybeUpdate, _this); | ||
_this._latestResult = null; | ||
return _this; | ||
@@ -168,4 +169,12 @@ } | ||
} else { | ||
var firstUpdatePromise = this.update.func(true); | ||
return createStoppablePromise(firstUpdatePromise); | ||
if (this._latestResult != null) { | ||
var propagatePromise = this.whenNotExecuting().then(function () { | ||
_this2._propagateUpdate(true); | ||
return _this2._latestResult; | ||
}); | ||
return createStoppablePromise(propagatePromise); | ||
} else { | ||
var firstUpdatePromise = this.update.func(true); | ||
return createStoppablePromise(firstUpdatePromise); | ||
} | ||
} | ||
@@ -236,5 +245,4 @@ } | ||
// 2. Is a new doc has different number of fields then an old doc? | ||
// 3. Is a new doc has a greater updatedAt time then an old doc? | ||
// 4. Is a new doc not equals to an old doc? | ||
var updatedInResult = removedFromResult || newDoc && oldDoc && (this._matcher.documentMatches(newDoc).result || this._matcher.documentMatches(oldDoc).result) && ((0, _keys3.default)(newDoc).length !== (0, _keys3.default)(oldDoc).length || newDoc.updatedAt && (!oldDoc.updatedAt || oldDoc.updatedAt && newDoc.updatedAt > oldDoc.updatedAt) || !_EJSON2.default.equals(newDoc, oldDoc)); | ||
// 3. Is a new doc not equals to an old doc? | ||
var updatedInResult = removedFromResult || newDoc && oldDoc && (this._matcher.documentMatches(newDoc).result || this._matcher.documentMatches(oldDoc).result) && ((0, _keys3.default)(newDoc).length !== (0, _keys3.default)(oldDoc).length || !_EJSON2.default.equals(newDoc, oldDoc)); | ||
@@ -241,0 +249,0 @@ // When it's an insert operation we just check |
@@ -35,2 +35,3 @@ "use strict"; | ||
} else { | ||
resolve(func.apply(context, args)); | ||
promise = null; | ||
@@ -41,3 +42,2 @@ callsCount = 0; | ||
maybeResolve = null; | ||
resolve(func.apply(context, args)); | ||
} | ||
@@ -44,0 +44,0 @@ }; |
@@ -18,2 +18,6 @@ 'use strict'; | ||
var _filter2 = require('fast.js/array/filter'); | ||
var _filter3 = _interopRequireDefault(_filter2); | ||
var _Document = require('./Document'); | ||
@@ -89,3 +93,8 @@ | ||
_this.db.storage.createReadStream().on('data', function (data) { | ||
return result.push(_this.db.create(data.value)); | ||
// After deleting of an item some storages | ||
// may return an undefined for a few times. | ||
// We need to check it there. | ||
if (data.value) { | ||
result.push(_this.db.create(data.value)); | ||
} | ||
}).on('end', function () { | ||
@@ -112,3 +121,7 @@ return resolve(result); | ||
}); | ||
return Promise.all(retrPromises); | ||
return Promise.all(retrPromises).then(function (docs) { | ||
return (0, _filter3.default)(docs, function (d) { | ||
return d; | ||
}); | ||
}); | ||
} | ||
@@ -128,3 +141,6 @@ | ||
return this.db.storage.get(id).then(function (buf) { | ||
return _this3.db.create(buf); | ||
// Accepted only non-undefined documents | ||
if (buf) { | ||
return _this3.db.create(buf); | ||
} | ||
}); | ||
@@ -131,0 +147,0 @@ } |
@@ -42,2 +42,3 @@ 'use strict'; | ||
this.db = db; | ||
this.options = options; | ||
this._queue = new _PromiseQueue2.default(1); | ||
@@ -44,0 +45,0 @@ this._storage = {}; |
@@ -0,10 +1,9 @@ | ||
import _map from 'fast.js/map'; | ||
import _each from 'fast.js/forEach'; | ||
import _map from 'fast.js/map'; | ||
import _check from 'check-types'; | ||
import EventEmitter from 'eventemitter3'; | ||
import invariant from 'invariant'; | ||
import DocumentModifier from './DocumentModifier'; | ||
import IndexManager from './IndexManager'; | ||
import StorageManager from './StorageManager'; | ||
import CursorObservable from './CursorObservable'; | ||
import CollectionDelegate from './CollectionDelegate'; | ||
import Random from './Random'; | ||
@@ -16,2 +15,3 @@ import EJSON from './EJSON'; | ||
const _defaultRandomGenerator = new Random(); | ||
let _defaultDelegate = CollectionDelegate; | ||
let _defaultCursorClass = CursorObservable; | ||
@@ -32,7 +32,6 @@ let _defaultStorageManager = StorageManager; | ||
super(); | ||
this._methods = {}; | ||
this._modelName = name; | ||
// Init managers | ||
const storageManagerClass = options.storageManager || _defaultStorageManager; | ||
const delegateClass = options.delegate || _defaultDelegate; | ||
this.cursorClass = options.cursorClass || _defaultCursorClass; | ||
@@ -42,2 +41,3 @@ this.indexManager = new IndexManager(this, options); | ||
this.idGenerator = options.idGenerator || _defaultIdGenerator; | ||
this.delegate = new delegateClass(this, options); | ||
} | ||
@@ -79,2 +79,10 @@ | ||
static defaultDelegate() { | ||
if (arguments.length > 0) { | ||
_defaultDelegate = arguments[0]; | ||
} else { | ||
return _defaultDelegate; | ||
} | ||
} | ||
/** | ||
@@ -90,2 +98,10 @@ * Factory for creating an object of the model | ||
/** | ||
* Return all currently indexed ids | ||
* @return {Array} | ||
*/ | ||
getIndexIds() { | ||
return this.indexes._id.getAll(); | ||
} | ||
/** | ||
* Ensures index by delegating to IndexManager. | ||
@@ -117,8 +133,5 @@ * @param {String} key | ||
// Add to indexes and persist | ||
return this.indexManager.indexDocument(doc).then(() => { | ||
return this.storageManager.persist(doc._id, doc).then(() => { | ||
this.emit('insert', doc, null, randomId); | ||
return doc._id; | ||
}); | ||
return this.delegate.insert(doc, options).then((docId) => { | ||
this.emit('insert', doc, null, randomId); | ||
return docId; | ||
}); | ||
@@ -128,8 +141,9 @@ } | ||
/** | ||
* Insert all documents in given list | ||
* Just a sugar for mulpitle inserts. Wrap all inserts | ||
* with a single Promise and return it. | ||
* @param {Array} docs | ||
* @param {Boolean} quiet | ||
* @param {Object} options | ||
* @return {Promise} | ||
*/ | ||
insertAll(docs, options) { | ||
insertAll(docs, options = {}) { | ||
return Promise.all( | ||
@@ -149,3 +163,2 @@ _map(docs, d => this.insert(d, options)) | ||
remove(query, options = {}) { | ||
// Fire sync event | ||
if (!options.quiet) { | ||
@@ -155,21 +168,5 @@ this.emit('sync:remove', query, options); | ||
// Remove locally | ||
return this.find(query).exec().then((docs) => { | ||
invariant( | ||
docs.length <= 1 || options.multi, | ||
'remove(..): multi removing is not enabled by options.multi' | ||
); | ||
const removeStorgePromises = _map(docs, d => { | ||
return this.storageManager.delete(d._id); | ||
}); | ||
const removeIndexPromises = _map(docs, d => { | ||
return this.indexManager.deindexDocument(d); | ||
}); | ||
const allPromises = removeStorgePromises.concat(removeIndexPromises); | ||
return Promise.all(allPromises).then(() => { | ||
_each(docs, d => this.emit('remove', null, d)); | ||
return docs; | ||
}); | ||
return this.delegate.remove(query, options).then((removedDocs) => { | ||
_each(removedDocs, d => this.emit('remove', null, d)); | ||
return removedDocs; | ||
}); | ||
@@ -188,5 +185,2 @@ } | ||
update(query, modifier, options = {}) { | ||
options.upsert = false; | ||
// Fire sync event | ||
if (!options.quiet) { | ||
@@ -196,39 +190,11 @@ this.emit('sync:update', query, modifier, options); | ||
// Update locally | ||
return new DocumentModifier(this, query) | ||
.modify(modifier, options) | ||
.then((result) => { | ||
var {original, updated} = result; | ||
updated = _map(updated, x => this.create(x)); | ||
const updateStorgePromises = _map(updated, d => { | ||
return this.storageManager.persist(d._id, d); | ||
}); | ||
const updateIndexPromises = _map(updated, (d, i) => { | ||
return this.indexManager.reindexDocument(original[i], d); | ||
}); | ||
const allPromises = updateStorgePromises.concat(updateIndexPromises); | ||
return Promise.all(allPromises).then(() => { | ||
_each(updated, (d, i) => { | ||
this.emit('update', d, original[i]); | ||
}); | ||
return { | ||
modified: updated.length, | ||
original: original, | ||
updated: updated, | ||
}; | ||
}); | ||
return this.delegate.update(query, modifier, options).then(res => { | ||
_each(res.updated, (d, i) => { | ||
this.emit('update', d, res.original[i]); | ||
}); | ||
return res; | ||
}); | ||
} | ||
/** | ||
* Return all currently indexed ids | ||
* @return {Array} | ||
*/ | ||
getIndexIds() { | ||
return this.indexes._id.getAll(); | ||
} | ||
/** | ||
* Make a cursor with given query and return. | ||
@@ -243,3 +209,3 @@ * By default all documents clonned before passed | ||
find(query, options = {}) { | ||
return new (this.cursorClass)(this, query, options); | ||
return this.delegate.find(query, options); | ||
} | ||
@@ -255,6 +221,4 @@ | ||
*/ | ||
findOne(query, sortObj, options = {}) { | ||
return this.find(query, options) | ||
.sort(sortObj).limit(1) | ||
.aggregate(docs => docs[0]); | ||
findOne(query, options = {}) { | ||
return this.delegate.findOne(query, options); | ||
} | ||
@@ -272,5 +236,3 @@ | ||
count(query, options = {}) { | ||
options.noClone = true; | ||
return this.find(query, options) | ||
.aggregate((docs) => docs.length); | ||
return this.delegate.count(query, options); | ||
} | ||
@@ -285,5 +247,3 @@ | ||
ids(query, options = {}) { | ||
options.noClone = true; | ||
return this.find(query, options) | ||
.map((doc) => doc._id); | ||
return this.delegate.ids(query, options); | ||
} | ||
@@ -290,0 +250,0 @@ } |
@@ -7,3 +7,2 @@ import _bind from 'fast.js/function/bind'; | ||
import invariant from 'invariant'; | ||
import keyMirror from 'keymirror'; | ||
import DocumentRetriver from './DocumentRetriver'; | ||
@@ -19,13 +18,13 @@ import DocumentMatcher from './DocumentMatcher'; | ||
// Pipeline processors definition | ||
export const PIPELINE_TYPE = keyMirror({ | ||
Filter: null, | ||
Sort: null, | ||
Map: null, | ||
Aggregate: null, | ||
Reduce: null, | ||
Join: null, | ||
JoinEach: null, | ||
JoinAll: null, | ||
IfNotEmpty: null, | ||
}); | ||
export const PIPELINE_TYPE = { | ||
Filter: 'Filter', | ||
Sort: 'Sort', | ||
Map: 'Map', | ||
Aggregate: 'Aggregate', | ||
Reduce: 'Reduce', | ||
Join: 'Join', | ||
JoinEach: 'JoinEach', | ||
JoinAll: 'JoinAll', | ||
IfNotEmpty: 'IfNotEmpty', | ||
}; | ||
@@ -32,0 +31,0 @@ export const PIPELINE_PROCESSORS = { |
@@ -27,2 +27,3 @@ import _bind from 'fast.js/function/bind'; | ||
this.maybeUpdate = _bind(this.maybeUpdate, this); | ||
this._latestResult = null; | ||
} | ||
@@ -130,4 +131,12 @@ | ||
} else { | ||
const firstUpdatePromise = this.update.func(true); | ||
return createStoppablePromise(firstUpdatePromise); | ||
if (this._latestResult != null) { | ||
const propagatePromise = this.whenNotExecuting().then(() => { | ||
this._propagateUpdate(true); | ||
return this._latestResult; | ||
}); | ||
return createStoppablePromise(propagatePromise); | ||
} else { | ||
const firstUpdatePromise = this.update.func(true); | ||
return createStoppablePromise(firstUpdatePromise); | ||
} | ||
} | ||
@@ -188,4 +197,3 @@ } | ||
// 2. Is a new doc has different number of fields then an old doc? | ||
// 3. Is a new doc has a greater updatedAt time then an old doc? | ||
// 4. Is a new doc not equals to an old doc? | ||
// 3. Is a new doc not equals to an old doc? | ||
const updatedInResult = removedFromResult || (newDoc && oldDoc && ( | ||
@@ -195,10 +203,4 @@ this._matcher.documentMatches(newDoc).result || | ||
) && ( | ||
_keys(newDoc).length !== _keys(oldDoc).length || ( | ||
newDoc.updatedAt && ( | ||
!oldDoc.updatedAt || | ||
(oldDoc.updatedAt && newDoc.updatedAt > oldDoc.updatedAt) | ||
) | ||
) || ( | ||
!EJSON.equals(newDoc, oldDoc) | ||
) | ||
_keys(newDoc).length !== _keys(oldDoc).length || | ||
!EJSON.equals(newDoc, oldDoc) | ||
) | ||
@@ -205,0 +207,0 @@ ); |
@@ -29,2 +29,3 @@ /** | ||
} else { | ||
resolve(func.apply(context, args)); | ||
promise = null; | ||
@@ -35,3 +36,2 @@ callsCount = 0; | ||
maybeResolve = null; | ||
resolve(func.apply(context, args)); | ||
} | ||
@@ -38,0 +38,0 @@ }; |
import _check from 'check-types'; | ||
import _map from 'fast.js/map'; | ||
import _filter from 'fast.js/array/filter'; | ||
import {selectorIsId, selectorIsIdPerhapsAsObject} from './Document'; | ||
@@ -63,3 +64,10 @@ | ||
this.db.storage.createReadStream() | ||
.on('data', (data) => result.push(this.db.create(data.value))) | ||
.on('data', (data) => { | ||
// After deleting of an item some storages | ||
// may return an undefined for a few times. | ||
// We need to check it there. | ||
if (data.value) { | ||
result.push(this.db.create(data.value)); | ||
} | ||
}) | ||
.on('end', () => resolve(result)); | ||
@@ -77,3 +85,5 @@ }); | ||
const retrPromises = _map(ids, id => this.retriveOne(id)); | ||
return Promise.all(retrPromises); | ||
return Promise.all(retrPromises).then((docs) => ( | ||
_filter(docs, (d) => d) | ||
)); | ||
} | ||
@@ -87,3 +97,9 @@ | ||
retriveOne(id) { | ||
return this.db.storage.get(id).then((buf) => this.db.create(buf)); | ||
return this.db.storage.get(id) | ||
.then((buf) => { | ||
// Accepted only non-undefined documents | ||
if (buf) { | ||
return this.db.create(buf); | ||
} | ||
}); | ||
} | ||
@@ -90,0 +106,0 @@ } |
@@ -16,2 +16,3 @@ import _each from 'fast.js/forEach'; | ||
this.db = db; | ||
this.options = options; | ||
this._queue = new PromiseQueue(1); | ||
@@ -18,0 +19,0 @@ this._storage = {}; |
{ | ||
"name": "marsdb", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"author": { | ||
@@ -28,10 +28,9 @@ "name": "Artem Artemev", | ||
"check-types": "^5.1.0", | ||
"core-js": "^2.0.1", | ||
"eventemitter3": "1.1.1", | ||
"fast.js": "^0.1.1", | ||
"geojson-utils": "^1.1.0", | ||
"invariant": "^2.2.0", | ||
"keymirror": "^0.1.1" | ||
"invariant": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"core-js": "^2.0.1", | ||
"lodash": "3.10.x", | ||
@@ -38,0 +37,0 @@ "babel-cli": "^6.3.17", |
@@ -113,2 +113,16 @@ import Collection from '../../lib/Collection'; | ||
describe('#observe', function () { | ||
it('should return result of previous execution', function () { | ||
const cursor = db.find({b: 1}) | ||
let result; | ||
return cursor.observe((res) => { | ||
result = res; | ||
}).then(() => { | ||
return cursor.observe((new_res) => { | ||
new_res.should.be.equal(result); | ||
}).then((new_res) => { | ||
new_res.should.be.equal(result); | ||
}); | ||
}) | ||
}); | ||
it('should support multiple declarative style observing', function (done) { | ||
@@ -231,6 +245,6 @@ let calls = 0; | ||
.joinAll((docs) => { | ||
return db.find({b: 30}).observe(res => { | ||
return db.find({b: 30}, {test: observerCalls}).observe(res => { | ||
if (res.length > 0) { | ||
joinCalls += 1; | ||
joinCalls.should.be.lte(1); | ||
joinCalls.should.be.lte(2); | ||
} | ||
@@ -245,3 +259,3 @@ }); | ||
if (observerCalls === 2) { | ||
done(); | ||
setTimeout(done, 60); | ||
} | ||
@@ -255,3 +269,3 @@ }).then(() => { | ||
it('should update when join funciton call updater function', function (done) { | ||
it('should update when join function call updater function', function (done) { | ||
var observerCalls = 0; | ||
@@ -333,3 +347,3 @@ db.find({$or: [{f: 1}, {f: 2}]}) | ||
it('should not update a cursor when updatedAt is equals', function (done) { | ||
it('should NOT update a cursor when updatedAt is equals', function (done) { | ||
var calls = 0; | ||
@@ -336,0 +350,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
835253
5
75
19552
33
- Removedcore-js@^2.0.1
- Removedkeymirror@^0.1.1
- Removedcore-js@2.6.12(transitive)
- Removedkeymirror@0.1.1(transitive)