dessert

Index

Classes

Interfaces

Argument()

Argument(): undefined | Primitive

Return the next argument, if there is a next argument

Returns

undefined | Primitive

Defined in

src/dessert/deserialization/types.d.ts:61

Argument<T>(...types): undefined | TypeOf<T>

Return the next argument, if there is a next argument, requiring the argument to be of the given type

Type Parameters

Type Parameter
T extends [PrimitiveType, ...PrimitiveType[]]

Parameters

ParameterType
...typesT

Returns

undefined | TypeOf<T>

Throws

If the next argument does not match any of the given types

Defined in

src/dessert/deserialization/types.d.ts:67

Methods

if()

if<T>(...types): undefined | TypeOf<T>

Return the next argument, if there is a next argument and it has a valid type

Type Parameters
Type Parameter
T extends [PrimitiveType, ...PrimitiveType[]]
Parameters
ParameterType
...typesT
Returns

undefined | TypeOf<T>

Defined in

src/dessert/deserialization/types.d.ts:74


required()
Call Signature

required(): Primitive

Return the next argument

Returns

Primitive

Throws

If there is no next argument

Defined in

src/dessert/deserialization/types.d.ts:83

Call Signature

required<T>(...types): TypeOf<T>

Return the next argument

Type Parameters
Type Parameter
T extends [PrimitiveType, ...PrimitiveType[]]
Parameters
ParameterType
...typesT
Returns

TypeOf<T>

Throws

If there is no next argument

Throws

If the next argument does not match any of the given types

Defined in

src/dessert/deserialization/types.d.ts:90


rest()
Call Signature

rest(): Primitive[]

Return all remaining arguments

Returns

Primitive[]

Defined in

src/dessert/deserialization/types.d.ts:97

Call Signature

rest<T>(...types): TypeOf<T>[]

Return all remaining arguments

Type Parameters
Type Parameter
T extends [PrimitiveType, ...PrimitiveType[]]
Parameters
ParameterType
...typesT
Returns

TypeOf<T>[]

Defined in

src/dessert/deserialization/types.d.ts:102


Child()

Child<T, P>(name, deserializer, ...parameters): undefined | T

Returns the next child with the given name, if there is any

Type Parameters

Type Parameter
T
P extends unknown[]

Parameters

ParameterType
namestring
deserializerDeserializer<T, P>
...parametersP

Returns

undefined | T

Throws

If the deserializer fails

Defined in

src/dessert/deserialization/types.d.ts:157

Properties

required()

required: <T, P>(name, deserializer, ...parameters) => T

Returns the next child with the given name

Type Parameters
Type Parameter
T
P extends unknown[]
Parameters
ParameterType
namestring
deserializerDeserializer<T, P>
...parametersP
Returns

T

Throws

If there is no next child with the given name

Throws

If the deserializer fails

single()

Returns the next child with the given name and validate that there are no others

Type Parameters
Type Parameter
T
P extends unknown[]
Parameters
ParameterType
namestring
deserializerDeserializer<T, P>
...parametersP
Returns

T

Throws

If there is no next child with the given name

Throws

If the deserializer fails

Throws

If there are other children left with the given name

Defined in

src/dessert/deserialization/types.d.ts:163


single()

single: <T, P>(name, deserializer, ...parameters) => undefined | T

Returns the next child with the given name if there is any and validate that there are no others

Type Parameters
Type Parameter
T
P extends unknown[]
Parameters
ParameterType
namestring
deserializerDeserializer<T, P>
...parametersP
Returns

undefined | T

Throws

If the deserializer fails

Throws

If there are other children left with the given name

required()

Returns the next child with the given name and validate that there are no others

Type Parameters
Type Parameter
T
P extends unknown[]
Parameters
ParameterType
namestring
deserializerDeserializer<T, P>
...parametersP
Returns

T

Throws

If there is no next child with the given name

Throws

If the deserializer fails

Throws

If there are other children left with the given name

Defined in

src/dessert/deserialization/types.d.ts:189


Children()

Children<T, P>(name, deserializer, ...parameters): T[]

Returns all remaining children with the given name

Type Parameters

