Skip to content

Aeria Schema

Schemas in Aeria are defined using a superset of JSON Schema with framework-specific attributes. Schemas used to define the data structure of collections are referred to as descriptions.

JSON Schema

$id

As in JSON Schema, this property is used to name the structure we are defining. It must have the same name as the collection. Collection names must consist of a camel-cased noun in the singular, like person, fruit or car. In Aeria Lang this property is implicit.

required

aeria
collection Example {
  required {
    name
    document
    // legal responsible is only required if age is lesser than 18 on insertion
    legal_responsible @cond(age < 18)
  }
}
typescript
defineCollection({
  description: {
    required: {
      name: true
      document: true,
      document: {
        if: {
          operator: 'lt',
          term1: 'age',
          term2: 18,
        },
      },
    },
  },
})
typescript
type RequiredProperties<TDescription extends Description> = readonly PropertiesWithId<TDescription>[] | Partial<Record<
  PropertiesWithId<TDescription>,
  Condition<TDescription> | boolean
>>

This property is used to verify document wholeness upon creation and update. Case set to an array of strings, will consider only specified properties to validate document wholeness, otherwise will check if all properties are not null or undefined.

properties Record<string, Property>

The properties contained in the collection. Properties are described in a separate section.

Description

actions CollectionActions<TDescription>? frontend

Actions that aren't associated with a single database entry.

aeria
collection Example {
  actions {
    add {
      label "Add new entry"
    }
  }
}
typescript
defineCollection({
  description: {
    actions: {
      add: {
        label: 'Add new entry',
      },
    },
  },
})
typescript
type CollectionActionRoute = {
  route: {
    name: string
    setItem?: boolean
    fetchItem?: boolean
    clearItem?: boolean
    params?: Record<string, unknown>
    query?: Record<string, unknown>
  }
}

type CollectionActionFunction = {
  function?: string
  selection?: boolean
  effect?: string
}

type CollectionActionEvent = {
  event?: string
}

type CollectionActionBase<TDescription extends Description> = {
  label?: string
  icon?: Icon
  ask?: boolean
  translate?: boolean
  roles?: readonly string[]
  requires?: readonly PropertiesWithId<TDescription>[]
}

export type CollectionAction<TDescription extends Description> = CollectionActionBase<TDescription> & (
  | CollectionActionRoute
  | CollectionActionFunction
  | CollectionActionEvent
)

export type CollectionActions<TDescription extends Description> = Record<
  string,
  | CollectionAction<TDescription> & {
    button?: boolean
  }
  | null
>

filters frontend

This property is used to control a filter widget rendered inside the aeria-crud component. If set, a filter button will appear, otherwise no filter functionallity will be made available.

The array passed to this property can contain two types of elements, either a string representing a property name, or an object containing both the property name and a default filter.

aeria
collection Example {
  filters {
    name
  }
}
typescript
defineCollection({
  description: {
    filters: [
      'name',
    ],
  },
})
typescript
type DescriptionFilters = readonly (PropertiesWithId<TDescription> | {
  property: PropertiesWithId<TDescription>
  default: string
})[]

filtersPresets Record<string, FiltersPreset<TDescription>>? frontend

aeria
collection Example {
  filtersPresets {
    active {
      label "Active"
      filters {
        active true
      }
    }
  }
}
typescript
defineCollection({
  description: {
    filtersPresets: {
      active: {
        label: 'Active',
        filters: {
          active: true,
        },
      },
    },
  },
})
typescript
type FiltersPreset<TDescription extends Description> = {
  label?: string
  icon?: string
  filters: Partial<Record<PropertiesWithId<TDescription> | `$${string}`, any>>
  table?: Array<PropertiesWithId<TDescription>>
  badgeFunction?: string
  default?: boolean
}

type FiltersPresets<TDescription extends Description> = Record<string, FiltersPreset<TDescription>

form frontend

If set, runtime generated forms will render only specified properties. Otherwise all properties are rendered.

WARNING

This property alone won't keep any of non-specified collection properties to be written. If you need to make properties read-only, use the writable property in an exclusive manner.

aeria
collection Example {
  form {
    name
    document
  }
}
typescript
defineCollection({
  description: {
    form: [
      'name',
      'document',
    ],
  },
})
typescript
type Form = readonly PropertiesWithId<TDescription>[] | Record<PropertiesWithId<TDescription>, string[]>

formLayout Partial<FormLayout<TDescription>>? frontend

This property controls how inputs should be dynamically rendered inside frontend forms.

aeria
collection Example {
  formLayout {
    fields {
      responsible @if(age == 18)
    }
  }
}
typescript
defineCollection({
  description: {
    formLayout: {
      fields: {
        responsible: {
          if: {
            operator: 'lt',
            term1: 'age',
            term2: 18,
          }
        }
      }
    },
  },
})
typescript
type FormLayout<TDescription extends Description> = {
  fields?: Partial<Record<PropertiesWithId<TDescription>, FormLayoutField<TDescription>>>
}

type FormLayoutField<TDescription extends Description> = {
  span?: number
  verticalSpacing?: number
  separator?:
    | true
    | 'top'
    | 'bottom'
  if?: Condition<TDescription>
  component?: {
    name: string
    props?: Record<string, any>
  }
}

icon string? frontend

This property may be used to specify an icon from an icon library to be associated with the collection in the frontend. It will be shown on navbars, breadcumbs, etc.

aeria
collection Example {
  icon "file"
}
typescript
defineCollection({
  description: {
    icon: 'file',
  },
})
typescript
type SearchOptions<TDescription extends Description> = {
  placeholder?: string
  indexes: readonly (keyof TDescription['properties'])[]
}

