baja-lite 1.0.5 → 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.
@@ -1 +1,2 @@
1
1
  import 'reflect-metadata';
2
+ export declare function go2(): Promise<void>;
package/es/test-mysql.js CHANGED
@@ -31,7 +31,7 @@ AmaService2 = __decorate([
31
31
  tableName: 'ama_fuck', clz: AmaFuck2, dbType: DBType.Mysql
32
32
  })
33
33
  ], AmaService2);
34
- async function go2() {
34
+ export async function go2() {
35
35
  await Boot({
36
36
  Mysql: {
37
37
  host: '39.98.58.252',
@@ -42,7 +42,7 @@ async function go2() {
42
42
  database: 'dmce',
43
43
  debug: false
44
44
  },
45
- log: 'trace',
45
+ log: 'info',
46
46
  columnMode: ColumnMode.HUMP,
47
47
  sqlDir: 'E:/pro/baja-lite/xml'
48
48
  });
@@ -110,6 +110,18 @@ async function go2() {
110
110
  return 1;
111
111
  }
112
112
  });
113
- await service.select({ sqlId: 'event-report.matchSectionTempWGoalPlayerList', params: { searchVo: { matchId: 'yyyy', matchSection: 'oooo' } } });
113
+ const data = await service.select({
114
+ sql: 'SELECT resourceid, resourcepid,resourcename FROM cp_resource ',
115
+ params: {
116
+ site: '1234',
117
+ matchInfo: { reportType: 'yyyy', id: '11' }
118
+ },
119
+ // mapper: [
120
+ // ['site', ['info', 'bSist'], 989],
121
+ // ['site', ['info2', 'bSist'], 33],
122
+ // ['site', ['Bsite'], 0]
123
+ // ]
124
+ });
125
+ console.log(data);
114
126
  }
115
127
  go2();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/util-man",
6
6
  "repository": {
@@ -30,9 +30,11 @@
30
30
  "sqlite": "node inspect ./dist/cjs/test-sqlite.js"
31
31
  },
32
32
  "dependencies": {
33
+ "@types/lodash.get": "^4.4.9",
33
34
  "decimal.js": "10.4.3",
34
35
  "html-parse-stringify": "3.0.1",
35
36
  "iterare": "1.2.1",
37
+ "lodash.get": "^4.4.2",
36
38
  "mustache": "4.2.0",
37
39
  "pino": "9.2.0",
38
40
  "pino-pretty": "11.2.1",
@@ -44,17 +46,17 @@
44
46
  "devDependencies": {
45
47
  "@types/better-sqlite3": "7.6.10",
46
48
  "@types/mustache": "4.2.5",
47
- "@types/node": "20.14.2",
49
+ "@types/node": "20.14.9",
48
50
  "@types/sqlstring": "2.3.2",
49
- "@typescript-eslint/eslint-plugin": "7.13.0",
50
- "@typescript-eslint/parser": "7.13.0",
51
+ "@typescript-eslint/eslint-plugin": "7.14.1",
52
+ "@typescript-eslint/parser": "7.14.1",
51
53
  "better-sqlite3": "11.0.0",
52
54
  "ioredis": "5.4.1",
53
55
  "mongodb": "6.7.0",
54
- "mysql2": "3.10.0",
56
+ "mysql2": "3.10.1",
55
57
  "redlock": "5.0.0-beta.2",
56
58
  "shelljs": "0.8.5",
57
- "typescript": "5.4.5"
59
+ "typescript": "5.5.2"
58
60
  },
59
61
  "engines": {
60
62
  "node": "20",
@@ -1,6 +1,6 @@
1
- import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, GlobalSqlOption2, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode } from './sql';
1
+ import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, GlobalSqlOptionForWeb, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode } from './sql';
2
2
 
