import { TProtocol } from './protocols' ; import { TTransport } from './transports' ; export * from './Int64' ; export type LogFunction = ( tags : Array < string > , data ? : string | object ) => void ; export interface IRequestHeaders { [ name ] : any ; } export interface ITraceId { readonly spanId : string ; readonly parentId : string ; readonly traceId : string ; readonly sampled ? : boolean ; readonly traceIdHigh ? : boolean ; } export interface IRequestContext { headers : IRequestHeaders ; traceId ? : ITraceId ; logger ? : LogFunction ; } /**
 * Options for any Thrift Server
 *
 * serviceName<string> - name of the service
 * handler<TProcessor> - a service processor instance for handling requests
 * transport<TransportType> - name of the transport to use
 * protocol<ProtocolType> - name of the protocol to use
 */ export interface IThriftServerOptions < Context , TProcessor extends IThriftProcessor < Context > > { serviceName : string ; handler : TProcessor ; transport ? : TransportType ; protocol ? : ProtocolType ; logger ? : LogFunction ; withEndpointPerMethod ? : boolean ; } export interface IThriftConnection < Context = void > { Transport : ITransportConstructor ; Protocol : IProtocolConstructor ; send ( dataToSend , context ? ) : Promise < Buffer > ; } export abstract class ThriftConnection < Context = void > implements IThriftConnection < Context > { constructor ( public Transport , public Protocol ) { } public abstract send ( dataToSend , context ? ) ; } export interface IThriftAnnotations { [ name ] : string ; } export interface IFieldAnnotations { [ fieldName ] : IThriftAnnotations ; } export interface IMethodAnnotations { [ methodName ] : { annotations : IThriftAnnotations ; fieldAnnotations : IFieldAnnotations ; } ; } export interface IStructLike { readonly _annotations : IThriftAnnotations ; readonly _fieldAnnotations : IFieldAnnotations ; write ( output ) : void ; } export abstract class StructLike implements IStructLike { public readonly _annotations : IThriftAnnotations = { } ; public readonly _fieldAnnotations : IFieldAnnotations = { } ; public abstract write ( output ) ; } export interface IStructConstructor < T extends StructLike > { new ( args ? ) : T ; read ( input ) : T ; write ( data , output ) : void ; } export type ThriftReadCodec < ThriftType > = IStructCodec < any , ThriftType > ; export type ThriftWriteCodec < ThriftType > = IStructCodec < ThriftType , any > ; export interface IStructCodec < LooseType , StrictType > { encode ( obj , output ) : void ; decode ( input ) : StrictType ; } export interface IStructToolkit < LooseType , StrictType > extends IStructCodec < LooseType , StrictType > { create ( args ) : StrictType ; } export type IProtocolConstructor = new ( trans , logger ? ) => TProtocol ; export interface ITransportConstructor { new ( buffer ? ) : TTransport ; receiver ( data ) : TTransport ; } export interface IThriftClient { readonly _serviceName : string ; readonly _annotations : IThriftAnnotations ; readonly _methodAnnotations : IMethodAnnotations ; readonly _methodNames : Array < string > ; } export abstract class ThriftClient < Context = any > implements IThriftClient { public static readonly serviceName ? : string = undefined ; public static readonly annotations ? : IThriftAnnotations = { } ; public static readonly methodAnnotations ? : IMethodAnnotations = { } ; public static readonly methodNames ? : Array < string > = [ ] ; public readonly _serviceName : string = '' ; public readonly _annotations : IThriftAnnotations = { } ; public readonly _methodAnnotations : IMethodAnnotations = { } ; public readonly _methodNames : Array < string > = [ ] ; protected _requestId : number ; protected transport : ITransportConstructor ; protected protocol : IProtocolConstructor ; protected connection : IThriftConnection < Context > ; constructor ( connection ) { this . _requestId = 0 ; this . transport = connection . Transport ; this . protocol = connection . Protocol ; this . connection = connection ; } protected incrementRequestId ( ) { return ( this . _requestId += 1 ) ; } } export interface IClientConstructor < TClient extends ThriftClient < Context > , Context > { readonly serviceName ? : string ; readonly annotations ? : IThriftAnnotations ; readonly methodAnnotations ? : IMethodAnnotations ; readonly methodNames ? : Array < string > ; new ( connection ) : TClient ; } export interface IThriftProcessor < Context > { readonly _serviceName : string ; readonly _annotations : IThriftAnnotations ; readonly _methodAnnotations : IMethodAnnotations ; readonly _methodNames : Array < string > ; process ( input , output , context ? ) : Promise < Buffer > ; } export abstract class ThriftProcessor < Context , IHandler > implements IThriftProcessor < Context > { public static readonly serviceName ? : string = undefined ; public static readonly annotations ? : IThriftAnnotations = { } ; public static readonly methodAnnotations ? : IMethodAnnotations = { } ; public static readonly methodNames ? : Array < string > = [ ] ; public readonly _serviceName : string = '' ; public readonly _annotations : IThriftAnnotations = { } ; public readonly _methodAnnotations : IMethodAnnotations = { } ; public readonly _methodNames : Array < string > = [ ] ; public abstract process ( input , output , context ? ) ; } export interface IProcessorConstructor < TProcessor , THandler > { readonly serviceName : string ; readonly annotations : IThriftAnnotations ; readonly methodAnnotations : IMethodAnnotations ; readonly methodNames : Array < string > ; new ( handler ) : TProcessor ; } export type ProtocolType = 'binary' | 'compact' | 'json' ; export type TransportType = 'buffered' ; export interface ITransportMap { [ name ] : ITransportConstructor ; } export interface IProtocolMap { [ name ] : IProtocolConstructor ; } export enum TType { STOP = 0 , VOID = 1 , BOOL = 2 , BYTE = 3 , I08 = 3 , DOUBLE = 4 , I16 = 6 , I32 = 8 , I64 = 10 , STRING = 11 , UTF7 = 11 , STRUCT = 12 , MAP = 13 , SET = 14 , LIST = 15 , ENUM = 16 , UTF8 = 16 , UTF16 = 17 } export interface IThriftMap { keyType : TType ; valueType : TType ; size : number ; } export interface IThriftMessage { fieldName : string ; messageType : MessageType ; requestId : number ; } export interface IThriftField { fieldName : string ; fieldType : TType ; fieldId : number ; } export interface IThriftList { elementType : TType ; size : number ; } export interface IThriftSet { elementType : TType ; size : number ; } export interface IThriftStruct { fieldName : string ; } export enum MessageType { CALL = 1 , REPLY = 2 , EXCEPTION = 3 , ONEWAY = 4 }