@@ -12,7 +12,6 @@ import type {
12
12
GraphQLFieldConfig ,
13
13
GraphQLFieldConfigMap ,
14
14
GraphQLFieldConfigArgumentMap ,
15
- GraphQLFieldMap ,
16
15
GraphQLInputType ,
17
16
} from "graphql/type/definition" ; // eslint-disable-line
18
17
@@ -89,8 +88,7 @@ export default class ElasticApiParser {
89
88
opts . elasticClient . transport . _config . apiVersion ) ||
90
89
'_default' ;
91
90
const apiFilePath = path . resolve (
92
- opts . elasticApiFilePath ||
93
- ElasticApiParser . findApiVersionFile ( this . apiVersion )
91
+ opts . elasticApiFilePath || ElasticApiParser . findApiVersionFile ( this . apiVersion )
94
92
) ;
95
93
const source = ElasticApiParser . loadApiFile ( apiFilePath ) ;
96
94
this . parsedSource = ElasticApiParser . parseSource ( source ) ;
@@ -109,9 +107,7 @@ export default class ElasticApiParser {
109
107
try {
110
108
code = ElasticApiParser . loadFile ( absolutePath ) ;
111
109
} catch ( e ) {
112
- throw new Error (
113
- `Cannot load Elastic API source file from ${ absolutePath } `
114
- ) ;
110
+ throw new Error ( `Cannot load Elastic API source file from ${ absolutePath } ` ) ;
115
111
}
116
112
return ElasticApiParser . cleanUpSource ( code ) ;
117
113
}
@@ -121,9 +117,7 @@ export default class ElasticApiParser {
121
117
try {
122
118
code = ElasticApiParser . loadFile ( absolutePath ) ;
123
119
} catch ( e ) {
124
- throw new Error (
125
- `Cannot load Elastic API file with avaliable versions from ${ absolutePath } `
126
- ) ;
120
+ throw new Error ( `Cannot load Elastic API file with avaliable versions from ${ absolutePath } ` ) ;
127
121
}
128
122
return code ;
129
123
}
@@ -135,29 +129,21 @@ export default class ElasticApiParser {
135
129
136
130
// parsing elasticsearch module 13.x and above
137
131
// get '5.3'() { return require('./5_3'); },
138
- const re = new RegExp (
139
- `\\'${ version } \\'\\(\\).*require\\(\\'(.+)\\'\\)` ,
140
- 'gi'
141
- ) ;
132
+ const re = new RegExp ( `\\'${ version } \\'\\(\\).*require\\(\\'(.+)\\'\\)` , 'gi' ) ;
142
133
const match = re . exec ( apiListCode ) ;
143
134
if ( match && match [ 1 ] ) {
144
135
return path . resolve ( apiFolder , `${ match [ 1 ] } .js` ) ;
145
136
}
146
137
147
138
// parsing elasticsearch module 12.x and below
148
139
// '5.0': require('./5_0'),
149
- const re12 = new RegExp (
150
- `\\'${ version } \\':\\srequire\\(\\'(.+)\\'\\)` ,
151
- 'gi'
152
- ) ;
140
+ const re12 = new RegExp ( `\\'${ version } \\':\\srequire\\(\\'(.+)\\'\\)` , 'gi' ) ;
153
141
const match12 = re12 . exec ( apiListCode ) ;
154
142
if ( match12 && match12 [ 1 ] ) {
155
143
return path . resolve ( apiFolder , `${ match12 [ 1 ] } .js` ) ;
156
144
}
157
145
158
- throw new Error (
159
- `Can not found Elastic version '${ version } ' in ${ apiListFile } `
160
- ) ;
146
+ throw new Error ( `Can not found Elastic version '${ version } ' in ${ apiListFile } ` ) ;
161
147
}
162
148
163
149
static cleanUpSource ( code : string ) : string {
@@ -172,9 +158,7 @@ export default class ElasticApiParser {
172
158
return codeCleaned ;
173
159
}
174
160
175
- static parseParamsDescription (
176
- doxItemAST : any
177
- ) : { [ fieldName : string ] : string } {
161
+ static parseParamsDescription ( doxItemAST : any ) : { [ fieldName : string ] : string } {
178
162
const descriptions = { } ;
179
163
if ( Array . isArray ( doxItemAST . tags ) ) {
180
164
doxItemAST . tags . forEach ( tag => {
@@ -184,9 +168,7 @@ export default class ElasticApiParser {
184
168
const name = ElasticApiParser . cleanupParamName ( tag . name ) ;
185
169
if ( ! name ) return ;
186
170
187
- descriptions [ name ] = ElasticApiParser . cleanupDescription (
188
- tag . description
189
- ) ;
171
+ descriptions [ name ] = ElasticApiParser . cleanupDescription ( tag . description ) ;
190
172
} ) ;
191
173
}
192
174
return descriptions ;
@@ -258,9 +240,7 @@ export default class ElasticApiParser {
258
240
// method description
259
241
let description ;
260
242
if ( item . description && item . description . full ) {
261
- description = ElasticApiParser . cleanupDescription (
262
- item . description . full
263
- ) ;
243
+ description = ElasticApiParser . cleanupDescription ( item . description . full ) ;
264
244
}
265
245
266
246
const elasticMethod = ElasticApiParser . getMethodName ( item . ctx . string ) ;
@@ -310,12 +290,9 @@ export default class ElasticApiParser {
310
290
throw new Error ( `Elastic search method '${ methodName } ' does not exists.` ) ;
311
291
}
312
292
313
- const {
314
- description,
315
- argsSettings,
316
- argsDescriptions,
317
- elasticMethod,
318
- } = this . parsedSource [ methodName ] ;
293
+ const { description, argsSettings, argsDescriptions, elasticMethod } = this . parsedSource [
294
+ methodName
295
+ ] ;
319
296
320
297
const argMap = this . settingsToArgMap ( argsSettings , argsDescriptions ) ;
321
298
@@ -366,10 +343,7 @@ export default class ElasticApiParser {
366
343
return result ;
367
344
}
368
345
369
- paramTypeToGraphQL (
370
- paramCfg : ElasticParamConfigT ,
371
- fieldName : string
372
- ) : GraphQLInputType {
346
+ paramTypeToGraphQL ( paramCfg : ElasticParamConfigT , fieldName : string ) : GraphQLInputType {
373
347
switch ( paramCfg . type ) {
374
348
case 'string' :
375
349
return GraphQLString ;
@@ -458,11 +432,7 @@ export default class ElasticApiParser {
458
432
459
433
if ( params ) {
460
434
Object . keys ( params ) . forEach ( k => {
461
- const fieldConfig = this . paramToGraphQLArgConfig (
462
- params [ k ] ,
463
- k ,
464
- descriptions [ k ]
465
- ) ;
435
+ const fieldConfig = this . paramToGraphQLArgConfig ( params [ k ] , k , descriptions [ k ] ) ;
466
436
if ( fieldConfig ) {
467
437
result [ k ] = fieldConfig ;
468
438
}
@@ -475,11 +445,7 @@ export default class ElasticApiParser {
475
445
urlList . forEach ( item => {
476
446
if ( item . req ) {
477
447
Object . keys ( item . req ) . forEach ( k => {
478
- const fieldConfig = this . paramToGraphQLArgConfig (
479
- item . req [ k ] ,
480
- k ,
481
- descriptions [ k ]
482
- ) ;
448
+ const fieldConfig = this . paramToGraphQLArgConfig ( item . req [ k ] , k , descriptions [ k ] ) ;
483
449
if ( fieldConfig ) {
484
450
result [ k ] = fieldConfig ;
485
451
}
@@ -491,7 +457,7 @@ export default class ElasticApiParser {
491
457
return result ;
492
458
}
493
459
494
- reassembleNestedFields ( fields : GraphQLFieldMap < * , * > ) : GraphQLFieldMap < * , * > {
460
+ reassembleNestedFields ( fields : GraphQLFieldConfigMap < * , * > ) : GraphQLFieldConfigMap < * , * > {
495
461
const result = { } ;
496
462
Object . keys ( fields ) . forEach ( k => {
497
463
const names = k . split ( '.' ) ;
@@ -510,10 +476,7 @@ export default class ElasticApiParser {
510
476
} ,
511
477
} ;
512
478
}
513
- TypeComposer . create ( result [ names [ 0 ] ] . type ) . setField (
514
- names [ 1 ] ,
515
- fields [ k ]
516
- ) ;
479
+ TypeComposer . create ( result [ names [ 0 ] ] . type ) . setField ( names [ 1 ] , fields [ k ] ) ;
517
480
}
518
481
} ) ;
519
482
0 commit comments