How to use the @algolia/client-common.createWaitablePromise function in @algolia/client-common

To help you get started, we’ve selected a few @algolia/client-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github algolia / algoliasearch-client-javascript / packages / client-search / src / methods / index / clearSynonyms.ts View on Github external
return (
    requestOptions?: ClearSynonymsOptions & RequestOptions
  ): Readonly> => {
    const { forwardToReplicas, ...options } = requestOptions || {};

    const mappedRequestOptions = createMappedRequestOptions(options);
    if (forwardToReplicas) {
      mappedRequestOptions.queryParameters.forwardToReplicas = 1; // eslint-disable-line functional/immutable-data
    }

    return createWaitablePromise(
      base.transporter.write(
        {
          method: MethodEnum.Post,
          path: encode('1/indexes/%s/synonyms/clear', base.indexName),
        },
        mappedRequestOptions
      ),
      (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)
    );
  };
};
github algolia / algoliasearch-client-javascript / packages / client-search / src / methods / index / saveObjects.ts View on Github external
return (
    objects: ReadonlyArray<{ readonly [key: string]: any }>,
    requestOptions?: RequestOptions & ChunkOptions & SaveObjectsOptions
  ): Readonly> => {
    const { autoGenerateObjectIDIfNotExist, ...options } = requestOptions || {};

    const action = autoGenerateObjectIDIfNotExist
      ? BatchActionEnum.AddObject
      : BatchActionEnum.UpdateObject;

    if (action === BatchActionEnum.UpdateObject) {
      // eslint-disable-next-line functional/no-loop-statement
      for (const object of objects) {
        if (object.objectID === undefined) {
          return createWaitablePromise(Promise.reject(createMissingObjectIDError()));
        }
      }
    }

    return chunk(base)(objects, action, options);
  };
};
github algolia / algoliasearch-client-javascript / packages / client-search / src / methods / index / deleteRule.ts View on Github external
return (
    objectID: string,
    requestOptions?: RequestOptions
  ): Readonly> => {
    const { forwardToReplicas, ...options } = requestOptions || {};

    const mappedRequestOptions = createMappedRequestOptions(options);
    if (forwardToReplicas) {
      mappedRequestOptions.queryParameters.forwardToReplicas = 1; // eslint-disable-line functional/immutable-data
    }

    return createWaitablePromise(
      base.transporter.write(
        {
          method: MethodEnum.Delete,
          path: encode('1/indexes/%s/rules/%s', base.indexName, objectID),
        },
        mappedRequestOptions
      ),
      (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)
    );
  };
};
github algolia / algoliasearch-client-javascript / packages / client-search / src / methods / index / replaceAllObjects.ts View on Github external
const operation = (
      from: string,
      to: string,
      type: string,
      operatioRequestOptions?: RequestOptions
    ): Readonly> => {
      return createWaitablePromise(
        base.transporter.write(
          {
            method: MethodEnum.Post,
            path: encode('1/indexes/%s/operation', from),
            data: {
              operation: type,
              destination: to,
            },
          },
          operatioRequestOptions
        ),
        (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)
      );
    };
github algolia / algoliasearch-client-javascript / packages / client-search / src / methods / index / partialUpdateObject.ts View on Github external
return (
    object: object,
    requestOptions?: RequestOptions & ChunkOptions & PartialUpdateObjectsOptions
  ): Readonly> => {
    return createWaitablePromise(
      partialUpdateObjects(base)([object], requestOptions).then(response => {
        return {
          objectID: response[0].objectIDs[0],
          taskID: response[0].taskID,
        };
      }),
      (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)
    );
  };
};
github algolia / algoliasearch-client-javascript / packages / client-search / src / methods / index / deleteBy.ts View on Github external
return (
    filters: DeleteByFiltersOptions,
    requestOptions?: RequestOptions
  ): Readonly> => {
    return createWaitablePromise(
      base.transporter.write(
        {
          method: MethodEnum.Post,
          path: encode('1/indexes/%s/deleteByQuery', base.indexName),
          data: filters,
        },
        requestOptions
      ),
      (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)
    );
  };
};
github algolia / algoliasearch-client-javascript / packages / client-search / src / methods / client / restoreApiKey.ts View on Github external
apiKey: string,
    requestOptions?: RequestOptions
  ): Readonly> => {
    const wait: Wait = (_, waitRequestOptions) => {
      return createRetryablePromise(retry => {
        return getApiKey(base)(apiKey, waitRequestOptions).catch((apiError: ApiError) => {
          if (apiError.status !== 404) {
            throw apiError;
          }

          return retry();
        });
      });
    };

    return createWaitablePromise(
      base.transporter.write(
        {
          method: MethodEnum.Post,
          path: encode('1/keys/%s/restore', apiKey),
        },
        requestOptions
      ),
      wait
    );
  };
};
github algolia / algoliasearch-client-javascript / packages / client-search / src / methods / index / deleteIndex.ts View on Github external
return (requestOptions?: RequestOptions): Readonly> => {
    return createWaitablePromise(
      base.transporter.write(
        {
          method: MethodEnum.Delete,
          path: encode('1/indexes/%s', base.indexName),
        },
        requestOptions
      ),
      (response, waitRequestOptions) => waitTask(base)(response.taskID, waitRequestOptions)
    );
  };
};

@algolia/client-common

Common package for the Algolia JavaScript API client.

MIT
Latest version published 4 days ago

Package Health Score

85 / 100
Full package analysis

Similar packages