PageSourceSearch

https://app.voxingpro.com/packages/matb33_collection-hooks.js?hash=f1f87bc2e36c884177945d27780c5feac3f558c7

js voxingpro.com collected 2026-10-02 14:39:58 UTC 29,638 bytes, 872 lines download raw bytes

1//////////////////////////////////////////////////////////////////////////
2//                                                                      //
3// This is a generated file. You can view the original                  //
4// source in your browser if your browser supports source maps.         //
5// Source maps are supported by all recent versions of Chrome, Safari,  //
6// and Firefox, and by Internet Explorer 11.                            //
7//                                                                      //
8//////////////////////////////////////////////////////////////////////////
9
10
11(function () {
12
13/* Imports */
14var Meteor = Package.meteor.Meteor;
15var global = Package.meteor.global;
16var meteorEnv = Package.meteor.meteorEnv;
17var Mongo = Package.mongo.Mongo;
18var Tracker = Package.tracker.Tracker;
19var Deps = Package.tracker.Deps;
20var _ = Package.underscore._;
21var EJSON = Package.ejson.EJSON;
22var LocalCollection = Package.minimongo.LocalCollection;
23var Minimongo = Package.minimongo.Minimongo;
24
25/* Package-scope variables */
26var CollectionHooks;
27
28(function(){
29
30////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
31//                                                                                                                    //
32// packages/matb33_collection-hooks/collection-hooks.js                                                               //
33//                                                                                                                    //
34////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
35                                                                                                                      //
36/* global Package Meteor Mongo LocalCollection CollectionHooks _ EJSON */
37/* eslint-disable no-proto, no-native-reassign */
38
39// Relevant AOP terminology:
40// Aspect: User code that runs before/after (hook)
41// Advice: Wrapper code that knows when to call user code (aspects)
42// Pointcut: before/after
43
44var advices = {}
45var Tracker = Package.tracker && Package.tracker.Tracker || Package.deps.Deps
46var publishUserId = Meteor.isServer && new Meteor.EnvironmentVariable()
47
48CollectionHooks = {
49  defaults: {
50    before: {insert: {}, update: {}, remove: {}, upsert: {}, find: {}, findOne: {}, all: {}},
51    after: {insert: {}, update: {}, remove: {}, find: {}, findOne: {}, all: {}},
52    all: {insert: {}, update: {}, remove: {}, find: {}, findOne: {}, all: {}}
53  },
54  directEnv: new Meteor.EnvironmentVariable(),
55  directOp: function directOp (func) {
56    return this.directEnv.withValue(true, func)
57  },
58  hookedOp: function hookedOp (func) {
59    return this.directEnv.withValue(false, func)
60  }
61}
62
63CollectionHooks.getUserId = function getUserId () {
64  var userId
65
66  if (Meteor.isClient) {
67    Tracker.nonreactive(function () {
68      userId = Meteor.userId && Meteor.userId()
69    })
70  }
71
72  if (Meteor.isServer) {
73    try {
74      // Will throw an error unless within method call.
75      // Attempt to recover gracefully by catching:
76      userId = Meteor.userId && Meteor.userId()
77    } catch (e) {}
78
79    if (!userId) {
80      // Get the userId if we are in a publish function.
81      userId = publishUserId.get()
82    }
83  }
84
85  return userId
86}
87
88CollectionHooks.extendCollectionInstance = function extendCollectionInstance (self, constructor) {
89  // Offer a public API to allow the user to define aspects
90  // Example: collection.before.insert(func);
91  _.each(['before', 'after'], function (pointcut) {
92    _.each(advices, function (advice, method) {
93      if (advice === 'upsert' && pointcut === 'after') return
94
95      Meteor._ensure(self, pointcut, method)
96      Meteor._ensure(self, '_hookAspects', method)
97
98      self._hookAspects[method][pointcut] = []
99      self[pointcut][method] = function (aspect, options) {
100        var len = self._hookAspects[method][pointcut].push({
101          aspect: aspect,
102          options: CollectionHooks.initOptions(options, pointcut, method)
103        })
104
105        return {
106          replace: function (aspect, options) {
107            self._hookAspects[method][pointcut].splice(len - 1, 1, {
108              aspect: aspect,
109              options: CollectionHooks.initOptions(options, pointcut, method)
110            })
111          },
112          remove: function () {
113            self._hookAspects[method][pointcut].splice(len - 1, 1)
114          }
115        }
116      }
117    })
118  })
119
120  // Offer a publicly accessible object to allow the user to define
121  // collection-wide hook options.
122  // Example: collection.hookOptions.after.update = {fetchPrevious: false};
123  self.hookOptions = EJSON.clone(CollectionHooks.defaults)
124
125  // Wrap mutator methods, letting the defined advice do the work
126  _.each(advices, function (advice, method) {
127    var collection = Meteor.isClient || method === 'upsert' ? self : self._collection
128
129    // Store a reference to the original mutator method
130    var _super = collection[method]
131
132    Meteor._ensure(self, 'direct', method)
133    self.direct[method] = function () {
134      var args = arguments
135      return CollectionHooks.directOp(function () {
136        return constructor.prototype[method].apply(self, args)
137      })
138    }
139
140    collection[method] = function () {
141      if (CollectionHooks.directEnv.get() === true) {
142        return _super.apply(collection, arguments)
143      }
144
145      // NOTE: should we decide to force `update` with `{upsert:true}` to use
146      // the `upsert` hooks, this is what will accomplish it. It's important to
147      // realize that Meteor won't distinguish between an `update` and an
148      // `insert` though, so we'll end up with `after.update` getting called
149      // even on an `insert`. That's why we've chosen to disable this for now.
150      // if (method === "update" && _.isObject(arguments[2]) && arguments[2].upsert) {
151      //   method = "upsert";
152      //   advice = CollectionHooks.getAdvice(method);
153      // }
154
155      return advice.call(this,
156        CollectionHooks.getUserId(),
157        _super,
158        self,
159        method === 'upsert' ? {
160          insert: self._hookAspects.insert || {},
161          update: self._hookAspects.update || {},
162          upsert: self._hookAspects.upsert || {}
163        } : self._hookAspects[method] || {},
164        function (doc) {
165          return (
166            _.isFunction(self._transform)
167            ? function (d) { return self._transform(d || doc) }
168            : function (d) { return d || doc }
169          )
170        },
171        _.toArray(arguments),
172        false
173      )
174    }
175  })
176}
177
178CollectionHooks.defineAdvice = function defineAdvice (method, advice) {
179  advices[method] = advice
180}
181
182CollectionHooks.getAdvice = function getAdvice (method) {
183  return advices[method]
184}
185
186CollectionHooks.initOptions = function initOptions (options, pointcut, method) {
187  return CollectionHooks.extendOptions(CollectionHooks.defaults, options, pointcut, method)
188}
189
190CollectionHooks.extendOptions = function extendOptions (source, options, pointcut, method) {
191  options = _.extend(options || {}, source.all.all)
192  options = _.extend(options, source[pointcut].all)
193  options = _.extend(options, source.all[method])
194  options = _.extend(options, source[pointcut][method])
195  return options
196}
197
198CollectionHooks.getDocs = function getDocs (collection, selector, options) {
199  var findOptions = {transform: null, reactive: false} // added reactive: false
200
201  /*
202  // No "fetch" support at this time.
203  if (!this._validators.fetchAllFields) {
204    findOptions.fields = {};
205    _.each(this._validators.fetch, function(fieldName) {
206      findOptions.fields[fieldName] = 1;
207    });
208  }
209  */
210
211  // Bit of a magic condition here... only "update" passes options, so this is
212  // only relevant to when update calls getDocs:
213  if (options) {
214    // This was added because in our case, we are potentially iterating over
215    // multiple docs. If multi isn't enabled, force a limit (almost like
216    // findOne), as the default for update without multi enabled is to affect
217    // only the first matched document:
218    if (!options.multi) {
219      findOptions.limit = 1
220    }
221  }
222
223  // Unlike validators, we iterate over multiple docs, so use
224  // find instead of findOne:
225  return collection.find(selector, findOptions)
226}
227
228// This function contains a snippet of code pulled and modified from:
229// ~/.meteor/packages/mongo-livedata/collection.js
230// It's contained in these utility functions to make updates easier for us in
231// case this code changes.
232CollectionHooks.getFields = function getFields (mutator) {
233  // compute modified fields
234  var fields = []
235
236  _.each(mutator, function (params, op) {
237    // ====ADDED START=======================
238    if (_.contains(['$set', '$unset', '$inc', '$push', '$pull', '$pop', '$rename', '$pullAll', '$addToSet', '$bit'], op)) {
239    // ====ADDED END=========================
240      _.each(_.keys(params), function (field) {
241        // treat dotted fields as if they are replacing their
242        // top-level part
243        if (field.indexOf('.') !== -1) {
244          field = field.substring(0, field.indexOf('.'))
245        }
246
247        // record the field we are trying to change
248        if (!_.contains(fields, field)) {
249          fields.push(field)
250        }
251      })
252      // ====ADDED START=======================
253    } else {
254      fields.push(op)
255    }
256    // ====ADDED END=========================
257  })
258
259  return fields
260}
261
262CollectionHooks.reassignPrototype = function reassignPrototype (instance, constr) {
263  var hasSetPrototypeOf = typeof Object.setPrototypeOf === 'function'
264
265  if (!constr) constr = typeof Mongo !== 'undefined' ? Mongo.Collection : Meteor.Collection
266
267  // __proto__ is not available in < IE11
268  // Note: Assigning a prototype dynamically has performance implications
269  if (hasSetPrototypeOf) {
270    Object.setPrototypeOf(instance, constr.prototype)
271  } else if (instance.__proto__) {
272    instance.__proto__ = constr.prototype
273  }
274}
275
276CollectionHooks.wrapCollection = function wrapCollection (ns, as) {
277  if (!as._CollectionConstructor) as._CollectionConstructor = as.Collection
278  if (!as._CollectionPrototype) as._CollectionPrototype = new as.Collection(null)
279
280  var constructor = as._CollectionConstructor
281  var proto = as._CollectionPrototype
282
283  ns.Collection = function () {
284    var ret = constructor.apply(this, arguments)
285    CollectionHooks.extendCollectionInstance(this, constructor)
286    return ret
287  }
288
289  ns.Collection.prototype = proto
290  ns.Collection.prototype.constructor = ns.Collection
291
292  for (var prop in constructor) {
293    if (constructor.hasOwnProperty(prop)) {
294      ns.Collection[prop] = constructor[prop]
295    }
296  }
297}
298
299CollectionHooks.modify = LocalCollection._modify
300
301if (typeof Mongo !== 'undefined') {
302  CollectionHooks.wrapCollection(Meteor, Mongo)
303  CollectionHooks.wrapCollection(Mongo, Mongo)
304} else {
305  CollectionHooks.wrapCollection(Meteor, Meteor)
306}
307
308if (Meteor.isServer) {
309  var _publish = Meteor.publish
310  Meteor.publish = function (name, func) {
311    return _publish.call(this, name, function () {
312      // This function is called repeatedly in publications
313      var ctx = this
314      var args = arguments
315      return publishUserId.withValue(ctx && ctx.userId, function () {
316        return func.apply(ctx, args)
317      })
318    })
319  }
320
321  // Make the above available for packages with hooks that want to determine
322  // whether they are running inside a publish function or not.
323  CollectionHooks.isWithinPublish = function isWithinPublish () {
324    return publishUserId.get() !== undefined
325  }
326}
327
328////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
329
330}).call(this);
331
332
333
334
335
336
337(function(){
338
339////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
340//                                                                                                                    //
341// packages/matb33_collection-hooks/insert.js                                                                         //
342//                                                                                                                    //
343////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
344                                                                                                                      //
345/* global CollectionHooks _ EJSON */
346
347CollectionHooks.defineAdvice('insert', function (userId, _super, instance, aspects, getTransform, args, suppressAspects) {
348  var self = this
349  var ctx = {context: self, _super: _super, args: args}
350  var callback = _.last(args)
351  var async = _.isFunction(callback)
352  var abort, ret
353
354  // args[0] : doc
355  // args[1] : callback
356
357  // before
358  if (!suppressAspects) {
359    try {
360      _.each(aspects.before, function (o) {
361        var r = o.aspect.call(_.extend({transform: getTransform(args[0])}, ctx), userId, args[0])
362        if (r === false) abort = true
363      })
364
365      if (abort) return false
366    } catch (e) {
367      if (async) return callback.call(self, e)
368      throw e
369    }
370  }
371
372  function after (id, err) {
373    var doc = args[0]
374    if (id) {
375      // In some cases (namely Meteor.users on Meteor 1.4+), the _id property
376      // is a raw mongo _id object. We need to extract the _id from this object
377      if (_.isObject(id) && id.ops) {
378        // If _str then collection is using Mongo.ObjectID as ids
379        if (doc._id._str) {
380          id = new Mongo.ObjectID(doc._id._str.toString());
381        } else {
382          id = id.ops && id.ops[0] && id.ops[0]._id
383        }
384      }
385      doc = EJSON.clone(args[0])
386      doc._id = id
387    }
388    if (!suppressAspects) {
389      var lctx = _.extend({transform: getTransform(doc), _id: id, err: err}, ctx)
390      _.each(aspects.after, function (o) {
391        o.aspect.call(lctx, userId, doc)
392      })
393    }
394    return id
395  }
396
397  if (async) {
398    args[args.length - 1] = function (err, obj) {
399      after(obj && obj[0] && obj[0]._id || obj, err)
400      return callback.apply(this, arguments)
401    }
402    return _super.apply(self, args)
403  } else {
404    ret = _super.apply(self, args)
405    return after(ret && ret[0] && ret[0]._id || ret)
406  }
407})
408
409////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
410
411}).call(this);
412
413
414
415
416
417
418(function(){
419
420////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
421//                                                                                                                    //
422// packages/matb33_collection-hooks/update.js                                                                         //
423//                                                                                                                    //
424////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
425                                                                                                                      //
426/* global CollectionHooks _ EJSON */
427
428CollectionHooks.defineAdvice('update', function (userId, _super, instance, aspects, getTransform, args, suppressAspects) {
429  var self = this
430  var ctx = {context: self, _super: _super, args: args}
431  var callback = _.last(args)
432  var async = _.isFunction(callback)
433  var docs
434  var docIds
435  var fields
436  var abort
437  var prev = {}
438  var collection = _.has(self, '_collection') ? self._collection : self
439
440  // args[0] : selector
441  // args[1] : mutator
442  // args[2] : options (optional)
443  // args[3] : callback
444
445  if (_.isFunction(args[2])) {
446    callback = args[2]
447    args[2] = {}
448  }
449
450  if (!suppressAspects) {
451    try {
452      if (aspects.before || aspects.after) {
453        fields = CollectionHooks.getFields(args[1])
454        docs = CollectionHooks.getDocs.call(self, collection, args[0], args[2]).fetch()
455        docIds = _.map(docs, function (doc) { return doc._id })
456      }
457
458      // copy originals for convenience for the 'after' pointcut
459      if (aspects.after) {
460        prev.mutator = EJSON.clone(args[1])
461        prev.options = EJSON.clone(args[2])
462        if (
463          _.some(aspects.after, function (o) { return o.options.fetchPrevious !== false }) &&
464          CollectionHooks.extendOptions(instance.hookOptions, {}, 'after', 'update').fetchPrevious !== false
465        ) {
466          prev.docs = {}
467          _.each(docs, function (doc) {
468            prev.docs[doc._id] = EJSON.clone(doc)
469          })
470        }
471      }
472
473      // before
474      _.each(aspects.before, function (o) {
475        _.each(docs, function (doc) {
476          var r = o.aspect.call(_.extend({transform: getTransform(doc)}, ctx), userId, doc, fields, args[1], args[2])
477          if (r === false) abort = true
478        })
479      })
480
481      if (abort) return false
482    } catch (e) {
483      if (async) return callback.call(self, e)
484      throw e
485    }
486  }
487
488  function after (affected, err) {
489    if (!suppressAspects) {
490      var fields = CollectionHooks.getFields(args[1])
491      var docs = CollectionHooks.getDocs.call(self, collection, {_id: {$in: docIds}}, args[2]).fetch()
492
493      _.each(aspects.after, function (o) {
494        _.each(docs, function (doc) {
495          o.aspect.call(_.extend({
496            transform: getTransform(doc),
497            previous: prev.docs && prev.docs[doc._id],
498            affected: affected,
499            err: err
500          }, ctx), userId, doc, fields, prev.mutator, prev.options)
501        })
502      })
503    }
504  }
505
506  if (async) {
507    args[args.length - 1] = function (err, affected) {
508      after(affected, err)
509      return callback.apply(this, arguments)
510    }
511    return _super.apply(this, args)
512  } else {
513    var affected = _super.apply(self, args)
514    after(affected)
515    return affected
516  }
517})
518
519////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
520
521}).call(this);
522
523
524
525
526
527
528(function(){
529
530////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
531//                                                                                                                    //
532// packages/matb33_collection-hooks/remove.js                                                                         //
533//                                                                                                                    //
534////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
535                                                                                                                      //
536/* global CollectionHooks _ EJSON */
537
538CollectionHooks.defineAdvice('remove', function (userId, _super, instance, aspects, getTransform, args, suppressAspects) {
539  var self = this
540  var ctx = {context: self, _super: _super, args: args}
541  var callback = _.last(args)
542  var async = _.isFunction(callback)
543  var docs
544  var abort
545  var prev = []
546  var collection = _.has(self, '_collection') ? self._collection : self
547
548  // args[0] : selector
549  // args[1] : callback
550
551  if (!suppressAspects) {
552    try {
553      if (aspects.before || aspects.after) {
554        docs = CollectionHooks.getDocs.call(self, collection, args[0]).fetch()
555      }
556
557      // copy originals for convenience for the 'after' pointcut
558      if (aspects.after) {
559        _.each(docs, function (doc) {
560          prev.push(EJSON.clone(doc))
561        })
562      }
563
564      // before
565      _.each(aspects.before, function (o) {
566        _.each(docs, function (doc) {
567          var r = o.aspect.call(_.extend({transform: getTransform(doc)}, ctx), userId, doc)
568          if (r === false) abort = true
569        })
570      })
571
572      if (abort) return false
573    } catch (e) {
574      if (async) return callback.call(self, e)
575      throw e
576    }
577  }
578
579  function after (err) {
580    if (!suppressAspects) {
581      _.each(aspects.after, function (o) {
582        _.each(prev, function (doc) {
583          o.aspect.call(_.extend({transform: getTransform(doc), err: err}, ctx), userId, doc)
584        })
585      })
586    }
587  }
588
589  if (async) {
590    args[args.length - 1] = function (err) {
591      after(err)
592      return callback.apply(this, arguments)
593    }
594    return _super.apply(self, args)
595  } else {
596    var result = _super.apply(self, args)
597    after()
598    return result
599  }
600})
601
602////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
603
604}).call(this);
605
606
607
608
609
610
611(function(){
612
613////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
614//                                                                                                                    //
615// packages/matb33_collection-hooks/upsert.js                                                                         //
616//                                                                                                                    //
617////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
618                                                                                                                      //
619/* global CollectionHooks _ EJSON */
620
621CollectionHooks.defineAdvice('upsert', function (userId, _super, instance, aspectGroup, getTransform, args, suppressAspects) {
622  var self = this
623  var ctx = {context: self, _super: _super, args: args}
624  var callback = _.last(args)
625  var async = _.isFunction(callback)
626  var docs
627  var docIds
628  var abort
629  var prev = {}
630  var collection = _.has(self, '_collection') ? self._collection : self
631
632  // args[0] : selector
633  // args[1] : mutator
634  // args[2] : options (optional)
635  // args[3] : callback
636
637  if (_.isFunction(args[2])) {
638    callback = args[2]
639    args[2] = {}
640  }
641
642  if (!suppressAspects) {
643    if (aspectGroup.upsert.before) {
644      docs = CollectionHooks.getDocs.call(self, collection, args[0], args[2]).fetch()
645      docIds = _.map(docs, function (doc) { return doc._id })
646    }
647
648    // copy originals for convenience for the 'after' pointcut
649    if (aspectGroup.update.after) {
650      if (_.some(aspectGroup.update.after, function (o) { return o.options.fetchPrevious !== false }) &&
651          CollectionHooks.extendOptions(instance.hookOptions, {}, 'after', 'update').fetchPrevious !== false) {
652        prev.mutator = EJSON.clone(args[1])
653        prev.options = EJSON.clone(args[2])
654        prev.docs = {}
655        _.each(docs, function (doc) {
656          prev.docs[doc._id] = EJSON.clone(doc)
657        })
658      }
659    }
660
661    // before
662    if (!suppressAspects) {
663      _.each(aspectGroup.upsert.before, function (o) {
664        var r = o.aspect.call(ctx, userId, args[0], args[1], args[2])
665        if (r === false) abort = true
666      })
667
668      if (abort) return false
669    }
670  }
671
672  function afterUpdate (affected, err) {
673    if (!suppressAspects) {
674      var fields = CollectionHooks.getFields(args[1])
675      var docs = CollectionHooks.getDocs.call(self, collection, {_id: {$in: docIds}}, args[2]).fetch()
676
677      _.each(aspectGroup.update.after, function (o) {
678        _.each(docs, function (doc) {
679          o.aspect.call(_.extend({
680            transform: getTransform(doc),
681            previous: prev.docs && prev.docs[doc._id],
682            affected: affected,
683            err: err
684          }, ctx), userId, doc, fields, prev.mutator, prev.options)
685        })
686      })
687    }
688  }
689
690  function afterInsert (id, err) {
691    if (!suppressAspects) {
692      var doc = CollectionHooks.getDocs.call(self, collection, {_id: id}, args[0], {}).fetch()[0] // 3rd argument passes empty object which causes magic logic to imply limit:1
693      var lctx = _.extend({transform: getTransform(doc), _id: id, err: err}, ctx)
694      _.each(aspectGroup.insert.after, function (o) {
695        o.aspect.call(lctx, userId, doc)
696      })
697    }
698  }
699
700  if (async) {
701    args[args.length - 1] = function (err, ret) {
702      if (err || ret.insertedId) {
703        // Send any errors to afterInsert
704        afterInsert(ret && ret.insertedId, err)
705      } else {
706        afterUpdate(ret && ret.numberAffected, err) // Note that err can never reach here
707      }
708
709      return CollectionHooks.hookedOp(function () {
710        return callback.call(this, err, ret)
711      })
712    }
713
714    return CollectionHooks.directOp(function () {
715      return _super.apply(self, args)
716    })
717  } else {
718    var ret = CollectionHooks.directOp(function () {
719      return _super.apply(self, args)
720    })
721
722    if (ret && ret.insertedId) {
723      afterInsert(ret && ret.insertedId)
724    } else {
725      afterUpdate(ret && ret.numberAffected)
726    }
727
728    return ret
729  }
730})
731
732////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
733
734}).call(this);
735
736
737
738
739
740
741(function(){
742
743////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
744//                                                                                                                    //
745// packages/matb33_collection-hooks/find.js                                                                           //
746//                                                                                                                    //
747////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
748                                                                                                                      //
749/* global CollectionHooks _ */
750
751CollectionHooks.defineAdvice('find', function (userId, _super, instance, aspects, getTransform, args, suppressAspects) {
752  var self = this
753  var ctx = {context: self, _super: _super, args: args}
754  var ret, abort
755
756  // args[0] : selector
757  // args[1] : options
758
759  // before
760  if (!suppressAspects) {
761    _.each(aspects.before, function (o) {
762      var r = o.aspect.call(ctx, userId, args[0], args[1])
763      if (r === false) abort = true
764    })
765
766    if (abort) return false
767  }
768
769  function after (cursor) {
770    if (!suppressAspects) {
771      _.each(aspects.after, function (o) {
772        o.aspect.call(ctx, userId, args[0], args[1], cursor)
773      })
774    }
775  }
776
777  ret = _super.apply(self, args)
778  after(ret)
779
780  return ret
781})
782
783////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
784
785}).call(this);
786
787
788
789
790
791
792(function(){
793
794////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
795//                                                                                                                    //
796// packages/matb33_collection-hooks/findone.js                                                                        //
797//                                                                                                                    //
798////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
799                                                                                                                      //
800/* global CollectionHooks _ */
801
802CollectionHooks.defineAdvice('findOne', function (userId, _super, instance, aspects, getTransform, args, suppressAspects) {
803  var self = this
804  var ctx = {context: self, _super: _super, args: args}
805  var ret, abort
806
807  // args[0] : selector
808  // args[1] : options
809
810  // before
811  if (!suppressAspects) {
812    _.each(aspects.before, function (o) {
813      var r = o.aspect.call(ctx, userId, args[0], args[1])
814      if (r === false) abort = true
815    })
816
817    if (abort) return false
818  }
819
820  function after (doc) {
821    if (!suppressAspects) {
822      _.each(aspects.after, function (o) {
823        o.aspect.call(ctx, userId, args[0], args[1], doc)
824      })
825    }
826  }
827
828  ret = _super.apply(self, args)
829  after(ret)
830
831  return ret
832})
833
834////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
835
836}).call(this);
837
838
839
840
841
842
843(function(){
844
845////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
846//                                                                                                                    //
847// packages/matb33_collection-hooks/users-compat.js                                                                   //
848//                                                                                                                    //
849////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
850                                                                                                                      //
851/* global CollectionHooks Meteor Mongo */
852
853if (Meteor.users) {
854  // If Meteor.users has been instantiated, attempt to re-assign its prototype:
855  CollectionHooks.reassignPrototype(Meteor.users)
856
857  // Next, give it the hook aspects:
858  var Collection = typeof Mongo !== 'undefined' && typeof Mongo.Collection !== 'undefined' ? Mongo.Collection : Meteor.Collection
859  CollectionHooks.extendCollectionInstance(Meteor.users, Collection)
860}
861
862////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
863
864}).call(this);
865
866
867/* Exports */
868Package._define("matb33:collection-hooks", {
869  CollectionHooks: CollectionHooks
870});
871
872})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.