@lesomnus/grpc-dgram 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/README.md +61 -21
- package/dist/{conn-DOmx4nbt.mjs → conn-CmYPHTPR.mjs} +327 -23
- package/dist/conn-Dc57BC-h.d.mts +775 -0
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +238 -48
- package/dist/{protocol-K4Zy8MuQ.mjs → protocol-CTxSUZQF.mjs} +60 -5
- package/dist/transport/connect.d.mts +1 -1
- package/dist/transport/node-udp.d.mts +5 -4
- package/dist/transport/node-udp.mjs +16 -10
- package/dist/transport/port.d.mts +5 -4
- package/dist/transport/port.mjs +15 -8
- package/dist/transport/webrtc.d.mts +5 -4
- package/dist/transport/webrtc.mjs +13 -7
- package/dist/transport/websocket.d.mts +5 -4
- package/dist/transport/websocket.mjs +14 -8
- package/dist/transport/webtransport.d.mts +53 -0
- package/dist/transport/webtransport.mjs +144 -0
- package/dist/wasm/worker.mjs +20 -5
- package/dist/wasm.d.mts +7 -3
- package/dist/wasm.mjs +21 -9
- package/dist/{wire-BR8KiyRg.mjs → wire-DqHx0oUs.mjs} +211 -39
- package/package.json +6 -3
- package/dist/conn-DTWG9vIx.d.mts +0 -331
- package/dist/server-xIr1mwqq.d.mts +0 -112
|
@@ -0,0 +1,775 @@
|
|
|
1
|
+
import { a as MethodDesc, h as Metadata, n as CallOptions, o as NamedCodec, s as PayloadCodec } from "./desc-BMF2FBqk.mjs";
|
|
2
|
+
//#region src/timing.d.ts
|
|
3
|
+
interface Timing {
|
|
4
|
+
callMs?: number;
|
|
5
|
+
livenessMs?: number;
|
|
6
|
+
retransmitMs?: number;
|
|
7
|
+
tombstoneMs?: number;
|
|
8
|
+
holdMs?: number;
|
|
9
|
+
}
|
|
10
|
+
interface ResolvedTiming {
|
|
11
|
+
callMs: number;
|
|
12
|
+
livenessMs: number;
|
|
13
|
+
retransmitMs: number;
|
|
14
|
+
tombstoneMs: number;
|
|
15
|
+
holdMs: number;
|
|
16
|
+
probeMs: number;
|
|
17
|
+
tickMs: number;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/limits.d.ts
|
|
21
|
+
declare enum DropPolicy {
|
|
22
|
+
Newest = 0,
|
|
23
|
+
Oldest = 1
|
|
24
|
+
}
|
|
25
|
+
interface RxBufferConfig {
|
|
26
|
+
size?: number;
|
|
27
|
+
policy?: DropPolicy;
|
|
28
|
+
}
|
|
29
|
+
interface ResolvedRxConfig {
|
|
30
|
+
size: number;
|
|
31
|
+
policy: DropPolicy;
|
|
32
|
+
}
|
|
33
|
+
interface Limits {
|
|
34
|
+
maxTombstones?: number;
|
|
35
|
+
maxTombstoneBytes?: number;
|
|
36
|
+
maxDeadPeers?: number;
|
|
37
|
+
maxPendingResets?: number;
|
|
38
|
+
maxLiveCalls?: number;
|
|
39
|
+
maxRepliesPerRTI?: number;
|
|
40
|
+
maxPeerWindow?: number;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/stats.d.ts
|
|
44
|
+
type ProtocolEventKind = 'skipped' | 'dropped' | 'off-shape' | 'reset-sent' | 'reset-received' | 'retransmit' | 'probe-sent' | 'keepalive-sent' | 'liveness-expired' | 'tombstone-replay' | 'data-loss' | 'flow-stall' | 'flow-resume' | 'peer-flow-stall' | 'peer-flow-resume';
|
|
45
|
+
interface ProtocolEvent {
|
|
46
|
+
readonly kind: ProtocolEventKind;
|
|
47
|
+
readonly peer?: unknown;
|
|
48
|
+
readonly sid: number;
|
|
49
|
+
readonly method: string;
|
|
50
|
+
readonly count: number;
|
|
51
|
+
}
|
|
52
|
+
type ProtocolStats = (ev: ProtocolEvent) => void;
|
|
53
|
+
interface CounterSnapshot {
|
|
54
|
+
skipped: number;
|
|
55
|
+
dropped: number;
|
|
56
|
+
offShape: number;
|
|
57
|
+
resetSent: number;
|
|
58
|
+
resetReceived: number;
|
|
59
|
+
retransmit: number;
|
|
60
|
+
probeSent: number;
|
|
61
|
+
keepaliveSent: number;
|
|
62
|
+
livenessExpired: number;
|
|
63
|
+
tombstoneReplay: number;
|
|
64
|
+
dataLoss: number;
|
|
65
|
+
flowStall: number;
|
|
66
|
+
flowResume: number;
|
|
67
|
+
peerFlowStall: number;
|
|
68
|
+
peerFlowResume: number;
|
|
69
|
+
}
|
|
70
|
+
declare class Counters {
|
|
71
|
+
private readonly n;
|
|
72
|
+
readonly observe: ProtocolStats;
|
|
73
|
+
snapshot(): CounterSnapshot;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/status.d.ts
|
|
77
|
+
declare enum Code {
|
|
78
|
+
OK = 0,
|
|
79
|
+
CANCELLED = 1,
|
|
80
|
+
UNKNOWN = 2,
|
|
81
|
+
INVALID_ARGUMENT = 3,
|
|
82
|
+
DEADLINE_EXCEEDED = 4,
|
|
83
|
+
NOT_FOUND = 5,
|
|
84
|
+
ALREADY_EXISTS = 6,
|
|
85
|
+
PERMISSION_DENIED = 7,
|
|
86
|
+
RESOURCE_EXHAUSTED = 8,
|
|
87
|
+
FAILED_PRECONDITION = 9,
|
|
88
|
+
ABORTED = 10,
|
|
89
|
+
OUT_OF_RANGE = 11,
|
|
90
|
+
UNIMPLEMENTED = 12,
|
|
91
|
+
INTERNAL = 13,
|
|
92
|
+
UNAVAILABLE = 14,
|
|
93
|
+
DATA_LOSS = 15,
|
|
94
|
+
UNAUTHENTICATED = 16
|
|
95
|
+
}
|
|
96
|
+
declare class StatusError extends Error {
|
|
97
|
+
readonly code: Code;
|
|
98
|
+
readonly desc: string;
|
|
99
|
+
constructor(code: Code, desc: string);
|
|
100
|
+
}
|
|
101
|
+
declare function statusError(code: Code, desc: string): StatusError;
|
|
102
|
+
declare class MessageTooLargeError extends Error {
|
|
103
|
+
constructor(message?: string);
|
|
104
|
+
}
|
|
105
|
+
declare function isMessageTooLarge(err: unknown): boolean;
|
|
106
|
+
declare function toStatusError(err: unknown): StatusError;
|
|
107
|
+
declare function abortCause(signal: AbortSignal): StatusError;
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/wire.d.ts
|
|
110
|
+
declare const FlagOpen = 1;
|
|
111
|
+
declare const FlagClose = 2;
|
|
112
|
+
declare const FlagReset = 4;
|
|
113
|
+
declare const FlagPing = 8;
|
|
114
|
+
declare const FlagWindow = 16;
|
|
115
|
+
declare const FlagCompressed = 32;
|
|
116
|
+
declare const SHAPE_MASK: number;
|
|
117
|
+
interface Any {
|
|
118
|
+
typeUrl: string;
|
|
119
|
+
value: Uint8Array;
|
|
120
|
+
}
|
|
121
|
+
interface Frame {
|
|
122
|
+
epoch: number;
|
|
123
|
+
sid: number;
|
|
124
|
+
seq: number;
|
|
125
|
+
flags: number;
|
|
126
|
+
method: string;
|
|
127
|
+
codec: string;
|
|
128
|
+
timeoutMs?: number;
|
|
129
|
+
payload?: Uint8Array;
|
|
130
|
+
code?: number;
|
|
131
|
+
desc: string;
|
|
132
|
+
header?: Metadata;
|
|
133
|
+
trailer?: Metadata;
|
|
134
|
+
peerEpoch: number;
|
|
135
|
+
window: number;
|
|
136
|
+
compressor: string;
|
|
137
|
+
details?: Any[];
|
|
138
|
+
connWindow: number;
|
|
139
|
+
}
|
|
140
|
+
declare function frame(init?: Partial<Frame>): Frame;
|
|
141
|
+
declare const isOpen: (f: Frame) => boolean;
|
|
142
|
+
declare const isClose: (f: Frame) => boolean;
|
|
143
|
+
declare const isReset: (f: Frame) => boolean;
|
|
144
|
+
declare const isPing: (f: Frame) => boolean;
|
|
145
|
+
declare const isWindow: (f: Frame) => boolean;
|
|
146
|
+
declare const isCompressed: (f: Frame) => boolean;
|
|
147
|
+
declare const shapeOf: (f: Frame) => number;
|
|
148
|
+
declare const hasUnknownFlags: (f: Frame) => boolean;
|
|
149
|
+
declare function legalShape(shape: number): boolean;
|
|
150
|
+
declare const isTerminal: (f: Frame) => boolean;
|
|
151
|
+
declare const isHalfClose: (f: Frame) => boolean;
|
|
152
|
+
declare const isData: (f: Frame) => boolean;
|
|
153
|
+
declare const isHeaderFrame: (f: Frame) => boolean;
|
|
154
|
+
declare function frameStatus(f: Frame): StatusError;
|
|
155
|
+
declare function setFrameError(f: Frame, err: unknown): void;
|
|
156
|
+
declare function resetFor(f: Frame): Frame;
|
|
157
|
+
declare function encodeFrame(f: Frame): Uint8Array;
|
|
158
|
+
declare function decodeFrame(data: Uint8Array): Frame;
|
|
159
|
+
declare function encodeEnvelope(frames: readonly Frame[]): Uint8Array;
|
|
160
|
+
declare function decodeEnvelope(data: Uint8Array): Frame[];
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/seam.d.ts
|
|
163
|
+
interface FrameContext {
|
|
164
|
+
peer?: unknown;
|
|
165
|
+
reliable?: boolean;
|
|
166
|
+
signal?: AbortSignal;
|
|
167
|
+
}
|
|
168
|
+
interface FrameHandler {
|
|
169
|
+
handle(frame: Frame, ctx?: FrameContext): void | Promise<void>;
|
|
170
|
+
}
|
|
171
|
+
interface EnvelopeSender {
|
|
172
|
+
sendFrames(frames: readonly Frame[], ctx?: FrameContext): Promise<void>;
|
|
173
|
+
}
|
|
174
|
+
interface TransportInfo {
|
|
175
|
+
reliable(): boolean;
|
|
176
|
+
}
|
|
177
|
+
interface ConnAttacher {
|
|
178
|
+
attachConn(conn: Conn): void;
|
|
179
|
+
}
|
|
180
|
+
declare function hasTransportInfo(tx: FrameHandler): tx is FrameHandler & TransportInfo;
|
|
181
|
+
declare function hasConnAttacher(tx: FrameHandler): tx is FrameHandler & ConnAttacher;
|
|
182
|
+
declare function unpack(frames: readonly Frame[], h: FrameHandler, ctx?: FrameContext): Promise<void>;
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/util.d.ts
|
|
185
|
+
declare class Latch {
|
|
186
|
+
tripped: boolean;
|
|
187
|
+
private readonly promise;
|
|
188
|
+
private resolve;
|
|
189
|
+
constructor();
|
|
190
|
+
trip(): void;
|
|
191
|
+
wait(): Promise<void>;
|
|
192
|
+
}
|
|
193
|
+
declare class FrameQueue {
|
|
194
|
+
readonly cap: number;
|
|
195
|
+
dropped: number;
|
|
196
|
+
private buf;
|
|
197
|
+
private readWaiters;
|
|
198
|
+
private spaceWaiters;
|
|
199
|
+
private putTail;
|
|
200
|
+
constructor(cap: number);
|
|
201
|
+
get size(): number;
|
|
202
|
+
tryTake(): Frame | undefined;
|
|
203
|
+
tryPut(f: Frame): boolean;
|
|
204
|
+
putDrop(f: Frame, policy: DropPolicy): number;
|
|
205
|
+
putBlocking(f: Frame, done: Latch, signal?: AbortSignal): Promise<boolean>;
|
|
206
|
+
readable(): Promise<void>;
|
|
207
|
+
private space;
|
|
208
|
+
}
|
|
209
|
+
declare const W_INIT = 32;
|
|
210
|
+
declare const W_CONN = 1024;
|
|
211
|
+
declare const DEFAULT_STALL_MS = 30000;
|
|
212
|
+
type FlowAcquire = 'ok' | 'ended' | 'aborted' | 'stalled';
|
|
213
|
+
interface SenderState {
|
|
214
|
+
on: boolean;
|
|
215
|
+
observed: boolean;
|
|
216
|
+
granted: number;
|
|
217
|
+
sent: number;
|
|
218
|
+
}
|
|
219
|
+
declare class FlowSender {
|
|
220
|
+
private on;
|
|
221
|
+
private observed;
|
|
222
|
+
private granted;
|
|
223
|
+
private sent;
|
|
224
|
+
private readonly waiters;
|
|
225
|
+
assume(window: number): void;
|
|
226
|
+
observe(window: number): void;
|
|
227
|
+
reassume(window: number): void;
|
|
228
|
+
grant(n: number): void;
|
|
229
|
+
undo(): boolean;
|
|
230
|
+
refund(n: number): number;
|
|
231
|
+
drain(): number;
|
|
232
|
+
release(): void;
|
|
233
|
+
tryAcquire(): boolean;
|
|
234
|
+
empty(): boolean;
|
|
235
|
+
state(): SenderState;
|
|
236
|
+
restore(st: SenderState): void;
|
|
237
|
+
acquire(done: Latch, stallMs: number, signal?: AbortSignal): Promise<FlowAcquire>;
|
|
238
|
+
parked(): Promise<void>;
|
|
239
|
+
}
|
|
240
|
+
declare class PeerFlowRx {
|
|
241
|
+
private window;
|
|
242
|
+
private outstanding;
|
|
243
|
+
private readonly pending;
|
|
244
|
+
private readonly evicted;
|
|
245
|
+
private evictCap;
|
|
246
|
+
enable(window: number, evictCap: number): void;
|
|
247
|
+
get active(): boolean;
|
|
248
|
+
admit(): boolean;
|
|
249
|
+
retire(epoch: number, n: number, credit: boolean): number;
|
|
250
|
+
unadmitted(epoch: number, n: number): number;
|
|
251
|
+
unadmittedEvicted(epoch: number, n: number): number;
|
|
252
|
+
private hold;
|
|
253
|
+
private due;
|
|
254
|
+
renew(): void;
|
|
255
|
+
stash(epoch: number, state: SenderState): void;
|
|
256
|
+
unstash(epoch: number): SenderState | undefined;
|
|
257
|
+
creditEvicted(epoch: number, n: number): void;
|
|
258
|
+
}
|
|
259
|
+
declare const DEFAULT_MAX_RECV_MSG_SIZE: number;
|
|
260
|
+
declare const DEFAULT_MAX_SEND_MSG_SIZE = 2147483647;
|
|
261
|
+
interface Compressor {
|
|
262
|
+
compress(data: Uint8Array): Uint8Array | Promise<Uint8Array>;
|
|
263
|
+
decompress(data: Uint8Array, maxBytes: number): Uint8Array | Promise<Uint8Array>;
|
|
264
|
+
}
|
|
265
|
+
declare function getCompressor(name: string): Compressor | undefined;
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/server.d.ts
|
|
268
|
+
interface ServerOptions {
|
|
269
|
+
reliable?: boolean;
|
|
270
|
+
timing?: FlowTiming;
|
|
271
|
+
maxHandlerTimeoutMs?: number;
|
|
272
|
+
rxBuffer?: RxBufferConfig;
|
|
273
|
+
methodRxBuffer?: Record<string, RxBufferConfig>;
|
|
274
|
+
limits?: Limits;
|
|
275
|
+
codecs?: Record<string, NamedCodec>;
|
|
276
|
+
compressors?: Record<string, Compressor>;
|
|
277
|
+
maxRecvMsgSize?: number;
|
|
278
|
+
maxSendMsgSize?: number;
|
|
279
|
+
unaryInterceptors?: UnaryServerInterceptor[];
|
|
280
|
+
streamInterceptors?: StreamServerInterceptor[];
|
|
281
|
+
protocolStats?: ProtocolStats | ProtocolStats[];
|
|
282
|
+
}
|
|
283
|
+
interface ServerContext {
|
|
284
|
+
readonly signal: AbortSignal;
|
|
285
|
+
readonly metadata: Metadata | undefined;
|
|
286
|
+
readonly peer: unknown;
|
|
287
|
+
readonly method: string;
|
|
288
|
+
readonly desc: MethodDesc;
|
|
289
|
+
readonly deadline: number | undefined;
|
|
290
|
+
setHeader(md: Metadata): void;
|
|
291
|
+
sendHeader(md?: Metadata): Promise<void>;
|
|
292
|
+
setTrailer(md: Metadata): void;
|
|
293
|
+
}
|
|
294
|
+
interface ServerReader<Req> {
|
|
295
|
+
recv(): Promise<Req | undefined>;
|
|
296
|
+
[Symbol.asyncIterator](): AsyncIterator<Req>;
|
|
297
|
+
}
|
|
298
|
+
interface ServerWriter<Res> {
|
|
299
|
+
send(msg: Res): Promise<void>;
|
|
300
|
+
}
|
|
301
|
+
type UnaryHandler<Req, Res> = (req: Req, ctx: ServerContext) => Res | Promise<Res>;
|
|
302
|
+
type ServerStreamingHandler<Req, Res> = (req: Req, stream: ServerWriter<Res>, ctx: ServerContext) => void | Promise<void>;
|
|
303
|
+
type ClientStreamingHandler<Req, Res> = (stream: ServerReader<Req>, ctx: ServerContext) => Res | Promise<Res>;
|
|
304
|
+
type BidiHandler<Req, Res> = (stream: ServerReader<Req> & ServerWriter<Res>, ctx: ServerContext) => void | Promise<void>;
|
|
305
|
+
type AnyHandler = UnaryHandler<unknown, unknown> | ServerStreamingHandler<unknown, unknown> | ClientStreamingHandler<unknown, unknown> | BidiHandler<unknown, unknown>;
|
|
306
|
+
interface Registration {
|
|
307
|
+
desc: MethodDesc<unknown, unknown>;
|
|
308
|
+
handler: AnyHandler;
|
|
309
|
+
}
|
|
310
|
+
interface SrvTomb {
|
|
311
|
+
sid: number;
|
|
312
|
+
term: Frame | undefined;
|
|
313
|
+
size: number;
|
|
314
|
+
expireAt: number;
|
|
315
|
+
lastReplay: number;
|
|
316
|
+
}
|
|
317
|
+
interface HwmCheckpoint {
|
|
318
|
+
at: number;
|
|
319
|
+
hwm: number;
|
|
320
|
+
}
|
|
321
|
+
interface PendingReset {
|
|
322
|
+
due: number;
|
|
323
|
+
echo: number;
|
|
324
|
+
peerEcho: number;
|
|
325
|
+
epoch: number;
|
|
326
|
+
sid: number;
|
|
327
|
+
}
|
|
328
|
+
declare class PeerState {
|
|
329
|
+
readonly peer: unknown;
|
|
330
|
+
readonly epoch: number;
|
|
331
|
+
readonly reliable: boolean;
|
|
332
|
+
readonly createdAt: number;
|
|
333
|
+
readonly maxTombs: number;
|
|
334
|
+
readonly maxTombBytes: number;
|
|
335
|
+
hwm: number;
|
|
336
|
+
cps: HwmCheckpoint[];
|
|
337
|
+
dead: boolean;
|
|
338
|
+
readonly tombs: Map<number, SrvTomb>;
|
|
339
|
+
tombOrder: number[];
|
|
340
|
+
tombBytes: number;
|
|
341
|
+
tombFloor: number;
|
|
342
|
+
readonly calls: Map<number, ServerStream<unknown, unknown>>;
|
|
343
|
+
liveCalls: number;
|
|
344
|
+
readonly connTx: FlowSender;
|
|
345
|
+
lastRx: number;
|
|
346
|
+
lastTx: number;
|
|
347
|
+
lastPing: number;
|
|
348
|
+
constructor(peer: unknown, epoch: number, reliable: boolean, createdAt: number, maxTombs: number, maxTombBytes: number);
|
|
349
|
+
hwmAged(now: number, ttlMs: number): number;
|
|
350
|
+
addTomb(sid: number, term: Frame | undefined, expireAt: number): void;
|
|
351
|
+
removeTomb(sid: number): void;
|
|
352
|
+
replayDue(tb: SrvTomb, now: number, rtiMs: number): boolean;
|
|
353
|
+
replayTomb(tb: SrvTomb, now: number, rtiMs: number): Frame | undefined;
|
|
354
|
+
}
|
|
355
|
+
declare class PeerSlot {
|
|
356
|
+
readonly peer: unknown;
|
|
357
|
+
readonly epochs: Map<number, PeerState>;
|
|
358
|
+
liveCalls: number;
|
|
359
|
+
replyBudget: {
|
|
360
|
+
windowStart: number;
|
|
361
|
+
n: number;
|
|
362
|
+
} | undefined;
|
|
363
|
+
readonly resetAt: Map<string, number>;
|
|
364
|
+
readonly pendingResets: Map<string, PendingReset>;
|
|
365
|
+
flow: PeerFlowRx | undefined;
|
|
366
|
+
constructor(peer: unknown);
|
|
367
|
+
}
|
|
368
|
+
declare class Server {
|
|
369
|
+
readonly epoch: number;
|
|
370
|
+
private readonly tx;
|
|
371
|
+
private readonly mode;
|
|
372
|
+
private readonly maxHandlerTimeoutMs;
|
|
373
|
+
private readonly rxCfg;
|
|
374
|
+
private readonly methodRx;
|
|
375
|
+
private readonly limits;
|
|
376
|
+
private readonly codecs;
|
|
377
|
+
private readonly compressors;
|
|
378
|
+
private readonly maxRecv;
|
|
379
|
+
private readonly maxSend;
|
|
380
|
+
private readonly stallMs;
|
|
381
|
+
/** @internal */ readonly pstats: readonly ProtocolStats[];
|
|
382
|
+
private readonly services;
|
|
383
|
+
private serving;
|
|
384
|
+
private readonly slots;
|
|
385
|
+
private pendingResetTotal;
|
|
386
|
+
private resetAtTotal;
|
|
387
|
+
private replyBudgetTotal;
|
|
388
|
+
private drain;
|
|
389
|
+
private closed;
|
|
390
|
+
private liveTasks;
|
|
391
|
+
private idleWaiters;
|
|
392
|
+
private sawUnreliable;
|
|
393
|
+
private readonly sw;
|
|
394
|
+
private readonly unaryInt;
|
|
395
|
+
private readonly streamInt;
|
|
396
|
+
constructor(tx: FrameHandler, opts?: ServerOptions);
|
|
397
|
+
private protoEvent;
|
|
398
|
+
register<Req, Res>(desc: MethodDesc<Req, Res> & {
|
|
399
|
+
clientStreams: false;
|
|
400
|
+
serverStreams: false;
|
|
401
|
+
}, handler: UnaryHandler<Req, Res>): void;
|
|
402
|
+
register<Req, Res>(desc: MethodDesc<Req, Res> & {
|
|
403
|
+
clientStreams: false;
|
|
404
|
+
serverStreams: true;
|
|
405
|
+
}, handler: ServerStreamingHandler<Req, Res>): void;
|
|
406
|
+
register<Req, Res>(desc: MethodDesc<Req, Res> & {
|
|
407
|
+
clientStreams: true;
|
|
408
|
+
serverStreams: false;
|
|
409
|
+
}, handler: ClientStreamingHandler<Req, Res>): void;
|
|
410
|
+
register<Req, Res>(desc: MethodDesc<Req, Res> & {
|
|
411
|
+
clientStreams: true;
|
|
412
|
+
serverStreams: true;
|
|
413
|
+
}, handler: BidiHandler<Req, Res>): void;
|
|
414
|
+
private rxReliable;
|
|
415
|
+
handle(f: Frame, ctx?: FrameContext): Promise<void>;
|
|
416
|
+
private open;
|
|
417
|
+
private rejectOpen;
|
|
418
|
+
private runUnary;
|
|
419
|
+
private runStream;
|
|
420
|
+
private finish;
|
|
421
|
+
private resetByPeerSid;
|
|
422
|
+
private sendReset;
|
|
423
|
+
private allowReply;
|
|
424
|
+
gracefulStop(): Promise<void>;
|
|
425
|
+
stop(): Promise<void>;
|
|
426
|
+
disconnectPeer(peer: unknown, err?: unknown): void;
|
|
427
|
+
private waitIdle;
|
|
428
|
+
private taskDone;
|
|
429
|
+
/** @internal */
|
|
430
|
+
get timing(): ResolvedTiming;
|
|
431
|
+
/** @internal */
|
|
432
|
+
send(f: Frame, ctx: FrameContext): Promise<void>;
|
|
433
|
+
/** @internal */
|
|
434
|
+
sendOrThrow(f: Frame, ctx: FrameContext): Promise<void>;
|
|
435
|
+
/** @internal */
|
|
436
|
+
txFor(peer: unknown): FrameContext;
|
|
437
|
+
/** @internal */
|
|
438
|
+
allowReplyFor(peer: unknown, now: number): boolean;
|
|
439
|
+
private ensureSlot;
|
|
440
|
+
private ensurePeer;
|
|
441
|
+
private observeAdvertisement;
|
|
442
|
+
/** @internal */
|
|
443
|
+
advertise(f: Frame, reliable: boolean): void;
|
|
444
|
+
private ensurePeerFlow;
|
|
445
|
+
/** @internal */
|
|
446
|
+
grantPeer(ps: PeerState, n: number): void;
|
|
447
|
+
private grantEpoch;
|
|
448
|
+
private grantOn;
|
|
449
|
+
/** @internal */
|
|
450
|
+
kickSweep(): void;
|
|
451
|
+
private hasWork;
|
|
452
|
+
private sweep;
|
|
453
|
+
}
|
|
454
|
+
declare class ServerStream<Req, Res> implements ServerReader<Req>, ServerWriter<Res> {
|
|
455
|
+
private readonly server;
|
|
456
|
+
readonly peer: unknown;
|
|
457
|
+
readonly clientEpoch: number;
|
|
458
|
+
readonly sid: number;
|
|
459
|
+
/** @internal */ readonly reg: Registration;
|
|
460
|
+
/** @internal */ readonly reliable: boolean;
|
|
461
|
+
private readonly comp;
|
|
462
|
+
private readonly maxRecv;
|
|
463
|
+
private readonly maxSend;
|
|
464
|
+
private readonly stallMs;
|
|
465
|
+
readonly context: ServerContext;
|
|
466
|
+
/** @internal */ ps: PeerState | undefined;
|
|
467
|
+
/** @internal */ pf: PeerFlowRx | undefined;
|
|
468
|
+
/** @internal */ slot: PeerSlot | undefined;
|
|
469
|
+
/** @internal */ deadlineAt: number | undefined;
|
|
470
|
+
/** @internal */ deadlineTimer: ReturnType<typeof setTimeout> | undefined;
|
|
471
|
+
/** @internal */ metadata: Metadata | undefined;
|
|
472
|
+
/** @internal */ suppressTerm: boolean;
|
|
473
|
+
/** @internal */ readonly flowTx: FlowSender;
|
|
474
|
+
private readonly flowRx;
|
|
475
|
+
private readonly txSeq;
|
|
476
|
+
/** @internal */ txHeader: Metadata | undefined;
|
|
477
|
+
private hdrSent;
|
|
478
|
+
private hdrFlushed;
|
|
479
|
+
private hdrFrame;
|
|
480
|
+
/** @internal */ trailerMd: Metadata | undefined;
|
|
481
|
+
private resp;
|
|
482
|
+
private respSet;
|
|
483
|
+
private lastRx;
|
|
484
|
+
private lastTx;
|
|
485
|
+
private lastProbe;
|
|
486
|
+
private hReplayAt;
|
|
487
|
+
private readonly rxWin;
|
|
488
|
+
private pinned;
|
|
489
|
+
private rxReleased;
|
|
490
|
+
/** @internal */ readonly rxq: FrameQueue;
|
|
491
|
+
private readonly rxCfg;
|
|
492
|
+
/** @internal */ rxDropped: number;
|
|
493
|
+
/** @internal */ readonly rxEOF: Latch;
|
|
494
|
+
private readonly ctrl;
|
|
495
|
+
private readonly endLatch;
|
|
496
|
+
/** @internal */
|
|
497
|
+
constructor(server: Server, peer: unknown, clientEpoch: number, sid: number, /** @internal */ reg: Registration, codec: {
|
|
498
|
+
request: PayloadCodec<unknown>;
|
|
499
|
+
response: PayloadCodec<unknown>;
|
|
500
|
+
}, rxCfg: ResolvedRxConfig, /** @internal */ reliable: boolean, comp: Compressor | undefined, maxRecv: number, maxSend: number, stallMs: number);
|
|
501
|
+
/** @internal */ readonly reqCodec: PayloadCodec<unknown>;
|
|
502
|
+
/** @internal */ readonly resCodec: PayloadCodec<unknown>;
|
|
503
|
+
get signal(): AbortSignal;
|
|
504
|
+
/** @internal */
|
|
505
|
+
cancel(cause: StatusError): void;
|
|
506
|
+
/** @internal */
|
|
507
|
+
protoEvent(kind: ProtocolEventKind, count?: number): void;
|
|
508
|
+
/** @internal */
|
|
509
|
+
handleRx(f: Frame, ctx: FrameContext): Promise<void>;
|
|
510
|
+
private noteValidatedRx;
|
|
511
|
+
recv(): Promise<Req | undefined>;
|
|
512
|
+
private recvBuffered;
|
|
513
|
+
private pin;
|
|
514
|
+
private unpin;
|
|
515
|
+
/** @internal */
|
|
516
|
+
releasePinned(): void;
|
|
517
|
+
private creditUnbuffered;
|
|
518
|
+
private retirePeer;
|
|
519
|
+
[Symbol.asyncIterator](): AsyncIterator<Req>;
|
|
520
|
+
/** @internal */
|
|
521
|
+
transmit(f: Frame): Promise<void>;
|
|
522
|
+
private nextFrame;
|
|
523
|
+
private attachHeader;
|
|
524
|
+
/** @internal */
|
|
525
|
+
sendH(): void;
|
|
526
|
+
private grantWindow;
|
|
527
|
+
private replayH;
|
|
528
|
+
/** @internal */
|
|
529
|
+
probeDue(now: number, probeMs: number, epoch: number): Frame | undefined;
|
|
530
|
+
/** @internal */
|
|
531
|
+
setHeader(md: Metadata): void;
|
|
532
|
+
/** @internal */
|
|
533
|
+
sendHeader(md?: Metadata): Promise<void>;
|
|
534
|
+
send(msg: Res): Promise<void>;
|
|
535
|
+
private transmitOrThrow;
|
|
536
|
+
private undoRefused;
|
|
537
|
+
private undoCredit;
|
|
538
|
+
private encodePayload;
|
|
539
|
+
/** @internal */
|
|
540
|
+
decodeMessage(f: Frame): Promise<unknown>;
|
|
541
|
+
/** @internal */
|
|
542
|
+
setResponse(resp: unknown): void;
|
|
543
|
+
/** @internal */
|
|
544
|
+
terminalFrame(err: StatusError | undefined): Promise<Frame>;
|
|
545
|
+
/** @internal */
|
|
546
|
+
transmitTerminal(f: Frame): Promise<void>;
|
|
547
|
+
private tryTransmit;
|
|
548
|
+
}
|
|
549
|
+
//#endregion
|
|
550
|
+
//#region src/interceptor.d.ts
|
|
551
|
+
interface ClientCall<Req = unknown, Res = unknown> {
|
|
552
|
+
readonly desc: MethodDesc<Req, Res>;
|
|
553
|
+
opts: CallConfig<Req, Res>;
|
|
554
|
+
}
|
|
555
|
+
type UnaryInvoker = (req: unknown, call: ClientCall) => Promise<NonNullable<unknown>>;
|
|
556
|
+
type UnaryClientInterceptor = (req: unknown, call: ClientCall, next: UnaryInvoker) => Promise<NonNullable<unknown>>;
|
|
557
|
+
type Streamer = (call: ClientCall) => ClientStream<unknown, unknown>;
|
|
558
|
+
type StreamClientInterceptor = (call: ClientCall, next: Streamer) => ClientStream<unknown, unknown>;
|
|
559
|
+
type UnaryServerHandler = (req: unknown, ctx: ServerContext) => Promise<NonNullable<unknown>>;
|
|
560
|
+
type UnaryServerInterceptor = (req: unknown, ctx: ServerContext, next: UnaryServerHandler) => Promise<NonNullable<unknown>>;
|
|
561
|
+
type StreamServerHandler = (stream: ServerReader<unknown> & ServerWriter<unknown>, ctx: ServerContext) => Promise<unknown>;
|
|
562
|
+
type StreamServerInterceptor = (stream: ServerReader<unknown> & ServerWriter<unknown>, ctx: ServerContext, next: StreamServerHandler) => Promise<unknown>;
|
|
563
|
+
//#endregion
|
|
564
|
+
//#region src/conn.d.ts
|
|
565
|
+
declare class EndOfStreamError extends Error {
|
|
566
|
+
constructor();
|
|
567
|
+
}
|
|
568
|
+
interface FlowTiming extends Timing {
|
|
569
|
+
stallMs?: number;
|
|
570
|
+
}
|
|
571
|
+
interface CallConfig<Req = unknown, Res = unknown> extends CallOptions<Req, Res> {
|
|
572
|
+
compressor?: string;
|
|
573
|
+
maxRecvMsgSize?: number;
|
|
574
|
+
maxSendMsgSize?: number;
|
|
575
|
+
}
|
|
576
|
+
interface ConnOptions {
|
|
577
|
+
reliable?: boolean;
|
|
578
|
+
timing?: FlowTiming;
|
|
579
|
+
rxBuffer?: RxBufferConfig;
|
|
580
|
+
limits?: Limits;
|
|
581
|
+
compressor?: string;
|
|
582
|
+
maxRecvMsgSize?: number;
|
|
583
|
+
maxSendMsgSize?: number;
|
|
584
|
+
compressors?: Record<string, Compressor>;
|
|
585
|
+
defaultCallOptions?: CallConfig;
|
|
586
|
+
unaryInterceptors?: UnaryClientInterceptor[];
|
|
587
|
+
streamInterceptors?: StreamClientInterceptor[];
|
|
588
|
+
protocolStats?: ProtocolStats | ProtocolStats[];
|
|
589
|
+
}
|
|
590
|
+
interface CallInfo {
|
|
591
|
+
compressorName: string;
|
|
592
|
+
compressor: Compressor | undefined;
|
|
593
|
+
maxRecv: number;
|
|
594
|
+
maxSend: number;
|
|
595
|
+
stallMs: number;
|
|
596
|
+
}
|
|
597
|
+
type DetailedStatusError = StatusError & {
|
|
598
|
+
details?: readonly Any[];
|
|
599
|
+
};
|
|
600
|
+
declare function statusDetails(err: unknown): readonly Any[] | undefined;
|
|
601
|
+
declare class Conn {
|
|
602
|
+
readonly epoch: number;
|
|
603
|
+
private readonly tx;
|
|
604
|
+
private readonly mode;
|
|
605
|
+
private readonly rxCfg;
|
|
606
|
+
private readonly limits;
|
|
607
|
+
private readonly defaults;
|
|
608
|
+
private readonly compressor;
|
|
609
|
+
private readonly compressors;
|
|
610
|
+
private readonly maxRecv;
|
|
611
|
+
private readonly maxSend;
|
|
612
|
+
private readonly stallMs;
|
|
613
|
+
/** @internal */ readonly pstats: readonly ProtocolStats[];
|
|
614
|
+
private readonly ss;
|
|
615
|
+
private readonly tombs;
|
|
616
|
+
private readonly resetAt;
|
|
617
|
+
private sidNext;
|
|
618
|
+
private exhausted;
|
|
619
|
+
private closed;
|
|
620
|
+
/** @internal */ readonly connTx: FlowSender;
|
|
621
|
+
/** @internal */ readonly connRx: PeerFlowRx;
|
|
622
|
+
private srvEpoch;
|
|
623
|
+
private srvEpochSet;
|
|
624
|
+
private lastRx;
|
|
625
|
+
private lastTx;
|
|
626
|
+
private lastPing;
|
|
627
|
+
private readonly sw;
|
|
628
|
+
private readonly unaryInt;
|
|
629
|
+
private readonly streamInt;
|
|
630
|
+
constructor(tx: FrameHandler, opts?: ConnOptions);
|
|
631
|
+
get reliable(): boolean;
|
|
632
|
+
private protoEvent;
|
|
633
|
+
handle(f: Frame, ctx?: FrameContext): Promise<void>;
|
|
634
|
+
close(err?: unknown): void;
|
|
635
|
+
invoke<Req, Res>(desc: MethodDesc<Req, Res>, req: Req, opts?: CallConfig<Req, Res>): Promise<Res>;
|
|
636
|
+
private doInvoke;
|
|
637
|
+
newStream<Req, Res>(desc: MethodDesc<Req, Res>, opts?: CallConfig<Req, Res>): ClientStream<Req, Res>;
|
|
638
|
+
private doNewStream;
|
|
639
|
+
private resolveCall;
|
|
640
|
+
private createStream;
|
|
641
|
+
/** @internal */
|
|
642
|
+
get timing(): ResolvedTiming;
|
|
643
|
+
/** @internal */
|
|
644
|
+
get isReliable(): boolean;
|
|
645
|
+
/** @internal */
|
|
646
|
+
get streamRxCfg(): ResolvedRxConfig;
|
|
647
|
+
/** @internal */
|
|
648
|
+
transmit(f: Frame): Promise<void>;
|
|
649
|
+
/** @internal */
|
|
650
|
+
noteRx(): void;
|
|
651
|
+
/** @internal */
|
|
652
|
+
lockServerEpoch(epoch: number): void;
|
|
653
|
+
/** @internal */
|
|
654
|
+
observeAdvertisement(f: Frame): void;
|
|
655
|
+
/** @internal */
|
|
656
|
+
get locked(): boolean;
|
|
657
|
+
private serverEpochIs;
|
|
658
|
+
private serverCurrent;
|
|
659
|
+
/** @internal */
|
|
660
|
+
creditUnbuffered(f: Frame): void;
|
|
661
|
+
/** @internal */
|
|
662
|
+
retirePeer(n: number, epoch: number): void;
|
|
663
|
+
/** @internal */
|
|
664
|
+
get peerWindow(): number;
|
|
665
|
+
private grantPeer;
|
|
666
|
+
/** @internal */
|
|
667
|
+
retire(s: ClientStream<unknown, unknown>): void;
|
|
668
|
+
private clearTombAbort;
|
|
669
|
+
private sendReset;
|
|
670
|
+
private failAll;
|
|
671
|
+
/** @internal */
|
|
672
|
+
kickSweep(): void;
|
|
673
|
+
private hasWork;
|
|
674
|
+
private sweep;
|
|
675
|
+
}
|
|
676
|
+
declare class ClientStream<Req, Res> {
|
|
677
|
+
readonly sid: number;
|
|
678
|
+
private readonly conn;
|
|
679
|
+
private readonly desc;
|
|
680
|
+
private readonly reqCodec;
|
|
681
|
+
private readonly resCodec;
|
|
682
|
+
private readonly codecName;
|
|
683
|
+
private readonly openHdr;
|
|
684
|
+
private readonly ci;
|
|
685
|
+
private readonly flowTx;
|
|
686
|
+
private readonly flowRx;
|
|
687
|
+
private readonly rxSize;
|
|
688
|
+
private readonly callerSignal;
|
|
689
|
+
private signalDispose;
|
|
690
|
+
private deadlineTimer;
|
|
691
|
+
private deadlineFired;
|
|
692
|
+
private readonly timeoutCause;
|
|
693
|
+
/** @internal */
|
|
694
|
+
deadlineAt: number | undefined;
|
|
695
|
+
private readonly txSeq;
|
|
696
|
+
private txOpened;
|
|
697
|
+
private txClosed;
|
|
698
|
+
/** @internal */
|
|
699
|
+
abortFrame: Frame | undefined;
|
|
700
|
+
private retxOpen;
|
|
701
|
+
private retxClose;
|
|
702
|
+
private retxAt;
|
|
703
|
+
private retxIval;
|
|
704
|
+
private lastRx;
|
|
705
|
+
private lastTx;
|
|
706
|
+
private lastProbe;
|
|
707
|
+
private readonly rxWin;
|
|
708
|
+
private srvEpoch;
|
|
709
|
+
private srvEpochSet;
|
|
710
|
+
private pinned;
|
|
711
|
+
private rxReleased;
|
|
712
|
+
private readonly rxq;
|
|
713
|
+
private readonly rxPolicy;
|
|
714
|
+
private rxDropped;
|
|
715
|
+
private rxHeader;
|
|
716
|
+
private trailerMd;
|
|
717
|
+
private readonly hdrLatch;
|
|
718
|
+
private readonly done;
|
|
719
|
+
private term;
|
|
720
|
+
private termErr;
|
|
721
|
+
private termPayloadDelivered;
|
|
722
|
+
/** @internal */
|
|
723
|
+
constructor(conn: Conn, desc: MethodDesc<Req, Res>, sid: number, opts: CallConfig<Req, Res>, ci: CallInfo, timeoutCause: StatusError | undefined);
|
|
724
|
+
/** @internal */
|
|
725
|
+
arm(opts: CallOptions<Req, Res>): void;
|
|
726
|
+
private pin;
|
|
727
|
+
private unpin;
|
|
728
|
+
private undoCredit;
|
|
729
|
+
/** @internal */
|
|
730
|
+
protoEvent(kind: ProtocolEventKind, count?: number): void;
|
|
731
|
+
/** @internal */
|
|
732
|
+
handleRx(f: Frame, ctx: FrameContext): Promise<void>;
|
|
733
|
+
private grantWindow;
|
|
734
|
+
private recvInto;
|
|
735
|
+
private latchHeader;
|
|
736
|
+
private noteValidatedRx;
|
|
737
|
+
private openFrame;
|
|
738
|
+
private nextFrame;
|
|
739
|
+
/** @internal */
|
|
740
|
+
sendOpen(): Promise<void>;
|
|
741
|
+
/** @internal */
|
|
742
|
+
sendRaw(m: Req): Promise<void>;
|
|
743
|
+
private undoRefused;
|
|
744
|
+
send(m: Req): Promise<void>;
|
|
745
|
+
closeSend(): void;
|
|
746
|
+
recv(): Promise<Res | undefined>;
|
|
747
|
+
private recvBuffered;
|
|
748
|
+
private terminalRecv;
|
|
749
|
+
[Symbol.asyncIterator](): AsyncIterator<Res>;
|
|
750
|
+
header(): Promise<Metadata | undefined>;
|
|
751
|
+
trailer(): Metadata | undefined;
|
|
752
|
+
latchedHeader(): Metadata | undefined;
|
|
753
|
+
cancel(): void;
|
|
754
|
+
private abortFromCtx;
|
|
755
|
+
private sendAbort;
|
|
756
|
+
private finishTerm;
|
|
757
|
+
/** @internal */
|
|
758
|
+
finishLocal(err: StatusError): void;
|
|
759
|
+
/** @internal */
|
|
760
|
+
abandon(): void;
|
|
761
|
+
/** @internal */
|
|
762
|
+
finishReset(): void;
|
|
763
|
+
private release;
|
|
764
|
+
/** @internal */
|
|
765
|
+
transmit(f: Frame): Promise<void>;
|
|
766
|
+
private scheduleRetx;
|
|
767
|
+
/** @internal */
|
|
768
|
+
dropRetx(): void;
|
|
769
|
+
/** @internal */
|
|
770
|
+
sweepRetx(now: number, capMs: number): Frame[];
|
|
771
|
+
/** @internal */
|
|
772
|
+
probeDue(now: number, probeMs: number): Frame | undefined;
|
|
773
|
+
}
|
|
774
|
+
//#endregion
|
|
775
|
+
export { encodeEnvelope as $, DEFAULT_STALL_MS as A, DropPolicy as At, hasTransportInfo as B, ServerReader as C, statusError as Ct, Compressor as D, ProtocolEvent as Dt, UnaryHandler as E, Counters as Et, EnvelopeSender as F, FlagOpen as G, Any as H, FrameContext as I, FlagWindow as J, FlagPing as K, FrameHandler as L, W_INIT as M, RxBufferConfig as Mt, getCompressor as N, Timing as Nt, DEFAULT_MAX_RECV_MSG_SIZE as O, ProtocolEventKind as Ot, ConnAttacher as P, decodeFrame as Q, TransportInfo as R, ServerOptions as S, isMessageTooLarge as St, ServerWriter as T, CounterSnapshot as Tt, FlagClose as U, unpack as V, FlagCompressed as W, SHAPE_MASK as X, Frame as Y, decodeEnvelope as Z, UnaryServerInterceptor as _, shapeOf as _t, DetailedStatusError as a, isCompressed as at, Server as b, StatusError as bt, statusDetails as c, isHeaderFrame as ct, StreamServerHandler as d, isReset as dt, encodeFrame as et, StreamServerInterceptor as f, isTerminal as ft, UnaryServerHandler as g, setFrameError as gt, UnaryInvoker as h, resetFor as ht, ConnOptions as i, isClose as it, W_CONN as j, Limits as jt, DEFAULT_MAX_SEND_MSG_SIZE as k, ProtocolStats as kt, ClientCall as l, isOpen as lt, UnaryClientInterceptor as m, legalShape as mt, ClientStream as n, frameStatus as nt, EndOfStreamError as o, isData as ot, Streamer as p, isWindow as pt, FlagReset as q, Conn as r, hasUnknownFlags as rt, FlowTiming as s, isHalfClose as st, CallConfig as t, frame as tt, StreamClientInterceptor as u, isPing as ut, BidiHandler as v, Code as vt, ServerStreamingHandler as w, toStatusError as wt, ServerContext as x, abortCause as xt, ClientStreamingHandler as y, MessageTooLargeError as yt, hasConnAttacher as z };
|