-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
72 lines (66 loc) · 1.88 KB
/
index.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import F from 'futil'
import _ from 'lodash/fp.js'
import {
Tree,
getRelevantFilters,
attachFilters,
getProvider as getProviderUtil,
runTypeFunction as runTypeFunctionUtil,
} from './utils.js'
let process = _.curry(async ({ providers, schemas }, group, options = {}) => {
let getProvider = getProviderUtil(providers, schemas)
let getSchema = (schema) => schemas[schema]
let runTypeFunction = runTypeFunctionUtil({
options,
getSchema,
getProvider,
processGroup: (g, options) => process({ providers, schemas }, g, options),
})
await attachFilters(runTypeFunction)(group)
Tree.walk((node) => {
// Skip groups
if (!Tree.traverse(node))
node._meta.relevantFilters = getRelevantFilters(
getProvider(node).groupCombinator,
node._meta.path,
group
)
})(group)
await Tree.walkAsync(async (node) => {
let validContext = await runTypeFunction('validContext', node)
// Reject filterOnly
if (node.filterOnly || !validContext) {
if (!options.debug) delete node._meta
return
}
let curriedSearch = _.partial(getProvider(node).runSearch, [
options,
node,
getSchema(node.schema),
node._meta.relevantFilters,
])
node.context = await runTypeFunction('result', node, curriedSearch).catch(
(error) => {
throw F.extendOn(error, { node })
}
)
let path = node._meta.path
if (!options.debug) delete node._meta
if (options.onResult) options.onResult({ path, node })
})(group)
return group
})
export default process
// Psuedo code process
// -----
// add _meta
// add materializedPaths
// add filter (reject !hasValue, reject contextOnly)
// iterate DFS
// get filters for context (by materialized path, filter lookup)
// reject filterOnly
// add resultProcessor (aka `query`)
// SEARCH
// process result, loop ^
// onResult
// return results