Module itinera/value

Values: data that can be serialised, the only data a data bag, an event, a reason's details or global metadata holds, and the type tokens that name the type a request or a read of the data bag checks a value against.

import assert from "node:assert/strict";
import type { PlainValue, Value } from "itinera/value";

class Payment {
constructor(readonly cents: number) {}

toValue(): PlainValue {
return { cents: this.cents };
}
}

function kind(value: Value): string {
return Array.isArray(value) ? "list" : typeof value;
}

assert.equal(kind(1250), "number");
assert.equal(kind(["tea", new Payment(1250)]), "list");
assert.equal(kind({ order: "R-1", payment: new Payment(1250) }), "object");
// @ts-expect-error: a Date is not a value
kind(new Date());
Optional
SerialisesItself
ValueClass
AsValue
PlainValue
RequestType
Value
boolean
integer
list
number
object
string
classOf
guard
listOf
objectOf
optional