Skip to content

Commit

Permalink
Fix extendMongoCollection.js to support allow_deny of Meteor 3
Browse files Browse the repository at this point in the history
  • Loading branch information
plbkbx committed Aug 7, 2024
1 parent 4668d1b commit 97b008e
Showing 1 changed file with 65 additions and 65 deletions.
130 changes: 65 additions & 65 deletions lib/mongo/extendMongoCollection.js
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;
}
},
});
}

0 comments on commit 97b008e

Please sign in to comment.