Besom - a Pulumi SDK for Scala. Also, incidentally, a broom made of twigs tied round a stick. Brooms and besoms are used for protection, to ward off evil spirits, and cleansing of ritual spaces.
The current StackReference in Pulumi uses a stringly typed interface that necessitates calling getOutput(key: String) to retrieve an Output[Option[JsValue]] and requireOutput(key: String) to fetch an Output[JsValue]. Both methods demand manual type conversion from JsValue, which is error-prone.
Issue:
Develop a type-safe API that allows direct deserialization into predefined types, maintaining backward compatibility with the existing API.
Proposed Solution:
Let's assume this case class as representation of outputs of a referred stack:
case class Platform(kubeconfig: String, nodes: List[String])
Simple variant:
Implement a semiauto derivation pattern for the StackReferenceOutputs typeclass to manage serialization while allowing for customizations. Add a method to StackReference that provides typed outputs directly:
def outputs[A: StackReferenceOutputs]: Output[A]
More involved variant:
Introduce a new API for StackReference that supports typed outputs through a generic type parameter. Define a Platform case class for expected outputs like kubeconfig and nodes.
case class Platform(kubeconfig: String, nodes: List[String])
Adapt the StackReferenceFactory to use type classes for deserialization.
Description:
The current
StackReference
in Pulumi uses a stringly typed interface that necessitates callinggetOutput(key: String)
to retrieve anOutput[Option[JsValue]]
andrequireOutput(key: String)
to fetch anOutput[JsValue]
. Both methods demand manual type conversion fromJsValue
, which is error-prone.Issue:
Develop a type-safe API that allows direct deserialization into predefined types, maintaining backward compatibility with the existing API.
Proposed Solution:
Let's assume this case class as representation of outputs of a referred stack:
Simple variant:
Implement a semiauto derivation pattern for the
StackReferenceOutputs
typeclass to manage serialization while allowing for customizations. Add a method toStackReference
that provides typed outputs directly:More involved variant:
Introduce a new API for
StackReference
that supports typed outputs through a generic type parameter. Define aPlatform
case class for expected outputs likekubeconfig
andnodes
.Adapt the
StackReferenceFactory
to use type classes for deserialization.