FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
koding/node_modules_koding/mongoop/index.js at master · stingbyte/koding · GitHub
stingbyte
/
koding
Public
forked from
koding/koding
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
koding
/
node_modules_koding
/
mongoop
/
index.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
183 lines (161 loc) · 5.29 KB
Breadcrumbs
koding
/
node_modules_koding
/
mongoop
/
index.js
Copy path
File metadata and controls
executable file
·
183 lines (161 loc) · 5.29 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
(
function
(
)
{
var
MongoOp
,
__slice
=
[
]
.
slice
;
MongoOp
=
(
function
(
)
{
var
deleteAt
,
getAt
,
isEqual
,
keys
,
popAt
,
pushAt
,
setAt
,
_ref
;
_ref
=
require
(
'jspath'
)
,
setAt
=
_ref
.
setAt
,
getAt
=
_ref
.
getAt
,
deleteAt
=
_ref
.
deleteAt
,
pushAt
=
_ref
.
pushAt
,
popAt
=
_ref
.
popAt
;
keys
=
Object
.
keys
;
isEqual
=
require
(
'deep-equal'
)
;
function
MongoOp
(
operation
)
{
if
(
!
(
this
instanceof
MongoOp
)
)
{
return
new
MongoOp
(
operation
)
;
}
this
.
operation
=
operation
;
}
MongoOp
.
prototype
.
applyTo
=
function
(
target
)
{
this
.
result
=
{
}
;
keys
(
this
.
operation
)
.
forEach
(
(
function
(
_this
)
{
return
function
(
operator
)
{
if
(
'function'
!==
typeof
_this
[
operator
]
)
{
throw
new
Error
(
"Unrecognized operator: "
+
operator
)
;
}
else
{
return
_this
[
operator
]
(
target
,
_this
.
operation
[
operator
]
)
;
}
}
;
}
)
(
this
)
)
;
return
this
;
}
;
MongoOp
.
prototype
.
map
=
function
(
fn
)
{
var
op
;
op
=
this
.
operation
;
this
.
operation
=
{
}
;
keys
(
op
)
.
forEach
(
(
function
(
_this
)
{
return
function
(
operator
)
{
return
_this
.
operation
[
operator
]
=
fn
(
operator
,
op
[
operator
]
)
;
}
;
}
)
(
this
)
)
;
return
this
;
}
;
MongoOp
.
prototype
.
forEachField
=
function
(
fields
,
fn
)
{
return
keys
(
fields
)
.
map
(
(
function
(
_this
)
{
return
function
(
path
)
{
var
val
;
val
=
fields
[
path
]
;
return
_this
.
result
[
path
]
=
fn
(
path
,
val
)
;
}
;
}
)
(
this
)
)
;
}
;
MongoOp
.
prototype
.
$addToSet
=
(
function
(
)
{
var
$addToSet
;
$addToSet
=
function
(
collection
,
val
)
{
var
item
,
matchFound
,
_i
,
_len
;
matchFound
=
false
;
for
(
_i
=
0
,
_len
=
collection
.
length
;
_i
<
_len
;
_i
++
)
{
item
=
collection
[
_i
]
;
if
(
!
(
isEqual
(
item
,
val
)
)
)
{
continue
;
}
matchFound
=
true
;
break
;
}
if
(
!
matchFound
)
{
return
collection
.
push
(
val
)
;
}
}
;
return
function
(
target
,
fields
)
{
return
this
.
forEachField
(
fields
,
(
function
(
_this
)
{
return
function
(
path
,
val
)
{
var
child
,
collection
,
_i
,
_len
,
_ref1
,
_results
;
collection
=
getAt
(
target
,
path
)
;
if
(
collection
==
null
)
{
collection
=
[
]
;
setAt
(
target
,
path
,
collection
)
;
}
if
(
val
.
$each
!=
null
)
{
_ref1
=
val
.
$each
;
_results
=
[
]
;
for
(
_i
=
0
,
_len
=
_ref1
.
length
;
_i
<
_len
;
_i
++
)
{
child
=
_ref1
[
_i
]
;
_results
.
push
(
$addToSet
(
collection
,
child
)
)
;
}
return
_results
;
}
else
{
return
$addToSet
(
collection
,
val
)
;
}
}
;
}
)
(
this
)
)
;
}
;
}
)
(
)
;
MongoOp
.
prototype
.
$push
=
function
(
target
,
fields
)
{
return
this
.
forEachField
(
fields
,
function
(
path
,
val
)
{
return
pushAt
(
target
,
path
,
val
)
;
}
)
;
}
;
MongoOp
.
prototype
.
$pushAll
=
function
(
target
,
fields
)
{
return
this
.
forEachField
(
fields
,
function
(
path
,
vals
)
{
return
pushAt
.
apply
(
null
,
[
target
,
path
]
.
concat
(
__slice
.
call
(
vals
)
)
)
;
}
)
;
}
;
MongoOp
.
prototype
.
$pull
=
function
(
)
{
throw
new
Error
(
"This version of MongoOp does not implement $pull...\nLook for that in a future version. You can use $pullAll instead."
)
;
}
;
MongoOp
.
prototype
.
$pullAll
=
function
(
target
,
fields
)
{
return
this
.
forEachField
(
fields
,
function
(
path
,
val
)
{
var
collection
,
i
,
index
,
_results
;
collection
=
getAt
(
target
,
path
)
;
index
=
0
;
_results
=
[
]
;
while
(
collection
&&
index
<
collection
.
length
)
{
i
=
index
++
;
if
(
isEqual
(
collection
[
i
]
,
val
)
)
{
_results
.
push
(
collection
.
splice
(
i
,
1
)
)
;
}
else
{
_results
.
push
(
void
0
)
;
}
}
return
_results
;
}
)
;
}
;
MongoOp
.
prototype
.
$pop
=
function
(
target
,
fields
)
{
return
this
.
forEachField
(
fields
,
function
(
path
)
{
return
popAt
(
target
,
path
)
;
}
)
;
}
;
MongoOp
.
prototype
.
$set
=
function
(
target
,
fields
)
{
return
this
.
forEachField
(
fields
,
function
(
path
,
val
)
{
setAt
(
target
,
path
,
val
)
;
return
val
;
}
)
;
}
;
MongoOp
.
prototype
.
$unset
=
function
(
target
,
fields
)
{
return
this
.
forEachField
(
fields
,
function
(
path
)
{
return
deleteAt
(
target
,
path
)
;
}
)
;
}
;
MongoOp
.
prototype
.
$rename
=
function
(
target
,
fields
)
{
return
this
.
forEachField
(
fields
,
function
(
oldPath
,
newPath
)
{
var
val
;
val
=
getAt
(
target
,
oldPath
)
;
deleteAt
(
target
,
oldPath
)
;
return
setAt
(
target
,
newPath
,
val
)
;
}
)
;
}
;
MongoOp
.
prototype
.
$inc
=
(
function
(
)
{
var
$inc
;
$inc
=
function
(
val
,
amt
)
{
return
val
+=
amt
;
}
;
return
function
(
target
,
fields
)
{
return
this
.
forEachField
(
fields
,
function
(
path
,
val
)
{
return
setAt
(
target
,
path
,
$inc
(
getAt
(
target
,
path
)
,
val
)
)
;
}
)
;
}
;
}
)
(
)
;
return
MongoOp
;
}
)
(
)
;
if
(
(
typeof
module
!==
"undefined"
&&
module
!==
null
?
module
.
exports
:
void
0
)
!=
null
)
{
module
.
exports
=
MongoOp
;
}
else
if
(
typeof
window
!==
"undefined"
&&
window
!==
null
)
{
window
[
'MongoOp'
]
=
MongoOp
;
}
}
)
.
call
(
this
)
;
Back
|
FazBrowse Home
|
New Git URL