@opra/elastic
Version:
Opra Elastic Search adapter package
69 lines (68 loc) • 2.23 kB
TypeScript
import { Client } from '@elastic/elasticsearch';
import { ServiceBase } from '@opra/core';
/**
* The namespace for the ElasticService.
*
* @namespace ElasticService
*/
export declare namespace ElasticService {
interface Options {
client?: ElasticService['client'];
interceptor?: ElasticService['interceptor'];
onError?: ElasticService['onError'];
}
type CrudOp = 'create' | 'read' | 'update' | 'delete';
interface CommandInfo {
crud: CrudOp;
method: string;
byId: boolean;
documentId?: any;
input?: any;
options?: any;
}
}
export interface ElasticService {
/**
* Interceptor function for handling callback execution with provided arguments.
* @type Function
* @param next - The callback function to be intercepted.
* @param {ElasticService.CommandInfo} command - The arguments object containing the following properties:
* @param _this - The reference to the current object.
* @returns - The promise that resolves to the result of the callback execution.
*/
interceptor?(next: () => any, command: ElasticService.CommandInfo, _this: any): Promise<any>;
}
/**
* Class representing a ElasticSearch service for interacting with a collection.
* @extends ServiceBase
* @template T - The type of the documents in the collection.
*/
export declare class ElasticService extends ServiceBase {
/**
* Represents a ElasticDB database object.
*/
client?: Client | ((_this: any) => Client);
/**
* Callback function for handling errors.
*
* @param {unknown} error - The error object.
* @param _this - The context object.
*/
onError?: (error: unknown, _this: any) => void | Promise<void>;
/**
* Constructs a new instance
*
* @param [options] - The options for the service
* @constructor
*/
constructor(options?: ElasticService.Options);
/**
* Retrieves the ElasticSearch client.
*
* @protected
*
* @throws {Error} If the context or client is not set.
*/
getClient(): Client;
protected _executeCommand(command: ElasticService.CommandInfo, commandFn: () => any): Promise<any>;
}