baja-lite 1.6.2 → 1.6.4

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 (73) hide show
  1. package/.eslintignore +7 -0
  2. package/.eslintrc.cjs +89 -0
  3. package/.prettierrc +7 -0
  4. package/.vscode/settings.json +9 -0
  5. package/ci.js +33 -0
  6. package/package-cjs.json +17 -0
  7. package/package.json +80 -80
  8. package/pnpm-lock.yaml +2840 -0
  9. package/pnpm-workspace.yaml +2 -0
  10. package/{boot-remote.js → src/boot-remote.ts} +64 -63
  11. package/{boot.js → src/boot.ts} +170 -163
  12. package/{code.js → src/code.ts} +526 -517
  13. package/{convert-xml.js → src/convert-xml.ts} +460 -410
  14. package/src/error.ts +11 -0
  15. package/src/event.ts +34 -0
  16. package/src/fn.ts +295 -0
  17. package/{index.d.ts → src/index.ts} +11 -10
  18. package/src/math.ts +405 -0
  19. package/src/object.ts +342 -0
  20. package/{snowflake.js → src/snowflake.ts} +127 -108
  21. package/src/sql.ts +5529 -0
  22. package/{sqlite.js → src/sqlite.ts} +157 -156
  23. package/src/string.ts +111 -0
  24. package/src/test-mysql.ts +148 -0
  25. package/{test-postgresql.js → src/test-postgresql.ts} +80 -91
  26. package/{test-sqlite.js → src/test-sqlite.ts} +80 -90
  27. package/{test-xml.js → src/test-xml.ts} +70 -70
  28. package/{test.js → src/test.ts} +3 -2
  29. package/src/wx/base.ts +77 -0
  30. package/src/wx/mini.ts +147 -0
  31. package/src/wx/organ.ts +290 -0
  32. package/{wx/types.d.ts → src/wx/types.ts} +549 -560
  33. package/{wx.d.ts → src/wx.ts} +3 -3
  34. package/tsconfig.cjs.json +42 -0
  35. package/tsconfig.json +44 -0
  36. package/xml/event-report.xml +13 -0
  37. package/yarn.lock +1977 -0
  38. package/boot-remote.d.ts +0 -2
  39. package/boot.d.ts +0 -2
  40. package/code.d.ts +0 -2
  41. package/convert-xml.d.ts +0 -10
  42. package/error.d.ts +0 -5
  43. package/error.js +0 -13
  44. package/event.d.ts +0 -10
  45. package/event.js +0 -38
  46. package/fn.d.ts +0 -128
  47. package/fn.js +0 -172
  48. package/index.js +0 -10
  49. package/math.d.ts +0 -83
  50. package/math.js +0 -451
  51. package/object.d.ts +0 -126
  52. package/object.js +0 -321
  53. package/snowflake.d.ts +0 -12
  54. package/sql.d.ts +0 -2148
  55. package/sql.js +0 -5372
  56. package/sqlite.d.ts +0 -32
  57. package/string.d.ts +0 -17
  58. package/string.js +0 -105
  59. package/test-mysql.d.ts +0 -2
  60. package/test-mysql.js +0 -114
  61. package/test-postgresql.d.ts +0 -2
  62. package/test-sqlite.d.ts +0 -1
  63. package/test-xml.d.ts +0 -1
  64. package/test.d.ts +0 -1
  65. package/wx/base.d.ts +0 -11
  66. package/wx/base.js +0 -78
  67. package/wx/mini.d.ts +0 -52
  68. package/wx/mini.js +0 -112
  69. package/wx/organ.d.ts +0 -65
  70. package/wx/organ.js +0 -171
  71. package/wx/types.js +0 -1
  72. package/wx.js +0 -3
  73. /package/{README.md → Readme.md} +0 -0
