From 8f648ad856cc01fa2cf4e82db5af45882d4aac21 Mon Sep 17 00:00:00 2001 From: Chloe Liban Date: Wed, 17 Feb 2021 11:17:30 +0100 Subject: [PATCH 01/13] feat(dictionaries): adds methods and tests --- packages/algoliasearch/src/builds/browser.ts | 61 ++++++++++++ packages/algoliasearch/src/builds/node.ts | 61 ++++++++++++ .../__tests__/integration/dictionary.test.ts | 93 +++++++++++++++++++ .../methods/client/clearDictionaryEntries.ts | 30 ++++++ .../methods/client/deleteDictionaryEntries.ts | 29 ++++++ .../methods/client/getDictionarySettings.ts | 17 ++++ .../src/methods/client/getDictionaryTask.ts | 20 ++++ .../client-search/src/methods/client/index.ts | 9 ++ .../client/replaceDictionaryEntries.ts | 34 +++++++ .../methods/client/saveDictionaryEntries.ts | 34 +++++++ .../methods/client/searchDictionaryEntries.ts | 26 ++++++ .../methods/client/setDictionarySettings.ts | 27 ++++++ .../src/methods/client/waitDictionaryTask.ts | 15 +++ .../src/types/DictionaryEntry.ts | 10 ++ .../src/types/DictionarySettings.ts | 10 ++ .../types/GetDictionarySettingsResponse.ts | 5 + .../src/types/SaveDictionaryEntriesOptions.ts | 5 + .../types/SaveDictionaryEntriesResponse.ts | 11 +++ .../types/SearchDictionaryEntriesResponse.ts | 70 ++++++++++++++ .../types/SetDictionarySettingsResponse.ts | 11 +++ packages/client-search/src/types/index.ts | 7 ++ 21 files changed, 585 insertions(+) create mode 100644 packages/client-search/src/__tests__/integration/dictionary.test.ts create mode 100644 packages/client-search/src/methods/client/clearDictionaryEntries.ts create mode 100644 packages/client-search/src/methods/client/deleteDictionaryEntries.ts create mode 100644 packages/client-search/src/methods/client/getDictionarySettings.ts create mode 100644 packages/client-search/src/methods/client/getDictionaryTask.ts create mode 100644 packages/client-search/src/methods/client/replaceDictionaryEntries.ts create mode 100644 packages/client-search/src/methods/client/saveDictionaryEntries.ts create mode 100644 packages/client-search/src/methods/client/searchDictionaryEntries.ts create mode 100644 packages/client-search/src/methods/client/setDictionarySettings.ts create mode 100644 packages/client-search/src/methods/client/waitDictionaryTask.ts create mode 100644 packages/client-search/src/types/DictionaryEntry.ts create mode 100644 packages/client-search/src/types/DictionarySettings.ts create mode 100644 packages/client-search/src/types/GetDictionarySettingsResponse.ts create mode 100644 packages/client-search/src/types/SaveDictionaryEntriesOptions.ts create mode 100644 packages/client-search/src/types/SaveDictionaryEntriesResponse.ts create mode 100644 packages/client-search/src/types/SearchDictionaryEntriesResponse.ts create mode 100644 packages/client-search/src/types/SetDictionarySettingsResponse.ts diff --git a/packages/algoliasearch/src/builds/browser.ts b/packages/algoliasearch/src/builds/browser.ts index f8976e59d..0dab73b08 100644 --- a/packages/algoliasearch/src/builds/browser.ts +++ b/packages/algoliasearch/src/builds/browser.ts @@ -45,6 +45,7 @@ import { browseSynonyms, ChunkedBatchResponse, ChunkOptions, + clearDictionaryEntries, clearObjects, clearRules, ClearRulesOptions, @@ -60,6 +61,7 @@ import { DeleteApiKeyResponse, deleteBy, DeleteByFiltersOptions, + deleteDictionaryEntries, deleteIndex, deleteObject, deleteObjects, @@ -67,6 +69,8 @@ import { deleteRule, deleteSynonym, DeleteSynonymOptions, + DictionaryEntry, + DictionarySettings, exists, findAnswers, FindAnswersOptions, @@ -76,6 +80,9 @@ import { FindObjectResponse, getApiKey, GetApiKeyResponse, + getDictionarySettings, + GetDictionarySettingsResponse, + getDictionaryTask, getLogs, GetLogsResponse, getObject, @@ -127,9 +134,13 @@ import { ReplaceAllObjectsOptions, replaceAllRules, replaceAllSynonyms, + replaceDictionaryEntries, restoreApiKey, RestoreApiKeyResponse, Rule, + saveDictionaryEntries, + SaveDictionaryEntriesOptions, + SaveDictionaryEntriesResponse, saveObject, SaveObjectResponse, saveObjects, @@ -146,6 +157,8 @@ import { SaveSynonymsResponse, search, SearchClient as BaseSearchClient, + searchDictionaryEntries, + SearchDictionaryEntriesResponse, searchForFacetValues, SearchForFacetValuesQueryParams, SearchForFacetValuesResponse, @@ -160,14 +173,18 @@ import { searchUserIDs, SearchUserIDsOptions, SearchUserIDsResponse, + setDictionarySettings, + SetDictionarySettingsResponse, setSettings, SetSettingsResponse, Settings, Synonym, + TaskStatusResponse, updateApiKey, UpdateApiKeyOptions, UpdateApiKeyResponse, UserIDResponse, + waitDictionaryTask, waitTask, } from '@algolia/client-search'; import { LogLevelEnum } from '@algolia/logger-common'; @@ -235,6 +252,15 @@ export default function algoliasearch( getTopUserIDs, removeUserID, hasPendingMappings, + clearDictionaryEntries, + deleteDictionaryEntries, + getDictionarySettings, + getDictionaryTask, + replaceDictionaryEntries, + saveDictionaryEntries, + searchDictionaryEntries, + setDictionarySettings, + waitDictionaryTask, initIndex: base => (indexName: string): SearchIndex => { return initIndex(base)(indexName, { methods: { @@ -601,6 +627,41 @@ export type SearchClient = BaseSearchClient & { readonly hasPendingMappings: ( requestOptions?: HasPendingMappingsOptions & RequestOptions ) => Readonly>; + readonly clearDictionaryEntries: ( + dictionary: string, + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly deleteDictionaryEntries: ( + dictionary: string, + objectIDs: readonly string[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly replaceDictionaryEntries: ( + dictionary: string, + entries: readonly DictionaryEntry[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly saveDictionaryEntries: ( + dictionary: string, + entries: readonly DictionaryEntry[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly searchDictionaryEntries: ( + dictionary: string, + query: string, + requestOptions?: RequestOptions + ) => Readonly>; + readonly getDictionarySettings: ( + requestOptions?: RequestOptions + ) => Readonly>; + readonly setDictionarySettings: ( + settings: readonly DictionarySettings[], + requestOptions?: RequestOptions + ) => Readonly>; + readonly getDictionaryTask: ( + taskID: number, + requestOptions?: RequestOptions + ) => Readonly>; readonly initAnalytics: (options?: InitAnalyticsOptions) => AnalyticsClient; readonly initRecommendation: (options?: InitRecommendationOptions) => RecommendationClient; }; diff --git a/packages/algoliasearch/src/builds/node.ts b/packages/algoliasearch/src/builds/node.ts index b1030fd6d..711b82000 100644 --- a/packages/algoliasearch/src/builds/node.ts +++ b/packages/algoliasearch/src/builds/node.ts @@ -44,6 +44,7 @@ import { browseSynonyms, ChunkedBatchResponse, ChunkOptions, + clearDictionaryEntries, clearObjects, clearRules, ClearRulesOptions, @@ -59,6 +60,7 @@ import { DeleteApiKeyResponse, deleteBy, DeleteByFiltersOptions, + deleteDictionaryEntries, deleteIndex, deleteObject, deleteObjects, @@ -66,6 +68,8 @@ import { deleteRule, deleteSynonym, DeleteSynonymOptions, + DictionaryEntry, + DictionarySettings, exists, findAnswers, FindAnswersOptions, @@ -76,6 +80,9 @@ import { generateSecuredApiKey, getApiKey, GetApiKeyResponse, + getDictionarySettings, + GetDictionarySettingsResponse, + getDictionaryTask, getLogs, GetLogsResponse, getObject, @@ -128,9 +135,13 @@ import { ReplaceAllObjectsOptions, replaceAllRules, replaceAllSynonyms, + replaceDictionaryEntries, restoreApiKey, RestoreApiKeyResponse, Rule, + saveDictionaryEntries, + SaveDictionaryEntriesOptions, + SaveDictionaryEntriesResponse, saveObject, SaveObjectResponse, saveObjects, @@ -147,6 +158,8 @@ import { SaveSynonymsResponse, search, SearchClient as BaseSearchClient, + searchDictionaryEntries, + SearchDictionaryEntriesResponse, searchForFacetValues, SearchForFacetValuesQueryParams, SearchForFacetValuesResponse, @@ -162,14 +175,18 @@ import { SearchUserIDsOptions, SearchUserIDsResponse, SecuredApiKeyRestrictions, + setDictionarySettings, + SetDictionarySettingsResponse, setSettings, SetSettingsResponse, Settings, Synonym, + TaskStatusResponse, updateApiKey, UpdateApiKeyOptions, UpdateApiKeyResponse, UserIDResponse, + waitDictionaryTask, waitTask, } from '@algolia/client-search'; import { createNullLogger } from '@algolia/logger-common'; @@ -238,6 +255,15 @@ export default function algoliasearch( generateSecuredApiKey, getSecuredApiKeyRemainingValidity, destroy, + clearDictionaryEntries, + deleteDictionaryEntries, + getDictionarySettings, + getDictionaryTask, + replaceDictionaryEntries, + saveDictionaryEntries, + searchDictionaryEntries, + setDictionarySettings, + waitDictionaryTask, initIndex: base => (indexName: string): SearchIndex => { return initIndex(base)(indexName, { methods: { @@ -609,6 +635,41 @@ export type SearchClient = BaseSearchClient & { restrictions: SecuredApiKeyRestrictions ) => string; readonly getSecuredApiKeyRemainingValidity: (securedApiKey: string) => number; + readonly clearDictionaryEntries: ( + dictionary: string, + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly deleteDictionaryEntries: ( + dictionary: string, + objectIDs: readonly string[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly replaceDictionaryEntries: ( + dictionary: string, + entries: readonly DictionaryEntry[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly saveDictionaryEntries: ( + dictionary: string, + entries: readonly DictionaryEntry[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ) => Readonly>; + readonly searchDictionaryEntries: ( + dictionary: string, + query: string, + requestOptions?: RequestOptions + ) => Readonly>; + readonly getDictionarySettings: ( + requestOptions?: RequestOptions + ) => Readonly>; + readonly setDictionarySettings: ( + settings: readonly DictionarySettings[], + requestOptions?: RequestOptions + ) => Readonly>; + readonly getDictionaryTask: ( + taskID: number, + requestOptions?: RequestOptions + ) => Readonly>; readonly initAnalytics: (options?: InitAnalyticsOptions) => AnalyticsClient; readonly initRecommendation: (options?: InitRecommendationOptions) => RecommendationClient; } & Destroyable; diff --git a/packages/client-search/src/__tests__/integration/dictionary.test.ts b/packages/client-search/src/__tests__/integration/dictionary.test.ts new file mode 100644 index 000000000..b28eefa9c --- /dev/null +++ b/packages/client-search/src/__tests__/integration/dictionary.test.ts @@ -0,0 +1,93 @@ +import { TestSuite } from '../../../../client-common/src/__tests__/TestSuite'; + +const testSuite = new TestSuite('dictionary'); + +test(testSuite.testName, async () => { + const client = testSuite.makeSearchClient('ALGOLIA_APPLICATION_ID_2', 'ALGOLIA_ADMIN_KEY_2') + + // Stopwords + const stopwordEntryId = Math.floor(Math.random() * 10000).toString(); + expect(await client.searchDictionaryEntries('stopwords', stopwordEntryId).nbHits).toEqual(0); + + const stopwordEntry = { + objectID: stopwordEntryId, + language: 'en', + word: 'down', + }; + + await client.saveDictionaryEntries('stopwords', [stopwordEntry]); + + const stopwords = await client.searchDictionaryEntries('stopwords', stopwordEntryId); + expect(stopwords.nbHits).toEqual(1); + expect(stopwords.hits[0].objectID).toEqual(stopwordEntry.objectID); + expect(stopwords.hits[0].word).toEqual(stopwordEntry.word); + + await client.deleteDictionaryEntries('stopwords', [stopwordEntryId]); + expect(await client.searchDictionaryEntries('stopwords', stopwordEntryId).nbHits).toEqual(0); + + const oldDictionaryState = await client.searchDictionaryEntries('stopwords', ''); + const oldDictionaryEntries = oldDictionaryState.hits.map(hit => { + delete hit.type; + + return hit; + }); + + await client.saveDictionaryEntries('stopwords', [stopwordEntry]); + expect(await client.searchDictionaryEntries('stopwords', stopwordEntryId).nbHits).toEqual(1); + + await client.replaceDictionaryEntries('stopwords', oldDictionaryEntries); + expect(await client.searchDictionaryEntries('stopwords', stopwordEntryId).nbHits).toEqual(0); + + const stopwordsSettings = { + disableStandardEntries: { + stopwords: { + en: true, + }, + }, + }; + + await client.setDictionarySettings(stopwordsSettings); + expect(await client.getDictionarySettings()).toEqual(stopwordsSettings); + + // Plurals + const pluralEntryId = Math.floor(Math.random() * 10000).toString(); + expect(await client.searchDictionaryEntries('plurals', pluralEntryId).nbHits).toEqual(0); + + const pluralEntry = { + objectID: pluralEntryId, + language: 'fr', + words: ['cheval', 'chevaux'], + }; + + await client.saveDictionaryEntries('plurals', [pluralEntry]); + + const plurals = await client.searchDictionaryEntries('plurals', pluralEntryId); + expect(plurals.nbHits).toEqual(1); + expect(plurals.hits[0].objectID).toEqual(pluralEntry.objectID); + expect(plurals.hits[0].words).toEqual(pluralEntry.words); + + await client.deleteDictionaryEntries('plurals', [pluralEntryId]); + expect(await client.searchDictionaryEntries('plurals', pluralEntryId).nbHits).toEqual(0); + + // Compounds + const compoundEntryId = Math.floor(Math.random() * 10000).toString(); + expect(await client.searchDictionaryEntries('plurals', compoundEntryId).nbHits).toEqual(0); + + const compoundEntry = { + objectID: compoundEntryId, + language: 'fr', + word: 'kopfschmerztablette', + decomposition: ['kopf', 'schmerz', 'tablette'], + }; + + await client.saveDictionaryEntries('plurals', [compoundEntry]); + + const compounds = await client.searchDictionaryEntries('plurals', compoundEntryId); + expect(compounds.nbHits).toEqual(1); + expect(compounds.hits[0].objectID).toEqual(compoundEntry.objectID); + expect(compounds.hits[0].word).toEqual(compoundEntry.word); + expect(compounds.hits[0].decomposition).toEqual(compoundEntry.decomposition); + + await client.deleteDictionaryEntries('plurals', [compoundEntryId]); + expect(await client.searchDictionaryEntries('plurals', compoundEntryId).nbHits).toEqual(0); +}); diff --git a/packages/client-search/src/methods/client/clearDictionaryEntries.ts b/packages/client-search/src/methods/client/clearDictionaryEntries.ts new file mode 100644 index 000000000..999c71d6c --- /dev/null +++ b/packages/client-search/src/methods/client/clearDictionaryEntries.ts @@ -0,0 +1,30 @@ +import { createWaitablePromise, encode, WaitablePromise } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient } from '../..'; +import { waitDictionaryTask } from '.'; + +// TODO: fill in SaveDictionaryEntriesOptions type +export const clearDictionaryEntries = (base: SearchClient) => { + return ( + dictionary: string, + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ): Readonly> => { + return createWaitablePromise( + base.transporter.write( + { + method: MethodEnum.Post, + path: encode('/1/dictionaries/%s/batch', dictionary), + data: { + clearExistingDictionaryEntries: true, + requests: { action: 'addEntry', body: [] }, + }, + }, + requestOptions + ), + (response, waitRequestOptions) => + waitDictionaryTask(base)(response.taskID, waitRequestOptions) + ); + }; +}; diff --git a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts new file mode 100644 index 000000000..3684625bf --- /dev/null +++ b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts @@ -0,0 +1,29 @@ +import { createWaitablePromise, encode, WaitablePromise } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient } from '../..'; +import { waitDictionaryTask } from '.'; + +// TODO: fill in SaveDictionaryEntriesOptions type +// TODO objectIDs have to be a composite objects with actionType=deleteEntry and body=objectID like MultipleBatch +export const deleteDictionaryEntries = (base: SearchClient) => { + return ( + dictionary: string, + objectIDs: readonly string[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ): Readonly> => { + return createWaitablePromise( + base.transporter.write( + { + method: MethodEnum.Post, + path: encode('/1/dictionaries/%s/batch', dictionary), + data: { clearExistingDictionaryEntries: false, requests: objectIDs }, + }, + requestOptions + ), + (response, waitRequestOptions) => + waitDictionaryTask(base)(response.taskID, waitRequestOptions) + ); + }; +}; diff --git a/packages/client-search/src/methods/client/getDictionarySettings.ts b/packages/client-search/src/methods/client/getDictionarySettings.ts new file mode 100644 index 000000000..11ea0c970 --- /dev/null +++ b/packages/client-search/src/methods/client/getDictionarySettings.ts @@ -0,0 +1,17 @@ +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { GetDictionarySettingsResponse, SearchClient } from '../..'; + +// TODO: fill in GetDictionarySettingsResponse type +export const getDictionarySettings = (base: SearchClient) => { + return (requestOptions?: RequestOptions): Readonly> => { + return base.transporter.read( + { + method: MethodEnum.Get, + path: '/1/dictionaries/*/settings', + }, + requestOptions + ); + }; +}; diff --git a/packages/client-search/src/methods/client/getDictionaryTask.ts b/packages/client-search/src/methods/client/getDictionaryTask.ts new file mode 100644 index 000000000..18ba6d081 --- /dev/null +++ b/packages/client-search/src/methods/client/getDictionaryTask.ts @@ -0,0 +1,20 @@ +import { encode } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { SearchClient, TaskStatusResponse } from '../..'; + +export const getDictionaryTask = (base: SearchClient) => { + return ( + taskID: number, + requestOptions?: RequestOptions + ): Readonly> => { + return base.transporter.read( + { + method: MethodEnum.Get, + path: encode('1/task/%s', taskID.toString()), + }, + requestOptions + ); + }; +}; diff --git a/packages/client-search/src/methods/client/index.ts b/packages/client-search/src/methods/client/index.ts index c0ed301c0..787a568c6 100644 --- a/packages/client-search/src/methods/client/index.ts +++ b/packages/client-search/src/methods/client/index.ts @@ -5,16 +5,20 @@ export * from './addApiKey'; export * from './assignUserID'; export * from './assignUserIDs'; +export * from './clearDictionaryEntries'; export * from './copyIndex'; export * from './copyRules'; export * from './copySettings'; export * from './copySynonyms'; export * from './deleteApiKey'; +export * from './deleteDictionaryEntries'; export * from './generateSecuredApiKey'; export * from './getApiKey'; +export * from './getDictionarySettings'; export * from './getLogs'; export * from './getSecuredApiKeyRemainingValidity'; export * from './getTopUserIDs'; +export * from './getDictionaryTask'; export * from './getUserID'; export * from './hasPendingMappings'; export * from './initIndex'; @@ -28,6 +32,11 @@ export * from './multipleGetObjects'; export * from './multipleQueries'; export * from './multipleSearchForFacetValues'; export * from './removeUserID'; +export * from './replaceDictionaryEntries'; export * from './restoreApiKey'; +export * from './saveDictionaryEntries'; +export * from './searchDictionaryEntries'; export * from './searchUserIDs'; +export * from './setDictionarySettings'; export * from './updateApiKey'; +export * from './waitDictionaryTask'; diff --git a/packages/client-search/src/methods/client/replaceDictionaryEntries.ts b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts new file mode 100644 index 000000000..39df752ca --- /dev/null +++ b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts @@ -0,0 +1,34 @@ +import { createWaitablePromise, encode, WaitablePromise } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { + DictionaryEntry, + SaveDictionaryEntriesOptions, + SaveDictionaryEntriesResponse, + SearchClient, +} from '../..'; +import { waitDictionaryTask } from '.'; + +// TODO: fill in DictionaryEntry & SaveDictionaryEntriesOptions types +// TODO entries have to be a composite objects with actionType=addEntry and body=DictEntry like MultipleBatch +export const replaceDictionaryEntries = (base: SearchClient) => { + return ( + dictionary: string, + entries: readonly DictionaryEntry[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ): Readonly> => { + return createWaitablePromise( + base.transporter.write( + { + method: MethodEnum.Post, + path: encode('/1/dictionaries/%s/batch', dictionary), + data: { clearExistingDictionaryEntries: true, requests: entries }, + }, + requestOptions + ), + (response, waitRequestOptions) => + waitDictionaryTask(base)(response.taskID, waitRequestOptions) + ); + }; +}; diff --git a/packages/client-search/src/methods/client/saveDictionaryEntries.ts b/packages/client-search/src/methods/client/saveDictionaryEntries.ts new file mode 100644 index 000000000..94dd4d151 --- /dev/null +++ b/packages/client-search/src/methods/client/saveDictionaryEntries.ts @@ -0,0 +1,34 @@ +import { createWaitablePromise, encode, WaitablePromise } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { + DictionaryEntry, + SaveDictionaryEntriesOptions, + SaveDictionaryEntriesResponse, + SearchClient, +} from '../..'; +import { waitDictionaryTask } from '.'; + +// TODO: fill in DictionaryEntry & SaveDictionaryEntriesOptions types +// TODO entries have to be a composite objects with actionType=addEntry and body=DictEntry like MultipleBatch +export const saveDictionaryEntries = (base: SearchClient) => { + return ( + dictionary: string, + entries: readonly DictionaryEntry[], + requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + ): Readonly> => { + return createWaitablePromise( + base.transporter.write( + { + method: MethodEnum.Post, + path: encode('/1/dictionaries/%s/batch', dictionary), + data: { clearExistingDictionaryEntries: false, requests: entries }, + }, + requestOptions + ), + (response, waitRequestOptions) => + waitDictionaryTask(base)(response.taskID, waitRequestOptions) + ); + }; +}; diff --git a/packages/client-search/src/methods/client/searchDictionaryEntries.ts b/packages/client-search/src/methods/client/searchDictionaryEntries.ts new file mode 100644 index 000000000..e91dd04b4 --- /dev/null +++ b/packages/client-search/src/methods/client/searchDictionaryEntries.ts @@ -0,0 +1,26 @@ +import { encode } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { SearchClient, SearchDictionaryEntriesResponse } from '../..'; + +// TODO: fill in SearchDictionaryEntriesResponse type +export const searchDictionaryEntries = (base: SearchClient) => { + return ( + dictionary: string, + query: string, + requestOptions?: RequestOptions + ): Readonly>> => { + return base.transporter.read( + { + method: MethodEnum.Post, + path: encode('1/indexes/%s/query', dictionary), + data: { + query, + }, + cacheable: true, + }, + requestOptions + ); + }; +}; diff --git a/packages/client-search/src/methods/client/setDictionarySettings.ts b/packages/client-search/src/methods/client/setDictionarySettings.ts new file mode 100644 index 000000000..023294320 --- /dev/null +++ b/packages/client-search/src/methods/client/setDictionarySettings.ts @@ -0,0 +1,27 @@ +import { createWaitablePromise, WaitablePromise } from '@algolia/client-common'; +import { MethodEnum } from '@algolia/requester-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { DictionarySettings, SearchClient, SetDictionarySettingsResponse } from '../..'; +import { waitDictionaryTask } from '.'; + +// TODO: fill in DictionarySettings & SetDictionarySettingsResponse types +export const setDictionarySettings = (base: SearchClient) => { + return ( + settings: readonly DictionarySettings[], + requestOptions?: RequestOptions + ): Readonly> => { + return createWaitablePromise( + base.transporter.write( + { + method: MethodEnum.Put, + path: '/1/dictionaries/*/settings', + data: settings, + }, + requestOptions + ), + (response, waitRequestOptions) => + waitDictionaryTask(base)(response.taskID, waitRequestOptions) + ); + }; +}; diff --git a/packages/client-search/src/methods/client/waitDictionaryTask.ts b/packages/client-search/src/methods/client/waitDictionaryTask.ts new file mode 100644 index 000000000..0e1c38b1a --- /dev/null +++ b/packages/client-search/src/methods/client/waitDictionaryTask.ts @@ -0,0 +1,15 @@ +import { createRetryablePromise } from '@algolia/client-common'; +import { RequestOptions } from '@algolia/transporter'; + +import { SearchClient } from '../..'; +import { getDictionaryTask } from '.'; + +export const waitDictionaryTask = (base: SearchClient) => { + return (taskID: number, requestOptions?: RequestOptions): Readonly> => { + return createRetryablePromise(retry => { + return getDictionaryTask(base)(taskID, requestOptions).then(response => { + return response.status !== 'published' ? retry() : undefined; + }); + }); + }; +}; diff --git a/packages/client-search/src/types/DictionaryEntry.ts b/packages/client-search/src/types/DictionaryEntry.ts new file mode 100644 index 000000000..c0c6e6d81 --- /dev/null +++ b/packages/client-search/src/types/DictionaryEntry.ts @@ -0,0 +1,10 @@ +export type DictionaryEntry = { + /** + * Unique identifier for the rule (format: [A-Za-z0-9_-]+). + */ + readonly objectID: string; + + /** + * TODO + */ +}; diff --git a/packages/client-search/src/types/DictionarySettings.ts b/packages/client-search/src/types/DictionarySettings.ts new file mode 100644 index 000000000..a6cb0090f --- /dev/null +++ b/packages/client-search/src/types/DictionarySettings.ts @@ -0,0 +1,10 @@ +export type DictionarySettings = { + /** + * Unique identifier for the rule (format: [A-Za-z0-9_-]+). + */ + readonly objectID: string; + + /** + * TODO + */ +}; diff --git a/packages/client-search/src/types/GetDictionarySettingsResponse.ts b/packages/client-search/src/types/GetDictionarySettingsResponse.ts new file mode 100644 index 000000000..4a82816ea --- /dev/null +++ b/packages/client-search/src/types/GetDictionarySettingsResponse.ts @@ -0,0 +1,5 @@ +export type GetDictionarySettingsResponse = { + /** + * TODO + */ +}; diff --git a/packages/client-search/src/types/SaveDictionaryEntriesOptions.ts b/packages/client-search/src/types/SaveDictionaryEntriesOptions.ts new file mode 100644 index 000000000..4b13c6de1 --- /dev/null +++ b/packages/client-search/src/types/SaveDictionaryEntriesOptions.ts @@ -0,0 +1,5 @@ +export type SaveDictionaryEntriesOptions = { + /** + * TODO + */ +}; diff --git a/packages/client-search/src/types/SaveDictionaryEntriesResponse.ts b/packages/client-search/src/types/SaveDictionaryEntriesResponse.ts new file mode 100644 index 000000000..e7ffba065 --- /dev/null +++ b/packages/client-search/src/types/SaveDictionaryEntriesResponse.ts @@ -0,0 +1,11 @@ +export type SaveDictionaryEntriesResponse = { + /** + * When the given rules got saved. + */ + updatedAt: number; + + /** + * The operation task id. May be used to perform a wait task. + */ + taskID: number; +}; diff --git a/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts b/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts new file mode 100644 index 000000000..fe67e73e5 --- /dev/null +++ b/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts @@ -0,0 +1,70 @@ +import { Hit } from '.'; + +export type SearchDictionaryEntriesResponse = { + /** + * TODO + */ + + /** + * The hits returned by the search. + * + * Hits are ordered according to the ranking or sorting of the index being queried. + */ + hits: Array>; + + /** + * Index of the current page (zero-based). + */ + page: number; + + /** + * Number of hits returned (used only with offset) + */ + length?: number; + + /** + * The offset of the first hit to returned. + */ + offset?: number; + + /** + * Number of hits matched by the query. + */ + nbHits: number; + + /** + * Subset of hits selected when relevancyStrictness is applied. + */ + nbSortedHits?: number; + + /** + * Number of pages returned. + * + * Calculation is based on the total number of hits (nbHits) divided by the + * number of hits per page (hitsPerPage), rounded up to the nearest integer. + */ + nbPages: number; + + /** + * Maximum number of hits returned per page. + */ + hitsPerPage: number; + + /** + * Time the server took to process the request, in milliseconds. This does not include network time. + */ + processingTimeMS: number; + + /** + * Whether the nbHits is exhaustive (true) or approximate (false). + * + * An approximation is done when the query takes more than 50ms to be + * processed (this can happen when using complex filters on millions on records). + */ + exhaustiveNbHits: boolean; + + /** + * Whether the facet count is exhaustive (true) or approximate (false). + */ + exhaustiveFacetsCount?: boolean; +}; diff --git a/packages/client-search/src/types/SetDictionarySettingsResponse.ts b/packages/client-search/src/types/SetDictionarySettingsResponse.ts new file mode 100644 index 000000000..eb8bb843b --- /dev/null +++ b/packages/client-search/src/types/SetDictionarySettingsResponse.ts @@ -0,0 +1,11 @@ +export type SetDictionarySettingsResponse = { + /** + * When the given rules got saved. + */ + updatedAt: number; + + /** + * The operation task id. May be used to perform a wait task. + */ + taskID: number; +}; diff --git a/packages/client-search/src/types/index.ts b/packages/client-search/src/types/index.ts index 523dfd08e..44d2eb8d2 100644 --- a/packages/client-search/src/types/index.ts +++ b/packages/client-search/src/types/index.ts @@ -24,6 +24,8 @@ export * from './DeleteApiKeyResponse'; export * from './DeleteByFiltersOptions'; export * from './DeleteResponse'; export * from './DeleteSynonymOptions'; +export * from './DictionaryEntry'; +export * from './DictionarySettings'; export * from './FacetHit'; export * from './FindAnswersOptions'; export * from './FindAnswersResponse'; @@ -35,6 +37,7 @@ export * from './GetLogsResponse'; export * from './GetObjectOptions'; export * from './GetObjectsOptions'; export * from './GetObjectsResponse'; +export * from './GetDictionarySettingsResponse'; export * from './GetTopUserIDsResponse'; export * from './HasPendingMappingsOptions'; export * from './HasPendingMappingsResponse'; @@ -61,6 +64,8 @@ export * from './RemoveUserIDResponse'; export * from './ReplaceAllObjectsOptions'; export * from './RestoreApiKeyResponse'; export * from './Rule'; +export * from './SaveDictionaryEntriesOptions'; +export * from './SaveDictionaryEntriesResponse'; export * from './SaveObjectResponse'; export * from './SaveObjectsOptions'; export * from './SaveRuleResponse'; @@ -71,6 +76,7 @@ export * from './SaveSynonymsOptions'; export * from './SaveSynonymsResponse'; export * from './SearchClient'; export * from './SearchClientOptions'; +export * from './SearchDictionaryEntriesResponse'; export * from './SearchForFacetValuesQueryParams'; export * from './SearchForFacetValuesResponse'; export * from './SearchIndex'; @@ -82,6 +88,7 @@ export * from './SearchSynonymsResponse'; export * from './SearchUserIDsOptions'; export * from './SearchUserIDsResponse'; export * from './SecuredApiKeyRestrictions'; +export * from './SetDictionarySettingsResponse'; export * from './SetSettingsOptions'; export * from './SetSettingsResponse'; export * from './Settings'; From 21a284886e84ed8b0c811ce81b3184da50a644fc Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Fri, 12 Mar 2021 10:28:38 +0100 Subject: [PATCH 02/13] rename dictionary task to app task --- packages/algoliasearch/src/builds/browser.ts | 10 +++++----- packages/algoliasearch/src/builds/node.ts | 10 +++++----- .../src/__tests__/integration/dictionary.test.ts | 8 ++++---- .../src/methods/client/clearDictionaryEntries.ts | 5 ++--- .../src/methods/client/deleteDictionaryEntries.ts | 5 ++--- .../client/{getDictionaryTask.ts => getAppTask.ts} | 2 +- packages/client-search/src/methods/client/index.ts | 4 ++-- .../src/methods/client/replaceDictionaryEntries.ts | 5 ++--- .../src/methods/client/saveDictionaryEntries.ts | 5 ++--- .../src/methods/client/setDictionarySettings.ts | 5 ++--- .../client/{waitDictionaryTask.ts => waitAppTask.ts} | 6 +++--- .../src/types/SearchDictionaryEntriesResponse.ts | 4 ---- 12 files changed, 30 insertions(+), 39 deletions(-) rename packages/client-search/src/methods/client/{getDictionaryTask.ts => getAppTask.ts} (89%) rename packages/client-search/src/methods/client/{waitDictionaryTask.ts => waitAppTask.ts} (68%) diff --git a/packages/algoliasearch/src/builds/browser.ts b/packages/algoliasearch/src/builds/browser.ts index 0dab73b08..d150a98c5 100644 --- a/packages/algoliasearch/src/builds/browser.ts +++ b/packages/algoliasearch/src/builds/browser.ts @@ -80,9 +80,9 @@ import { FindObjectResponse, getApiKey, GetApiKeyResponse, + getAppTask, getDictionarySettings, GetDictionarySettingsResponse, - getDictionaryTask, getLogs, GetLogsResponse, getObject, @@ -184,7 +184,7 @@ import { UpdateApiKeyOptions, UpdateApiKeyResponse, UserIDResponse, - waitDictionaryTask, + waitAppTask, waitTask, } from '@algolia/client-search'; import { LogLevelEnum } from '@algolia/logger-common'; @@ -255,12 +255,12 @@ export default function algoliasearch( clearDictionaryEntries, deleteDictionaryEntries, getDictionarySettings, - getDictionaryTask, + getAppTask, replaceDictionaryEntries, saveDictionaryEntries, searchDictionaryEntries, setDictionarySettings, - waitDictionaryTask, + waitAppTask, initIndex: base => (indexName: string): SearchIndex => { return initIndex(base)(indexName, { methods: { @@ -658,7 +658,7 @@ export type SearchClient = BaseSearchClient & { settings: readonly DictionarySettings[], requestOptions?: RequestOptions ) => Readonly>; - readonly getDictionaryTask: ( + readonly getAppTask: ( taskID: number, requestOptions?: RequestOptions ) => Readonly>; diff --git a/packages/algoliasearch/src/builds/node.ts b/packages/algoliasearch/src/builds/node.ts index 711b82000..78a06703f 100644 --- a/packages/algoliasearch/src/builds/node.ts +++ b/packages/algoliasearch/src/builds/node.ts @@ -80,9 +80,9 @@ import { generateSecuredApiKey, getApiKey, GetApiKeyResponse, + getAppTask, getDictionarySettings, GetDictionarySettingsResponse, - getDictionaryTask, getLogs, GetLogsResponse, getObject, @@ -186,7 +186,7 @@ import { UpdateApiKeyOptions, UpdateApiKeyResponse, UserIDResponse, - waitDictionaryTask, + waitAppTask, waitTask, } from '@algolia/client-search'; import { createNullLogger } from '@algolia/logger-common'; @@ -258,12 +258,12 @@ export default function algoliasearch( clearDictionaryEntries, deleteDictionaryEntries, getDictionarySettings, - getDictionaryTask, + getAppTask, replaceDictionaryEntries, saveDictionaryEntries, searchDictionaryEntries, setDictionarySettings, - waitDictionaryTask, + waitAppTask, initIndex: base => (indexName: string): SearchIndex => { return initIndex(base)(indexName, { methods: { @@ -666,7 +666,7 @@ export type SearchClient = BaseSearchClient & { settings: readonly DictionarySettings[], requestOptions?: RequestOptions ) => Readonly>; - readonly getDictionaryTask: ( + readonly getAppTask: ( taskID: number, requestOptions?: RequestOptions ) => Readonly>; diff --git a/packages/client-search/src/__tests__/integration/dictionary.test.ts b/packages/client-search/src/__tests__/integration/dictionary.test.ts index b28eefa9c..a2437989c 100644 --- a/packages/client-search/src/__tests__/integration/dictionary.test.ts +++ b/packages/client-search/src/__tests__/integration/dictionary.test.ts @@ -7,7 +7,7 @@ test(testSuite.testName, async () => { // Stopwords const stopwordEntryId = Math.floor(Math.random() * 10000).toString(); - expect(await client.searchDictionaryEntries('stopwords', stopwordEntryId).nbHits).toEqual(0); + expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); const stopwordEntry = { objectID: stopwordEntryId, @@ -23,7 +23,7 @@ test(testSuite.testName, async () => { expect(stopwords.hits[0].word).toEqual(stopwordEntry.word); await client.deleteDictionaryEntries('stopwords', [stopwordEntryId]); - expect(await client.searchDictionaryEntries('stopwords', stopwordEntryId).nbHits).toEqual(0); + expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); const oldDictionaryState = await client.searchDictionaryEntries('stopwords', ''); const oldDictionaryEntries = oldDictionaryState.hits.map(hit => { @@ -33,10 +33,10 @@ test(testSuite.testName, async () => { }); await client.saveDictionaryEntries('stopwords', [stopwordEntry]); - expect(await client.searchDictionaryEntries('stopwords', stopwordEntryId).nbHits).toEqual(1); + expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(1); await client.replaceDictionaryEntries('stopwords', oldDictionaryEntries); - expect(await client.searchDictionaryEntries('stopwords', stopwordEntryId).nbHits).toEqual(0); + expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); const stopwordsSettings = { disableStandardEntries: { diff --git a/packages/client-search/src/methods/client/clearDictionaryEntries.ts b/packages/client-search/src/methods/client/clearDictionaryEntries.ts index 999c71d6c..f5b846448 100644 --- a/packages/client-search/src/methods/client/clearDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/clearDictionaryEntries.ts @@ -3,7 +3,7 @@ import { MethodEnum } from '@algolia/requester-common'; import { RequestOptions } from '@algolia/transporter'; import { SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient } from '../..'; -import { waitDictionaryTask } from '.'; +import { waitAppTask } from '.'; // TODO: fill in SaveDictionaryEntriesOptions type export const clearDictionaryEntries = (base: SearchClient) => { @@ -23,8 +23,7 @@ export const clearDictionaryEntries = (base: SearchClient) => { }, requestOptions ), - (response, waitRequestOptions) => - waitDictionaryTask(base)(response.taskID, waitRequestOptions) + (response, waitRequestOptions) => waitAppTask(base)(response.taskID, waitRequestOptions) ); }; }; diff --git a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts index 3684625bf..535c63a3e 100644 --- a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts @@ -3,7 +3,7 @@ import { MethodEnum } from '@algolia/requester-common'; import { RequestOptions } from '@algolia/transporter'; import { SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient } from '../..'; -import { waitDictionaryTask } from '.'; +import { waitAppTask } from '.'; // TODO: fill in SaveDictionaryEntriesOptions type // TODO objectIDs have to be a composite objects with actionType=deleteEntry and body=objectID like MultipleBatch @@ -22,8 +22,7 @@ export const deleteDictionaryEntries = (base: SearchClient) => { }, requestOptions ), - (response, waitRequestOptions) => - waitDictionaryTask(base)(response.taskID, waitRequestOptions) + (response, waitRequestOptions) => waitAppTask(base)(response.taskID, waitRequestOptions) ); }; }; diff --git a/packages/client-search/src/methods/client/getDictionaryTask.ts b/packages/client-search/src/methods/client/getAppTask.ts similarity index 89% rename from packages/client-search/src/methods/client/getDictionaryTask.ts rename to packages/client-search/src/methods/client/getAppTask.ts index 18ba6d081..7805babf2 100644 --- a/packages/client-search/src/methods/client/getDictionaryTask.ts +++ b/packages/client-search/src/methods/client/getAppTask.ts @@ -4,7 +4,7 @@ import { RequestOptions } from '@algolia/transporter'; import { SearchClient, TaskStatusResponse } from '../..'; -export const getDictionaryTask = (base: SearchClient) => { +export const getAppTask = (base: SearchClient) => { return ( taskID: number, requestOptions?: RequestOptions diff --git a/packages/client-search/src/methods/client/index.ts b/packages/client-search/src/methods/client/index.ts index 787a568c6..9cc3f64f2 100644 --- a/packages/client-search/src/methods/client/index.ts +++ b/packages/client-search/src/methods/client/index.ts @@ -18,7 +18,7 @@ export * from './getDictionarySettings'; export * from './getLogs'; export * from './getSecuredApiKeyRemainingValidity'; export * from './getTopUserIDs'; -export * from './getDictionaryTask'; +export * from './getAppTask'; export * from './getUserID'; export * from './hasPendingMappings'; export * from './initIndex'; @@ -39,4 +39,4 @@ export * from './searchDictionaryEntries'; export * from './searchUserIDs'; export * from './setDictionarySettings'; export * from './updateApiKey'; -export * from './waitDictionaryTask'; +export * from './waitAppTask'; diff --git a/packages/client-search/src/methods/client/replaceDictionaryEntries.ts b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts index 39df752ca..583461f46 100644 --- a/packages/client-search/src/methods/client/replaceDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts @@ -8,7 +8,7 @@ import { SaveDictionaryEntriesResponse, SearchClient, } from '../..'; -import { waitDictionaryTask } from '.'; +import { waitAppTask } from '.'; // TODO: fill in DictionaryEntry & SaveDictionaryEntriesOptions types // TODO entries have to be a composite objects with actionType=addEntry and body=DictEntry like MultipleBatch @@ -27,8 +27,7 @@ export const replaceDictionaryEntries = (base: SearchClient) => { }, requestOptions ), - (response, waitRequestOptions) => - waitDictionaryTask(base)(response.taskID, waitRequestOptions) + (response, waitRequestOptions) => waitAppTask(base)(response.taskID, waitRequestOptions) ); }; }; diff --git a/packages/client-search/src/methods/client/saveDictionaryEntries.ts b/packages/client-search/src/methods/client/saveDictionaryEntries.ts index 94dd4d151..7bcfcf15d 100644 --- a/packages/client-search/src/methods/client/saveDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/saveDictionaryEntries.ts @@ -8,7 +8,7 @@ import { SaveDictionaryEntriesResponse, SearchClient, } from '../..'; -import { waitDictionaryTask } from '.'; +import { waitAppTask } from '.'; // TODO: fill in DictionaryEntry & SaveDictionaryEntriesOptions types // TODO entries have to be a composite objects with actionType=addEntry and body=DictEntry like MultipleBatch @@ -27,8 +27,7 @@ export const saveDictionaryEntries = (base: SearchClient) => { }, requestOptions ), - (response, waitRequestOptions) => - waitDictionaryTask(base)(response.taskID, waitRequestOptions) + (response, waitRequestOptions) => waitAppTask(base)(response.taskID, waitRequestOptions) ); }; }; diff --git a/packages/client-search/src/methods/client/setDictionarySettings.ts b/packages/client-search/src/methods/client/setDictionarySettings.ts index 023294320..a739dda63 100644 --- a/packages/client-search/src/methods/client/setDictionarySettings.ts +++ b/packages/client-search/src/methods/client/setDictionarySettings.ts @@ -3,7 +3,7 @@ import { MethodEnum } from '@algolia/requester-common'; import { RequestOptions } from '@algolia/transporter'; import { DictionarySettings, SearchClient, SetDictionarySettingsResponse } from '../..'; -import { waitDictionaryTask } from '.'; +import { waitAppTask } from '.'; // TODO: fill in DictionarySettings & SetDictionarySettingsResponse types export const setDictionarySettings = (base: SearchClient) => { @@ -20,8 +20,7 @@ export const setDictionarySettings = (base: SearchClient) => { }, requestOptions ), - (response, waitRequestOptions) => - waitDictionaryTask(base)(response.taskID, waitRequestOptions) + (response, waitRequestOptions) => waitAppTask(base)(response.taskID, waitRequestOptions) ); }; }; diff --git a/packages/client-search/src/methods/client/waitDictionaryTask.ts b/packages/client-search/src/methods/client/waitAppTask.ts similarity index 68% rename from packages/client-search/src/methods/client/waitDictionaryTask.ts rename to packages/client-search/src/methods/client/waitAppTask.ts index 0e1c38b1a..ae25111ae 100644 --- a/packages/client-search/src/methods/client/waitDictionaryTask.ts +++ b/packages/client-search/src/methods/client/waitAppTask.ts @@ -2,12 +2,12 @@ import { createRetryablePromise } from '@algolia/client-common'; import { RequestOptions } from '@algolia/transporter'; import { SearchClient } from '../..'; -import { getDictionaryTask } from '.'; +import { getAppTask } from '.'; -export const waitDictionaryTask = (base: SearchClient) => { +export const waitAppTask = (base: SearchClient) => { return (taskID: number, requestOptions?: RequestOptions): Readonly> => { return createRetryablePromise(retry => { - return getDictionaryTask(base)(taskID, requestOptions).then(response => { + return getAppTask(base)(taskID, requestOptions).then(response => { return response.status !== 'published' ? retry() : undefined; }); }); diff --git a/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts b/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts index fe67e73e5..9b3ae8abf 100644 --- a/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts +++ b/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts @@ -1,10 +1,6 @@ import { Hit } from '.'; export type SearchDictionaryEntriesResponse = { - /** - * TODO - */ - /** * The hits returned by the search. * From fe25469a8025689bb2049b2c1f0eb8077402c73c Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Tue, 6 Apr 2021 17:48:44 +0200 Subject: [PATCH 03/13] semicolon --- .../client-search/src/__tests__/integration/dictionary.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client-search/src/__tests__/integration/dictionary.test.ts b/packages/client-search/src/__tests__/integration/dictionary.test.ts index a2437989c..dc08419ba 100644 --- a/packages/client-search/src/__tests__/integration/dictionary.test.ts +++ b/packages/client-search/src/__tests__/integration/dictionary.test.ts @@ -3,7 +3,7 @@ import { TestSuite } from '../../../../client-common/src/__tests__/TestSuite'; const testSuite = new TestSuite('dictionary'); test(testSuite.testName, async () => { - const client = testSuite.makeSearchClient('ALGOLIA_APPLICATION_ID_2', 'ALGOLIA_ADMIN_KEY_2') + const client = testSuite.makeSearchClient('ALGOLIA_APPLICATION_ID_2', 'ALGOLIA_ADMIN_KEY_2'); // Stopwords const stopwordEntryId = Math.floor(Math.random() * 10000).toString(); From d34a139f5a32300a3fb0a9bed64dc1981c90079b Mon Sep 17 00:00:00 2001 From: shortcuts Date: Thu, 8 Apr 2021 15:14:24 +0200 Subject: [PATCH 04/13] add missing types --- package.json | 2 +- packages/algoliasearch/src/builds/browser.ts | 13 +- packages/algoliasearch/src/builds/node.ts | 13 +- .../__tests__/integration/dictionary.test.ts | 135 +++++++++--------- .../methods/client/clearDictionaryEntries.ts | 10 +- .../methods/client/deleteDictionaryEntries.ts | 18 ++- .../methods/client/getDictionarySettings.ts | 1 - .../client/replaceDictionaryEntries.ts | 12 +- .../methods/client/saveDictionaryEntries.ts | 12 +- .../methods/client/searchDictionaryEntries.ts | 9 +- .../methods/client/setDictionarySettings.ts | 3 +- .../src/types/DictionaryEntry.ts | 12 +- .../client-search/src/types/DictionaryName.ts | 1 + .../src/types/DictionarySettings.ts | 13 +- .../types/GetDictionarySettingsResponse.ts | 8 +- .../src/types/RequireAtLeastOne.ts | 4 + .../src/types/SaveDictionaryEntriesOptions.ts | 5 +- .../types/SearchDictionaryEntriesResponse.ts | 50 +------ packages/client-search/src/types/index.ts | 1 + 19 files changed, 164 insertions(+), 158 deletions(-) create mode 100644 packages/client-search/src/types/DictionaryName.ts create mode 100644 packages/client-search/src/types/RequireAtLeastOne.ts diff --git a/package.json b/package.json index 7c2ef7631..df61ab93a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { + "version": "4.8.5", "private": true, "license": "MIT", - "version": "4.8.5", "workspaces": [ "packages/*" ], diff --git a/packages/algoliasearch/src/builds/browser.ts b/packages/algoliasearch/src/builds/browser.ts index d150a98c5..32ea491c8 100644 --- a/packages/algoliasearch/src/builds/browser.ts +++ b/packages/algoliasearch/src/builds/browser.ts @@ -70,6 +70,7 @@ import { deleteSynonym, DeleteSynonymOptions, DictionaryEntry, + DictionaryName, DictionarySettings, exists, findAnswers, @@ -628,26 +629,26 @@ export type SearchClient = BaseSearchClient & { requestOptions?: HasPendingMappingsOptions & RequestOptions ) => Readonly>; readonly clearDictionaryEntries: ( - dictionary: string, + dictionary: DictionaryName, requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ) => Readonly>; readonly deleteDictionaryEntries: ( - dictionary: string, + dictionary: DictionaryName, objectIDs: readonly string[], requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ) => Readonly>; readonly replaceDictionaryEntries: ( - dictionary: string, + dictionary: DictionaryName, entries: readonly DictionaryEntry[], requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ) => Readonly>; readonly saveDictionaryEntries: ( - dictionary: string, + dictionary: DictionaryName, entries: readonly DictionaryEntry[], requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ) => Readonly>; readonly searchDictionaryEntries: ( - dictionary: string, + dictionary: DictionaryName, query: string, requestOptions?: RequestOptions ) => Readonly>; @@ -655,7 +656,7 @@ export type SearchClient = BaseSearchClient & { requestOptions?: RequestOptions ) => Readonly>; readonly setDictionarySettings: ( - settings: readonly DictionarySettings[], + settings: DictionarySettings, requestOptions?: RequestOptions ) => Readonly>; readonly getAppTask: ( diff --git a/packages/algoliasearch/src/builds/node.ts b/packages/algoliasearch/src/builds/node.ts index 78a06703f..7cf7d8fe0 100644 --- a/packages/algoliasearch/src/builds/node.ts +++ b/packages/algoliasearch/src/builds/node.ts @@ -69,6 +69,7 @@ import { deleteSynonym, DeleteSynonymOptions, DictionaryEntry, + DictionaryName, DictionarySettings, exists, findAnswers, @@ -636,26 +637,26 @@ export type SearchClient = BaseSearchClient & { ) => string; readonly getSecuredApiKeyRemainingValidity: (securedApiKey: string) => number; readonly clearDictionaryEntries: ( - dictionary: string, + dictionary: DictionaryName, requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ) => Readonly>; readonly deleteDictionaryEntries: ( - dictionary: string, + dictionary: DictionaryName, objectIDs: readonly string[], requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ) => Readonly>; readonly replaceDictionaryEntries: ( - dictionary: string, + dictionary: DictionaryName, entries: readonly DictionaryEntry[], requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ) => Readonly>; readonly saveDictionaryEntries: ( - dictionary: string, + dictionary: DictionaryName, entries: readonly DictionaryEntry[], requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ) => Readonly>; readonly searchDictionaryEntries: ( - dictionary: string, + dictionary: DictionaryName, query: string, requestOptions?: RequestOptions ) => Readonly>; @@ -663,7 +664,7 @@ export type SearchClient = BaseSearchClient & { requestOptions?: RequestOptions ) => Readonly>; readonly setDictionarySettings: ( - settings: readonly DictionarySettings[], + settings: DictionarySettings, requestOptions?: RequestOptions ) => Readonly>; readonly getAppTask: ( diff --git a/packages/client-search/src/__tests__/integration/dictionary.test.ts b/packages/client-search/src/__tests__/integration/dictionary.test.ts index dc08419ba..23d32290e 100644 --- a/packages/client-search/src/__tests__/integration/dictionary.test.ts +++ b/packages/client-search/src/__tests__/integration/dictionary.test.ts @@ -1,93 +1,98 @@ +/* eslint-disable no-param-reassign */ import { TestSuite } from '../../../../client-common/src/__tests__/TestSuite'; const testSuite = new TestSuite('dictionary'); -test(testSuite.testName, async () => { +describe(testSuite.testName, () => { const client = testSuite.makeSearchClient('ALGOLIA_APPLICATION_ID_2', 'ALGOLIA_ADMIN_KEY_2'); - // Stopwords - const stopwordEntryId = Math.floor(Math.random() * 10000).toString(); - expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); + test('stopwords', async () => { + const stopwordEntryId = Math.floor(Math.random() * 10000).toString(); + expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); - const stopwordEntry = { - objectID: stopwordEntryId, - language: 'en', - word: 'down', - }; + const stopwordEntry = { + objectID: stopwordEntryId, + language: 'en', + word: 'down', + }; - await client.saveDictionaryEntries('stopwords', [stopwordEntry]); + await client.saveDictionaryEntries('stopwords', [stopwordEntry]); - const stopwords = await client.searchDictionaryEntries('stopwords', stopwordEntryId); - expect(stopwords.nbHits).toEqual(1); - expect(stopwords.hits[0].objectID).toEqual(stopwordEntry.objectID); - expect(stopwords.hits[0].word).toEqual(stopwordEntry.word); + const stopwords = await client.searchDictionaryEntries('stopwords', stopwordEntryId); + expect(stopwords.nbHits).toEqual(1); + expect(stopwords.hits[0].objectID).toEqual(stopwordEntry.objectID); + expect(stopwords.hits[0].word).toEqual(stopwordEntry.word); - await client.deleteDictionaryEntries('stopwords', [stopwordEntryId]); - expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); + await client.deleteDictionaryEntries('stopwords', [stopwordEntryId]); + expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); - const oldDictionaryState = await client.searchDictionaryEntries('stopwords', ''); - const oldDictionaryEntries = oldDictionaryState.hits.map(hit => { - delete hit.type; + const oldDictionaryState = await client.searchDictionaryEntries('stopwords', ''); + const oldDictionaryEntries = oldDictionaryState.hits.map(hit => { + // @ts-ignore + delete hit.type; - return hit; - }); + return hit; + }); - await client.saveDictionaryEntries('stopwords', [stopwordEntry]); - expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(1); + await client.saveDictionaryEntries('stopwords', [stopwordEntry]); + expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(1); - await client.replaceDictionaryEntries('stopwords', oldDictionaryEntries); - expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); + await client.replaceDictionaryEntries('stopwords', oldDictionaryEntries); + expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); - const stopwordsSettings = { - disableStandardEntries: { - stopwords: { - en: true, + const stopwordsSettings = { + disableStandardEntries: { + stopwords: { + en: true, + }, }, - }, - }; + }; - await client.setDictionarySettings(stopwordsSettings); - expect(await client.getDictionarySettings()).toEqual(stopwordsSettings); + await client.setDictionarySettings(stopwordsSettings); + expect(await client.getDictionarySettings()).toEqual(stopwordsSettings); + }); - // Plurals - const pluralEntryId = Math.floor(Math.random() * 10000).toString(); - expect(await client.searchDictionaryEntries('plurals', pluralEntryId).nbHits).toEqual(0); + test('plurals', async () => { + const pluralEntryId = Math.floor(Math.random() * 10000).toString(); + expect((await client.searchDictionaryEntries('plurals', pluralEntryId)).nbHits).toEqual(0); - const pluralEntry = { - objectID: pluralEntryId, - language: 'fr', - words: ['cheval', 'chevaux'], - }; + const pluralEntry = { + objectID: pluralEntryId, + language: 'fr', + words: ['cheval', 'chevaux'], + }; - await client.saveDictionaryEntries('plurals', [pluralEntry]); + await client.saveDictionaryEntries('plurals', [pluralEntry]); - const plurals = await client.searchDictionaryEntries('plurals', pluralEntryId); - expect(plurals.nbHits).toEqual(1); - expect(plurals.hits[0].objectID).toEqual(pluralEntry.objectID); - expect(plurals.hits[0].words).toEqual(pluralEntry.words); + const plurals = await client.searchDictionaryEntries('plurals', pluralEntryId); + expect(plurals.nbHits).toEqual(1); + expect(plurals.hits[0].objectID).toEqual(pluralEntry.objectID); + expect(plurals.hits[0].words).toEqual(pluralEntry.words); - await client.deleteDictionaryEntries('plurals', [pluralEntryId]); - expect(await client.searchDictionaryEntries('plurals', pluralEntryId).nbHits).toEqual(0); + await client.deleteDictionaryEntries('plurals', [pluralEntryId]); + expect((await client.searchDictionaryEntries('plurals', pluralEntryId)).nbHits).toEqual(0); + }); - // Compounds - const compoundEntryId = Math.floor(Math.random() * 10000).toString(); - expect(await client.searchDictionaryEntries('plurals', compoundEntryId).nbHits).toEqual(0); + test('compounds', async () => { + const compoundEntryId = Math.floor(Math.random() * 10000).toString(); + expect((await client.searchDictionaryEntries('plurals', compoundEntryId)).nbHits).toEqual(0); - const compoundEntry = { - objectID: compoundEntryId, - language: 'fr', - word: 'kopfschmerztablette', - decomposition: ['kopf', 'schmerz', 'tablette'], - }; + const compoundEntry = { + objectID: compoundEntryId, + language: 'fr', + word: 'kopfschmerztablette', + decomposition: ['kopf', 'schmerz', 'tablette'], + }; - await client.saveDictionaryEntries('plurals', [compoundEntry]); + await client.saveDictionaryEntries('plurals', [compoundEntry]); - const compounds = await client.searchDictionaryEntries('plurals', compoundEntryId); - expect(compounds.nbHits).toEqual(1); - expect(compounds.hits[0].objectID).toEqual(compoundEntry.objectID); - expect(compounds.hits[0].word).toEqual(compoundEntry.word); - expect(compounds.hits[0].decomposition).toEqual(compoundEntry.decomposition); + const compounds = await client.searchDictionaryEntries('plurals', compoundEntryId); + expect(compounds.nbHits).toEqual(1); + expect(compounds.hits[0].objectID).toEqual(compoundEntry.objectID); + expect(compounds.hits[0].word).toEqual(compoundEntry.word); + expect(compounds.hits[0].decomposition).toEqual(compoundEntry.decomposition); - await client.deleteDictionaryEntries('plurals', [compoundEntryId]); - expect(await client.searchDictionaryEntries('plurals', compoundEntryId).nbHits).toEqual(0); + await client.deleteDictionaryEntries('plurals', [compoundEntryId]); + expect((await client.searchDictionaryEntries('plurals', compoundEntryId)).nbHits).toEqual(0); + }); }); diff --git a/packages/client-search/src/methods/client/clearDictionaryEntries.ts b/packages/client-search/src/methods/client/clearDictionaryEntries.ts index f5b846448..d8f0e68bc 100644 --- a/packages/client-search/src/methods/client/clearDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/clearDictionaryEntries.ts @@ -2,13 +2,17 @@ import { createWaitablePromise, encode, WaitablePromise } from '@algolia/client- import { MethodEnum } from '@algolia/requester-common'; import { RequestOptions } from '@algolia/transporter'; -import { SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient } from '../..'; +import { + DictionaryName, + SaveDictionaryEntriesOptions, + SaveDictionaryEntriesResponse, + SearchClient, +} from '../..'; import { waitAppTask } from '.'; -// TODO: fill in SaveDictionaryEntriesOptions type export const clearDictionaryEntries = (base: SearchClient) => { return ( - dictionary: string, + dictionary: DictionaryName, requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ): Readonly> => { return createWaitablePromise( diff --git a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts index 535c63a3e..3b7a32428 100644 --- a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts @@ -2,23 +2,31 @@ import { createWaitablePromise, encode, WaitablePromise } from '@algolia/client- import { MethodEnum } from '@algolia/requester-common'; import { RequestOptions } from '@algolia/transporter'; -import { SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient } from '../..'; +import { + DictionaryName, + SaveDictionaryEntriesOptions, + SaveDictionaryEntriesResponse, + SearchClient, +} from '../..'; import { waitAppTask } from '.'; -// TODO: fill in SaveDictionaryEntriesOptions type -// TODO objectIDs have to be a composite objects with actionType=deleteEntry and body=objectID like MultipleBatch export const deleteDictionaryEntries = (base: SearchClient) => { return ( - dictionary: string, + dictionary: DictionaryName, objectIDs: readonly string[], requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ): Readonly> => { + const requests = objectIDs.map(objectID => ({ + actionType: 'deleteEntry', + body: objectID, + })); + return createWaitablePromise( base.transporter.write( { method: MethodEnum.Post, path: encode('/1/dictionaries/%s/batch', dictionary), - data: { clearExistingDictionaryEntries: false, requests: objectIDs }, + data: { clearExistingDictionaryEntries: false, requests }, }, requestOptions ), diff --git a/packages/client-search/src/methods/client/getDictionarySettings.ts b/packages/client-search/src/methods/client/getDictionarySettings.ts index 11ea0c970..cb4758347 100644 --- a/packages/client-search/src/methods/client/getDictionarySettings.ts +++ b/packages/client-search/src/methods/client/getDictionarySettings.ts @@ -3,7 +3,6 @@ import { RequestOptions } from '@algolia/transporter'; import { GetDictionarySettingsResponse, SearchClient } from '../..'; -// TODO: fill in GetDictionarySettingsResponse type export const getDictionarySettings = (base: SearchClient) => { return (requestOptions?: RequestOptions): Readonly> => { return base.transporter.read( diff --git a/packages/client-search/src/methods/client/replaceDictionaryEntries.ts b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts index 583461f46..3dc9cf33c 100644 --- a/packages/client-search/src/methods/client/replaceDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts @@ -4,26 +4,30 @@ import { RequestOptions } from '@algolia/transporter'; import { DictionaryEntry, + DictionaryName, SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient, } from '../..'; import { waitAppTask } from '.'; -// TODO: fill in DictionaryEntry & SaveDictionaryEntriesOptions types -// TODO entries have to be a composite objects with actionType=addEntry and body=DictEntry like MultipleBatch export const replaceDictionaryEntries = (base: SearchClient) => { return ( - dictionary: string, + dictionary: DictionaryName, entries: readonly DictionaryEntry[], requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ): Readonly> => { + const requests = entries.map(entry => ({ + actionType: 'addEntry', + body: entry, + })); + return createWaitablePromise( base.transporter.write( { method: MethodEnum.Post, path: encode('/1/dictionaries/%s/batch', dictionary), - data: { clearExistingDictionaryEntries: true, requests: entries }, + data: { clearExistingDictionaryEntries: true, requests }, }, requestOptions ), diff --git a/packages/client-search/src/methods/client/saveDictionaryEntries.ts b/packages/client-search/src/methods/client/saveDictionaryEntries.ts index 7bcfcf15d..a885aac3e 100644 --- a/packages/client-search/src/methods/client/saveDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/saveDictionaryEntries.ts @@ -4,26 +4,30 @@ import { RequestOptions } from '@algolia/transporter'; import { DictionaryEntry, + DictionaryName, SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient, } from '../..'; import { waitAppTask } from '.'; -// TODO: fill in DictionaryEntry & SaveDictionaryEntriesOptions types -// TODO entries have to be a composite objects with actionType=addEntry and body=DictEntry like MultipleBatch export const saveDictionaryEntries = (base: SearchClient) => { return ( - dictionary: string, + dictionary: DictionaryName, entries: readonly DictionaryEntry[], requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ): Readonly> => { + const requests = entries.map(entry => ({ + actionType: 'addEntry', + body: entry, + })); + return createWaitablePromise( base.transporter.write( { method: MethodEnum.Post, path: encode('/1/dictionaries/%s/batch', dictionary), - data: { clearExistingDictionaryEntries: false, requests: entries }, + data: { clearExistingDictionaryEntries: false, requests }, }, requestOptions ), diff --git a/packages/client-search/src/methods/client/searchDictionaryEntries.ts b/packages/client-search/src/methods/client/searchDictionaryEntries.ts index e91dd04b4..98787cb95 100644 --- a/packages/client-search/src/methods/client/searchDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/searchDictionaryEntries.ts @@ -2,15 +2,14 @@ import { encode } from '@algolia/client-common'; import { MethodEnum } from '@algolia/requester-common'; import { RequestOptions } from '@algolia/transporter'; -import { SearchClient, SearchDictionaryEntriesResponse } from '../..'; +import { DictionaryName, SearchClient, SearchDictionaryEntriesResponse } from '../..'; -// TODO: fill in SearchDictionaryEntriesResponse type export const searchDictionaryEntries = (base: SearchClient) => { - return ( - dictionary: string, + return ( + dictionary: DictionaryName, query: string, requestOptions?: RequestOptions - ): Readonly>> => { + ): Readonly> => { return base.transporter.read( { method: MethodEnum.Post, diff --git a/packages/client-search/src/methods/client/setDictionarySettings.ts b/packages/client-search/src/methods/client/setDictionarySettings.ts index a739dda63..39a90ce5b 100644 --- a/packages/client-search/src/methods/client/setDictionarySettings.ts +++ b/packages/client-search/src/methods/client/setDictionarySettings.ts @@ -5,10 +5,9 @@ import { RequestOptions } from '@algolia/transporter'; import { DictionarySettings, SearchClient, SetDictionarySettingsResponse } from '../..'; import { waitAppTask } from '.'; -// TODO: fill in DictionarySettings & SetDictionarySettingsResponse types export const setDictionarySettings = (base: SearchClient) => { return ( - settings: readonly DictionarySettings[], + settings: DictionarySettings, requestOptions?: RequestOptions ): Readonly> => { return createWaitablePromise( diff --git a/packages/client-search/src/types/DictionaryEntry.ts b/packages/client-search/src/types/DictionaryEntry.ts index c0c6e6d81..f3c061ddd 100644 --- a/packages/client-search/src/types/DictionaryEntry.ts +++ b/packages/client-search/src/types/DictionaryEntry.ts @@ -4,7 +4,13 @@ export type DictionaryEntry = { */ readonly objectID: string; - /** - * TODO - */ + readonly language: string; + + readonly word?: string; + + readonly words?: readonly string[]; + + readonly decomposition?: readonly string[]; + + readonly state?: 'enabled' | 'disabled'; }; diff --git a/packages/client-search/src/types/DictionaryName.ts b/packages/client-search/src/types/DictionaryName.ts new file mode 100644 index 000000000..46333d441 --- /dev/null +++ b/packages/client-search/src/types/DictionaryName.ts @@ -0,0 +1 @@ +export type DictionaryName = 'plurals' | 'stopwords' | 'compounds'; diff --git a/packages/client-search/src/types/DictionarySettings.ts b/packages/client-search/src/types/DictionarySettings.ts index a6cb0090f..2dfff0333 100644 --- a/packages/client-search/src/types/DictionarySettings.ts +++ b/packages/client-search/src/types/DictionarySettings.ts @@ -1,10 +1,11 @@ -export type DictionarySettings = { - /** - * Unique identifier for the rule (format: [A-Za-z0-9_-]+). - */ - readonly objectID: string; +import { DictionaryName } from './DictionaryName'; +import { RequireAtLeastOne } from './RequireAtLeastOne'; +export type DictionarySettings = { /** - * TODO + * TODO: Description */ + readonly disableStandardEntries: RequireAtLeastOne< + Record> + >; }; diff --git a/packages/client-search/src/types/GetDictionarySettingsResponse.ts b/packages/client-search/src/types/GetDictionarySettingsResponse.ts index 4a82816ea..618481418 100644 --- a/packages/client-search/src/types/GetDictionarySettingsResponse.ts +++ b/packages/client-search/src/types/GetDictionarySettingsResponse.ts @@ -1,5 +1,11 @@ +import { DictionaryName } from './DictionaryName'; +import { RequireAtLeastOne } from './RequireAtLeastOne'; + export type GetDictionarySettingsResponse = { /** - * TODO + * TODO: Description */ + readonly disableStandardEntries: RequireAtLeastOne< + Record> + >; }; diff --git a/packages/client-search/src/types/RequireAtLeastOne.ts b/packages/client-search/src/types/RequireAtLeastOne.ts new file mode 100644 index 000000000..9b2cb5406 --- /dev/null +++ b/packages/client-search/src/types/RequireAtLeastOne.ts @@ -0,0 +1,4 @@ +export type RequireAtLeastOne = { + [TKey in keyof TType]-?: Required> & + Partial>>; +}[keyof TType]; diff --git a/packages/client-search/src/types/SaveDictionaryEntriesOptions.ts b/packages/client-search/src/types/SaveDictionaryEntriesOptions.ts index 4b13c6de1..c9ef0157a 100644 --- a/packages/client-search/src/types/SaveDictionaryEntriesOptions.ts +++ b/packages/client-search/src/types/SaveDictionaryEntriesOptions.ts @@ -1,5 +1,8 @@ +import { DictionaryEntry } from './DictionaryEntry'; + export type SaveDictionaryEntriesOptions = { /** - * TODO + * Array of dictionary entries */ + readonly dictionaryEntries: readonly DictionaryEntry[]; }; diff --git a/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts b/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts index 9b3ae8abf..1d054e0af 100644 --- a/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts +++ b/packages/client-search/src/types/SearchDictionaryEntriesResponse.ts @@ -1,12 +1,10 @@ -import { Hit } from '.'; +import { DictionaryEntry } from './DictionaryEntry'; -export type SearchDictionaryEntriesResponse = { +export type SearchDictionaryEntriesResponse = { /** - * The hits returned by the search. - * - * Hits are ordered according to the ranking or sorting of the index being queried. + * The dictionary entries returned by the search. */ - hits: Array>; + hits: DictionaryEntry[]; /** * Index of the current page (zero-based). @@ -14,25 +12,10 @@ export type SearchDictionaryEntriesResponse = { page: number; /** - * Number of hits returned (used only with offset) - */ - length?: number; - - /** - * The offset of the first hit to returned. - */ - offset?: number; - - /** - * Number of hits matched by the query. + * Number of dictionary entries matched by the query. */ nbHits: number; - /** - * Subset of hits selected when relevancyStrictness is applied. - */ - nbSortedHits?: number; - /** * Number of pages returned. * @@ -40,27 +23,4 @@ export type SearchDictionaryEntriesResponse = { * number of hits per page (hitsPerPage), rounded up to the nearest integer. */ nbPages: number; - - /** - * Maximum number of hits returned per page. - */ - hitsPerPage: number; - - /** - * Time the server took to process the request, in milliseconds. This does not include network time. - */ - processingTimeMS: number; - - /** - * Whether the nbHits is exhaustive (true) or approximate (false). - * - * An approximation is done when the query takes more than 50ms to be - * processed (this can happen when using complex filters on millions on records). - */ - exhaustiveNbHits: boolean; - - /** - * Whether the facet count is exhaustive (true) or approximate (false). - */ - exhaustiveFacetsCount?: boolean; }; diff --git a/packages/client-search/src/types/index.ts b/packages/client-search/src/types/index.ts index 44d2eb8d2..63a1f74b3 100644 --- a/packages/client-search/src/types/index.ts +++ b/packages/client-search/src/types/index.ts @@ -25,6 +25,7 @@ export * from './DeleteByFiltersOptions'; export * from './DeleteResponse'; export * from './DeleteSynonymOptions'; export * from './DictionaryEntry'; +export * from './DictionaryName'; export * from './DictionarySettings'; export * from './FacetHit'; export * from './FindAnswersOptions'; From fe2ca4ee6ba86e312ce38773193a689f54579b0d Mon Sep 17 00:00:00 2001 From: shortcuts Date: Thu, 8 Apr 2021 15:21:43 +0200 Subject: [PATCH 05/13] group tests --- package.json | 2 +- .../__tests__/integration/dictionary.test.ts | 132 +++++++++--------- 2 files changed, 64 insertions(+), 70 deletions(-) diff --git a/package.json b/package.json index df61ab93a..8135f05fe 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "bundlesize": [ { "path": "packages/algoliasearch/dist/algoliasearch.umd.js", - "maxSize": "7.65KB" + "maxSize": "7.85KB" }, { "path": "packages/algoliasearch/dist/algoliasearch-lite.umd.js", diff --git a/packages/client-search/src/__tests__/integration/dictionary.test.ts b/packages/client-search/src/__tests__/integration/dictionary.test.ts index 23d32290e..641b38244 100644 --- a/packages/client-search/src/__tests__/integration/dictionary.test.ts +++ b/packages/client-search/src/__tests__/integration/dictionary.test.ts @@ -3,96 +3,90 @@ import { TestSuite } from '../../../../client-common/src/__tests__/TestSuite'; const testSuite = new TestSuite('dictionary'); -describe(testSuite.testName, () => { +test(testSuite.testName, async () => { const client = testSuite.makeSearchClient('ALGOLIA_APPLICATION_ID_2', 'ALGOLIA_ADMIN_KEY_2'); - test('stopwords', async () => { - const stopwordEntryId = Math.floor(Math.random() * 10000).toString(); - expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); + const stopwordEntryId = Math.floor(Math.random() * 10000).toString(); + expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); - const stopwordEntry = { - objectID: stopwordEntryId, - language: 'en', - word: 'down', - }; + const stopwordEntry = { + objectID: stopwordEntryId, + language: 'en', + word: 'down', + }; - await client.saveDictionaryEntries('stopwords', [stopwordEntry]); + await client.saveDictionaryEntries('stopwords', [stopwordEntry]); - const stopwords = await client.searchDictionaryEntries('stopwords', stopwordEntryId); - expect(stopwords.nbHits).toEqual(1); - expect(stopwords.hits[0].objectID).toEqual(stopwordEntry.objectID); - expect(stopwords.hits[0].word).toEqual(stopwordEntry.word); + const stopwords = await client.searchDictionaryEntries('stopwords', stopwordEntryId); + expect(stopwords.nbHits).toEqual(1); + expect(stopwords.hits[0].objectID).toEqual(stopwordEntry.objectID); + expect(stopwords.hits[0].word).toEqual(stopwordEntry.word); - await client.deleteDictionaryEntries('stopwords', [stopwordEntryId]); - expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); + await client.deleteDictionaryEntries('stopwords', [stopwordEntryId]); + expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); - const oldDictionaryState = await client.searchDictionaryEntries('stopwords', ''); - const oldDictionaryEntries = oldDictionaryState.hits.map(hit => { - // @ts-ignore - delete hit.type; + const oldDictionaryState = await client.searchDictionaryEntries('stopwords', ''); + const oldDictionaryEntries = oldDictionaryState.hits.map(hit => { + // @ts-ignore + delete hit.type; - return hit; - }); + return hit; + }); - await client.saveDictionaryEntries('stopwords', [stopwordEntry]); - expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(1); + await client.saveDictionaryEntries('stopwords', [stopwordEntry]); + expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(1); - await client.replaceDictionaryEntries('stopwords', oldDictionaryEntries); - expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); + await client.replaceDictionaryEntries('stopwords', oldDictionaryEntries); + expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); - const stopwordsSettings = { - disableStandardEntries: { - stopwords: { - en: true, - }, + const stopwordsSettings = { + disableStandardEntries: { + stopwords: { + en: true, }, - }; + }, + }; - await client.setDictionarySettings(stopwordsSettings); - expect(await client.getDictionarySettings()).toEqual(stopwordsSettings); - }); + await client.setDictionarySettings(stopwordsSettings); + expect(await client.getDictionarySettings()).toEqual(stopwordsSettings); - test('plurals', async () => { - const pluralEntryId = Math.floor(Math.random() * 10000).toString(); - expect((await client.searchDictionaryEntries('plurals', pluralEntryId)).nbHits).toEqual(0); + const pluralEntryId = Math.floor(Math.random() * 10000).toString(); + expect((await client.searchDictionaryEntries('plurals', pluralEntryId)).nbHits).toEqual(0); - const pluralEntry = { - objectID: pluralEntryId, - language: 'fr', - words: ['cheval', 'chevaux'], - }; + const pluralEntry = { + objectID: pluralEntryId, + language: 'fr', + words: ['cheval', 'chevaux'], + }; - await client.saveDictionaryEntries('plurals', [pluralEntry]); + await client.saveDictionaryEntries('plurals', [pluralEntry]); - const plurals = await client.searchDictionaryEntries('plurals', pluralEntryId); - expect(plurals.nbHits).toEqual(1); - expect(plurals.hits[0].objectID).toEqual(pluralEntry.objectID); - expect(plurals.hits[0].words).toEqual(pluralEntry.words); + const plurals = await client.searchDictionaryEntries('plurals', pluralEntryId); + expect(plurals.nbHits).toEqual(1); + expect(plurals.hits[0].objectID).toEqual(pluralEntry.objectID); + expect(plurals.hits[0].words).toEqual(pluralEntry.words); - await client.deleteDictionaryEntries('plurals', [pluralEntryId]); - expect((await client.searchDictionaryEntries('plurals', pluralEntryId)).nbHits).toEqual(0); - }); + await client.deleteDictionaryEntries('plurals', [pluralEntryId]); + expect((await client.searchDictionaryEntries('plurals', pluralEntryId)).nbHits).toEqual(0); - test('compounds', async () => { - const compoundEntryId = Math.floor(Math.random() * 10000).toString(); - expect((await client.searchDictionaryEntries('plurals', compoundEntryId)).nbHits).toEqual(0); + const compoundEntryId = Math.floor(Math.random() * 10000).toString(); + expect((await client.searchDictionaryEntries('plurals', compoundEntryId)).nbHits).toEqual(0); - const compoundEntry = { - objectID: compoundEntryId, - language: 'fr', - word: 'kopfschmerztablette', - decomposition: ['kopf', 'schmerz', 'tablette'], - }; + const compoundEntry = { + objectID: compoundEntryId, + language: 'fr', + word: 'kopfschmerztablette', + decomposition: ['kopf', 'schmerz', 'tablette'], + }; - await client.saveDictionaryEntries('plurals', [compoundEntry]); + await client.saveDictionaryEntries('plurals', [compoundEntry]); - const compounds = await client.searchDictionaryEntries('plurals', compoundEntryId); - expect(compounds.nbHits).toEqual(1); - expect(compounds.hits[0].objectID).toEqual(compoundEntry.objectID); - expect(compounds.hits[0].word).toEqual(compoundEntry.word); - expect(compounds.hits[0].decomposition).toEqual(compoundEntry.decomposition); + const compounds = await client.searchDictionaryEntries('plurals', compoundEntryId); + expect(compounds.nbHits).toEqual(1); + expect(compounds.hits[0].objectID).toEqual(compoundEntry.objectID); + expect(compounds.hits[0].word).toEqual(compoundEntry.word); + expect(compounds.hits[0].decomposition).toEqual(compoundEntry.decomposition); - await client.deleteDictionaryEntries('plurals', [compoundEntryId]); - expect((await client.searchDictionaryEntries('plurals', compoundEntryId)).nbHits).toEqual(0); - }); + await client.deleteDictionaryEntries('plurals', [compoundEntryId]); + expect((await client.searchDictionaryEntries('plurals', compoundEntryId)).nbHits).toEqual(0); }); From 18f39823ffb94d69f2f579d837db6ced4e9fba14 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Fri, 9 Apr 2021 15:54:28 +0200 Subject: [PATCH 06/13] remove `dictionary` tests from `browser-lite` env --- jest.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jest.config.js b/jest.config.js index 883687c91..0988cb768 100644 --- a/jest.config.js +++ b/jest.config.js @@ -48,6 +48,7 @@ module.exports = { 'packages/client-search/src/__tests__/integration/secured-api-keys.test.ts', 'packages/client-search/src/__tests__/integration/settings.test.ts', 'packages/client-search/src/__tests__/integration/synonyms.test.ts', + 'packages/client-search/src/__tests__/integration/dictionary.test.ts', ], globals: { environment: 'browser-lite', From a9dc6afc6b455df4e5fe83aefad8fb767cb59a6d Mon Sep 17 00:00:00 2001 From: shortcuts Date: Fri, 9 Apr 2021 16:36:20 +0200 Subject: [PATCH 07/13] fix methods --- .../client-search/src/methods/client/deleteDictionaryEntries.ts | 2 +- .../src/methods/client/replaceDictionaryEntries.ts | 2 +- .../client-search/src/methods/client/saveDictionaryEntries.ts | 2 +- .../client-search/src/methods/client/searchDictionaryEntries.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts index 3b7a32428..6219d6b1b 100644 --- a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts @@ -17,7 +17,7 @@ export const deleteDictionaryEntries = (base: SearchClient) => { requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ): Readonly> => { const requests = objectIDs.map(objectID => ({ - actionType: 'deleteEntry', + action: 'deleteEntry', body: objectID, })); diff --git a/packages/client-search/src/methods/client/replaceDictionaryEntries.ts b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts index 3dc9cf33c..33bae0eed 100644 --- a/packages/client-search/src/methods/client/replaceDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts @@ -18,7 +18,7 @@ export const replaceDictionaryEntries = (base: SearchClient) => { requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ): Readonly> => { const requests = entries.map(entry => ({ - actionType: 'addEntry', + action: 'addEntry', body: entry, })); diff --git a/packages/client-search/src/methods/client/saveDictionaryEntries.ts b/packages/client-search/src/methods/client/saveDictionaryEntries.ts index a885aac3e..7fbf83a06 100644 --- a/packages/client-search/src/methods/client/saveDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/saveDictionaryEntries.ts @@ -18,7 +18,7 @@ export const saveDictionaryEntries = (base: SearchClient) => { requestOptions?: RequestOptions & SaveDictionaryEntriesOptions ): Readonly> => { const requests = entries.map(entry => ({ - actionType: 'addEntry', + action: 'addEntry', body: entry, })); diff --git a/packages/client-search/src/methods/client/searchDictionaryEntries.ts b/packages/client-search/src/methods/client/searchDictionaryEntries.ts index 98787cb95..dc45abd90 100644 --- a/packages/client-search/src/methods/client/searchDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/searchDictionaryEntries.ts @@ -13,7 +13,7 @@ export const searchDictionaryEntries = (base: SearchClient) => { return base.transporter.read( { method: MethodEnum.Post, - path: encode('1/indexes/%s/query', dictionary), + path: encode('/1/dictionaries/%s/search', dictionary), data: { query, }, From cbe487588a9a8596cc7f333a98995f31889d4bfa Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 12 Apr 2021 15:29:45 +0200 Subject: [PATCH 08/13] split and fix tests --- jest.config.js | 1 + .../__tests__/integration/dictionary.test.ts | 211 +++++++++++------- .../methods/client/deleteDictionaryEntries.ts | 2 +- 3 files changed, 133 insertions(+), 81 deletions(-) diff --git a/jest.config.js b/jest.config.js index 0988cb768..f0135e341 100644 --- a/jest.config.js +++ b/jest.config.js @@ -66,6 +66,7 @@ module.exports = { testPathIgnorePatterns: [ 'packages/requester-node-http/*', 'packages/client-search/src/__tests__/integration/secured-api-keys.test.ts', + 'packages/client-search/src/__tests__/integration/dictionary.test.ts', ], globals: { environment: 'browser', diff --git a/packages/client-search/src/__tests__/integration/dictionary.test.ts b/packages/client-search/src/__tests__/integration/dictionary.test.ts index 641b38244..1ac246523 100644 --- a/packages/client-search/src/__tests__/integration/dictionary.test.ts +++ b/packages/client-search/src/__tests__/integration/dictionary.test.ts @@ -3,90 +3,141 @@ import { TestSuite } from '../../../../client-common/src/__tests__/TestSuite'; const testSuite = new TestSuite('dictionary'); -test(testSuite.testName, async () => { +describe(testSuite.testName, () => { const client = testSuite.makeSearchClient('ALGOLIA_APPLICATION_ID_2', 'ALGOLIA_ADMIN_KEY_2'); - const stopwordEntryId = Math.floor(Math.random() * 10000).toString(); - expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); - - const stopwordEntry = { - objectID: stopwordEntryId, - language: 'en', - word: 'down', - }; - - await client.saveDictionaryEntries('stopwords', [stopwordEntry]); - - const stopwords = await client.searchDictionaryEntries('stopwords', stopwordEntryId); - expect(stopwords.nbHits).toEqual(1); - expect(stopwords.hits[0].objectID).toEqual(stopwordEntry.objectID); - expect(stopwords.hits[0].word).toEqual(stopwordEntry.word); - - await client.deleteDictionaryEntries('stopwords', [stopwordEntryId]); - expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); - - const oldDictionaryState = await client.searchDictionaryEntries('stopwords', ''); - const oldDictionaryEntries = oldDictionaryState.hits.map(hit => { - // @ts-ignore - delete hit.type; - - return hit; - }); - - await client.saveDictionaryEntries('stopwords', [stopwordEntry]); - expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(1); - - await client.replaceDictionaryEntries('stopwords', oldDictionaryEntries); - expect((await client.searchDictionaryEntries('stopwords', stopwordEntryId)).nbHits).toEqual(0); - - const stopwordsSettings = { - disableStandardEntries: { - stopwords: { - en: true, + test('stopwords', async () => { + const stopwordEntry = { + objectID: Math.floor(Math.random() * 10000).toString(), + language: 'en', + word: 'down', + }; + + // clean past entries + await client + .deleteDictionaryEntries( + 'stopwords', + (await client.searchDictionaryEntries('stopwords', stopwordEntry.objectID)).hits.map( + hit => hit.objectID + ) + ) + .wait(); + + const nbSearchEntries = ( + await client.searchDictionaryEntries('stopwords', stopwordEntry.objectID) + ).nbHits; + + await client.saveDictionaryEntries('stopwords', [stopwordEntry]).wait(); + + const stopwords = await client.searchDictionaryEntries('stopwords', stopwordEntry.objectID); + + expect(stopwords.nbHits).toEqual(nbSearchEntries + 1); + expect(stopwords.hits[nbSearchEntries].objectID).toEqual(stopwordEntry.objectID); + expect(stopwords.hits[nbSearchEntries].word).toEqual(stopwordEntry.word); + + await client.deleteDictionaryEntries('stopwords', [stopwordEntry.objectID]).wait(); + expect( + (await client.searchDictionaryEntries('stopwords', stopwordEntry.objectID)).nbHits + ).toEqual(0); + + const oldDictionaryState = await client.searchDictionaryEntries('stopwords', ''); + const oldDictionaryEntries = oldDictionaryState.hits.map(hit => { + // @ts-ignore + delete hit.type; + + return hit; + }); + + await client.saveDictionaryEntries('stopwords', [stopwordEntry]).wait(); + expect( + (await client.searchDictionaryEntries('stopwords', stopwordEntry.objectID)).nbHits + ).toEqual(1); + + await client.replaceDictionaryEntries('stopwords', oldDictionaryEntries).wait(); + expect( + (await client.searchDictionaryEntries('stopwords', stopwordEntry.objectID)).nbHits + ).toEqual(0); + + const stopwordsSettings = { + disableStandardEntries: { + stopwords: { + en: true, + fr: true, + }, }, - }, - }; - - await client.setDictionarySettings(stopwordsSettings); - expect(await client.getDictionarySettings()).toEqual(stopwordsSettings); + }; - const pluralEntryId = Math.floor(Math.random() * 10000).toString(); - expect((await client.searchDictionaryEntries('plurals', pluralEntryId)).nbHits).toEqual(0); - - const pluralEntry = { - objectID: pluralEntryId, - language: 'fr', - words: ['cheval', 'chevaux'], - }; - - await client.saveDictionaryEntries('plurals', [pluralEntry]); - - const plurals = await client.searchDictionaryEntries('plurals', pluralEntryId); - expect(plurals.nbHits).toEqual(1); - expect(plurals.hits[0].objectID).toEqual(pluralEntry.objectID); - expect(plurals.hits[0].words).toEqual(pluralEntry.words); - - await client.deleteDictionaryEntries('plurals', [pluralEntryId]); - expect((await client.searchDictionaryEntries('plurals', pluralEntryId)).nbHits).toEqual(0); - - const compoundEntryId = Math.floor(Math.random() * 10000).toString(); - expect((await client.searchDictionaryEntries('plurals', compoundEntryId)).nbHits).toEqual(0); - - const compoundEntry = { - objectID: compoundEntryId, - language: 'fr', - word: 'kopfschmerztablette', - decomposition: ['kopf', 'schmerz', 'tablette'], - }; - - await client.saveDictionaryEntries('plurals', [compoundEntry]); + await client.setDictionarySettings(stopwordsSettings); + expect(await client.getDictionarySettings()).toEqual(stopwordsSettings); + }); - const compounds = await client.searchDictionaryEntries('plurals', compoundEntryId); - expect(compounds.nbHits).toEqual(1); - expect(compounds.hits[0].objectID).toEqual(compoundEntry.objectID); - expect(compounds.hits[0].word).toEqual(compoundEntry.word); - expect(compounds.hits[0].decomposition).toEqual(compoundEntry.decomposition); + test('plurals', async () => { + const pluralEntry = { + objectID: Math.floor(Math.random() * 10000).toString(), + language: 'fr', + words: ['cheval', 'chevaux'], + }; + + // clean past entries + await client + .deleteDictionaryEntries( + 'plurals', + (await client.searchDictionaryEntries('plurals', pluralEntry.objectID)).hits.map( + hit => hit.objectID + ) + ) + .wait(); + + const nbSearchEntries = (await client.searchDictionaryEntries('plurals', pluralEntry.objectID)) + .nbHits; + + await client.saveDictionaryEntries('plurals', [pluralEntry]).wait(); + + const plurals = await client.searchDictionaryEntries('plurals', pluralEntry.objectID); + + expect(plurals.nbHits).toEqual(nbSearchEntries + 1); + expect(plurals.hits[nbSearchEntries].objectID).toEqual(pluralEntry.objectID); + expect(plurals.hits[nbSearchEntries].words).toEqual(pluralEntry.words); + + await client.deleteDictionaryEntries('plurals', [pluralEntry.objectID]).wait(); + expect((await client.searchDictionaryEntries('plurals', pluralEntry.objectID)).nbHits).toEqual( + 0 + ); + }); - await client.deleteDictionaryEntries('plurals', [compoundEntryId]); - expect((await client.searchDictionaryEntries('plurals', compoundEntryId)).nbHits).toEqual(0); + test('compounds', async () => { + const compoundEntry = { + objectID: Math.floor(Math.random() * 10000).toString(), + language: 'de', + word: 'kopfschmerztablette', + decomposition: ['kopf', 'schmerz', 'tablette'], + }; + + // clean past entries + await client + .deleteDictionaryEntries( + 'compounds', + (await client.searchDictionaryEntries('compounds', compoundEntry.objectID)).hits.map( + hit => hit.objectID + ) + ) + .wait(); + + const nbSearchEntries = ( + await client.searchDictionaryEntries('compounds', compoundEntry.objectID) + ).nbHits; + + await client.saveDictionaryEntries('compounds', [compoundEntry]).wait(); + + const compounds = await client.searchDictionaryEntries('compounds', compoundEntry.objectID); + + expect(compounds.nbHits).toEqual(nbSearchEntries + 1); + expect(compounds.hits[nbSearchEntries].objectID).toEqual(compoundEntry.objectID); + expect(compounds.hits[nbSearchEntries].word).toEqual(compoundEntry.word); + + await client.deleteDictionaryEntries('compounds', [compoundEntry.objectID]).wait(); + expect( + (await client.searchDictionaryEntries('compounds', compoundEntry.objectID)).nbHits + ).toEqual(0); + }); }); diff --git a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts index 6219d6b1b..49be0922f 100644 --- a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts @@ -18,7 +18,7 @@ export const deleteDictionaryEntries = (base: SearchClient) => { ): Readonly> => { const requests = objectIDs.map(objectID => ({ action: 'deleteEntry', - body: objectID, + body: { objectID }, })); return createWaitablePromise( From b67cb54e8f86f9e2df00f6c22bf8cb277e645a19 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 12 Apr 2021 15:58:46 +0200 Subject: [PATCH 09/13] Rename `SaveDictionaryEntriesOptions` type to `DictionaryEntriesOptions` --- packages/algoliasearch/src/builds/browser.ts | 10 +++++----- packages/algoliasearch/src/builds/node.ts | 10 +++++----- .../src/methods/client/clearDictionaryEntries.ts | 4 ++-- .../src/methods/client/deleteDictionaryEntries.ts | 4 ++-- .../src/methods/client/replaceDictionaryEntries.ts | 4 ++-- .../src/methods/client/saveDictionaryEntries.ts | 4 ++-- ...ryEntriesOptions.ts => DictionaryEntriesOptions.ts} | 2 +- packages/client-search/src/types/DictionarySettings.ts | 2 +- .../src/types/GetDictionarySettingsResponse.ts | 2 +- packages/client-search/src/types/index.ts | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) rename packages/client-search/src/types/{SaveDictionaryEntriesOptions.ts => DictionaryEntriesOptions.ts} (78%) diff --git a/packages/algoliasearch/src/builds/browser.ts b/packages/algoliasearch/src/builds/browser.ts index 32ea491c8..13b56b50e 100644 --- a/packages/algoliasearch/src/builds/browser.ts +++ b/packages/algoliasearch/src/builds/browser.ts @@ -69,6 +69,7 @@ import { deleteRule, deleteSynonym, DeleteSynonymOptions, + DictionaryEntriesOptions, DictionaryEntry, DictionaryName, DictionarySettings, @@ -140,7 +141,6 @@ import { RestoreApiKeyResponse, Rule, saveDictionaryEntries, - SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, saveObject, SaveObjectResponse, @@ -630,22 +630,22 @@ export type SearchClient = BaseSearchClient & { ) => Readonly>; readonly clearDictionaryEntries: ( dictionary: DictionaryName, - requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + requestOptions?: RequestOptions & DictionaryEntriesOptions ) => Readonly>; readonly deleteDictionaryEntries: ( dictionary: DictionaryName, objectIDs: readonly string[], - requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + requestOptions?: RequestOptions & DictionaryEntriesOptions ) => Readonly>; readonly replaceDictionaryEntries: ( dictionary: DictionaryName, entries: readonly DictionaryEntry[], - requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + requestOptions?: RequestOptions & DictionaryEntriesOptions ) => Readonly>; readonly saveDictionaryEntries: ( dictionary: DictionaryName, entries: readonly DictionaryEntry[], - requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + requestOptions?: RequestOptions & DictionaryEntriesOptions ) => Readonly>; readonly searchDictionaryEntries: ( dictionary: DictionaryName, diff --git a/packages/algoliasearch/src/builds/node.ts b/packages/algoliasearch/src/builds/node.ts index 7cf7d8fe0..299883c26 100644 --- a/packages/algoliasearch/src/builds/node.ts +++ b/packages/algoliasearch/src/builds/node.ts @@ -68,6 +68,7 @@ import { deleteRule, deleteSynonym, DeleteSynonymOptions, + DictionaryEntriesOptions, DictionaryEntry, DictionaryName, DictionarySettings, @@ -141,7 +142,6 @@ import { RestoreApiKeyResponse, Rule, saveDictionaryEntries, - SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, saveObject, SaveObjectResponse, @@ -638,22 +638,22 @@ export type SearchClient = BaseSearchClient & { readonly getSecuredApiKeyRemainingValidity: (securedApiKey: string) => number; readonly clearDictionaryEntries: ( dictionary: DictionaryName, - requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + requestOptions?: RequestOptions & DictionaryEntriesOptions ) => Readonly>; readonly deleteDictionaryEntries: ( dictionary: DictionaryName, objectIDs: readonly string[], - requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + requestOptions?: RequestOptions & DictionaryEntriesOptions ) => Readonly>; readonly replaceDictionaryEntries: ( dictionary: DictionaryName, entries: readonly DictionaryEntry[], - requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + requestOptions?: RequestOptions & DictionaryEntriesOptions ) => Readonly>; readonly saveDictionaryEntries: ( dictionary: DictionaryName, entries: readonly DictionaryEntry[], - requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + requestOptions?: RequestOptions & DictionaryEntriesOptions ) => Readonly>; readonly searchDictionaryEntries: ( dictionary: DictionaryName, diff --git a/packages/client-search/src/methods/client/clearDictionaryEntries.ts b/packages/client-search/src/methods/client/clearDictionaryEntries.ts index d8f0e68bc..8db90a455 100644 --- a/packages/client-search/src/methods/client/clearDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/clearDictionaryEntries.ts @@ -3,8 +3,8 @@ import { MethodEnum } from '@algolia/requester-common'; import { RequestOptions } from '@algolia/transporter'; import { + DictionaryEntriesOptions, DictionaryName, - SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient, } from '../..'; @@ -13,7 +13,7 @@ import { waitAppTask } from '.'; export const clearDictionaryEntries = (base: SearchClient) => { return ( dictionary: DictionaryName, - requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + requestOptions?: RequestOptions & DictionaryEntriesOptions ): Readonly> => { return createWaitablePromise( base.transporter.write( diff --git a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts index 49be0922f..f841de82d 100644 --- a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts @@ -3,8 +3,8 @@ import { MethodEnum } from '@algolia/requester-common'; import { RequestOptions } from '@algolia/transporter'; import { + DictionaryEntriesOptions, DictionaryName, - SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient, } from '../..'; @@ -14,7 +14,7 @@ export const deleteDictionaryEntries = (base: SearchClient) => { return ( dictionary: DictionaryName, objectIDs: readonly string[], - requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + requestOptions?: RequestOptions & DictionaryEntriesOptions ): Readonly> => { const requests = objectIDs.map(objectID => ({ action: 'deleteEntry', diff --git a/packages/client-search/src/methods/client/replaceDictionaryEntries.ts b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts index 33bae0eed..881d1de16 100644 --- a/packages/client-search/src/methods/client/replaceDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts @@ -3,9 +3,9 @@ import { MethodEnum } from '@algolia/requester-common'; import { RequestOptions } from '@algolia/transporter'; import { + DictionaryEntriesOptions, DictionaryEntry, DictionaryName, - SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient, } from '../..'; @@ -15,7 +15,7 @@ export const replaceDictionaryEntries = (base: SearchClient) => { return ( dictionary: DictionaryName, entries: readonly DictionaryEntry[], - requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + requestOptions?: RequestOptions & DictionaryEntriesOptions ): Readonly> => { const requests = entries.map(entry => ({ action: 'addEntry', diff --git a/packages/client-search/src/methods/client/saveDictionaryEntries.ts b/packages/client-search/src/methods/client/saveDictionaryEntries.ts index 7fbf83a06..2fc28145a 100644 --- a/packages/client-search/src/methods/client/saveDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/saveDictionaryEntries.ts @@ -3,9 +3,9 @@ import { MethodEnum } from '@algolia/requester-common'; import { RequestOptions } from '@algolia/transporter'; import { + DictionaryEntriesOptions, DictionaryEntry, DictionaryName, - SaveDictionaryEntriesOptions, SaveDictionaryEntriesResponse, SearchClient, } from '../..'; @@ -15,7 +15,7 @@ export const saveDictionaryEntries = (base: SearchClient) => { return ( dictionary: DictionaryName, entries: readonly DictionaryEntry[], - requestOptions?: RequestOptions & SaveDictionaryEntriesOptions + requestOptions?: RequestOptions & DictionaryEntriesOptions ): Readonly> => { const requests = entries.map(entry => ({ action: 'addEntry', diff --git a/packages/client-search/src/types/SaveDictionaryEntriesOptions.ts b/packages/client-search/src/types/DictionaryEntriesOptions.ts similarity index 78% rename from packages/client-search/src/types/SaveDictionaryEntriesOptions.ts rename to packages/client-search/src/types/DictionaryEntriesOptions.ts index c9ef0157a..5769d1915 100644 --- a/packages/client-search/src/types/SaveDictionaryEntriesOptions.ts +++ b/packages/client-search/src/types/DictionaryEntriesOptions.ts @@ -1,6 +1,6 @@ import { DictionaryEntry } from './DictionaryEntry'; -export type SaveDictionaryEntriesOptions = { +export type DictionaryEntriesOptions = { /** * Array of dictionary entries */ diff --git a/packages/client-search/src/types/DictionarySettings.ts b/packages/client-search/src/types/DictionarySettings.ts index 2dfff0333..2a6a4c48d 100644 --- a/packages/client-search/src/types/DictionarySettings.ts +++ b/packages/client-search/src/types/DictionarySettings.ts @@ -3,7 +3,7 @@ import { RequireAtLeastOne } from './RequireAtLeastOne'; export type DictionarySettings = { /** - * TODO: Description + * Disable the builtin Algolia entries for a type of dictionary per language. */ readonly disableStandardEntries: RequireAtLeastOne< Record> diff --git a/packages/client-search/src/types/GetDictionarySettingsResponse.ts b/packages/client-search/src/types/GetDictionarySettingsResponse.ts index 618481418..88ddad87d 100644 --- a/packages/client-search/src/types/GetDictionarySettingsResponse.ts +++ b/packages/client-search/src/types/GetDictionarySettingsResponse.ts @@ -3,7 +3,7 @@ import { RequireAtLeastOne } from './RequireAtLeastOne'; export type GetDictionarySettingsResponse = { /** - * TODO: Description + * Disable the builtin Algolia entries for a type of dictionary per language. */ readonly disableStandardEntries: RequireAtLeastOne< Record> diff --git a/packages/client-search/src/types/index.ts b/packages/client-search/src/types/index.ts index 63a1f74b3..426113fad 100644 --- a/packages/client-search/src/types/index.ts +++ b/packages/client-search/src/types/index.ts @@ -24,6 +24,7 @@ export * from './DeleteApiKeyResponse'; export * from './DeleteByFiltersOptions'; export * from './DeleteResponse'; export * from './DeleteSynonymOptions'; +export * from './DictionaryEntriesOptions'; export * from './DictionaryEntry'; export * from './DictionaryName'; export * from './DictionarySettings'; @@ -65,7 +66,6 @@ export * from './RemoveUserIDResponse'; export * from './ReplaceAllObjectsOptions'; export * from './RestoreApiKeyResponse'; export * from './Rule'; -export * from './SaveDictionaryEntriesOptions'; export * from './SaveDictionaryEntriesResponse'; export * from './SaveObjectResponse'; export * from './SaveObjectsOptions'; From edd67145294c007fd9275df481c48f9a01e50995 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 12 Apr 2021 16:27:17 +0200 Subject: [PATCH 10/13] Rename `SaveDictionaryEntriesResponse` type to `DictionaryEntriesResponse` --- packages/algoliasearch/src/builds/browser.ts | 10 +++++----- packages/algoliasearch/src/builds/node.ts | 10 +++++----- .../src/methods/client/clearDictionaryEntries.ts | 6 +++--- .../src/methods/client/deleteDictionaryEntries.ts | 6 +++--- .../src/methods/client/replaceDictionaryEntries.ts | 6 +++--- .../src/methods/client/saveDictionaryEntries.ts | 6 +++--- ...EntriesResponse.ts => DictionaryEntriesResponse.ts} | 2 +- packages/client-search/src/types/index.ts | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) rename packages/client-search/src/types/{SaveDictionaryEntriesResponse.ts => DictionaryEntriesResponse.ts} (78%) diff --git a/packages/algoliasearch/src/builds/browser.ts b/packages/algoliasearch/src/builds/browser.ts index 13b56b50e..a2eefd7b1 100644 --- a/packages/algoliasearch/src/builds/browser.ts +++ b/packages/algoliasearch/src/builds/browser.ts @@ -70,6 +70,7 @@ import { deleteSynonym, DeleteSynonymOptions, DictionaryEntriesOptions, + DictionaryEntriesResponse, DictionaryEntry, DictionaryName, DictionarySettings, @@ -141,7 +142,6 @@ import { RestoreApiKeyResponse, Rule, saveDictionaryEntries, - SaveDictionaryEntriesResponse, saveObject, SaveObjectResponse, saveObjects, @@ -631,22 +631,22 @@ export type SearchClient = BaseSearchClient & { readonly clearDictionaryEntries: ( dictionary: DictionaryName, requestOptions?: RequestOptions & DictionaryEntriesOptions - ) => Readonly>; + ) => Readonly>; readonly deleteDictionaryEntries: ( dictionary: DictionaryName, objectIDs: readonly string[], requestOptions?: RequestOptions & DictionaryEntriesOptions - ) => Readonly>; + ) => Readonly>; readonly replaceDictionaryEntries: ( dictionary: DictionaryName, entries: readonly DictionaryEntry[], requestOptions?: RequestOptions & DictionaryEntriesOptions - ) => Readonly>; + ) => Readonly>; readonly saveDictionaryEntries: ( dictionary: DictionaryName, entries: readonly DictionaryEntry[], requestOptions?: RequestOptions & DictionaryEntriesOptions - ) => Readonly>; + ) => Readonly>; readonly searchDictionaryEntries: ( dictionary: DictionaryName, query: string, diff --git a/packages/algoliasearch/src/builds/node.ts b/packages/algoliasearch/src/builds/node.ts index 299883c26..774ffdbf6 100644 --- a/packages/algoliasearch/src/builds/node.ts +++ b/packages/algoliasearch/src/builds/node.ts @@ -69,6 +69,7 @@ import { deleteSynonym, DeleteSynonymOptions, DictionaryEntriesOptions, + DictionaryEntriesResponse, DictionaryEntry, DictionaryName, DictionarySettings, @@ -142,7 +143,6 @@ import { RestoreApiKeyResponse, Rule, saveDictionaryEntries, - SaveDictionaryEntriesResponse, saveObject, SaveObjectResponse, saveObjects, @@ -639,22 +639,22 @@ export type SearchClient = BaseSearchClient & { readonly clearDictionaryEntries: ( dictionary: DictionaryName, requestOptions?: RequestOptions & DictionaryEntriesOptions - ) => Readonly>; + ) => Readonly>; readonly deleteDictionaryEntries: ( dictionary: DictionaryName, objectIDs: readonly string[], requestOptions?: RequestOptions & DictionaryEntriesOptions - ) => Readonly>; + ) => Readonly>; readonly replaceDictionaryEntries: ( dictionary: DictionaryName, entries: readonly DictionaryEntry[], requestOptions?: RequestOptions & DictionaryEntriesOptions - ) => Readonly>; + ) => Readonly>; readonly saveDictionaryEntries: ( dictionary: DictionaryName, entries: readonly DictionaryEntry[], requestOptions?: RequestOptions & DictionaryEntriesOptions - ) => Readonly>; + ) => Readonly>; readonly searchDictionaryEntries: ( dictionary: DictionaryName, query: string, diff --git a/packages/client-search/src/methods/client/clearDictionaryEntries.ts b/packages/client-search/src/methods/client/clearDictionaryEntries.ts index 8db90a455..e89e574de 100644 --- a/packages/client-search/src/methods/client/clearDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/clearDictionaryEntries.ts @@ -4,8 +4,8 @@ import { RequestOptions } from '@algolia/transporter'; import { DictionaryEntriesOptions, + DictionaryEntriesResponse, DictionaryName, - SaveDictionaryEntriesResponse, SearchClient, } from '../..'; import { waitAppTask } from '.'; @@ -14,8 +14,8 @@ export const clearDictionaryEntries = (base: SearchClient) => { return ( dictionary: DictionaryName, requestOptions?: RequestOptions & DictionaryEntriesOptions - ): Readonly> => { - return createWaitablePromise( + ): Readonly> => { + return createWaitablePromise( base.transporter.write( { method: MethodEnum.Post, diff --git a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts index f841de82d..c29e4dbf7 100644 --- a/packages/client-search/src/methods/client/deleteDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/deleteDictionaryEntries.ts @@ -4,8 +4,8 @@ import { RequestOptions } from '@algolia/transporter'; import { DictionaryEntriesOptions, + DictionaryEntriesResponse, DictionaryName, - SaveDictionaryEntriesResponse, SearchClient, } from '../..'; import { waitAppTask } from '.'; @@ -15,13 +15,13 @@ export const deleteDictionaryEntries = (base: SearchClient) => { dictionary: DictionaryName, objectIDs: readonly string[], requestOptions?: RequestOptions & DictionaryEntriesOptions - ): Readonly> => { + ): Readonly> => { const requests = objectIDs.map(objectID => ({ action: 'deleteEntry', body: { objectID }, })); - return createWaitablePromise( + return createWaitablePromise( base.transporter.write( { method: MethodEnum.Post, diff --git a/packages/client-search/src/methods/client/replaceDictionaryEntries.ts b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts index 881d1de16..4e9c24734 100644 --- a/packages/client-search/src/methods/client/replaceDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/replaceDictionaryEntries.ts @@ -4,9 +4,9 @@ import { RequestOptions } from '@algolia/transporter'; import { DictionaryEntriesOptions, + DictionaryEntriesResponse, DictionaryEntry, DictionaryName, - SaveDictionaryEntriesResponse, SearchClient, } from '../..'; import { waitAppTask } from '.'; @@ -16,13 +16,13 @@ export const replaceDictionaryEntries = (base: SearchClient) => { dictionary: DictionaryName, entries: readonly DictionaryEntry[], requestOptions?: RequestOptions & DictionaryEntriesOptions - ): Readonly> => { + ): Readonly> => { const requests = entries.map(entry => ({ action: 'addEntry', body: entry, })); - return createWaitablePromise( + return createWaitablePromise( base.transporter.write( { method: MethodEnum.Post, diff --git a/packages/client-search/src/methods/client/saveDictionaryEntries.ts b/packages/client-search/src/methods/client/saveDictionaryEntries.ts index 2fc28145a..5b6a6b5c4 100644 --- a/packages/client-search/src/methods/client/saveDictionaryEntries.ts +++ b/packages/client-search/src/methods/client/saveDictionaryEntries.ts @@ -4,9 +4,9 @@ import { RequestOptions } from '@algolia/transporter'; import { DictionaryEntriesOptions, + DictionaryEntriesResponse, DictionaryEntry, DictionaryName, - SaveDictionaryEntriesResponse, SearchClient, } from '../..'; import { waitAppTask } from '.'; @@ -16,13 +16,13 @@ export const saveDictionaryEntries = (base: SearchClient) => { dictionary: DictionaryName, entries: readonly DictionaryEntry[], requestOptions?: RequestOptions & DictionaryEntriesOptions - ): Readonly> => { + ): Readonly> => { const requests = entries.map(entry => ({ action: 'addEntry', body: entry, })); - return createWaitablePromise( + return createWaitablePromise( base.transporter.write( { method: MethodEnum.Post, diff --git a/packages/client-search/src/types/SaveDictionaryEntriesResponse.ts b/packages/client-search/src/types/DictionaryEntriesResponse.ts similarity index 78% rename from packages/client-search/src/types/SaveDictionaryEntriesResponse.ts rename to packages/client-search/src/types/DictionaryEntriesResponse.ts index e7ffba065..1ae88d50c 100644 --- a/packages/client-search/src/types/SaveDictionaryEntriesResponse.ts +++ b/packages/client-search/src/types/DictionaryEntriesResponse.ts @@ -1,4 +1,4 @@ -export type SaveDictionaryEntriesResponse = { +export type DictionaryEntriesResponse = { /** * When the given rules got saved. */ diff --git a/packages/client-search/src/types/index.ts b/packages/client-search/src/types/index.ts index 426113fad..20a9e4d3e 100644 --- a/packages/client-search/src/types/index.ts +++ b/packages/client-search/src/types/index.ts @@ -25,6 +25,7 @@ export * from './DeleteByFiltersOptions'; export * from './DeleteResponse'; export * from './DeleteSynonymOptions'; export * from './DictionaryEntriesOptions'; +export * from './DictionaryEntriesResponse'; export * from './DictionaryEntry'; export * from './DictionaryName'; export * from './DictionarySettings'; @@ -66,7 +67,6 @@ export * from './RemoveUserIDResponse'; export * from './ReplaceAllObjectsOptions'; export * from './RestoreApiKeyResponse'; export * from './Rule'; -export * from './SaveDictionaryEntriesResponse'; export * from './SaveObjectResponse'; export * from './SaveObjectsOptions'; export * from './SaveRuleResponse'; From eb9b26b45845b94a8cdf5ff3c25522c3af9477ea Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 12 Apr 2021 16:28:40 +0200 Subject: [PATCH 11/13] Remove duplicate type: `SetDictionarySettingsResponse` --- packages/algoliasearch/src/builds/browser.ts | 3 +-- packages/algoliasearch/src/builds/node.ts | 3 +-- .../src/methods/client/setDictionarySettings.ts | 6 +++--- .../src/types/SetDictionarySettingsResponse.ts | 11 ----------- packages/client-search/src/types/index.ts | 1 - 5 files changed, 5 insertions(+), 19 deletions(-) delete mode 100644 packages/client-search/src/types/SetDictionarySettingsResponse.ts diff --git a/packages/algoliasearch/src/builds/browser.ts b/packages/algoliasearch/src/builds/browser.ts index a2eefd7b1..cb7bb484b 100644 --- a/packages/algoliasearch/src/builds/browser.ts +++ b/packages/algoliasearch/src/builds/browser.ts @@ -175,7 +175,6 @@ import { SearchUserIDsOptions, SearchUserIDsResponse, setDictionarySettings, - SetDictionarySettingsResponse, setSettings, SetSettingsResponse, Settings, @@ -658,7 +657,7 @@ export type SearchClient = BaseSearchClient & { readonly setDictionarySettings: ( settings: DictionarySettings, requestOptions?: RequestOptions - ) => Readonly>; + ) => Readonly>; readonly getAppTask: ( taskID: number, requestOptions?: RequestOptions diff --git a/packages/algoliasearch/src/builds/node.ts b/packages/algoliasearch/src/builds/node.ts index 774ffdbf6..439605f04 100644 --- a/packages/algoliasearch/src/builds/node.ts +++ b/packages/algoliasearch/src/builds/node.ts @@ -177,7 +177,6 @@ import { SearchUserIDsResponse, SecuredApiKeyRestrictions, setDictionarySettings, - SetDictionarySettingsResponse, setSettings, SetSettingsResponse, Settings, @@ -666,7 +665,7 @@ export type SearchClient = BaseSearchClient & { readonly setDictionarySettings: ( settings: DictionarySettings, requestOptions?: RequestOptions - ) => Readonly>; + ) => Readonly>; readonly getAppTask: ( taskID: number, requestOptions?: RequestOptions diff --git a/packages/client-search/src/methods/client/setDictionarySettings.ts b/packages/client-search/src/methods/client/setDictionarySettings.ts index 39a90ce5b..5ceebc6d4 100644 --- a/packages/client-search/src/methods/client/setDictionarySettings.ts +++ b/packages/client-search/src/methods/client/setDictionarySettings.ts @@ -2,15 +2,15 @@ import { createWaitablePromise, WaitablePromise } from '@algolia/client-common'; import { MethodEnum } from '@algolia/requester-common'; import { RequestOptions } from '@algolia/transporter'; -import { DictionarySettings, SearchClient, SetDictionarySettingsResponse } from '../..'; +import { DictionaryEntriesResponse, DictionarySettings, SearchClient } from '../..'; import { waitAppTask } from '.'; export const setDictionarySettings = (base: SearchClient) => { return ( settings: DictionarySettings, requestOptions?: RequestOptions - ): Readonly> => { - return createWaitablePromise( + ): Readonly> => { + return createWaitablePromise( base.transporter.write( { method: MethodEnum.Put, diff --git a/packages/client-search/src/types/SetDictionarySettingsResponse.ts b/packages/client-search/src/types/SetDictionarySettingsResponse.ts deleted file mode 100644 index eb8bb843b..000000000 --- a/packages/client-search/src/types/SetDictionarySettingsResponse.ts +++ /dev/null @@ -1,11 +0,0 @@ -export type SetDictionarySettingsResponse = { - /** - * When the given rules got saved. - */ - updatedAt: number; - - /** - * The operation task id. May be used to perform a wait task. - */ - taskID: number; -}; diff --git a/packages/client-search/src/types/index.ts b/packages/client-search/src/types/index.ts index 20a9e4d3e..02eb82f6c 100644 --- a/packages/client-search/src/types/index.ts +++ b/packages/client-search/src/types/index.ts @@ -89,7 +89,6 @@ export * from './SearchSynonymsResponse'; export * from './SearchUserIDsOptions'; export * from './SearchUserIDsResponse'; export * from './SecuredApiKeyRestrictions'; -export * from './SetDictionarySettingsResponse'; export * from './SetSettingsOptions'; export * from './SetSettingsResponse'; export * from './Settings'; From 65587604c7ebfe22b35dd6066e06078a16bfeca3 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 12 Apr 2021 16:58:38 +0200 Subject: [PATCH 12/13] Assert object is present --- .../__tests__/integration/dictionary.test.ts | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/client-search/src/__tests__/integration/dictionary.test.ts b/packages/client-search/src/__tests__/integration/dictionary.test.ts index 1ac246523..80a0be9bb 100644 --- a/packages/client-search/src/__tests__/integration/dictionary.test.ts +++ b/packages/client-search/src/__tests__/integration/dictionary.test.ts @@ -32,8 +32,13 @@ describe(testSuite.testName, () => { const stopwords = await client.searchDictionaryEntries('stopwords', stopwordEntry.objectID); expect(stopwords.nbHits).toEqual(nbSearchEntries + 1); - expect(stopwords.hits[nbSearchEntries].objectID).toEqual(stopwordEntry.objectID); - expect(stopwords.hits[nbSearchEntries].word).toEqual(stopwordEntry.word); + expect(stopwords.hits).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + ...stopwordEntry, + }), + ]) + ); await client.deleteDictionaryEntries('stopwords', [stopwordEntry.objectID]).wait(); expect( @@ -96,8 +101,13 @@ describe(testSuite.testName, () => { const plurals = await client.searchDictionaryEntries('plurals', pluralEntry.objectID); expect(plurals.nbHits).toEqual(nbSearchEntries + 1); - expect(plurals.hits[nbSearchEntries].objectID).toEqual(pluralEntry.objectID); - expect(plurals.hits[nbSearchEntries].words).toEqual(pluralEntry.words); + expect(plurals.hits).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + ...pluralEntry, + }), + ]) + ); await client.deleteDictionaryEntries('plurals', [pluralEntry.objectID]).wait(); expect((await client.searchDictionaryEntries('plurals', pluralEntry.objectID)).nbHits).toEqual( @@ -132,8 +142,13 @@ describe(testSuite.testName, () => { const compounds = await client.searchDictionaryEntries('compounds', compoundEntry.objectID); expect(compounds.nbHits).toEqual(nbSearchEntries + 1); - expect(compounds.hits[nbSearchEntries].objectID).toEqual(compoundEntry.objectID); - expect(compounds.hits[nbSearchEntries].word).toEqual(compoundEntry.word); + expect(compounds.hits).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + ...compoundEntry, + }), + ]) + ); await client.deleteDictionaryEntries('compounds', [compoundEntry.objectID]).wait(); expect( From fb5a73f32782b2f0b7f3ead05b86a513258fc4cb Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 12 Apr 2021 17:24:27 +0200 Subject: [PATCH 13/13] Remove unneeded spread --- .../__tests__/integration/dictionary.test.ts | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/packages/client-search/src/__tests__/integration/dictionary.test.ts b/packages/client-search/src/__tests__/integration/dictionary.test.ts index 80a0be9bb..61aabf1fb 100644 --- a/packages/client-search/src/__tests__/integration/dictionary.test.ts +++ b/packages/client-search/src/__tests__/integration/dictionary.test.ts @@ -33,11 +33,7 @@ describe(testSuite.testName, () => { expect(stopwords.nbHits).toEqual(nbSearchEntries + 1); expect(stopwords.hits).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - ...stopwordEntry, - }), - ]) + expect.arrayContaining([expect.objectContaining(stopwordEntry)]) ); await client.deleteDictionaryEntries('stopwords', [stopwordEntry.objectID]).wait(); @@ -101,13 +97,7 @@ describe(testSuite.testName, () => { const plurals = await client.searchDictionaryEntries('plurals', pluralEntry.objectID); expect(plurals.nbHits).toEqual(nbSearchEntries + 1); - expect(plurals.hits).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - ...pluralEntry, - }), - ]) - ); + expect(plurals.hits).toEqual(expect.arrayContaining([expect.objectContaining(pluralEntry)])); await client.deleteDictionaryEntries('plurals', [pluralEntry.objectID]).wait(); expect((await client.searchDictionaryEntries('plurals', pluralEntry.objectID)).nbHits).toEqual( @@ -143,11 +133,7 @@ describe(testSuite.testName, () => { expect(compounds.nbHits).toEqual(nbSearchEntries + 1); expect(compounds.hits).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - ...compoundEntry, - }), - ]) + expect.arrayContaining([expect.objectContaining(compoundEntry)]) ); await client.deleteDictionaryEntries('compounds', [compoundEntry.objectID]).wait();