baja-lite 1.0.33 → 1.0.34

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 (103) hide show
  1. package/{cjs/boot-remote.d.ts → boot-remote.d.ts} +1 -1
  2. package/{es/boot-remote.js → boot-remote.js} +2 -2
  3. package/{es/boot.d.ts → boot.d.ts} +1 -1
  4. package/{es/boot.js → boot.js} +2 -2
  5. package/{es/enum.js → enum.js} +1 -1
  6. package/{es/fn.js → fn.js} +2 -2
  7. package/index.d.ts +12 -0
  8. package/index.js +12 -0
  9. package/package.json +6 -8
  10. package/{cjs/sql.d.ts → sql.d.ts} +3 -3
  11. package/{es/sql.js → sql.js} +7 -7
  12. package/{es/sqlite.d.ts → sqlite.d.ts} +1 -1
  13. package/{es/sqlite.js → sqlite.js} +1 -1
  14. package/{es/test-mysql.js → test-mysql.js} +2 -2
  15. package/{es/test-postgresql.js → test-postgresql.js} +2 -2
  16. package/cjs/boot-remote.js +0 -49
  17. package/cjs/boot.d.ts +0 -2
  18. package/cjs/boot.js +0 -183
  19. package/cjs/code.js +0 -379
  20. package/cjs/convert-xml.js +0 -417
  21. package/cjs/enum.js +0 -64
  22. package/cjs/error.js +0 -16
  23. package/cjs/fn.js +0 -179
  24. package/cjs/index.d.ts +0 -10
  25. package/cjs/index.js +0 -26
  26. package/cjs/list.js +0 -60
  27. package/cjs/math.js +0 -474
  28. package/cjs/object.js +0 -242
  29. package/cjs/set-ex.js +0 -345
  30. package/cjs/sql.js +0 -5083
  31. package/cjs/sqlite.d.ts +0 -32
  32. package/cjs/sqlite.js +0 -169
  33. package/cjs/string.js +0 -119
  34. package/cjs/test-mysql.js +0 -138
  35. package/cjs/test-postgresql.js +0 -93
  36. package/cjs/test-sqlite.js +0 -91
  37. package/cjs/test-xml.js +0 -75
  38. package/cjs/test.js +0 -4
  39. package/es/boot-remote.d.ts +0 -2
  40. package/es/code.d.ts +0 -2
  41. package/es/convert-xml.d.ts +0 -10
  42. package/es/enum.d.ts +0 -18
  43. package/es/error.d.ts +0 -5
  44. package/es/fn.d.ts +0 -128
  45. package/es/index.d.ts +0 -10
  46. package/es/index.js +0 -10
  47. package/es/list.d.ts +0 -10
  48. package/es/math.d.ts +0 -83
  49. package/es/object.d.ts +0 -83
  50. package/es/set-ex.d.ts +0 -198
  51. package/es/sql.d.ts +0 -1858
  52. package/es/string.d.ts +0 -17
  53. package/es/test-mysql.d.ts +0 -2
  54. package/es/test-postgresql.d.ts +0 -2
  55. package/es/test-sqlite.d.ts +0 -1
  56. package/es/test-xml.d.ts +0 -1
  57. package/es/test.d.ts +0 -1
  58. package/src/boot-remote.ts +0 -46
  59. package/src/boot.ts +0 -153
  60. package/src/code.ts +0 -377
  61. package/src/convert-xml.ts +0 -460
  62. package/src/enum.ts +0 -71
  63. package/src/error.ts +0 -11
  64. package/src/fn.ts +0 -295
  65. package/src/index.ts +0 -10
  66. package/src/list.ts +0 -57
  67. package/src/math.ts +0 -405
  68. package/src/object.ts +0 -247
  69. package/src/set-ex.ts +0 -374
  70. package/src/sql.ts +0 -5281
  71. package/src/sqlite.ts +0 -161
  72. package/src/string.ts +0 -111
  73. package/src/test-mysql.ts +0 -126
  74. package/src/test-postgresql.ts +0 -79
  75. package/src/test-sqlite.ts +0 -80
  76. package/src/test-xml.ts +0 -70
  77. package/src/test.ts +0 -2
  78. /package/{cjs/code.d.ts → code.d.ts} +0 -0
  79. /package/{es/code.js → code.js} +0 -0
  80. /package/{cjs/convert-xml.d.ts → convert-xml.d.ts} +0 -0
  81. /package/{es/convert-xml.js → convert-xml.js} +0 -0
  82. /package/{cjs/enum.d.ts → enum.d.ts} +0 -0
  83. /package/{cjs/error.d.ts → error.d.ts} +0 -0
  84. /package/{es/error.js → error.js} +0 -0
  85. /package/{cjs/fn.d.ts → fn.d.ts} +0 -0
  86. /package/{cjs/list.d.ts → list.d.ts} +0 -0
  87. /package/{es/list.js → list.js} +0 -0
  88. /package/{cjs/math.d.ts → math.d.ts} +0 -0
  89. /package/{es/math.js → math.js} +0 -0
  90. /package/{cjs/object.d.ts → object.d.ts} +0 -0
  91. /package/{es/object.js → object.js} +0 -0
  92. /package/{cjs/set-ex.d.ts → set-ex.d.ts} +0 -0
  93. /package/{es/set-ex.js → set-ex.js} +0 -0
  94. /package/{cjs/string.d.ts → string.d.ts} +0 -0
  95. /package/{es/string.js → string.js} +0 -0
  96. /package/{cjs/test-mysql.d.ts → test-mysql.d.ts} +0 -0
  97. /package/{cjs/test-postgresql.d.ts → test-postgresql.d.ts} +0 -0
  98. /package/{cjs/test-sqlite.d.ts → test-sqlite.d.ts} +0 -0
  99. /package/{es/test-sqlite.js → test-sqlite.js} +0 -0
  100. /package/{cjs/test-xml.d.ts → test-xml.d.ts} +0 -0
  101. /package/{es/test-xml.js → test-xml.js} +0 -0
  102. /package/{cjs/test.d.ts → test.d.ts} +0 -0
  103. /package/{es/test.js → test.js} +0 -0
