corebasic 1.0.86 → 1.0.88
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/libs/features.js +16 -1
- package/libs/messaging.js +27 -1
- package/package.json +1 -1
package/libs/features.js
CHANGED
|
@@ -12,8 +12,11 @@ const getFeatureMethod = api => api.split(' ')[0].toLowerCase()
|
|
|
12
12
|
const getFeatureUrl = api => api.split(' ')[1]
|
|
13
13
|
const getFeature = name => features[name]
|
|
14
14
|
|
|
15
|
+
let SLYP_FEATURES_LIST = {}
|
|
16
|
+
|
|
15
17
|
export const send = async (feature, params, payload, headers) => {
|
|
16
|
-
|
|
18
|
+
const throwError = () => {throw {message: `Feature ${feature} not found in internal or external list during inter feature call`}}
|
|
19
|
+
let {api} = getFeature(feature) ?? SLYP_FEATURES_LIST[feature] ?? throwError()
|
|
17
20
|
let method = getFeatureMethod(api)
|
|
18
21
|
let url = getFeatureUrl(api)
|
|
19
22
|
|
|
@@ -29,9 +32,21 @@ export const send = async (feature, params, payload, headers) => {
|
|
|
29
32
|
return (await axios[method](`http://127.0.0.1:3000${url}`, { data: payload, headers: {jwt: headers.jwt}, timeout: 1000 })).data
|
|
30
33
|
}
|
|
31
34
|
|
|
35
|
+
async function exportAllFeatures() {
|
|
36
|
+
let exp_features = {}
|
|
37
|
+
for (let [key, {api}] of Object.entries(features))
|
|
38
|
+
exp_features[key] = {api}
|
|
39
|
+
|
|
40
|
+
await Messaging.subscribe("SLYP_FEATURES_LIST", (message, channel) => {
|
|
41
|
+
SLYP_FEATURES_LIST = {...SLYP_FEATURES_LIST, ...JSON.parse(message)}
|
|
42
|
+
console.log('Incoming message in channel', channel, JSON.parse(message))
|
|
43
|
+
})
|
|
44
|
+
await Messaging.produce("SLYP_FEATURES_LIST", JSON.stringify(exp_features))
|
|
45
|
+
}
|
|
32
46
|
|
|
33
47
|
export const start = async (app, url, file) => {
|
|
34
48
|
features = await Utils.fileToJson(url, file)
|
|
49
|
+
await exportAllFeatures()
|
|
35
50
|
|
|
36
51
|
|
|
37
52
|
// Registering handlers
|
package/libs/messaging.js
CHANGED
|
@@ -3,6 +3,8 @@ import axios from 'axios'
|
|
|
3
3
|
import { createClient } from 'redis';
|
|
4
4
|
import * as Utils from './utils.js'
|
|
5
5
|
|
|
6
|
+
const url = process.env.REDIS_URL || "redis://localhost:6380"
|
|
7
|
+
|
|
6
8
|
// url: 'redis://alice:foobared@localhost:6380'
|
|
7
9
|
let consumer, publisher
|
|
8
10
|
|
|
@@ -49,7 +51,6 @@ async function connect({user,req,res, uid}) {
|
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
export async function start(app) {
|
|
52
|
-
const url = process.env.REDIS_URL || "redis://localhost:6380"
|
|
53
54
|
consumer = createClient({ url });
|
|
54
55
|
await consumer.connect();
|
|
55
56
|
publisher = createClient({ url });
|
|
@@ -78,6 +79,31 @@ export async function publish(channel, message) {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
|
|
82
|
+
// Generic Functions
|
|
83
|
+
// -----------------
|
|
84
|
+
|
|
85
|
+
export async function newConsumer() {
|
|
86
|
+
let consumer = createClient({ url })
|
|
87
|
+
await consumer.connect()
|
|
88
|
+
return consumer
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function newProducer() {
|
|
92
|
+
let publisher = createClient({ url })
|
|
93
|
+
await publisher.connect()
|
|
94
|
+
return publisher
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function subscribe(channel, listener) {
|
|
98
|
+
let consumer = await newConsumer()
|
|
99
|
+
await consumer.subscribe(channel, listener)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
export async function produce(channel, message) {
|
|
104
|
+
let producer = await newProducer()
|
|
105
|
+
await producer.publish(channel, message)
|
|
106
|
+
}
|
|
81
107
|
|
|
82
108
|
|
|
83
109
|
|