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 = val returnVal =
func.ret.fold("Promise.race([promise, Promise.resolve()])")(_ => "promise") func.ret.fold("Promise.race([promise, Promise.resolve()])")(_ => "promise")
val configArgName ="config"
s""" s"""
|export async function ${func.funcName}(client${if (func.args.isEmpty) "" |export async function ${func.funcName}(client${if (func.args.isEmpty) ""
else ", "}${argsJavaScript}) { else ", "}${argsJavaScript}, $configArgName) {
| let request; | let request;
| $configArgName = $configArgName || {};
| const promise = new Promise((resolve, reject) => { | const promise = new Promise((resolve, reject) => {
| request = new RequestFlowBuilder() | var r = new RequestFlowBuilder()
| .disableInjections() | .disableInjections()
| .withRawScript( | .withRawScript(
| ` | `
@ -73,7 +76,10 @@ case class JavaScriptFunc(func: FuncCallable) {
| .handleTimeout(() => { | .handleTimeout(() => {
| reject('Request timed out for ${func.funcName}'); | reject('Request timed out for ${func.funcName}');
| }) | })
| .build(); | if(${configArgName}.ttl) {
| r.withTTL(${configArgName}.ttl)
| }
| request = r.build();
| }); | });
| await client.initiateFlow(request); | await client.initiateFlow(request);
| return ${returnVal}; | return ${returnVal};

View File

@ -66,9 +66,8 @@ case class TypeScriptFunc(func: FuncCallable) {
else ", "}${argsTypescript}, $configArgName?: $configType): Promise<$retType> { else ", "}${argsTypescript}, $configArgName?: $configType): Promise<$retType> {
| let request: RequestFlow; | let request: RequestFlow;
| const promise = new Promise<$retType>((resolve, reject) => { | const promise = new Promise<$retType>((resolve, reject) => {
| request = new RequestFlowBuilder() | const r = new RequestFlowBuilder()
| .disableInjections() | .disableInjections()
| .withTTL($configArgName?.ttl || 5000)
| .withRawScript( | .withRawScript(
| ` | `
|${tsAir.show} |${tsAir.show}
@ -92,7 +91,10 @@ case class TypeScriptFunc(func: FuncCallable) {
| .handleTimeout(() => { | .handleTimeout(() => {
| reject('Request timed out for ${func.funcName}'); | reject('Request timed out for ${func.funcName}');
| }) | })
| .build(); | if(${configArgName}?.ttl) {
| r.withTTL(${configArgName}.ttl)
| }
| request = r.build();
| }); | });
| await $clientArgName.initiateFlow(request!); | await $clientArgName.initiateFlow(request!);
| return ${returnVal}; | return ${returnVal};