Skip to main content
Version: Next

Components (Structured Entities)

An entity type can own embedded, typed sub-entities via has_component. Such an entity is called a structured entity.

The three ways to connect entities differ in ownership:

MechanismDeclared withWhat it holds
Relationshiphas_relA link to an independent entity that exists on its own
Listhas_listAn ordered collection of owned sub-entities
Componenthas_componentExactly one owned sub-entity per name

A component is created, versioned and deleted together with its owner, addressed only through it, and validated as a whole. Use it for a composed value with internal rules that must never be shared or left behind -- for example the delivery address { street, number, zip } of a sales order: required as a unit, owned by the order, never created, referenced or orphaned on its own.

Declaring a Component​

Each has_component relationship instance carries:

FieldTypeRequiredDescription
namesystem_nameyesName of the component on the owner
labellocalized mapyesDisplay name
descriptionlocalized mapnoDescription
requiredboolnotrue = exactly one (1..1); otherwise optional (0..1)

The target is the entity type of the component.

"has_component": [
{
"properties": { "name": "delivery_address", "label": { "en_us": "Delivery Address" }, "required": true },
"target": "entity_type/address"
},
{
"properties": { "name": "invoice_address", "label": { "en_us": "Invoice Address" } },
"target": "entity_type/address"
}
]

Embeddable-Only Types​

Any entity type can be used as a component. A type marked embeddable_only: true is a strict value object: it can only be embedded -- it can never be created as a top-level entity or used as the target of a reference. This guarantees that its instances are always owned, never shared and never orphaned.

Wire Format​

Components appear in the components field of an entity -- one object per name:

"components": {
"delivery_address": { "type_id": "<address>", "properties": { "street": "Main", "zip": "1010" } },
"invoice_address": null
}

The GET …/components route always returns every declared name; an optional component that is not set is null.

v1

The full entity read (GET …/<key>) currently includes only the components that are set -- an unset optional component is omitted instead of shown as null. Use GET …/components for the complete set of names.

Writing Components​

On create or update, the components field patches each supplied component in place: the fields you send are merged, unmentioned components are carried forward. An explicit null -- or the name listed in remove_components -- clears an optional component. A required component cannot be cleared.

{
"components": {
"delivery_address": { "properties": { "zip": "1020" } },
"invoice_address": null
}
}

A component payload carries no key, type_name or root_id: its type is fixed by the declaration. The same edits are available through the component routes (/components/<name>), see the REST API Reference.

Editing a component is a content change: it is blocked by a read-only or released lifecycle status of the owner, and it creates a new commit of the owner on the active branch.

Ownership and Keys​

Components are owned sub-entities, like list items: they belong to the owner (by root_id), are part of the owner's manifest, and their key space is scoped to (component type, owner) and keyed by the component name (see Ownership and Manifests and Key Spaces).

A child type that re-declares an inherited component should only tighten it (for example make it required). In v1 this is not enforced: the child's declaration simply replaces the inherited one.