Type Parameter
T
P extends unknown[]

Parameters

ParameterType
namestring
deserializerDeserializer<T, P>
...parametersP

Returns

T[]

Throws

If the deserializer fails

Defined in

src/dessert/deserialization/types.d.ts:222

Properties

entries()

entries: <T, P>(deserializer, ...parameters) => [string, T][]

Returns all remaining children with their name

Type Parameters
Type Parameter
T
P extends unknown[]
Parameters
ParameterType
deserializerDeserializer<T, P>
...parametersP
Returns

[string, T][]

Throws

If the deserializer fails

filtered()

filtered: <T, P>(filter, deserializer, ...parameters) => [string, T][]

Returns all remaining children with their name if that name matches the given filter

Type Parameters
Type Parameter
T
P extends unknown[]
Parameters
ParameterType
filterRegExp
deserializerDeserializer<T, P>
...parametersP
Returns

[string, T][]

Throws

If the deserializer fails

filtered.unique()

Returns all remaining children with their name if that name matches the given filter, requiring all matching names to be unique

Type Parameters
Type Parameter
T
P extends unknown[]
Parameters
ParameterType
filterRegExp
deserializerDeserializer<T, P>
...parametersP
Returns

[string, T][]

Throws

If the deserializer fails

Throws

If a duplicate name is encountered

unique()

unique: <T, P>(deserializer, ...parameters) => [string, T][]

Returns all remaining children with their name, requiring all names to be unique

Type Parameters
Type Parameter
T
P extends unknown[]
Parameters
ParameterType
deserializerDeserializer<T, P>
...parametersP
Returns

[string, T][]

Throws

If the deserializer fails

Throws

If a duplicate name is encountered

unique.filtered()

Returns all remaining children with their name if that name matches the given filter, requiring all matching names to be unique

Type Parameters
Type Parameter
T
P extends unknown[]
Parameters
ParameterType
filterRegExp
deserializerDeserializer<T, P>
...parametersP
Returns

[string, T][]

Throws

If the deserializer fails

Throws

If a duplicate name is encountered

Defined in

src/dessert/deserialization/types.d.ts:240

Methods

required()

required<T, P>(name, deserializer, ...parameters): [T, ...T[]]

Returns all remaining children with the given name, requiring at least one such child

Type Parameters
Type Parameter
T
P extends unknown[]
Parameters
ParameterType
namestring
deserializerDeserializer<T, P>
...parametersP
Returns

[T, ...T[]]

Throws

If the deserializer fails

Throws

If there are no remaining children with the given name

Defined in

src/dessert/deserialization/types.d.ts:234


DeserializationContext

Wrapper around a Node to help deserializing a single Node into a value

Properties

argument

readonly argument: Argument

Helper to access the node's arguments

Defined in

src/dessert/deserialization/types.d.ts:385


child

readonly child: Child

Helper to access the node's children

Defined in

src/dessert/deserialization/types.d.ts:394


children

readonly children: Children

Helper to access the node's children

Defined in

src/dessert/deserialization/types.d.ts:398


json

readonly json: Json

Helper for processing the node as JSON

Defined in

src/dessert/deserialization/types.d.ts:403


name

readonly name: string

Name of the node being deserialized

Defined in

src/dessert/deserialization/types.d.ts:375


property

readonly property: Property

Helper to access the node's properties

Defined in

src/dessert/deserialization/types.d.ts:389


run()

readonly run: <T, P>(deserializer, ...parameters) => T

Run the given deserializer

Type Parameters
Type Parameter
T
P extends unknown[]
Parameters
ParameterType
deserializerDeserializerFromContext<T, P>
...parametersP
Returns

T

Defined in

src/dessert/deserialization/types.d.ts:408


tag

readonly tag: null | string

Tag of the node being deserialized

Defined in

src/dessert/deserialization/types.d.ts:380


DocumentSerializationContext

Wrapper around a Document to help serializing a value or values into a Document

Properties

child()

readonly child: <P>(name, serializer, ...params) => void

Run the given serializer to create a node with the given name and add that node as child to the document being serialized

