Heap.Tuple
Declares a tuple field - a fixed-length array with specified types for each position.
Usage / Signature
import { Heap } from '@app/heap'
Heap.Tuple(elementsSchema, options)
Arguments
-
<b id="elementsSchema">elementsSchema</b>: HeapSchema
[]
<b style="color:red">*</b>
A list of schemas for the corresponding elements at each position in the tuple. This can be any supported field type of a heap table - simple or complex.Schemas with modifiers Heap.Optional and Heap.NonRequired are not supported and will result in a runtime error, as they do not make sense in this context.
-
<b id="options">options</b>:
{
default}
An object with additional optional parameters for the field.- <b id="default">default</b>:
array
The default value for this field. For more information on how default values work, see Guide / Heap / Default Values
- <b id="default">default</b>:
Return Value
A JSON schema for an array with a fixed length and element types.
Examples
Modeling a weight unit using Heap.Tuple
const weightSchema = Heap.Tuple([
Heap.Number({ minimum: 0 }),
Heap.Union([
Heap.Literal('gram'),
Heap.Literal('kilogram'),
Heap.Literal('ton'),
]),
])
const scales = Heap.Table('scales', {
minWeight: weightSchema,
maxWeight: weightSchema,
})
await scales.create(ctx, {
minWeight: [10, 'gram'],
maxWeight: [100, 'kilogram'],
})