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/cjs/set-ex.d.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  export declare class SetEx<T> extends Set {
2
- private uniqueKey;
3
- private whenOnExist?;
4
- private whenOnNotExist?;
5
- private replaceItemWhenExits;
2
+ private _key;
3
+ private _onExist1?;
4
+ private _onNotExist1?;
5
+ private _replaceIfExits1;
6
+ private _onExist2?;
7
+ private _onNotExist2?;
8
+ private _replaceIfExits2;
6
9
  /**
7
10
  * @param key 识别是否存在的对象的属性名
8
11
  * @param onExist 当存在时作何操作? oldData/newData 哪个将添加到set,由replaceItemWhenExits决定,默认是oldData生效
@@ -10,13 +13,22 @@ export declare class SetEx<T> extends Set {
10
13
  * @param replaceWhenExits 当存在时是否覆盖?
11
14
  * @param values 初始数组
12
15
  */
13
- constructor(key: keyof T | {
16
+ constructor(option: {
14
17
  key: keyof T;
15
- onExist?: (oldData: T, newData: T) => void;
16
- onNotExist?: (newData: T) => void;
17
- replaceWhenExits?: boolean;
18
+ /** add&addAll触发 */
19
+ onExist1?: (oldData: T, newData: T) => void;
20
+ /** add&addAll触发 */
21
+ onNotExist1?: (newData: T) => void;
22
+ /** add&addAll触发 */
23
+ replaceIfExits1?: boolean;
24
+ /** add2&addAll2触发 */
25
+ onExist2?: (oldData: T, newData: T) => void;
26
+ /** add2&addAll2触发 */
27
+ onNotExist2?: (newData: T) => void;
28
+ /** add2&addAll2触发 */
29
+ replaceIfExits2?: boolean;
18
30
  values?: ReadonlyArray<T> | null;
19
- }, onExist?: (oldData: T, newData: T) => void, replaceWhenExits?: boolean, values?: ReadonlyArray<T> | null, onNotExist?: (newData: T) => void);
31
+ });
20
32
  /**
21
33
  *
22
34
  * 添加返回
@@ -117,11 +129,21 @@ export declare class SetEx<T> extends Set {
117
129
  * @param {(oldData: T, newData: T) => void} [onExist]
118
130
  * @param {boolean} [replaceWhenExits=false]
119
131
  */
120
- reset({ key, onExist, onNotExist, replaceWhenExits }: {
132
+ reset(option: {
121
133
  key?: keyof T;
122
- onExist?: (oldData: T, newData: T) => void | null;
123
- onNotExist?: (newData: T) => void | null;
124
- replaceWhenExits?: boolean;
134
+ /** add&addAll触发 */
135
+ onExist1?: (oldData: T, newData: T) => void;
136
+ /** add&addAll触发 */
137
+ onNotExist1?: (newData: T) => void;
138
+ /** add&addAll触发 */
139
+ replaceIfExits1?: boolean;
140
+ /** add2&addAll2触发 */
141
+ onExist2?: (oldData: T, newData: T) => void;
142
+ /** add2&addAll2触发 */
143
+ onNotExist2?: (newData: T) => void;
144
+ /** add2&addAll2触发 */
145
+ replaceIfExits2?: boolean;
146
+ values?: ReadonlyArray<T> | null;
125
147
  }): this;
126
148
  /**
127
149
  *
@@ -165,7 +187,11 @@ export declare class SetEx<T> extends Set {
165
187
  name: T[keyof T];
166
188
  }[];
167
189
  };
168
- set onExist(onExist: ((oldData: T, newData: T) => void) | undefined);
190
+ set onExist1(onExist1: ((oldData: T, newData: T) => void) | undefined);
191
+ set onExist2(onExist2: ((oldData: T, newData: T) => void) | undefined);
192
+ set onNotExist1(onNotExist1: ((newData: T) => void) | undefined);
193
+ set onNotExist2(onNotExist2: ((newData: T) => void) | undefined);
194
+ set replaceIfExits1(replaceIfExits1: boolean);
195
+ set replaceIfExits2(replaceIfExits2: boolean);
169
196
  set key(key: keyof T);
170
- set replaceWhenExits(replaceWhenExits: boolean);
171
197
  }
package/cjs/set-ex.js CHANGED
@@ -9,25 +9,17 @@ class SetEx extends Set {
9
9
  * @param replaceWhenExits 当存在时是否覆盖?
10
10
  * @param values 初始数组
11
11
  */
12
- constructor(key, onExist, replaceWhenExits = false, values, onNotExist) {
12
+ constructor(option) {
13
13
  super();
14
- if (typeof key === 'object') {
15
- this.whenOnExist = key.onExist;
16
- this.uniqueKey = key.key;
17
- this.replaceItemWhenExits = key.replaceWhenExits === true;
18
- this.whenOnNotExist = key.onNotExist;
19
- if (key.values) {
20
- this.addAll(...key.values);
21
- }
22
- }
23
- else {
24
- this.whenOnExist = onExist;
25
- this.uniqueKey = key;
26
- this.replaceItemWhenExits = replaceWhenExits;
27
- this.whenOnNotExist = onNotExist;
28
- if (values) {
29
- this.addAll(...values);
30
- }
14
+ this._key = option.key;
15
+ this._onExist1 = option.onExist1;
16
+ this._onNotExist1 = option.onNotExist1;
17
+ this._replaceIfExits1 = option.replaceIfExits1 === true;
18
+ this._onExist2 = option.onExist2;
19
+ this._onNotExist2 = option.onNotExist2;
20
+ this._replaceIfExits2 = option.replaceIfExits2 === true;
21
+ if (option.values) {
22
+ this.addAll(...option.values);
31
23
  }
32
24
  }
33
25
  /**
@@ -39,12 +31,12 @@ class SetEx extends Set {
39
31
  add(value) {
40
32
  let flag = false;
41
33
  this.forEach((item) => {
42
- if (item[this.uniqueKey] === value[this.uniqueKey]) {
34
+ if (item[this._key] === value[this._key]) {
43
35
  flag = true;
44
- if (this.whenOnExist) {
45
- this.whenOnExist(item, value);
36
+ if (this._onExist1) {
37
+ this._onExist1(item, value);
46
38
  }
47
- if (this.replaceItemWhenExits === true) {
39
+ if (this._replaceIfExits1 === true) {
48
40
  super.delete(item);
49
41
  flag = false;
50
42
  }
@@ -53,8 +45,8 @@ class SetEx extends Set {
53
45
  });
54
46
  if (flag === false) {
55
47
  super.add(value);
56
- if (this.whenOnNotExist) {
57
- this.whenOnNotExist(value);
48
+ if (this._onNotExist1) {
49
+ this._onNotExist1(value);
58
50
  }
59
51
  }
60
52
  return this;
@@ -80,13 +72,13 @@ class SetEx extends Set {
80
72
  let flag = false;
81
73
  let tmp = value;
82
74
  this.forEach((item) => {
83
- if (item[this.uniqueKey] === value[this.uniqueKey]) {
75
+ if (item[this._key] === value[this._key]) {
84
76
  flag = true;
85
- if (this.whenOnExist) {
86
- this.whenOnExist(item, value);
77
+ if (this._onExist2) {
78
+ this._onExist2(item, value);
87
79
  }
88
- if (this.replaceItemWhenExits === true) {
89
- super.delete(item);
80
+ if (this._replaceIfExits2 === true) {
81
+ super.delete(value);
90
82
  flag = false;
91
83
  }
92
84
  else {
@@ -97,8 +89,8 @@ class SetEx extends Set {
97
89
  });
98
90
  if (flag === false) {
99
91
  super.add(value);
100
- if (this.whenOnNotExist) {
101
- this.whenOnNotExist(value);
92
+ if (this._onNotExist2) {
93
+ this._onNotExist2(value);
102
94
  }
103
95
  }
104
96
  return tmp;
@@ -123,7 +115,7 @@ class SetEx extends Set {
123
115
  */
124
116
  find(value) {
125
117
  for (const item of this) {
126
- if (item[this.uniqueKey] === value) {
118
+ if (item[this._key] === value) {
127
119
  return item;
128
120
  }
129
121
  }
@@ -137,7 +129,7 @@ class SetEx extends Set {
137
129
  findAll(value) {
138
130
  const res = new Array();
139
131
  this.forEach((item) => {
140
- if (item[this.uniqueKey] === value) {
132
+ if (item[this._key] === value) {
141
133
  res.push(item);
142
134
  }
143
135
  });
@@ -180,7 +172,7 @@ class SetEx extends Set {
180
172
  */
181
173
  has(value) {
182
174
  for (const item of this) {
183
- if (item[this.uniqueKey] === value) {
175
+ if (item[this._key] === value) {
184
176
  return true;
185
177
  }
186
178
  }
@@ -225,7 +217,7 @@ class SetEx extends Set {
225
217
  */
226
218
  delete(value) {
227
219
  for (const item of this) {
228
- if (item[this.uniqueKey] === value) {
220
+ if (item[this._key] === value) {
229
221
  super.delete(item);
230
222
  return true;
231
223
  }
@@ -239,20 +231,32 @@ class SetEx extends Set {
239
231
  * @param {(oldData: T, newData: T) => void} [onExist]
240
232
  * @param {boolean} [replaceWhenExits=false]
241
233
  */
242
- reset({ key, onExist, onNotExist, replaceWhenExits }) {
243
- if (onExist !== undefined) {
244
- this.whenOnExist = onExist;
234
+ reset(option) {
235
+ this.clear();
236
+ if (option.key) {
237
+ this._key = option.key;
245
238
  }
246
- if (onNotExist !== undefined) {
247
- this.whenOnNotExist = onNotExist;
239
+ if (option.onExist1) {
240
+ this._onExist1 = option.onExist1;
248
241
  }
249
- if (key) {
250
- this.uniqueKey = key;
242
+ if (option.onNotExist1) {
243
+ this._onNotExist1 = option.onNotExist1;
251
244
  }
252
- if (replaceWhenExits !== undefined) {
253
- this.replaceItemWhenExits = replaceWhenExits;
245
+ if (option.replaceIfExits1) {
246
+ this._replaceIfExits1 = option.replaceIfExits1;
247
+ }
248
+ if (option.onExist2) {
249
+ this._onExist2 = option.onExist2;
250
+ }
251
+ if (option.onNotExist2) {
252
+ this._onNotExist2 = option.onNotExist2;
253
+ }
254
+ if (option.replaceIfExits2) {
255
+ this._replaceIfExits2 = option.replaceIfExits2;
256
+ }
257
+ if (option.values) {
258
+ this.addAll(...option.values);
254
259
  }
255
- this.clear();
256
260
  return this;
257
261
  }
258
262
  /**
@@ -313,7 +317,7 @@ class SetEx extends Set {
313
317
  const result = {};
314
318
  const list = this.toArray({ sort, each, filter, map });
315
319
  for (const item of list) {
316
- const name = item[this.uniqueKey];
320
+ const name = item[this._key];
317
321
  for (const key in item) {
318
322
  if (!result[key]) {
319
323
  result[key] = [];
@@ -323,14 +327,26 @@ class SetEx extends Set {
323
327
  }
324
328
  return result;
325
329
  }
326
- set onExist(onExist) {
327
- this.whenOnExist = onExist;
330
+ set onExist1(onExist1) {
331
+ this._onExist1 = onExist1;
328
332
  }
329
- set key(key) {
330
- this.uniqueKey = key;
333
+ set onExist2(onExist2) {
334
+ this._onExist2 = onExist2;
335
+ }
336
+ set onNotExist1(onNotExist1) {
337
+ this._onNotExist1 = onNotExist1;
331
338
  }
332
- set replaceWhenExits(replaceWhenExits) {
333
- this.replaceItemWhenExits = replaceWhenExits;
339
+ set onNotExist2(onNotExist2) {
340
+ this._onNotExist2 = onNotExist2;
341
+ }
342
+ set replaceIfExits1(replaceIfExits1) {
343
+ this._replaceIfExits1 = replaceIfExits1;
344
+ }
345
+ set replaceIfExits2(replaceIfExits2) {
346
+ this._replaceIfExits2 = replaceIfExits2;
347
+ }
348
+ set key(key) {
349
+ this._key = key;
334
350
  }
335
351
  }
336
352
  exports.SetEx = SetEx;