immutable (boolean | readonly string[])?

This property may be used to specify properties that should be writable upon creation, but read-only upon update. If set to true, then will enable immutability to all properties, if set to an array of strings, only specified properties will receive that attribute.

aeria
collection Example {
  immutable {
    status
  }
}
typescript
defineCollection({
  description: {
    immutable: [
      'status',
    ],
  },
})
typescript
type DescriptionImmutable<TDescription extends Description> =
  | boolean
  | readonly (keyof TDescription['properties'])[]
  | ((doc: WithId<any>)=> boolean | Promise<boolean>)

indexes readonly string? frontend

This optional property may be used to specify an icon from an icon library to be associated with the collection in the frontend. It will be shown on navbars, breadcumbs, etc.

aeria
collection Example {
  indexes {
    name
    document
  }
}
typescript
defineCollection({
  description: {
    indexes: [
      'name',
      'document',
    ],
  },
})
typescript
type DescriptionIndexes = readonly PropertiesWithId<TDescription>[]

individualActions CollectionIndividualActions<TDescription>? frontend

Actions associated with a single database entry. In a tabular layout, these are displayed inside a dropdown in the last column.

aeria
collection Example {
  individualActions {
    remove {
      label "Remove"
    }
  }
}
typescript
defineCollection({
  description: {
    individualActions: {
      remove: {
        label: 'Remove',
      },
    },
  },
})
typescript
type CollectionIndividualActions<TDescription extends Description> =
  Record<string, CollectionAction<TDescription> | null>

owned (boolean | 'always')?

This property is used to control the access of user-owned resources. If set to true or 'always' in a description, users will only be able to view and edit resources created by themselves.

aeria
collection Example {
  owned true
}
typescript
defineCollection({
  description: {
    owned: true,
  },
})
typescript
type OwnershipMode =
  | boolean
  | 'always'
  | 'on-write'

type DescriptionOwned = OwnershipMode

table readonly PropertiesWithId<TDescription>? frontend

This property is used exclusively by the frontend. Case set to an array of strings, will specify properties to be used as columns in aeria-crud component. Otherwise all properties will be used.

NOTE

In the frontend, Aeria will smartly request only required properties in order to make network payloads lighter. This is specialy important in runtime generated views. If you need to use a property that isn't set as a column inside your view, please add the tableMeta property.

aeria
collection Example {
  table {
    name
    document
  }
}
typescript
defineCollection({
  description: {
    table: [
      'name',
      'document',
    ],
  },
})
typescript
type DescriptionTable = readonly PropertiesWithId<TDescription>[]

tableMeta readonly PropertiesWithId<TDescription>[]? frontend

If set, grid and tabular runtime generated views will request the specified properties alongside the ones specified in table.

aeria
collection Example {
  tableMeta {
    extra_property
  }
}
typescript
defineCollection({
  description: {
    tableMeta: [
      'extra_property',
    ],
  },
})
typescript
type DescriptionTableMeta = readonly PropertiesWithId<TDescription>[]

timestamps false?

This property should only be used to disable automatic timestamps in a certain collection (created_at and updated_at). Timestamps are always enabled by default.

aeria
collection Example {
  timestamps false
}
typescript
defineCollection({
  description: {
    timestamps: false,
  },
})
typescript
type DescriptionTimestamps = false

layout Layout?

Specifies a layout to override the default tabular one.

aeria
collection Example {
  layout {
    name "tabular"
    options {
      title title
    }
  }
}
typescript
defineCollection({
  description: {
    layout: {
      name: 'tabular',
      options: {
        title: 'title,'
      },
    },
  },
})
typescript
type LayoutName =
  | 'tabular'
  | 'grid'
  | 'list'

type LayoutOptions<TDescription extends Description = any> = {
  picture?: PropertiesWithId<TDescription>
  title?: PropertiesWithId<TDescription>
  badge?: PropertiesWithId<TDescription>
  information?: PropertiesWithId<TDescription>
  active?: PropertiesWithId<TDescription>
  translateBadge?: boolean
}

type Layout<TDescription extends Description = any> = {
  name: LayoutName
  options?: LayoutOptions<TDescription>
}

preset readonly CollectionPresets[]?

Merges a description preset into the current one. To see what each preset contains please head to the source code.

aeria
collection Example {
  presets {
    crud
    view
  }
}
typescript
type DescriptionPreset =
  | 'crud'
  | 'duplicate'
  | 'remove'
  | 'removeAll'
  | 'owned'
  | 'timestamped'
  | 'view'

writable readonly PropertiesWithId<TDescription>[]?

If set, all properties except the one specified will be made read-only. Trying writing on them will trigger an Access Control error.

aeria
collection Example {
  writable {
    name
    document
  }
}
typescript
defineCollection({
  description: {
    writable: [
      'name',
      'document',
    ],
  },
})
typescript
type DescriptionWritable = readonly PropertiesWithId<TDescription>[]

Activates a search bar in the frontend that will perform a MongoDB $text query.

aeria
collection Example {
  search {
    placeholder "Something"
    indexes {
      name
      document
    }
  }
}
typescript
defineCollection({
  description: {
    search: {
      placeholder: 'Something',
      indexes: [
        'name',
        'document',
      ],
    },
  },
})
typescript
type DescriptionSearch<TDescription extends Description> = {
  placeholder?: string
  indexes: readonly (keyof TDescription['properties'])[]
}

Released under the MIT License.