deno-vm
Version:
A VM module that provides a secure runtime environment via Deno.
73 lines (72 loc) • 2.54 kB
TypeScript
import { Transferrable } from './MessageTarget';
/**
* Serializes the given value into a new object that is flat and contains no circular references.
*
* The returned object is JSON-safe and contains a root which is the entry point to the data structure and optionally
* contains a refs property which is a flat map of references.
*
* If the refs property is defined, then the data structure was circular.
*
* @param value The value to serialize.
* @param transferrable The transferrable list.
*/
export declare function serializeStructure(value: unknown, transferrable?: Transferrable[]): Structure;
/**
* Deserializes the given structure into its original form.
* @param value The structure to deserialize.
*/
export declare function deserializeStructure(value: Structure): DeserializedStructure;
/**
* Defines an interface for a serializable structure.
* Usually created from a normal JavaScript object.
*/
export interface Structure {
/**
* The entry point into the structure.
* Can be a reference to an object in the refs property.
*/
root: any;
/**
* The ID of the channel that serialized this structure.
* If omitted, then the root channel sent this message.
* Used to multiplex messages.
*/
channel?: number | string;
/**
* A map of reference IDs to objects.
* Objects can additionally reference other objects.
*/
refs?: {
[key: string]: Ref;
};
}
/**
* Defines an interface for a structure that was deserialized.
*/
export interface DeserializedStructure {
/**
* The data in the structure.
*/
data: any;
/**
* The list of values that were transferred and require extra processing to be fully transferred.
*/
transferred: Transferrable[];
}
/**
* Defines an interface for an object that has been serialized into a flat structure with references to other objects.
*/
export interface Ref {
/**
* The entry point for the object.
* Can contain references to other objects.
*/
root: any;
/**
* The type of the reference.
* If omitted, then the value is either an object or an array.
* If specified, then the value should be converted into the given type on
* deserialization.
*/
type?: 'ArrayBuffer' | 'Uint8Array' | 'Uint16Array' | 'Uint32Array' | 'Int8Array' | 'Int16Array' | 'Int32Array' | 'BigInt' | 'Date' | 'RegExp' | 'Map' | 'Set' | 'Error' | 'MessagePort';
}