Skip to content

Commit

Permalink
drop old dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanlas committed Mar 27, 2024
1 parent cf69c34 commit 60b2879
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package demo

import scala.util.chaining.*

import cats.data.Chain
import cats.data.NonEmptyList
import cats.syntax.all.*

Expand All @@ -14,12 +13,10 @@ import com.htmlism.temporaldiagrams.plantuml.*
sealed trait DemoDsl

object DemoDsl:
case class Lambda(name: String) extends DemoDsl
case class Service(name: String) extends DemoDsl
case class Database(name: String, replicas: Int) extends DemoDsl
case class ClusterService(name: String, asCluster: Boolean) extends DemoDsl
case class Buffered(name: String) extends DemoDsl
case class Title(s: String) extends DemoDsl
case class Lambda(name: String) extends DemoDsl
case class Service(name: String) extends DemoDsl
case class Database(name: String, replicas: Int) extends DemoDsl
case class Title(s: String) extends DemoDsl

case class Arrow(src: String, dest: String)

Expand Down Expand Up @@ -81,30 +78,6 @@ object DemoDsl:
if isBright then skinPlantUmlYellow("database", "Database") else skinPlantUmlWhite("database")
)

case ClusterService(n, asCluster) =>
if asCluster then
Chain(1, 2, 3, 4)
.flatMap { i =>
Chain[PlantUml](
PlantUml.Component(n + i.toString, None, Option.when(isBright)("Service")),
if isBright then skinPlantUmlBlue("component", "Service") else skinPlantUmlWhite("component")
)
}
.pipe(PlantUml.ComponentDiagram.apply(_))
else
PlantUml.ComponentDiagram(
PlantUml.Component(n, None, Option.when(isBright)("Service")),
if isBright then skinPlantUmlBlue("component", "Service") else skinPlantUmlWhite("component")
)

case Buffered(n) =>
PlantUml.ComponentDiagram(
PlantUml.Component(n, None, Option.when(isBright)("Service")),
if isBright then skinPlantUmlBlue("component", "Service") else skinPlantUmlWhite("component"),
PlantUml.Queue(n + "_queue", None, None),
queueSkin
)

case Title(s) =>
PlantUml.ComponentDiagram:
PlantUml.Title(List(s))
Expand Down Expand Up @@ -150,43 +123,9 @@ object DemoDsl:
skinMermaidBlue(isBright)).toSet,
links = Set.empty
)

case ClusterService(n, asCluster) =>
if asCluster then
val nodes =
(1 to 4)
.map: i =>
Node.Simple(n + i.toString, nodeClass = Option.when(isBright)("Service"))
.toList

MermaidDiagram.of:
Flowchart:
nodes ::: skinMermaidBlue(isBright)
else
MermaidDiagram.of:
Flowchart:
Node.Simple(n, nodeClass = Option.when(isBright)("Service")) ::
skinMermaidBlue(isBright)

case Buffered(n) =>
MermaidDiagram.of:
Flowchart:
Node.WithShape(n + "_queue", Node.Shape.Cylinder) ::
Node.Simple(n, nodeClass = Option.when(isBright)("Service")) ::
skinMermaidBlue(isBright)

case Title(s) =>
MermaidDiagram.empty

private val queueSkin =
PlantUml
.SkinParamGroup("queue")
.and("fontStyle", "bold")
.and("fontColor", "#444")
.and("backgroundColor", "#faf2c8/#e6c72c")
.and("borderColor", "#807746")
.and("borderThickness", "2")

private def skinPlantUmlYellow(name: String, stereotype: String) =
PlantUml
.SkinParamGroup(name, stereotype)
Expand Down Expand Up @@ -236,19 +175,7 @@ object DemoDsl:
.toList

case class Config(
fooStyle: Config.ServiceAppearance,
barStyle: Config.ServiceAppearance,
title: String,
databaseReplicas: Int,
serviceInstances: Int
)

object Config:
sealed trait ServiceAppearance

object ServiceAppearance:
case object AsSingleton extends ServiceAppearance

case object AsCluster extends ServiceAppearance

