/** @module services */
import { IOpenable } from 'pip-services3-commons-nodex';
import { IConfigurable } from 'pip-services3-commons-nodex';
import { IReferenceable } from 'pip-services3-commons-nodex';
import { IReferences } from 'pip-services3-commons-nodex';
import { ConfigParams } from 'pip-services3-commons-nodex';
import { DependencyResolver } from 'pip-services3-commons-nodex';
import { CompositeLogger } from 'pip-services3-components-nodex';
import { CompositeCounters } from 'pip-services3-components-nodex';
import { CompositeTracer } from 'pip-services3-components-nodex';
import { InstrumentTiming } from 'pip-services3-rpc-nodex';
import { Schema } from 'pip-services3-commons-nodex';
import { LambdaAction } from './LambdaAction';
import { ILambdaService } from './ILambdaService';
/**
* Abstract service that receives remove calls via AWS Lambda protocol.
*
* This service is intended to work inside LambdaFunction container that
* exploses registered actions externally.
*
* ### Configuration parameters ###
*
* - dependencies:
* - controller: override for Controller dependency
*
* ### References ###
*
* - \*:logger:\*:\*:1.0 (optional) [[https://pip-services3-nodex.github.io/pip-services3-components-nodex/interfaces/log.ilogger.html ILogger]] components to pass log messages
* - \*:counters:\*:\*:1.0 (optional) [[https://pip-services3-nodex.github.io/pip-services3-components-nodex/interfaces/count.icounters.html ICounters]] components to pass collected measurements
*
* @see [[LambdaClient]]
*
* ### Example ###
*
* class MyLambdaService extends LambdaService {
* private _controller: IMyController;
* ...
* public constructor() {
* base('v1.myservice');
* this._dependencyResolver.put(
* "controller",
* new Descriptor("mygroup","controller","*","*","1.0")
* );
* }
*
* public setReferences(references: IReferences): void {
* base.setReferences(references);
* this._controller = this._dependencyResolver.getRequired("controller");
* }
*
* public register(): void {
* registerAction("get_mydata", null, async (params) => {
* let correlationId = params.correlation_id;
* let id = params.id;
* return await this._controller.getMyData(correlationId, id);
* });
* ...
* }
* }
*
* let service = new MyLambdaService();
* service.configure(ConfigParams.fromTuples(
* "connection.protocol", "http",
* "connection.host", "localhost",
* "connection.port", 8080
* ));
* service.setReferences(References.fromTuples(
* new Descriptor("mygroup","controller","default","default","1.0"), controller
* ));
*
* service.open("123");
* console.log("The GRPC service is running on port 8080");
*/
export declare abstract class LambdaService implements ILambdaService, IOpenable, IConfigurable, IReferenceable {
protected _name: string;
private _actions;
private _interceptors;
private _opened;
/**
* The dependency resolver.
*/
protected _dependencyResolver: DependencyResolver;
/**
* The logger.
*/
protected _logger: CompositeLogger;
/**
* The performance counters.
*/
protected _counters: CompositeCounters;
/**
* The tracer.
*/
protected _tracer: CompositeTracer;
/**
* Creates an instance of this service.
* @param name a service name to generate action cmd.
*/
constructor(name?: string);
/**
* Configures component by passing configuration parameters.
*
* @param config configuration parameters to be set.
*/
configure(config: ConfigParams): void;
/**
* Sets references to dependent components.
*
* @param references references to locate the component dependencies.
*/
setReferences(references: IReferences): void;
/**
* Get all actions supported by the service.
* @returns an array with supported actions.
*/
getActions(): LambdaAction[];
/**
* Adds instrumentation to log calls and measure call time.
* It returns a Timing object that is used to end the time measurement.
*
* @param correlationId (optional) transaction id to trace execution through call chain.
* @param name a method name.
* @returns Timing object to end the time measurement.
*/
protected instrument(correlationId: string, name: string): InstrumentTiming;
/**
* Checks if the component is opened.
*
* @returns true if the component has been opened and false otherwise.
*/
isOpen(): boolean;
/**
* Opens the component.
*
* @param correlationId (optional) transaction id to trace execution through call chain.
*/
open(correlationId: string): Promise;
/**
* Closes component and frees used resources.
*
* @param correlationId (optional) transaction id to trace execution through call chain.
*/
close(correlationId: string): Promise;
protected applyValidation(schema: Schema, action: (params: any) => Promise): (params: any) => Promise;
protected applyInterceptors(action: (params: any) => Promise): (params: any) => Promise;
protected generateActionCmd(name: string): string;
/**
* Registers a action in AWS Lambda function.
*
* @param name an action name
* @param schema a validation schema to validate received parameters.
* @param action an action function that is called when operation is invoked.
*/
protected registerAction(name: string, schema: Schema, action: (params: any) => Promise): void;
/**
* Registers an action with authorization.
*
* @param name an action name
* @param schema a validation schema to validate received parameters.
* @param authorize an authorization interceptor
* @param action an action function that is called when operation is invoked.
*/
protected registerActionWithAuth(name: string, schema: Schema, authorize: (call: any, next: (call: any) => Promise) => Promise, action: (call: any) => Promise): void;
/**
* Registers a middleware for actions in AWS Lambda service.
*
* @param action an action function that is called when middleware is invoked.
*/
protected registerInterceptor(action: (params: any, next: (params: any) => Promise) => Promise): void;
/**
* Registers all service routes in HTTP endpoint.
*
* This method is called by the service and must be overriden
* in child classes.
*/
protected abstract register(): void;
/**
* Calls registered action in this lambda function.
* "cmd" parameter in the action parameters determin
* what action shall be called.
*
* This method shall only be used in testing.
*
* @param params action parameters.
*/
act(params: any): Promise;
}