@@ -11,31 +11,17 @@ class CollectionController extends BaseController {
1111 super ( kuzzle , 'collection' ) ;
1212 }
1313
14- create ( index , collection , body = { } , options = { } ) {
15- if ( ! index ) {
16- throw new Error ( 'Kuzzle.collection.create: index is required' ) ;
17- }
18- if ( ! collection ) {
19- throw new Error ( 'Kuzzle.collection.create: collection is required' ) ;
20- }
21-
14+ create ( index , collection , mappings = { } , options = { } ) {
2215 return this . query ( {
2316 index,
2417 collection,
25- body,
18+ body : mappings ,
2619 action : 'create'
2720 } , options )
2821 . then ( response => response . result ) ;
2922 }
3023
3124 deleteSpecifications ( index , collection , options = { } ) {
32- if ( ! index ) {
33- throw new Error ( 'Kuzzle.collection.deleteSpecifications: index is required' ) ;
34- }
35- if ( ! collection ) {
36- throw new Error ( 'Kuzzle.collection.deleteSpecifications: collection is required' ) ;
37- }
38-
3925 return this . query ( {
4026 index,
4127 collection,
@@ -45,13 +31,6 @@ class CollectionController extends BaseController {
4531 }
4632
4733 exists ( index , collection , options = { } ) {
48- if ( ! index ) {
49- throw new Error ( 'Kuzzle.collection.exists: index is required' ) ;
50- }
51- if ( ! collection ) {
52- throw new Error ( 'Kuzzle.collection.exists: collection is required' ) ;
53- }
54-
5534 return this . query ( {
5635 index,
5736 collection,
@@ -61,13 +40,6 @@ class CollectionController extends BaseController {
6140 }
6241
6342 getMapping ( index , collection , options = { } ) {
64- if ( ! index ) {
65- throw new Error ( 'Kuzzle.collection.getMapping: index is required' ) ;
66- }
67- if ( ! collection ) {
68- throw new Error ( 'Kuzzle.collection.getMapping: collection is required' ) ;
69- }
70-
7143 return this . query ( {
7244 index,
7345 collection,
@@ -77,13 +49,6 @@ class CollectionController extends BaseController {
7749 }
7850
7951 getSpecifications ( index , collection , options = { } ) {
80- if ( ! index ) {
81- throw new Error ( 'Kuzzle.collection.getSpecifications: index is required' ) ;
82- }
83- if ( ! collection ) {
84- throw new Error ( 'Kuzzle.collection.getSpecifications: collection is required' ) ;
85- }
86-
8752 return this . query ( {
8853 index,
8954 collection,
@@ -93,10 +58,6 @@ class CollectionController extends BaseController {
9358 }
9459
9560 list ( index , options = { } ) {
96- if ( ! index ) {
97- throw new Error ( 'Kuzzle.collection.list: index is required' ) ;
98- }
99-
10061 const request = {
10162 index,
10263 action : 'list' ,
@@ -115,8 +76,10 @@ class CollectionController extends BaseController {
11576 body,
11677 action : 'searchSpecifications'
11778 } ;
79+
11880 for ( const opt of [ 'from' , 'size' , 'scroll' ] ) {
11981 request [ opt ] = options [ opt ] ;
82+
12083 delete options [ opt ] ;
12184 }
12285
@@ -125,13 +88,6 @@ class CollectionController extends BaseController {
12588 }
12689
12790 truncate ( index , collection , options = { } ) {
128- if ( ! index ) {
129- throw new Error ( 'Kuzzle.collection.truncate: index is required' ) ;
130- }
131- if ( ! collection ) {
132- throw new Error ( 'Kuzzle.collection.truncate: collection is required' ) ;
133- }
134-
13591 return this . query ( {
13692 index,
13793 collection,
@@ -142,13 +98,6 @@ class CollectionController extends BaseController {
14298 }
14399
144100 updateMapping ( index , collection , body , options = { } ) {
145- if ( ! index ) {
146- throw new Error ( 'Kuzzle.collection.updateMapping: index is required' ) ;
147- }
148- if ( ! collection ) {
149- throw new Error ( 'Kuzzle.collection.updateMapping: collection is required' ) ;
150- }
151-
152101 return this . query ( {
153102 index,
154103 collection,
@@ -159,16 +108,6 @@ class CollectionController extends BaseController {
159108 }
160109
161110 updateSpecifications ( index , collection , specifications , options = { } ) {
162- if ( ! index ) {
163- throw new Error ( 'Kuzzle.collection.updateSpecifications: index is required' ) ;
164- }
165- if ( ! collection ) {
166- throw new Error ( 'Kuzzle.collection.updateSpecifications: collection is required' ) ;
167- }
168- if ( ! specifications ) {
169- throw new Error ( 'Kuzzle.collection.updateSpecifications: specifications are required' ) ;
170- }
171-
172111 const body = {
173112 [ index ] : {
174113 [ collection ] : specifications
@@ -183,16 +122,6 @@ class CollectionController extends BaseController {
183122 }
184123
185124 validateSpecifications ( index , collection , specifications , options = { } ) {
186- if ( ! index ) {
187- throw new Error ( 'Kuzzle.collection.validateSpecifications: index is required' ) ;
188- }
189- if ( ! collection ) {
190- throw new Error ( 'Kuzzle.collection.validateSpecifications: collection is required' ) ;
191- }
192- if ( ! specifications ) {
193- throw new Error ( 'Kuzzle.collection.updateSpecifications: specifications are required' ) ;
194- }
195-
196125 const body = {
197126 [ index ] : {
198127 [ collection ] : specifications
0 commit comments