1 |
|
2 |
|
3 | import * as http2 from 'http2';
|
4 | import { CallCredentials } from './call-credentials';
|
5 | import { Status } from './constants';
|
6 | import { Filter } from './filter';
|
7 | import { FilterStackFactory, FilterStack } from './filter-stack';
|
8 | import { Metadata } from './metadata';
|
9 | import { ChannelImplementation } from './channel';
|
10 | import { SubchannelCallStatsTracker, Subchannel } from './subchannel';
|
11 | import { ServerSurfaceCall } from './server-call';
|
12 | export type Deadline = Date | number;
|
13 | export interface CallStreamOptions {
|
14 | deadline: Deadline;
|
15 | flags: number;
|
16 | host: string;
|
17 | parentCall: ServerSurfaceCall | null;
|
18 | }
|
19 | export type PartialCallStreamOptions = Partial<CallStreamOptions>;
|
20 | export interface StatusObject {
|
21 | code: Status;
|
22 | details: string;
|
23 | metadata: Metadata;
|
24 | }
|
25 | export declare const enum WriteFlags {
|
26 | BufferHint = 1,
|
27 | NoCompress = 2,
|
28 | WriteThrough = 4
|
29 | }
|
30 | export interface WriteObject {
|
31 | message: Buffer;
|
32 | flags?: number;
|
33 | }
|
34 | export interface MetadataListener {
|
35 | (metadata: Metadata, next: (metadata: Metadata) => void): void;
|
36 | }
|
37 | export interface MessageListener {
|
38 | (message: any, next: (message: any) => void): void;
|
39 | }
|
40 | export interface StatusListener {
|
41 | (status: StatusObject, next: (status: StatusObject) => void): void;
|
42 | }
|
43 | export interface FullListener {
|
44 | onReceiveMetadata: MetadataListener;
|
45 | onReceiveMessage: MessageListener;
|
46 | onReceiveStatus: StatusListener;
|
47 | }
|
48 | export type Listener = Partial<FullListener>;
|
49 |
|
50 |
|
51 |
|
52 | export interface InterceptingListener {
|
53 | onReceiveMetadata(metadata: Metadata): void;
|
54 | onReceiveMessage(message: any): void;
|
55 | onReceiveStatus(status: StatusObject): void;
|
56 | }
|
57 | export declare function isInterceptingListener(listener: Listener | InterceptingListener): listener is InterceptingListener;
|
58 | export declare class InterceptingListenerImpl implements InterceptingListener {
|
59 | private listener;
|
60 | private nextListener;
|
61 | private processingMetadata;
|
62 | private hasPendingMessage;
|
63 | private pendingMessage;
|
64 | private processingMessage;
|
65 | private pendingStatus;
|
66 | constructor(listener: FullListener, nextListener: InterceptingListener);
|
67 | private processPendingMessage;
|
68 | private processPendingStatus;
|
69 | onReceiveMetadata(metadata: Metadata): void;
|
70 | onReceiveMessage(message: any): void;
|
71 | onReceiveStatus(status: StatusObject): void;
|
72 | }
|
73 | export interface WriteCallback {
|
74 | (error?: Error | null): void;
|
75 | }
|
76 | export interface MessageContext {
|
77 | callback?: WriteCallback;
|
78 | flags?: number;
|
79 | }
|
80 | export interface Call {
|
81 | cancelWithStatus(status: Status, details: string): void;
|
82 | getPeer(): string;
|
83 | start(metadata: Metadata, listener: InterceptingListener): void;
|
84 | sendMessageWithContext(context: MessageContext, message: Buffer): void;
|
85 | startRead(): void;
|
86 | halfClose(): void;
|
87 | getDeadline(): Deadline;
|
88 | getCredentials(): CallCredentials;
|
89 | setCredentials(credentials: CallCredentials): void;
|
90 | getMethod(): string;
|
91 | getHost(): string;
|
92 | }
|
93 | export declare class Http2CallStream implements Call {
|
94 | private readonly methodName;
|
95 | private readonly channel;
|
96 | private readonly options;
|
97 | private readonly channelCallCredentials;
|
98 | private readonly callNumber;
|
99 | credentials: CallCredentials;
|
100 | filterStack: FilterStack;
|
101 | private http2Stream;
|
102 | private pendingRead;
|
103 | private isWriteFilterPending;
|
104 | private pendingWrite;
|
105 | private pendingWriteCallback;
|
106 | private writesClosed;
|
107 | private decoder;
|
108 | private isReadFilterPending;
|
109 | private canPush;
|
110 | |
111 |
|
112 |
|
113 |
|
114 | private readsClosed;
|
115 | private statusOutput;
|
116 | private unpushedReadMessages;
|
117 | private unfilteredReadMessages;
|
118 | private mappedStatusCode;
|
119 | private finalStatus;
|
120 | private subchannel;
|
121 | private disconnectListener;
|
122 | private listener;
|
123 | private internalError;
|
124 | private configDeadline;
|
125 | private statusWatchers;
|
126 | private streamEndWatchers;
|
127 | private callStatsTracker;
|
128 | constructor(methodName: string, channel: ChannelImplementation, options: CallStreamOptions, filterStackFactory: FilterStackFactory, channelCallCredentials: CallCredentials, callNumber: number);
|
129 | private outputStatus;
|
130 | private trace;
|
131 | /**
|
132 | * On first call, emits a 'status' event with the given StatusObject.
|
133 | * Subsequent calls are no-ops.
|
134 | * @param status The status of the call.
|
135 | */
|
136 | private endCall;
|
137 | private maybeOutputStatus;
|
138 | private push;
|
139 | private handleFilterError;
|
140 | private handleFilteredRead;
|
141 | private filterReceivedMessage;
|
142 | private tryPush;
|
143 | private handleTrailers;
|
144 | private writeMessageToStream;
|
145 | attachHttp2Stream(stream: http2.ClientHttp2Stream, subchannel: Subchannel, extraFilters: Filter[], callStatsTracker: SubchannelCallStatsTracker): void;
|
146 | start(metadata: Metadata, listener: InterceptingListener): void;
|
147 | private destroyHttp2Stream;
|
148 | cancelWithStatus(status: Status, details: string): void;
|
149 | getDeadline(): Deadline;
|
150 | getCredentials(): CallCredentials;
|
151 | setCredentials(credentials: CallCredentials): void;
|
152 | getStatus(): StatusObject | null;
|
153 | getPeer(): string;
|
154 | getMethod(): string;
|
155 | getHost(): string;
|
156 | setConfigDeadline(configDeadline: Deadline): void;
|
157 | addStatusWatcher(watcher: (status: StatusObject) => void): void;
|
158 | addStreamEndWatcher(watcher: (success: boolean) => void): void;
|
159 | addFilters(extraFilters: Filter[]): void;
|
160 | getCallNumber(): number;
|
161 | startRead(): void;
|
162 | private maybeCloseWrites;
|
163 | sendMessageWithContext(context: MessageContext, message: Buffer): void;
|
164 | halfClose(): void;
|
165 | }
|