mm_ret 1.4.4 → 1.4.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.
- package/README.md +57 -57
- package/README_EN.md +234 -0
- package/eslint.config.js +68 -0
- package/package.json +2 -2
- package/test.js +0 -11
package/README.md
CHANGED
|
@@ -3,64 +3,64 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/mm_ret)
|
|
4
4
|
[](https://github.com/qiuwenwu91/mm_ret/blob/main/LICENSE)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
一个用于生成符合 JSON-RPC 2.0 标准的响应和请求的 Node.js 模块。
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## 特性
|
|
9
|
+
|
|
10
|
+
- ✅ **JSON-RPC 2.0 标准兼容** - 完全符合 JSON-RPC 2.0 规范
|
|
11
|
+
- ✅ **多种响应类型** - 支持对象、列表、布尔值等响应格式
|
|
12
|
+
- ✅ **错误码管理** - 内置标准错误码和自定义错误码
|
|
13
|
+
- ✅ **请求模板** - 支持请求参数模板功能
|
|
14
|
+
- ✅ **轻量级** - 无依赖,体积小巧
|
|
15
|
+
- ✅ **TypeScript 支持** - 提供完整的类型定义
|
|
16
|
+
|
|
17
|
+
## 安装
|
|
9
18
|
|
|
10
19
|
```bash
|
|
11
20
|
npm install mm_ret
|
|
12
21
|
```
|
|
13
22
|
|
|
14
|
-
## 快速开始
|
|
23
|
+
## 快速开始
|
|
15
24
|
|
|
16
|
-
### 基本使用
|
|
25
|
+
### 基本使用
|
|
17
26
|
|
|
18
27
|
```javascript
|
|
19
28
|
const { Ret, Req, Error } = require('mm_ret');
|
|
20
29
|
|
|
21
|
-
// 生成成功响应
|
|
30
|
+
// 生成成功响应
|
|
22
31
|
const successResponse = Ret.body('操作成功');
|
|
23
32
|
console.log(successResponse);
|
|
24
33
|
// 输出: {"result":"操作成功"}
|
|
25
34
|
|
|
26
|
-
// 生成错误响应
|
|
35
|
+
// 生成错误响应
|
|
27
36
|
const errorResponse = Ret.error(10000, '参数错误');
|
|
28
37
|
console.log(errorResponse);
|
|
29
38
|
// 输出: {"error":{"code":10000,"message":"参数错误"}}
|
|
30
39
|
|
|
31
|
-
// 生成请求
|
|
40
|
+
// 生成请求
|
|
32
41
|
const req = new Req('user');
|
|
33
42
|
const requestBody = req.send('getUser', { id: 123 });
|
|
34
43
|
console.log(requestBody);
|
|
35
44
|
// 输出: {"jsonrpc":"2.0","method":"user.getUser","params":{"id":123},"id":"..."}
|
|
36
45
|
```
|
|
37
46
|
|
|
38
|
-
##
|
|
39
|
-
|
|
40
|
-
- ✅ **JSON-RPC 2.0 标准兼容** - 完全符合JSON-RPC 2.0规范
|
|
41
|
-
- ✅ **多种响应类型** - 支持对象、列表、布尔值等响应格式
|
|
42
|
-
- ✅ **错误码管理** - 内置标准错误码和自定义错误码
|
|
43
|
-
- ✅ **请求模板** - 支持请求参数模板功能
|
|
44
|
-
- ✅ **轻量级** - 无依赖,体积小巧
|
|
45
|
-
- ✅ **TypeScript 支持** - 提供完整的类型定义
|
|
46
|
-
|
|
47
|
-
## API 文档 / API Documentation
|
|
47
|
+
## API 文档
|
|
48
48
|
|
|
49
49
|
### Ret 类 - 响应生成器
|
|
50
50
|
|
|
51
|
-
生成符合JSON-RPC 2.0标准的响应对象。
|
|
51
|
+
生成符合 JSON-RPC 2.0 标准的响应对象。
|
|
52
52
|
|
|
53
|
-
#### 方法
|
|
53
|
+
#### 方法
|
|
54
54
|
|
|
55
55
|
##### `body(result, error, id)`
|
|
56
|
-
生成基础的JSON-RPC响应体。
|
|
56
|
+
生成基础的 JSON-RPC 响应体。
|
|
57
57
|
|
|
58
58
|
**参数:**
|
|
59
59
|
- `result` {any} - 返回结果
|
|
60
60
|
- `error` {Object} - 错误信息(可选)
|
|
61
61
|
- `id` {String} - 请求ID(可选)
|
|
62
62
|
|
|
63
|
-
**返回值:** {Object} JSON-RPC响应对象
|
|
63
|
+
**返回值:** {Object} JSON-RPC 响应对象
|
|
64
64
|
|
|
65
65
|
##### `error(code, message, id)`
|
|
66
66
|
生成错误响应。
|
|
@@ -103,7 +103,7 @@ console.log(requestBody);
|
|
|
103
103
|
|
|
104
104
|
### Req 类 - 请求生成器
|
|
105
105
|
|
|
106
|
-
生成符合JSON-RPC 2.0标准的请求对象。
|
|
106
|
+
生成符合 JSON-RPC 2.0 标准的请求对象。
|
|
107
107
|
|
|
108
108
|
#### 构造函数
|
|
109
109
|
```javascript
|
|
@@ -113,22 +113,22 @@ new Req(scope = 'sys')
|
|
|
113
113
|
**参数:**
|
|
114
114
|
- `scope` {String} - 作用域,默认为"sys"
|
|
115
115
|
|
|
116
|
-
#### 方法
|
|
116
|
+
#### 方法
|
|
117
117
|
|
|
118
118
|
##### `send(method, params)`
|
|
119
|
-
生成JSON-RPC请求。
|
|
119
|
+
生成 JSON-RPC 请求。
|
|
120
120
|
|
|
121
121
|
**参数:**
|
|
122
122
|
- `method` {String} - 方法名
|
|
123
123
|
- `params` {Object} - 参数对象
|
|
124
124
|
|
|
125
|
-
**返回值:** {Object} 标准的JSON-RPC请求对象
|
|
125
|
+
**返回值:** {Object} 标准的 JSON-RPC 请求对象
|
|
126
126
|
|
|
127
127
|
### Error 类 - 错误码管理
|
|
128
128
|
|
|
129
|
-
管理JSON-RPC标准错误码和自定义错误码。
|
|
129
|
+
管理 JSON-RPC 标准错误码和自定义错误码。
|
|
130
130
|
|
|
131
|
-
#### 方法
|
|
131
|
+
#### 方法
|
|
132
132
|
|
|
133
133
|
##### `get(keyword)`
|
|
134
134
|
根据关键词或错误码获取对应的错误信息。
|
|
@@ -136,11 +136,11 @@ new Req(scope = 'sys')
|
|
|
136
136
|
**参数:**
|
|
137
137
|
- `keyword` {String|Number} - 关键词或错误码
|
|
138
138
|
|
|
139
|
-
**返回值:** {Object} 错误信息对象,包含code和message
|
|
139
|
+
**返回值:** {Object} 错误信息对象,包含 code 和 message
|
|
140
140
|
|
|
141
|
-
## 使用示例
|
|
141
|
+
## 使用示例
|
|
142
142
|
|
|
143
|
-
### 响应示例
|
|
143
|
+
### 响应示例
|
|
144
144
|
|
|
145
145
|
```javascript
|
|
146
146
|
const { Ret } = require('mm_ret');
|
|
@@ -166,7 +166,7 @@ const bool = Ret.bl(true, '操作成功');
|
|
|
166
166
|
// {"result":{"bl":true,"tip":"操作成功"}}
|
|
167
167
|
```
|
|
168
168
|
|
|
169
|
-
### 请求示例
|
|
169
|
+
### 请求示例
|
|
170
170
|
|
|
171
171
|
```javascript
|
|
172
172
|
const { Req } = require('mm_ret');
|
|
@@ -190,45 +190,45 @@ const templateRequest = reqWithTemplate.send('message', {
|
|
|
190
190
|
// 自动合并模板字段
|
|
191
191
|
```
|
|
192
192
|
|
|
193
|
-
## 错误码参考
|
|
194
|
-
|
|
195
|
-
### 标准JSON-RPC错误码
|
|
196
|
-
| 错误码 | 说明 |
|
|
197
|
-
|
|
198
|
-
| -32700 | 格式错误 |
|
|
199
|
-
| -32701 | 编码不支持 |
|
|
200
|
-
| -32702 | 无效字符 |
|
|
201
|
-
| -32600 | 无效请求 |
|
|
202
|
-
| -32601 | 方法不存在 |
|
|
203
|
-
| -32602 | 无效参数 |
|
|
204
|
-
| -32603 | 内部错误 |
|
|
205
|
-
| -32500 | 应用错误 |
|
|
206
|
-
| -32400 | 系统错误 |
|
|
207
|
-
| -32300 | 传输错误 |
|
|
193
|
+
## 错误码参考
|
|
194
|
+
|
|
195
|
+
### 标准 JSON-RPC 错误码
|
|
196
|
+
| 错误码 | 说明 |
|
|
197
|
+
|--------|------|
|
|
198
|
+
| -32700 | 格式错误 |
|
|
199
|
+
| -32701 | 编码不支持 |
|
|
200
|
+
| -32702 | 无效字符 |
|
|
201
|
+
| -32600 | 无效请求 |
|
|
202
|
+
| -32601 | 方法不存在 |
|
|
203
|
+
| -32602 | 无效参数 |
|
|
204
|
+
| -32603 | 内部错误 |
|
|
205
|
+
| -32500 | 应用错误 |
|
|
206
|
+
| -32400 | 系统错误 |
|
|
207
|
+
| -32300 | 传输错误 |
|
|
208
208
|
|
|
209
209
|
### 自定义错误码
|
|
210
|
-
| 错误码 | 说明 |
|
|
211
|
-
|
|
212
|
-
| 10000 | 业务逻辑错误 |
|
|
213
|
-
| 30000 | 身份验证失败 |
|
|
214
|
-
| 40000 | 数据库执行错误 |
|
|
215
|
-
| 50000 | 服务端执行错误 |
|
|
216
|
-
| 70000 | 参数不正确 |
|
|
210
|
+
| 错误码 | 说明 |
|
|
211
|
+
|--------|------|
|
|
212
|
+
| 10000 | 业务逻辑错误 |
|
|
213
|
+
| 30000 | 身份验证失败 |
|
|
214
|
+
| 40000 | 数据库执行错误 |
|
|
215
|
+
| 50000 | 服务端执行错误 |
|
|
216
|
+
| 70000 | 参数不正确 |
|
|
217
217
|
|
|
218
|
-
## 测试
|
|
218
|
+
## 测试
|
|
219
219
|
|
|
220
220
|
```bash
|
|
221
221
|
npm test
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
-
## 许可证
|
|
224
|
+
## 许可证
|
|
225
225
|
|
|
226
226
|
ISC License
|
|
227
227
|
|
|
228
|
-
## 贡献
|
|
228
|
+
## 贡献
|
|
229
229
|
|
|
230
230
|
欢迎提交 Issue 和 Pull Request!
|
|
231
231
|
|
|
232
|
-
## 更新日志
|
|
232
|
+
## 更新日志
|
|
233
233
|
|
|
234
234
|
查看 [GitHub Releases](https://github.com/qiuwenwu91/mm_ret/releases) 获取详细更新信息。
|
package/README_EN.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# mm_ret
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/mm_ret)
|
|
4
|
+
[](https://github.com/qiuwenwu91/mm_ret/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
A Node.js module for generating JSON-RPC 2.0 compliant responses and requests.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- ✅ **JSON-RPC 2.0 Compliant** - Fully conforms to JSON-RPC 2.0 specification
|
|
11
|
+
- ✅ **Multiple Response Types** - Supports object, list, boolean, and other response formats
|
|
12
|
+
- ✅ **Error Code Management** - Built-in standard error codes and custom error codes
|
|
13
|
+
- ✅ **Request Templates** - Supports request parameter template functionality
|
|
14
|
+
- ✅ **Lightweight** - No dependencies, small footprint
|
|
15
|
+
- ✅ **TypeScript Support** - Provides complete type definitions
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install mm_ret
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
### Basic Usage
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
const { Ret, Req, Error } = require('mm_ret');
|
|
29
|
+
|
|
30
|
+
// Generate success response
|
|
31
|
+
const successResponse = Ret.body('Operation successful');
|
|
32
|
+
console.log(successResponse);
|
|
33
|
+
// Output: {"result":"Operation successful"}
|
|
34
|
+
|
|
35
|
+
// Generate error response
|
|
36
|
+
const errorResponse = Ret.error(10000, 'Parameter error');
|
|
37
|
+
console.log(errorResponse);
|
|
38
|
+
// Output: {"error":{"code":10000,"message":"Parameter error"}}
|
|
39
|
+
|
|
40
|
+
// Generate request
|
|
41
|
+
const req = new Req('user');
|
|
42
|
+
const requestBody = req.send('getUser', { id: 123 });
|
|
43
|
+
console.log(requestBody);
|
|
44
|
+
// Output: {"jsonrpc":"2.0","method":"user.getUser","params":{"id":123},"id":"..."}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API Documentation
|
|
48
|
+
|
|
49
|
+
### Ret Class - Response Generator
|
|
50
|
+
|
|
51
|
+
Generates JSON-RPC 2.0 compliant response objects.
|
|
52
|
+
|
|
53
|
+
#### Methods
|
|
54
|
+
|
|
55
|
+
##### `body(result, error, id)`
|
|
56
|
+
Generates a basic JSON-RPC response body.
|
|
57
|
+
|
|
58
|
+
**Parameters:**
|
|
59
|
+
- `result` {any} - Return result
|
|
60
|
+
- `error` {Object} - Error information (optional)
|
|
61
|
+
- `id` {String} - Request ID (optional)
|
|
62
|
+
|
|
63
|
+
**Returns:** {Object} JSON-RPC response object
|
|
64
|
+
|
|
65
|
+
##### `error(code, message, id)`
|
|
66
|
+
Generates an error response.
|
|
67
|
+
|
|
68
|
+
**Parameters:**
|
|
69
|
+
- `code` {Number} - Error code
|
|
70
|
+
- `message` {String} - Error message
|
|
71
|
+
- `id` {String} - Request ID (optional)
|
|
72
|
+
|
|
73
|
+
**Returns:** {Object} Response object containing error information
|
|
74
|
+
|
|
75
|
+
##### `list(list, count, id)`
|
|
76
|
+
Generates a list-type response.
|
|
77
|
+
|
|
78
|
+
**Parameters:**
|
|
79
|
+
- `list` {Array} - Data list
|
|
80
|
+
- `count` {Number} - Total count (optional)
|
|
81
|
+
- `id` {String} - Request ID (optional)
|
|
82
|
+
|
|
83
|
+
**Returns:** {Object} Response object containing list data
|
|
84
|
+
|
|
85
|
+
##### `obj(obj, id)`
|
|
86
|
+
Generates an object-type response.
|
|
87
|
+
|
|
88
|
+
**Parameters:**
|
|
89
|
+
- `obj` {Object} - Return object
|
|
90
|
+
- `id` {String} - Request ID (optional)
|
|
91
|
+
|
|
92
|
+
**Returns:** {Object} Response object containing object data
|
|
93
|
+
|
|
94
|
+
##### `bl(bl, tip, id)`
|
|
95
|
+
Generates a boolean-type response.
|
|
96
|
+
|
|
97
|
+
**Parameters:**
|
|
98
|
+
- `bl` {Boolean} - Boolean value
|
|
99
|
+
- `tip` {String} - Tip message (optional)
|
|
100
|
+
- `id` {String} - Request ID (optional)
|
|
101
|
+
|
|
102
|
+
**Returns:** {Object} Response object containing boolean value and tip message
|
|
103
|
+
|
|
104
|
+
### Req Class - Request Generator
|
|
105
|
+
|
|
106
|
+
Generates JSON-RPC 2.0 compliant request objects.
|
|
107
|
+
|
|
108
|
+
#### Constructor
|
|
109
|
+
```javascript
|
|
110
|
+
new Req(scope = 'sys')
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Parameters:**
|
|
114
|
+
- `scope` {String} - Scope, defaults to "sys"
|
|
115
|
+
|
|
116
|
+
#### Methods
|
|
117
|
+
|
|
118
|
+
##### `send(method, params)`
|
|
119
|
+
Generates a JSON-RPC request.
|
|
120
|
+
|
|
121
|
+
**Parameters:**
|
|
122
|
+
- `method` {String} - Method name
|
|
123
|
+
- `params` {Object} - Parameter object
|
|
124
|
+
|
|
125
|
+
**Returns:** {Object} Standard JSON-RPC request object
|
|
126
|
+
|
|
127
|
+
### Error Class - Error Code Management
|
|
128
|
+
|
|
129
|
+
Manages JSON-RPC standard error codes and custom error codes.
|
|
130
|
+
|
|
131
|
+
#### Methods
|
|
132
|
+
|
|
133
|
+
##### `get(keyword)`
|
|
134
|
+
Retrieves corresponding error information based on keyword or error code.
|
|
135
|
+
|
|
136
|
+
**Parameters:**
|
|
137
|
+
- `keyword` {String|Number} - Keyword or error code
|
|
138
|
+
|
|
139
|
+
**Returns:** {Object} Error information object containing code and message
|
|
140
|
+
|
|
141
|
+
## Usage Examples
|
|
142
|
+
|
|
143
|
+
### Response Examples
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
const { Ret } = require('mm_ret');
|
|
147
|
+
|
|
148
|
+
// Success response
|
|
149
|
+
const success = Ret.body({ message: 'Operation successful' });
|
|
150
|
+
// {"result":{"message":"Operation successful"}}
|
|
151
|
+
|
|
152
|
+
// Error response
|
|
153
|
+
const error = Ret.error(400, 'Parameter validation failed');
|
|
154
|
+
// {"error":{"code":400,"message":"Parameter validation failed"}}
|
|
155
|
+
|
|
156
|
+
// List response
|
|
157
|
+
const list = Ret.list([{ id: 1, name: 'User1' }, { id: 2, name: 'User2' }], 2);
|
|
158
|
+
// {"result":{"list":[{...}],"count":2}}
|
|
159
|
+
|
|
160
|
+
// Object response
|
|
161
|
+
const obj = Ret.obj({ id: 1, name: 'John', age: 25 });
|
|
162
|
+
// {"result":{"obj":{...}}}
|
|
163
|
+
|
|
164
|
+
// Boolean response
|
|
165
|
+
const bool = Ret.bl(true, 'Operation successful');
|
|
166
|
+
// {"result":{"bl":true,"tip":"Operation successful"}}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Request Examples
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
const { Req } = require('mm_ret');
|
|
173
|
+
|
|
174
|
+
// Basic request
|
|
175
|
+
const req = new Req('user');
|
|
176
|
+
const request = req.send('getProfile', { userId: 123 });
|
|
177
|
+
// {"method":"user.getProfile","params":{"userId":123},"id":"..."}
|
|
178
|
+
|
|
179
|
+
// Using templates
|
|
180
|
+
const reqWithTemplate = new Req('message');
|
|
181
|
+
reqWithTemplate.tpl.message = {
|
|
182
|
+
to_user: '',
|
|
183
|
+
from_user: '',
|
|
184
|
+
content: ''
|
|
185
|
+
};
|
|
186
|
+
const templateRequest = reqWithTemplate.send('message', {
|
|
187
|
+
content: 'Hello!',
|
|
188
|
+
media: { title: 'Important Notice' }
|
|
189
|
+
});
|
|
190
|
+
// Automatically merges template fields
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Error Code Reference
|
|
194
|
+
|
|
195
|
+
### Standard JSON-RPC Error Codes
|
|
196
|
+
| Code | Description |
|
|
197
|
+
|------|-------------|
|
|
198
|
+
| -32700 | Parse error - Not well-formed |
|
|
199
|
+
| -32701 | Parse error - Unsupported encoding |
|
|
200
|
+
| -32702 | Parse error - Invalid character for encoding |
|
|
201
|
+
| -32600 | Invalid Request - Not conforming to JSON-RPC 2.0 |
|
|
202
|
+
| -32601 | Method not found |
|
|
203
|
+
| -32602 | Invalid params |
|
|
204
|
+
| -32603 | Internal error |
|
|
205
|
+
| -32500 | Application error |
|
|
206
|
+
| -32400 | System error |
|
|
207
|
+
| -32300 | Transport error |
|
|
208
|
+
|
|
209
|
+
### Custom Error Codes
|
|
210
|
+
| Code | Description |
|
|
211
|
+
|------|-------------|
|
|
212
|
+
| 10000 | Business logic error |
|
|
213
|
+
| 30000 | Authentication failed |
|
|
214
|
+
| 40000 | Database execution error |
|
|
215
|
+
| 50000 | Server execution error |
|
|
216
|
+
| 70000 | Invalid parameters |
|
|
217
|
+
|
|
218
|
+
## Testing
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
npm test
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
ISC License
|
|
227
|
+
|
|
228
|
+
## Contributing
|
|
229
|
+
|
|
230
|
+
Welcome to submit issues and pull requests!
|
|
231
|
+
|
|
232
|
+
## Changelog
|
|
233
|
+
|
|
234
|
+
Check [GitHub Releases](https://github.com/qiuwenwu91/mm_ret/releases) for detailed update information.
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const jsdoc = require('eslint-plugin-jsdoc');
|
|
2
|
+
|
|
3
|
+
module.exports = [
|
|
4
|
+
{
|
|
5
|
+
files: ['index.js','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
|
+
}
|
|
68
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_ret",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "这是超级美眉http请求结果输出类函数模块,用于输出json-rpc2.0标准结果",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://gitee.com/qiuwenwu91/mm_ret#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"mm_expand": "^
|
|
33
|
+
"mm_expand": "^2.0.0"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/test.js
CHANGED
|
@@ -91,14 +91,3 @@ function reqDemo() {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
reqDemo();
|
|
94
|
-
|
|
95
|
-
// var reqCS = new Req();
|
|
96
|
-
// const request = reqCS.send('getProfile', { userId: 123 });
|
|
97
|
-
// $.log.debug("封装:", JSON.stringify(request));
|
|
98
|
-
|
|
99
|
-
// var model = reqCS.parse({
|
|
100
|
-
// id: "1231233",
|
|
101
|
-
// method: 'getProfile',
|
|
102
|
-
// params: [{ userId: 123 }]
|
|
103
|
-
// });
|
|
104
|
-
// $.log.debug("解析:", model);
|