baja-lite 1.6.4 → 1.6.5
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/boot-remote.d.ts +2 -0
- package/{src/boot-remote.ts → boot-remote.js} +63 -64
- package/boot.d.ts +2 -0
- package/{src/boot.ts → boot.js} +163 -170
- package/code.d.ts +2 -0
- package/{src/code.ts → code.js} +405 -414
- package/convert-xml.d.ts +10 -0
- package/{src/convert-xml.ts → convert-xml.js} +410 -460
- package/error.d.ts +5 -0
- package/error.js +13 -0
- package/event.d.ts +10 -0
- package/event.js +38 -0
- package/fn.d.ts +128 -0
- package/fn.js +172 -0
- package/{src/index.ts → index.d.ts} +10 -11
- package/index.js +10 -0
- package/math.d.ts +83 -0
- package/math.js +451 -0
- package/object.d.ts +126 -0
- package/object.js +321 -0
- package/package.json +1 -1
- package/snowflake.d.ts +12 -0
- package/{src/snowflake.ts → snowflake.js} +108 -127
- package/sql.d.ts +2148 -0
- package/sql.js +5370 -0
- package/sqlite.d.ts +32 -0
- package/{src/sqlite.ts → sqlite.js} +156 -157
- package/string.d.ts +17 -0
- package/string.js +105 -0
- package/test-mysql.d.ts +2 -0
- package/test-mysql.js +114 -0
- package/test-postgresql.d.ts +2 -0
- package/{src/test-postgresql.ts → test-postgresql.js} +91 -80
- package/test-sqlite.d.ts +1 -0
- package/{src/test-sqlite.ts → test-sqlite.js} +90 -80
- package/test-xml.d.ts +1 -0
- package/{src/test-xml.ts → test-xml.js} +2 -2
- package/test.d.ts +1 -0
- package/{src/test.ts → test.js} +2 -3
- package/wx/base.d.ts +11 -0
- package/wx/base.js +78 -0
- package/wx/mini.d.ts +52 -0
- package/wx/mini.js +112 -0
- package/wx/organ.d.ts +65 -0
- package/wx/organ.js +171 -0
- package/{src/wx/types.ts → wx/types.d.ts} +560 -549
- package/wx/types.js +1 -0
- package/{src/wx.ts → wx.d.ts} +3 -3
- package/wx.js +3 -0
- package/.eslintignore +0 -7
- package/.eslintrc.cjs +0 -89
- package/.prettierrc +0 -7
- package/.vscode/settings.json +0 -9
- package/ci.js +0 -33
- package/package-cjs.json +0 -17
- package/pnpm-lock.yaml +0 -2840
- package/pnpm-workspace.yaml +0 -2
- package/src/error.ts +0 -11
- package/src/event.ts +0 -34
- package/src/fn.ts +0 -295
- package/src/math.ts +0 -405
- package/src/object.ts +0 -342
- package/src/sql.ts +0 -5529
- package/src/string.ts +0 -111
- package/src/test-mysql.ts +0 -148
- package/src/wx/base.ts +0 -77
- package/src/wx/mini.ts +0 -147
- package/src/wx/organ.ts +0 -290
- package/tsconfig.cjs.json +0 -42
- package/tsconfig.json +0 -44
- package/xml/event-report.xml +0 -13
- package/yarn.lock +0 -1977
- /package/{Readme.md → README.md} +0 -0
package/boot-remote.d.ts
ADDED
|
@@ -1,64 +1,63 @@
|
|
|
1
|
-
import { DBType, _Hump, getEnums } from 'baja-lite-field';
|
|
2
|
-
import { ColumnMode,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
options.SqliteRemote.service
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
let flag = false;
|
|
42
|
-
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
43
|
-
await options.SqliteRemote.service.initDB(fileName);
|
|
44
|
-
const db = new SqliteRemote(options.SqliteRemote.service, fileName);
|
|
45
|
-
if (flag === false) {
|
|
46
|
-
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
|
|
47
|
-
flag = true;
|
|
48
|
-
}
|
|
49
|
-
globalThis[_dao][DBType.SqliteRemote][key] = db;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
// globalThis[_GlobalSqlOption].SqliteRemote.service
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
// }
|
|
1
|
+
import { DBType, _Hump, getEnums } from 'baja-lite-field';
|
|
2
|
+
import { ColumnMode, SqlCache, SqliteRemote, _DataConvert, _GlobalSqlOption, _dao, _defOption, _enum, _primaryDB, _sqlCache, logger } from './sql.js';
|
|
3
|
+
export const BootRomote = async function (options) {
|
|
4
|
+
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption);
|
|
5
|
+
if (options.skipEmptyString !== undefined) {
|
|
6
|
+
globalThis[_GlobalSqlOption].skipEmptyString = options.skipEmptyString;
|
|
7
|
+
}
|
|
8
|
+
if (options.skipNull !== undefined) {
|
|
9
|
+
globalThis[_GlobalSqlOption].skipNull = options.skipNull;
|
|
10
|
+
}
|
|
11
|
+
if (options.skipEmptyString !== undefined) {
|
|
12
|
+
globalThis[_GlobalSqlOption].skipEmptyString = options.skipEmptyString;
|
|
13
|
+
}
|
|
14
|
+
if (options.maxDeal !== undefined) {
|
|
15
|
+
globalThis[_GlobalSqlOption].maxDeal = options.maxDeal;
|
|
16
|
+
}
|
|
17
|
+
if (options.SqliteRemote !== undefined) {
|
|
18
|
+
globalThis[_GlobalSqlOption].SqliteRemote = options.SqliteRemote;
|
|
19
|
+
}
|
|
20
|
+
globalThis[_Hump] = options.columnMode === ColumnMode.HUMP;
|
|
21
|
+
logger.level = options.log ?? 'info';
|
|
22
|
+
globalThis[_sqlCache] = new SqlCache();
|
|
23
|
+
if (options.sqlMap) {
|
|
24
|
+
await globalThis[_sqlCache].init(options);
|
|
25
|
+
}
|
|
26
|
+
globalThis[_dao] = {
|
|
27
|
+
[DBType.SqliteRemote]: {},
|
|
28
|
+
};
|
|
29
|
+
if (options.enums) {
|
|
30
|
+
globalThis[_enum] = getEnums(options.enums);
|
|
31
|
+
}
|
|
32
|
+
if (options.dataConvert) {
|
|
33
|
+
globalThis[_DataConvert] = options.dataConvert;
|
|
34
|
+
}
|
|
35
|
+
if (options.SqliteRemote && options.SqliteRemote.db) {
|
|
36
|
+
if (typeof options.SqliteRemote.db === 'string') {
|
|
37
|
+
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
38
|
+
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
let flag = false;
|
|
42
|
+
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
43
|
+
await options.SqliteRemote.service.initDB(fileName);
|
|
44
|
+
const db = new SqliteRemote(options.SqliteRemote.service, fileName);
|
|
45
|
+
if (flag === false) {
|
|
46
|
+
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
|
|
47
|
+
flag = true;
|
|
48
|
+
}
|
|
49
|
+
globalThis[_dao][DBType.SqliteRemote][key] = db;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
// export const AppendRomote = async function (dbName: string) {
|
|
55
|
+
// if (!globalThis[_dao][DBType.SqliteRemote][dbName]) {
|
|
56
|
+
// globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
|
|
57
|
+
// const db = new SqliteRemote(globalThis[_GlobalSqlOption].SqliteRemote.service, dbName);
|
|
58
|
+
// if (globalThis[_dao][DBType.SqliteRemote][_primaryDB] === undefined) {
|
|
59
|
+
// globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
|
|
60
|
+
// }
|
|
61
|
+
// globalThis[_dao][DBType.SqliteRemote][dbName] = db;
|
|
62
|
+
// }
|
|
63
|
+
// }
|
package/boot.d.ts
ADDED
package/{src/boot.ts → boot.js}
RENAMED
|
@@ -1,170 +1,163 @@
|
|
|
1
|
-
import { _Hump, DBType, getEnums } from 'baja-lite-field';
|
|
2
|
-
import events from 'events';
|
|
3
|
-
import { _dao, _DataConvert, _defOption, _enum, _EventBus, _fs, _GlobalSqlOption, _path, _primaryDB, _sqlCache, ColumnMode,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
globalThis[
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
[DBType.
|
|
31
|
-
[DBType.
|
|
32
|
-
[DBType.
|
|
33
|
-
[DBType.
|
|
34
|
-
[DBType.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
let flag = false;
|
|
75
|
-
for (const [key, fileName] of Object.entries(options.Sqlite)) {
|
|
76
|
-
const db = new Sqlite(new options.BetterSqlite3(fileName, { fileMustExist: false }));
|
|
77
|
-
if (!flag) {
|
|
78
|
-
globalThis[_dao][DBType.Sqlite][_primaryDB] = db;
|
|
79
|
-
flag = true;
|
|
80
|
-
}
|
|
81
|
-
globalThis[_dao][DBType.Sqlite][key] = db;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (options.SqliteRemote && options.SqliteRemote.db) {
|
|
86
|
-
if (typeof options.SqliteRemote.db === 'string') {
|
|
87
|
-
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
88
|
-
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
let flag = false;
|
|
92
|
-
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
93
|
-
options.SqliteRemote.service.initDB(fileName);
|
|
94
|
-
const db = new SqliteRemote(options.SqliteRemote.service, fileName);
|
|
95
|
-
if (!flag) {
|
|
96
|
-
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
|
|
97
|
-
flag = true;
|
|
98
|
-
}
|
|
99
|
-
globalThis[_dao][DBType.SqliteRemote][key] = db;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (options.Redis) {
|
|
104
|
-
events.setMaxListeners(0);
|
|
105
|
-
const { Redis } = await import('ioredis');
|
|
106
|
-
if (options.Redis['host']) {
|
|
107
|
-
globalThis[_dao][DBType.Redis][_primaryDB] = new Redis(options.Redis);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
let flag = false;
|
|
111
|
-
for (const [key, option] of Object.entries(options.Redis)) {
|
|
112
|
-
const db = new Redis(option);
|
|
113
|
-
if (!flag) {
|
|
114
|
-
globalThis[_dao][DBType.Redis][_primaryDB] = db;
|
|
115
|
-
flag = true;
|
|
116
|
-
}
|
|
117
|
-
globalThis[_dao][DBType.Redis][key] = db;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const clients = Object.values(globalThis[_dao][DBType.Redis])
|
|
121
|
-
const Redlock = await import('redlock');
|
|
122
|
-
globalThis[_dao][DBType.RedisLock] = new Redlock.default(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
flag = true;
|
|
165
|
-
}
|
|
166
|
-
globalThis[_dao][DBType.Postgresql][key] = db;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
1
|
+
import { _Hump, DBType, getEnums } from 'baja-lite-field';
|
|
2
|
+
import events from 'events';
|
|
3
|
+
import { _dao, _DataConvert, _defOption, _enum, _EventBus, _fs, _GlobalSqlOption, _path, _primaryDB, _sqlCache, ColumnMode, logger, Mysql, Postgresql, SqlCache, Sqlite, SqliteRemote } from './sql.js';
|
|
4
|
+
export const Boot = async function (options) {
|
|
5
|
+
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption);
|
|
6
|
+
if (options.skipEmptyString !== undefined) {
|
|
7
|
+
globalThis[_GlobalSqlOption].skipEmptyString = options.skipEmptyString;
|
|
8
|
+
}
|
|
9
|
+
if (options.skipNull !== undefined) {
|
|
10
|
+
globalThis[_GlobalSqlOption].skipNull = options.skipNull;
|
|
11
|
+
}
|
|
12
|
+
if (options.skipEmptyString !== undefined) {
|
|
13
|
+
globalThis[_GlobalSqlOption].skipEmptyString = options.skipEmptyString;
|
|
14
|
+
}
|
|
15
|
+
if (options.maxDeal !== undefined) {
|
|
16
|
+
globalThis[_GlobalSqlOption].maxDeal = options.maxDeal;
|
|
17
|
+
}
|
|
18
|
+
globalThis[_Hump] = options.columnMode === ColumnMode.HUMP;
|
|
19
|
+
logger.level = options.log ?? 'info';
|
|
20
|
+
globalThis[_sqlCache] = new SqlCache();
|
|
21
|
+
if (options.sqlDir) {
|
|
22
|
+
globalThis[_path] = await import('path');
|
|
23
|
+
globalThis[_fs] = await import('fs');
|
|
24
|
+
}
|
|
25
|
+
if (options.sqlMap || options.sqlDir) {
|
|
26
|
+
await globalThis[_sqlCache].init(options);
|
|
27
|
+
}
|
|
28
|
+
globalThis[_dao] = {
|
|
29
|
+
[DBType.Mongo]: {},
|
|
30
|
+
[DBType.Mysql]: {},
|
|
31
|
+
[DBType.Postgresql]: {},
|
|
32
|
+
[DBType.Sqlite]: {},
|
|
33
|
+
[DBType.SqliteRemote]: {},
|
|
34
|
+
[DBType.Redis]: {}
|
|
35
|
+
};
|
|
36
|
+
if (options.enums) {
|
|
37
|
+
globalThis[_enum] = getEnums(options.enums);
|
|
38
|
+
}
|
|
39
|
+
if (options.dataConvert) {
|
|
40
|
+
globalThis[_DataConvert] = options.dataConvert;
|
|
41
|
+
}
|
|
42
|
+
if (options.Mysql) {
|
|
43
|
+
const { createPool } = await import('mysql2/promise');
|
|
44
|
+
if (options.Mysql['host']) {
|
|
45
|
+
globalThis[_dao][DBType.Mysql][_primaryDB] = new Mysql(createPool({
|
|
46
|
+
...options.Mysql,
|
|
47
|
+
multipleStatements: true,
|
|
48
|
+
decimalNumbers: true,
|
|
49
|
+
supportBigNumbers: true
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
let flag = false;
|
|
54
|
+
for (const [key, option] of Object.entries(options.Mysql)) {
|
|
55
|
+
const db = new Mysql(createPool({
|
|
56
|
+
...option,
|
|
57
|
+
multipleStatements: true,
|
|
58
|
+
decimalNumbers: true,
|
|
59
|
+
supportBigNumbers: true
|
|
60
|
+
}));
|
|
61
|
+
if (!flag) {
|
|
62
|
+
globalThis[_dao][DBType.Mysql][_primaryDB] = db;
|
|
63
|
+
flag = true;
|
|
64
|
+
}
|
|
65
|
+
globalThis[_dao][DBType.Mysql][key] = db;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (options.Sqlite) {
|
|
70
|
+
if (typeof options.Sqlite === 'string') {
|
|
71
|
+
globalThis[_dao][DBType.Sqlite][_primaryDB] = new Sqlite(new options.BetterSqlite3(options.Sqlite, { fileMustExist: false }));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
let flag = false;
|
|
75
|
+
for (const [key, fileName] of Object.entries(options.Sqlite)) {
|
|
76
|
+
const db = new Sqlite(new options.BetterSqlite3(fileName, { fileMustExist: false }));
|
|
77
|
+
if (!flag) {
|
|
78
|
+
globalThis[_dao][DBType.Sqlite][_primaryDB] = db;
|
|
79
|
+
flag = true;
|
|
80
|
+
}
|
|
81
|
+
globalThis[_dao][DBType.Sqlite][key] = db;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (options.SqliteRemote && options.SqliteRemote.db) {
|
|
86
|
+
if (typeof options.SqliteRemote.db === 'string') {
|
|
87
|
+
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
88
|
+
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
let flag = false;
|
|
92
|
+
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
93
|
+
options.SqliteRemote.service.initDB(fileName);
|
|
94
|
+
const db = new SqliteRemote(options.SqliteRemote.service, fileName);
|
|
95
|
+
if (!flag) {
|
|
96
|
+
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
|
|
97
|
+
flag = true;
|
|
98
|
+
}
|
|
99
|
+
globalThis[_dao][DBType.SqliteRemote][key] = db;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (options.Redis) {
|
|
104
|
+
events.setMaxListeners(0);
|
|
105
|
+
const { Redis } = await import('ioredis');
|
|
106
|
+
if (options.Redis['host']) {
|
|
107
|
+
globalThis[_dao][DBType.Redis][_primaryDB] = new Redis(options.Redis);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
let flag = false;
|
|
111
|
+
for (const [key, option] of Object.entries(options.Redis)) {
|
|
112
|
+
const db = new Redis(option);
|
|
113
|
+
if (!flag) {
|
|
114
|
+
globalThis[_dao][DBType.Redis][_primaryDB] = db;
|
|
115
|
+
flag = true;
|
|
116
|
+
}
|
|
117
|
+
globalThis[_dao][DBType.Redis][key] = db;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const clients = Object.values(globalThis[_dao][DBType.Redis]);
|
|
121
|
+
const Redlock = await import('redlock');
|
|
122
|
+
globalThis[_dao][DBType.RedisLock] = new Redlock.default(clients, {
|
|
123
|
+
// The expected clock drift; for more details see:
|
|
124
|
+
// http://redis.io/topics/distlock
|
|
125
|
+
driftFactor: 0.01, // multiplied by lock ttl to determine drift time
|
|
126
|
+
// The max number of times Redlock will attempt to lock a resource
|
|
127
|
+
// before erroring.
|
|
128
|
+
retryCount: 10,
|
|
129
|
+
// the time in ms between attempts
|
|
130
|
+
retryDelay: 200, // time in ms
|
|
131
|
+
// the max time in ms randomly added to retries
|
|
132
|
+
// to improve performance under high contention
|
|
133
|
+
// see https://www.awsarchitectureblog.com/2015/03/backoff.html
|
|
134
|
+
retryJitter: 200, // time in ms
|
|
135
|
+
// The minimum remaining time on a lock before an extension is automatically
|
|
136
|
+
// attempted with the `using` API.
|
|
137
|
+
automaticExtensionThreshold: 500, // time in ms
|
|
138
|
+
});
|
|
139
|
+
const { EventEmitter } = await import('events');
|
|
140
|
+
const event = new EventEmitter({ captureRejections: true });
|
|
141
|
+
event.on('error', error => {
|
|
142
|
+
logger.error('event-bus', error);
|
|
143
|
+
});
|
|
144
|
+
globalThis[_EventBus] = event;
|
|
145
|
+
}
|
|
146
|
+
if (options.Postgresql) {
|
|
147
|
+
const Pool = await import('pg-pool');
|
|
148
|
+
if (options.Postgresql['host']) {
|
|
149
|
+
globalThis[_dao][DBType.Postgresql][_primaryDB] = new Postgresql(new Pool.default(options.Postgresql));
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
let flag = false;
|
|
153
|
+
for (const [key, option] of Object.entries(options.Postgresql)) {
|
|
154
|
+
const db = new Postgresql(new Pool.default(option));
|
|
155
|
+
if (!flag) {
|
|
156
|
+
globalThis[_dao][DBType.Postgresql][_primaryDB] = db;
|
|
157
|
+
flag = true;
|
|
158
|
+
}
|
|
159
|
+
globalThis[_dao][DBType.Postgresql][key] = db;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
package/code.d.ts
ADDED