Skip to content

Commit 6fed21d

Browse files
committed
fix(ElasticApiParser): Add methods which defined via square brackets
1 parent 5429d66 commit 6fed21d

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
8181
"docker": "npm run docker:v5",
8282
"docker:v2": "node ./scripts/docker/start 2 & wait",
83-
"docker:v5": "node ./scripts/docker/start 5 & wait"
83+
"docker:v5": "node ./scripts/docker/start 5 & wait",
84+
"link": "yarn build && yarn link graphql && yarn link graphql-compose && yarn link",
85+
"unlink": "yarn unlink graphql && yarn unlink graphql-compose && yarn add graphql graphql-compose"
8486
}
8587
}

src/ElasticApiParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export default class ElasticApiParser {
203203
}
204204

205205
static getMethodName(str: string): string | string[] {
206-
const parts = str.split('.');
206+
const parts = str.replace(/\['(.+)'\]/, '.$1').split('.');
207207
if (parts[0] === 'api') {
208208
parts.shift();
209209
}

src/__mocks__/apiPartial.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,32 @@ api.cat.prototype.allocation = ca({
491491
}
492492
]
493493
});
494+
495+
/**
496+
* Perform a [indices.delete](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-delete-index.html) request
497+
*
498+
* @param {Object} params - An object with parameters used to carry out this action
499+
* @param {<<api-param-type-duration-string,`DurationString`>>} params.timeout - Explicit operation timeout
500+
* @param {<<api-param-type-duration-string,`DurationString`>>} params.masterTimeout - Specify timeout for connection to master
501+
* @param {<<api-param-type-string,`String`>>, <<api-param-type-string-array,`String[]`>>, <<api-param-type-boolean,`Boolean`>>} params.index - A comma-separated list of indices to delete; use `_all` or `*` string to delete all indices
502+
*/
503+
api.indices.prototype['delete'] = ca({
504+
params: {
505+
timeout: {
506+
type: 'time'
507+
},
508+
masterTimeout: {
509+
type: 'time',
510+
name: 'master_timeout'
511+
}
512+
},
513+
url: {
514+
fmt: '/<%=index%>',
515+
req: {
516+
index: {
517+
type: 'list'
518+
}
519+
}
520+
},
521+
method: 'DELETE'
522+
});

src/__tests__/ElasticApiParser-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,20 @@ describe('ElasticApiParser', () => {
201201
expect(ElasticApiParser.getMethodName('api.updateByQuery')).toEqual(
202202
'updateByQuery'
203203
);
204+
205+
expect(ElasticApiParser.getMethodName(`api['delete']`)).toEqual(
206+
'delete'
207+
);
204208
});
205209

206210
it('should return array of string', () => {
207211
expect(
208212
ElasticApiParser.getMethodName('api.cat.prototype.allocation')
209213
).toEqual(['cat', 'allocation']);
214+
215+
expect(
216+
ElasticApiParser.getMethodName(`api.indices.prototype['delete']`)
217+
).toEqual(['indices', 'delete']);
210218
});
211219
});
212220

0 commit comments

Comments
 (0)