UNPKG

4.37 kBTypeScriptView Raw
1import { Metadata } from './metadata';
2import { Listener, MetadataListener, MessageListener, StatusListener, InterceptingListener, MessageContext } from './call-stream';
3import { Status } from './constants';
4import { Channel } from './channel';
5import { CallOptions } from './client';
6import { CallCredentials } from './call-credentials';
7import { ClientMethodDefinition } from './make-client';
8/**
9 * Error class associated with passing both interceptors and interceptor
10 * providers to a client constructor or as call options.
11 */
12export declare class InterceptorConfigurationError extends Error {
13 constructor(message: string);
14}
15export interface MetadataRequester {
16 (metadata: Metadata, listener: InterceptingListener, next: (metadata: Metadata, listener: InterceptingListener | Listener) => void): void;
17}
18export interface MessageRequester {
19 (message: any, next: (message: any) => void): void;
20}
21export interface CloseRequester {
22 (next: () => void): void;
23}
24export interface CancelRequester {
25 (next: () => void): void;
26}
27/**
28 * An object with methods for intercepting and modifying outgoing call operations.
29 */
30export interface FullRequester {
31 start: MetadataRequester;
32 sendMessage: MessageRequester;
33 halfClose: CloseRequester;
34 cancel: CancelRequester;
35}
36export declare type Requester = Partial<FullRequester>;
37export declare class ListenerBuilder {
38 private metadata;
39 private message;
40 private status;
41 withOnReceiveMetadata(onReceiveMetadata: MetadataListener): this;
42 withOnReceiveMessage(onReceiveMessage: MessageListener): this;
43 withOnReceiveStatus(onReceiveStatus: StatusListener): this;
44 build(): Listener;
45}
46export declare class RequesterBuilder {
47 private start;
48 private message;
49 private halfClose;
50 private cancel;
51 withStart(start: MetadataRequester): this;
52 withSendMessage(sendMessage: MessageRequester): this;
53 withHalfClose(halfClose: CloseRequester): this;
54 withCancel(cancel: CancelRequester): this;
55 build(): Requester;
56}
57export interface InterceptorOptions extends CallOptions {
58 method_definition: ClientMethodDefinition<any, any>;
59}
60export interface InterceptingCallInterface {
61 cancelWithStatus(status: Status, details: string): void;
62 getPeer(): string;
63 start(metadata: Metadata, listener?: Partial<InterceptingListener>): void;
64 sendMessageWithContext(context: MessageContext, message: any): void;
65 sendMessage(message: any): void;
66 startRead(): void;
67 halfClose(): void;
68 setCredentials(credentials: CallCredentials): void;
69}
70export declare class InterceptingCall implements InterceptingCallInterface {
71 private nextCall;
72 /**
73 * The requester that this InterceptingCall uses to modify outgoing operations
74 */
75 private requester;
76 /**
77 * Indicates that a message has been passed to the listener's onReceiveMessage
78 * method it has not been passed to the corresponding next callback
79 */
80 private processingMessage;
81 /**
82 * Indicates that a status was received but could not be propagated because
83 * a message was still being processed.
84 */
85 private pendingHalfClose;
86 constructor(nextCall: InterceptingCallInterface, requester?: Requester);
87 cancelWithStatus(status: Status, details: string): void;
88 getPeer(): string;
89 start(metadata: Metadata, interceptingListener?: Partial<InterceptingListener>): void;
90 sendMessageWithContext(context: MessageContext, message: any): void;
91 sendMessage(message: any): void;
92 startRead(): void;
93 halfClose(): void;
94 setCredentials(credentials: CallCredentials): void;
95}
96export interface NextCall {
97 (options: InterceptorOptions): InterceptingCallInterface;
98}
99export interface Interceptor {
100 (options: InterceptorOptions, nextCall: NextCall): InterceptingCall;
101}
102export interface InterceptorProvider {
103 (methodDefinition: ClientMethodDefinition<any, any>): Interceptor;
104}
105export interface InterceptorArguments {
106 clientInterceptors: Interceptor[];
107 clientInterceptorProviders: InterceptorProvider[];
108 callInterceptors: Interceptor[];
109 callInterceptorProviders: InterceptorProvider[];
110}
111export declare function getInterceptingCall(interceptorArgs: InterceptorArguments, methodDefinition: ClientMethodDefinition<any, any>, options: CallOptions, channel: Channel): InterceptingCallInterface;