<commit_before>(function () {

	var directInsert, directUpdate, directRemove, _validatedInsert, _validatedUpdate, _validatedRemove;

	function delegate() {
		var i, len, c;
		var args = Array.prototype.slice.call(arguments);
		var type = args.shift();
		var verb = args.shift();

		if (this._x_matb33_hooks && this._x_matb33_hooks[type] && this._x_matb33_hooks[type][verb]) {
			for (i = 0, len = this._x_matb33_hooks[type][verb].length; i < len; i++) {
				c = this._x_matb33_hooks[type][verb][i];
				if (typeof c === "function") {
					if (c.apply(this, args) === false) {
						return false;
					}
				}
			}
		}
	}

	function getUserId() {
		var currentInvocation;

		try {
			currentInvocation = Meteor._CurrentInvocation.get();
		} catch (e) {}

		if (currentInvocation) {
			return currentInvocation.userId;
		} else {
			// this.userId will likely not be defined because no one usually
			// invokes collection.insert with a `.call(this)`... But if they
			// do, userId will be available to the end-callback.
			return this.userId || null;
		}
	}

	directInsert = Meteor.Collection.prototype.insert;
	directUpdate = Meteor.Collection.prototype.update;
	directRemove = Meteor.Collection.prototype.remove;

	// These are invoked when the method is called directly on the collection
	// from either the server or client. These are adapted to match the
	// function signature of the triggered version (adding userId)

	Meteor.Collection.prototype.insert = function (doc, callback) {
		var result, userId = getUserId.call(this);

		if (delegate.call(this, "before", "insert", userId, doc, callback) !== false) {
			result = directInsert.call(this, doc, callback);
			delegate.call(this, "after", "insert", userId, result && this._collection.findOne({_id: result}) || doc, callback);
		}

		return result;
	};

	Meteor.Collection.prototype.update = function (selector, modifier, options, callback) {
		var result, previous, userId = getUserId.call(this);

		if (delegate.call(this, "before", "update", userId, selector, modifier, options, callback) !== false) {
			previous = this._collection.find(selector, {reactive: false}).fetch();
			result = directUpdate.call(this, selector, modifier, options, callback);
			delegate.call(this, "after", "update", userId, selector, modifier, options, previous, callback);
		}

		return result;
	};

	Meteor.Collection.prototype.remove = function (selector, callback) {
		var result, previous, userId = getUserId.call(this);

		if (delegate.call(this, "before", "remove", userId, selector, callback) !== false) {
			previous = this._collection.find(selector, {reactive: false}).fetch();
			result = directRemove.call(this, selector, callback);
			delegate.call(this, "after", "remove", userId, selector, previous, callback);
		}

		return result;
	};

	if (Meteor.isServer) {
		_validatedInsert = Meteor.Collection.prototype._validatedInsert;
		_validatedUpdate = Meteor.Collection.prototype._validatedUpdate;
		_validatedRemove = Meteor.Collection.prototype._validatedRemove;

		// These are triggered on the server, but only when a client initiates
		// the method call. They act similarly to observes, but simply hi-jack
		// _validatedInsert. Additionally, they hi-jack the collection
		// instance's _collection.insert/update/remove temporarily in order to
		// maintain validator integrity (allow/deny).

		Meteor.Collection.prototype._validatedInsert = function (userId, doc) {
			var result, id;
			var self = this;

			var _insert = self._collection.insert;
			self._collection.insert = function (doc) {
				if (delegate.call(self, "before", "insert", userId, doc) !== false) {
					id = _insert.call(this, doc);
					delegate.call(self, "after", "insert", userId, id && this.findOne({_id: id}) || doc);
				}
			};
			_validatedRemove.call(self, userId, doc);
			self._collection.insert = _insert;
		};

		Meteor.Collection.prototype._validatedUpdate = function (userId, selector, mutator, options) {
			var result, previous;
			var self = this;

			var _update = self._collection.update;
			self._collection.update = function (selector, mutator, options) {
				if (delegate.call(self, "before", "update", userId, selector, mutator, options) !== false) {
					previous = this.find(selector).fetch();
					_update.call(this, selector, mutator, options);
					delegate.call(self, "after", "update", userId, selector, mutator, options, previous);
				}
			};
			_validatedRemove.call(self, userId, selector, mutator, options);
			self._collection.update = _update;
		};
<commit_msg>fix incorrect call to _validatedRemove for insert and update<commit_after>(function () {

	var directInsert, directUpdate, directRemove, _validatedInsert, _validatedUpdate, _validatedRemove;

	function delegate() {
		var i, len, c;
		var args = Array.prototype.slice.call(arguments);
		var type = args.shift();
		var verb = args.shift();

		if (this._x_matb33_hooks && this._x_matb33_hooks[type] && this._x_matb33_hooks[type][verb]) {
			for (i = 0, len = this._x_matb33_hooks[type][verb].length; i < len; i++) {
				c = this._x_matb33_hooks[type][verb][i];
				if (typeof c === "function") {
					if (c.apply(this, args) === false) {
						return false;
					}
				}
			}
		}
	}

	function getUserId() {
		var currentInvocation;

		try {
			currentInvocation = Meteor._CurrentInvocation.get();
		} catch (e) {}

		if (currentInvocation) {
			return currentInvocation.userId;
		} else {
			// this.userId will likely not be defined because no one usually
			// invokes collection.insert with a `.call(this)`... But if they
			// do, userId will be available to the end-callback.
			return this.userId || null;
		}
	}

	directInsert = Meteor.Collection.prototype.insert;
	directUpdate = Meteor.Collection.prototype.update;
	directRemove = Meteor.Collection.prototype.remove;

	// These are invoked when the method is called directly on the collection
	// from either the server or client. These are adapted to match the
	// function signature of the triggered version (adding userId)

	Meteor.Collection.prototype.insert = function (doc, callback) {
		var result, userId = getUserId.call(this);

		if (delegate.call(this, "before", "insert", userId, doc, callback) !== false) {
			result = directInsert.call(this, doc, callback);
			delegate.call(this, "after", "insert", userId, result && this._collection.findOne({_id: result}) || doc, callback);
		}

		return result;
	};

	Meteor.Collection.prototype.update = function (selector, modifier, options, callback) {
		var result, previous, userId = getUserId.call(this);

		if (delegate.call(this, "before", "update", userId, selector, modifier, options, callback) !== false) {
			previous = this._collection.find(selector, {reactive: false}).fetch();
			result = directUpdate.call(this, selector, modifier, options, callback);
			delegate.call(this, "after", "update", userId, selector, modifier, options, previous, callback);
		}

		return result;
	};

	Meteor.Collection.prototype.remove = function (selector, callback) {
		var result, previous, userId = getUserId.call(this);

		if (delegate.call(this, "before", "remove", userId, selector, callback) !== false) {
			previous = this._collection.find(selector, {reactive: false}).fetch();
			result = directRemove.call(this, selector, callback);
			delegate.call(this, "after", "remove", userId, selector, previous, callback);
		}

		return result;
	};

	if (Meteor.isServer) {
		_validatedInsert = Meteor.Collection.prototype._validatedInsert;
		_validatedUpdate = Meteor.Collection.prototype._validatedUpdate;
		_validatedRemove = Meteor.Collection.prototype._validatedRemove;

		// These are triggered on the server, but only when a client initiates
		// the method call. They act similarly to observes, but simply hi-jack
		// _validatedInsert. Additionally, they hi-jack the collection
		// instance's _collection.insert/update/remove temporarily in order to
		// maintain validator integrity (allow/deny).

		Meteor.Collection.prototype._validatedInsert = function (userId, doc) {
			var result, id;
			var self = this;

			var _insert = self._collection.insert;
			self._collection.insert = function (doc) {
				if (delegate.call(self, "before", "insert", userId, doc) !== false) {
					id = _insert.call(this, doc);
					delegate.call(self, "after", "insert", userId, id && this.findOne({_id: id}) || doc);
				}
			};
			_validatedInsert.call(self, userId, doc);
			self._collection.insert = _insert;
		};

		Meteor.Collection.prototype._validatedUpdate = function (userId, selector, mutator, options) {
			var result, previous;
			var self = this;

			var _update = self._collection.update;
			self._collection.update = function (selector, mutator, options) {
				if (delegate.call(self, "before", "update", userId, selector, mutator, options) !== false) {
					previous = this.find(selector).fetch();
					_update.call(this, selector, mutator, options);
					delegate.call(self, "after", "update", userId, selector, mutator, options, previous);
				}
			};
			_validatedUpdate.call(self, userId, selector, mutator, options);
			self._collection.update = _update;
		};

{'fraction_non_alphanumeric': 0.1336552178206957, 'fraction_numerical': 0.0024141336552178207, 'mean_word_length': 4.128868880135059, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5243813', 'n_tokens_mistral': 3078, 'n_tokens_neox': 2739, 'n_words': 750}