midas/effect
The effect module defines all the side effects supported by Midas. It also defines functions to compose effectful functions
Gleam does not offer extensible types and so adding new types will require contribution to this project.
Use this module to explicitly handle errors, use the midas/task module for a simpler API where all errors are snag errors.
Types
pub type Effect(a, key) {
Done(a)
Bundle(
module: String,
function: String,
resume: fn(Result(String, String)) -> Effect(a, key),
)
ExportJsonWebKey(
key: key,
resume: fn(Result(json.Json, String)) -> Effect(a, key),
)
Follow(
uri: uri.Uri,
resume: fn(Result(uri.Uri, Nil)) -> Effect(a, key),
)
Fetch(
request: request.Request(BitArray),
resume: fn(Result(response.Response(BitArray), FetchError)) -> Effect(
a,
key,
),
)
GenerateKeyPair(
algorithm: KeyPairAlgorithm,
extractable: Bool,
usages: List(KeyUsage),
resume: fn(Result(KeyPair(key), String)) -> Effect(a, key),
)
Hash(
algorithm: HashAlgorithm,
bytes: BitArray,
resume: fn(Result(BitArray, String)) -> Effect(a, key),
)
List(
directory: String,
resume: fn(Result(List(String), String)) -> Effect(a, key),
)
Log(
message: String,
resume: fn(Result(Nil, Nil)) -> Effect(a, key),
)
Read(
file: String,
resume: fn(Result(BitArray, String)) -> Effect(a, key),
)
Serve(
port: option.Option(Int),
handle: fn(request.Request(BitArray)) -> response.Response(
BitArray,
),
resume: fn(Result(Nil, String)) -> Effect(a, key),
)
Sign(
algorithm: SignAlgorithm,
key: key,
data: BitArray,
resume: fn(Result(BitArray, String)) -> Effect(a, key),
)
StrongRandom(
length: Int,
resume: fn(Result(BitArray, String)) -> Effect(a, key),
)
Write(
file: String,
bytes: BitArray,
resume: fn(Result(Nil, String)) -> Effect(a, key),
)
Visit(
uri: uri.Uri,
resume: fn(Result(Nil, String)) -> Effect(a, key),
)
Zip(
files: List(#(String, BitArray)),
resume: fn(Result(BitArray, Nil)) -> Effect(a, key),
)
UnixNow(resume: fn(Int) -> Effect(a, key))
}
Constructors
-
Done(a) -
Bundle( module: String, function: String, resume: fn(Result(String, String)) -> Effect(a, key), ) -
-
-
Fetch( request: request.Request(BitArray), resume: fn(Result(response.Response(BitArray), FetchError)) -> Effect( a, key, ), ) -
GenerateKeyPair( algorithm: KeyPairAlgorithm, extractable: Bool, usages: List(KeyUsage), resume: fn(Result(KeyPair(key), String)) -> Effect(a, key), ) -
Hash( algorithm: HashAlgorithm, bytes: BitArray, resume: fn(Result(BitArray, String)) -> Effect(a, key), ) -
List( directory: String, resume: fn(Result(List(String), String)) -> Effect(a, key), ) -
Log( message: String, resume: fn(Result(Nil, Nil)) -> Effect(a, key), ) -
Read( file: String, resume: fn(Result(BitArray, String)) -> Effect(a, key), ) -
Serve( port: option.Option(Int), handle: fn(request.Request(BitArray)) -> response.Response( BitArray, ), resume: fn(Result(Nil, String)) -> Effect(a, key), ) -
Sign( algorithm: SignAlgorithm, key: key, data: BitArray, resume: fn(Result(BitArray, String)) -> Effect(a, key), ) -
StrongRandom( length: Int, resume: fn(Result(BitArray, String)) -> Effect(a, key), ) -
Write( file: String, bytes: BitArray, resume: fn(Result(Nil, String)) -> Effect(a, key), ) -
-
Zip( files: List(#(String, BitArray)), resume: fn(Result(BitArray, Nil)) -> Effect(a, key), ) -
UnixNow(resume: fn(Int) -> Effect(a, key))
pub type FetchError {
NetworkError(String)
UnableToReadBody
NotImplemented
}
Constructors
-
NetworkError(String) -
UnableToReadBody -
NotImplemented
pub type HashAlgorithm {
Sha1
Sha256
Sha384
Sha512
}
Constructors
-
Sha1 -
Sha256 -
Sha384 -
Sha512
pub type KeyPair(key) {
KeyPair(public: key, private: key)
}
Constructors
-
KeyPair(public: key, private: key)
pub type KeyPairAlgorithm {
EcKeyGenParams(name: String, named_curve: String)
}
Constructors
-
EcKeyGenParams(name: String, named_curve: String)
pub type KeyUsage {
CanEncrypt
CanDecrypt
CanSign
CanVerify
CanDeriveKey
CanDeriveBits
CanWrapKey
CanUnwrapKey
}
Constructors
-
CanEncrypt -
CanDecrypt -
CanSign -
CanVerify -
CanDeriveKey -
CanDeriveBits -
CanWrapKey -
CanUnwrapKey
pub type SignAlgorithm {
EcdsaParams(hash: HashAlgorithm)
}
Constructors
-
EcdsaParams(hash: HashAlgorithm)
Values
pub fn fetch(
request: request.Request(BitArray),
) -> Effect(Result(response.Response(BitArray), FetchError), a)
pub fn generate_keypair(
algorithm: KeyPairAlgorithm,
extractable: Bool,
usages: List(KeyUsage),
) -> Effect(Result(KeyPair(a), String), a)
pub fn hash(
algorithm: HashAlgorithm,
bytes: BitArray,
) -> Effect(Result(BitArray, String), a)
pub fn proxy(
task: Effect(a, b),
scheme: http.Scheme,
host: String,
port: option.Option(Int),
prefix: String,
) -> Effect(a, b)
pub fn serve(
port: option.Option(Int),
handle: fn(request.Request(BitArray)) -> response.Response(
BitArray,
),
) -> Effect(Result(Nil, String), a)
pub fn serve_static(
port: option.Option(Int),
files: List(#(String, BitArray)),
) -> Effect(Result(Nil, String), a)
pub fn sign(
algorithm: SignAlgorithm,
key: a,
data: BitArray,
) -> Effect(Result(BitArray, String), a)
pub fn strong_random(
length: Int,
) -> Effect(Result(BitArray, String), a)