skir-client

    SkirRPC integration for MoonBit

    moonbit
    json
    serialization
    skir
    skirrpc
    Download zip
    Author
    Version
    0.1.2
    License
    MIT
    Last updated
    yesterday
    Downloads
    116

    No dependencies

    #skir-client

    MoonBit runtime client library for Skir-generated APIs.

    Website: https://skir.build/

    For SkirRPC support, check out skir-moonbit-client-async.

    #Install

    Add this module to your MoonBit project:

    moon add gepheum/skir-client

    #Development

    moon fmt --check moon check moon test

    #License

    MIT

    ImmutVector

    using @moonbitlang/core/immut/vector { type Vector as ImmutVector }

    Invariants:
    • shift = tree height * NUM_BITS. When it is 0, we are at the leaf level.
    • size = the total number of elements in tree and tail.
    • tail stores the right-most chunk and has at most BRANCHING_FACTOR elements.
    • tree stores the prefix before tail.
    • shift is 0 when tree is Empty, and otherwise names the height of tree exactly: every operation that walks the tree is handed this shift and decrements it by NUM_BITS per level, so a Leaf must sit at shift 0.

    NativeBool

    type NativeBool = Bool

    The boolean type, with the values true and false.

    NativeBytes

    type NativeBytes = Bytes

    An immutable sequence of bytes.

    NativeDouble

    type NativeDouble = Double

    A 64-bit IEEE 754 floating-point number.

    NativeFloat

    type NativeFloat = Float

    A 32-bit IEEE 754 floating-point number.

    NativeInt

    type NativeInt = Int

    A signed 32-bit integer.

    NativeInt64

    type NativeInt64 = Int64

    A signed 64-bit integer.

    NativeString

    type NativeString = String

    An immutable sequence of UTF-16 code units.

    NativeUInt64

    type NativeUInt64 = UInt64

    An unsigned 64-bit integer.

    ArraySignature

    pub struct ArraySignature {
    item_type : TypeSignature
    key_extractor : String
    }

    EnumConstantVariant

    pub struct EnumConstantVariant {
    name : String
    number : Int
    doc : String
    }

    EnumRecordDescriptor

    pub struct EnumRecordDescriptor {
    record_id : String
    doc : String
    removed_numbers :
    Vector
    [Int]
    variants :
    Vector
    [EnumVariant]
    }

    EnumVariant

    pub enum EnumVariant {
    Constant(EnumConstantVariant)
    Wrapper(EnumWrapperVariant)
    }

    EnumWrapperVariant

    pub struct EnumWrapperVariant {
    name : String
    number : Int
    variant_type : TypeSignature
    doc : String
    }

    Internal_EnumAdapter

    pub struct Internal_EnumAdapter[T] {
    // private fields
    }

    Internal_EnumAdapter::add_constant_variant

    fn[T] Internal_EnumAdapter::add_constant_variant(self : Internal_EnumAdapter[T], name : String, number : Int, kind_ordinal : Int, doc : String, instance : T) -> Unit

    Internal_EnumAdapter::add_removed_number

    fn[T] Internal_EnumAdapter::add_removed_number(self : Internal_EnumAdapter[T], number : Int) -> Unit

    Internal_EnumAdapter::add_wrapper_variant

    fn[T, V] Internal_EnumAdapter::add_wrapper_variant(self : Internal_EnumAdapter[T], name : String, number : Int, kind_ordinal : Int, serializer : Serializer[V], doc : String, wrap : (V) -> T, get_value : (T) -> V) -> Unit

    Internal_EnumAdapter::finalize

    fn[T] Internal_EnumAdapter::finalize(self : Internal_EnumAdapter[T]) -> Unit

    Internal_EnumAdapter::new

    fn[T] Internal_EnumAdapter::new(module_path : String, qualified_name : String, doc : String, default_value : T, get_kind_ordinal : (T) -> Int, wrap_unrecognized : (Internal_UnrecognizedVariant) -> T, get_unrecognized : (T) -> Internal_UnrecognizedVariant?) -> Internal_EnumAdapter[T]

    Internal_EnumAdapter::serializer

    fn[T] Internal_EnumAdapter::serializer(self : Internal_EnumAdapter[T]) -> Serializer[T]

    Internal_KeyedVector

    pub struct Internal_KeyedVector[T, K] {
    vector :
    Vector
    [T]
    // private fields
    }

    impl Eq for Internal_KeyedVector[T, K]

    Internal_KeyedVector::empty

    Internal_KeyedVector::find_by_key

    fn[T, K : Hash + Eq] Internal_KeyedVector::find_by_key(self : Internal_KeyedVector[T, K], key : K) -> T?

    Internal_KeyedVector::find_by_key_or_default

    fn[T, K : Hash + Eq] Internal_KeyedVector::find_by_key_or_default(self : Internal_KeyedVector[T, K], key : K) -> T

    Internal_KeyedVector::from_array

    fn[T, K] Internal_KeyedVector::from_array(items : Array[T], spec : Internal_KeyedVectorSpec[T, K]) -> Internal_KeyedVector[T, K]

    Internal_KeyedVector::new

    Internal_KeyedVectorSpec

    pub(all) struct Internal_KeyedVectorSpec[T, K] {
    get_key : (T) -> K
    key_extractor : String
    default_item : T
    }

    Internal_StructAdapter

    pub struct Internal_StructAdapter[T, Mutable] {
    // private fields
    }

    Internal_StructAdapter::add_field

    fn[T, Mutable, V] Internal_StructAdapter::add_field(self : Internal_StructAdapter[T, Mutable], name : String, number : Int, serializer : Serializer[V], getter : (T) -> V, setter : (Mutable, V) -> Unit, doc : String) -> Unit

    Internal_StructAdapter::add_removed_number

    fn[T, Mutable] Internal_StructAdapter::add_removed_number(self : Internal_StructAdapter[T, Mutable], number : Int) -> Unit

    Internal_StructAdapter::finalize

    fn[T, Mutable] Internal_StructAdapter::finalize(self : Internal_StructAdapter[T, Mutable]) -> Unit

    Internal_StructAdapter::new

    fn[T, Mutable] Internal_StructAdapter::new(module_path : String, qualified_name : String, doc : String, new_mutable : () -> Mutable, to_frozen : (Mutable) -> T, get_unrecognized : (T) -> Internal_UnrecognizedFields?, set_unrecognized : (Mutable, Internal_UnrecognizedFields?) -> Unit) -> Internal_StructAdapter[T, Mutable]

    Internal_StructAdapter::serializer

    fn[T, Mutable] Internal_StructAdapter::serializer(self : Internal_StructAdapter[T, Mutable]) -> Serializer[T]

    Internal_UnrecognizedFields

    pub struct Internal_UnrecognizedFields {
    // private fields
    }

    Internal_UnrecognizedVariant

    pub struct Internal_UnrecognizedVariant {
    // private fields
    }

    KeepOrSet

    pub(all) enum KeepOrSet[T] {
    Keep
    Set(T)
    } derive(Eq,
    Debug
    )

    Method

    pub(all) struct Method[T, U] {
    name : String
    number : Int
    request_serializer : Serializer[T]
    response_serializer : Serializer[U]
    doc : String
    }

    PrimitiveType

    pub enum PrimitiveType {
    Bool
    Int32
    Int64
    Hash64
    Float32
    Float64
    Timestamp
    String
    Bytes
    }

    RecordDescriptor

    pub enum RecordDescriptor {
    Struct(StructRecordDescriptor)
    Enum(EnumRecordDescriptor)
    }

    Recursive

    pub(all) enum Recursive[T] {
    Default
    Some(T)
    } derive(Eq,
    Debug
    )

    Serializer

    pub struct Serializer[T] {
    // private fields
    }

    Serializes and deserializes values of type T in JSON and binary formats.

    Serializer::from_bytes

    fn[T] Serializer::from_bytes(self : Serializer[T], bytes : Array[Int], unrecognized_values? : UnrecognizedValues) -> Result[T, String]

    Deserializes a value from the Skir binary wire format.

    Set unrecognized_values to UnrecognizedValues::Keep to preserve unrecognized fields/variants from newer schema versions.

    Use UnrecognizedValues::Drop (the default) when input may come from untrusted or malicious sources.

    Serializer::from_json

    fn[T] Serializer::from_json(self : Serializer[T], json :
    Json
    , unrecognized_values? : UnrecognizedValues) -> Result[T, String]

    Deserializes a value from an already-parsed JSON value.

    Set unrecognized_values to UnrecognizedValues::Keep to preserve unrecognized fields/variants so they can be emitted again after re-serialization.

    Use UnrecognizedValues::Drop (the default) when input may come from untrusted or malicious sources.

    Serializer::from_json_code

    fn[T] Serializer::from_json_code(self : Serializer[T], code : String, unrecognized_values? : UnrecognizedValues) -> Result[T, String]

    Deserializes a value from JSON source code.

    Set unrecognized_values to UnrecognizedValues::Keep to preserve unrecognized fields/variants from newer schema versions.

    Use UnrecognizedValues::Drop (the default) when input may come from untrusted or malicious sources.

    Returns Err("invalid JSON: ...") when parsing fails.

    Serializer::to_bytes

    fn[T] Serializer::to_bytes(self : Serializer[T], input : T) -> Array[Int]

    Serializes input to the Skir binary wire format.

    Serializer::to_dense_json_code

    fn[T] Serializer::to_dense_json_code(self : Serializer[T], input : T) -> String

    Serializes input to the compact (dense) JSON representation.

    Dense JSON is designed for persistence and wire efficiency.

    Serializer::to_readable_json

    fn[T] Serializer::to_readable_json(self : Serializer[T], input : T) ->
    Json

    Serializes input to the readable JSON representation.

    Structs are encoded as JSON objects and enum constants as strings. This format is more verbose and readable, but should not be used for persistence because field names may change across schema versions.

    In other words, do not store readable JSON on disk or in a database.

    Serializer::type_descriptor

    fn[T] Serializer::type_descriptor(self : Serializer[T]) -> TypeDescriptor

    Returns the type descriptor describing the schema of T.

    StructField

    pub struct StructField {
    name : String
    number : Int
    field_type : TypeSignature
    doc : String
    }

    StructRecordDescriptor

    pub struct StructRecordDescriptor {
    record_id : String
    doc : String
    removed_numbers :
    Vector
    [Int]
    fields :
    Vector
    [StructField]
    }

    Timestamp

    pub struct Timestamp {
    // private fields
    }

    Represents a point in time.
    impl Eq for Timestamp
    impl Hash for Timestamp

    Timestamp::from_unix_millis

    fn Timestamp::from_unix_millis(ms : Int64) -> Timestamp

    Creates a Timestamp from Unix milliseconds.

    Timestamp::from_unix_seconds

    fn Timestamp::from_unix_seconds(seconds : Double) -> Timestamp

    Creates a Timestamp from Unix seconds.

    Timestamp::max

    fn Timestamp::max() -> Timestamp

    Returns the maximum representable Timestamp.

    Timestamp::min

    fn Timestamp::min() -> Timestamp

    Returns the minimum representable Timestamp.

    Timestamp::now

    fn Timestamp::now() -> Timestamp

    Returns the current Timestamp.

    Timestamp::to_iso8601

    fn Timestamp::to_iso8601(self : Timestamp) -> String

    Formats the Timestamp as ISO8601 string.

    Timestamp::unix_epoch

    fn Timestamp::unix_epoch() -> Timestamp

    Returns the Unix epoch Timestamp.

    Timestamp::unix_millis

    fn Timestamp::unix_millis(self : Timestamp) -> Int64

    Returns the Unix milliseconds representation.

    Timestamp::unix_seconds

    fn Timestamp::unix_seconds(self : Timestamp) -> Double

    Returns the Unix seconds representation.

    TypeAdapter

    type TypeAdapter[T]

    TypeDescriptor

    pub struct TypeDescriptor {
    root_type : TypeSignature
    records :
    Vector
    [RecordDescriptor]
    }

    TypeDescriptor::as_json

    TypeSignature

    pub enum TypeSignature {
    Primitive(PrimitiveType)
    Optional(TypeSignature)
    Array(ArraySignature)
    Record(String)
    }

    UnrecognizedValues

    pub(all) enum UnrecognizedValues {
    Keep
    Drop
    }

    Controls how unknown fields/variants are handled during deserialization.

    bool_serializer

    fn bool_serializer() -> Serializer[Bool]

    bytes_serializer

    fn bytes_serializer() -> Serializer[Bytes]

    float32_serializer

    fn float32_serializer() -> Serializer[Float]

    float64_serializer

    fn float64_serializer() -> Serializer[Double]

    hash64_serializer

    fn hash64_serializer() -> Serializer[UInt64]

    int32_serializer

    fn int32_serializer() -> Serializer[Int]

    int64_serializer

    fn int64_serializer() -> Serializer[Int64]

    keyed_vector_serializer

    fn[T] keyed_vector_serializer(item_serializer : Serializer[T], key_extractor : String) -> Serializer[
    Vector
    [T]]

    optional_serializer

    fn[T] optional_serializer(other : Serializer[T]) -> Serializer[T?]

    parse_from_json

    fn parse_from_json(root :
    Json
    ) -> Result[TypeDescriptor, String]

    recursive_serializer

    fn[T] recursive_serializer(other : Serializer[T]) -> Serializer[Recursive[T]]

    string_serializer

    fn string_serializer() -> Serializer[String]

    timestamp_serializer

    fn timestamp_serializer() -> Serializer[Timestamp]

    vector_serializer

    fn[T] vector_serializer(item_serializer : Serializer[T]) -> Serializer[
    Vector
    [T]]