mm_expand 2.2.0 → 2.2.2
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/index.js +6 -0
- package/lib/errors.js +3 -3
- package/lib/req.js +9 -9
- package/lib/ret.js +13 -8
- package/package.json +1 -1
package/index.js
CHANGED
package/lib/errors.js
CHANGED
|
@@ -121,7 +121,7 @@ class Errors extends Base {
|
|
|
121
121
|
* @returns {string|null} 错误信息
|
|
122
122
|
*/
|
|
123
123
|
Errors.prototype.get = function (code) {
|
|
124
|
-
const lang = this.
|
|
124
|
+
const lang = this.config.lang;
|
|
125
125
|
const lang_pack = this._langs[lang];
|
|
126
126
|
|
|
127
127
|
if (lang_pack && lang_pack[code]) {
|
|
@@ -141,7 +141,7 @@ Errors.prototype.get = function (code) {
|
|
|
141
141
|
* @param {string} lang 语言代码
|
|
142
142
|
*/
|
|
143
143
|
Errors.prototype.setLang = function (lang) {
|
|
144
|
-
this.
|
|
144
|
+
this.config.lang = lang;
|
|
145
145
|
};
|
|
146
146
|
|
|
147
147
|
/**
|
|
@@ -149,7 +149,7 @@ Errors.prototype.setLang = function (lang) {
|
|
|
149
149
|
* @returns {string} 当前语言代码
|
|
150
150
|
*/
|
|
151
151
|
Errors.prototype.getLang = function () {
|
|
152
|
-
return this.
|
|
152
|
+
return this.config.lang;
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
/**
|
package/lib/req.js
CHANGED
|
@@ -36,7 +36,7 @@ class Req extends Base {
|
|
|
36
36
|
* @returns {string} 新的ID
|
|
37
37
|
*/
|
|
38
38
|
Req.prototype.genId = function () {
|
|
39
|
-
return this.
|
|
39
|
+
return this.config.scope + Date.now();
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -49,10 +49,10 @@ Req.prototype.send = function (method, ...args) {
|
|
|
49
49
|
if (this._methods[method]) {
|
|
50
50
|
return this._methods[method](...args);
|
|
51
51
|
}
|
|
52
|
-
else if (this.
|
|
52
|
+
else if (this.config.format === "json-rpc") {
|
|
53
53
|
return this._sendJsonRPC(method, args);
|
|
54
54
|
}
|
|
55
|
-
else if (this.
|
|
55
|
+
else if (this.config.format === "json-rpc3") {
|
|
56
56
|
return this._sendJsonRPC3(method, ...args);
|
|
57
57
|
}
|
|
58
58
|
else {
|
|
@@ -159,19 +159,19 @@ Req.prototype.parse = function (req) {
|
|
|
159
159
|
params.push(req.meta || null);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
if (this.
|
|
162
|
+
if (this.config.format === "json-rpc") {
|
|
163
163
|
if (req.params) {
|
|
164
164
|
params = req.params;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
else if (this.
|
|
167
|
+
else if (this.config.format === "json-rpc3") {
|
|
168
168
|
var pm = {};
|
|
169
169
|
pm.query = params.length > 0 ? params[0] || null : null;
|
|
170
170
|
pm.body = params.length > 1 ? params[1] || null : null;
|
|
171
171
|
pm.meta = params.length > 2 ? params[2] || null : null;
|
|
172
172
|
params = pm;
|
|
173
173
|
}
|
|
174
|
-
else if (this.
|
|
174
|
+
else if (this.config.format === "restful") {
|
|
175
175
|
var ret = {
|
|
176
176
|
id,
|
|
177
177
|
method,
|
|
@@ -251,14 +251,14 @@ Req.prototype.setFormat = function (format) {
|
|
|
251
251
|
switch (format?.toLowerCase()) {
|
|
252
252
|
case "json":
|
|
253
253
|
case "json-rpc":
|
|
254
|
-
this.
|
|
254
|
+
this.config.format = "json-rpc";
|
|
255
255
|
break;
|
|
256
256
|
case "json3":
|
|
257
257
|
case "json-rpc3":
|
|
258
|
-
this.
|
|
258
|
+
this.config.format = "json-rpc3";
|
|
259
259
|
break;
|
|
260
260
|
default:
|
|
261
|
-
this.
|
|
261
|
+
this.config.format = "restful";
|
|
262
262
|
break;
|
|
263
263
|
}
|
|
264
264
|
};
|
package/lib/ret.js
CHANGED
|
@@ -128,6 +128,10 @@ Ret.prototype._toJsonRPC = function (result, error, id, diy = true) {
|
|
|
128
128
|
* @returns {Object} RESTful响应格式
|
|
129
129
|
*/
|
|
130
130
|
Ret.prototype._toRESTful = function (result, error, id, diy = true) {
|
|
131
|
+
let ret = {};
|
|
132
|
+
if (id) {
|
|
133
|
+
ret.id = id;
|
|
134
|
+
}
|
|
131
135
|
var code;
|
|
132
136
|
var msg;
|
|
133
137
|
if (result) {
|
|
@@ -151,13 +155,13 @@ Ret.prototype._toRESTful = function (result, error, id, diy = true) {
|
|
|
151
155
|
code = this.config.error_code;
|
|
152
156
|
msg = this._getMessage(code);
|
|
153
157
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
158
|
+
ret.code = code;
|
|
159
|
+
ret.msg = msg;
|
|
160
|
+
if (result) {
|
|
161
|
+
ret.data = result;
|
|
162
|
+
}
|
|
163
|
+
return ret;
|
|
164
|
+
};
|
|
161
165
|
|
|
162
166
|
/**
|
|
163
167
|
* 生成响应体
|
|
@@ -334,7 +338,8 @@ Ret.prototype.setFormat = function (format) {
|
|
|
334
338
|
this.config.format = "restful";
|
|
335
339
|
break;
|
|
336
340
|
}
|
|
337
|
-
|
|
341
|
+
return this;
|
|
342
|
+
};
|
|
338
343
|
|
|
339
344
|
module.exports = {
|
|
340
345
|
Ret
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_expand",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Super Meimei Prototype Function Extension Module - Enhanced operations for string, array, object, date manipulation with error prevention and simplified business logic.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|