Move jsonrpc back to single package

This commit is contained in:
Jerko Steiner 2019-08-01 12:26:23 +07:00
parent 9adbc584b3
commit 166981fe3b
31 changed files with 43 additions and 162 deletions

10
package-lock.json generated
View File

@ -2130,14 +2130,8 @@
"@rondo/image-upload": {
"version": "file:packages/image-upload"
},
"@rondo/jsonrpc-client": {
"version": "file:packages/jsonrpc-client"
},
"@rondo/jsonrpc-common": {
"version": "file:packages/jsonrpc-common"
},
"@rondo/jsonrpc-server": {
"version": "file:packages/jsonrpc-server"
"@rondo/jsonrpc": {
"version": "file:packages/jsonrpc"
},
"@rondo/scripts": {
"version": "file:packages/scripts"

View File

@ -8,9 +8,7 @@
"@rondo/comments-client": "file:packages/comments-client",
"@rondo/image-upload": "file:packages/image-upload",
"@rondo/tasq": "file:packages/tasq",
"@rondo/jsonrpc-client": "file:packages/jsonrpc-client",
"@rondo/jsonrpc-server": "file:packages/jsonrpc-server",
"@rondo/jsonrpc-common": "file:packages/jsonrpc-common",
"@rondo/jsonrpc": "file:packages/jsonrpc",
"@rondo/scripts": "file:packages/scripts"
},
"devDependencies": {

View File

@ -1,2 +0,0 @@
export * from './local'
export * from './remote'

View File

@ -1,10 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "esm"
},
"references": [
{"path": "../jsonrpc-common/tsconfig.esm.json"},
{"path": "../jsonrpc-server/tsconfig.esm.json"}
]
}

View File

@ -1,11 +0,0 @@
{
"extends": "../tsconfig.common.json",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
},
"references": [
{"path": "../jsonrpc-common"},
{"path": "../jsonrpc-server"}
]
}

View File

@ -1,22 +0,0 @@
module.exports = {
globals: {
'ts-jest': {
compiler: 'ttypescript'
}
},
roots: [
'<rootDir>/src'
],
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
testRegex: '(/__tests__/.*|\\.(test|spec))\\.tsx?$',
moduleFileExtensions: [
'ts',
'tsx',
'js',
'jsx'
],
setupFiles: ['<rootDir>/jest.setup.js'],
verbose: false
}

View File

@ -1,15 +0,0 @@
{
"name": "@rondo/jsonrpc-common",
"private": true,
"scripts": {
"test": "jest",
"lint": "tslint --project .",
"compile": "tsc",
"clean": "rm -rf lib/"
},
"dependencies": {},
"devDependencies": {},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"module": "esm/index.js"
}

View File

@ -1,19 +0,0 @@
export type ArgumentTypes<T> =
T extends (...args: infer U) => infer R ? U : never
export type RetType<T> = T extends (...args: any[]) => infer R ? R : never
export type UnwrapHOC<T> = T extends (...args: any[]) => infer R ? R : T
export type RetProm<T> = T extends Promise<any> ? T : Promise<T>
export type PromisifyReturnType<T> = (...a: ArgumentTypes<T>) =>
RetProm<UnwrapHOC<RetType<T>>>
export type Asyncified<T> = {
[K in keyof T]: PromisifyReturnType<T[K]>
}
export type Reduxed<T, ActionType extends string> = {
[K in keyof T]: (...a: ArgumentTypes<T[K]>) => {
type: ActionType
payload: RetProm<UnwrapHOC<RetType<T[K]>>>
method: K
status: 'pending'
}
}

View File

@ -1,22 +0,0 @@
module.exports = {
globals: {
'ts-jest': {
compiler: 'ttypescript'
}
},
roots: [
'<rootDir>/src'
],
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
testRegex: '(/__tests__/.*|\\.(test|spec))\\.tsx?$',
moduleFileExtensions: [
'ts',
'tsx',
'js',
'jsx'
],
setupFiles: ['<rootDir>/jest.setup.js'],
verbose: false
}

View File

@ -1,15 +0,0 @@
{
"name": "@rondo/jsonrpc-server",
"private": true,
"scripts": {
"test": "jest",
"lint": "tslint --project .",
"compile": "tsc",
"clean": "rm -rf lib/"
},
"dependencies": {},
"devDependencies": {},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"module": "esm/index.js"
}

View File

@ -1 +0,0 @@
export * from './server'

View File

@ -1,9 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "esm"
},
"references": [
{"path": "../jsonrpc-common/tsconfig.esm.json"}
]
}

