Heap.Object
Declares an object field with a specified structure.
Usage / Signature
import { Heap } from '@app/heap'
Heap.Object(propertiesSchema, options)
Arguments
-
<b id="propertiesSchema">propertiesSchema</b>:
{ [key: string]: HeapSchema }
<b style="color:red">*</b>
An object where the keys are the names of the object's fields and the values are schemas that describe their types.Field names can only contain Latin letters (both lowercase and uppercase), digits, the underscore (
_
) character, and must not start with a digit.The values can be any supported schemas that can be declared using the Heap functions (except those that declare/modify entire tables).
Modifiers Heap.Optional, Heap.NonRequired (and its derivative - Heap.Nullable) are exclusively intended for object fields (including top-level table fields) and cannot be applied elsewhere.
-
<b id="options">options</b>:
{
default}
An object with additional optional parameters for the field.- <b id="default">default</b>:
object
The default value for this field. For more information on how default values work, see Guide / Heap / Default Values
The
additionalProperties
property from JSON schema is not supported. If an object is provided with fields that are not listed in the schema, such "extra" fields will be ignored and will not be written to or read from storage. - <b id="default">default</b>:
Return Value
JSON schema for the object.
Examples
Simple nested object with three fields with modifiers
const issues = Heap.Table('issues', {
owner: Heap.Object({
name: Heap.String(),
role: Heap.NonRequired(Heap.Enum(IssueOwnerRole), IssueOwnerRole.Employee),
rank: Heap.Optional(Heap.Number()),
}),
})