Properties
A intersection of JSON Schema data types Aeria can validate and store.
ObjectProperty
This type of property is used to create denormalized subschemas that will be validated on runtime. Unlike RefProperty
, which is another way of storing data structures, it inserts the actual object instead of it's identifier, and doesn't require a collection.
Example:
error {
properties {
code str
message str
}
}
{
error: {
type: 'object',
properties: {
code: {
type: 'string'
},
message: {
type: 'string'
}
}
}
}
{
error: {
code: '001',
message: 'file not found'
}
}
type
'object'
Object properties are distinguished by the type
property set to 'object'
. It can either specify a fixed data structure with properties
or make a variable Map<string, T>
with additionalProperties
.
properties
Record<string, Property>
StringProperty
Example:
name str @maxLength(20)
{
name: {
type: 'string',
maxLength: 20,
}
}
{
name: 'Terry Davis'
}
type
'string'
String properties are distinguished by the type
property set to 'string'
. Dates also use the same type, but they are set apart by the format
attribute.
minLength
number?
This property sets a minimal string length.
maxLength
number?
This property sets a maximal string length.
element
string?
The element with which the input should be rendered. Whether "input"
or "textarea"
.
format
PropertyFormat?
The following text is quoted directly from json-schema.org: "The format keyword allows for basic semantic identification of certain kinds of string values that are commonly used. For example, because JSON doesn't have a "DateTime" type, dates need to be encoded as strings. format allows the schema author to indicate that the string value should be interpreted as a date".
type PropertyFormat =
| 'date'
| 'date-time'
inputType
PropertyInputType? frontend
When applicable, this property specifies a custom input type to be passed to the HTML <input />
element.
type PropertyInputType =
| 'text'
| 'email'
| 'password'
| 'search'
| 'time'
| 'month'
mask
(string | readonly string[])?
This property specifies one or more masks to be applied to the input.
placeholder
string?
The placeholder text rendered inside the input.
NumberProperty
Example:
rating num @minimum(5) @maximum(5)
{
rating: {
type: 'number',
minimum: 5,
maximum: 5,
}
}
{
rating: 5
}
type
'number' | 'integer'
This property is used to represent JS-native numbers. It can also specify integers only, in which case runtime validators will be used.
minimum
number?
This property ensures number will be greater than specified value, inclusively.
maximum
number?
This property ensures number will be less than specified value, inclusively.
exclusiveMinimum
number?
This property ensures number will be greater than specified value, exclusively.
exclusiveMaximum
number?
This property ensures number will be less than specified value, exclusively.
placeholder
string?
The placeholder text rendered inside the input.
BooleanProperty
Example:
active bool
{
active: {
type: 'boolean'
}
}
{
active: true
}
type
'boolean'
Boolean properties are distinguished by the type
property set to 'boolean'
RefProperty
Example:
company Company @indexes(["name", "headquarters"])
{
company: {
$ref: 'company',
indexes: [
'name',
'headquarters'
]
}
}
{
company: {
_id: ObjectId('...'),
name: 'ACME Co.',
headquarters: [
'Baltimore'
]
}
}
$ref
string
A string containing the name of the target collection as in $id
.
indexes
readonly string[]?
This property specifies indexes to be used when searching documents from the target collection in case default indexes are missing.
populate
readonly string[]?
By default, Aeria populates only properties specified by indexes
, but there are cases where you need to populate a property that isn't a index. You may pass those properties into populate
array.
inline
boolean?
This attribute determines the reference is always linked to the parent document, meaning it is updated when the parent document is updated, and deleted when parent document is deleted. Setting it to true
will make Aeria UI embed the referenced document in forms instead of providing the default search panel.
constraints
Condition<any>?
Sometimes reference properties need to have constraints to make them useful. Constraints are conditions applied when inserting documents from the referenced collection into the property. Constraints allow you to have
Example:
{
herbivore_animals: {
$ref: 'animals',
constraints: {
operator: 'equal',
term1: 'herbivore',
term2: true,
}
}
}
FileProperty
Example:
picture File @accept(["image/*"])
{
picture: {
$ref: 'file',
accept: [
'image/*'
]
}
}
{
picture: {
_id: ObjectId('...'),
name: 'picture.jpg',
link: 'https://example.com/api/file/...',
download_link: 'https://example.com/api/file/...',
}
}
$ref
'file'
File properties are ultimately reference properties that have $ref
set to 'file'
. Aeria will be able to tell the property is a file in the runtime and the frontend should render a file component accordingly.
accept
readonly string[]?
This read-only array of strings may contain accepted mime types. Wildcards such as image/*
are accepted.
EnumProperty
Example:
status enum @options([
"pending",
"paid",
"refused",
"chargeback"
])
{
status: {
enum: [
'pending',
'paid',
'refused',
'chargeback'
]
}
}
{
status: 'pending'
}
enum
readonly any[]
Enum properties specify an array of valid elements that will be validated upon insert. The elements of the enum must be of a scalar type. Passing objects will fail at runtime because references will be compared instead of actual value.
ArrayProperty
Example:
items []{
properties {
product Product
quantity int @minimum(1)
}
}
{
items: {
type: 'array',
items: {
type: 'object',
properties: {
product: {
$ref: 'product'
},
quantity: {
type: 'integer',
minimum: 1
}
}
}
}
}
{
items: [
{
product: {
_id: ObjectId('...'),
name: 'Product 1'
},
quantity: 1
},
{
product: {
_id: ObjectId('...'),
name: 'Product 2'
},
quantity: 3
}
]
}
type
'array'
Array properties are properties which type is set to 'array'
. Additionally, the items
property is required to type the elements of the array.
items
Property?
This property defines the schema of array elements.
ConstProperty
Example:
error const @value(true)
message str
{
error: {
const: true
},
message: {
type: 'string'
}
}
{
error: true,
message: 'there was an error'
}
const
any
The literal value the property expects.
GetterProperty
Example:
{
full_name: {
getter: (doc: any) => {
return `${doc.first_name} ${doc.full_name}`
}
}
}
{
full_name: 'Terry'
}
getter
(doc: any) => any
The getter function. In TypeScript, the doc
parameter must be explicitly annotated to any
.
PropertyBase
default
any?
If set to any value, the value of this property will be preferred over null or undefined on document creation.
description
string?
If set to a string, the value of this property will be preferred when displaying the property name on form labels. Otherwise an internationalized version of the property name will be used.
readOnly
boolean?
If true, will make the property unwritable on document creation and update. Trying to write on it won't return any error, the new value will just be ignored instead.
focus
boolean?
Signals the input of this property should be focused as soon as a form is rendered. Each form may have only one property with this flag enabled.
hidden
boolean?
If true, omits the value of this property from backend response.
WARNING
This attribute will take effect only if the document is returned from one of the collection functions (get
, getAll
, insert
, etc). If you query the document(s) using the MongoDB interface directly then the property value will still be returned and you should omit it manually.
hint
string?
If set to a string, this property will exhibit a small text underneat form inputs, regardless of the input type.
icon
string?
This property assigns an icon from an icon library to the property. It will be shown inside inputs and wherever applicable.
noForm
boolean?
If set to true will prevent the input of this property from being displayed on forms.
WARNING
Like the Description form
property, this flag won't make the property read-only. If aside from hiding the property in forms you want to ensure it won't be changed by crafted requests, you should use the Description writable
property in an exclusive manner.
noLabel
boolean?
If set to true will prevent a label containing the property name or description from being displayed on forms.
translate
boolean?
This property defines whether or not the value of the input should be internationalized when displayed. Defaults to false.