This commit is contained in:
Daniel Hübleitner
2019-09-18 07:34:51 +02:00
parent a744e9df9b
commit 7ff0d1e67e
12 changed files with 52 additions and 287 deletions
+6 -4
View File
@@ -1,7 +1,9 @@
node_modules node_modules
*/**/*.js src/**/*.js
*/**/*.d.ts src/**/*.d.ts
!lib/Backend.js test/**/*.js
!lib/Frontend.js test/**/*.d.ts
lib
-167
View File
File diff suppressed because one or more lines are too long
-19
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "rpclib", "name": "rpclibrary",
"version": "1.0.0", "version": "1.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
+8 -7
View File
@@ -1,12 +1,14 @@
{ {
"name": "rpclib", "name": "rpclibrary",
"version": "1.0.0", "version": "1.0.1",
"description": "", "description": "",
"scripts": { "scripts": {
"build": "npm run clean; npm run tsc; npm run webpack",
"tsc": "tsc", "tsc": "tsc",
"webpack": "webpack --config src/webpack.prod.js --progress --colors", "webpack": "webpack",
"clean": "rm -rf lib" "build-lib": "npm run webpack --config ./src/webpack.js",
"build-test": "npm run webpack --config ./test/webpack.js",
"build": "npm run clean && npm run tsc && npm run build-lib && npm run build-test",
"clean": "rm -rf lib ./*.js ./*.d.ts"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
@@ -25,7 +27,6 @@
"uuid": "^3.3.3" "uuid": "^3.3.3"
}, },
"files": [ "files": [
"./lib/Backend.js", "lib/*.js"
"./lib/Frontend.js"
] ]
} }
+9 -1
View File
@@ -6,8 +6,16 @@ import bsock = require('bsock');
import * as T from './Types'; import * as T from './Types';
import * as U from './Utils'; import * as U from './Utils';
import * as I from './Interfaces'; import * as I from './Interfaces';
import * as R from './Responses';
export class Server{ export {
T as Types,
U as Utils,
I as Interfaces,
R as Responses
}
export class Backend{
private ws = http.createServer() private ws = http.createServer()
private io = bsock.createServer() private io = bsock.createServer()
+7 -2
View File
@@ -2,8 +2,13 @@
var bsock = require('bsock') var bsock = require('bsock')
import * as I from './Interfaces';
import * as T from './Types'; import * as T from './Types';
import * as I from './Interfaces';
export {
T as Types,
I as Interfaces,
}
//fix args with defaults like "force = true" -> "force" //fix args with defaults like "force = true" -> "force"
@@ -11,7 +16,7 @@ function stripAfterEquals(str:string){
return str.split("=")[0] return str.split("=")[0]
} }
export class Client implements I.Socket{ export class Frontend implements I.Socket{
private socket: I.Socket private socket: I.Socket
constructor(public port:number, private server: string, private tls: boolean = false){ constructor(public port:number, private server: string, private tls: boolean = false){
-66
View File
@@ -1,66 +0,0 @@
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const frontendConf = {
mode: 'production',
target: "web",
entry: path.resolve(__dirname, 'Client.ts'),
output: {
path: path.resolve(__dirname, '../lib'),
filename: 'Frontend.js',
libraryTarget: 'commonjs',
},
module: {
rules: [
{ test: /\.ts?$/, loader: "ts-loader" }
]
},
resolve: {
extensions: [".ts", ".tsx", ".js"]
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
exclude: [
/\.\/(.*)\/.ts/,
/\.\/(.*).ts/,
],
}),
],
},
}
const backendConf = {
mode: 'production',
target: "node",
entry: path.resolve(__dirname, 'Server.ts'),
output: {
path: path.resolve(__dirname, '../lib'),
filename: 'Backend.js',
libraryTarget: 'commonjs',
},
module: {
rules: [
{ test: /\.ts?$/, loader: "ts-loader" }
]
},
resolve: {
extensions: [".ts", ".tsx", ".js"]
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
exclude: [
/\.\/(.*)\/.ts/,
/\.\/(.*).ts/,
],
}),
],
},
}
module.exports = [frontendConf, backendConf]
+11
View File
@@ -0,0 +1,11 @@
import { Backend } from '../src/Backend'
const testServer = new Backend(20000, [{
name: "HelloWorldRPCGroup",
publicRPCs: () => [],
localRPCs: () => [{
type: 'Call',
name: 'echo',
call: async (s:string) => s,
}]
}])
+7
View File
@@ -0,0 +1,7 @@
import { Frontend } from '../src/Frontend'
const testClient = new Frontend(20000, 'localhost')
testClient.connect().then(_ => {
testClient.info().then(console.log)
testClient["HelloWorldRPCGroup"].echo("x").then(console.log)
})
-18
View File
@@ -1,18 +0,0 @@
import { Server } from '../src/Server'
import {Client} from '../src/Client'
new Server(20000, [{
name: "HelloWorldRPCGroup",
publicRPCs: () => [],
localRPCs: () => [{
type: 'Call',
name: 'echo',
call: async (s:string) => s,
}]
}])
const caller = new Client(20000, 'localhost')
caller.connect().then(_ => {
caller.info().then(console.log)
caller["HelloWorldRPCGroup"].echo("x").then(console.log)
})
+1
View File
@@ -5,6 +5,7 @@
"target": "ESnext", "target": "ESnext",
"module": "commonjs", "module": "commonjs",
"declaration": true, "declaration": true,
"outDir": "./lib",
"strict": true, "strict": true,
"experimentalDecorators": true "experimentalDecorators": true
}, },