UNPKG

5.79 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3import * as http2 from 'http2';
4import { CallCredentials } from './call-credentials';
5import { Status } from './constants';
6import { Filter } from './filter';
7import { FilterStackFactory, FilterStack } from './filter-stack';
8import { Metadata } from './metadata';
9import { ChannelImplementation } from './channel';
10import { SubchannelCallStatsTracker, Subchannel } from './subchannel';
11import { ServerSurfaceCall } from './server-call';
12export type Deadline = Date | number;
13export interface CallStreamOptions {
14 deadline: Deadline;
15 flags: number;
16 host: string;
17 parentCall: ServerSurfaceCall | null;
18}
19export type PartialCallStreamOptions = Partial<CallStreamOptions>;
20export interface StatusObject {
21 code: Status;
22 details: string;
23 metadata: Metadata;
24}
25export declare const enum WriteFlags {
26 BufferHint = 1,
27 NoCompress = 2,
28 WriteThrough = 4
29}
30export interface WriteObject {
31 message: Buffer;
32 flags?: number;
33}
34export interface MetadataListener {
35 (metadata: Metadata, next: (metadata: Metadata) => void): void;
36}
37export interface MessageListener {
38 (message: any, next: (message: any) => void): void;
39}
40export interface StatusListener {
41 (status: StatusObject, next: (status: StatusObject) => void): void;
42}
43export interface FullListener {
44 onReceiveMetadata: MetadataListener;
45 onReceiveMessage: MessageListener;
46 onReceiveStatus: StatusListener;
47}
48export type Listener = Partial<FullListener>;
49/**
50 * An object with methods for handling the responses to a call.
51 */
52export interface InterceptingListener {
53 onReceiveMetadata(metadata: Metadata): void;
54 onReceiveMessage(message: any): void;
55 onReceiveStatus(status: StatusObject): void;
56}
57export declare function isInterceptingListener(listener: Listener | InterceptingListener): listener is InterceptingListener;
58export 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}
73export interface WriteCallback {
74 (error?: Error | null): void;
75}
76export interface MessageContext {
77 callback?: WriteCallback;
78 flags?: number;
79}
80export 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}
93export 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 * Indicates that an 'end' event has come from the http2 stream, so there
112 * will be no more data events.
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}