Skip to main content
Module

x/cav/serial.ts

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

Classes

An error class for describing exceptions during HTTP processing.

Functions

Deserializes a value returned by serialize() into the original input value. Referential equality will be restored on the output object. An error will be thrown if a value was serialized with an unknown/unused serializer.

Deserializes a Request or Response object whose body was serialized with serializeBody(). Any Serializers used outside of the library defaults during serialization need to be provided here as well, or an error may be thrown.

Utility function used in the serial functions that determines if an object is a plain object or not. Because this is such a common operation when checking and serializing unknown objects, it's being exported as part of the API.

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. Referential equality will be preserved whenever the same object or symbol value is encountered more than once. If a value isn't recognized by any of the provided serializers or the default serializers, an error is thrown.

Serializes a value into a type that is compatible with a Response BodyInit, making it easy to serialize values for sending to an external host/client via HTTP. If a provided value is already compatible with BodyInit, it will be returned with an appropriate mime type, skipping the serialization process. During serialization, this function extends the default supported types to include Blobs and Files. If a Blob is encountered during serialization, the resulting body will be a multipart FormData that encodes the shape of the input as well as the blobs that were encountered. Otherwise, a regular JSON string will be returned. Blobs and Files can be placed anywhere on the input value, even if they are nested.

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

Interfaces

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

A group of functions used to recognize (check), serialize, and deserialize objects and special values that are not strings, basic numbers, booleans, or nulls into objects that are JSON compatible.

Type Aliases

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

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.

A Serializer's deserialize() function receives the raw serialized JSON value as its first argument and this registration function as the second. Functions registered with whenDone will be run last-in-first-out (stack order) when the raw JSON has been processed into the final object instance. WhenDone functions are needed whenever the serialized data is more complex than simple JSON values, for example when referential equality needs to be maintained or when the serialize function returns anything that needs to be re-serialized by some other serializer. Referenced objects may not be fully initialized when the registered function is called, but its instance will be instantiated so that references can be fixed.