@mimik/mongooser 2.1.0 → 3.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 +1 -1
- package/eslint.config.js +63 -0
- package/index.js +24 -15
- package/package.json +16 -19
- package/.eslintrc +0 -44
package/README.md
CHANGED
package/eslint.config.js
ADDED
|
@@ -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,15 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import {
|
|
2
|
+
MASK,
|
|
3
|
+
isProd,
|
|
4
|
+
} from '@mimik/lib-filters';
|
|
5
|
+
import {
|
|
6
|
+
clearInterval,
|
|
7
|
+
setInterval,
|
|
8
|
+
} from 'timers';
|
|
9
|
+
import Buffer from 'buffer';
|
|
10
|
+
import Promise from 'bluebird';
|
|
11
|
+
import { getCorrelationId } from '@mimik/request-helper';
|
|
12
|
+
import logger from '@mimik/sumologic-winston-logger';
|
|
13
|
+
import mongoose from 'mongoose';
|
|
14
|
+
import replace from 'lodash.replace';
|
|
8
15
|
|
|
9
16
|
/**
|
|
10
17
|
* @module mongooser
|
|
11
18
|
* @example
|
|
12
|
-
*
|
|
19
|
+
* import mongodb from '@mimik/mongooser';
|
|
13
20
|
*/
|
|
14
21
|
|
|
15
22
|
const type = 'mongo';
|
|
@@ -19,10 +26,12 @@ const DISCONNECTED = 0;
|
|
|
19
26
|
const CONNECTED = 1;
|
|
20
27
|
const CONNECTING = 2;
|
|
21
28
|
const DISCONNECTING = 3;
|
|
29
|
+
const ISSUE_EXIT = 1;
|
|
30
|
+
const MILLI_SEC = 1000;
|
|
22
31
|
|
|
23
32
|
let fatal = false;
|
|
24
33
|
|
|
25
|
-
|
|
34
|
+
export default (config) => {
|
|
26
35
|
const { mongoSettings, encryption } = config;
|
|
27
36
|
const { options } = mongoSettings;
|
|
28
37
|
|
|
@@ -95,7 +104,7 @@ module.exports = (config) => {
|
|
|
95
104
|
fatal = true;
|
|
96
105
|
logger.error('Fatal error: Could not connect to database', { type, error }, correlationId);
|
|
97
106
|
if (interval) clearInterval(interval);
|
|
98
|
-
logger.flushAndExit(
|
|
107
|
+
logger.flushAndExit(ISSUE_EXIT);
|
|
99
108
|
});
|
|
100
109
|
}
|
|
101
110
|
|
|
@@ -107,9 +116,9 @@ module.exports = (config) => {
|
|
|
107
116
|
fatal = true;
|
|
108
117
|
logger.error('Fatal error: Could not connect to database', { type, error: state }, correlationId);
|
|
109
118
|
clearInterval(interval);
|
|
110
|
-
logger.flushAndExit(
|
|
119
|
+
logger.flushAndExit(ISSUE_EXIT);
|
|
111
120
|
}
|
|
112
|
-
}, (options.heartbeatFrequencyMS + (mongoSettings.reconnectOffset *
|
|
121
|
+
}, (options.heartbeatFrequencyMS + (mongoSettings.reconnectOffset * MILLI_SEC)));
|
|
113
122
|
});
|
|
114
123
|
mongoose.connection.on('connected', () => {
|
|
115
124
|
if (interval) clearInterval(interval);
|
|
@@ -141,9 +150,9 @@ module.exports = (config) => {
|
|
|
141
150
|
type, error: state, timeout: mongoSettings.connectTimeout,
|
|
142
151
|
}, correlationId);
|
|
143
152
|
clearInterval(interval);
|
|
144
|
-
logger.flushAndExit(
|
|
153
|
+
logger.flushAndExit(ISSUE_EXIT);
|
|
145
154
|
}
|
|
146
|
-
}, mongoSettings.connectTimeout *
|
|
155
|
+
}, mongoSettings.connectTimeout * MILLI_SEC); // convert in seconds
|
|
147
156
|
|
|
148
157
|
return Promise.delay(mongoSettings.validationCheck).then(() => {
|
|
149
158
|
const state = mongoose.connection.readyState;
|
|
@@ -172,7 +181,7 @@ module.exports = (config) => {
|
|
|
172
181
|
* @return {boolean} `True` if replica is set, `False` if not.
|
|
173
182
|
*/
|
|
174
183
|
const replicat = () => {
|
|
175
|
-
const isReplicaSet =
|
|
184
|
+
const isReplicaSet = Boolean(mongoose.connection.client.s.options.replicaSet);
|
|
176
185
|
return isReplicaSet;
|
|
177
186
|
};
|
|
178
187
|
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/mongooser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Helper for setting up mongodb using mongoose for mimik microservices",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"engines": {
|
|
7
8
|
"node": ">=12.0.0"
|
|
8
9
|
},
|
|
9
10
|
"scripts": {
|
|
10
|
-
"lint": "eslint --
|
|
11
|
+
"lint": "eslint . --no-error-on-unmatched-pattern",
|
|
11
12
|
"docs": "jsdoc2md index.js > README.md",
|
|
12
13
|
"test": "echo \"Error: no test specified\" && exit 0",
|
|
13
14
|
"test-ci": "echo \"Error: no test specified\" && exit 0",
|
|
14
15
|
"prepublishOnly": "npm run docs && npm run lint && npm run test-ci",
|
|
15
|
-
"commit-ready": "npm run docs && npm run lint && npm run test-ci"
|
|
16
|
-
"prepare": "husky"
|
|
16
|
+
"commit-ready": "npm run docs && npm run lint && npm run test-ci"
|
|
17
17
|
},
|
|
18
18
|
"husky": {
|
|
19
19
|
"hooks": {
|
|
@@ -32,23 +32,20 @@
|
|
|
32
32
|
"url": "https://bitbucket.org/mimiktech/mongooser"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@mimik/lib-filters": "^
|
|
36
|
-
"@mimik/request-helper": "^
|
|
37
|
-
"@mimik/sumologic-winston-logger": "^
|
|
35
|
+
"@mimik/lib-filters": "^2.0.1",
|
|
36
|
+
"@mimik/request-helper": "^2.0.0",
|
|
37
|
+
"@mimik/sumologic-winston-logger": "^2.0.1",
|
|
38
38
|
"bluebird": "3.7.2",
|
|
39
39
|
"lodash.replace": "4.1.4",
|
|
40
|
-
"mongoose": "8.
|
|
40
|
+
"mongoose": "8.12.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@
|
|
44
|
-
"@mimik/eslint-plugin-document-env": "^
|
|
45
|
-
"eslint": "
|
|
46
|
-
"eslint
|
|
47
|
-
"eslint-plugin-import": "2.
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"eslint-plugin-react-hooks": "4.6.2",
|
|
51
|
-
"husky": "9.1.2",
|
|
52
|
-
"jsdoc-to-markdown": "8.0.3"
|
|
43
|
+
"@eslint/js": "9.22.0",
|
|
44
|
+
"@mimik/eslint-plugin-document-env": "^2.0.2",
|
|
45
|
+
"@stylistic/eslint-plugin": "4.2.0",
|
|
46
|
+
"eslint": "9.22.0",
|
|
47
|
+
"eslint-plugin-import": "2.31.0",
|
|
48
|
+
"husky": "9.1.7",
|
|
49
|
+
"jsdoc-to-markdown": "9.1.1"
|
|
53
50
|
}
|
|
54
51
|
}
|
package/.eslintrc
DELETED
|
@@ -1,44 +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/no-unresolved": 2,
|
|
27
|
-
"@mimik/dependencies/require-json-ext": 2
|
|
28
|
-
},
|
|
29
|
-
"settings":{
|
|
30
|
-
"react": {
|
|
31
|
-
"version": "detect"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"globals": {
|
|
35
|
-
"module": true,
|
|
36
|
-
"require": true,
|
|
37
|
-
"const": false,
|
|
38
|
-
"it": false,
|
|
39
|
-
"describe": false,
|
|
40
|
-
"before": true,
|
|
41
|
-
"after": true,
|
|
42
|
-
"JSON": true
|
|
43
|
-
}
|
|
44
|
-
}
|