Comparing version 0.5.12 to 0.5.13
@@ -38,6 +38,2 @@ 'use strict'; | ||
var _CursorObservable = require('./CursorObservable'); | ||
var _CursorObservable2 = _interopRequireDefault(_CursorObservable); | ||
var _CollectionDelegate = require('./CollectionDelegate'); | ||
@@ -64,4 +60,4 @@ | ||
// Defaults | ||
var _defaultUpgradeEmitter = new _eventemitter2.default(); | ||
var _defaultDelegate = _CollectionDelegate2.default; | ||
var _defaultCursorClass = _CursorObservable2.default; | ||
var _defaultStorageManager = _StorageManager2.default; | ||
@@ -89,3 +85,3 @@ var _defaultIndexManager = _IndexManager2.default; | ||
_this._modelName = name; | ||
_this._writeQueue = new _PromiseQueue2.default(options.writeConcurrency || 2); | ||
_this._writeQueue = new _PromiseQueue2.default(options.writeConcurrency || 5); | ||
@@ -95,3 +91,2 @@ var storageManagerClass = options.storageManager || _defaultStorageManager; | ||
var indexManagerClass = options.indexManager || _defaultIndexManager; | ||
_this.cursorClass = options.cursorClass || _defaultCursorClass; | ||
_this.idGenerator = options.idGenerator || _defaultIdGenerator; | ||
@@ -101,2 +96,3 @@ _this.indexManager = new indexManagerClass(_this, options); | ||
_this.delegate = new delegateClass(_this, options); | ||
_this._registerDefaultUpgradeHandlers(options); | ||
return _this; | ||
@@ -309,3 +305,38 @@ } | ||
} | ||
/** | ||
* If defaults is not overrided by options, then collection | ||
* registered in evenbus for default upgrade. | ||
* @param {Object} options | ||
*/ | ||
}, { | ||
key: '_registerDefaultUpgradeHandlers', | ||
value: function _registerDefaultUpgradeHandlers() { | ||
var _this6 = this; | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
if (!options.storageManager) { | ||
_defaultUpgradeEmitter.on('storageManager', function () { | ||
return _this6.storageManager = new _defaultStorageManager(_this6, options); | ||
}); | ||
} | ||
if (!options.idGenerator) { | ||
_defaultUpgradeEmitter.on('idGenerator', function () { | ||
return _this6.idGenerator = _defaultIdGenerator; | ||
}); | ||
} | ||
if (!options.delegate) { | ||
_defaultUpgradeEmitter.on('delegate', function () { | ||
return _this6.delegate = new _defaultDelegate(_this6, options); | ||
}); | ||
} | ||
if (!options.indexManager) { | ||
_defaultUpgradeEmitter.on('indexManager', function () { | ||
return _this6.indexManager = new _defaultIndexManager(_this6, options); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: 'modelName', | ||
@@ -325,2 +356,11 @@ get: function get() { | ||
} | ||
/** | ||
* Wihout arguments it returns current default storage manager. | ||
* If arguments provided, then first argument will be set as default | ||
* storage manager and all collections, who uses default storage manager, | ||
* will be upgraded to a new strage manager. | ||
* @return {undefined|Class} | ||
*/ | ||
}], [{ | ||
@@ -331,2 +371,3 @@ key: 'defaultStorageManager', | ||
_defaultStorageManager = arguments[0]; | ||
_defaultUpgradeEmitter.emit('storageManager'); | ||
} else { | ||
@@ -336,2 +377,11 @@ return _defaultStorageManager; | ||
} | ||
/** | ||
* Wihout arguments it returns current default id generator. | ||
* If arguments provided, then first argument will be set as default | ||
* id generator and all collections, who uses default id generator, | ||
* will be upgraded to a new id generator. | ||
* @return {undefined|Class} | ||
*/ | ||
}, { | ||
@@ -342,2 +392,3 @@ key: 'defaultIdGenerator', | ||
_defaultIdGenerator = arguments[0]; | ||
_defaultUpgradeEmitter.emit('idGenerator'); | ||
} else { | ||
@@ -347,12 +398,12 @@ return _defaultIdGenerator; | ||
} | ||
/** | ||
* Wihout arguments it returns current default delegate class. | ||
* If arguments provided, then first argument will be set as default | ||
* delegate and all collections, who uses default delegate, | ||
* will be upgraded to a new delegate. | ||
* @return {undefined|Class} | ||
*/ | ||
}, { | ||
key: 'defaultCursorClass', | ||
value: function defaultCursorClass() { | ||
if (arguments.length > 0) { | ||
_defaultCursorClass = arguments[0]; | ||
} else { | ||
return _defaultCursorClass; | ||
} | ||
} | ||
}, { | ||
key: 'defaultDelegate', | ||
@@ -362,2 +413,3 @@ value: function defaultDelegate() { | ||
_defaultDelegate = arguments[0]; | ||
_defaultUpgradeEmitter.emit('delegate'); | ||
} else { | ||
@@ -367,2 +419,11 @@ return _defaultDelegate; | ||
} | ||
/** | ||
* Wihout arguments it returns current default index manager class. | ||
* If arguments provided, then first argument will be set as default | ||
* index manager and all collections, who uses default index manager, | ||
* will be upgraded to a new index manager. | ||
* @return {undefined|Class} | ||
*/ | ||
}, { | ||
@@ -373,2 +434,3 @@ key: 'defaultIndexManager', | ||
_defaultIndexManager = arguments[0]; | ||
_defaultUpgradeEmitter.emit('indexManager'); | ||
} else { | ||
@@ -375,0 +437,0 @@ return _defaultIndexManager; |
@@ -18,2 +18,6 @@ 'use strict'; | ||
var _CursorObservable = require('./CursorObservable'); | ||
var _CursorObservable2 = _interopRequireDefault(_CursorObservable); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -114,3 +118,3 @@ | ||
return new this.db.cursorClass(this.db, query, options); | ||
return new _CursorObservable2.default(this.db, query, options); | ||
} | ||
@@ -117,0 +121,0 @@ }, { |
@@ -8,3 +8,2 @@ import _map from 'fast.js/map'; | ||
import StorageManager from './StorageManager'; | ||
import CursorObservable from './CursorObservable'; | ||
import CollectionDelegate from './CollectionDelegate'; | ||
@@ -16,4 +15,4 @@ import Random from './Random'; | ||
// Defaults | ||
const _defaultUpgradeEmitter = new EventEmitter(); | ||
let _defaultDelegate = CollectionDelegate; | ||
let _defaultCursorClass = CursorObservable; | ||
let _defaultStorageManager = StorageManager; | ||
@@ -35,3 +34,3 @@ let _defaultIndexManager = IndexManager; | ||
this._modelName = name; | ||
this._writeQueue = new PromiseQueue(options.writeConcurrency || 2); | ||
this._writeQueue = new PromiseQueue(options.writeConcurrency || 5); | ||
@@ -41,3 +40,2 @@ const storageManagerClass = options.storageManager || _defaultStorageManager; | ||
const indexManagerClass = options.indexManager || _defaultIndexManager; | ||
this.cursorClass = options.cursorClass || _defaultCursorClass; | ||
this.idGenerator = options.idGenerator || _defaultIdGenerator; | ||
@@ -47,2 +45,3 @@ this.indexManager = new indexManagerClass(this, options); | ||
this.delegate = new delegateClass(this, options); | ||
this._registerDefaultUpgradeHandlers(options); | ||
} | ||
@@ -60,5 +59,13 @@ | ||
/** | ||
* Wihout arguments it returns current default storage manager. | ||
* If arguments provided, then first argument will be set as default | ||
* storage manager and all collections, who uses default storage manager, | ||
* will be upgraded to a new strage manager. | ||
* @return {undefined|Class} | ||
*/ | ||
static defaultStorageManager() { | ||
if (arguments.length > 0) { | ||
_defaultStorageManager = arguments[0]; | ||
_defaultUpgradeEmitter.emit('storageManager'); | ||
} else { | ||
@@ -69,5 +76,13 @@ return _defaultStorageManager; | ||
/** | ||
* Wihout arguments it returns current default id generator. | ||
* If arguments provided, then first argument will be set as default | ||
* id generator and all collections, who uses default id generator, | ||
* will be upgraded to a new id generator. | ||
* @return {undefined|Class} | ||
*/ | ||
static defaultIdGenerator() { | ||
if (arguments.length > 0) { | ||
_defaultIdGenerator = arguments[0]; | ||
_defaultUpgradeEmitter.emit('idGenerator'); | ||
} else { | ||
@@ -78,13 +93,13 @@ return _defaultIdGenerator; | ||
static defaultCursorClass() { | ||
if (arguments.length > 0) { | ||
_defaultCursorClass = arguments[0]; | ||
} else { | ||
return _defaultCursorClass; | ||
} | ||
} | ||
/** | ||
* Wihout arguments it returns current default delegate class. | ||
* If arguments provided, then first argument will be set as default | ||
* delegate and all collections, who uses default delegate, | ||
* will be upgraded to a new delegate. | ||
* @return {undefined|Class} | ||
*/ | ||
static defaultDelegate() { | ||
if (arguments.length > 0) { | ||
_defaultDelegate = arguments[0]; | ||
_defaultUpgradeEmitter.emit('delegate'); | ||
} else { | ||
@@ -95,5 +110,13 @@ return _defaultDelegate; | ||
/** | ||
* Wihout arguments it returns current default index manager class. | ||
* If arguments provided, then first argument will be set as default | ||
* index manager and all collections, who uses default index manager, | ||
* will be upgraded to a new index manager. | ||
* @return {undefined|Class} | ||
*/ | ||
static defaultIndexManager() { | ||
if (arguments.length > 0) { | ||
_defaultIndexManager = arguments[0]; | ||
_defaultUpgradeEmitter.emit('indexManager'); | ||
} else { | ||
@@ -255,4 +278,32 @@ return _defaultIndexManager; | ||
} | ||
/** | ||
* If defaults is not overrided by options, then collection | ||
* registered in evenbus for default upgrade. | ||
* @param {Object} options | ||
*/ | ||
_registerDefaultUpgradeHandlers(options = {}) { | ||
if (!options.storageManager) { | ||
_defaultUpgradeEmitter.on('storageManager', () => | ||
this.storageManager = new _defaultStorageManager(this, options) | ||
); | ||
} | ||
if (!options.idGenerator) { | ||
_defaultUpgradeEmitter.on('idGenerator', () => | ||
this.idGenerator = _defaultIdGenerator | ||
); | ||
} | ||
if (!options.delegate) { | ||
_defaultUpgradeEmitter.on('delegate', () => | ||
this.delegate = new _defaultDelegate(this, options) | ||
); | ||
} | ||
if (!options.indexManager) { | ||
_defaultUpgradeEmitter.on('indexManager', () => | ||
this.indexManager = new _defaultIndexManager(this, options) | ||
); | ||
} | ||
} | ||
} | ||
export default Collection; |
import _map from 'fast.js/map'; | ||
import DocumentModifier from './DocumentModifier'; | ||
import CursorObservable from './CursorObservable'; | ||
@@ -68,3 +69,3 @@ | ||
find(query, options = {}) { | ||
return new (this.db.cursorClass)(this.db, query, options); | ||
return new CursorObservable(this.db, query, options); | ||
} | ||
@@ -71,0 +72,0 @@ |
{ | ||
"name": "marsdb", | ||
"version": "0.5.12", | ||
"version": "0.5.13", | ||
"author": { | ||
@@ -28,2 +28,3 @@ "name": "Artem Artemev", | ||
"check-types": "^6.0.0", | ||
"double-ended-queue": "^0.9.7", | ||
"eventemitter3": "1.1.1", | ||
@@ -30,0 +31,0 @@ "fast.js": "^0.1.1", |
@@ -43,4 +43,9 @@ <div style="text-align:center"><img src="https://static.studytime.me/marsdb.png" /></div> | ||
* [Validation via Mongoose](https://github.com/c58/marsdb-validation) – validate objects with Mongoose | ||
* **Meteor compatible** [Client](https://github.com/c58/marsdb-sync-client) / [Server](https://github.com/c58/marsdb-sync-server) synchronizer | ||
## Meteor compatible client/server | ||
Sometimes you can't use Meteor infrastructure. Maybe you need to build a custom client. Maybe you need to build a custom server with express and other modules. In meteor it can be done with a ton of hack. But the only reason why it's so ugly to do a simple things is because Meteor forces you to use their infrastructure. I'm trying to solve this issue with DDP client/server modules, based on MarsDB. | ||
* [DDP client](https://github.com/c58/marsdb-sync-client) | ||
* [DDP server](https://github.com/c58/marsdb-sync-server) | ||
## Examples | ||
@@ -47,0 +52,0 @@ |
@@ -15,7 +15,19 @@ import {Document} from '../../lib/Document'; | ||
const _defaultIdGenerator = Collection.defaultIdGenerator(); | ||
const _defaultDelegate = Collection.defaultDelegate(); | ||
const _defaultStorageManager = Collection.defaultStorageManager(); | ||
const _defaultIndexManager = Collection.defaultIndexManager(); | ||
beforeEach(function () { | ||
Collection.defaultDelegate(_defaultDelegate); | ||
Collection.defaultStorageManager(_defaultStorageManager); | ||
Collection.defaultIndexManager(_defaultIndexManager); | ||
Collection.defaultIdGenerator(_defaultIdGenerator); | ||
}); | ||
describe('#constructor', function () { | ||
it('should accept second argument with options', function () { | ||
it('should override defaults', function () { | ||
class NewStorageManager {} | ||
function new_id_generator() {} | ||
class NewCursor {} | ||
class NewIndexManager {} | ||
class NewDelegate {} | ||
@@ -25,3 +37,4 @@ const db = new Collection('test', { | ||
idGenerator: new_id_generator, | ||
cursorClass: NewCursor, | ||
indexManager: NewIndexManager, | ||
delegate: NewDelegate, | ||
}); | ||
@@ -31,3 +44,4 @@ | ||
db.idGenerator.should.be.equal(new_id_generator); | ||
db.cursorClass.should.be.equal(NewCursor); | ||
db.indexManager.should.be.an.instanceof(NewIndexManager); | ||
db.delegate.should.be.an.instanceof(NewDelegate); | ||
}); | ||
@@ -53,12 +67,14 @@ }); | ||
describe('#defaultStorageManager', function () { | ||
it('should return default in-memory StorageManager', function () { | ||
Collection.defaultStorageManager().should.be.equal(StorageManager); | ||
}); | ||
it('should set default storage manager', function () { | ||
const oldStorage = Collection.defaultStorageManager(); | ||
class NewStorageManager {} | ||
Collection.defaultStorageManager(NewStorageManager); | ||
Collection.defaultStorageManager().should.be.equal(NewStorageManager); | ||
Collection.defaultStorageManager(oldStorage); | ||
}); | ||
it('should upgrade all collections uses defaults', function () { | ||
const defColl = new Collection(); | ||
defColl.storage.should.be.instanceof(Collection.defaultStorageManager()); | ||
class NewStorageManager {} | ||
Collection.defaultStorageManager(NewStorageManager); | ||
defColl.storage.should.be.instanceof(NewStorageManager); | ||
}); | ||
}); | ||
@@ -68,36 +84,45 @@ | ||
it('should set default id generator', function () { | ||
const oldGenerator = Collection.defaultIdGenerator(); | ||
function new_id_generator() {} | ||
Collection.defaultIdGenerator(new_id_generator); | ||
Collection.defaultIdGenerator().should.be.equal(new_id_generator); | ||
Collection.defaultIdGenerator(oldGenerator); | ||
}); | ||
}); | ||
describe('#defaultCursorClass', function () { | ||
it('should return default CursorObservable', function () { | ||
Collection.defaultCursorClass().should.be.equal(CursorObservable); | ||
it('should upgrade all collections uses defaults', function () { | ||
const defColl = new Collection(); | ||
defColl.idGenerator.should.be.equal(Collection.defaultIdGenerator()); | ||
function new_id_generator() {} | ||
Collection.defaultIdGenerator(new_id_generator); | ||
defColl.idGenerator.should.be.equal(new_id_generator); | ||
}); | ||
it('should set default Cursor class', function () { | ||
const oldCursor = Collection.defaultCursorClass(); | ||
class NewCursor {} | ||
Collection.defaultCursorClass(NewCursor); | ||
Collection.defaultCursorClass().should.be.equal(NewCursor); | ||
Collection.defaultCursorClass(oldCursor); | ||
}); | ||
}); | ||
describe('#defaultDelegate', function () { | ||
it('should return default CollectionDelegate', function () { | ||
Collection.defaultDelegate().should.be.equal(CollectionDelegate); | ||
}); | ||
it('should set default Delegate class', function () { | ||
const oldDelegate = Collection.defaultDelegate(); | ||
class NewDelegate {} | ||
Collection.defaultDelegate(NewDelegate); | ||
Collection.defaultDelegate().should.be.equal(NewDelegate); | ||
Collection.defaultDelegate(oldDelegate); | ||
}); | ||
it('should upgrade all collections uses defaults', function () { | ||
const defColl = new Collection(); | ||
defColl.delegate.should.be.instanceof(Collection.defaultDelegate()); | ||
class NewDelegate {} | ||
Collection.defaultDelegate(NewDelegate); | ||
defColl.delegate.should.be.instanceof(NewDelegate); | ||
}); | ||
}); | ||
describe('#defaultIndexManager', function () { | ||
it('should set default index manager class', function () { | ||
class NewIndexManager {} | ||
Collection.defaultIndexManager(NewIndexManager); | ||
Collection.defaultIndexManager().should.be.equal(NewIndexManager); | ||
}); | ||
it('should upgrade all collections uses defaults', function () { | ||
const defColl = new Collection(); | ||
defColl.indexManager.should.be.instanceof(Collection.defaultIndexManager()); | ||
class NewIndexManager {} | ||
Collection.defaultIndexManager(NewIndexManager); | ||
defColl.indexManager.should.be.instanceof(NewIndexManager); | ||
}); | ||
}); | ||
describe('#modelName', function () { | ||
@@ -104,0 +129,0 @@ it('should return name of the model', function () { |
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
945782
22042
208
6
+ Addeddouble-ended-queue@^0.9.7
+ Addeddouble-ended-queue@0.9.7(transitive)