-
Notifications
You must be signed in to change notification settings - Fork 0
/
find.js
30 lines (25 loc) · 858 Bytes
/
find.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { CollectionHooks } from './collection-hooks'
CollectionHooks.defineAdvice('find', function (userId, _super, instance, aspects, getTransform, args, suppressAspects) {
const ctx = { context: this, _super, args }
const selector = CollectionHooks.normalizeSelector(instance._getFindSelector(args))
const options = instance._getFindOptions(args)
let abort
// before
if (!suppressAspects) {
aspects.before.forEach((o) => {
const r = o.aspect.call(ctx, userId, selector, options)
if (r === false) abort = true
})
if (abort) return instance.find(undefined)
}
const after = (cursor) => {
if (!suppressAspects) {
aspects.after.forEach((o) => {
o.aspect.call(ctx, userId, selector, options, cursor)
})
}
}
const ret = _super.call(this, selector, options)
after(ret)
return ret
})