-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
88 lines (75 loc) · 1.63 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const R = require(`./lib/ramda`)
const apis = require(`./lib/apis`)
const Call = require(`./lib/Call`)
const getFunc = R.ifElse(
R.propSatisfies(R.isTrue, `ispromise`),
R.always(Call.callP),
R.always(Call.call)
)
const applyArgs = v2 =>
R.compose(
R.apply(getFunc(v2)),
R.append(v2)
)
const makeFunc = path_name =>
R.compose(
v2 => R.unapply(applyArgs(v2)),
R.assoc(`path_name`, path_name)
)
const getFuncModels = path_name =>
R.map(makeFunc(path_name))({
alis: {},
"alis.p": { ispromise: true },
"alis.oauth": { isOauth: true },
"alis.oauth.p": { ispromise: true, isOauth: true }
})
const rmAlis = R.compose(
R.sliceFrom(1),
R.split(`.`)
)
const getMethodPath = key =>
R.compose(
R.insertAll(0, rmAlis(key)),
R.sliceFrom(1),
R.split(`/`)
)
const makeMethod = R.curry((path_name, obj) =>
R.compose(
R.values,
R.mapObjIndexed((func, key) =>
R.compose(
R.pair(R.__, func),
getMethodPath(key)
)(path_name)
)
)(obj)
)
const getMethodAssocComposition = R.chain(R.ap(makeMethod, getFuncModels))
let alis = { p: {}, oauth: { p: {} } }
const isLastElem = index =>
R.compose(
R.equals(index),
R.dec,
R.length,
R.prop(0)
)
const assocMethods = R.forEach(path_func =>
R.addIndex(R.reduce)(
(obj, key, index) =>
R.when(
R.isNil,
() =>
(obj[key] = R.ifElse(isLastElem(index), R.prop(1), R.always({}))(
path_func
))
)(obj[key]),
alis
)(path_func[0])
)
R.compose(
assocMethods,
getMethodAssocComposition,
R.sortBy(R.length),
R.keys
)(apis)
module.exports = alis