woonplan-packages-redishelper 1.0.41 → 1.0.42
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/dist/getters.d.ts +3 -1
- package/dist/getters.js +28 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/types.d.ts +3 -0
- package/getters.ts +43 -2
- package/index.ts +2 -2
- package/package.json +1 -1
- package/types.ts +4 -0
package/dist/getters.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Redis } from "ioredis";
|
|
2
|
+
import { Struct } from "./types";
|
|
2
3
|
declare const getOrRequestKey: (client: Redis, key: string, service: string) => Promise<unknown>;
|
|
4
|
+
declare const requestAndWaitForData: (client: Redis, data: Struct, service: string) => Promise<unknown>;
|
|
3
5
|
declare const subscribeToMessageResponse: (client: Redis, messageid: string, timeout: number) => void;
|
|
4
6
|
declare const requestAndWaitForList: (client: Redis, service: string, listname: string, listsubject: string, props: {} | undefined, {}: {}) => Promise<unknown>;
|
|
5
|
-
export { getOrRequestKey, requestAndWaitForList, subscribeToMessageResponse };
|
|
7
|
+
export { getOrRequestKey, requestAndWaitForList, subscribeToMessageResponse, requestAndWaitForData };
|
package/dist/getters.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.subscribeToMessageResponse = exports.requestAndWaitForList = exports.getOrRequestKey = void 0;
|
|
3
|
+
exports.requestAndWaitForData = exports.subscribeToMessageResponse = exports.requestAndWaitForList = exports.getOrRequestKey = void 0;
|
|
4
4
|
var utils_1 = require("./utils");
|
|
5
5
|
var getOrRequestKey = function (client, key, service) { return new Promise(function (resolve, reject) {
|
|
6
6
|
client.get(key)
|
|
@@ -41,10 +41,36 @@ var requestAndWaitForKey = function (client, key, service) { return new Promise(
|
|
|
41
41
|
resolve(null);
|
|
42
42
|
});
|
|
43
43
|
}); };
|
|
44
|
+
var requestAndWaitForData = function (client, data, service) { return new Promise(function (resolve) {
|
|
45
|
+
service = capitalizeFirstLetter(service);
|
|
46
|
+
client.xadd("dataRequestedFrom".concat(service, "Service"), '*', 'data', JSON.stringify(data))
|
|
47
|
+
.then(function (messageid) {
|
|
48
|
+
// create a key to listen to, the key contains the message we just created;
|
|
49
|
+
return subscribeToMessageResponse(client, messageid, 250);
|
|
50
|
+
}).then(function () {
|
|
51
|
+
// we are subscribed
|
|
52
|
+
// setting up a one time event listener
|
|
53
|
+
client.once("message", function (channel, message) {
|
|
54
|
+
console.log("unsubscribing from ".concat(channel));
|
|
55
|
+
client.unsubscribe().then(function () {
|
|
56
|
+
if (message.length)
|
|
57
|
+
resolve(message);
|
|
58
|
+
else
|
|
59
|
+
resolve(null);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}).catch(function (e) {
|
|
63
|
+
console.log(e);
|
|
64
|
+
resolve(null);
|
|
65
|
+
});
|
|
66
|
+
}); };
|
|
67
|
+
exports.requestAndWaitForData = requestAndWaitForData;
|
|
44
68
|
var subscribeToMessageResponse = function (client, messageid, timeout) {
|
|
45
69
|
setTimeout(function () {
|
|
46
|
-
if (client.status != "end")
|
|
70
|
+
if (client.status != "end") {
|
|
47
71
|
console.log("sub ".concat(messageid, " timedout"));
|
|
72
|
+
client.disconnect();
|
|
73
|
+
}
|
|
48
74
|
}, timeout);
|
|
49
75
|
client.subscribe((0, utils_1.getMessageReponseKey)(messageid));
|
|
50
76
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Redis } from "ioredis";
|
|
2
2
|
import { RedisMessage } from "./types";
|
|
3
3
|
import { sendMessageToStream, publishMessageResponse } from "./setters";
|
|
4
|
-
import { getOrRequestKey, subscribeToMessageResponse, requestAndWaitForList } from "./getters";
|
|
4
|
+
import { getOrRequestKey, subscribeToMessageResponse, requestAndWaitForList, requestAndWaitForData } from "./getters";
|
|
5
5
|
declare const listenToStream: (client: Redis, groupname: string, channelname: string, consumername: string, callback: Function) => Promise<boolean>;
|
|
6
|
-
export { listenToStream, RedisMessage, sendMessageToStream, publishMessageResponse, getOrRequestKey, subscribeToMessageResponse, requestAndWaitForList };
|
|
6
|
+
export { listenToStream, RedisMessage, sendMessageToStream, publishMessageResponse, requestAndWaitForData, getOrRequestKey, subscribeToMessageResponse, requestAndWaitForList };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requestAndWaitForList = exports.subscribeToMessageResponse = exports.getOrRequestKey = exports.publishMessageResponse = exports.sendMessageToStream = exports.listenToStream = void 0;
|
|
3
|
+
exports.requestAndWaitForList = exports.subscribeToMessageResponse = exports.getOrRequestKey = exports.requestAndWaitForData = exports.publishMessageResponse = exports.sendMessageToStream = exports.listenToStream = void 0;
|
|
4
4
|
var setters_1 = require("./setters");
|
|
5
5
|
Object.defineProperty(exports, "sendMessageToStream", { enumerable: true, get: function () { return setters_1.sendMessageToStream; } });
|
|
6
6
|
Object.defineProperty(exports, "publishMessageResponse", { enumerable: true, get: function () { return setters_1.publishMessageResponse; } });
|
|
@@ -8,6 +8,7 @@ var getters_1 = require("./getters");
|
|
|
8
8
|
Object.defineProperty(exports, "getOrRequestKey", { enumerable: true, get: function () { return getters_1.getOrRequestKey; } });
|
|
9
9
|
Object.defineProperty(exports, "subscribeToMessageResponse", { enumerable: true, get: function () { return getters_1.subscribeToMessageResponse; } });
|
|
10
10
|
Object.defineProperty(exports, "requestAndWaitForList", { enumerable: true, get: function () { return getters_1.requestAndWaitForList; } });
|
|
11
|
+
Object.defineProperty(exports, "requestAndWaitForData", { enumerable: true, get: function () { return getters_1.requestAndWaitForData; } });
|
|
11
12
|
var listenToStream = function (client, groupname, channelname, consumername, callback) { return new Promise(function (resolve, reject) {
|
|
12
13
|
createGroup(client, groupname, channelname).then(function () {
|
|
13
14
|
listenForMessage(client, groupname, channelname, consumername, callback);
|
package/dist/types.d.ts
CHANGED
package/getters.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Redis } from "ioredis"
|
|
2
2
|
import { getMessageReponseKey } from "./utils"
|
|
3
|
+
import { Struct } from "./types"
|
|
3
4
|
const getOrRequestKey = ( client:Redis, key:string, service:string ) => new Promise((resolve, reject) => {
|
|
4
5
|
client.get( key )
|
|
5
6
|
.then(
|
|
@@ -58,10 +59,50 @@ const requestAndWaitForKey = (
|
|
|
58
59
|
)
|
|
59
60
|
})
|
|
60
61
|
|
|
62
|
+
|
|
63
|
+
const requestAndWaitForData = (
|
|
64
|
+
client:Redis,
|
|
65
|
+
data:Struct,
|
|
66
|
+
service:string,
|
|
67
|
+
) => new Promise((resolve) => {
|
|
68
|
+
service = capitalizeFirstLetter( service );
|
|
69
|
+
|
|
70
|
+
client.xadd( `dataRequestedFrom${service}Service`, '*', 'data', JSON.stringify( data ) )
|
|
71
|
+
.then(
|
|
72
|
+
(messageid:string) => {
|
|
73
|
+
// create a key to listen to, the key contains the message we just created;
|
|
74
|
+
return subscribeToMessageResponse( client, messageid, 250 )
|
|
75
|
+
}
|
|
76
|
+
).then(
|
|
77
|
+
() => {
|
|
78
|
+
// we are subscribed
|
|
79
|
+
// setting up a one time event listener
|
|
80
|
+
client.once( "message", ( channel, message ) => {
|
|
81
|
+
console.log( `unsubscribing from ${channel}` )
|
|
82
|
+
|
|
83
|
+
client.unsubscribe().then(
|
|
84
|
+
() => {
|
|
85
|
+
if( message.length ) resolve( message );
|
|
86
|
+
else resolve( null )
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
).catch(
|
|
93
|
+
(e) => {
|
|
94
|
+
console.log( e )
|
|
95
|
+
resolve( null )
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
})
|
|
99
|
+
|
|
61
100
|
const subscribeToMessageResponse = ( client:Redis, messageid:string, timeout:number ) => {
|
|
62
101
|
setTimeout( () => {
|
|
63
|
-
if( client.status != "end" )
|
|
102
|
+
if( client.status != "end" ){
|
|
64
103
|
console.log( `sub ${messageid} timedout`)
|
|
104
|
+
client.disconnect()
|
|
105
|
+
}
|
|
65
106
|
|
|
66
107
|
}, timeout )
|
|
67
108
|
client.subscribe( getMessageReponseKey( messageid ) )
|
|
@@ -89,4 +130,4 @@ const requestAndWaitForList = (
|
|
|
89
130
|
const capitalizeFirstLetter = (string:string) => string.charAt(0).toUpperCase() + string.slice(1)
|
|
90
131
|
|
|
91
132
|
|
|
92
|
-
export { getOrRequestKey, requestAndWaitForList, subscribeToMessageResponse }
|
|
133
|
+
export { getOrRequestKey, requestAndWaitForList, subscribeToMessageResponse, requestAndWaitForData }
|
package/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Redis } from "ioredis"
|
|
2
2
|
import { RedisMessage } from "./types"
|
|
3
3
|
import { sendMessageToStream, publishMessageResponse } from "./setters"
|
|
4
|
-
import { getOrRequestKey, subscribeToMessageResponse, requestAndWaitForList } from "./getters"
|
|
4
|
+
import { getOrRequestKey, subscribeToMessageResponse, requestAndWaitForList, requestAndWaitForData } from "./getters"
|
|
5
5
|
|
|
6
6
|
const listenToStream = ( client:Redis, groupname:string, channelname:string, consumername:string, callback:Function ):Promise<boolean> => new Promise((resolve,reject) => {
|
|
7
7
|
createGroup( client, groupname, channelname ).then(
|
|
@@ -79,4 +79,4 @@ const listenForMessage = ( client:Redis, groupname:string, channelname:string, c
|
|
|
79
79
|
})
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export { listenToStream, RedisMessage, sendMessageToStream, publishMessageResponse, getOrRequestKey, subscribeToMessageResponse, requestAndWaitForList }
|
|
82
|
+
export { listenToStream, RedisMessage, sendMessageToStream, publishMessageResponse, requestAndWaitForData, getOrRequestKey, subscribeToMessageResponse, requestAndWaitForList }
|
package/package.json
CHANGED