decisions/wire
The JSON form of every value a record holds, and Codec, which carries
a point’s output type across the store and across a process boundary.
An occurrence survives a restart only as text, so every value in
decisions/vocabulary has an encoder and a decoder here. A tagged sum
is an object whose "t" field names the variant. Times are whole
milliseconds since the Unix epoch.
Build a point’s codec from a json_blueprint codec with codec, and
the codec also carries the output’s JSON Schema, which a card shows so
that a client with none of the point’s code can build a correction
form. plain builds a codec without a schema.
import decisions/wire
import json/blueprint/codec
pub type Refund {
Refund(fee: String, cents: Int)
}
pub fn refund() -> wire.Codec(Refund) {
wire.codec({
use fee <- codec.field("fee", codec.string(), get: fn(r) { r.fee })
use cents <- codec.field("cents", codec.int(), get: fn(r) { r.cents })
codec.success(Refund(fee:, cents:))
})
}
Target-independent: builds for Erlang and JavaScript.
Types
Values
pub fn assessment(
assessment: vocabulary.Assessment(o),
output: Codec(o),
) -> Result(json.Json, String)
{"finding", "evidence", "source", "known_at"}.
pub fn assessment_decoder(
output: Codec(o),
) -> decode.Decoder(vocabulary.Assessment(o))
Decodes an assessment written by assessment.
pub fn blueprint(codec: Codec(a)) -> codec.Codec(a)
The output’s codec as a json_blueprint codec, for building a document
that holds outputs, such as the card’s (decisions/view.codec). For a
plain codec its schema admits any JSON.
pub fn codec(blueprint: codec.Codec(a)) -> Codec(a)
A codec from a json_blueprint codec. It carries the output’s JSON
Schema (Draft 2020-12), which schema returns and a card shows.
pub fn effect(effect: vocabulary.Effect) -> json.Json
Tagged performed, not_performed or uncertain.
pub fn effect_decoder() -> decode.Decoder(vocabulary.Effect)
Decodes an Effect written by effect.
pub fn encode(
codec: Codec(a),
item: a,
) -> Result(json.Json, String)
Encode an output. An error means the codec cannot represent this value, such as a number with no exact JSON form.
pub fn expiry_cause(cause: vocabulary.ExpiryCause) -> json.Json
Tagged deadline or superseded.
pub fn expiry_cause_decoder() -> decode.Decoder(
vocabulary.ExpiryCause,
)
Decodes an ExpiryCause written by expiry_cause.
pub fn explanation(
explanation: vocabulary.Explanation,
) -> json.Json
Tagged by explanation kind.
pub fn explanation_decoder() -> decode.Decoder(
vocabulary.Explanation,
)
Decodes an Explanation written by explanation.
pub fn fact(fact: vocabulary.Fact) -> json.Json
Tagged number, text or flag, with the value in "v".
pub fn fact_decoder() -> decode.Decoder(vocabulary.Fact)
Decodes a Fact written by fact. A number written as an integer
decodes as well.
pub fn facts(
facts: List(#(String, vocabulary.Fact)),
) -> json.Json
A list of {"name", "fact"}.
pub fn facts_decoder() -> decode.Decoder(
List(#(String, vocabulary.Fact)),
)
Decodes Facts written by facts.
pub fn from_milliseconds(ms: Int) -> timestamp.Timestamp
The time ms milliseconds after the Unix epoch.
pub fn manifest_decoder() -> decode.Decoder(vocabulary.Manifest)
Decodes a Manifest written by manifest.
pub fn milliseconds(at: timestamp.Timestamp) -> Int
Whole milliseconds since the Unix epoch, rounded down.
pub fn number_decoder() -> decode.Decoder(Float)
A JSON number as a float, whether it was written with a decimal point or not.
pub fn optional(
item: option.Option(a),
encode: fn(a) -> json.Json,
) -> json.Json
null for None, the encoded value otherwise.
pub fn parent(parent: vocabulary.Parent) -> json.Json
Tagged run or occurrence, with "id".
pub fn parent_decoder() -> decode.Decoder(vocabulary.Parent)
Decodes a Parent written by parent.
pub fn parse(
codec: Codec(a),
text: String,
) -> Result(a, json.DecodeError)
Decode an output from JSON text.
pub fn plain(
encode: fn(a) -> json.Json,
decoder: decode.Decoder(a),
) -> Codec(a)
A codec from an encoder and a decoder, with no schema. A card for a point with this codec can be approved or rejected by any client, and a correction form must be built by code that knows the output type.
pub fn reason_decoder() -> decode.Decoder(vocabulary.Reason)
Decodes a Reason written by reason. A missing note is None.
pub fn recommendation(
recommendation: vocabulary.Recommendation(o),
output: Codec(o),
) -> Result(json.Json, String)
A recommendation, with the output encoded by the point’s codec.
pub fn recommendation_decoder(
output: Codec(o),
) -> decode.Decoder(vocabulary.Recommendation(o))
Decodes a recommendation written by recommendation.
pub fn recommender(by: vocabulary.Recommender) -> json.Json
Tagged by recommender kind, with "name" and "version".
pub fn recommender_decoder() -> decode.Decoder(
vocabulary.Recommender,
)
Decodes a Recommender written by recommender.
pub fn ref_decoder() -> decode.Decoder(vocabulary.Ref)
Decodes a Ref written by ref.
pub fn schema(codec: Codec(a)) -> option.Option(json.Json)
The output’s JSON Schema document, when the codec carries one.
pub fn subject_decoder() -> decode.Decoder(vocabulary.Subject)
Decodes a Subject written by subject.
pub fn tagged(
tag: String,
fields: List(#(String, json.Json)),
) -> json.Json
An object whose "t" field names the variant, followed by fields.
pub fn time_decoder() -> decode.Decoder(timestamp.Timestamp)
Decodes a time written by time.
pub fn trigger_decoder() -> decode.Decoder(vocabulary.Trigger)
Decodes a Trigger written by trigger.
pub fn validator_decoder() -> decode.Decoder(vocabulary.Validator)
Decodes a Validator written by validator.
pub fn verdict(
verdict: vocabulary.Verdict(o),
output: Codec(o),
) -> Result(json.Json, String)
Tagged approve, reject or correct.
pub fn verdict_decoder(
output: Codec(o),
) -> decode.Decoder(vocabulary.Verdict(o))
Decodes a verdict written by verdict. Only the point’s own codec can
decode a corrected output.
pub fn verdicts(allowed: vocabulary.Verdicts) -> json.Json
The names of the verdicts a declaration allows, as a card lists them.