From fbc34a793a2cb9853ff538ab0bde83c22467bae1 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 7 Jul 2021 14:45:20 +0300 Subject: [PATCH] Add config to JS backend similar to it's TS counterpart (#196) --- .../main/scala/aqua/backend/js/JavaScriptFunc.scala | 12 +++++++++--- .../main/scala/aqua/backend/ts/TypeScriptFunc.scala | 8 +++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/js/src/main/scala/aqua/backend/js/JavaScriptFunc.scala b/backend/js/src/main/scala/aqua/backend/js/JavaScriptFunc.scala index 80506f9a..c7124f1a 100644 --- a/backend/js/src/main/scala/aqua/backend/js/JavaScriptFunc.scala +++ b/backend/js/src/main/scala/aqua/backend/js/JavaScriptFunc.scala @@ -43,12 +43,15 @@ case class JavaScriptFunc(func: FuncCallable) { val returnVal = func.ret.fold("Promise.race([promise, Promise.resolve()])")(_ => "promise") + val configArgName ="config" + s""" |export async function ${func.funcName}(client${if (func.args.isEmpty) "" - else ", "}${argsJavaScript}) { + else ", "}${argsJavaScript}, $configArgName) { | let request; + | $configArgName = $configArgName || {}; | const promise = new Promise((resolve, reject) => { - | request = new RequestFlowBuilder() + | var r = new RequestFlowBuilder() | .disableInjections() | .withRawScript( | ` @@ -73,7 +76,10 @@ case class JavaScriptFunc(func: FuncCallable) { | .handleTimeout(() => { | reject('Request timed out for ${func.funcName}'); | }) - | .build(); + | if(${configArgName}.ttl) { + | r.withTTL(${configArgName}.ttl) + | } + | request = r.build(); | }); | await client.initiateFlow(request); | return ${returnVal}; diff --git a/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptFunc.scala b/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptFunc.scala index 05ad3cdf..5ef82161 100644 --- a/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptFunc.scala +++ b/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptFunc.scala @@ -66,9 +66,8 @@ case class TypeScriptFunc(func: FuncCallable) { else ", "}${argsTypescript}, $configArgName?: $configType): Promise<$retType> { | let request: RequestFlow; | const promise = new Promise<$retType>((resolve, reject) => { - | request = new RequestFlowBuilder() + | const r = new RequestFlowBuilder() | .disableInjections() - | .withTTL($configArgName?.ttl || 5000) | .withRawScript( | ` |${tsAir.show} @@ -92,7 +91,10 @@ case class TypeScriptFunc(func: FuncCallable) { | .handleTimeout(() => { | reject('Request timed out for ${func.funcName}'); | }) - | .build(); + | if(${configArgName}?.ttl) { + | r.withTTL(${configArgName}.ttl) + | } + | request = r.build(); | }); | await $clientArgName.initiateFlow(request!); | return ${returnVal};