package/cjs/object.js DELETED
@@ -1,242 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.C2P = exports.P2C = exports.arraySplit = exports.array2map = exports.mixList = exports.mixArray = exports.fixEmptyPrototy = exports.coverComplexBean = exports.createBeanFromArray = exports.emptyBean = exports.convertBeans = exports.convertBean = exports.copyBean = void 0;
7
- exports.C2P2 = C2P2;
8
- exports.P2C2 = P2C2;
9
- const iterare_1 = __importDefault(require("iterare"));
10
- /**
11
- * 对象对象(等同与convertBean)
12
- * 仅会将classType有的属性进行转换
13
- * * 相当与一次属性过滤
14
- * @param source
15
- * @param classType
16
- */
17
- const copyBean = (source, classType) => {
18
- const result = {};
19
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
20
- Object.keys(classType).forEach((key) => {
21
- result[key] =
22
- source[key] !== undefined ? source[key] : (result[key] = null);
23
- });
24
- return result;
25
- };
26
- exports.copyBean = copyBean;
27
- /**
28
- * 对象转换(等同与copyBean)
29
- * 仅会将classType有的属性进行转换
30
- * 相当与一次属性过滤
31
- * @param source
32
- * @param classType
33
- */
34
- exports.convertBean = exports.copyBean;
35
- /**
36
- * 批量对象转换(等同与copyBean)
37
- * 仅会将classType有的属性进行转换
38
- * 相当与一次属性过滤
39
- * @param source
40
- * @param classType
41
- */
42
- const convertBeans = (source, classType, cb) => {
43
- const result = new Array();
44
- for (const bean of source) {
45
- const data = (0, exports.convertBean)(bean, classType);
46
- if (cb) {
47
- cb(data, bean);
48
- }
49
- result.push(data);
50
- }
51
- return result;
52
- };
53
- exports.convertBeans = convertBeans;
54
- /**
55
- * 创建一个空对象
56
- * 其内各属性都是null
57
- * @param classType
58
- */
59
- const emptyBean = (classType) => {
60
- const target = {};
61
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
62
- Object.keys(classType).forEach((key) => {
63
- target[key] = null;
64
- });
65
- return target;
66
- };
67
- exports.emptyBean = emptyBean;
68
- /**
69
- * 将一个json数组提取为一个json对象
70
- * @param source 源数组
71
- * @param key 作为新对象的key的字段
72
- * @param value 作为新对象value的字段,不传则将自身为value
73
- */
74
- const createBeanFromArray = (source, key, value) => {
75
- const result = {};
76
- if (value) {
77
- source.forEach((item) => {
78
- if (item[key]) {
79
- result[`${item[key]}`] = item[value];
80
- }
81
- });
82
- }
83
- else {
84
- source.forEach((item) => {
85
- if (item[key]) {
86
- result[`${item[key]}`] = item;
87
- }
88
- });
89
- }
90
- return result;
91
- };
92
- exports.createBeanFromArray = createBeanFromArray;
93
- /**
94
- * 转换复合对象为指定bean
95
- * @param source
96
- * @param classType
97
- */
98
- const coverComplexBean = (source, classType) => {
99
- const result = {};
100
- const arrayData = {};
101
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
102
- for (const [key, value] of Object.entries(source)) {
103
- if (value instanceof Array) {
104
- arrayData[key] = value;
105
- }
106
- else if (typeof value === 'object') {
107
- Object.assign(result, value);
108
- }
109
- else {
110
- result[key] = value;
111
- }
112
- }
113
- return {
114
- data: (0, exports.convertBean)(result, classType),
115
- array: arrayData
116
- };
117
- };
118
- exports.coverComplexBean = coverComplexBean;
119
- /**
120
- * 将目标对象中为空的字段替换为source中对应key的值或者函数返回值
121
- * @param target
122
- * @param source
123
- */
124
- const fixEmptyPrototy = async (target, source) => {
125
- for (const [key, fn] of Object.entries(source)) {
126
- if (!target[key]) {
127
- if (typeof fn === 'function') {
128
- target[key] = await fn();
129
- }
130
- else {
131
- target[key] = fn;
132
- }
133
- }
134
- }
135
- };
136
- exports.fixEmptyPrototy = fixEmptyPrototy;
137
- const mixArray = (array, key, defKey) => {
138
- const obj = array.map(item => item[key]);
139
- const result = {};
140
- for (const i of obj) {
141
- let ki = '';
142
- if (i !== undefined && i !== null) {
143
- ki = `${i}`;
144
- }
145
- else if (defKey) {
146
- ki = defKey;
147
- }
148
- if (!result[ki]) {
149
- result[ki] = 0;
150
- }
151
- result[ki]++;
152
- }
153
- return result;
154
- };
155
- exports.mixArray = mixArray;
156
- const mixList = (array, key, value, defKey) => {
157
- const result = {};
158
- for (const i of array) {
159
- let ki = '';
160
- if (i[key] !== undefined && i[key] !== null) {
161
- ki = `${i[key]}`;
162
- }
163
- else if (defKey) {
164
- ki = defKey;
165
- }
166
- if (!result[ki]) {
167
- result[ki] = [];
168
- }
169
- if (value) {
170
- result[ki].push(i[value]);
171
- }
172
- else {
173
- result[ki].push(i);
174
- }
175
- }
176
- return result;
177
- };
178
- exports.mixList = mixList;
179
- const array2map = (array, v) => {
180
- const ot = {};
181
- for (const item of array) {
182
- ot[item] = v;
183
- }
184
- return ot;
185
- };
186
- exports.array2map = array2map;
187
- /**
188
- * 数组分割
189
- * @param datas
190
- * @param config(二选一) everyLength=每组个数(最后一组可能不足次数), groupCount=拆分几组
191
- * @returns T[][]
192
- */
193
- const arraySplit = (datas, { everyLength = 0, groupCount = 0 } = {}) => {
194
- if (groupCount > 0) {
195
- everyLength = Math.floor(datas.length / groupCount + 0.9);
196
- const result = [];
197
- for (let i = 0; i < groupCount; i++) {
198
- result.push(datas.slice(i * everyLength, (i + 1) * everyLength));
199
- }
200
- return result;
201
- }
202
- else if (everyLength > 0) {
203
- groupCount = Math.ceil(datas.length / everyLength);
204
- const result = [];
205
- for (let i = 0; i < groupCount; i++) {
206
- result.push(datas.slice(i * everyLength, (i + 1) * everyLength));
207
- }
208
- return result;
209
- }
210
- else {
211
- throw new Error('参数错误!');
212
- }
213
- };
214
- exports.arraySplit = arraySplit;
215
- const P2CEX = /[A-Z]/g;
216
- const P2C = (pro, IF = true) => IF ? pro.replace(P2CEX, (a) => `_${a.toLowerCase()}`) : pro;
217
- exports.P2C = P2C;
218
- const C2PEX = /_([a-z])/g;
219
- const C2P = (pro, IF = true) => IF ? pro.replace(C2PEX, (a, b) => `${b.toUpperCase()}`) : pro;
220
- exports.C2P = C2P;
221
- function C2P2(datas) {
222
- if (datas instanceof Array) {
223
- return (0, iterare_1.default)(datas).map((data) => Object.fromEntries(Object.entries(data).map(([K, V]) => [(0, exports.C2P)(K), V]))).toArray();
224
- }
225
- else if (datas) {
226
- return Object.fromEntries(Object.entries(datas).map(([K, V]) => [(0, exports.C2P)(K), V]));
227
- }
228
- else {
229
- return datas;
230
- }
231
- }
232
- function P2C2(datas) {
233
- if (datas instanceof Array) {
234
- return (0, iterare_1.default)(datas).map((data) => Object.fromEntries(Object.entries(data).map(([K, V]) => [(0, exports.P2C)(K), V]))).toArray();
235
- }
236
- else if (datas) {
237
- return Object.fromEntries(Object.entries(datas).map(([K, V]) => [(0, exports.P2C)(K), V]));
238
- }
239
- else {
240
- return datas;
241
- }
242
- }
package/cjs/set-ex.js DELETED
@@ -1,345 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SetEx = void 0;
7
- const iterare_1 = __importDefault(require("iterare"));
8
- class SetEx extends Set {
9
- /**
10
- * @param key 识别是否存在的对象的属性名
11
- * @param onExist 当存在时作何操作? oldData/newData 哪个将添加到set,由replaceItemWhenExits决定,默认是oldData生效
12
- * @param onNotExist 当不存在时作何操作?
13
- * @param replaceWhenExits 当存在时是否覆盖?
14
- * @param values 初始数组
15
- */
16
- constructor(option) {
17
- super();
18
- this._map = new Map();
19
- this._key = option.key;
20
- this._onExist1 = option.onExist1;
21
- this._onNotExist1 = option.onNotExist1;
22
- this._replaceIfExits1 = option.replaceIfExits1 === true;
23
- this._onExist2 = option.onExist2;
24
- this._onNotExist2 = option.onNotExist2;
25
- this._replaceIfExits2 = option.replaceIfExits2 === true;
26
- if (option.values) {
27
- this.addAll(...option.values);
28
- }
29
- }
30
- /**
31
- *
32
- * 添加返回
33
- * @param {T} value
34
- * @returns {this} 当前对象
35
- */
36
- add(value) {
37
- let flag = 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
- }
45
- if (this._replaceIfExits1 === true) {
46
- super.delete(item);
47
- this._map.delete(key);
48
- flag = false;
49
- }
50
- }
51
- if (flag === false) {
52
- super.add(value);
53
- this._map.set(key, value);
54
- if (this._onNotExist1) {
55
- this._onNotExist1(value);
56
- }
57
- }
58
- return this;
59
- }
60
- /**
61
- * 批量添加
62
- * @param values
63
- * @returns 当前对象
64
- */
65
- addAll(...values) {
66
- for (const value of values) {
67
- this.add(value);
68
- }
69
- return this;
70
- }
71
- /**
72
- *
73
- * 添加
74
- * @param {T} value
75
- * @returns {T} 添加成功的对象:可能是新加入集合的,也可能是原本存在的
76
- */
77
- add2(value) {
78
- let flag = false;
79
- const key = value[this._key];
80
- const item = this._map.get(key);
81
- let tmp = value;
82
- if (item) {
83
- flag = true;
84
- if (this._onExist2) {
85
- this._onExist2(item, value);
86
- }
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
- }
96
- if (flag === false) {
97
- super.add(value);
98
- this._map.set(key, value);
99
- if (this._onNotExist2) {
100
- this._onNotExist2(value);
101
- }
102
- }
103
- return tmp;
104
- }
105
- /**
106
- *
107
- * 添加并返回添加成功的对象:可能是新加入集合的,也可能是原本存在的
108
- * @param {T} values
109
- * @returns {T}
110
- */
111
- addAll2(values) {
112
- const result = [];
113
- for (const value of values) {
114
- result.push(this.add2(value));
115
- }
116
- return result;
117
- }
118
- /**
119
- * 用key找到匹配的第一个对象
120
- * @param {*} key 这是对象的关键属性,而非对象
121
- * @returns {(T | null)}
122
- */
123
- find(key) {
124
- return this._map.get(key) ?? null;
125
- }
126
- /**
127
- * 用key找到匹配的所有对象
128
- * @param {*} key 这是对象的关键属性,而非对象
129
- * @returns {T[]}
130
- */
131
- findAll(key) {
132
- return (0, iterare_1.default)(key).map(k => this._map.get(k)).filter(v => v !== undefined).toArray();
133
- }
134
- /**
135
- *
136
- * 用函数回调找到匹配的第一个对象
137
- * @param {(item: T) => boolean} fn
138
- * @returns {T[]}
139
- */
140
- filter(fn) {
141
- for (const item of this) {
142
- if (fn(item) === true) {
143
- return item;
144
- }
145
- }
146
- return null;
147
- }
148
- /**
149
- *
150
- * 用函数回调找到匹配的所有对象
151
- * @param {(item: T) => boolean} fn
152
- * @returns {T[]}
153
- */
154
- filterAll(fn) {
155
- const res = new Array();
156
- this.forEach((item) => {
157
- if (fn(item) === true) {
158
- res.push(item);
159
- }
160
- });
161
- return res;
162
- }
163
- /**
164
- *
165
- * 是否存在key对应的对象
166
- * @param {*} value 这是对象的关键属性,而非对象
167
- * @returns {boolean}
168
- */
169
- has(key) {
170
- return this._map.has(key);
171
- }
172
- /**
173
- * 转为数组
174
- * @param param0
175
- * @returns
176
- */
177
- toArray({ sort, each, filter, map } = {}) {
178
- let list = Array.from(this);
179
- if (filter) {
180
- list = list.filter(filter);
181
- }
182
- if (sort) {
183
- list.sort(sort);
184
- }
185
- if (each) {
186
- list.forEach(each);
187
- }
188
- if (map) {
189
- list = list.map(map);
190
- }
191
- return list;
192
- }
193
- /**
194
- * 转为JSON对象
195
- * @param key
196
- * @param value
197
- * @param param2
198
- * @returns
199
- */
200
- toJSON(key, value, { sort, each, filter, map } = {}) {
201
- return Object.fromEntries(this.toArray({ sort, each, filter, map }).map(i => [i[key], value ? i[value] : i]));
202
- }
203
- /**
204
- *
205
- * 删除key对应的对象
206
- * @param {*} _key 这是对象的关键属性,而非对象
207
- * @returns {boolean}
208
- */
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;
216
- }
217
- return false;
218
- }
219
- /**
220
- *
221
- * 重置
222
- * @param {keyof T} key
223
- * @param {(oldData: T, newData: T) => void} [onExist]
224
- * @param {boolean} [replaceWhenExits=false]
225
- */
226
- reset(option) {
227
- this.clear();
228
- this._map.clear();
229
- if (option.key) {
230
- this._key = option.key;
231
- }
232
- if (option.onExist1) {
233
- this._onExist1 = option.onExist1;
234
- }
235
- if (option.onNotExist1) {
236
- this._onNotExist1 = option.onNotExist1;
237
- }
238
- if (option.replaceIfExits1) {
239
- this._replaceIfExits1 = option.replaceIfExits1;
240
- }
241
- if (option.onExist2) {
242
- this._onExist2 = option.onExist2;
243
- }
244
- if (option.onNotExist2) {
245
- this._onNotExist2 = option.onNotExist2;
246
- }
247
- if (option.replaceIfExits2) {
248
- this._replaceIfExits2 = option.replaceIfExits2;
249
- }
250
- if (option.values) {
251
- this.addAll(...option.values);
252
- }
253
- return this;
254
- }
255
- /**
256
- *
257
- * @param param0 转为JSON对象,value可能是数组
258
- * @returns
259
- */
260
- toJSONArray({ sort, each, filter, map } = {}) {
261
- const result = {};
262
- const list = this.toArray({ sort, each, filter, map });
263
- for (const item of list) {
264
- for (const key in item) {
265
- if (!result[key]) {
266
- result[key] = [];
267
- }
268
- result[key].push(item[key]);
269
- }
270
- }
271
- return result;
272
- }
273
- /**
274
- * 转为hot-table支持的数组
275
- * @param param0
276
- * @param keys
277
- * @returns
278
- */
279
- toDataGrid({ sort, each, filter, map } = {}, ...keys) {
280
- if (this.size === 0) {
281
- return [];
282
- }
283
- if (keys.length === 0) {
284
- keys = Object.keys(this.values().next().value);
285
- }
286
- const result = [keys];
287
- const list = this.toArray({ sort, each, filter, map });
288
- for (const item of list) {
289
- const one = [];
290
- for (const key of keys) {
291
- one.push(item[key]);
292
- }
293
- result.push(one);
294
- }
295
- return result;
296
- }
297
- /**
298
- * 转为饼图支持的数组
299
- * @param param0
300
- * @param keys
301
- * @returns
302
- */
303
- toPieGrid({ sort, each, filter, map } = {}, ...keys) {
304
- if (this.size === 0) {
305
- return {};
306
- }
307
- if (keys.length === 0) {
308
- keys = Object.keys(this.values().next().value);
309
- }
310
- const result = {};
311
- const list = this.toArray({ sort, each, filter, map });
312
- for (const item of list) {
313
- const name = item[this._key];
314
- for (const key in item) {
315
- if (!result[key]) {
316
- result[key] = [];
317
- }
318
- result[key].push({ name, value: item[key] });
319
- }
320
- }
321
- return result;
322
- }
323
- set onExist1(onExist1) {
324
- this._onExist1 = onExist1;
325
- }
326
- set onExist2(onExist2) {
327
- this._onExist2 = onExist2;
328
- }
329
- set onNotExist1(onNotExist1) {
330
- this._onNotExist1 = onNotExist1;
331
- }
332
- set onNotExist2(onNotExist2) {
333
- this._onNotExist2 = onNotExist2;
334
- }
335
- set replaceIfExits1(replaceIfExits1) {
336
- this._replaceIfExits1 = replaceIfExits1;
337
- }
338
- set replaceIfExits2(replaceIfExits2) {
339
- this._replaceIfExits2 = replaceIfExits2;
340
- }
341
- set key(key) {
342
- this._key = key;
343
- }
344
- }
345
- exports.SetEx = SetEx;