baja-lite 1.1.5 → 1.1.11
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.
- package/code.js +5 -2
- package/object.js +0 -1
- package/package.json +2 -1
- package/sql.js +23 -23
- package/wx/mini.d.ts +7 -0
- package/wx/mini.js +10 -0
package/code.js
CHANGED
|
@@ -47,7 +47,7 @@ const lxMap = {
|
|
|
47
47
|
geometrycollection: "Object"
|
|
48
48
|
};
|
|
49
49
|
let force = false;
|
|
50
|
-
const basepath = path.join(__dirname, '..', '..'
|
|
50
|
+
const basepath = path.join(__dirname, '..', '..');
|
|
51
51
|
const config = path.join(basepath, 'baja.code.json');
|
|
52
52
|
const templatePath = path.join(basepath, 'code-template');
|
|
53
53
|
console.log(`
|
|
@@ -109,7 +109,8 @@ console.log(`
|
|
|
109
109
|
], Field(类型string),表示字段的注解, Type 表示JS类型
|
|
110
110
|
columnNames_join: 'sku_id, sku_name'
|
|
111
111
|
ColumnNames_join: 'sku_id skuId, sku_name skuName'
|
|
112
|
-
|
|
112
|
+
columnNames_joinT: 't.sku_id, t.sku_name'
|
|
113
|
+
ColumnNames_joinT: 't.sku_id skuId, t.sku_name skuName'
|
|
113
114
|
columns_no_id: [], 同columns,没有ID而已
|
|
114
115
|
columnNames_no_id: [],
|
|
115
116
|
|
|
@@ -253,6 +254,8 @@ try {
|
|
|
253
254
|
ColumnNames: columns?.map(i => i.Name),
|
|
254
255
|
columnNames_join: columns?.map(i => i.name).join(','),
|
|
255
256
|
ColumnNames_join: columns?.map(i => `${i.name} ${i.Name}`).join(','),
|
|
257
|
+
columnNames_joinT: columns?.map(i => `t.${i.name}`).join(','),
|
|
258
|
+
ColumnNames_joinT: columns?.map(i => `t.${i.name} ${i.Name}`).join(','),
|
|
256
259
|
columns_no_id: columns?.filter(i => !i.id),
|
|
257
260
|
columnNames_no_id: columns?.filter(i => !i.id).map(i => i.name),
|
|
258
261
|
ColumnNames_no_id: columns?.filter(i => !i.id).map(i => i.Name),
|
package/object.js
CHANGED
|
@@ -8,7 +8,6 @@ import iterate from "iterare";
|
|
|
8
8
|
*/
|
|
9
9
|
export const copyBean = (source, classType) => {
|
|
10
10
|
const result = {};
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
12
11
|
Object.keys(classType).forEach((key) => {
|
|
13
12
|
result[key] =
|
|
14
13
|
source[key] !== undefined ? source[key] : (result[key] = null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "baja-lite",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "some util for self",
|
|
5
5
|
"homepage": "https://github.com/void-soul/util-man",
|
|
6
6
|
"repository": {
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"pino": "9.6.0",
|
|
46
46
|
"pino-pretty": "13.0.0",
|
|
47
47
|
"reflect-metadata": "0.2.2",
|
|
48
|
+
"request": "2.88.2",
|
|
48
49
|
"request-promise": "4.2.6",
|
|
49
50
|
"sql-formatter": "15.4.10",
|
|
50
51
|
"sqlstring": "2.3.3",
|
package/sql.js
CHANGED
|
@@ -11,7 +11,7 @@ var _b, _c, _d, _e;
|
|
|
11
11
|
var _f, _g, _h, _j;
|
|
12
12
|
import { Throw } from './error.js';
|
|
13
13
|
import tslib from 'tslib';
|
|
14
|
-
import
|
|
14
|
+
import { iterate } from 'iterare';
|
|
15
15
|
import { emptyString } from './string.js';
|
|
16
16
|
import pino from 'pino';
|
|
17
17
|
import { excuteSplit, ExcuteSplitMode, sleep } from './fn.js';
|
|
@@ -2244,7 +2244,7 @@ export const DB = (config) => {
|
|
|
2244
2244
|
this[_x] = __stateFileName;
|
|
2245
2245
|
this[_y] = __deleteState;
|
|
2246
2246
|
this[_z] = (data, option) => {
|
|
2247
|
-
return Object.fromEntries(
|
|
2247
|
+
return Object.fromEntries(iterate(option?.skipId === true ? __columnsNoId : __columns)
|
|
2248
2248
|
.map(K => [K, FieldFilter(K, data[K], __def, __fields[K].uuid === true || __fields[K].uuidShort === true, option)])
|
|
2249
2249
|
.filter(data => {
|
|
2250
2250
|
if (data[1][0] === 1) {
|
|
@@ -2338,7 +2338,7 @@ export class SqlService {
|
|
|
2338
2338
|
const conditions = option.existConditionOtherThanIds || this[_ids];
|
|
2339
2339
|
Throw.if(!conditions, 'not found where condition for insertIfNotExists!');
|
|
2340
2340
|
Throw.if(conditions.length === 0, 'insertIfNotExists must have not null where!');
|
|
2341
|
-
const where =
|
|
2341
|
+
const where = iterate(conditions).map(c => `${this[_fields][c]?.C2()} = ?`).join(' AND ');
|
|
2342
2342
|
const finalColumns = new Set();
|
|
2343
2343
|
const whereColumns = conditions;
|
|
2344
2344
|
const params = [];
|
|
@@ -2397,7 +2397,7 @@ export class SqlService {
|
|
|
2397
2397
|
}
|
|
2398
2398
|
return `SELECT ${questMark.join(',')} FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM ${tableName} WHERE ${where})`;
|
|
2399
2399
|
});
|
|
2400
|
-
const columnNames =
|
|
2400
|
+
const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
|
|
2401
2401
|
const sql = formatDialect(`INSERT INTO
|
|
2402
2402
|
${tableName}
|
|
2403
2403
|
(${columnNames})
|
|
@@ -2456,7 +2456,7 @@ export class SqlService {
|
|
|
2456
2456
|
}
|
|
2457
2457
|
return `(${questMark.join(',')})`;
|
|
2458
2458
|
});
|
|
2459
|
-
const columnNames =
|
|
2459
|
+
const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
|
|
2460
2460
|
const sql = formatDialect(`
|
|
2461
2461
|
${option.dbType === DBType.Mysql ? '' : 'INSERT OR'} REPLACE INTO
|
|
2462
2462
|
${tableName}
|
|
@@ -2517,7 +2517,7 @@ export class SqlService {
|
|
|
2517
2517
|
}
|
|
2518
2518
|
return `(${questMark.join(',')})`;
|
|
2519
2519
|
});
|
|
2520
|
-
const columnNames =
|
|
2520
|
+
const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
|
|
2521
2521
|
const sql = formatDialect(`
|
|
2522
2522
|
INSERT INTO
|
|
2523
2523
|
${tableName}
|
|
@@ -2583,7 +2583,7 @@ export class SqlService {
|
|
|
2583
2583
|
});
|
|
2584
2584
|
const _sqls = this._createTable({ tableName: tableTemp, temp: true, columns: Array.from(finalColumns) });
|
|
2585
2585
|
sqls.push(..._sqls);
|
|
2586
|
-
const columnNames =
|
|
2586
|
+
const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
|
|
2587
2587
|
sqls.push({
|
|
2588
2588
|
sql: formatDialect(`
|
|
2589
2589
|
INSERT INTO
|
|
@@ -2679,7 +2679,7 @@ export class SqlService {
|
|
|
2679
2679
|
_update(datas, option) {
|
|
2680
2680
|
const sqls = [];
|
|
2681
2681
|
const tableName = option?.tableName;
|
|
2682
|
-
const where = `WHEN ${
|
|
2682
|
+
const where = `WHEN ${iterate(this[_ids]).map(c => `${this[_fields][c]?.C2()} = ?`).join(' AND ')} THEN ?`;
|
|
2683
2683
|
const columnMaps = Object.fromEntries(this[_columnsNoId].map(c => [c, {
|
|
2684
2684
|
where: new Array(),
|
|
2685
2685
|
params: []
|
|
@@ -2699,7 +2699,7 @@ export class SqlService {
|
|
|
2699
2699
|
}
|
|
2700
2700
|
});
|
|
2701
2701
|
}
|
|
2702
|
-
const sql = formatDialect(`UPDATE ${tableName} SET ${
|
|
2702
|
+
const sql = formatDialect(`UPDATE ${tableName} SET ${iterate(this[_columnsNoId])
|
|
2703
2703
|
.filter(K => columnMaps[K].where.length > 0)
|
|
2704
2704
|
.map(K => {
|
|
2705
2705
|
params.push(...columnMaps[K].params);
|
|
@@ -2725,7 +2725,7 @@ export class SqlService {
|
|
|
2725
2725
|
}
|
|
2726
2726
|
return result;
|
|
2727
2727
|
}, { everyLength: option?.maxDeal });
|
|
2728
|
-
return result.reduce((a, b) => a + b);
|
|
2728
|
+
return result.length > 0 ? result.reduce((a, b) => a + b) : 0;
|
|
2729
2729
|
};
|
|
2730
2730
|
if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
|
|
2731
2731
|
return fn();
|
|
@@ -2747,7 +2747,7 @@ export class SqlService {
|
|
|
2747
2747
|
}
|
|
2748
2748
|
return result;
|
|
2749
2749
|
}, { everyLength: option?.maxDeal });
|
|
2750
|
-
return result.reduce((a, b) => a + b);
|
|
2750
|
+
return result.length > 0 ? result.reduce((a, b) => a + b) : 0;
|
|
2751
2751
|
};
|
|
2752
2752
|
if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
|
|
2753
2753
|
return fn();
|
|
@@ -2776,7 +2776,7 @@ export class SqlService {
|
|
|
2776
2776
|
const sqls = [];
|
|
2777
2777
|
if (option.mode === DeleteMode.Common) {
|
|
2778
2778
|
const params = new Array();
|
|
2779
|
-
const whereSql =
|
|
2779
|
+
const whereSql = iterate(wheres).map(where => {
|
|
2780
2780
|
return `(
|
|
2781
2781
|
${Object.entries(where).map(([K, V]) => {
|
|
2782
2782
|
params.push(V);
|
|
@@ -2820,7 +2820,7 @@ export class SqlService {
|
|
|
2820
2820
|
}
|
|
2821
2821
|
case DBType.Sqlite:
|
|
2822
2822
|
case DBType.SqliteRemote: {
|
|
2823
|
-
const columnNames =
|
|
2823
|
+
const columnNames = iterate(delWhere).map(K => this[_fields][K]?.C2()).join(',');
|
|
2824
2824
|
if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
|
|
2825
2825
|
sqls.push({
|
|
2826
2826
|
sql: formatDialect(`UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
|
|
@@ -2906,13 +2906,13 @@ export class SqlService {
|
|
|
2906
2906
|
const ids = option.id instanceof Array ? option.id : [option.id];
|
|
2907
2907
|
option.where = ids.map(i => ({ [idName]: i }));
|
|
2908
2908
|
}
|
|
2909
|
-
const columns = option.templateResult === TemplateResult.Count ? 'COUNT(1) ct' :
|
|
2909
|
+
const columns = option.templateResult === TemplateResult.Count ? 'COUNT(1) ct' : iterate((option.columns ?? this[_columns])).map((K) => `a.${this[_fields][K]?.C3()}`).join(',');
|
|
2910
2910
|
const wheres = option.where instanceof Array ? option.where : [option.where];
|
|
2911
2911
|
const sqls = [];
|
|
2912
2912
|
let resultIndex = -1;
|
|
2913
2913
|
if (option.mode === SelectMode.Common) {
|
|
2914
2914
|
const params = new Array();
|
|
2915
|
-
const whereSql = formatDialect(
|
|
2915
|
+
const whereSql = formatDialect(iterate(wheres).map(where => this[_transformer](where, option)).map(where => {
|
|
2916
2916
|
return `SELECT ${columns} FROM ${tableNameESC} a WHERE
|
|
2917
2917
|
${Object.entries(where).map(([K, V]) => {
|
|
2918
2918
|
params.push(V);
|
|
@@ -3017,10 +3017,10 @@ export class SqlService {
|
|
|
3017
3017
|
}
|
|
3018
3018
|
case SelectResult.RS_CS: {
|
|
3019
3019
|
if (mapper) {
|
|
3020
|
-
return
|
|
3020
|
+
return iterate(result).map((data) => flatData({ data, mapper, mapperIfUndefined })).toArray();
|
|
3021
3021
|
}
|
|
3022
3022
|
else if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
|
|
3023
|
-
return
|
|
3023
|
+
return iterate(result).map((r) => C2P2(r)).toArray();
|
|
3024
3024
|
}
|
|
3025
3025
|
else {
|
|
3026
3026
|
return result;
|
|
@@ -3036,10 +3036,10 @@ export class SqlService {
|
|
|
3036
3036
|
}
|
|
3037
3037
|
case SelectResult.RS_CS_List: {
|
|
3038
3038
|
if (mapper) {
|
|
3039
|
-
return new ArrayList(
|
|
3039
|
+
return new ArrayList(iterate(result).map((data) => flatData({ data, mapper, mapperIfUndefined })).toArray());
|
|
3040
3040
|
}
|
|
3041
3041
|
else if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
|
|
3042
|
-
return new ArrayList(
|
|
3042
|
+
return new ArrayList(iterate(result).map((r) => C2P2(r)).toArray());
|
|
3043
3043
|
}
|
|
3044
3044
|
else {
|
|
3045
3045
|
return new ArrayList();
|
|
@@ -3272,7 +3272,7 @@ export class SqlService {
|
|
|
3272
3272
|
Throw.if(list.length === 0, 'not found data!');
|
|
3273
3273
|
const columnTitles = new Array();
|
|
3274
3274
|
const keys = this[_fields] ?
|
|
3275
|
-
|
|
3275
|
+
iterate(Object.entries(this[_fields]))
|
|
3276
3276
|
.filter(([K, F]) => (F.id !== true && F.exportable !== false) || (F.id === true && F.exportable === true))
|
|
3277
3277
|
.map(([K, F]) => {
|
|
3278
3278
|
columnTitles.push(F.comment ?? K);
|
|
@@ -3291,7 +3291,7 @@ export class SqlService {
|
|
|
3291
3291
|
imp() {
|
|
3292
3292
|
Throw.if(!this[_fields], 'not set fields!');
|
|
3293
3293
|
const columnTitles = new Array();
|
|
3294
|
-
const keys =
|
|
3294
|
+
const keys = iterate(Object.entries(this[_fields]))
|
|
3295
3295
|
.filter(([K, F]) => (F.id !== true && F.exportable !== false) || (F.id === true && F.exportable === true))
|
|
3296
3296
|
.map(([K, F]) => {
|
|
3297
3297
|
columnTitles.push(F.comment ?? K);
|
|
@@ -3317,7 +3317,7 @@ export class SqlService {
|
|
|
3317
3317
|
const tableVersion = option.conn.pluck(SyncMode.Sync, 'SELECT ______version v from TABLE_VERSION WHERE ______tableName = ?', [option.tableName]);
|
|
3318
3318
|
if (tableVersion && tableVersion < lastVersion) { // 发现需要升级的版本
|
|
3319
3319
|
// 更新版本
|
|
3320
|
-
const columns =
|
|
3320
|
+
const columns = iterate(option.conn.query(SyncMode.Sync, `PRAGMA table_info(${tableES})`))
|
|
3321
3321
|
.filter(c => this[_fields].hasOwnProperty(C2P(c.name, globalThis[_Hump])))
|
|
3322
3322
|
.map(c => c.name)
|
|
3323
3323
|
.join(',');
|
|
@@ -3376,7 +3376,7 @@ export class SqlService {
|
|
|
3376
3376
|
const tableVersion = await option.conn.pluck(SyncMode.Async, 'SELECT ______version v from TABLE_VERSION WHERE ______tableName = ?', [option.tableName]);
|
|
3377
3377
|
if (tableVersion && tableVersion < lastVersion) { // 发现需要升级的版本
|
|
3378
3378
|
// 更新版本
|
|
3379
|
-
const columns =
|
|
3379
|
+
const columns = iterate(await option.conn.query(SyncMode.Async, `PRAGMA table_info(${tableES})`))
|
|
3380
3380
|
.filter(c => this[_fields].hasOwnProperty(C2P(c.name, globalThis[_Hump])))
|
|
3381
3381
|
.map(c => c.name)
|
|
3382
3382
|
.join(',');
|
package/wx/mini.d.ts
CHANGED
|
@@ -42,4 +42,11 @@ export declare class WxMini extends BaseWx {
|
|
|
42
42
|
}): T | undefined;
|
|
43
43
|
getLiveInfo(start: number, limit: number): Promise<WxLiveInfo[]>;
|
|
44
44
|
getLiveReplay(room_id: number, start: number, limit: number): Promise<WxLiveReplay[]>;
|
|
45
|
+
getPhone(code: string, openid: string): Promise<{
|
|
46
|
+
phoneNumber: any;
|
|
47
|
+
purePhoneNumber: any;
|
|
48
|
+
countryCode: any;
|
|
49
|
+
timestamp: any;
|
|
50
|
+
appid: any;
|
|
51
|
+
}>;
|
|
45
52
|
}
|
package/wx/mini.js
CHANGED
|
@@ -99,4 +99,14 @@ export class WxMini extends BaseWx {
|
|
|
99
99
|
const data = await this.fetch((token) => `https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=${token}`, 'post', { room_id, start, limit, action: 'get_replay' });
|
|
100
100
|
return data.live_replay;
|
|
101
101
|
}
|
|
102
|
+
async getPhone(code, openid) {
|
|
103
|
+
const data = await this.fetch((token) => `https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=${token}`, 'post', { code, openid });
|
|
104
|
+
return {
|
|
105
|
+
phoneNumber: data.phone_info.phoneNumber,
|
|
106
|
+
purePhoneNumber: data.phone_info.purePhoneNumber,
|
|
107
|
+
countryCode: data.phone_info.countryCode,
|
|
108
|
+
timestamp: data.phone_info.watermark.timestamp,
|
|
109
|
+
appid: data.phone_info.watermark.appid
|
|
110
|
+
};
|
|
111
|
+
}
|
|
102
112
|
}
|