This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.coffee
45 lines (36 loc) · 1.44 KB
/
util.coffee
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
abbrevArrays = (val) ->
if !val? || typeof val != 'object'
return val
if R.isArrayLike val
#console.log "treating val as array"
if val.length < 6
return R.map ((item) -> abbrevArrays item), val
else
return ["#{val.length} items"]
else
#console.log "treating val as obj"
R.map ((item) -> abbrevArrays item), val
exports.abbrevArrays = abbrevArrays
# Psi combinator (`on` in Haskell), except with function arguments reversed because otherwise they don't
# read well in prefix form
exports.on = R.curry (g, f, x, y) -> f g(x), g(y) # f(g(x))(g(y))
exports.getHQPermissions = (projectId, projectPermissions, userPermissions) ->
permittedProjects = if R.has "all", userPermissions
"all"
else
R.keys userPermissions
if projectId?
reports = R.merge projectPermissions.reports, userPermissions[projectId]?.reports
R.mergeAll [ projectPermissions, userPermissions[projectId], permittedProjects: permittedProjects, reports: reports ]
else
permittedProjects: permittedProjects
exports.takePipeSample = R.curry (name, shouldTakeSample, debugDataObj, pipeState) ->
#logs?.messages.push "got to #{name}"
if shouldTakeSample
debugDataObj[name] = pipeState
else
# Do nothing
pipeState
exports.logPipeState = R.curry (label, pipeState) ->
console.log "#{label} = #{JSON.stringify pipeState}"
pipeState