UNPKG

@jsonjoy.com/reactive-rpc

Version:

Reactive-RPC is a library for building reactive APIs over WebSocket, HTTP, and other RPCs.

44 lines (43 loc) 1.78 kB
import * as http2 from 'http2'; import { Writer } from '@jsonjoy.com/util/lib/buffers/Writer'; import { Router, type RouteMatcher } from '@jsonjoy.com/jit-router'; import type { Printable } from 'sonic-forest/lib/print/types'; import type { Http2ConnectionContext } from './context'; import { RpcCodecs } from '../../common/codec/RpcCodecs'; export type Http2Handler = (ctx: Http2ConnectionContext) => void | Promise<void>; export type Http2NotFoundHandler = (stream: http2.Http2Stream) => void; export type Http2InternalErrorHandler = (error: unknown, stream: http2.Http2Stream) => void; export declare class Http1EndpointMatch { readonly handler: Http2Handler; constructor(handler: Http2Handler); } export interface Http2EndpointDefinition { method?: string | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'CONNECT'; path: string; handler: Http2Handler; } export interface WsEndpointDefinition { path: string; maxIncomingMessage?: number; maxOutgoingBackpressure?: number; } export interface Http2ServerOpts { server: http2.Http2Server; codecs?: RpcCodecs; writer?: Writer; } export declare class Http2Server implements Printable { protected readonly opts: Http2ServerOpts; static start(opts?: http2.ServerOptions, port?: number): Http2Server; readonly codecs: RpcCodecs; readonly server: http2.Http2Server; constructor(opts: Http2ServerOpts); start(): void; onnotfound: Http2NotFoundHandler; oninternalerror: Http2InternalErrorHandler; protected readonly httpRouter: Router<Http1EndpointMatch>; protected httpMatcher: RouteMatcher<Http1EndpointMatch>; route(def: Http2EndpointDefinition): void; private readonly onStream; toString(tab?: string): string; }