Type Parameters
Type Parameter
P extends unknown[]
Parameters
ParameterType
namestring
serializerSerializer<P>
...paramsP
Returns

void

tagged()

Run the given serializer to create a node with the given name and tag and add that node as child to the document being serialized

Type Parameters
Type Parameter
P extends unknown[]
Parameters
ParameterType
tagstring
namestring
serializerSerializer<P>
...paramsP
Returns

void

Defined in

src/dessert/serialization/types.d.ts:149


json()

readonly json: (value) => void

Serialize a JSON value

The allowed values are limited to only values that can be entirely serialized into nodes placed inside the document. For example, a string value would be added as argument but a document can't have arguments.

Parameters
ParameterType
valueJsonObject | JsonValue[]
Returns

void

Defined in

src/dessert/serialization/types.d.ts:175


run()

readonly run: <P>(serializer, ...parameters) => void

Run the given serializer

Type Parameters
Type Parameter
P extends unknown[]
Parameters
ParameterType
serializerDocumentSerializer<P>
...parametersP
Returns

void

Defined in

src/dessert/serialization/types.d.ts:180


source()

readonly source: (sourceCtx) => void

Link this serialization to a prior deserialization

Attaching a deserialization context as source to this serialization allows the serialization to keep track of metadata in the original text. For example, an effort is made to preserve formatting and comments.

Parameters
ParameterType
sourceCtxundefined | null | DeserializationContext
Returns

void

Defined in

src/dessert/serialization/types.d.ts:145


target

readonly target: "document"

Marker property that can be used to distinguish between a DocumentSerializationContext and SerializationContext.

Defined in

src/dessert/serialization/types.d.ts:137


Json()

Json(): undefined | JsonValue

Turn the remaining arguments, properties, and children into a JSON value

After calling this function, all remaining arguments, properties, and children of the context have been consumed. Further calls to any of the context's utilities will return undefined or throw, depending on how the utility handles an empty context.

Returns

undefined | JsonValue

Throws

If the context doesn't contain a valid JSON value

Defined in

src/dessert/deserialization/types.d.ts:333

Json<T>(...types): undefined | JsonTypeOf<T>

Turn the remaining arguments, properties, and children into a JSON value matching any of the given types

After calling this function, all remaining arguments, properties, and children of the context have been consumed. Further calls to any of the context's utilities will return undefined or throw, depending on how the utility handles an empty context.

Type Parameters

Type Parameter
T extends [JsonType, ...JsonType[]]

Parameters

ParameterType
...typesT

Returns

undefined | JsonTypeOf<T>

Throws

If the context doesn't contain a valid JSON value

Throws

If the deserialized value doesn't match any of the given types

Defined in

src/dessert/deserialization/types.d.ts:343

Methods

required()
Call Signature

required(): JsonValue

Turn the remaining arguments, properties, and children into a JSON value

After calling this function, all remaining arguments, properties, and children of the context have been consumed. Further calls to any of the context's utilities will return undefined or throw, depending on how the utility handles an empty context.

Returns

JsonValue

Throws

If the context doesn't contain a valid JSON value

Throws

If the context is empty

Defined in

src/dessert/deserialization/types.d.ts:354

Call Signature

required<T>(...types): JsonTypeOf<T>

Turn the remaining arguments, properties, and children into a JSON value matching any of the given types

After calling this function, all remaining arguments, properties, and children of the context have been consumed. Further calls to any of the context's utilities will return undefined or throw, depending on how the utility handles an empty context.

Type Parameters
Type Parameter
T extends [JsonType, ...JsonType[]]
Parameters
ParameterType
...typesT
Returns

JsonTypeOf<T>

Throws

If the context doesn't contain a valid JSON value

Throws

If the context is empty

Throws

If the deserialized value doesn't match any of the given types

Defined in

src/dessert/deserialization/types.d.ts:365


Property()

Property(name): undefined | Primitive

Return the property with the given name if it exists and it hasn't been returned yet

Parameters

ParameterType
namestring

Returns

undefined | Primitive

Defined in

src/dessert/deserialization/types.d.ts:109

Property<T>(name, ...types): undefined | TypeOf<T>

