From 0d1ee2470cdf7883f8d5cc074aef97d9450c9081 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Mon, 14 May 2018 13:21:16 +0200 Subject: [PATCH 1/6] fix(algolia): correct signature of copyIndex the scope is optional --- types/algoliasearch/index.d.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/types/algoliasearch/index.d.ts b/types/algoliasearch/index.d.ts index 87c1f79a0e..74fa64d0d5 100644 --- a/types/algoliasearch/index.d.ts +++ b/types/algoliasearch/index.d.ts @@ -88,7 +88,16 @@ declare namespace algoliasearch { */ deleteIndex(name: string): Promise; /** - * Copy an index from a specific index to a new one + * Copy an index from a specific index to a new one + * https://github.com/algolia/algoliasearch-client-js#copy-index---copyindex + */ + copyIndex( + from: string, + to: string, + cb: (err: Error, res: Task) => void + ): void; + /** + * Copy settings of an index from a specific index to a new one * https://github.com/algolia/algoliasearch-client-js#copy-index---copyindex */ copyIndex( @@ -98,13 +107,13 @@ declare namespace algoliasearch { cb: (err: Error, res: Task) => void ): void; /** - * Copy an index from a specific index to a new one + * Copy settings of an index from a specific index to a new one * https://github.com/algolia/algoliasearch-client-js#copy-index---copyindex */ copyIndex( from: string, to: string, - scope: ('settings' | 'synonyms' | 'rules')[] + scope?: ('settings' | 'synonyms' | 'rules')[] ): Promise; /** * Move index to a new one (and will overwrite the original one) @@ -230,6 +239,7 @@ declare namespace algoliasearch { * Interface for the index algolia object */ interface Index { + indexName: string; /** * Gets a specific object * https://github.com/algolia/algoliasearch-client-js#find-by-ids---getobjects From a77cf124c2b2681a5494dec6ead7e8ae39bc05f3 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Mon, 14 May 2018 13:27:42 +0200 Subject: [PATCH 2/6] chore: add tests --- types/algoliasearch/algoliasearch-tests.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/types/algoliasearch/algoliasearch-tests.ts b/types/algoliasearch/algoliasearch-tests.ts index 2898f889fc..dcc1fdcc9e 100644 --- a/types/algoliasearch/algoliasearch-tests.ts +++ b/types/algoliasearch/algoliasearch-tests.ts @@ -10,6 +10,7 @@ import { IndexSettings, QueryParameters, } from 'algoliasearch'; +import { Client } from './lite'; let _algoliaResponse: Response = { hits: [{}, {}], @@ -147,6 +148,7 @@ let _algoliaQueryParameters: QueryParameters = { minProximity: 0, }; +let client: Client = algoliasearch('', ''); let index: Index = algoliasearch('', '').initIndex(''); let search = index.search({ query: '' }); @@ -164,3 +166,12 @@ index.partialUpdateObjects([{}], () => {}); index.partialUpdateObjects([{}], false, () => {}); index.partialUpdateObjects([{}]).then(() => {}); index.partialUpdateObjects([{}], false).then(() => {}); + +let indexName : string = index.indexName; + +// complete copy +algoliasearch('','').copyIndex('from', 'to').then(()=>{}) +algoliasearch('','').copyIndex('from', 'to', ()=> {}) +// with scope +algoliasearch('','').copyIndex('from', 'to', ['settings']).then(()=>{}) +algoliasearch('','').copyIndex('from', 'to', ['synonyms', 'rules'], ()=> {}) From 0d005626d507a2e482dfeb5cd546eaef9357828a Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Mon, 14 May 2018 13:30:37 +0200 Subject: [PATCH 3/6] fix: correct import --- types/algoliasearch/algoliasearch-tests.ts | 12 ++++++------ types/algoliasearch/lite/index.d.ts | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/types/algoliasearch/algoliasearch-tests.ts b/types/algoliasearch/algoliasearch-tests.ts index dcc1fdcc9e..2a3fcd2eb2 100644 --- a/types/algoliasearch/algoliasearch-tests.ts +++ b/types/algoliasearch/algoliasearch-tests.ts @@ -9,8 +9,8 @@ import { Response, IndexSettings, QueryParameters, + Client } from 'algoliasearch'; -import { Client } from './lite'; let _algoliaResponse: Response = { hits: [{}, {}], @@ -149,7 +149,7 @@ let _algoliaQueryParameters: QueryParameters = { }; let client: Client = algoliasearch('', ''); -let index: Index = algoliasearch('', '').initIndex(''); +let index: Index = client.initIndex(''); let search = index.search({ query: '' }); @@ -170,8 +170,8 @@ index.partialUpdateObjects([{}], false).then(() => {}); let indexName : string = index.indexName; // complete copy -algoliasearch('','').copyIndex('from', 'to').then(()=>{}) -algoliasearch('','').copyIndex('from', 'to', ()=> {}) +client.copyIndex('from', 'to').then(()=>{}) +client.copyIndex('from', 'to', ()=> {}) // with scope -algoliasearch('','').copyIndex('from', 'to', ['settings']).then(()=>{}) -algoliasearch('','').copyIndex('from', 'to', ['synonyms', 'rules'], ()=> {}) +client.copyIndex('from', 'to', ['settings']).then(()=>{}) +client.copyIndex('from', 'to', ['synonyms', 'rules'], ()=> {}) diff --git a/types/algoliasearch/lite/index.d.ts b/types/algoliasearch/lite/index.d.ts index 588e2ac543..1bb8254de9 100644 --- a/types/algoliasearch/lite/index.d.ts +++ b/types/algoliasearch/lite/index.d.ts @@ -67,6 +67,7 @@ declare namespace algoliasearch { * Interface for the index algolia object */ interface Index { + indexName: string; /** * Gets a specific object * https://github.com/algolia/algoliasearch-client-js#find-by-ids---getobjects From 7dcbb8074cd747ae7e5095b91e1121d56371a1b5 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Mon, 14 May 2018 13:32:57 +0200 Subject: [PATCH 4/6] feat: add Sam --- types/algoliasearch/index.d.ts | 1 + types/algoliasearch/lite/index.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/types/algoliasearch/index.d.ts b/types/algoliasearch/index.d.ts index 74fa64d0d5..b2e8f95663 100644 --- a/types/algoliasearch/index.d.ts +++ b/types/algoliasearch/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Baptiste Coquelle // Haroen Viaene // Aurélien Hervé +// Samuel Vaillant // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 diff --git a/types/algoliasearch/lite/index.d.ts b/types/algoliasearch/lite/index.d.ts index 1bb8254de9..b9932f1346 100644 --- a/types/algoliasearch/lite/index.d.ts +++ b/types/algoliasearch/lite/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Baptiste Coquelle // Haroen Viaene // Aurélien Hervé +// Samuel Vaillant // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 From 44b53c0f1e75b1ca625962af3aa8fb87d6315a20 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Mon, 14 May 2018 13:43:08 +0200 Subject: [PATCH 5/6] chore: add more info about tasks --- types/algoliasearch/index.d.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/types/algoliasearch/index.d.ts b/types/algoliasearch/index.d.ts index b2e8f95663..21ad90e665 100644 --- a/types/algoliasearch/index.d.ts +++ b/types/algoliasearch/index.d.ts @@ -340,7 +340,7 @@ declare namespace algoliasearch { * Wait for an indexing task to be compete * https://github.com/algolia/algoliasearch-client-js#wait-for-operations---waittask */ - waitTask(taskID: number, cb: (err: Error, res: any) => void): void; + waitTask(taskID: number, cb: (err: Error, res: TaskStatus) => void): void; /** * Get an index settings * https://github.com/algolia/algoliasearch-client-js#get-settings---getsettings @@ -572,7 +572,7 @@ declare namespace algoliasearch { * Wait for an indexing task to be compete * https://github.com/algolia/algoliasearch-client-js#wait-for-operations---waittask */ - waitTask(taskID: number): Promise; + waitTask(taskID: number): Promise; /** * Get an index settings * https://github.com/algolia/algoliasearch-client-js#get-settings---getsettings @@ -1492,6 +1492,13 @@ declare namespace algoliasearch { interface Task { taskID: number; + createdAt: string; + objectID?: string; + } + + interface TaskStatus { + status: 'published' | 'notPublished', + pendingTask: boolean, } interface IndexSettings { From a36bb6891a65c87b7b35be5240db1106594c2c8d Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Mon, 14 May 2018 13:48:42 +0200 Subject: [PATCH 6/6] chore: stricter settings type --- types/algoliasearch/algoliasearch-tests.ts | 4 ++-- types/algoliasearch/index.d.ts | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/types/algoliasearch/algoliasearch-tests.ts b/types/algoliasearch/algoliasearch-tests.ts index 2a3fcd2eb2..96270b31eb 100644 --- a/types/algoliasearch/algoliasearch-tests.ts +++ b/types/algoliasearch/algoliasearch-tests.ts @@ -79,7 +79,7 @@ let _algoliaIndexSettings: IndexSettings = { ignorePlurals: false, disableTypoToleranceOnAttributes: '', separatorsToIndex: '', - queryType: '', + queryType: 'prefixAll', removeWordsIfNoResults: '', advancedSyntax: false, optionalWords: [''], @@ -87,7 +87,7 @@ let _algoliaIndexSettings: IndexSettings = { disablePrefixOnAttributes: [''], disableExactOnAttributes: [''], exactOnSingleWordQuery: '', - alternativesAsExact: false, + alternativesAsExact: ['ignorePlurals'], attributeForDistinct: '', distinct: false, numericAttributesToIndex: [''], diff --git a/types/algoliasearch/index.d.ts b/types/algoliasearch/index.d.ts index 21ad90e665..ba46f37ce6 100644 --- a/types/algoliasearch/index.d.ts +++ b/types/algoliasearch/index.d.ts @@ -1619,7 +1619,7 @@ declare namespace algoliasearch { * 'strict' Hits matching with 2 typos are not retrieved if there are some matching without typos. * https://github.com/algolia/algoliasearch-client-js#typotolerance */ - typoTolerance?: any; + typoTolerance?: boolean | 'min' | 'strict'; /** * If set to false, disables typo tolerance on numeric tokens (numbers). * default: true @@ -1652,7 +1652,7 @@ declare namespace algoliasearch { * 'prefixNone' No query word is interpreted as a prefix. This option is not recommended. * https://github.com/algolia/algoliasearch-client-js#querytype */ - queryType?: any; + queryType?: 'prefixAll' | 'prefixLast' | 'prefixNone'; /** * This option is used to select a strategy in order to avoid having an empty result page * default: 'none' @@ -1718,7 +1718,10 @@ declare namespace algoliasearch { * 'multiWordsSynonym': multiple-words synonym * https://github.com/algolia/algoliasearch-client-js#alternativesasexact */ - alternativesAsExact?: any; + alternativesAsExact?: ( + | "ignorePlurals" + | "singleWordSynonym" + | "multiWordsSynonym")[]; /** * The name of the attribute used for the Distinct feature * default: null @@ -1729,7 +1732,7 @@ declare namespace algoliasearch { * If set to 1, enables the distinct feature, disabled by default, if the attributeForDistinct index setting is set. * https://github.com/algolia/algoliasearch-client-js#distinct */ - distinct?: any; + distinct?: boolean | number; /** * All numerical attributes are automatically indexed as numerical filters * default ''