Add config to JS backend similar to it's TS counterpart (#196)

This commit is contained in:
Pavel 2021-07-07 14:45:20 +03:00 committed by GitHub
parent d24e77b5e3
commit fbc34a793a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -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};

View File

@ -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};