examples to new tsrpc-cli
This commit is contained in:
parent
c21445548e
commit
69a90884d5
@ -4,20 +4,20 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts",
|
||||
"sync": "tsrpc sync --from src/shared --to ../frontend/src/shared",
|
||||
"api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api",
|
||||
"dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"",
|
||||
"build": "tsrpc build"
|
||||
"proto": "tsrpc proto --config tsrpc.config.ts",
|
||||
"sync": "tsrpc sync --config tsrpc.config.ts",
|
||||
"api": "tsrpc api --config tsrpc.config.ts",
|
||||
"dev": "tsrpc dev --config tsrpc.config.ts",
|
||||
"build": "tsrpc build --config tsrpc.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^15.12.3",
|
||||
"@types/node": "^15.14.9",
|
||||
"onchange": "^7.1.0",
|
||||
"ts-node": "^9.1.1",
|
||||
"tsrpc-cli": "^2.0.3",
|
||||
"typescript": "^4.3.4"
|
||||
"tsrpc-cli": "^2.0.8",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc": "^3.0.2"
|
||||
"tsrpc": "^3.0.9"
|
||||
}
|
||||
}
|
||||
|
36
examples/chatroom/backend/tsrpc.config.ts
Normal file
36
examples/chatroom/backend/tsrpc.config.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
const tsrpcConf: TsrpcConfig = {
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api' // API dir
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
{
|
||||
from: 'src/shared',
|
||||
to: '../frontend/src/shared',
|
||||
type: 'symlink' // Change this to 'copy' if your environment not support symlink
|
||||
}
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
||||
export default tsrpcConf;
|
@ -7,15 +7,15 @@
|
||||
"build": "webpack --mode=production"
|
||||
},
|
||||
"devDependencies": {
|
||||
"copy-webpack-plugin": "^9.0.0",
|
||||
"html-webpack-plugin": "^5.3.1",
|
||||
"ts-loader": "^9.2.3",
|
||||
"typescript": "^4.3.4",
|
||||
"webpack": "^5.39.1",
|
||||
"webpack-cli": "^4.7.2",
|
||||
"copy-webpack-plugin": "^9.0.1",
|
||||
"html-webpack-plugin": "^5.3.2",
|
||||
"ts-loader": "^9.2.6",
|
||||
"typescript": "^4.4.3",
|
||||
"webpack": "^5.57.1",
|
||||
"webpack-cli": "^4.9.0",
|
||||
"webpack-dev-server": "^3.11.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc-browser": "^3.0.3"
|
||||
"tsrpc-browser": "^3.0.7"
|
||||
}
|
||||
}
|
||||
|
1
examples/chatroom/frontend/src/shared
Symbolic link
1
examples/chatroom/frontend/src/shared
Symbolic link
@ -0,0 +1 @@
|
||||
../../backend/src/shared
|
@ -1,4 +0,0 @@
|
||||
export interface MsgChat {
|
||||
content: string,
|
||||
time: Date
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
export interface ReqSend {
|
||||
content: string
|
||||
}
|
||||
|
||||
export interface ResSend {
|
||||
time: Date
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
import { ServiceProto } from 'tsrpc-proto';
|
||||
import { MsgChat } from './MsgChat';
|
||||
import { ReqSend, ResSend } from './PtlSend';
|
||||
|
||||
export interface ServiceType {
|
||||
api: {
|
||||
"Send": {
|
||||
req: ReqSend,
|
||||
res: ResSend
|
||||
}
|
||||
},
|
||||
msg: {
|
||||
"Chat": MsgChat
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"services": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Chat",
|
||||
"type": "msg"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Send",
|
||||
"type": "api"
|
||||
}
|
||||
],
|
||||
"types": {
|
||||
"MsgChat/MsgChat": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "content",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "time",
|
||||
"type": {
|
||||
"type": "Date"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlSend/ReqSend": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "content",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlSend/ResSend": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "time",
|
||||
"type": {
|
||||
"type": "Date"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
@ -4,20 +4,20 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts",
|
||||
"sync": "tsrpc sync --from src/shared --to ../frontend/src/shared",
|
||||
"api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api",
|
||||
"dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"",
|
||||
"build": "tsrpc build"
|
||||
"proto": "tsrpc proto --config tsrpc.config.ts",
|
||||
"sync": "tsrpc sync --config tsrpc.config.ts",
|
||||
"api": "tsrpc api --config tsrpc.config.ts",
|
||||
"dev": "tsrpc dev --config tsrpc.config.ts",
|
||||
"build": "tsrpc build --config tsrpc.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^15.12.5",
|
||||
"@types/node": "^15.14.9",
|
||||
"onchange": "^7.1.0",
|
||||
"ts-node": "^10.0.0",
|
||||
"tsrpc-cli": "^2.0.3",
|
||||
"typescript": "^4.3.4"
|
||||
"ts-node": "^10.2.1",
|
||||
"tsrpc-cli": "^2.0.8",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc": "^3.0.4"
|
||||
"tsrpc": "^3.0.9"
|
||||
}
|
||||
}
|
||||
|
36
examples/client-mock/backend/tsrpc.config.ts
Normal file
36
examples/client-mock/backend/tsrpc.config.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
const tsrpcConf: TsrpcConfig = {
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api' // API dir
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
{
|
||||
from: 'src/shared',
|
||||
to: '../frontend/src/shared',
|
||||
type: 'symlink' // Change this to 'copy' if your environment not support symlink
|
||||
}
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
||||
export default tsrpcConf;
|
@ -9,14 +9,14 @@
|
||||
"devDependencies": {
|
||||
"copy-webpack-plugin": "^9.0.1",
|
||||
"html-webpack-plugin": "^5.3.2",
|
||||
"ts-loader": "^9.2.3",
|
||||
"typescript": "^4.3.4",
|
||||
"webpack": "^5.41.1",
|
||||
"webpack-cli": "^4.7.2",
|
||||
"ts-loader": "^9.2.6",
|
||||
"typescript": "^4.4.3",
|
||||
"webpack": "^5.57.1",
|
||||
"webpack-cli": "^4.9.0",
|
||||
"webpack-dev-server": "^3.11.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc-browser": "^3.0.4"
|
||||
"tsrpc-browser": "^3.0.7"
|
||||
},
|
||||
"browserslist": [
|
||||
"defaults"
|
||||
|
1
examples/client-mock/frontend/src/shared
Symbolic link
1
examples/client-mock/frontend/src/shared
Symbolic link
@ -0,0 +1 @@
|
||||
../../backend/src/shared
|
@ -1,10 +0,0 @@
|
||||
// This is a demo code file
|
||||
// Feel free to delete it
|
||||
|
||||
export interface ReqAddData {
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface ResAddData {
|
||||
time: Date
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
// This is a demo code file
|
||||
// Feel free to delete it
|
||||
|
||||
export interface ReqGetData {
|
||||
|
||||
}
|
||||
|
||||
export interface ResGetData {
|
||||
data: {
|
||||
content: string,
|
||||
time: Date
|
||||
}[]
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
import { ServiceProto } from 'tsrpc-proto';
|
||||
import { ReqAddData, ResAddData } from './PtlAddData';
|
||||
import { ReqGetData, ResGetData } from './PtlGetData';
|
||||
|
||||
// This is a demo service proto file (auto generated)
|
||||
// Feel free to delete it
|
||||
|
||||
export interface ServiceType {
|
||||
api: {
|
||||
"AddData": {
|
||||
req: ReqAddData,
|
||||
res: ResAddData
|
||||
},
|
||||
"GetData": {
|
||||
req: ReqGetData,
|
||||
res: ResGetData
|
||||
}
|
||||
},
|
||||
msg: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"version": 1,
|
||||
"services": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "AddData",
|
||||
"type": "api"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "GetData",
|
||||
"type": "api"
|
||||
}
|
||||
],
|
||||
"types": {
|
||||
"PtlAddData/ReqAddData": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "content",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlAddData/ResAddData": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "time",
|
||||
"type": {
|
||||
"type": "Date"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlGetData/ReqGetData": {
|
||||
"type": "Interface"
|
||||
},
|
||||
"PtlGetData/ResGetData": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "data",
|
||||
"type": {
|
||||
"type": "Array",
|
||||
"elementType": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "content",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "time",
|
||||
"type": {
|
||||
"type": "Date"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
@ -4,20 +4,20 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts",
|
||||
"sync": "tsrpc sync --from src/shared --to ../frontend/assets/scripts/shared",
|
||||
"api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api",
|
||||
"dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"",
|
||||
"build": "tsrpc build"
|
||||
"proto": "tsrpc proto --config tsrpc.config.ts",
|
||||
"sync": "tsrpc sync --config tsrpc.config.ts",
|
||||
"api": "tsrpc api --config tsrpc.config.ts",
|
||||
"dev": "tsrpc dev --config tsrpc.config.ts",
|
||||
"build": "tsrpc build --config tsrpc.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^15.12.3",
|
||||
"@types/node": "^15.14.9",
|
||||
"onchange": "^7.1.0",
|
||||
"ts-node": "^9.1.1",
|
||||
"tsrpc-cli": "^2.0.3",
|
||||
"typescript": "^4.3.4"
|
||||
"tsrpc-cli": "^2.0.8",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc": "^3.0.2"
|
||||
"tsrpc": "^3.0.9"
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "ba5a8782-c57d-437b-9371-4441de673229",
|
||||
"uuid": "40721700-8121-4c1e-be92-c90e93cdc4c8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
@ -2,7 +2,7 @@
|
||||
"ver": "4.0.22",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "bd48404c-a47a-4bbc-b177-19352bd570bf",
|
||||
"uuid": "43723a09-6be4-404b-a21a-22ad675d0e58",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
@ -2,7 +2,7 @@
|
||||
"ver": "4.0.22",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "2a458e30-4c4a-4f1a-9aff-05ea0bdf0ab6",
|
||||
"uuid": "48e989fd-b5a5-4a5b-ac68-71d7f7f3d8ee",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
@ -2,7 +2,7 @@
|
||||
"ver": "4.0.22",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "56f77762-3150-4a83-ab4a-15025fd73ade",
|
||||
"uuid": "aeef551d-77fd-412f-be4b-4ea615a24639",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
36
examples/cocos-creator-3.3.0/backend/tsrpc.config.ts
Normal file
36
examples/cocos-creator-3.3.0/backend/tsrpc.config.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
const tsrpcConf: TsrpcConfig = {
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api' // API dir
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
{
|
||||
from: 'src/shared',
|
||||
to: '../frontend/assets/scripts/shared',
|
||||
type: 'symlink' // Change this to 'copy' if your environment not support symlink
|
||||
}
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
||||
export default tsrpcConf;
|
1
examples/cocos-creator-3.3.0/frontend/assets/scripts/shared
Symbolic link
1
examples/cocos-creator-3.3.0/frontend/assets/scripts/shared
Symbolic link
@ -0,0 +1 @@
|
||||
../../../backend/src/shared
|
@ -1,4 +0,0 @@
|
||||
export interface MsgChat {
|
||||
content: string,
|
||||
time: Date
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
export interface ReqSend {
|
||||
content: string
|
||||
}
|
||||
|
||||
export interface ResSend {
|
||||
time: Date
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
import { ServiceProto } from 'tsrpc-proto';
|
||||
import { MsgChat } from './MsgChat';
|
||||
import { ReqSend, ResSend } from './PtlSend';
|
||||
|
||||
export interface ServiceType {
|
||||
api: {
|
||||
"Send": {
|
||||
req: ReqSend,
|
||||
res: ResSend
|
||||
}
|
||||
},
|
||||
msg: {
|
||||
"Chat": MsgChat
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"services": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Chat",
|
||||
"type": "msg"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Send",
|
||||
"type": "api"
|
||||
}
|
||||
],
|
||||
"types": {
|
||||
"MsgChat/MsgChat": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "content",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "time",
|
||||
"type": {
|
||||
"type": "Date"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlSend/ReqSend": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "content",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlSend/ResSend": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "time",
|
||||
"type": {
|
||||
"type": "Date"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
@ -4,7 +4,7 @@
|
||||
"uuid": "cd1e2fff-2ab5-4407-b917-e60b25207723",
|
||||
"version": "3.3.0",
|
||||
"dependencies": {
|
||||
"tsrpc-browser": "^3.0.6",
|
||||
"tsrpc-browser": "^3.0.7",
|
||||
"tsrpc-miniapp": "^3.0.6"
|
||||
}
|
||||
}
|
||||
|
@ -48,8 +48,8 @@
|
||||
},
|
||||
"86c03e47-dc7e-4335-92f0-cf39fcd2462e": {
|
||||
"position": {
|
||||
"x": 807.1672726448774,
|
||||
"y": 621.6458364416596,
|
||||
"x": 1061.8571855907594,
|
||||
"y": 54.22598603125158,
|
||||
"z": 5000
|
||||
},
|
||||
"rotation": {
|
||||
@ -66,6 +66,6 @@
|
||||
}
|
||||
},
|
||||
"camera-uuids": [
|
||||
"86c03e47-dc7e-4335-92f0-cf39fcd2462e"
|
||||
"f46876e4-e81b-4931-b493-6d367be385e7"
|
||||
]
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"game": {
|
||||
"name": "UNKNOW GAME",
|
||||
"name": "未知游戏",
|
||||
"app_id": "UNKNOW",
|
||||
"c_id": "0"
|
||||
},
|
||||
|
@ -4,23 +4,23 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts",
|
||||
"sync": "tsrpc sync --from src/shared --to ../frontend/src/shared",
|
||||
"api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api",
|
||||
"dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"",
|
||||
"proto": "tsrpc proto --config tsrpc.config.ts",
|
||||
"sync": "tsrpc sync --config tsrpc.config.ts",
|
||||
"api": "tsrpc api --config tsrpc.config.ts",
|
||||
"dev": "tsrpc dev --config tsrpc.config.ts",
|
||||
"test": "mocha test/**/*.test.ts",
|
||||
"build": "tsrpc build"
|
||||
"build": "tsrpc build --config tsrpc.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@types/node": "^15.12.5",
|
||||
"mocha": "^9.0.1",
|
||||
"@types/mocha": "^8.2.3",
|
||||
"@types/node": "^15.14.9",
|
||||
"mocha": "^9.1.2",
|
||||
"onchange": "^7.1.0",
|
||||
"ts-node": "^10.0.0",
|
||||
"tsrpc-cli": "^2.0.3",
|
||||
"typescript": "^4.3.4"
|
||||
"ts-node": "^10.2.1",
|
||||
"tsrpc-cli": "^2.0.8",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc": "^3.0.4"
|
||||
"tsrpc": "^3.0.9"
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,14 @@ server.flows.preRecvBufferFlow.push(async v => {
|
||||
let conn = v.conn as HttpConnection;
|
||||
|
||||
if (conn.httpReq.method === 'GET') {
|
||||
conn.logger.log('[GET]', conn.httpReq.url);
|
||||
// Static File Service
|
||||
if (conn.httpReq.url) {
|
||||
// Check whether the file is existed
|
||||
// Check if the file is existed
|
||||
let resFilePath = path.join('res', conn.httpReq.url)
|
||||
let isExisted = await fs.access(resFilePath).then(() => true).catch(() => false);
|
||||
if (isExisted) {
|
||||
// Response the file
|
||||
if (isExisted && (await fs.stat(resFilePath)).isFile()) {
|
||||
// Send the file
|
||||
let content = await fs.readFile(resFilePath);
|
||||
conn.httpRes.end(content);
|
||||
return undefined;
|
||||
|
36
examples/custom-http-res/tsrpc.config.ts
Normal file
36
examples/custom-http-res/tsrpc.config.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
const tsrpcConf: TsrpcConfig = {
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api' // API dir
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
// {
|
||||
// from: 'src/shared',
|
||||
// to: '../frontend/src/shared',
|
||||
// type: 'symlink' // Change this to 'copy' if your environment not support symlink
|
||||
// }
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
||||
export default tsrpcConf;
|
@ -4,20 +4,20 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts",
|
||||
"sync": "tsrpc sync --from src/shared --to ../frontend/src/shared",
|
||||
"api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api",
|
||||
"dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"",
|
||||
"build": "tsrpc build"
|
||||
"proto": "tsrpc proto --config tsrpc.config.ts",
|
||||
"sync": "tsrpc sync --config tsrpc.config.ts",
|
||||
"api": "tsrpc api --config tsrpc.config.ts",
|
||||
"dev": "tsrpc dev --config tsrpc.config.ts",
|
||||
"build": "tsrpc build --config tsrpc.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^15.12.3",
|
||||
"@types/node": "^15.14.9",
|
||||
"onchange": "^7.1.0",
|
||||
"ts-node": "^9.1.1",
|
||||
"tsrpc-cli": "^2.0.3",
|
||||
"typescript": "^4.3.4"
|
||||
"tsrpc-cli": "^2.0.8",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc": "^3.0.2"
|
||||
"tsrpc": "^3.0.9"
|
||||
}
|
||||
}
|
||||
|
36
examples/file-upload/backend/tsrpc.config.ts
Normal file
36
examples/file-upload/backend/tsrpc.config.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
const tsrpcConf: TsrpcConfig = {
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api' // API dir
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
{
|
||||
from: 'src/shared',
|
||||
to: '../frontend/src/shared',
|
||||
type: 'symlink' // Change this to 'copy' if your environment not support symlink
|
||||
}
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
||||
export default tsrpcConf;
|
@ -7,15 +7,15 @@
|
||||
"build": "webpack --mode=production"
|
||||
},
|
||||
"devDependencies": {
|
||||
"copy-webpack-plugin": "^9.0.0",
|
||||
"html-webpack-plugin": "^5.3.1",
|
||||
"ts-loader": "^9.2.3",
|
||||
"typescript": "^4.3.4",
|
||||
"webpack": "^5.39.1",
|
||||
"webpack-cli": "^4.7.2",
|
||||
"copy-webpack-plugin": "^9.0.1",
|
||||
"html-webpack-plugin": "^5.3.2",
|
||||
"ts-loader": "^9.2.6",
|
||||
"typescript": "^4.4.3",
|
||||
"webpack": "^5.57.1",
|
||||
"webpack-cli": "^4.9.0",
|
||||
"webpack-dev-server": "^3.11.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc-browser": "^3.0.3"
|
||||
"tsrpc-browser": "^3.0.7"
|
||||
}
|
||||
}
|
||||
|
1
examples/file-upload/frontend/src/shared
Symbolic link
1
examples/file-upload/frontend/src/shared
Symbolic link
@ -0,0 +1 @@
|
||||
../../backend/src/shared
|
@ -1,8 +0,0 @@
|
||||
export interface ReqUpload {
|
||||
fileName: string,
|
||||
fileData: Uint8Array
|
||||
}
|
||||
|
||||
export interface ResUpload {
|
||||
url: string;
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
import { ServiceProto } from 'tsrpc-proto';
|
||||
import { ReqUpload, ResUpload } from './PtlUpload';
|
||||
|
||||
export interface ServiceType {
|
||||
api: {
|
||||
"Upload": {
|
||||
req: ReqUpload,
|
||||
res: ResUpload
|
||||
}
|
||||
},
|
||||
msg: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"version": 2,
|
||||
"services": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Upload",
|
||||
"type": "api"
|
||||
}
|
||||
],
|
||||
"types": {
|
||||
"PtlUpload/ReqUpload": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "fileName",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "fileData",
|
||||
"type": {
|
||||
"type": "Buffer",
|
||||
"arrayType": "Uint8Array"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlUpload/ResUpload": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 2,
|
||||
"name": "url",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
@ -4,20 +4,20 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts",
|
||||
"sync": "tsrpc sync --from src/shared --to ../frontend/src/shared",
|
||||
"api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api",
|
||||
"dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"",
|
||||
"build": "tsrpc build"
|
||||
"proto": "tsrpc proto --config tsrpc.config.ts",
|
||||
"sync": "tsrpc sync --config tsrpc.config.ts",
|
||||
"api": "tsrpc api --config tsrpc.config.ts",
|
||||
"dev": "tsrpc dev --config tsrpc.config.ts",
|
||||
"build": "tsrpc build --config tsrpc.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^15.12.3",
|
||||
"@types/node": "^15.14.9",
|
||||
"onchange": "^7.1.0",
|
||||
"ts-node": "^9.1.1",
|
||||
"tsrpc-cli": "^2.0.3",
|
||||
"typescript": "^4.3.4"
|
||||
"tsrpc-cli": "^2.0.8",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc": "^3.0.2"
|
||||
"tsrpc": "^3.0.9"
|
||||
}
|
||||
}
|
||||
|
36
examples/first-api/backend/tsrpc.config.ts
Normal file
36
examples/first-api/backend/tsrpc.config.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
const tsrpcConf: TsrpcConfig = {
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api' // API dir
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
{
|
||||
from: 'src/shared',
|
||||
to: '../frontend/src/shared',
|
||||
type: 'symlink' // Change this to 'copy' if your environment not support symlink
|
||||
}
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
||||
export default tsrpcConf;
|
@ -7,15 +7,15 @@
|
||||
"build": "webpack --mode=production"
|
||||
},
|
||||
"devDependencies": {
|
||||
"copy-webpack-plugin": "^9.0.0",
|
||||
"html-webpack-plugin": "^5.3.1",
|
||||
"ts-loader": "^9.2.3",
|
||||
"typescript": "^4.3.4",
|
||||
"webpack": "^5.39.1",
|
||||
"webpack-cli": "^4.7.2",
|
||||
"copy-webpack-plugin": "^9.0.1",
|
||||
"html-webpack-plugin": "^5.3.2",
|
||||
"ts-loader": "^9.2.6",
|
||||
"typescript": "^4.4.3",
|
||||
"webpack": "^5.57.1",
|
||||
"webpack-cli": "^4.9.0",
|
||||
"webpack-dev-server": "^3.11.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc-browser": "^3.0.3"
|
||||
"tsrpc-browser": "^3.0.7"
|
||||
}
|
||||
}
|
||||
|
1
examples/first-api/frontend/src/shared
Symbolic link
1
examples/first-api/frontend/src/shared
Symbolic link
@ -0,0 +1 @@
|
||||
../../backend/src/shared
|
@ -1,8 +0,0 @@
|
||||
export interface ReqHello {
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface ResHello {
|
||||
reply: string,
|
||||
time: Date
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
import { ServiceProto } from 'tsrpc-proto';
|
||||
import { ReqHello, ResHello } from './PtlHello';
|
||||
|
||||
export interface ServiceType {
|
||||
api: {
|
||||
"Hello": {
|
||||
req: ReqHello,
|
||||
res: ResHello
|
||||
}
|
||||
},
|
||||
msg: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"services": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Hello",
|
||||
"type": "api"
|
||||
}
|
||||
],
|
||||
"types": {
|
||||
"PtlHello/ReqHello": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "name",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlHello/ResHello": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "reply",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "time",
|
||||
"type": {
|
||||
"type": "Date"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
@ -4,20 +4,20 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts",
|
||||
"sync": "tsrpc sync --from src/shared --to ../frontend/src/shared",
|
||||
"api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api",
|
||||
"dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"",
|
||||
"build": "tsrpc build"
|
||||
"proto": "tsrpc proto --config tsrpc.config.ts",
|
||||
"sync": "tsrpc sync --config tsrpc.config.ts",
|
||||
"api": "tsrpc api --config tsrpc.config.ts",
|
||||
"dev": "tsrpc dev --config tsrpc.config.ts",
|
||||
"build": "tsrpc build --config tsrpc.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^15.14.1",
|
||||
"@types/node": "^15.14.9",
|
||||
"onchange": "^7.1.0",
|
||||
"ts-node": "^10.0.0",
|
||||
"tsrpc-cli": "^2.0.3",
|
||||
"typescript": "^4.3.5"
|
||||
"ts-node": "^10.2.1",
|
||||
"tsrpc-cli": "^2.0.8",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc": "^3.0.4"
|
||||
"tsrpc": "^3.0.9"
|
||||
}
|
||||
}
|
||||
|
36
examples/layaair/backend/tsrpc.config.ts
Normal file
36
examples/layaair/backend/tsrpc.config.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
const tsrpcConf: TsrpcConfig = {
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api' // API dir
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
{
|
||||
from: 'src/shared',
|
||||
to: '../frontend/src/shared',
|
||||
type: 'copy' // Change this to 'copy' if your environment not support symlink
|
||||
}
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
||||
export default tsrpcConf;
|
@ -7,17 +7,17 @@
|
||||
"tsrpc-laya": "index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"core-js": "^3.15.2",
|
||||
"core-js": "^3.18.2",
|
||||
"k8w-extend-native": "^1.4.5",
|
||||
"k8w-linq-array": "^0.2.7",
|
||||
"k8w-super-date": "^0.1.2",
|
||||
"k8w-super-date": "^0.1.3",
|
||||
"k8w-super-object": "^0.3.0",
|
||||
"tsbuffer": "^2.0.4",
|
||||
"tsbuffer-schema": "^2.0.2",
|
||||
"tsbuffer-validator": "^2.0.4",
|
||||
"tslib": "^2.3.0",
|
||||
"tsrpc-base-client": "^1.0.6",
|
||||
"tsrpc-browser": "^3.0.4",
|
||||
"tslib": "^2.3.1",
|
||||
"tsrpc-base-client": "^1.0.11",
|
||||
"tsrpc-browser": "^3.0.7",
|
||||
"tsrpc-proto": "^1.3.4"
|
||||
},
|
||||
"scripts": {
|
||||
|
@ -4,27 +4,24 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"watch:proto": "onchange \"src/shared/protocols/**/Ptl*.ts\" -- npm run protoAndSync",
|
||||
"protoAndSync": "npm run proto && npm run sync",
|
||||
"proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts",
|
||||
"sync": "tsrpc sync --from src/shared --to ../frontend/src/shared",
|
||||
"api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api",
|
||||
"dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"",
|
||||
"test": "mocha test/**/*.test.ts",
|
||||
"build": "tsrpc build"
|
||||
"proto": "tsrpc proto --config tsrpc.config.ts",
|
||||
"sync": "tsrpc sync --config tsrpc.config.ts",
|
||||
"api": "tsrpc api --config tsrpc.config.ts",
|
||||
"dev": "tsrpc dev --config tsrpc.config.ts",
|
||||
"build": "tsrpc build --config tsrpc.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@types/mongodb": "^3.6.18",
|
||||
"@types/node": "^15.12.4",
|
||||
"mocha": "^9.0.1",
|
||||
"@types/mocha": "^8.2.3",
|
||||
"@types/mongodb": "^3.6.20",
|
||||
"@types/node": "^15.14.9",
|
||||
"mocha": "^9.1.2",
|
||||
"onchange": "^7.1.0",
|
||||
"ts-node": "^10.0.0",
|
||||
"tsrpc-cli": "^2.0.3",
|
||||
"typescript": "^4.3.4"
|
||||
"ts-node": "^10.2.1",
|
||||
"tsrpc-cli": "^2.0.8",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"mongodb": "^3.6.9",
|
||||
"tsrpc": "^3.0.2"
|
||||
"mongodb": "^3.7.2",
|
||||
"tsrpc": "^3.0.9"
|
||||
}
|
||||
}
|
36
examples/mongodb-crud/backend/tsrpc.config.ts
Normal file
36
examples/mongodb-crud/backend/tsrpc.config.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
const tsrpcConf: TsrpcConfig = {
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api' // API dir
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
{
|
||||
from: 'src/shared',
|
||||
to: '../frontend/src/shared',
|
||||
type: 'symlink' // Change this to 'copy' if your environment not support symlink
|
||||
}
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
||||
export default tsrpcConf;
|
@ -9,14 +9,14 @@
|
||||
"devDependencies": {
|
||||
"copy-webpack-plugin": "^9.0.1",
|
||||
"html-webpack-plugin": "^5.3.2",
|
||||
"ts-loader": "^9.2.3",
|
||||
"typescript": "^4.3.4",
|
||||
"webpack": "^5.40.0",
|
||||
"webpack-cli": "^4.7.2",
|
||||
"ts-loader": "^9.2.6",
|
||||
"typescript": "^4.4.3",
|
||||
"webpack": "^5.57.1",
|
||||
"webpack-cli": "^4.9.0",
|
||||
"webpack-dev-server": "^3.11.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc-browser": "^3.0.3"
|
||||
"tsrpc-browser": "^3.0.7"
|
||||
},
|
||||
"browserslist": [
|
||||
"defaults"
|
||||
|
1
examples/mongodb-crud/frontend/src/shared
Symbolic link
1
examples/mongodb-crud/frontend/src/shared
Symbolic link
@ -0,0 +1 @@
|
||||
../../backend/src/shared
|
@ -1,9 +0,0 @@
|
||||
import { Post } from "./models/Post";
|
||||
|
||||
export interface ReqAddPost {
|
||||
newPost: Omit<Post, '_id' | 'create' | 'update' | 'visitedNum'>;
|
||||
}
|
||||
|
||||
export interface ResAddPost {
|
||||
insertedId: string;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
export interface ReqDelPost {
|
||||
_id: string;
|
||||
}
|
||||
|
||||
export interface ResDelPost {
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
import { Post } from "./models/Post";
|
||||
|
||||
export interface ReqGetPost {
|
||||
_id: string;
|
||||
}
|
||||
|
||||
export interface ResGetPost {
|
||||
post: Post;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
import { Post } from "./models/Post";
|
||||
|
||||
export interface ReqUpdatePost {
|
||||
update: { _id: string } & Partial<Pick<Post, 'title' | 'content'>>;
|
||||
}
|
||||
|
||||
export interface ResUpdatePost {
|
||||
matchedCount: number;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
export interface Post {
|
||||
_id: string;
|
||||
author: string;
|
||||
title: string;
|
||||
content: string;
|
||||
visitedNum: number;
|
||||
|
||||
create: {
|
||||
uid: string;
|
||||
time: Date;
|
||||
}
|
||||
|
||||
update?: {
|
||||
uid: string,
|
||||
time: Date
|
||||
}
|
||||
}
|
@ -1,276 +0,0 @@
|
||||
import { ServiceProto } from 'tsrpc-proto';
|
||||
import { ReqAddPost, ResAddPost } from './PtlAddPost';
|
||||
import { ReqDelPost, ResDelPost } from './PtlDelPost';
|
||||
import { ReqGetPost, ResGetPost } from './PtlGetPost';
|
||||
import { ReqUpdatePost, ResUpdatePost } from './PtlUpdatePost';
|
||||
|
||||
export interface ServiceType {
|
||||
api: {
|
||||
"AddPost": {
|
||||
req: ReqAddPost,
|
||||
res: ResAddPost
|
||||
},
|
||||
"DelPost": {
|
||||
req: ReqDelPost,
|
||||
res: ResDelPost
|
||||
},
|
||||
"GetPost": {
|
||||
req: ReqGetPost,
|
||||
res: ResGetPost
|
||||
},
|
||||
"UpdatePost": {
|
||||
req: ReqUpdatePost,
|
||||
res: ResUpdatePost
|
||||
}
|
||||
},
|
||||
msg: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"version": 16,
|
||||
"services": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "AddPost",
|
||||
"type": "api"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "DelPost",
|
||||
"type": "api"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "GetPost",
|
||||
"type": "api"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "UpdatePost",
|
||||
"type": "api"
|
||||
}
|
||||
],
|
||||
"types": {
|
||||
"PtlAddPost/ReqAddPost": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "newPost",
|
||||
"type": {
|
||||
"target": {
|
||||
"type": "Reference",
|
||||
"target": "models/Post/Post"
|
||||
},
|
||||
"keys": [
|
||||
"_id",
|
||||
"create",
|
||||
"update",
|
||||
"visitedNum"
|
||||
],
|
||||
"type": "Omit"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"models/Post/Post": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "_id",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "author",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "title",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "content",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "visitedNum",
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"name": "create",
|
||||
"type": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "uid",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "time",
|
||||
"type": {
|
||||
"type": "Date"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"name": "update",
|
||||
"type": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "uid",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "time",
|
||||
"type": {
|
||||
"type": "Date"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"optional": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlAddPost/ResAddPost": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "insertedId",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlDelPost/ReqDelPost": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "_id",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlDelPost/ResDelPost": {
|
||||
"type": "Interface"
|
||||
},
|
||||
"PtlGetPost/ReqGetPost": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "_id",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlGetPost/ResGetPost": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "post",
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "models/Post/Post"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlUpdatePost/ReqUpdatePost": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "update",
|
||||
"type": {
|
||||
"type": "Intersection",
|
||||
"members": [
|
||||
{
|
||||
"id": 1,
|
||||
"type": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "_id",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"type": {
|
||||
"type": "Partial",
|
||||
"target": {
|
||||
"target": {
|
||||
"type": "Reference",
|
||||
"target": "models/Post/Post"
|
||||
},
|
||||
"keys": [
|
||||
"title",
|
||||
"content"
|
||||
],
|
||||
"type": "Pick"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlUpdatePost/ResUpdatePost": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "matchedCount",
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
@ -4,22 +4,22 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts",
|
||||
"sync": "tsrpc sync --from src/shared --to ../frontend/src/shared",
|
||||
"api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api",
|
||||
"dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"",
|
||||
"build": "tsrpc build"
|
||||
"proto": "tsrpc proto --config tsrpc.config.ts",
|
||||
"sync": "tsrpc sync --config tsrpc.config.ts",
|
||||
"api": "tsrpc api --config tsrpc.config.ts",
|
||||
"dev": "tsrpc dev --config tsrpc.config.ts",
|
||||
"build": "tsrpc build --config tsrpc.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^15.12.3",
|
||||
"@types/uuid": "^8.3.0",
|
||||
"@types/node": "^15.14.9",
|
||||
"@types/uuid": "^8.3.1",
|
||||
"onchange": "^7.1.0",
|
||||
"ts-node": "^9.1.1",
|
||||
"tsrpc-cli": "^2.0.3",
|
||||
"typescript": "^4.3.4"
|
||||
"tsrpc-cli": "^2.0.8",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc": "^3.0.2",
|
||||
"tsrpc": "^3.0.9",
|
||||
"uuid": "^8.3.2"
|
||||
}
|
||||
}
|
||||
|
36
examples/session-and-cookie/backend/tsrpc.config.ts
Normal file
36
examples/session-and-cookie/backend/tsrpc.config.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
const tsrpcConf: TsrpcConfig = {
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api' // API dir
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
{
|
||||
from: 'src/shared',
|
||||
to: '../frontend/src/shared',
|
||||
type: 'symlink' // Change this to 'copy' if your environment not support symlink
|
||||
}
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
||||
export default tsrpcConf;
|
@ -7,15 +7,15 @@
|
||||
"build": "webpack --mode=production"
|
||||
},
|
||||
"devDependencies": {
|
||||
"copy-webpack-plugin": "^9.0.0",
|
||||
"html-webpack-plugin": "^5.3.1",
|
||||
"ts-loader": "^9.2.3",
|
||||
"typescript": "^4.3.4",
|
||||
"webpack": "^5.39.1",
|
||||
"webpack-cli": "^4.7.2",
|
||||
"copy-webpack-plugin": "^9.0.1",
|
||||
"html-webpack-plugin": "^5.3.2",
|
||||
"ts-loader": "^9.2.6",
|
||||
"typescript": "^4.4.3",
|
||||
"webpack": "^5.57.1",
|
||||
"webpack-cli": "^4.9.0",
|
||||
"webpack-dev-server": "^3.11.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc-browser": "^3.0.3"
|
||||
"tsrpc-browser": "^3.0.7"
|
||||
}
|
||||
}
|
||||
|
1
examples/session-and-cookie/frontend/src/shared
Symbolic link
1
examples/session-and-cookie/frontend/src/shared
Symbolic link
@ -0,0 +1 @@
|
||||
../../backend/src/shared
|
@ -1,9 +0,0 @@
|
||||
import { BaseRequest, BaseResponse } from './base';
|
||||
|
||||
export interface ReqClear extends BaseRequest {
|
||||
|
||||
}
|
||||
|
||||
export interface ResClear extends BaseResponse {
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
import { BaseRequest, BaseResponse } from './base'
|
||||
|
||||
export interface ReqSetCookie extends BaseRequest {
|
||||
|
||||
}
|
||||
|
||||
export interface ResSetCookie extends BaseResponse {
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
import { BaseRequest, BaseResponse } from './base'
|
||||
|
||||
export interface ReqSetSession extends BaseRequest {
|
||||
|
||||
}
|
||||
|
||||
export interface ResSetSession extends BaseResponse {
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
import { BaseRequest, BaseResponse } from './base';
|
||||
|
||||
export interface ReqTest extends BaseRequest {
|
||||
|
||||
}
|
||||
|
||||
export interface ResTest extends BaseResponse {
|
||||
// From Session
|
||||
testSession?: string
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
export interface BaseRequest {
|
||||
__cookie?: Cookie;
|
||||
}
|
||||
|
||||
export interface BaseResponse {
|
||||
__cookie?: Cookie;
|
||||
}
|
||||
|
||||
export interface Cookie {
|
||||
sessionId?: string,
|
||||
[key: string]: any
|
||||
}
|
@ -1,209 +0,0 @@
|
||||
import { ServiceProto } from 'tsrpc-proto';
|
||||
import { ReqClear, ResClear } from './PtlClear';
|
||||
import { ReqSetCookie, ResSetCookie } from './PtlSetCookie';
|
||||
import { ReqSetSession, ResSetSession } from './PtlSetSession';
|
||||
import { ReqTest, ResTest } from './PtlTest';
|
||||
|
||||
export interface ServiceType {
|
||||
api: {
|
||||
"Clear": {
|
||||
req: ReqClear,
|
||||
res: ResClear
|
||||
},
|
||||
"SetCookie": {
|
||||
req: ReqSetCookie,
|
||||
res: ResSetCookie
|
||||
},
|
||||
"SetSession": {
|
||||
req: ReqSetSession,
|
||||
res: ResSetSession
|
||||
},
|
||||
"Test": {
|
||||
req: ReqTest,
|
||||
res: ResTest
|
||||
}
|
||||
},
|
||||
msg: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"services": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Clear",
|
||||
"type": "api"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "SetCookie",
|
||||
"type": "api"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "SetSession",
|
||||
"type": "api"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Test",
|
||||
"type": "api"
|
||||
}
|
||||
],
|
||||
"types": {
|
||||
"PtlClear/ReqClear": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseRequest"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"base/BaseRequest": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "__cookie",
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/Cookie"
|
||||
},
|
||||
"optional": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"base/Cookie": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "sessionId",
|
||||
"type": {
|
||||
"type": "String"
|
||||
},
|
||||
"optional": true
|
||||
}
|
||||
],
|
||||
"indexSignature": {
|
||||
"keyType": "String",
|
||||
"type": {
|
||||
"type": "Any"
|
||||
}
|
||||
}
|
||||
},
|
||||
"PtlClear/ResClear": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseResponse"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"base/BaseResponse": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "__cookie",
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/Cookie"
|
||||
},
|
||||
"optional": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlSetCookie/ReqSetCookie": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseRequest"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlSetCookie/ResSetCookie": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseResponse"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlSetSession/ReqSetSession": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseRequest"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlSetSession/ResSetSession": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseResponse"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlTest/ReqTest": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseRequest"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlTest/ResTest": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseResponse"
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "testSession",
|
||||
"type": {
|
||||
"type": "String"
|
||||
},
|
||||
"optional": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
@ -4,20 +4,20 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts",
|
||||
"sync": "tsrpc sync --from src/shared --to ../frontend/src/shared",
|
||||
"api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api",
|
||||
"dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"",
|
||||
"build": "tsrpc build"
|
||||
"proto": "tsrpc proto --config tsrpc.config.ts",
|
||||
"sync": "tsrpc sync --config tsrpc.config.ts",
|
||||
"api": "tsrpc api --config tsrpc.config.ts",
|
||||
"dev": "tsrpc dev --config tsrpc.config.ts",
|
||||
"build": "tsrpc build --config tsrpc.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^15.12.5",
|
||||
"@types/node": "^15.14.9",
|
||||
"onchange": "^7.1.0",
|
||||
"ts-node": "^10.0.0",
|
||||
"tsrpc-cli": "^2.0.3",
|
||||
"typescript": "^4.3.4"
|
||||
"ts-node": "^10.2.1",
|
||||
"tsrpc-cli": "^2.0.8",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc": "^3.0.4"
|
||||
"tsrpc": "^3.0.9"
|
||||
}
|
||||
}
|
||||
|
36
examples/transfer-encryption/backend/tsrpc.config.ts
Normal file
36
examples/transfer-encryption/backend/tsrpc.config.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
const tsrpcConf: TsrpcConfig = {
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api' // API dir
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
{
|
||||
from: 'src/shared',
|
||||
to: '../frontend/src/shared',
|
||||
type: 'symlink' // Change this to 'copy' if your environment not support symlink
|
||||
}
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
||||
export default tsrpcConf;
|
@ -9,14 +9,14 @@
|
||||
"devDependencies": {
|
||||
"copy-webpack-plugin": "^9.0.1",
|
||||
"html-webpack-plugin": "^5.3.2",
|
||||
"ts-loader": "^9.2.3",
|
||||
"typescript": "^4.3.4",
|
||||
"webpack": "^5.41.0",
|
||||
"webpack-cli": "^4.7.2",
|
||||
"ts-loader": "^9.2.6",
|
||||
"typescript": "^4.4.3",
|
||||
"webpack": "^5.57.1",
|
||||
"webpack-cli": "^4.9.0",
|
||||
"webpack-dev-server": "^3.11.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc-browser": "^3.0.4"
|
||||
"tsrpc-browser": "^3.0.7"
|
||||
},
|
||||
"browserslist": [
|
||||
"defaults"
|
||||
|
1
examples/transfer-encryption/frontend/src/shared
Symbolic link
1
examples/transfer-encryption/frontend/src/shared
Symbolic link
@ -0,0 +1 @@
|
||||
../../backend/src/shared
|
@ -1,17 +0,0 @@
|
||||
export class EncryptUtil {
|
||||
|
||||
static encrypt(buf: Uint8Array): Uint8Array {
|
||||
for (let i = 0; i < buf.length; ++i) {
|
||||
buf[i] -= 1;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static decrypt(buf: Uint8Array): Uint8Array {
|
||||
for (let i = 0; i < buf.length; ++i) {
|
||||
buf[i] += 1;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
// This is a demo code file
|
||||
// Feel free to delete it
|
||||
|
||||
export interface ReqAddData {
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface ResAddData {
|
||||
time: Date
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
// This is a demo code file
|
||||
// Feel free to delete it
|
||||
|
||||
export interface ReqGetData {
|
||||
|
||||
}
|
||||
|
||||
export interface ResGetData {
|
||||
data: {
|
||||
content: string,
|
||||
time: Date
|
||||
}[]
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
import { ServiceProto } from 'tsrpc-proto';
|
||||
import { ReqAddData, ResAddData } from './PtlAddData';
|
||||
import { ReqGetData, ResGetData } from './PtlGetData';
|
||||
|
||||
// This is a demo service proto file (auto generated)
|
||||
// Feel free to delete it
|
||||
|
||||
export interface ServiceType {
|
||||
api: {
|
||||
"AddData": {
|
||||
req: ReqAddData,
|
||||
res: ResAddData
|
||||
},
|
||||
"GetData": {
|
||||
req: ReqGetData,
|
||||
res: ResGetData
|
||||
}
|
||||
},
|
||||
msg: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"version": 1,
|
||||
"services": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "AddData",
|
||||
"type": "api"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "GetData",
|
||||
"type": "api"
|
||||
}
|
||||
],
|
||||
"types": {
|
||||
"PtlAddData/ReqAddData": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "content",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlAddData/ResAddData": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "time",
|
||||
"type": {
|
||||
"type": "Date"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlGetData/ReqGetData": {
|
||||
"type": "Interface"
|
||||
},
|
||||
"PtlGetData/ResGetData": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "data",
|
||||
"type": {
|
||||
"type": "Array",
|
||||
"elementType": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "content",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "time",
|
||||
"type": {
|
||||
"type": "Date"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
@ -4,22 +4,22 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts",
|
||||
"sync": "tsrpc sync --from src/shared --to ../frontend/src/shared",
|
||||
"api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api",
|
||||
"dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"",
|
||||
"build": "tsrpc build"
|
||||
"proto": "tsrpc proto --config tsrpc.config.ts",
|
||||
"sync": "tsrpc sync --config tsrpc.config.ts",
|
||||
"api": "tsrpc api --config tsrpc.config.ts",
|
||||
"dev": "tsrpc dev --config tsrpc.config.ts",
|
||||
"build": "tsrpc build --config tsrpc.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^15.12.3",
|
||||
"@types/uuid": "^8.3.0",
|
||||
"@types/node": "^15.14.9",
|
||||
"@types/uuid": "^8.3.1",
|
||||
"onchange": "^7.1.0",
|
||||
"ts-node": "^9.1.1",
|
||||
"tsrpc-cli": "^2.0.3",
|
||||
"typescript": "^4.3.4"
|
||||
"tsrpc-cli": "^2.0.8",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc": "^3.0.2",
|
||||
"tsrpc": "^3.0.9",
|
||||
"uuid": "^8.3.2"
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ export interface ServiceType {
|
||||
}
|
||||
|
||||
export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"version": 2,
|
||||
"version": 3,
|
||||
"services": [
|
||||
{
|
||||
"id": 0,
|
||||
@ -248,6 +248,43 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "user",
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "../../models/CurrentUser/CurrentUser"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"../../models/CurrentUser/CurrentUser": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "uid",
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "username",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "roles",
|
||||
"type": {
|
||||
"type": "Array",
|
||||
"elementType": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
36
examples/user-authentication/backend/tsrpc.config.ts
Normal file
36
examples/user-authentication/backend/tsrpc.config.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TsrpcConfig } from 'tsrpc-cli';
|
||||
|
||||
const tsrpcConf: TsrpcConfig = {
|
||||
// Generate ServiceProto
|
||||
proto: [
|
||||
{
|
||||
ptlDir: 'src/shared/protocols', // Protocol dir
|
||||
output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto
|
||||
apiDir: 'src/api' // API dir
|
||||
}
|
||||
],
|
||||
// Sync shared code
|
||||
sync: [
|
||||
{
|
||||
from: 'src/shared',
|
||||
to: '../frontend/src/shared',
|
||||
type: 'symlink' // Change this to 'copy' if your environment not support symlink
|
||||
}
|
||||
],
|
||||
// Dev server
|
||||
dev: {
|
||||
autoProto: true, // Auto regenerate proto
|
||||
autoSync: true, // Auto sync when file changed
|
||||
autoApi: true, // Auto create API when ServiceProto updated
|
||||
watch: 'src', // Restart dev server when these files changed
|
||||
entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry}
|
||||
},
|
||||
// Build config
|
||||
build: {
|
||||
autoProto: true, // Auto generate proto before build
|
||||
autoSync: true, // Auto sync before build
|
||||
autoApi: true, // Auto generate API before build
|
||||
outDir: 'dist', // Clean this dir before build
|
||||
}
|
||||
}
|
||||
export default tsrpcConf;
|
@ -7,15 +7,15 @@
|
||||
"build": "webpack --mode=production"
|
||||
},
|
||||
"devDependencies": {
|
||||
"copy-webpack-plugin": "^9.0.0",
|
||||
"html-webpack-plugin": "^5.3.1",
|
||||
"ts-loader": "^9.2.3",
|
||||
"typescript": "^4.3.4",
|
||||
"webpack": "^5.39.1",
|
||||
"webpack-cli": "^4.7.2",
|
||||
"copy-webpack-plugin": "^9.0.1",
|
||||
"html-webpack-plugin": "^5.3.2",
|
||||
"ts-loader": "^9.2.6",
|
||||
"typescript": "^4.4.3",
|
||||
"webpack": "^5.57.1",
|
||||
"webpack-cli": "^4.9.0",
|
||||
"webpack-dev-server": "^3.11.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsrpc-browser": "^3.0.3"
|
||||
"tsrpc-browser": "^3.0.7"
|
||||
}
|
||||
}
|
||||
|
1
examples/user-authentication/frontend/src/shared
Symbolic link
1
examples/user-authentication/frontend/src/shared
Symbolic link
@ -0,0 +1 @@
|
||||
../../backend/src/shared
|
@ -1,14 +0,0 @@
|
||||
import { BaseRequest, BaseResponse, BaseConf } from '../base'
|
||||
|
||||
export interface ReqAdminAction extends BaseRequest {
|
||||
|
||||
}
|
||||
|
||||
export interface ResAdminAction extends BaseResponse {
|
||||
result: string
|
||||
}
|
||||
|
||||
export const conf: BaseConf = {
|
||||
needLogin: true,
|
||||
needRoles: ['Admin']
|
||||
};
|
@ -1,13 +0,0 @@
|
||||
import { BaseConf, BaseRequest, BaseResponse } from '../base';
|
||||
|
||||
export interface ReqGuestAction extends BaseRequest {
|
||||
|
||||
}
|
||||
|
||||
export interface ResGuestAction extends BaseResponse {
|
||||
result: string
|
||||
}
|
||||
|
||||
export const conf: BaseConf = {
|
||||
needLogin: false
|
||||
};
|
@ -1,13 +0,0 @@
|
||||
import { BaseConf, BaseRequest, BaseResponse } from '../base';
|
||||
|
||||
export interface ReqNormalAction extends BaseRequest {
|
||||
|
||||
}
|
||||
|
||||
export interface ResNormalAction extends BaseResponse {
|
||||
result: string
|
||||
}
|
||||
|
||||
export const conf: BaseConf = {
|
||||
needLogin: true
|
||||
};
|
@ -1,13 +0,0 @@
|
||||
export interface BaseRequest {
|
||||
__ssoToken?: string;
|
||||
}
|
||||
|
||||
export interface BaseResponse {
|
||||
// Init or refresh sso token
|
||||
__ssoToken?: string;
|
||||
}
|
||||
|
||||
export interface BaseConf {
|
||||
needLogin?: boolean,
|
||||
needRoles?: string[]
|
||||
}
|
@ -1,279 +0,0 @@
|
||||
import { ServiceProto } from 'tsrpc-proto';
|
||||
import { ReqAdminAction, ResAdminAction } from './action/PtlAdminAction';
|
||||
import { ReqGuestAction, ResGuestAction } from './action/PtlGuestAction';
|
||||
import { ReqNormalAction, ResNormalAction } from './action/PtlNormalAction';
|
||||
import { ReqLogin, ResLogin } from './user/PtlLogin';
|
||||
import { ReqLogout, ResLogout } from './user/PtlLogout';
|
||||
|
||||
export interface ServiceType {
|
||||
api: {
|
||||
"action/AdminAction": {
|
||||
req: ReqAdminAction,
|
||||
res: ResAdminAction
|
||||
},
|
||||
"action/GuestAction": {
|
||||
req: ReqGuestAction,
|
||||
res: ResGuestAction
|
||||
},
|
||||
"action/NormalAction": {
|
||||
req: ReqNormalAction,
|
||||
res: ResNormalAction
|
||||
},
|
||||
"user/Login": {
|
||||
req: ReqLogin,
|
||||
res: ResLogin
|
||||
},
|
||||
"user/Logout": {
|
||||
req: ReqLogout,
|
||||
res: ResLogout
|
||||
}
|
||||
},
|
||||
msg: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"version": 2,
|
||||
"services": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "action/AdminAction",
|
||||
"type": "api",
|
||||
"conf": {
|
||||
"needLogin": true,
|
||||
"needRoles": [
|
||||
"Admin"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "action/GuestAction",
|
||||
"type": "api",
|
||||
"conf": {
|
||||
"needLogin": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "action/NormalAction",
|
||||
"type": "api",
|
||||
"conf": {
|
||||
"needLogin": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "user/Login",
|
||||
"type": "api",
|
||||
"conf": {}
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "user/Logout",
|
||||
"type": "api",
|
||||
"conf": {}
|
||||
}
|
||||
],
|
||||
"types": {
|
||||
"action/PtlAdminAction/ReqAdminAction": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseRequest"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"base/BaseRequest": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "__ssoToken",
|
||||
"type": {
|
||||
"type": "String"
|
||||
},
|
||||
"optional": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"action/PtlAdminAction/ResAdminAction": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseResponse"
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "result",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"base/BaseResponse": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "__ssoToken",
|
||||
"type": {
|
||||
"type": "String"
|
||||
},
|
||||
"optional": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"action/PtlGuestAction/ReqGuestAction": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseRequest"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"action/PtlGuestAction/ResGuestAction": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseResponse"
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "result",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"action/PtlNormalAction/ReqNormalAction": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseRequest"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"action/PtlNormalAction/ResNormalAction": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseResponse"
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "result",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"user/PtlLogin/ReqLogin": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "username",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "password",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"user/PtlLogin/ResLogin": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseResponse"
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "__ssoToken",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"user/PtlLogout/ReqLogout": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseRequest"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"user/PtlLogout/ResLogout": {
|
||||
"type": "Interface",
|
||||
"extends": [
|
||||
{
|
||||
"id": 0,
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "base/BaseResponse"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
@ -1,14 +0,0 @@
|
||||
import { BaseConf, BaseRequest, BaseResponse } from '../base';
|
||||
|
||||
export interface ReqLogin extends BaseRequest {
|
||||
username: string,
|
||||
password: string
|
||||
}
|
||||
|
||||
export interface ResLogin extends BaseResponse {
|
||||
__ssoToken: string;
|
||||
}
|
||||
|
||||
export const conf: BaseConf = {
|
||||
|
||||
};
|
@ -1,13 +0,0 @@
|
||||
import { BaseRequest, BaseResponse, BaseConf } from '../base'
|
||||
|
||||
export interface ReqLogout extends BaseRequest {
|
||||
|
||||
}
|
||||
|
||||
export interface ResLogout extends BaseResponse {
|
||||
|
||||
}
|
||||
|
||||
export const conf: BaseConf = {
|
||||
|
||||
};
|
@ -1,13 +1,35 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { execSync } = require('child_process');
|
||||
const { execSync, exec } = require('child_process');
|
||||
|
||||
let dirs = fs.readdirSync(path.resolve(__dirname, '../examples'));
|
||||
|
||||
dirs.forEach(dir => {
|
||||
console.log(dir);
|
||||
process.chdir(path.resolve(__dirname, '../examples', dir, 'backend'));
|
||||
execSync('ncu -u -t minor', { stdio: 'inherit' });
|
||||
process.chdir(path.resolve(__dirname, '../examples', dir, 'frontend'));
|
||||
execSync('ncu -u -t minor', { stdio: 'inherit' });
|
||||
|
||||
if (!isDir(path.resolve(__dirname, '../examples', dir,))) {
|
||||
return;
|
||||
}
|
||||
|
||||
let num = 0;
|
||||
if (isDir(path.resolve(__dirname, '../examples', dir, 'backend'))) {
|
||||
++num;
|
||||
process.chdir(path.resolve(__dirname, '../examples', dir, 'backend'));
|
||||
execSync('ncu -u -t minor && npm i --registry https://registry.npm.taobao.org', { stdio: 'inherit' });
|
||||
}
|
||||
|
||||
if (isDir(path.resolve(__dirname, '../examples', dir, 'frontend'))) {
|
||||
++num;
|
||||
process.chdir(path.resolve(__dirname, '../examples', dir, 'frontend'));
|
||||
execSync('ncu -u -t minor && npm i --registry https://registry.npm.taobao.org', { stdio: 'inherit' });
|
||||
}
|
||||
|
||||
if (!num) {
|
||||
process.chdir(path.resolve(__dirname, '../examples', dir));
|
||||
execSync('ncu -u -t minor && npm i --registry https://registry.npm.taobao.org', { stdio: 'inherit' });
|
||||
}
|
||||
})
|
||||
|
||||
function isDir(dir) {
|
||||
return fs.existsSync(dir) && fs.statSync(dir).isDirectory()
|
||||
}
|
Loading…
Reference in New Issue
Block a user