@vyr/service-rpc-universal 0.0.19 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/Message.ts +2 -0
- package/src/RpcService.ts +15 -5
- package/src/domain/Entity.ts +12 -0
- package/src/domain/Example.ts +80 -0
- package/src/domain/User.ts +84 -0
- package/src/domain/index.ts +3 -0
- package/src/example/apply.ts +35 -0
- package/src/example/create.ts +36 -0
- package/src/example/delete.ts +33 -0
- package/src/example/index.ts +5 -0
- package/src/example/initialize.ts +22 -0
- package/src/example/list.ts +35 -0
- package/src/index.ts +1 -1
- package/src/rpc/getUser.ts +2 -2
- package/src/User.ts +0 -21
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vyr/service-rpc-universal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"
|
|
9
|
+
"moment": "^2.30.1",
|
|
10
|
+
"@vyr/engine": "0.0.20"
|
|
10
11
|
},
|
|
11
12
|
"files": [
|
|
12
13
|
"package.json",
|
package/src/Message.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as rpc from './rpc'
|
|
|
3
3
|
import * as sidebar from './sidebar'
|
|
4
4
|
import * as asset from './asset'
|
|
5
5
|
import * as scene from './scene'
|
|
6
|
+
import * as example from './example'
|
|
6
7
|
import * as dep from './dep'
|
|
7
8
|
|
|
8
9
|
/** 通信消息 */
|
|
@@ -11,6 +12,7 @@ class Message extends IMessage {
|
|
|
11
12
|
static sidebar = sidebar
|
|
12
13
|
static asset = asset
|
|
13
14
|
static scene = scene
|
|
15
|
+
static example = example
|
|
14
16
|
static dep = dep
|
|
15
17
|
}
|
|
16
18
|
|
package/src/RpcService.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
|
-
import {
|
|
2
|
+
import { Serialization, Listener } from '@vyr/engine'
|
|
3
3
|
import { Service } from '@vyr/service'
|
|
4
4
|
import { path, tokenKey, topic, Confirm, Message } from '@vyr/service-rpc-universal'
|
|
5
5
|
|
|
@@ -55,7 +55,7 @@ class RpcService extends Service {
|
|
|
55
55
|
this.socket = new window.io(location.href, params)
|
|
56
56
|
|
|
57
57
|
this.socket.on(topic, (content: string) => {
|
|
58
|
-
const msg =
|
|
58
|
+
const msg = Serialization.parse(content) as Message
|
|
59
59
|
if (msg.message !== undefined) return config.notify(msg.message)
|
|
60
60
|
this._delayTrigger(msg)
|
|
61
61
|
})
|
|
@@ -106,7 +106,7 @@ class RpcService extends Service {
|
|
|
106
106
|
trigger<T extends Message = Message>(method: string, msg: T) {
|
|
107
107
|
this._listener.trigger(method, msg)
|
|
108
108
|
}
|
|
109
|
-
listen<T extends Message = Message>(method: string, cb: (msg: T) => void) {
|
|
109
|
+
listen<T extends Message = Message>(method: string, cb: (msg: T, ...others: any[]) => void) {
|
|
110
110
|
this._listener.listen(method, cb)
|
|
111
111
|
}
|
|
112
112
|
unlisten<T extends Message = Message>(method: string, cb: (msg: T) => void) {
|
|
@@ -114,8 +114,18 @@ class RpcService extends Service {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
/**向服务端发送数据 */
|
|
117
|
-
send(msg: Message) {
|
|
118
|
-
|
|
117
|
+
send<T extends Message | void = Message>(msg: Message) {
|
|
118
|
+
return new Promise<T>(resolve => {
|
|
119
|
+
this.socket.emit(topic, Serialization.stringify(msg), (content: string) => {
|
|
120
|
+
if (content) {
|
|
121
|
+
const msg = Serialization.parse(content)
|
|
122
|
+
resolve(msg as T)
|
|
123
|
+
} else {
|
|
124
|
+
//@ts-ignore
|
|
125
|
+
resolve()
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
})
|
|
119
129
|
}
|
|
120
130
|
}
|
|
121
131
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import moment from 'moment'
|
|
2
|
+
import { Entity } from './Entity'
|
|
3
|
+
|
|
4
|
+
abstract class Example extends Entity {
|
|
5
|
+
static primaryKey: keyof Example = 'id'
|
|
6
|
+
id: string
|
|
7
|
+
name: string
|
|
8
|
+
badge: string
|
|
9
|
+
author: string
|
|
10
|
+
radio: string
|
|
11
|
+
download: number
|
|
12
|
+
image: string
|
|
13
|
+
abstract createTime: string | number
|
|
14
|
+
|
|
15
|
+
constructor(record: Partial<Example>) {
|
|
16
|
+
super()
|
|
17
|
+
this.id = record.id ?? ''
|
|
18
|
+
this.name = record.name ?? ''
|
|
19
|
+
this.badge = record.badge ?? ''
|
|
20
|
+
this.author = record.author ?? ''
|
|
21
|
+
this.radio = record.radio ?? ''
|
|
22
|
+
this.download = record.download ?? 0
|
|
23
|
+
this.image = record.image ?? ''
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
toVO() {
|
|
27
|
+
let createTime
|
|
28
|
+
if (typeof this.createTime === 'number') {
|
|
29
|
+
createTime = moment(this.createTime).format(Example.dateFormat)
|
|
30
|
+
} else {
|
|
31
|
+
createTime = this.createTime
|
|
32
|
+
}
|
|
33
|
+
const vo: ExampleVO = new ExampleVO({
|
|
34
|
+
...this,
|
|
35
|
+
createTime,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return vo
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
toDO() {
|
|
42
|
+
let createTime
|
|
43
|
+
if (typeof this.createTime === 'number') {
|
|
44
|
+
createTime = this.createTime
|
|
45
|
+
} else {
|
|
46
|
+
const date = moment(this.createTime, Example.dateFormat)
|
|
47
|
+
createTime = date.valueOf()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const DO: ExampleDO = new ExampleDO({
|
|
51
|
+
...this,
|
|
52
|
+
createTime
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
return DO
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class ExampleDO extends Example {
|
|
60
|
+
createTime: number
|
|
61
|
+
|
|
62
|
+
constructor(record: Partial<ExampleDO> = {}) {
|
|
63
|
+
super(record)
|
|
64
|
+
this.createTime = record.createTime ?? 0
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
class ExampleVO extends Example {
|
|
69
|
+
createTime: string
|
|
70
|
+
|
|
71
|
+
constructor(record: Partial<ExampleVO> = {}) {
|
|
72
|
+
super(record)
|
|
73
|
+
this.createTime = record.createTime ?? ''
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
ExampleDO,
|
|
79
|
+
ExampleVO,
|
|
80
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import moment from 'moment'
|
|
2
|
+
import { Entity } from './Entity'
|
|
3
|
+
|
|
4
|
+
abstract class User extends Entity {
|
|
5
|
+
static primaryKey: keyof User = 'id'
|
|
6
|
+
id: string
|
|
7
|
+
name = ''
|
|
8
|
+
password = ''
|
|
9
|
+
token = ''
|
|
10
|
+
role = ''
|
|
11
|
+
abstract createTime: string | number
|
|
12
|
+
|
|
13
|
+
constructor(record: Partial<User>) {
|
|
14
|
+
super()
|
|
15
|
+
this.id = record.id ?? ''
|
|
16
|
+
this.name = record.name ?? ''
|
|
17
|
+
this.password = record.password ?? ''
|
|
18
|
+
this.token = record.token ?? ''
|
|
19
|
+
this.role = record.role ?? ''
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
toVO() {
|
|
23
|
+
let createTime
|
|
24
|
+
if (typeof this.createTime === 'number') {
|
|
25
|
+
createTime = moment(this.createTime).format(User.dateFormat)
|
|
26
|
+
} else {
|
|
27
|
+
createTime = this.createTime
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const VO: UserVO = new UserVO({
|
|
31
|
+
...this,
|
|
32
|
+
createTime
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return VO
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
toDO() {
|
|
39
|
+
let createTime
|
|
40
|
+
if (typeof this.createTime === 'number') {
|
|
41
|
+
createTime = this.createTime
|
|
42
|
+
} else {
|
|
43
|
+
const date = moment(this.createTime, User.dateFormat)
|
|
44
|
+
createTime = date.valueOf()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const DO: UserDO = new UserDO({
|
|
48
|
+
...this,
|
|
49
|
+
createTime
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return DO
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
class UserDO extends User {
|
|
57
|
+
createTime: number
|
|
58
|
+
|
|
59
|
+
constructor(record: Partial<UserDO> = {}) {
|
|
60
|
+
super(record)
|
|
61
|
+
this.createTime = record.createTime ?? 0
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
toJSON() {
|
|
65
|
+
return {
|
|
66
|
+
...this,
|
|
67
|
+
token: '',
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
class UserVO extends User {
|
|
73
|
+
createTime: string
|
|
74
|
+
|
|
75
|
+
constructor(record: Partial<UserVO> = {}) {
|
|
76
|
+
super(record)
|
|
77
|
+
this.createTime = record.createTime ?? ''
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export {
|
|
82
|
+
UserDO,
|
|
83
|
+
UserVO,
|
|
84
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IMessage } from '../IMessage'
|
|
2
|
+
|
|
3
|
+
const Method = '/cli/example.apply'
|
|
4
|
+
|
|
5
|
+
interface RequestParams {
|
|
6
|
+
example: string
|
|
7
|
+
node: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
class RequestMessage extends IMessage {
|
|
11
|
+
method = Method
|
|
12
|
+
params: RequestParams
|
|
13
|
+
|
|
14
|
+
constructor(example: string, node: string) {
|
|
15
|
+
super()
|
|
16
|
+
this.params = { example, node }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface NoticeParams {
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class NoticeMessage extends IMessage {
|
|
25
|
+
method = Method
|
|
26
|
+
params: NoticeParams
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
super()
|
|
30
|
+
this.params = {}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export { Method, RequestMessage, NoticeMessage }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IMessage } from '../IMessage'
|
|
2
|
+
|
|
3
|
+
const Method = '/cli/example.create'
|
|
4
|
+
|
|
5
|
+
interface RequestParams {
|
|
6
|
+
name: string
|
|
7
|
+
image: string
|
|
8
|
+
node: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class RequestMessage extends IMessage {
|
|
12
|
+
method = Method
|
|
13
|
+
params: RequestParams
|
|
14
|
+
|
|
15
|
+
constructor(params: RequestParams) {
|
|
16
|
+
super()
|
|
17
|
+
this.params = params
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface NoticeParams {
|
|
22
|
+
example: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class NoticeMessage extends IMessage {
|
|
26
|
+
method = Method
|
|
27
|
+
params: NoticeParams
|
|
28
|
+
|
|
29
|
+
constructor(example: NoticeParams['example']) {
|
|
30
|
+
super()
|
|
31
|
+
this.params = { example }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export { Method, RequestMessage, NoticeMessage }
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IMessage } from '../IMessage'
|
|
2
|
+
|
|
3
|
+
const Method = '/cli/example.delete'
|
|
4
|
+
|
|
5
|
+
interface RequestParams {
|
|
6
|
+
example: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class RequestMessage extends IMessage {
|
|
10
|
+
method = Method
|
|
11
|
+
params: RequestParams
|
|
12
|
+
|
|
13
|
+
constructor(example: RequestParams['example']) {
|
|
14
|
+
super()
|
|
15
|
+
this.params = { example }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface NoticeParams {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class NoticeMessage extends IMessage {
|
|
23
|
+
method = Method
|
|
24
|
+
params: NoticeParams
|
|
25
|
+
|
|
26
|
+
constructor() {
|
|
27
|
+
super()
|
|
28
|
+
this.params = {}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export { Method, RequestMessage, NoticeMessage }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IMessage } from '../IMessage'
|
|
2
|
+
|
|
3
|
+
const Method = '/cli/example.initialize'
|
|
4
|
+
|
|
5
|
+
class RequestMessage extends IMessage {
|
|
6
|
+
method = Method
|
|
7
|
+
constructor() {
|
|
8
|
+
super()
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class NoticeMessage extends IMessage {
|
|
13
|
+
method = Method
|
|
14
|
+
params
|
|
15
|
+
constructor() {
|
|
16
|
+
super()
|
|
17
|
+
this.params = { }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export { Method, RequestMessage, NoticeMessage }
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ExampleVO } from '../domain'
|
|
2
|
+
import { IMessage } from '../IMessage'
|
|
3
|
+
|
|
4
|
+
const Method = '/cli/example.list'
|
|
5
|
+
|
|
6
|
+
interface RequestParams {
|
|
7
|
+
name: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
class RequestMessage extends IMessage {
|
|
11
|
+
method = Method
|
|
12
|
+
params: RequestParams
|
|
13
|
+
|
|
14
|
+
constructor(name: RequestParams['name']) {
|
|
15
|
+
super()
|
|
16
|
+
this.params = { name }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface NoticeParams {
|
|
21
|
+
list: ExampleVO[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class NoticeMessage extends IMessage {
|
|
25
|
+
method = Method
|
|
26
|
+
params: NoticeParams
|
|
27
|
+
|
|
28
|
+
constructor(list: NoticeParams['list']) {
|
|
29
|
+
super()
|
|
30
|
+
this.params = { list }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export { Method, RequestMessage, NoticeMessage }
|
package/src/index.ts
CHANGED
package/src/rpc/getUser.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeserializationObject } from '@vyr/engine'
|
|
2
2
|
import { IMessage } from '../IMessage'
|
|
3
|
-
import {
|
|
3
|
+
import { UserVO } from '../domain'
|
|
4
4
|
|
|
5
5
|
const Method = '/cli/rpc.getUser'
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@ class RequestMessage extends IMessage {
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
interface NoticeParams {
|
|
23
|
-
user: DeserializationObject<
|
|
23
|
+
user: DeserializationObject<UserVO> | null
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
class NoticeMessage extends IMessage {
|
package/src/User.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
class User {
|
|
2
|
-
name = ''
|
|
3
|
-
password = ''
|
|
4
|
-
token = ''
|
|
5
|
-
role = ''
|
|
6
|
-
|
|
7
|
-
constructor(user: Partial<User> = {}) {
|
|
8
|
-
this.name = user.name ?? ''
|
|
9
|
-
this.password = user.password ?? ''
|
|
10
|
-
this.token = user.token ?? ''
|
|
11
|
-
this.role = user.role ?? ''
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
clone() {
|
|
15
|
-
const user = new User(this)
|
|
16
|
-
user.password = ''
|
|
17
|
-
return user
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { User }
|