baja-lite 1.0.33 → 1.0.35

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 (103) hide show
  1. package/{cjs/boot-remote.d.ts → boot-remote.d.ts} +1 -1
  2. package/{es/boot-remote.js → boot-remote.js} +2 -2
  3. package/{es/boot.d.ts → boot.d.ts} +1 -1
  4. package/{es/boot.js → boot.js} +2 -2
  5. package/{es/enum.js → enum.js} +1 -1
  6. package/{es/fn.js → fn.js} +2 -2
  7. package/index.d.ts +10 -0
  8. package/index.js +10 -0
  9. package/package.json +11 -12
  10. package/{cjs/sql.d.ts → sql.d.ts} +3 -3
  11. package/{es/sql.js → sql.js} +7 -7
  12. package/{es/sqlite.d.ts → sqlite.d.ts} +1 -1
  13. package/{es/sqlite.js → sqlite.js} +1 -1
  14. package/{es/test-mysql.js → test-mysql.js} +2 -2
  15. package/{es/test-postgresql.js → test-postgresql.js} +2 -2
  16. package/cjs/boot-remote.js +0 -49
  17. package/cjs/boot.d.ts +0 -2
  18. package/cjs/boot.js +0 -183
  19. package/cjs/code.js +0 -379
  20. package/cjs/convert-xml.js +0 -417
  21. package/cjs/enum.js +0 -64
  22. package/cjs/error.js +0 -16
  23. package/cjs/fn.js +0 -179
  24. package/cjs/index.d.ts +0 -10
  25. package/cjs/index.js +0 -26
  26. package/cjs/list.js +0 -60
  27. package/cjs/math.js +0 -474
  28. package/cjs/object.js +0 -242
  29. package/cjs/set-ex.js +0 -345
  30. package/cjs/sql.js +0 -5083
  31. package/cjs/sqlite.d.ts +0 -32
  32. package/cjs/sqlite.js +0 -169
  33. package/cjs/string.js +0 -119
  34. package/cjs/test-mysql.js +0 -138
  35. package/cjs/test-postgresql.js +0 -93
  36. package/cjs/test-sqlite.js +0 -91
  37. package/cjs/test-xml.js +0 -75
  38. package/cjs/test.js +0 -4
  39. package/es/boot-remote.d.ts +0 -2
  40. package/es/code.d.ts +0 -2
  41. package/es/convert-xml.d.ts +0 -10
  42. package/es/enum.d.ts +0 -18
  43. package/es/error.d.ts +0 -5
  44. package/es/fn.d.ts +0 -128
  45. package/es/index.d.ts +0 -10
  46. package/es/index.js +0 -10
  47. package/es/list.d.ts +0 -10
  48. package/es/math.d.ts +0 -83
  49. package/es/object.d.ts +0 -83
  50. package/es/set-ex.d.ts +0 -198
  51. package/es/sql.d.ts +0 -1858
  52. package/es/string.d.ts +0 -17
  53. package/es/test-mysql.d.ts +0 -2
  54. package/es/test-postgresql.d.ts +0 -2
  55. package/es/test-sqlite.d.ts +0 -1
  56. package/es/test-xml.d.ts +0 -1
  57. package/es/test.d.ts +0 -1
  58. package/src/boot-remote.ts +0 -46
  59. package/src/boot.ts +0 -153
  60. package/src/code.ts +0 -377
  61. package/src/convert-xml.ts +0 -460
  62. package/src/enum.ts +0 -71
  63. package/src/error.ts +0 -11
  64. package/src/fn.ts +0 -295
  65. package/src/index.ts +0 -10
  66. package/src/list.ts +0 -57
  67. package/src/math.ts +0 -405
  68. package/src/object.ts +0 -247
  69. package/src/set-ex.ts +0 -374
  70. package/src/sql.ts +0 -5281
  71. package/src/sqlite.ts +0 -161
  72. package/src/string.ts +0 -111
  73. package/src/test-mysql.ts +0 -126
  74. package/src/test-postgresql.ts +0 -79
  75. package/src/test-sqlite.ts +0 -80
  76. package/src/test-xml.ts +0 -70
  77. package/src/test.ts +0 -2
  78. /package/{cjs/code.d.ts → code.d.ts} +0 -0
  79. /package/{es/code.js → code.js} +0 -0
  80. /package/{cjs/convert-xml.d.ts → convert-xml.d.ts} +0 -0
  81. /package/{es/convert-xml.js → convert-xml.js} +0 -0
  82. /package/{cjs/enum.d.ts → enum.d.ts} +0 -0
  83. /package/{cjs/error.d.ts → error.d.ts} +0 -0
  84. /package/{es/error.js → error.js} +0 -0
  85. /package/{cjs/fn.d.ts → fn.d.ts} +0 -0
  86. /package/{cjs/list.d.ts → list.d.ts} +0 -0
  87. /package/{es/list.js → list.js} +0 -0
  88. /package/{cjs/math.d.ts → math.d.ts} +0 -0
  89. /package/{es/math.js → math.js} +0 -0
  90. /package/{cjs/object.d.ts → object.d.ts} +0 -0
  91. /package/{es/object.js → object.js} +0 -0
  92. /package/{cjs/set-ex.d.ts → set-ex.d.ts} +0 -0
  93. /package/{es/set-ex.js → set-ex.js} +0 -0
  94. /package/{cjs/string.d.ts → string.d.ts} +0 -0
  95. /package/{es/string.js → string.js} +0 -0
  96. /package/{cjs/test-mysql.d.ts → test-mysql.d.ts} +0 -0
  97. /package/{cjs/test-postgresql.d.ts → test-postgresql.d.ts} +0 -0
  98. /package/{cjs/test-sqlite.d.ts → test-sqlite.d.ts} +0 -0
  99. /package/{es/test-sqlite.js → test-sqlite.js} +0 -0
  100. /package/{cjs/test-xml.d.ts → test-xml.d.ts} +0 -0
  101. /package/{es/test-xml.js → test-xml.js} +0 -0
  102. /package/{cjs/test.d.ts → test.d.ts} +0 -0
  103. /package/{es/test.js → test.js} +0 -0
