From 99563959c6a73017ba4967c7b58154559ec83528 Mon Sep 17 00:00:00 2001 From: K35 Date: Mon, 3 Jan 2022 21:08:25 +0000 Subject: [PATCH] Adding some Readme stuff --- README.md | 4 ++++ examples/example.jrpc | 1 + src/targets/typescript.ts | 15 ++++++++++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fa66103..f7a9d89 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@ type Test { } service TestService { + @Description("This Function adds two number") + @Param("v1", "The first Number") + @Param("v2", "The second Number") + @Returns("The added values of the two numbers") AddNumbers(v1: number, v2: number): number; diff --git a/examples/example.jrpc b/examples/example.jrpc index 0e65668..312a20f 100644 --- a/examples/example.jrpc +++ b/examples/example.jrpc @@ -28,6 +28,7 @@ type AddValueResponse { service TestService { @Description("Add two numbers") @Param("request", "Parameter containing the two numbers") + @Returns("") AddValuesSingleParam(request: AddValueRequest): AddValueResponse; @Description("Add two numbers") diff --git a/src/targets/typescript.ts b/src/targets/typescript.ts index 92bc0a0..8d1a0eb 100644 --- a/src/targets/typescript.ts +++ b/src/targets/typescript.ts @@ -308,10 +308,15 @@ export class TypescriptTarget extends CompileTarget { (e) => `${e.name}: ${toJSType(e.type) + (e.array ? "[]" : "")}` ) .join(", "); + //TODO: Prio 1 : Verify and strip input parameters //TODO: Prio 2 : Add optional parameters to this and the declaration file + // const verifyInputs = () => { + + // } + if (!fnc.return) { - a(1, `${fnc.name}(${params}): void {`); + a(1, `${fnc.name}(${params}): void {`);1 a(2, `this._provider.sendMessage({`); a(3, `jsonrpc: "2.0",`); a(3, `method: "${def.name}.${fnc.name}",`); @@ -334,11 +339,11 @@ export class TypescriptTarget extends CompileTarget { a(3, `});`); a(2, `}).then(result => {`); if (fnc.return.array) { - a(2, `for(const elm of result) {`); - a(3, `apply_${fnc.return.type}(elm);`); - a(2, `}`); + a(3, `for(let i = 0; i < result.length; i++) {`); + a(4, `result[i] = apply_${fnc.return.type}(result[i]);`); + a(3, `}`); } else { - a(3, `apply_${fnc.return.type}(result);`); + a(3, `result = apply_${fnc.return.type}(result);`); } a(3, `return result;`); a(2, `});`);