baja-lite 1.1.8 → 1.1.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.1.8",
3
+ "version": "1.1.12",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/util-man",
6
6
  "repository": {
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 iterare from 'iterare';
14
+ import * as ite from 'iterare';
15
15
  import { emptyString } from './string.js';
16
16
  import pino from 'pino';
17
17
  import { excuteSplit, ExcuteSplitMode, sleep } from './fn.js';
@@ -24,6 +24,7 @@ import { convert } from './convert-xml.js';
24
24
  import { ArrayList } from './list.js';
25
25
  import LGet from 'lodash.get';
26
26
  import { encode, decode, ExtensionCodec, DecodeError } from "@msgpack/msgpack";
27
+ const iterate = ite.iterate;
27
28
  BigInt.prototype.toJSON = function () { return this.toString(); };
28
29
  const BIGINT_EXT_TYPE = 0;
29
30
  export const extensionCodec = new ExtensionCodec();
@@ -2244,7 +2245,7 @@ export const DB = (config) => {
2244
2245
  this[_x] = __stateFileName;
2245
2246
  this[_y] = __deleteState;
2246
2247
  this[_z] = (data, option) => {
2247
- return Object.fromEntries(iterare(option?.skipId === true ? __columnsNoId : __columns)
2248
+ return Object.fromEntries(iterate(option?.skipId === true ? __columnsNoId : __columns)
2248
2249
  .map(K => [K, FieldFilter(K, data[K], __def, __fields[K].uuid === true || __fields[K].uuidShort === true, option)])
2249
2250
  .filter(data => {
2250
2251
  if (data[1][0] === 1) {
@@ -2338,7 +2339,7 @@ export class SqlService {
2338
2339
  const conditions = option.existConditionOtherThanIds || this[_ids];
2339
2340
  Throw.if(!conditions, 'not found where condition for insertIfNotExists!');
2340
2341
  Throw.if(conditions.length === 0, 'insertIfNotExists must have not null where!');
2341
- const where = iterare(conditions).map(c => `${this[_fields][c]?.C2()} = ?`).join(' AND ');
2342
+ const where = iterate(conditions).map(c => `${this[_fields][c]?.C2()} = ?`).join(' AND ');
2342
2343
  const finalColumns = new Set();
2343
2344
  const whereColumns = conditions;
2344
2345
  const params = [];
@@ -2397,7 +2398,7 @@ export class SqlService {
2397
2398
  }
2398
2399
  return `SELECT ${questMark.join(',')} FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM ${tableName} WHERE ${where})`;
2399
2400
  });
2400
- const columnNames = iterare(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2401
+ const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2401
2402
  const sql = formatDialect(`INSERT INTO
2402
2403
  ${tableName}
2403
2404
  (${columnNames})
@@ -2456,7 +2457,7 @@ export class SqlService {
2456
2457
  }
2457
2458
  return `(${questMark.join(',')})`;
2458
2459
  });
2459
- const columnNames = iterare(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2460
+ const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2460
2461
  const sql = formatDialect(`
2461
2462
  ${option.dbType === DBType.Mysql ? '' : 'INSERT OR'} REPLACE INTO
2462
2463
  ${tableName}
@@ -2517,7 +2518,7 @@ export class SqlService {
2517
2518
  }
2518
2519
  return `(${questMark.join(',')})`;
2519
2520
  });
2520
- const columnNames = iterare(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2521
+ const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2521
2522
  const sql = formatDialect(`
2522
2523
  INSERT INTO
2523
2524
  ${tableName}
@@ -2583,7 +2584,7 @@ export class SqlService {
2583
2584
  });
2584
2585
  const _sqls = this._createTable({ tableName: tableTemp, temp: true, columns: Array.from(finalColumns) });
2585
2586
  sqls.push(..._sqls);
2586
- const columnNames = iterare(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2587
+ const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2587
2588
  sqls.push({
2588
2589
  sql: formatDialect(`
2589
2590
  INSERT INTO
@@ -2679,7 +2680,7 @@ export class SqlService {
2679
2680
  _update(datas, option) {
2680
2681
  const sqls = [];
2681
2682
  const tableName = option?.tableName;
2682
- const where = `WHEN ${iterare(this[_ids]).map(c => `${this[_fields][c]?.C2()} = ?`).join(' AND ')} THEN ?`;
2683
+ const where = `WHEN ${iterate(this[_ids]).map(c => `${this[_fields][c]?.C2()} = ?`).join(' AND ')} THEN ?`;
2683
2684
  const columnMaps = Object.fromEntries(this[_columnsNoId].map(c => [c, {
2684
2685
  where: new Array(),
2685
2686
  params: []
@@ -2699,7 +2700,7 @@ export class SqlService {
2699
2700
  }
2700
2701
  });
2701
2702
  }
2702
- const sql = formatDialect(`UPDATE ${tableName} SET ${iterare(this[_columnsNoId])
2703
+ const sql = formatDialect(`UPDATE ${tableName} SET ${iterate(this[_columnsNoId])
2703
2704
  .filter(K => columnMaps[K].where.length > 0)
2704
2705
  .map(K => {
2705
2706
  params.push(...columnMaps[K].params);
@@ -2776,7 +2777,7 @@ export class SqlService {
2776
2777
  const sqls = [];
2777
2778
  if (option.mode === DeleteMode.Common) {
2778
2779
  const params = new Array();
2779
- const whereSql = iterare(wheres).map(where => {
2780
+ const whereSql = iterate(wheres).map(where => {
2780
2781
  return `(
2781
2782
  ${Object.entries(where).map(([K, V]) => {
2782
2783
  params.push(V);
@@ -2820,7 +2821,7 @@ export class SqlService {
2820
2821
  }
2821
2822
  case DBType.Sqlite:
2822
2823
  case DBType.SqliteRemote: {
2823
- const columnNames = iterare(delWhere).map(K => this[_fields][K]?.C2()).join(',');
2824
+ const columnNames = iterate(delWhere).map(K => this[_fields][K]?.C2()).join(',');
2824
2825
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2825
2826
  sqls.push({
2826
2827
  sql: formatDialect(`UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
@@ -2906,13 +2907,13 @@ export class SqlService {
2906
2907
  const ids = option.id instanceof Array ? option.id : [option.id];
2907
2908
  option.where = ids.map(i => ({ [idName]: i }));
2908
2909
  }
2909
- const columns = option.templateResult === TemplateResult.Count ? 'COUNT(1) ct' : iterare((option.columns ?? this[_columns])).map((K) => `a.${this[_fields][K]?.C3()}`).join(',');
2910
+ const columns = option.templateResult === TemplateResult.Count ? 'COUNT(1) ct' : iterate((option.columns ?? this[_columns])).map((K) => `a.${this[_fields][K]?.C3()}`).join(',');
2910
2911
  const wheres = option.where instanceof Array ? option.where : [option.where];
2911
2912
  const sqls = [];
2912
2913
  let resultIndex = -1;
2913
2914
  if (option.mode === SelectMode.Common) {
2914
2915
  const params = new Array();
2915
- const whereSql = formatDialect(iterare(wheres).map(where => this[_transformer](where, option)).map(where => {
2916
+ const whereSql = formatDialect(iterate(wheres).map(where => this[_transformer](where, option)).map(where => {
2916
2917
  return `SELECT ${columns} FROM ${tableNameESC} a WHERE
2917
2918
  ${Object.entries(where).map(([K, V]) => {
2918
2919
  params.push(V);
@@ -3017,10 +3018,10 @@ export class SqlService {
3017
3018
  }
3018
3019
  case SelectResult.RS_CS: {
3019
3020
  if (mapper) {
3020
- return iterare(result).map((data) => flatData({ data, mapper, mapperIfUndefined })).toArray();
3021
+ return iterate(result).map((data) => flatData({ data, mapper, mapperIfUndefined })).toArray();
3021
3022
  }
3022
3023
  else if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
3023
- return iterare(result).map((r) => C2P2(r)).toArray();
3024
+ return iterate(result).map((r) => C2P2(r)).toArray();
3024
3025
  }
3025
3026
  else {
3026
3027
  return result;
@@ -3036,10 +3037,10 @@ export class SqlService {
3036
3037
  }
3037
3038
  case SelectResult.RS_CS_List: {
3038
3039
  if (mapper) {
3039
- return new ArrayList(iterare(result).map((data) => flatData({ data, mapper, mapperIfUndefined })).toArray());
3040
+ return new ArrayList(iterate(result).map((data) => flatData({ data, mapper, mapperIfUndefined })).toArray());
3040
3041
  }
3041
3042
  else if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
3042
- return new ArrayList(iterare(result).map((r) => C2P2(r)).toArray());
3043
+ return new ArrayList(iterate(result).map((r) => C2P2(r)).toArray());
3043
3044
  }
3044
3045
  else {
3045
3046
  return new ArrayList();
@@ -3272,7 +3273,7 @@ export class SqlService {
3272
3273
  Throw.if(list.length === 0, 'not found data!');
3273
3274
  const columnTitles = new Array();
3274
3275
  const keys = this[_fields] ?
3275
- iterare(Object.entries(this[_fields]))
3276
+ iterate(Object.entries(this[_fields]))
3276
3277
  .filter(([K, F]) => (F.id !== true && F.exportable !== false) || (F.id === true && F.exportable === true))
3277
3278
  .map(([K, F]) => {
3278
3279
  columnTitles.push(F.comment ?? K);
@@ -3291,7 +3292,7 @@ export class SqlService {
3291
3292
  imp() {
3292
3293
  Throw.if(!this[_fields], 'not set fields!');
3293
3294
  const columnTitles = new Array();
3294
- const keys = iterare(Object.entries(this[_fields]))
3295
+ const keys = iterate(Object.entries(this[_fields]))
3295
3296
  .filter(([K, F]) => (F.id !== true && F.exportable !== false) || (F.id === true && F.exportable === true))
3296
3297
  .map(([K, F]) => {
3297
3298
  columnTitles.push(F.comment ?? K);
@@ -3317,7 +3318,7 @@ export class SqlService {
3317
3318
  const tableVersion = option.conn.pluck(SyncMode.Sync, 'SELECT ______version v from TABLE_VERSION WHERE ______tableName = ?', [option.tableName]);
3318
3319
  if (tableVersion && tableVersion < lastVersion) { // 发现需要升级的版本
3319
3320
  // 更新版本
3320
- const columns = iterare(option.conn.query(SyncMode.Sync, `PRAGMA table_info(${tableES})`))
3321
+ const columns = iterate(option.conn.query(SyncMode.Sync, `PRAGMA table_info(${tableES})`))
3321
3322
  .filter(c => this[_fields].hasOwnProperty(C2P(c.name, globalThis[_Hump])))
3322
3323
  .map(c => c.name)
3323
3324
  .join(',');
@@ -3376,7 +3377,7 @@ export class SqlService {
3376
3377
  const tableVersion = await option.conn.pluck(SyncMode.Async, 'SELECT ______version v from TABLE_VERSION WHERE ______tableName = ?', [option.tableName]);
3377
3378
  if (tableVersion && tableVersion < lastVersion) { // 发现需要升级的版本
3378
3379
  // 更新版本
3379
- const columns = iterare(await option.conn.query(SyncMode.Async, `PRAGMA table_info(${tableES})`))
3380
+ const columns = iterate(await option.conn.query(SyncMode.Async, `PRAGMA table_info(${tableES})`))
3380
3381
  .filter(c => this[_fields].hasOwnProperty(C2P(c.name, globalThis[_Hump])))
3381
3382
  .map(c => c.name)
3382
3383
  .join(',');
package/sqlite.js CHANGED
@@ -154,7 +154,7 @@ export class SqliteRemoteClass {
154
154
  }
155
155
  else {
156
156
  for (const db of Object.values(this.dbList)) {
157
- db.close();
157
+ db?.close();
158
158
  }
159
159
  this.dbList = {};
160
160
  }
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
  }