Return the property with the given name if it exists and it hasn't been returned yet

Type Parameters

Type Parameter
T extends [PrimitiveType, ...PrimitiveType[]]

Parameters

ParameterType
namestring
...typesT

Returns

undefined | TypeOf<T>

Throws

If the property value does not match any of the given types

Defined in

src/dessert/deserialization/types.d.ts:115

Methods

if()

if<T>(name, ...types): undefined | TypeOf<T>

Return the property with the given name if it exists and it hasn't been returned yet and its value has the correct type

Type Parameters
Type Parameter
T extends [PrimitiveType, ...PrimitiveType[]]
Parameters
ParameterType
namestring
...typesT
Returns

undefined | TypeOf<T>

Defined in

src/dessert/deserialization/types.d.ts:123


required()
Call Signature

required(name): Primitive

Return the property with the given name

Parameters
ParameterType
namestring
Returns

Primitive

Throws

If the property doesn't exist or it has already been returned

Defined in

src/dessert/deserialization/types.d.ts:133

Call Signature

required<T>(name, ...types): TypeOf<T>

Return the property with the given name

Type Parameters
Type Parameter
T extends [PrimitiveType, ...PrimitiveType[]]
Parameters
ParameterType
namestring
...typesT
Returns

TypeOf<T>

Throws

If the property doesn't exist or it has already been returned

Throws

If the property value does not match any of the given types

Defined in

src/dessert/deserialization/types.d.ts:140


rest()

rest(): Map<string, Primitive>

Return all remaining properties

Returns

Map<string, Primitive>

Defined in

src/dessert/deserialization/types.d.ts:148


SerializationContext

Wrapper around a Node to help serializing a value into a single Node

Properties

argument()

readonly argument: (value) => void

Add an argument to the serialized node

Parameters
ParameterType
valuePrimitive
Returns

void

tagged()

Add an argument with a tag to the serialized node

Parameters
ParameterType
tagstring
valuePrimitive
Returns

void

Defined in

src/dessert/serialization/types.d.ts:67


child()

readonly child: <P>(name, serializer, ...params) => void

Serialize a child node and add it to this serialized node

Run the given serializer to create a node with the given name and add that node as child to the node being serialized

Type Parameters
Type Parameter
P extends unknown[]
Parameters
ParameterType
namestring
serializerSerializer<P>
...paramsP
Returns

void

tagged()

Run the given serializer to create a node with the given name and tag and add that node as child to the node being serialized

Type Parameters
Type Parameter
P extends unknown[]
Parameters
ParameterType
tagstring
namestring
serializerSerializer<P>
...paramsP
Returns

void

Defined in

src/dessert/serialization/types.d.ts:96


json()

readonly json: (value) => void

Serialize a JSON value

Parameters
ParameterType
valueJsonValue
Returns

void

Defined in

src/dessert/serialization/types.d.ts:119


property()

readonly property: (name, value) => void

Set a property on the serialized node

If the same property was already set previously, the previous value is overwritten.

Parameters
ParameterType
namestring
valuePrimitive
Returns

void

tagged()

Set a property with a tag on the serialized node

If the same property was already set previously, the previous value is overwritten.

Parameters
ParameterType
tagstring
namestring
valuePrimitive
Returns

void

Defined in

src/dessert/serialization/types.d.ts:78


run()

readonly run: <P>(serializer, ...parameters) => void

Run the given serializer

Type Parameters
Type Parameter
P extends unknown[]
Parameters
ParameterType
serializerSerializerFromContext<P>
...parametersP
Returns

void

Defined in

src/dessert/serialization/types.d.ts:124


source()

readonly source: (sourceCtx) => void

Link this serialization to a prior deserialization

Attaching a deserialization context as source to this serialization allows the serialization to keep track of metadata in the original text. For example, an effort is made to preserve formatting and comments.

Parameters
ParameterType
sourceCtxundefined | null | DeserializationContext
Returns

void

Defined in

src/dessert/serialization/types.d.ts:63


target

readonly target: "node"

Marker property that can be used to distinguish between a DocumentSerializationContext and SerializationContext.

Defined in

