mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 06:50:19 +00:00
[algoliasearch]: fix typing for browse & browseAll
This commit is contained in:
@@ -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']
|
||||
})
|
||||
|
||||
Vendored
+26
-3
@@ -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 <https://github.com/cbaptiste>
|
||||
// Haroen Viaene <https://github.com/haroenv>
|
||||
@@ -7,6 +7,8 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
|
||||
|
||||
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<BrowseResponse>;
|
||||
browse(query: string, parameters?: BrowseParameters): Promise<BrowseResponse>;
|
||||
/**
|
||||
* 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<Response>;
|
||||
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
|
||||
*/
|
||||
|
||||
Vendored
+18
-3
@@ -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 <https://github.com/cbaptiste>
|
||||
// Haroen Viaene <https://github.com/haroenv>
|
||||
@@ -8,6 +8,8 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
|
||||
|
||||
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<BrowseResponse>;
|
||||
browse(query: string, parameters?: BrowseParameters): Promise<BrowseResponse>;
|
||||
/**
|
||||
* 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
|
||||
|
||||
Reference in New Issue
Block a user