Config options to omit xor wrapper, relay passing (#105)

This commit is contained in:
Dmitry Kurinskiy 2021-04-30 11:43:48 +03:00 committed by GitHub
parent 0e550491fa
commit 53ad29ab31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 26 deletions

View File

@ -58,12 +58,11 @@ case class TypescriptFunc(func: FuncCallable) {
| `,
| )
| .configHandler((h) => {
| h.on('${conf.getDataService}', 'relay', () => {
| ${conf.relayVarName.fold("") { r =>
s"""h.on('${conf.getDataService}', '$r', () => {
| return client.relayPeerId!;
| });
| h.on('getRelayService', 'hasRelay', () => {// Not Used
| return client.relayPeerId !== undefined;
| });
| });""".stripMargin
}}
| $setCallbacks
| ${returnCallback.getOrElse("")}
| h.onEvent('${conf.errorHandlingService}', '${conf.errorFuncName}', (args) => {

View File

@ -29,24 +29,39 @@ object AquaCli extends IOApp {
.map(_ => true)
.withDefault(false)
val noRelay: Opts[Boolean] =
Opts
.flag("no-relay", "Do not generate a pass through the relay node")
.map(_ => true)
.withDefault(false)
val noXorWrapper: Opts[Boolean] =
Opts
.flag("no-xor", "Do not generate a wrapper that catches and displays errors")
.map(_ => true)
.withDefault(false)
def mainOpts: Opts[IO[ExitCode]] =
(inputOpts, importOpts, outputOpts, compileToAir).mapN { case (input, imports, output, toAir) =>
AquaCompiler
.compileFilesTo[IO](
input,
imports,
output,
if (toAir) AquaCompiler.AirTarget else AquaCompiler.TypescriptTarget,
BodyConfig()
)
.map {
case Validated.Invalid(errs) =>
errs.map(println)
ExitCode.Error
case Validated.Valid(res) =>
res.map(println)
ExitCode.Success
}
(inputOpts, importOpts, outputOpts, compileToAir, noRelay, noXorWrapper).mapN {
case (input, imports, output, toAir, noRelay, noXor) =>
AquaCompiler
.compileFilesTo[IO](
input,
imports,
output,
if (toAir) AquaCompiler.AirTarget else AquaCompiler.TypescriptTarget, {
val bc = BodyConfig(wrapWithXor = !noXor)
bc.copy(relayVarName = bc.relayVarName.filterNot(_ => noRelay))
}
)
.map {
case Validated.Invalid(errs) =>
errs.map(println)
ExitCode.Error
case Validated.Valid(res) =>
res.map(println)
ExitCode.Success
}
}
override def run(args: List[String]): IO[ExitCode] =

View File

@ -8,7 +8,7 @@ case class BodyConfig(
errorHandlingService: String = "errorHandlingSrv",
errorFuncName: String = "error",
respFuncName: String = "response",
relayVarName: String = "relay",
relayVarName: Option[String] = Some("relay"),
wrapWithXor: Boolean = true
) {

View File

@ -12,7 +12,7 @@ object Transform {
def forClient(func: FuncCallable, conf: BodyConfig): Cofree[Chain, OpTag] = {
val initCallable: InitPeerCallable = InitViaRelayCallable(
Chain.one(VarModel(conf.relayVarName, ScalarType.string))
Chain.fromOption(conf.relayVarName).map(VarModel(_, ScalarType.string))
)
val errorsCatcher = ErrorsCatcher(
enabled = conf.wrapWithXor,
@ -23,8 +23,8 @@ object Transform {
val argsProvider: ArgsProvider =
ArgsFromService(
conf.dataSrvId,
conf.relayVarName -> ScalarType.string :: func.args.dataArgs.toList.map(add =>
add.name -> add.dataType
conf.relayVarName.map(_ -> ScalarType.string).toList ::: func.args.dataArgs.toList.map(
add => add.name -> add.dataType
)
)