baja-lite 1.0.4 → 1.0.6

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.
Files changed (85) hide show
  1. package/cjs/boot-remote.d.ts +2 -0
  2. package/cjs/boot-remote.js +35 -0
  3. package/cjs/boot.d.ts +2 -0
  4. package/cjs/boot.js +152 -0
  5. package/cjs/code.d.ts +1 -0
  6. package/cjs/code.js +359 -1
  7. package/cjs/convert-xml.d.ts +10 -0
  8. package/cjs/convert-xml.js +414 -0
  9. package/cjs/enum.d.ts +10 -0
  10. package/cjs/enum.js +32 -0
  11. package/cjs/error.js +1 -1
  12. package/cjs/fn.js +3 -3
  13. package/cjs/index.d.ts +3 -0
  14. package/cjs/index.js +3 -0
  15. package/cjs/list.d.ts +10 -0
  16. package/cjs/list.js +36 -0
  17. package/cjs/object.d.ts +7 -1
  18. package/cjs/object.js +36 -2
  19. package/cjs/set-ex.d.ts +41 -15
  20. package/cjs/set-ex.js +68 -52
  21. package/cjs/sql.d.ts +760 -305
  22. package/cjs/sql.js +1702 -1041
  23. package/cjs/sqlite.d.ts +38 -0
  24. package/cjs/sqlite.js +194 -0
  25. package/cjs/test-mysql.d.ts +2 -1
  26. package/cjs/test-mysql.js +85 -63
  27. package/cjs/test-sqlite.d.ts +1 -1
  28. package/cjs/test-sqlite.js +3 -1
  29. package/cjs/test-xml.d.ts +1 -0
  30. package/cjs/test-xml.js +75 -0
  31. package/es/boot-remote.d.ts +2 -0
  32. package/es/boot-remote.js +31 -0
  33. package/es/boot.d.ts +2 -0
  34. package/es/boot.js +125 -0
  35. package/es/code.d.ts +1 -0
  36. package/es/code.js +355 -2
  37. package/es/convert-xml.d.ts +10 -0
  38. package/es/convert-xml.js +410 -0
  39. package/es/enum.d.ts +10 -0
  40. package/es/enum.js +28 -0
  41. package/es/error.js +1 -1
  42. package/es/index.d.ts +3 -0
  43. package/es/index.js +3 -0
  44. package/es/list.d.ts +10 -0
  45. package/es/list.js +32 -0
  46. package/es/object.d.ts +7 -1
  47. package/es/object.js +28 -1
  48. package/es/set-ex.d.ts +41 -15
  49. package/es/set-ex.js +68 -52
  50. package/es/sql.d.ts +760 -305
  51. package/es/sql.js +1573 -917
  52. package/es/sqlite.d.ts +38 -0
  53. package/es/sqlite.js +164 -0
  54. package/es/test-mysql.d.ts +2 -1
  55. package/es/test-mysql.js +85 -64
  56. package/es/test-sqlite.d.ts +1 -1
  57. package/es/test-sqlite.js +3 -1
  58. package/es/test-xml.d.ts +1 -0
  59. package/es/test-xml.js +70 -0
  60. package/package.json +15 -10
  61. package/src/boot-remote.ts +31 -0
  62. package/src/boot.ts +129 -0
  63. package/src/code.ts +342 -1
  64. package/src/convert-xml.ts +462 -0
  65. package/src/enum.ts +31 -0
  66. package/src/error.ts +1 -1
  67. package/src/index.ts +4 -1
  68. package/src/list.ts +31 -0
  69. package/src/object.ts +48 -14
  70. package/src/set-ex.ts +91 -70
  71. package/src/sql.ts +1652 -965
  72. package/src/sqlite.ts +161 -0
  73. package/src/test-mysql.ts +93 -65
  74. package/src/test-sqlite.ts +3 -1
  75. package/src/test-xml.ts +70 -0
  76. package/cjs/constant.d.ts +0 -13
  77. package/cjs/constant.js +0 -19
  78. package/cjs/redis.d.ts +0 -0
  79. package/cjs/redis.js +0 -1
  80. package/es/constant.d.ts +0 -13
  81. package/es/constant.js +0 -16
  82. package/es/redis.d.ts +0 -0
  83. package/es/redis.js +0 -1
  84. package/src/constant.ts +0 -14
  85. package/src/redis.ts +0 -0
