Skip to content

Commit 67c6e64

Browse files
committed
style: Prettify and fix flowtype warnings
1 parent be31a39 commit 67c6e64

File tree

102 files changed

+307
-437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+307
-437
lines changed

src/ElasticApiParser.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {
2222
GraphQLFieldConfigArgumentMap,
2323
GraphQLFieldMap,
2424
GraphQLInputType,
25-
} from 'graphql/type/definition'; // eslint-disable-line
25+
} from "graphql/type/definition"; // eslint-disable-line
2626

2727
export type ElasticParamConfigT = {
2828
type: string,
@@ -80,7 +80,8 @@ export default class ElasticApiParser {
8080
constructor(opts: ElasticApiParserOptsT = {}) {
8181
// avaliable varsions can be found in installed package `elasticsearch`
8282
// in file /node_modules/elasticsearch/src/lib/apis/index.js
83-
this.apiVersion = opts.apiVersion ||
83+
this.apiVersion =
84+
opts.apiVersion ||
8485
(opts.elasticClient &&
8586
opts.elasticClient.transport &&
8687
opts.elasticClient.transport._config &&
@@ -133,15 +134,21 @@ export default class ElasticApiParser {
133134

134135
// parsing elasticsearch module 13.x and above
135136
// get '5.3'() { return require('./5_3'); },
136-
const re = new RegExp(`\\'${version}\\'\\(\\).*require\\(\\'(.+)\\'\\)`, 'gi');
137+
const re = new RegExp(
138+
`\\'${version}\\'\\(\\).*require\\(\\'(.+)\\'\\)`,
139+
'gi'
140+
);
137141
const match = re.exec(apiListCode);
138142
if (match && match[1]) {
139143
return path.resolve(apiFolder, `${match[1]}.js`);
140144
}
141145

142146
// parsing elasticsearch module 12.x and below
143147
// '5.0': require('./5_0'),
144-
const re12 = new RegExp(`\\'${version}\\':\\srequire\\(\\'(.+)\\'\\)`, 'gi');
148+
const re12 = new RegExp(
149+
`\\'${version}\\':\\srequire\\(\\'(.+)\\'\\)`,
150+
'gi'
151+
);
145152
const match12 = re12.exec(apiListCode);
146153
if (match12 && match12[1]) {
147154
return path.resolve(apiFolder, `${match12[1]}.js`);
@@ -400,30 +407,27 @@ export default class ElasticApiParser {
400407
}
401408

402409
if (!this.cachedEnums[key][subKey]) {
403-
const values = vals.reduce(
404-
(result, val) => {
405-
if (val === '') {
406-
result.empty_string = { value: '' };
407-
} else if (val === 'true') {
408-
result.true_string = { value: 'true' };
409-
} else if (val === true) {
410-
result.true_boolean = { value: true };
411-
} else if (val === 'false') {
412-
result.false_string = { value: 'false' };
413-
} else if (val === false) {
414-
result.false_boolean = { value: false };
415-
} else if (val === 'null') {
416-
result.null_string = { value: 'null' };
417-
} else if (Number.isFinite(val)) {
418-
// $FlowFixMe
419-
result[`number_${val}`] = { value: val };
420-
} else if (typeof val === 'string') {
421-
result[val] = { value: val };
422-
}
423-
return result;
424-
},
425-
{}
426-
);
410+
const values = vals.reduce((result, val) => {
411+
if (val === '') {
412+
result.empty_string = { value: '' };
413+
} else if (val === 'true') {
414+
result.true_string = { value: 'true' };
415+
} else if (val === true) {
416+
result.true_boolean = { value: true };
417+
} else if (val === 'false') {
418+
result.false_string = { value: 'false' };
419+
} else if (val === false) {
420+
result.false_boolean = { value: false };
421+
} else if (val === 'null') {
422+
result.null_string = { value: 'null' };
423+
} else if (Number.isFinite(val)) {
424+
// $FlowFixMe
425+
result[`number_${val}`] = { value: val };
426+
} else if (typeof val === 'string') {
427+
result[val] = { value: val };
428+
}
429+
return result;
430+
}, {});
427431

428432
let postfix = Object.keys(this.cachedEnums[key]).length;
429433
if (postfix === 0) postfix = '';

src/__tests__/mappingConverter-test.js

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ describe('PropertiesConverter', () => {
7676
const tc = convertToSourceTC(mapping, 'TestMapping');
7777
expect(tc).toBeInstanceOf(TypeComposer);
7878
expect(tc.getTypeName()).toBe('TestMapping');
79-
expect(tc.getFieldNames()).toEqual(
80-
expect.arrayContaining(['name', 'avatarUrl'])
81-
);
79+
expect(tc.getFieldNames()).toEqual(expect.arrayContaining(['name', 'avatarUrl']));
8280
});
8381

8482
it('should make singular and plural fields', () => {
@@ -107,40 +105,26 @@ describe('PropertiesConverter', () => {
107105
});
108106

109107
it('should return GraphQLJSON as fallback for unknown Elastic type', () => {
110-
expect(propertyToSourceGraphQLType({ type: 'strange' })).toEqual(
111-
GraphQLJSON
112-
);
108+
expect(propertyToSourceGraphQLType({ type: 'strange' })).toEqual(GraphQLJSON);
113109
});
114110

115111
it('should return GraphQLInt for int types', () => {
116-
expect(propertyToSourceGraphQLType({ type: 'integer' })).toEqual(
117-
GraphQLInt
118-
);
112+
expect(propertyToSourceGraphQLType({ type: 'integer' })).toEqual(GraphQLInt);
119113
expect(propertyToSourceGraphQLType({ type: 'long' })).toEqual(GraphQLInt);
120114
});
121115

122116
it('should return GraphQLString for string types', () => {
123-
expect(propertyToSourceGraphQLType({ type: 'text' })).toEqual(
124-
GraphQLString
125-
);
126-
expect(propertyToSourceGraphQLType({ type: 'keyword' })).toEqual(
127-
GraphQLString
128-
);
117+
expect(propertyToSourceGraphQLType({ type: 'text' })).toEqual(GraphQLString);
118+
expect(propertyToSourceGraphQLType({ type: 'keyword' })).toEqual(GraphQLString);
129119
});
130120

131121
it('should return GraphQLFloat for float types', () => {
132-
expect(propertyToSourceGraphQLType({ type: 'float' })).toEqual(
133-
GraphQLFloat
134-
);
135-
expect(propertyToSourceGraphQLType({ type: 'double' })).toEqual(
136-
GraphQLFloat
137-
);
122+
expect(propertyToSourceGraphQLType({ type: 'float' })).toEqual(GraphQLFloat);
123+
expect(propertyToSourceGraphQLType({ type: 'double' })).toEqual(GraphQLFloat);
138124
});
139125

140126
it('should return GraphQLBoolean for float types', () => {
141-
expect(propertyToSourceGraphQLType({ type: 'boolean' })).toEqual(
142-
GraphQLBoolean
143-
);
127+
expect(propertyToSourceGraphQLType({ type: 'boolean' })).toEqual(GraphQLBoolean);
144128
});
145129

146130
it('should return GraphQLObjectType for object with subfields', () => {
@@ -160,9 +144,7 @@ describe('PropertiesConverter', () => {
160144
expect(type).toBeInstanceOf(GraphQLObjectType);
161145
const tc = TypeComposer.create(type);
162146
expect(tc.getTypeName()).toEqual('ComplexType');
163-
expect(tc.getFieldNames()).toEqual(
164-
expect.arrayContaining(['big', 'thumb'])
165-
);
147+
expect(tc.getFieldNames()).toEqual(expect.arrayContaining(['big', 'thumb']));
166148
expect(tc.getFieldType('big')).toEqual(GraphQLString);
167149
});
168150
});
@@ -205,15 +187,9 @@ describe('PropertiesConverter', () => {
205187
},
206188
});
207189
expect(Object.keys(fields._all).length).toEqual(2);
208-
expect(Object.keys(fields._all)).toEqual(
209-
expect.arrayContaining(['name', 'name__keyword'])
210-
);
211-
expect(Object.keys(fields.keyword)).toEqual(
212-
expect.arrayContaining(['name__keyword'])
213-
);
214-
expect(Object.keys(fields.text)).toEqual(
215-
expect.arrayContaining(['name'])
216-
);
190+
expect(Object.keys(fields._all)).toEqual(expect.arrayContaining(['name', 'name__keyword']));
191+
expect(Object.keys(fields.keyword)).toEqual(expect.arrayContaining(['name__keyword']));
192+
expect(Object.keys(fields.text)).toEqual(expect.arrayContaining(['name']));
217193
});
218194

219195
it('should not return index:false fields', () => {
@@ -229,21 +205,18 @@ describe('PropertiesConverter', () => {
229205
},
230206
});
231207
expect(Object.keys(fields._all).length).toEqual(1);
232-
expect(Object.keys(fields._all)).toEqual(
233-
expect.arrayContaining(['date'])
234-
);
208+
expect(Object.keys(fields._all)).toEqual(expect.arrayContaining(['date']));
235209
expect(Object.keys(fields.date).length).toEqual(1);
236-
expect(Object.keys(fields.date)).toEqual(
237-
expect.arrayContaining(['date'])
238-
);
210+
expect(Object.keys(fields.date)).toEqual(expect.arrayContaining(['date']));
239211
});
240212
});
241213

242214
describe('getSubFields()', () => {
243215
it('should return array of sub fields', () => {
244-
expect(
245-
getSubFields('range', ['ok', 'range', 'range.min', 'range.max'])
246-
).toEqual(['min', 'max']);
216+
expect(getSubFields('range', ['ok', 'range', 'range.min', 'range.max'])).toEqual([
217+
'min',
218+
'max',
219+
]);
247220
});
248221

249222
it('should return array for empty/undefined list', () => {

src/__tests__/typeStorage-test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ describe('typeStorage', () => {
3030
});
3131

3232
it('should set new type as function and return type, if key not exists', () => {
33-
expect(typeStorage.getOrSet('MyType', () => GraphQLType)).toEqual(
34-
GraphQLType
35-
);
33+
expect(typeStorage.getOrSet('MyType', () => GraphQLType)).toEqual(GraphQLType);
3634
expect(typeStorage.get('MyType')).toEqual(GraphQLType);
3735
});
3836

src/elasticDSL/Aggs/AggBlock.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export function getAggBlockITC(opts: mixed = {}): InputTypeComposer {
1616
);
1717

1818
return getOrSetType(name, () =>
19-
// $FlowFixMe
2019
InputTypeComposer.create({
2120
name,
2221
description,
@@ -30,5 +29,6 @@ export function getAggBlockITC(opts: mixed = {}): InputTypeComposer {
3029
description: 'Aggregation rules',
3130
},
3231
},
33-
}));
32+
})
33+
);
3434
}

src/elasticDSL/Aggs/AggRules.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export function getAggRulesITC(opts: mixed = {}): InputTypeComposer {
6464
);
6565

6666
return getOrSetType(name, () =>
67-
// $FlowFixMe
6867
InputTypeComposer.create({
6968
name,
7069
description,
@@ -122,5 +121,6 @@ export function getAggRulesITC(opts: mixed = {}): InputTypeComposer {
122121
description: 'Aggregation block',
123122
},
124123
},
125-
}));
124+
})
125+
);
126126
}