@@ -1,2 +1,2 @@
1
- import { GlobalSqlOptionForWeb } from './sql';
1
+ import { GlobalSqlOptionForWeb } from './sql.js';
2
2
  export declare const BootRomote: (options: GlobalSqlOptionForWeb) => Promise<void>;
@@ -1,5 +1,5 @@
1
- import { getEnums } from './enum';
2
- import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode, _enums } from './sql';
1
+ import { getEnums } from './enum.js';
2
+ import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode, _enums } from './sql.js';
3
3
  export const BootRomote = async function (options) {
4
4
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
5
5
  globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
@@ -1,2 +1,2 @@
1
- import { GlobalSqlOption } from './sql';
1
+ import { GlobalSqlOption } from './sql.js';
2
2
  export declare const Boot: (options: GlobalSqlOption) => Promise<void>;
@@ -1,5 +1,5 @@
1
- import { getEnums } from './enum';
2
- import { _GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode, Postgresql } from './sql';
1
+ import { getEnums } from './enum.js';
2
+ import { _GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode, Postgresql } from './sql.js';
3
3
  export const Boot = async function (options) {
4
4
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
5
5
  globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
@@ -1,4 +1,4 @@
1
- import { _enums } from "./sql";
1
+ import { _enums } from "./sql.js";
2
2
  export class Enum {
3
3
  constructor(value, desc, ...config) {
4
4
  this._value = value;
@@ -1,5 +1,5 @@
1
- import { arraySplit } from './object';
2
- import { Throw } from './error';
1
+ import { arraySplit } from './object.js';
2
+ import { Throw } from './error.js';
3
3
  /**
4
4
  * 回调函数promise化
5
5
  * 调用示例
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import 'reflect-metadata';
2
+ export * from './error.js';
3
+ export * from './fn.js';
4
+ export * from './math.js';
5
+ export * from './object.js';
6
+ export * from './set-ex.js';
7
+ export * from './sql.js';
8
+ export * from './string.js';
9
+ export * from './enum.js';
10
+ export * from './list.js';
package/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import 'reflect-metadata';
2
+ export * from './error.js';
3
+ export * from './fn.js';
4
+ export * from './math.js';
5
+ export * from './object.js';
6
+ export * from './set-ex.js';
7
+ export * from './sql.js';
8
+ export * from './string.js';
9
+ export * from './enum.js';
10
+ export * from './list.js';
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "some util for self",
5
- "type": "module",
6
5
  "homepage": "https://github.com/void-soul/util-man",
7
6
  "repository": {
8
7
  "type": "git",
@@ -10,19 +9,20 @@
10
9
  },
11
10
  "license": "MIT",
12
11
  "author": "void-soul",
12
+ "type": "module",
13
13
  "exports": {
14
14
  ".": {
15
- "types": "./es/index.d.ts",
16
- "import": "./es/index.js",
17
- "require": "./cjs/index.js"
15
+ "types": "./index.d.ts",
16
+ "import": "./index.js"
18
17
  },
19
- "./*": "./*"
18
+ "./boot.js":"./boot.js",
19
+ "./boot-remote.js":"./boot-remote.js"
20
20
  },
21
- "main": "./cjs/index.js",
22
- "types": "./es/index.d.ts",
21
+ "types": "./index.d.ts",
23
22
  "bin": {
24
- "baja": "./cjs/code.js"
23
+ "baja": "./code.js"
25
24
  },
25
+ "models": "./es/index.js",
26
26
  "scripts": {
27
27
  "dist": "node ./ci.js",
28
28
  "mysql": "bun --inspect ./src/test-mysql.ts",
@@ -50,7 +50,7 @@
50
50
  "@types/better-sqlite3": "7.6.12",
51
51
  "@types/lodash.get": "4.4.9",
52
52
  "@types/mustache": "4.2.5",
53
- "@types/node": "20.14.14",
53
+ "@types/node": "22.12.0",
54
54
  "@types/pg-pool": "2.0.6",
55
55
  "@types/shelljs": "0.8.15",
56
56
  "@types/sqlstring": "2.3.2",
@@ -71,6 +71,5 @@
71
71
  },
72
72
  "publishConfig": {
73
73
  "access": "public"
74
- },
75
- "models": "./es/index.js"
74
+ }
76
75
  }
@@ -1,6 +1,6 @@
1
- import { XML } from './convert-xml';
2
- import { ArrayList } from './list';
3
- import { EnumMap } from './enum';
1
+ import { XML } from './convert-xml.js';
2
+ import { ArrayList } from './list.js';
3
+ import { EnumMap } from './enum.js';
4
4
  import { ExtensionCodec } from "@msgpack/msgpack";
5
5
  export declare const extensionCodec: ExtensionCodec<undefined>;
6
6
  declare const _daoDBName: unique symbol;
@@ -9,19 +9,19 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  var _b, _c, _d, _e;
11
11
  var _f, _g, _h, _j;
12
- import { Throw } from './error';
12
+ import { Throw } from './error.js';
13
13
  import tslib from 'tslib';
14
14
  import iterare from 'iterare';
15
- import { emptyString } from './string';
15
+ import { emptyString } from './string.js';
16
16
  import pino from 'pino';
17
- import { excuteSplit, ExcuteSplitMode, sleep } from './fn';
18
- import { add, calc, ten2Any } from './math';
17
+ import { excuteSplit, ExcuteSplitMode, sleep } from './fn.js';
18
+ import { add, calc, ten2Any } from './math.js';
19
19
  import mustache from 'mustache';
20
- import { C2P, C2P2, P2C } from './object';
20
+ import { C2P, C2P2, P2C } from './object.js';
21
21
  import { formatDialect, sqlite, mysql, postgresql } from 'sql-formatter';
22
22
  import HTML from 'html-parse-stringify';
23
- import { convert } from './convert-xml';
24
- import { ArrayList } from './list';
23
+ import { convert } from './convert-xml.js';
24
+ import { ArrayList } from './list.js';
25
25
  import LGet from 'lodash.get';
26
26
  import { encode, decode, ExtensionCodec, DecodeError } from "@msgpack/msgpack";
27
27
  BigInt.prototype.toJSON = function () { return this.toString(); };
@@ -1,4 +1,4 @@
1
- import { SqliteRemoteInterface } from './sql';
1
+ import { SqliteRemoteInterface } from './sql.js';
2
2
  export declare abstract class SqliteRemoteClass implements SqliteRemoteInterface {
3
3
  private dbList;
4
4
  /** 原始存放路径 */
@@ -1,4 +1,4 @@
1
- import { extensionCodec, logger } from './sql';
1
+ import { extensionCodec, logger } from './sql.js';
2
2
  import Sqlstring from 'sqlstring';
3
3
  import { encode, decode } from "@msgpack/msgpack";
4
4
  export class SqliteRemoteClass {
@@ -8,8 +8,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import 'reflect-metadata';
11
- import { Boot } from './boot';
12
- import { SqlService, Field, DB, DBType, SqlType, ColumnMode, SelectResult, } from './sql';
11
+ import { Boot } from './boot.js';
12
+ import { SqlService, Field, DB, DBType, SqlType, ColumnMode, SelectResult, } from './sql.js';
13
13
  class AmaFuck2 {
14
14
  }
15
15
  __decorate([
@@ -8,8 +8,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import 'reflect-metadata';
11
- import { Boot } from './boot';
12
- import { SqlService, Field, DB, DBType, SqlType, ColumnMode, SelectResult, } from './sql';
11
+ import { Boot } from './boot.js';
12
+ import { SqlService, Field, DB, DBType, SqlType, ColumnMode, SelectResult, } from './sql.js';
13
13
  class AmaFuck2 {
14
14
  }
15
15
  __decorate([
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BootRomote = void 0;
4
- const enum_1 = require("./enum");
5
- const sql_1 = require("./sql");
6
- const BootRomote = async function (options) {
7
- globalThis[sql_1._GlobalSqlOption] = Object.assign({}, sql_1._defOption, options);
8
- globalThis[sql_1._Hump] = globalThis[sql_1._GlobalSqlOption].columnMode === sql_1.ColumnMode.HUMP;
9
- sql_1.logger.level = options.log ?? 'info';
10
- globalThis[sql_1._sqlCache] = new sql_1.SqlCache();
11
- if (options.sqlMap) {
12
- await globalThis[sql_1._sqlCache].init(options);
13
- }
14
- globalThis[sql_1._dao] = {
15
- [sql_1.DBType.SqliteRemote]: {},
16
- };
17
- if (options.enums) {
18
- globalThis[sql_1._enums] = (0, enum_1.getEnums)(options.enums);
19
- }
20
- if (options.SqliteRemote && options.SqliteRemote.db) {
21
- if (typeof options.SqliteRemote.db === 'string') {
22
- options.SqliteRemote.service.initDB(options.SqliteRemote.db);
23
- globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][sql_1._primaryDB] = new sql_1.SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
24
- }
25
- else {
26
- let flag = false;
27
- for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
28
- await options.SqliteRemote.service.initDB(fileName);
29
- const db = new sql_1.SqliteRemote(options.SqliteRemote.service, fileName);
30
- if (flag === false) {
31
- globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][sql_1._primaryDB] = db;
32
- flag = true;
33
- }
34
- globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][key] = db;
35
- }
36
- }
37
- }
38
- };
39
- exports.BootRomote = BootRomote;
40
- // export const AppendRomote = async function (dbName: string) {
41
- // if (!globalThis[_dao][DBType.SqliteRemote][dbName]) {
42
- // globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
43
- // const db = new SqliteRemote(globalThis[_GlobalSqlOption].SqliteRemote.service, dbName);
44
- // if (globalThis[_dao][DBType.SqliteRemote][_primaryDB] === undefined) {
45
- // globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
46
- // }
47
- // globalThis[_dao][DBType.SqliteRemote][dbName] = db;
48
- // }
49
- // }
package/cjs/boot.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { GlobalSqlOption } from './sql';
2
- export declare const Boot: (options: GlobalSqlOption) => Promise<void>;
package/cjs/boot.js DELETED
@@ -1,183 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Boot = void 0;
37
- const enum_1 = require("./enum");
38
- const sql_1 = require("./sql");
39
- const Boot = async function (options) {
40
- globalThis[sql_1._GlobalSqlOption] = Object.assign({}, sql_1._defOption, options);
41
- globalThis[sql_1._Hump] = globalThis[sql_1._GlobalSqlOption].columnMode === sql_1.ColumnMode.HUMP;
42
- if (options.sqlDir) {
43
- globalThis[sql_1._path] = await Promise.resolve().then(() => __importStar(require('path')));
44
- globalThis[sql_1._fs] = await Promise.resolve().then(() => __importStar(require('fs')));
45
- }
46
- sql_1.logger.level = options.log ?? 'info';
47
- globalThis[sql_1._sqlCache] = new sql_1.SqlCache();
48
- if (options.sqlMap || options.sqlDir) {
49
- await globalThis[sql_1._sqlCache].init(options);
50
- }
51
- globalThis[sql_1._dao] = {
52
- [sql_1.DBType.Mongo]: {},
53
- [sql_1.DBType.Mysql]: {},
54
- [sql_1.DBType.Postgresql]: {},
55
- [sql_1.DBType.Sqlite]: {},
56
- [sql_1.DBType.SqliteRemote]: {},
57
- [sql_1.DBType.Redis]: {}
58
- };
59
- if (options.enums) {
60
- globalThis[sql_1._enums] = (0, enum_1.getEnums)(options.enums);
61
- }
62
- if (options.Mysql) {
63
- const { createPool } = await Promise.resolve().then(() => __importStar(require('mysql2/promise')));
64
- if (options.Mysql['host']) {
65
- globalThis[sql_1._dao][sql_1.DBType.Mysql][sql_1._primaryDB] = new sql_1.Mysql(createPool({
66
- ...options.Mysql,
67
- multipleStatements: true,
68
- decimalNumbers: true,
69
- supportBigNumbers: true
70
- }));
71
- }
72
- else {
73
- let flag = false;
74
- for (const [key, option] of Object.entries(options.Mysql)) {
75
- const db = new sql_1.Mysql(createPool({
76
- ...option,
77
- multipleStatements: true,
78
- decimalNumbers: true,
79
- supportBigNumbers: true
80
- }));
81
- if (flag === false) {
82
- globalThis[sql_1._dao][sql_1.DBType.Mysql][sql_1._primaryDB] = db;
83
- flag = true;
84
- }
85
- globalThis[sql_1._dao][sql_1.DBType.Mysql][key] = db;
86
- }
87
- }
88
- }
89
- if (options.Sqlite) {
90
- if (typeof options.Sqlite === 'string') {
91
- globalThis[sql_1._dao][sql_1.DBType.Sqlite][sql_1._primaryDB] = new sql_1.Sqlite(new options.BetterSqlite3(options.Sqlite, { fileMustExist: false }));
92
- }
93
- else {
94
- let flag = false;
95
- for (const [key, fileName] of Object.entries(options.Sqlite)) {
96
- const db = new sql_1.Sqlite(new options.BetterSqlite3(fileName, { fileMustExist: false }));
97
- if (flag === false) {
98
- globalThis[sql_1._dao][sql_1.DBType.Sqlite][sql_1._primaryDB] = db;
99
- flag = true;
100
- }
101
- globalThis[sql_1._dao][sql_1.DBType.Sqlite][key] = db;
102
- }
103
- }
104
- }
105
- if (options.SqliteRemote && options.SqliteRemote.db) {
106
- if (typeof options.SqliteRemote.db === 'string') {
107
- options.SqliteRemote.service.initDB(options.SqliteRemote.db);
108
- globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][sql_1._primaryDB] = new sql_1.SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
109
- }
110
- else {
111
- let flag = false;
112
- for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
113
- options.SqliteRemote.service.initDB(fileName);
114
- const db = new sql_1.SqliteRemote(options.SqliteRemote.service, fileName);
115
- if (flag === false) {
116
- globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][sql_1._primaryDB] = db;
117
- flag = true;
118
- }
119
- globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][key] = db;
120
- }
121
- }
122
- }
123
- if (options.Redis) {
124
- const { Redis } = await Promise.resolve().then(() => __importStar(require('ioredis')));
125
- if (options.Redis['host']) {
126
- globalThis[sql_1._dao][sql_1.DBType.Redis][sql_1._primaryDB] = new Redis(options.Redis);
127
- }
128
- else {
129
- let flag = false;
130
- for (const [key, option] of Object.entries(options.Redis)) {
131
- const db = new Redis(option);
132
- if (flag === false) {
133
- globalThis[sql_1._dao][sql_1.DBType.Redis][sql_1._primaryDB] = db;
134
- flag = true;
135
- }
136
- globalThis[sql_1._dao][sql_1.DBType.Redis][key] = db;
137
- }
138
- }
139
- const clients = Object.values(globalThis[sql_1._dao][sql_1.DBType.Redis]);
140
- const Redlock = await Promise.resolve().then(() => __importStar(require('redlock')));
141
- globalThis[sql_1._dao][sql_1.DBType.RedisLock] = new Redlock.default(clients, {
142
- // The expected clock drift; for more details see:
143
- // http://redis.io/topics/distlock
144
- driftFactor: 0.01, // multiplied by lock ttl to determine drift time
145
- // The max number of times Redlock will attempt to lock a resource
146
- // before erroring.
147
- retryCount: 10,
148
- // the time in ms between attempts
149
- retryDelay: 200, // time in ms
150
- // the max time in ms randomly added to retries
151
- // to improve performance under high contention
152
- // see https://www.awsarchitectureblog.com/2015/03/backoff.html
153
- retryJitter: 200, // time in ms
154
- // The minimum remaining time on a lock before an extension is automatically
155
- // attempted with the `using` API.
156
- automaticExtensionThreshold: 500, // time in ms
157
- });
158
- const { EventEmitter } = await Promise.resolve().then(() => __importStar(require('events')));
159
- const event = new EventEmitter({ captureRejections: true });
160
- event.on('error', error => {
161
- sql_1.logger.error('event-bus', error);
162
- });
163
- globalThis[sql_1._EventBus] = event;
164
- }
165
- if (options.Postgresql) {
166
- const Pool = await Promise.resolve().then(() => __importStar(require('pg-pool')));
167
- if (options.Postgresql['host']) {
168
- globalThis[sql_1._dao][sql_1.DBType.Postgresql][sql_1._primaryDB] = new sql_1.Postgresql(new Pool.default(options.Postgresql));
169
- }
170
- else {
171
- let flag = false;
172
- for (const [key, option] of Object.entries(options.Postgresql)) {
173
- const db = new sql_1.Postgresql(new Pool.default(option));
174
- if (flag === false) {
175
- globalThis[sql_1._dao][sql_1.DBType.Postgresql][sql_1._primaryDB] = db;
176
- flag = true;
177
- }
178
- globalThis[sql_1._dao][sql_1.DBType.Postgresql][key] = db;
179
- }
180
- }
181
- }
182
- };
183
- exports.Boot = Boot;