Merge pull request #21679 from SimonSchick/elastic/errors

elasticsearch: add error classes, flatten definitions, lint
This commit is contained in:
Benjamin Lichtman
2017-11-27 12:31:49 -05:00
committed by GitHub
5 changed files with 1640 additions and 1657 deletions
+31 -28
View File
@@ -1,6 +1,6 @@
import elasticsearch = require("elasticsearch");
import * as elasticsearch from "elasticsearch";
var client = new elasticsearch.Client({
let client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
@@ -10,26 +10,26 @@ client = new elasticsearch.Client({
'box1.server.org',
'box2.server.org'
],
selector: function (hosts: any) { }
selector: (hosts: any) => { }
});
client.ping({
requestTimeout: 30000
}, function (error) {
}, (error) => {
});
client.search({
q: 'pants'
}).then(function (body) {
var hits = body.hits.hits;
}, function (error) {
}).then((body) => {
const hits = body.hits.hits;
}, (error) => {
});
client.indices.delete({
index: 'test_index',
ignore: [404]
}).then(function (body) {
}, function (error) {
}).then((body) => {
}, (error) => {
});
client.deleteByQuery({
@@ -39,8 +39,8 @@ client.deleteByQuery({
query: {
}
}
}).then(function (response) {
}, function (error) {
}).then((response) => {
}, (error) => {
});
client.create({
@@ -103,7 +103,7 @@ client.cluster.stats({
client.count({
index: 'index_name'
}, function (error, response) {
}, (error, response) => {
// ...
});
@@ -120,7 +120,7 @@ client.count({
}
}
}
}, function (err, response) {
}, (err, response) => {
// ...
});
@@ -132,7 +132,7 @@ client.explain({
// the query to score it against
q: 'field:value'
}, function (error, response) {
}, (error, response) => {
// ...
});
@@ -145,7 +145,7 @@ client.explain({
match: { title: 'test' }
}
}
}, function (error, response) {
}, (error, response) => {
// ...
});
@@ -158,8 +158,7 @@ client.index({
tags: ['y', 'z'],
published: true,
}
}, function (error, response) {
}, (error, response) => {
});
client.mget({
@@ -170,7 +169,7 @@ client.mget({
{ _index: 'indexC', _type: 'typeC', _id: '1' }
]
}
}, function (error, response) {
}, (error, response) => {
// ...
});
@@ -180,14 +179,14 @@ client.mget({
body: {
ids: [1, 2, 3]
}
}, function (error, response) {
}, (error, response) => {
// ...
});
client.search({
index: 'myindex',
q: 'title:test'
}, function (error, response) {
}, (error, response) => {
// ...
});
@@ -207,7 +206,7 @@ client.search({
}
}
}
}, function (error, response) {
}, (error, response) => {
// ...
});
@@ -221,12 +220,11 @@ client.suggest({
}
}
}
}, function (error, response) {
}, (error, response) => {
});
// first we do a search, and specify a scroll timeout
var allTitles: string[] = [];
const allTitles: string[] = [];
client.search({
index: 'myindex',
// Set to 30 seconds because we are calling right back
@@ -236,14 +234,14 @@ client.search({
q: 'title:test'
}, function getMoreUntilDone(error, response) {
// collect the title from each response
response.hits.hits.forEach(function (hit) {
response.hits.hits.forEach((hit) => {
allTitles.push(hit.fields.title);
});
if (response.hits.total !== allTitles.length) {
// now we can call scroll over and over
client.scroll({
scrollId: response._scroll_id,
scrollId: response._scroll_id!,
scroll: '30s'
}, getMoreUntilDone);
} else {
@@ -258,8 +256,13 @@ client.indices.updateAliases({
{ add: { index: 'logstash-2014.05', alias: 'logstash-current' } }
]
}
}).then(function (response) {
}).then((response) => {
// ...
}, function (error) {
}, (error) => {
// ...
});
// Errors
function testErrors() {
throw new elasticsearch.errors.AuthenticationException();
}
+1605 -1554
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -7,7 +7,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
@@ -21,4 +21,4 @@
"index.d.ts",
"elasticsearch-tests.ts"
]
}
}
+1 -73
View File
@@ -1,79 +1,7 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
"no-empty-interface": false
}
}
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/TheDeveloper/http-aws-es#readme
// Definitions by: Marco Gonzalez <https://github.com/marcogrcr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
/// <reference types="node" />