mm_config 2.3.2 → 2.3.4
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 +9 -40
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -21,6 +21,7 @@ class Config extends Base {
|
|
|
21
21
|
format: 'json',
|
|
22
22
|
file: ''
|
|
23
23
|
};
|
|
24
|
+
|
|
24
25
|
/**
|
|
25
26
|
* 预设选项
|
|
26
27
|
* @type {object}
|
|
@@ -41,8 +42,6 @@ class Config extends Base {
|
|
|
41
42
|
constructor(config, options = {}) {
|
|
42
43
|
super(config);
|
|
43
44
|
this.options = { ...Config.options, ...options };
|
|
44
|
-
this._conn = null;
|
|
45
|
-
this._timer = null;
|
|
46
45
|
this._promise = Promise.resolve();
|
|
47
46
|
}
|
|
48
47
|
}
|
|
@@ -56,13 +55,11 @@ Config.prototype.setOptions = function (options) {
|
|
|
56
55
|
};
|
|
57
56
|
|
|
58
57
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @
|
|
61
|
-
* @returns {object} 连接的文件对象
|
|
58
|
+
* 获取配置
|
|
59
|
+
* @returns {object} 配置对象
|
|
62
60
|
*/
|
|
63
|
-
Config.prototype.
|
|
64
|
-
|
|
65
|
-
return this._conn;
|
|
61
|
+
Config.prototype.getOptions = function () {
|
|
62
|
+
return this.options;
|
|
66
63
|
};
|
|
67
64
|
|
|
68
65
|
/**
|
|
@@ -194,14 +191,7 @@ Config.prototype.getAsyncProxy = function () {
|
|
|
194
191
|
* @returns {*} 配置值
|
|
195
192
|
*/
|
|
196
193
|
Config.prototype.get = async function (key) {
|
|
197
|
-
|
|
198
|
-
if (this._conn) {
|
|
199
|
-
value = await this._conn.get(key);
|
|
200
|
-
}
|
|
201
|
-
if (!value) {
|
|
202
|
-
value = this.options[key];
|
|
203
|
-
}
|
|
204
|
-
return value;
|
|
194
|
+
return this.options[key];
|
|
205
195
|
};
|
|
206
196
|
|
|
207
197
|
/**
|
|
@@ -209,13 +199,8 @@ Config.prototype.get = async function (key) {
|
|
|
209
199
|
* @param {string} key - 配置键
|
|
210
200
|
* @param {*} value - 配置值
|
|
211
201
|
*/
|
|
212
|
-
Config.prototype.set =
|
|
213
|
-
|
|
214
|
-
await this._conn.set(key, value);
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
this.options[key] = value;
|
|
218
|
-
}
|
|
202
|
+
Config.prototype.set = function (key, value) {
|
|
203
|
+
this.options[key] = value;
|
|
219
204
|
};
|
|
220
205
|
|
|
221
206
|
/**
|
|
@@ -224,14 +209,7 @@ Config.prototype.set = async function (key, value) {
|
|
|
224
209
|
* @returns {boolean} 配置项是否存在
|
|
225
210
|
*/
|
|
226
211
|
Config.prototype.has = async function (key) {
|
|
227
|
-
|
|
228
|
-
if (this._conn) {
|
|
229
|
-
bl = await this._conn.has(key);
|
|
230
|
-
};
|
|
231
|
-
if (!bl) {
|
|
232
|
-
bl = this.options.hasOwnProperty(key);
|
|
233
|
-
}
|
|
234
|
-
return bl;
|
|
212
|
+
return this.options.hasOwnProperty(key);
|
|
235
213
|
};
|
|
236
214
|
|
|
237
215
|
/**
|
|
@@ -239,9 +217,6 @@ Config.prototype.has = async function (key) {
|
|
|
239
217
|
* @param {string} key - 配置键
|
|
240
218
|
*/
|
|
241
219
|
Config.prototype.del = async function (key) {
|
|
242
|
-
if (this._conn) {
|
|
243
|
-
await this._conn.del(key);
|
|
244
|
-
};
|
|
245
220
|
delete this.options[key];
|
|
246
221
|
};
|
|
247
222
|
|
|
@@ -251,9 +226,6 @@ Config.prototype.del = async function (key) {
|
|
|
251
226
|
*/
|
|
252
227
|
Config.prototype.keys = async function () {
|
|
253
228
|
let keys = [];
|
|
254
|
-
if (this._conn) {
|
|
255
|
-
keys = await this._conn.keys();
|
|
256
|
-
}
|
|
257
229
|
let local_keys = Object.keys(this.options);
|
|
258
230
|
keys = keys.concat(local_keys);
|
|
259
231
|
return keys;
|
|
@@ -263,9 +235,6 @@ Config.prototype.keys = async function () {
|
|
|
263
235
|
* 销毁
|
|
264
236
|
*/
|
|
265
237
|
Config.prototype.destroy = function () {
|
|
266
|
-
if (this._conn) {
|
|
267
|
-
this._conn.close();
|
|
268
|
-
}
|
|
269
238
|
delete dict[this.config.file];
|
|
270
239
|
};
|
|
271
240
|
|