View File

@ -1,10 +0,0 @@
{
"extends": "../tsconfig.common.json",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
},
"references": [
{"path": "../jsonrpc-common"}
]
}

View File

@ -1,5 +1,5 @@
{
"name": "@rondo/jsonrpc-client",
"name": "@rondo/jsonrpc",
"private": true,
"scripts": {
"test": "jest",

View File

@ -2,7 +2,7 @@ import bodyParser from 'body-parser'
import express from 'express'
import request from 'supertest'
import {createClient} from './supertest'
import {jsonrpc} from './server'
import {jsonrpc} from './express'
describe('jsonrpc', () => {

View File

@ -0,0 +1,4 @@
export * from './express'
export * from './local'
export * from './redux'
export * from './remote'

View File

@ -1,4 +1,4 @@
import {Asyncified} from '@rondo/jsonrpc-common'
import {TAsyncified} from './types'
/**
* Creates a local client for a specific service instance. The actual service
@ -17,5 +17,5 @@ export function createLocalClient<T>(service: T, context: any) {
}
},
})
return proxy as Asyncified<T>
return proxy as TAsyncified<T>
}

View File

@ -1,13 +1,14 @@
/**
* @jest-environment node
*/
import bodyParser from 'body-parser'
import express from 'express'
import {AddressInfo} from 'net'
import {Server} from 'http'
import {createReduxClient} from './redux'
import {createRemoteClient} from './remote'
import {jsonrpc} from '@rondo/jsonrpc-server'
import {jsonrpc} from './express'
import {keys} from 'ts-transformer-keys'
describe('createReduxClient', () => {

View File

@ -1,8 +1,8 @@
import {Asyncified, Reduxed} from '@rondo/jsonrpc-common'
import {TAsyncified, TReduxed} from './types'
import {createRemoteClient} from './remote'
export function createReduxClient<T, ActionType extends string>(
client: Asyncified<T>,
client: TAsyncified<T>,
type: ActionType,
) {
const service = Object.keys(client).reduce((obj, method: any) => {
@ -18,5 +18,5 @@ export function createReduxClient<T, ActionType extends string>(
return obj
}, {} as any)
return service as Reduxed<T, ActionType>
return service as TReduxed<T, ActionType>
}

View File

@ -1,12 +1,13 @@
/**
* @jest-environment node
*/
import bodyParser from 'body-parser'
import express from 'express'
import {AddressInfo} from 'net'
import {Server} from 'http'
import {createRemoteClient} from './remote'
import {jsonrpc} from '@rondo/jsonrpc-server'
import {jsonrpc} from './server'
import {keys} from 'ts-transformer-keys'
describe('remote', () => {

View File

@ -1,5 +1,5 @@
import Axios from 'axios'
import {Asyncified} from '@rondo/jsonrpc-common'
import {TAsyncified} from './types'
export function createRemoteClient<T>(
baseUrl: string,
@ -36,5 +36,5 @@ export function createRemoteClient<T>(
return obj
}, {} as any)
return service as Asyncified<T>
return service as TAsyncified<T>
}

View File

@ -1,9 +1,8 @@
import request from 'supertest'
import {Application} from 'express'
import {Asyncified} from '@rondo/jsonrpc-common'
import {TAsyncified} from './types'
export function createClient<T>(
app: Application, path: string,
export function createClient<T>( app: Application, path: string,
) {
let id = 0
const proxy = new Proxy({}, {
@ -26,5 +25,5 @@ export function createClient<T>(
}
},
})
return proxy as Asyncified<T>
return proxy as TAsyncified<T>
}

View File

@ -0,0 +1,20 @@
type ArgumentTypes<T> =
T extends (...args: infer U) => infer R ? U : never
type RetType<T> = T extends (...args: any[]) => infer R ? R : never
type UnwrapHOC<T> = T extends (...args: any[]) => infer R ? R : T
type RetProm<T> = T extends Promise<any> ? T : Promise<T>
type PromisifyReturnType<T> = (...a: ArgumentTypes<T>) =>
RetProm<UnwrapHOC<RetType<T>>>
export type TAsyncified<T> = {
[K in keyof T]: PromisifyReturnType<T[K]>
}
export type TReduxed<T, ActionType extends string> = {
[K in keyof T]: (...a: ArgumentTypes<T[K]>) => {
type: ActionType
payload: RetProm<UnwrapHOC<RetType<T[K]>>>
method: K
status: 'pending'
}
}