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/es/set-ex.js CHANGED
@@ -6,25 +6,17 @@ export class SetEx extends Set {
6
6
  * @param replaceWhenExits 当存在时是否覆盖?
7
7
  * @param values 初始数组
8
8
  */
9
- constructor(key, onExist, replaceWhenExits = false, values, onNotExist) {
9
+ constructor(option) {
10
10
  super();
11
- if (typeof key === 'object') {
12
- this.whenOnExist = key.onExist;
13
- this.uniqueKey = key.key;
14
- this.replaceItemWhenExits = key.replaceWhenExits === true;
15
- this.whenOnNotExist = key.onNotExist;
16
- if (key.values) {
17
- this.addAll(...key.values);
18
- }
19
- }
20
- else {
21
- this.whenOnExist = onExist;
22
- this.uniqueKey = key;
23
- this.replaceItemWhenExits = replaceWhenExits;
24
- this.whenOnNotExist = onNotExist;
25
- if (values) {
26
- this.addAll(...values);
27
- }
11
+ this._key = option.key;
12
+ this._onExist1 = option.onExist1;
13
+ this._onNotExist1 = option.onNotExist1;
14
+ this._replaceIfExits1 = option.replaceIfExits1 === true;
15
+ this._onExist2 = option.onExist2;
16
+ this._onNotExist2 = option.onNotExist2;
17
+ this._replaceIfExits2 = option.replaceIfExits2 === true;
18
+ if (option.values) {
19
+ this.addAll(...option.values);
28
20
  }
29
21
  }
30
22
  /**
@@ -36,12 +28,12 @@ export class SetEx extends Set {
36
28
  add(value) {
37
29
  let flag = false;
38
30
  this.forEach((item) => {
39
- if (item[this.uniqueKey] === value[this.uniqueKey]) {
31
+ if (item[this._key] === value[this._key]) {
40
32
  flag = true;
41
- if (this.whenOnExist) {
42
- this.whenOnExist(item, value);
33
+ if (this._onExist1) {
34
+ this._onExist1(item, value);
43
35
  }
44
- if (this.replaceItemWhenExits === true) {
36
+ if (this._replaceIfExits1 === true) {
45
37
  super.delete(item);
46
38
  flag = false;
47
39
  }
@@ -50,8 +42,8 @@ export class SetEx extends Set {
50
42
  });
51
43
  if (flag === false) {
52
44
  super.add(value);
53
- if (this.whenOnNotExist) {
54
- this.whenOnNotExist(value);
45
+ if (this._onNotExist1) {
46
+ this._onNotExist1(value);
55
47
  }
56
48
  }
57
49
  return this;
@@ -77,13 +69,13 @@ export class SetEx extends Set {
77
69
  let flag = false;
78
70
  let tmp = value;
79
71
  this.forEach((item) => {
80
- if (item[this.uniqueKey] === value[this.uniqueKey]) {
72
+ if (item[this._key] === value[this._key]) {
81
73
  flag = true;
82
- if (this.whenOnExist) {
83
- this.whenOnExist(item, value);
74
+ if (this._onExist2) {
75
+ this._onExist2(item, value);
84
76
  }
85
- if (this.replaceItemWhenExits === true) {
86
- super.delete(item);
77
+ if (this._replaceIfExits2 === true) {
78
+ super.delete(value);
87
79
  flag = false;
88
80
  }
89
81
  else {
@@ -94,8 +86,8 @@ export class SetEx extends Set {
94
86
  });
95
87
  if (flag === false) {
96
88
  super.add(value);
97
- if (this.whenOnNotExist) {
98
- this.whenOnNotExist(value);
89
+ if (this._onNotExist2) {
90
+ this._onNotExist2(value);
99
91
  }
100
92
  }
101
93
  return tmp;
@@ -120,7 +112,7 @@ export class SetEx extends Set {
120
112
  */
121
113
  find(value) {
122
114
  for (const item of this) {
123
- if (item[this.uniqueKey] === value) {
115
+ if (item[this._key] === value) {
124
116
  return item;
125
117
  }
126
118
  }
@@ -134,7 +126,7 @@ export class SetEx extends Set {
134
126
  findAll(value) {
135
127
  const res = new Array();
136
128
  this.forEach((item) => {
137
- if (item[this.uniqueKey] === value) {
129
+ if (item[this._key] === value) {
138
130
  res.push(item);
139
131
  }
140
132
  });
@@ -177,7 +169,7 @@ export class SetEx extends Set {
177
169
  */
178
170
  has(value) {
179
171
  for (const item of this) {
180
- if (item[this.uniqueKey] === value) {
172
+ if (item[this._key] === value) {
181
173
  return true;
182
174
  }
183
175
  }
@@ -222,7 +214,7 @@ export class SetEx extends Set {
222
214
  */
223
215
  delete(value) {
224
216
  for (const item of this) {
225
- if (item[this.uniqueKey] === value) {
217
+ if (item[this._key] === value) {
226
218
  super.delete(item);
227
219
  return true;
228
220
  }
@@ -236,20 +228,32 @@ export class SetEx extends Set {
236
228
  * @param {(oldData: T, newData: T) => void} [onExist]
237
229
  * @param {boolean} [replaceWhenExits=false]
238
230
  */
239
- reset({ key, onExist, onNotExist, replaceWhenExits }) {
240
- if (onExist !== undefined) {
241
- this.whenOnExist = onExist;
231
+ reset(option) {
232
+ this.clear();
233
+ if (option.key) {
234
+ this._key = option.key;
242
235
  }
243
- if (onNotExist !== undefined) {
244
- this.whenOnNotExist = onNotExist;
236
+ if (option.onExist1) {
237
+ this._onExist1 = option.onExist1;
245
238
  }
246
- if (key) {
247
- this.uniqueKey = key;
239
+ if (option.onNotExist1) {
240
+ this._onNotExist1 = option.onNotExist1;
248
241
  }
249
- if (replaceWhenExits !== undefined) {
250
- this.replaceItemWhenExits = replaceWhenExits;
242
+ if (option.replaceIfExits1) {
243
+ this._replaceIfExits1 = option.replaceIfExits1;
244
+ }
245
+ if (option.onExist2) {
246
+ this._onExist2 = option.onExist2;
247
+ }
248
+ if (option.onNotExist2) {
249
+ this._onNotExist2 = option.onNotExist2;
250
+ }
251
+ if (option.replaceIfExits2) {
252
+ this._replaceIfExits2 = option.replaceIfExits2;
253
+ }
254
+ if (option.values) {
255
+ this.addAll(...option.values);
251
256
  }
252
- this.clear();
253
257
  return this;
254
258
  }
255
259
  /**
@@ -310,7 +314,7 @@ export class SetEx extends Set {
310
314
  const result = {};
311
315
  const list = this.toArray({ sort, each, filter, map });
312
316
  for (const item of list) {
313
- const name = item[this.uniqueKey];
317
+ const name = item[this._key];
314
318
  for (const key in item) {
315
319
  if (!result[key]) {
316
320
  result[key] = [];
@@ -320,13 +324,25 @@ export class SetEx extends Set {
320
324
  }
321
325
  return result;
322
326
  }
323
- set onExist(onExist) {
324
- this.whenOnExist = onExist;
327
+ set onExist1(onExist1) {
328
+ this._onExist1 = onExist1;
325
329
  }
326
- set key(key) {
327
- this.uniqueKey = key;
330
+ set onExist2(onExist2) {
331
+ this._onExist2 = onExist2;
332
+ }
333
+ set onNotExist1(onNotExist1) {
334
+ this._onNotExist1 = onNotExist1;
328
335
  }
329
- set replaceWhenExits(replaceWhenExits) {
330
- this.replaceItemWhenExits = replaceWhenExits;
336
+ set onNotExist2(onNotExist2) {
337
+ this._onNotExist2 = onNotExist2;
338
+ }
339
+ set replaceIfExits1(replaceIfExits1) {
340
+ this._replaceIfExits1 = replaceIfExits1;
341
+ }
342
+ set replaceIfExits2(replaceIfExits2) {
343
+ this._replaceIfExits2 = replaceIfExits2;
344
+ }
345
+ set key(key) {
346
+ this._key = key;
331
347
  }
332
348
  }