forked from cult-of-coders/redis-oplog
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix extendMongoCollection.js to support allow_deny of Meteor 3
- Loading branch information
Showing
1 changed file
with
65 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,98 @@ | ||
import { Mongo } from 'meteor/mongo' | ||
import { _ } from 'meteor/underscore' | ||
import _validatedInsert from './allow-deny/validatedInsert' | ||
import _validatedUpdate from './allow-deny/validatedUpdate' | ||
import _validatedRemove from './allow-deny/validatedRemove' | ||
import Mutator from './Mutator' | ||
import extendObserveChanges from './extendObserveChanges' | ||
import { Meteor } from 'meteor/meteor' | ||
import { Mongo } from 'meteor/mongo'; | ||
import { _ } from 'meteor/underscore'; | ||
import _validatedInsertAsync from './allow-deny/validatedInsert'; | ||
import _validatedUpdateAsync from './allow-deny/validatedUpdate'; | ||
import _validatedRemoveAsync from './allow-deny/validatedRemove'; | ||
import Mutator from './Mutator'; | ||
import extendObserveChanges from './extendObserveChanges'; | ||
import { Meteor } from 'meteor/meteor'; | ||
|
||
export default () => { | ||
const Originals = { | ||
insertAsync: Mongo.Collection.prototype.insertAsync, | ||
updateAsync: Mongo.Collection.prototype.updateAsync, | ||
removeAsync: Mongo.Collection.prototype.removeAsync, | ||
find: Mongo.Collection.prototype.find, | ||
findOneAsync: Mongo.Collection.prototype.findOneAsync | ||
} | ||
const Originals = { | ||
insertAsync: Mongo.Collection.prototype.insertAsync, | ||
updateAsync: Mongo.Collection.prototype.updateAsync, | ||
removeAsync: Mongo.Collection.prototype.removeAsync, | ||
find: Mongo.Collection.prototype.find, | ||
findOneAsync: Mongo.Collection.prototype.findOneAsync, | ||
}; | ||
|
||
Mutator.init() | ||
Mutator.init(); | ||
|
||
extendObserveChanges() | ||
extendObserveChanges(); | ||
|
||
Object.assign(Mongo.Collection.prototype, { | ||
/** | ||
Object.assign(Mongo.Collection.prototype, { | ||
/** | ||
* @param data | ||
* @param config | ||
* @returns {*} | ||
*/ | ||
insertAsync (data, config) { | ||
return Mutator.insert.call(this, Originals, data, config) | ||
}, | ||
insertAsync(data, config) { | ||
return Mutator.insert.call(this, Originals, data, config); | ||
}, | ||
|
||
/** | ||
/** | ||
* @param selector | ||
* @param modifier | ||
* @param config | ||
* @param callback | ||
* @returns {*} | ||
*/ | ||
updateAsync (selector, modifier, config, callback) { | ||
return Mutator.update.call( | ||
this, | ||
Originals, | ||
selector, | ||
modifier, | ||
config, | ||
callback | ||
) | ||
}, | ||
updateAsync(selector, modifier, config, callback) { | ||
return Mutator.update.call( | ||
this, | ||
Originals, | ||
selector, | ||
modifier, | ||
config, | ||
callback, | ||
); | ||
}, | ||
|
||
/** | ||
/** | ||
* @param selector | ||
* @param config | ||
* @returns {*} | ||
*/ | ||
removeAsync (selector, config) { | ||
return Mutator.remove.call(this, Originals, selector, config) | ||
}, | ||
removeAsync(selector, config) { | ||
return Mutator.remove.call(this, Originals, selector, config); | ||
}, | ||
|
||
_validatedInsert, | ||
_validatedUpdate, | ||
_validatedRemove, | ||
_validatedInsertAsync, | ||
_validatedUpdateAsync, | ||
_validatedRemoveAsync, | ||
|
||
/** | ||
/** | ||
* Configure defaults for your collection | ||
* | ||
* @param {function} mutation | ||
* @param {function} cursor | ||
* @param {boolean} shouldIncludePrevDocument | ||
*/ | ||
configureRedisOplog ({ mutation, cursor, ...rest }) { | ||
this._redisOplog = { | ||
shouldIncludePrevDocument: false, | ||
protectAgainstRaceConditions: true, | ||
...rest | ||
} | ||
configureRedisOplog({ mutation, cursor, ...rest }) { | ||
this._redisOplog = { | ||
shouldIncludePrevDocument: false, | ||
protectAgainstRaceConditions: true, | ||
...rest, | ||
}; | ||
|
||
if (mutation) { | ||
if (!_.isFunction(mutation)) { | ||
throw new Meteor.Error( | ||
'To configure defaults for the collection, "mutation" needs to be a function' | ||
) | ||
} | ||
if (mutation) { | ||
if (!_.isFunction(mutation)) { | ||
throw new Meteor.Error( | ||
'To configure defaults for the collection, "mutation" needs to be a function', | ||
); | ||
} | ||
|
||
this._redisOplog.mutation = mutation | ||
} | ||
if (cursor) { | ||
if (!_.isFunction(cursor)) { | ||
throw new Meteor.Error( | ||
'To configure defaults for the collection, "cursor" needs to be a function' | ||
) | ||
} | ||
this._redisOplog.mutation = mutation; | ||
} | ||
if (cursor) { | ||
if (!_.isFunction(cursor)) { | ||
throw new Meteor.Error( | ||
'To configure defaults for the collection, "cursor" needs to be a function', | ||
); | ||
} | ||
|
||
this._redisOplog.cursor = cursor | ||
} | ||
} | ||
}) | ||
this._redisOplog.cursor = cursor; | ||
} | ||
}, | ||
}); | ||
} |