[add] first

This commit is contained in:
2022-04-29 15:25:10 +08:00
commit da8024fc30
87 changed files with 16892 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
import { TsrpcClient } from "../../..";
import { serviceProto } from '../server/protocols/proto';
let client = new TsrpcClient({
proto: serviceProto
});
client.callApi('Test', { name: 'ssss' }).then(v => {
console.log('then', v)
}).catch(e => {
console.log('catch', e)
})

View File

@@ -0,0 +1,10 @@
import { TsrpcServer } from '../../../index';
import { serviceProto } from './protocols/proto';
let server = new TsrpcServer({
proto: serviceProto,
});
server.autoImplementApi('src/api');
server.start();

View File

@@ -0,0 +1,7 @@
export interface ReqTest {
name: string
}
export interface ResTest {
reply: string
}

View File

@@ -0,0 +1,52 @@
import { ServiceProto } from 'tsrpc-proto';
import { ReqTest, ResTest } from './PtlTest'
export interface ServiceType {
req: {
"Test": ReqTest
},
res: {
"Test": ResTest
},
msg: {
}
}
export const serviceProto: ServiceProto<ServiceType> = {
"services": [
{
"id": 0,
"name": "Test",
"type": "api",
"req": "PtlTest/ReqTest",
"res": "PtlTest/ResTest"
}
],
"types": {
"PtlTest/ReqTest": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "name",
"type": {
"type": "String"
}
}
]
},
"PtlTest/ResTest": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "reply",
"type": {
"type": "String"
}
}
]
}
}
};

View File

@@ -0,0 +1,18 @@
import { ReqTest, ResTest } from "../../protocols/PtlTest";
import { ApiCall } from "../../../../..";
export async function ApiTest(call: ApiCall<ReqTest, ResTest>) {
await new Promise(rs => {
let i = 5;
call.logger.log(i);
let interval = setInterval(() => {
call.logger.log(--i);
if (i === 0) {
clearInterval(interval);
rs();
}
}, 1000);
});
call.error('asdfasdf', { a: 1, b: 2 })
}