case object WithBuffer extends ServiceAppearance
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.htmlism.temporaldiagrams.demo

import scala.collection.immutable.ListSet
import scala.util.chaining.*

import cats.*
Expand Down Expand Up @@ -29,52 +28,6 @@ class WriteDemoDslDiagrams[F[_]: Applicative: Parallel](out: FilePrinter[F]):
f: D => Chain[String],
extension: String
)(using HighlightEncoder[D, DemoDsl.Arrow], HighlightEncoder[D, DemoDsl]): F[Unit] =
val toProducer =
(_: DemoDsl.Config.ServiceAppearance) match
case DemoDsl.Config.ServiceAppearance.AsSingleton =>
Chain(
DemoDsl.ClusterService("foo", asCluster = false).tag("foo"),
WithMultiArrows.Source("foo", List("foo"))
)

case DemoDsl.Config.ServiceAppearance.AsCluster =>
Chain(
DemoDsl.ClusterService("foo", asCluster = true).tag("foo"),
WithMultiArrows.Source("foo", (1 to 4).map("foo" + _).toList)
)

case DemoDsl.Config.ServiceAppearance.WithBuffer =>
Chain(
DemoDsl.Buffered("foo").tag("foo"),
WithMultiArrows.Source("foo", List("foo"))
)

val toConsumer =
(_: DemoDsl.Config.ServiceAppearance) match
case DemoDsl.Config.ServiceAppearance.AsSingleton =>
Chain(
DemoDsl.ClusterService("bar", asCluster = false).tag("bar"),
WithMultiArrows.MultiArrow("foo", "bar", ListSet.empty),
WithMultiArrows.Destination("bar", List("bar"))
)

case DemoDsl.Config.ServiceAppearance.AsCluster =>
Chain(
DemoDsl.ClusterService("bar", asCluster = true).tag("bar"),
WithMultiArrows.MultiArrow("foo", "bar", ListSet.empty),
WithMultiArrows.Destination("bar", (1 to 4).map("bar" + _).toList)
)

case DemoDsl.Config.ServiceAppearance.WithBuffer =>
Chain(
DemoDsl.Buffered("bar").tag("bar"),
WithMultiArrows.MultiArrow("foo", "bar", ListSet.empty),
WithMultiArrows.Source("barqueue", List("bar_queue")),
WithMultiArrows.Destination("barraw", List("bar")),
WithMultiArrows.MultiArrow("barqueue", "barraw", ListSet.empty),
WithMultiArrows.Destination("bar", List("bar_queue"))
)

val toLambda =
(_: Unit) =>
Chain(
Expand Down Expand Up @@ -122,8 +75,6 @@ class WriteDemoDslDiagrams[F[_]: Applicative: Parallel](out: FilePrinter[F]):
NonEmptyList
.of(
toTitle.compose[DemoDsl.Config](_.title),
toProducer.compose[DemoDsl.Config](_.fooStyle),
toConsumer.compose[DemoDsl.Config](_.barStyle),
toLambda.compose[DemoDsl.Config](_ => ()),
toService.compose[DemoDsl.Config](_.serviceInstances),
toDatabase.compose[DemoDsl.Config](_.databaseReplicas)
Expand All @@ -132,18 +83,13 @@ class WriteDemoDslDiagrams[F[_]: Applicative: Parallel](out: FilePrinter[F]):

val initialDiagramConfig =
DemoDsl.Config(
fooStyle = DemoDsl.Config.ServiceAppearance.AsSingleton,
DemoDsl.Config.ServiceAppearance.AsSingleton,
title = "Component diagram",
databaseReplicas = 0,
serviceInstances = 1
)

val episodesDeltas =
List[DemoDsl.Config => DemoDsl.Config](
_.copy(fooStyle = DemoDsl.Config.ServiceAppearance.AsCluster),
_.copy(barStyle = DemoDsl.Config.ServiceAppearance.AsCluster),
_.copy(barStyle = DemoDsl.Config.ServiceAppearance.WithBuffer),
_.copy(databaseReplicas = 2),
_.copy(serviceInstances = 3)
)
Expand Down

0 comments on commit 60b2879

Please sign in to comment.