diff --git a/types/algoliasearch/algoliasearch-tests.ts b/types/algoliasearch/algoliasearch-tests.ts index b148e84599..a43a8a3b79 100644 --- a/types/algoliasearch/algoliasearch-tests.ts +++ b/types/algoliasearch/algoliasearch-tests.ts @@ -177,3 +177,31 @@ client.copyIndex('from', 'to', ()=> {}) // with scope client.copyIndex('from', 'to', ['settings']).then(()=>{}) client.copyIndex('from', 'to', ['synonyms', 'rules'], ()=> {}) + +// Browsing +const browser = index.browseAll(); +index.browseAll('query'); +index.browseAll('', { + filters: 'dog', +}); + +let hits: Object[] = []; + +browser.on('result', function onResult(content) { + hits = hits.concat(content.hits); +}); + +browser.on('end', function onEnd() { + const _message = `We got ${hits.length} hits` +}); + +browser.on('error', function onError(err) { + throw err; +}); + +browser.stop() + +index.browse("", { + advancedSyntax: false, + attributesToRetrieve: ['dogs'] +}) diff --git a/types/algoliasearch/index.d.ts b/types/algoliasearch/index.d.ts index a0bb0e0e45..34124fa111 100644 --- a/types/algoliasearch/index.d.ts +++ b/types/algoliasearch/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for algoliasearch-client-js 3.27.0 +// Type definitions for algoliasearch-client-js 3.30.0 // Project: https://github.com/algolia/algoliasearch-client-js // Definitions by: Baptiste Coquelle // Haroen Viaene @@ -7,6 +7,8 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 +type Omit = Pick> + declare namespace algoliasearch { /** * Interface for the algolia client object @@ -611,6 +613,11 @@ declare namespace algoliasearch { options: SearchForFacetValues.Parameters, cb: (err: Error, res: SearchForFacetValues.Response) => void ): void; + /** + * Browse an index + * https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse + */ + browse(query: string, parameters: BrowseParameters, cb: (err: Error, res: BrowseResponse) => void): void; /** * Browse an index * https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse @@ -620,7 +627,7 @@ declare namespace algoliasearch { * Browse an index * https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse */ - browse(query: string): Promise; + browse(query: string, parameters?: BrowseParameters): Promise; /** * Browse an index from a cursor * https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse @@ -638,7 +645,7 @@ declare namespace algoliasearch { * Browse an entire index * https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse */ - browseAll(): Promise; + browseAll(query?: string, parameters?: BrowseParameters): Browser; /** * Clear an index content * https://github.com/algolia/algoliasearch-client-js#clear-index---clearindex @@ -966,6 +973,22 @@ declare namespace algoliasearch { query: string; processingTimeMS: number; } + type BrowseParameters = Omit< + QueryParameters, + | "typoTolerance" + | "distinct" + | "facets" + | "getRankingInfo" + | "attributesToHighlight" + | "attributesToSnippet" + > + interface Browser { + on(type: "error", cb: (err: Error) => void): void + on(type: "end", cb: () => void): void + on(type: "stop", cb: () => void): void + on(type: "result", cb: (content: BrowseResponse) => void): void + stop(): void + } /** * Describes a synonym object */ diff --git a/types/algoliasearch/lite/index.d.ts b/types/algoliasearch/lite/index.d.ts index 4f068d5647..87eedb108d 100644 --- a/types/algoliasearch/lite/index.d.ts +++ b/types/algoliasearch/lite/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for algoliasearch-client-js 3.27.0 +// Type definitions for algoliasearch-client-js 3.30.0 // Project: https://github.com/algolia/algoliasearch-client-js // Definitions by: Baptiste Coquelle // Haroen Viaene @@ -8,6 +8,8 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 +type Omit = Pick> + declare namespace algoliasearch { /** * Interface for the algolia client object @@ -130,6 +132,11 @@ declare namespace algoliasearch { options: SearchForFacetValues.Parameters, cb: (err: Error, res: SearchForFacetValues.Response) => void ): void; + /** + * Browse an index + * https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse + */ + browse(query: string, parameters: BrowseParameters, cb: (err: Error, res: BrowseResponse) => void): void; /** * Browse an index * https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse @@ -139,7 +146,7 @@ declare namespace algoliasearch { * Browse an index * https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse */ - browse(query: string): Promise; + browse(query: string, parameters?: BrowseParameters): Promise; /** * Browse an index from a cursor * https://github.com/algolia/algoliasearch-client-js#backup--export-an-index---browse @@ -194,7 +201,15 @@ declare namespace algoliasearch { query: string; processingTimeMS: number; } - + type BrowseParameters = Omit< + QueryParameters, + | "typoTolerance" + | "distinct" + | "facets" + | "getRankingInfo" + | "attributesToHighlight" + | "attributesToSnippet" + > interface QueryParameters { /** * Query string used to perform the search