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, `});`);