src/dessert/serialization/types.d.ts:55

Type Aliases

Deserialized<T>

Deserialized<T>: T extends Deserializer<infer V, any[]> ? V : never

Helper type to extract the type a deserializer supports

Type Parameters

Type Parameter
T extends Deserializer<unknown, any[]>

Defined in

src/dessert/deserialization/types.d.ts:54


Deserializer<T, P>

Deserializer<T, P>: DeserializerFromContext<T, P> | { deserializeFromNode: T; }

Function or object capable of deserializing objects of type T

There are three types of deserializers:

All three variants can be parameterized. Parameters can be passed via deserialize or any of the child/children functions on a DeserializationContext

Type Parameters

Type ParameterDefault type
T-
P extends unknown[][]

Type declaration

DeserializerFromContext<T, P>

{ deserializeFromNode: T; }

deserializeFromNode()

Function that is given a Node

Parameters
ParameterType
nodeNode
...parametersP
Returns

T

Defined in

src/dessert/deserialization/types.d.ts:44


DeserializerFromContext<T, P>

DeserializerFromContext<T, P>: (ctx, ...parameters) => T | { deserialize: T; }

Function or object capable of deserializing objects of type T using a DeserializationContext

Type Parameters

Type ParameterDefault type
T-
P extends unknown[][]

Type declaration

(ctx, ...parameters) => T

Parameters

ParameterType
ctxDeserializationContext
...parametersP

Returns

T

{ deserialize: T; }

deserialize()

Function that is given a DeserializationContext

Parameters
ParameterType
ctxDeserializationContext
...parametersP
Returns

T

Defined in

src/dessert/deserialization/types.d.ts:26


DocumentSerializer<P>

DocumentSerializer<P>: (ctx, ...parameters) => void | { serialize: void; }

Function or object capable of serializing a Document

There are three types of serializers:

Both types can accept parameters, in which case these parameters have to be passed when calling serialize.

Type Parameters

Type Parameter
P extends unknown[]

Type declaration

(ctx, ...parameters) => void

Parameters

ParameterType
ctxDocumentSerializationContext
...parametersP

Returns

void

{ serialize: void; }

serialize()

Function that is given a DocumentSerializationContext

Parameters
ParameterType
ctxDocumentSerializationContext
...parametersP
Returns

void

Defined in

src/dessert/serialization/types.d.ts:41


JsonType

JsonType: PrimitiveType | "object" | "array"

String representation of the JsonValue types

Defined in

src/dessert/deserialization/types.d.ts:304


JsonTypeOf<T>

JsonTypeOf<T>: object[T[number]]

Helper type to turn JsonTypes into the corresponding JsonValue types

Type Parameters

Type Parameter
T extends JsonType[]

Defined in

src/dessert/deserialization/types.d.ts:309


PrimitiveType

PrimitiveType: "boolean" | "null" | "number" | "string"

String representation of the Primitive types

Defined in

src/dessert/deserialization/types.d.ts:7


Serializer<P>

Serializer<P>: SerializerFromContext<P> | { serializeToNode: Node; }

Function or object capable of serializing a Node

There are three types of serializers:

  • Functions that are given a SerializationContext
  • A value (usually a class instance) with a serialize function that is given a SerializationContext
  • A value (usually a class instance) with a serializeTNode function that returns a Node

All three of these types can accept parameters, in which case these parameters have to be passed when calling serialize.

Type Parameters

Type Parameter
P extends unknown[]

Type declaration

SerializerFromContext<P>

{ serializeToNode: Node; }

serializeToNode()

Function to serialize a Node of the given name

Parameters
ParameterType
namestring
...parametersP
Returns

Node

Defined in

src/dessert/serialization/types.d.ts:25


SerializerFromContext<P>

SerializerFromContext<P>: (ctx, ...parameters) => void | { serialize: void; }

Function or object capable of serializing via a SerializationContext

Type Parameters

Type Parameter
P extends unknown[]

Type declaration

(ctx, ...parameters) => void

Parameters

ParameterType
ctxSerializationContext
...parametersP

Returns

void

{ serialize: void; }

serialize()

