@things-factory/shell 7.0.14 → 7.0.19
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/config/config.development.js +2 -34
- package/config/config.production.js +5 -26
- package/dist-server/pubsub.d.ts +1 -1
- package/dist-server/pubsub.js +13 -32
- package/dist-server/pubsub.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/helps/about/framework/redirection.md +1 -1
- package/helps/about/framework.ja.md +73 -0
- package/helps/about/framework.ko.md +73 -0
- package/helps/about/framework.md +63 -0
- package/helps/about/framework.ms.md +76 -0
- package/helps/about/framework.zh.md +73 -0
- package/helps/config/fileUpload.ja.md +5 -7
- package/helps/config/fileUpload.md +5 -7
- package/helps/config/fileUpload.ms.md +5 -7
- package/helps/config/pubsub.ja.md +46 -0
- package/helps/config/pubsub.ko.md +46 -0
- package/helps/config/pubsub.md +46 -0
- package/helps/config/pubsub.ms.md +46 -0
- package/helps/config/pubsub.zh.md +46 -0
- package/package.json +4 -5
- package/server/pubsub.ts +13 -37
@@ -0,0 +1,46 @@
|
|
1
|
+
## pubsub
|
2
|
+
|
3
|
+
### 設定オプション
|
4
|
+
|
5
|
+
- **middleware**: Pub/Sub機能を実装するために使用するミドルウェア。(`redis` または `redisCluster` から選択)
|
6
|
+
- **host**: Redisサーバーのホスト名(middlewareが `redis` の場合に使用)
|
7
|
+
- **port**: Redisサーバーのポート番号(middlewareが `redis` の場合に使用)
|
8
|
+
- **nodes**: Redisクラスターノード情報(middlewareが `redisCluster` の場合に使用)
|
9
|
+
- 例:
|
10
|
+
```json
|
11
|
+
[
|
12
|
+
{ "host": "endpoint1", "port": 6379 },
|
13
|
+
{ "host": "endpoint2", "port": 6379 }
|
14
|
+
]
|
15
|
+
```
|
16
|
+
- **options**: RedisまたはRedisクラスターに使用する追加オプション
|
17
|
+
|
18
|
+
### デフォルト設定例
|
19
|
+
|
20
|
+
```javascript
|
21
|
+
module.exports = {
|
22
|
+
pubsub: {
|
23
|
+
middleware: 'redis',
|
24
|
+
host: 'redis',
|
25
|
+
port: 6379,
|
26
|
+
options: {
|
27
|
+
// Redisに対する追加オプション
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
```
|
32
|
+
|
33
|
+
```javascript
|
34
|
+
module.exports = {
|
35
|
+
pubsub: {
|
36
|
+
middleware: 'redisCluster',
|
37
|
+
nodes: [
|
38
|
+
{ host: 'endpoint1', port: 6379 },
|
39
|
+
{ host: 'endpoint2', port: 6379 }
|
40
|
+
],
|
41
|
+
options: {
|
42
|
+
// Redisクラスターに対する追加オプション
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
```
|
@@ -0,0 +1,46 @@
|
|
1
|
+
## pubsub
|
2
|
+
|
3
|
+
### 설정 옵션
|
4
|
+
|
5
|
+
- **middleware**: Pub/Sub 기능을 구현하기 위해 사용할 미들웨어. (`redis` 또는 `redisCluster` 중 선택)
|
6
|
+
- **host**: Redis 서버의 호스트 이름 (middleware가 `redis`일 경우 사용)
|
7
|
+
- **port**: Redis 서버의 포트 번호 (middleware가 `redis`일 경우 사용)
|
8
|
+
- **nodes**: Redis 클러스터 노드 정보 (middleware가 `redisCluster`일 경우 사용)
|
9
|
+
- 예시:
|
10
|
+
```json
|
11
|
+
[
|
12
|
+
{ "host": "endpoint1", "port": 6379 },
|
13
|
+
{ "host": "endpoint2", "port": 6379 }
|
14
|
+
]
|
15
|
+
```
|
16
|
+
- **options**: Redis 또는 Redis 클러스터에 사용할 추가 옵션
|
17
|
+
|
18
|
+
### 기본 설정 예시
|
19
|
+
|
20
|
+
```javascript
|
21
|
+
module.exports = {
|
22
|
+
pubsub: {
|
23
|
+
middleware: 'redis',
|
24
|
+
host: 'redis',
|
25
|
+
port: 6379,
|
26
|
+
options: {
|
27
|
+
// Redis에 대한 추가 옵션
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
```
|
32
|
+
|
33
|
+
```javascript
|
34
|
+
module.exports = {
|
35
|
+
pubsub: {
|
36
|
+
middleware: 'redisCluster',
|
37
|
+
nodes: [
|
38
|
+
{ host: 'endpoint1', port: 6379 },
|
39
|
+
{ host: 'endpoint2', port: 6379 }
|
40
|
+
],
|
41
|
+
options: {
|
42
|
+
// Redis 클러스터에 대한 추가 옵션
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
```
|
@@ -0,0 +1,46 @@
|
|
1
|
+
## pubsub
|
2
|
+
|
3
|
+
### Configuration Options
|
4
|
+
|
5
|
+
- **middleware**: Middleware to be used for implementing Pub/Sub functionality. (Choose between `redis` or `redisCluster`)
|
6
|
+
- **host**: Host name of the Redis server (used when middleware is `redis`)
|
7
|
+
- **port**: Port number of the Redis server (used when middleware is `redis`)
|
8
|
+
- **nodes**: Redis cluster node information (used when middleware is `redisCluster`)
|
9
|
+
- Example:
|
10
|
+
```json
|
11
|
+
[
|
12
|
+
{ "host": "endpoint1", "port": 6379 },
|
13
|
+
{ "host": "endpoint2", "port": 6379 }
|
14
|
+
]
|
15
|
+
```
|
16
|
+
- **options**: Additional options for Redis or Redis cluster
|
17
|
+
|
18
|
+
### Default Configuration Example
|
19
|
+
|
20
|
+
```javascript
|
21
|
+
module.exports = {
|
22
|
+
pubsub: {
|
23
|
+
middleware: 'redis',
|
24
|
+
host: 'redis',
|
25
|
+
port: 6379,
|
26
|
+
options: {
|
27
|
+
// Additional options for Redis
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
```
|
32
|
+
|
33
|
+
```javascript
|
34
|
+
module.exports = {
|
35
|
+
pubsub: {
|
36
|
+
middleware: 'redisCluster',
|
37
|
+
nodes: [
|
38
|
+
{ host: 'endpoint1', port: 6379 },
|
39
|
+
{ host: 'endpoint2', port: 6379 }
|
40
|
+
],
|
41
|
+
options: {
|
42
|
+
// Additional options for Redis cluster
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
```
|
@@ -0,0 +1,46 @@
|
|
1
|
+
## pubsub
|
2
|
+
|
3
|
+
### Pilihan Konfigurasi
|
4
|
+
|
5
|
+
- **middleware**: Middleware yang akan digunakan untuk melaksanakan fungsi Pub/Sub. (Pilih antara `redis` atau `redisCluster`)
|
6
|
+
- **host**: Nama host pelayan Redis (digunakan apabila middleware adalah `redis`)
|
7
|
+
- **port**: Nombor port pelayan Redis (digunakan apabila middleware adalah `redis`)
|
8
|
+
- **nodes**: Maklumat nod kluster Redis (digunakan apabila middleware adalah `redisCluster`)
|
9
|
+
- Contoh:
|
10
|
+
```json
|
11
|
+
[
|
12
|
+
{ "host": "endpoint1", "port": 6379 },
|
13
|
+
{ "host": "endpoint2", "port": 6379 }
|
14
|
+
]
|
15
|
+
```
|
16
|
+
- **options**: Pilihan tambahan untuk Redis atau kluster Redis
|
17
|
+
|
18
|
+
### Contoh Konfigurasi Lalai
|
19
|
+
|
20
|
+
```javascript
|
21
|
+
module.exports = {
|
22
|
+
pubsub: {
|
23
|
+
middleware: 'redis',
|
24
|
+
host: 'redis',
|
25
|
+
port: 6379,
|
26
|
+
options: {
|
27
|
+
// Pilihan tambahan untuk Redis
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
```
|
32
|
+
|
33
|
+
```javascript
|
34
|
+
module.exports = {
|
35
|
+
pubsub: {
|
36
|
+
middleware: 'redisCluster',
|
37
|
+
nodes: [
|
38
|
+
{ host: 'endpoint1', port: 6379 },
|
39
|
+
{ host: 'endpoint2', port: 6379 }
|
40
|
+
],
|
41
|
+
options: {
|
42
|
+
// Pilihan tambahan untuk kluster Redis
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
```
|
@@ -0,0 +1,46 @@
|
|
1
|
+
## pubsub
|
2
|
+
|
3
|
+
### 配置选项
|
4
|
+
|
5
|
+
- **middleware**: 用于实现Pub/Sub功能的中间件。 (选择 `redis` 或 `redisCluster`)
|
6
|
+
- **host**: Redis服务器的主机名(当middleware为 `redis` 时使用)
|
7
|
+
- **port**: Redis服务器的端口号(当middleware为 `redis` 时使用)
|
8
|
+
- **nodes**: Redis集群节点信息(当middleware为 `redisCluster` 时使用)
|
9
|
+
- 示例:
|
10
|
+
```json
|
11
|
+
[
|
12
|
+
{ "host": "endpoint1", "port": 6379 },
|
13
|
+
{ "host": "endpoint2", "port": 6379 }
|
14
|
+
]
|
15
|
+
```
|
16
|
+
- **options**: Redis或Redis集群的附加选项
|
17
|
+
|
18
|
+
### 默认配置示例
|
19
|
+
|
20
|
+
```javascript
|
21
|
+
module.exports = {
|
22
|
+
pubsub: {
|
23
|
+
middleware: 'redis',
|
24
|
+
host: 'redis',
|
25
|
+
port: 6379,
|
26
|
+
options: {
|
27
|
+
// Redis的附加选项
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
```
|
32
|
+
|
33
|
+
```javascript
|
34
|
+
module.exports = {
|
35
|
+
pubsub: {
|
36
|
+
middleware: 'redisCluster',
|
37
|
+
nodes: [
|
38
|
+
{ host: 'endpoint1', port: 6379 },
|
39
|
+
{ host: 'endpoint2', port: 6379 }
|
40
|
+
],
|
41
|
+
options: {
|
42
|
+
// Redis集群的附加选项
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
```
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/shell",
|
3
|
-
"version": "7.0.
|
3
|
+
"version": "7.0.19",
|
4
4
|
"description": "Core module for framework",
|
5
5
|
"bin": {
|
6
6
|
"things-factory": "bin/things-factory",
|
@@ -41,6 +41,7 @@
|
|
41
41
|
"@graphql-tools/merge": "^9.0.3",
|
42
42
|
"@graphql-tools/schema": "^8.5.0",
|
43
43
|
"@graphql-tools/utils": "^10.1.2",
|
44
|
+
"@graphql-yoga/redis-event-target": "^3.0.1",
|
44
45
|
"@hatiolab/koa-webpack": "^7.0.9",
|
45
46
|
"@hatiolab/things-scene": "^3.2.0",
|
46
47
|
"@koa/cors": "^5.0.0",
|
@@ -77,8 +78,6 @@
|
|
77
78
|
"fs-extra": "^9.0.1",
|
78
79
|
"glob": "^7.1.6",
|
79
80
|
"graphql": "^16.5.0",
|
80
|
-
"graphql-mqtt-subscriptions": "^1.2.0",
|
81
|
-
"graphql-redis-subscriptions": "^2.5.0",
|
82
81
|
"graphql-scalars": "^1.22.4",
|
83
82
|
"graphql-tag": "^2.12.6",
|
84
83
|
"graphql-upload": "^15.0.2",
|
@@ -88,7 +87,7 @@
|
|
88
87
|
"html-webpack-plugin": "^5.5.0",
|
89
88
|
"husky": "7.0.1",
|
90
89
|
"inquirer": "^8.2.0",
|
91
|
-
"ioredis": "^4.
|
90
|
+
"ioredis": "^5.4.1",
|
92
91
|
"json-stringify-safe": "^5.0.1",
|
93
92
|
"json5": "^2.2.0",
|
94
93
|
"koa": "^2.13.4",
|
@@ -134,5 +133,5 @@
|
|
134
133
|
"pg": "^8.7.3",
|
135
134
|
"sqlite3": "^5.0.8"
|
136
135
|
},
|
137
|
-
"gitHead": "
|
136
|
+
"gitHead": "d12e0e75184c6d17e73f0a330a618a18a7e61d22"
|
138
137
|
}
|
package/server/pubsub.ts
CHANGED
@@ -2,33 +2,22 @@
|
|
2
2
|
* @module pubsub
|
3
3
|
* @description
|
4
4
|
* This module provides a Pub/Sub (Publish/Subscribe) mechanism for handling messages and events.
|
5
|
-
* Developers can use various middleware options such as
|
5
|
+
* Developers can use various middleware options such as Redis, Redis Cluster
|
6
6
|
* to implement Pub/Sub functionality.
|
7
7
|
*/
|
8
8
|
|
9
|
-
import { MQTTPubSub } from 'graphql-mqtt-subscriptions'
|
10
|
-
import { RedisPubSub } from 'graphql-redis-subscriptions'
|
11
9
|
import { createPubSub } from 'graphql-yoga'
|
10
|
+
import { createRedisEventTarget } from '@graphql-yoga/redis-event-target'
|
12
11
|
import Redis from 'ioredis'
|
13
|
-
import { connect } from 'mqtt'
|
14
12
|
|
15
13
|
import { config, logger } from '@things-factory/env'
|
16
14
|
import { PubSub } from 'type-graphql'
|
17
15
|
|
18
|
-
const { middleware, host, port, nodes,
|
16
|
+
const { middleware, host, port, nodes, options } = config.get('pubsub', {})
|
19
17
|
|
20
18
|
let pubsub: PubSub
|
21
19
|
|
22
20
|
switch (middleware) {
|
23
|
-
case 'mqtt':
|
24
|
-
//@ts-ignore
|
25
|
-
pubsub = new MQTTPubSub({
|
26
|
-
client: connect('mqtt://' + host, {
|
27
|
-
reconnectPeriod: 1000,
|
28
|
-
...options
|
29
|
-
}) as any
|
30
|
-
})
|
31
|
-
break
|
32
21
|
case 'redis':
|
33
22
|
const redisOption = {
|
34
23
|
host,
|
@@ -40,35 +29,22 @@ switch (middleware) {
|
|
40
29
|
...options
|
41
30
|
}
|
42
31
|
//@ts-ignore
|
43
|
-
pubsub =
|
44
|
-
|
45
|
-
|
32
|
+
pubsub = createPubSub({
|
33
|
+
eventTarget: createRedisEventTarget({
|
34
|
+
publishClient: new Redis(redisOption),
|
35
|
+
subscribeClient: new Redis(redisOption)
|
36
|
+
})
|
46
37
|
})
|
47
38
|
break
|
48
39
|
case 'redisCluster':
|
49
40
|
const cluster = new Redis.Cluster(nodes, options)
|
50
41
|
//@ts-ignore
|
51
|
-
pubsub =
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
break
|
56
|
-
case 'kafka':
|
57
|
-
try {
|
58
|
-
/*
|
59
|
-
* https://github.com/hatiolab/things-factory/issues/1239
|
60
|
-
*/
|
61
|
-
const { KafkaPubSub } = require('graphql-kafka-subscriptions')
|
62
|
-
pubsub = new KafkaPubSub({
|
63
|
-
topic,
|
64
|
-
host,
|
65
|
-
port,
|
66
|
-
...options
|
42
|
+
pubsub = createPubSub({
|
43
|
+
eventTarget: createRedisEventTarget({
|
44
|
+
publishClient: cluster,
|
45
|
+
subscribeClient: cluster
|
67
46
|
})
|
68
|
-
}
|
69
|
-
logger.error('graphql-kafka-subscriptions module is not installed, so application can not go further.', e)
|
70
|
-
throw e
|
71
|
-
}
|
47
|
+
})
|
72
48
|
break
|
73
49
|
default:
|
74
50
|
pubsub = createPubSub()
|