Supporting void function return type
This commit is contained in:
parent
478094f2c3
commit
579055d8fb
@ -28,6 +28,7 @@ type AddValueResponse {
|
|||||||
service TestService {
|
service TestService {
|
||||||
AddValuesSingleParam(request: AddValueRequest): AddValueResponse;
|
AddValuesSingleParam(request: AddValueRequest): AddValueResponse;
|
||||||
AddValuesMultipleParams(value1: number, value2: number): number;
|
AddValuesMultipleParams(value1: number, value2: number): number;
|
||||||
|
ReturningVoid(param1: number): void;
|
||||||
|
|
||||||
notification OnEvent(param1: string);
|
notification OnEvent(param1: string);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,10 @@ class TestService extends Server.TestService<undefined> {
|
|||||||
return value1 + value2;
|
return value1 + value2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async ReturningVoid(param1) {
|
||||||
|
console.log("Calling Returning Void");
|
||||||
|
}
|
||||||
|
|
||||||
OnEvent(param1: string, ctx: undefined): void {
|
OnEvent(param1: string, ctx: undefined): void {
|
||||||
console.log("Received notification", param1);
|
console.log("Received notification", param1);
|
||||||
}
|
}
|
||||||
|
11
lib/jrpc.js
11
lib/jrpc.js
@ -7341,7 +7341,7 @@ function get_ir(parsed) {
|
|||||||
if (!depends.some((a) => a === fnc.return_type))
|
if (!depends.some((a) => a === fnc.return_type))
|
||||||
depends.push(fnc.return_type);
|
depends.push(fnc.return_type);
|
||||||
} else {
|
} else {
|
||||||
if (builtin.indexOf(fnc.return_type) < 0) {
|
if (fnc.return_type !== "void" && builtin.indexOf(fnc.return_type) < 0) {
|
||||||
throw new IRError(fnc, `Type ${fnc.return_type} is not defined`);
|
throw new IRError(fnc, `Type ${fnc.return_type} is not defined`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7432,7 +7432,8 @@ function compile(ir, target) {
|
|||||||
var conversion = {
|
var conversion = {
|
||||||
boolean: "boolean",
|
boolean: "boolean",
|
||||||
number: "number",
|
number: "number",
|
||||||
string: "string"
|
string: "string",
|
||||||
|
void: "void"
|
||||||
};
|
};
|
||||||
function toJSType(type) {
|
function toJSType(type) {
|
||||||
return conversion[type] || type;
|
return conversion[type] || type;
|
||||||
@ -7566,7 +7567,7 @@ var TypescriptTarget = class extends CompileTarget {
|
|||||||
a(1, `${dep},`);
|
a(1, `${dep},`);
|
||||||
});
|
});
|
||||||
a(0, `}`);
|
a(0, `}`);
|
||||||
a(0, this.generateImport("{ verify_number, verify_string, verify_boolean }", "./service_base"));
|
a(0, this.generateImport("{ verify_number, verify_string, verify_boolean, verify_void }", "./service_base"));
|
||||||
a(0, this.generateImport("{ Service, ServiceProvider, getRandomID }", "./service_client"));
|
a(0, this.generateImport("{ Service, ServiceProvider, getRandomID }", "./service_client"));
|
||||||
a(0, ``);
|
a(0, ``);
|
||||||
a(0, `export class ${def.name} extends Service {`);
|
a(0, `export class ${def.name} extends Service {`);
|
||||||
@ -7622,7 +7623,7 @@ var TypescriptTarget = class extends CompileTarget {
|
|||||||
});
|
});
|
||||||
a(0, `}`);
|
a(0, `}`);
|
||||||
a(0, this.generateImport("{ Service }", "./service_server"));
|
a(0, this.generateImport("{ Service }", "./service_server"));
|
||||||
a(0, this.generateImport("{ verify_number, verify_string, verify_boolean }", "./service_base"));
|
a(0, this.generateImport("{ verify_number, verify_string, verify_boolean, verify_void }", "./service_base"));
|
||||||
a(0, ``);
|
a(0, ``);
|
||||||
a(0, `export abstract class ${def.name}<T> extends Service<T> {`);
|
a(0, `export abstract class ${def.name}<T> extends Service<T> {`);
|
||||||
a(1, `public name = "${def.name}";`);
|
a(1, `public name = "${def.name}";`);
|
||||||
@ -7657,7 +7658,7 @@ var TypescriptTarget = class extends CompileTarget {
|
|||||||
}
|
}
|
||||||
a(2, ``);
|
a(2, ``);
|
||||||
a(2, `p.push(ctx);`);
|
a(2, `p.push(ctx);`);
|
||||||
a(2, `return this.${fnc.name}.call(this, ...p);`);
|
a(2, `return this.${fnc.name}.call(this, ...p)${fnc.return == "void" ? ".then(res => undefined)" : ""};`);
|
||||||
a(1, `}`);
|
a(1, `}`);
|
||||||
a(0, ``);
|
a(0, ``);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hibas123/jrpcgen",
|
"name": "@hibas123/jrpcgen",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"packageManager": "yarn@3.1.1",
|
"packageManager": "yarn@3.1.1",
|
||||||
|
@ -185,7 +185,7 @@ export default function get_ir(parsed: Parsed): IR {
|
|||||||
if (!depends.some((a) => a === fnc.return_type))
|
if (!depends.some((a) => a === fnc.return_type))
|
||||||
depends.push(fnc.return_type);
|
depends.push(fnc.return_type);
|
||||||
} else {
|
} else {
|
||||||
if (builtin.indexOf(fnc.return_type) < 0) {
|
if (fnc.return_type !== "void" && builtin.indexOf(fnc.return_type) < 0) {
|
||||||
throw new IRError(
|
throw new IRError(
|
||||||
fnc,
|
fnc,
|
||||||
`Type ${fnc.return_type} is not defined`
|
`Type ${fnc.return_type} is not defined`
|
||||||
|
@ -15,6 +15,7 @@ const conversion = {
|
|||||||
boolean: "boolean",
|
boolean: "boolean",
|
||||||
number: "number",
|
number: "number",
|
||||||
string: "string",
|
string: "string",
|
||||||
|
void: "void"
|
||||||
};
|
};
|
||||||
|
|
||||||
function toJSType(type: string): string {
|
function toJSType(type: string): string {
|
||||||
@ -215,7 +216,7 @@ export class TypescriptTarget extends CompileTarget {
|
|||||||
a(
|
a(
|
||||||
0,
|
0,
|
||||||
this.generateImport(
|
this.generateImport(
|
||||||
"{ verify_number, verify_string, verify_boolean }",
|
"{ verify_number, verify_string, verify_boolean, verify_void }",
|
||||||
"./service_base"
|
"./service_base"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -312,7 +313,7 @@ export class TypescriptTarget extends CompileTarget {
|
|||||||
a(
|
a(
|
||||||
0,
|
0,
|
||||||
this.generateImport(
|
this.generateImport(
|
||||||
"{ verify_number, verify_string, verify_boolean }",
|
"{ verify_number, verify_string, verify_boolean, verify_void }",
|
||||||
"./service_base"
|
"./service_base"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -360,7 +361,7 @@ export class TypescriptTarget extends CompileTarget {
|
|||||||
|
|
||||||
a(2, ``);
|
a(2, ``);
|
||||||
a(2, `p.push(ctx);`);
|
a(2, `p.push(ctx);`);
|
||||||
a(2, `return this.${fnc.name}.call(this, ...p);`);
|
a(2, `return this.${fnc.name}.call(this, ...p)${fnc.return == "void" ? ".then(res => undefined)" : ""};`);
|
||||||
a(1, `}`);
|
a(1, `}`);
|
||||||
a(0, ``);
|
a(0, ``);
|
||||||
}
|
}
|
||||||
|
@ -46,3 +46,7 @@ export function verify_boolean(data: any) {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function verify_void(data: any) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user