@@ -163,29 +163,34 @@ module.exports.searchItems = function(search, client, fn, errFn) {
163
163
module . exports . castFields = function ( type , fields ) {
164
164
var output = { } ;
165
165
_ . forEach ( fields , function ( field ) {
166
- try { // field is a valid JSON
166
+ if ( field [ 0 ] == '@' ) {
167
+ var fs = require ( 'fs' ) ;
168
+ output = JSON . parse ( fs . readFileSync ( field . substring ( 1 ) , 'utf-8' ) ) ;
169
+ } else {
170
+ try { // field is a valid JSON
167
171
168
- var parsed = JSON . parse ( field ) ;
169
- if ( typeof ( parsed ) === 'object' ) {
170
- output = _ . defaults ( output , parsed ) ;
171
- }
172
+ var parsed = JSON . parse ( field ) ;
173
+ if ( typeof ( parsed ) === 'object' ) {
174
+ output = _ . defaults ( output , parsed ) ;
175
+ }
172
176
173
- } catch ( e ) { // field is an operation
177
+ } catch ( e ) { // field is an operation
174
178
175
- var split = field . split ( '=' ) ;
176
- var key = split [ 0 ] , value = split [ 1 ] ;
179
+ var split = field . split ( '=' ) ;
180
+ var key = split [ 0 ] , value = split [ 1 ] ;
177
181
178
- if ( [ 'true' , 'false' , 'True' , 'False' ] . indexOf ( value ) >= 0 ) {
179
- value = validator . toBoolean ( value . toLowerCase ( ) ) ;
180
- }
182
+ if ( [ 'true' , 'false' , 'True' , 'False' ] . indexOf ( value ) >= 0 ) {
183
+ value = validator . toBoolean ( value . toLowerCase ( ) ) ;
184
+ }
181
185
182
- if ( validator . isNumeric ( value ) ) {
183
- value = parseInt ( value ) ;
184
- }
186
+ if ( validator . isNumeric ( value ) ) {
187
+ value = parseInt ( value ) ;
188
+ }
185
189
186
- output [ key ] = value ;
187
- // FIXME: cast values accordingly to the resources
188
- // FIXME: type can be a type OR an object, if so, we need to resolve type
190
+ output [ key ] = value ;
191
+ // FIXME: cast values accordingly to the resources
192
+ // FIXME: type can be a type OR an object, if so, we need to resolve type
193
+ }
189
194
}
190
195
191
196
} ) ;
0 commit comments