diff --git a/types/algoliasearch/algoliasearch-tests.ts b/types/algoliasearch/algoliasearch-tests.ts index a71779378a..6d4fede9fa 100644 --- a/types/algoliasearch/algoliasearch-tests.ts +++ b/types/algoliasearch/algoliasearch-tests.ts @@ -1,162 +1,167 @@ import * as algoliasearch from 'algoliasearch'; import { - ClientOptions, - SynonymOption, - ApiKeyOptions, - SearchSynonymOptions, - SecuredApiOptions, - Index, - Response, - IndexSettings, - QueryParameters, - Client, + ClientOptions, + SynonymOption, + ApiKeyOptions, + SearchSynonymOptions, + SecuredApiOptions, + Index, + Response, + IndexSettings, + QueryParameters, + ApiKey, + MultiResponse, + Client, } from 'algoliasearch'; import * as algoliasearchLite from 'algoliasearch/lite'; let _algoliaResponse: Response = { - hits: [{}, {}], - page: 0, - nbHits: 12, - nbPages: 6, - hitsPerPage: 2, - processingTimeMS: 32, - query: '', - params: '', - index: '', - exhaustiveFacetsCount: true, - exhaustiveNbHits: false, + hits: [{}, {}], + page: 0, + nbHits: 12, + nbPages: 6, + hitsPerPage: 2, + processingTimeMS: 32, + query: '', + params: '', + index: '', + exhaustiveFacetsCount: true, + exhaustiveNbHits: false, }; let _clientOptions: ClientOptions = { - timeout: 12, - protocol: '', - httpAgent: '', + timeout: 12, + protocol: '', + httpAgent: '', }; let _synonymOption: SynonymOption = { - forwardToReplicas: false, - replaceExistingSynonyms: false, + forwardToReplicas: false, + replaceExistingSynonyms: false, }; let _algoliaApiKeyOptions: ApiKeyOptions = { - validity: 0, - maxQueriesPerIPPerHour: 0, - indexes: [''], - queryParameters: { attributesToRetrieve: ['algolia'] }, - description: '', + validity: 0, + maxQueriesPerIPPerHour: 0, + indexes: [''], + queryParameters: { attributesToRetrieve: ['algolia'] }, + description: '', }; let _searchSynonymOptions: SearchSynonymOptions = { - query: '', - page: 0, - type: '', - hitsPerPage: 0, + query: '', + page: 0, + type: '', + hitsPerPage: 0, }; let _algoliaSecuredApiOptions: SecuredApiOptions = { - filters: '', - validUntil: 0, - restrictIndices: '', - userToken: '', + filters: '', + validUntil: 0, + restrictIndices: '', + userToken: '', }; let _algoliaIndexSettings: IndexSettings = { - attributesToIndex: [''], - attributesForFaceting: [''], - unretrievableAttributes: [''], - attributesToRetrieve: [''], - ranking: [''], - customRanking: [''], - replicas: [''], - maxValuesPerFacet: 100, - attributesToHighlight: [''], - attributesToSnippet: [''], - highlightPreTag: '', - highlightPostTag: '', - snippetEllipsisText: '', - restrictHighlightAndSnippetArrays: false, - hitsPerPage: 0, - minWordSizefor1Typo: 0, - minWordSizefor2Typos: 0, - typoTolerance: false, - allowTyposOnNumericTokens: false, - ignorePlurals: false, - disableTypoToleranceOnAttributes: '', - separatorsToIndex: '', - queryType: 'prefixAll', - removeWordsIfNoResults: '', - advancedSyntax: false, - optionalWords: [''], - removeStopWords: [''], - disablePrefixOnAttributes: [''], - disableExactOnAttributes: [''], - exactOnSingleWordQuery: '', - alternativesAsExact: ['ignorePlurals'], - attributeForDistinct: '', - distinct: false, - numericAttributesToIndex: [''], - allowCompressionOfIntegerArray: false, - altCorrections: [{}], - minProximity: 0, - placeholders: { '': [''] }, - camelCaseAttributes: [''], - sortFacetValuesBy: 'count', - queryLanguages: ['fr', 'es'], + attributesToIndex: [''], + attributesForFaceting: [''], + unretrievableAttributes: [''], + attributesToRetrieve: [''], + ranking: [''], + customRanking: [''], + replicas: [''], + maxValuesPerFacet: 100, + attributesToHighlight: [''], + attributesToSnippet: [''], + highlightPreTag: '', + highlightPostTag: '', + snippetEllipsisText: '', + restrictHighlightAndSnippetArrays: false, + hitsPerPage: 0, + minWordSizefor1Typo: 0, + minWordSizefor2Typos: 0, + typoTolerance: false, + allowTyposOnNumericTokens: false, + ignorePlurals: false, + disableTypoToleranceOnAttributes: '', + separatorsToIndex: '', + queryType: 'prefixAll', + removeWordsIfNoResults: '', + advancedSyntax: false, + optionalWords: [''], + removeStopWords: [''], + disablePrefixOnAttributes: [''], + disableExactOnAttributes: [''], + exactOnSingleWordQuery: '', + alternativesAsExact: ['ignorePlurals'], + attributeForDistinct: '', + distinct: false, + numericAttributesToIndex: [''], + allowCompressionOfIntegerArray: false, + altCorrections: [{}], + minProximity: 0, + placeholders: { '': [''] }, + camelCaseAttributes: [''], }; let _algoliaQueryParameters: QueryParameters = { - query: '', - filters: '', - attributesToRetrieve: [''], - restrictSearchableAttributes: [''], - facets: [''], - facetingAfterDistinct: true, - maxValuesPerFacet: 2, - attributesToHighlight: [''], - attributesToSnippet: [''], - highlightPreTag: '', - highlightPostTag: '', - snippetEllipsisText: '', - restrictHighlightAndSnippetArrays: false, - hitsPerPage: 0, - page: 0, - offset: 0, - length: 0, - minWordSizefor1Typo: 0, - minWordSizefor2Typos: 0, - typoTolerance: false, - allowTyposOnNumericTokens: false, - ignorePlurals: false, - disableTypoToleranceOnAttributes: [''], - aroundLatLng: '', - aroundLatLngViaIP: true, - aroundRadius: 0, - aroundPrecision: 0, - minimumAroundRadius: 0, - insideBoundingBox: [[0]], - queryType: 'prefixAll', - insidePolygon: [[0]], - removeWordsIfNoResults: 'firstWords', - advancedSyntax: false, - optionalWords: [''], - removeStopWords: [''], - disableExactOnAttributes: [''], - exactOnSingleWordQuery: 'attribute', - alternativesAsExact: ['ignorePlurals'], - distinct: 0, - getRankingInfo: false, - numericAttributesToIndex: [''], - numericAttributesForFiltering: [''], - numericFilters: [''], - tagFilters: [''], - facetFilters: ['', ['']], - analytics: false, - clickAnalytics: true, - analyticsTags: [''], - synonyms: true, - replaceSynonymsInHighlight: false, - minProximity: 0, - sortFacetValuesBy: 'alpha', + query: '', + filters: '', + attributesToRetrieve: [''], + restrictSearchableAttributes: [''], + facets: [''], + facetingAfterDistinct: true, + maxValuesPerFacet: 2, + attributesToHighlight: [''], + attributesToSnippet: [''], + highlightPreTag: '', + highlightPostTag: '', + snippetEllipsisText: '', + restrictHighlightAndSnippetArrays: false, + hitsPerPage: 0, + page: 0, + offset: 0, + length: 0, + minWordSizefor1Typo: 0, + minWordSizefor2Typos: 0, + typoTolerance: false, + allowTyposOnNumericTokens: false, + ignorePlurals: false, + disableTypoToleranceOnAttributes: [''], + aroundLatLng: '', + aroundLatLngViaIP: true, + aroundRadius: 0, + aroundPrecision: 0, + minimumAroundRadius: 0, + insideBoundingBox: [[0]], + queryType: 'prefixAll', + insidePolygon: [[0]], + removeWordsIfNoResults: 'firstWords', + advancedSyntax: false, + optionalWords: [''], + removeStopWords: [''], + disableExactOnAttributes: [''], + exactOnSingleWordQuery: 'attribute', + alternativesAsExact: ['ignorePlurals'], + distinct: 0, + getRankingInfo: false, + numericAttributesToIndex: [''], + numericAttributesForFiltering: [''], + numericFilters: [''], + tagFilters: [''], + facetFilters: [''], + analytics: false, + analyticsTags: [''], + synonyms: true, + replaceSynonymsInHighlight: false, + minProximity: 0, +}; + +let _apiKey: ApiKey = { + value: '0eb3e6308abccdf9b67d70ddacb418b4', + createdAt: 1513462891, + acl: ['search'], + validity: 0, }; let client: Client = algoliasearch('', ''); @@ -191,21 +196,21 @@ client.copyIndex('from', 'to', ['synonyms', 'rules'], () => {}); const browser = index.browseAll(); index.browseAll('query'); index.browseAll('', { - filters: 'dog', + filters: 'dog', }); let hits: Object[] = []; browser.on('result', function onResult(content) { - hits = hits.concat(content.hits); + hits = hits.concat(content.hits); }); browser.on('end', function onEnd() { - const _message = `We got ${hits.length} hits`; + const _message = `We got ${hits.length} hits`; }); browser.on('error', function onError(err) { - throw err; + throw err; }); browser.stop(); @@ -213,20 +218,18 @@ browser.stop(); index.setSettings({ hitsPerPage: 10 }, () => {}); index.setSettings({ hitsPerPage: 10 }, { forwardToReplicas: true }, () => {}); index.setSettings({ hitsPerPage: 10 }).then(() => {}); -index - .setSettings({ hitsPerPage: 10 }, { forwardToReplicas: true }) - .then(() => {}); +index.setSettings({ hitsPerPage: 10 }, { forwardToReplicas: true }).then(() => {}); index.browse('', { - advancedSyntax: false, - attributesToRetrieve: ['dogs'], + advancedSyntax: false, + attributesToRetrieve: ['dogs'], }); client.copyIndex('from', 'to', ['settings']).then(() => {}); client.copyIndex('from', 'to', ['synonyms', 'rules'], () => {}); const liteClient: algoliasearchLite.Client = algoliasearchLite('', ''); -liteClient.search([], (err: Error, res: algoliasearch.MultiResponse) => {}); -liteClient.search([]).then((res: algoliasearch.MultiResponse) => {}); +liteClient.search([], (err: Error, res: MultiResponse) => {}); +liteClient.search([]).then((res: MultiResponse) => {}); type Res = { zipzop: true }; -liteClient.search([]).then((res: algoliasearch.MultiResponse) => {}); +liteClient.search([]).then((res: MultiResponse) => {}); diff --git a/types/algoliasearch/index.d.ts b/types/algoliasearch/index.d.ts index d16bfd6170..116365a4f7 100644 --- a/types/algoliasearch/index.d.ts +++ b/types/algoliasearch/index.d.ts @@ -10,6 +10,7 @@ // Alexandre Deve // Dan Grayson // Peter Esenwa +// Samuel Bodin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -139,34 +140,40 @@ declare namespace algoliasearch { /** * Lists global API Keys */ - listApiKeys(cb: (err: Error, res: any) => void): void; + listApiKeys(cb: (err: Error, res: ApiKey[]) => void): void; /** * Lists global API Keys */ - listApiKeys(): Promise; + listApiKeys(): Promise; /** * Add global API Keys */ - addApiKey(scopes: string[], cb: (err: Error, res: Task) => void): void; + addApiKey( + scopes: string[], + cb: (err: Error, res: AddApiKeyTask) => void + ): void; /** * Add global API Key */ addApiKey( scopes: string[], options: ApiKeyOptions, - cb: (err: Error, res: Task) => void + cb: (err: Error, res: AddApiKeyTask) => void ): void; /** * Add global API Keys */ - addApiKey(scopes: string[], options?: ApiKeyOptions): Promise; + addApiKey( + scopes: string[], + options?: ApiKeyOptions + ): Promise; /** * Update global API key */ updateApiKey( key: string, scopes: string[], - cb: (err: Error, res: Task) => void + cb: (err: Error, res: UpdateApiKeyTask) => void ): void; /** * Update global API key @@ -175,7 +182,7 @@ declare namespace algoliasearch { key: string, scopes: string[], options: ApiKeyOptions, - cb: (err: Error, res: Task) => void + cb: (err: Error, res: UpdateApiKeyTask) => void ): void; /** * Update global API key @@ -184,23 +191,26 @@ declare namespace algoliasearch { key: string, scopes: string[], options?: ApiKeyOptions - ): Promise; + ): Promise; /** * Gets the rights of a global key */ - getApiKey(key: string, cb: (err: Error, res: any) => void): void; + getApiKey(key: string, cb: (err: Error, res: ApiKey) => void): void; /** * Gets the rights of a global key */ - getApiKey(key: string): Promise; + getApiKey(key: string): Promise; /** * Deletes a global key */ - deleteApiKey(key: string, cb: (err: Error, res: Task) => void): void; + deleteApiKey( + key: string, + cb: (err: Error, res: DeleteApiKeyTask) => void + ): void; /** * Deletes a global key */ - deleteApiKey(key: string): Promise; + deleteApiKey(key: string): Promise; /** * Get 1000 last events */ @@ -424,18 +434,21 @@ declare namespace algoliasearch { /** * List index user keys */ - listApiKeys(cb: (err: Error, res: any) => void): void; + listApiKeys(cb: (err: Error, res: ApiKey[]) => void): void; /** * Add key for this index */ - addApiKey(scopes: string[], cb: (err: Error, res: Task) => void): void; + addApiKey( + scopes: string[], + cb: (err: Error, res: AddApiKeyTask) => void + ): void; /** * Add key for this index */ addApiKey( scopes: string[], options: ApiKeyOptions, - cb: (err: Error, res: Task) => void + cb: (err: Error, res: AddApiKeyTask) => void ): void; /** * Update a key for this index @@ -443,7 +456,7 @@ declare namespace algoliasearch { updateApiKey( key: string, scopes: string[], - cb: (err: Error, res: Task) => void + cb: (err: Error, res: UpdateApiKeyTask) => void ): void; /** * Update a key for this index @@ -452,16 +465,19 @@ declare namespace algoliasearch { key: string, scopes: string[], options: ApiKeyOptions, - cb: (err: Error, res: Task) => void + cb: (err: Error, res: UpdateApiKeyTask) => void ): void; /** * Gets the rights of an index specific key */ - getApiKey(key: string, cb: (err: Error, res: any) => void): void; + getApiKey(key: string, cb: (err: Error, res: ApiKey) => void): void; /** * Deletes an index specific key */ - deleteApiKey(key: string, cb: (err: Error, res: Task) => void): void; + deleteApiKey( + key: string, + cb: (err: Error, res: DeleteApiKeyTask) => void + ): void; /** * Gets specific attributes from an object */ @@ -630,15 +646,18 @@ declare namespace algoliasearch { /** * List index user keys */ - listApiKeys(): Promise; + listApiKeys(): Promise; /** * Add key for this index */ - addApiKey(scopes: string[], options?: ApiKeyOptions): Promise; + addApiKey( + scopes: string[], + options?: ApiKeyOptions + ): Promise; /** * Update a key for this index */ - updateApiKey(key: string, scopes: string[]): Promise; + updateApiKey(key: string, scopes: string[]): Promise; /** * Update a key for this index */ @@ -646,15 +665,15 @@ declare namespace algoliasearch { key: string, scopes: string[], options: ApiKeyOptions - ): Promise; + ): Promise; /** * Gets the rights of an index specific key */ - getApiKey(key: string): Promise; + getApiKey(key: string): Promise; /** * Deletes an index specific key */ - deleteApiKey(key: string): Promise; + deleteApiKey(key: string): Promise; } /** * Interface describing available options when initializing a client @@ -1356,8 +1375,41 @@ declare namespace algoliasearch { } interface TaskStatus { - status: 'published' | 'notPublished', - pendingTask: boolean, + status: 'published' | 'notPublished'; + pendingTask: boolean; + } + + interface ApiKey { + value: string; + createdAt: number; + acl: ( + | 'search' + | 'browse' + | 'addObject' + | 'deleteObject' + | 'deleteIndex' + | 'settings' + | 'editSettings' + | 'analytics' + | 'listIndexes' + | 'logs' + | 'seeUnretrievableAttributes')[]; + validity: number; + description?: string; + } + + interface AddApiKeyTask { + key: string; + createdAt: string; + } + + interface UpdateApiKeyTask { + key: string; + updatedAt: string; + } + + interface DeleteApiKeyTask { + deletedAt: string; } interface IndexSettings { @@ -1689,7 +1741,7 @@ declare namespace algoliasearch { * If a search encounters an index that is being A/B tested, abTestVariantID * reports the variant ID of the index used (note, this is the ID not the name). * The variant ID is the position in the array of variants (starting at 1). - * + * * For example, abTestVariantID=1 is variant A (the main index), abTestVariantID=2 * is variant B (the replica you chose when creating the A/B test , or the queries * with the changed query parameters if the A/B test is based on query parameters).