Business objects
Declaration
Section titled “Declaration”"objects": { "customer": { "type": "crm.customer", "cardinality": "one", "identity": "id", "fields": { "id": { "kind": "string", "required": true } }, "capabilities": { "fetch": { "inputs": { "customerId": { "kind": "string", "required": true } } } }, "sample": { "id": "cus_sample" } }}| Member | Required | Rules |
|---|---|---|
| alias (map key) | — | Starts with a letter; letters, digits, _; up to 64 characters; not __proto__, prototype, constructor. At most 32 aliases. |
type |
yes | Dot-separated names (crm.customer, helpdesk.ticket), each starting with a letter; up to 128 characters. Never a URL. |
cardinality |
yes | "one" (a record) or "many" (a collection). A collection may declare any of the four capabilities; its update and delete name their row with row, and its sample is an array of records. |
identity |
yes | Names a top-level field of kind string, integer or number that is required: true and not nullable. |
fields |
yes | A non-empty map of field specs, at most 64 per level. |
capabilities |
no | Any of fetch, create, update, delete, each {} or { "inputs": { … } }. |
sample |
no | A record (for a collection, an array of records) that satisfies fields: every required field present with the right kind, no undeclared fields. Design-time only. |
Unknown members anywhere in a declaration are refused by name.
Field spec
Section titled “Field spec”Record fields and operation inputs use the same spec:
| Key | Kinds | Meaning |
|---|---|---|
kind |
— | string, number, integer, boolean or object. Required. |
required |
all | For a record field: the host returns it on every response. For an input: it must have a value. |
requiredWhen |
all, inputs only | A condition; the input is required while it holds. Not together with required: true. |
nullable |
all | null is an accepted value. Independent of required. |
enum |
string, number, integer | 1–64 distinct allowed values of the field’s kind. |
format |
string | date, date-time, email or uri — a presentation hint, never checked. |
pattern |
string | A regular expression valid with the u flag, 1–256 characters. Unanchored unless you add ^…$. |
minLength, maxLength |
string | Whole numbers ≥ 0, counted in Unicode code points; min ≤ max. |
minimum, maximum |
number, integer | Inclusive bounds; min ≤ max. |
fields |
object | Nested field specs, up to 6 levels of object deep. Required for object, refused otherwise. |
Field and input names follow the alias rule. The constraint keys (pattern
through maximum) and requiredWhen are enforced on operation inputs only:
by the check before a write is sent, by the runtime’s validate, and on literal
input values at import. Host records and samples are checked for kind,
required, nullable and enum only.
Capabilities and inputs
Section titled “Capabilities and inputs”inputsare typed business inputs only — authentication, tenant, locale and routing stay in the host.- A write capability (
create,update,delete) may not declare the identity field as an input. - A nested input (an
objectinput) is addressed dot-joined in field errors, for exampleaddress.city.
Projected state
Section titled “Projected state”For every declared alias the runtime maintains:
/objects/{alias}/data the record (declared fields only) or null; for a collection, the list of records/meta/objects/{alias}/count a collection's row count/meta/objects/{alias}/operations/{op}/phase "idle" | "loading" | "success" | "error"/meta/objects/{alias}/operations/{op}/error null | { category, code, message, retryable, fieldErrors? }/meta/objects/{alias}/capabilities/{op} { implemented, allowed, reason? }/meta/objects/{alias}/fields/{field} { writable, reason? } one per declared leaf field{op} is fetch, create, update or delete; {field} is a leaf field’s
name path, dot-joined (contact.email). The error’s fieldErrors holds one
message per declared input name.
A collection’s fetch must answer with a list whose every row carries each
required declared field with the right kind and its identity, and shares that
identity with no other row; anything else is a host-contract error on the
fetch’s error path, and the last good list stays. Undeclared row fields are
dropped. A collection has no fields/{field} writability entries. A
collection’s create, update and delete merge one row into the list by
identity, with the count; see
collection row writes.
Ownership. Once an alias is declared, no setState, $bindState or state
seed may target /objects/{alias}, /meta/objects/{alias}, or the containers
above them (/objects, /meta, /meta/objects). A document with no
declarations may use /objects and /meta as ordinary state. A document may
seed ordinary siblings inside those containers, which the runtime keeps.
Reads. A $state read inside a declared alias’s paths must name something
listed above: a declared field under data, a known operation, and phase,
error (with its members), implemented, allowed, reason, writable.
Import refuses anything else with a message saying what is projected there.
The runtime path helpers
Section titled “The runtime path helpers”mica/runtime exports functions that build these paths, so host code never
spells them by hand:
| Function | Returns |
|---|---|
objectDataPath(alias) |
/objects/{alias}/data |
objectPhasePath(alias, op) |
/meta/objects/{alias}/operations/{op}/phase |
objectErrorPath(alias, op) |
/meta/objects/{alias}/operations/{op}/error |
objectFieldErrorPath(alias, op, field) |
…/error/fieldErrors/{field} |
objectCapabilityPath(alias, op) |
/meta/objects/{alias}/capabilities/{op} |
objectFieldWritabilityPath(alias, field) |
/meta/objects/{alias}/fields/{field} |
objectCountPath(alias) |
/meta/objects/{alias}/count |
OBJECT_DATA_ROOT (/objects) and OBJECT_META_ROOT (/meta/objects) are
the two roots.