Move jsonrpc back to single package
This commit is contained in:
parent
9adbc584b3
commit
166981fe3b
10
package-lock.json
generated
10
package-lock.json
generated
@ -2130,14 +2130,8 @@
|
|||||||
"@rondo/image-upload": {
|
"@rondo/image-upload": {
|
||||||
"version": "file:packages/image-upload"
|
"version": "file:packages/image-upload"
|
||||||
},
|
},
|
||||||
"@rondo/jsonrpc-client": {
|
"@rondo/jsonrpc": {
|
||||||
"version": "file:packages/jsonrpc-client"
|
"version": "file:packages/jsonrpc"
|
||||||
},
|
|
||||||
"@rondo/jsonrpc-common": {
|
|
||||||
"version": "file:packages/jsonrpc-common"
|
|
||||||
},
|
|
||||||
"@rondo/jsonrpc-server": {
|
|
||||||
"version": "file:packages/jsonrpc-server"
|
|
||||||
},
|
},
|
||||||
"@rondo/scripts": {
|
"@rondo/scripts": {
|
||||||
"version": "file:packages/scripts"
|
"version": "file:packages/scripts"
|
||||||
|
|||||||
@ -8,9 +8,7 @@
|
|||||||
"@rondo/comments-client": "file:packages/comments-client",
|
"@rondo/comments-client": "file:packages/comments-client",
|
||||||
"@rondo/image-upload": "file:packages/image-upload",
|
"@rondo/image-upload": "file:packages/image-upload",
|
||||||
"@rondo/tasq": "file:packages/tasq",
|
"@rondo/tasq": "file:packages/tasq",
|
||||||
"@rondo/jsonrpc-client": "file:packages/jsonrpc-client",
|
"@rondo/jsonrpc": "file:packages/jsonrpc",
|
||||||
"@rondo/jsonrpc-server": "file:packages/jsonrpc-server",
|
|
||||||
"@rondo/jsonrpc-common": "file:packages/jsonrpc-common",
|
|
||||||
"@rondo/scripts": "file:packages/scripts"
|
"@rondo/scripts": "file:packages/scripts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@ -1,2 +0,0 @@
|
|||||||
export * from './local'
|
|
||||||
export * from './remote'
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "./tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "esm"
|
|
||||||
},
|
|
||||||
"references": [
|
|
||||||
{"path": "../jsonrpc-common/tsconfig.esm.json"},
|
|
||||||
{"path": "../jsonrpc-server/tsconfig.esm.json"}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../tsconfig.common.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "lib",
|
|
||||||
"rootDir": "src"
|
|
||||||
},
|
|
||||||
"references": [
|
|
||||||
{"path": "../jsonrpc-common"},
|
|
||||||
{"path": "../jsonrpc-server"}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -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
|
|
||||||
}
|
|
||||||
@ -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"
|
|
||||||
}
|
|
||||||
@ -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'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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
|
|
||||||
}
|
|
||||||
@ -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"
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
export * from './server'
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "./tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "esm"
|
|
||||||
},
|
|
||||||
"references": [
|
|
||||||
{"path": "../jsonrpc-common/tsconfig.esm.json"}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../tsconfig.common.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "lib",
|
|
||||||
"rootDir": "src"
|
|
||||||
},
|
|
||||||
"references": [
|
|
||||||
{"path": "../jsonrpc-common"}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "@rondo/jsonrpc-client",
|
"name": "@rondo/jsonrpc",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
@ -2,7 +2,7 @@ import bodyParser from 'body-parser'
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import request from 'supertest'
|
import request from 'supertest'
|
||||||
import {createClient} from './supertest'
|
import {createClient} from './supertest'
|
||||||
import {jsonrpc} from './server'
|
import {jsonrpc} from './express'
|
||||||
|
|
||||||
describe('jsonrpc', () => {
|
describe('jsonrpc', () => {
|
||||||
|
|
||||||
4
packages/jsonrpc/src/index.ts
Normal file
4
packages/jsonrpc/src/index.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export * from './express'
|
||||||
|
export * from './local'
|
||||||
|
export * from './redux'
|
||||||
|
export * from './remote'
|
||||||
@ -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
|
* 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>
|
||||||
}
|
}
|
||||||
@ -1,13 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* @jest-environment node
|
* @jest-environment node
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import bodyParser from 'body-parser'
|
import bodyParser from 'body-parser'
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import {AddressInfo} from 'net'
|
import {AddressInfo} from 'net'
|
||||||
import {Server} from 'http'
|
import {Server} from 'http'
|
||||||
import {createReduxClient} from './redux'
|
import {createReduxClient} from './redux'
|
||||||
import {createRemoteClient} from './remote'
|
import {createRemoteClient} from './remote'
|
||||||
import {jsonrpc} from '@rondo/jsonrpc-server'
|
import {jsonrpc} from './express'
|
||||||
import {keys} from 'ts-transformer-keys'
|
import {keys} from 'ts-transformer-keys'
|
||||||
|
|
||||||
describe('createReduxClient', () => {
|
describe('createReduxClient', () => {
|
||||||
@ -1,8 +1,8 @@
|
|||||||
import {Asyncified, Reduxed} from '@rondo/jsonrpc-common'
|
import {TAsyncified, TReduxed} from './types'
|
||||||
import {createRemoteClient} from './remote'
|
import {createRemoteClient} from './remote'
|
||||||
|
|
||||||
export function createReduxClient<T, ActionType extends string>(
|
export function createReduxClient<T, ActionType extends string>(
|
||||||
client: Asyncified<T>,
|
client: TAsyncified<T>,
|
||||||
type: ActionType,
|
type: ActionType,
|
||||||
) {
|
) {
|
||||||
const service = Object.keys(client).reduce((obj, method: any) => {
|
const service = Object.keys(client).reduce((obj, method: any) => {
|
||||||
@ -18,5 +18,5 @@ export function createReduxClient<T, ActionType extends string>(
|
|||||||
return obj
|
return obj
|
||||||
}, {} as any)
|
}, {} as any)
|
||||||
|
|
||||||
return service as Reduxed<T, ActionType>
|
return service as TReduxed<T, ActionType>
|
||||||
}
|
}
|
||||||
@ -1,12 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* @jest-environment node
|
* @jest-environment node
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import bodyParser from 'body-parser'
|
import bodyParser from 'body-parser'
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import {AddressInfo} from 'net'
|
import {AddressInfo} from 'net'
|
||||||
import {Server} from 'http'
|
import {Server} from 'http'
|
||||||
import {createRemoteClient} from './remote'
|
import {createRemoteClient} from './remote'
|
||||||
import {jsonrpc} from '@rondo/jsonrpc-server'
|
import {jsonrpc} from './server'
|
||||||
import {keys} from 'ts-transformer-keys'
|
import {keys} from 'ts-transformer-keys'
|
||||||
|
|
||||||
describe('remote', () => {
|
describe('remote', () => {
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import Axios from 'axios'
|
import Axios from 'axios'
|
||||||
import {Asyncified} from '@rondo/jsonrpc-common'
|
import {TAsyncified} from './types'
|
||||||
|
|
||||||
export function createRemoteClient<T>(
|
export function createRemoteClient<T>(
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
@ -36,5 +36,5 @@ export function createRemoteClient<T>(
|
|||||||
return obj
|
return obj
|
||||||
}, {} as any)
|
}, {} as any)
|
||||||
|
|
||||||
return service as Asyncified<T>
|
return service as TAsyncified<T>
|
||||||
}
|
}
|
||||||
@ -1,9 +1,8 @@
|
|||||||
import request from 'supertest'
|
import request from 'supertest'
|
||||||
import {Application} from 'express'
|
import {Application} from 'express'
|
||||||
import {Asyncified} from '@rondo/jsonrpc-common'
|
import {TAsyncified} from './types'
|
||||||
|
|
||||||
export function createClient<T>(
|
export function createClient<T>( app: Application, path: string,
|
||||||
app: Application, path: string,
|
|
||||||
) {
|
) {
|
||||||
let id = 0
|
let id = 0
|
||||||
const proxy = new Proxy({}, {
|
const proxy = new Proxy({}, {
|
||||||
@ -26,5 +25,5 @@ export function createClient<T>(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return proxy as Asyncified<T>
|
return proxy as TAsyncified<T>
|
||||||
}
|
}
|
||||||
20
packages/jsonrpc/src/types.ts
Normal file
20
packages/jsonrpc/src/types.ts
Normal 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'
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user