From 96b9ca5e82123c106b7be832acb1e985358b3d37 Mon Sep 17 00:00:00 2001 From: Casper Skydt Date: Thu, 23 Jun 2016 10:02:37 +0200 Subject: [PATCH 1/4] Added elasticsearch --- elasticsearch/elasticsearch-tests.ts | 27 +++ elasticsearch/elasticsearch.d.ts | 253 +++++++++++++++++++++++++++ 2 files changed, 280 insertions(+) create mode 100644 elasticsearch/elasticsearch-tests.ts create mode 100644 elasticsearch/elasticsearch.d.ts diff --git a/elasticsearch/elasticsearch-tests.ts b/elasticsearch/elasticsearch-tests.ts new file mode 100644 index 0000000000..784e965fec --- /dev/null +++ b/elasticsearch/elasticsearch-tests.ts @@ -0,0 +1,27 @@ +/// +import elasticsearch = require("elasticsearch"); + +var client = new elasticsearch.Client({ + host: 'localhost:9200', + log: 'trace' +}); + +client.ping({ + requestTimeout: 30000, + hello: "elasticsearch" +}, function (error) { +}); + +client.search({ + q: 'pants' +}).then(function (body) { + var hits = body.hits.hits; +}, function (error) { +}); + +client.indices.delete({ + index: 'test_index', + ignore: [404] +}).then(function (body) { +}, function (error) { +}); \ No newline at end of file diff --git a/elasticsearch/elasticsearch.d.ts b/elasticsearch/elasticsearch.d.ts new file mode 100644 index 0000000000..7d692d6a31 --- /dev/null +++ b/elasticsearch/elasticsearch.d.ts @@ -0,0 +1,253 @@ +// Type definitions for elasticsearch +// Project: https://www.npmjs.com/package/elasticsearch +// Definitions by: Casper Skydt +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module Elasticsearch { + export class Client { + constructor(params: any); + indices: Indices; + bulk(params: BulkIndexDocumentsParams): IPromise; + bulk(params: BulkIndexDocumentsParams, callback: (error: any, response: any) => void): void; + delete(params: DeleteDocumentParams): IPromise; + delete(params: DeleteDocumentParams, callback: (error: any, response: any) => void): void; + get(params: GetParams, callback: (error: any, response: any) => void): void; + get(params: GetParams): IPromise>; + index(params: IndexDocumentParams): IPromise; + index(params: IndexDocumentParams, callback: (error: any, response: any) => void): void; + mget(params: MGetParams, callback: (error: any, response: any) => void): void; + mget(params: MGetParams): IPromise>; + msearch(params: MSearchParams, callback: (error: any, response: any) => void): void; + msearch(params: MSearchParams): IPromise>; + ping(params: PingParams): IPromise; + ping(params: PingParams, callback: (err: any, response: any, status: any) => void): void; + scroll(params: ScrollParams): IPromise; + scroll(params: ScrollParams, callback: (error: any, response: any) => void): void; + search(params: SearchParams): IPromise; + search(params: SearchParams, callback: (error: any, response: any) => void): void; + suggest(params: SuggestParams): IPromise; + suggest(params: SuggestParams, callback: (error: any, response: any) => void): void; + update(params: UpdateDocumentParams): IPromise; + update(params: UpdateDocumentParams, callback: (error: any, response: any) => void): void; + } + + export class Indices { + delete(params: IndicesDeleteParams, callback: (error: any, response: any, status: any) => void): void; + delete(params: IndicesDeleteParams): IPromise; + create(params: IndicesCreateParams, callback: (error: any, response: any, status: any) => void): void; + create(params: IndicesCreateParams): IPromise; + exists(params: IndicesIndexExitsParams, callback: (error: any, response: any, status: any) => void): void; + exists(params: IndicesIndexExitsParams): IPromise; + get(params: IndicesGetParams, callback: (error: any, response: any, status: any) => void): void; + get(params: IndicesGetParams): IPromise; + getAlias(params: IndicesGetAliasParams, callback: (error: any, response: any, status: any) => void): void; + getAlias(params: IndicesGetAliasParams): IPromise; + putAlias(params: IndicesPutAliasParams, callback: (error: any, response: any, status: any) => void): void; + putAlias(params: IndicesPutAliasParams): IPromise; + putTemplate(params: IndicesPutTemplateParams, callback: (error: any, response: any) => void): void; + putTemplate(params: IndicesPutTemplateParams): IPromise; + refresh(params: IndicesRefreshParams, callback: (error: any, response: any) => void): void; + refresh(params: IndicesRefreshParams): IPromise; + } + + export interface GenericParams { + requestTimeout?: number; + maxRetries?: number; + method?: string; + body?: string | any; + ignore?: number | number[]; + } + + export interface BulkIndexDocumentsParams extends GenericParams { + refresh?: boolean; + routing? : string; + timeout?: number | Date; + type?: string; + fields?: string | string[] | boolean; + index?: string; + } + + export interface IndicesGetParams extends GenericParams { + ignoreUnavailable?: boolean; + index: string | string[] | boolean; + } + + export interface IndicesRefreshParams extends GenericParams { + force?: boolean; + ignoreUnavailable?: boolean; + index: string | string[] | boolean; + } + + export interface IndicesDeleteParams extends GenericParams { + index: string | string[] | boolean; + timeout?: Date | number; + masterTimeout?: Date | number; + } + + export interface IndicesCreateParams extends GenericParams { + index: string | string[] | boolean; + timeout?: Date | number; + masterTimeout?: Date | number; + } + + export interface IndicesPutTemplateParams extends GenericParams { + order?: number; + create?: boolean; + timeout?: Date | number; + masterTimeout?: Date | number; + flatSettings?: boolean; + name: string; + body: string | any; + } + + export interface IndicesGetAliasParams extends GenericParams { + ignoreUnavailable?: boolean; + allowNoIndices?: boolean; + expandWildcards?: string; + local?: boolean; + index?: string | string[] | boolean; + name: string | string[] | boolean; + } + + export interface IndicesPutAliasParams extends GenericParams { + index?: string | string[] | boolean; + name: string | string[] | boolean; + } + + export interface GetParams extends GenericParams { + index: string; + type: string; + id: string; + fields?: string | string[] | boolean; + parent?: string; + preference?: string; + realtime?: boolean; + refresh?: boolean; + routing?: string; + _source?: string | string[] | boolean; + _sourceExclude?: string | string[] | boolean; + _sourceInclude?: string | string[] | boolean; + version?: number; + versionType?: string; + } + + export interface GetResponse extends GenericParams { + _type: string; + _id: string; + _version: number; + found: boolean; + _source: T; + } + + export interface IndexDocumentParams extends GenericParams { + index: string; + type: string; + id: string; + body: T; + consistensy?: string; + parent?: string; + replication?: string; + routing?: string; + timeout?: Date | number; + timestamp?: Date | number; + version?: number; + versionType?: string; + } + + export interface ScrollParams extends GenericParams { + scroll: string; + scrollId: string; + } + + export interface SearchParams extends GenericParams { + index?: string; + type?: string | string[] | number; + body?: any; + q?: string; + scroll?: string; + search_type?: string; + fields?: string[]; + size?: number; + sort?: string | string[] | boolean; + _source?: string | string[] | boolean; + _sourceExclude?: string | string[] | boolean; + _sourceInclude?: string | string[] | boolean; + stats?: string | string[] | boolean; + suggestField?: string; + suggestSize?: number; + suggestText?: string; + timeout?: Date | number; + } + + export interface MSearchParams extends GenericParams { + index?: string | string[] | Boolean; + type?: string | string[] | Boolean; + search_type?: string; + } + + export interface MGetParams extends GenericParams { + fields?: string | string[] | Boolean; + preference?: string; + realtime?: Boolean; + refresh?: Boolean; + _sourceExclude?: string | string[] | boolean; + _sourceInclude?: string | string[] | boolean; + index?: string; + type?: string; + } + + export interface IndicesIndexExitsParams extends GenericParams { + index: string | string[] | boolean; + ignoreUnavailable?: boolean; + } + + export interface PingParams extends GenericParams { + requestTimeout?: number; + hello?: string; + } + + export interface DeleteDocumentParams extends GenericParams { + index: string; + type: string; + id: string; + refresh?: boolean; + } + + export interface UpdateDocumentParams extends GenericParams { + index: string; + type: string; + id: string; + body?: string | any; + version?: Number; + timesstamp?: Date | Number; + scriptedUpsert?: Boolean; + scriptId?: any; + script?: any; + routing?: string; + retryOnConflict?: Number; + refresh?: Boolean; + parent?: string; + lang?:string; + fields?: string | string[] | Boolean; + consistensy?: string; + } + + export interface SuggestParams extends GenericParams { + ignoreUnavailable?: boolean; + allowNoIndices?: boolean; + expandWildcards?: string; + preference?: string; + routing?: string; + source?: string; + body: string | any; + index: string | string[] | boolean; + } + + export interface IPromise { + then(resolve: (response: T) => void, reject: (error: any) => void): any; + } +} + +declare module "elasticsearch" { + export = Elasticsearch; +} From 43365544c225efd521f0391b68121db5d85d31f7 Mon Sep 17 00:00:00 2001 From: Casper Skydt Date: Fri, 24 Jun 2016 07:57:19 +0200 Subject: [PATCH 2/4] Review changes --- elasticsearch/elasticsearch-tests.ts | 8 ++++ elasticsearch/elasticsearch.d.ts | 71 ++++++++++++++++++---------- 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/elasticsearch/elasticsearch-tests.ts b/elasticsearch/elasticsearch-tests.ts index 784e965fec..9a85f2c908 100644 --- a/elasticsearch/elasticsearch-tests.ts +++ b/elasticsearch/elasticsearch-tests.ts @@ -6,6 +6,14 @@ var client = new elasticsearch.Client({ log: 'trace' }); +client = new elasticsearch.Client({ + hosts: [ + 'box1.server.org', + 'box2.server.org' + ], + selector: function (hosts: any) { } +}); + client.ping({ requestTimeout: 30000, hello: "elasticsearch" diff --git a/elasticsearch/elasticsearch.d.ts b/elasticsearch/elasticsearch.d.ts index 7d692d6a31..7d0f86a651 100644 --- a/elasticsearch/elasticsearch.d.ts +++ b/elasticsearch/elasticsearch.d.ts @@ -1,53 +1,78 @@ // Type definitions for elasticsearch -// Project: https://www.npmjs.com/package/elasticsearch +// Project: https://www.npmjs.com/package/elasticsearch | https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html // Definitions by: Casper Skydt // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare module Elasticsearch { export class Client { - constructor(params: any); + constructor(params: ConfigOptions); indices: Indices; - bulk(params: BulkIndexDocumentsParams): IPromise; + bulk(params: BulkIndexDocumentsParams): PromiseLike; bulk(params: BulkIndexDocumentsParams, callback: (error: any, response: any) => void): void; - delete(params: DeleteDocumentParams): IPromise; + delete(params: DeleteDocumentParams): PromiseLike; delete(params: DeleteDocumentParams, callback: (error: any, response: any) => void): void; get(params: GetParams, callback: (error: any, response: any) => void): void; - get(params: GetParams): IPromise>; - index(params: IndexDocumentParams): IPromise; + get(params: GetParams): PromiseLike>; + index(params: IndexDocumentParams): PromiseLike; index(params: IndexDocumentParams, callback: (error: any, response: any) => void): void; mget(params: MGetParams, callback: (error: any, response: any) => void): void; - mget(params: MGetParams): IPromise>; + mget(params: MGetParams): PromiseLike>; msearch(params: MSearchParams, callback: (error: any, response: any) => void): void; - msearch(params: MSearchParams): IPromise>; - ping(params: PingParams): IPromise; + msearch(params: MSearchParams): PromiseLike>; + ping(params: PingParams): PromiseLike; ping(params: PingParams, callback: (err: any, response: any, status: any) => void): void; - scroll(params: ScrollParams): IPromise; + scroll(params: ScrollParams): PromiseLike; scroll(params: ScrollParams, callback: (error: any, response: any) => void): void; - search(params: SearchParams): IPromise; + search(params: SearchParams): PromiseLike; search(params: SearchParams, callback: (error: any, response: any) => void): void; - suggest(params: SuggestParams): IPromise; + suggest(params: SuggestParams): PromiseLike; suggest(params: SuggestParams, callback: (error: any, response: any) => void): void; - update(params: UpdateDocumentParams): IPromise; + update(params: UpdateDocumentParams): PromiseLike; update(params: UpdateDocumentParams, callback: (error: any, response: any) => void): void; } export class Indices { delete(params: IndicesDeleteParams, callback: (error: any, response: any, status: any) => void): void; - delete(params: IndicesDeleteParams): IPromise; + delete(params: IndicesDeleteParams): PromiseLike; create(params: IndicesCreateParams, callback: (error: any, response: any, status: any) => void): void; - create(params: IndicesCreateParams): IPromise; + create(params: IndicesCreateParams): PromiseLike; exists(params: IndicesIndexExitsParams, callback: (error: any, response: any, status: any) => void): void; - exists(params: IndicesIndexExitsParams): IPromise; + exists(params: IndicesIndexExitsParams): PromiseLike; get(params: IndicesGetParams, callback: (error: any, response: any, status: any) => void): void; - get(params: IndicesGetParams): IPromise; + get(params: IndicesGetParams): PromiseLike; getAlias(params: IndicesGetAliasParams, callback: (error: any, response: any, status: any) => void): void; - getAlias(params: IndicesGetAliasParams): IPromise; + getAlias(params: IndicesGetAliasParams): PromiseLike; putAlias(params: IndicesPutAliasParams, callback: (error: any, response: any, status: any) => void): void; - putAlias(params: IndicesPutAliasParams): IPromise; + putAlias(params: IndicesPutAliasParams): PromiseLike; putTemplate(params: IndicesPutTemplateParams, callback: (error: any, response: any) => void): void; - putTemplate(params: IndicesPutTemplateParams): IPromise; + putTemplate(params: IndicesPutTemplateParams): PromiseLike; refresh(params: IndicesRefreshParams, callback: (error: any, response: any) => void): void; - refresh(params: IndicesRefreshParams): IPromise; + refresh(params: IndicesRefreshParams): PromiseLike; + } + + export interface ConfigOptions{ + host?: string | string[] | any; + hosts?: string | string[] | any; + log?: string | string[] | any | any[]; + apiVersion?: string; + plugins?: any; + sniffOnStart?: boolean; + sniffInterval?: number; + sniffOnConnectionFault?: boolean; + maxRetries?: number; + requestTimeout?: number; + deadTimeout?: number; + pingTimeout?: number; + keepAlive?: boolean; + maxSockets?: number; + suggestCompression?: boolean; + connectionClass?: string; + sniffedNodesProtocol?: string; + ssl?: Object; + selector?: string | any; + defer?: () => void; + nodesToHostCallback?: any; + createNodeAgent?: any; } export interface GenericParams { @@ -242,10 +267,6 @@ declare module Elasticsearch { body: string | any; index: string | string[] | boolean; } - - export interface IPromise { - then(resolve: (response: T) => void, reject: (error: any) => void): any; - } } declare module "elasticsearch" { From 3ad90d539d9071a407207fa8f1b3c2c2f7d2d12b Mon Sep 17 00:00:00 2001 From: Casper Skydt Date: Fri, 24 Jun 2016 08:02:13 +0200 Subject: [PATCH 3/4] Removed linebreak --- elasticsearch/elasticsearch.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticsearch/elasticsearch.d.ts b/elasticsearch/elasticsearch.d.ts index 7d0f86a651..a4acc3f825 100644 --- a/elasticsearch/elasticsearch.d.ts +++ b/elasticsearch/elasticsearch.d.ts @@ -1,5 +1,5 @@ // Type definitions for elasticsearch -// Project: https://www.npmjs.com/package/elasticsearch | https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html +// Project: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html // Definitions by: Casper Skydt // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped From c817cb6838099699f044f7011321b6a575ba587d Mon Sep 17 00:00:00 2001 From: Casper Skydt Date: Fri, 24 Jun 2016 09:29:00 +0200 Subject: [PATCH 4/4] Removed unnessesary options --- elasticsearch/elasticsearch.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/elasticsearch/elasticsearch.d.ts b/elasticsearch/elasticsearch.d.ts index a4acc3f825..5b7ba8055c 100644 --- a/elasticsearch/elasticsearch.d.ts +++ b/elasticsearch/elasticsearch.d.ts @@ -51,9 +51,9 @@ declare module Elasticsearch { } export interface ConfigOptions{ - host?: string | string[] | any; - hosts?: string | string[] | any; - log?: string | string[] | any | any[]; + host?: any; + hosts?: any; + log?: any; apiVersion?: string; plugins?: any; sniffOnStart?: boolean; @@ -69,7 +69,7 @@ declare module Elasticsearch { connectionClass?: string; sniffedNodesProtocol?: string; ssl?: Object; - selector?: string | any; + selector?: any; defer?: () => void; nodesToHostCallback?: any; createNodeAgent?: any; @@ -79,7 +79,7 @@ declare module Elasticsearch { requestTimeout?: number; maxRetries?: number; method?: string; - body?: string | any; + body?: any; ignore?: number | number[]; }