Skip to content

Commit

Permalink
feat(api, lsp): Case classes exported to JS as normal JSONs (#1151)
Browse files Browse the repository at this point in the history
  • Loading branch information
DieMyst authored Jun 7, 2024
1 parent af741c3 commit 037532f
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 254 deletions.
18 changes: 5 additions & 13 deletions api/api/.js/src/main/scala/api/types/InputTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,38 @@ import cats.data.Validated.{invalidNec, validNec}
import cats.data.{Chain, NonEmptyChain, Validated, ValidatedNec}
import scala.scalajs.js
import scala.scalajs.js.JSConverters.*
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scala.scalajs.js.annotation.{JSExport, JSExportAll, JSExportTopLevel}
import scala.scalajs.js.|

@JSExportTopLevel("Input")
@JSExportAll
class Input(
@JSExport
val input: String
)

@JSExportTopLevel("Path")
@JSExportAll
class Path(
@JSExport
val path: String
)

@JSExportTopLevel("Call")
@JSExportAll
class Call(
@JSExport
val functionCall: String,
@JSExport
val arguments: js.Dynamic,
@JSExport
val input: Path | Input
)

@JSExportTopLevel("AquaConfig")
@JSExportAll
class AquaConfig(
@JSExport
val logLevel: js.UndefOr[String],
@JSExport
val constants: js.UndefOr[js.Array[String]],
@JSExport
val noXor: js.UndefOr[Boolean],
@JSExport
val noRelay: js.UndefOr[Boolean],
@JSExport
val targetType: js.UndefOr[String],
@JSExport
val tracing: js.UndefOr[Boolean],
@JSExport
val noEmptyResponse: js.UndefOr[Boolean]
)

Expand Down
31 changes: 7 additions & 24 deletions api/api/.js/src/main/scala/api/types/OutputTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,24 @@ package api.types

import aqua.js.{FunctionDefJs, ServiceDefJs}
import aqua.model.transform.TransformConfig

import cats.data.Validated.{invalidNec, validNec, Invalid, Valid}
import cats.data.{Chain, NonEmptyChain, Validated, ValidatedNec}

import scala.scalajs.js
import scala.scalajs.js.JSConverters.*
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scala.scalajs.js.|

@JSExportTopLevel("AquaFunction")
case class AquaFunction(
@JSExport
funcDef: FunctionDefJs,
@JSExport
script: String
)
class AquaFunction(
val funcDef: FunctionDefJs,
val script: String
) extends js.Object

@JSExportTopLevel("GeneratedSource")
case class GeneratedSource(
@JSExport
class GeneratedSource(
val name: String,
@JSExport
val tsSource: js.UndefOr[String],
@JSExport
val jsSource: js.UndefOr[String],
@JSExport
val tsTypes: js.UndefOr[String]
)
) extends js.Object

object GeneratedSource {

Expand All @@ -40,21 +30,14 @@ object GeneratedSource {
new GeneratedSource(name, null, jsSource, tsTypes)
}

@JSExportTopLevel("CompilationResult")
class CompilationResult(
@JSExport
val services: js.Dictionary[ServiceDefJs],
@JSExport
val functions: js.Dictionary[AquaFunction],
@JSExport
val functionCall: js.UndefOr[AquaFunction],
@JSExport
val generatedSources: js.Array[GeneratedSource],
@JSExport
val errors: js.Array[String],
@JSExport
val warnings: js.Array[String]
)
) extends js.Object

object CompilationResult {

Expand Down
120 changes: 4 additions & 116 deletions aqua-src/antithesis.aqua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
aqua StreamMapTest declares *

export testGetFunc, testGetStreamFunc, testKeysFunc, testKeysStreamFunc
export testContainsFunc, testForFunc, testParSeqMap, testForTupleFunc
export testGetFunc, Srv

import "builtin.aqua"
service Srv("baaa"):
g() -> string

func testGetFunc() -> []string, []string, []string, u32:
streamMap: %string
Expand All @@ -13,116 +13,4 @@ func testGetFunc() -> []string, []string, []string, u32:
resFirst = streamMap.get(key)
streamMap <<- key, "second value"
resSecond = streamMap.get(key)
<- resEmpty, resFirst, resSecond, resSecond.length

func testGetStreamFunc() -> []string, string, string:
streamMap: %string
key = "key"
resEmptyStream = streamMap.getStream(key)
streamMap <<- key, "first value"
resFirstStream = streamMap.getStream(key)
streamMap <<- key, "second value"
resSecondStream = streamMap.getStream(key)
resFirst = resFirstStream[0]
resSecond = resSecondStream[1]
<- resEmptyStream, resFirst, resSecond

func testKeysFunc() -> []string, []string, []string:
streamMap: %string
resEmpty = streamMap.keys()
streamMap <<- "key one", ""
resFirst = streamMap.keys()
streamMap <<- "key two", ""
streamMap <<- "key one", ""
streamMap <<- "key one", "text"
resSecond = streamMap.keys()
<- resEmpty, resFirst, resSecond

func testKeysStreamFunc() -> []string, []string, []string:
streamMap: %string
resEmpty = streamMap.keysStream()
streamMap <<- "key one", ""
resFirst = streamMap.keysStream()
streamMap <<- "key one", "new"
streamMap <<- "key two", ""
resSecond = streamMap.keysStream()
<- resEmpty, resFirst, resSecond

func testContainsFunc() -> bool, bool, bool, bool, bool:
keys = ["key one", "key two"]
streamMap: %string
resFirst = streamMap.contains(keys[0])
streamMap <<- keys[0], ""
resSecond = streamMap.contains(keys[0])
resThird = streamMap.contains(keys[1])
streamMap <<- keys[0], "new"
streamMap <<- keys[1], ""
resFourth = streamMap.contains(keys[0])
resFifth = streamMap.contains(keys[1])
<- resFirst, resSecond, resThird, resFourth, resFifth

func testForFunc() -> []string, []string:
streamMap: %string
streamMap <<- "key one", "1"
streamMap <<- "key one", "2"

streamMap <<- "key two", "3"
streamMap <<- "key two", "4"
streamMap <<- "key two", "5"

streamMap <<- "key three", "6"

streamMap <<- "key four", "7"

streamKeys: *string
streamValues: *string

for kv <- streamMap:
streamKeys <<- kv.key
streamValues <<- kv.value
<- streamKeys, streamValues

func testParSeqMap(relay1: string, relay2: string, relay3: string) -> string:
relays = [relay1, relay2, relay3]
map: %u64
map2: %u64
parseq r <- relays on r:
map <<- "time", Peer.timestamp_ms()

for r <- relays par:
on r:
join map.get("time")[relays.length - 1]
map2 <<- "time", Peer.timestamp_ms()

join map2.get("time")[relays.length - 1]
<- "ok"

func testForTupleFunc() -> []string, []string, []string:
streamMap: %string
streamMap <<- "key one", "1"
streamMap <<- "key one", "2"

streamMap <<- "key two", "3"
streamMap <<- "key two", "4"
streamMap <<- "key two", "5"

streamMap <<- "key three", "6"

streamMap <<- "key four", "7"

streamFirst: *string
streamSecond: *string
streamThird: *string

for k, v <- streamMap:
streamFirst <<- k
streamSecond <<- v

for k, v <- streamMap:
streamFirst <<- v
streamSecond <<- k

for k, v <- streamMap:
streamThird <<- streamMap.get(k)!

<- streamFirst, streamSecond, streamThird
<- resEmpty, resFirst, resSecond, resSecond.length
Loading

0 comments on commit 037532f

Please sign in to comment.