1
- import * as _ from './lodash' ;
1
+ import {
2
+ includes ,
3
+ isUndefined ,
4
+ isNull ,
5
+ isArray ,
6
+ isObject ,
7
+ isBoolean ,
8
+ defaults ,
9
+ each ,
10
+ extend ,
11
+ find ,
12
+ has ,
13
+ initial ,
14
+ last ,
15
+ clone ,
16
+ reduce ,
17
+ keys ,
18
+ isEmpty ,
19
+ forEach ,
20
+ } from 'lodash' ;
2
21
3
22
export function RestangularConfigurer ( object , config ) {
4
23
object . configuration = config ;
@@ -8,24 +27,24 @@ export function RestangularConfigurer(object, config){
8
27
*/
9
28
var safeMethods = [ 'get' , 'head' , 'options' , 'trace' , 'getlist' ] ;
10
29
config . isSafe = function ( operation ) {
11
- return _ . includes ( safeMethods , operation . toLowerCase ( ) ) ;
30
+ return includes ( safeMethods , operation . toLowerCase ( ) ) ;
12
31
} ;
13
32
14
33
var absolutePattern = / ^ h t t p s ? : \/ \/ / i;
15
34
config . isAbsoluteUrl = function ( string ) {
16
- return _ . isUndefined ( config . absoluteUrl ) || _ . isNull ( config . absoluteUrl ) ?
35
+ return isUndefined ( config . absoluteUrl ) || isNull ( config . absoluteUrl ) ?
17
36
string && absolutePattern . test ( string ) :
18
37
config . absoluteUrl ;
19
38
} ;
20
39
21
- config . absoluteUrl = _ . isUndefined ( config . absoluteUrl ) ? true : config . absoluteUrl ;
40
+ config . absoluteUrl = isUndefined ( config . absoluteUrl ) ? true : config . absoluteUrl ;
22
41
object . setSelfLinkAbsoluteUrl = function ( value ) {
23
42
config . absoluteUrl = value ;
24
43
} ;
25
44
/**
26
45
* This is the BaseURL to be used with Restangular
27
46
*/
28
- config . baseUrl = _ . isUndefined ( config . baseUrl ) ? '' : config . baseUrl ;
47
+ config . baseUrl = isUndefined ( config . baseUrl ) ? '' : config . baseUrl ;
29
48
object . setBaseUrl = function ( newBaseUrl ) {
30
49
config . baseUrl = / \/ $ / . test ( newBaseUrl ) ?
31
50
newBaseUrl . substring ( 0 , newBaseUrl . length - 1 ) :
@@ -61,10 +80,10 @@ export function RestangularConfigurer(object, config){
61
80
}
62
81
63
82
config . withHttpValues = function ( httpLocalConfig , obj ) {
64
- return _ . defaults ( obj , httpLocalConfig , config . defaultHttpFields ) ;
83
+ return defaults ( obj , httpLocalConfig , config . defaultHttpFields ) ;
65
84
} ;
66
85
67
- config . encodeIds = _ . isUndefined ( config . encodeIds ) ? true : config . encodeIds ;
86
+ config . encodeIds = isUndefined ( config . encodeIds ) ? true : config . encodeIds ;
68
87
object . setEncodeIds = function ( encode ) {
69
88
config . encodeIds = encode ;
70
89
} ;
@@ -80,8 +99,8 @@ export function RestangularConfigurer(object, config){
80
99
object . setDefaultRequestParams = function ( param1 , param2 ) {
81
100
var methods = [ ] ,
82
101
params = param2 || param1 ;
83
- if ( ! _ . isUndefined ( param2 ) ) {
84
- if ( _ . isArray ( param1 ) ) {
102
+ if ( ! isUndefined ( param2 ) ) {
103
+ if ( isArray ( param1 ) ) {
85
104
methods = param1 ;
86
105
} else {
87
106
methods . push ( param1 ) ;
@@ -90,7 +109,7 @@ export function RestangularConfigurer(object, config){
90
109
methods . push ( 'common' ) ;
91
110
}
92
111
93
- _ . each ( methods , function ( method ) {
112
+ each ( methods , function ( method ) {
94
113
config . defaultRequestParams [ method ] = params ;
95
114
} ) ;
96
115
return this ;
@@ -124,22 +143,22 @@ export function RestangularConfigurer(object, config){
124
143
**/
125
144
config . methodOverriders = config . methodOverriders || [ ] ;
126
145
object . setMethodOverriders = function ( values ) {
127
- var overriders = _ . extend ( [ ] , values ) ;
146
+ var overriders = extend ( [ ] , values ) ;
128
147
if ( config . isOverridenMethod ( 'delete' , overriders ) ) {
129
148
overriders . push ( 'remove' ) ;
130
149
}
131
150
config . methodOverriders = overriders ;
132
151
return this ;
133
152
} ;
134
153
135
- config . jsonp = _ . isUndefined ( config . jsonp ) ? false : config . jsonp ;
154
+ config . jsonp = isUndefined ( config . jsonp ) ? false : config . jsonp ;
136
155
object . setJsonp = function ( active ) {
137
156
config . jsonp = active ;
138
157
} ;
139
158
140
159
config . isOverridenMethod = function ( method , values ) {
141
160
var search = values || config . methodOverriders ;
142
- return ! _ . isUndefined ( _ . find ( search , function ( one : string ) {
161
+ return ! isUndefined ( find ( search , function ( one : string ) {
143
162
return one . toLowerCase ( ) === method . toLowerCase ( ) ;
144
163
} ) ) ;
145
164
} ;
@@ -149,7 +168,7 @@ export function RestangularConfigurer(object, config){
149
168
**/
150
169
config . urlCreator = config . urlCreator || 'path' ;
151
170
object . setUrlCreator = function ( name ) {
152
- if ( ! _ . has ( config . urlCreatorFactory , name ) ) {
171
+ if ( ! has ( config . urlCreatorFactory , name ) ) {
153
172
throw new Error ( 'URL Path selected isn\'t valid' ) ;
154
173
}
155
174
@@ -221,7 +240,7 @@ export function RestangularConfigurer(object, config){
221
240
} ;
222
241
object . setRestangularFields = function ( resFields ) {
223
242
config . restangularFields =
224
- _ . extend ( { } , config . restangularFields , resFields ) ;
243
+ extend ( { } , config . restangularFields , resFields ) ;
225
244
return this ;
226
245
} ;
227
246
@@ -232,24 +251,24 @@ export function RestangularConfigurer(object, config){
232
251
config . setFieldToElem = function ( field , elem , value ) {
233
252
var properties = field . split ( '.' ) ;
234
253
var idValue = elem ;
235
- _ . each ( _ . initial ( properties ) , function ( prop : any ) {
254
+ each ( initial ( properties ) , function ( prop : any ) {
236
255
idValue [ prop ] = { } ;
237
256
idValue = idValue [ prop ] ;
238
257
} ) ;
239
- var index : any = _ . last ( properties ) ;
258
+ var index : any = last ( properties ) ;
240
259
idValue [ index ] = value ;
241
260
return this ;
242
261
} ;
243
262
244
263
config . getFieldFromElem = function ( field , elem ) {
245
264
var properties = field . split ( '.' ) ;
246
265
var idValue : any = elem ;
247
- _ . each ( properties , function ( prop ) {
266
+ each ( properties , function ( prop ) {
248
267
if ( idValue ) {
249
268
idValue = idValue [ prop ] ;
250
269
}
251
270
} ) ;
252
- return _ . clone ( idValue ) ;
271
+ return clone ( idValue ) ;
253
272
} ;
254
273
255
274
config . setIdToElem = function ( elem , id /*, route */ ) {
@@ -262,7 +281,7 @@ export function RestangularConfigurer(object, config){
262
281
} ;
263
282
264
283
config . isValidId = function ( elemId ) {
265
- return '' !== elemId && ! _ . isUndefined ( elemId ) && ! _ . isNull ( elemId ) ;
284
+ return '' !== elemId && ! isUndefined ( elemId ) && ! isNull ( elemId ) ;
266
285
} ;
267
286
268
287
config . setUrlToElem = function ( elem , url /*, route */ ) {
@@ -274,7 +293,7 @@ export function RestangularConfigurer(object, config){
274
293
return config . getFieldFromElem ( config . restangularFields . selfLink , elem ) ;
275
294
} ;
276
295
277
- config . useCannonicalId = _ . isUndefined ( config . useCannonicalId ) ? false : config . useCannonicalId ;
296
+ config . useCannonicalId = isUndefined ( config . useCannonicalId ) ? false : config . useCannonicalId ;
278
297
object . setUseCannonicalId = function ( value ) {
279
298
config . useCannonicalId = value ;
280
299
return this ;
@@ -301,10 +320,10 @@ export function RestangularConfigurer(object, config){
301
320
} ;
302
321
303
322
config . responseExtractor = function ( data , operation , what , url , response , subject ) {
304
- var interceptors = _ . clone ( config . responseInterceptors ) ;
323
+ var interceptors = clone ( config . responseInterceptors ) ;
305
324
interceptors . push ( config . defaultResponseInterceptor ) ;
306
325
var theData = data ;
307
- _ . each ( interceptors , function ( interceptor : any ) {
326
+ each ( interceptors , function ( interceptor : any ) {
308
327
theData = interceptor ( theData , operation ,
309
328
what , url , response , subject ) ;
310
329
} ) ;
@@ -346,12 +365,12 @@ export function RestangularConfigurer(object, config){
346
365
} ;
347
366
348
367
config . fullRequestInterceptor = function ( element , operation , path , url , headers , params , httpConfig ) {
349
- var interceptors = _ . clone ( config . requestInterceptors ) ;
368
+ var interceptors = clone ( config . requestInterceptors ) ;
350
369
var defaultRequest = config . defaultInterceptor ( element , operation , path , url , headers , params , httpConfig ) ;
351
- return _ . reduce ( interceptors , function ( request : any , interceptor : any ) {
370
+ return reduce ( interceptors , function ( request : any , interceptor : any ) {
352
371
353
372
let returnInterceptor : any = interceptor ( request . element , operation , path , url , request . headers , request . params , request . httpConfig ) ;
354
- return _ . extend ( request , returnInterceptor ) ;
373
+ return extend ( request , returnInterceptor ) ;
355
374
} , defaultRequest ) ;
356
375
} ;
357
376
@@ -408,11 +427,11 @@ export function RestangularConfigurer(object, config){
408
427
return true ;
409
428
} ;
410
429
object . setParentless = function ( values ) {
411
- if ( _ . isArray ( values ) ) {
430
+ if ( isArray ( values ) ) {
412
431
config . shouldSaveParent = function ( route ) {
413
- return ! _ . includes ( values , route ) ;
432
+ return ! includes ( values , route ) ;
414
433
} ;
415
- } else if ( _ . isBoolean ( values ) ) {
434
+ } else if ( isBoolean ( values ) ) {
416
435
config . shouldSaveParent = function ( ) {
417
436
return ! values ;
418
437
} ;
@@ -429,7 +448,7 @@ export function RestangularConfigurer(object, config){
429
448
*
430
449
* By default, the suffix is null
431
450
*/
432
- config . suffix = _ . isUndefined ( config . suffix ) ? null : config . suffix ;
451
+ config . suffix = isUndefined ( config . suffix ) ? null : config . suffix ;
433
452
object . setRequestSuffix = function ( newSuffix ) {
434
453
config . suffix = newSuffix ;
435
454
return this ;
@@ -455,7 +474,7 @@ export function RestangularConfigurer(object, config){
455
474
}
456
475
457
476
typeTransformers . push ( function ( coll , elem ) {
458
- if ( _ . isNull ( isCollection ) || ( coll === isCollection ) ) {
477
+ if ( isNull ( isCollection ) || ( coll === isCollection ) ) {
459
478
return transformer ( elem ) ;
460
479
}
461
480
return elem ;
@@ -479,22 +498,22 @@ export function RestangularConfigurer(object, config){
479
498
var typeTransformers = config . transformers [ route ] ;
480
499
var changedElem = elem ;
481
500
if ( typeTransformers ) {
482
- _ . each ( typeTransformers , function ( transformer : ( isCollection : boolean , changedElem : any ) => any ) {
501
+ each ( typeTransformers , function ( transformer : ( isCollection : boolean , changedElem : any ) => any ) {
483
502
changedElem = transformer ( isCollection , changedElem ) ;
484
503
} ) ;
485
504
}
486
505
return config . onElemRestangularized ( changedElem , isCollection , route , Restangular ) ;
487
506
} ;
488
507
489
- config . transformLocalElements = _ . isUndefined ( config . transformLocalElements ) ?
508
+ config . transformLocalElements = isUndefined ( config . transformLocalElements ) ?
490
509
false :
491
510
config . transformLocalElements ;
492
511
493
512
object . setTransformOnlyServerElements = function ( active ) {
494
513
config . transformLocalElements = ! active ;
495
514
} ;
496
515
497
- config . fullResponse = _ . isUndefined ( config . fullResponse ) ? false : config . fullResponse ;
516
+ config . fullResponse = isUndefined ( config . fullResponse ) ? false : config . fullResponse ;
498
517
object . setFullResponse = function ( full ) {
499
518
config . fullResponse = full ;
500
519
return this ;
@@ -527,20 +546,20 @@ export function RestangularConfigurer(object, config){
527
546
528
547
function RestangularResource ( config , $http , url , configurer ) {
529
548
var resource = { } ;
530
- _ . each ( _ . keys ( configurer ) , function ( key ) {
549
+ each ( keys ( configurer ) , function ( key ) {
531
550
var value = configurer [ key ] ;
532
551
533
552
// Add default parameters
534
- value . params = _ . extend ( { } , value . params , config . defaultRequestParams [ value . method . toLowerCase ( ) ] ) ;
553
+ value . params = extend ( { } , value . params , config . defaultRequestParams [ value . method . toLowerCase ( ) ] ) ;
535
554
// We don't want the ? if no params are there
536
- if ( _ . isEmpty ( value . params ) ) {
555
+ if ( isEmpty ( value . params ) ) {
537
556
delete value . params ;
538
557
}
539
558
540
559
if ( config . isSafe ( value . method ) ) {
541
560
542
561
resource [ key ] = function ( ) {
543
- let config = _ . extend ( value , {
562
+ let config = extend ( value , {
544
563
url : url
545
564
} ) ;
546
565
return $http . createRequest ( config ) ;
@@ -549,7 +568,7 @@ export function RestangularConfigurer(object, config){
549
568
} else {
550
569
551
570
resource [ key ] = function ( data ) {
552
- let config = _ . extend ( value , {
571
+ let config = extend ( value , {
553
572
url : url ,
554
573
data : data
555
574
} ) ;
@@ -563,8 +582,8 @@ export function RestangularConfigurer(object, config){
563
582
}
564
583
565
584
BaseCreator . prototype . resource = function ( current , $http , localHttpConfig , callHeaders , callParams , what , etag , operation ) {
566
- var params = _ . defaults ( callParams || { } , this . config . defaultRequestParams . common ) ;
567
- var headers = _ . defaults ( callHeaders || { } , this . config . defaultHeaders ) ;
585
+ var params = defaults ( callParams || { } , this . config . defaultRequestParams . common ) ;
586
+ var headers = defaults ( callHeaders || { } , this . config . defaultHeaders ) ;
568
587
569
588
if ( etag ) {
570
589
if ( ! config . isSafe ( operation ) ) {
@@ -683,7 +702,7 @@ export function RestangularConfigurer(object, config){
683
702
684
703
Path . prototype . base = function ( current ) {
685
704
var __this = this ;
686
- return _ . reduce ( this . parentsArray ( current ) , function ( acum : any , elem : any ) {
705
+ return reduce ( this . parentsArray ( current ) , function ( acum : any , elem : any ) {
687
706
var elemUrl ;
688
707
var elemSelfLink = __this . config . getUrlFromElem ( elem ) ;
689
708
if ( elemSelfLink ) {
@@ -769,12 +788,12 @@ export function RestangularConfigurer(object, config){
769
788
if ( value === null || value === undefined ) {
770
789
return ;
771
790
}
772
- if ( ! _ . isArray ( value ) ) {
791
+ if ( ! isArray ( value ) ) {
773
792
value = [ value ] ;
774
793
}
775
794
776
- _ . forEach ( value , function ( v ) {
777
- if ( _ . isObject ( v ) ) {
795
+ forEach ( value , function ( v ) {
796
+ if ( isObject ( v ) ) {
778
797
v = JSON . stringify ( v ) ;
779
798
}
780
799
parts . push ( encodeUriQuery ( key ) + '=' + encodeUriQuery ( v ) ) ;
0 commit comments