Lists, Enums & Virtual Properties
Lists
An entity type can declare ordered sub-entity collections via has_list. This allows grouping child entities directly inside a parent entity's representation.
A relationship type and a trait can declare lists just the same: relationship instances and trait instances are entities, so a relationship payload carries its list items beside its edge properties.
Declaring a List
Each has_list relationship instance carries a name, label and description plus optional constraints:
| Field | Type | Required | Description |
|---|---|---|---|
name | system_name | yes | Identifier for the list |
label | localized map | yes | Display name |
description | localized map | no | Description |
min_items | int | no | Minimum number of items (0 = no lower bound) |
max_items | int | no | Maximum number of items (absent = unbounded) |
required | bool | no | The list must not be empty (an effective minimum of at least 1) |
is_ordered | bool | no | true (default) = the position of the items is significant; false = a set |
allow_duplicates | bool | no | true = the items of this list are exempt from the item type's uniqueness checks |
The target of the relationship is the entity type whose instances populate the list.
"has_list": [
{
"properties": {
"name": "ingredients",
"label": { "en_us": "Ingredients" },
"required": true,
"max_items": 20
},
"target": "entity_type/ingredient_item"
}
]
List Constraints
The constraints are checked when an entity is saved. A has_list without constraints behaves like an unconstrained list, so adding constraints to an existing model needs no data migration.
- Cardinality -- a save is rejected if the list ends up with fewer than
min_itemsitems (fewer than 1 withrequired) or more thanmax_items.max_itemsis checked only against additions: an edit that leaves an already over-full list as it is is not blocked, so tighteningmax_itemslater never blocks unrelated edits, and removing items brings the list back into line. - Uniqueness -- comes from the item type: a
uniqueproperty or the item key is already enforced per owner (see List Item Key Spaces). Withallow_duplicates: true, the same item may appear several times in this list; such items may share a key and are addressed only byroot_id. - Ordered vs. set --
is_orderedrecords whether the item order matters. In v1 the flag is stored, but an unordered list is not re-sorted. - Inheritance -- a child type that re-declares an inherited list should only tighten it (raise
min_items, lowermax_items, turn onrequired, dropallow_duplicates, keep the same target type or a subtype). In v1 this is not enforced: the child's declaration simply replaces the inherited one.
Wire Format
In entity responses, list contents appear under the lists field:
{
"lists": {
"ingredients": [
{
"id": "<uuid>",
"type_id": "<uuid>",
"root_id": "<uuid>",
"@key": "flour",
"properties": { "name": "Flour", "amount": 500 }
},
{
"id": "<uuid>",
"type_id": "<uuid>",
"root_id": "<uuid>",
"@key": "sugar",
"properties": { "name": "Sugar", "amount": 200 }
}
]
}
}
When creating or updating an entity, list items can be supplied inline:
{
"lists": {
"ingredients": [
{ "key": "flour", "properties": { "name": "Flour", "amount": 500 } },
{ "key": "sugar", "properties": { "name": "Sugar", "amount": 200 } }
]
}
}
Editing List Items
The lists field of a create or update request works in two modes. The same operations are also available as dedicated list routes (/lists/<name>, including /lists/<name>/@order for reordering), see the REST API Reference.
| Mode | Behaviour |
|---|---|
| Merge (default) | Items with a root_id are updated in place, items without one are appended, items named in remove_lists are removed. Existing items that are not mentioned are kept. |
| Replace | For a list named in replace_lists, the payload is authoritative: its order is taken over, and existing items missing from the payload are removed. |
To reorder a list, use replace mode and list the existing items as { "root_id": … } stubs in the new order: the items keep their identity, and only the parent gets a new commit.
{
"lists": { "ingredients": [ { "root_id": "<sugar>" }, { "root_id": "<flour>" } ] },
"replace_lists": ["ingredients"]
}
Editing a list is a content change: it is blocked by a read-only or released lifecycle status, creates a new commit of the parent on the active branch only, and appears in the history even if the parent's own properties did not change.
List Item Key Spaces
List items are owned sub-entities: they belong to the parent (by root_id) and are part of the parent's manifest with an explicit position (see Ownership and Manifests). List item keys are scoped to a sub key space tied to (list-item type, owner entity). A list item keyed step1 under procedure/A does not collide with step1 under procedure/B. See Key Spaces for the full model.
Enums
An enum is a fixed set of named values. Enums are implemented as entities, which means they are versioned, queryable, and can be extended without breaking existing data. Three entities are involved:
enums/<name> the definition
└── entries[] list of enum_entry -- the valid values
enum_property_type/<name> enum_ref ──▶ enums/<name>
entity_type/<name> has_prop ──▶ enum_property_type/<name>
The enums Entity
An enum definition:
| Field | Required | Description |
|---|---|---|
name | yes | System identifier, unique. Also the key, so the entity is addressed as enums/<name> |
label | yes | Localized display name |
description | no | Localized description |
The valid values are its entries list (has_list → entity_type/enum_entry).
The enum_entry Entity
An individual value within an enum. Enum entries are list items of their enums entity.
| Field | Required | Description |
|---|---|---|
value | yes | The string used in the API (system name). Unique within the enum, and also the entry's key |
label | yes | Localized display name |
int_value | no | Integer mapping for the value |
int_value and int_mappingUse int_value for everything created through the API -- sending int_mapping is rejected. The built-in enums shipped with EP carry the same information in a property named int_mapping, so entries read back from those differ.
Creating an Enum
Create the definition and its entries in one request -- entries is a list, so the entries are written in line. No key is needed; it is derived from name (and each entry's key from its value).
POST /api/v1/by-type/enums
{
"properties": {
"name": "fruit_color",
"label": { "en_us": "Fruit Color" }
},
"lists": {
"entries": [
{ "properties": { "value": "red", "label": { "en_us": "Red" }, "int_value": 0 } },
{ "properties": { "value": "green", "label": { "en_us": "Green" }, "int_value": 1 } },
{ "properties": { "value": "yellow", "label": { "en_us": "Yellow" }, "int_value": 2 } }
]
}
}
Entries can be added, edited, reordered and removed later through the list routes of the enums entity (/lists/entries).
Creating an enum_property_type
An enum_property_type entity links a property type to a specific enums definition via its enum_ref property:
{
"type_name": "entity_type/enum_property_type",
"key": "fruit_color",
"properties": {
"name": "fruit_color",
"label": { "en_us": "Fruit Color" },
"enum_ref": "enums/fruit_color"
}
}
The order matters: each reference is resolved when it is saved, so the enum must exist before the property type, and the property type before the entity type that uses it.
Wire Format
Both input and output use the plain string value:
{ "properties": { "color": "red" } }
Internally, the engine resolves the string "red" to the stable root_id of the matching enum_entry and stores that reference. On read, it is resolved back to the value string. A value that matches no entry fails the whole write. See Enum Properties for the read and write rules.
Using an Enum Property
Declare it on an entity type via has_prop:
"has_prop": [
{
"properties": { "name": "color", "label": { "en_us": "Color" } },
"target": "enum_property_type/fruit_color"
}
]
The property name on the instances (color) is independent of the property type's name (fruit_color), so one enum property type can back differently named properties on many entity types. See Property Types for more details.
Built-in Enums
| Reference | Values | Used by |
|---|---|---|
enums/hook_event | on_create, on_update, on_status_change | has_hook.event |
enums/hook_type | pre, post | has_hook.type |
Evolving a Value Set
| Change | Effect on existing data |
|---|---|
| Add an entry | Safe. The new value is accepted on writes immediately |
| Reorder entries | Safe. The order is for presentation only |
Edit an entry's label or int_value | Safe. Entities refer to the entry's root_id |
| Remove an entry | Entities that use it keep an unresolvable reference and show that property as null. Check first: GET …/enums/<name>/@referenced-by lists the property types that use the enum, and a search on each of those properties finds the entities that still hold the value |
Rename an entry's value | Avoid. See below |
Renaming the value of an entry that is already in use makes reading and writing disagree: writes require the new string, but reads keep showing the old string. Add a new entry and migrate the entities instead.
Virtual Properties
An entity type can declare computed, read-only properties via has_virtual_prop. A Lua script computes the value when the entity is saved: on every create and update, the script runs and its result is stored together with the regular properties (without an extra commit). Nothing is computed on read; read-only means that a caller cannot supply the value.
Declaration
Each has_virtual_prop instance carries:
| Field | Description |
|---|---|
name | Property identifier |
label | Localized display name |
description | Localized description |
script | Lua script; return value is the computed property value |
The target of the relationship defines the output type (e.g. string_property_type/generic).
"has_virtual_prop": [
{
"properties": {
"name": "adjusted_weight",
"label": { "en_us": "Adjusted Weight" },
"script": "return tostring(self.properties[\"weight\"] * 2)"
},
"target": "string_property_type/generic"
}
]
Behavior
- Virtual properties appear in entity responses alongside regular properties.
- They cannot be set or updated directly -- they are computed from the entity's state at the time it is saved.
- Because the value is stored, a virtual property can be filtered and sorted in search like a regular property. GraphQL, however, returns
nullfor it. - A virtual property can be stale: it reflects its inputs as of the last save of this entity. If the script reads properties of a related entity, it is not recomputed when that other entity changes.
- The
selfvariable in the script refers to the current entity instance. A virtual property script cannot change entities. See Lua Scripting for the scripting reference.
Aggregating Over Relationship Targets
A script may read the virtual properties of its relationship targets -- for example a folder's size that sums up rel.target.properties["size"] of its files. Within one save, the targets' virtual properties are computed before the entity that aggregates over them, so the roll-up also works when the targets are created in line in the same request, at any nesting depth.
A target that already exists is read as it is: pointing a new relationship at it does not re-run the target's own script.
Virtual properties are useful for derived values, formatted display strings, or calculations that depend on multiple properties of the same entity.