eip-cloud-services 1.1.8 → 1.1.9
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/eslint.config.js +51 -0
- package/package.json +2 -1
- package/src/redis.js +20 -9
package/eslint.config.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module.exports = [ {
|
|
2
|
+
languageOptions: {
|
|
3
|
+
ecmaVersion: 2021,
|
|
4
|
+
sourceType: 'module',
|
|
5
|
+
parserOptions: {
|
|
6
|
+
ecmaFeatures: {
|
|
7
|
+
jsx: true
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
rules: {
|
|
12
|
+
'max-len': 'off',
|
|
13
|
+
'semi': [ 'error', 'always' ],
|
|
14
|
+
'no-underscore-dangle': 'off',
|
|
15
|
+
'class-methods-use-this': 'off',
|
|
16
|
+
'no-param-reassign': 'off',
|
|
17
|
+
'no-restricted-syntax': 'warn',
|
|
18
|
+
'no-continue': 'warn',
|
|
19
|
+
'consistent-return': 'warn',
|
|
20
|
+
'guard-for-in': 'warn',
|
|
21
|
+
'import/no-commonjs': 'off',
|
|
22
|
+
'import/no-dynamic-require': 'off',
|
|
23
|
+
'new-cap': 'warn',
|
|
24
|
+
'no-nested-ternary': 'off',
|
|
25
|
+
'prefer-const': 'error',
|
|
26
|
+
'newline-before-return': [ 'error', 'always' ],
|
|
27
|
+
'quotes': [ 'error', 'single' ],
|
|
28
|
+
'no-multiple-empty-lines': [ 'error', { max: 1 } ],
|
|
29
|
+
'space-before-function-paren': [ 'error', 'always' ],
|
|
30
|
+
'func-call-spacing': [ 'error', 'always' ],
|
|
31
|
+
'block-spacing': [ 'error', 'always' ],
|
|
32
|
+
'space-in-parens': [ 'error', 'always' ],
|
|
33
|
+
'object-curly-spacing': [ 'error', 'always' ],
|
|
34
|
+
'no-spaced-func': 'off',
|
|
35
|
+
'space-unary-ops': [ 'error', { 'words': true, 'nonwords': false, 'overrides': { 'new': false, '++': false } } ],
|
|
36
|
+
'arrow-spacing': [ 'error', { 'before': true, 'after': true } ],
|
|
37
|
+
'indent': [ 'error', 4, { 'SwitchCase': 1 } ],
|
|
38
|
+
'key-spacing': [ 'error', { 'beforeColon': false, 'afterColon': true } ],
|
|
39
|
+
'computed-property-spacing': [ 'error', 'always' ],
|
|
40
|
+
'array-bracket-spacing': [ 'error', 'never' ],
|
|
41
|
+
'comma-spacing': [ 'error', { 'before': false, 'after': true } ],
|
|
42
|
+
'brace-style': [ 'error', 'stroustrup' ],
|
|
43
|
+
'space-infix-ops': 'error',
|
|
44
|
+
'keyword-spacing': [ 'error', { overrides: {
|
|
45
|
+
if: { after: true },
|
|
46
|
+
for: { after: true },
|
|
47
|
+
while: { after: true }
|
|
48
|
+
} } ],
|
|
49
|
+
'array-bracket-spacing': [ 'error', 'always' ],
|
|
50
|
+
},
|
|
51
|
+
} ];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eip-cloud-services",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Houses a collection of helpers for connecting with Cloud services.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"chai": "^4.3.7",
|
|
13
|
+
"eslint": "^9.1.1",
|
|
13
14
|
"mocha": "^10.2.0"
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
package/src/redis.js
CHANGED
|
@@ -78,6 +78,13 @@ const getClient = async ( clientId = 'main' ) => {
|
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
+
const deleteClient = async ( clientId ) => {
|
|
82
|
+
if ( clients[ clientId ] ){
|
|
83
|
+
await clients[ clientId ].quit ();
|
|
84
|
+
delete clients[ clientId ];
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
81
88
|
/**
|
|
82
89
|
* Retrieves a Redis client based on the provided identifier.
|
|
83
90
|
* This function is primarily used internally within the module.
|
|
@@ -700,6 +707,7 @@ exports.subscribe = async ( channel, messageHandler ) => {
|
|
|
700
707
|
messageHandler ( message );
|
|
701
708
|
}
|
|
702
709
|
} );
|
|
710
|
+
|
|
703
711
|
await client.subscribe ( channel );
|
|
704
712
|
|
|
705
713
|
return;
|
|
@@ -721,21 +729,24 @@ exports.subscribe = async ( channel, messageHandler ) => {
|
|
|
721
729
|
*
|
|
722
730
|
* @description This method unsubscribes from the specified channel in Redis for incoming messages.
|
|
723
731
|
*/
|
|
724
|
-
exports.unsubscribe = async (channel) => {
|
|
732
|
+
exports.unsubscribe = async ( channel ) => {
|
|
725
733
|
try {
|
|
726
|
-
if (typeof channel === 'string') {
|
|
727
|
-
const client = await getClient(`${channel}_sub`);
|
|
734
|
+
if ( typeof channel === 'string' ) {
|
|
735
|
+
const client = await getClient ( `${channel}_sub` );
|
|
728
736
|
|
|
729
|
-
client.removeAllListeners('message');
|
|
737
|
+
client.removeAllListeners ( 'message' );
|
|
730
738
|
|
|
731
|
-
await client.unsubscribe(channel);
|
|
739
|
+
await client.unsubscribe ( channel );
|
|
740
|
+
await deleteClient ( `${channel}_sub` );
|
|
732
741
|
|
|
733
742
|
return;
|
|
734
|
-
} else {
|
|
735
|
-
throw new Error('redis.unsubscribe expects a string channel and a function as handler');
|
|
736
743
|
}
|
|
737
|
-
|
|
738
|
-
|
|
744
|
+
else {
|
|
745
|
+
throw new Error ( 'redis.unsubscribe expects a string channel and a function as handler' );
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
catch ( error ) {
|
|
749
|
+
console.error ( 'REDIS LIB ERROR [unsubscribe]', error );
|
|
739
750
|
throw error;
|
|
740
751
|
}
|
|
741
752
|
};
|