mm_mongodb 1.5.4 → 1.5.5

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.
Files changed (3) hide show
  1. package/eslint.config.js +210 -67
  2. package/index.js +24 -28
  3. package/package.json +1 -1
package/eslint.config.js CHANGED
@@ -1,68 +1,211 @@
1
- const jsdoc = require('eslint-plugin-jsdoc');
2
-
3
- module.exports = [
4
- {
5
- files: ['lib/**/*.js'],
6
- languageOptions: {
7
- ecmaVersion: 2020,
8
- sourceType: 'script'
9
- },
10
- plugins: {
11
- jsdoc: jsdoc
12
- },
13
- rules: {
14
- // JSDoc相关规则 - 设置为error级别强制要求
15
- 'jsdoc/require-jsdoc': ['error', {
16
- require: {
17
- FunctionDeclaration: true,
18
- MethodDefinition: true,
19
- ClassDeclaration: true,
20
- ArrowFunctionExpression: true
21
- }
22
- }],
23
- 'jsdoc/check-param-names': 'off',
24
- 'jsdoc/check-tag-names': 'off',
25
- 'jsdoc/check-types': 'off',
26
- 'jsdoc/require-param': 'off',
27
- 'jsdoc/require-param-description': 'off',
28
- 'jsdoc/require-returns': 'off',
29
- 'jsdoc/require-returns-description': 'off',
30
-
31
- // 基础语法规则
32
- 'no-unused-vars': ['error', { args: 'none', vars: 'all' }],
33
- 'no-console': 'warn',
34
-
35
- // 代码风格规则
36
- 'indent': ['error', 2],
37
- 'quotes': ['error', 'single'],
38
- 'semi': ['error', 'always'],
39
- 'comma-dangle': ['error', 'never'],
40
- 'no-trailing-spaces': 'error',
41
- 'eol-last': 'error',
42
- 'max-len': ['error', { code: 100 }],
43
- 'max-lines-per-function': ['error', { max: 40 }],
44
- 'complexity': ['error', 12],
45
- 'max-depth': ['error', 4],
46
- 'max-params': ['error', 4],
47
-
48
- // 命名规则
49
- 'id-length': ['error', {
50
- min: 1,
51
- max: 20,
52
- properties: 'always'
53
- }]
54
- }
55
- },
56
- {
57
- files: ['test/**/*.js'],
58
- languageOptions: {
59
- ecmaVersion: 2020,
60
- sourceType: 'script'
61
- },
62
- rules: {
63
- // 测试文件中允许使用console
64
- 'no-console': 'off',
65
- 'no-unused-vars': 'off'
66
- }
67
- }
1
+ 'use strict';
2
+
3
+ const namingConventionPlugin = require('mm_eslint');
4
+
5
+ /**
6
+ * 基于个人规则的ESLint配置
7
+ * 符合最新ESLint Flat Config格式
8
+ */
9
+
10
+ module.exports = [
11
+ {
12
+ files: ['**/*.js'],
13
+ plugins: {
14
+ 'naming-convention': namingConventionPlugin,
15
+ 'jsdoc': require('eslint-plugin-jsdoc')
16
+ },
17
+ languageOptions: {
18
+ ecmaVersion: 'latest',
19
+ sourceType: 'module',
20
+ parserOptions: {
21
+ ecmaVersion: 'latest',
22
+ sourceType: 'module'
23
+ }
24
+ },
25
+
26
+ // 命名规范规则 - 由自定义插件处理
27
+ rules: {
28
+ // 自定义命名规范插件规则(优先使用)
29
+ 'naming-convention/class-name': 'error',
30
+ 'naming-convention/function-name': 'error',
31
+ 'naming-convention/method-name': 'error',
32
+ 'naming-convention/variable-name': 'warn',
33
+ 'naming-convention/constant-name': 'error',
34
+ 'naming-convention/private-method-naming': 'warn',
35
+ 'naming-convention/private-variable-naming': 'warn',
36
+ 'naming-convention/param-name': 'warn',
37
+ 'naming-convention/property-name': 'warn',
38
+ 'naming-convention/instance-property': 'warn',
39
+
40
+ // 禁用与命名规范插件冲突的默认规则
41
+ 'camelcase': 'off',
42
+ 'id-match': 'off',
43
+ 'new-cap': 'off',
44
+ 'id-length': 'off',
45
+ 'id-denylist': 'off',
46
+ 'id-blacklist': 'off'
47
+ }
48
+ },
49
+
50
+ {
51
+ // 代码风格规则
52
+ rules: {
53
+ // 最大行长度100字符
54
+ 'max-len': ['error', {
55
+ code: 100,
56
+ ignoreComments: true,
57
+ ignoreUrls: true,
58
+ ignoreStrings: true,
59
+ ignoreTemplateLiterals: true
60
+ }],
61
+
62
+ // 缩进2空格
63
+ 'indent': ['error', 2, {
64
+ SwitchCase: 1,
65
+ VariableDeclarator: 1,
66
+ outerIIFEBody: 1,
67
+ MemberExpression: 1,
68
+ FunctionDeclaration: { parameters: 1, body: 1 },
69
+ FunctionExpression: { parameters: 1, body: 1 },
70
+ CallExpression: { arguments: 1 },
71
+ ArrayExpression: 1,
72
+ ObjectExpression: 1,
73
+ ImportDeclaration: 1,
74
+ flatTernaryExpressions: false,
75
+ ignoreComments: false
76
+ }],
77
+
78
+ // 单引号
79
+ 'quotes': ['error', 'single', {
80
+ avoidEscape: true,
81
+ allowTemplateLiterals: true
82
+ }],
83
+
84
+ // 禁止制表符
85
+ 'no-tabs': 'error',
86
+
87
+ // 行尾分号
88
+ 'semi': ['error', 'always'],
89
+
90
+ // 逗号风格
91
+ 'comma-style': ['error', 'last'],
92
+
93
+ // 逗号后必须有空格,逗号前不能有空格
94
+ 'comma-spacing': ['error', {
95
+ before: false,
96
+ after: true
97
+ }]
98
+ }
99
+ },
100
+
101
+ {
102
+ // 错误处理规则
103
+ rules: {
104
+ // 必须进行参数校验
105
+ 'no-unused-vars': ['error', {
106
+ args: 'all',
107
+ argsIgnorePattern: '^_',
108
+ caughtErrors: 'all',
109
+ caughtErrorsIgnorePattern: '^_',
110
+ destructuredArrayIgnorePattern: '^_',
111
+ varsIgnorePattern: '^_',
112
+ ignoreRestSiblings: true
113
+ }],
114
+
115
+ // 建议使用try-catch
116
+ 'no-unsafe-finally': 'warn',
117
+
118
+ // 禁止直接抛出字符串
119
+ 'no-throw-literal': 'error'
120
+ }
121
+ },
122
+
123
+ {
124
+ // 最佳实践规则
125
+ rules: {
126
+ // 优先使用async/await
127
+ 'prefer-promise-reject-errors': 'error',
128
+
129
+ // 避免副作用
130
+ 'no-param-reassign': ['error', {
131
+ props: true,
132
+ ignorePropertyModificationsFor: [
133
+ 'acc', // for reduce accumulators
134
+ 'accumulator', // for reduce accumulators
135
+ 'e', // for e.returnvalue
136
+ 'ctx', // for Koa routing
137
+ 'context', // for Koa routing
138
+ 'req', // for Express requests
139
+ 'request', // for Express requests
140
+ 'res', // for Express responses
141
+ 'response', // for Express responses
142
+ '$scope', // for Angular 1 scopes
143
+ 'staticContext' // for ReactRouter context
144
+ ]
145
+ }],
146
+
147
+ // 优先链式编程
148
+ 'prefer-object-spread': 'error',
149
+
150
+ // 优先函数式编程
151
+ 'prefer-arrow-callback': 'error',
152
+
153
+ // 方法长度限制
154
+ 'max-lines-per-function': ['warn', {
155
+ max: 40,
156
+ skipBlankLines: true,
157
+ skipComments: true
158
+ }],
159
+
160
+ // 复杂度限制
161
+ 'complexity': ['warn', 10]
162
+ }
163
+ },
164
+
165
+ {
166
+ // JSDoc规则
167
+ rules: {
168
+ // 要求公开方法有JSDoc注释
169
+ 'jsdoc/require-jsdoc': ['warn', {
170
+ publicOnly: true,
171
+ require: {
172
+ FunctionDeclaration: true,
173
+ MethodDefinition: true,
174
+ ClassDeclaration: true,
175
+ ArrowFunctionExpression: false,
176
+ FunctionExpression: false
177
+ }
178
+ }],
179
+
180
+ // 检查JSDoc语法
181
+ 'jsdoc/check-alignment': 'warn',
182
+ 'jsdoc/check-indentation': 'warn',
183
+ 'jsdoc/check-param-names': 'warn',
184
+ 'jsdoc/check-syntax': 'warn',
185
+ 'jsdoc/check-tag-names': 'warn',
186
+ 'jsdoc/check-types': 'warn',
187
+ 'jsdoc/no-undefined-types': 'warn',
188
+ 'jsdoc/require-description': 'warn',
189
+ 'jsdoc/require-param': 'warn',
190
+ 'jsdoc/require-param-description': 'warn',
191
+ 'jsdoc/require-param-name': 'warn',
192
+ 'jsdoc/require-param-type': 'warn',
193
+ 'jsdoc/require-returns': 'warn',
194
+ 'jsdoc/require-returns-check': 'warn',
195
+ 'jsdoc/require-returns-description': 'warn',
196
+ 'jsdoc/require-returns-type': 'warn',
197
+ 'jsdoc/valid-types': 'warn'
198
+ }
199
+ },
200
+
201
+ {
202
+ // 忽略规则
203
+ ignores: [
204
+ 'node_modules/**',
205
+ 'dist/**',
206
+ 'build/**',
207
+ 'coverage/**',
208
+ '*.min.js'
209
+ ]
210
+ }
68
211
  ];
package/index.js CHANGED
@@ -12,31 +12,32 @@ const MongoClient = require('mongodb').MongoClient;
12
12
  * @description MongoDB帮助类
13
13
  */
14
14
  class MongoDB extends Base {
15
+ static config = {
16
+ // 服务器地址
17
+ host: "localhost",
18
+ // 端口号
19
+ port: 27017,
20
+ // 数据库名
21
+ database: "mm",
22
+ // 用户名
23
+ user: "",
24
+ // 密码
25
+ password: "",
26
+ // 连接选项 (MongoDB驱动7.x版本支持的参数)
27
+ min_pool_size: 10,
28
+ max_pool_size: 100,
29
+ connect_timeout_ms: 10000,
30
+ server_selection_timeout_ms: 5000,
31
+ retry_writes: true
32
+ };
33
+
15
34
  /**
16
35
  * @description 创建MongoDB帮助类函数 (构造函数)
17
36
  * @param {Object} config 配置参数
18
37
  * @constructor
19
38
  */
20
39
  constructor(config) {
21
- super();
22
- this.config = {
23
- // 服务器地址
24
- host: "localhost",
25
- // 端口号
26
- port: 27017,
27
- // 数据库名
28
- database: "mm",
29
- // 用户名
30
- user: "",
31
- // 密码
32
- password: "",
33
- // 连接选项 (MongoDB驱动7.x版本支持的参数)
34
- min_pool_size: 10,
35
- max_pool_size: 100,
36
- connect_timeout_ms: 10000,
37
- server_selection_timeout_ms: 5000,
38
- retry_writes: true
39
- };
40
+ super(MongoDB.config);
40
41
 
41
42
  // 数据库连接器
42
43
  this.conn = null;
@@ -3951,11 +3952,6 @@ MongoDB.prototype.rollbackTransaction = async function (session) {
3951
3952
  }
3952
3953
  };
3953
3954
 
3954
- /**
3955
- * 导出MongoDB类
3956
- */
3957
- exports.MongoDB = MongoDB;
3958
-
3959
3955
  /**
3960
3956
  * 确保连接池对象存在
3961
3957
  */
@@ -3991,7 +3987,7 @@ function mongodbAdmin(scope, config) {
3991
3987
  return obj;
3992
3988
  }
3993
3989
 
3994
- /**
3995
- * @module 导出MongoDB管理器
3996
- */
3997
- exports.mongodbAdmin = mongodbAdmin;
3990
+ module.exports = {
3991
+ MongoDB,
3992
+ mongodbAdmin
3993
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_mongodb",
3
- "version": "1.5.4",
3
+ "version": "1.5.5",
4
4
  "description": "MongoDB数据库操作模块,提供简洁易用的API、缓存功能以及完整的Redis兼容接口,支持事件系统、事务和连接池管理",
5
5
  "main": "index.js",
6
6
  "scripts": {