sdk

    MoonBit-native Unleash evaluation core and explicitly scoped server-side SDK

    unleash
    feature-flags
    sdk
    rollout
    Download zip
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    15 hours ago
    Downloads
    11

    #MoonUnleash documentation entry

    The maintained introduction, examples, backend matrix and limitations are in the project README. Module metadata selects that document.

    This legacy scaffold entry is retained for tooling compatibility; it is not a second API guide or a claim of complete Unleash compatibility.

    ConfigError

    pub(all) suberror ConfigError {
    Invalid(String)
    Unsupported(String)
    } derive(
    Debug
    )

    Invalid input and unsupported semantics are distinct, observable failures.

    ConfigError::message

    fn ConfigError::message(self : ConfigError) -> String

    A diagnostic safe to display without serializing the original configuration.

    ConfigError::to_repr

    automatically derived

    BatchDecision

    pub(all) struct BatchDecision {
    decisions : Array[Decision]
    generation : Int64
    stale : Bool
    }

    Context

    pub struct Context {
    // private fields
    }

    Context::new

    fn Context::new(user_id? : String) -> Context

    Context::parse

    fn Context::parse(source : String) -> Context raise

    Context::with_defaults

    fn Context::with_defaults(self : Context, app_name : String, environment? : String) -> Context

    Return a fresh context with client defaults. Explicit keys, including null and empty strings, override defaults; nested properties are not promoted.

    Decision

    pub(all) struct Decision {
    enabled : Bool
    reason : String
    } derive(Eq,
    Debug
    )

    Decision::equal

    fn Decision::equal(Decision, Decision) -> Bool
    automatically derived

    Decision::not_equal

    fn Decision::not_equal(x : Decision, y : Decision) -> Bool
    automatically derived

    Decision::to_repr

    automatically derived

    EvaluatedDecision

    pub(all) struct EvaluatedDecision {
    decision : Decision
    generation : Int64
    stale : Bool
    }

    Metrics

    pub struct Metrics {
    // private fields
    }

    Single-owner telemetry accumulator; no I/O, scheduling, or OS-thread safety. A frozen pending string and a separate bounded active bucket are retained. Invalid or excess names silently omit telemetry, not evaluation results.

    Metrics::acknowledge

    fn Metrics::acknowledge(self : Metrics) -> Unit

    Clear only the pending bucket after the caller accepts the send result. This is idempotent and does not imply exactly-once delivery by a transport.

    Metrics::count

    fn Metrics::count(self : Metrics, name : String, enabled : Bool, variant? : String) -> Unit

    Record one boolean evaluation and, when supplied, one variant observation. A rejected variant still records yes/no. Existing counters keep incrementing after either cardinality limit, with every counter capped at 2^53 - 1.

    Metrics::new

    fn Metrics::new(now_ms : Int64) -> Metrics raise ConfigError

    Start a bucket at a validated UTC epoch-millisecond timestamp.

    Metrics::prepare

    fn Metrics::prepare(self : Metrics, now_ms : Int64) -> String? raise ConfigError

    Freeze a nonempty active bucket, or return the exact pending string on retry. Counts made after freezing belong to a new bucket starting at that stop. Every accepted call, including an empty call or retry, advances the rollback check; empty calls do not move the bucket start. Invalid times change nothing.

    Metrics::started_at

    fn Metrics::started_at(self : Metrics) -> String

    The immutable construction timestamp, suitable for registration's started. This does not move when active buckets are frozen or acknowledged.

    Payload

    pub(all) struct Payload {
    kind : String
    value : String
    }

    Variant payloads remain text: JSON payloads are not executed or reinterpreted.

    Snapshot

    pub struct Snapshot {
    // private fields
    }

    Private owned JSON: callers cannot mutate installed configuration.

    Snapshot::apply_delta

    fn Snapshot::apply_delta(self : Snapshot, source : String) -> Snapshot raise

    Returns a new fully validated snapshot, never mutating this snapshot. Within a batch ids must increase (gaps are allowed). Replayed old events are structurally validated and ignored; a failed event rejects the entire batch.

    Snapshot::delta_event_id

    fn Snapshot::delta_event_id(self : Snapshot) -> Int64?

    Last accepted delta event id; a full-state snapshot has no stream cursor.

    Snapshot::evaluate

    fn Snapshot::evaluate(self : Snapshot, name : String, ctx : Context, fallback? : Bool, random? : () -> Double) -> Decision

    Evaluation performs no network/disk I/O. Inject randomness and currentTime in the context for reproducibility; absent date context reads the local clock.

    Snapshot::from_delta

    fn Snapshot::from_delta(source : String) -> Snapshot raise

    Builds from an empty state using the public delta hydration/events envelope. A feature-update-only initial batch is allowed by official suite 20.

    Snapshot::get_variant

    fn Snapshot::get_variant(self : Snapshot, name : String, ctx : Context, random? : () -> Double) -> Variant

    Evaluates once; first-match strategy variants take precedence over legacy ones.

    Snapshot::is_enabled

    fn Snapshot::is_enabled(self : Snapshot, name : String, ctx : Context, fallback? : Bool) -> Bool

    Snapshot::parse

    fn Snapshot::parse(source : String) -> Snapshot raise

    Parses a supported full-state response. Nothing is published on failure.

    Snapshot::size

    fn Snapshot::size(self : Snapshot) -> Int

    SnapshotStore

    pub struct SnapshotStore {
    // private fields
    }

    Single-owner state machine. All timestamps are monotonic milliseconds. This type does not start tasks or perform I/O and is not OS-thread-safe.

    SnapshotStore::apply_delta

    fn SnapshotStore::apply_delta(self : SnapshotStore, source : String, now_ms : Int64) -> Int64 raise

    Atomically installs one accepted batch. Replays/empty batches revalidate an existing state without advancing its generation. No tasks or SSE are started.

    SnapshotStore::close

    fn SnapshotStore::close(self : SnapshotStore) -> Unit

    SnapshotStore::delta_event_id

    fn SnapshotStore::delta_event_id(self : SnapshotStore) -> Int64?

    SnapshotStore::evaluate

    fn SnapshotStore::evaluate(self : SnapshotStore, name : String, ctx : Context, now_ms : Int64, fallback? : Bool) -> EvaluatedDecision

    SnapshotStore::evaluate_many

    fn SnapshotStore::evaluate_many(self : SnapshotStore, names : Array[String], ctx : Context, now_ms : Int64, fallback? : Bool) -> BatchDecision

    SnapshotStore::get_variant

    fn SnapshotStore::get_variant(self : SnapshotStore, name : String, ctx : Context, now_ms : Int64) -> Variant

    SnapshotStore::hydrate_delta

    fn SnapshotStore::hydrate_delta(self : SnapshotStore, source : String, now_ms : Int64) -> Int64 raise

    Explicit resynchronization: the first event must be hydration. This may reset a cursor after a server/stream restart and replaces both state maps.

    SnapshotStore::install

    fn SnapshotStore::install(self : SnapshotStore, source : String, now_ms : Int64, origin? : String) -> Int64 raise

    Installs only a fully parsed/validated snapshot; a failure leaves state intact.

    SnapshotStore::invalidate_clock

    fn SnapshotStore::invalidate_clock(self : SnapshotStore) -> Unit

    Conservatively invalidate freshness after an adapter detects clock rollback. The snapshot is retained. A new validated install/update restores readiness; a no-change replay cannot revalidate an untrusted clock.

    SnapshotStore::new

    fn SnapshotStore::new(stale_after_ms? : Int64, max_stale_ms? : Int64) -> SnapshotStore raise ConfigError

    SnapshotStore::record_failure

    fn SnapshotStore::record_failure(self : SnapshotStore, reason : String) -> Unit

    SnapshotStore::revalidate

    fn SnapshotStore::revalidate(self : SnapshotStore, now_ms : Int64) -> Unit raise ConfigError

    A 304 can revalidate only an existing snapshot for an already accepted ETag.

    SnapshotStore::status

    fn SnapshotStore::status(self : SnapshotStore, now_ms : Int64) -> Status

    Status

    pub(all) struct Status {
    ready : Bool
    closed : Bool
    stale : Bool
    generation : Int64
    feature_count : Int
    source : String
    last_error : String?
    consecutive_failures : Int
    }

    Variant

    pub(all) struct Variant {
    name : String
    enabled : Bool
    feature_enabled : Bool
    payload : Payload?
    }

    Variant::to_json