2022-01-01 00:39:15 +00:00
|
|
|
import { AddValueRequest, AddValueResponse, Logging } from "./out/index";
|
2021-12-31 21:38:26 +00:00
|
|
|
|
|
|
|
// Logging.verbose = false;
|
|
|
|
|
2022-01-01 00:39:15 +00:00
|
|
|
import * as Client from "./out/index_client";
|
|
|
|
import * as Server from "./out/index_server";
|
2022-01-02 22:02:47 +00:00
|
|
|
import { VerificationError } from "./out/ts_base";
|
2021-12-31 21:38:26 +00:00
|
|
|
|
2022-01-01 00:39:15 +00:00
|
|
|
const client = new Client.ServiceProvider((msg) => {
|
2021-12-31 21:38:26 +00:00
|
|
|
session.onMessage(msg);
|
2022-01-01 00:39:15 +00:00
|
|
|
});
|
2021-12-31 21:38:26 +00:00
|
|
|
|
2022-01-01 00:39:15 +00:00
|
|
|
const server = new Server.ServiceProvider();
|
2021-12-31 21:38:26 +00:00
|
|
|
|
2022-01-01 00:39:15 +00:00
|
|
|
const session = server.getSession((msg) => {
|
2021-12-31 21:38:26 +00:00
|
|
|
client.onPacket(msg);
|
2022-01-01 00:39:15 +00:00
|
|
|
});
|
2021-12-31 21:38:26 +00:00
|
|
|
|
|
|
|
class TestService extends Server.TestService<undefined> {
|
2022-01-01 00:39:15 +00:00
|
|
|
async AddValuesSingleParam(
|
|
|
|
request: AddValueRequest,
|
|
|
|
ctx: undefined
|
|
|
|
): Promise<AddValueResponse> {
|
2021-12-31 21:38:26 +00:00
|
|
|
return {
|
2022-07-21 16:33:23 +00:00
|
|
|
value: request.value1 + request!.value2,
|
2022-01-01 00:39:15 +00:00
|
|
|
};
|
2021-12-31 21:38:26 +00:00
|
|
|
}
|
2022-01-01 00:39:15 +00:00
|
|
|
async AddValuesMultipleParams(
|
|
|
|
value1: number,
|
|
|
|
value2: number,
|
|
|
|
ctx: undefined
|
|
|
|
): Promise<number> {
|
2021-12-31 21:38:26 +00:00
|
|
|
return value1 + value2;
|
|
|
|
}
|
|
|
|
|
2022-01-01 15:03:43 +00:00
|
|
|
async ReturningVoid(param1) {
|
|
|
|
console.log("Calling Returning Void");
|
|
|
|
}
|
|
|
|
|
2021-12-31 21:38:26 +00:00
|
|
|
OnEvent(param1: string, ctx: undefined): void {
|
|
|
|
console.log("Received notification", param1);
|
|
|
|
}
|
2022-01-02 20:51:45 +00:00
|
|
|
|
|
|
|
async FunctionWithArrayAsParamAndReturn(vals1, vals2) {
|
2022-01-02 22:02:47 +00:00
|
|
|
return [...vals1, ...vals2];
|
2022-01-02 20:51:45 +00:00
|
|
|
}
|
2022-01-05 21:16:17 +00:00
|
|
|
|
|
|
|
async ThrowingError(ctx: undefined): Promise<void> {
|
|
|
|
throw new Error("Remote error!");
|
|
|
|
}
|
2021-12-31 21:38:26 +00:00
|
|
|
}
|
|
|
|
|
2022-01-01 00:39:15 +00:00
|
|
|
server.addService(new TestService());
|
2021-12-31 21:38:26 +00:00
|
|
|
|
|
|
|
const test = new Client.TestService(client);
|
|
|
|
|
|
|
|
async function run() {
|
2022-01-01 00:39:15 +00:00
|
|
|
console.log("Testing AddValuesSingleParam");
|
|
|
|
console.log(
|
|
|
|
await test.AddValuesSingleParam({
|
|
|
|
value1: 1,
|
|
|
|
value2: 2,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log("Testing AddValuesMultipleParams");
|
|
|
|
console.log(await test.AddValuesMultipleParams(1, 2));
|
|
|
|
|
|
|
|
console.log("Testing Notification");
|
2021-12-31 21:38:26 +00:00
|
|
|
test.OnEvent("Hi, this is an event");
|
2022-01-01 00:39:15 +00:00
|
|
|
|
|
|
|
console.log("Let verification fail!");
|
|
|
|
await test
|
|
|
|
//@ts-ignore
|
|
|
|
.AddValuesMultipleParams("asd", 2)
|
|
|
|
.then(() => {
|
|
|
|
console.log("!!!!This should have failed!!!!");
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2022-01-02 22:02:47 +00:00
|
|
|
if (err instanceof VerificationError)
|
|
|
|
console.log(
|
|
|
|
"Found expected error!",
|
|
|
|
{
|
|
|
|
type: err.type,
|
|
|
|
field: err.field,
|
|
|
|
value: err.value
|
|
|
|
}
|
|
|
|
);
|
|
|
|
else {
|
|
|
|
console.error(err);
|
|
|
|
throw new Error("Unexpected Error");
|
|
|
|
}
|
2022-01-01 00:39:15 +00:00
|
|
|
});
|
2022-01-02 20:51:45 +00:00
|
|
|
|
|
|
|
console.log("Test with arrays:");
|
2022-01-02 22:02:47 +00:00
|
|
|
console.log(
|
|
|
|
await test
|
|
|
|
//@ts-ignore
|
|
|
|
.FunctionWithArrayAsParamAndReturn([1, 2, 3], [4, 5, 6])
|
|
|
|
);
|
2022-01-02 20:51:45 +00:00
|
|
|
|
|
|
|
console.log("Let with Array fail!");
|
|
|
|
await test
|
|
|
|
//@ts-ignore
|
2022-01-02 22:02:47 +00:00
|
|
|
.FunctionWithArrayAsParamAndReturn([1, 2, 3], [4, "asd", 6])
|
2022-01-02 20:51:45 +00:00
|
|
|
.then(() => {
|
|
|
|
console.log("!!!!This should have failed!!!!");
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2022-01-02 22:02:47 +00:00
|
|
|
if (err instanceof VerificationError)
|
|
|
|
console.log(
|
|
|
|
"Found expected error!",
|
|
|
|
{
|
|
|
|
type: err.type,
|
|
|
|
field: err.field,
|
|
|
|
value: err.value
|
|
|
|
}
|
|
|
|
);
|
|
|
|
else {
|
|
|
|
console.error(err);
|
|
|
|
throw new Error("Unexpected Error");
|
|
|
|
}
|
2022-01-02 20:51:45 +00:00
|
|
|
});
|
2021-12-31 21:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
run();
|