eip-cloud-services 1.1.7 → 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 +3 -2
- package/src/redis.js +37 -0
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": {
|
|
@@ -23,4 +24,4 @@
|
|
|
23
24
|
"mysql": "^2.18.1",
|
|
24
25
|
"redis": "^4.6.7"
|
|
25
26
|
}
|
|
26
|
-
}
|
|
27
|
+
}
|
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;
|
|
@@ -714,6 +722,35 @@ exports.subscribe = async ( channel, messageHandler ) => {
|
|
|
714
722
|
}
|
|
715
723
|
};
|
|
716
724
|
|
|
725
|
+
/**
|
|
726
|
+
* Unsubscribes from a channel.
|
|
727
|
+
* @param {string} channel - The channel to unsubscribe from.
|
|
728
|
+
* @returns {Promise<void>} - A promise that resolves when the unsubscribe is complete.
|
|
729
|
+
*
|
|
730
|
+
* @description This method unsubscribes from the specified channel in Redis for incoming messages.
|
|
731
|
+
*/
|
|
732
|
+
exports.unsubscribe = async ( channel ) => {
|
|
733
|
+
try {
|
|
734
|
+
if ( typeof channel === 'string' ) {
|
|
735
|
+
const client = await getClient ( `${channel}_sub` );
|
|
736
|
+
|
|
737
|
+
client.removeAllListeners ( 'message' );
|
|
738
|
+
|
|
739
|
+
await client.unsubscribe ( channel );
|
|
740
|
+
await deleteClient ( `${channel}_sub` );
|
|
741
|
+
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
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 );
|
|
750
|
+
throw error;
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
|
|
717
754
|
/**
|
|
718
755
|
* Retrieves information and statistics about the Redis server.
|
|
719
756
|
* @returns {Promise<string>} - A promise that resolves with server information.
|