Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Attributes

An attribute is a relation elevated with type and cardinality constraints. Where a raw claim like com.app.person/name just associates a value with an entity, an attribute says: “this relation accepts Text values and each entity has exactly one.”

Attributes are the building blocks of concepts.

Defining Attributes

Via the CLI

carry assert attribute @person-name \
  the=com.app.person/name \
  as=Text \
  cardinality=one \
  description="Name of a person"

The @person-name creates a bookmark so you can reference this attribute by name later.

Via YAML

person-name:
  attribute:
    description: Name of a person
    the: com.app.person/name
    as: Text
    cardinality: one

The top-level key (person-name) becomes the bookmark name.

Attribute Fields

FieldRequiredDescription
theYesThe relation identifier – domain/name format
asYesThe value type (see below)
cardinalityNoone (default) or many
descriptionYesHuman-readable description

Value Types

TypeDescriptionExample Values
TextUTF-8 string"Alice", "hello world"
UnsignedIntegerNon-negative integer0, 28, 1000
SignedIntegerSigned integer-5, 0, 42
FloatFloating-point number3.14, -0.5
BooleanTrue or falsetrue, false
SymbolA namespaced constantcarry.profile/work
EntityReference to another entitydid:key:z...
BytesRaw binary data(binary)

You can also specify an enumeration of allowed symbols:

task-status:
  attribute:
    description: Current status of a task
    the: com.app.task/status
    as: [":todo", ":in-progress", ":done"]
    cardinality: one

Cardinality

  • one – Each entity has at most one value for this attribute. Asserting a new value replaces the old one.
  • many – Each entity can have multiple values. Asserting adds to the set; retracting a specific value removes it.
# A person has one name
person-name:
  attribute:
    description: Name
    the: com.app.person/name
    as: Text
    cardinality: one

# A recipe can have many ingredients
recipe-ingredient:
  attribute:
    description: An ingredient in the recipe
    the: diy.cook/ingredient
    as: Entity
    cardinality: many

Attribute Identity

Two attributes with the same relation identifier (the) but different type or cardinality are distinct entities. The attribute’s DID is derived from the hash of (relation_id, type, cardinality). The description does not affect identity.

This means you can have, for example, both a Text version and an Entity version of the same relation, and they will be treated as different attributes.

Querying Attributes

# List all defined attributes
carry query attribute

# Find a specific attribute by name
carry query attribute the=com.app.person/name