Skip to content

Commit

Permalink
it works! or at least looks like it works!
Browse files Browse the repository at this point in the history
  • Loading branch information
lbialy committed Sep 6, 2024
1 parent 1ee09ec commit 70d2538
Show file tree
Hide file tree
Showing 20 changed files with 438 additions and 146 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/besom/aliases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import besom.internal.ResourceOptsVariant
object aliases:
type Output[+A] = besom.internal.Output[A]
object Output extends besom.internal.OutputFactory
// object OutputExtensions extends besom.internal.OutputExtensionsFactory
// export OutputExtensions.*
object OutputExtensions extends besom.internal.OutputExtensionsFactory
export OutputExtensions.*
type Input[+A] = besom.internal.Input[A]
object Input:
export besom.internal.Input.*
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/besom/internal/BesomModule.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package besom.internal

import besom.internal.logging.{LocalBesomLogger => logger, BesomLogger}
import besom.internal.logging.{BesomMDC, LocalBesomLogger => logger, BesomLogger}
import besom.util.printer

/** An abstract effect Besom module, which can be implemented for different effect types.
Expand Down Expand Up @@ -40,6 +40,8 @@ trait EffectBesomModule extends BesomSyntax:
* the program to run
*/
def run(program: Context ?=> Stack): Unit =
given emptyMDC: BesomMDC[_] = BesomMDC.empty

val everything: Result[Unit] = Result.scoped {
for
_ <- BesomLogger.setupLogger()
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/besom/internal/Context.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class ContextImpl(
override private[besom] def pulumiStack: NonEmptyString = runInfo.stack

override private[besom] def getParentURN: Result[URN] =
stackPromise.get.flatMap(_.urn.getData).map(_.getValue).flatMap {
stackPromise.get.flatMap(_.urn.getData(using this)).map(_.getValue).flatMap {
case Some(urn) => Result.pure(urn)
case None => Result.fail(Exception("Stack urn is not available. This should not happen."))
}
Expand Down
24 changes: 11 additions & 13 deletions core/src/main/scala/besom/internal/Input.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,59 @@ object Input:

given simpleInputOps: {} with
extension [A](input: Input[A])
private[Input] def wrappedAsOutput(isSecret: Boolean = false)(using ctx: Context): Output[A] =
private[Input] def wrappedAsOutput(isSecret: Boolean = false): Output[A] =
input match
case output: Output[_] => output.asInstanceOf[Output[A]]
case a: A @unchecked => if isSecret then Output.secret(a) else Output(a)

extension [A](input: Input[A])
def asOutput(isSecret: Boolean = false)(using ctx: Context): Output[A] =
def asOutput(isSecret: Boolean = false): Output[A] =
input.wrappedAsOutput(isSecret)

extension [A](input: Input.Optional[A])
private[Input] def wrappedAsOptionOutput(isSecret: Boolean = false)(using ctx: Context): Output[Option[A]] =
private[Input] def wrappedAsOptionOutput(isSecret: Boolean = false): Output[Option[A]] =
val output = input match
case output: Output[_] => output.asInstanceOf[Output[A | Option[A]]]
case maybeA: (A | Option[A]) @unchecked => if isSecret then Output.secret(maybeA) else Output(maybeA)
output.map(_.asOption)

def asOptionOutput(isSecret: Boolean = false)(using ctx: Context): Output[Option[A]] =
def asOptionOutput(isSecret: Boolean = false): Output[Option[A]] =
input.wrappedAsOptionOutput(isSecret)

given mapInputOps: {} with
private def inputMapToMapOutput[A](inputMap: Map[String, Input[A]], isSecret: Boolean)(using ctx: Context): Output[Map[String, A]] =
private def inputMapToMapOutput[A](inputMap: Map[String, Input[A]], isSecret: Boolean): Output[Map[String, A]] =
val outputMap = inputMap.view.mapValues(_.asOutput(isSecret)).toMap
Output.traverseMap(outputMap)

extension [A](input: Input[Map[String, Input[A]]])
def asOutput(isSecret: Boolean = false)(using ctx: Context): Output[Map[String, A]] =
def asOutput(isSecret: Boolean = false): Output[Map[String, A]] =
input.wrappedAsOutput(isSecret).flatMap(inputMapToMapOutput(_, isSecret = isSecret))

extension [A](input: Input.Optional[Map[String, Input[A]]])
def asOptionOutput(isSecret: Boolean = false)(using ctx: Context): Output[Option[Map[String, A]]] =
def asOptionOutput(isSecret: Boolean = false): Output[Option[Map[String, A]]] =
input.wrappedAsOptionOutput(isSecret).flatMap {
case Some(map) => inputMapToMapOutput(map, isSecret = isSecret).map(Option(_))
case None => Output(None)
}

given iterableInputOps: {} with
private def inputIterableToIterableOutput[A](inputIterable: Iterable[Input[A]], isSecret: Boolean)(using
ctx: Context
): Output[Iterable[A]] =
private def inputIterableToIterableOutput[A](inputIterable: Iterable[Input[A]], isSecret: Boolean): Output[Iterable[A]] =
val outputIterable = inputIterable.map(simpleInputOps.asOutput(_)(isSecret = isSecret))
Output.sequence(outputIterable)

extension [A](input: Input.OneOrIterable[A])
def asManyOutput(isSecret: Boolean = false)(using ctx: Context): Output[Iterable[A]] =
def asManyOutput(isSecret: Boolean = false): Output[Iterable[A]] =
input.wrappedAsOutput(isSecret).flatMap {
case iterable: Iterable[Input[A]] @unchecked => inputIterableToIterableOutput(iterable, isSecret = isSecret)
case a: A @unchecked => Output(Iterable(a))
}

extension [A](input: Input[Iterable[Input[A]]])
def asOutput(isSecret: Boolean = false)(using ctx: Context): Output[Iterable[A]] =
def asOutput(isSecret: Boolean = false): Output[Iterable[A]] =
input.wrappedAsOutput(isSecret).flatMap(inputIterableToIterableOutput(_, isSecret = isSecret))

extension [A](input: Input.Optional[Iterable[Input[A]]])
def asOptionOutput(isSecret: Boolean = false)(using ctx: Context): Output[Option[Iterable[A]]] =
def asOptionOutput(isSecret: Boolean = false): Output[Option[Iterable[A]]] =
input.wrappedAsOptionOutput(isSecret).flatMap {
case Some(map) => inputIterableToIterableOutput(map, isSecret = isSecret).map(Option(_))
case None => Output(None)
Expand Down
Loading

0 comments on commit 70d2538

Please sign in to comment.