Home

Explain

Explain base:

 
 

Expressions and Selectors

A crucial part of the Collection Rules and Filter Rules are expressions. Expressions are used for configuration, and must be simple and very flexible to permit very complex Collections.

Expressions tend to grow over time into a full programming language. For security reasons, it is undesired to run any code for Collections, so hopefully we can avoid that. Therefore, epressions are (for now) limited to simple conditions.

Expressions have a name (b:name). You can use the name of one expression inside an other (boolean) expression. The result of an expression is cached: when you keep them simple, they improve in efficiency.

Context sensitive

Expressions know what they need to produce. For instance, they need to produce a number, a boolean, or an Indentity Unit. Operations are executed to make that happen.

Source of values

Expressions produce values, which can be computed with constant values and with variables taken from the working environment. Via b:Fragments and functions, your can get to Units which can produce values.

payload.size > 42k         
type like "ms:Type/image/*"
resource1.host =~ "\.nl$"
namespace.root.nr_units
system.now + P1DT5M3S

A condition can be derived from Voting.

Any Unit can declare expressions (b:let). This is especially useful in Namespace, (Collection) Rules, and Type Units. Besides, there are many expressions provided by the context.

When any name in an expression is not known, it will return "undefined" for the whole expression.

Examples

Most of expressions is already implemented. Have a look at Math-Formula. That module needs some extensions to support namespaces correctly. Issues can be discussed on GitHub.

The exact valid uses are still to be determined, but to give some examples of expressions, see below.

<let name="unit_is_large" expr="payload.size &gt; 1Mibi" />

<let name="unit_is_image" expr="unit.type like 'iana:MIME/image/*'" />

<let name="collection_is_full" expr="collection.nr_units == 5k" />

<let name="auto_expire" expr="unit.deprecate + P2D" />

<let name="unit_is_visible" expr="
   unit.state like 'ms:UnitState/{Accepted,Published,Deprecated}'" />

<state
   to="ms:UnitState/Expired"
   when="(unit_is_visible and unit.expired) or auto_expire"
/>

Values are typed. A date used in boolean context will be compared to the current time. A duration in value context is relative to the unit's upload time. Any constant is namespaced: it does understand difference in choice of prefix for the same namespace.


mark@overmeer.net      Web-pages generated on 2023-12-19