Step Function (:function)
Quick Answer
Use this reference for the :function step schema, deterministic transform rules, and allowed helper/interop surface.
Use for sandboxed transforms.
Canonical Shape
Core fields:
| Field | Type | Required | Notes |
|---|---|---|---|
:type | keyword | Yes | Use :function (:code alias is deprecated) |
:input | map | Yes | Input payload map |
:code | form/string | Yes* | Inline function body |
:ref | keyword | Yes* | Reference top-level :functions entry |
:load | vector | No | Input keys to load from blob refs before execution |
* Provide exactly one of :code or :ref.
Limits And Behavior
- Prefer
:reffor reuse and readability. - Keep reusable logic in top-level
:functions; keep step-level:flowfocused on orchestration. - Keep functions deterministic; avoid time, randomness, and I/O.
- Safe helpers are exposed under
breyta.sandbox(preferred; pure/deterministic):base64-encode(string|bytes) -> string(Base64)base64-decode(string|bytes) -> string(UTF-8)base64-decode-bytes(string|bytes) -> byteshex-encode(string|bytes) -> stringhex-decode(string) -> string(UTF-8)hex-decode-bytes(string) -> bytessha256-hex(string|bytes) -> string(hex digest)hmac-sha256-hex(key string|bytes, value string|bytes) -> string(hex digest)uuid-from(string) -> uuiduuid-from-bytes(string|bytes) -> uuidparse-instant(string) -> java.time.Instant(ISO-8601)format-instant(Instant) -> string(ISO-8601)format-instant-pattern(Instant, pattern) -> string(UTC)instant->epoch-ms(Instant) -> longepoch-ms->instant(long) -> Instantduration-between(Instant, Instant) -> Durationtruncate-instant(Instant, unit) -> Instant(unit::seconds|:minutes|:hours|:days)instant-plus(Instant, amount, unit) -> Instant(unit::millis|:seconds|:minutes|:hours|:days)instant-minus(Instant, amount, unit) -> Instanturl-encode(string) -> string(UTF-8)url-decode(string) -> string(UTF-8)
- Limited Java interop is also allowed in
:functioncode (small allowlist):java.time.*,
java.time.format.DateTimeFormatter,java.time.temporal.{ChronoUnit,TemporalAdjusters},
java.util.{UUID,Base64},java.math.{BigInteger,BigDecimal}. Preferbreyta.sandbox.
Canonical Example
;; In the flow definition:
;; :functions [{:id :normalize
;; :language :clojure
;; :code "(fn [input]\n;; {:value (str (:value input))})"}]
(flow/step :function :normalize
{:ref :normalize
:input {:value 42}})