1
- import JSData from 'js-data' ;
2
- import redis from 'redis' ;
3
- import underscore from 'mout/string/underscore' ;
4
- import guid from 'mout/random/guid' ;
5
- import omit from 'mout/object/omit' ;
1
+ let JSData = require ( 'js-data' ) ;
2
+ let redis = require ( 'redis' ) ;
3
+ let underscore = require ( 'mout/string/underscore' ) ;
4
+ let guid = require ( 'mout/random/guid' ) ;
6
5
let { DSUtils } = JSData ;
7
- let { Promise : P , deepMixIn, removeCircular, forEach, contains } = DSUtils ;
6
+ let { deepMixIn, removeCircular, forEach, contains, omit } = DSUtils ;
8
7
let emptyStore = new JSData . DS ( ) ;
9
8
let filter = emptyStore . defaults . defaultFilter ;
10
9
@@ -27,20 +26,20 @@ class DSRedisAdapter {
27
26
}
28
27
29
28
getIds ( resourceConfig ) {
30
- return new P ( ( resolve , reject ) => {
29
+ return new DSUtils . Promise ( ( resolve , reject ) => {
31
30
return this . client . SMEMBERS ( getPath ( resourceConfig ) , ( err , ids ) => err ? reject ( err ) : resolve ( ids ) ) ;
32
31
} ) ;
33
32
}
34
33
35
34
GET ( path ) {
36
- return new P ( ( resolve , reject ) => {
35
+ return new DSUtils . Promise ( ( resolve , reject ) => {
37
36
return this . client . GET ( path , ( err , value ) => err ? reject ( err ) : resolve ( JSON . parse ( value ) ) ) ;
38
37
} ) ;
39
38
}
40
39
41
40
find ( resourceConfig , id , options ) {
42
41
let fields = [ ] ;
43
- return new P ( ( resolve , reject ) => {
42
+ return new DSUtils . Promise ( ( resolve , reject ) => {
44
43
options = options || { } ;
45
44
return this . client . GET ( `${ getPath ( resourceConfig ) } -${ id } ` , ( err , item ) => {
46
45
if ( err ) {
@@ -91,7 +90,7 @@ class DSRedisAdapter {
91
90
}
92
91
} ) ;
93
92
if ( tasks . length ) {
94
- return P . all ( tasks ) . then ( loadedRelations => {
93
+ return DSUtils . Promise . all ( tasks ) . then ( loadedRelations => {
95
94
forEach ( fields , ( field , index ) => {
96
95
instance [ field ] = loadedRelations [ index ] ;
97
96
} ) ;
@@ -108,7 +107,7 @@ class DSRedisAdapter {
108
107
let tasks = [ ] ;
109
108
let path = getPath ( resourceConfig ) ;
110
109
forEach ( ids , id => tasks . push ( this . GET ( `${ path } -${ id } ` ) ) ) ;
111
- return P . all ( tasks ) ;
110
+ return DSUtils . Promise . all ( tasks ) ;
112
111
} )
113
112
. then ( items => filter . call ( emptyStore , items , resourceConfig . name , params , { allowSimpleWhere : true } ) )
114
113
. then ( items => {
@@ -154,7 +153,7 @@ class DSRedisAdapter {
154
153
}
155
154
} ) ;
156
155
if ( tasks . length ) {
157
- topTasks . push ( P . all ( tasks ) . then ( loadedRelations => {
156
+ topTasks . push ( DSUtils . Promise . all ( tasks ) . then ( loadedRelations => {
158
157
forEach ( fields , ( field , index ) => {
159
158
instance [ field ] = loadedRelations [ index ] ;
160
159
} ) ;
@@ -163,14 +162,14 @@ class DSRedisAdapter {
163
162
}
164
163
} ) ;
165
164
if ( topTasks . length ) {
166
- return P . all ( topTasks ) ;
165
+ return DSUtils . Promise . all ( topTasks ) ;
167
166
}
168
167
return items ;
169
168
} ) ;
170
169
}
171
170
172
171
create ( resourceConfig , attrs ) {
173
- return new P ( ( resolve , reject ) => {
172
+ return new DSUtils . Promise ( ( resolve , reject ) => {
174
173
attrs = removeCircular ( omit ( attrs , resourceConfig . relationFields || [ ] ) ) ;
175
174
attrs [ resourceConfig . idAttribute ] = attrs [ resourceConfig . idAttribute ] || guid ( ) ;
176
175
return this . client
@@ -182,7 +181,7 @@ class DSRedisAdapter {
182
181
}
183
182
184
183
update ( resourceConfig , id , attrs ) {
185
- return new P ( ( resolve , reject ) => {
184
+ return new DSUtils . Promise ( ( resolve , reject ) => {
186
185
attrs = removeCircular ( omit ( attrs , resourceConfig . relationFields || [ ] ) ) ;
187
186
let path = `${ getPath ( resourceConfig ) } -${ id } ` ;
188
187
return this . client . GET ( path , ( err , value ) => {
@@ -203,12 +202,12 @@ class DSRedisAdapter {
203
202
return this . findAll ( resourceConfig , params ) . then ( items => {
204
203
let tasks = [ ] ;
205
204
forEach ( items , item => tasks . push ( this . update ( resourceConfig , item [ resourceConfig . idAttribute ] , attrs ) ) ) ;
206
- return P . all ( tasks ) ;
205
+ return DSUtils . Promise . all ( tasks ) ;
207
206
} ) ;
208
207
}
209
208
210
209
destroy ( resourceConfig , id ) {
211
- return new P ( ( resolve , reject ) => {
210
+ return new DSUtils . Promise ( ( resolve , reject ) => {
212
211
let path = getPath ( resourceConfig ) ;
213
212
return this . client
214
213
. multi ( )
@@ -222,7 +221,7 @@ class DSRedisAdapter {
222
221
return this . findAll ( resourceConfig , params ) . then ( items => {
223
222
let tasks = [ ] ;
224
223
forEach ( items , item => tasks . push ( this . destroy ( resourceConfig , item [ resourceConfig . idAttribute ] ) ) ) ;
225
- return P . all ( tasks ) ;
224
+ return DSUtils . Promise . all ( tasks ) ;
226
225
} ) ;
227
226
}
228
227
}
0 commit comments