Heap.Array
Declares a field-array (js array) of homogeneous elements.
Usage / Signature
import { Heap } from '@app/heap'
Heap.Array(elementSchema, options)
Arguments
-
elementSchema:
{ HeapSchema }
A schema that describes the type of elements in the array. 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 lead to a runtime error, as they do not make sense in this context.
-
options:
{default, minItems, maxItems, uniqueItems}
An object with additional optional parameters for the field. -
default:
array
The default value for this field. For more information on how default values work, see Guide / Heap / Default Values. -
minItems:
number
Validation for the minimum length of the array. -
maxItems:
number
Validation for the maximum length of the array. -
uniqueItems:
boolean
Validation for the uniqueness of the array elements. Uniqueness is checked using "deep" comparison. For safety, this parameter should only be used in conjunction withmaxItems.
Return Value
JSON Schema for the array field.
Examples
Array of strings with a default value
const customers = Heap.Table('customers', {
searchHistory: Heap.Array(Heap.String(), { default: ['start'] }),
})
Array of objects with a specified structure
const issues = Heap.Table('issues', {
checklist: Heap.Array(
Heap.Object({
title: Heap.String(),
done: Heap.Boolean(),
}),
),
})
await issues.create(ctx, { checklist: [
{ title: 'first', done: false },
{ title: 'second', done: true },
]})