3
- export const BootRomote = async function (options: GlobalSqlOption2) {
3
+ export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
4
4
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
5
5
  globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
6
6
  logger.level = options.log ?? 'info';
package/src/code.ts CHANGED
@@ -75,6 +75,7 @@ console.log(`
75
75
  "s": ["entity", "controller", "service", "sql", "module"]
76
76
  },
77
77
  "output": "{ClassName}Module",
78
+ "id"? : "uuidShort: true, notNull: true, uuid: true"
78
79
  }
79
80
  command是生成命令,这里声明命令同时定义文件生成路径:可用下面的变量替换.同时必须有同名模板.
80
81
  路径是相对于项目根目录的
@@ -88,16 +89,18 @@ console.log(`
88
89
  请在项目根目录的code-template添加模板文件, 按照mustache(标签定义成了[ '<%', '%>' ])进行格式化,变量:
89
90
  title,
90
91
 
91
- tableName,
92
- className,
93
- ClassName,
94
- vueName,
95
- splitName,
92
+ tableName, event_main_info
93
+ className, eventMainInfo
94
+ ClassName, EventMainInfo
95
+ vueName, event-main-info
96
+ splitName, event/main/info
97
+ SplitName, event/mainInfo
96
98
 
97
99
  columns: [
98
100
  comment:
99
101
  name: sku_id
100
102
  Name: skuId
103
+ NAME: SkuId
101
104
  Field
102
105
  Type
103
106
  ], Field(类型string),表示字段的注解, Type 表示JS类型
@@ -125,7 +128,7 @@ console.log(`
125
128
  try {
126
129
  const outputs = new Set<string>();
127
130
  const _configData = fs.readFileSync(config, { encoding: 'utf-8' }).toString();
128
- const configData = JSON.parse(_configData) ;
131
+ const configData = JSON.parse(_configData);
129
132
  const templates = Object.fromEntries(fs.readdirSync(templatePath).map(r => [path.basename(r, '.mu'), fs.readFileSync(path.join(templatePath, r), { encoding: 'utf-8' }).toString()]));
130
133
  const pool = createPool({
131
134
  host: configData.host,
@@ -167,7 +170,7 @@ try {
167
170
  else delete r.id;
168
171
  if (r.notNull === 1) { r.notNull = true; }
169
172
  else delete r.notNull;
170
- r.comment = `* ${r.comment??''}(\`${tableName}.${r.name}\`)`;
173
+ r.comment = `* ${r.comment ?? ''}(\`${tableName}.${r.name}\`)`;
171
174
  const fields = new Array<string>(`type:SqlType.${r.type}`);
172
175
  if (r.length !== null) { fields.push(`length:${r.length}`); }
173
176
  if (r.scale !== null) { fields.push(`scale:${r.scale}`); }
@@ -179,11 +182,17 @@ try {
179
182
  fields.push(`def:${r.def}`);
180
183
  }
181
184
  }
182
- if (r.id === true) { fields.push(`id:true`); }
185
+ if (r.id === true) {
186
+ fields.push(`id:true`);
187
+ }
183
188
  if (r.notNull === true) { fields.push(`notNull:true`); }
189
+ if (r.id === true && configData.id) {
190
+ fields.push(configData.id);
191
+ }
184
192
  r.Type = lxMap[r.type];
185
193
  r.Field = `@Field({${fields.join(',')}})`;
186
194
  r.Name = r.name.replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
195
+ r.NAME = r.Name.replace(/\w/, (v: string) => v.toUpperCase());
187
196
  return r;
188
197
  });
189
198
  conn.release();
@@ -206,6 +215,7 @@ try {
206
215
  const ClassName = className.replace(/\w/, (v: string) => v.toUpperCase());
207
216
  const vueName = tableName.replace(/_/g, '-');
208
217
  const splitName = tableName.replace(/_/g, '/');
218
+ const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
209
219
  const data = {
210
220
  title,
211
221
 
@@ -214,19 +224,25 @@ try {
214
224
  ClassName,
215
225
  vueName,
216
226
  splitName,
227
+ SplitName,
217
228
 
218
229
  columns,
219
230
  columnNames: columns?.map(i => i.name),
231
+ ColumnNames: columns?.map(i => i.Name),
220
232
  columnNames_join: columns?.map(i => i.name).join(','),
221
233
  ColumnNames_join: columns?.map(i => `${i.name} ${i.Name}`).join(','),
222
234
 
223
235
  columns_no_id: columns?.filter(i => !i.id),
224
236
  columnNames_no_id: columns?.filter(i => !i.id).map(i => i.name),
237
+ ColumnNames_no_id: columns?.filter(i => !i.id).map(i => i.Name),
225
238
  columnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.name).join(','),
239
+ ColumnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.Name).join(','),
226
240
 
227
241
  ids: columns?.filter(i => i.id),
228
242
  idNames: columns?.filter(i => i.id).map(i => i.name),
243
+ IdNames: columns?.filter(i => i.id).map(i => i.Name),
229
244
  idNames_join: columns?.filter(i => i.id).map(i => i.name).join(','),
245
+ IdNames_join: columns?.filter(i => i.id).map(i => i.Name).join(','),
230
246
 
231
247
  modelName,
232
248
  modelPath
@@ -143,8 +143,9 @@ const convertIf = function (children: XML, param: Record<string, any>, parentIds
143
143
  evalString = evalString.replace(/ or /gi, ' || ');
144
144
 
145
145
  // replace == to === for strict evaluate
146
- evalString = evalString.replace(/==/g, '===');
147
- evalString = evalString.replace(/!=/g, '!==');
146
+ // TODO: fix != null & != ''
147
+ // evalString = evalString.replace(/==/g, '===');
148
+ // evalString = evalString.replace(/!=/g, '!==');
148
149
 
149
150
  evalString = evalString.replace(/^'(.*?)'\.equalsIgnoreCase\( ([a-zA-Z]+\.[a-zA-Z]+) \)/i, `($2 && $2.toUpperCase() === '$1'.toUpperCase())`);
150
151
  evalString = evalString.replace(/\('(.*?)'\.equalsIgnoreCase\( ([a-zA-Z]+\.[a-zA-Z]+) \)/i, `(($2 && $2.toUpperCase() === '$1'.toUpperCase())`);
package/src/index.ts CHANGED
@@ -6,4 +6,5 @@ export * from './object';
6
6
  export * from './set-ex';
7
7
  export * from './sql';
8
8
  export * from './string';
9
- export * from './enum';
9
+ export * from './enum';
10
+ export * from './list';
package/src/list.ts ADDED
@@ -0,0 +1,31 @@
1
+ export class ArrayList<T> extends Array<T> {
2
+ constructor(array?: Array<T> | T | undefined) {
3
+ super();
4
+ if (array instanceof Array) {
5
+ super.push(...array);
6
+ } else if (typeof array !== 'undefined') {
7
+ super.push(array);
8
+ }
9
+ }
10
+ add(...items: T[]) {
11
+ this.push(...items);
12
+ }
13
+ size() {
14
+ return this.length;
15
+ }
16
+ isEmpty() {
17
+ return this.length === 0;
18
+ }
19
+ get(index: number) {
20
+ return this[index];
21
+ }
22
+ clear() {
23
+ this.length = 0;
24
+ }
25
+ set(index: number, item: T) {
26
+ this[index] = item;
27
+ }
28
+ remove(index: number) {
29
+ this.splice(index, 1);
30
+ }
31
+ }
package/src/object.ts CHANGED
@@ -218,7 +218,7 @@ export const arraySplit = <T = any>(datas: T[], { everyLength = 0, groupCount =
218
218
  const P2CEX = /[A-Z]/g;
219
219
  export const P2C = (pro: string, IF = true) => IF ? pro.replace(P2CEX, (a: string) => `_${a.toLowerCase()}`) : pro;
220
220
  const C2PEX = /_([a-z])/g;
221
- export const C2P = (pro: string, IF = true) => IF ? pro.replace(C2PEX, (a: string, b: string) => `_${b.toUpperCase()}`) : pro;
221
+ export const C2P = (pro: string, IF = true) => IF ? pro.replace(C2PEX, (a: string, b: string) => `${b.toUpperCase()}`) : pro;
222
222
 
223
223
 
224
224
  export function C2P2<T extends Object = any, L extends Object = T>(datas: L[]): T[];
@@ -243,4 +243,5 @@ export function P2C2<T extends Object = any, L extends Object = T>(datas: L | L[
243
243
  } else {
244
244
  return datas;
245
245
  }
246
- }
246
+ }
247
+
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
  }