baja-lite 1.1.8 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.1.8",
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": {
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 { 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(iterare(option?.skipId === true ? __columnsNoId : __columns)
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 = iterare(conditions).map(c => `${this[_fields][c]?.C2()} = ?`).join(' AND ');
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 = iterare(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
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 = iterare(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
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 = iterare(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
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 = iterare(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
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 ${iterare(this[_ids]).map(c => `${this[_fields][c]?.C2()} = ?`).join(' AND ')} THEN ?`;
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 ${iterare(this[_columnsNoId])
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);
@@ -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 = iterare(wheres).map(where => {
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 = iterare(delWhere).map(K => this[_fields][K]?.C2()).join(',');
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' : iterare((option.columns ?? this[_columns])).map((K) => `a.${this[_fields][K]?.C3()}`).join(',');
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(iterare(wheres).map(where => this[_transformer](where, option)).map(where => {
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 iterare(result).map((data) => flatData({ data, mapper, mapperIfUndefined })).toArray();
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 iterare(result).map((r) => C2P2(r)).toArray();
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(iterare(result).map((data) => flatData({ data, mapper, mapperIfUndefined })).toArray());
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(iterare(result).map((r) => C2P2(r)).toArray());
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
- iterare(Object.entries(this[_fields]))
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 = iterare(Object.entries(this[_fields]))
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 = iterare(option.conn.query(SyncMode.Sync, `PRAGMA table_info(${tableES})`))
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 = iterare(await option.conn.query(SyncMode.Async, `PRAGMA table_info(${tableES})`))
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
  }