@@ -1,91 +1,80 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { DBType, Field, SqlType } from 'baja-lite-field';
11
- import 'reflect-metadata';
12
- import { Boot } from './boot.js';
13
- import { ColumnMode, DB, SelectResult, SqlService, } from './sql.js';
14
- class AmaFuck2 {
15
- }
16
- __decorate([
17
- Field({ type: SqlType.int, length: 200, id: true, uuid: true }),
18
- __metadata("design:type", Number)
19
- ], AmaFuck2.prototype, "userid", void 0);
20
- __decorate([
21
- Field({ type: SqlType.varchar, length: 200, def: '333' }),
22
- __metadata("design:type", String)
23
- ], AmaFuck2.prototype, "username", void 0);
24
- __decorate([
25
- Field({ type: SqlType.varchar, length: 200 }),
26
- __metadata("design:type", String)
27
- ], AmaFuck2.prototype, "pwd", void 0);
28
- let AmaService2 = class AmaService2 extends SqlService {
29
- };
30
- AmaService2 = __decorate([
31
- DB({
32
- tableName: 'nfc_user', clz: AmaFuck2, dbType: DBType.Postgresql
33
- })
34
- ], AmaService2);
35
- // interface Menu {
36
- // resourceid: string;
37
- // resourcepid: string;
38
- // resourcename: string;
39
- // children: Menu[];
40
- // }
41
- export async function go2() {
42
- await Boot({
43
- Postgresql: {
44
- database: 'nfc',
45
- user: 'postgres',
46
- password: 'abcd1234',
47
- port: 5432,
48
- host: '127.0.0.1'
49
- },
50
- log: 'info',
51
- columnMode: ColumnMode.HUMP,
52
- sqlDir: 'E:/pro/baja-lite/xml',
53
- sqlMap: {
54
- ['test.test']: `SELECT * FROM nfc_user {{#username}} WHERE username = :username {{/username}}`
55
- }
56
- });
57
- const service = new AmaService2();
58
- await service.transaction({
59
- fn: async (conn) => {
60
- const rt5 = await service.select({
61
- sqlId: 'test.test',
62
- params: { username: '1111' },
63
- selectResult: SelectResult.RS_CS,
64
- conn
65
- });
66
- console.log(55, rt5.length);
67
- await service.insert({
68
- data: {
69
- userid: 22,
70
- username: '222',
71
- pwd: '333'
72
- }
73
- });
74
- return 1;
75
- }
76
- });
77
- // const data = await service.select<Menu>({
78
- // sql: 'SELECT resourceid, resourcepid,resourcename FROM cp_resource ',
79
- // params: {
80
- // site: '1234',
81
- // matchInfo: { reportType: 'yyyy', id: '11' }
82
- // },
83
- // // mapper: [
84
- // // ['site', ['info', 'bSist'], 989],
85
- // // ['site', ['info2', 'bSist'], 33],
86
- // // ['site', ['Bsite'], 0]
87
- // // ]
88
- // });
89
- // console.log(data);
90
- }
91
- go2();
1
+ import { DBType, Field, SqlType } from 'baja-lite-field';
2
+ import 'reflect-metadata';
3
+ import { Boot } from './boot.js';
4
+ import { ColumnMode, DB, SelectResult, SqlService, } from './sql.js';
5
+ class AmaFuck2 {
6
+ @Field({ type: SqlType.int, length: 200, id: true, uuid: true })
7
+ userid?: number;
8
+ @Field({ type: SqlType.varchar, length: 200, def: '333' })
9
+ username?: string;
10
+ @Field({ type: SqlType.varchar, length: 200 })
11
+ pwd?: string;
12
+ }
13
+
14
+ @DB({
15
+ tableName: 'nfc_user', clz: AmaFuck2, dbType: DBType.Postgresql
16
+ })
17
+ class AmaService2 extends SqlService<AmaFuck2> {
18
+
19
+ }
20
+
21
+ // interface Menu {
22
+ // resourceid: string;
23
+ // resourcepid: string;
24
+ // resourcename: string;
25
+ // children: Menu[];
26
+ // }
27
+
28
+ export async function go2() {
29
+ await Boot({
30
+ Postgresql: {
31
+ database: 'nfc',
32
+ user: 'postgres',
33
+ password: 'abcd1234',
34
+ port: 5432,
35
+ host: '127.0.0.1'
36
+ },
37
+ log: 'info',
38
+ columnMode: ColumnMode.HUMP,
39
+ sqlDir: 'E:/pro/baja-lite/xml',
40
+ sqlMap: {
41
+ ['test.test']: `SELECT * FROM nfc_user {{#username}} WHERE username = :username {{/username}}`
42
+ }
43
+ });
44
+ const service = new AmaService2();
45
+ await service.transaction<number>({
46
+ fn: async conn => {
47
+ const rt5 = await service.select<{ username: string }>({
48
+ sqlId: 'test.test',
49
+ params: { username: '1111' },
50
+ selectResult: SelectResult.RS_CS,
51
+ conn
52
+ })
53
+ console.log(55, rt5.length);
54
+ await service.insert({
55
+ data: {
56
+ userid: 22,
57
+ username: '222',
58
+ pwd: '333'
59
+ }
60
+ })
61
+ return 1;
62
+ }
63
+ });
64
+
65
+ // const data = await service.select<Menu>({
66
+ // sql: 'SELECT resourceid, resourcepid,resourcename FROM cp_resource ',
67
+ // params: {
68
+ // site: '1234',
69
+ // matchInfo: { reportType: 'yyyy', id: '11' }
70
+ // },
71
+ // // mapper: [
72
+ // // ['site', ['info', 'bSist'], 989],
73
+ // // ['site', ['info2', 'bSist'], 33],
74
+ // // ['site', ['Bsite'], 0]
75
+ // // ]
76
+ // });
77
+ // console.log(data);
78
+
79
+ }
80
+ go2();
@@ -1,90 +1,80 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { DBType, Field, SqlType } from 'baja-lite-field';
11
- import 'reflect-metadata';
12
- import { Boot } from './boot';
13
- import { DB, DeleteMode, InsertMode, SqlService, SyncMode } from './sql';
14
- class AmaFuck {
15
- }
16
- __decorate([
17
- Field({ type: SqlType.varchar }),
18
- __metadata("design:type", String)
19
- ], AmaFuck.prototype, "site", void 0);
20
- __decorate([
21
- Field({ type: SqlType.varchar }),
22
- __metadata("design:type", String)
23
- ], AmaFuck.prototype, "SellerSKU2", void 0);
24
- __decorate([
25
- Field({ type: SqlType.varchar, id: true }),
26
- __metadata("design:type", String)
27
- ], AmaFuck.prototype, "SellerSKU", void 0);
28
- let AmaService = class AmaService extends SqlService {
29
- };
30
- AmaService = __decorate([
31
- DB({
32
- tableName: 'ama_fuck2', clz: AmaFuck, dbType: DBType.Sqlite, sqliteVersion: '0.0.3'
33
- })
34
- ], AmaService);
35
- async function go() {
36
- await Boot({
37
- Sqlite: 'd:1.db',
38
- log: 'info'
39
- });
40
- const service = new AmaService();
41
- const ret = service.transaction({
42
- sync: SyncMode.Sync,
43
- fn: conn => {
44
- const list = new Array({
45
- SellerSKU: '1',
46
- site: '111'
47
- }, {
48
- SellerSKU: '2',
49
- SellerSKU2: '22',
50
- }, {
51
- SellerSKU2: '33',
52
- SellerSKU: '3',
53
- site: '333'
54
- }, {
55
- SellerSKU2: '44',
56
- SellerSKU: '4',
57
- site: '444'
58
- }, {
59
- SellerSKU2: '',
60
- SellerSKU: '66',
61
- site: undefined
62
- });
63
- const rt = service.insert({
64
- sync: SyncMode.Sync,
65
- data: list,
66
- conn, skipEmptyString: false, mode: InsertMode.InsertWithTempTable
67
- });
68
- console.log(rt);
69
- const rt2 = service.update({
70
- sync: SyncMode.Sync,
71
- data: list,
72
- conn, skipEmptyString: false
73
- });
74
- console.log(rt2);
75
- const rt3 = service.delete({
76
- sync: SyncMode.Sync,
77
- where: [
78
- { SellerSKU2: '11', SellerSKU: '1' },
79
- { SellerSKU2: '22', SellerSKU: '2' },
80
- { SellerSKU2: '33', SellerSKU: '3' }
81
- ],
82
- mode: DeleteMode.TempTable
83
- });
84
- console.log(rt3);
85
- return 1;
86
- }
87
- });
88
- return ret;
89
- }
90
- go();
1
+ import { DBType, Field, SqlType } from 'baja-lite-field';
2
+ import 'reflect-metadata';
3
+ import { Boot } from './boot';
4
+ import { DB, DeleteMode, InsertMode, SqlService, SyncMode } from './sql';
5
+ class AmaFuck {
6
+ @Field({ type: SqlType.varchar })
7
+ site?: string;
8
+ @Field({ type: SqlType.varchar })
9
+ SellerSKU2?: string;
10
+ @Field({ type: SqlType.varchar, id: true })
11
+ SellerSKU?: string;
12
+ }
13
+
14
+ @DB({
15
+ tableName: 'ama_fuck2', clz: AmaFuck, dbType: DBType.Sqlite, sqliteVersion: '0.0.3'
16
+ })
17
+ class AmaService extends SqlService<AmaFuck> {
18
+
19
+ }
20
+ async function go() {
21
+ await Boot({
22
+ Sqlite: 'd:1.db',
23
+ log: 'info'
24
+ });
25
+ const service = new AmaService();
26
+ const ret = service.transaction<number>({
27
+ sync: SyncMode.Sync,
28
+ fn: conn => {
29
+ const list = new Array<AmaFuck>({
30
+ SellerSKU: '1',
31
+ site: '111'
32
+ }, {
33
+ SellerSKU: '2',
34
+ SellerSKU2: '22',
35
+ }, {
36
+ SellerSKU2: '33',
37
+ SellerSKU: '3',
38
+ site: '333'
39
+ }, {
40
+ SellerSKU2: '44',
41
+ SellerSKU: '4',
42
+ site: '444'
43
+ }, {
44
+ SellerSKU2: '',
45
+ SellerSKU: '66',
46
+ site: undefined
47
+ });
48
+ const rt = service.insert({
49
+ sync: SyncMode.Sync,
50
+ data: list,
51
+ conn, skipEmptyString: false, mode: InsertMode.InsertWithTempTable
52
+ });
53
+ console.log(rt);
54
+ const rt2 = service.update({
55
+ sync: SyncMode.Sync,
56
+ data: list,
57
+ conn, skipEmptyString: false
58
+ });
59
+ console.log(rt2);
60
+ const rt3 = service.delete({
61
+ sync: SyncMode.Sync,
62
+ where: [
63
+ { SellerSKU2: '11', SellerSKU: '1' },
64
+ { SellerSKU2: '22', SellerSKU: '2' },
65
+ { SellerSKU2: '33', SellerSKU: '3' }
66
+ ],
67
+ mode: DeleteMode.TempTable
68
+ });
69
+ console.log(rt3);
70
+ return 1;
71
+ }
72
+ });
73
+ return ret;
74
+ }
75
+
76
+
77
+
78
+
79
+
80
+ go();
@@ -1,70 +1,70 @@
1
- import HTML from 'html-parse-stringify';
2
- console.log((HTML.parse(`
3
- <sql id="reportField">
4
- a.left_e_foul leftEFoul,
5
- a.right_e_foul rightEFoul,
6
- a.left_em_foul leftEmFoul,
7
- a.right_em_foul rightEmFoul,
8
- a.left_s_foul leftSFoul,
9
- a.right_s_foul rightSFoul,
10
- a.left_sb_foul leftSbFoul,
11
- a.right_sb_foul rightSbFoul,
12
- a.left_p_foul leftPFoul,
13
- a.right_p_foul rightPFoul,
14
- a.left_attack_goal leftAttackGoal,
15
- a.right_attack_goal rightAttackGoal,
16
- a.left_point_goal leftPointGoal,
17
- a.right_point_goal rightPointGoal,
18
- a.left_over_time_goal leftOverTimeGoal,
19
- a.right_over_time_goal rightOverTimeGoal,
20
- a.left_normal_goal leftNormalGoal,
21
- a.right_normal_goal rightNormalGoal,
22
- a.left_own_goal leftOwnGoal,
23
- a.right_own_goal rightOwnGoal,
24
- a.left_time_out leftTimeOut,
25
- a.right_time_out rightTimeOut,
26
- a.left_coach_y_card leftCoachYCard,
27
- a.right_coach_y_card rightCoachYCard,
28
- a.left_player_r_card leftPlayerRCard,
29
- a.right_player_r_card rightPlayerRCard,
30
- a.left_jump_ball leftJumpBall,
31
- a.right_jump_ball rightJumpBall
32
- </sql>
33
- <select id="matchReport" resultType="org.jeecg.modules.event.entity.EventMatchReport">
34
- select
35
- b.event_name eventName,
36
- a.match_id matchId,
37
- a.event_times eventTimes,
38
- a.team_left_id teamLeftId,
39
- a.team_RIGHt_id teamRightId,
40
- a.team_left_name teamLeftName,
41
- a.team_right_name teamRightName,
42
- a.team_left_image teamLeftImage,
43
- a.team_right_image teamRightImage,
44
- <include refid="reportField" />
45
- <if test="matchInfo.reportType!=null and matchInfo.reportType!=''">
46
- from view_match_report a
47
- </if>
48
- <if test="matchInfo.reportType==null or matchInfo.reportType==''">
49
- from event_match_report a
50
- </if>
51
- left join event_main_info b on a.event_id = b.id
52
- <where>
53
- <if test="matchInfo.id!=null and matchInfo.id!=''">
54
- and a.match_id = #{matchInfo.id}
55
- </if>
56
- <if test="matchInfo.eventId!=null and matchInfo.eventId!=''">
57
- and a.event_id = #{matchInfo.eventId}
58
- </if>
59
- <if test="matchInfo.teamLeftId!=null and matchInfo.teamLeftId!=''">
60
- and (a.team_left_id = #{matchInfo.teamLeftId} OR a.team_right_id = #{matchInfo.teamLeftId})
61
- </if>
62
- <if test="dataIdList!=null">
63
- and a.event_id in
64
- <foreach collection="dataIdList" item="item" open="(" close=")" separator=",">
65
- #{item}
66
- </foreach>
67
- </if>
68
- </where>
69
- </select>
70
- >`)));
1
+ import HTML from 'html-parse-stringify';
2
+ console.log((HTML.parse(`
3
+ <sql id="reportField">
4
+ a.left_e_foul leftEFoul,
5
+ a.right_e_foul rightEFoul,
6
+ a.left_em_foul leftEmFoul,
7
+ a.right_em_foul rightEmFoul,
8
+ a.left_s_foul leftSFoul,
9
+ a.right_s_foul rightSFoul,
10
+ a.left_sb_foul leftSbFoul,
11
+ a.right_sb_foul rightSbFoul,
12
+ a.left_p_foul leftPFoul,
13
+ a.right_p_foul rightPFoul,
14
+ a.left_attack_goal leftAttackGoal,
15
+ a.right_attack_goal rightAttackGoal,
16
+ a.left_point_goal leftPointGoal,
17
+ a.right_point_goal rightPointGoal,
18
+ a.left_over_time_goal leftOverTimeGoal,
19
+ a.right_over_time_goal rightOverTimeGoal,
20
+ a.left_normal_goal leftNormalGoal,
21
+ a.right_normal_goal rightNormalGoal,
22
+ a.left_own_goal leftOwnGoal,
23
+ a.right_own_goal rightOwnGoal,
24
+ a.left_time_out leftTimeOut,
25
+ a.right_time_out rightTimeOut,
26
+ a.left_coach_y_card leftCoachYCard,
27
+ a.right_coach_y_card rightCoachYCard,
28
+ a.left_player_r_card leftPlayerRCard,
29
+ a.right_player_r_card rightPlayerRCard,
30
+ a.left_jump_ball leftJumpBall,
31
+ a.right_jump_ball rightJumpBall
32
+ </sql>
33
+ <select id="matchReport" resultType="org.jeecg.modules.event.entity.EventMatchReport">
34
+ select
35
+ b.event_name eventName,
36
+ a.match_id matchId,
37
+ a.event_times eventTimes,
38
+ a.team_left_id teamLeftId,
39
+ a.team_RIGHt_id teamRightId,
40
+ a.team_left_name teamLeftName,
41
+ a.team_right_name teamRightName,
42
+ a.team_left_image teamLeftImage,
43
+ a.team_right_image teamRightImage,
44
+ <include refid="reportField" />
45
+ <if test="matchInfo.reportType!=null and matchInfo.reportType!=''">
46
+ from view_match_report a
47
+ </if>
48
+ <if test="matchInfo.reportType==null or matchInfo.reportType==''">
49
+ from event_match_report a
50
+ </if>
51
+ left join event_main_info b on a.event_id = b.id
52
+ <where>
53
+ <if test="matchInfo.id!=null and matchInfo.id!=''">
54
+ and a.match_id = #{matchInfo.id}
55
+ </if>
56
+ <if test="matchInfo.eventId!=null and matchInfo.eventId!=''">
57
+ and a.event_id = #{matchInfo.eventId}
58
+ </if>
59
+ <if test="matchInfo.teamLeftId!=null and matchInfo.teamLeftId!=''">
60
+ and (a.team_left_id = #{matchInfo.teamLeftId} OR a.team_right_id = #{matchInfo.teamLeftId})
61
+ </if>
62
+ <if test="dataIdList!=null">
63
+ and a.event_id in
64
+ <foreach collection="dataIdList" item="item" open="(" close=")" separator=",">
65
+ #{item}
66
+ </foreach>
67
+ </if>
68
+ </where>
69
+ </select>
70
+ >`)));
@@ -1,2 +1,3 @@
1
- import { snowflake } from "snowflake";
2
- console.log(snowflake.generate());
1
+ import { snowflake } from "snowflake";
2
+
3
+ console.log(snowflake.generate());
package/src/wx/base.ts ADDED
@@ -0,0 +1,77 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
2
+ import pino from 'pino';
3
+ import * as rp from 'request-promise';
4
+ import { Throw } from '../error.js';
5
+ const logger =
6
+ process.env['NODE_ENV'] !== 'production' ? pino({
7
+ name: 'wx',
8
+ transport: {
9
+ target: 'pino-pretty'
10
+ }
11
+ }) : pino({ name: 'wx' });
12
+ export abstract class BaseWx {
13
+ protected authErrorCodes = [40001, 40014, 41001, 42001];
14
+ protected name: string = '';
15
+ protected tokenUrl: string = '';
16
+ private tokenData = '';
17
+ protected mock = false;
18
+ protected async getToken(force?: boolean): Promise<string> {
19
+ let token = '';
20
+ const now = +new Date();
21
+ let need = force === true;
22
+ if (this.tokenData) {
23
+ const datas = this.tokenData.split('^_^');
24
+ token = datas[0]!;
25
+ const lastTime = datas[1]!;
26
+ const spliceTime = datas[2]!;
27
+ if (now - parseInt(lastTime, 10) - parseInt(spliceTime, 10) > 0) {
28
+ need = true;
29
+ }
30
+ } else {
31
+ need = true;
32
+ }
33
+ if (need === true) {
34
+ const data = await this.fetch(() => this.tokenUrl, 'get', {}, false);
35
+ token = data.access_token;
36
+ this.tokenData = `${token}^_^${now}^_^${data.expires_in * 1000}`;
37
+ }
38
+ return token;
39
+ }
40
+ protected async fetch(uri: (token: string) => string, method: 'get' | 'post', data: { [key: string]: any }, needToken = true, buffer = false) {
41
+ if (this.mock === true) {
42
+ return {};
43
+ }
44
+ let token = needToken ? await this.getToken() : '';
45
+ if (!needToken || token) {
46
+ const start = +new Date();
47
+ let url = uri(token);
48
+ const param = method === 'get' ? {
49
+ method,
50
+ json: buffer ? false : true,
51
+ qs: data,
52
+ encoding: buffer ? null : undefined
53
+ } : {
54
+ json: data,
55
+ method,
56
+ encoding: buffer ? null : undefined
57
+ };
58
+
59
+ let response = await rp.default({
60
+ uri: url,
61
+ ...param
62
+ });
63
+ if (this.authErrorCodes.includes(response.errcode)) {
64
+ token = await this.getToken(true);
65
+ url = uri(token);
66
+ response = await rp.default({
67
+ uri: url,
68
+ ...param
69
+ });
70
+ Throw.if(response.errcode && response.errcode - 0 !== 0, `${url}-${response.errcode}-${response.errmsg}`);
71
+ }
72
+ Throw.if(response.errcode && response.errcode - 0 !== 0, `${url}-${response.errcode}-${response.errmsg}`);
73
+ logger.info(`fetch data ${+new Date() - start} ms`);
74
+ return response;
75
+ }
76
+ }
77
+ }