@things-factory/shell 7.0.14 → 7.0.28
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 +8 -9
- package/server/pubsub.ts +13 -37
@@ -55,7 +55,7 @@ module.exports = {
|
|
55
55
|
* pubsub configuration
|
56
56
|
* ie.
|
57
57
|
* pubsub: {
|
58
|
-
* middleware: 'redis',
|
58
|
+
* middleware: 'redis',
|
59
59
|
* host: 'redis',
|
60
60
|
* port: 6379,
|
61
61
|
* options: {
|
@@ -64,7 +64,7 @@ module.exports = {
|
|
64
64
|
* }
|
65
65
|
*
|
66
66
|
* pubsub: {
|
67
|
-
* middleware: 'redisCluster',
|
67
|
+
* middleware: 'redisCluster',
|
68
68
|
* nodes: [
|
69
69
|
* { host: '{endpoint1}', port: 6379 },
|
70
70
|
* { host: '{endpoint2}', port: 6379 },
|
@@ -73,38 +73,6 @@ module.exports = {
|
|
73
73
|
* ...
|
74
74
|
* }
|
75
75
|
* }
|
76
|
-
*
|
77
|
-
* pubsub: {
|
78
|
-
* middleware: 'kafka',
|
79
|
-
* topic: 'operato-app-graphql-pubsub'
|
80
|
-
* host: 'b-3.kafka-server:9092,b-1.kafka-server:9092,b-2.kafka-server:9092',
|
81
|
-
* options: {
|
82
|
-
* ...
|
83
|
-
* }
|
84
|
-
* }
|
85
|
-
*
|
86
|
-
* pubsub: {
|
87
|
-
* middleware: 'kafka',
|
88
|
-
* host: 'confluent.cloud:9092',
|
89
|
-
* topic: 'operato-app-graphql-pubsub',
|
90
|
-
* options: {
|
91
|
-
* globalConfig: {
|
92
|
-
* "sasl.mechanisms": "PLAIN",
|
93
|
-
* "security.protocol": "SASL_SSL",
|
94
|
-
* "sasl.username": "{CLOUD_KEY}",
|
95
|
-
* "sasl.password": "{CLOUD_SECRET_KEY}"
|
96
|
-
* }
|
97
|
-
* }
|
98
|
-
* }
|
99
|
-
*
|
100
|
-
* pubsub: {
|
101
|
-
* middleware: 'mqtt',
|
102
|
-
* host: 'mosquitto',
|
103
|
-
* port: 1884,
|
104
|
-
* options: {
|
105
|
-
* ...
|
106
|
-
* }
|
107
|
-
* }
|
108
76
|
*/
|
109
77
|
ormconfig: {
|
110
78
|
name: 'default',
|
@@ -73,32 +73,11 @@ module.exports = {
|
|
73
73
|
* }
|
74
74
|
*
|
75
75
|
* pubsub: {
|
76
|
-
* middleware: '
|
77
|
-
*
|
78
|
-
*
|
79
|
-
*
|
80
|
-
*
|
81
|
-
* }
|
82
|
-
* }
|
83
|
-
*
|
84
|
-
* pubsub: {
|
85
|
-
* middleware: 'kafka',
|
86
|
-
* host: 'confluent.cloud:9092',
|
87
|
-
* topic: 'operato-app-graphql-pubsub',
|
88
|
-
* options: {
|
89
|
-
* globalConfig: {
|
90
|
-
* "sasl.mechanisms": "PLAIN",
|
91
|
-
* "security.protocol": "SASL_SSL",
|
92
|
-
* "sasl.username": "{CLOUD_KEY}",
|
93
|
-
* "sasl.password": "{CLOUD_SECRET_KEY}"
|
94
|
-
* }
|
95
|
-
* }
|
96
|
-
* }
|
97
|
-
*
|
98
|
-
* pubsub: {
|
99
|
-
* middleware: 'mqtt',
|
100
|
-
* host: 'mosquitto',
|
101
|
-
* port: 1884,
|
76
|
+
* middleware: 'redisCluster',
|
77
|
+
* nodes: [
|
78
|
+
* { host: '{endpoint1}', port: 6379 },
|
79
|
+
* { host: '{endpoint2}', port: 6379 },
|
80
|
+
* ]
|
102
81
|
* options: {
|
103
82
|
* ...
|
104
83
|
* }
|
package/dist-server/pubsub.d.ts
CHANGED
@@ -2,7 +2,7 @@
|
|
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
|
import { PubSub } from 'type-graphql';
|
package/dist-server/pubsub.js
CHANGED
@@ -3,27 +3,19 @@
|
|
3
3
|
* @module pubsub
|
4
4
|
* @description
|
5
5
|
* This module provides a Pub/Sub (Publish/Subscribe) mechanism for handling messages and events.
|
6
|
-
* Developers can use various middleware options such as
|
6
|
+
* Developers can use various middleware options such as Redis, Redis Cluster
|
7
7
|
* to implement Pub/Sub functionality.
|
8
8
|
*/
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
10
10
|
exports.pubsub = void 0;
|
11
11
|
const tslib_1 = require("tslib");
|
12
|
-
const graphql_mqtt_subscriptions_1 = require("graphql-mqtt-subscriptions");
|
13
|
-
const graphql_redis_subscriptions_1 = require("graphql-redis-subscriptions");
|
14
12
|
const graphql_yoga_1 = require("graphql-yoga");
|
13
|
+
const redis_event_target_1 = require("@graphql-yoga/redis-event-target");
|
15
14
|
const ioredis_1 = tslib_1.__importDefault(require("ioredis"));
|
16
|
-
const mqtt_1 = require("mqtt");
|
17
15
|
const env_1 = require("@things-factory/env");
|
18
|
-
const { middleware, host, port, nodes,
|
16
|
+
const { middleware, host, port, nodes, options } = env_1.config.get('pubsub', {});
|
19
17
|
let pubsub;
|
20
18
|
switch (middleware) {
|
21
|
-
case 'mqtt':
|
22
|
-
//@ts-ignore
|
23
|
-
exports.pubsub = pubsub = new graphql_mqtt_subscriptions_1.MQTTPubSub({
|
24
|
-
client: (0, mqtt_1.connect)('mqtt://' + host, Object.assign({ reconnectPeriod: 1000 }, options))
|
25
|
-
});
|
26
|
-
break;
|
27
19
|
case 'redis':
|
28
20
|
const redisOption = Object.assign({ host,
|
29
21
|
port, retryStrategy: times => {
|
@@ -31,34 +23,23 @@ switch (middleware) {
|
|
31
23
|
return Math.min(times * 50, 2000);
|
32
24
|
} }, options);
|
33
25
|
//@ts-ignore
|
34
|
-
exports.pubsub = pubsub =
|
35
|
-
|
36
|
-
|
26
|
+
exports.pubsub = pubsub = (0, graphql_yoga_1.createPubSub)({
|
27
|
+
eventTarget: (0, redis_event_target_1.createRedisEventTarget)({
|
28
|
+
publishClient: new ioredis_1.default(redisOption),
|
29
|
+
subscribeClient: new ioredis_1.default(redisOption)
|
30
|
+
})
|
37
31
|
});
|
38
32
|
break;
|
39
33
|
case 'redisCluster':
|
40
34
|
const cluster = new ioredis_1.default.Cluster(nodes, options);
|
41
35
|
//@ts-ignore
|
42
|
-
exports.pubsub = pubsub =
|
43
|
-
|
44
|
-
|
36
|
+
exports.pubsub = pubsub = (0, graphql_yoga_1.createPubSub)({
|
37
|
+
eventTarget: (0, redis_event_target_1.createRedisEventTarget)({
|
38
|
+
publishClient: cluster,
|
39
|
+
subscribeClient: cluster
|
40
|
+
})
|
45
41
|
});
|
46
42
|
break;
|
47
|
-
case 'kafka':
|
48
|
-
try {
|
49
|
-
/*
|
50
|
-
* https://github.com/hatiolab/things-factory/issues/1239
|
51
|
-
*/
|
52
|
-
const { KafkaPubSub } = require('graphql-kafka-subscriptions');
|
53
|
-
exports.pubsub = pubsub = new KafkaPubSub(Object.assign({ topic,
|
54
|
-
host,
|
55
|
-
port }, options));
|
56
|
-
}
|
57
|
-
catch (e) {
|
58
|
-
env_1.logger.error('graphql-kafka-subscriptions module is not installed, so application can not go further.', e);
|
59
|
-
throw e;
|
60
|
-
}
|
61
|
-
break;
|
62
43
|
default:
|
63
44
|
exports.pubsub = pubsub = (0, graphql_yoga_1.createPubSub)();
|
64
45
|
break;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../server/pubsub.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;AAEH
|
1
|
+
{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../server/pubsub.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;AAEH,+CAA2C;AAC3C,yEAAyE;AACzE,8DAA2B;AAE3B,6CAAoD;AAGpD,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,YAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;AAE3E,IAAI,MAAc,CAAA;AAElB,QAAQ,UAAU,EAAE,CAAC;IACnB,KAAK,OAAO;QACV,MAAM,WAAW,mBACf,IAAI;YACJ,IAAI,EACJ,aAAa,EAAE,KAAK,CAAC,EAAE;gBACrB,kBAAkB;gBAClB,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,EAAE,IAAI,CAAC,CAAA;YACnC,CAAC,IACE,OAAO,CACX,CAAA;QACD,YAAY;QACZ,iBAAA,MAAM,GAAG,IAAA,2BAAY,EAAC;YACpB,WAAW,EAAE,IAAA,2CAAsB,EAAC;gBAClC,aAAa,EAAE,IAAI,iBAAK,CAAC,WAAW,CAAC;gBACrC,eAAe,EAAE,IAAI,iBAAK,CAAC,WAAW,CAAC;aACxC,CAAC;SACH,CAAC,CAAA;QACF,MAAK;IACP,KAAK,cAAc;QACjB,MAAM,OAAO,GAAG,IAAI,iBAAK,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACjD,YAAY;QACZ,iBAAA,MAAM,GAAG,IAAA,2BAAY,EAAC;YACpB,WAAW,EA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ribe) mechanism for handling messages and events.\n * Developers can use various middleware options such as Redis, Redis Cluster\n * to implement Pub/Sub functionality.\n */\n\nimport { createPubSub } from 'graphql-yoga'\nimport { createRedisEventTarget } from '@graphql-yoga/redis-event-target'\nimport Redis from 'ioredis'\n\nimport { config, logger } from '@things-factory/env'\nimport { PubSub } from 'type-graphql'\n\nconst { middleware, host, port, nodes, options } = config.get('pubsub', {})\n\nlet pubsub: PubSub\n\nswitch (middleware) {\n case 'redis':\n const redisOption = {\n host,\n port,\n retryStrategy: times => {\n // reconnect after\n return Math.min(times * 50, 2000)\n },\n ...options\n }\n //@ts-ignore\n pubsub = createPubSub({\n eventTarget: createRedisEventTarget({\n publishClient: new Redis(redisOption),\n subscribeClient: new Redis(redisOption)\n })\n })\n break\n case 'redisCluster':\n const cluster = new Redis.Cluster(nodes, options)\n //@ts-ignore\n pubsub = createPubSub({\n eventTarget: createRedisEventTarget({\n publishClient: cluster,\n subscribeClient: cluster\n })\n })\n break\n default:\n pubsub = createPubSub()\n break\n}\n\n// kafka pubsub keeps connection and app port with 'ctrl+c' termination.\nconst exitHandler = async evt => {\n //@ts-ignore\n if (pubsub.close) {\n try {\n //@ts-ignore\n await pubsub.close()\n } catch (err) {\n logger.error(err)\n }\n }\n}\n\n/*\n * exit events hint from https://stackoverflow.com/a/14032965/14539284\n */\n\n//do something when app is closing\nprocess.on('exit', exitHandler.bind(null, { name: 'exit', exit: true }))\n\n//catches ctrl+c event\nprocess.on('SIGINT', exitHandler.bind(null, { name: 'SIGINT', exit: true }))\n\n// catches \"kill pid\" (for example: nodemon restart)\nprocess.on('SIGUSR1', exitHandler.bind(null, { name: 'SIGUSR1', exit: true }))\nprocess.on('SIGUSR2', exitHandler.bind(null, { name: 'SIGUSR2', exit: true }))\n\n//catches uncaught exceptions\n// process.on('uncaughtException', exitHandler.bind(null, { name: 'uncaughtException', exit: true }))\n\nexport { pubsub }\n"]}
|