mm_expand 2.2.1 → 2.2.3

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/lib/base.js CHANGED
@@ -34,7 +34,7 @@ class Base extends Event {
34
34
  // 监听事件
35
35
  this._listen();
36
36
  }
37
-
37
+
38
38
  /**
39
39
  * 获取当前状态
40
40
  * @returns {string} 当前状态
@@ -101,6 +101,15 @@ Base.prototype._onDestroy = function () {
101
101
  Base.prototype._preset = function () {
102
102
  };
103
103
 
104
+ /**
105
+ * 设置配置参数 - 内部方法
106
+ * @private
107
+ * @param {object} config 主要配置
108
+ */
109
+ Base.prototype._setConfig = function (config) {
110
+ Object.assign(this.config, config);
111
+ }
112
+
104
113
  /**
105
114
  * 设置配置参数
106
115
  * @param {object} config 主要配置
@@ -111,7 +120,7 @@ Base.prototype.setConfig = function (config) {
111
120
  if (typeof config !== 'object') {
112
121
  throw new TypeError('配置参数必须是对象');
113
122
  }
114
- Object.assign(this.config, config);
123
+ this._setConfig(config);
115
124
  }
116
125
  // 初始化设置
117
126
  this._preset();
@@ -135,13 +144,24 @@ Base.prototype._initCore = async function (...params) {
135
144
  return this;
136
145
  };
137
146
 
147
+
148
+ /**
149
+ * 初始化模块 - 内部方法
150
+ * @private
151
+ * @param {...any} params 初始化参数
152
+ * @returns {Promise<void>} 初始化完成
153
+ */
154
+ Base.prototype._init = async function (...params) {
155
+ return this;
156
+ };
157
+
138
158
  /**
139
159
  * 初始化
140
160
  * @param {...object} params 参数列表
141
161
  * @returns {object} 返回当前对象
142
162
  */
143
163
  Base.prototype.init = async function (...params) {
144
- return this;
164
+ return this._init(...params);
145
165
  };
146
166
 
147
167
  /**
@@ -152,11 +172,19 @@ Base.prototype._destroyCore = async function () {
152
172
  return this;
153
173
  };
154
174
 
175
+ /**
176
+ * 销毁模块 - 内部方法
177
+ * @private
178
+ */
179
+ Base.prototype._destroy = async function () {
180
+ return this;
181
+ };
182
+
155
183
  /**
156
184
  * 销毁
157
185
  */
158
186
  Base.prototype.destroy = async function () {
159
- return this;
187
+ return this._destroy();
160
188
  };
161
189
 
162
190
  /**
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._config.lang;
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._config.lang = lang;
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._config.lang;
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._config.scope + Date.now();
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._config.format === "json-rpc") {
52
+ else if (this.config.format === "json-rpc") {
53
53
  return this._sendJsonRPC(method, args);
54
54
  }
55
- else if (this._config.format === "json-rpc3") {
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._config.format === "json-rpc") {
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._config.format === "json-rpc3") {
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._config.format === "restful") {
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._config.format = "json-rpc";
254
+ this.config.format = "json-rpc";
255
255
  break;
256
256
  case "json3":
257
257
  case "json-rpc3":
258
- this._config.format = "json-rpc3";
258
+ this.config.format = "json-rpc3";
259
259
  break;
260
260
  default:
261
- this._config.format = "restful";
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
- return {
155
- id,
156
- code,
157
- msg,
158
- data: result
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.1",
3
+ "version": "2.2.3",
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": {