Skip to content

API Reference

All public symbols are exported from the vgi-rpc-typescript package entry point.

Classes

Protocol

Fluent builder for defining RPC methods.

import { Protocol } from "vgi-rpc-typescript";
const protocol = new Protocol(name: string);

Properties:

  • name: string — the protocol/service name

Methods:

  • unary(name, config) — register a unary method
  • producer<S>(name, config) — register a producer stream
  • exchange<S>(name, config) — register an exchange stream
  • getMethods() — returns Map<string, MethodDefinition>

VgiRpcServer

RPC server that reads Arrow IPC requests from stdin and writes responses to stdout.

import { VgiRpcServer } from "vgi-rpc-typescript";
const server = new VgiRpcServer(protocol, options?);

Options:

  • enableDescribe?: boolean — register the __describe__ introspection method (default: true)
  • serverId?: string — server ID included in response metadata (random if omitted)

Methods:

  • run(): Promise<void> — start the server loop; reads requests until stdin closes

OutputCollector

Accumulates output batches during produce/exchange calls. Passed as the out parameter to streaming handlers.

import { OutputCollector } from "vgi-rpc-typescript";

Methods:

  • emit(columns: Record<string, any[]>) — emit a data batch from column arrays
  • emit(batch: RecordBatch, metadata?: Map<string, string>) — emit a pre-built RecordBatch
  • emitRow(values: Record<string, any>) — emit a single-row batch
  • finish() — signal stream completion (producer only)
  • clientLog(level, message, extra?) — emit a log message

Properties:

  • finished: boolean — whether finish() has been called
  • batches: EmittedBatch[] — accumulated batches
  • outputSchema: Schema — the output schema

Functions

createHttpHandler

Create a fetch-compatible HTTP handler for a Protocol.

import { createHttpHandler } from "vgi-rpc-typescript";
const handler = createHttpHandler(protocol: Protocol, options?: HttpHandlerOptions);
// Returns: (request: Request) => Response | Promise<Response>

See HTTP Transport for usage details.

toSchema

Convert a SchemaLike value to an Arrow Schema:

import { toSchema } from "vgi-rpc-typescript";
const schema = toSchema({ name: str, value: float });
// Returns: Schema

inferParamTypes

Infer parameter type strings from an Arrow schema:

import { inferParamTypes } from "vgi-rpc-typescript";
const types = inferParamTypes(schema);
// Returns: Record<string, string>

Type singletons

Schema shorthand values — see Schema Shorthand for details.

ExportArrow Type
strUtf8
bytesBinary
intInt64
int32Int32
floatFloat64
float32Float32
boolBool

Type aliases

type UnaryHandler = (
params: Record<string, any>,
ctx: LogContext,
) => Promise<Record<string, any>> | Record<string, any>;
type ProducerInit<S> = (
params: Record<string, any>,
) => Promise<S> | S;
type ProducerFn<S> = (
state: S,
out: OutputCollector,
) => Promise<void> | void;
type ExchangeInit<S> = (
params: Record<string, any>,
) => Promise<S> | S;
type ExchangeFn<S> = (
state: S,
input: RecordBatch,
out: OutputCollector,
) => Promise<void> | void;
type HeaderInit = (
params: Record<string, any>,
state: any,
ctx: LogContext,
) => Record<string, any>;
type SchemaLike = Schema | Record<string, DataType>;

Interfaces

LogContext

interface LogContext {
clientLog(level: string, message: string, extra?: Record<string, string>): void;
}

HttpHandlerOptions

See Configuration.

StateSerializer

interface StateSerializer {
serialize(state: any): Uint8Array;
deserialize(bytes: Uint8Array): any;
}

Enums

MethodType

enum MethodType {
UNARY = "unary",
STREAM = "stream",
}

Error classes

RpcError

class RpcError extends Error {
readonly errorType: string;
readonly errorMessage: string;
readonly remoteTraceback: string;
}

VersionError

class VersionError extends Error {}

Constants

Wire protocol metadata keys:

ConstantValue
RPC_METHOD_KEYvgi_rpc.method
REQUEST_VERSION_KEYvgi_rpc.request_version
REQUEST_VERSION1
LOG_LEVEL_KEYvgi_rpc.log_level
LOG_MESSAGE_KEYvgi_rpc.log_message
LOG_EXTRA_KEYvgi_rpc.log_extra
SERVER_ID_KEYvgi_rpc.server_id
REQUEST_ID_KEYvgi_rpc.request_id
PROTOCOL_NAME_KEYvgi_rpc.protocol_name
DESCRIBE_VERSION_KEYvgi_rpc.describe_version
DESCRIBE_VERSION2
DESCRIBE_METHOD_NAME__describe__
STATE_KEYvgi_rpc.stream_state
ARROW_CONTENT_TYPEapplication/vnd.apache.arrow.stream