state — Entity Schema

Defines entity types and their field schemas. Each state entry becomes a stream (<name>_stream) in the runtime.

state:
  user:
    entity_key: user_id          # field name used as the entity ID
    description: "App user"      # optional
    fields:
      - name: username
        type: string
        default: ""
      - name: following_count
        type: int
        default: 0
      - name: tags
        type: array
        item_type: string
        default: []
      - name: metadata
        type: object
        default: {}
      - name: preferences/notifications
        type: boolean
        default: true
      - name: cart/items
        type: array
        item_type: object
        item_fields:
          product_id: { type: string, required: true }
          quantity:   { type: int,    required: true }
        default: []
      - name: _tmp/pending_tx    # scratch space; never exposed in ledger
        type: any

Field types

TypeDescriptionDefault example
stringText string""
int / integerInteger number0
number / decimal / floatFloating-point0
booleanBooleanfalse
arrayList; requires item_type[]
objectMap/object{}
datetimeISO datetime string""
anyNo type validationnull

Arrays must declare item_type. When item_type: object, also declare item_fields with { type, required? } per field.

⚠️

Always declare default: — omitting it leaves the field null. contains(null, x) throws; size(null) returns 0 in some paths and errors in others.

Field path notation

In state definitions, use slash paths for nested fields: preferences/notifications becomes /preferences/notifications for ops and entity.preferences.notifications in expressions.