package/src/set-ex.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  export class SetEx<T> extends Set {
2
- private uniqueKey: keyof T;
3
- private whenOnExist?: (oldData: T, newData: T) => void | null;
4
- private whenOnNotExist?: (newData: T) => void | null;
5
- private replaceItemWhenExits: boolean;
2
+ private _key: keyof T;
3
+ private _onExist1?: (oldData: T, newData: T) => void | null;
4
+ private _onNotExist1?: (newData: T) => void | null;
5
+ private _replaceIfExits1: boolean;
6
+ private _onExist2?: (oldData: T, newData: T) => void | null;
7
+ private _onNotExist2?: (newData: T) => void | null;
8
+ private _replaceIfExits2: boolean;
6
9
  /**
7
10
  * @param key 识别是否存在的对象的属性名
8
11
  * @param onExist 当存在时作何操作? oldData/newData 哪个将添加到set,由replaceItemWhenExits决定,默认是oldData生效
@@ -11,35 +14,33 @@ export class SetEx<T> extends Set {
11
14
  * @param values 初始数组
12
15
  */
13
16
  constructor(
14
- key: keyof T | {
17
+ option: {
15
18
  key: keyof T;
16
- onExist?: (oldData: T, newData: T) => void;
17
- onNotExist?: (newData: T) => void;
18
- replaceWhenExits?: boolean;
19
+ /** add&addAll触发 */
20
+ onExist1?: (oldData: T, newData: T) => void;
21
+ /** add&addAll触发 */
22
+ onNotExist1?: (newData: T) => void;
23
+ /** add&addAll触发 */
24
+ replaceIfExits1?: boolean;
25
+ /** add2&addAll2触发 */
26
+ onExist2?: (oldData: T, newData: T) => void;
27
+ /** add2&addAll2触发 */
28
+ onNotExist2?: (newData: T) => void;
29
+ /** add2&addAll2触发 */
30
+ replaceIfExits2?: boolean;
19
31
  values?: ReadonlyArray<T> | null;
20
- },
21
- onExist?: (oldData: T, newData: T) => void,
22
- replaceWhenExits = false,
23
- values?: ReadonlyArray<T> | null,
24
- onNotExist?: (newData: T) => void
32
+ }
25
33
  ) {
26
34
  super();
27
- if (typeof key === 'object') {
28
- this.whenOnExist = key.onExist;
29
- this.uniqueKey = key.key;
30
- this.replaceItemWhenExits = key.replaceWhenExits === true;
31
- this.whenOnNotExist = key.onNotExist;
32
- if (key.values) {
33
- this.addAll(...key.values);
34
- }
35
- } else {
36
- this.whenOnExist = onExist;
37
- this.uniqueKey = key;
38
- this.replaceItemWhenExits = replaceWhenExits;
39
- this.whenOnNotExist = onNotExist;
40
- if (values) {
41
- this.addAll(...values);
42
- }
35
+ this._key = option.key;
36
+ this._onExist1 = option.onExist1;
37
+ this._onNotExist1 = option.onNotExist1;
38
+ this._replaceIfExits1 = option.replaceIfExits1 === true;
39
+ this._onExist2 = option.onExist2;
40
+ this._onNotExist2 = option.onNotExist2;
41
+ this._replaceIfExits2 = option.replaceIfExits2 === true;
42
+ if (option.values) {
43
+ this.addAll(...option.values);
43
44
  }
44
45
  }
45
46
 
@@ -52,12 +53,12 @@ export class SetEx<T> extends Set {
52
53
  override add(value: T): this {
53
54
  let flag = false;
54
55
  this.forEach((item: T): any => {
55
- if (item[this.uniqueKey] === value[this.uniqueKey]) {
56
+ if (item[this._key] === value[this._key]) {
56
57
  flag = true;
57
- if (this.whenOnExist) {
58
- this.whenOnExist(item, value);
58
+ if (this._onExist1) {
59
+ this._onExist1(item, value);
59
60
  }
60
- if (this.replaceItemWhenExits === true) {
61
+ if (this._replaceIfExits1 === true) {
61
62
  super.delete(item);
62
63
  flag = false;
63
64
  }
@@ -66,8 +67,8 @@ export class SetEx<T> extends Set {
66
67
  });
67
68
  if (flag === false) {
68
69
  super.add(value);
69
- if (this.whenOnNotExist) {
70
- this.whenOnNotExist(value);
70
+ if (this._onNotExist1) {
71
+ this._onNotExist1(value);
71
72
  }
72
73
  }
73
74
  return this;
@@ -93,13 +94,13 @@ export class SetEx<T> extends Set {
93
94
  let flag = false;
94
95
  let tmp = value;
95
96
  this.forEach((item: T): any => {
96
- if (item[this.uniqueKey] === value[this.uniqueKey]) {
97
+ if (item[this._key] === value[this._key]) {
97
98
  flag = true;
98
- if (this.whenOnExist) {
99
- this.whenOnExist(item, value);
99
+ if (this._onExist2) {
100
+ this._onExist2(item, value);
100
101
  }
101
- if (this.replaceItemWhenExits === true) {
102
- super.delete(item);
102
+ if (this._replaceIfExits2 === true) {
103
+ super.delete(value);
103
104
  flag = false;
104
105
  } else {
105
106
  tmp = item;
@@ -109,8 +110,8 @@ export class SetEx<T> extends Set {
109
110
  });
110
111
  if (flag === false) {
111
112
  super.add(value);
112
- if (this.whenOnNotExist) {
113
- this.whenOnNotExist(value);
113
+ if (this._onNotExist2) {
114
+ this._onNotExist2(value);
114
115
  }
115
116
  }
116
117
  return tmp;
@@ -135,7 +136,7 @@ export class SetEx<T> extends Set {
135
136
  */
136
137
  find(value: T[keyof T]): T | null {
137
138
  for (const item of this) {
138
- if (item[this.uniqueKey] === value) {
139
+ if (item[this._key] === value) {
139
140
  return item;
140
141
  }
141
142
  }
@@ -149,7 +150,7 @@ export class SetEx<T> extends Set {
149
150
  findAll(value: T[keyof T]): T[] {
150
151
  const res = new Array<T>();
151
152
  this.forEach((item) => {
152
- if (item[this.uniqueKey] === value) {
153
+ if (item[this._key] === value) {
153
154
  res.push(item);
154
155
  }
155
156
  });
@@ -190,9 +191,9 @@ export class SetEx<T> extends Set {
190
191
  * @param {*} value 这是对象的关键属性,而非对象
191
192
  * @returns {boolean}
192
193
  */
193
- override has(value: T[keyof T]): boolean {
194
+ override has(value: T[keyof T] ): boolean {
194
195
  for (const item of this) {
195
- if (item[this.uniqueKey] === value) {
196
+ if (item[this._key] === value) {
196
197
  return true;
197
198
  }
198
199
  }
@@ -239,7 +240,7 @@ export class SetEx<T> extends Set {
239
240
  */
240
241
  override delete(value: T[keyof T]): boolean {
241
242
  for (const item of this) {
242
- if (item[this.uniqueKey] === value) {
243
+ if (item[this._key] === value) {
243
244
  super.delete(item);
244
245
  return true;
245
246
  }
@@ -253,25 +254,33 @@ export class SetEx<T> extends Set {
253
254
  * @param {(oldData: T, newData: T) => void} [onExist]
254
255
  * @param {boolean} [replaceWhenExits=false]
255
256
  */
256
- reset({ key, onExist, onNotExist, replaceWhenExits }: {
257
+ reset(option: {
257
258
  key?: keyof T;
258
- onExist?: (oldData: T, newData: T) => void | null;
259
- onNotExist?: (newData: T) => void | null;
260
- replaceWhenExits?: boolean;
259
+ /** add&addAll触发 */
260
+ onExist1?: (oldData: T, newData: T) => void;
261
+ /** add&addAll触发 */
262
+ onNotExist1?: (newData: T) => void;
263
+ /** add&addAll触发 */
264
+ replaceIfExits1?: boolean;
265
+ /** add2&addAll2触发 */
266
+ onExist2?: (oldData: T, newData: T) => void;
267
+ /** add2&addAll2触发 */
268
+ onNotExist2?: (newData: T) => void;
269
+ /** add2&addAll2触发 */
270
+ replaceIfExits2?: boolean;
271
+ values?: ReadonlyArray<T> | null;
261
272
  }): this {
262
- if (onExist !== undefined) {
263
- this.whenOnExist = onExist;
264
- }
265
- if (onNotExist !== undefined) {
266
- this.whenOnNotExist = onNotExist;
267
- }
268
- if (key) {
269
- this.uniqueKey = key;
270
- }
271
- if (replaceWhenExits !== undefined) {
272
- this.replaceItemWhenExits = replaceWhenExits;
273
- }
274
273
  this.clear();
274
+ if (option.key) { this._key = option.key; }
275
+ if (option.onExist1) { this._onExist1 = option.onExist1; }
276
+ if (option.onNotExist1) { this._onNotExist1 = option.onNotExist1; }
277
+ if (option.replaceIfExits1) { this._replaceIfExits1 = option.replaceIfExits1; }
278
+ if (option.onExist2) { this._onExist2 = option.onExist2; }
279
+ if (option.onNotExist2) { this._onNotExist2 = option.onNotExist2; }
280
+ if (option.replaceIfExits2) { this._replaceIfExits2 = option.replaceIfExits2; }
281
+ if (option.values) {
282
+ this.addAll(...option.values);
283
+ }
275
284
  return this;
276
285
  }
277
286
  /**
@@ -339,7 +348,7 @@ export class SetEx<T> extends Set {
339
348
  const result: { [k: string]: { value: T[keyof T], name: T[keyof T] }[] } = {};
340
349
  const list = this.toArray({ sort, each, filter, map });
341
350
  for (const item of list) {
342
- const name = item[this.uniqueKey];
351
+ const name = item[this._key];
343
352
  for (const key in item) {
344
353
  if (!result[key]) {
345
354
  result[key] = [];
@@ -350,13 +359,25 @@ export class SetEx<T> extends Set {
350
359
  return result;
351
360
  }
352
361
 
353
- set onExist(onExist: ((oldData: T, newData: T) => void) | undefined) {
354
- this.whenOnExist = onExist;
362
+ set onExist1(onExist1: ((oldData: T, newData: T) => void) | undefined) {
363
+ this._onExist1 = onExist1;
355
364
  }
356
- set key(key: keyof T) {
357
- this.uniqueKey = key;
365
+ set onExist2(onExist2: ((oldData: T, newData: T) => void) | undefined) {
366
+ this._onExist2 = onExist2;
367
+ }
368
+ set onNotExist1(onNotExist1: ((newData: T) => void) | undefined) {
369
+ this._onNotExist1 = onNotExist1;
370
+ }
371
+ set onNotExist2(onNotExist2: ((newData: T) => void) | undefined) {
372
+ this._onNotExist2 = onNotExist2;
358
373
  }
359
- set replaceWhenExits(replaceWhenExits: boolean) {
360
- this.replaceItemWhenExits = replaceWhenExits;
374
+ set replaceIfExits1(replaceIfExits1: boolean) {
375
+ this._replaceIfExits1 = replaceIfExits1;
376
+ }
377
+ set replaceIfExits2(replaceIfExits2: boolean) {
378
+ this._replaceIfExits2 = replaceIfExits2;
379
+ }
380
+ set key(key: keyof T) {
381
+ this._key = key;
361
382
  }
362
383
  }