@algolia/client-search
Advanced tools
Comparing version 4.0.0-beta.11 to 4.0.0-beta.12
@@ -32,17 +32,23 @@ 'use strict'; | ||
const appId = options.appId; | ||
const transporter$1 = transporter.createTransporter(options); | ||
transporter$1.setHosts([ | ||
{ url: `${appId}-dsn.algolia.net`, accept: transporter.CallEnum.Read }, | ||
{ url: `${appId}.algolia.net`, accept: transporter.CallEnum.Write }, | ||
].concat(clientCommon.shuffle([ | ||
{ url: `${appId}-1.algolianet.com`, accept: transporter.CallEnum.Any }, | ||
{ url: `${appId}-2.algolianet.com`, accept: transporter.CallEnum.Any }, | ||
{ url: `${appId}-3.algolianet.com`, accept: transporter.CallEnum.Any }, | ||
]))); | ||
const auth = clientCommon.createAuth(options.authMode !== undefined ? options.authMode : clientCommon.AuthMode.WithinHeaders, appId, options.apiKey); | ||
transporter$1.addHeaders({ | ||
...auth.headers(), | ||
...{ 'content-type': 'application/x-www-form-urlencoded' }, | ||
const transporter$1 = transporter.createTransporter({ | ||
hosts: [ | ||
{ url: `${appId}-dsn.algolia.net`, accept: transporter.CallEnum.Read }, | ||
{ url: `${appId}.algolia.net`, accept: transporter.CallEnum.Write }, | ||
].concat(clientCommon.shuffle([ | ||
{ url: `${appId}-1.algolianet.com`, accept: transporter.CallEnum.Any }, | ||
{ url: `${appId}-2.algolianet.com`, accept: transporter.CallEnum.Any }, | ||
{ url: `${appId}-3.algolianet.com`, accept: transporter.CallEnum.Any }, | ||
])), | ||
...options, | ||
headers: { | ||
...auth.headers(), | ||
...{ 'content-type': 'application/x-www-form-urlencoded' }, | ||
...options.headers, | ||
}, | ||
queryParameters: { | ||
...auth.queryParameters(), | ||
...options.queryParameters, | ||
}, | ||
}); | ||
transporter$1.addQueryParameters(auth.queryParameters()); | ||
const base = { | ||
@@ -65,4 +71,3 @@ transporter: transporter$1, | ||
"automatically but *it's not recommended*. " + | ||
'To do it, use `saveObjects(objects, ' + | ||
"{'autoGenerateObjectIDIfNotExist': true})`.", | ||
"To do it, use the `{'autoGenerateObjectIDIfNotExist': true}` option.", | ||
}; | ||
@@ -95,3 +100,3 @@ } | ||
return getApiKey(base)(response.key, waitRequestOptions).catch((apiError) => { | ||
if (apiError.status === 404) { | ||
if (apiError.status !== 404) { | ||
throw apiError; | ||
@@ -157,6 +162,15 @@ } | ||
const copyRules = (base) => { | ||
return (from, to, requestOptions) => { | ||
return copyIndex(base)(from, to, { | ||
...requestOptions, | ||
scope: [ScopeEnum.Rules], | ||
}); | ||
}; | ||
}; | ||
const copySettings = (base) => { | ||
return (from, to, requestOptions) => { | ||
return copyIndex(base)(from, to, { | ||
...(requestOptions === undefined ? {} : requestOptions), | ||
...requestOptions, | ||
scope: [ScopeEnum.Settings], | ||
@@ -170,3 +184,3 @@ }); | ||
return copyIndex(base)(from, to, { | ||
...(requestOptions === undefined ? {} : requestOptions), | ||
...requestOptions, | ||
scope: [ScopeEnum.Synonyms], | ||
@@ -182,2 +196,3 @@ }); | ||
return getApiKey(base)(apiKey, waitRequestOptions) | ||
.then(retry) | ||
.catch((apiError) => { | ||
@@ -187,4 +202,3 @@ if (apiError.status !== 404) { | ||
} | ||
}) | ||
.then(retry); | ||
}); | ||
}); | ||
@@ -220,17 +234,6 @@ }; | ||
return (requestOptions) => { | ||
const { length, offset, type, ...options } = requestOptions || {}; | ||
const mappedRequestOptions = transporter.createMappedRequestOptions(options); | ||
if (length) { | ||
mappedRequestOptions.queryParameters.length = length; // eslint-disable-line functional/immutable-data | ||
} | ||
if (offset) { | ||
mappedRequestOptions.queryParameters.offset = offset; // eslint-disable-line functional/immutable-data | ||
} | ||
if (type) { | ||
mappedRequestOptions.queryParameters.type = type; // eslint-disable-line functional/immutable-data | ||
} | ||
return base.transporter.read({ | ||
method: requesterCommon.MethodEnum.Get, | ||
path: '1/logs', | ||
}, mappedRequestOptions); | ||
}, requestOptions); | ||
}; | ||
@@ -309,14 +312,6 @@ }; | ||
return (requestOptions) => { | ||
const { page, hitsPerPage, ...options } = requestOptions || {}; | ||
const mappedRequestOptions = transporter.createMappedRequestOptions(options); | ||
if (page) { | ||
mappedRequestOptions.queryParameters.page = page; // eslint-disable-line functional/immutable-data | ||
} | ||
if (hitsPerPage) { | ||
mappedRequestOptions.queryParameters.hitsPerPage = hitsPerPage; // eslint-disable-line functional/immutable-data | ||
} | ||
return base.transporter.read({ | ||
method: requesterCommon.MethodEnum.Get, | ||
path: '1/clusters/mapping', | ||
}, mappedRequestOptions); | ||
}, requestOptions); | ||
}; | ||
@@ -568,7 +563,9 @@ }; | ||
const chunk = (base) => { | ||
const chunkedBatch = (base) => { | ||
return (bodies, action, requestOptions) => { | ||
const { batchSize, ...options } = requestOptions || {}; | ||
// eslint-disable-next-line functional/prefer-readonly-type | ||
const responses = []; | ||
const response = { | ||
taskIDs: [], | ||
objectIDs: [], | ||
}; | ||
const forEachBatch = (lastIndex = 0) => { | ||
@@ -588,3 +585,3 @@ // eslint-disable-next-line functional/prefer-readonly-type | ||
if (bodiesChunk.length === 0) { | ||
return Promise.resolve(responses); | ||
return Promise.resolve(response); | ||
} | ||
@@ -596,5 +593,5 @@ return batch(base)(bodiesChunk.map(body => { | ||
}; | ||
}), options).then(response => { | ||
// eslint-disable-next-line functional/immutable-data | ||
responses.push(response); | ||
}), options).then(res => { | ||
response.objectIDs = response.objectIDs.concat(res.objectIDs); // eslint-disable-line functional/immutable-data | ||
response.taskIDs.push(res.taskID); // eslint-disable-line functional/immutable-data | ||
index++; | ||
@@ -604,4 +601,6 @@ return forEachBatch(index); | ||
}; | ||
return clientCommon.createWaitablePromise(forEachBatch(), (batchResponses, waitRequestOptions) => { | ||
return Promise.all(batchResponses.map(response => waitTask(base)(response.taskID, waitRequestOptions))); | ||
return clientCommon.createWaitablePromise(forEachBatch(), (chunkedBatchResponse, waitRequestOptions) => { | ||
return Promise.all(chunkedBatchResponse.taskIDs.map(taskID => { | ||
return waitTask(base)(taskID, waitRequestOptions); | ||
})); | ||
}); | ||
@@ -670,3 +669,3 @@ }; | ||
return clientCommon.createWaitablePromise(deleteObjects(base)([objectID], requestOptions).then(response => { | ||
return { taskID: response[0].taskID }; | ||
return { taskID: response.taskIDs[0] }; | ||
}), (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)); | ||
@@ -681,3 +680,3 @@ }; | ||
}); | ||
return chunk(base)(objects, BatchActionEnum.DeleteObject, requestOptions); | ||
return chunkedBatch(base)(objects, BatchActionEnum.DeleteObject, requestOptions); | ||
}; | ||
@@ -759,11 +758,6 @@ }; | ||
return (objectID, requestOptions) => { | ||
const { attributesToRetrieve, ...options } = requestOptions || {}; | ||
const mappedRequestOptions = transporter.createMappedRequestOptions(options); | ||
if (attributesToRetrieve) { | ||
mappedRequestOptions.queryParameters.attributesToRetrieve = attributesToRetrieve; // eslint-disable-line functional/immutable-data | ||
} | ||
return base.transporter.read({ | ||
method: requesterCommon.MethodEnum.Get, | ||
path: clientCommon.encode('1/indexes/%s/%s', base.indexName, objectID), | ||
}, mappedRequestOptions); | ||
}, requestOptions); | ||
}; | ||
@@ -815,9 +809,9 @@ }; | ||
return (requestOptions) => { | ||
const mappedRequestOptions = transporter.createMappedRequestOptions(requestOptions); | ||
// eslint-disable-next-line functional/immutable-data | ||
mappedRequestOptions.queryParameters.getVersion = '2'; | ||
return base.transporter.read({ | ||
method: requesterCommon.MethodEnum.Get, | ||
path: clientCommon.encode('1/indexes/%s/settings', base.indexName), | ||
}, mappedRequestOptions); | ||
data: { | ||
getVersion: 2, | ||
}, | ||
}, requestOptions); | ||
}; | ||
@@ -848,4 +842,4 @@ }; | ||
return { | ||
objectID: response[0].objectIDs[0], | ||
taskID: response[0].taskID, | ||
objectID: response.objectIDs[0], | ||
taskID: response.taskIDs[0], | ||
}; | ||
@@ -862,3 +856,3 @@ }), (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)); | ||
: BatchActionEnum.PartialUpdateObjectNoCreate; | ||
return chunk(base)(objects, action, options); | ||
return chunkedBatch(base)(objects, action, options); | ||
}; | ||
@@ -869,4 +863,4 @@ }; | ||
return (objects, requestOptions) => { | ||
const { safe, ...options } = requestOptions || {}; | ||
const operation = (from, to, type, operatioRequestOptions) => { | ||
const { safe, autoGenerateObjectIDIfNotExist, batchSize, ...options } = requestOptions || {}; | ||
const operation = (from, to, type, operationRequestOptions) => { | ||
return clientCommon.createWaitablePromise(base.transporter.write({ | ||
@@ -879,3 +873,3 @@ method: requesterCommon.MethodEnum.Post, | ||
}, | ||
}, operatioRequestOptions), (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)); | ||
}, operationRequestOptions), (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)); | ||
}; | ||
@@ -891,2 +885,3 @@ const randomSuffix = Math.random() | ||
}); | ||
// @ts-ignore | ||
// eslint-disable-next-line prefer-const, functional/no-let, functional/prefer-readonly-type | ||
@@ -900,5 +895,11 @@ let responses = []; | ||
responses.push(copyWaitablePromise); | ||
const result = (safe ? copyWaitablePromise.wait(options) : copyWaitablePromise) | ||
const result = (safe | ||
? copyWaitablePromise.wait(options) | ||
: copyWaitablePromise) | ||
.then(() => { | ||
const saveObjectsWaitablePromise = saveObjectsInTemporary(objects, options); | ||
const saveObjectsWaitablePromise = saveObjectsInTemporary(objects, { | ||
...options, | ||
autoGenerateObjectIDIfNotExist, | ||
batchSize, | ||
}); | ||
// eslint-disable-next-line functional/immutable-data | ||
@@ -914,3 +915,9 @@ responses.push(saveObjectsWaitablePromise); | ||
}) | ||
.then(() => Promise.resolve()); | ||
.then(() => Promise.all(responses)) | ||
.then(([copyResponse, saveObjectsResponse, moveResponse]) => { | ||
return { | ||
objectIDs: saveObjectsResponse.objectIDs, | ||
taskIDs: [copyResponse.taskID, ...saveObjectsResponse.taskIDs, moveResponse.taskID], | ||
}; | ||
}); | ||
return clientCommon.createWaitablePromise(result, (_, waitRequestOptions) => { | ||
@@ -934,3 +941,3 @@ return Promise.all(responses.map(response => response.wait(waitRequestOptions))); | ||
return saveSynonyms(base)(synonyms, { | ||
...(requestOptions === undefined ? {} : requestOptions), | ||
...requestOptions, | ||
replaceExistingSynonyms: true, | ||
@@ -945,4 +952,4 @@ }); | ||
return { | ||
objectID: response[0].objectIDs[0], | ||
taskID: response[0].taskID, | ||
objectID: response.objectIDs[0], | ||
taskID: response.taskIDs[0], | ||
}; | ||
@@ -967,3 +974,3 @@ }), (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)); | ||
} | ||
return chunk(base)(objects, action, options); | ||
return chunkedBatch(base)(objects, action, options); | ||
}; | ||
@@ -1133,3 +1140,3 @@ }; | ||
exports.browseSynonyms = browseSynonyms; | ||
exports.chunk = chunk; | ||
exports.chunkedBatch = chunkedBatch; | ||
exports.clearObjects = clearObjects; | ||
@@ -1139,2 +1146,3 @@ exports.clearRules = clearRules; | ||
exports.copyIndex = copyIndex; | ||
exports.copyRules = copyRules; | ||
exports.copySettings = copySettings; | ||
@@ -1141,0 +1149,0 @@ exports.copySynonyms = copySynonyms; |
import { AuthModeType } from '@algolia/client-common'; | ||
import { ClientTransporterOptions } from '@algolia/client-common'; | ||
import { CreateClient } from '@algolia/client-common'; | ||
import { RequestOptions } from '@algolia/transporter'; | ||
import { Transporter } from '@algolia/transporter'; | ||
import { TransporterOptions } from '@algolia/transporter'; | ||
import { WaitablePromise } from '@algolia/client-common'; | ||
@@ -88,5 +88,3 @@ | ||
export declare const BatchActionEnum: { | ||
readonly [key: string]: BatchActionType; | ||
}; | ||
export declare const BatchActionEnum: Readonly<Record<string, BatchActionType>>; | ||
@@ -96,8 +94,21 @@ export declare type BatchActionType = 'addObject' | 'updateObject' | 'partialUpdateObject' | 'partialUpdateObjectNoCreate' | 'deleteObject'; | ||
export declare type BatchRequest = { | ||
/** | ||
* The batch action. | ||
*/ | ||
readonly action: BatchActionType; | ||
readonly body: object; | ||
/** | ||
* The body of the given `action`. Note that, bodies difer | ||
* depending of the action. | ||
*/ | ||
readonly body: Record<string, any>; | ||
}; | ||
export declare type BatchResponse = { | ||
/** | ||
* The operation task id. May be used to perform a wait task. | ||
*/ | ||
readonly taskID: number; | ||
/** | ||
* The object ids created/updated by the batch request. | ||
*/ | ||
readonly objectIDs: readonly string[]; | ||
@@ -109,2 +120,5 @@ }; | ||
export declare type BrowseOptions<TObject> = { | ||
/** | ||
* The callback called for each batch of objects. | ||
*/ | ||
readonly batch?: (batch: ReadonlyArray<TObject & ObjectWithObjectID>) => any; | ||
@@ -114,3 +128,9 @@ }; | ||
export declare type BrowseResponse<TObject> = { | ||
/** | ||
* The hits per page. | ||
*/ | ||
readonly hits: ReadonlyArray<TObject & ObjectWithObjectID>; | ||
/** | ||
* The cursor used for iterate on the next page. | ||
*/ | ||
readonly cursor?: string; | ||
@@ -123,5 +143,19 @@ }; | ||
export declare const chunk: (base: SearchIndex) => (bodies: readonly object[], action: BatchActionType, requestOptions?: (RequestOptions & ChunkOptions) | undefined) => Readonly<WaitablePromise<readonly BatchResponse[]>>; | ||
export declare const chunkedBatch: (base: SearchIndex) => (bodies: readonly object[], action: BatchActionType, requestOptions?: (RequestOptions & ChunkOptions) | undefined) => Readonly<WaitablePromise<ChunkedBatchResponse>>; | ||
export declare type ChunkedBatchResponse = { | ||
/** | ||
* The operations task ids. May be used to perform a wait task. | ||
*/ | ||
readonly taskIDs: readonly number[]; | ||
/** | ||
* The object ids created/updated/deleted by the multiple requests. | ||
*/ | ||
readonly objectIDs: readonly string[]; | ||
}; | ||
export declare type ChunkOptions = { | ||
/** | ||
* The number of objects per batch. | ||
*/ | ||
readonly batchSize?: number; | ||
@@ -135,2 +169,5 @@ }; | ||
export declare type ClearRulesOptions = { | ||
/** | ||
* If the clear rules request should be forward to replicas. | ||
*/ | ||
readonly forwardToReplicas?: boolean; | ||
@@ -142,2 +179,5 @@ }; | ||
export declare type ClearSynonymsOptions = { | ||
/** | ||
* If the clear synonyms request should be forward to replicas. | ||
*/ | ||
readonly forwardToReplicas?: boolean; | ||
@@ -259,2 +299,4 @@ }; | ||
export declare const copyRules: (base: SearchClient) => (from: string, to: string, requestOptions?: RequestOptions | undefined) => Readonly<WaitablePromise<IndexOperationResponse>>; | ||
export declare const copySettings: (base: SearchClient) => (from: string, to: string, requestOptions?: RequestOptions | undefined) => Readonly<WaitablePromise<IndexOperationResponse>>; | ||
@@ -283,3 +325,3 @@ | ||
export declare const createSearchClient: CreateClient<SearchClient, SearchClientOptions & TransporterOptions>; | ||
export declare const createSearchClient: CreateClient<SearchClient, SearchClientOptions & ClientTransporterOptions>; | ||
@@ -291,2 +333,5 @@ export declare function createValidUntilNotFoundError(): Error; | ||
export declare type DeleteApiKeyResponse = { | ||
/** | ||
* The date when the api key was deleted. | ||
*/ | ||
readonly deletedAt: string; | ||
@@ -338,5 +383,8 @@ }; | ||
export declare const deleteObjects: (base: SearchIndex) => (objectIDs: readonly string[], requestOptions?: (RequestOptions & ChunkOptions) | undefined) => Readonly<WaitablePromise<readonly BatchResponse[]>>; | ||
export declare const deleteObjects: (base: SearchIndex) => (objectIDs: readonly string[], requestOptions?: (RequestOptions & ChunkOptions) | undefined) => Readonly<WaitablePromise<ChunkedBatchResponse>>; | ||
export declare type DeleteResponse = { | ||
/** | ||
* The operation task id. May be used to perform a wait task. | ||
*/ | ||
readonly taskID: number; | ||
@@ -350,2 +398,5 @@ }; | ||
export declare type DeleteSynonymOptions = { | ||
/** | ||
* If the delete synonym request should be forward to replicas. | ||
*/ | ||
readonly forwardToReplicas?: boolean; | ||
@@ -357,4 +408,13 @@ }; | ||
export declare type FacetHit = { | ||
/** | ||
* The value of the facet. | ||
*/ | ||
readonly value: string; | ||
/** | ||
* The highlighted value. | ||
*/ | ||
readonly highlighted: string; | ||
/** | ||
* The count. | ||
*/ | ||
readonly count: number; | ||
@@ -366,3 +426,11 @@ }; | ||
export declare type FindObjectOptions = { | ||
/** | ||
* If the underlying find object options should paginate | ||
* over a search method. | ||
*/ | ||
readonly paginate?: boolean; | ||
/** | ||
* The query used by the underlying find object to | ||
* find the object. | ||
*/ | ||
readonly query?: string; | ||
@@ -372,4 +440,13 @@ }; | ||
export declare type FindObjectResponse<TObject> = { | ||
/** | ||
* The found object. | ||
*/ | ||
readonly object: TObject & ObjectWithObjectID; | ||
/** | ||
* The position where the object was found. | ||
*/ | ||
readonly position: number; | ||
/** | ||
* The page where the object was found. | ||
*/ | ||
readonly page: number; | ||
@@ -429,3 +506,9 @@ }; | ||
export declare type GetLogsOptions = { | ||
/** | ||
* The offset. | ||
*/ | ||
readonly offset: number; | ||
/** | ||
* The length size. | ||
*/ | ||
readonly length: number; | ||
@@ -435,3 +518,5 @@ }; | ||
export declare type GetLogsResponse = { | ||
/** List of logs */ | ||
/** | ||
* The list of logs. | ||
*/ | ||
readonly logs: readonly Log[]; | ||
@@ -444,3 +529,3 @@ }; | ||
export declare const getObjectPosition: () => (searchResponse: SearchResponse<{}>, objectID: string) => number; | ||
export declare const getObjectPosition: <TObject>() => (searchResponse: SearchResponse<TObject>, objectID: string) => number; | ||
@@ -450,2 +535,5 @@ export declare const getObjects: (base: SearchIndex) => <TObject>(objectIDs: readonly string[], requestOptions?: (RequestOptions & GetObjectsOptions) | undefined) => Readonly<Promise<GetObjectsResponse<TObject>>>; | ||
export declare type GetObjectsOptions = { | ||
/** | ||
* The attributes that should come with witch object. | ||
*/ | ||
readonly attributesToRetrieve?: readonly string[]; | ||
@@ -455,2 +543,5 @@ }; | ||
export declare type GetObjectsResponse<TObject> = { | ||
/** | ||
* The list of results. | ||
*/ | ||
readonly results: ReadonlyArray<TObject & ObjectWithObjectID>; | ||
@@ -475,5 +566,3 @@ }; | ||
*/ | ||
readonly topUsers: { | ||
readonly [key: string]: readonly UserIDResponse[]; | ||
}; | ||
readonly topUsers: Readonly<Record<string, readonly UserIDResponse[]>>; | ||
}; | ||
@@ -484,2 +573,5 @@ | ||
export declare type IndexOperationResponse = { | ||
/** | ||
* The operation task id. May be used to perform a wait task. | ||
*/ | ||
readonly taskID: number; | ||
@@ -489,19 +581,37 @@ }; | ||
export declare type Indice = { | ||
/** Index name. */ | ||
/** | ||
* Index name. | ||
*/ | ||
readonly name: string; | ||
/** Index creation date. */ | ||
/** | ||
* Index creation date. | ||
*/ | ||
readonly createdAt: number; | ||
/** Date of last update. */ | ||
/** | ||
* Date of last update. | ||
*/ | ||
readonly updatedAt: number; | ||
/** Number of records contained in the index */ | ||
/** | ||
* Number of records contained in the index | ||
*/ | ||
readonly entries: number; | ||
/** Number of bytes of the index in minified format. */ | ||
/** | ||
* Number of bytes of the index in minified format. | ||
*/ | ||
readonly dataSize: number; | ||
/** Number of bytes of the index binary file. */ | ||
/** | ||
* Number of bytes of the index binary file. | ||
*/ | ||
readonly fileSize: number; | ||
/** Last build time in seconds. */ | ||
/** | ||
* Last build time in seconds. | ||
*/ | ||
readonly lastBuildTimes: number; | ||
/** Number of pending indexing operations. */ | ||
/** | ||
* Number of pending indexing operations. | ||
*/ | ||
readonly numberOfPendingTasks: number; | ||
/** A boolean which says whether the index has pending tasks. */ | ||
/** | ||
* A boolean which says whether the index has pending tasks. | ||
*/ | ||
readonly pendingTask: boolean; | ||
@@ -524,3 +634,5 @@ }; | ||
export declare type ListClustersResponse = { | ||
/** List of clusters */ | ||
/** | ||
* List of clusters. | ||
*/ | ||
readonly clusters: readonly Cluster[]; | ||
@@ -532,5 +644,9 @@ }; | ||
export declare type ListIndicesResponse = { | ||
/** Number of pages */ | ||
/** | ||
* Number of pages | ||
*/ | ||
readonly nbPages: number; | ||
/** List of index response */ | ||
/** | ||
* List of index response | ||
*/ | ||
readonly items: readonly Indice[]; | ||
@@ -554,3 +670,3 @@ }; | ||
/** | ||
* List of users id | ||
* List of users id. | ||
*/ | ||
@@ -561,29 +677,57 @@ readonly userIDs: readonly UserIDResponse[]; | ||
export declare type Log = { | ||
/** Timestamp in ISO-8601 format. */ | ||
/** | ||
* Timestamp in ISO-8601 format. | ||
*/ | ||
readonly timeStamp: string; | ||
/** Rest type of the method. */ | ||
/** | ||
* Rest type of the method. | ||
*/ | ||
readonly method: string; | ||
/** Http response code. */ | ||
/** | ||
* Http response code. | ||
*/ | ||
readonly answerCode: string; | ||
/** Request body. It’s truncated after 1000 characters. */ | ||
/** | ||
* Request body. It’s truncated after 1000 characters. | ||
*/ | ||
readonly queryBody: string; | ||
/** Answer body. It’s truncated after 1000 characters. */ | ||
/** | ||
* Answer body. It’s truncated after 1000 characters. | ||
*/ | ||
readonly answer: string; | ||
/** Request URL. */ | ||
/** | ||
* Request URL. | ||
*/ | ||
readonly url: string; | ||
/** Client ip of the call. */ | ||
/** | ||
* Client ip of the call. | ||
*/ | ||
readonly ip: string; | ||
/** SHA1 ID of entry. */ | ||
/** | ||
* SHA1 ID of entry. | ||
*/ | ||
readonly sha1: string; | ||
/** Request Headers (API Key is obfuscated). */ | ||
/** | ||
* Request Headers (API Key is obfuscated). | ||
*/ | ||
readonly queryHeaders: string; | ||
/** Number Of Api Calls */ | ||
/** | ||
* Number Of Api Calls | ||
*/ | ||
readonly numberOfApiCalls: string; | ||
/** Processing time for the query. This does not include network time. */ | ||
/** | ||
* Processing time for the query. This does not include network time. | ||
*/ | ||
readonly processingTimeMS: string; | ||
/** Number of hits returned for the query. */ | ||
/** | ||
* Number of hits returned for the query. | ||
*/ | ||
readonly numberOfQueryHits: string; | ||
/** Exhaustive flags used during the query. */ | ||
/** | ||
* Exhaustive flags used during the query. | ||
*/ | ||
readonly exhaustive?: boolean; | ||
/** Index name of the log */ | ||
/** | ||
* Index name of the log | ||
*/ | ||
readonly index: string; | ||
@@ -597,17 +741,39 @@ }; | ||
export declare type MultipleBatchRequest = { | ||
/** | ||
* The index name where the multiple batch are going to be applied. | ||
*/ | ||
readonly indexName: string; | ||
/** | ||
* The action used. | ||
*/ | ||
readonly action: BatchActionType; | ||
readonly body: object; | ||
/** | ||
* The body associated with the request. | ||
*/ | ||
readonly body: Record<string, any>; | ||
}; | ||
export declare type MultipleBatchResponse = { | ||
/** | ||
* The list of object ids. | ||
*/ | ||
readonly objectIDs: readonly string[]; | ||
readonly taskID: { | ||
readonly [key: string]: number; | ||
}; | ||
/** | ||
* The operation task id. May be used to perform a wait task. | ||
*/ | ||
readonly taskID: Readonly<Record<string, number>>; | ||
}; | ||
export declare type MultipleGetObject = { | ||
/** | ||
* The index name. | ||
*/ | ||
readonly indexName: string; | ||
/** | ||
* The object id. | ||
*/ | ||
readonly objectID: string; | ||
/** | ||
* The attributes that should be returned with the object. | ||
*/ | ||
readonly attributesToRetrieve?: readonly string[]; | ||
@@ -618,4 +784,7 @@ }; | ||
export declare type MultipleGetObjectsResponse<TResult> = { | ||
readonly results: readonly TResult[]; | ||
export declare type MultipleGetObjectsResponse<TObject> = { | ||
/** | ||
* The list of objects. | ||
*/ | ||
readonly results: ReadonlyArray<TObject & ObjectWithObjectID>; | ||
}; | ||
@@ -630,4 +799,13 @@ | ||
export declare type MultipleQueriesQuery = { | ||
/** | ||
* The index name. | ||
*/ | ||
readonly indexName: string; | ||
/** | ||
* The search options. | ||
*/ | ||
readonly params?: SearchOptions; | ||
/** | ||
* The query associated with the request. | ||
*/ | ||
readonly query?: string; | ||
@@ -637,2 +815,5 @@ }; | ||
export declare type MultipleQueriesResponse<TObject> = { | ||
/** | ||
* The list of results. | ||
*/ | ||
readonly results: ReadonlyArray<SearchResponse<TObject & ObjectWithObjectID>>; | ||
@@ -647,15 +828,27 @@ }; | ||
export declare type ObjectWithObjectID = { | ||
/** | ||
* The object id of the object. | ||
*/ | ||
readonly objectID: string; | ||
}; | ||
export declare const partialUpdateObject: (base: SearchIndex) => (object: object, requestOptions?: (RequestOptions & ChunkOptions & PartialUpdateObjectsOptions) | undefined) => Readonly<WaitablePromise<PartialUpdateObjectResponse>>; | ||
export declare const partialUpdateObject: (base: SearchIndex) => (object: Record<string, any>, requestOptions?: (RequestOptions & ChunkOptions & PartialUpdateObjectsOptions) | undefined) => Readonly<WaitablePromise<PartialUpdateObjectResponse>>; | ||
export declare type PartialUpdateObjectResponse = { | ||
/** | ||
* The operation task id. May be used to perform a wait task. | ||
*/ | ||
readonly taskID: number; | ||
/** | ||
* The object id updated. | ||
*/ | ||
readonly objectID: string; | ||
}; | ||
export declare const partialUpdateObjects: (base: SearchIndex) => (objects: readonly Record<string, any>[], requestOptions?: (RequestOptions & ChunkOptions & PartialUpdateObjectsOptions) | undefined) => Readonly<WaitablePromise<readonly BatchResponse[]>>; | ||
export declare const partialUpdateObjects: (base: SearchIndex) => (objects: readonly Record<string, any>[], requestOptions?: (RequestOptions & ChunkOptions & PartialUpdateObjectsOptions) | undefined) => Readonly<WaitablePromise<ChunkedBatchResponse>>; | ||
export declare type PartialUpdateObjectsOptions = { | ||
/** | ||
* If the object should be created when does not exist. | ||
*/ | ||
readonly createIfNotExists?: boolean; | ||
@@ -668,3 +861,3 @@ }; | ||
/** | ||
* Date of deletion | ||
* When the given `userID` got removed. | ||
*/ | ||
@@ -674,7 +867,10 @@ readonly deletedAt: string; | ||
export declare const replaceAllObjects: (base: SearchIndex) => (objects: readonly { | ||
readonly [key: string]: any; | ||
}[], requestOptions?: (ReplaceAllObjectsOptions & RequestOptions) | undefined) => Readonly<WaitablePromise<void>>; | ||
export declare const replaceAllObjects: (base: SearchIndex) => (objects: readonly Readonly<Record<string, any>>[], requestOptions?: (ReplaceAllObjectsOptions & ChunkOptions & SaveObjectsOptions & RequestOptions) | undefined) => Readonly<WaitablePromise<ChunkedBatchResponse>>; | ||
export declare type ReplaceAllObjectsOptions = { | ||
/** | ||
* If the all objects should be replaced using wait operations. Keep | ||
* in mind that, when the `safe` option is used, the operation may | ||
* take a little more than expected. | ||
*/ | ||
readonly safe?: boolean; | ||
@@ -724,14 +920,21 @@ }; | ||
export declare const saveObject: (base: SearchIndex) => (object: object, requestOptions?: (RequestOptions & ChunkOptions & SaveObjectsOptions) | undefined) => Readonly<WaitablePromise<SaveObjectResponse>>; | ||
export declare const saveObject: (base: SearchIndex) => (object: Readonly<Record<string, any>>, requestOptions?: (RequestOptions & ChunkOptions & SaveObjectsOptions) | undefined) => Readonly<WaitablePromise<SaveObjectResponse>>; | ||
export declare type SaveObjectResponse = { | ||
/** | ||
* The operation task id. May be used to perform a wait task. | ||
*/ | ||
readonly taskID: number; | ||
/** | ||
* The object id saved. | ||
*/ | ||
readonly objectID: string; | ||
}; | ||
export declare const saveObjects: (base: SearchIndex) => (objects: readonly { | ||
readonly [key: string]: any; | ||
}[], requestOptions?: (RequestOptions & ChunkOptions & SaveObjectsOptions) | undefined) => Readonly<WaitablePromise<readonly BatchResponse[]>>; | ||
export declare const saveObjects: (base: SearchIndex) => (objects: readonly Readonly<Record<string, any>>[], requestOptions?: (RequestOptions & ChunkOptions & SaveObjectsOptions) | undefined) => Readonly<WaitablePromise<ChunkedBatchResponse>>; | ||
export declare type SaveObjectsOptions = { | ||
/** | ||
* If the object id should be generated when does not exists. | ||
*/ | ||
readonly autoGenerateObjectIDIfNotExist?: boolean; | ||
@@ -747,3 +950,9 @@ }; | ||
export declare type SaveRulesOptions = { | ||
/** | ||
* If the saved rules should be forward to replicas. | ||
*/ | ||
readonly forwardToReplicas?: boolean; | ||
/** | ||
* If the existing rules should be removed. | ||
*/ | ||
readonly clearExistingRules?: boolean; | ||
@@ -753,3 +962,9 @@ }; | ||
export declare type SaveRulesResponse = { | ||
/** | ||
* When the given rules got saved. | ||
*/ | ||
readonly updatedAt: number; | ||
/** | ||
* The operation task id. May be used to perform a wait task. | ||
*/ | ||
readonly taskID: number; | ||
@@ -765,3 +980,9 @@ }; | ||
export declare type SaveSynonymsOptions = { | ||
/** | ||
* If the saved synonyms should be forward to replicas. | ||
*/ | ||
readonly forwardToReplicas?: boolean; | ||
/** | ||
* If the existing synonyms should be removed. | ||
*/ | ||
readonly replaceExistingSynonyms?: boolean; | ||
@@ -771,9 +992,13 @@ }; | ||
export declare type SaveSynonymsResponse = { | ||
/** | ||
* When the given synonyms got saved. | ||
*/ | ||
readonly updatedAt: number; | ||
/** | ||
* The operation task id. May be used to perform a wait task. | ||
*/ | ||
readonly taskID: number; | ||
}; | ||
export declare const ScopeEnum: { | ||
readonly [key: string]: ScopeType; | ||
}; | ||
export declare const ScopeEnum: Readonly<Record<string, ScopeType>>; | ||
@@ -785,4 +1010,13 @@ export declare type ScopeType = 'settings' | 'synonyms' | 'rules'; | ||
export declare type SearchClient = { | ||
/** | ||
* The application id. | ||
*/ | ||
readonly appId: string; | ||
/** | ||
* The underlying transporter. | ||
*/ | ||
readonly transporter: Transporter; | ||
/** | ||
* Mutates the transporter, adding the given user agent. | ||
*/ | ||
readonly addAlgoliaAgent: (segment: string, version?: string) => void; | ||
@@ -792,4 +1026,14 @@ }; | ||
export declare type SearchClientOptions = { | ||
/** | ||
* The application id. | ||
*/ | ||
readonly appId: string; | ||
/** | ||
* The api key. | ||
*/ | ||
readonly apiKey: string; | ||
/** | ||
* The auth mode type. In browser environments credentials may | ||
* be passed within the headers. | ||
*/ | ||
readonly authMode?: AuthModeType; | ||
@@ -801,3 +1045,9 @@ }; | ||
export declare type SearchForFacetValuesQueryParams = { | ||
/** | ||
* The facet name. | ||
*/ | ||
readonly facetName: string; | ||
/** | ||
* The facet query. | ||
*/ | ||
readonly facetQuery: string; | ||
@@ -807,4 +1057,13 @@ }; | ||
export declare type SearchForFacetValuesResponse = { | ||
/** | ||
* The list of facet hits. | ||
*/ | ||
readonly facetHits: readonly FacetHit[]; | ||
/** | ||
* The exhaustive facets count. | ||
*/ | ||
readonly exhaustiveFacetsCount: boolean; | ||
/** | ||
* The time that the API toke the process the request. | ||
*/ | ||
readonly processingTimeMS?: number; | ||
@@ -814,4 +1073,13 @@ }; | ||
export declare type SearchIndex = { | ||
/** | ||
* The application id. | ||
*/ | ||
readonly appId: string; | ||
/** | ||
* The index name. | ||
*/ | ||
readonly indexName: string; | ||
/** | ||
* The underlying transporter. | ||
*/ | ||
readonly transporter: Transporter; | ||
@@ -1098,15 +1366,9 @@ }; | ||
readonly exhaustiveFacetsCount?: boolean; | ||
readonly facets?: { | ||
readonly [key: string]: { | ||
readonly [key: string]: number; | ||
}; | ||
}; | ||
readonly facetsStats?: { | ||
readonly [key: string]: { | ||
readonly min: number; | ||
readonly max: number; | ||
readonly avg: number; | ||
readonly sum: number; | ||
}; | ||
}; | ||
readonly facets?: Readonly<Record<string, Readonly<Record<string, number>>>>; | ||
readonly facetsStats?: Readonly<Record<string, { | ||
readonly min: number; | ||
readonly max: number; | ||
readonly avg: number; | ||
readonly sum: number; | ||
}>>; | ||
readonly query: string; | ||
@@ -1125,5 +1387,3 @@ readonly queryAfterRemoval?: string; | ||
readonly userData?: any; | ||
readonly appliedRules?: ReadonlyArray<{ | ||
readonly [key: string]: any; | ||
}>; | ||
readonly appliedRules?: ReadonlyArray<Readonly<Record<string, any>>>; | ||
}; | ||
@@ -1134,11 +1394,21 @@ | ||
export declare type SearchRulesOptions = { | ||
/** Full text query. */ | ||
/** | ||
* Full text query. | ||
*/ | ||
readonly query?: string; | ||
/** When specified, restricts matches to rules with a specific anchoring type. When omitted, all anchoring types may match. */ | ||
/** | ||
* When specified, restricts matches to rules with a specific anchoring type. When omitted, all anchoring types may match. | ||
*/ | ||
readonly anchoring?: string; | ||
/** Restricts matches to contextual rules with a specific context (exact match). */ | ||
/** | ||
* Restricts matches to contextual rules with a specific context (exact match). | ||
*/ | ||
readonly context?: string; | ||
/** Requested page (zero-based). */ | ||
/** | ||
* Requested page (zero-based). | ||
*/ | ||
readonly page?: number; | ||
/** Maximum number of hits in a page. Minimum is 1, maximum is 1000. */ | ||
/** | ||
* Maximum number of hits in a page. Minimum is 1, maximum is 1000. | ||
*/ | ||
readonly hitsPerPage?: number; | ||
@@ -1158,3 +1428,3 @@ /** | ||
*/ | ||
readonly type?: SynonymType | readonly SynonymType[]; | ||
readonly type?: string; | ||
/** | ||
@@ -1171,3 +1441,9 @@ * Page to retrieve. | ||
export declare type SearchSynonymsResponse = { | ||
/** | ||
* The list of synonyms. | ||
*/ | ||
readonly hits: readonly Synonym[]; | ||
/** | ||
* The number of synonyms on the list. | ||
*/ | ||
readonly nbHits: number; | ||
@@ -1238,2 +1514,5 @@ }; | ||
export declare type SetSettingsOptions = { | ||
/** | ||
* If the saved settings should be forward to replicas. | ||
*/ | ||
readonly forwardToReplicas?: boolean; | ||
@@ -1243,4 +1522,10 @@ }; | ||
export declare type SetSettingsResponse = { | ||
/** | ||
* The operation task id. May be used to perform a wait task. | ||
*/ | ||
readonly taskID: number; | ||
readonly UpdatedAt: number; | ||
/** | ||
* When the settings got updated. | ||
*/ | ||
readonly updatedAt: number; | ||
}; | ||
@@ -1458,5 +1743,3 @@ | ||
*/ | ||
readonly decompoundedAttributes?: { | ||
readonly [key: string]: readonly string[]; | ||
}; | ||
readonly decompoundedAttributes?: Readonly<Record<string, readonly string[]>>; | ||
/** | ||
@@ -1469,7 +1752,3 @@ * Characters that should not be automatically normalized by the search engine. | ||
*/ | ||
readonly customNormalization?: { | ||
readonly [key: string]: { | ||
readonly [key: string]: string; | ||
}; | ||
}; | ||
readonly customNormalization?: Readonly<Record<string, Readonly<Record<string, string>>>>; | ||
/** | ||
@@ -1481,5 +1760,3 @@ * Custom userData that could be added to the Settings. | ||
export declare const StrategyEnum: { | ||
readonly [key: string]: StrategyType; | ||
}; | ||
export declare const StrategyEnum: Readonly<Record<string, StrategyType>>; | ||
@@ -1523,5 +1800,3 @@ export declare type StrategyType = 'none' | 'stopIfEnoughMatches'; | ||
export declare const SynonymEnum: { | ||
readonly [key: string]: SynonymType; | ||
}; | ||
export declare const SynonymEnum: Readonly<Record<string, SynonymType>>; | ||
@@ -1531,3 +1806,10 @@ export declare type SynonymType = 'synonym' | 'oneWaySynonym' | 'altCorrection1' | 'altCorrection2' | 'placeholder'; | ||
export declare type TaskStatusResponse = { | ||
/** | ||
* The operation status. When the value is `published` the | ||
* operation is completed. | ||
*/ | ||
readonly status: string; | ||
/** | ||
* If the operation is pending. | ||
*/ | ||
readonly pendingTask: boolean; | ||
@@ -1534,0 +1816,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { shuffle, createAuth, AuthMode, addMethods, createWaitablePromise, createRetryablePromise, encode } from '@algolia/client-common'; | ||
import { createAuth, AuthMode, shuffle, addMethods, createWaitablePromise, createRetryablePromise, encode } from '@algolia/client-common'; | ||
import { createTransporter, CallEnum, createMappedRequestOptions, serializeQueryParameters } from '@algolia/transporter'; | ||
@@ -28,17 +28,23 @@ import { MethodEnum } from '@algolia/requester-common'; | ||
const appId = options.appId; | ||
const transporter = createTransporter(options); | ||
transporter.setHosts([ | ||
{ url: `${appId}-dsn.algolia.net`, accept: CallEnum.Read }, | ||
{ url: `${appId}.algolia.net`, accept: CallEnum.Write }, | ||
].concat(shuffle([ | ||
{ url: `${appId}-1.algolianet.com`, accept: CallEnum.Any }, | ||
{ url: `${appId}-2.algolianet.com`, accept: CallEnum.Any }, | ||
{ url: `${appId}-3.algolianet.com`, accept: CallEnum.Any }, | ||
]))); | ||
const auth = createAuth(options.authMode !== undefined ? options.authMode : AuthMode.WithinHeaders, appId, options.apiKey); | ||
transporter.addHeaders({ | ||
...auth.headers(), | ||
...{ 'content-type': 'application/x-www-form-urlencoded' }, | ||
const transporter = createTransporter({ | ||
hosts: [ | ||
{ url: `${appId}-dsn.algolia.net`, accept: CallEnum.Read }, | ||
{ url: `${appId}.algolia.net`, accept: CallEnum.Write }, | ||
].concat(shuffle([ | ||
{ url: `${appId}-1.algolianet.com`, accept: CallEnum.Any }, | ||
{ url: `${appId}-2.algolianet.com`, accept: CallEnum.Any }, | ||
{ url: `${appId}-3.algolianet.com`, accept: CallEnum.Any }, | ||
])), | ||
...options, | ||
headers: { | ||
...auth.headers(), | ||
...{ 'content-type': 'application/x-www-form-urlencoded' }, | ||
...options.headers, | ||
}, | ||
queryParameters: { | ||
...auth.queryParameters(), | ||
...options.queryParameters, | ||
}, | ||
}); | ||
transporter.addQueryParameters(auth.queryParameters()); | ||
const base = { | ||
@@ -61,4 +67,3 @@ transporter, | ||
"automatically but *it's not recommended*. " + | ||
'To do it, use `saveObjects(objects, ' + | ||
"{'autoGenerateObjectIDIfNotExist': true})`.", | ||
"To do it, use the `{'autoGenerateObjectIDIfNotExist': true}` option.", | ||
}; | ||
@@ -91,3 +96,3 @@ } | ||
return getApiKey(base)(response.key, waitRequestOptions).catch((apiError) => { | ||
if (apiError.status === 404) { | ||
if (apiError.status !== 404) { | ||
throw apiError; | ||
@@ -153,6 +158,15 @@ } | ||
const copyRules = (base) => { | ||
return (from, to, requestOptions) => { | ||
return copyIndex(base)(from, to, { | ||
...requestOptions, | ||
scope: [ScopeEnum.Rules], | ||
}); | ||
}; | ||
}; | ||
const copySettings = (base) => { | ||
return (from, to, requestOptions) => { | ||
return copyIndex(base)(from, to, { | ||
...(requestOptions === undefined ? {} : requestOptions), | ||
...requestOptions, | ||
scope: [ScopeEnum.Settings], | ||
@@ -166,3 +180,3 @@ }); | ||
return copyIndex(base)(from, to, { | ||
...(requestOptions === undefined ? {} : requestOptions), | ||
...requestOptions, | ||
scope: [ScopeEnum.Synonyms], | ||
@@ -178,2 +192,3 @@ }); | ||
return getApiKey(base)(apiKey, waitRequestOptions) | ||
.then(retry) | ||
.catch((apiError) => { | ||
@@ -183,4 +198,3 @@ if (apiError.status !== 404) { | ||
} | ||
}) | ||
.then(retry); | ||
}); | ||
}); | ||
@@ -216,17 +230,6 @@ }; | ||
return (requestOptions) => { | ||
const { length, offset, type, ...options } = requestOptions || {}; | ||
const mappedRequestOptions = createMappedRequestOptions(options); | ||
if (length) { | ||
mappedRequestOptions.queryParameters.length = length; // eslint-disable-line functional/immutable-data | ||
} | ||
if (offset) { | ||
mappedRequestOptions.queryParameters.offset = offset; // eslint-disable-line functional/immutable-data | ||
} | ||
if (type) { | ||
mappedRequestOptions.queryParameters.type = type; // eslint-disable-line functional/immutable-data | ||
} | ||
return base.transporter.read({ | ||
method: MethodEnum.Get, | ||
path: '1/logs', | ||
}, mappedRequestOptions); | ||
}, requestOptions); | ||
}; | ||
@@ -305,14 +308,6 @@ }; | ||
return (requestOptions) => { | ||
const { page, hitsPerPage, ...options } = requestOptions || {}; | ||
const mappedRequestOptions = createMappedRequestOptions(options); | ||
if (page) { | ||
mappedRequestOptions.queryParameters.page = page; // eslint-disable-line functional/immutable-data | ||
} | ||
if (hitsPerPage) { | ||
mappedRequestOptions.queryParameters.hitsPerPage = hitsPerPage; // eslint-disable-line functional/immutable-data | ||
} | ||
return base.transporter.read({ | ||
method: MethodEnum.Get, | ||
path: '1/clusters/mapping', | ||
}, mappedRequestOptions); | ||
}, requestOptions); | ||
}; | ||
@@ -564,7 +559,9 @@ }; | ||
const chunk = (base) => { | ||
const chunkedBatch = (base) => { | ||
return (bodies, action, requestOptions) => { | ||
const { batchSize, ...options } = requestOptions || {}; | ||
// eslint-disable-next-line functional/prefer-readonly-type | ||
const responses = []; | ||
const response = { | ||
taskIDs: [], | ||
objectIDs: [], | ||
}; | ||
const forEachBatch = (lastIndex = 0) => { | ||
@@ -584,3 +581,3 @@ // eslint-disable-next-line functional/prefer-readonly-type | ||
if (bodiesChunk.length === 0) { | ||
return Promise.resolve(responses); | ||
return Promise.resolve(response); | ||
} | ||
@@ -592,5 +589,5 @@ return batch(base)(bodiesChunk.map(body => { | ||
}; | ||
}), options).then(response => { | ||
// eslint-disable-next-line functional/immutable-data | ||
responses.push(response); | ||
}), options).then(res => { | ||
response.objectIDs = response.objectIDs.concat(res.objectIDs); // eslint-disable-line functional/immutable-data | ||
response.taskIDs.push(res.taskID); // eslint-disable-line functional/immutable-data | ||
index++; | ||
@@ -600,4 +597,6 @@ return forEachBatch(index); | ||
}; | ||
return createWaitablePromise(forEachBatch(), (batchResponses, waitRequestOptions) => { | ||
return Promise.all(batchResponses.map(response => waitTask(base)(response.taskID, waitRequestOptions))); | ||
return createWaitablePromise(forEachBatch(), (chunkedBatchResponse, waitRequestOptions) => { | ||
return Promise.all(chunkedBatchResponse.taskIDs.map(taskID => { | ||
return waitTask(base)(taskID, waitRequestOptions); | ||
})); | ||
}); | ||
@@ -666,3 +665,3 @@ }; | ||
return createWaitablePromise(deleteObjects(base)([objectID], requestOptions).then(response => { | ||
return { taskID: response[0].taskID }; | ||
return { taskID: response.taskIDs[0] }; | ||
}), (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)); | ||
@@ -677,3 +676,3 @@ }; | ||
}); | ||
return chunk(base)(objects, BatchActionEnum.DeleteObject, requestOptions); | ||
return chunkedBatch(base)(objects, BatchActionEnum.DeleteObject, requestOptions); | ||
}; | ||
@@ -755,11 +754,6 @@ }; | ||
return (objectID, requestOptions) => { | ||
const { attributesToRetrieve, ...options } = requestOptions || {}; | ||
const mappedRequestOptions = createMappedRequestOptions(options); | ||
if (attributesToRetrieve) { | ||
mappedRequestOptions.queryParameters.attributesToRetrieve = attributesToRetrieve; // eslint-disable-line functional/immutable-data | ||
} | ||
return base.transporter.read({ | ||
method: MethodEnum.Get, | ||
path: encode('1/indexes/%s/%s', base.indexName, objectID), | ||
}, mappedRequestOptions); | ||
}, requestOptions); | ||
}; | ||
@@ -811,9 +805,9 @@ }; | ||
return (requestOptions) => { | ||
const mappedRequestOptions = createMappedRequestOptions(requestOptions); | ||
// eslint-disable-next-line functional/immutable-data | ||
mappedRequestOptions.queryParameters.getVersion = '2'; | ||
return base.transporter.read({ | ||
method: MethodEnum.Get, | ||
path: encode('1/indexes/%s/settings', base.indexName), | ||
}, mappedRequestOptions); | ||
data: { | ||
getVersion: 2, | ||
}, | ||
}, requestOptions); | ||
}; | ||
@@ -844,4 +838,4 @@ }; | ||
return { | ||
objectID: response[0].objectIDs[0], | ||
taskID: response[0].taskID, | ||
objectID: response.objectIDs[0], | ||
taskID: response.taskIDs[0], | ||
}; | ||
@@ -858,3 +852,3 @@ }), (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)); | ||
: BatchActionEnum.PartialUpdateObjectNoCreate; | ||
return chunk(base)(objects, action, options); | ||
return chunkedBatch(base)(objects, action, options); | ||
}; | ||
@@ -865,4 +859,4 @@ }; | ||
return (objects, requestOptions) => { | ||
const { safe, ...options } = requestOptions || {}; | ||
const operation = (from, to, type, operatioRequestOptions) => { | ||
const { safe, autoGenerateObjectIDIfNotExist, batchSize, ...options } = requestOptions || {}; | ||
const operation = (from, to, type, operationRequestOptions) => { | ||
return createWaitablePromise(base.transporter.write({ | ||
@@ -875,3 +869,3 @@ method: MethodEnum.Post, | ||
}, | ||
}, operatioRequestOptions), (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)); | ||
}, operationRequestOptions), (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)); | ||
}; | ||
@@ -887,2 +881,3 @@ const randomSuffix = Math.random() | ||
}); | ||
// @ts-ignore | ||
// eslint-disable-next-line prefer-const, functional/no-let, functional/prefer-readonly-type | ||
@@ -896,5 +891,11 @@ let responses = []; | ||
responses.push(copyWaitablePromise); | ||
const result = (safe ? copyWaitablePromise.wait(options) : copyWaitablePromise) | ||
const result = (safe | ||
? copyWaitablePromise.wait(options) | ||
: copyWaitablePromise) | ||
.then(() => { | ||
const saveObjectsWaitablePromise = saveObjectsInTemporary(objects, options); | ||
const saveObjectsWaitablePromise = saveObjectsInTemporary(objects, { | ||
...options, | ||
autoGenerateObjectIDIfNotExist, | ||
batchSize, | ||
}); | ||
// eslint-disable-next-line functional/immutable-data | ||
@@ -910,3 +911,9 @@ responses.push(saveObjectsWaitablePromise); | ||
}) | ||
.then(() => Promise.resolve()); | ||
.then(() => Promise.all(responses)) | ||
.then(([copyResponse, saveObjectsResponse, moveResponse]) => { | ||
return { | ||
objectIDs: saveObjectsResponse.objectIDs, | ||
taskIDs: [copyResponse.taskID, ...saveObjectsResponse.taskIDs, moveResponse.taskID], | ||
}; | ||
}); | ||
return createWaitablePromise(result, (_, waitRequestOptions) => { | ||
@@ -930,3 +937,3 @@ return Promise.all(responses.map(response => response.wait(waitRequestOptions))); | ||
return saveSynonyms(base)(synonyms, { | ||
...(requestOptions === undefined ? {} : requestOptions), | ||
...requestOptions, | ||
replaceExistingSynonyms: true, | ||
@@ -941,4 +948,4 @@ }); | ||
return { | ||
objectID: response[0].objectIDs[0], | ||
taskID: response[0].taskID, | ||
objectID: response.objectIDs[0], | ||
taskID: response.taskIDs[0], | ||
}; | ||
@@ -963,3 +970,3 @@ }), (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)); | ||
} | ||
return chunk(base)(objects, action, options); | ||
return chunkedBatch(base)(objects, action, options); | ||
}; | ||
@@ -1118,2 +1125,2 @@ }; | ||
export { BatchActionEnum, ScopeEnum, StrategyEnum, SynonymEnum, addApiKey, assignUserID, assignUserIDs, batch, browseObjects, browseRules, browseSynonyms, chunk, clearObjects, clearRules, clearSynonyms, copyIndex, copySettings, copySynonyms, createBrowsablePromise, createMissingObjectIDError, createObjectNotFoundError, createSearchClient, createValidUntilNotFoundError, deleteApiKey, deleteBy, deleteIndex, deleteObject, deleteObjects, deleteRule, deleteSynonym, exists, findObject, generateSecuredApiKey, getApiKey, getLogs, getObject, getObjectPosition, getObjects, getRule, getSecuredApiKeyRemainingValidity, getSettings, getSynonym, getTask, getTopUserIDs, getUserID, initIndex, listApiKeys, listClusters, listIndices, listUserIDs, moveIndex, multipleBatch, multipleGetObjects, multipleQueries, multipleSearchForFacetValues, partialUpdateObject, partialUpdateObjects, removeUserID, replaceAllObjects, replaceAllRules, replaceAllSynonyms, restoreApiKey, saveObject, saveObjects, saveRule, saveRules, saveSynonym, saveSynonyms, search, searchForFacetValues, searchRules, searchSynonyms, searchUserIDs, setSettings, updateApiKey, waitTask }; | ||
export { BatchActionEnum, ScopeEnum, StrategyEnum, SynonymEnum, addApiKey, assignUserID, assignUserIDs, batch, browseObjects, browseRules, browseSynonyms, chunkedBatch, clearObjects, clearRules, clearSynonyms, copyIndex, copyRules, copySettings, copySynonyms, createBrowsablePromise, createMissingObjectIDError, createObjectNotFoundError, createSearchClient, createValidUntilNotFoundError, deleteApiKey, deleteBy, deleteIndex, deleteObject, deleteObjects, deleteRule, deleteSynonym, exists, findObject, generateSecuredApiKey, getApiKey, getLogs, getObject, getObjectPosition, getObjects, getRule, getSecuredApiKeyRemainingValidity, getSettings, getSynonym, getTask, getTopUserIDs, getUserID, initIndex, listApiKeys, listClusters, listIndices, listUserIDs, moveIndex, multipleBatch, multipleGetObjects, multipleQueries, multipleSearchForFacetValues, partialUpdateObject, partialUpdateObjects, removeUserID, replaceAllObjects, replaceAllRules, replaceAllSynonyms, restoreApiKey, saveObject, saveObjects, saveRule, saveRules, saveSynonym, saveSynonyms, search, searchForFacetValues, searchRules, searchSynonyms, searchUserIDs, setSettings, updateApiKey, waitTask }; |
{ | ||
"name": "@algolia/client-search", | ||
"version": "4.0.0-beta.11", | ||
"version": "4.0.0-beta.12", | ||
"private": false, | ||
@@ -15,7 +15,7 @@ "license": "MIT", | ||
"dependencies": { | ||
"@algolia/client-common": "4.0.0-beta.11", | ||
"@algolia/logger-common": "4.0.0-beta.11", | ||
"@algolia/requester-common": "4.0.0-beta.11", | ||
"@algolia/transporter": "4.0.0-beta.11" | ||
"@algolia/client-common": "4.0.0-beta.12", | ||
"@algolia/logger-common": "4.0.0-beta.12", | ||
"@algolia/requester-common": "4.0.0-beta.12", | ||
"@algolia/transporter": "4.0.0-beta.12" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
148143
3764
+ Added@algolia/cache-common@4.0.0-beta.12(transitive)
+ Added@algolia/client-common@4.0.0-beta.12(transitive)
+ Added@algolia/logger-common@4.0.0-beta.12(transitive)
+ Added@algolia/requester-common@4.0.0-beta.12(transitive)
+ Added@algolia/transporter@4.0.0-beta.12(transitive)
- Removed@algolia/cache-common@4.0.0-beta.11(transitive)
- Removed@algolia/client-common@4.0.0-beta.11(transitive)
- Removed@algolia/logger-common@4.0.0-beta.11(transitive)
- Removed@algolia/requester-common@4.0.0-beta.11(transitive)
- Removed@algolia/transporter@4.0.0-beta.11(transitive)