src/elasticDSL/Aggs/Bucket/Children.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ export function getChildrenITC(opts: mixed = {}): InputTypeComposer {
1414
);
1515

1616
return getOrSetType(name, () =>
17-
// $FlowFixMe
1817
InputTypeComposer.create({
1918
name,
2019
description,
2120
fields: {
2221
type: 'String',
2322
},
24-
}));
23+
})
24+
);
2525
}

src/elasticDSL/Aggs/Bucket/DateHistogram.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
import { InputTypeComposer } from 'graphql-compose';
44
import { getTypeName, getOrSetType, desc } from '../../../utils';
55
import { getCommonsScriptITC } from '../../Commons/Script';
6-
import {
7-
getDateIntervalFC,
8-
getDateFormatFC,
9-
getDateTimeZoneFC,
10-
} from '../../Commons/Date';
6+
import { getDateIntervalFC, getDateFormatFC, getDateTimeZoneFC } from '../../Commons/Date';
117
import { getDateFields } from '../../Commons/FieldNames';
128

139
export function getDateHistogramITC(opts: mixed = {}): InputTypeComposer {
@@ -21,7 +17,6 @@ export function getDateHistogramITC(opts: mixed = {}): InputTypeComposer {
2117
);
2218

2319
return getOrSetType(name, () =>
24-
// $FlowFixMe
2520
InputTypeComposer.create({
2621
name,
2722
description,
@@ -34,5 +29,6 @@ export function getDateHistogramITC(opts: mixed = {}): InputTypeComposer {
3429
missing: 'String',
3530
script: () => getCommonsScriptITC(opts),
3631
},
37-
}));
32+
})
33+
);
3834
}

