@mimik/rediser 1.5.2 → 2.0.0

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ## rediser
4
4
  **Example**
5
5
  ```js
6
- const redis = require('@mimik/rediser');
6
+ import redis from '@mimik/rediser';
7
7
  ```
8
8
 
9
9
  * [rediser](#module_rediser)
@@ -0,0 +1,63 @@
1
+ import importPlugin from 'eslint-plugin-import';
2
+ import js from '@eslint/js';
3
+ import processDoc from '@mimik/eslint-plugin-document-env';
4
+ import stylistic from '@stylistic/eslint-plugin';
5
+
6
+ const MAX_LENGTH_LINE = 180;
7
+ const MAX_FUNCTION_PARAMETERS = 6;
8
+ const MAX_LINES_IN_FILES = 600;
9
+ const MAX_LINES_IN_FUNCTION = 150;
10
+ const MAX_STATEMENTS_IN_FUNCTION = 45;
11
+ const MIN_KEYS_IN_OBJECT = 10;
12
+ const MAX_COMPLEXITY = 30;
13
+
14
+ export default [
15
+ {
16
+ ignores: ['mochawesome-report/**', 'node_modules/**', 'dist/**'],
17
+ },
18
+ importPlugin.flatConfigs.recommended,
19
+ stylistic.configs['recommended-flat'],
20
+ js.configs.all,
21
+ {
22
+ plugins: {
23
+ processDoc,
24
+ },
25
+ languageOptions: {
26
+ ecmaVersion: 2022,
27
+ globals: {
28
+ console: 'readonly',
29
+ describe: 'readonly',
30
+ it: 'readonly',
31
+ require: 'readonly',
32
+ },
33
+ sourceType: 'module',
34
+ },
35
+ rules: {
36
+ '@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
37
+ '@stylistic/line-comment-position': ['off'],
38
+ '@stylistic/semi': ['error', 'always'],
39
+ 'capitalized-comments': ['off'],
40
+ 'complexity': ['error', MAX_COMPLEXITY],
41
+ 'curly': ['off'],
42
+ 'id-length': ['error', { exceptions: ['x', 'y', 'z', 'i', 'j', 'k'] }],
43
+ 'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
44
+ 'import/no-unresolved': ['error', { amd: true, caseSensitiveStrict: true, commonjs: true }],
45
+ 'init-declarations': ['off'],
46
+ 'linebreak-style': ['off'],
47
+ 'max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true }],
48
+ 'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true }],
49
+ 'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true }],
50
+ 'max-params': ['error', MAX_FUNCTION_PARAMETERS],
51
+ 'max-statements': ['warn', MAX_STATEMENTS_IN_FUNCTION],
52
+ 'no-confusing-arrow': ['off'], // arrow isnt confusing
53
+ 'no-inline-comments': ['off'],
54
+ 'no-process-env': ['error'],
55
+ 'no-ternary': ['off'],
56
+ 'no-undefined': ['off'],
57
+ 'one-var': ['error', 'never'],
58
+ 'processDoc/validate-document-env': ['error'],
59
+ 'quotes': ['warn', 'single'],
60
+ 'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false }],
61
+ },
62
+ },
63
+ ];
package/index.js CHANGED
@@ -1,11 +1,18 @@
1
- const logger = require('@mimik/sumologic-winston-logger');
2
- const { isProd, MASK } = require('@mimik/lib-filters');
3
- const redis = require('redis');
4
- const Promise = require('bluebird');
1
+ import {
2
+ MASK,
3
+ isProd,
4
+ } from '@mimik/lib-filters';
5
+ import {
6
+ clearInterval,
7
+ setInterval,
8
+ } from 'timers';
9
+ import Promise from 'bluebird';
10
+ import logger from '@mimik/sumologic-winston-logger';
11
+ import redis from 'redis';
5
12
  /**
6
13
  * @module rediser
7
14
  * @example
8
- * const redis = require('@mimik/rediser');
15
+ * import redis from '@mimik/rediser';
9
16
  */
10
17
 
11
18
  const type = 'redis';
@@ -13,13 +20,16 @@ const correlationId = `${type}-cache-start@0/${new Date().toISOString()}`;
13
20
 
14
21
  const CONNECTED = 1;
15
22
  const DISCONNECTED = 2;
23
+ const FIRST = 0;
24
+ const ISSUE_EXIT = 1;
25
+ const MILLI_SEC = 1000;
16
26
 
17
27
  let displayCreate = true;
18
28
  let displayDisconnect = true;
19
29
  let state = DISCONNECTED;
20
30
  let clusterConnectInterval;
21
31
 
22
- module.exports = (set, config) => {
32
+ export default (set, config) => {
23
33
  const { redisSettings } = config;
24
34
  /**
25
35
  * Database initialization.
@@ -43,20 +53,20 @@ module.exports = (set, config) => {
43
53
  state = DISCONNECTED;
44
54
  if (!interval) {
45
55
  interval = setInterval(() => {
46
- if (state !== CONNECTED) {
56
+ if (state === CONNECTED) {
57
+ clearInterval(interval);
58
+ interval = null;
59
+ }
60
+ else {
47
61
  if (displayDisconnect) {
48
62
  logger.error('fatal error: Timeout in connecting to cache', {
49
63
  type, error: state, timeout: redisSettings.connectTimeout,
50
64
  }, correlationId);
51
65
  displayDisconnect = false;
52
66
  }
53
- logger.flushAndExit(1);
67
+ logger.flushAndExit(ISSUE_EXIT);
54
68
  }
55
- else {
56
- clearInterval(interval);
57
- interval = null;
58
- }
59
- }, config.redisSettings.connectTimeout * 1000); // convert in seconds
69
+ }, config.redisSettings.connectTimeout * MILLI_SEC); // convert in seconds
60
70
  }
61
71
  };
62
72
 
@@ -64,7 +74,7 @@ module.exports = (set, config) => {
64
74
  if (isProd(config.nodeEnvironment)) {
65
75
  const redisSettingsClone = { ...redisSettings };
66
76
 
67
- if (redisSettings.password) redisSettingsClone.url = `${redisSettings.url.split('=')[0]}=${MASK}`;
77
+ if (redisSettings.password) redisSettingsClone.url = `${redisSettings.url.split('=')[FIRST]}=${MASK}`;
68
78
  logger.info('creating a cache connection', { type, settings: redisSettingsClone }, correlationId);
69
79
  }
70
80
  else logger.info('creating a cache connection', { type, settings: redisSettings }, correlationId);
@@ -74,7 +84,7 @@ module.exports = (set, config) => {
74
84
  const isClusterEnabled = redisSettings.cluster.set === 'on';
75
85
  if (isClusterEnabled) {
76
86
  const clusterConfig = {
77
- rootNodes: redisSettings.domain.split(',').map((url) => ({ url: `redis://${url}` })),
87
+ rootNodes: redisSettings.domain.split(',').map(url => ({ url: `redis://${url}` })),
78
88
  useReplicas: redisSettings.cluster.useReplicas === 'on',
79
89
  minimizeConnections: redisSettings.cluster.minimizeConnections === 'on',
80
90
  };
@@ -103,11 +113,17 @@ module.exports = (set, config) => {
103
113
  .on('end', () => disconnectHandler)
104
114
  .connect();
105
115
 
116
+ // eslint-disable-next-line no-warning-comments
106
117
  // Todo: remove this if block, when redis library has events implemented for cluster connections
107
118
  if (!clusterConnectInterval && isClusterEnabled) {
108
119
  const connectionTestKey = 'b7ddc6b6-57a8-4cde-80a1-c6a8f174f386';
120
+
109
121
  clusterConnectInterval = setInterval(() => {
110
- if (state !== CONNECTED) {
122
+ if (state === CONNECTED) {
123
+ clearInterval(clusterConnectInterval);
124
+ clusterConnectInterval = null;
125
+ }
126
+ else {
111
127
  client.set('connectionTestKey', connectionTestKey)
112
128
  .then(() => client.get('connectionTestKey'))
113
129
  .then((value) => {
@@ -117,10 +133,6 @@ module.exports = (set, config) => {
117
133
  logger.error('connection not ready yet', { error }, correlationId);
118
134
  });
119
135
  }
120
- else {
121
- clearInterval(clusterConnectInterval);
122
- clusterConnectInterval = null;
123
- }
124
136
  }, redisSettings.validationCheck);
125
137
  }
126
138
  return client;
@@ -147,9 +159,9 @@ module.exports = (set, config) => {
147
159
  logger.error('fatal error: Timeout in connecting to cache', {
148
160
  type, error: state, timeout: redisSettings.connectTimeout,
149
161
  }, correlationId);
150
- logger.flushAndExit(1);
162
+ logger.flushAndExit(ISSUE_EXIT);
151
163
  }
152
- }, config.redisSettings.connectTimeout * 1000); // convert in seconds
164
+ }, config.redisSettings.connectTimeout * MILLI_SEC); // convert in seconds
153
165
 
154
166
  return Promise.delay(redisSettings.validationCheck)
155
167
  .then(() => {
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@mimik/rediser",
3
- "version": "1.5.2",
3
+ "version": "2.0.0",
4
4
  "description": "Helper for setting up redis using redis for mimik microservices",
5
- "main": "index.js",
5
+ "main": "./index.js",
6
+ "type": "module",
6
7
  "scripts": {
7
- "lint": "eslint --ignore-path .gitignore .",
8
+ "lint": "eslint . --no-error-on-unmatched-pattern",
8
9
  "docs": "jsdoc2md index.js > README.md",
9
10
  "test": "echo \"Error: no test specified\" && exit 0",
10
11
  "test-ci": "echo \"Error: no test specified\" && exit 0",
11
12
  "prepublishOnly": "npm run docs && npm run lint && npm run test-ci",
12
- "commit-ready": "npm run docs && npm run lint && npm run test-ci",
13
- "prepare": "husky install"
13
+ "commit-ready": "npm run docs && npm run lint && npm run test-ci"
14
14
  },
15
15
  "husky": {
16
16
  "hooks": {
@@ -29,21 +29,18 @@
29
29
  "url": "https://bitbucket.org/mimiktech/rediser"
30
30
  },
31
31
  "dependencies": {
32
- "@mimik/lib-filters": "^1.4.8",
33
- "@mimik/sumologic-winston-logger": "^1.6.19",
32
+ "@mimik/lib-filters": "^2.0.1",
33
+ "@mimik/sumologic-winston-logger": "^2.0.1",
34
34
  "bluebird": "3.7.2",
35
- "redis": "4.6.10"
35
+ "redis": "4.7.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@mimik/eslint-plugin-dependencies": "^2.4.5",
39
- "@mimik/eslint-plugin-document-env": "^1.0.5",
40
- "eslint": "8.50.0",
41
- "eslint-config-airbnb": "19.0.4",
42
- "eslint-plugin-import": "2.28.1",
43
- "eslint-plugin-jsx-a11y": "6.7.1",
44
- "eslint-plugin-react": "7.33.2",
45
- "eslint-plugin-react-hooks": "4.6.0",
46
- "husky": "8.0.3",
47
- "jsdoc-to-markdown": "8.0.0"
38
+ "@eslint/js": "9.22.0",
39
+ "@mimik/eslint-plugin-document-env": "^2.0.2",
40
+ "@stylistic/eslint-plugin": "4.2.0",
41
+ "eslint": "9.22.0",
42
+ "eslint-plugin-import": "2.31.0",
43
+ "husky": "9.1.7",
44
+ "jsdoc-to-markdown": "9.1.1"
48
45
  }
49
46
  }
package/.eslintrc DELETED
@@ -1,43 +0,0 @@
1
- {
2
- "plugins": [
3
- "@mimik/document-env",
4
- "@mimik/dependencies"
5
- ],
6
- "env": {
7
- "node": true
8
- },
9
- "parserOptions": {
10
- "ecmaVersion": 2020
11
- },
12
- "extends": "airbnb",
13
- "rules": {
14
- "import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
15
- "import/no-unresolved": ["error", { "amd": true, "commonjs": true, "caseSensitiveStrict": true }],
16
- "brace-style": [1, "stroustrup", { "allowSingleLine": true }],
17
- "no-confusing-arrow": [0], // arrow isnt confusing
18
- "max-len": [1, 180, { "ignoreComments": true }],
19
- "linebreak-style": 0,
20
- "quotes": [1, "single"],
21
- "semi": [1, "always"],
22
- "no-process-env": ["error"],
23
- "@mimik/document-env/validate-document-env": 2,
24
- "@mimik/dependencies/case-sensitive": 2,
25
- "@mimik/dependencies/no-cycles": 2,
26
- "@mimik/dependencies/require-json-ext": 2
27
- },
28
- "settings":{
29
- "react": {
30
- "version": "detect"
31
- }
32
- },
33
- "globals": {
34
- "module": true,
35
- "require": true,
36
- "const": false,
37
- "it": false,
38
- "describe": false,
39
- "before": true,
40
- "after": true,
41
- "JSON": true
42
- }
43
- }