@sqb/nestjs 4.20.7 → 4.21.0
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 +10 -26
- package/cjs/get-sqb-config.js +0 -45
- package/cjs/index.js +0 -10
- package/cjs/package.json +0 -3
- package/cjs/sqb-core.module.js +0 -129
- package/cjs/sqb.constants.js +0 -6
- package/cjs/sqb.decorators.js +0 -7
- package/cjs/sqb.interface.js +0 -2
- package/cjs/sqb.module.js +0 -25
- package/cjs/sqb.utils.js +0 -39
- package/esm/package.json +0 -3
- package/types/index.d.cts +0 -5
- /package/{types/get-sqb-config.d.ts → get-sqb-config.d.ts} +0 -0
- /package/{esm/get-sqb-config.js → get-sqb-config.js} +0 -0
- /package/{types/index.d.ts → index.d.ts} +0 -0
- /package/{esm/index.js → index.js} +0 -0
- /package/{types/sqb-core.module.d.ts → sqb-core.module.d.ts} +0 -0
- /package/{esm/sqb-core.module.js → sqb-core.module.js} +0 -0
- /package/{types/sqb.constants.d.ts → sqb.constants.d.ts} +0 -0
- /package/{esm/sqb.constants.js → sqb.constants.js} +0 -0
- /package/{types/sqb.decorators.d.ts → sqb.decorators.d.ts} +0 -0
- /package/{esm/sqb.decorators.js → sqb.decorators.js} +0 -0
- /package/{types/sqb.interface.d.ts → sqb.interface.d.ts} +0 -0
- /package/{esm/sqb.interface.js → sqb.interface.js} +0 -0
- /package/{types/sqb.module.d.ts → sqb.module.d.ts} +0 -0
- /package/{esm/sqb.module.js → sqb.module.js} +0 -0
- /package/{types/sqb.utils.d.ts → sqb.utils.d.ts} +0 -0
- /package/{esm/sqb.utils.js → sqb.utils.js} +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/nestjs",
|
|
3
3
|
"description": "Nestjs module for data connection using SQB",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.21.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"dependencies": {
|
|
@@ -12,29 +12,24 @@
|
|
|
12
12
|
"peerDependencies": {
|
|
13
13
|
"@nestjs/common": ">=7.4.0",
|
|
14
14
|
"@nestjs/core": ">=7.4.0",
|
|
15
|
-
"@sqb/builder": "^4.
|
|
16
|
-
"@sqb/connect": "^4.
|
|
15
|
+
"@sqb/builder": "^4.21.0",
|
|
16
|
+
"@sqb/connect": "^4.21.0",
|
|
17
17
|
"reflect-metadata": "^0.2.2",
|
|
18
18
|
"rxjs": ">=6.6.0"
|
|
19
19
|
},
|
|
20
20
|
"type": "module",
|
|
21
|
+
"module": "./index.js",
|
|
22
|
+
"types": "./index.d.ts",
|
|
21
23
|
"exports": {
|
|
22
24
|
".": {
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"default": "./esm/index.js"
|
|
26
|
-
},
|
|
27
|
-
"require": {
|
|
28
|
-
"types": "./types/index.d.cts",
|
|
29
|
-
"default": "./cjs/index.js"
|
|
30
|
-
},
|
|
31
|
-
"default": "./esm/index.js"
|
|
25
|
+
"types": "./index.d.ts",
|
|
26
|
+
"default": "./index.js"
|
|
32
27
|
},
|
|
33
28
|
"./package.json": "./package.json"
|
|
34
29
|
},
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20.0"
|
|
32
|
+
},
|
|
38
33
|
"contributors": [
|
|
39
34
|
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
40
35
|
"Ilker Gurelli <i.gurelli@panates.com>"
|
|
@@ -44,17 +39,6 @@
|
|
|
44
39
|
"url": "https://github.com/panates/sqb.git",
|
|
45
40
|
"directory": "packages/nestjs"
|
|
46
41
|
},
|
|
47
|
-
"engines": {
|
|
48
|
-
"node": ">=18.0"
|
|
49
|
-
},
|
|
50
|
-
"files": [
|
|
51
|
-
"bin/",
|
|
52
|
-
"cjs/",
|
|
53
|
-
"esm/",
|
|
54
|
-
"types/",
|
|
55
|
-
"LICENSE",
|
|
56
|
-
"README.md"
|
|
57
|
-
],
|
|
58
42
|
"keywords": [
|
|
59
43
|
"sqb",
|
|
60
44
|
"nestjs",
|
package/cjs/get-sqb-config.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSqbConfig = getSqbConfig;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
6
|
-
const objects_1 = require("@jsopen/objects");
|
|
7
|
-
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
8
|
-
function getSqbConfig(moduleOptions, prefix = 'SQB_') {
|
|
9
|
-
const options = (0, objects_1.clone)(moduleOptions);
|
|
10
|
-
const env = node_process_1.default.env;
|
|
11
|
-
options.dialect = options.dialect || env[prefix + 'DIALECT'];
|
|
12
|
-
options.name = options.name || env[prefix + 'CONNECTION_NAME'];
|
|
13
|
-
options.host = options.host || env[prefix + 'HOST'];
|
|
14
|
-
options.port = options.port || (0, putil_varhelpers_1.toInt)(env[prefix + 'PORT']);
|
|
15
|
-
options.database = options.database || env[prefix + 'DATABASE'];
|
|
16
|
-
options.schema = options.schema || env[prefix + 'SCHEMA'];
|
|
17
|
-
options.user = options.user || env[prefix + 'USER'];
|
|
18
|
-
options.password = options.password || env[prefix + 'PASSWORD'];
|
|
19
|
-
options.driver = options.driver || env[prefix + 'DRIVER'];
|
|
20
|
-
options.pool = options.pool || {};
|
|
21
|
-
options.pool.max = options.pool.max || (0, putil_varhelpers_1.toInt)(env[prefix + 'POOL_MAX']);
|
|
22
|
-
options.pool.min = options.pool.min || (0, putil_varhelpers_1.toInt)(env[prefix + 'POOL_MIN']);
|
|
23
|
-
options.pool.idleTimeoutMillis =
|
|
24
|
-
options.pool.idleTimeoutMillis || (0, putil_varhelpers_1.toInt)(env[prefix + 'POOL_IDLE_TIMEOUT']);
|
|
25
|
-
options.pool.acquireTimeoutMillis =
|
|
26
|
-
options.pool.acquireTimeoutMillis ||
|
|
27
|
-
(0, putil_varhelpers_1.toInt)(env[prefix + 'POOL_ACQUIRE_TIMEOUT']);
|
|
28
|
-
options.pool.acquireMaxRetries =
|
|
29
|
-
options.pool.acquireMaxRetries ||
|
|
30
|
-
(0, putil_varhelpers_1.toInt)(env[prefix + 'POOL_ACQUIRE_MAX_RETRIES']);
|
|
31
|
-
options.pool.acquireRetryWait =
|
|
32
|
-
options.pool.acquireRetryWait ||
|
|
33
|
-
(0, putil_varhelpers_1.toInt)(env[prefix + 'POOL_ACQUIRE_RETRY_WAIT']);
|
|
34
|
-
options.pool.fifo = options.pool.fifo || (0, putil_varhelpers_1.toBoolean)(env[prefix + 'POOL_FIFO']);
|
|
35
|
-
options.pool.maxQueue =
|
|
36
|
-
options.pool.maxQueue || (0, putil_varhelpers_1.toInt)(env[prefix + 'POOL_MAX_QUEUE']);
|
|
37
|
-
options.pool.minIdle =
|
|
38
|
-
options.pool.minIdle || (0, putil_varhelpers_1.toInt)(env[prefix + 'POOL_MIN_IDLE']);
|
|
39
|
-
options.pool.validation =
|
|
40
|
-
options.pool.validation || (0, putil_varhelpers_1.toBoolean)(env[prefix + 'POOL_VALIDATION']);
|
|
41
|
-
options.pool.houseKeepInterval =
|
|
42
|
-
options.pool.houseKeepInterval ||
|
|
43
|
-
(0, putil_varhelpers_1.toInt)(env[prefix + 'POOL_HOUSE_KEEP_INTERVAL']);
|
|
44
|
-
return options;
|
|
45
|
-
}
|
package/cjs/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SqbClient = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
tslib_1.__exportStar(require("./sqb.decorators.js"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./sqb.interface.js"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./sqb.module.js"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./sqb.utils.js"), exports);
|
|
9
|
-
var connect_1 = require("@sqb/connect");
|
|
10
|
-
Object.defineProperty(exports, "SqbClient", { enumerable: true, get: function () { return connect_1.SqbClient; } });
|
package/cjs/package.json
DELETED
package/cjs/sqb-core.module.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var SqbCoreModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.SqbCoreModule = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const common_1 = require("@nestjs/common");
|
|
7
|
-
const core_1 = require("@nestjs/core");
|
|
8
|
-
const connect_1 = require("@sqb/connect");
|
|
9
|
-
const crypto = tslib_1.__importStar(require("crypto"));
|
|
10
|
-
const rxjs_1 = require("rxjs");
|
|
11
|
-
const rxjs = tslib_1.__importStar(require("rxjs"));
|
|
12
|
-
const get_sqb_config_js_1 = require("./get-sqb-config.js");
|
|
13
|
-
const sqb_constants_js_1 = require("./sqb.constants.js");
|
|
14
|
-
const sqb_utils_js_1 = require("./sqb.utils.js");
|
|
15
|
-
let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
16
|
-
options;
|
|
17
|
-
moduleRef;
|
|
18
|
-
constructor(options, moduleRef) {
|
|
19
|
-
this.options = options;
|
|
20
|
-
this.moduleRef = moduleRef;
|
|
21
|
-
}
|
|
22
|
-
static forRoot(options = {}) {
|
|
23
|
-
const optionsProvider = {
|
|
24
|
-
provide: sqb_constants_js_1.SQB_MODULE_OPTIONS,
|
|
25
|
-
useValue: options,
|
|
26
|
-
};
|
|
27
|
-
const connectionProvider = {
|
|
28
|
-
provide: (0, sqb_utils_js_1.getSQBToken)(options.name),
|
|
29
|
-
inject: [sqb_constants_js_1.SQB_CONNECTION_OPTIONS],
|
|
30
|
-
useFactory: (sqbConnectionOptions) => this.createConnection(options, sqbConnectionOptions),
|
|
31
|
-
};
|
|
32
|
-
return {
|
|
33
|
-
module: SqbCoreModule_1,
|
|
34
|
-
providers: [
|
|
35
|
-
connectionProvider,
|
|
36
|
-
optionsProvider,
|
|
37
|
-
{
|
|
38
|
-
provide: sqb_constants_js_1.SQB_CONNECTION_OPTIONS,
|
|
39
|
-
useValue: (0, get_sqb_config_js_1.getSqbConfig)(options.useValue || {}, options.envPrefix),
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
exports: [connectionProvider],
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
static forRootAsync(options) {
|
|
46
|
-
const connectionProvider = {
|
|
47
|
-
provide: (0, sqb_utils_js_1.getSQBToken)(options.name),
|
|
48
|
-
inject: [sqb_constants_js_1.SQB_MODULE_OPTIONS, sqb_constants_js_1.SQB_CONNECTION_OPTIONS],
|
|
49
|
-
useFactory: async (sqbOptions, sqbConnectionOptions) => this.createConnection(sqbOptions, sqbConnectionOptions),
|
|
50
|
-
};
|
|
51
|
-
const asyncProviders = this.createAsyncProviders(options);
|
|
52
|
-
return {
|
|
53
|
-
module: SqbCoreModule_1,
|
|
54
|
-
imports: options.imports,
|
|
55
|
-
providers: [
|
|
56
|
-
...asyncProviders,
|
|
57
|
-
connectionProvider,
|
|
58
|
-
{
|
|
59
|
-
provide: sqb_constants_js_1.SQB_MODULE_OPTIONS,
|
|
60
|
-
useValue: options,
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
provide: sqb_constants_js_1.SQB_MODULE_ID,
|
|
64
|
-
useValue: crypto.randomUUID(),
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
exports: [connectionProvider],
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
async onApplicationShutdown() {
|
|
71
|
-
const client = this.moduleRef.get((0, sqb_utils_js_1.getSQBToken)(this.options.name));
|
|
72
|
-
const op = this.moduleRef.get(sqb_constants_js_1.SQB_CONNECTION_OPTIONS);
|
|
73
|
-
if (client)
|
|
74
|
-
await client.close(op.shutdownWaitMs);
|
|
75
|
-
}
|
|
76
|
-
static createAsyncProviders(options) {
|
|
77
|
-
if (options.useExisting || options.useFactory)
|
|
78
|
-
return [this.createAsyncOptionsProvider(options)];
|
|
79
|
-
if (options.useClass) {
|
|
80
|
-
return [
|
|
81
|
-
this.createAsyncOptionsProvider(options),
|
|
82
|
-
{
|
|
83
|
-
provide: options.useClass,
|
|
84
|
-
useClass: options.useClass,
|
|
85
|
-
},
|
|
86
|
-
];
|
|
87
|
-
}
|
|
88
|
-
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
89
|
-
}
|
|
90
|
-
static createAsyncOptionsProvider(options) {
|
|
91
|
-
if (options.useFactory) {
|
|
92
|
-
return {
|
|
93
|
-
provide: sqb_constants_js_1.SQB_CONNECTION_OPTIONS,
|
|
94
|
-
useFactory: options.useFactory,
|
|
95
|
-
inject: options.inject || [],
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
const useClass = options.useClass || options.useExisting;
|
|
99
|
-
if (useClass) {
|
|
100
|
-
return {
|
|
101
|
-
provide: sqb_constants_js_1.SQB_CONNECTION_OPTIONS,
|
|
102
|
-
useFactory: (optionsFactory) => optionsFactory.createSqbOptions(options.name),
|
|
103
|
-
inject: [useClass],
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
|
|
107
|
-
}
|
|
108
|
-
static async createConnection(moduleOptions, sqbConnectionOptions) {
|
|
109
|
-
const connectionToken = moduleOptions.name;
|
|
110
|
-
// NestJS 8
|
|
111
|
-
// @ts-ignore
|
|
112
|
-
if (rxjs.lastValueFrom) {
|
|
113
|
-
// @ts-ignore
|
|
114
|
-
return await rxjs.lastValueFrom((0, rxjs_1.defer)(async () => new connect_1.SqbClient(sqbConnectionOptions)).pipe((0, sqb_utils_js_1.handleRetry)(connectionToken, sqbConnectionOptions.retryAttempts, sqbConnectionOptions.retryDelay, sqbConnectionOptions.verboseRetryLog, sqbConnectionOptions.toRetry)));
|
|
115
|
-
}
|
|
116
|
-
// NestJS 7
|
|
117
|
-
// @ts-ignore
|
|
118
|
-
return await (0, rxjs_1.defer)(async () => new connect_1.SqbClient(sqbConnectionOptions))
|
|
119
|
-
.pipe((0, sqb_utils_js_1.handleRetry)(connectionToken, sqbConnectionOptions.retryAttempts, sqbConnectionOptions.retryDelay, sqbConnectionOptions.verboseRetryLog, sqbConnectionOptions.toRetry))
|
|
120
|
-
.toPromise();
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
exports.SqbCoreModule = SqbCoreModule;
|
|
124
|
-
exports.SqbCoreModule = SqbCoreModule = SqbCoreModule_1 = tslib_1.__decorate([
|
|
125
|
-
(0, common_1.Global)(),
|
|
126
|
-
(0, common_1.Module)({}),
|
|
127
|
-
tslib_1.__param(0, (0, common_1.Inject)(sqb_constants_js_1.SQB_MODULE_OPTIONS)),
|
|
128
|
-
tslib_1.__metadata("design:paramtypes", [Object, core_1.ModuleRef])
|
|
129
|
-
], SqbCoreModule);
|
package/cjs/sqb.constants.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SQB_MODULE_ID = exports.SQB_CONNECTION_OPTIONS = exports.SQB_MODULE_OPTIONS = void 0;
|
|
4
|
-
exports.SQB_MODULE_OPTIONS = Symbol('SQB_MODULE_OPTIONS');
|
|
5
|
-
exports.SQB_CONNECTION_OPTIONS = Symbol('SQB_CONNECTION_OPTIONS');
|
|
6
|
-
exports.SQB_MODULE_ID = Symbol('SQB_MODULE_ID');
|
package/cjs/sqb.decorators.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InjectSQB = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
const sqb_utils_js_1 = require("./sqb.utils.js");
|
|
6
|
-
const InjectSQB = (name) => (0, common_1.Inject)((0, sqb_utils_js_1.getSQBToken)(name));
|
|
7
|
-
exports.InjectSQB = InjectSQB;
|
package/cjs/sqb.interface.js
DELETED
package/cjs/sqb.module.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var SqbModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.SqbModule = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const common_1 = require("@nestjs/common");
|
|
7
|
-
const sqb_core_module_js_1 = require("./sqb-core.module.js");
|
|
8
|
-
let SqbModule = SqbModule_1 = class SqbModule {
|
|
9
|
-
static forRoot(options) {
|
|
10
|
-
return {
|
|
11
|
-
module: SqbModule_1,
|
|
12
|
-
imports: [sqb_core_module_js_1.SqbCoreModule.forRoot(options)],
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
static forRootAsync(options) {
|
|
16
|
-
return {
|
|
17
|
-
module: SqbModule_1,
|
|
18
|
-
imports: [sqb_core_module_js_1.SqbCoreModule.forRootAsync(options)],
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
exports.SqbModule = SqbModule;
|
|
23
|
-
exports.SqbModule = SqbModule = SqbModule_1 = tslib_1.__decorate([
|
|
24
|
-
(0, common_1.Module)({})
|
|
25
|
-
], SqbModule);
|
package/cjs/sqb.utils.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSQBToken = getSQBToken;
|
|
4
|
-
exports.handleRetry = handleRetry;
|
|
5
|
-
const common_1 = require("@nestjs/common");
|
|
6
|
-
const connect_1 = require("@sqb/connect");
|
|
7
|
-
const operators_1 = require("rxjs/operators");
|
|
8
|
-
const logger = new common_1.Logger('SqbModule');
|
|
9
|
-
/**
|
|
10
|
-
* This function returns a Connection injection token for the given connection name.
|
|
11
|
-
* @param {string | symbol} [name=SQB_DEFAULT_CONNECTION] This optional parameter is either
|
|
12
|
-
* a SqbClient, or a ConnectionOptions or a string.
|
|
13
|
-
* @returns {string | symbol} The Connection injection token.
|
|
14
|
-
*/
|
|
15
|
-
function getSQBToken(name) {
|
|
16
|
-
if (!name)
|
|
17
|
-
return connect_1.SqbClient;
|
|
18
|
-
if (typeof name === 'symbol' || typeof name === 'function')
|
|
19
|
-
return name;
|
|
20
|
-
return `${name}_SqbConnection`;
|
|
21
|
-
}
|
|
22
|
-
function handleRetry(connectionName, retryAttempts = 9, retryDelay = 3000, verboseRetryLog = false, toRetry) {
|
|
23
|
-
return (source) => source.pipe((0, operators_1.retryWhen)(e => e.pipe((0, operators_1.scan)((errorCount, error) => {
|
|
24
|
-
if (toRetry && !toRetry(error)) {
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
const connectionInfo = !connectionName || connectionName === connect_1.SqbClient
|
|
28
|
-
? 'default'
|
|
29
|
-
: ` (${String(connectionName)})`;
|
|
30
|
-
const verboseMessage = verboseRetryLog
|
|
31
|
-
? ` Message: ${error.message}.`
|
|
32
|
-
: '';
|
|
33
|
-
logger.error(`Unable to connect to the database ${connectionInfo}.${verboseMessage} Retrying (${errorCount + 1})...`, error.stack);
|
|
34
|
-
if (errorCount + 1 >= retryAttempts) {
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
return errorCount + 1;
|
|
38
|
-
}, 0), (0, operators_1.delay)(retryDelay))));
|
|
39
|
-
}
|
package/esm/package.json
DELETED
package/types/index.d.cts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|