src/elasticDSL/Aggs/Bucket/DateRange.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
import { InputTypeComposer } from 'graphql-compose';
44
import { getTypeName, getOrSetType, desc } from '../../../utils';
5-
import {
6-
getDateFormatFC,
7-
getDateTimeZoneFC,
8-
getDateRangeITC,
9-
} from '../../Commons/Date';
5+
import { getDateFormatFC, getDateTimeZoneFC, getDateRangeITC } from '../../Commons/Date';
106
import { getDateFields } from '../../Commons/FieldNames';
117

128
export function getAggsDateRangeITC(opts: mixed = {}): InputTypeComposer {
@@ -24,7 +20,6 @@ export function getAggsDateRangeITC(opts: mixed = {}): InputTypeComposer {
2420
);
2521

2622
return getOrSetType(name, () =>
27-
// $FlowFixMe
2823
InputTypeComposer.create({
2924
name,
3025
description,
@@ -34,5 +29,6 @@ export function getAggsDateRangeITC(opts: mixed = {}): InputTypeComposer {
3429
ranges: () => [getDateRangeITC(opts)],
3530
time_zone: getDateTimeZoneFC(opts),
3631
},
37-
}));
32+
})
33+
);
3834
}

src/elasticDSL/Aggs/Bucket/DiversifiedSampler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export function getDiversifiedSamplerITC(opts: mixed = {}): InputTypeComposer {
1717
);
1818

1919
return getOrSetType(name, () =>
20-
// $FlowFixMe
2120
InputTypeComposer.create({
2221
name,
2322
description,
@@ -31,5 +30,6 @@ export function getDiversifiedSamplerITC(opts: mixed = {}): InputTypeComposer {
3130
script: () => getCommonsScriptITC(opts),
3231
execution_hint: 'String',
3332
},
34-
}));
33+
})
34+
);
3535
}

src/elasticDSL/Aggs/Bucket/Filters.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export function getFiltersITC(opts: mixed = {}): InputTypeComposer {
1515
);
1616

1717
return getOrSetType(name, () =>
18-
// $FlowFixMe
1918
InputTypeComposer.create({
2019
name,
2120
description,
@@ -24,5 +23,6 @@ export function getFiltersITC(opts: mixed = {}): InputTypeComposer {
2423
other_bucket: 'Boolean',
2524
other_bucket_key: 'String',
2625
},
27-
}));
26+
})
27+
);
2828
}

0 commit comments

Comments
 (0)