Skip to main content
Module

x/cav/mod.ts>RpcInit

A server framework for Deno
Go to Latest
interface RpcInit
import { type RpcInit } from "https://deno.land/x/cav@0.0.14/mod.ts";

Initializer options when constructing Rpcs.

Type Parameters

optional
Resp = unknown
optional
Groups extends GroupsParser | null = null
optional
Context extends Ctx<unknown> | null = null
optional
Query extends QueryParser | null = null
optional
Message extends Parser | null = null
optional
Upgrade extends boolean | null = null

Properties

optional
path: string | null

If the routed path of the request doesn't match this URLPattern string, the NO_MATCH error will be thrown and the stack will continue searching for matching routes. If this string starts with "^", the full Request path is used instead of the routed path. (The routed path is determined by the containing stack, the full path comes from req.url.pathname.) The default behavior expects that the containing stack(s) consumed the entire path, thus leaving the Rpc path as "/". The full URLPattern syntax is supported, and any captured path groups will be merged with the path groups captured by the containing stack(s) before undergoing groups parsing. (See the docs for the "groups" property.) The path that matched this string is available on the ResolveArg, CtxArg, and ResolveErrorArg as the "path" property. Default: "/"

optional
groups: Groups

When a Request matches the path for this Rpc, all captured groups from the Rpc and the Stack will be parsed using this Parser. If the Parser throws an error, the error will be converted into a NO_MATCH and the containing stack will continue looking for matching routes to handle the request. The result of parsing is available on the ResolverArg as the "groups" property. If the parser is "optional" (i.e. it successfully parses undefined), all parsing errors will be suppressed and that fallback value will be used for the ResolverArg whenever an error is thrown. Default: null

optional
maxBodySize: number | null

This limits the maximum size of the Request body. Note that, currently, the entire Request body is loaded into memory during request processing. Support for large file uploads is in the works. The unit is bytes. Default: 5 * 1024 * 1024 (5 MB)

optional
keys: [string, ...string[]] | null

Keys used when creating the "cookie" that's available on the ResolverArg. If this isn't provided, a random fallback key will be used. Default: null

optional
packers: Packers | null

Packers used when packing and unpacking request and response bodies as well as socket messages. Default: null

optional
upgrade: Upgrade

If true, this causes requests to be upgraded into web sockets. Requests that don't request an upgrade will be rejected. The resolve function should return the response from the upgrade() utility available on the ResolveArg. Default: null

optional
ctx: Context

A Ctx function responsible for constructing the "ctx" property available on the ResolverArg. This is only run if the requested path matched. Default: null

optional
query: Query

A parser used to parse the "query" object from the RequestData associated with a Request. This data comes from the query string in the url of the request. Default: null

optional
message: Message

A parser used to either (1) parse the Request body after it's unpacked using unpackBody or (2) parse the message received if this Rpc results in a webSocket connection via the "upgrade" utility function available on the ResolverArg. If this Rpc is not a socket-type Rpc and this parser does not successfully parse undefined, the allowed methods for this Rpc will only include "POST", not "GET" or "HEAD". If this Parser is omitted, the only allowed methods are "GET" and "HEAD". If it does parse undefined, all three methods are allowed. Default: null

This function is called to resolve the parsed request into a response to pack and send back to the client.

optional
resolveError: ResolveError | null

When an error is thrown during processing, this function is meant to handle the error. The return value will be packed into a Response to send back to the client. Re-throwing the error will cause that error to be packed as the response. Default: null