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.21/mod.ts";

Initializer options for constructing Rpcs.

Type Parameters

optional
Resp = unknown
optional
Groups extends AnyParser | null = null
optional
Context extends AnyCtx | null = null
optional
Query extends AnyParser | null = null
optional
Message extends AnyParser | null = null
optional
Upgrade extends boolean | null = null

Properties

optional
path: string | null

If the path of the request doesn't match this URLPattern string, a 404 Response will be returned before resolution starts. If this string starts with "^", the full Request path is used instead of the Stack routed path. The fallback behavior expects that the containing Stack(s) consumed the entire path, equivalent to specifying path: "/". 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 groups parsing. 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 Rpc will suppress the error and return a 404 Response. 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 ResolveArg 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. Unit: bytes. Default: 5 * 1024 * 1024 (5 MB)

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

Keys used when creating the "cookie" that's available to the ctx, resolve, and resolveError functions. If this isn't provided, a random fallback key will be used. Default: null

optional
serializers: Serializers | null

Additional serializers to use when serializing and deserializing request and response bodies and web 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 function responsible for constructing the "ctx" property available to the resolve function. This is only run if the requested path matched. Default: null

optional
query: Query

A parser used to parse the "query" object created from the Request's query string parameters. 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 deserialized using deserializeBody or (2) parse the message received if this Rpc results in a web socket connection via the "upgrade" option. Default: null

optional
resolve: Resolve<Resp, Groups, Context, Query, Message, Upgrade> | null

This function is called to resolve the parsed request into a response to serialize and send back to the client. If nothing is provided, the response will be a 204 no content.

optional
resolveError: ResolveError | null

When an error is thrown during processing, this function can handle the error. The return value will be serialized into a Response to send back to the client. Returning undefined or re-throwing the error will cause that error to be serialized as the response, which is the default behavior. Default: null