Skip to content

Commit be31a39

Browse files
committed
fix(ElasticApiParser): Support new format of the api list in elasticsearch 13.0
closes #1
1 parent a756939 commit be31a39

File tree

4 files changed

+112
-114
lines changed

4 files changed

+112
-114
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"babel-plugin-transform-object-rest-spread": "^6.22.0",
3737
"babel-preset-env": "^1.4.0",
3838
"cz-conventional-changelog": "^2.0.0",
39-
"elasticsearch": "^12.1.3",
39+
"elasticsearch": "^13.0.0",
4040
"eslint": "^3.19.0",
4141
"eslint-config-airbnb-base": "^11.1.3",
4242
"eslint-config-prettier": "^1.7.0",
@@ -46,7 +46,7 @@
4646
"express": "^4.15.2",
4747
"express-graphql": "^0.6.4",
4848
"flow-bin": "^0.45.0",
49-
"graphql": "^0.9.4",
49+
"graphql": "^0.9.6",
5050
"graphql-compose": "^1.18.1",
5151
"jest": "^19.0.2",
5252
"jest-babel": "^1.0.1",

src/ElasticApiParser.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,23 @@ export default class ElasticApiParser {
130130
const apiFolder = './node_modules/elasticsearch/src/lib/apis/';
131131
const apiListFile = path.resolve(apiFolder, 'index.js');
132132
const apiListCode = ElasticApiParser.loadApiListFile(apiListFile);
133-
const re = new RegExp(`\\'${version}\\':\\srequire\\(\\'(.+)\\'\\)`, 'gi');
133+
134+
// parsing elasticsearch module 13.x and above
135+
// get '5.3'() { return require('./5_3'); },
136+
const re = new RegExp(`\\'${version}\\'\\(\\).*require\\(\\'(.+)\\'\\)`, 'gi');
134137
const match = re.exec(apiListCode);
135138
if (match && match[1]) {
136139
return path.resolve(apiFolder, `${match[1]}.js`);
137140
}
141+
142+
// parsing elasticsearch module 12.x and below
143+
// '5.0': require('./5_0'),
144+
const re12 = new RegExp(`\\'${version}\\':\\srequire\\(\\'(.+)\\'\\)`, 'gi');
145+
const match12 = re12.exec(apiListCode);
146+
if (match12 && match12[1]) {
147+
return path.resolve(apiFolder, `${match12[1]}.js`);
148+
}
149+
138150
throw new Error(
139151
`Can not found Elastic version '${version}' in ${apiListFile}`
140152
);

src/__tests__/ElasticApiParser-test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('ElasticApiParser', () => {
4545
});
4646

4747
describe('findApiVersionFile()', () => {
48-
it('should find proper version', () => {
48+
it('should find proper version in elasticsearch 12.x', () => {
4949
const loadApiListFile = ElasticApiParser.loadApiListFile;
5050
// $FlowFixMe
5151
ElasticApiParser.loadApiListFile = () =>
@@ -82,6 +82,46 @@ describe('ElasticApiParser', () => {
8282
// $FlowFixMe
8383
ElasticApiParser.loadApiListFile = loadApiListFile;
8484
});
85+
86+
it('should find proper version in elasticsearch 13.x', () => {
87+
const loadApiListFile = ElasticApiParser.loadApiListFile;
88+
// $FlowFixMe
89+
ElasticApiParser.loadApiListFile = () =>
90+
`
91+
module.exports = {
92+
get '_default'() { return require('./5_3'); },
93+
get '5.3'() { return require('./5_3'); },
94+
get '5.2'() { return require('./5_2'); },
95+
get '5.1'() { return require('./5_1'); },
96+
get '5.0'() { return require('./5_0'); },
97+
get '2.4'() { return require('./2_4'); },
98+
get '1.7'() { return require('./1_7'); },
99+
get '0.90'() { return require('./0_90'); },
100+
get '5.x'() { return require('./5_x'); },
101+
get 'master'() { return require('./master'); },
102+
};
103+
`;
104+
105+
expect(ElasticApiParser.findApiVersionFile('5.0')).toMatch(
106+
// $FlowFixMe
107+
'elasticsearch/src/lib/apis/5_0.js'
108+
);
109+
expect(ElasticApiParser.findApiVersionFile('2.4')).toMatch(
110+
// $FlowFixMe
111+
'elasticsearch/src/lib/apis/2_4.js'
112+
);
113+
expect(ElasticApiParser.findApiVersionFile('1.7')).toMatch(
114+
// $FlowFixMe
115+
'elasticsearch/src/lib/apis/1_7.js'
116+
);
117+
expect(ElasticApiParser.findApiVersionFile('_default')).toMatch(
118+
// $FlowFixMe
119+
'elasticsearch/src/lib/apis/5_3.js'
120+
);
121+
122+
// $FlowFixMe
123+
ElasticApiParser.loadApiListFile = loadApiListFile;
124+
});
85125
});
86126

87127
describe('cleanupDescription()', () => {

0 commit comments

Comments
 (0)