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: anyField types
| Type | Description | Default example |
|---|---|---|
string | Text string | "" |
int / integer | Integer number | 0 |
number / decimal / float | Floating-point | 0 |
boolean | Boolean | false |
array | List; requires item_type | [] |
object | Map/object | {} |
datetime | ISO datetime string | "" |
any | No type validation | null |
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.