Skip to content

Update a calc rule

PATCH
/calc-rules/{name}
curl --request PATCH \
--url https://example.com/api/v1/calc-rules/example \
--header 'Content-Type: application/json' \
--data '{ "description": "example", "enabled": true, "inputs": [ { "alias": "example", "key": "example" } ], "label": "example", "output_key": "example", "reduce": { "expr": "example" }, "selector": { "component_types": [ "example" ], "components": [ "example" ], "system_types": [ "example" ], "systems": [ "example" ] } }'

Patches a rule (an absent field is unchanged), bumping its version; a patch that changes nothing writes nothing. What changed is checked as on create: changed inputs, reduce or output recompile, a changed output must be one no collection writes, and an enabled rule may not close a cycle or share its output with another enabled rule. Enabling a disabled rule recompiles it and checks both, so a rule carrying calc_error cannot be enabled (422). The owner kind is fixed at create. Official rules are read-only (409). Audited. Gated by rule:update, with an all-scope grant.

name
required

The rule’s name (its uuid is accepted too)

string

The rule’s name (its uuid is accepted too)

Media type application/json
object
$schema

A URL to the JSON Schema for this object.

string format: uri
description

What the rule derives and why

string
enabled

Whether the rule runs; an enabled rule is part of the key graph

boolean
inputs

Replace the keys the rule reads

Array<object>
>= 1 items <= 16 items
object
alias
required

The name the reduce’s expression binds the input by: an identifier of at most 64, not a keyword, a builtin or list function’s name, or one of the calc site’s own bindings (component, has, members, system, value); unique in the rule

string
>= 1 characters <= 64 characters /^[A-Za-z_][A-Za-z0-9_]*$/
key
required

The property or metric the input reads, by name or uuid; the rule holds it by uuid, so a rename changes nothing

string
>= 1 characters
label

A human label

string
output_key

The property or metric the rule writes

string
reduce

Replace the reduce’s expression

object
expr
required

An expression over the inputs by alias, each bound as the list of its current values (one per instance on a component, every member’s on a system), yielding the output key’s type: max(tcp), avg(temp), any(call) || max(people) > 0

string
>= 1 characters
selector

Replace the owners the rule derives for; an empty selector is every owner of its kind

object
component_types

A component rule: derive on components whose type falls within one of these component types

Array<string> | null
components

A component rule: derive on these components (by name or id on write; ids on read)

Array<string> | null
system_types

A system rule: derive on systems whose type falls within one of these system types (subtypes included)

Array<string> | null
systems

A system rule: derive on these systems (by name or id on write; ids on read)

Array<string> | null

OK

Media type application/json
object
$schema

A URL to the JSON Schema for this object.

string format: uri
calc_error

Why the stored reduce does not compile against the registries as they are now (an input key deleted or retyped, or an expression a newer diagnostic refuses); absent when it compiles. While present the rule cannot be enabled

object
code

The registered diagnostic that gave it, when one did (documented on the expressions page)

string
column

The 1-based column of the fault, when it has a line

integer format: int64
field
required

The field at fault: an input’s key (inputs[0].key), reduce.expr or output_key

string
line

The 1-based line of the fault, when the reduce’s expression is what failed

integer format: int64
message
required

Why it does not compile, or what it warns of

string
calc_warnings

The warnings the stored reduce compiles with (a likely mistake, such as an input it never names), each with its code; notes only, never a fault: the rule computes all the same

Array<object> | null
object
code

The registered diagnostic that gave it, when one did (documented on the expressions page)

string
column

The 1-based column of the fault, when it has a line

integer format: int64
field
required

The field at fault: an input’s key (inputs[0].key), reduce.expr or output_key

string
line

The 1-based line of the fault, when the reduce’s expression is what failed

integer format: int64
message
required

Why it does not compile, or what it warns of

string
created_at
required

When the rule was created

string format: date-time
description

What the rule derives and why

string
enabled
required

Whether the rule runs; an enabled rule is part of the key graph

boolean
id
required

The rule’s uuid, the stable form of name

string
inputs
required

The keys the rule reads, each by the alias its reduce uses

Array<object> | null
object
alias
required

The name the reduce’s expression binds the input by

string
key
required

The key’s name now

string
key_id
required

The key’s uuid, which the rule holds it by

string
lane
required

Which registry the key is in

string
Allowed values: property metric
label

A human label

string
name
required

The rule’s name, the address an operator types; renameable

string
official
required

Shipped with the platform and read-only

boolean
output_key
required

The property or metric the rule writes

string
output_lane
required

Which lane the output key is on, derived from the registries

string
Allowed values: property metric
owner_kind
required

What the rule derives a value on: each component its selector picks, or each system its selector picks (read from the system’s role-bound members)

string
Allowed values: component system
owners_computed
required

How many owners the caller may read hold a value the rule computed (on the list; 0 on a single read)

integer format: int64
owners_failed
required

How many owners the caller may read the rule last failed on (on the list)

integer format: int64
owners_pending
required

How many owners the caller may read are marked for the next tick (on the list)

integer format: int64
owners_unsupported
required

How many owners the caller may read the rule last wrote nothing for: an input missing, a system with no members (on the list)

integer format: int64
reduce
required

How the inputs reduce into the output: an expression over their aliases

object
expr
required

An expression over the inputs by alias, each bound as the list of its current values (one per instance on a component, every member’s on a system), yielding the output key’s type: max(tcp), avg(temp), any(call) || max(people) > 0

string
>= 1 characters
selector
required

The owners the rule derives for: a component rule’s components or a system rule’s systems; empty is every owner of its kind

object
component_types

A component rule: derive on components whose type falls within one of these component types

Array<string> | null
components

A component rule: derive on these components (by name or id on write; ids on read)

Array<string> | null
system_types

A system rule: derive on systems whose type falls within one of these system types (subtypes included)

Array<string> | null
systems

A system rule: derive on these systems (by name or id on write; ids on read)

Array<string> | null
updated_at
required

When the rule was last written

string format: date-time
version
required

Bumps on every update

integer format: int64
Example
{
"$schema": "/api/v1/schemas/CalcRuleBody.json",
"inputs": [
{
"lane": "property"
}
],
"output_lane": "property",
"owner_kind": "component"
}

Error

Media type application/problem+json
object
$schema

A URL to the JSON Schema for this object.

string format: uri
detail

A human-readable explanation specific to this occurrence of the problem.

string
errors

Optional list of individual error details

Array<object> | null
object
location

Where the error occurred, e.g. ‘body.items[3].tags’ or ‘path.thing-id’

string
message

Error message text

string
value

The value at the given location

instance

A URI reference that identifies the specific occurrence of the problem.

string format: uri
status

HTTP status code

integer format: int64
title

A short, human-readable summary of the problem type. This value should not change between occurrences of the error.

string
type

A URI reference to human-readable documentation for the error.

string format: uri
default: about:blank
Example
{
"$schema": "/api/v1/schemas/ErrorModel.json",
"detail": "Property foo is required but is missing.",
"instance": "https://example.com/error-log/abc123",
"status": 400,
"title": "Bad Request",
"type": "about:blank"
}