Protocol
Defined in: src/protocol.ts:25
Fluent builder for defining RPC methods.
Register unary, producer, and exchange methods, then pass to VgiRpcServer.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Protocol(name, options?): Protocol;Defined in: src/protocol.ts:40
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name | string |
options? | { protocolVersion?: string; } |
options.protocolVersion? | string |
Returns
Section titled “Returns”Protocol
Properties
Section titled “Properties”readonly name: string;Defined in: src/protocol.ts:27
Service / protocol name, exposed to clients via introspection.
protocolVersion
Section titled “protocolVersion”readonly protocolVersion: string;Defined in: src/protocol.ts:35
Application protocol surface version. When non-empty, the server enforces
exact major+minor match (patch ignored) against every request’s
vgi_rpc.protocol_version metadata; clients bound to this Protocol emit
the value on every request. Format: canonical semver MAJOR.MINOR.PATCH.
Mirrors Python’s Protocol.protocol_version ClassVar.
protocolVersionParts
Section titled “protocolVersionParts”readonly protocolVersionParts: readonly [number, number, number] | null;Defined in: src/protocol.ts:37
Parsed semver tuple; null when protocolVersion is unset.
Methods
Section titled “Methods”exchange()
Section titled “exchange()”exchange<S>(name, config): this;Defined in: src/protocol.ts:130
Register an exchange (bidirectional-streaming) method.
The generic S is inferred from the init return type and threaded to exchange.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
S |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name | string |
config | { defaults?: Record<string, any>; doc?: string; exchange: ExchangeFn<S>; headerInit?: HeaderInit; headerSchema?: SchemaLike; init: ExchangeInit<S>; inputSchema: SchemaLike; onCancel?: OnCancelFn<S>; outputSchema: SchemaLike; params: SchemaLike; paramTypes?: Record<string, string>; } |
config.defaults? | Record<string, any> |
config.doc? | string |
config.exchange | ExchangeFn<S> |
config.headerInit? | HeaderInit |
config.headerSchema? | SchemaLike |
config.init | ExchangeInit<S> |
config.inputSchema | SchemaLike |
config.onCancel? | OnCancelFn<S> |
config.outputSchema | SchemaLike |
config.params | SchemaLike |
config.paramTypes? | Record<string, string> |
Returns
Section titled “Returns”this
getMethods()
Section titled “getMethods()”getMethods(): Map<string, MethodDefinition>;Defined in: src/protocol.ts:168
Snapshot of the registered methods, keyed by method name. Returns a copy, so mutating it does not affect the protocol.
Returns
Section titled “Returns”Map<string, MethodDefinition>
producer()
Section titled “producer()”producer<S>(name, config): this;Defined in: src/protocol.ts:91
Register a producer (server-streaming) method.
The generic S is inferred from the init return type and threaded to produce.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
S |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name | string |
config | { defaults?: Record<string, any>; doc?: string; headerInit?: HeaderInit; headerSchema?: SchemaLike; init: ProducerInit<S>; onCancel?: OnCancelFn<S>; outputSchema: SchemaLike; params: SchemaLike; paramTypes?: Record<string, string>; produce: ProducerFn<S>; } |
config.defaults? | Record<string, any> |
config.doc? | string |
config.headerInit? | HeaderInit |
config.headerSchema? | SchemaLike |
config.init | ProducerInit<S> |
config.onCancel? | OnCancelFn<S> |
config.outputSchema | SchemaLike |
config.params | SchemaLike |
config.paramTypes? | Record<string, string> |
config.produce | ProducerFn<S> |
Returns
Section titled “Returns”this
unary()
Section titled “unary()”unary(name, config): this;Defined in: src/protocol.ts:62
Register a unary (request-response) method.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
name | string | Method name exposed to clients |
config | { defaults?: Record<string, any>; doc?: string; handler: UnaryHandler; params: SchemaLike; paramTypes?: Record<string, string>; result: SchemaLike; } | - |
config.defaults? | Record<string, any> | Optional default parameter values |
config.doc? | string | Optional documentation string |
config.handler | UnaryHandler | Async function receiving params and returning result values |
config.params | SchemaLike | Parameter schema (SchemaLike) |
config.paramTypes? | Record<string, string> | Optional parameter type hints (inferred from params if omitted) |
config.result | SchemaLike | Result schema (SchemaLike) |
Returns
Section titled “Returns”this