baja-lite 1.0.7 → 1.0.10

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BootRomote = void 0;
4
+ const enum_1 = require("./enum");
4
5
  const sql_1 = require("./sql");
5
6
  const BootRomote = async function (options) {
6
7
  globalThis[sql_1._GlobalSqlOption] = Object.assign({}, sql_1._defOption, options);
@@ -13,6 +14,9 @@ const BootRomote = async function (options) {
13
14
  globalThis[sql_1._dao] = {
14
15
  [sql_1.DBType.SqliteRemote]: {},
15
16
  };
17
+ if (options.enums) {
18
+ globalThis[sql_1._enums] = (0, enum_1.getEnums)(options.enums);
19
+ }
16
20
  if (options.SqliteRemote) {
17
21
  if (typeof options.SqliteRemote.db === 'string') {
18
22
  await options.SqliteRemote.service.initDB(options.SqliteRemote.db);
package/cjs/boot.js CHANGED
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Boot = void 0;
27
+ const enum_1 = require("./enum");
27
28
  const sql_1 = require("./sql");
28
29
  const Boot = async function (options) {
29
30
  globalThis[sql_1._GlobalSqlOption] = Object.assign({}, sql_1._defOption, options);
@@ -44,6 +45,9 @@ const Boot = async function (options) {
44
45
  [sql_1.DBType.SqliteRemote]: {},
45
46
  [sql_1.DBType.Redis]: {}
46
47
  };
48
+ if (options.enums) {
49
+ globalThis[sql_1._enums] = (0, enum_1.getEnums)(options.enums);
50
+ }
47
51
  if (options.Mysql) {
48
52
  const { createPool } = await Promise.resolve().then(() => __importStar(require('mysql2/promise')));
49
53
  if (options.Mysql['host']) {
package/cjs/code.js CHANGED
@@ -9,6 +9,7 @@ const fs_1 = __importDefault(require("fs"));
9
9
  const repl_1 = require("repl");
10
10
  const promise_1 = require("mysql2/promise");
11
11
  const mustache_1 = __importDefault(require("mustache"));
12
+ const shelljs_1 = require("shelljs");
12
13
  const lxMap = {
13
14
  tinyint: "number",
14
15
  smallint: "number",
@@ -79,7 +80,10 @@ console.log(`
79
80
  "s": ["entity", "controller", "service", "sql", "module"]
80
81
  },
81
82
  "output": "{ClassName}Module",
82
- "id"? : "uuidShort: true, notNull: true, uuid: true"
83
+ "id"? : "uuidShort: true, notNull: true, uuid: true",
84
+ "logicDeleteK"?: "逻辑删除字段名",
85
+ "logicDeleteV"?: "逻辑删除值",如果是字符串需要这样 logicDeleteV: "'0'"
86
+ "NotlogicDeleteV"?: "未逻辑删除值",如果是字符串需要这样 NotlogicDeleteV: "'0'"
83
87
  }
84
88
  command是生成命令,这里声明命令同时定义文件生成路径:可用下面的变量替换.同时必须有同名模板.
85
89
  路径是相对于项目根目录的
@@ -120,6 +124,8 @@ console.log(`
120
124
 
121
125
  modelName: 模块名称,可能为空字符串
122
126
  modelPath: 模块名称实际就影响访问路径,所以这里会直接拼好controller的模块访问路径,如果模块为空,则该属性就是空字符串,否则是 /模块名称/
127
+
128
+ logicDelete: 逻辑删除的查询条件,可以附加在sql条件的末尾,可能是空的
123
129
  -----
124
130
  命令 table1,table2,table3:模块名称
125
131
  table=. 表示扫描全库表
@@ -167,6 +173,7 @@ try {
167
173
  COLUMN_COMMENT \`comment\`
168
174
  FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=? AND TABLE_NAME = ?;
169
175
  `, [configData.database, tableName]);
176
+ let logicDelete = '';
170
177
  const columns = result.map(r => {
171
178
  if (r.id === 1) {
172
179
  r.id = true;
@@ -178,7 +185,6 @@ try {
178
185
  }
179
186
  else
180
187
  delete r.notNull;
181
- r.comment = `* ${r.comment ?? ''}(\`${tableName}.${r.name}\`)`;
182
188
  const fields = new Array(`type:SqlType.${r.type}`);
183
189
  if (r.length !== null) {
184
190
  fields.push(`length:${r.length}`);
@@ -204,6 +210,14 @@ try {
204
210
  if (r.id === true && configData.id) {
205
211
  fields.push(configData.id);
206
212
  }
213
+ if (r.name === configData.logicDeleteK) {
214
+ fields.push(`logicDelete: ${configData.logicDeleteV}`);
215
+ logicDelete = `AND ${r.name} = ${configData.NotlogicDeleteV}`;
216
+ }
217
+ if (r.comment) {
218
+ fields.push(`comment: '${r.comment}'`);
219
+ }
220
+ r.comment = r.comment ?? '';
207
221
  r.Type = lxMap[r.type];
208
222
  r.Field = `@Field({${fields.join(',')}})`;
209
223
  r.Name = r.name.replace(/_(\w)/g, (a, b) => b.toUpperCase());
@@ -211,7 +225,7 @@ try {
211
225
  return r;
212
226
  });
213
227
  conn.release();
214
- return columns;
228
+ return { columns, logicDelete };
215
229
  }
216
230
  async function excute(command, input, modelName) {
217
231
  const tables = await getTables(input);
@@ -225,7 +239,7 @@ try {
225
239
  modelName ?? (modelName = '');
226
240
  const modelPath = modelName ? `/${modelName}/` : '';
227
241
  for (const { tableName, title } of tables) {
228
- const columns = await getColumns(tableName);
242
+ const { columns, logicDelete } = await getColumns(tableName);
229
243
  const className = tableName.replace(/_(\w)/g, (a, b) => b.toUpperCase());
230
244
  const ClassName = className.replace(/\w/, (v) => v.toUpperCase());
231
245
  const vueName = tableName.replace(/_/g, '-');
@@ -255,7 +269,8 @@ try {
255
269
  idNames_join: columns?.filter(i => i.id).map(i => i.name).join(','),
256
270
  IdNames_join: columns?.filter(i => i.id).map(i => i.Name).join(','),
257
271
  modelName,
258
- modelPath
272
+ modelPath,
273
+ logicDelete
259
274
  };
260
275
  const template = templates[command];
261
276
  if (!template) {
@@ -266,13 +281,13 @@ try {
266
281
  const fileName = configData.command[command].replace(/{([a-zA-Z]+)}/g, (a, b) => data[b]);
267
282
  const filePath = path_1.default.join(basepath, fileName);
268
283
  const dirname = path_1.default.dirname(filePath);
269
- try {
270
- fs_1.default.statSync(dirname);
271
- }
272
- catch (error) {
273
- fs_1.default.mkdirSync(dirname);
274
- console.info(`[生成] ${dirname}`);
275
- }
284
+ (0, shelljs_1.mkdir)('-p', dirname);
285
+ // try {
286
+ // fs.statSync(dirname);
287
+ // } catch (error) {
288
+ // fs.mkdirSync(dirname);
289
+ // console.info(`[生成] ${dirname}`);
290
+ // }
276
291
  try {
277
292
  fs_1.default.statSync(filePath);
278
293
  if (force === false) {
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.convert = void 0;
7
+ const lodash_get_1 = __importDefault(require("lodash.get"));
4
8
  const convert = function (childrens, param, parentIds, myBatisMapper) {
5
9
  let statement = '';
6
10
  for (let i = 0, children; children = childrens[i]; i++) {
@@ -89,7 +93,7 @@ const convertParametersInner = function (change, convertString, param) {
89
93
  for (let i = 0; i < _stringTarget.length; i++) {
90
94
  target = _stringTarget[i];
91
95
  const t = target.replace(change + '{', '').replace('}', '');
92
- let tempParamKey = eval('param.' + t);
96
+ let tempParamKey = (0, lodash_get_1.default)(param, t);
93
97
  if (tempParamKey !== undefined) {
94
98
  const reg = new RegExp('\\' + change + '{' + t + '}', 'g');
95
99
  if (tempParamKey === null) {
package/cjs/enum.d.ts CHANGED
@@ -8,3 +8,11 @@ export declare class Enum {
8
8
  desc(): string;
9
9
  config(): string[];
10
10
  }
11
+ export type EnumMap = Record<string, Enum>;
12
+ export type GlobalArray = Record<string, Array<[string, string]>>;
13
+ export type GlobalMap = Record<string, Record<string, string>>;
14
+ export interface EnmuJson {
15
+ GlobalArray: GlobalArray;
16
+ GlobalMap: GlobalMap;
17
+ }
18
+ export declare const getEnums: (GlobalValues?: EnumMap) => EnmuJson;
package/cjs/enum.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Enum = void 0;
3
+ exports.getEnums = exports.Enum = void 0;
4
+ const sql_1 = require("./sql");
4
5
  class Enum {
5
6
  constructor(value, desc, ...config) {
6
7
  this._value = value;
@@ -30,3 +31,34 @@ class Enum {
30
31
  }
31
32
  }
32
33
  exports.Enum = Enum;
34
+ let configData = null;
35
+ const getEnums = (GlobalValues) => {
36
+ if (!GlobalValues) {
37
+ return globalThis[sql_1._enums];
38
+ }
39
+ if (configData) {
40
+ return configData;
41
+ }
42
+ const result = {
43
+ GlobalArray: {},
44
+ GlobalMap: {}
45
+ };
46
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
47
+ Object.keys(GlobalValues).forEach((item) => {
48
+ // const guess = /([\w\W]+)_([^_]+)$/.exec(item);
49
+ const guess = item.replace(new RegExp(`_${GlobalValues[item].value()}`, 'i'), '');
50
+ if (guess) {
51
+ if (!result.GlobalArray[guess]) {
52
+ result.GlobalArray[guess] = [];
53
+ }
54
+ result.GlobalArray[guess].push([GlobalValues[item].value(), GlobalValues[item].desc()]);
55
+ if (!result.GlobalMap[guess]) {
56
+ result.GlobalMap[guess] = {};
57
+ }
58
+ result.GlobalMap[guess][GlobalValues[item].value()] = GlobalValues[item].desc();
59
+ }
60
+ });
61
+ configData = result;
62
+ return result;
63
+ };
64
+ exports.getEnums = getEnums;
package/cjs/fn.js CHANGED
@@ -92,55 +92,65 @@ function excuteSplit(sync, datas, fn, { everyLength = 0, groupCount = 0, settled
92
92
  const list = (0, object_1.arraySplit)(datas, ps);
93
93
  if (sync === ExcuteSplitMode.AsyncTrust) {
94
94
  return new Promise(async (resolve, reject) => {
95
- const reasons = [];
96
- if (settled) {
97
- const result = await Promise.allSettled(list.map((list, i) => fn(list, i, list.length, extendParams[i])));
98
- for (const item of result) {
99
- if (item.status === 'rejected') {
100
- reject(item.reason);
95
+ try {
96
+ const reasons = [];
97
+ if (settled) {
98
+ const result = await Promise.allSettled(list.map((list, i) => fn(list, i, list.length, extendParams[i])));
99
+ for (const item of result) {
100
+ if (item.status === 'rejected') {
101
+ reject(item.reason);
102
+ }
103
+ else {
104
+ reasons.push(item.value);
105
+ }
101
106
  }
102
- else {
103
- reasons.push(item.value);
107
+ }
108
+ else {
109
+ for (let i = 0; i < list.length; i++) {
110
+ const startIndex = (i - 1) * ps.everyLength;
111
+ const endIndex = startIndex + list[i].length - 1;
112
+ reasons.push(await fn(list[i], i, list.length, extendParams[i], startIndex, endIndex));
104
113
  }
105
114
  }
115
+ resolve(reasons);
106
116
  }
107
- else {
108
- for (let i = 0; i < list.length; i++) {
109
- const startIndex = (i - 1) * ps.everyLength;
110
- const endIndex = startIndex + list[i].length - 1;
111
- reasons.push(await fn(list[i], i, list.length, extendParams[i], startIndex, endIndex));
112
- }
117
+ catch (error) {
118
+ reject(error);
113
119
  }
114
- resolve(reasons);
115
120
  });
116
121
  }
117
122
  else if (sync === ExcuteSplitMode.AsyncNoTrust) {
118
123
  return new Promise(async (resolve, reject) => {
119
- const reasons = { result: [], error: [] };
120
- if (settled) {
121
- const result = await Promise.allSettled(list.map((list, i) => fn(list, i, list.length, extendParams[i])));
122
- for (const item of result) {
123
- if (item.status === 'rejected') {
124
- reasons.error.push(item.reason);
125
- }
126
- else {
127
- reasons.result.push(item.value);
124
+ try {
125
+ const reasons = { result: [], error: [] };
126
+ if (settled) {
127
+ const result = await Promise.allSettled(list.map((list, i) => fn(list, i, list.length, extendParams[i])));
128
+ for (const item of result) {
129
+ if (item.status === 'rejected') {
130
+ reasons.error.push(item.reason);
131
+ }
132
+ else {
133
+ reasons.result.push(item.value);
134
+ }
128
135
  }
129
136
  }
130
- }
131
- else {
132
- for (let i = 0; i < list.length; i++) {
133
- const startIndex = (i - 1) * ps.everyLength;
134
- const endIndex = startIndex + list[i].length - 1;
135
- try {
136
- reasons.result.push(await fn(list[i], i, list.length, extendParams[i], startIndex, endIndex));
137
- }
138
- catch (error) {
139
- reasons.error.push(error);
137
+ else {
138
+ for (let i = 0; i < list.length; i++) {
139
+ const startIndex = (i - 1) * ps.everyLength;
140
+ const endIndex = startIndex + list[i].length - 1;
141
+ try {
142
+ reasons.result.push(await fn(list[i], i, list.length, extendParams[i], startIndex, endIndex));
143
+ }
144
+ catch (error) {
145
+ reasons.error.push(error);
146
+ }
140
147
  }
141
148
  }
149
+ resolve(reasons);
150
+ }
151
+ catch (error) {
152
+ reject(error);
142
153
  }
143
- resolve(reasons);
144
154
  });
145
155
  }
146
156
  else if (sync === ExcuteSplitMode.SyncTrust) {
package/cjs/list.js CHANGED
@@ -34,3 +34,27 @@ class ArrayList extends Array {
34
34
  }
35
35
  }
36
36
  exports.ArrayList = ArrayList;
37
+ // export class ArrayMap<T> extends Array<T> {
38
+ // private _map: Map<string, T> = new Map();
39
+ // private key: keyof T;
40
+ // constructor(key: keyof T, array?: Array<T> | T | undefined) {
41
+ // super();
42
+ // this.key = key;
43
+ // if (array instanceof Array) {
44
+ // super.push(...array);
45
+ // } else if (typeof array !== 'undefined') {
46
+ // super.push(array);
47
+ // }
48
+ // }
49
+ // override push(...items: T[]): number {
50
+ // for (const item of items) {
51
+ // const key = item[this.key] as string;
52
+ // if (!this._map.has(key)) {
53
+ // super.push(item);
54
+ // this._map.set(key, item);
55
+ // }
56
+ // }
57
+ // return this.length;
58
+ // }
59
+ // override
60
+ // }
package/cjs/math.d.ts CHANGED
@@ -67,3 +67,17 @@ export declare class Bus {
67
67
  }
68
68
  export declare const calc: (result: any) => Bus;
69
69
  export declare const getGeo: (p1: Point, p2: Point) => number;
70
+ /**
71
+ * 十进制转换自定义进制
72
+ * @param from 数字
73
+ * @param to 自定义进制的字符
74
+ * @returns
75
+ */
76
+ export declare function ten2Any(from: number, to?: string): string;
77
+ /**
78
+ * 自定义进制转换十进制
79
+ * @param from
80
+ * @param to
81
+ * @returns
82
+ */
83
+ export declare function any2Ten(from: string, to?: string): number;
package/cjs/math.js CHANGED
@@ -13,6 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getGeo = exports.calc = exports.Bus = exports.money = exports.merge = exports.round = exports.sub = exports.mul = exports.add = exports.divDef = exports.div = exports.min = exports.max = exports.num = exports.MoneyOption = void 0;
16
+ exports.ten2Any = ten2Any;
17
+ exports.any2Ten = any2Ten;
16
18
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
17
19
  const decimal_js_1 = __importDefault(require("decimal.js"));
18
20
  /** 金钱格式化可用样式 */
@@ -433,3 +435,40 @@ const getGeo = (p1, p2) => {
433
435
  return (0, exports.calc)(Math.round((0, exports.mul)(Math.asin(Math.sqrt((0, exports.add)(Math.pow(Math.sin((0, exports.div)((0, exports.sub)(p1.lat, p2.lat), 2)), 2), (0, exports.mul)(Math.cos(p1.lat), Math.cos(p2.lat), Math.pow(Math.sin((0, exports.div)((0, exports.sub)(p1.long, p2.long), 2)), 2))))), 2, 6378.137, 10000))).div(10000).round(2).over();
434
436
  };
435
437
  exports.getGeo = getGeo;
438
+ const ZM = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
439
+ /**
440
+ * 十进制转换自定义进制
441
+ * @param from 数字
442
+ * @param to 自定义进制的字符
443
+ * @returns
444
+ */
445
+ function ten2Any(from, to = ZM) {
446
+ let result = '';
447
+ const length = to.length;
448
+ while (from > 0) {
449
+ from--;
450
+ let remainder = from % length;
451
+ result = to.charAt(remainder) + result;
452
+ from = Math.floor(from / length);
453
+ }
454
+ return result;
455
+ }
456
+ /**
457
+ * 自定义进制转换十进制
458
+ * @param from
459
+ * @param to
460
+ * @returns
461
+ */
462
+ function any2Ten(from, to = ZM) {
463
+ let decimal = 0;
464
+ from = from.toUpperCase();
465
+ for (let i = 0; i < from.length; i++) {
466
+ const char = from[from.length - 1 - i].toUpperCase();
467
+ const index = to.indexOf(char);
468
+ if (index > -1) {
469
+ const value = to.indexOf(char) + 1;
470
+ decimal += value * Math.pow(26, i);
471
+ }
472
+ }
473
+ return decimal;
474
+ }
package/cjs/set-ex.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare class SetEx<T> extends Set {
6
6
  private _onExist2?;
7
7
  private _onNotExist2?;
8
8
  private _replaceIfExits2;
9
+ private _map;
9
10
  /**
10
11
  * @param key 识别是否存在的对象的属性名
11
12
  * @param onExist 当存在时作何操作? oldData/newData 哪个将添加到set,由replaceItemWhenExits决定,默认是oldData生效
@@ -58,16 +59,16 @@ export declare class SetEx<T> extends Set {
58
59
  addAll2(values: T[]): T[];
59
60
  /**
60
61
  * 用key找到匹配的第一个对象
61
- * @param {*} value 这是对象的关键属性,而非对象
62
+ * @param {*} key 这是对象的关键属性,而非对象
62
63
  * @returns {(T | null)}
63
64
  */
64
- find(value: T[keyof T]): T | null;
65
+ find(key: T[keyof T]): T | null;
65
66
  /**
66
67
  * 用key找到匹配的所有对象
67
- * @param {*} value 这是对象的关键属性,而非对象
68
+ * @param {*} key 这是对象的关键属性,而非对象
68
69
  * @returns {T[]}
69
70
  */
70
- findAll(value: T[keyof T]): T[];
71
+ findAll(key: T[keyof T]): T[];
71
72
  /**
72
73
  *
73
74
  * 用函数回调找到匹配的第一个对象
@@ -88,7 +89,7 @@ export declare class SetEx<T> extends Set {
88
89
  * @param {*} value 这是对象的关键属性,而非对象
89
90
  * @returns {boolean}
90
91
  */
91
- has(value: T[keyof T]): boolean;
92
+ has(key: T[keyof T]): boolean;
92
93
  /**
93
94
  * 转为数组
94
95
  * @param param0
@@ -118,10 +119,10 @@ export declare class SetEx<T> extends Set {
118
119
  /**
119
120
  *
120
121
  * 删除key对应的对象
121
- * @param {*} value 这是对象的关键属性,而非对象
122
+ * @param {*} _key 这是对象的关键属性,而非对象
122
123
  * @returns {boolean}
123
124
  */
124
- delete(value: T[keyof T]): boolean;
125
+ delete(_key: T[keyof T]): boolean;
125
126
  /**
126
127
  *
127
128
  * 重置
package/cjs/set-ex.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.SetEx = void 0;
7
+ const iterare_1 = __importDefault(require("iterare"));
4
8
  class SetEx extends Set {
5
9
  /**
6
10
  * @param key 识别是否存在的对象的属性名
@@ -11,6 +15,7 @@ class SetEx extends Set {
11
15
  */
12
16
  constructor(option) {
13
17
  super();
18
+ this._map = new Map();
14
19
  this._key = option.key;
15
20
  this._onExist1 = option.onExist1;
16
21
  this._onNotExist1 = option.onNotExist1;
@@ -30,21 +35,22 @@ class SetEx extends Set {
30
35
  */
31
36
  add(value) {
32
37
  let flag = false;
33
- this.forEach((item) => {
34
- if (item[this._key] === value[this._key]) {
35
- flag = true;
36
- if (this._onExist1) {
37
- this._onExist1(item, value);
38
- }
39
- if (this._replaceIfExits1 === true) {
40
- super.delete(item);
41
- flag = false;
42
- }
43
- return false;
38
+ const key = value[this._key];
39
+ const item = this._map.get(key);
40
+ if (item) {
41
+ flag = true;
42
+ if (this._onExist1) {
43
+ this._onExist1(item, value);
44
44
  }
45
- });
45
+ if (this._replaceIfExits1 === true) {
46
+ super.delete(item);
47
+ this._map.delete(key);
48
+ flag = false;
49
+ }
50
+ }
46
51
  if (flag === false) {
47
52
  super.add(value);
53
+ this._map.set(key, value);
48
54
  if (this._onNotExist1) {
49
55
  this._onNotExist1(value);
50
56
  }
@@ -70,25 +76,26 @@ class SetEx extends Set {
70
76
  */
71
77
  add2(value) {
72
78
  let flag = false;
79
+ const key = value[this._key];
80
+ const item = this._map.get(key);
73
81
  let tmp = value;
74
- this.forEach((item) => {
75
- if (item[this._key] === value[this._key]) {
76
- flag = true;
77
- if (this._onExist2) {
78
- this._onExist2(item, value);
79
- }
80
- if (this._replaceIfExits2 === true) {
81
- super.delete(value);
82
- flag = false;
83
- }
84
- else {
85
- tmp = item;
86
- }
87
- return false;
82
+ if (item) {
83
+ flag = true;
84
+ if (this._onExist2) {
85
+ this._onExist2(item, value);
88
86
  }
89
- });
87
+ if (this._replaceIfExits2 === true) {
88
+ super.delete(value);
89
+ this._map.delete(key);
90
+ flag = false;
91
+ }
92
+ else {
93
+ tmp = item;
94
+ }
95
+ }
90
96
  if (flag === false) {
91
97
  super.add(value);
98
+ this._map.set(key, value);
92
99
  if (this._onNotExist2) {
93
100
  this._onNotExist2(value);
94
101
  }
@@ -110,30 +117,19 @@ class SetEx extends Set {
110
117
  }
111
118
  /**
112
119
  * 用key找到匹配的第一个对象
113
- * @param {*} value 这是对象的关键属性,而非对象
120
+ * @param {*} key 这是对象的关键属性,而非对象
114
121
  * @returns {(T | null)}
115
122
  */
116
- find(value) {
117
- for (const item of this) {
118
- if (item[this._key] === value) {
119
- return item;
120
- }
121
- }
122
- return null;
123
+ find(key) {
124
+ return this._map.get(key) ?? null;
123
125
  }
124
126
  /**
125
127
  * 用key找到匹配的所有对象
126
- * @param {*} value 这是对象的关键属性,而非对象
128
+ * @param {*} key 这是对象的关键属性,而非对象
127
129
  * @returns {T[]}
128
130
  */
129
- findAll(value) {
130
- const res = new Array();
131
- this.forEach((item) => {
132
- if (item[this._key] === value) {
133
- res.push(item);
134
- }
135
- });
136
- return res;
131
+ findAll(key) {
132
+ return (0, iterare_1.default)(key).map(k => this._map.get(k)).filter(v => v !== undefined).toArray();
137
133
  }
138
134
  /**
139
135
  *
@@ -170,13 +166,8 @@ class SetEx extends Set {
170
166
  * @param {*} value 这是对象的关键属性,而非对象
171
167
  * @returns {boolean}
172
168
  */
173
- has(value) {
174
- for (const item of this) {
175
- if (item[this._key] === value) {
176
- return true;
177
- }
178
- }
179
- return false;
169
+ has(key) {
170
+ return this._map.has(key);
180
171
  }
181
172
  /**
182
173
  * 转为数组
@@ -212,15 +203,16 @@ class SetEx extends Set {
212
203
  /**
213
204
  *
214
205
  * 删除key对应的对象
215
- * @param {*} value 这是对象的关键属性,而非对象
206
+ * @param {*} _key 这是对象的关键属性,而非对象
216
207
  * @returns {boolean}
217
208
  */
218
- delete(value) {
219
- for (const item of this) {
220
- if (item[this._key] === value) {
221
- super.delete(item);
222
- return true;
223
- }
209
+ delete(_key) {
210
+ const key = _key;
211
+ const item = this._map.get(key);
212
+ if (item) {
213
+ super.delete(item);
214
+ this._map.delete(key);
215
+ return true;
224
216
  }
225
217
  return false;
226
218
  }
@@ -233,6 +225,7 @@ class SetEx extends Set {
233
225
  */
234
226
  reset(option) {
235
227
  this.clear();
228
+ this._map.clear();
236
229
  if (option.key) {
237
230
  this._key = option.key;
238
231
  }