Skip to main content
Module

x/cav/browser.ts

A server framework for Deno
Go to Latest
import * as cav from "https://deno.land/x/cav@0.0.24/browser.ts";

Classes

Error class for describing exceptions during HTTP processing.

Functions

Constructs a new Client function tied to the base URL. The provided set of serializers will be used everywhere that data is de/serialized when using this client, including web sockets.

Deserializes a JSON value that was serialize()d back into the original input. An error will be thrown if a value was serialized with an unknown serializer.

Determines if the object is a plain object or not. This also checks for prototype poisoning; it returns false whenever the prototype of an input object was poisoned before JSON.parsing it. See https://book.hacktricks.xyz/pentesting-web/deserialization/nodejs-proto-prototype-pollution for more information on prototype poisoning.

Normalizes a Parser into a ParserFunction.

Serializes a new Request, which can then be deserialized using unpack(). Only GET and POST requests are supported; the method used is automatically determined based on the presence of the message init option. Any headers specified on the init options will override the headers determined during serialization. The serializable input types can be extended with the serializers option.

Serializes a new Response, which can then be deserialized back into the input body using unpack(). Any headers specified on the init options will override the headers determined during serialization. The same applies for status and statusText. The serializable input types can be extended with the serializers option.

Serializes a value recursively until it's JSON-compatible. Serializers can be plugged in to extend the accepted types beyond what Cav supports by default. If a value isn't recognized by any of the provided or default serializers, an error will be thrown.

Constructs a Serializer. This simply returns the first argument, it's only used for type annotations.

Deserializes a Request generated with packRequest() back into the original request message. Any serializers specified during packing need to be specified here as well.

Wraps a WebSocket instance with added serialization functionality and E2E type support. If the input is a string, the wrapped WebSocket will be created with the given URL.

Interfaces

A server endpoint handler can use this Request type to ferry type information to the client about what argument types are acceptable and what the Response will deserialize into.

Init options for constructing HttpErrors, which can expose arbitrary data and status codes during de/serialization.

Initializer options when creating a Request with packRequest().

A function that parses data. If data is not shaped as expected, an error should be thrown.

An object with a ParserFunction as its "parse" property. Zod compatible.

A server router handler can use this Request type to ferry type information to the client about what routes exist and what data they accept/return. The client uses the RouterShape to infer which property accesses are valid and what their response type will be.

Type constraint for the type parameter of a RouterRequest. The shape describes the client property accesses that would result in a valid endpoint call. The endpoints are specified by their handler definitions.

Interface for serializing and deserializing arbitrary non-JSON primitive values into JSON.

A server socket handler can use this Request type to ferry type information to the client about the valid socket send/receive message types and acceptable query string parameters for the initial request.

A version of the Client type without E2E type safety.

ClientArg but without any type information. These are the arguments when the type for the client function isn't known.

Options for the unpack() function.

Isomorphic WebSocket interface with JSON serialization and typed messages.

Initializer options for the webSocket() function.

Type Aliases

Type alias representing a Serializer with any input or output type. Useful for type constraints.

Type that matches any socket. Useful for type constraints.

Client function that wraps a fetch() process tailored for making requests to a Cav handler, complete with serialization and socket support.

Arguments for the client function when its internal path points to an endpoint.

Type constraint for the Client's type parameter.

Generic handler type for server-defined Request handlers.

An object or function responsible for parsing data or throwing errors if the data isn't shaped as expected. These can either be functions with a single data argument that return the parsed data or an object with a parse(data): unknown function that does the same. Parsers can be asynchronous.

Extracts the input type of a given Parser.

Extracts the output type of a given Parser.

A group of named Serializer objects. Serializer keys are used to tag serialized values on the output JSON, which is required in order to correctly deserialize the value on the other side.

Listener for a Socket's "close" event.

Listener for a web socket's "error" event.

Listener for a web socket's "message" event. The message is deserialized from the event data.

Listener for a Socket's "open" event.