Function that is given a SerializationContext

Parameters
ParameterType
ctxSerializationContext
...parametersP
Returns

void

Defined in

src/dessert/serialization/types.d.ts:8


TypeOf<T>

TypeOf<T>: object[T[number]]

Helper type to turn a list of PrimitiveTypes into matching Primitive types

Type Parameters

Type Parameter
T extends PrimitiveType[]

Defined in

src/dessert/deserialization/types.d.ts:12

Functions

concat()

concat(...docsAndNodes): Document

Create a document containing the given nodes in order

If documents are passed, all nodes from those documents will be inserted in order into the returned document.

Parameters

ParameterTypeDescription
...docsAndNodes(Node | Document)[]

Returns

Document

Defined in

src/dessert/serialization/public-utils.js:12


deserialize()

deserialize<T, P>(node, deserializer, ...parameters): T

Deserialize the given Document or Node using the given deserializer.

If this function is given a Document, it will be wrapped with a nameless node (using "-" as name) without any arguments or properties.

Type Parameters

Type ParameterDefault typeDescription
T-
P extends unknown[][]

Parameters

ParameterTypeDescription
nodeNode | Document
deserializerDeserializer<T, P>
...parametersP

Returns

T

Defined in

src/dessert/deserialization/deserialize.js:521


firstMatchingDeserializer()

firstMatchingDeserializer<T>(...deserializers): Deserializer<Deserialized<T[number]>>

Create a deserializer that tries all of the given deserializers until it finds one that doesn't throw an error.

The returned deserializer throws an AggregateError if all of the given deserializers throw on a certain node.

Type Parameters

Type ParameterDescription
T extends Deserializer<unknown>[]

Parameters

ParameterTypeDescription
...deserializersT

Returns

Deserializer<Deserialized<T[number]>>

Defined in

src/dessert/deserialization/public-utils.js:59


format()

format<P>(serializer, ...parameters): string

Serialize a KDL document and format it to a string

Type Parameters

Type ParameterDescription
P extends unknown[]

Parameters

ParameterTypeDescription
serializerDocumentSerializer<P>
...parametersP

Returns

string

Defined in

src/dessert/serialization/serialize.js:181


parse()

parse<T>(text, deserializer): T

Parse the given KDL text as a document and run it through the given deserializer

The deserializer will only have access to children, as a document has no arguments or properties.

This is a small function that runs parse and then runs the resulting Document through deserialize.

Type Parameters

Type ParameterDescription
T

Parameters

ParameterTypeDescription
textstring | ArrayBuffer | DataView | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array
deserializerDeserializer<T, []>

Returns

T

Defined in

src/dessert/deserialization/deserialize.js:650


repeat()

repeat<A, T>(fn, ...args): undefined | [T, ...T[]]

Call the given function with the given arguments until it returns undefined

This function returns all return values apart from the final undefined. If the given function returned undefined on the first call, this function returns undefined.

Type Parameters

Type ParameterDescription
A extends unknown[]
T

Parameters

ParameterTypeDescription
fn(...args) => undefined | T
...argsA

Returns

undefined | [T, ...T[]]

Defined in

src/dessert/deserialization/public-utils.js:20


serialize()

Call Signature

serialize<P>(name, serializer, ...params): Node

Create a node with the given name using the given serializer

Type Parameters
Type Parameter
P extends unknown[]
Parameters
ParameterTypeDescription
namestringThe name of the node
serializerSerializer<P>Serializer to call
...paramsPParameters to pass along to the serializer
Returns

Node

Defined in

src/dessert/serialization/types.d.ts:193

Call Signature

serialize<P>(name, serializer, ...params): Document

Create a document using the given serializer

The first parameter can be null or typeof Document. Passing null is easiest, but it won't work when using TypeScript with "strictNullChecks" disabled.

Type Parameters
Type Parameter
P extends unknown[]
Parameters
ParameterTypeDescription
namenull | typeof DocumentNull or a refernece to the Document class
serializerDocumentSerializer<P>Serializer to call
...paramsPParameters to pass along to the serializer
Returns

Document

Defined in

src/dessert/serialization/types.d.ts:208